From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id B12F4112B59 for ; Tue, 17 May 2022 13:31:31 +0000 (UTC) From: Anshuman Gupta To: igt-dev@lists.freedesktop.org Date: Tue, 17 May 2022 19:01:08 +0530 Message-Id: <20220517133112.25507-3-anshuman.gupta@intel.com> In-Reply-To: <20220517133112.25507-1-anshuman.gupta@intel.com> References: <20220517133112.25507-1-anshuman.gupta@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t 2/6] lib/igt_device: Get gfx PCI card root port List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: petri.latvala@intel.com, badal.nilawar@intel.com, rodrigo.vivi@intel.com Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: 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 Signed-off-by: Anshuman Gupta Reviewed-by: Rodrigo Vivi --- lib/igt_device.c | 28 ++++++++++++++++++++++++++++ lib/igt_device.h | 1 + 2 files changed, 29 insertions(+) diff --git a/lib/igt_device.c b/lib/igt_device.c index 9794a9928f..fddfba72cd 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 1aaa840e25..800a0fcc3c 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__ */ -- 2.26.2