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

[Minios-devel] [UNIKRAFT PATCH RFC 15/23] plat/ofw: add fdt_node_offset_idx_by_compatible_list



The helper fdt_node_offset_idx_by_compatible_list is similar as
fdt_node_offset_by_compatible_list except that it returns the index
of compatible_list[] array when compatible string is matched.
This is useful when supporting multiple types of platform devices on
arm64.

Signed-off-by: Jia He <justin.he@xxxxxxx>
---
 plat/drivers/include/ofw/fdt.h | 28 ++++++++++++++++++++++++++++
 plat/drivers/ofw/fdt.c         | 18 ++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h
index 8826845a..0220fadc 100644
--- a/plat/drivers/include/ofw/fdt.h
+++ b/plat/drivers/include/ofw/fdt.h
@@ -139,6 +139,34 @@ int fdt_get_address(const void *fdt, int nodeoffset, 
uint32_t index,
 int fdt_node_offset_by_compatible_list(const void *fdt, int startoffset,
                                        const char * const compatibles[]);
 
+/**
+ * fdt_node_offset_idx_by_compatible_list - find nodes with a given
+ *                                     'compatible' list value, and return
+ *                                     index of compatible array
+ * @fdt: pointer to the device tree blob
+ * @startoffset: only find nodes after this offset
+ * @compatibles: a list of 'compatible' string to match, should be ended
+ * with NULL string.
+ * @idx the index of compatible array
+ * fdt_node_offset_idx_by_compatible_list() returns the offset of the
+ * first matched node after startoffset, which has a 'compatible'
+ * property which lists the given compatible string; or if
+ * startoffset is -1, the very first such node in the tree.
+ *
+ * returns:
+ *     structure block offset of the located node (>= 0, >startoffset),
+ *              on success
+ *     -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
+ *             tree after startoffset
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
+ *     -FDT_ERR_BADMAGIC,
+ *     -FDT_ERR_BADVERSION,
+ *     -FDT_ERR_BADSTATE,
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings
+ */
+int fdt_node_offset_idx_by_compatible_list(const void *fdt, int startoffset,
+                               const char * const compatibles[], int *index);
+
 /**
  * fdt_get_interrupt - retrieve device interrupt of a given index
  * @fdt: pointer to the device tree blob
diff --git a/plat/drivers/ofw/fdt.c b/plat/drivers/ofw/fdt.c
index 40b956dc..175ce9d2 100644
--- a/plat/drivers/ofw/fdt.c
+++ b/plat/drivers/ofw/fdt.c
@@ -287,6 +287,24 @@ int fdt_node_offset_by_compatible_list(const void *fdt, 
int startoffset,
        return -FDT_ERR_NOTFOUND;
 }
 
+int fdt_node_offset_idx_by_compatible_list(const void *fdt, int startoffset,
+                         const char * const compatibles[], int *index)
+{
+       int idx, offset;
+
+       for (idx = 0; compatibles[idx] != NULL; idx++) {
+               offset = fdt_node_offset_by_compatible(fdt, startoffset,
+                                 compatibles[idx]);
+               if (offset >= 0) {
+                       *index = idx;
+                       return offset;
+               }
+       }
+
+       *index = idx;
+       return -FDT_ERR_NOTFOUND;
+}
+
 int fdt_get_interrupt(const void *fdt, int nodeoffset,
                        uint32_t index, int *size, fdt32_t **prop)
 {
-- 
2.17.1


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

 


Rackspace

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