Skip to content

Commit 23e24fb

Browse files
Nirmoy Dasalexdeucher
authored andcommitted
drm/amdgpu: parameterize ttm BO destroy callback
Make provision to pass different ttm BO destroy callback while creating a amdgpu_bo. Signed-off-by: Nirmoy Das <nirmoy.das@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 391629b commit 23e24fb

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,40 @@
5454

5555
static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
5656
{
57-
struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
5857
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
59-
struct amdgpu_bo_user *ubo;
6058

6159
amdgpu_bo_kunmap(bo);
6260

6361
if (bo->tbo.base.import_attach)
6462
drm_prime_gem_destroy(&bo->tbo.base, bo->tbo.sg);
6563
drm_gem_object_release(&bo->tbo.base);
64+
amdgpu_bo_unref(&bo->parent);
65+
kvfree(bo);
66+
}
67+
68+
static void amdgpu_bo_user_destroy(struct ttm_buffer_object *tbo)
69+
{
70+
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
71+
struct amdgpu_bo_user *ubo;
72+
73+
ubo = to_amdgpu_bo_user(bo);
74+
kfree(ubo->metadata);
75+
amdgpu_bo_destroy(tbo);
76+
}
77+
78+
static void amdgpu_bo_vm_destroy(struct ttm_buffer_object *tbo)
79+
{
80+
struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
81+
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
82+
6683
/* in case amdgpu_device_recover_vram got NULL of bo->parent */
6784
if (!list_empty(&bo->shadow_list)) {
6885
mutex_lock(&adev->shadow_list_lock);
6986
list_del_init(&bo->shadow_list);
7087
mutex_unlock(&adev->shadow_list_lock);
7188
}
72-
amdgpu_bo_unref(&bo->parent);
73-
74-
if (bo->tbo.type != ttm_bo_type_kernel) {
75-
ubo = to_amdgpu_bo_user(bo);
76-
kfree(ubo->metadata);
77-
}
7889

79-
kvfree(bo);
90+
amdgpu_bo_destroy(tbo);
8091
}
8192

8293
/**
@@ -91,8 +102,11 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
91102
*/
92103
bool amdgpu_bo_is_amdgpu_bo(struct ttm_buffer_object *bo)
93104
{
94-
if (bo->destroy == &amdgpu_bo_destroy)
105+
if (bo->destroy == &amdgpu_bo_destroy ||
106+
bo->destroy == &amdgpu_bo_user_destroy ||
107+
bo->destroy == &amdgpu_bo_vm_destroy)
95108
return true;
109+
96110
return false;
97111
}
98112

@@ -568,9 +582,12 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
568582
if (bp->type == ttm_bo_type_kernel)
569583
bo->tbo.priority = 1;
570584

585+
if (!bp->destroy)
586+
bp->destroy = &amdgpu_bo_destroy;
587+
571588
r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
572589
&bo->placement, page_align, &ctx, NULL,
573-
bp->resv, &amdgpu_bo_destroy);
590+
bp->resv, bp->destroy);
574591
if (unlikely(r != 0))
575592
return r;
576593

@@ -634,6 +651,7 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
634651
int r;
635652

636653
bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
654+
bp->destroy = &amdgpu_bo_user_destroy;
637655
r = amdgpu_bo_create(adev, bp, &bo_ptr);
638656
if (r)
639657
return r;
@@ -665,6 +683,7 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev,
665683
* num of amdgpu_vm_pt entries.
666684
*/
667685
BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
686+
bp->destroy = &amdgpu_bo_vm_destroy;
668687
r = amdgpu_bo_create(adev, bp, &bo_ptr);
669688
if (r)
670689
return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ struct amdgpu_bo_param {
5555
u64 flags;
5656
enum ttm_bo_type type;
5757
bool no_wait_gpu;
58-
struct dma_resv *resv;
58+
struct dma_resv *resv;
59+
void (*destroy)(struct ttm_buffer_object *bo);
5960
};
6061

6162
/* bo virtual addresses in a vm */

0 commit comments

Comments
 (0)