If get_pbus() is called for a device which has no parent/ancestor bus
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Thu, 5 Mar 2009 19:33:12 +0000 (19:33 +0000)
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Thu, 5 Mar 2009 19:33:12 +0000 (19:33 +0000)
with nonzero PCI bus operations, get_pbus() will get stuck in a silent
endless loop.
Detect the endless loop and break out with an error message.

Such a situation can happen if the device tree is not yet
initialized/walked completely.

This fixes the unexplainable hang if pci_{read,write}_config{8,16,32}was
used in early mainboard code for the AMD DBM690T. Instead, the code will
now die() with a meaningful error message.

Thanks to Ward Vandewege for testing my patches to track down that bug.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Marc Jones <marcj303@gmail.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3972 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

src/devices/pci_ops.c

index a8f09e229d0619004f75ce23bf1a045e7667e2f4..412b0c5b4baee6fb331c273d0fb4e82227e334c7 100644 (file)
@@ -28,6 +28,12 @@ static struct bus *get_pbus(device_t dev)
 {
        struct bus *pbus = dev->bus;
        while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
+               if (pbus == pbus->dev->bus) {
+                       printk_alert("%s in endless loop looking for a parent "
+                               "bus with ops_pci_bus for %s, breaking out\n",
+                                __func__, dev_path(dev));
+                       break;
+               }
                pbus = pbus->dev->bus;
        }
        if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {