X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=drivers%2Fpci%2Fsearch.c;h=8541034021f0d5eaf168d83e425bb66d1b03a2e1;hb=7556afa0e0e436cad4f560ee83e5fbd5dac9359a;hp=c13232435dc06322f824b1f4fd07d34bdce112bb;hpb=c8d8170feb824875baf68f8aaecb181a6500ce81;p=powerpc.git diff --git a/drivers/pci/search.c b/drivers/pci/search.c index c13232435d..8541034021 100644 --- a/drivers/pci/search.c +++ b/drivers/pci/search.c @@ -14,6 +14,40 @@ #include "pci.h" DECLARE_RWSEM(pci_bus_sem); +/* + * find the upstream PCIE-to-PCI bridge of a PCI device + * if the device is PCIE, return NULL + * if the device isn't connected to a PCIE bridge (that is its parent is a + * legacy PCI bridge and the bridge is directly connected to bus 0), return its + * parent + */ +struct pci_dev * +pci_find_upstream_pcie_bridge(struct pci_dev *pdev) +{ + struct pci_dev *tmp = NULL; + + if (pdev->is_pcie) + return NULL; + while (1) { + if (!pdev->bus->self) + break; + pdev = pdev->bus->self; + /* a p2p bridge */ + if (!pdev->is_pcie) { + tmp = pdev; + continue; + } + /* PCI device should connect to a PCIE bridge */ + if (pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE) { + /* Busted hardware? */ + WARN_ON_ONCE(1); + return NULL; + } + return pdev; + } + + return tmp; +} static struct pci_bus *pci_do_find_bus(struct pci_bus *bus, unsigned char busnr) { @@ -79,6 +113,8 @@ pci_find_next_bus(const struct pci_bus *from) return b; } +#ifdef CONFIG_PCI_LEGACY + /** * pci_find_slot - locate PCI device from a given PCI slot * @bus: number of PCI bus on which desired PCI device resides @@ -103,6 +139,8 @@ pci_find_slot(unsigned int bus, unsigned int devfn) return NULL; } +#endif /* CONFIG_PCI_LEGACY */ + /** * pci_get_slot - locate PCI device for a given PCI slot * @bus: PCI bus on which desired PCI device resides @@ -139,12 +177,14 @@ struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn) } /** - * pci_get_bus_and_slot - locate PCI device from a given PCI slot + * pci_get_bus_and_slot - locate PCI device from a given PCI bus & slot * @bus: number of PCI bus on which desired PCI device resides * @devfn: encodes number of PCI slot in which the desired PCI * device resides and the logical device number within that slot * in case of multi-function devices. * + * Note: the bus/slot search is limited to PCI domain (segment) 0. + * * Given a PCI bus and slot/function number, the desired PCI device * is located in system global list of PCI devices. If the device * is found, a pointer to its data structure is returned. If no @@ -157,12 +197,14 @@ struct pci_dev * pci_get_bus_and_slot(unsigned int bus, unsigned int devfn) struct pci_dev *dev = NULL; while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { - if (dev->bus->number == bus && dev->devfn == devfn) + if (pci_domain_nr(dev->bus) == 0 && + (dev->bus->number == bus && dev->devfn == devfn)) return dev; } return NULL; } +#ifdef CONFIG_PCI_LEGACY /** * pci_find_subsys - begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids @@ -199,7 +241,7 @@ static struct pci_dev * pci_find_subsys(unsigned int vendor, * can cause some machines to crash. So here we detect and flag that * situation and bail out early. */ - if (unlikely(list_empty(&pci_devices))) + if (unlikely(no_pci_devices())) return NULL; down_read(&pci_bus_sem); n = from ? from->global_list.next : pci_devices.next; @@ -241,6 +283,7 @@ pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev * { return pci_find_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from); } +#endif /* CONFIG_PCI_LEGACY */ /** * pci_get_subsys - begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id @@ -274,7 +317,7 @@ pci_get_subsys(unsigned int vendor, unsigned int device, * can cause some machines to crash. So here we detect and flag that * situation and bail out early. */ - if (unlikely(list_empty(&pci_devices))) + if (unlikely(no_pci_devices())) return NULL; down_read(&pci_bus_sem); n = from ? from->global_list.next : pci_devices.next; @@ -431,8 +474,11 @@ int pci_dev_present(const struct pci_device_id *ids) EXPORT_SYMBOL(pci_dev_present); EXPORT_SYMBOL(pci_find_present); +#ifdef CONFIG_PCI_LEGACY EXPORT_SYMBOL(pci_find_device); EXPORT_SYMBOL(pci_find_slot); +#endif /* CONFIG_PCI_LEGACY */ + /* For boot time work */ EXPORT_SYMBOL(pci_find_bus); EXPORT_SYMBOL(pci_find_next_bus);