drm/amdgpu: parameterize ttm BO destroy callback
Subsystems (2)
PATCH 1/3 drm/amdgpu: parameterize ttm BO destroy callback
Make provision to pass different ttm BO destroy callback while creating a amdgpu_bo.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +24 -4
@@ -522,15 +522,17 @@ bool amdgpu_bo_support_uswc(u64 bo_flags)* @adev: amdgpu device object * @bp: parameters to be used for the buffer object * @bo_ptr: pointer to the buffer object pointer +* @destroy: ttm bo destroy callback * -* Creates an &amdgpu_bo buffer object. +* Creates an &amdgpu_bo buffer object with a specified ttm bo destroy callback. * * Returns: * 0 for success or a negative error code on failure. */ -int amdgpu_bo_create (struct amdgpu_device *adev, +static int amdgpu_bo_do_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp, -struct amdgpu_bo **bo_ptr) +struct amdgpu_bo **bo_ptr, +void (*destroy)(struct ttm_buffer_object *)) {struct ttm_operation_ctx ctx = { .interruptible = (bp->type != ttm_bo_type_kernel),
@@ -594,7 +596,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, bp->type, &bo->placement, page_align, &ctx,NULL , - bp->resv, &amdgpu_bo_destroy); + bp->resv, destroy);if (unlikely (r !=0 ))return r;
@@ -638,6 +640,24 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } +/** +* amdgpu_bo_create - create an &amdgpu_bo buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @bo_ptr: pointer to the buffer object pointer +* +* Creates an &amdgpu_bo buffer object. +* +* Returns: +* 0 for success or a negative error code on failure. +*/ +int amdgpu_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr) +{ +return amdgpu_bo_do_create (adev, bp, bo_ptr, &amdgpu_bo_destroy); +} +/** * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object * @adev: amdgpu device object
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/3 drm/amdgpu: use separate ttm destroy callback
Use different ttm destroy callback for different type of amdgpu BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 47 ++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +35 -12
@@ -73,11 +73,9 @@ static void amdgpu_bo_subtract_pin_size(struct amdgpu_bo *bo) } } -static void amdgpu_bo_destroy (struct ttm_buffer_object *tbo) +static void amdgpu_bo_destroy_base (struct ttm_buffer_object *tbo) { -struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); -struct amdgpu_bo_user *ubo;if (bo->tbo.pin_count >0 )amdgpu_bo_subtract_pin_size (bo);
@@ -87,18 +85,40 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)if (bo->tbo.base.import_attach)drm_prime_gem_destroy (&bo->tbo.base, bo->tbo.sg);drm_gem_object_release (&bo->tbo.base); +amdgpu_bo_unref (&bo->parent); +} + +static void amdgpu_bo_destroy (struct ttm_buffer_object *tbo) +{ +struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); + +amdgpu_bo_destroy_base (tbo); +kvfree (bo); +} + +static void amdgpu_bo_user_destroy (struct ttm_buffer_object *tbo) +{ +struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); +struct amdgpu_bo_user *ubo; + +amdgpu_bo_destroy_base (tbo); + ubo =to_amdgpu_bo_user (bo); +kfree (ubo->metadata); +kvfree (bo); +} + +static void amdgpu_bo_vm_destroy (struct ttm_buffer_object *tbo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev); +struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); + +amdgpu_bo_destroy_base (tbo);/* in case amdgpu_device_recover_vram got NULL of bo->parent */ if (!list_empty (&bo->shadow_list)) {mutex_lock (&adev->shadow_list_lock);list_del_init (&bo->shadow_list);mutex_unlock (&adev->shadow_list_lock); } -amdgpu_bo_unref (&bo->parent); - -if (bo->tbo.type != ttm_bo_type_kernel) { - ubo =to_amdgpu_bo_user (bo); -kfree (ubo->metadata); - }kvfree (bo); }
@@ -115,8 +135,11 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)*/ bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo) { -if (bo->destroy == &amdgpu_bo_destroy) +if (bo->destroy == &amdgpu_bo_destroy || + bo->destroy == &amdgpu_bo_user_destroy || + bo->destroy == &amdgpu_bo_vm_destroy)return true; +return false; }
@@ -678,7 +701,7 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,int r; bp->bo_ptr_size =sizeof (struct amdgpu_bo_user ); - r =amdgpu_bo_create (adev, bp, &bo_ptr); + r =amdgpu_bo_do_create (adev, bp, &bo_ptr, &amdgpu_bo_user_destroy);if (r)return r;
@@ -709,7 +732,7 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev,* num of amdgpu_vm_pt entries. */ BUG_ON (bp->bo_ptr_size <sizeof (struct amdgpu_bo_vm )); - r =amdgpu_bo_create (adev, bp, &bo_ptr); + r =amdgpu_bo_do_create (adev, bp, &bo_ptr, &amdgpu_bo_vm_destroy);if (r)return r;
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: move shadow_list to amdgpu_bo_vm
In reply to Nirmoy DasMove shadow_list to struct amdgpu_bo_vm as shadow BOs are part of PT/PD BOs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 13 +++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 6 ++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -2
@@ -4063,6 +4063,7 @@ static int amdgpu_device_recover_vram(struct amdgpu_device *adev) {struct dma_fence *fence =NULL , *next =NULL ;struct amdgpu_bo *shadow; +struct amdgpu_bo_vm *vmbo;long r =1 , tmo;if (amdgpu_sriov_runtime (adev))
@@ -4072,8 +4073,8 @@ static int amdgpu_device_recover_vram(struct amdgpu_device *adev)dev_info (adev->dev,"recover vram bo from shadow start\n" );mutex_lock (&adev->shadow_list_lock); -list_for_each_entry (shadow, &adev->shadow_list, shadow_list) { - +list_for_each_entry (vmbo, &adev->shadow_list, shadow_list) { + shadow = &vmbo->bo;/* No need to recover an evicted BO */ if (shadow->tbo.mem.mem_type != TTM_PL_TT || shadow->tbo.mem.start == AMDGPU_BO_INVALID_OFFSET ||
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7 -6
@@ -111,12 +111,13 @@ static void amdgpu_bo_vm_destroy(struct ttm_buffer_object *tbo) {struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); +struct amdgpu_bo_vm *vmbo =to_amdgpu_bo_vm (bo);amdgpu_bo_destroy_base (tbo);/* in case amdgpu_device_recover_vram got NULL of bo->parent */ -if (!list_empty (&bo->shadow_list)) { +if (!list_empty (&vmbo->shadow_list)) {mutex_lock (&adev->shadow_list_lock); -list_del_init (&bo->shadow_list); +list_del_init (&vmbo->shadow_list);mutex_unlock (&adev->shadow_list_lock); }
@@ -594,7 +595,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,if (bo ==NULL )return -ENOMEM ;drm_gem_private_object_init (adev_to_drm (adev), &bo->tbo.base, size); -INIT_LIST_HEAD (&bo->shadow_list); bo->vm_bo =NULL ; bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain : bp->domain;
@@ -737,6 +737,7 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev,return r; *vmbo_ptr =to_amdgpu_bo_vm (bo_ptr); +INIT_LIST_HEAD (&(*vmbo_ptr)->shadow_list);return r; }
@@ -781,12 +782,12 @@ int amdgpu_bo_validate(struct amdgpu_bo *bo)* * Insert a BO to the shadow list. */ -void amdgpu_bo_add_to_shadow_list (struct amdgpu_bo *bo) +void amdgpu_bo_add_to_shadow_list (struct amdgpu_bo_vm *vmbo) { -struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +struct amdgpu_device *adev =amdgpu_ttm_adev (vmbo->bo.tbo.bdev);mutex_lock (&adev->shadow_list_lock); -list_add_tail (&bo->shadow_list, &adev->shadow_list); +list_add_tail (&vmbo->shadow_list, &adev->shadow_list);mutex_unlock (&adev->shadow_list_lock); }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -4
@@ -108,9 +108,6 @@ struct amdgpu_bo {#ifdef CONFIG_MMU_NOTIFIER struct mmu_interval_notifier notifier;#endif - -struct list_head shadow_list; -struct kgd_mem *kfd_bo; };
@@ -126,6 +123,7 @@ struct amdgpu_bo_user {struct amdgpu_bo_vm {struct amdgpu_bo bo;struct amdgpu_bo *shadow; +struct list_head shadow_list;struct amdgpu_vm_bo_base entries[]; };
@@ -332,7 +330,7 @@ u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo);int amdgpu_bo_validate (struct amdgpu_bo *bo);void amdgpu_bo_get_memory (struct amdgpu_bo *bo,uint64_t *vram_mem,uint64_t *gtt_mem,uint64_t *cpu_mem); -void amdgpu_bo_add_to_shadow_list (struct amdgpu_bo *bo); +void amdgpu_bo_add_to_shadow_list (struct amdgpu_bo_vm *vmbo);int amdgpu_bo_restore_shadow (struct amdgpu_bo *shadow,struct dma_fence **fence); uint32_t amdgpu_bo_get_preferred_pin_domain(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -936,7 +936,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, } (*vmbo)->shadow->parent =amdgpu_bo_ref (bo); -amdgpu_bo_add_to_shadow_list ((*vmbo)->shadow); +amdgpu_bo_add_to_shadow_list ((*vmbo));return 0 ; }
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c bool amdgpu_bo_support_uswc(u64 bo_flags)
Quoted 13 lines · Nirmoy Das
Make provision to pass different ttm BO destroy callback while creating a
amdgpu_bo.Signed-off-by Nirmoy Das <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -522,15 +522,17 @@ bool amdgpu_bo_support_uswc(u64 bo_flags)
copy-paste typo : Need to replace function header amdgpu_bo_create -> amdgpu_bo_do_create.
Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +17
-4* @adev: amdgpu device object * @bp: parameters to be used for the buffer object * @bo_ptr: pointer to the buffer object pointer +* @destroy: ttm bo destroy callback * -* Creates an &amdgpu_bo buffer object. +* Creates an &amdgpu_bo buffer object with a specified ttm bo destroy callback. * * Returns: * 0 for success or a negative error code on failure. */ -int amdgpu_bo_create (struct amdgpu_device *adev, +static int amdgpu_bo_do_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp, -struct amdgpu_bo **bo_ptr) +struct amdgpu_bo **bo_ptr, +void (*destroy)(struct ttm_buffer_object *)) {struct ttm_operation_ctx ctx = { .interruptible = (bp->type != ttm_bo_type_kernel),@@ -594,7 +596,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, bp->type, &bo->placement, page_align, &ctx,NULL , - bp->resv, &amdgpu_bo_destroy); + bp->resv, destroy);if (unlikely (r !=0 ))return r;@@ -638,6 +640,24 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } +/** +* amdgpu_bo_create - create an &amdgpu_bo buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @bo_ptr: pointer to the buffer object pointer +* +* Creates an &amdgpu_bo buffer object. +* +* Returns: +* 0 for success or a negative error code on failure. +*/
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 663
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7
-0+int amdgpu_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr) +{ +return amdgpu_bo_do_create (adev, bp, bo_ptr, &amdgpu_bo_destroy); +} +/** * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object * @adev: amdgpu device object
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 14.06.21 um 16:32 schrieb Nirmoy Das:
Quoted 16 lines
Make provision to pass different ttm BO destroy callback while creating a
amdgpu_bo.Signed-off-by Nirmoy Das <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -522,15 +522,17 @@ bool amdgpu_bo_support_uswc(u64 bo_flags)* @adev: amdgpu device object * @bp: parameters to be used for the buffer object * @bo_ptr: pointer to the buffer object pointer
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c bool amdgpu_bo_support_uswc(u64 bo_flags) · line 532
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-2+* @destroy: ttm bo destroy callback * -* Creates an &amdgpu_bo buffer object. +* Creates an &amdgpu_bo buffer object with a specified ttm bo destroy callback. * * Returns: * 0 for success or a negative error code on failure. */ -int amdgpu_bo_create(struct amdgpu_device *adev, +static int amdgpu_bo_do_create(struct amdgpu_device *adev,
Please don't. Rather expose an amdgpu_vm_bo_create function.
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c bool amdgpu_bo_support_uswc(u64 bo_flags) · line 535
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1struct amdgpu_bo_param *bp, - struct amdgpu_bo **bo_ptr) + struct amdgpu_bo **bo_ptr, + void (*destroy)(struct ttm_buffer_object *))
That rather belongs into the amdgpu_bo_param structure.
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +12
-1{struct ttm_operation_ctx ctx = { .interruptible = (bp->type != ttm_bo_type_kernel),@@ -594,7 +596,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, bp->type, &bo->placement, page_align, &ctx,NULL , - bp->resv, &amdgpu_bo_destroy); + bp->resv, destroy);if (unlikely (r !=0 ))return r;@@ -638,6 +640,24 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } +/** +* amdgpu_bo_create - create an &amdgpu_bo buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @bo_ptr: pointer to the buffer object pointer +* +* Creates an &amdgpu_bo buffer object. +* +* Returns: +* 0 for success or a negative error code on failure. +*/
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 663
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7
-0+int amdgpu_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr) +{ +return amdgpu_bo_do_create (adev, bp, bo_ptr, &amdgpu_bo_destroy); +} +/** * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object * @adev: amdgpu device object
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 33 lines · Christian König
Am 14.06.21 um 16:32 schrieb Nirmoy Das:
Quoted 25 lines
Make provision to pass different ttm BO destroy callback while creating a
amdgpu_bo.Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c| 28 ++++++++++++++++++----1 file changed, 24 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1@@ -522,15 +522,17 @@ bool amdgpu_bo_support_uswc(u64 bo_flags) * @adev: amdgpu device object * @bp: parameters to be used for the buffer object * @bo_ptr: pointer to the buffer object pointer + * @destroy: ttm bo destroy callback * - * Creates an &amdgpu_bo buffer object. + * Creates an &amdgpu_bo buffer object with a specified ttm bodestroy callback.
*
* Returns:
* 0 for success or a negative error code on failure. */drivers/gpu/drm/amd/amdgpu/amdgpu_object.c bool amdgpu_bo_support_uswc(u64 bo_flags) · line 532
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1-int amdgpu_bo_create(struct amdgpu_device *adev, +static int amdgpu_bo_do_create(struct amdgpu_device *adev,Please don't. Rather expose an
amdgpu_vm_bo_createfunction.
Quoted 6 lines
Quoted 4 lines
struct
amdgpu_bo_param*bp,
- structamdgpu_bo**bo_ptr)
+ structamdgpu_bo**bo_ptr,
+ void (*destroy)(structttm_buffer_object*))That rather belongs into the
amdgpu_bo_paramstructure.
I misinterpret Teams conversation. I will resend.
Thanks,
Nirmoy
Quoted 28 lines
Quoted 28 lines
{
structttm_operation_ctxctx = { .interruptible = (bp->type!=ttm_bo_type_kernel),drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -594,7 +596,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type, &bo->placement, page_align, &ctx, NULL, - bp->resv, &amdgpu_bo_destroy); + bp->resv, destroy); if (unlikely(r != 0)) return r; @@ -638,6 +640,24 @@ int amdgpu_bo_create(struct amdgpu_device *adev, return r;}
+/**
+ *amdgpu_bo_create- create an&amdgpu_bobuffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @bo_ptr: pointer to the buffer object pointer
+ *
+ * Creates an&amdgpu_bobuffer object.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+int amdgpu_bo_create(structamdgpu_device*adev, + structamdgpu_bo_param*bp,
Quoted 9 lines
Quoted 8 lines
+ struct
amdgpu_bo**bo_ptr)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-0+{ + return amdgpu_bo_do_create(adev, bp, bo_ptr, &amdgpu_bo_destroy); +} +/**
*amdgpu_bo_create_user- create an&amdgpu_bo_userbuffer object
* @adev: amdgpu device object
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx