[igt-dev] [PATCH i-g-t] Revert "lib/igt_device: Move intel_get_pci_device under igt_device"

Ville Syrjala ville.syrjala at linux.intel.com
Wed Mar 27 19:03:37 UTC 2019


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

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 at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 benchmarks/gem_latency.c        |   4 +-
 benchmarks/gem_wsim.c           |   4 +-
 debugger/debug_rdata.c          |   7 +-
 debugger/eudb.c                 |   8 +--
 lib/igt_device.c                | 120 --------------------------------
 lib/igt_device.h                |   1 -
 lib/intel_chipset.c             |  51 ++++++++++++++
 lib/intel_chipset.h             |   1 +
 lib/intel_mmio.c                |   4 +-
 lib/ioctl_wrappers.c            |   5 +-
 lib/ioctl_wrappers.h            |   2 +-
 tests/i915/gem_concurrent_all.c |  12 ++--
 tests/i915/gem_cpu_reloc.c      |   4 +-
 tests/i915/gem_exec_latency.c   |   3 +-
 tests/i915/gem_exec_parse.c     |   4 +-
 tests/i915/gem_mmap.c           |   4 +-
 tests/i915/gem_mmap_gtt.c       |  10 +--
 tests/i915/gem_pwrite.c         |   4 +-
 tests/i915/gem_shrink.c         |   2 +-
 tests/i915/i915_pm_lpsp.c       |   3 +-
 tests/i915/i915_pm_rpm.c        |   4 +-
 tests/kms_flip.c                |   2 +-
 tests/prime_mmap.c              |   4 +-
 tools/intel_audio_dump.c        |   9 +--
 tools/intel_backlight.c         |   8 +--
 tools/intel_display_poller.c    |   8 +--
 tools/intel_forcewaked.c        |  10 +--
 tools/intel_gpu_time.c          |   8 +--
 tools/intel_gtt.c               |   8 +--
 tools/intel_infoframes.c        |   7 +-
 tools/intel_l3_parity.c         |   3 +-
 tools/intel_lid.c               |   9 +--
 tools/intel_panel_fitter.c      |   8 +--
 tools/intel_perf_counters.c     |   3 +-
 tools/intel_reg.c               |  23 +++---
 tools/intel_reg_checker.c       |   8 +--
 tools/intel_watermark.c         |  23 +++---
 37 files changed, 131 insertions(+), 267 deletions(-)

diff --git a/benchmarks/gem_latency.c b/benchmarks/gem_latency.c
index a20bbf8a310e..c3fc4bf0f74c 100644
--- a/benchmarks/gem_latency.c
+++ b/benchmarks/gem_latency.c
@@ -44,8 +44,6 @@
 #include <sys/resource.h>
 #include "drm.h"
 
-#include "igt_device.h"
-
 #define LOCAL_I915_EXEC_FENCE_IN              (1<<16)
 #define LOCAL_I915_EXEC_FENCE_OUT             (1<<17)
 
