|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH V2 08/33] xen/arm: Add helpers to use the device tree
On Wed, 2013-05-08 at 03:33 +0100, Julien Grall wrote:
> Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx>
>
> Changes in v2:
> - use dt_node_cmp and dt_compat_cmp in early device tree code
> ---
> xen/common/device_tree.c | 127
> ++++++++++++++++++++++++++++++++++++++++-
> xen/include/xen/device_tree.h | 120 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 245 insertions(+), 2 deletions(-)
>
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index bdf8871..449c332 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -88,20 +88,23 @@ bool_t device_tree_type_matches(const void *fdt, int
> node, const char *match)
> if ( prop == NULL )
> return 0;
>
> - return !strcmp(prop, match);
> + return !dt_node_cmp(prop, match);
> }
>
> bool_t device_tree_node_compatible(const void *fdt, int node, const char
> *match)
Aside: I wonder if any of these should be __init...
> {
> int len, l;
> + int mlen;
> const void *prop;
>
> + mlen = strlen(match);
> +
> prop = fdt_getprop(fdt, node, "compatible", &len);
> if ( prop == NULL )
> return 0;
>
> while ( len > 0 ) {
> - if ( !strcmp(prop, match) )
> + if ( !dt_compat_cmp(prop, match, mlen) )
Is there a change in behaviour here where strlen(match) < strlen(prop)?
I may be mistaken but I think match=="foo" would be compatible with a
node "foobar" now whereas it wasn't before.
On the otherhand this is the same behaviour as dt_device_is_compatible
so maybe it is expected. I seem to recall some name matching code which
explicitly wanted to handle foo@0 as matching foo and things, not sure
that applies here though.
> return 1;
> l = strlen(prop) + 1;
> prop += l;
> @@ -573,6 +576,54 @@ const void *dt_get_property(const struct dt_device_node
> *np,
> return pp ? pp->value : NULL;
> }
>
> +bool_t dt_device_is_compatible(const struct dt_device_node *device,
> + const char *compat)
> +{
> + const char* cp;
> + u32 cplen, l;
> +
> + cp = dt_get_property(device, "compatible", &cplen);
> + if ( cp == NULL )
> + return 0;
> + while ( cplen > 0 )
> + {
> + if ( dt_compat_cmp(cp, compat, strlen(compat)) == 0 )
> + return 1;
> + l = strlen(cp) + 1;
> + cp += l;
> + cplen -= l;
> + }
> +
> + return 0;
> +}
> +
> +bool_t dt_machine_is_compatible(const char *compat)
> +{
> + const struct dt_device_node *root;
> + bool_t rc = 0;
> +
> + root = dt_find_node_by_path("/");
> + if ( root )
> + {
> + rc = dt_device_is_compatible(root, compat);
> + }
> + return rc;
> +}
> +
> +struct dt_device_node *dt_find_node_by_name(struct dt_device_node *from,
> + const char *name)
> +{
> + struct dt_device_node *np;
> + struct dt_device_node *dt;
> +
> + dt = from ? from->allnext : dt_host;
> + for_each_device_node(dt, np)
> + if ( np->name && (dt_node_cmp(np->name, name) == 0) )
> + break;
> +
> + return np;
> +}
> +
> struct dt_device_node *dt_find_node_by_path(const char *path)
> {
> struct dt_device_node *np;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |