Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/40543 )
Change subject: device: Add helper function to find matching device on bus ......................................................................
device: Add helper function to find matching device on bus
This change adds a helper function dev_find_matching_device_on_bus() which scans all the child devices on the given bus and calls a function provided by the caller to return the device that matches the caller's criteria.
Change-Id: I2e3332c0a175ab995c523f078f29a9f498f17931 Signed-off-by: Furquan Shaikh furquan@google.com --- M src/device/device_const.c M src/include/device/device.h 2 files changed, 22 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/43/40543/1
diff --git a/src/device/device_const.c b/src/device/device_const.c index c59c5e9..a38cb7e 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -69,6 +69,19 @@ return result; }
+DEVTREE_CONST struct device *dev_find_matching_device_on_bus(const struct bus *bus, + match_device_fn fn) +{ + struct device *child = NULL; + + while ((child = dev_bus_each_child(bus, child)) != NULL) { + if (fn(child)) + break; + } + + return child; +} + /** * Given a device pointer, find the next PCI device. * diff --git a/src/include/device/device.h b/src/include/device/device.h index 4e9c594..2cefecc 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -207,6 +207,15 @@ struct device *dev_find_lapic(unsigned int apic_id); int dev_count_cpu(void);
+/* + * Signature for matching function that is used by dev_find_matching_device_on_bus() to decide + * if the device being considered is the one that matches the caller's criteria. This function + * is supposed to return true if the provided device matches the criteria, else false. + */ +typedef bool (*match_device_fn)(DEVTREE_CONST struct device *dev); +DEVTREE_CONST struct device *dev_find_matching_device_on_bus(const struct bus *bus, + match_device_fn fn); + struct device *add_cpu_device(struct bus *cpu_bus, unsigned int apic_id, int enabled); void set_cpu_topology(struct device *cpu, unsigned int node,