Am 05.03.21 um 13:56 schrieb Nirmoy Das:
Implement a new struct amdgpu_bo_user as subclass of
struct amdgpu_bo and a function to created amdgpu_bo_user
bo with a flag to identify the owner.

Signed-off-by: Nirmoy Das <nirmoy....@amd.com>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 44 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  9 +++++
  include/uapi/drm/amdgpu_drm.h              |  2 +
  3 files changed, 55 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 745393472564..f21679f38383 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -699,6 +699,50 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
        return r;
  }
+/**
+ * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @ubo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be used by user application;
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+                    struct amdgpu_bo_param *bp,
+                    struct amdgpu_bo_user **ubo_ptr)
+{
+       struct amdgpu_bo *bo_ptr;
+       u64 flags = bp->flags;
+       int r;
+
+       bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+       bp->flags = bp->flags | AMDGPU_GEM_CREATE_USER;
+       bp->bo_ptr_size = sizeof(struct amdgpu_bo);
+       r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
+       if (r)
+               return r;
+
+       *ubo_ptr = (struct amdgpu_bo_user *)bo_ptr;
+       if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags & AMD_IS_APU)) {
+               if (!bp->resv)
+                       WARN_ON(dma_resv_lock((*ubo_ptr)->bo.tbo.base.resv,
+                                                       NULL));
+
+               r = amdgpu_bo_create_shadow(adev, bp->size, bo_ptr);
+
+               if (!bp->resv)
+                       dma_resv_unlock((*ubo_ptr)->bo.tbo.base.resv);
+
+               if (r)
+                       ttm_bo_put(&(*ubo_ptr)->bo.tbo);
+       }

The shadows handling is specific for VM BOs and not necessary for BOs which are used by userspace.

Regards,
Christian.

+
+       return r;
+}
  /**
   * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
   * @bo: pointer to the buffer object
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 848dc0a017dd..332e269c3fd1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -114,6 +114,12 @@ struct amdgpu_bo {
        struct kgd_mem                  *kfd_bo;
  };
+struct amdgpu_bo_user {
+       struct amdgpu_bo                bo;
+       u64                             tiling_flags;
+
+};
+
  static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object 
*tbo)
  {
        return container_of(tbo, struct amdgpu_bo, tbo);
@@ -257,6 +263,9 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
  int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
                               uint64_t offset, uint64_t size, uint32_t domain,
                               struct amdgpu_bo **bo_ptr, void **cpu_addr);
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+                    struct amdgpu_bo_param *bp,
+                    struct amdgpu_bo_user **ubo_ptr);
  void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
                           void **cpu_addr);
  int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 8b832f7458f2..9b9a4ac6f00f 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -141,6 +141,8 @@ extern "C" {
   * accessing it with various hw blocks
   */
  #define AMDGPU_GEM_CREATE_ENCRYPTED           (1 << 10)
+/* Flag that indicates the BO is created for userspace */
+#define AMDGPU_GEM_CREATE_USER                 (1 << 11)
struct drm_amdgpu_gem_create_in {
        /** the requested memory size */

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to