All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs
@ 2019-03-13 17:38 Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

The "benchmark" mode is no longer used.
While I'm here, let's also move things around and start to use
igt_sysfs, rather implementing own set of helpers.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_exec_blt.c | 117 ++++++++++++--------------------------
 1 file changed, 35 insertions(+), 82 deletions(-)

diff --git a/tests/i915/gem_exec_blt.c b/tests/i915/gem_exec_blt.c
index 8d61dc87..0fcfdd4b 100644
--- a/tests/i915/gem_exec_blt.c
+++ b/tests/i915/gem_exec_blt.c
@@ -38,6 +38,7 @@
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include "drm.h"
+#include "igt_sysfs.h"
 
 #define OBJECT_SIZE 16384
 
@@ -181,19 +182,16 @@ static int dcmp(const void *A, const void *B)
 		return 0;
 }
 
-static void run(int object_size, bool dumb)
+static void run(int fd, int object_size, bool dumb)
 {
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 exec[3];
 	struct drm_i915_gem_relocation_entry reloc[4];
 	uint32_t buf[20];
 	uint32_t handle, src, dst;
-	int fd, len, count;
+	int len, count;
 	int ring;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	igt_require_gem(fd);
-
 	if (dumb)
 		handle = kmstest_dumb_create(fd, 32, 32, 32, NULL, NULL);
 	else
@@ -262,81 +260,36 @@ static void run(int object_size, bool dumb)
 		fflush(stdout);
 	}
 	gem_close(fd, handle);
-
-	close(fd);
-}
-
-static int sysfs_read(const char *name)
-{
-	char buf[4096];
-	int sysfd;
-	int len;
-
-	sprintf(buf, "/sys/class/drm/card%d/%s",
-		drm_get_card(), name);
-	sysfd = open(buf, O_RDONLY);
-	if (sysfd < 0)
-		return -1;
-
-	len = read(sysfd, buf, sizeof(buf)-1);
-	close(sysfd);
-	if (len < 0)
-		return -1;
-
-	buf[len] = '\0';
-	return atoi(buf);
-}
-
-static int sysfs_write(const char *name, int value)
-{
-	char buf[4096];
-	int sysfd;
-	int len;
-
-	sprintf(buf, "/sys/class/drm/card%d/%s",
-		drm_get_card(), name);
-	sysfd = open(buf, O_WRONLY);
-	if (sysfd < 0)
-		return -1;
-
-	len = sprintf(buf, "%d", value);
-	len = write(sysfd, buf, len);
-	close(sysfd);
-
-	if (len < 0)
-		return len;
-
-	return 0;
 }
 
-static void set_auto_freq(void)
+static void set_auto_freq(int sysfs)
 {
-	int min = sysfs_read("gt_RPn_freq_mhz");
-	int max = sysfs_read("gt_RP0_freq_mhz");
+	int min = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
+	int max = igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz");
 	if (max <= min)
 		return;
 
 	igt_debug("Setting min to %dMHz, and max to %dMHz\n", min, max);
-	sysfs_write("gt_min_freq_mhz", min);
-	sysfs_write("gt_max_freq_mhz", max);
+	igt_sysfs_set_u32(sysfs, "gt_min_freq_mhz", min);
+	igt_sysfs_set_u32(sysfs, "gt_max_freq_mhz", max);
 }
 
-static void set_min_freq(void)
+static void set_min_freq(int sysfs)
 {
-	int min = sysfs_read("gt_RPn_freq_mhz");
+	int min = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
 	igt_require(min > 0);
 	igt_debug("Setting min/max to %dMHz\n", min);
-	igt_require(sysfs_write("gt_min_freq_mhz", min) == 0 &&
-		    sysfs_write("gt_max_freq_mhz", min) == 0);
+	igt_require(igt_sysfs_set_u32(sysfs, "gt_min_freq_mhz", min) &&
+		    igt_sysfs_set_u32(sysfs, "gt_max_freq_mhz", min));
 }
 
-static void set_max_freq(void)
+static void set_max_freq(int sysfs)
 {
-	int max = sysfs_read("gt_RP0_freq_mhz");
+	int max = igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz");
 	igt_require(max > 0);
 	igt_debug("Setting min/max to %dMHz\n", max);
-	igt_require(sysfs_write("gt_max_freq_mhz", max) == 0 &&
-		    sysfs_write("gt_min_freq_mhz", max) == 0);
+	igt_require(igt_sysfs_set_u32(sysfs, "gt_max_freq_mhz", max) &&
+		    igt_sysfs_set_u32(sysfs, "gt_min_freq_mhz", max));
 }
 
 
