[Intel-gfx] [PATCH igt 1/2] lib: Support opening vGEM device

Chris Wilson chris at chris-wilson.co.uk
Sat Jun 18 13:59:09 UTC 2016


Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/drmtest.c | 47 ++++++++++++++++++++++++++++++++---------------
 lib/drmtest.h |  7 ++++---
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index c59cabe..30eae19 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -90,24 +90,29 @@ static int __get_drm_device_name(int fd, char *name)
 	return -1;
 }
 
-bool is_i915_device(int fd)
+static bool __is_device(int fd, const char *expect)
 {
-	int ret;
 	char name[5] = "";
 
-	ret = __get_drm_device_name(fd, name);
+	if (__get_drm_device_name(fd, name))
+		return false;
 
-	return !ret && strcmp("i915", name) == 0;
+	return strcmp(expect, name) == 0;
 }
 
-static bool is_vc4_device(int fd)
+bool is_i915_device(int fd)
 {
-	int ret;
-	char name[5] = "";
+	return __is_device(fd, "i915");
+}
 
-	ret = __get_drm_device_name(fd, name);
+static bool is_vc4_device(int fd)
+{
+	return __is_device(fd, "vc4");
+}
 
-	return !ret && strcmp("vc4", name) == 0;
+static bool is_vgem_device(int fd)
+{
+	return __is_device(fd, "vgem");
 }
 
 static bool has_known_intel_chipset(int fd)
@@ -213,6 +218,13 @@ int drm_get_card(void)
 	return -1;
 }
 
+static void modprobe(const char *driver)
+{
+	char buf[128];
+	snprintf(buf, sizeof(buf), "/sbin/modprobe %s", driver);
+	system(buf);
+}
+
 /**
  * __drm_open_driver:
  * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
@@ -224,23 +236,28 @@ int drm_get_card(void)
  */
 int __drm_open_driver(int chipset)
 {
+	if (chipset & DRIVER_VGEM)
+		modprobe("vgem");
+
 	for (int i = 0; i < 16; i++) {
 		char name[80];
 		int fd;
-		bool found_intel, found_vc4;
 
 		sprintf(name, "/dev/dri/card%u", i);
 		fd = open(name, O_RDWR);
 		if (fd == -1)
 			continue;
 
-		found_intel = is_i915_device(fd) &&
-			      has_known_intel_chipset(fd) &&
-			      (chipset & DRIVER_INTEL);
+		if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
+		    has_known_intel_chipset(fd))
+			return fd;
 
-		found_vc4 = is_vc4_device(fd) && (chipset & DRIVER_VC4);
+		if (chipset & DRIVER_VC4 &&
+		    is_vc4_device(fd))
+			return fd;
 
-		if ((chipset & DRIVER_ANY) || found_intel || found_vc4)
+		if (chipset & DRIVER_VGEM &&
+		    is_vgem_device(fd))
 			return fd;
 
 		close(fd);
diff --git a/lib/drmtest.h b/lib/drmtest.h
index c391464..8ce32a6 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -38,9 +38,10 @@
 
 #include "intel_batchbuffer.h"
 
-#define DRIVER_ANY 0x1
-#define DRIVER_INTEL (0x1 << 1)
-#define DRIVER_VC4 (0x1 << 2)
+#define DRIVER_INTEL	(1 << 0)
+#define DRIVER_VC4	(1 << 1)
+#define DRIVER_VGEM	(1 << 2)
+#define DRIVER_ANY 	~(DRIVER_VGEM)
 
 #ifdef ANDROID
 #if (!(defined HAVE_MMAP64)) && (!(defined __x86_64__))
-- 
2.8.1



More information about the Intel-gfx mailing list