summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2022-08-05 12:58:18 +0200
committerFelix Held <felix-coreboot@felixheld.de>2022-08-17 16:29:39 +0000
commit5ffc2c8a3f38fbb7be2faadf207590acd3999205 (patch)
treec46ac16e011b35867b67550a66a57ee0a7333b8c /src
parentd5ab24cd48006022ca60fe35f0f0366f3edce748 (diff)
pciexp_device: Join pciexp_find_(next_)extended_cap() APIs
Move the `offset` parameter into pciexp_find_extended_cap(). If it's called with `0`, we start a new search. If it's an existing offset, we continue the search. This makes it easier to search for multiple occurences of a capa- bility in a single loop. Change-Id: I80115372a82523b90460d97f0fd0fa565c3f56cb Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/66453 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/device/pci_device.c2
-rw-r--r--src/device/pciexp_device.c34
-rw-r--r--src/drivers/generic/bayhub_lv2/lv2.c2
-rw-r--r--src/include/device/pciexp.h5
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)
{