summaryrefslogtreecommitdiff
path: root/src/device/pciexp_device.c
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/device/pciexp_device.c
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/device/pciexp_device.c')
-rw-r--r--src/device/pciexp_device.c34
1 files changed, 23 insertions, 11 deletions
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;
}