]> git.dujemihanovic.xyz Git - linux.git/commitdiff
drm/amdgpu: use GEM references instead of TTMs v2
authorChristian König <christian.koenig@amd.com>
Thu, 11 Jul 2024 12:39:43 +0000 (14:39 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 18 Sep 2024 20:15:13 +0000 (16:15 -0400)
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>
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

index 0e617dff8765e28469419720b0ea767c51c31457..1a5df8b9466161eda0007d74aa7c817c7b1e9b0c 100644 (file)
@@ -43,8 +43,6 @@
 #include "amdgpu_hmm.h"
 #include "amdgpu_xgmi.h"
 
-static const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
-
 static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf)
 {
        struct ttm_buffer_object *bo = vmf->vma->vm_private_data;
@@ -87,11 +85,11 @@ static const struct vm_operations_struct amdgpu_gem_vm_ops = {
 
 static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
 {
-       struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
+       struct amdgpu_bo *aobj = gem_to_amdgpu_bo(gobj);
 
-       if (robj) {
-               amdgpu_hmm_unregister(robj);
-               amdgpu_bo_unref(&robj);
+       if (aobj) {
+               amdgpu_hmm_unregister(aobj);
+               ttm_bo_put(&aobj->tbo);
        }
 }
 
@@ -126,7 +124,6 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 
        bo = &ubo->bo;
        *obj = &bo->tbo.base;
-       (*obj)->funcs = &amdgpu_gem_object_funcs;
 
        return 0;
 }
@@ -295,7 +292,7 @@ static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_str
        return drm_gem_ttm_mmap(obj, vma);
 }
 
-static const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
+const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
        .free = amdgpu_gem_object_free,
        .open = amdgpu_gem_object_open,
        .close = amdgpu_gem_object_close,
index f30264782ba27bfad89acbfbf52b503f81a41ee5..3a8f57900a3aaf23befa1f41c373386aac589746 100644 (file)
@@ -33,6 +33,8 @@
 #define AMDGPU_GEM_DOMAIN_MAX          0x3
 #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, tbo.base)
 
+extern const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
+
 unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
 
 /*
index 5bff4249b35737e2be6aaf17ee0aa3ebf0ee2f71..44819cdba7fbe8eab25df9fa2b45f253076aabc8 100644 (file)
@@ -564,6 +564,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
        if (bo == NULL)
                return -ENOMEM;
        drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size);
+       bo->tbo.base.funcs = &amdgpu_gem_object_funcs;
        bo->vm_bo = NULL;
        bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain :
                bp->domain;
@@ -786,7 +787,7 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
        if (bo == NULL)
                return NULL;
 
-       ttm_bo_get(&bo->tbo);
+       drm_gem_object_get(&bo->tbo.base);
        return bo;
 }
 
@@ -798,13 +799,10 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
  */
 void amdgpu_bo_unref(struct amdgpu_bo **bo)
 {
-       struct ttm_buffer_object *tbo;
-
        if ((*bo) == NULL)
                return;
 
-       tbo = &((*bo)->tbo);
-       ttm_bo_put(tbo);
+       drm_gem_object_put(&(*bo)->tbo.base);
        *bo = NULL;
 }