@@ -344,7 +297,7 @@ int main(int argc, char **argv)
 {
 	const struct {
 		const char *suffix;
-		void (*func)(void);
+		void (*func)(int);
 	} rps[] = {
 		{ "", set_auto_freq },
 		{ "-min", set_min_freq },
@@ -352,44 +305,44 @@ int main(int argc, char **argv)
 		{ NULL, NULL },
 	}, *r;
 	int min = -1, max = -1;
-	int i;
+	int fd, sysfs;
 
 	igt_subtest_init(argc, argv);
 
 	igt_skip_on_simulation();
 
-	if (argc > 1) {
-		for (i = 1; i < argc; i++) {
-			int object_size = atoi(argv[i]);
-			if (object_size)
-				run((object_size + 3) & -4, false);
-		}
-		_exit(0); /* blergh */
-	}
-
 	igt_fixture {
-		min = sysfs_read("gt_min_freq_mhz");
-		max = sysfs_read("gt_max_freq_mhz");
+		fd = drm_open_driver(DRIVER_INTEL);
+		igt_require_gem(fd);
+
+		sysfs = igt_sysfs_open(fd, NULL);
+		igt_require(sysfs >= 0);
+
+		min = igt_sysfs_get_u32(sysfs, "gt_min_freq_mhz");
+		max = igt_sysfs_get_u32(sysfs, "gt_max_freq_mhz");
 	}
 
 	for (r = rps; r->suffix; r++) {
-		igt_fixture r->func();
+		igt_fixture r->func(sysfs);
 
 		igt_subtest_f("cold%s", r->suffix)
-			run(OBJECT_SIZE, false);
+			run(fd, OBJECT_SIZE, false);
 
 		igt_subtest_f("normal%s", r->suffix)
-			run(OBJECT_SIZE, false);
+			run(fd, OBJECT_SIZE, false);
 
 		igt_subtest_f("dumb-buf%s", r->suffix)
-			run(OBJECT_SIZE, true);
+			run(fd, OBJECT_SIZE, true);
 	}
 
 	igt_fixture {
 		if (min > 0)
-			sysfs_write("gt_min_freq_mhz", min);
+			igt_sysfs_set_u32(sysfs, "gt_min_freq_mhz", min);
 		if (max > 0)
-			sysfs_write("gt_max_freq_mhz", max);
+			igt_sysfs_set_u32(sysfs, "gt_max_freq_mhz", max);
+
+		close(sysfs);
+		close(fd);
 	}
 
 	igt_exit();
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:55   ` Chris Wilson
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 3/8] tests/i915_pm_rps: Use " Michał Winiarski
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

Doing this lets us avoid drm_get_card, which we plan to remove
eventually.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/perf.c | 82 +++++++++++++++++++---------------------------------
 1 file changed, 30 insertions(+), 52 deletions(-)

diff --git a/tests/perf.c b/tests/perf.c
index 220c52ef..ecbadfcd 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -185,7 +185,6 @@ static int sysfs = -1;
 static int pm_fd = -1;
 static int stream_fd = -1;
 static uint32_t devid;
-static int card = -1;
 static int n_eus;
 
 static uint64_t test_metric_set_id = UINT64_MAX;
@@ -259,63 +258,47 @@ lookup_format(int i915_perf_fmt_id)
 	return i915_perf_fmt_id;
 }
 
-static bool
-try_read_u64_file(const char *file, uint64_t *val)
-{
-	char buf[32];
-	int fd, n;
-
-	fd = open(file, O_RDONLY);
-	if (fd < 0)
-		return false;
-
-	while ((n = read(fd, buf, sizeof(buf) - 1)) < 0 && errno == EINTR)
-		;
-	igt_assert(n >= 0);
-
-	close(fd);
-
-	buf[n] = '\0';
-	*val = strtoull(buf, NULL, 0);
-
-	return true;
-}
-
 static uint64_t
-read_u64_file(const char *file)
+read_u64_file(const char *path)
 {
+	FILE *f;
 	uint64_t val;
 
-	igt_assert_eq(try_read_u64_file(file, &val), true);
+	f = fopen(path, "r");
+	igt_assert(f);
+
+	igt_assert_eq(fscanf(f, "%"PRIu64, &val), 1);
+
+	fclose(f);
 
 	return val;
 }
 
 static void
-write_u64_file(const char *file, uint64_t val)
+write_u64_file(const char *path, uint64_t val)
 {
-	char buf[32];
-	int fd, len, ret;
+	FILE *f;
 
-	fd = open(file, O_WRONLY);
-	igt_assert(fd >= 0);
+	f = fopen(path, "r");
+	igt_assert(f);
 
-	len = snprintf(buf, sizeof(buf), "%"PRIu64, val);
-	igt_assert(len > 0);
+	igt_assert(fprintf(f, "%"PRIu64, val) > 0);
 
-	while ((ret = write(fd, buf, len)) < 0 && errno == EINTR)
-		;
-	igt_assert_eq(ret, len);
+	fclose(f);
+}
 
-	close(fd);
+static bool
+try_sysfs_read_u64(const char *path, uint64_t *val)
+{
+	return igt_sysfs_scanf(sysfs, path, "%"PRIu64, val) == 1;
 }
 
 static unsigned long
-sysfs_read(const char *file)
+sysfs_read(const char *path)
 {
 	unsigned long value;
 
-	igt_assert(igt_sysfs_scanf(sysfs, file, "%lu", &value) == 1);
+	igt_assert(igt_sysfs_scanf(sysfs, path, "%lu", &value) == 1);
 
 	return value;
 }
@@ -876,7 +859,6 @@ init_sys_info(void)
 	const char *test_set_uuid = NULL;
 	char buf[256];
 
-	igt_assert_neq(card, -1);
 	igt_assert_neq(devid, 0);
 
 	timestamp_frequency = get_cs_timestamp_frequency();
@@ -979,12 +961,9 @@ init_sys_info(void)
 
 	oa_exp_1_millisec = max_oa_exponent_for_period_lte(1000000);
 
-	snprintf(buf, sizeof(buf),
-		 "/sys/class/drm/card%d/metrics/%s/id",
-		 card,
-		 test_set_uuid);
+	snprintf(buf, sizeof(buf), "metrics/%s/id", test_set_uuid);
 
-	return try_read_u64_file(buf, &test_metric_set_id);
+	return try_sysfs_read_u64(buf, &test_metric_set_id);
 }
 
 static int
@@ -3739,10 +3718,10 @@ test_invalid_remove_userspace_config(void)
 
 	igt_require(has_i915_perf_userspace_config(drm_fd));
 
-	snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+	snprintf(path, sizeof(path), "metrics/%s/id", uuid);
 
 	/* Destroy previous configuration if present */
-	if (try_read_u64_file(path, &config_id))
+	if (try_sysfs_read_u64(path, &config_id))
 		i915_perf_remove_config(drm_fd, config_id);
 
 	memset(&config, 0, sizeof(config));
@@ -3799,10 +3778,10 @@ test_create_destroy_userspace_config(void)
 
 	igt_require(has_i915_perf_userspace_config(drm_fd));
 
-	snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+	snprintf(path, sizeof(path), "metrics/%s/id", uuid);
 
 	/* Destroy previous configuration if present */
-	if (try_read_u64_file(path, &config_id))
+	if (try_sysfs_read_u64(path, &config_id))
 		i915_perf_remove_config(drm_fd, config_id);
 
 	memset(&config, 0, sizeof(config));
@@ -3881,9 +3860,9 @@ test_whitelisted_registers_userspace_config(void)
 
 	igt_require(has_i915_perf_userspace_config(drm_fd));
 
-	snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+	snprintf(path, sizeof(path), "metrics/%s/id", uuid);
 
-	if (try_read_u64_file(path, &config_id))
+	if (try_sysfs_read_u64(path, &config_id))
 		i915_perf_remove_config(drm_fd, config_id);
 
 	memset(&config, 0, sizeof(config));
@@ -4034,7 +4013,6 @@ test_i915_ref_count(void)
 
 	drm_fd = __drm_open_driver(DRIVER_INTEL);
 	devid = intel_get_drm_devid(drm_fd);
-	card = drm_get_card();
 
 	/* Note: these global variables are only initialized after calling
 	 * init_sys_info()...
@@ -4111,7 +4089,7 @@ igt_main
 		igt_require_gem(drm_fd);
 
 		devid = intel_get_drm_devid(drm_fd);
-		sysfs = igt_sysfs_open(drm_fd, &card);
+		sysfs = igt_sysfs_open(drm_fd, NULL);
 
 		igt_require(init_sys_info());
 
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 3/8] tests/i915_pm_rps: Use sysfs helpers
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 4/8] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

Doing this lets us avoid drm_get_card, which we plan to remove
eventually.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/i915_pm_rps.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/i915/i915_pm_rps.c b/tests/i915/i915_pm_rps.c
index d20cd2d8..41dc9bbb 100644
--- a/tests/i915/i915_pm_rps.c
+++ b/tests/i915/i915_pm_rps.c
@@ -38,12 +38,12 @@
 
 #include "igt.h"
 #include "igt_dummyload.h"
+#include "igt_sysfs.h"
 
 IGT_TEST_DESCRIPTION("Render P-States tests - verify GPU frequency changes");
 
 static int drm_fd;
 
-static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz";
 enum {
 	CUR,
 	MIN,
@@ -629,20 +629,23 @@ igt_main
 	igt_skip_on_simulation();
 
 	igt_fixture {
-		const int device = drm_get_card();
 		struct sysfs_file *sysfs_file = sysfs_files;
+		char sysfs_path[80];
 		int ret;
 
 		/* Use drm_open_driver to verify device existence */
 		drm_fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(drm_fd);
 		igt_require(gem_can_store_dword(drm_fd, 0));
+		igt_assert(igt_sysfs_path(drm_fd, sysfs_path,
+					  sizeof(sysfs_path), NULL));
 
 		do {
 			int val = -1;
 			char *path;
 
-			ret = asprintf(&path, sysfs_base_path, device, sysfs_file->name);
+			ret = asprintf(&path, "gt_%s_freq_mhz",
+				       sysfs_file->name);
 			igt_assert(ret != -1);
 			sysfs_file->filp = fopen(path, sysfs_file->mode);
 			igt_require(sysfs_file->filp);
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 4/8] lib/igt_device: Introduce igt_device_get_card_index
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 3/8] tests/i915_pm_rps: Use " Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 5/8] lib: Kill drm_get_card() Michał Winiarski
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

And use it! But let's start small.
Rather than going with "and by the way, here's the card index" from
igt_sysfs_path, we're making things more explicit.

v2: Drop idx comment. (Chris)

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_device.c         | 19 +++++++++++++++++++
 lib/igt_device.h         |  2 ++
 lib/igt_sysfs.c          | 12 +++++++-----
 lib/igt_sysfs.h          |  2 +-
 tests/i915/i915_pm_rpm.c |  2 +-
 tests/i915/i915_pm_rps.c |  2 +-
 6 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/lib/igt_device.c b/lib/igt_device.c
index 5b3722c8..08f39c8b 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -22,6 +22,8 @@
  *
  */
 
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
 #include "igt.h"
 #include "igt_device.h"
 
@@ -84,3 +86,20 @@ void igt_device_drop_master(int fd)
 			      "Failed to drop DRM master.\n");
 	}
 }
+
+/**
+ * igt_device_get_card_index:
+ * @fd: the device
+ *
+ * Returns:
+ * Index (N) of /dev/dri/cardN or /dev/dri/renderDN corresponding with fd.
+ *
+ */
+int igt_device_get_card_index(int fd)
+{
+	struct stat st;
+
+	igt_fail_on(fstat(fd, &st) || !S_ISCHR(st.st_mode));
+
+	return minor(st.st_rdev);
+}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index 2995f969..9d7dc2c3 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -31,4 +31,6 @@ void igt_device_set_master(int fd);
 int __igt_device_drop_master(int fd);
 void igt_device_drop_master(int fd);
 
+int igt_device_get_card_index(int fd);
+
 #endif /* __IGT_DEVICE_H__ */
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index c57e4ae2..5a25d579 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -41,6 +41,7 @@
 
 #include "igt_core.h"
 #include "igt_sysfs.h"
+#include "igt_device.h"
 
 /**
  * SECTION:igt_sysfs
@@ -89,14 +90,13 @@ static int writeN(int fd, const char *buf, int len)
  * @device: fd of the device
  * @path: buffer to fill with the sysfs path to the device
  * @pathlen: length of @path buffer
- * @idx: optional pointer to store the card index of the opened device
  *
  * This finds the sysfs directory corresponding to @device.
  *
  * Returns:
  * The directory path, or NULL on failure.
  */
-char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
+char *igt_sysfs_path(int device, char *path, int pathlen)
 {
 	struct stat st;
 
@@ -125,8 +125,7 @@ char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
 			continue;
 
 		path[len] = '\0';
-		if (idx)
-			*idx = n;
+
 		return path;
 	}
 
@@ -148,9 +147,12 @@ int igt_sysfs_open(int device, int *idx)
 {
 	char path[80];
 
-	if (!igt_sysfs_path(device, path, sizeof(path), idx))
+	if (!igt_sysfs_path(device, path, sizeof(path)))
 		return -1;
 
+	if (idx)
+		*idx = igt_device_get_card_index(device);
+
 	return open(path, O_RDONLY);
 }
 
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 2ce5b7bd..b181a95f 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -28,7 +28,7 @@
 #include <stdbool.h>
 #include <stdarg.h>
 
-char *igt_sysfs_path(int device, char *path, int pathlen, int *idx);
+char *igt_sysfs_path(int device, char *path, int pathlen);
 int igt_sysfs_open(int device, int *idx);
 int igt_sysfs_open_parameters(int device);
 bool igt_sysfs_set_parameter(int device,
diff --git a/tests/i915/i915_pm_rpm.c b/tests/i915/i915_pm_rpm.c
index 759c76ea..03de609c 100644
--- a/tests/i915/i915_pm_rpm.c
+++ b/tests/i915/i915_pm_rpm.c
@@ -962,7 +962,7 @@ static void sysfs_read_subtest(void)
 {
 	char path[80];
 
-	igt_require_f(igt_sysfs_path(drm_fd, path, sizeof(path), NULL),
+	igt_require_f(igt_sysfs_path(drm_fd, path, sizeof(path)),
 		      "Can't find the sysfs directory\n");
 	walk_fs(path);
 }
diff --git a/tests/i915/i915_pm_rps.c b/tests/i915/i915_pm_rps.c
index 41dc9bbb..8ad4401b 100644
--- a/tests/i915/i915_pm_rps.c
+++ b/tests/i915/i915_pm_rps.c
@@ -638,7 +638,7 @@ igt_main
 		igt_require_gem(drm_fd);
 		igt_require(gem_can_store_dword(drm_fd, 0));
 		igt_assert(igt_sysfs_path(drm_fd, sysfs_path,
-					  sizeof(sysfs_path), NULL));
+					  sizeof(sysfs_path)));
 
 		do {
 			int val = -1;
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 5/8] lib: Kill drm_get_card()
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
                   ` (2 preceding siblings ...)
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 4/8] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 6/8] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

