All of lore.kernel.org
 help / color / mirror / Atom feed
From: Micah Fedke <micah.fedke@collabora.co.uk>
To: intel-gfx@lists.freedesktop.org, daniel@ffwll.ch, daniel@fooishbar.org
Subject: [PATCH 1/5] lib: adding drm_open_driver() interface
Date: Fri, 31 Jul 2015 16:11:07 -0400	[thread overview]
Message-ID: <1438373471-11798-2-git-send-email-micah.fedke@collabora.co.uk> (raw)
In-Reply-To: <1438373471-11798-1-git-send-email-micah.fedke@collabora.co.uk>

---
 lib/drmtest.c | 108 ++++++++++++++++++++++++++++++++++++++--------------------
 lib/drmtest.h |  18 +++++++---
 2 files changed, 86 insertions(+), 40 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index ee5c123..4e3ddd6 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -75,23 +75,43 @@
 
 uint16_t __drm_device_id;
 
-static int is_i915_device(int fd)
+/**
+ * __get_drm_device_name:
+ *
+ * Obtains the name of the drm device driver of the opened drm fd
+ *
+ * @fd: opened drm file descriptor to query
+ * @name: output: pointer to string to be filled with the device name
+ *
+ * Returns:
+ * 0 if the name was successfully written to @name, or -1 on error
+ */
+static int __get_drm_device_name(int fd, char *name)
 {
 	drm_version_t version;
-	char name[5] = "";
 
 	memset(&version, 0, sizeof(version));
 	version.name_len = 4;
 	version.name = name;
 
-	if (drmIoctl(fd, DRM_IOCTL_VERSION, &version))
+	if (!drmIoctl(fd, DRM_IOCTL_VERSION, &version)){
 		return 0;
+   }
 
-	return strcmp("i915", name) == 0;
+   return -1;
 }
 
-static int
-is_intel(int fd)
+static bool is_i915_device(int fd)
+{
+   int ret;
+	char name[5] = "";
+
+   ret = __get_drm_device_name(fd, name);
+
+	return !ret && strcmp("i915", name) == 0;
+}
+
+static bool is_intel(int fd)
 {
 	struct drm_i915_getparam gp;
 	int devid = 0;
@@ -101,13 +121,13 @@ is_intel(int fd)
 	gp.value = &devid;
 
 	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
-		return 0;
+		return false;
 
 	if (!IS_INTEL(devid))
-		return 0;
+		return false;
 
 	__drm_device_id = devid;
-	return 1;
+	return true;
 }
 
 static void check_stop_rings(void)
@@ -230,19 +250,31 @@ int drm_get_card(void)
 	return -1;
 }
 
