summaryrefslogtreecommitdiffstats
path: root/src/device/device_const.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2018-07-25 08:49:19 -0600
committerAaron Durbin <adurbin@chromium.org>2018-07-26 15:35:44 +0000
commita0dabd1848e3e857fe6b6b882278a96b62614ba2 (patch)
tree407a1cc09543c91f0499ccd9c8abd3ffbe211136 /src/device/device_const.c
parent8c2852420c0f46ab3986697a93e0f941d53f49b3 (diff)
downloadcoreboot-a0dabd1848e3e857fe6b6b882278a96b62614ba2.tar.gz
coreboot-a0dabd1848e3e857fe6b6b882278a96b62614ba2.tar.bz2
coreboot-a0dabd1848e3e857fe6b6b882278a96b62614ba2.zip
device: add child traversal helper function
Add a function, dev_bus_each_child(), which walks through all the children for a given bus of a device. This helper allows one to walk through all the children of a given device's bus. BUG=b:111808427,b:111743717 TEST=built Change-Id: Iedceb0d19c05b7abd5a48f8dc30f85461bef5ec6 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/27636 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Justin TerAvest <teravest@chromium.org>
Diffstat (limited to 'src/device/device_const.c')
-rw-r--r--src/device/device_const.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/device/device_const.c b/src/device/device_const.c
index ee64bd13e604..90b68679e99d 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -216,3 +216,27 @@ DEVTREE_CONST struct device *dev_find_slot_pnp(u16 port, u16 device)
}
return 0;
}
+
+/**
+ * Given a device and previous match iterate through all the children.
+ *
+ * @param bus parent device's bus holding all the children
+ * @param prev_child previous child already traversed, if NULL start at
+ * children of parent bus.
+ * @return pointer to child or NULL when no more children
+ */
+DEVTREE_CONST struct device *dev_bus_each_child(const struct bus *parent,
+ DEVTREE_CONST struct device *prev_child)
+{
+ DEVTREE_CONST struct device *dev;
+
+ if (parent == NULL)
+ return NULL;
+
+ if (prev_child == NULL)
+ dev = parent->children;
+ else
+ dev = prev_child->sibling;
+
+ return dev;
+}