diff options
-rw-r--r-- | src/device/pci_device.c | 2 | ||||
-rw-r--r-- | src/device/pciexp_device.c | 34 | ||||
-rw-r--r-- | src/drivers/generic/bayhub_lv2/lv2.c | 2 | ||||
-rw-r--r-- | src/include/device/pciexp.h | 5 |
4 files changed, 27 insertions, 16 deletions
diff --git a/src/device/pci_device.c b/src/device/pci_device.c index 44c47a7548..232328dca8 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -313,7 +313,7 @@ struct msix_entry *pci_msix_get_table(struct device *dev) static unsigned int get_rebar_offset(const struct device *dev, unsigned long index) { - uint32_t offset = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RESIZABLE_BAR); + uint32_t offset = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RESIZABLE_BAR, 0); if (!offset) return 0; diff --git a/src/device/pciexp_device.c b/src/device/pciexp_device.c index 694f1dd275..ea0ec1a39b 100644 --- a/src/device/pciexp_device.c +++ b/src/device/pciexp_device.c @@ -32,17 +32,29 @@ static unsigned int pciexp_get_ext_cap_offset(const struct device *dev, unsigned return 0; } -unsigned int pciexp_find_next_extended_cap(const struct device *dev, unsigned int cap, - unsigned int pos) +/* + * Search for an extended capability with the ID `cap`. + * + * Returns the offset of the first matching extended + * capability if found, or 0 otherwise. + * + * A new search is started with `offset == 0`. + * To continue a search, the prior return value + * should be passed as `offset`. + */ +unsigned int pciexp_find_extended_cap(const struct device *dev, unsigned int cap, + unsigned int offset) { - const unsigned int next_cap_offset = pci_read_config32(dev, pos) >> 20; + unsigned int next_cap_offset; + + if (offset) + next_cap_offset = pci_read_config32(dev, offset) >> 20; + else + next_cap_offset = PCIE_EXT_CAP_OFFSET; + return pciexp_get_ext_cap_offset(dev, cap, next_cap_offset); } -unsigned int pciexp_find_extended_cap(const struct device *dev, unsigned int cap) -{ - return pciexp_get_ext_cap_offset(dev, cap, PCIE_EXT_CAP_OFFSET); -} /* * Re-train a PCIe link @@ -215,7 +227,7 @@ static void pciexp_configure_ltr(struct device *parent, unsigned int parent_cap, if (!_pciexp_enable_ltr(parent, parent_cap, dev, cap)) return; - const unsigned int ltr_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_LTR_ID); + const unsigned int ltr_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_LTR_ID, 0); if (!ltr_cap) return; @@ -340,13 +352,13 @@ static void pciexp_config_L1_sub_state(struct device *root, struct device *dev) if (dev->path.pci.devfn & 0x7) return; - root_cap = pciexp_find_extended_cap(root, PCIE_EXT_CAP_L1SS_ID); + root_cap = pciexp_find_extended_cap(root, PCIE_EXT_CAP_L1SS_ID, 0); if (!root_cap) return; - end_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_L1SS_ID); + end_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_L1SS_ID, 0); if (!end_cap) { - end_cap = pciexp_find_extended_cap(dev, 0xcafe); + end_cap = pciexp_find_extended_cap(dev, 0xcafe, 0); if (!end_cap) return; } diff --git a/src/drivers/generic/bayhub_lv2/lv2.c b/src/drivers/generic/bayhub_lv2/lv2.c index 3a249e0419..b8d4113994 100644 --- a/src/drivers/generic/bayhub_lv2/lv2.c +++ b/src/drivers/generic/bayhub_lv2/lv2.c @@ -23,7 +23,7 @@ static void lv2_enable_ltr(struct device *dev) if (!pciexp_get_ltr_max_latencies(dev, &max_snoop, &max_nosnoop)) return; - const unsigned int ltr_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_LTR_ID); + const unsigned int ltr_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_LTR_ID, 0); if (!ltr_cap) return; diff --git a/src/include/device/pciexp.h b/src/include/device/pciexp.h index 13776dfa72..5a996834d2 100644 --- a/src/include/device/pciexp.h +++ b/src/include/device/pciexp.h @@ -32,9 +32,8 @@ void pciexp_hotplug_scan_bridge(struct device *dev); extern struct device_operations default_pciexp_hotplug_ops_bus; -unsigned int pciexp_find_extended_cap(const struct device *dev, unsigned int cap); -unsigned int pciexp_find_next_extended_cap(const struct device *dev, unsigned int cap, - unsigned int offset); +unsigned int pciexp_find_extended_cap(const struct device *dev, unsigned int cap, + unsigned int offset); static inline bool pciexp_is_downstream_port(int type) { |