drm/amdgpu: implement amdgpu_gem_map_(attach/detach)
authorChristian König <christian.koenig@amd.com>
Fri, 16 Feb 2018 12:16:11 +0000 (13:16 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 20 Feb 2018 19:40:03 +0000 (14:40 -0500)
Instead of the pin/unpin callback implement the attach/detach ones.

Functional identical, but allows us access to the attachment.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c

index c6123e58658919447dea68a6e435b4cf551a35d9..1ac81be374dd5d9d84f0a814864525df99a821db 100644 (file)
@@ -393,8 +393,6 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
                                        int flags);
 struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
                                            struct dma_buf *dma_buf);
-int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
-void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
 struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
 void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
 void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
index 6c8ae59d4d9499920e7414e3141dd2ef621ddfc8..88ec9280a67aab148810347f5cf6f9d768d3fe52 100644 (file)
@@ -885,8 +885,6 @@ static struct drm_driver kms_driver = {
        .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
        .gem_prime_export = amdgpu_gem_prime_export,
        .gem_prime_import = amdgpu_gem_prime_import,
-       .gem_prime_pin = amdgpu_gem_prime_pin,
-       .gem_prime_unpin = amdgpu_gem_prime_unpin,
        .gem_prime_res_obj = amdgpu_gem_prime_res_obj,
        .gem_prime_get_sg_table = amdgpu_gem_prime_get_sg_table,
        .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
index 2a8d980d17f6ab6e0a37325088c92c1a63cfd2d9..f6d7f6404a07d19d27257156761d598c9ea0b6e8 100644 (file)
@@ -113,49 +113,65 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
        return &bo->gem_base;
 }
 
-int amdgpu_gem_prime_pin(struct drm_gem_object *obj)
+static int amdgpu_gem_map_attach(struct dma_buf *dma_buf,
+                                struct device *target_dev,
+                                struct dma_buf_attachment *attach)
 {
+       struct drm_gem_object *obj = dma_buf->priv;
        struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
-       long ret = 0;
+       long r;
 
-       ret = amdgpu_bo_reserve(bo, false);
-       if (unlikely(ret != 0))
-               return ret;
+       r = drm_gem_map_attach(dma_buf, target_dev, attach);
+       if (r)
+               return r;
+
+       r = amdgpu_bo_reserve(bo, false);
+       if (unlikely(r != 0))
+               goto error_detach;
 
        /*
         * Wait for all shared fences to complete before we switch to future
         * use of exclusive fence on this prime shared bo.
         */
-       ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
-                                                 MAX_SCHEDULE_TIMEOUT);
-       if (unlikely(ret < 0)) {
-               DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
-               amdgpu_bo_unreserve(bo);
-               return ret;
+       r = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+                                               MAX_SCHEDULE_TIMEOUT);
+       if (unlikely(r < 0)) {
+               DRM_DEBUG_PRIME("Fence wait failed: %li\n", r);
+               goto error_unreserve;
        }
 
        /* pin buffer into GTT */
-       ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
-       if (likely(ret == 0))
+       r = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+       if (likely(r == 0))
                bo->prime_shared_count++;
 
+error_unreserve:
        amdgpu_bo_unreserve(bo);
-       return ret;
+
+error_detach:
+       if (r)
+               drm_gem_map_detach(dma_buf, attach);
+       return r;
 }
 
-void amdgpu_gem_prime_unpin(struct drm_gem_object *obj)
+static void amdgpu_gem_map_detach(struct dma_buf *dma_buf,
+                                 struct dma_buf_attachment *attach)
 {
+       struct drm_gem_object *obj = dma_buf->priv;
        struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
        int ret = 0;
 
        ret = amdgpu_bo_reserve(bo, true);
        if (unlikely(ret != 0))
-               return;
+               goto error;
 
        amdgpu_bo_unpin(bo);
        if (bo->prime_shared_count)
                bo->prime_shared_count--;
        amdgpu_bo_unreserve(bo);
+
+error:
+       drm_gem_map_detach(dma_buf, attach);
 }
 
 struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)
@@ -194,8 +210,8 @@ static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,
 }
 
 static const struct dma_buf_ops amdgpu_dmabuf_ops = {
-       .attach = drm_gem_map_attach,
-       .detach = drm_gem_map_detach,
+       .attach = amdgpu_gem_map_attach,
+       .detach = amdgpu_gem_map_detach,
        .map_dma_buf = drm_gem_map_dma_buf,
        .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,