Skip to content

Commit ee12203

Browse files
Ben Widawskydjbw
authored andcommitted
PCI: Add pci_find_dvsec_capability to find designated VSEC
Add pci_find_dvsec_capability to locate a Designated Vendor-Specific Extended Capability with the specified Vendor ID and Capability ID. The Designated Vendor-Specific Extended Capability (DVSEC) allows one or more "vendor" specific capabilities that are not tied to the Vendor ID of the PCI component. Where the DVSEC Vendor may be a standards body like CXL. Cc: David E. Box <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Dan Williams <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Andrew Donnellan <[email protected]> Cc: Lu Baolu <[email protected]> Reviewed-by: Frederic Barrat <[email protected]> Signed-off-by: Ben Widawsky <[email protected]> Reviewed-by: Andrew Donnellan <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Tested-by: Kan Liang <[email protected]> Signed-off-by: Kan Liang <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/163379787943.692348.6814373487017444007.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 85afc31 commit ee12203

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

drivers/pci/pci.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,38 @@ u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap)
732732
}
733733
EXPORT_SYMBOL_GPL(pci_find_vsec_capability);
734734

735+
/**
736+
* pci_find_dvsec_capability - Find DVSEC for vendor
737+
* @dev: PCI device to query
738+
* @vendor: Vendor ID to match for the DVSEC
739+
* @dvsec: Designated Vendor-specific capability ID
740+
*
741+
* If DVSEC has Vendor ID @vendor and DVSEC ID @dvsec return the capability
742+
* offset in config space; otherwise return 0.
743+
*/
744+
u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec)
745+
{
746+
int pos;
747+
748+
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DVSEC);
749+
if (!pos)
750+
return 0;
751+
752+
while (pos) {
753+
u16 v, id;
754+
755+
pci_read_config_word(dev, pos + PCI_DVSEC_HEADER1, &v);
756+
pci_read_config_word(dev, pos + PCI_DVSEC_HEADER2, &id);
757+
if (vendor == v && dvsec == id)
758+
return pos;
759+
760+
pos = pci_find_next_ext_capability(dev, pos, PCI_EXT_CAP_ID_DVSEC);
761+
}
762+
763+
return 0;
764+
}
765+
EXPORT_SYMBOL_GPL(pci_find_dvsec_capability);
766+
735767
/**
736768
* pci_find_parent_resource - return resource region of parent bus of given
737769
* region

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ u16 pci_find_ext_capability(struct pci_dev *dev, int cap);
11301130
u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 pos, int cap);
11311131
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
11321132
u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap);
1133+
u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec);
11331134

11341135
u64 pci_get_dsn(struct pci_dev *dev);
11351136

0 commit comments

Comments
 (0)