[coreboot-gerrit] Change in coreboot[master]: device/device_util: Add function to determine bridge state

Patrick Rudolph (Code Review) gerrit at coreboot.org
Mon May 22 19:32:54 CEST 2017


Patrick Rudolph has uploaded a new change for review. ( https://review.coreboot.org/19817 )

Change subject: device/device_util: Add function to determine bridge state
......................................................................

device/device_util: Add function to determine bridge state

Add a method to get the state of a bridge device.
Recursively scan all buses behind the bridge for enabled
devices. Return true if at least one enabled device is found.

Useful to disable non hotplugable bridges without any devices attached.

Change-Id: Ic8fe539d233031d4d177b03dd2c03edb5ab8c88d
Signed-off-by: Patrick Rudolph <siro at das-labor.org>
---
M src/device/device_util.c
M src/include/device/device.h
2 files changed, 30 insertions(+), 0 deletions(-)


  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/17/19817/1

diff --git a/src/device/device_util.c b/src/device/device_util.c
index e31ade5..2e59a11 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -775,6 +775,35 @@
 	}
 }
 
+/*
+ * Returns true if the device is an enabled bridge that has at least
+ * one enabled device on it's secondary bus or behind further
+ * bridge devices.
+ */
+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->link_list && child->enabled)
+				return 1;
+
+			if (dev_is_active_bridge(child))
+				return 1;
+		}
+	}
+
+	return 0;
+}
+
 static void resource_tree(struct device *root, int debug_level, int depth)
 {
 	int i = 0;
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 7b4fce3..5bc4d1c 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -190,6 +190,7 @@
 const char *bus_path(struct bus *bus);
 void dev_set_enabled(device_t dev, int enable);
 void disable_children(struct bus *bus);
+bool dev_is_active_bridge(device_t dev);
 
 /* Option ROM helper functions */
 void run_bios(struct device *dev, unsigned long addr);

-- 
To view, visit https://review.coreboot.org/19817
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8fe539d233031d4d177b03dd2c03edb5ab8c88d
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Patrick Rudolph <siro at das-labor.org>



More information about the coreboot-gerrit mailing list