Skip to content

Commit 6dcba09

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: use GEM references instead of TTMs v2
Instead of a TTM reference grab a GEM reference whenever necessary. v2: fix typo in amdgpu_bo_unref pointed out by Vitaly, initialize the GEM funcs for kernel allocations as well. Signed-off-by: Christian König <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> (v1) Signed-off-by: Alex Deucher <[email protected]>
1 parent 87d749a commit 6dcba09

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
#include "amdgpu_hmm.h"
4444
#include "amdgpu_xgmi.h"
4545

46-
static const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
47-
4846
static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf)
4947
{
5048
struct ttm_buffer_object *bo = vmf->vma->vm_private_data;
@@ -87,11 +85,11 @@ static const struct vm_operations_struct amdgpu_gem_vm_ops = {
8785

8886
static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
8987
{
90-
struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
88+
struct amdgpu_bo *aobj = gem_to_amdgpu_bo(gobj);
9189

92-
if (robj) {
93-
amdgpu_hmm_unregister(robj);
94-
amdgpu_bo_unref(&robj);
90+
if (aobj) {
91+
amdgpu_hmm_unregister(aobj);
92+
ttm_bo_put(&aobj->tbo);
9593
}
9694
}
9795

@@ -126,7 +124,6 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
126124

127125
bo = &ubo->bo;
128126
*obj = &bo->tbo.base;
129-
(*obj)->funcs = &amdgpu_gem_object_funcs;
130127

131128
return 0;
132129
}
@@ -295,7 +292,7 @@ static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_str
295292
return drm_gem_ttm_mmap(obj, vma);
296293
}
297294

298-
static const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
295+
const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
299296
.free = amdgpu_gem_object_free,
300297
.open = amdgpu_gem_object_open,
301298
.close = amdgpu_gem_object_close,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#define AMDGPU_GEM_DOMAIN_MAX 0x3
3434
#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, tbo.base)
3535

36+
extern const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
37+
3638
unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
3739

3840
/*

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
564564
if (bo == NULL)
565565
return -ENOMEM;
566566
drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size);
567+
bo->tbo.base.funcs = &amdgpu_gem_object_funcs;
567568
bo->vm_bo = NULL;
568569
bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain :
569570
bp->domain;
@@ -786,7 +787,7 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
786787
if (bo == NULL)
787788
return NULL;
788789

789-
ttm_bo_get(&bo->tbo);
790+
drm_gem_object_get(&bo->tbo.base);
790791
return bo;
791792
}
792793

@@ -798,13 +799,10 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
798799
*/
799800
void amdgpu_bo_unref(struct amdgpu_bo **bo)
800801
{
801-
struct ttm_buffer_object *tbo;
802-
803802
if ((*bo) == NULL)
804803
return;
805804

806-
tbo = &((*bo)->tbo);
807-
ttm_bo_put(tbo);
805+
drm_gem_object_put(&(*bo)->tbo.base);
808806
*bo = NULL;
809807
}
810808

0 commit comments

Comments
 (0)