It's not operating on FD, and we've provided a nice reimplementation
that does. Let's use it instead.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/drmtest.c               | 40 -------------------------------------
 lib/drmtest.h               |  1 -
 tests/i915/i915_suspend.c   | 17 ++++++++--------
 tools/intel_gpu_frequency.c |  9 ++++++---
 4 files changed, 15 insertions(+), 52 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 6506791b..25eeab88 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -177,46 +177,6 @@ void gem_quiescent_gpu(int fd)
 			    DROP_ACTIVE | DROP_RETIRE | DROP_IDLE | DROP_FREED);
 }
 
-/**
- * drm_get_card:
- *
- * Get an i915 drm card index number for use in /dev or /sys. The minor index of
- * the legacy node is returned, not of the control or render node.
- *
- * Returns:
- * The i915 drm index or -1 on error
- */
-int drm_get_card(void)
-{
-	char *name;
-	int i, fd;
-
-	for (i = 0; i < 16; i++) {
-		int ret;
-
-		ret = asprintf(&name, "/dev/dri/card%u", i);
-		igt_assert(ret != -1);
-
-		fd = open(name, O_RDWR);
-		free(name);
-
-		if (fd == -1)
-			continue;
-
-		if (!is_i915_device(fd) || !has_known_intel_chipset(fd)) {
-			close(fd);
-			continue;
-		}
-
-		close(fd);
-		return i;
-	}
-
-	igt_skip("No intel gpu found\n");
-
-	return -1;
-}
-
 static int modprobe(const char *driver)
 {
 	return igt_kmod_load(driver, "");
diff --git a/lib/drmtest.h b/lib/drmtest.h
index ca347a71..f4401ac9 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -71,7 +71,6 @@ void __set_forced_driver(const char *name);
  */
 #define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1))
 
-int drm_get_card(void);
 int drm_open_driver(int chipset);
 int drm_open_driver_master(int chipset);
 int drm_open_driver_render(int chipset);
diff --git a/tests/i915/i915_suspend.c b/tests/i915/i915_suspend.c
index cd7cf967..0d49fdcb 100644
--- a/tests/i915/i915_suspend.c
+++ b/tests/i915/i915_suspend.c
@@ -39,6 +39,7 @@
 
 #include <drm.h>
 
+#include "igt_device.h"
 
 #define OBJECT_SIZE (16*1024*1024)
 
@@ -101,7 +102,7 @@ test_fence_restore(int fd, bool tiled2untiled, bool hibernate)
 }
 
 static void
-test_debugfs_reader(bool hibernate)
+test_debugfs_reader(int fd, bool hibernate)
 {
 	struct igt_helper_process reader = {};
 	reader.use_SIGKILL = true;
@@ -112,7 +113,7 @@ test_debugfs_reader(bool hibernate)
 
 		snprintf(tmp, sizeof(tmp) - 1,
 			 "while true; do find %s/%i/ -type f ! -path \"*/crc/*\" | xargs cat > /dev/null 2>&1; done",
-			 dfs_base, drm_get_card());
+			 dfs_base, igt_device_get_card_index(fd));
 		igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
 	}
 
@@ -131,7 +132,7 @@ test_debugfs_reader(bool hibernate)
 }
 
 static void
-test_sysfs_reader(bool hibernate)
+test_sysfs_reader(int fd, bool hibernate)
 {
 	struct igt_helper_process reader = {};
 	reader.use_SIGKILL = true;
@@ -142,7 +143,7 @@ test_sysfs_reader(bool hibernate)
 
 		snprintf(tmp, sizeof(tmp) - 1,
 			 "while true; do find %s%i*/ -type f | xargs cat > /dev/null 2>&1; done",
-			 dfs_base, drm_get_card());
+			 dfs_base, igt_device_get_card_index(fd));
 		igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
 	}
 
@@ -212,10 +213,10 @@ igt_main
 		test_fence_restore(fd, false, false);
 
 	igt_subtest("debugfs-reader")
-		test_debugfs_reader(false);
+		test_debugfs_reader(fd, false);
 
 	igt_subtest("sysfs-reader")
-		test_sysfs_reader(false);
+		test_sysfs_reader(fd, false);
 
 	igt_subtest("shrink")
 		test_shrink(fd, SUSPEND_STATE_MEM);
@@ -230,10 +231,10 @@ igt_main
 		test_fence_restore(fd, false, true);
 
 	igt_subtest("debugfs-reader-hibernate")
-		test_debugfs_reader(true);
+		test_debugfs_reader(fd, true);
 
 	igt_subtest("sysfs-reader-hibernate")
-		test_sysfs_reader(true);
+		test_sysfs_reader(fd, true);
 
 	igt_subtest("forcewake-hibernate")
 		test_forcewake(fd, true);
diff --git a/tools/intel_gpu_frequency.c b/tools/intel_gpu_frequency.c
index 80786ad9..52b11a98 100644
--- a/tools/intel_gpu_frequency.c
+++ b/tools/intel_gpu_frequency.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include "drmtest.h"
+#include "igt_device.h"
 #include "intel_chipset.h"
 
 #define VERSION "1.0"
