Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v1)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
6dcba097 87d749a6

+10 -13
+5 -8
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
··· 43 43 #include "amdgpu_hmm.h" 44 44 #include "amdgpu_xgmi.h" 45 45 46 - static const struct drm_gem_object_funcs amdgpu_gem_object_funcs; 47 - 48 46 static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf) 49 47 { 50 48 struct ttm_buffer_object *bo = vmf->vma->vm_private_data; ··· 85 87 86 88 static void amdgpu_gem_object_free(struct drm_gem_object *gobj) 87 89 { 88 - struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj); 90 + struct amdgpu_bo *aobj = gem_to_amdgpu_bo(gobj); 89 91 90 - if (robj) { 91 - amdgpu_hmm_unregister(robj); 92 - amdgpu_bo_unref(&robj); 92 + if (aobj) { 93 + amdgpu_hmm_unregister(aobj); 94 + ttm_bo_put(&aobj->tbo); 93 95 } 94 96 } 95 97 ··· 124 126 125 127 bo = &ubo->bo; 126 128 *obj = &bo->tbo.base; 127 - (*obj)->funcs = &amdgpu_gem_object_funcs; 128 129 129 130 return 0; 130 131 } ··· 292 295 return drm_gem_ttm_mmap(obj, vma); 293 296 } 294 297 295 - static const struct drm_gem_object_funcs amdgpu_gem_object_funcs = { 298 + const struct drm_gem_object_funcs amdgpu_gem_object_funcs = { 296 299 .free = amdgpu_gem_object_free, 297 300 .open = amdgpu_gem_object_open, 298 301 .close = amdgpu_gem_object_close,
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
··· 33 33 #define AMDGPU_GEM_DOMAIN_MAX 0x3 34 34 #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, tbo.base) 35 35 36 + extern const struct drm_gem_object_funcs amdgpu_gem_object_funcs; 37 + 36 38 unsigned long amdgpu_gem_timeout(uint64_t timeout_ns); 37 39 38 40 /*
+3 -5
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
··· 564 564 if (bo == NULL) 565 565 return -ENOMEM; 566 566 drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size); 567 + bo->tbo.base.funcs = &amdgpu_gem_object_funcs; 567 568 bo->vm_bo = NULL; 568 569 bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain : 569 570 bp->domain; ··· 787 786 if (bo == NULL) 788 787 return NULL; 789 788 790 - ttm_bo_get(&bo->tbo); 789 + drm_gem_object_get(&bo->tbo.base); 791 790 return bo; 792 791 } 793 792 ··· 799 798 */ 800 799 void amdgpu_bo_unref(struct amdgpu_bo **bo) 801 800 { 802 - struct ttm_buffer_object *tbo; 803 - 804 801 if ((*bo) == NULL) 805 802 return; 806 803 807 - tbo = &((*bo)->tbo); 808 - ttm_bo_put(tbo); 804 + drm_gem_object_put(&(*bo)->tbo.base); 809 805 *bo = NULL; 810 806 } 811 807