xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Rahul Singh <rahul.singh@arm.com>
To: xen-devel@lists.xenproject.org
Cc: bertrand.marquis@arm.com, rahul.singh@arm.com,
	andre.przywara@arm.com,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>
Subject: [PATCH v2 06/17] xen/device-tree: Add dt_property_read_variable_u32_array helper
Date: Wed, 22 Sep 2021 12:34:52 +0100	[thread overview]
Message-ID: <35eb7ec429da3a9e1af626af4521c13c9683f8fd.1632307952.git.rahul.singh@arm.com> (raw)
In-Reply-To: <cover.1632307952.git.rahul.singh@arm.com>
In-Reply-To: <cover.1632307952.git.rahul.singh@arm.com>

Based on tag Linux v5.14.2 commit bbdd3de144fc142f2f4b9834c9241cc4e7f3d3fc

Import the Linux helper of_property_read_variable_u32_array. This
function find and read an array of 32 bit integers from a property,
with bounds on the minimum and maximum array size.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
Change in v2: Patch introduced in v2
---
 xen/common/device_tree.c      | 61 +++++++++++++++++++++++++++++++++++
 xen/include/xen/device_tree.h | 26 +++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 03d25a81ce..53160d61f8 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -208,6 +208,67 @@ int dt_property_read_string(const struct dt_device_node *np,
     return 0;
 }
 
