drm/amdgpu: introduce struct amdgpu_bo_user
Subsystems (3)
PATCH 1/3 drm/amdgpu: introduce struct amdgpu_bo_user
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.
--- 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(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +44 -0
@@ -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
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9 -0
@@ -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);
include/uapi/drm/amdgpu_drm.h +2 -0
@@ -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 */
Signature · 6 lines
2.30.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/amdgpu: use amdgpu_bo_create_user() for gem object
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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -1
@@ -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 ;
Signature · 6 lines
2.30.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/amdgpu: use tiling_flags of struct amdgpu_bo_user
In reply to Nirmoy DasThis flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.
--- 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +17 -2
@@ -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; }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -1
@@ -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;
Signature · 6 lines
2.30.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 3/3] drm/amdgpu: use tiling_flags of struct amdgpu_bo_user
Am 05.03.21 um 13:56 schrieb Nirmoy Das:
Quoted 14 lines
This flag is only needed for BOs created by
amdgpu_gem_object_create(), so we can removetiling_flagsfrom the base class.Signed-off-by Nirmoy Das <[email protected]>--- 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(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, · line 1195
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0@@ -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.
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +14
-2+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; }/** drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 96
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1@@ -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.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/3] drm/amdgpu: use tiling_flags of struct amdgpu_bo_user
Quoted 10 lines · Christian König
Am 05.03.21 um 13:56 schrieb Nirmoy Das:
Quoted 9 lines
This flag is only needed for BOs created by
amdgpu_gem_object_create(), so we can removetiling_flagsfrom the base class.Signed-off-by Nirmoy Das <[email protected]>---
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(-)
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, · line 1195
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0@@ -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_USERflag, just test TTMs BO type.
Okay I will remove AMDGPU_GEM_CREATE_USER flag completely.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0+ 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 @@ intamdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)*/
voidamdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
{
+ structamdgpu_bo_user*ubo;
+
+ if (!(bo->flags &AMDGPU_GEM_CREATE_USER)) {
+ DRM_ERROR("can not gettiling_flagsfor 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;
}
/**drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0@@ -91,7 +91,6 @@ struct amdgpu_bo { struct ttm_bo_kmap_obj kmap;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 96
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1u64 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
Quoted 4 lines
Thanks,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 05.03.21 um 13:56 schrieb Nirmoy Das:
Quoted 50 lines
Implement a new struct
amdgpu_bo_useras subclass of structamdgpu_boand a function to createdamdgpu_bo_userbo with a flag to identify the owner.Signed-off-by Nirmoy Das <[email protected]>--- 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(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +31
-0@@ -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,
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 742
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10
-0+ 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.
Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0+ +return r; +}/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9
-0@@ -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);include/uapi/drm/amdgpu_drm.h +0
-0
include/uapi/drm/amdgpu_drm.h extern "C" { · line 148
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2
-0@@ -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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel