[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 09/31] xen/device-tree: Add dt_property_for_each_string macros
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx> This is a port from Linux. Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx> CC: Julien Grall <julien.grall@xxxxxxxxxx> --- xen/common/device_tree.c | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 60b0095..08f8072 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -208,6 +208,24 @@ int dt_property_read_string(const struct dt_device_node *np, return 0; } +const char *dt_property_next_string(const struct dt_property *prop, + const char *cur) +{ + const void *curv = cur; + + if ( !prop ) + return NULL; + + if ( !cur ) + return prop->value; + + curv += strlen(cur) + 1; + if ( curv >= prop->value + prop->length ) + return NULL; + + return curv; +} + 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 738f1b6..9e0931c 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -420,6 +420,27 @@ int dt_property_read_string(const struct dt_device_node *np, const char *propname, const char **out_string); /** + * dt_property_for_each_string - Iterate over an array of strings within + * a property with a given name for a given node. + * + * Example: + * + * struct dt_property *prop; + * const char *s; + * + * dt_property_for_each_string(np, "propname", prop, s) + * printk("String value: %s\n", s); + */ +const char *dt_property_next_string(const struct dt_property *prop, + const char *cur); + +#define dt_property_for_each_string(np, propname, prop, s) \ + for (prop = dt_find_property(np, propname, NULL), \ + s = dt_property_next_string(prop, NULL); \ + s; \ + s = dt_property_next_string(prop, s)) + +/** * Checks if the given "compat" string matches one of the strings in * the device's "compatible" property */ -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |