[Mesa-dev] [PATCH 2/9] gallium/winsys/drm: Prepare for passing prime fds in winsys_handle

christopher.halse.rogers at canonical.com christopher.halse.rogers at canonical.com
Wed Nov 20 20:11:39 PST 2013


From: Christopher James Halse Rogers <raof at ubuntu.com>

---
 src/gallium/drivers/freedreno/freedreno_screen.c      | 5 +++++
 src/gallium/drivers/nouveau/nouveau_screen.c          | 6 ++++++
 src/gallium/include/state_tracker/drm_driver.h        | 9 ++++++---
 src/gallium/state_trackers/dri/drm/dri2.c             | 2 ++
 src/gallium/state_trackers/egl/common/native_helper.c | 1 +
 src/gallium/state_trackers/egl/x11/native_dri2.c      | 1 +
 src/gallium/winsys/i915/drm/i915_drm_buffer.c         | 6 +++++-
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c         | 6 ++++++
 src/gallium/winsys/svga/drm/vmw_screen_dri.c          | 6 ++++++
 9 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
index 20adf21..47bb6e1 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -359,6 +359,11 @@ fd_screen_bo_from_handle(struct pipe_screen *pscreen,
 	struct fd_screen *screen = fd_screen(pscreen);
 	struct fd_bo *bo;
 
+	if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+		DBG("Attempt to import unsupported handle type %d", whandle->type);
+		return NULL;
+	}
+
 	bo = fd_bo_from_name(screen->dev, whandle->handle);
 	if (!bo) {
 		DBG("ref name 0x%08x failed", whandle->handle);
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
index 5b35ee4..e453556 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.c
+++ b/src/gallium/drivers/nouveau/nouveau_screen.c
@@ -85,6 +85,12 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
 	struct nouveau_device *dev = nouveau_screen(pscreen)->device;
 	struct nouveau_bo *bo = 0;
 	int ret;
+ 
+	if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+		debug_printf("%s: attempt to import unsupported handle type %d\n",
+			     __FUNCTION__, whandle->type);
+		return NULL;		
+	}
 
 	ret = nouveau_bo_name_ref(dev, whandle->handle, &bo);
 	if (ret) {
diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h
index f9bd222..5b76d87 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -10,6 +10,8 @@ struct pipe_resource;
 
 #define DRM_API_HANDLE_TYPE_SHARED 0
 #define DRM_API_HANDLE_TYPE_KMS    1
+#define DRM_API_HANDLE_TYPE_FD     2
+
 
 /**
  * For use with pipe_screen::{texture_from_handle|texture_get_handle}.
@@ -17,9 +19,10 @@ struct pipe_resource;
 struct winsys_handle
 {
    /**
-    * Unused for texture_from_handle, always
-    * DRM_API_HANDLE_TYPE_SHARED.  Input to texture_get_handle,
-    * use TEXTURE_USAGE to select handle for kms or ipc.
+    * Input for texture_from_handle, valid values are
+    * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD.
+    * Input to texture_get_handle,
+    * to select handle for kms, flink, or prime.
     */
    unsigned type;
    /**
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index bc6ca0a..42c863b 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -265,6 +265,7 @@ dri2_drawable_process_buffers(struct dri_context *ctx,
 
       templ.format = format;
       templ.bind = bind;
+      whandle.type = DRM_API_HANDLE_TYPE_SHARED;
       whandle.handle = buf->name;
       whandle.stride = buf->pitch;
 
@@ -578,6 +579,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
 
    memset(&whandle, 0, sizeof(whandle));
    whandle.handle = name;
+   whandle.type = DRM_API_HANDLE_TYPE_SHARED;
    whandle.stride = pitch * util_format_get_blocksize(pf);
 
    img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
diff --git a/src/gallium/state_trackers/egl/common/native_helper.c b/src/gallium/state_trackers/egl/common/native_helper.c
index b578a8a..d1e1acd 100644
--- a/src/gallium/state_trackers/egl/common/native_helper.c
+++ b/src/gallium/state_trackers/egl/common/native_helper.c
@@ -427,6 +427,7 @@ drm_display_import_native_buffer(struct native_display *ndpy,
 
          memset(&wsh, 0, sizeof(wsh));
          wsh.handle = nbuf->u.drm.name;
+         wsh.type = DRM_API_HANDLE_TYPE_SHARED;
          wsh.stride = nbuf->u.drm.stride;
 
          res = screen->resource_from_handle(screen, &nbuf->u.drm.templ, &wsh);
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index 3c58979..bbd962d 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -173,6 +173,7 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf,
       }
 
       memset(&whandle, 0, sizeof(whandle));
+      whandle.type = DRM_API_HANDLE_TYPE_SHARED;
       whandle.stride = xbuf->pitch;
       whandle.handle = xbuf->name;
       dri2surf->textures[natt] = dri2dpy->base.screen->resource_from_handle(
diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
index ac66af3..38e0619 100644
--- a/src/gallium/winsys/i915/drm/i915_drm_buffer.c
+++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
@@ -95,9 +95,13 @@ i915_drm_buffer_from_handle(struct i915_winsys *iws,
                             unsigned *stride)
 {
    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
-   struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer);
+   struct i915_drm_buffer *buf;
    uint32_t tile = 0, swizzle = 0;
 
+   if (whandle->type != DRM_API_HANDLE_TYPE_SHARED)
+      return NULL;
+
+   buf = CALLOC_STRUCT(i915_drm_buffer);
    if (!buf)
       return NULL;
 
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
index 19e2715..44fb503 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
@@ -877,6 +877,9 @@ static struct pb_buffer *radeon_winsys_bo_from_handle(struct radeon_winsys *rws,
 
     memset(&open_arg, 0, sizeof(open_arg));
 
+    if (whandle->type != DRM_API_HANDLE_TYPE_SHARED)
+        return NULL;
+
     /* We must maintain a list of pairs <handle, bo>, so that we always return
      * the same BO for one particular handle. If we didn't do that and created
      * more than one BO for the same handle and then relocated them in a CS,
@@ -992,6 +995,9 @@ static boolean radeon_winsys_bo_get_handle(struct pb_buffer *buffer,
         whandle->handle = bo->flink;
     } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
         whandle->handle = bo->handle;
+    } else if (whandle->type == DRM_API_HANDLE_TYPE_FD) {
+        /* TODO: Implement */
+        return FALSE;
     }
 
     whandle->stride = stride;
diff --git a/src/gallium/winsys/svga/drm/vmw_screen_dri.c b/src/gallium/winsys/svga/drm/vmw_screen_dri.c
index 511cca7..6323a8a 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen_dri.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c
@@ -163,6 +163,12 @@ vmw_drm_surface_from_handle(struct svga_winsys_screen *sws,
     int ret;
     int i;
 
+    if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+        vmw_error("Attempt to import unknown handle type %d\n",
+                  whandle->type);
+        return NULL;
+    }
+
     /**
      * The vmware device specific handle is the hardware SID.
      * FIXME: We probably want to move this to the ioctl implementations.
-- 
1.8.4.3



More information about the mesa-dev mailing list