aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/search.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/pci/search.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/pci/search.c')
-rw-r--r--drivers/pci/search.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index ec415352d9ba..20d03f772289 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -9,15 +9,16 @@
9 9
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/slab.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
14#include "pci.h" 15#include "pci.h"
15 16
16DECLARE_RWSEM(pci_bus_sem); 17DECLARE_RWSEM(pci_bus_sem);
17/* 18/*
18 * find the upstream PCIE-to-PCI bridge of a PCI device 19 * find the upstream PCIe-to-PCI bridge of a PCI device
19 * if the device is PCIE, return NULL 20 * if the device is PCIE, return NULL
20 * if the device isn't connected to a PCIE bridge (that is its parent is a 21 * if the device isn't connected to a PCIe bridge (that is its parent is a
21 * legacy PCI bridge and the bridge is directly connected to bus 0), return its 22 * legacy PCI bridge and the bridge is directly connected to bus 0), return its
22 * parent 23 * parent
23 */ 24 */
@@ -26,18 +27,18 @@ pci_find_upstream_pcie_bridge(struct pci_dev *pdev)
26{ 27{
27 struct pci_dev *tmp = NULL; 28 struct pci_dev *tmp = NULL;
28 29
29 if (pdev->is_pcie) 30 if (pci_is_pcie(pdev))
30 return NULL; 31 return NULL;
31 while (1) { 32 while (1) {
32 if (pci_is_root_bus(pdev->bus)) 33 if (pci_is_root_bus(pdev->bus))
33 break; 34 break;
34 pdev = pdev->bus->self; 35 pdev = pdev->bus->self;
35 /* a p2p bridge */ 36 /* a p2p bridge */
36 if (!pdev->is_pcie) { 37 if (!pci_is_pcie(pdev)) {
37 tmp = pdev; 38 tmp = pdev;
38 continue; 39 continue;
39 } 40 }
40 /* PCI device should connect to a PCIE bridge */ 41 /* PCI device should connect to a PCIe bridge */
41 if (pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE) { 42 if (pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE) {
42 /* Busted hardware? */ 43 /* Busted hardware? */
43 WARN_ON_ONCE(1); 44 WARN_ON_ONCE(1);
@@ -149,32 +150,33 @@ struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn)
149} 150}
150 151
151/** 152/**
152 * pci_get_bus_and_slot - locate PCI device from a given PCI bus & slot 153 * pci_get_domain_bus_and_slot - locate PCI device for a given PCI domain (segment), bus, and slot
153 * @bus: number of PCI bus on which desired PCI device resides 154 * @domain: PCI domain/segment on which the PCI device resides.
154 * @devfn: encodes number of PCI slot in which the desired PCI 155 * @bus: PCI bus on which desired PCI device resides
155 * device resides and the logical device number within that slot 156 * @devfn: encodes number of PCI slot in which the desired PCI device
156 * in case of multi-function devices. 157 * resides and the logical device number within that slot in case of
157 * 158 * multi-function devices.
158 * Note: the bus/slot search is limited to PCI domain (segment) 0.
159 * 159 *
160 * Given a PCI bus and slot/function number, the desired PCI device 160 * Given a PCI domain, bus, and slot/function number, the desired PCI
161 * is located in system global list of PCI devices. If the device 161 * device is located in the list of PCI devices. If the device is
162 * is found, a pointer to its data structure is returned. If no 162 * found, its reference count is increased and this function returns a
163 * device is found, %NULL is returned. The returned device has its 163 * pointer to its data structure. The caller must decrement the
164 * reference count bumped by one. 164 * reference count by calling pci_dev_put(). If no device is found,
165 * %NULL is returned.
165 */ 166 */
166 167struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
167struct pci_dev * pci_get_bus_and_slot(unsigned int bus, unsigned int devfn) 168 unsigned int devfn)
168{ 169{
169 struct pci_dev *dev = NULL; 170 struct pci_dev *dev = NULL;
170 171
171 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 172 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
172 if (pci_domain_nr(dev->bus) == 0 && 173 if (pci_domain_nr(dev->bus) == domain &&
173 (dev->bus->number == bus && dev->devfn == devfn)) 174 (dev->bus->number == bus && dev->devfn == devfn))
174 return dev; 175 return dev;
175 } 176 }
176 return NULL; 177 return NULL;
177} 178}
179EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
178 180
179static int match_pci_dev_by_id(struct device *dev, void *data) 181static int match_pci_dev_by_id(struct device *dev, void *data)
180{ 182{
@@ -354,5 +356,4 @@ EXPORT_SYMBOL(pci_find_next_bus);
354EXPORT_SYMBOL(pci_get_device); 356EXPORT_SYMBOL(pci_get_device);
355EXPORT_SYMBOL(pci_get_subsys); 357EXPORT_SYMBOL(pci_get_subsys);
356EXPORT_SYMBOL(pci_get_slot); 358EXPORT_SYMBOL(pci_get_slot);
357EXPORT_SYMBOL(pci_get_bus_and_slot);
358EXPORT_SYMBOL(pci_get_class); 359EXPORT_SYMBOL(pci_get_class);