devicetree: Single scan_bridges()

Change-Id: Ifd277992a69a4182e2fac92aaf746abe4fec2a1b
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/8540
Tested-by: build bot (Jenkins)
Reviewed-by: Timothy Pearson <tpearson@raptorengineeringinc.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/src/device/device.c b/src/device/device.c
index 35bb6e2..a8900a6 100644
--- a/src/device/device.c
+++ b/src/device/device.c
@@ -916,15 +916,15 @@
  * @param max Current bus number.
  * @return The maximum bus number found, after scanning all subordinate buses.
  */
-unsigned int scan_bus(struct device *busdev, unsigned int max)
+static unsigned int scan_bus(struct device *busdev, unsigned int max)
 {
 	unsigned int new_max;
 	int do_scan_bus;
 
-	if (!busdev || !busdev->enabled || !busdev->ops ||
-	    !busdev->ops->scan_bus) {
+	if (!busdev->enabled)
 		return max;
-	}
+
+	printk(BIOS_SPEW, "%s scanning...\n", dev_path(busdev));
 
 	post_log_path(busdev);
 
@@ -945,6 +945,19 @@
 	return new_max;
 }
 
+void scan_bridges(struct bus *bus)
+{
+	struct device *child;
+	unsigned int max = bus->secondary;
+
+	for (child = bus->children; child; child = child->sibling) {
+		if (!child->ops || !child->ops->scan_bus)
+			continue;
+		max = scan_bus(child, max);
+	}
+	bus->subordinate = max;
+}
+
 /**
  * Determine the existence of devices and extend the device tree.
  *
diff --git a/src/device/pci_device.c b/src/device/pci_device.c
index 188f101..07b1993 100644
--- a/src/device/pci_device.c
+++ b/src/device/pci_device.c
@@ -1083,7 +1083,6 @@
 {
 	unsigned int devfn;
 	struct device *old_devices;
-	struct device *child;
 
 	printk(BIOS_DEBUG, "PCI: pci_scan_bus for bus %02x\n", bus->secondary);
 
@@ -1144,12 +1143,8 @@
 	 * For all children that implement scan_bus() (i.e. bridges)
 	 * scan the bus behind that child.
 	 */
-	unsigned int max = bus->secondary;
 
-	for (child = bus->children; child; child = child->sibling)
-		max = scan_bus(child, max);
-
-	bus->subordinate = max;
+	scan_bridges(bus);
 
 	/*
 	 * We've scanned the bus and so we know all about what's on the other
diff --git a/src/device/root_device.c b/src/device/root_device.c
index d4ad034..4eae12a 100644
--- a/src/device/root_device.c
+++ b/src/device/root_device.c
@@ -126,22 +126,14 @@
  */
 static unsigned int root_dev_scan_bus(device_t bus, unsigned int passthru)
 {
-	device_t child;
 	struct bus *link;
-	unsigned int max = 0;
 
 	printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
 
 	scan_static_bus(bus, 0);
 
-	for (link = bus->link_list; link; link = link->next) {
-		for (child = link->children; child; child = child->sibling) {
-			if (!child->ops || !child->ops->scan_bus)
-				continue;
-			printk(BIOS_SPEW, "%s scanning...\n", dev_path(child));
-			max = scan_bus(child, max);
-		}
-	}
+	for (link = bus->link_list; link; link = link->next)
+		scan_bridges(link);
 
 	printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));