summaryrefslogtreecommitdiff
path: root/lib/intel_chipset.c
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2019-03-27 20:52:52 +0200
committerVille Syrjälä <ville.syrjala@linux.intel.com>2019-03-29 22:23:27 +0200
commite408d569973b610ba4aafdba016c48b25e563468 (patch)
treee3e1050d63918d053369c7669b62097d501a0451 /lib/intel_chipset.c
parent1ac3264e0370134d06e2cff211c0da4aa5c7d83b (diff)
Revert "lib/igt_device: Move intel_get_pci_device under igt_device"
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 <michal.winiarski@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Acked-by: Jani Nikula <jani.nikula@intel.com> Acked-by: Michał Winiarski <michal.winiarski@intel.com>
Diffstat (limited to 'lib/intel_chipset.c')
-rw-r--r--lib/intel_chipset.c51
1 files changed, 51 insertions, 0 deletions
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
@@ -62,6 +62,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
*