PCI: Add pci_find_next_ext_capability()
Some extended capabilities, e.g., the vendor-specific capability, can occur several times. The existing pci_find_ext_capability() only finds the first occurrence. This adds pci_find_next_ext_capability(), which can iterate through all of them. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
0d7614f09c
commit
44a9a36f6b
|
@ -285,6 +285,58 @@ static int pci_pcie_cap2(struct pci_dev *dev)
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pci_find_next_ext_capability - Find an extended capability
|
||||||
|
* @dev: PCI device to query
|
||||||
|
* @start: address at which to start looking (0 to start at beginning of list)
|
||||||
|
* @cap: capability code
|
||||||
|
*
|
||||||
|
* Returns the address of the next matching extended capability structure
|
||||||
|
* within the device's PCI configuration space or 0 if the device does
|
||||||
|
* not support it. Some capabilities can occur several times, e.g., the
|
||||||
|
* vendor-specific capability, and this provides a way to find them all.
|
||||||
|
*/
|
||||||
|
int pci_find_next_ext_capability(struct pci_dev *dev, int start, int cap)
|
||||||
|
{
|
||||||
|
u32 header;
|
||||||
|
int ttl;
|
||||||
|
int pos = PCI_CFG_SPACE_SIZE;
|
||||||
|
|
||||||
|
/* minimum 8 bytes per capability */
|
||||||
|
ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
|
||||||
|
|
||||||
|
if (dev->cfg_size <= PCI_CFG_SPACE_SIZE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (start)
|
||||||
|
pos = start;
|
||||||
|
|
||||||
|
if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we have no capabilities, this is indicated by cap ID,
|
||||||
|
* cap version and next pointer all being 0.
|
||||||
|
*/
|
||||||
|
if (header == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while (ttl-- > 0) {
|
||||||
|
if (PCI_EXT_CAP_ID(header) == cap && pos != start)
|
||||||
|
return pos;
|
||||||
|
|
||||||
|
pos = PCI_EXT_CAP_NEXT(header);
|
||||||
|
if (pos < PCI_CFG_SPACE_SIZE)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(pci_find_next_ext_capability);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pci_find_ext_capability - Find an extended capability
|
* pci_find_ext_capability - Find an extended capability
|
||||||
* @dev: PCI device to query
|
* @dev: PCI device to query
|
||||||
|
@ -301,39 +353,7 @@ static int pci_pcie_cap2(struct pci_dev *dev)
|
||||||
*/
|
*/
|
||||||
int pci_find_ext_capability(struct pci_dev *dev, int cap)
|
int pci_find_ext_capability(struct pci_dev *dev, int cap)
|
||||||
{
|
{
|
||||||
u32 header;
|
return pci_find_next_ext_capability(dev, 0, cap);
|
||||||
int ttl;
|
|
||||||
int pos = PCI_CFG_SPACE_SIZE;
|
|
||||||
|
|
||||||
/* minimum 8 bytes per capability */
|
|
||||||
ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
|
|
||||||
|
|
||||||
if (dev->cfg_size <= PCI_CFG_SPACE_SIZE)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we have no capabilities, this is indicated by cap ID,
|
|
||||||
* cap version and next pointer all being 0.
|
|
||||||
*/
|
|
||||||
if (header == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while (ttl-- > 0) {
|
|
||||||
if (PCI_EXT_CAP_ID(header) == cap)
|
|
||||||
return pos;
|
|
||||||
|
|
||||||
pos = PCI_EXT_CAP_NEXT(header);
|
|
||||||
if (pos < PCI_CFG_SPACE_SIZE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pci_find_ext_capability);
|
EXPORT_SYMBOL_GPL(pci_find_ext_capability);
|
||||||
|
|
||||||
|
|
|
@ -755,6 +755,7 @@ enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev);
|
||||||
int pci_find_capability(struct pci_dev *dev, int cap);
|
int pci_find_capability(struct pci_dev *dev, int cap);
|
||||||
int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
|
int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
|
||||||
int pci_find_ext_capability(struct pci_dev *dev, int cap);
|
int pci_find_ext_capability(struct pci_dev *dev, int cap);
|
||||||
|
int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
|
||||||
int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
|
int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
|
||||||
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
|
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
|
||||||
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
|
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
|
||||||
|
|
Loading…
Reference in New Issue