|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH RFC v2 1/7] plat/drivers/ofw: Introduce fdt_get_last_node_by_compatible
Hi Justin,
Thanks fort he patch. Please see my comments inline.
Best,
Santiago
On 23.10.19, 05:52, "Minios-devel on behalf of Jia He"
<minios-devel-bounces@xxxxxxxxxxxxxxxxxxxx on behalf of justin.he@xxxxxxx>
wrote:
This patch provides a helper for fdt to get the last node in dts
by the name of compatible matching
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
plat/drivers/include/ofw/fdt.h | 20 ++++++++++++++++++++
plat/drivers/ofw/fdt.c | 27 +++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h
index 6f80a27..b2fb27d 100644
--- a/plat/drivers/include/ofw/fdt.h
+++ b/plat/drivers/include/ofw/fdt.h
@@ -137,4 +137,24 @@ int fdt_node_offset_by_compatible_list(const void
*fdt, int startoffset,
*/
int fdt_get_interrupt(const void *fdt, int nodeoffset,
uint32_t index, int *size, fdt32_t **prop);
+
+/**
+ * fdt_get_last_node_by_compatible - get the last compatible node in fdt
+ * @fdt: pointer to the device tree blob
+ * @endoffset: end offset of the node to find the address for
+ * @compatibles: a list of 'compatible' string to match, should be ended
+ * with NULL string.
+ * If endoffset is -1, no limitation
+ * Else try to get he last node by compatible between [0, endoffset)
+ * returns:
+ * 0 on success , < 0 on failed > 0 the found offset
The comment explaining the return value could be better explained. The way it
reads is that 0 means success, less than 0 is an error, and larger than zero is
the found offset. However, 0 is probably a valid offset to return, and any
other value returned as offset is also valid. Therefore, it should read
something like: ">= 0 on success (where the value is the found offset), < 0 on
failure:", and then like you have now the possible error codes.
+ * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
+ * -FDT_ERR_BADOFFSET, if 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_get_last_node_by_compatible(const void *fdt, int endoffset,
+ const char * const compatible);
#endif
diff --git a/plat/drivers/ofw/fdt.c b/plat/drivers/ofw/fdt.c
index 76f8ff3..a8fe18f 100644
--- a/plat/drivers/ofw/fdt.c
+++ b/plat/drivers/ofw/fdt.c
@@ -288,3 +288,30 @@ int fdt_get_interrupt(const void *fdt, int nodeoffset,
return 0;
}
+
+/*
+ * get the last compatible node in fdt
+ * If endoffset is -1, no limitation
+ * Else try to get he last node by compatible between [0, endoffset)
+ */
+int fdt_get_last_node_by_compatible(const void *fdt, int endoffset,
+ const char * const compatible)
+{
+ int offset, err;
+ int lastoffset = -FDT_ERR_NOTFOUND;
+
+ for (offset = fdt_next_node(fdt, -1, NULL); offset >= 0;
+ offset = fdt_next_node(fdt, offset, NULL)) {
+ err = fdt_node_check_compatible(fdt, offset, compatible);
+ if ((err < 0) && (err != -FDT_ERR_NOTFOUND))
+ return err;
+ else if (err == 0) /* found */ {
+ if (endoffset != -1 && offset >= endoffset)
+ return lastoffset;
+
+ lastoffset = offset;
+ }
+ }
+
+ return lastoffset; /* last node offset */
+}
--
2.17.1
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |