summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorPatrick Rudolph <siro@das-labor.org>2017-05-22 18:30:27 +0200
committerMartin Roth <martinroth@google.com>2017-06-02 18:51:13 +0200
commita6909f88e95e1ba48e84207f146c9f9a01c7dd32 (patch)
treeb684bf36432bd064ef3d412617d2c5004da497bb /src/device
parent7971582ec49574e42c5fa5d75e6bdba8a0b9b1f8 (diff)
device/device_util: Add function to determine bridge state
Add a method to get the state of a bridge device. Return true if at least one enabled device on the secondary bus is found. Useful to disable non hotplugable bridges without any devices attached. Change-Id: Ic8fe539d233031d4d177b03dd2c03edb5ab8c88d Signed-off-by: Patrick Rudolph <siro@das-labor.org> Reviewed-on: https://review.coreboot.org/19817 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com> Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'src/device')
-rw-r--r--src/device/device_util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/device/device_util.c b/src/device/device_util.c
index e31ade56c0..859de319fa 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -775,6 +775,31 @@ void disable_children(struct bus *bus)
}
}
+/*
+ * Returns true if the device is an enabled bridge that has at least
+ * one enabled device on its secondary bus.
+ */
+bool dev_is_active_bridge(device_t dev)
+{
+ struct bus *link;
+ device_t child;
+
+ if (!dev || !dev->enabled)
+ return 0;
+
+ if (!dev->link_list || !dev->link_list->children)
+ return 0;
+
+ for (link = dev->link_list; link; link = link->next) {
+ for (child = link->children; child; child = child->sibling) {
+ if (child->enabled)
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static void resource_tree(struct device *root, int debug_level, int depth)
{
int i = 0;