summaryrefslogtreecommitdiffstats
path: root/cpukit/include/libfdt.h
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2016-07-27 14:55:53 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-07-19 07:01:08 +0200
commitda8eff9943780d1e294da14f096398196316f6d6 (patch)
tree5db91221a6fb74b66a54e21fe15a79a16e734756 /cpukit/include/libfdt.h
parentCorrect a missing space in a fdt_header cast (diff)
downloadrtems-da8eff9943780d1e294da14f096398196316f6d6.tar.bz2
libfdt: Add a subnodes iterator macro
The fdt_for_each_subnode() iterator macro provided by this patch can be used to iterate over a device tree node's subnodes. At each iteration a loop variable will be set to the next subnode. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'cpukit/include/libfdt.h')
-rw-r--r--cpukit/include/libfdt.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 36222fd4a6..911e548163 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -168,6 +168,34 @@ int fdt_first_subnode(const void *fdt, int offset);
*/
int fdt_next_subnode(const void *fdt, int offset);
+/**
+ * fdt_for_each_subnode - iterate over all subnodes of a parent
+ *
+ * @node: child node (int, lvalue)
+ * @fdt: FDT blob (const void *)
+ * @parent: parent node (int)
+ *
+ * This is actually a wrapper around a for loop and would be used like so:
+ *
+ * fdt_for_each_subnode(node, fdt, parent) {
+ * Use node
+ * ...
+ * }
+ *
+ * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
+ * Error handling
+ * }
+ *
+ * Note that this is implemented as a macro and @node is used as
+ * iterator in the loop. The parent variable be constant or even a
+ * literal.
+ *
+ */
+#define fdt_for_each_subnode(node, fdt, parent) \
+ for (node = fdt_first_subnode(fdt, parent); \
+ node >= 0; \
+ node = fdt_next_subnode(fdt, node))
+
/**********************************************************************/
/* General functions */
/**********************************************************************/