@@ -458,7 +456,7 @@ static int run(int seconds,
 	if (gen < 6)
 		return IGT_EXIT_SKIP; /* Needs BCS timestamp */
 
-	intel_register_access_init(igt_device_get_pci_device(fd), false, fd);
+	intel_register_access_init(intel_get_pci_device(), false, fd);
 
 	if (gen == 6)
 		timestamp_reg = REG(RCS_TIMESTAMP);
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index 21e2668685c0..afb9644dd7f0 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -41,6 +41,7 @@
 #include <limits.h>
 #include <pthread.h>
 
+
 #include "intel_chipset.h"
 #include "intel_reg.h"
 #include "drm.h"
@@ -49,7 +50,6 @@
 
 #include "intel_io.h"
 #include "igt_aux.h"
-#include "igt_device.h"
 #include "igt_rand.h"
 #include "igt_perf.h"
 #include "sw_sync.h"
@@ -2223,7 +2223,7 @@ static void init_clocks(void)
 	uint32_t rcs_start, rcs_end;
 	double overhead, t;
 
-	intel_register_access_init(igt_device_get_pci_device(fd), false, fd);
+	intel_register_access_init(intel_get_pci_device(), false, fd);
 
 	if (verbose <= 1)
 		return;
diff --git a/debugger/debug_rdata.c b/debugger/debug_rdata.c
index fea950296539..61d82d9e51ad 100644
--- a/debugger/debug_rdata.c
+++ b/debugger/debug_rdata.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "intel_io.h"
+#include "intel_chipset.h"
 
 struct eu_rdata {
 	union {
@@ -132,11 +133,7 @@ find_stuck_threads(void)
 
 int main(int argc, char *argv[]) {
 	struct pci_device *pci_dev;
-	int fd;
-
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
+	pci_dev = intel_get_pci_device();
 
 	intel_register_access_init(pci_dev, 1);
 	find_stuck_threads();
diff --git a/debugger/eudb.c b/debugger/eudb.c
index b5784148664e..866d4b524ed4 100644
--- a/debugger/eudb.c
+++ b/debugger/eudb.c
@@ -42,6 +42,7 @@
 #include "drm.h"
 #include "i915_drm.h"
 #include "drmtest.h"
+#include "intel_chipset.h"
 #include "intel_bufmgr.h"
 #include "intel_io.h"
 #include "intel_batchbuffer.h"
@@ -505,7 +506,7 @@ int main(int argc, char* argv[]) {
 	struct pci_device *pci_dev;
 	volatile uint8_t *scratch = NULL;
 	int bits[64];
-	int devid = -1, opt, fd;
+	int devid = -1, opt;
 
 	while ((opt = getopt(argc, argv, "cdr:pf?h")) != -1) {
 		switch (opt) {
@@ -532,10 +533,7 @@ int main(int argc, char* argv[]) {
 		}
 	}
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
-
+	pci_dev = intel_get_pci_device();
 	if (devid == -1)
 		devid = pci_dev->device_id;
 	if (identify_device(devid)) {
diff --git a/lib/igt_device.c b/lib/igt_device.c
index a2f9bb3afc16..08f39c8b1605 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -26,7 +26,6 @@
 #include <sys/sysmacros.h>
 #include "igt.h"
 #include "igt_device.h"
-#include "igt_sysfs.h"
 
 int __igt_device_set_master(int fd)
 {
@@ -104,122 +103,3 @@ int igt_device_get_card_index(int fd)
 
 	return minor(st.st_rdev);
 }
-
-#define IGT_DEV_PATH_LEN 80
-
-static bool igt_device_is_pci(int fd)
-{
-	char path[IGT_DEV_PATH_LEN];
-	char *subsystem;
-	int sysfs;
-	int len;
-
-	sysfs = igt_sysfs_open(fd);
-	if (sysfs == -1)
-		return false;
-
-	len = readlinkat(sysfs, "device/subsystem", path, sizeof(path) - 1);
-	if (len == -1)
-		return false;
-	path[len] = '\0';
-
-	subsystem = strrchr(path, '/');
-	if (!subsystem)
-		return false;
-
-	return strcmp(subsystem, "/pci") == 0;
-}
-
-struct igt_pci_addr {
-	unsigned int domain;
-	unsigned int bus;
-	unsigned int device;
-	unsigned int function;
-};
-
-static int igt_device_get_pci_addr(int fd, struct igt_pci_addr *pci)
-{
-	char path[IGT_DEV_PATH_LEN];
-	char *buf;
-	int sysfs;
-	int len;
-
-	if (!igt_device_is_pci(fd))
-		return -ENODEV;
-
-	sysfs = igt_sysfs_open(fd);
-	if (sysfs == -1)
-		return -ENOENT;
-
-	len = readlinkat(sysfs, "device", path, sizeof(path) - 1);
-	if (len == -1)
-		return -ENOENT;
-	path[len] = '\0';
-
-	buf = strrchr(path, '/');
-	if (!buf)
-		return -ENOENT;
-
-	if (sscanf(buf, "/%4x:%2x:%2x.%2x",
-		   &pci->domain, &pci->bus,
-		   &pci->device, &pci->function) != 4) {
-		igt_warn("Unable to extract PCI device address from '%s'\n", buf);
-		return -ENOENT;
-	}
-
-	return 0;
-}
-
-static struct pci_device *__igt_device_get_pci_device(int fd)
-{
-	struct igt_pci_addr pci_addr;
-	struct pci_device *pci_dev;
-
-	if (igt_device_get_pci_addr(fd, &pci_addr)) {
-		igt_warn("Unable to find device PCI address\n");
-		return NULL;
-	}
-
-	if (pci_system_init()) {
-		igt_warn("Couldn't initialize PCI system\n");
-		return NULL;
-	}
-
-	pci_dev = pci_device_find_by_slot(pci_addr.domain,
-					  pci_addr.bus,
-					  pci_addr.device,
-					  pci_addr.function);
-	if (!pci_dev) {
-		igt_warn("Couldn't find PCI device %04x:%02x:%02x:%02x\n",
-			 pci_addr.domain, pci_addr.bus,
-			 pci_addr.device, pci_addr.function);
-		return NULL;
-	}
-
-	if (pci_device_probe(pci_dev)) {
-		igt_warn("Couldn't probe PCI device\n");
-		return NULL;
-	}
-
-	return pci_dev;
-}
-
-/**
- * igt_device_get_pci_device:
- *
- * @fd: the device
- *
- * Looks up the main graphics pci device using libpciaccess.
- *
- * Returns:
- * The pci_device, skips the test on any failures.
- */
-struct pci_device *igt_device_get_pci_device(int fd)
-{
-	struct pci_device *pci_dev;
-
-	pci_dev = __igt_device_get_pci_device(fd);
-	igt_require(pci_dev);
-
-	return pci_dev;
-}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index 278ba7a9b380..9d7dc2c392cb 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -32,6 +32,5 @@ int __igt_device_drop_master(int fd);
 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);
 
 #endif /* __IGT_DEVICE_H__ */
diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
index 0577f77a490d..4748a3fb853b 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
diff --git a/lib/intel_chipset.h b/lib/intel_chipset.h
index dd31d3fb6bef..40170b7bf30f 100644
--- a/lib/intel_chipset.h
+++ b/lib/intel_chipset.h
@@ -31,6 +31,7 @@
 #include <pciaccess.h>
 #include <stdbool.h>
 
+struct pci_device *intel_get_pci_device(void);
 uint32_t intel_get_drm_devid(int fd);
 
 struct intel_device_info {
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index f5e0be0ce586..a5458aebabe2 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -112,7 +112,7 @@ intel_mmio_use_dump_file(char *file)
  *
  * Sets up #igt_global_mmio to point at the mmio bar.
  *
- * @pci_dev can be obtained from igt_device_get_pci_device().
+ * @pci_dev can be obtained from intel_get_pci_device().
  */
 void
 intel_mmio_use_pci_bar(struct pci_device *pci_dev)
@@ -162,7 +162,7 @@ release_forcewake_lock(int fd)
  *
  * It also initializes #igt_global_mmio like intel_mmio_use_pci_bar().
  *
- * @pci_dev can be obtained from igt_device_get_pci_device().
+ * @pci_dev can be obtained from intel_get_pci_device().
  */
 int
 intel_register_access_init(struct pci_device *pci_dev, int safe, int fd)
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index a66eb4bc0f4f..39920f8707d2 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -53,7 +53,6 @@
 #include "intel_chipset.h"
 #include "intel_io.h"
 #include "igt_debugfs.h"
-#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "config.h"
 
@@ -1097,9 +1096,9 @@ uint64_t gem_aperture_size(int fd)
  *
  * Returns: The mappable gtt address space size.
  */
-uint64_t gem_mappable_aperture_size(int fd)
+uint64_t gem_mappable_aperture_size(void)
 {
-	struct pci_device *pci_dev = igt_device_get_pci_device(fd);
+	struct pci_device *pci_dev = intel_get_pci_device();
 	int bar;
 
 	if (intel_gen(pci_dev->device_id) < 3)
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index ad93daffcfd5..f0be26080da6 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -136,7 +136,7 @@ uint64_t gem_total_stolen_size(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
 uint64_t gem_global_aperture_size(int fd);
-uint64_t gem_mappable_aperture_size(int fd);
+uint64_t gem_mappable_aperture_size(void);
 bool gem_has_softpin(int fd);
 bool gem_has_exec_fence(int fd);
 
diff --git a/tests/i915/gem_concurrent_all.c b/tests/i915/gem_concurrent_all.c
index f719b0a19a83..6049372d1a61 100644
--- a/tests/i915/gem_concurrent_all.c
+++ b/tests/i915/gem_concurrent_all.c
@@ -1850,7 +1850,7 @@ igt_main
 				 c->name, s->name, "small");
 			igt_subtest_group {
 				igt_fixture {
-					count = num_buffers(gem_mappable_aperture_size(fd)/4,
+					count = num_buffers(gem_mappable_aperture_size()/4,
 							    s, c, CHECK_RAM);
 				}
 				run_modes(name, c, modes, s, count);
@@ -1861,7 +1861,7 @@ igt_main
 				 c->name, s->name, "thrash");
 			igt_subtest_group {
 				igt_fixture {
-					count = num_buffers(gem_mappable_aperture_size(fd),
+					count = num_buffers(gem_mappable_aperture_size(),
 							    s, c, CHECK_RAM);
 				}
 				run_modes(name, c, modes, s, count);
@@ -1893,7 +1893,7 @@ igt_main
 				 c->name, s->name, "shrink");
 			igt_subtest_group {
 				igt_fixture {
-					count = num_buffers(gem_mappable_aperture_size(fd),
+					count = num_buffers(gem_mappable_aperture_size(),
 							    s, c, CHECK_RAM);
 
 					igt_fork_shrink_helper(fd);
@@ -1909,8 +1909,8 @@ igt_main
 				 c->name, s->name, "swap");
 			igt_subtest_group {
 				igt_fixture {
-					if (intel_get_avail_ram_mb() > gem_mappable_aperture_size(fd)/(1024*1024)) {
-						pin_sz = intel_get_avail_ram_mb() - gem_mappable_aperture_size(fd)/(1024*1024);
+					if (intel_get_avail_ram_mb() > gem_mappable_aperture_size()/(1024*1024)) {
+						pin_sz = intel_get_avail_ram_mb() - gem_mappable_aperture_size()/(1024*1024);
 
 						igt_debug("Pinning %lld MiB\n", (long long)pin_sz);
 						pin_sz *= 1024 * 1024;
@@ -1924,7 +1924,7 @@ igt_main
 						igt_require(pinned);
 					}
 
-					count = num_buffers(gem_mappable_aperture_size(fd),
+					count = num_buffers(gem_mappable_aperture_size(),
 							    s, c, CHECK_RAM | CHECK_SWAP);
 				}
 				run_modes(name, c, modes, s, count);
diff --git a/tests/i915/gem_cpu_reloc.c b/tests/i915/gem_cpu_reloc.c
index 17c2fe1155da..47099862853e 100644
--- a/tests/i915/gem_cpu_reloc.c
+++ b/tests/i915/gem_cpu_reloc.c
@@ -283,7 +283,7 @@ igt_main
 		run_test(i915, 1);
 
 	igt_subtest("full") {
-		uint64_t aper_size = gem_mappable_aperture_size(i915);
+		uint64_t aper_size = gem_mappable_aperture_size();
 		unsigned long count = aper_size / 4096 + 1;
 
 		intel_require_memory(count, 4096, CHECK_RAM);
@@ -292,7 +292,7 @@ igt_main
 	}
 
 	igt_subtest("forked") {
-		uint64_t aper_size = gem_mappable_aperture_size(i915);
+		uint64_t aper_size = gem_mappable_aperture_size();
 		unsigned long count = aper_size / 4096 + 1;
 		int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 
diff --git a/tests/i915/gem_exec_latency.c b/tests/i915/gem_exec_latency.c
index f308e0851c86..6dd191ecee21 100644
--- a/tests/i915/gem_exec_latency.c
+++ b/tests/i915/gem_exec_latency.c
@@ -40,7 +40,6 @@
 
 #include "drm.h"
 
-#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "igt_vgem.h"
 #include "igt_dummyload.h"
@@ -680,7 +679,7 @@ igt_main
 		if (ring_size > 1024)
 			ring_size = 1024;
 
-		intel_register_access_init(igt_device_get_pci_device(device), false, device);
+		intel_register_access_init(intel_get_pci_device(), false, device);
 		rcs_clock = clockrate(device, RCS_TIMESTAMP);
 		igt_info("RCS timestamp clock: %.0fKHz, %.1fns\n",
 			 rcs_clock / 1e3, 1e9 / rcs_clock);
diff --git a/tests/i915/gem_exec_parse.c b/tests/i915/gem_exec_parse.c
index d3b848e2a106..62e8d0a51d0b 100644
--- a/tests/i915/gem_exec_parse.c
+++ b/tests/i915/gem_exec_parse.c
@@ -30,8 +30,6 @@
 
 #include <drm.h>
 
-#include "igt_device.h"
-
 #ifndef I915_PARAM_CMD_PARSER_VERSION
 #define I915_PARAM_CMD_PARSER_VERSION       28
 #endif
@@ -532,7 +530,7 @@ igt_main
 #undef REG
 
 		igt_fixture {
-			intel_register_access_init(igt_device_get_pci_device(fd), 0, fd);
+			intel_register_access_init(intel_get_pci_device(), 0, fd);
 		}
 
 		for (int i = 0; i < ARRAY_SIZE(lris); i++) {
diff --git a/tests/i915/gem_mmap.c b/tests/i915/gem_mmap.c
index 227ae7ca742b..1f5348d9133b 100644
--- a/tests/i915/gem_mmap.c
+++ b/tests/i915/gem_mmap.c
@@ -53,10 +53,10 @@ test_huge_bo(int huge)
 
 	switch (huge) {
 	case -1:
-		huge_object_size = gem_mappable_aperture_size(fd) / 2;
+		huge_object_size = gem_mappable_aperture_size() / 2;
 		break;
 	case 0:
-		huge_object_size = gem_mappable_aperture_size(fd) + PAGE_SIZE;
+		huge_object_size = gem_mappable_aperture_size() + PAGE_SIZE;
 		break;
 	case 1:
 		huge_object_size = gem_aperture_size(fd) + PAGE_SIZE;
diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index 639de1902168..58922ee32752 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -562,7 +562,7 @@ test_huge_bo(int fd, int huge, int tiling)
 
 	switch (huge) {
 	case -1:
-		size = gem_mappable_aperture_size(fd) / 2;
+		size = gem_mappable_aperture_size() / 2;
 
 		/* Power of two fence size, natural fence
 		 * alignment, and the guard page at the end
@@ -577,7 +577,7 @@ test_huge_bo(int fd, int huge, int tiling)
 			size /= 2;
 		break;
 	case 0:
-		size = gem_mappable_aperture_size(fd) + PAGE_SIZE;
+		size = gem_mappable_aperture_size() + PAGE_SIZE;
 		break;
 	default:
 		size = gem_global_aperture_size(fd) + PAGE_SIZE;
@@ -658,13 +658,13 @@ test_huge_copy(int fd, int huge, int tiling_a, int tiling_b, int ncpus)
 
 	switch (huge) {
 	case -2:
-		huge_object_size = gem_mappable_aperture_size(fd) / 4;
+		huge_object_size = gem_mappable_aperture_size() / 4;
 		break;
 	case -1:
-		huge_object_size = gem_mappable_aperture_size(fd) / 2;
+		huge_object_size = gem_mappable_aperture_size() / 2;
 		break;
 	case 0:
-		huge_object_size = gem_mappable_aperture_size(fd) + PAGE_SIZE;
+		huge_object_size = gem_mappable_aperture_size() + PAGE_SIZE;
 		break;
 	case 1:
 		huge_object_size = gem_global_aperture_size(fd) + PAGE_SIZE;
diff --git a/tests/i915/gem_pwrite.c b/tests/i915/gem_pwrite.c
index 5cae121a7384..696bd316ab7c 100644
--- a/tests/i915/gem_pwrite.c
+++ b/tests/i915/gem_pwrite.c
@@ -89,7 +89,7 @@ static void test_big_cpu(int fd, int scale, unsigned flags)
 
 	switch (scale) {
 	case 0:
-		size = gem_mappable_aperture_size(fd) + 4096;
+		size = gem_mappable_aperture_size() + 4096;
 		break;
 	case 1:
 		size = gem_global_aperture_size(fd) + 4096;
@@ -151,7 +151,7 @@ static void test_big_gtt(int fd, int scale, unsigned flags)
 	igt_require(gem_mmap__has_wc(fd));
 	switch (scale) {
 	case 0:
-		size = gem_mappable_aperture_size(fd) + 4096;
+		size = gem_mappable_aperture_size() + 4096;
 		break;
 	case 1:
 		size = gem_global_aperture_size(fd) + 4096;
diff --git a/tests/i915/gem_shrink.c b/tests/i915/gem_shrink.c
index f71a1fcb9113..3e8b8f2dcdfd 100644
--- a/tests/i915/gem_shrink.c
+++ b/tests/i915/gem_shrink.c
@@ -413,7 +413,7 @@ igt_main
 		 * we expect the shrinker to start purging objects,
 		 * and possibly fail.
 		 */
-		alloc_size = gem_mappable_aperture_size(fd) / 2;
+		alloc_size = gem_mappable_aperture_size() / 2;
 		num_processes = 1 + (mem_size / (alloc_size >> 20));
 
 		igt_info("Using %d processes and %'lluMiB per process\n",
diff --git a/tests/i915/i915_pm_lpsp.c b/tests/i915/i915_pm_lpsp.c
index 4e7ce399d813..b319dbe9a0b7 100644
--- a/tests/i915/i915_pm_lpsp.c
+++ b/tests/i915/i915_pm_lpsp.c
@@ -30,7 +30,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "igt_device.h"
 
 static bool supports_lpsp(uint32_t devid)
 {
@@ -211,7 +210,7 @@ igt_main
 
 		igt_require(supports_lpsp(devid));
 
-		intel_register_access_init(igt_device_get_pci_device(drm_fd), 0, drm_fd);
+		intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
 
 		kmstest_set_vt_graphics_mode();
 	}
diff --git a/tests/i915/i915_pm_rpm.c b/tests/i915/i915_pm_rpm.c
index 18adaf6b5751..03de609cbfcb 100644
--- a/tests/i915/i915_pm_rpm.c
+++ b/tests/i915/i915_pm_rpm.c
@@ -1368,7 +1368,7 @@ static void gem_evict_pwrite_subtest(void)
 	unsigned int num_trash_bos, n;
 	uint32_t buf;
 
-	num_trash_bos = gem_mappable_aperture_size(drm_fd) / (1024*1024) + 1;
+	num_trash_bos = gem_mappable_aperture_size() / (1024*1024) + 1;
 	trash_bos = malloc(num_trash_bos * sizeof(*trash_bos));
 	igt_assert(trash_bos);
 
@@ -1412,7 +1412,7 @@ static bool device_in_pci_d3(void)
 	uint16_t val;
 	int rc;
 
-	rc = pci_device_cfg_read_u16(igt_device_get_pci_device(drm_fd), &val, 0xd4);
+	rc = pci_device_cfg_read_u16(intel_get_pci_device(), &val, 0xd4);
 	igt_assert_eq(rc, 0);
 
 	igt_debug("%s: PCI D3 state=%d\n", __func__, val & 0x3);
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 6ece1e53bce3..dfa5a69e8f28 100755
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -1224,7 +1224,7 @@ static void run_test_on_crtc_set(struct test_output *o, int *crtc_idxs,
 	/* 256 MB is usually the maximum mappable aperture,
 	 * (make it 4x times that to ensure failure) */
 	if (o->flags & TEST_BO_TOOBIG) {
-		bo_size = 4*gem_mappable_aperture_size(drm_fd);
+		bo_size = 4*gem_mappable_aperture_size();
 		igt_require(bo_size < gem_global_aperture_size(drm_fd));
 	}
 
diff --git a/tests/prime_mmap.c b/tests/prime_mmap.c
index 06a66cab7494..fc985784407b 100644
--- a/tests/prime_mmap.c
+++ b/tests/prime_mmap.c
@@ -447,8 +447,8 @@ test_aperture_limit(void)
 	char *ptr1, *ptr2;
 	uint32_t handle1, handle2;
 	/* Two buffers the sum of which > mappable aperture */
-	uint64_t size1 = (gem_mappable_aperture_size(fd) * 7) / 8;
-	uint64_t size2 = (gem_mappable_aperture_size(fd) * 3) / 8;
+	uint64_t size1 = (gem_mappable_aperture_size() * 7) / 8;
+	uint64_t size2 = (gem_mappable_aperture_size() * 3) / 8;
 
 	handle1 = gem_create(fd, size1);
 	fill_bo(handle1, BO_SIZE);
diff --git a/tools/intel_audio_dump.c b/tools/intel_audio_dump.c
index 350a21d9fa30..90260a2fe007 100644
--- a/tools/intel_audio_dump.c
+++ b/tools/intel_audio_dump.c
@@ -32,7 +32,6 @@
 #include <string.h>
 #include <err.h>
 #include <arpa/inet.h>
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
@@ -2465,12 +2464,8 @@ static void dump_braswell(void)
 int main(int argc, char **argv)
 {
 	struct pci_device *pci_dev;
-	int fd;
-
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
 
+	pci_dev = intel_get_pci_device();
 	devid = pci_dev->device_id; /* XXX not true when mapping! */
 
 	do_self_tests();
@@ -2498,7 +2493,5 @@ int main(int argc, char **argv)
 		dump_eaglelake();
 	}
 
-	close(fd);
-
 	return 0;
 }
diff --git a/tools/intel_backlight.c b/tools/intel_backlight.c
index fc45d9853430..067fd4180968 100644
--- a/tools/intel_backlight.c
+++ b/tools/intel_backlight.c
@@ -30,9 +30,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
+#include "intel_chipset.h"
 #include "intel_reg.h"
 
 /* XXX PCH only today */
@@ -40,11 +39,8 @@
 int main(int argc, char** argv)
 {
 	uint32_t current, max;
-	int fd;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
-	close(fd);
+	intel_mmio_use_pci_bar(intel_get_pci_device());
 
 	current = INREG(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
 	max = INREG(BLC_PWM_PCH_CTL2) >> 16;
diff --git a/tools/intel_display_poller.c b/tools/intel_display_poller.c
index 293574f24aad..51f5b9a58ad1 100644
--- a/tools/intel_display_poller.c
+++ b/tools/intel_display_poller.c
@@ -36,7 +36,6 @@
 #include "intel_io.h"
 #include "intel_reg.h"
 #include "igt_debugfs.h"
-#include "igt_device.h"
 #include "drmtest.h"
 #include "igt_aux.h"
 
@@ -972,7 +971,6 @@ int main(int argc, char *argv[])
 	uint32_t a, b;
 	enum test test = TEST_INVALID;
 	const int count = ARRAY_SIZE(min)/2;
-	int fd;
 
 	for (;;) {
 		static const struct option long_options[] = {
@@ -1048,8 +1046,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	devid = igt_device_get_pci_device(fd)->device_id;
+	devid = intel_get_pci_device()->device_id;
 
 	/*
 	 * check if the requires registers are
@@ -1190,7 +1187,7 @@ int main(int argc, char *argv[])
 		break;
 	}
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	printf("%s?\n", test_name(test, pipe, bit, test_pixelcount));
 
@@ -1266,7 +1263,6 @@ int main(int argc, char *argv[])
 	}
 
 	intel_register_access_fini();
-	close(fd);
 
 	if (quit)
 		return 0;
diff --git a/tools/intel_forcewaked.c b/tools/intel_forcewaked.c
index 7d32337ad273..02fbf8880604 100644
--- a/tools/intel_forcewaked.c
+++ b/tools/intel_forcewaked.c
@@ -34,8 +34,8 @@
 #include <stdlib.h>
 #include <syslog.h>
 #include <unistd.h>
-#include "igt_device.h"
 #include "intel_io.h"
+#include "intel_chipset.h"
 #include "drmtest.h"
 
 bool daemonized;
@@ -65,7 +65,6 @@ is_alive(void) {
 int main(int argc, char *argv[])
 {
 	int ret;
-	int fd;
 
 	if (argc > 2 || (argc == 2 && !strncmp(argv[1], "-h", 2))) {
 		help(argv[1]);
@@ -81,27 +80,24 @@ int main(int argc, char *argv[])
 		INFO_PRINT("started daemon");
 	}
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	ret = intel_register_access_init(igt_device_get_pci_device(fd), 1, -1);
+	ret = intel_register_access_init(intel_get_pci_device(), 1, -1);
 	if (ret) {
 		INFO_PRINT("Couldn't init register access\n");
 		exit(1);
 	} else {
 		INFO_PRINT("Forcewake locked\n");
 	}
-
 	while(1) {
 		if (!is_alive()) {
 			INFO_PRINT("gpu reset? restarting daemon\n");
 			intel_register_access_fini();
-			ret = intel_register_access_init(igt_device_get_pci_device(fd), 1, -1);
+			ret = intel_register_access_init(intel_get_pci_device(), 1, -1);
 			if (ret)
 				INFO_PRINT("Reg access init fail\n");
 		}
 		sleep(1);
 	}
 	intel_register_access_fini();
-	close(fd);
 	INFO_PRINT("Forcewake unlock\n");
 
 	if (daemonized) {
diff --git a/tools/intel_gpu_time.c b/tools/intel_gpu_time.c
index 0fc73f92043d..56d65fe07967 100644
--- a/tools/intel_gpu_time.c
+++ b/tools/intel_gpu_time.c
@@ -34,9 +34,8 @@
 #include <sys/resource.h>
 #include <sys/wait.h>
 
-#include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
+#include "intel_chipset.h"
 #include "intel_reg.h"
 
 #define SAMPLES_PER_SEC             10000
@@ -67,11 +66,8 @@ int main(int argc, char **argv)
 	struct timeval start, end;
 	static struct rusage rusage;
 	int status;
-	int fd;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
-	close(fd);
+	intel_mmio_use_pci_bar(intel_get_pci_device());
 
 	if (argc == 1) {
 		fprintf(stderr, "usage: %s cmd [args...]\n", argv[0]);
diff --git a/tools/intel_gtt.c b/tools/intel_gtt.c
index 5740e794e887..311694baab7a 100644
--- a/tools/intel_gtt.c
+++ b/tools/intel_gtt.c
@@ -34,8 +34,6 @@
 #include <pciaccess.h>
 #include <unistd.h>
 
-#include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 
@@ -142,17 +140,13 @@ int main(int argc, char **argv)
 {
 	struct pci_device *pci_dev;
 	unsigned int start, gtt_size;
-	int fd;
 	int flag[] = {
 		PCI_DEV_MAP_FLAG_WRITE_COMBINE,
 		PCI_DEV_MAP_FLAG_WRITABLE,
 		0
 	}, f;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
-
+	pci_dev = intel_get_pci_device();
 	devid = pci_dev->device_id;
 
 	if (IS_GEN2(devid)) {
diff --git a/tools/intel_infoframes.c b/tools/intel_infoframes.c
index 9129572a2007..2ef5d4fdd020 100644
--- a/tools/intel_infoframes.c
+++ b/tools/intel_infoframes.c
@@ -30,7 +30,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 #include "drmtest.h"
@@ -1082,7 +1081,6 @@ printf("Options:\n"
 int main(int argc, char *argv[])
 {
 	int opt;
-	int fd;
 	int ret = 0;
 	Transcoder transcoder = TRANSC_INVALID;
 	DipType dip = DIP_INVALID;
@@ -1109,10 +1107,7 @@ int main(int argc, char *argv[])
 	printf("WARNING: This is just a debugging tool! Don't expect it to work"
 	       " perfectly: the Kernel might undo our changes.\n");
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
-
+	pci_dev = intel_get_pci_device();
 	intel_register_access_init(pci_dev, 0, -1);
 	intel_check_pch();
 
diff --git a/tools/intel_l3_parity.c b/tools/intel_l3_parity.c
index e2e4503a1244..d8c997af9b97 100644
--- a/tools/intel_l3_parity.c
+++ b/tools/intel_l3_parity.c
@@ -36,7 +36,6 @@
 #include <getopt.h>
 #include "intel_chipset.h"
 #include "intel_io.h"
-#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "drmtest.h"
 #include "config.h"
@@ -190,7 +189,7 @@ int main(int argc, char *argv[])
 	if (intel_gen(devid) < 7 || IS_VALLEYVIEW(devid))
 		exit(77);
 
-	assert(intel_register_access_init(igt_device_get_pci_device(device), 0, device) == 0);
+	assert(intel_register_access_init(intel_get_pci_device(), 0, device) == 0);
 
 	dir = igt_sysfs_open(device);
 
diff --git a/tools/intel_lid.c b/tools/intel_lid.c
index 447790d9c545..37c6ba5e443f 100644
--- a/tools/intel_lid.c
+++ b/tools/intel_lid.c
@@ -37,10 +37,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_reg.h"
+#include "intel_chipset.h"
 
 #define SWF14_LID_STATUS_CLOSED	(1<<29) /* 0 here means open */
 
@@ -119,11 +118,8 @@ out:
 int main(int argc, char **argv)
 {
 	int swf14, acpi_lid;
-	int fd;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
-	close(fd);
+	intel_mmio_use_pci_bar(intel_get_pci_device());
 
 	while (1) {
 		swf14 = INREG(SWF14);
@@ -146,6 +142,5 @@ int main(int argc, char **argv)
 		}
 		sleep(2);
 	}
-
 	return 0;
 }
diff --git a/tools/intel_panel_fitter.c b/tools/intel_panel_fitter.c
index 06f4ac596f5c..137ef61abe59 100644
--- a/tools/intel_panel_fitter.c
+++ b/tools/intel_panel_fitter.c
@@ -30,7 +30,6 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 #include "intel_reg.h"
@@ -274,17 +273,13 @@ int main (int argc, char *argv[])
 	bool do_disable = false, do_dump = false, do_usage = false;
 	struct pci_device *pci_dev;
 	uint32_t devid;
-	int fd;
 
 	printf("WARNING:\n"
 	       "This tool is a workaround for people that don't have a Kernel "
 	       "with overscan compensation properties: it is just a temporary "
 	       "solution that may or may not work. Use it at your own risk.\n");
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	pci_dev = igt_device_get_pci_device(fd);
-	close(fd);
-
+	pci_dev = intel_get_pci_device();
 	intel_register_access_init(pci_dev, 0, -1);
 	devid = pci_dev->device_id;
 
@@ -348,6 +343,5 @@ int main (int argc, char *argv[])
 
 out:
 	intel_register_access_fini();
-
 	return ret;
 }
diff --git a/tools/intel_perf_counters.c b/tools/intel_perf_counters.c
index 105a0924f6dc..50c4bce61ff7 100644
--- a/tools/intel_perf_counters.c
+++ b/tools/intel_perf_counters.c
@@ -45,7 +45,6 @@
 #include "drm.h"
 #include "i915_drm.h"
 #include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
@@ -484,7 +483,7 @@ main(int argc, char **argv)
 
 	if (oacontrol) {
 		/* Forcewake */
-		intel_register_access_init(igt_device_get_pci_device(fd), 0, fd);
+		intel_register_access_init(intel_get_pci_device(), 0, fd);
 
 		/* Enable performance counters */
 		intel_register_write(OACONTROL,
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index 305323b603d8..1247b70b0927 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -33,9 +33,9 @@
 #include <unistd.h>
 
 #include "igt.h"
-#include "igt_device.h"
 #include "igt_gt.h"
 #include "intel_io.h"
+#include "intel_chipset.h"
 
 #include "intel_reg_spec.h"
 
@@ -274,6 +274,15 @@ static int register_srm(struct config *config, struct reg *reg,
 	int fd, i;
 	uint32_t val;
 
+	if (config->fd == -1) {
+		config->fd = __drm_open_driver(DRIVER_INTEL);
+		if (config->fd == -1) {
+			fprintf(stderr, "Error opening driver: %s",
+				strerror(errno));
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	fd = config->fd;
 	engine = find_engine(reg->engine);
 	if (engine == NULL)
@@ -1006,13 +1015,6 @@ int main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	config.fd = __drm_open_driver(DRIVER_INTEL);
-	if (config.fd == -1) {
-		fprintf(stderr, "Error opening driver: %s",
-			strerror(errno));
-		exit(EXIT_FAILURE);
-	}
-
 	if (config.mmiofile) {
 		if (!config.devid) {
 			fprintf(stderr, "--mmio requires --devid\n");
@@ -1024,7 +1026,7 @@ int main(int argc, char *argv[])
 			fprintf(stderr, "--devid without --mmio\n");
 			return EXIT_FAILURE;
 		}
-		config.pci_dev = igt_device_get_pci_device(config.fd);
+		config.pci_dev = intel_get_pci_device();
 		config.devid = config.pci_dev->device_id;
 	}
 
@@ -1048,7 +1050,8 @@ int main(int argc, char *argv[])
 
 	free(config.mmiofile);
 
-	close(config.fd);
+	if (config.fd >= 0)
+		close(config.fd);
 
 	return ret;
 }
diff --git a/tools/intel_reg_checker.c b/tools/intel_reg_checker.c
index 0ed26029c72f..6bde63ecee22 100644
--- a/tools/intel_reg_checker.c
+++ b/tools/intel_reg_checker.c
@@ -26,8 +26,6 @@
 #include <err.h>
 #include <string.h>
 #include <stdbool.h>
-#include "drmtest.h"
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 
@@ -344,12 +342,8 @@ check_dpfc_control_sa(void)
 int main(int argc, char** argv)
 {
 	struct pci_device *dev;
-	int fd;
-
-	fd = drm_open_driver(DRIVER_INTEL);
-	dev = igt_device_get_pci_device(fd);
-	close(fd);
 
+	dev = intel_get_pci_device();
 	devid = dev->device_id;
 	intel_mmio_use_pci_bar(dev);
 
diff --git a/tools/intel_watermark.c b/tools/intel_watermark.c
index 2dc4307c33a3..e71c3d9cff6d 100644
--- a/tools/intel_watermark.c
+++ b/tools/intel_watermark.c
@@ -29,14 +29,12 @@
 #include <stdbool.h>
 #include <err.h>
 #include <string.h>
-#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 #include "drmtest.h"
 
 static uint32_t display_base;
 static uint32_t devid;
-static int fd;
 
 static uint32_t read_reg(uint32_t addr)
 {
@@ -251,7 +249,7 @@ static void skl_wm_dump(void)
 	uint32_t plane_ctl[num_pipes][max_planes];
 	uint32_t wm_linetime[num_pipes];
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	for (pipe = 0; pipe < num_pipes; pipe++) {
 		int num_planes = skl_num_planes(devid, pipe);
@@ -471,7 +469,7 @@ static void ilk_wm_dump(void)
 	int num_pipes = intel_gen(devid) >= 7 ? 3 : 2;
 	struct ilk_wm wm = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	for (i = 0; i < num_pipes; i++) {
 		dspcntr[i] = read_reg(0x70180 + i * 0x1000);
@@ -621,7 +619,7 @@ static void vlv_wm_dump(void)
 	uint32_t dsp_ss_pm, ddr_setup2;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	dsparb2 = read_reg(0x70060);
@@ -837,7 +835,7 @@ static void g4x_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dspacntr = read_reg(0x70180);
 	dspbcntr = read_reg(0x71180);
@@ -923,7 +921,7 @@ static void gen4_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	fw1 = read_reg(0x70034);
@@ -994,7 +992,7 @@ static void pnv_wm_dump(void)
 	uint32_t cbr;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	fw1 = read_reg(0x70034);
@@ -1084,7 +1082,7 @@ static void gen3_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	instpm = read_reg(0x20c0);
@@ -1153,7 +1151,7 @@ static void gen2_wm_dump(void)
 	uint32_t mi_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
+	intel_register_access_init(intel_get_pci_device(), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	mem_mode = read_reg(0x20cc);
@@ -1228,8 +1226,7 @@ static void gen2_wm_dump(void)
 
 int main(int argc, char *argv[])
 {
-	fd = drm_open_driver(DRIVER_INTEL);
-	devid = igt_device_get_pci_device(fd)->device_id;
+	devid = intel_get_pci_device()->device_id;
 
 	if (intel_gen(devid) >= 9) {
 		skl_wm_dump();
@@ -1253,7 +1250,5 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
-	close(fd);
-
 	return 0;
 }
-- 
2.19.2



More information about the igt-dev mailing list