summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnshuman Gupta <anshuman.gupta@intel.com>2022-05-17 19:01:08 +0530
committerAshutosh Dixit <ashutosh.dixit@intel.com>2022-05-18 09:28:41 -0700
commit9dd9be530386093c30b3da80093a6887876040ec (patch)
tree2d680ca3cf5b443f5c1d06bf23a8fd0af03f6655 /lib
parentf8e20496602d57b8b62c22261af0615114c544f3 (diff)
lib/igt_device: Get gfx PCI card root port
Utility library function to get the Gfx Card PCI topology root port pci device using libpaciaccess. root port will be used to get the real ACPI D state. Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_device.c28
-rw-r--r--lib/igt_device.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/igt_device.c b/lib/igt_device.c
index 9794a992..fddfba72 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -257,3 +257,31 @@ struct pci_device *igt_device_get_pci_device(int fd)
return pci_dev;
}
+
+/**
+ * igt_device_get_pci_root_port:
+ * @fd: the device.
+ *
+ * Looks up the graphics pci device root port using libpciaccess.
+ *
+ * Returns:
+ * The root port pci_device.
+ */
+struct pci_device *
+igt_device_get_pci_root_port(int fd)
+{
+ struct pci_device *pci_dev, *prev;
+
+ pci_dev = __igt_device_get_pci_device(fd, 0);
+ igt_require(pci_dev);
+
+ while (pci_dev) {
+ prev = pci_dev;
+ pci_dev = pci_device_get_parent_bridge(pci_dev);
+ }
+
+ igt_debug("Root Port PCI device %04x:%02x:%02x.%01x\n",
+ prev->domain, prev->bus, prev->dev, prev->func);
+
+ return prev;
+}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index 1aaa840e..800a0fcc 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -34,5 +34,6 @@ void igt_device_drop_master(int fd);
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);
#endif /* __IGT_DEVICE_H__ */