[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [RFC PATCH 10/31] xen/device-tree: Add dt_property_read_u32_index 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: please original signed-off-bys and also name of the property
in Linux.

> ---
>  xen/common/device_tree.c      | 52 
> +++++++++++++++++++++++++++++++++++++++++++
>  xen/include/xen/device_tree.h | 20 +++++++++++++++++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 08f8072..0fa654e 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -176,6 +176,58 @@ bool_t dt_property_read_u32(const struct dt_device_node 
> *np,
>      return 1;
>  }
>  
> +/**
> + * dt_find_property_value_of_size
> + *
> + * @np:       device node from which the property value is to be read.
> + * @propname: name of the property to be searched.
> + * @min:      minimum allowed length of property value
> + * @max:      maximum allowed length of property value (0 means unlimited)
> + * @len:      if !=NULL, actual length is written to here
> + *
> + * Search for a property in a device node and valid the requested size.
> + * Returns the property value on success, -EINVAL if the property does not
> + * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
> + * property data is too small or too large.
> + */
> +static void *dt_find_property_value_of_size(const struct dt_device_node *np,
> +                                            const char *propname,
> +                                            u32 min, u32 max, size_t *len)
> +{
> +    const struct dt_property *prop = dt_find_property(np, propname, NULL);
> +
> +    if ( !prop )
> +        return ERR_PTR(-EINVAL);
> +    if ( !prop->value )
> +        return ERR_PTR(-ENODATA);
> +    if ( prop->length < min )
> +        return ERR_PTR(-EOVERFLOW);
> +    if ( max && prop->length > max )
> +        return ERR_PTR(-EOVERFLOW);
> +
> +    if ( len )
> +        *len = prop->length;
> +
> +    return prop->value;
> +}
> +
> +int dt_property_read_u32_index(const struct dt_device_node *np,
> +                               const char *propname,
> +                               u32 index, u32 *out_value)
> +{
> +    const u32 *val =
> +        dt_find_property_value_of_size(np, propname,
> +                                       ((index + 1) * sizeof(*out_value)),
> +                                       0,
> +                                       NULL);
> +
> +    if ( IS_ERR(val) )
> +        return PTR_ERR(val);
> +
> +    *out_value = be32_to_cpup(((__be32 *)val) + index);
> +
> +    return 0;
> +}
>  
>  bool_t dt_property_read_u64(const struct dt_device_node *np,
>                           const char *name, u64 *out_value)
> diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
> index 9e0931c..87b4b67 100644
> --- a/xen/include/xen/device_tree.h
> +++ b/xen/include/xen/device_tree.h
> @@ -374,6 +374,26 @@ const struct dt_property *dt_find_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_u32_index - Find and read a u32 from a multi-value 
> property.
> + *
> + * @np:        device node from which the property value is to be read.
> + * @propname:  name of the property to be searched.
> + * @index:     index of the u32 in the list of values
> + * @out_value: pointer to return value, modified only if no error.
> + *
> + * Search for a property in a device node and read nth 32-bit value from
> + * it. Returns 0 on success, -EINVAL if the property does not exist,
> + * -ENODATA if property does not have a value, and -EOVERFLOW if the
> + * property data isn't large enough.
> + *
> + * The out_value is modified only if a valid u32 value can be decoded.
> + */
> +int dt_property_read_u32_index(const struct dt_device_node *np,
> +                               const char *propname,
> +                               u32 index, u32 *out_value);
> +
>  /**
>   * dt_property_read_u64 - Helper to read a u64 property.
>   * @np: node to get the value
> -- 
> 2.7.4
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.