From: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
To: <igt-dev@lists.freedesktop.org>
Cc: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
Subject: [PATCH v1 2/4] lib/igt_pci: Add PCI extended capability lookup
Date: Wed, 16 Sep 2026 13:51:59 +0200 [thread overview]
Message-ID: <20260916115201.1973752-3-piotr.piorkowski@intel.com> (raw)
In-Reply-To: <20260916115201.1973752-1-piotr.piorkowski@intel.com>
From: Piotr Piórkowski <piotr.piorkowski@intel.com>
Add support for locating PCI Express extended capabilities in raw
configuration space.
Validate the extended capability list while traversing it and report
malformed chains or invalid offsets.
Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Assisted-by: GPT-5.6 Luna
---
lib/igt_pci.c | 40 ++++++++++++++++++++++++++++++++++++++++
lib/igt_pci.h | 1 +
2 files changed, 41 insertions(+)
diff --git a/lib/igt_pci.c b/lib/igt_pci.c
index 06717fe8eb..a87e45c184 100644
--- a/lib/igt_pci.c
+++ b/lib/igt_pci.c
@@ -61,6 +61,46 @@ int find_pci_cap_offset(struct pci_device *dev, enum pci_cap_id cap_id)
return find_pci_cap_offset_at(dev, cap_id, PCI_CAPS_START);
}
+/**
+ * find_pci_ext_cap_offset:
+ * @dev: pci device
+ * @cap_id: searched extended capability id, 0 means any capability
+ *
+ * return:
+ * -1 on config read error, 0 if capability is not found,
+ * otherwise offset at which capability with cap_id is found
+ */
+int find_pci_ext_cap_offset(struct pci_device *dev, uint16_t cap_id)
+{
+ uint32_t cap_header;
+ unsigned int offset = PCI_EXT_CAPS_START;
+ int loop = (PCI_EXT_CFG_SPACE_SIZE - PCI_EXT_CAPS_START) / sizeof(cap_header);
+
+ while (loop--) {
+ if (pci_device_cfg_read_u32(dev, &cap_header, offset))
+ return -1;
+
+ if (!cap_header)
+ break;
+
+ if (!cap_id || cap_id == (cap_header & 0xffff))
+ return offset;
+
+ offset = (cap_header >> 20) & 0xffc;
+ if (!offset)
+ break;
+
+ igt_fail_on_f(offset < PCI_EXT_CAPS_START ||
+ offset >= PCI_EXT_CFG_SPACE_SIZE,
+ "pci extended capability offset is invalid: 0x%x\n", offset);
+ }
+
+ igt_fail_on_f(loop <= 0 && offset,
+ "pci extended capability offset doesn't terminate\n");
+
+ return 0;
+}
+
/**
* igt_pci_config_raw_read:
* @pci_slot: PCI device BDF (e.g. "0000:01:00.0")
diff --git a/lib/igt_pci.h b/lib/igt_pci.h
index 787c10fc51..d7d2254678 100644
--- a/lib/igt_pci.h
+++ b/lib/igt_pci.h
@@ -29,6 +29,7 @@ enum pci_cap_id {
#define PCI_SLOT_PWR_CTRL_PRESENT (1 << 1)
int find_pci_cap_offset(struct pci_device *dev, enum pci_cap_id cap_id);
+int find_pci_ext_cap_offset(struct pci_device *dev, uint16_t cap_id);
int igt_pci_config_raw_read(const char *pci_slot, void *buffer, size_t length);
uint16_t igt_pci_config_raw_read_u16(const uint8_t *config, unsigned int offset);
uint32_t igt_pci_config_raw_read_u32(const uint8_t *config, unsigned int offset);
--
2.34.1
next prev parent reply other threads:[~2026-09-16 11:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 11:51 [PATCH v1 0/4] Add PCI configuration tests for SR-IOV VFs Piórkowski, Piotr
2026-09-16 11:51 ` [PATCH v1 1/4] lib/igt_pci: Add raw configuration space helpers Piórkowski, Piotr
2026-09-17 15:33 ` [v1,1/4] " Laguna, Lukasz
2026-09-16 11:51 ` Piórkowski, Piotr [this message]
2026-09-17 15:36 ` [v1,2/4] lib/igt_pci: Add PCI extended capability lookup Laguna, Lukasz
2026-09-16 11:52 ` [PATCH v1 3/4] tests/sriov_pci_config: Add VF core config checks Piórkowski, Piotr
2026-09-17 15:38 ` [v1,3/4] " Laguna, Lukasz
2026-09-16 11:52 ` [PATCH v1 4/4] tests/sriov_pci_config: Add optional capability checks Piórkowski, Piotr
2026-09-17 15:47 ` [v1,4/4] " Laguna, Lukasz
2026-09-16 19:24 ` ✓ Xe.CI.BAT: success for Add PCI configuration tests for SR-IOV VFs Patchwork
2026-09-16 20:10 ` ✓ i915.CI.BAT: " Patchwork
2026-09-16 22:49 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-17 4:13 ` ✓ i915.CI.Full: success " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916115201.1973752-3-piotr.piorkowski@intel.com \
--to=piotr.piorkowski@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox