|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC PATCH 11/31] xen/device-tree: Add dt_property_count_elems_of_size helper
On Thu, 9 Nov 2017, Oleksandr Tyshchenko wrote:
> 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>
Same here
> ---
> xen/common/device_tree.c | 20 ++++++++++++++++++++
> xen/include/xen/device_tree.h | 15 +++++++++++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 0fa654e..7b4cad3 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -278,6 +278,26 @@ const char *dt_property_next_string(const struct
> dt_property *prop,
> return curv;
> }
>
> +int dt_property_count_elems_of_size(const struct dt_device_node *np,
> + const char *propname, int elem_size)
> +{
> + const struct dt_property *prop = dt_find_property(np, propname, NULL);
> +
> + if ( !prop )
> + return -EINVAL;
> + if ( !prop->value )
> + return -ENODATA;
> +
> + if ( prop->length % elem_size != 0 )
> + {
> + printk("%s: size of %s is not a multiple of %d\n", np->full_name,
> + propname, elem_size);
> + return -EINVAL;
> + }
> +
> + return prop->length / elem_size;
> +}
> +
> 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 87b4b67..e2d7346 100644
> --- a/xen/include/xen/device_tree.h
> +++ b/xen/include/xen/device_tree.h
> @@ -461,6 +461,21 @@ const char *dt_property_next_string(const struct
> dt_property *prop,
> s = dt_property_next_string(prop, s))
>
> /**
> + * dt_property_count_elems_of_size - Count the number of elements in a
> property
> + *
> + * @np: device node from which the property value is to be read.
> + * @propname: name of the property to be searched.
> + * @elem_size: size of the individual element
> + *
> + * Search for a property in a device node and count the number of elements of
> + * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
> + * property does not exist or its length does not match a multiple of
> elem_size
> + * and -ENODATA if the property does not have a value.
> + */
> +int dt_property_count_elems_of_size(const struct dt_device_node *np,
> + const char *propname, int elem_size);
> +
> +/**
> * 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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |