From: Chen Baozi Date: Tue, 13 Aug 2013 11:14:23 +0000 (+0800) Subject: xen: Introduce a helper to read a u32 property in device tree. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~6478 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=282a1c2aba06d1860ed91e4df8dd4c42f1a822e6;p=xen.git xen: Introduce a helper to read a u32 property in device tree. Signed-off-by: Chen Baozi Acked-by: Julien Grall --- diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 84d704dc3d..12499853df 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np, return pp ? pp->value : NULL; } +bool_t dt_property_read_u32(const struct dt_device_node *np, + const char *name, u32 *out_value) +{ + u32 len; + const __be32 *val; + + val = dt_get_property(np, name, &len); + if ( !val || len < sizeof(*out_value) ) + return 0; + + *out_value = be32_to_cpup(val); + + return 1; +} + bool_t dt_device_is_compatible(const struct dt_device_node *device, const char *compat) { diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 5a2a5c6971..faf727f10b 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -299,6 +299,17 @@ struct dt_device_node *dt_find_compatible_node(struct dt_device_node *from, const void *dt_get_property(const struct dt_device_node *np, const char *name, u32 *lenp); +/** + * dt_property_read_u32 - Helper to read a u32 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_u32(const struct dt_device_node *np, + const char *name, u32 *out_value); + /** * Checks if the given "compat" string matches one of the strings in * the device's "compatible" property