From: Karthik Poosa <karthik.poosa@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com,
riana.tauro@intel.com, rodrigo.vivi@intel.com,
kamil.konieczny@linux.intel.com,
Karthik Poosa <karthik.poosa@intel.com>
Subject: [PATCH i-g-t v10 1/2] lib/igt_device: Add API to get pci device upstream port
Date: Tue, 6 Jan 2026 19:21:53 +0530 [thread overview]
Message-ID: <20260106135154.33722-2-karthik.poosa@intel.com> (raw)
In-Reply-To: <20260106135154.33722-1-karthik.poosa@intel.com>
Add API igt_device_get_pci_upstream_port() to get pci device's
upstream port.
This API returns struct pci_device* of the upstream port that is closest
to the root port within the device's hierarchy.
v2: Avoid igt_require in igt_device_get_pci_usp(). (Kamil)
v3: Rename igt_device_get_pci_usp() to
igt_device_get_pci_upstream_port(). (Kamil)
v4: Use device type from pci express capability of pci config space
to identify upstream port. (Badal)
v5: Search for upstream port only two levels up of the endpoint as we want
to verify ASPM only on PCIe link on which GPU card is present.
v6: Add missing spaces and new lines as per coding guidelines. (Kamil)
Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
Reviewed-by: Badal Nilawar <badal.nilawar@intel.com>
---
lib/igt_device.c | 43 +++++++++++++++++++++++++++++++++++++++++++
lib/igt_device.h | 1 +
lib/igt_pci.h | 2 ++
3 files changed, 46 insertions(+)
diff --git a/lib/igt_device.c b/lib/igt_device.c
index c24f6a58d..c617a98bc 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -32,6 +32,7 @@
#include "igt.h"
#include "igt_device.h"
#include "igt_sysfs.h"
+#include "igt_pci.h"
int __igt_device_set_master(int fd)
{
@@ -308,3 +309,45 @@ void igt_device_get_pci_slot_name(int fd, char *pci_slot_name)
snprintf(pci_slot_name, NAME_MAX, "%04x:%02x:%02x.%01x",
pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
}
+
+/**
+ * igt_device_get_pci_upstream_port:
+ * @fd: fd of the GPU endpoint.
+ *
+ * Looks up for the pci device's upstream port using libpciaccess.
+ *
+ * Returns:
+ * The pci_device of upstream port of the device referenced by fd, NULL on any failures.
+ */
+struct pci_device *
+igt_device_get_pci_upstream_port(int fd)
+{
+ struct pci_device *pci_dev = NULL;
+ uint8_t device_type = 0;
+ int offset = 0;
+ int level = 0;
+
+ pci_dev = __igt_device_get_pci_device(fd, 0);
+ if (!pci_dev) {
+ igt_warn("Couldn't get pci device for fd %d\n", fd);
+ return NULL;
+ }
+
+ for (pci_dev = pci_device_get_parent_bridge(pci_dev); (pci_dev && (level < 2));
+ pci_dev = pci_device_get_parent_bridge(pci_dev), level++) {
+ igt_debug("PCI device %04x:%02x:%02x.%01x\n", pci_dev->domain, pci_dev->bus,
+ pci_dev->dev, pci_dev->func);
+ offset = find_pci_cap_offset(pci_dev, PCI_EXPRESS_CAP_ID);
+ if (offset <= 0) {
+ igt_warn("PCI Express Capability not found\n");
+ return NULL;
+ }
+
+ igt_assert(!pci_device_cfg_read_u8(pci_dev, &device_type,
+ offset + PCI_DEVICE_TYPE_OFFSET));
+ if ((device_type >> 4) == PCI_DEVICE_TYPE_UPSTREAM_PORT)
+ return pci_dev;
+ }
+
+ return NULL;
+}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index dad7bb047..781a72235 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -35,6 +35,7 @@ int igt_device_get_card_index(int fd);
struct pci_device *igt_device_get_pci_device(int fd);
struct pci_device *__igt_device_get_pci_device(int fd, unsigned int vf_id);
struct pci_device *igt_device_get_pci_root_port(int fd);
+struct pci_device *igt_device_get_pci_upstream_port(int fd);
void igt_device_get_pci_slot_name(int fd, char *pci_slot_name);
#endif /* __IGT_DEVICE_H__ */
diff --git a/lib/igt_pci.h b/lib/igt_pci.h
index 92b9cc392..84355e9dd 100644
--- a/lib/igt_pci.h
+++ b/lib/igt_pci.h
@@ -20,6 +20,8 @@ enum pci_cap_id {
PCI_EXPRESS_CAP_ID = 0x10
};
+#define PCI_DEVICE_TYPE_OFFSET 0x2
+#define PCI_DEVICE_TYPE_UPSTREAM_PORT 0x5
#define PCI_SLOT_CAP_OFFSET 0x14
#define PCI_SLOT_PWR_CTRL_PRESENT (1 << 1)
--
2.25.1
next prev parent reply other threads:[~2026-01-06 13:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 13:51 [PATCH i-g-t v10 0/2] tests/intel/xe_pm_residency: Add ASPM Link residency test Karthik Poosa
2026-01-06 13:51 ` Karthik Poosa [this message]
2026-01-06 13:51 ` [PATCH i-g-t v10 2/2] tests/intel/xe_pm_residency: Add subtest for ASPM Link state residency Karthik Poosa
2026-01-07 6:24 ` Riana Tauro
2026-01-06 14:17 ` ✓ Xe.CI.BAT: success for tests/intel/xe_pm_residency: Add ASPM Link residency test Patchwork
2026-01-06 14:42 ` ✓ i915.CI.BAT: " Patchwork
2026-01-06 16:26 ` ✗ Xe.CI.Full: failure " Patchwork
2026-01-06 19:35 ` ✓ i915.CI.Full: success " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2026-01-21 14:57 [PATCH i-g-t v10 0/2] " Karthik Poosa
2026-01-21 14:57 ` [PATCH i-g-t v10 1/2] lib/igt_device: Add API to get pci device upstream port Karthik Poosa
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=20260106135154.33722-2-karthik.poosa@intel.com \
--to=karthik.poosa@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=riana.tauro@intel.com \
--cc=rodrigo.vivi@intel.com \
/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