@@ -280,10 +281,12 @@ int main(int argc, char *argv[])
 {
 
 	bool write, fail, targets[MAX+1] = {false};
-	int i, try = 1, set_freq[MAX+1] = {0};
+	int i, fd, try = 1, set_freq[MAX+1] = {0};
 
-	devid = intel_get_drm_devid(drm_open_driver(DRIVER_INTEL));
-	device = drm_get_card();
+	fd = drm_open_driver(DRIVER_INTEL);
+	devid = intel_get_drm_devid(fd);
+	device = igt_device_get_card_index(fd);
+	close(fd);
 
 	write = parse(argc, argv, targets, ARRAY_SIZE(targets), set_freq);
 	fail = write;
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 6/8] lib/igt_sysfs: Remove idx from sysfs_open
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
                   ` (3 preceding siblings ...)
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 5/8] lib: Kill drm_get_card() Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 7/8] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

Similar to sysfs_path - more explicit more better.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_gt.c                       | 2 +-
 lib/igt_kms.c                      | 7 ++++++-
 lib/igt_sysfs.c                    | 8 ++------
 lib/igt_sysfs.h                    | 2 +-
 tests/i915/gem_exec_blt.c          | 2 +-
 tests/i915/gem_exec_capture.c      | 2 +-
 tests/i915/i915_hangman.c          | 4 +---
 tests/i915/i915_pm_rc6_residency.c | 2 +-
 tests/perf.c                       | 2 +-
 tests/perf_pmu.c                   | 2 +-
 tests/vgem_basic.c                 | 2 +-
 tools/intel_l3_parity.c            | 2 +-
 12 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index c98a7553..59995243 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -76,7 +76,7 @@ static void eat_error_state(int dev)
 {
 	int dir;
 
-	dir = igt_sysfs_open(dev, NULL);
+	dir = igt_sysfs_open(dev);
 	if (dir < 0)
 		return;
 
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e1eacc1e..8656ea11 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -52,6 +52,7 @@
 #include "igt_aux.h"
 #include "intel_chipset.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "sw_sync.h"
 
@@ -806,10 +807,14 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
 		break;
 	}
 
-	dir = igt_sysfs_open(drm_fd, &idx);
+	dir = igt_sysfs_open(drm_fd);
 	if (dir < 0)
 		return false;
 
+	idx = igt_device_get_card_index(drm_fd);
+	if (idx < 0 || idx > 63)
+		return false;
+
 	if (asprintf(&path, "card%d-%s-%d/status",
 		     idx,
 		     kmstest_connector_type_str(connector->connector_type),
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 5a25d579..aa880775 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -135,7 +135,6 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
 /**
  * igt_sysfs_open:
  * @device: fd of the device
- * @idx: optional pointer to store the card index of the opened device
  *
  * This opens the sysfs directory corresponding to device for use
  * with igt_sysfs_set() and igt_sysfs_get().
@@ -143,16 +142,13 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
  * Returns:
  * The directory fd, or -1 on failure.
  */
-int igt_sysfs_open(int device, int *idx)
+int igt_sysfs_open(int device)
 {
 	char path[80];
 
 	if (!igt_sysfs_path(device, path, sizeof(path)))
 		return -1;
 
-	if (idx)
-		*idx = igt_device_get_card_index(device);
-
 	return open(path, O_RDONLY);
 }
 
@@ -199,7 +195,7 @@ int igt_sysfs_open_parameters(int device)
 {
 	int dir, params = -1;
 
-	dir = igt_sysfs_open(device, &params);
+	dir = igt_sysfs_open(device);
 	if (dir >= 0) {
 		params = openat(dir,
 				"device/driver/module/parameters",
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index b181a95f..c12e36d1 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -29,7 +29,7 @@
 #include <stdarg.h>
 
 char *igt_sysfs_path(int device, char *path, int pathlen);
-int igt_sysfs_open(int device, int *idx);
+int igt_sysfs_open(int device);
 int igt_sysfs_open_parameters(int device);
 bool igt_sysfs_set_parameter(int device,
 			     const char *parameter,
diff --git a/tests/i915/gem_exec_blt.c b/tests/i915/gem_exec_blt.c
index 0fcfdd4b..00926e55 100644
--- a/tests/i915/gem_exec_blt.c
+++ b/tests/i915/gem_exec_blt.c
@@ -315,7 +315,7 @@ int main(int argc, char **argv)
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 
-		sysfs = igt_sysfs_open(fd, NULL);
+		sysfs = igt_sysfs_open(fd);
 		igt_require(sysfs >= 0);
 
 		min = igt_sysfs_get_u32(sysfs, "gt_min_freq_mhz");
diff --git a/tests/i915/gem_exec_capture.c b/tests/i915/gem_exec_capture.c
index 56837dfc..4457496d 100644
--- a/tests/i915/gem_exec_capture.c
+++ b/tests/i915/gem_exec_capture.c
@@ -547,7 +547,7 @@ igt_main
 		igt_require(has_capture(fd));
 		igt_allow_hang(fd, 0, HANG_ALLOW_CAPTURE);
 
-		dir = igt_sysfs_open(fd, NULL);
+		dir = igt_sysfs_open(fd);
 		igt_require(igt_sysfs_set(dir, "error", "Begone!"));
 		igt_require(safer_strlen(igt_sysfs_get(dir, "error")) > 0);
 	}
diff --git a/tests/i915/i915_hangman.c b/tests/i915/i915_hangman.c
index 4e515e3a..9a1d5889 100644
--- a/tests/i915/i915_hangman.c
+++ b/tests/i915/i915_hangman.c
@@ -262,14 +262,12 @@ igt_main
 	igt_skip_on_simulation();
 
 	igt_fixture {
-		int idx;
-
 		device = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(device);
 
 		hang = igt_allow_hang(device, 0, HANG_ALLOW_CAPTURE);
 
-		sysfs = igt_sysfs_open(device, &idx);
+		sysfs = igt_sysfs_open(device);
 		igt_assert(sysfs != -1);
 
 		igt_require(has_error_state(sysfs));
diff --git a/tests/i915/i915_pm_rc6_residency.c b/tests/i915/i915_pm_rc6_residency.c
index abc30ac6..1b52e4f5 100644
--- a/tests/i915/i915_pm_rc6_residency.c
+++ b/tests/i915/i915_pm_rc6_residency.c
@@ -208,7 +208,7 @@ igt_main
 
 		fd = drm_open_driver(DRIVER_INTEL);
 		devid = intel_get_drm_devid(fd);
-		sysfs = igt_sysfs_open(fd, NULL);
+		sysfs = igt_sysfs_open(fd);
 
 		igt_require(has_rc6_residency("rc6"));
 
diff --git a/tests/perf.c b/tests/perf.c
index ecbadfcd..37c16cca 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -4089,7 +4089,7 @@ igt_main
 		igt_require_gem(drm_fd);
 
 		devid = intel_get_drm_devid(drm_fd);
-		sysfs = igt_sysfs_open(drm_fd, NULL);
+		sysfs = igt_sysfs_open(drm_fd);
 
 		igt_require(init_sys_info());
 
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index aa5b9921..1a08f564 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -1275,7 +1275,7 @@ test_frequency(int gem_fd)
 	igt_spin_t *spin;
 	int fd, sysfs;
 
-	sysfs = igt_sysfs_open(gem_fd, NULL);
+	sysfs = igt_sysfs_open(gem_fd);
 	igt_require(sysfs >= 0);
 
 	min_freq = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 1a952c54..526636dd 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -262,7 +262,7 @@ static void test_dmabuf_fence_before(int fd)
 
 static void test_sysfs_read(int fd)
 {
-	int dir = igt_sysfs_open(fd, NULL);
+	int dir = igt_sysfs_open(fd);
 	DIR *dirp = fdopendir(dir);
 	struct dirent *de;
 
diff --git a/tools/intel_l3_parity.c b/tools/intel_l3_parity.c
index d1a9bc44..d8c997af 100644
--- a/tools/intel_l3_parity.c
+++ b/tools/intel_l3_parity.c
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
 
 	assert(intel_register_access_init(intel_get_pci_device(), 0, device) == 0);
 
-	dir = igt_sysfs_open(device, NULL);
+	dir = igt_sysfs_open(device);
 
 	for_each_slice(i) {
 		fd[i] = openat(dir, path[i], O_RDWR);
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 7/8] lib/igt_sysfs: Simplify obtaining sysfs path
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
                   ` (4 preceding siblings ...)
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 6/8] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
  2019-03-13 19:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v2,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Patchwork
  7 siblings, 0 replies; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

