powerpc/eeh: Reworked eeh_pe_bus_get()
[cascardo/linux.git] / arch / powerpc / kernel / eeh_pe.c
index 8654cb1..9066afc 100644 (file)
@@ -883,32 +883,29 @@ void eeh_pe_restore_bars(struct eeh_pe *pe)
 const char *eeh_pe_loc_get(struct eeh_pe *pe)
 {
        struct pci_bus *bus = eeh_pe_bus_get(pe);
-       struct device_node *dn = pci_bus_to_OF_node(bus);
+       struct device_node *dn;
        const char *loc = NULL;
 
-       if (!dn)
-               goto out;
+       while (bus) {
+               dn = pci_bus_to_OF_node(bus);
+               if (!dn) {
+                       bus = bus->parent;
+                       continue;
+               }
 
-       /* PHB PE or root PE ? */
-       if (pci_is_root_bus(bus)) {
-               loc = of_get_property(dn, "ibm,loc-code", NULL);
-               if (!loc)
+               if (pci_is_root_bus(bus))
                        loc = of_get_property(dn, "ibm,io-base-loc-code", NULL);
+               else
+                       loc = of_get_property(dn, "ibm,slot-location-code",
+                                             NULL);
+
                if (loc)
-                       goto out;
+                       return loc;
 
-               /* Check the root port */
-               dn = dn->child;
-               if (!dn)
-                       goto out;
+               bus = bus->parent;
        }
 
-       loc = of_get_property(dn, "ibm,loc-code", NULL);
-       if (!loc)
-               loc = of_get_property(dn, "ibm,slot-location-code", NULL);
-
-out:
-       return loc ? loc : "N/A";
+       return "N/A";
 }
 
 /**
@@ -923,25 +920,21 @@ out:
  */
 struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 {
-       struct pci_bus *bus = NULL;
        struct eeh_dev *edev;
        struct pci_dev *pdev;
 
-       if (pe->type & EEH_PE_PHB) {
-               bus = pe->phb->bus;
-       } else if (pe->type & EEH_PE_BUS ||
-                  pe->type & EEH_PE_DEVICE) {
-               if (pe->bus) {
-                       bus = pe->bus;
-                       goto out;
-               }
+       if (pe->type & EEH_PE_PHB)
+               return pe->phb->bus;
 
-               edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
-               pdev = eeh_dev_to_pci_dev(edev);
-               if (pdev)
-                       bus = pdev->bus;
-       }
+       /* The primary bus might be cached during probe time */
+       if (pe->state & EEH_PE_PRI_BUS)
+               return pe->bus;
 
-out:
-       return bus;
+       /* Retrieve the parent PCI bus of first (top) PCI device */
+       edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, list);
+       pdev = eeh_dev_to_pci_dev(edev);
+       if (pdev)
+               return pdev->bus;
+
+       return NULL;
 }