From e1dbd62d48ef6b82fd6f4906e37ae1a8f873a2cf Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 17 Sep 2013 02:27:49 +0100 Subject: xen: arm: add two new device tree helpers - dt_property_read_u64 - dt_find_node_by_type Signed-off-by: Ian Campbell Acked-by: Julien Grall --- xen/common/device_tree.c | 29 +++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'xen') diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 4a1391cfc2..27ee70875c 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -511,6 +511,21 @@ bool_t dt_property_read_u32(const struct dt_device_node *np, return 1; } + +bool_t dt_property_read_u64(const struct dt_device_node *np, + const char *name, u64 *out_value) +{ + u32 len; + const __be32 *val; + + val = dt_get_property(np, name, &len); + if ( !val || len < sizeof(*out_value) ) + return 0; + + *out_value = dt_read_number(val, 2); + + return 1; +} int dt_property_read_string(const struct dt_device_node *np, const char *propname, const char **out_string) { @@ -576,6 +591,20 @@ struct dt_device_node *dt_find_node_by_name(struct dt_device_node *from, return np; } +struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, + const char *type) +{ + struct dt_device_node *np; + struct dt_device_node *dt; + + dt = from ? from->allnext : dt_host; + dt_for_each_device_node(dt, np) + if ( np->type && (dt_node_cmp(np->type, type) == 0) ) + break; + + return np; +} + struct dt_device_node *dt_find_node_by_path(const char *path) { struct dt_device_node *np; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index a665c9760e..da78c9f0d4 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -351,6 +351,17 @@ const void *dt_get_property(const struct dt_device_node *np, */ bool_t dt_property_read_u32(const struct dt_device_node *np, const char *name, u32 *out_value); +/** + * dt_property_read_u64 - Helper to read a u64 property. + * @np: node to get the value + * @name: name of the property + * @out_value: pointer to return value + * + * Return true if get the desired value. + */ +bool_t dt_property_read_u64(const struct dt_device_node *np, + const char *name, u64 *out_value); + /** * dt_property_read_string - Find and read a string from a property * @np: Device node from which the property value is to be read @@ -399,6 +410,12 @@ bool_t dt_machine_is_compatible(const char *compat); struct dt_device_node *dt_find_node_by_name(struct dt_device_node *node, const char *name); +/** + * dt_find_node_by_type - Find a node by its "type" property + */ +struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, + const char *type); + /** * df_find_node_by_alias - Find a node matching an alias * @alias: The alias to match -- cgit v1.2.3