Now that we've extracted card index, we no longer have the need to
iterate over device nodes.

v2: Drop ret.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_sysfs.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index aa880775..f806f4fc 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -106,30 +106,13 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
 	if (fstat(device, &st) || !S_ISCHR(st.st_mode))
 		return NULL;
 
-	for (int n = 0; n < 16; n++) {
-		int len, ret, maj, min;
-		FILE *file;
+	snprintf(path, pathlen, "/sys/dev/char/%d:%d",
+		 major(st.st_rdev), minor(st.st_rdev));
 
-		len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
-
-		sprintf(path + len, "/dev");
-		file = fopen(path, "r");
-		if (!file)
-			continue;
-
-		ret = fscanf(file, "%d:%d", &maj, &min);
-		fclose(file);
-
-		if (ret != 2 || major(st.st_rdev) != maj ||
-		    minor(st.st_rdev) != min)
-			continue;
-
-		path[len] = '\0';
-
-		return path;
-	}
+	if (access(path, F_OK))
+		return NULL;
 
-	return NULL;
+	return path;
 }
 
 /**
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
                   ` (5 preceding siblings ...)
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 7/8] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
@ 2019-03-13 17:38 ` Michał Winiarski
  2019-03-13 18:00   ` Chris Wilson
  2019-03-13 19:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v2,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Patchwork
  7 siblings, 1 reply; 11+ messages in thread
From: Michał Winiarski @ 2019-03-13 17:38 UTC (permalink / raw)
  To: igt-dev

It allows us to make things a little bit more generic. Also, we now
require fd rather than doing guesswork when it comes to pci address.

v2: Use readlinkat rather than string concat, move stuff around, provide
a version that does not assert. (Chris)

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 benchmarks/gem_latency.c        |   4 +-
 benchmarks/gem_wsim.c           |   4 +-
 debugger/debug_rdata.c          |   7 +-
 debugger/eudb.c                 |   8 ++-
 lib/igt_device.c                | 115 ++++++++++++++++++++++++++++++++
 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, 262 insertions(+), 131 deletions(-)

diff --git a/benchmarks/gem_latency.c b/benchmarks/gem_latency.c
index c3fc4bf0..a20bbf8a 100644
--- a/benchmarks/gem_latency.c
+++ b/benchmarks/gem_latency.c
@@ -44,6 +44,8 @@
 #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)
 
@@ -456,7 +458,7 @@ static int run(int seconds,
 	if (gen < 6)
 		return IGT_EXIT_SKIP; /* Needs BCS timestamp */
 
-	intel_register_access_init(intel_get_pci_device(), false, fd);
+	intel_register_access_init(igt_device_get_pci_device(fd), false, fd);
 
 	if (gen == 6)
 		timestamp_reg = REG(RCS_TIMESTAMP);
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index afb9644d..21e26686 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -41,7 +41,6 @@
 #include <limits.h>
 #include <pthread.h>
 
-
 #include "intel_chipset.h"
 #include "intel_reg.h"
 #include "drm.h"
@@ -50,6 +49,7 @@
 
 #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(intel_get_pci_device(), false, fd);
+	intel_register_access_init(igt_device_get_pci_device(fd), false, fd);
 
 	if (verbose <= 1)
 		return;
