[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv2 7/8] lib/fdt: Introduce fdt_node_offset_by_compatible_list helper
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. Jira: ENTOS-860 Signed-off-by: Wei Chen <wei.chen@xxxxxxx> Signed-off-by: Jianyong Wu <jianyong.wu@xxxxxxx> Signed-off-by: Jia He <justin.he@xxxxxxx> --- lib/fdt/exportsyms.uk | 1 + lib/fdt/fdt_ro.c | 15 +++++++++++++++ lib/fdt/include/libfdt.h | 27 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/lib/fdt/exportsyms.uk b/lib/fdt/exportsyms.uk index bdef33c..a5ecf7c 100644 --- a/lib/fdt/exportsyms.uk +++ b/lib/fdt/exportsyms.uk @@ -64,3 +64,4 @@ fdt_getprop_u32_by_offset fdt_interrupt_cells fdt_get_address fdt_get_interrupt +fdt_node_offset_by_compatible_list diff --git a/lib/fdt/fdt_ro.c b/lib/fdt/fdt_ro.c index 9afede3..161928e 100644 --- a/lib/fdt/fdt_ro.c +++ b/lib/fdt/fdt_ro.c @@ -741,3 +741,18 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset, return offset; /* error from fdt_next_node() */ } + +int fdt_node_offset_by_compatible_list(const void *fdt, int startoffset, + const char *compatibles[], int size) +{ + int idx, offset; + + for (idx = 0; idx < size; idx++) { + offset = fdt_node_offset_by_compatible(fdt, startoffset, + compatibles[idx]); + if (offset >= 0) + return offset; + } + + return FDT_ERR_NOTFOUND; +} diff --git a/lib/fdt/include/libfdt.h b/lib/fdt/include/libfdt.h index d546b81..b45fe0b 100644 --- a/lib/fdt/include/libfdt.h +++ b/lib/fdt/include/libfdt.h @@ -991,6 +991,33 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset, int fdt_node_offset_by_compatible(const void *fdt, int startoffset, const char *compatible); +/** + * 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 against + * @size: compatible list size + * + * 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[], int size); + /** * fdt_stringlist_contains - check a string list property for a string * @strlist: Property containing a list of strings to check -- 2.17.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |