From e408d569973b610ba4aafdba016c48b25e563468 Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Wed, 27 Mar 2019 20:52:52 +0200 Subject: Revert "lib/igt_device: Move intel_get_pci_device under igt_device" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One significant usecase for intel_reg/etc. is to be able to examine the hardware state *before* loading the driver. If the tool forces the driver to load we've totally lost that capability. This reverts commit 8ae86621d6fff60b6e20c6b0f9b336785c935b0f. Cc: Michał Winiarski Cc: Chris Wilson Signed-off-by: Ville Syrjälä Acked-by: Jani Nikula Acked-by: Michał Winiarski --- lib/intel_chipset.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'lib/intel_chipset.c') diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c index 0577f77a..4748a3fb 100644 --- a/lib/intel_chipset.c +++ b/lib/intel_chipset.c @@ -61,6 +61,57 @@ */ enum pch_type intel_pch; +/** + * intel_get_pci_device: + * + * Looks up the main graphics pci device using libpciaccess. + * + * Returns: + * The pci_device, exits the program on any failures. + */ +struct pci_device * +intel_get_pci_device(void) +{ + struct pci_device *pci_dev; + int error; + + error = pci_system_init(); + igt_fail_on_f(error != 0, + "Couldn't initialize PCI system\n"); + + /* Grab the graphics card. Try the canonical slot first, then + * walk the entire PCI bus for a matching device. */ + pci_dev = pci_device_find_by_slot(0, 0, 2, 0); + if (pci_dev == NULL || pci_dev->vendor_id != 0x8086) { + struct pci_device_iterator *iter; + struct pci_id_match match; + + match.vendor_id = 0x8086; /* Intel */ + match.device_id = PCI_MATCH_ANY; + match.subvendor_id = PCI_MATCH_ANY; + match.subdevice_id = PCI_MATCH_ANY; + + match.device_class = 0x3 << 16; + match.device_class_mask = 0xff << 16; + + match.match_data = 0; + + iter = pci_id_match_iterator_create(&match); + pci_dev = pci_device_next(iter); + pci_iterator_destroy(iter); + } + igt_require_f(pci_dev, "Couldn't find Intel graphics card\n"); + + error = pci_device_probe(pci_dev); + igt_fail_on_f(error != 0, + "Couldn't probe graphics card\n"); + + if (pci_dev->vendor_id != 0x8086) + errx(1, "Graphics card is non-intel"); + + return pci_dev; +} + /** * intel_get_drm_devid: * @fd: open i915 drm file descriptor -- cgit v1.2.3