+/**
+ * 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.
+ *
+ * Return: 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_variable_u32_array(const struct dt_device_node *np,
+                                        const char *propname, u32 *out_values,
+                                        size_t sz_min, size_t sz_max)
+{
+    size_t sz, count;
+    const __be32 *val = dt_find_property_value_of_size(np, propname,
+                        (sz_min * sizeof(*out_values)),
+                        (sz_max * sizeof(*out_values)),
+                        &sz);
+
+    if ( IS_ERR(val) )
+        return PTR_ERR(val);
+
+    if ( !sz_max )
+        sz = sz_min;
+    else
+        sz /= sizeof(*out_values);
+
+    count = sz;
+    while ( count-- )
+        *out_values++ = be32_to_cpup(val++);
+
+    return sz;
+}
+
 int dt_property_match_string(const struct dt_device_node *np,
                              const char *propname, const char *string)
 {
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index b02696be94..1693fb8e8c 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -366,6 +366,32 @@ bool_t dt_property_read_u32(const struct dt_device_node *np,
 bool_t dt_property_read_u64(const struct dt_device_node *np,
                             const char *name, u64 *out_value);
 
+
+/**
+ * dt_property_read_variable_u32_array - Find and read an array of 32 bit
+ * integers from a property, with bounds on the minimum and maximum array size.
+ *
+ * @np:     device node from which the property value is to be read.
+ * @propname:   name of the property to be searched.
+ * @out_values: pointer to return found values.
+ * @sz_min: minimum number of array elements to read
+ * @sz_max: maximum number of array elements to read, if zero there is no
+ *      upper limit on the number of elements in the dts entry but only
+ *      sz_min will be read.
+ *
+ * Search for a property in a device node and read 32-bit value(s) from
+ * it.
+ *
+ * Return: The number of elements read on success, -EINVAL if the property
+ * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
+ * if the property data is smaller than sz_min or longer than sz_max.
+ *
+ * The out_values is modified only if a valid u32 value can be decoded.
+ */
+int dt_property_read_variable_u32_array(const struct dt_device_node *np,
+                                        const char *propname, u32 *out_values,
+                                        size_t sz_min, size_t sz_max);
+
 /**
  * dt_property_read_bool - Check if a property exists
  * @np: node to get the value
-- 
2.17.1



  parent reply	other threads:[~2021-09-22 11:37 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 11:34 [PATCH v2 00/17] PCI devices passthrough on Arm Rahul Singh
2021-09-22 11:34 ` [PATCH v2 01/17] xen/pci: Refactor MSI code that implements MSI functionality within XEN Rahul Singh
2021-09-22 11:34 ` [PATCH v2 02/17] xen/pci: solve compilation error on ARM with HAS_PCI enabled Rahul Singh
2021-09-22 22:04   ` Stefano Stabellini
2021-09-23  2:07   ` Julien Grall
2021-09-23 11:14     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 03/17] xen/arm: solve compilation error on ARM with ACPI && HAS_PCI Rahul Singh
2021-09-22 22:08   ` Stefano Stabellini
2021-09-22 11:34 ` [PATCH v2 04/17] xen/arm: xc_domain_ioport_permission(..) not supported on ARM Rahul Singh
2021-09-22 22:13   ` Stefano Stabellini
2021-09-22 11:34 ` [PATCH v2 05/17] xen/arm: Add PHYSDEVOP_pci_device_* support for ARM Rahul Singh
2021-09-22 22:37   ` Stefano Stabellini
2021-09-23 11:19     ` Rahul Singh
2021-09-22 11:34 ` Rahul Singh [this message]
2021-09-22 23:06   ` [PATCH v2 06/17] xen/device-tree: Add dt_property_read_variable_u32_array helper Stefano Stabellini
2021-09-23 11:21     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 07/17] xen/device-tree: Add dt_property_read_u32_array helper Rahul Singh
2021-09-22 23:44   ` Stefano Stabellini
2021-09-22 11:34 ` [PATCH v2 08/17] xen/device-tree: Add dt_get_pci_domain_nr helper Rahul Singh
2021-09-22 23:50   ` Stefano Stabellini
2021-09-23 11:52     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 09/17] xen/arm: Add support for PCI init to initialize the PCI driver Rahul Singh
2021-09-23  0:03   ` Stefano Stabellini
2021-09-23 14:53     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 10/17] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" Rahul Singh
2021-09-23  0:14   ` Stefano Stabellini
2021-09-23 15:03     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 11/17] xen/arm: PCI host bridge discovery within XEN on ARM Rahul Singh
2021-09-23  2:09   ` Stefano Stabellini
2021-09-23 13:03     ` Oleksandr Andrushchenko
2021-09-23 15:36       ` Stefano Stabellini
2021-09-23 17:08     ` Rahul Singh
2021-09-23 19:12       ` Stefano Stabellini
2021-09-24 12:54         ` Rahul Singh
2021-09-24 21:42           ` Stefano Stabellini
2021-09-24 23:26             ` Stefano Stabellini
2021-09-27 16:20               ` Rahul Singh
2021-09-27 16:59             ` Julien Grall
2021-09-22 11:34 ` [PATCH v2 12/17] xen/arm: Add support for Xilinx ZynqMP PCI host controller Rahul Singh
2021-09-23  2:11   ` Stefano Stabellini
2021-09-23 15:08     ` Rahul Singh
2021-09-22 11:34 ` [PATCH v2 13/17] xen:arm: Implement pci access functions Rahul Singh
2021-09-23  2:23   ` Stefano Stabellini
2021-09-23  8:52     ` Julien Grall
2021-09-23 15:17       ` Rahul Singh
2021-09-23  9:02     ` Julien Grall
2021-09-23 15:19       ` Rahul Singh
2021-09-23 15:15     ` Rahul Singh
2021-09-22 11:35 ` [PATCH v2 14/17] xen/arm: Enable the existing x86 virtual PCI support for ARM Rahul Singh
2021-09-23  2:41   ` Stefano Stabellini
2021-09-23 15:34     ` Rahul Singh
2021-09-24  7:21       ` Oleksandr Andrushchenko
2021-09-24  7:37     ` Jan Beulich
2021-09-24  7:44   ` Jan Beulich
2021-09-28 16:32     ` Rahul Singh
2021-09-22 11:35 ` [PATCH v2 15/17] xen/arm: Transitional change to build HAS_VPCI on ARM Rahul Singh
2021-09-22 11:35 ` [PATCH v2 16/17] arm/libxl: Emulated PCI device tree node in libxl Rahul Singh
2021-09-23 20:41   ` Stefano Stabellini
2021-09-22 11:35 ` [PATCH v2 17/17] xen/arm: Add linux,pci-domain property for hwdom if not available Rahul Singh
2021-09-23  2:52   ` Stefano Stabellini
2021-09-23 15:21     ` Rahul Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=35eb7ec429da3a9e1af626af4521c13c9683f8fd.1632307952.git.rahul.singh@arm.com \
    --to=rahul.singh@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).