diff options
author | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-07-15 16:13:00 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-02-19 19:12:26 -0500 |
commit | cf4c43dd439b90a1a876b3f836ebe745abb9a269 (patch) | |
tree | 59d7a278d9d5cb6c9927819fa75231e284b29556 /drivers/pci | |
parent | 724e6d3fe8003c3f60bf404bf22e4e331327c596 (diff) |
PCI: Add pci_bus_find_ext_capability
For use by code that needs to walk extended capability lists before
pci_dev structures are set up.
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
LKML-Reference: <43F901BD926A4E43B106BF17856F07559FB80CFD@orsmsx508.amr.corp.intel.com>
Signed-off-by: Jacob Pan <jacob.jun.pan@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/pci.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 315fea47e784..aad62af2b4c6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -297,6 +297,49 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap) | |||
297 | } | 297 | } |
298 | EXPORT_SYMBOL_GPL(pci_find_ext_capability); | 298 | EXPORT_SYMBOL_GPL(pci_find_ext_capability); |
299 | 299 | ||
300 | /** | ||
301 | * pci_bus_find_ext_capability - find an extended capability | ||
302 | * @bus: the PCI bus to query | ||
303 | * @devfn: PCI device to query | ||
304 | * @cap: capability code | ||
305 | * | ||
306 | * Like pci_find_ext_capability() but works for pci devices that do not have a | ||
307 | * pci_dev structure set up yet. | ||
308 | * | ||
309 | * Returns the address of the requested capability structure within the | ||
310 | * device's PCI configuration space or 0 in case the device does not | ||
311 | * support it. | ||
312 | */ | ||
313 | int pci_bus_find_ext_capability(struct pci_bus *bus, unsigned int devfn, | ||
314 | int cap) | ||
315 | { | ||
316 | u32 header; | ||
317 | int ttl; | ||
318 | int pos = PCI_CFG_SPACE_SIZE; | ||
319 | |||
320 | /* minimum 8 bytes per capability */ | ||
321 | ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; | ||
322 | |||
323 | if (!pci_bus_read_config_dword(bus, devfn, pos, &header)) | ||
324 | return 0; | ||
325 | if (header == 0xffffffff || header == 0) | ||
326 | return 0; | ||
327 | |||
328 | while (ttl-- > 0) { | ||
329 | if (PCI_EXT_CAP_ID(header) == cap) | ||
330 | return pos; | ||
331 | |||
332 | pos = PCI_EXT_CAP_NEXT(header); | ||
333 | if (pos < PCI_CFG_SPACE_SIZE) | ||
334 | break; | ||
335 | |||
336 | if (!pci_bus_read_config_dword(bus, devfn, pos, &header)) | ||
337 | break; | ||
338 | } | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
300 | static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap) | 343 | static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap) |
301 | { | 344 | { |
302 | int rc, ttl = PCI_FIND_CAP_TTL; | 345 | int rc, ttl = PCI_FIND_CAP_TTL; |