summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2013-10-24 15:19:32 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2013-10-28 11:00:07 +0000
commit69c200b0bb39bb585f46fa5c779c97166779cd93 (patch)
tree62d5971d31efc66a3d078834ce964cfa0515d94c /lib/drmtest.c
parent8329acb752721ad93dab70624b136f1befd4be3f (diff)
lib: Add a drm_open_any_render() that will try to use render nodes
I was fedup with having to run my tests as root and not being able to use my usual setup for tests that only exercise the GT part of the GPU. Render nodes to the rescue! Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3b80920b..8164ef93 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -222,6 +222,35 @@ static int __drm_open_any(void)
return fd;
}
+static int __drm_open_any_render(void)
+{
+ char *name;
+ int i, fd;
+
+ for (i = 128; i < (128 + 16); i++) {
+ int ret;
+
+ ret = asprintf(&name, "/dev/dri/renderD%u", i);
+ igt_assert(ret != -1);
+
+ fd = open(name, O_RDWR);
+ free(name);
+
+ if (fd == -1)
+ continue;
+
+ if (!is_intel(fd)) {
+ close(fd);
+ fd = -1;
+ continue;
+ }
+
+ return fd;
+ }
+
+ return fd;
+}
+
static void quiescent_gpu_at_exit(int sig)
{
int fd;
@@ -233,6 +262,17 @@ static void quiescent_gpu_at_exit(int sig)
}
}
+static void quiescent_gpu_at_exit_render(int sig)
+{
+ int fd;
+
+ fd = __drm_open_any_render();
+ if (fd >= 0) {
+ gem_quiescent_gpu(fd);
+ close(fd);
+ }
+}
+
int drm_open_any(void)
{
static int open_count;
@@ -249,6 +289,24 @@ int drm_open_any(void)
return fd;
}
+int drm_open_any_render(void)
+{
+ static int open_count;
+ int fd = __drm_open_any_render();
+
+ /* no render nodes, fallback to drm_open_any() */
+ if (fd == -1)
+ return drm_open_any();
+
+ if (__sync_fetch_and_add(&open_count, 1))
+ return fd;
+
+ gem_quiescent_gpu(fd);
+ igt_install_exit_handler(quiescent_gpu_at_exit_render);
+
+ return fd;
+}
+
int __gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling st;