diff --git a/debugger/debug_rdata.c b/debugger/debug_rdata.c
index 61d82d9e..fea95029 100644
--- a/debugger/debug_rdata.c
+++ b/debugger/debug_rdata.c
@@ -29,7 +29,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "intel_io.h"
-#include "intel_chipset.h"
 
 struct eu_rdata {
 	union {
@@ -133,7 +132,11 @@ find_stuck_threads(void)
 
 int main(int argc, char *argv[]) {
 	struct pci_device *pci_dev;
-	pci_dev = intel_get_pci_device();
+	int fd;
+
+	fd = drm_open_driver(DRIVER_INTEL);
+	pci_dev = igt_device_get_pci_device(fd);
+	close(fd);
 
 	intel_register_access_init(pci_dev, 1);
 	find_stuck_threads();
diff --git a/debugger/eudb.c b/debugger/eudb.c
index 866d4b52..b5784148 100644
--- a/debugger/eudb.c
+++ b/debugger/eudb.c
@@ -42,7 +42,6 @@
 #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"
@@ -506,7 +505,7 @@ int main(int argc, char* argv[]) {
 	struct pci_device *pci_dev;
 	volatile uint8_t *scratch = NULL;
 	int bits[64];
-	int devid = -1, opt;
+	int devid = -1, opt, fd;
 
 	while ((opt = getopt(argc, argv, "cdr:pf?h")) != -1) {
 		switch (opt) {
@@ -533,7 +532,10 @@ int main(int argc, char* argv[]) {
 		}
 	}
 
-	pci_dev = intel_get_pci_device();
+	fd = drm_open_driver(DRIVER_INTEL);
+	pci_dev = igt_device_get_pci_device(fd);
+	close(fd);
+
 	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 08f39c8b..aafc414f 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -26,6 +26,7 @@
 #include <sys/sysmacros.h>
 #include "igt.h"
 #include "igt_device.h"
+#include "igt_sysfs.h"
 
 int __igt_device_set_master(int fd)
 {
@@ -103,3 +104,117 @@ 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;
+
+	if ((sysfs = igt_sysfs_open(fd)) == -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;
+
+	if ((sysfs = igt_sysfs_open(fd)) == -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\n");
+		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;
+
+	igt_require(pci_dev = __igt_device_get_pci_device(fd));
+
+	return pci_dev;
+}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index 9d7dc2c3..278ba7a9 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -32,5 +32,6 @@ 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 4748a3fb..0577f77a 100644
--- a/lib/intel_chipset.c
+++ b/lib/intel_chipset.c
@@ -61,57 +61,6 @@
  */
 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 40170b7b..dd31d3fb 100644
--- a/lib/intel_chipset.h
+++ b/lib/intel_chipset.h
@@ -31,7 +31,6 @@
 #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 a5458aeb..f5e0be0c 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 intel_get_pci_device().
+ * @pci_dev can be obtained from igt_device_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 intel_get_pci_device().
+ * @pci_dev can be obtained from igt_device_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 39920f87..a66eb4bc 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -53,6 +53,7 @@
 #include "intel_chipset.h"
 #include "intel_io.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "config.h"
 
@@ -1096,9 +1097,9 @@ uint64_t gem_aperture_size(int fd)
  *
  * Returns: The mappable gtt address space size.
  */
-uint64_t gem_mappable_aperture_size(void)
+uint64_t gem_mappable_aperture_size(int fd)
 {
-	struct pci_device *pci_dev = intel_get_pci_device();
+	struct pci_device *pci_dev = igt_device_get_pci_device(fd);
 	int bar;
 
 	if (intel_gen(pci_dev->device_id) < 3)
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index f0be2608..ad93daff 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(void);
+uint64_t gem_mappable_aperture_size(int fd);
 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 6049372d..f719b0a1 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()/4,
+					count = num_buffers(gem_mappable_aperture_size(fd)/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(),
+					count = num_buffers(gem_mappable_aperture_size(fd),
 							    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(),
+					count = num_buffers(gem_mappable_aperture_size(fd),
 							    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()/(1024*1024)) {
-						pin_sz = intel_get_avail_ram_mb() - gem_mappable_aperture_size()/(1024*1024);
+					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);
 
 						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(),
+					count = num_buffers(gem_mappable_aperture_size(fd),
 							    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 47099862..17c2fe11 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();
+		uint64_t aper_size = gem_mappable_aperture_size(i915);
 		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();
+		uint64_t aper_size = gem_mappable_aperture_size(i915);
 		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 6dd191ec..f308e085 100644
--- a/tests/i915/gem_exec_latency.c
+++ b/tests/i915/gem_exec_latency.c
@@ -40,6 +40,7 @@
 
 #include "drm.h"
 
+#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "igt_vgem.h"
 #include "igt_dummyload.h"
@@ -679,7 +680,7 @@ igt_main
 		if (ring_size > 1024)
 			ring_size = 1024;
 
-		intel_register_access_init(intel_get_pci_device(), false, device);
+		intel_register_access_init(igt_device_get_pci_device(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 62e8d0a5..d3b848e2 100644
--- a/tests/i915/gem_exec_parse.c
+++ b/tests/i915/gem_exec_parse.c
@@ -30,6 +30,8 @@
 
 #include <drm.h>
 
+#include "igt_device.h"
+
 #ifndef I915_PARAM_CMD_PARSER_VERSION
 #define I915_PARAM_CMD_PARSER_VERSION       28
 #endif
@@ -530,7 +532,7 @@ igt_main
 #undef REG
 
 		igt_fixture {
-			intel_register_access_init(intel_get_pci_device(), 0, fd);
+			intel_register_access_init(igt_device_get_pci_device(fd), 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 0ed15878..4e30fec1 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() / 2;
+		huge_object_size = gem_mappable_aperture_size(fd) / 2;
 		break;
 	case 0:
-		huge_object_size = gem_mappable_aperture_size() + PAGE_SIZE;
+		huge_object_size = gem_mappable_aperture_size(fd) + 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 f6fbbe19..60c19d61 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -527,7 +527,7 @@ test_huge_bo(int fd, int huge, int tiling)
 
 	switch (huge) {
 	case -1:
-		size = gem_mappable_aperture_size() / 2;
+		size = gem_mappable_aperture_size(fd) / 2;
 
 		/* Power of two fence size, natural fence
 		 * alignment, and the guard page at the end
@@ -542,7 +542,7 @@ test_huge_bo(int fd, int huge, int tiling)
 			size /= 2;
 		break;
 	case 0:
-		size = gem_mappable_aperture_size() + PAGE_SIZE;
+		size = gem_mappable_aperture_size(fd) + PAGE_SIZE;
 		break;
 	default:
 		size = gem_global_aperture_size(fd) + PAGE_SIZE;
@@ -623,13 +623,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() / 4;
+		huge_object_size = gem_mappable_aperture_size(fd) / 4;
 		break;
 	case -1:
-		huge_object_size = gem_mappable_aperture_size() / 2;
+		huge_object_size = gem_mappable_aperture_size(fd) / 2;
 		break;
 	case 0:
-		huge_object_size = gem_mappable_aperture_size() + PAGE_SIZE;
+		huge_object_size = gem_mappable_aperture_size(fd) + 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 696bd316..5cae121a 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() + 4096;
+		size = gem_mappable_aperture_size(fd) + 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() + 4096;
+		size = gem_mappable_aperture_size(fd) + 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 c8e05814..73b6be72 100644
--- a/tests/i915/gem_shrink.c
+++ b/tests/i915/gem_shrink.c
@@ -409,7 +409,7 @@ igt_main
 		 * we expect the shrinker to start purging objects,
 		 * and possibly fail.
 		 */
-		alloc_size = gem_mappable_aperture_size() / 2;
+		alloc_size = gem_mappable_aperture_size(fd) / 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 b319dbe9..4e7ce399 100644
--- a/tests/i915/i915_pm_lpsp.c
+++ b/tests/i915/i915_pm_lpsp.c
@@ -30,6 +30,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "igt_device.h"
 
 static bool supports_lpsp(uint32_t devid)
 {
@@ -210,7 +211,7 @@ igt_main
 
 		igt_require(supports_lpsp(devid));
 
-		intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+		intel_register_access_init(igt_device_get_pci_device(drm_fd), 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 03de609c..18adaf6b 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() / (1024*1024) + 1;
+	num_trash_bos = gem_mappable_aperture_size(drm_fd) / (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(intel_get_pci_device(), &val, 0xd4);
+	rc = pci_device_cfg_read_u16(igt_device_get_pci_device(drm_fd), &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 dfa5a69e..6ece1e53 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();
+		bo_size = 4*gem_mappable_aperture_size(drm_fd);
 		igt_require(bo_size < gem_global_aperture_size(drm_fd));
 	}
 
diff --git a/tests/prime_mmap.c b/tests/prime_mmap.c
index fc985784..06a66cab 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() * 7) / 8;
-	uint64_t size2 = (gem_mappable_aperture_size() * 3) / 8;
+	uint64_t size1 = (gem_mappable_aperture_size(fd) * 7) / 8;
+	uint64_t size2 = (gem_mappable_aperture_size(fd) * 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 90260a2f..350a21d9 100644
--- a/tools/intel_audio_dump.c
+++ b/tools/intel_audio_dump.c
@@ -32,6 +32,7 @@
 #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"
@@ -2464,8 +2465,12 @@ 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();
@@ -2493,5 +2498,7 @@ 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 067fd418..fc45d985 100644
--- a/tools/intel_backlight.c
+++ b/tools/intel_backlight.c
@@ -30,8 +30,9 @@
 #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 */
@@ -39,8 +40,11 @@
 int main(int argc, char** argv)
 {
 	uint32_t current, max;
+	int fd;
 
-	intel_mmio_use_pci_bar(intel_get_pci_device());
+	fd = drm_open_driver(DRIVER_INTEL);
+	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
+	close(fd);
 
 	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 51f5b9a5..293574f2 100644
--- a/tools/intel_display_poller.c
+++ b/tools/intel_display_poller.c
@@ -36,6 +36,7 @@
 #include "intel_io.h"
 #include "intel_reg.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "drmtest.h"
 #include "igt_aux.h"
 
@@ -971,6 +972,7 @@ 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[] = {
@@ -1046,7 +1048,8 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	devid = intel_get_pci_device()->device_id;
+	fd = drm_open_driver(DRIVER_INTEL);
+	devid = igt_device_get_pci_device(fd)->device_id;
 
 	/*
 	 * check if the requires registers are
@@ -1187,7 +1190,7 @@ int main(int argc, char *argv[])
 		break;
 	}
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	printf("%s?\n", test_name(test, pipe, bit, test_pixelcount));
 
@@ -1263,6 +1266,7 @@ 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 02fbf888..7d32337a 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,6 +65,7 @@ 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]);
@@ -80,24 +81,27 @@ int main(int argc, char *argv[])
 		INFO_PRINT("started daemon");
 	}
 
-	ret = intel_register_access_init(intel_get_pci_device(), 1, -1);
+	fd = drm_open_driver(DRIVER_INTEL);
+	ret = intel_register_access_init(igt_device_get_pci_device(fd), 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(intel_get_pci_device(), 1, -1);
+			ret = intel_register_access_init(igt_device_get_pci_device(fd), 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 56d65fe0..0fc73f92 100644
--- a/tools/intel_gpu_time.c
+++ b/tools/intel_gpu_time.c
@@ -34,8 +34,9 @@
 #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
@@ -66,8 +67,11 @@ int main(int argc, char **argv)
 	struct timeval start, end;
 	static struct rusage rusage;
 	int status;
+	int fd;
 
-	intel_mmio_use_pci_bar(intel_get_pci_device());
+	fd = drm_open_driver(DRIVER_INTEL);
+	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
+	close(fd);
 
 	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 311694ba..5740e794 100644
--- a/tools/intel_gtt.c
+++ b/tools/intel_gtt.c
@@ -34,6 +34,8 @@
 #include <pciaccess.h>
 #include <unistd.h>
 
+#include "drmtest.h"
+#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 
@@ -140,13 +142,17 @@ 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;
 
-	pci_dev = intel_get_pci_device();
+	fd = drm_open_driver(DRIVER_INTEL);
+	pci_dev = igt_device_get_pci_device(fd);
+	close(fd);
+
 	devid = pci_dev->device_id;
 
 	if (IS_GEN2(devid)) {
diff --git a/tools/intel_infoframes.c b/tools/intel_infoframes.c
index 2ef5d4fd..9129572a 100644
--- a/tools/intel_infoframes.c
+++ b/tools/intel_infoframes.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
+#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 #include "drmtest.h"
@@ -1081,6 +1082,7 @@ printf("Options:\n"
 int main(int argc, char *argv[])
 {
 	int opt;
+	int fd;
 	int ret = 0;
 	Transcoder transcoder = TRANSC_INVALID;
 	DipType dip = DIP_INVALID;
@@ -1107,7 +1109,10 @@ 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");
 
-	pci_dev = intel_get_pci_device();
+	fd = drm_open_driver(DRIVER_INTEL);
+	pci_dev = igt_device_get_pci_device(fd);
+	close(fd);
+
 	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 d8c997af..e2e4503a 100644
--- a/tools/intel_l3_parity.c
+++ b/tools/intel_l3_parity.c
@@ -36,6 +36,7 @@
 #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"
@@ -189,7 +190,7 @@ int main(int argc, char *argv[])
 	if (intel_gen(devid) < 7 || IS_VALLEYVIEW(devid))
 		exit(77);
 
-	assert(intel_register_access_init(intel_get_pci_device(), 0, device) == 0);
+	assert(intel_register_access_init(igt_device_get_pci_device(device), 0, device) == 0);
 
 	dir = igt_sysfs_open(device);
 
diff --git a/tools/intel_lid.c b/tools/intel_lid.c
index 37c6ba5e..447790d9 100644
--- a/tools/intel_lid.c
+++ b/tools/intel_lid.c
@@ -37,9 +37,10 @@
 #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 */
 
@@ -118,8 +119,11 @@ out:
 int main(int argc, char **argv)
 {
 	int swf14, acpi_lid;
+	int fd;
 
-	intel_mmio_use_pci_bar(intel_get_pci_device());
+	fd = drm_open_driver(DRIVER_INTEL);
+	intel_mmio_use_pci_bar(igt_device_get_pci_device(fd));
+	close(fd);
 
 	while (1) {
 		swf14 = INREG(SWF14);
@@ -142,5 +146,6 @@ 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 137ef61a..06f4ac59 100644
--- a/tools/intel_panel_fitter.c
+++ b/tools/intel_panel_fitter.c
@@ -30,6 +30,7 @@
 #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"
@@ -273,13 +274,17 @@ 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");
 
-	pci_dev = intel_get_pci_device();
+	fd = drm_open_driver(DRIVER_INTEL);
+	pci_dev = igt_device_get_pci_device(fd);
+	close(fd);
+
 	intel_register_access_init(pci_dev, 0, -1);
 	devid = pci_dev->device_id;
 
@@ -343,5 +348,6 @@ 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 50c4bce6..105a0924 100644
--- a/tools/intel_perf_counters.c
+++ b/tools/intel_perf_counters.c
@@ -45,6 +45,7 @@
 #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"
@@ -483,7 +484,7 @@ main(int argc, char **argv)
 
 	if (oacontrol) {
 		/* Forcewake */
-		intel_register_access_init(intel_get_pci_device(), 0, fd);
+		intel_register_access_init(igt_device_get_pci_device(fd), 0, fd);
 
 		/* Enable performance counters */
 		intel_register_write(OACONTROL,
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index 1247b70b..305323b6 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,15 +274,6 @@ 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)
@@ -1015,6 +1006,13 @@ 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");
@@ -1026,7 +1024,7 @@ int main(int argc, char *argv[])
 			fprintf(stderr, "--devid without --mmio\n");
 			return EXIT_FAILURE;
 		}
-		config.pci_dev = intel_get_pci_device();
+		config.pci_dev = igt_device_get_pci_device(config.fd);
 		config.devid = config.pci_dev->device_id;
 	}
 
@@ -1050,8 +1048,7 @@ int main(int argc, char *argv[])
 
 	free(config.mmiofile);
 
-	if (config.fd >= 0)
-		close(config.fd);
+	close(config.fd);
 
 	return ret;
 }
diff --git a/tools/intel_reg_checker.c b/tools/intel_reg_checker.c
index 6bde63ec..0ed26029 100644
--- a/tools/intel_reg_checker.c
+++ b/tools/intel_reg_checker.c
@@ -26,6 +26,8 @@
 #include <err.h>
 #include <string.h>
 #include <stdbool.h>
+#include "drmtest.h"
+#include "igt_device.h"
 #include "intel_io.h"
 #include "intel_chipset.h"
 
@@ -342,8 +344,12 @@ 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 e71c3d9c..2dc4307c 100644
--- a/tools/intel_watermark.c
+++ b/tools/intel_watermark.c
@@ -29,12 +29,14 @@
 #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)
 {
@@ -249,7 +251,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(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	for (pipe = 0; pipe < num_pipes; pipe++) {
 		int num_planes = skl_num_planes(devid, pipe);
@@ -469,7 +471,7 @@ static void ilk_wm_dump(void)
 	int num_pipes = intel_gen(devid) >= 7 ? 3 : 2;
 	struct ilk_wm wm = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	for (i = 0; i < num_pipes; i++) {
 		dspcntr[i] = read_reg(0x70180 + i * 0x1000);
@@ -619,7 +621,7 @@ static void vlv_wm_dump(void)
 	uint32_t dsp_ss_pm, ddr_setup2;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	dsparb2 = read_reg(0x70060);
@@ -835,7 +837,7 @@ static void g4x_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dspacntr = read_reg(0x70180);
 	dspbcntr = read_reg(0x71180);
@@ -921,7 +923,7 @@ static void gen4_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	fw1 = read_reg(0x70034);
@@ -992,7 +994,7 @@ static void pnv_wm_dump(void)
 	uint32_t cbr;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	fw1 = read_reg(0x70034);
@@ -1082,7 +1084,7 @@ static void gen3_wm_dump(void)
 	uint32_t mi_arb_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	instpm = read_reg(0x20c0);
@@ -1151,7 +1153,7 @@ static void gen2_wm_dump(void)
 	uint32_t mi_state;
 	struct gmch_wm wms[MAX_PLANE] = {};
 
-	intel_register_access_init(intel_get_pci_device(), 0, -1);
+	intel_register_access_init(igt_device_get_pci_device(fd), 0, -1);
 
 	dsparb = read_reg(0x70030);
 	mem_mode = read_reg(0x20cc);
@@ -1226,7 +1228,8 @@ static void gen2_wm_dump(void)
 
 int main(int argc, char *argv[])
 {
-	devid = intel_get_pci_device()->device_id;
+	fd = drm_open_driver(DRIVER_INTEL);
+	devid = igt_device_get_pci_device(fd)->device_id;
 
 	if (intel_gen(devid) >= 9) {
 		skl_wm_dump();
@@ -1250,5 +1253,7 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	close(fd);
+
 	return 0;
 }
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
@ 2019-03-13 17:55   ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2019-03-13 17:55 UTC (permalink / raw)
  To: Michał Winiarski, igt-dev

Quoting Michał Winiarski (2019-03-13 17:38:15)
> Doing this lets us avoid drm_get_card, which we plan to remove
> eventually.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>

Looks convincing enough to me.
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
@ 2019-03-13 18:00   ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2019-03-13 18:00 UTC (permalink / raw)
  To: Michał Winiarski, igt-dev

Quoting Michał Winiarski (2019-03-13 17:38:21)
> +#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;
> +
> +       if ((sysfs = igt_sysfs_open(fd)) == -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;
> +
> +       if ((sysfs = igt_sysfs_open(fd)) == -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",

Heh, buf+1 :)

> +                  &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\n");

"Couldn't find PCI device %04x:%02x:%02x:%02x\n"

> +               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;
> +
> +       igt_require(pci_dev = __igt_device_get_pci_device(fd));
> +
> +       return pci_dev;
> +}

That looks a lot more orderly and controlled. Style-wise, probably best
to avoid assignment inside conditionals.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v2,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs
  2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
                   ` (6 preceding siblings ...)
  2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
@ 2019-03-13 19:44 ` Patchwork
  7 siblings, 0 replies; 11+ messages in thread
From: Patchwork @ 2019-03-13 19:44 UTC (permalink / raw)
  To: Michał Winiarski; +Cc: igt-dev

== Series Details ==

Series: series starting with [i-g-t,v2,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs
URL   : https://patchwork.freedesktop.org/series/57955/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_5740 -> IGTPW_2608
====================================================

Summary
-------

  **FAILURE**

  Serious unknown changes coming with IGTPW_2608 absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_2608, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/57955/revisions/1/mbox/

Possible new issues
-------------------

  Here are the unknown changes that may have been introduced in IGTPW_2608:

### IGT changes ###

#### Possible regressions ####

  * igt@i915_pm_rps@basic-api:
    - fi-icl-u3:          PASS -> SKIP
    - fi-icl-u2:          PASS -> SKIP

  
Known issues
------------

  Here are the changes found in IGTPW_2608 that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@amdgpu/amd_basic@query-info:
    - fi-bsw-kefka:       NOTRUN -> SKIP [fdo#109271] +57

  * igt@gem_ctx_create@basic-files:
    - fi-gdg-551:         NOTRUN -> SKIP [fdo#109271] +106

  * igt@gem_exec_basic@gtt-bsd2:
    - fi-byt-clapper:     NOTRUN -> SKIP [fdo#109271] +58

  * igt@gem_exec_basic@readonly-bsd2:
    - fi-pnv-d510:        NOTRUN -> SKIP [fdo#109271] +76

  * igt@gem_exec_store@basic-bsd2:
    - fi-hsw-4770:        NOTRUN -> SKIP [fdo#109271] +42

  * igt@i915_pm_rpm@basic-rte:
    - fi-bsw-kefka:       NOTRUN -> FAIL [fdo#108800]

  * igt@i915_pm_rps@basic-api:
    - fi-kbl-guc:         PASS -> SKIP [fdo#109271]
    - fi-cfl-8109u:       PASS -> SKIP [fdo#109271]
    - fi-kbl-r:           PASS -> SKIP [fdo#109271]
    - fi-skl-6260u:       PASS -> SKIP [fdo#109271]
    - fi-bxt-j4205:       PASS -> SKIP [fdo#109271]
    - fi-skl-6770hq:      PASS -> SKIP [fdo#109271]
    - fi-snb-2600:        PASS -> SKIP [fdo#109271]
    - fi-cfl-guc:         PASS -> SKIP [fdo#109271]
    - fi-skl-6700k2:      PASS -> SKIP [fdo#109271]
    - fi-byt-n2820:       PASS -> SKIP [fdo#109271]
    - fi-cfl-8700k:       PASS -> SKIP [fdo#109271]
    - fi-apl-guc:         PASS -> SKIP [fdo#109271]
    - fi-bdw-5557u:       PASS -> SKIP [fdo#109271]
    - fi-kbl-7560u:       PASS -> SKIP [fdo#109271]
    - fi-skl-6600u:       PASS -> SKIP [fdo#109271]
    - fi-skl-guc:         PASS -> SKIP [fdo#109271]
    - fi-hsw-4770r:       PASS -> SKIP [fdo#109271]
    - fi-hsw-peppy:       PASS -> SKIP [fdo#109271]
    - fi-kbl-8809g:       PASS -> SKIP [fdo#109271]
    - fi-skl-gvtdvm:      PASS -> SKIP [fdo#109271]
    - fi-kbl-x1275:       PASS -> SKIP [fdo#109271]
    - fi-bsw-n3050:       PASS -> SKIP [fdo#109271]
    - fi-ivb-3770:        PASS -> SKIP [fdo#109271]
    - fi-snb-2520m:       PASS -> SKIP [fdo#109271]
    - fi-whl-u:           PASS -> SKIP [fdo#109271]
    - fi-bdw-gvtdvm:      PASS -> SKIP [fdo#109271]

  * igt@i915_selftest@live_execlists:
    - fi-apl-guc:         PASS -> INCOMPLETE [fdo#103927] / [fdo#109720]

  * igt@kms_busy@basic-flip-b:
    - fi-gdg-551:         NOTRUN -> FAIL [fdo#103182]

  * igt@kms_busy@basic-flip-c:
    - fi-byt-j1900:       NOTRUN -> SKIP [fdo#109271] / [fdo#109278]
    - fi-byt-clapper:     NOTRUN -> SKIP [fdo#109271] / [fdo#109278]
    - fi-gdg-551:         NOTRUN -> SKIP [fdo#109271] / [fdo#109278]
    - fi-bsw-kefka:       NOTRUN -> SKIP [fdo#109271] / [fdo#109278]
    - fi-pnv-d510:        NOTRUN -> SKIP [fdo#109271] / [fdo#109278]

  * igt@kms_chamelium@common-hpd-after-suspend:
    - fi-kbl-7567u:       PASS -> WARN [fdo#109380]

  * igt@kms_chamelium@hdmi-crc-fast:
    - fi-byt-j1900:       NOTRUN -> SKIP [fdo#109271] +53

  * igt@kms_frontbuffer_tracking@basic:
    - fi-byt-clapper:     NOTRUN -> FAIL [fdo#103167]

  * igt@kms_pipe_crc_basic@nonblocking-crc-pipe-a-frame-sequence:
    - fi-byt-clapper:     NOTRUN -> FAIL [fdo#103191] / [fdo#107362] +1

  * igt@kms_pipe_crc_basic@nonblocking-crc-pipe-c:
    - fi-kbl-7567u:       PASS -> SKIP [fdo#109271] +34

  * igt@runner@aborted:
    - fi-apl-guc:         NOTRUN -> FAIL [fdo#108622] / [fdo#109720]

  
#### Possible fixes ####

  * igt@gem_exec_suspend@basic-s4-devices:
    - fi-kbl-7500u:       DMESG-WARN [fdo#105128] / [fdo#107139] -> PASS

  * igt@i915_module_load@reload:
    - fi-ilk-650:         DMESG-WARN [fdo#106387] -> PASS

  
#### Warnings ####

  * igt@i915_selftest@live_contexts:
    - fi-icl-u3:          DMESG-FAIL [fdo#108569] -> INCOMPLETE [fdo#108569]

  
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  [fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
  [fdo#103182]: https://bugs.freedesktop.org/show_bug.cgi?id=103182
  [fdo#103191]: https://bugs.freedesktop.org/show_bug.cgi?id=103191
  [fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
  [fdo#105128]: https://bugs.freedesktop.org/show_bug.cgi?id=105128
  [fdo#106387]: https://bugs.freedesktop.org/show_bug.cgi?id=106387
  [fdo#107139]: https://bugs.freedesktop.org/show_bug.cgi?id=107139
  [fdo#107362]: https://bugs.freedesktop.org/show_bug.cgi?id=107362
  [fdo#108569]: https://bugs.freedesktop.org/show_bug.cgi?id=108569
  [fdo#108622]: https://bugs.freedesktop.org/show_bug.cgi?id=108622
  [fdo#108800]: https://bugs.freedesktop.org/show_bug.cgi?id=108800
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
  [fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
  [fdo#109284]: https://bugs.freedesktop.org/show_bug.cgi?id=109284
  [fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
  [fdo#109289]: https://bugs.freedesktop.org/show_bug.cgi?id=109289
  [fdo#109294]: https://bugs.freedesktop.org/show_bug.cgi?id=109294
  [fdo#109315]: https://bugs.freedesktop.org/show_bug.cgi?id=109315
  [fdo#109380]: https://bugs.freedesktop.org/show_bug.cgi?id=109380
  [fdo#109720]: https://bugs.freedesktop.org/show_bug.cgi?id=109720
  [fdo#110028]: https://bugs.freedesktop.org/show_bug.cgi?id=110028


Participating hosts (39 -> 43)
------------------------------

  Additional (7): fi-byt-j1900 fi-byt-clapper fi-hsw-4770 fi-gdg-551 fi-pnv-d510 fi-icl-y fi-bsw-kefka 
  Missing    (3): fi-ilk-m540 fi-bdw-samus fi-hsw-4200u 


Build changes
-------------

    * IGT: IGT_4884 -> IGTPW_2608

  CI_DRM_5740: a9decdcc27ca0e8dbdb538cf58e3840274110c17 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_2608: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2608/
  IGT_4884: c46051337b972f8b5a302afb6f603df06fea527d @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2608/
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-03-13 19:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 17:38 [igt-dev] [PATCH i-g-t v2 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
2019-03-13 17:55   ` Chris Wilson
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 3/8] tests/i915_pm_rps: Use " Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 4/8] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 5/8] lib: Kill drm_get_card() Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 6/8] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 7/8] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
2019-03-13 17:38 ` [igt-dev] [PATCH i-g-t v2 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
2019-03-13 18:00   ` Chris Wilson
2019-03-13 19:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v2,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.