From 69c200b0bb39bb585f46fa5c779c97166779cd93 Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Thu, 24 Oct 2013 15:19:32 +0100 Subject: [PATCH] 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 --- lib/drmtest.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/drmtest.h | 1 + 2 files changed, 59 insertions(+) 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; diff --git a/lib/drmtest.h b/lib/drmtest.h index 609e7d84..f5e27081 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -50,6 +50,7 @@ drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd, int drm_get_card(void); int drm_open_any(void); +int drm_open_any_render(void); void gem_quiescent_gpu(int fd);