From d807358c867e6c2ce845161c70097719e754c33a Mon Sep 17 00:00:00 2001 From: cwz Date: Tue, 17 Mar 2015 16:59:02 +0800 Subject: [PATCH] libfdt: add api fdt_node_offset_by_phandle_node() find node with phandle and start node. Change-Id: I3d7c710367005510ed936e75863f9d3685cb4bc5 Signed-off-by: Mark Yao Signed-off-by: cwz --- lib/libfdt/fdt_ro.c | 23 +++++++++++++++++++++++ lib/libfdt/libfdt.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index 9994d17e56..49c3cddc6f 100755 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -526,6 +526,29 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) return offset; /* error from fdt_next_node() */ } +int fdt_node_offset_by_phandle_node(const void *fdt, int node, uint32_t phandle) +{ + int offset; + + if ((phandle == 0) || (phandle == -1) || (node < 0)) + return -FDT_ERR_BADPHANDLE; + + FDT_CHECK_HEADER(fdt); + + offset = node; + if (fdt_get_phandle(fdt, offset) == phandle) + return offset; + + for (offset = fdt_next_node(fdt, offset, NULL); + offset >= 0; + offset = fdt_next_node(fdt, offset, NULL)) { + if (fdt_get_phandle(fdt, offset) == phandle) + return offset; + } + + return offset; /* error from fdt_next_node() */ +} + int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) { int len = strlen(str); diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h index 210bc855e9..cb533f4275 100644 --- a/lib/libfdt/libfdt.h +++ b/lib/libfdt/libfdt.h @@ -2166,6 +2166,27 @@ int fdt_next_region(const void *fdt, int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, int max_regions, struct fdt_region_state *info); int fdt_device_is_available(const void *blob, int node); +/** + * fdt_node_offset_by_phandle_node - find the node with a given phandle and node + * @fdt: pointer to the device tree blob + * @phandle: phandle value + * @node: start node value + * + * fdt_node_offset_by_phandle_node() returns the offset of the node + * which has the given phandle value. If there is more than one node + * in the tree with the given phandle (an invalid tree), results are + * undefined. + * + * returns: + * structure block offset of the located node (>= 0), on success + * -FDT_ERR_NOTFOUND, no node with that phandle exists + * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, standard meanings + */ +int fdt_node_offset_by_phandle_node(const void *fdt, int node, uint32_t phandle); #endif /* SWIG */ #endif /* _LIBFDT_H */