-/** Open the first DRM device we can find, searching up to 16 device nodes */
-int __drm_open_any(void)
+/**
+ * __drm_open_driver:
+ *
+ * Open the first DRM device we can find, searching up to 16 device nodes
+ *
+ * @chipset: OR'd flags for each chipset to search, eg. DRIVER_INTEL
+ *
+ * Returns:
+ * An open DRM fd or -1 on error
+ */
+int __drm_open_driver(int chipset)
 {
 	for (int i = 0; i < 16; i++) {
 		char name[80];
 		int fd;
+      bool found_intel;
 
 		sprintf(name, "/dev/dri/card%u", i);
 		fd = open(name, O_RDWR);
 		if (fd == -1)
 			continue;
+     
+      found_intel =  is_i915_device(fd) && is_intel(fd) && (chipset & DRIVER_INTEL);
 
-		if (is_i915_device(fd) && is_intel(fd))
+		if ((chipset & OPEN_ANY_GPU) || found_intel)
 			return fd;
 
 		close(fd);
@@ -252,7 +284,7 @@ int __drm_open_any(void)
 	return -1;
 }
 
-static int __drm_open_any_render(void)
+static int __drm_open_driver_render(int chipset)
 {
 	char *name;
 	int i, fd;
@@ -307,41 +339,43 @@ static void quiescent_gpu_at_exit_render(int sig)
 }
 
 /**
- * drm_open_any:
+ * drm_open_driver:
  *
- * Open an i915 drm legacy device node. This function always returns a valid
+ * Open a drm legacy device node. This function always returns a valid
  * file descriptor.
  *
- * Returns: a i915 drm file descriptor
+ * Returns: a drm file descriptor
  */
-int drm_open_any(void)
+int drm_open_driver(int chipset)
 {
 	static int open_count;
-	int fd = __drm_open_any();
+	int fd = __drm_open_driver(chipset);
 
 	igt_require(fd >= 0);
 
 	if (__sync_fetch_and_add(&open_count, 1))
 		return fd;
 
-	gem_quiescent_gpu(fd);
-	at_exit_drm_fd = __drm_open_any();
-	igt_install_exit_handler(quiescent_gpu_at_exit);
+   if(chipset & DRIVER_INTEL){
+	   gem_quiescent_gpu(fd);
+	   igt_install_exit_handler(quiescent_gpu_at_exit);
+   }
+	at_exit_drm_fd = __drm_open_driver(chipset);
 
 	return fd;
 }
 
 /**
- * drm_open_any_master:
+ * drm_open_driver_master:
  *
- * Open an i915 drm legacy device node and ensure that it is drm master.
+ * Open a drm legacy device node and ensure that it is drm master.
  *
  * Returns:
- * The i915 drm file descriptor or -1 on error
+ * The drm file descriptor or -1 on error
  */
-int drm_open_any_master(void)
+int drm_open_driver_master(int chipset)
 {
-	int fd = drm_open_any();
+	int fd = drm_open_driver(chipset);
 
 	igt_require(fd >= 0);
 	igt_require_f(drmSetMaster(fd) == 0, "Can't become DRM master, "
@@ -351,28 +385,30 @@ int drm_open_any_master(void)
 }
 
 /**
- * drm_open_any_render:
+ * drm_open_driver_render:
  *
- * Open an i915 drm render device node.
+ * Open a drm render device node.
  *
  * Returns:
- * The i915 drm file descriptor or -1 on error
+ * The drm file descriptor or -1 on error
  */
-int drm_open_any_render(void)
+int drm_open_driver_render(int chipset)
 {
 	static int open_count;
-	int fd = __drm_open_any_render();
+	int fd = __drm_open_driver_render(chipset);
 
-	/* no render nodes, fallback to drm_open_any() */
+	/* no render nodes, fallback to drm_open_driver() */
 	if (fd == -1)
-		return drm_open_any();
+		return drm_open_driver(chipset);
 
 	if (__sync_fetch_and_add(&open_count, 1))
 		return fd;
 
-	at_exit_drm_render_fd = __drm_open_any();
-	gem_quiescent_gpu(fd);
-	igt_install_exit_handler(quiescent_gpu_at_exit_render);
+	at_exit_drm_render_fd = __drm_open_driver(chipset);
+   if(chipset & DRIVER_INTEL){
+	   gem_quiescent_gpu(fd);
+	   igt_install_exit_handler(quiescent_gpu_at_exit_render);
+   }
 
 	return fd;
 }
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 508cc83..740aac1 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -38,6 +38,16 @@
 
 #include "intel_batchbuffer.h"
 
+#define OPEN_ANY_GPU 0x1
+#define DRIVER_INTEL 0x1 << 1
+
+// provide the deprecated drm_open_any*() calls
+#define drm_open_any() drm_open_driver(OPEN_ANY_GPU)
+#define drm_open_any_master() drm_open_driver_master(OPEN_ANY_GPU)
+#define drm_open_any_render() drm_open_driver_render(OPEN_ANY_GPU)
+#define __drm_open_any() __drm_open_driver(OPEN_ANY_GPU)
+
+
 #ifdef ANDROID
 #ifndef HAVE_MMAP64
 extern void*  __mmap2(void *, size_t, int, int, int, off_t);
@@ -71,10 +81,10 @@ static inline void *igt_mmap64(void *addr, size_t length, int prot, int flags,
 #define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1))
 
 int drm_get_card(void);
-int __drm_open_any(void);
-int drm_open_any(void);
-int drm_open_any_master(void);
-int drm_open_any_render(void);
+int drm_open_driver(int chipset);
+int drm_open_driver_master(int chipset);
+int drm_open_driver_render(int chipset);
+int __drm_open_driver(int chipset);
 
 void gem_quiescent_gpu(int fd);
 
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-07-31 20:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 20:11 [PATCH 0/5] igt: adding parameter to drm_open_any and drm_open_any_master to allow specification of non-intel GPUs Micah Fedke
2015-07-31 20:11 ` Micah Fedke [this message]
2015-08-05  8:42   ` [PATCH 1/5] lib: adding drm_open_driver() interface Daniel Vetter
2015-08-05  8:46   ` Daniel Vetter
2015-07-31 20:11 ` [PATCH 2/5] convert drm_open_any*() calls to drm_open_driver*(DRIVER_INTEL) calls with cocci Micah Fedke
2015-08-05  8:45   ` Daniel Vetter
2015-07-31 20:11 ` [PATCH 3/5] lib: remove support for deprecated drm_open_any*() calls Micah Fedke
2015-07-31 20:11 ` [PATCH 4/5] lib/tests: make kmstest_get_pipe_from_crtc_id and igt_enable_connectors generic to prepare for platform agnostic tests Micah Fedke
2015-08-05  8:49   ` Daniel Vetter
2015-07-31 20:11 ` [PATCH 5/5] tests: make drm_read platform agnostic Micah Fedke
2015-08-05  8:50   ` Daniel Vetter
2015-08-01  9:31 ` [PATCH 0/5] igt: adding parameter to drm_open_any and drm_open_any_master to allow specification of non-intel GPUs Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438373471-11798-2-git-send-email-micah.fedke@collabora.co.uk \
    --to=micah.fedke@collabora.co.uk \
    --cc=daniel@ffwll.ch \
    --cc=daniel@fooishbar.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.