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.das@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); + } + + 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 */
GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.
Signed-off-by: Nirmoy Das nirmoy.das@amd.com --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 8e9b8a6e6ef0..9d2b55eb31c2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, struct drm_gem_object **obj) { struct amdgpu_bo *bo; + struct amdgpu_bo_user *ubo; struct amdgpu_bo_param bp; int r;
@@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, retry: bp.flags = flags; bp.domain = initial_domain; - r = amdgpu_bo_create(adev, &bp, &bo); + r = amdgpu_bo_create_user(adev, &bp, &ubo); if (r) { if (r != -ERESTARTSYS) { if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) { @@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, } return r; } + bo = &ubo->bo; *obj = &bo->tbo.base;
return 0;
This flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.
Signed-off-by: Nirmoy Das nirmoy.das@amd.com --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 +++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 - 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index f21679f38383..c19cb6863966 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1190,12 +1190,19 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) { struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); + struct amdgpu_bo_user *ubo; + + if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) { + DRM_ERROR("can not set tiling_flags for a non-amdgpu_bo_user type BO\n"); + return -EINVAL; + }
if (adev->family <= AMDGPU_FAMILY_CZ && AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6) return -EINVAL;
- bo->tiling_flags = tiling_flags; + ubo = container_of((bo), struct amdgpu_bo_user, bo); + ubo->tiling_flags = tiling_flags; return 0; }
@@ -1209,10 +1216,18 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) */ void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags) { + struct amdgpu_bo_user *ubo; + + if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) { + DRM_ERROR("can not get tiling_flags for a non-amdgpu_bo_user type BO\n"); + return; + } + dma_resv_assert_held(bo->tbo.base.resv); + ubo = container_of((bo), struct amdgpu_bo_user, bo);
if (tiling_flags) - *tiling_flags = bo->tiling_flags; + *tiling_flags = ubo->tiling_flags; }
/** diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 332e269c3fd1..7164c0799534 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h @@ -91,7 +91,6 @@ struct amdgpu_bo { struct ttm_bo_kmap_obj kmap; u64 flags; unsigned pin_count; - u64 tiling_flags; u64 metadata_flags; void *metadata; u32 metadata_size;
Am 05.03.21 um 13:56 schrieb Nirmoy Das:
This flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.
Signed-off-by: Nirmoy Das nirmoy.das@amd.com
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 +++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 - 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index f21679f38383..c19cb6863966 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1190,12 +1190,19 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) { struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
- struct amdgpu_bo_user *ubo;
- if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) {
You don't need the AMDGPU_GEM_CREATE_USER flag, just test TTMs BO type.
DRM_ERROR("can not set tiling_flags for a non-amdgpu_bo_user type BO\n");
return -EINVAL;
}
if (adev->family <= AMDGPU_FAMILY_CZ && AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6) return -EINVAL;
- bo->tiling_flags = tiling_flags;
- ubo = container_of((bo), struct amdgpu_bo_user, bo);
- ubo->tiling_flags = tiling_flags; return 0; }
@@ -1209,10 +1216,18 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) */ void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags) {
struct amdgpu_bo_user *ubo;
if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) {
DRM_ERROR("can not get tiling_flags for a non-amdgpu_bo_user type BO\n");
return;
}
dma_resv_assert_held(bo->tbo.base.resv);
ubo = container_of((bo), struct amdgpu_bo_user, bo);
if (tiling_flags)
*tiling_flags = bo->tiling_flags;
*tiling_flags = ubo->tiling_flags;
}
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 332e269c3fd1..7164c0799534 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h @@ -91,7 +91,6 @@ struct amdgpu_bo { struct ttm_bo_kmap_obj kmap; u64 flags; unsigned pin_count;
- u64 tiling_flags; u64 metadata_flags; void *metadata; u32 metadata_size;
BTW: The metadata can be moved to the user BOs as well!
Thanks, Christian.
On 3/5/21 2:08 PM, Christian König wrote:
Am 05.03.21 um 13:56 schrieb Nirmoy Das:
This flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.
Signed-off-by: Nirmoy Das nirmoy.das@amd.com
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 +++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 - 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index f21679f38383..c19cb6863966 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1190,12 +1190,19 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) { struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); + struct amdgpu_bo_user *ubo;
+ if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) {
You don't need the AMDGPU_GEM_CREATE_USER flag, just test TTMs BO type.
Okay I will remove AMDGPU_GEM_CREATE_USER flag completely.
+ DRM_ERROR("can not set tiling_flags for a non-amdgpu_bo_user type BO\n"); + return -EINVAL; + } if (adev->family <= AMDGPU_FAMILY_CZ && AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6) return -EINVAL; - bo->tiling_flags = tiling_flags; + ubo = container_of((bo), struct amdgpu_bo_user, bo); + ubo->tiling_flags = tiling_flags; return 0; } @@ -1209,10 +1216,18 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) */ void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags) { + struct amdgpu_bo_user *ubo;
+ if (!(bo->flags & AMDGPU_GEM_CREATE_USER)) { + DRM_ERROR("can not get tiling_flags for a non-amdgpu_bo_user type BO\n"); + return; + }
dma_resv_assert_held(bo->tbo.base.resv); + ubo = container_of((bo), struct amdgpu_bo_user, bo); if (tiling_flags) - *tiling_flags = bo->tiling_flags; + *tiling_flags = ubo->tiling_flags; } /** diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 332e269c3fd1..7164c0799534 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h @@ -91,7 +91,6 @@ struct amdgpu_bo { struct ttm_bo_kmap_obj kmap; u64 flags; unsigned pin_count; - u64 tiling_flags; u64 metadata_flags; void *metadata; u32 metadata_size;
BTW: The metadata can be moved to the user BOs as well!
I resend with metadata members moved to the user BO.
Thanks,
Nirmoy
Thanks, Christian.
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.das@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,
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);struct amdgpu_bo_user **ubo_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@lists.freedesktop.org