diff mbox series

[i-g-t,2/5] lib/igt_fb: Call dumb_destroy ioctl in case of dumb buffers

Message ID 20180906000350.2478-3-drawat@vmware.com (mailing list archive)
State New, archived
Headers show
Series vmwgfx as a new driver for igt-gpu-tools | expand

Commit Message

Deepak Singh Rawat Sept. 6, 2018, 12:03 a.m. UTC
vmwgfx does not support GEM interface so calling gem_close on vmwgfx
results in error. Call dumb destroy IOCTL in case have dumb buffer.

Signed-off-by: Deepak Rawat <drawat@vmware.com>
---
 lib/igt_fb.c  |  5 ++++-
 lib/igt_kms.c | 15 +++++++++++++++
 lib/igt_kms.h |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

Comments

Chris Wilson Sept. 6, 2018, 8:49 a.m. UTC | #1
Quoting Deepak Rawat (2018-09-06 01:03:47)
> vmwgfx does not support GEM interface so calling gem_close on vmwgfx
> results in error. Call dumb destroy IOCTL in case have dumb buffer.
> 
> Signed-off-by: Deepak Rawat <drawat@vmware.com>
> ---
>  lib/igt_fb.c  |  5 ++++-
>  lib/igt_kms.c | 15 +++++++++++++++
>  lib/igt_kms.h |  1 +
>  3 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index ae71d967..ba995a1a 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -1920,7 +1920,10 @@ void igt_remove_fb(int fd, struct igt_fb *fb)
>  
>         cairo_surface_destroy(fb->cairo_surface);
>         do_or_die(drmModeRmFB(fd, fb->fb_id));
> -       gem_close(fd, fb->gem_handle);
> +       if (fb->is_dumb)
> +               kmstest_dumb_destroy(fd, fb->gem_handle);
> +       else
> +               gem_close(fd, fb->gem_handle);
>         fb->fb_id = 0;
>  }
>  
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 62d84684..9e9414cf 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -639,6 +639,21 @@ void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
>         return ptr;
>  }
>  
> +/**
> + * kmstest_dumb_destroy:
> + * @fd: Opened drm file descriptor
> + * @handle: Offset in the file referred to by fd
> + */
> +void kmstest_dumb_destroy(int fd, uint32_t handle)
> +{
> +       struct drm_mode_destroy_dumb arg = {};
> +
> +       igt_assert_neq(handle, 0);

Don't bother doing the kernel's job for it. Abusing the ioctl iface is
the name of the game.

> +       arg.handle = handle;
> +       do_ioctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);

struct drm_mode_destroy_dumb arg = { handle };

Try never to use do_ioctl() if you ever want to debug an error.
-Chris
diff mbox series

Patch

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index ae71d967..ba995a1a 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1920,7 +1920,10 @@  void igt_remove_fb(int fd, struct igt_fb *fb)
 
 	cairo_surface_destroy(fb->cairo_surface);
 	do_or_die(drmModeRmFB(fd, fb->fb_id));
-	gem_close(fd, fb->gem_handle);
+	if (fb->is_dumb)
+		kmstest_dumb_destroy(fd, fb->gem_handle);
+	else
+		gem_close(fd, fb->gem_handle);
 	fb->fb_id = 0;
 }
 
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 62d84684..9e9414cf 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -639,6 +639,21 @@  void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
 	return ptr;
 }
 
+/**
+ * kmstest_dumb_destroy:
+ * @fd: Opened drm file descriptor
+ * @handle: Offset in the file referred to by fd
+ */
+void kmstest_dumb_destroy(int fd, uint32_t handle)
+{
+	struct drm_mode_destroy_dumb arg = {};
+
+	igt_assert_neq(handle, 0);
+
+	arg.handle = handle;
+	do_ioctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
+}
+
 /*
  * Returns: the previous mode, or KD_GRAPHICS if no /dev/tty0 was
  * found and nothing was done.
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 3a12f278..bd0c0f09 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -222,6 +222,7 @@  uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
 
 void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
 			      unsigned prot);
+void kmstest_dumb_destroy(int fd, uint32_t handle);
 void kmstest_wait_for_pageflip(int fd);
 unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
 void igt_assert_plane_visible(int fd, enum pipe pipe, bool visibility);