summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2020-04-20 17:59:50 -0700
committerFurquan Shaikh <furquan@google.com>2020-04-22 19:14:51 +0000
commit1f3055aa36655cce731dcc8f33a21b011cec14eb (patch)
treeaabdc97bc0cdfc6caf3ccab5f90d94e0bb7b704b
parent38b349cb35738377cf42b71afa9e5d66e1a8eb4b (diff)
downloadcoreboot-1f3055aa36655cce731dcc8f33a21b011cec14eb.tar.xz
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 match function provided by the caller. It returns the first device that the match function returns true for, else NULL if no such device is found. Change-Id: I2e3332c0a175ab995c523f078f29a9f498f17931 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/40543 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r--src/device/device_const.c13
-rw-r--r--src/include/device/device.h13
2 files changed, 26 insertions, 0 deletions
diff --git a/src/device/device_const.c b/src/device/device_const.c
index de404dc0d1..add253b511 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -70,6 +70,19 @@ DEVTREE_CONST struct device *dev_find_path(
return result;
}
+DEVTREE_CONST struct device *dev_find_matching_device_on_bus(const struct bus *bus,
+ match_device_fn fn)
+{
+ DEVTREE_CONST 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 a33702a234..4983b486a4 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -207,6 +207,19 @@ DEVTREE_CONST struct device *dev_find_path(
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);
+/*
+ * Returns the first device on the bus that the match_device_fn returns true for. If no such
+ * device is found, it returns NULL.
+ */
+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,