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

Re: [Minios-devel] [UNIKRAFT PATCHv3 4/6] plat/common: Introduce fdt_node_offset_by_compatible_list helper



Hi Jia,

On 3/21/19 8:05 AM, Jia He wrote:
From: Jianyong Wu <jianyong.wu@xxxxxxx>
For most of devices that will use the device tree will have one
or more compatible strings. This helper will avoid implement a
function to match compatible list everywhere.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jianyong Wu <jianyong.wu@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
  plat/common/arm/irq_fdt.c         | 15 +++++++++++++++
  plat/common/include/arm/irq_fdt.h | 25 +++++++++++++++++++++++++
  2 files changed, 40 insertions(+)

diff --git a/plat/common/arm/irq_fdt.c b/plat/common/arm/irq_fdt.c
index 90260c4..a13b04d 100644
--- a/plat/common/arm/irq_fdt.c
+++ b/plat/common/arm/irq_fdt.c
@@ -162,3 +162,18 @@ int fdt_get_address(const void *fdt, int nodeoffset, int 
index,
return 0;
  }
+
+int fdt_node_offset_by_compatible_list(const void *fdt, int startoffset,
+                                 const char *compatibles[])
+{
+       int idx, offset;
+
+       for (idx = 0;  strlen(compatibles[idx]) != 0; idx++) {

In the comment below, you say it should be ended with a "NULL string". I understand it as this should compatibles[idx] should contain NULL.

However, strlen cannot deal with it. So should not the check be compatibles[idx] != NULL?

+               offset = fdt_node_offset_by_compatible(fdt, startoffset,
+                                 compatibles[idx]);
+               if (offset >= 0)
+                       return offset;
+       }
+
+       return FDT_ERR_NOTFOUND;
+}
diff --git a/plat/common/include/arm/irq_fdt.h 
b/plat/common/include/arm/irq_fdt.h
index 2637a58..9d7c802 100644
--- a/plat/common/include/arm/irq_fdt.h
+++ b/plat/common/include/arm/irq_fdt.h
@@ -91,4 +91,29 @@ int fdt_interrupt_cells(const void *fdt, int nodeoffset);
   */
  int fdt_get_address(const void *fdt, int nodeoffset, int index,
                        uint64_t *addr, uint64_t *size);
+/**
+ * fdt_node_offset_by_compatible_list - find nodes with a given
+ *                                     'compatible' list value
+ * @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.
+ * fdt_node_offset_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_by_compatible_list(const void *fdt, int startoffset,
+                                 const char *compatibles[]);


Cheers,

--
Julien Grall

_______________________________________________
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®.