Am 08.03.21 um 16:37 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 | 28 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 14 +++++++++++
  2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d32379cbad89..abfeb8304894 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -695,6 +695,34 @@ 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;
+       int r;
+
+       bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+       bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
+       r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
+       if (r)
+               return r;
+
+       *ubo_ptr = amdgpu_bo_to_amdgpu_bo_user(bo_ptr);
+       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 8e2b556f0b7b..fd30221266c8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -37,6 +37,8 @@
  #define AMDGPU_BO_INVALID_OFFSET      LONG_MAX
  #define AMDGPU_BO_MAX_PLACEMENTS      3
+#define amdgpu_bo_to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)

Mhm, the name could be improved, but apart from that the patch looks good to me.

Christian.

+
  struct amdgpu_bo_param {
        unsigned long                   size;
        int                             byte_align;
@@ -112,6 +114,15 @@ struct amdgpu_bo {
        struct kgd_mem                  *kfd_bo;
  };
+struct amdgpu_bo_user {
+       struct amdgpu_bo                bo;
+       u64                             tiling_flags;
+       u64                             metadata_flags;
+       void                            *metadata;
+       u32                             metadata_size;
+
+};
+
  static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object 
*tbo)
  {
        return container_of(tbo, struct amdgpu_bo, tbo);
@@ -255,6 +266,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);

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to