[Intel-gfx] [i-g-t PATCH v1 07/14] lib: Map dumb buffers

Tomeu Vizoso tomeu.vizoso at collabora.com
Wed Mar 2 14:00:14 UTC 2016


If a buffer object is dumb, call DRM_IOCTL_MODE_MAP_DUMB when mapping
it. Also, don't call DRM_IOCTL_I915_GEM_SET_DOMAIN on dumb buffers.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
---

 lib/igt_fb.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 3e76a419b3ee..cd1605308308 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -984,7 +984,20 @@ static void destroy_cairo_surface__gtt(void *arg)
 
 static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
 {
-	void *ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
+	void *ptr;
+
+	if (fb->is_dumb) {
+		struct drm_mode_map_dumb arg = {};
+
+		arg.handle = fb->gem_handle;
+
+		do_ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
+
+		ptr = mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, arg.offset);
+		igt_assert(ptr != MAP_FAILED);
+	} else
+		ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
+				    PROT_READ | PROT_WRITE);
 
 	fb->cairo_surface =
 		cairo_image_surface_create_for_data(ptr,
@@ -1006,8 +1019,9 @@ static cairo_surface_t *get_cairo_surface(int fd, struct igt_fb *fb)
 			create_cairo_surface__gtt(fd, fb);
 	}
 
-	gem_set_domain(fd, fb->gem_handle,
-		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	if (!fb->is_dumb)
+		gem_set_domain(fd, fb->gem_handle, I915_GEM_DOMAIN_CPU,
+			       I915_GEM_DOMAIN_CPU);
 
 	igt_assert(cairo_surface_status(fb->cairo_surface) == CAIRO_STATUS_SUCCESS);
 	return fb->cairo_surface;
-- 
2.5.0



More information about the Intel-gfx mailing list