]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
drm/nouveau: use GEM references instead of TTMs
authorDanilo Krummrich <dakr@kernel.org>
Thu, 18 Jul 2024 16:58:48 +0000 (18:58 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Mon, 22 Jul 2024 20:46:45 +0000 (22:46 +0200)
TTM wants to get rid of the duplicate refcounting of the embedded GEM
object and its own reference count.

Hence, use of GEM object references where possible.

Also get rid of nouveau_bo_ref() and replace it with nouveau_bo_fini(),
which drops the initial reference we get from initializing a ttm_bo.

Reviewed-by: Ben Skeggs <bskeggs@nvidia.com>
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240718165959.3983-4-dakr@kernel.org
drivers/gpu/drm/nouveau/dispnv04/crtc.c
drivers/gpu/drm/nouveau/dispnv50/disp.c
drivers/gpu/drm/nouveau/nouveau_bo.h
drivers/gpu/drm/nouveau/nouveau_chan.c
drivers/gpu/drm/nouveau/nouveau_dmem.c
drivers/gpu/drm/nouveau/nv10_fence.c
drivers/gpu/drm/nouveau/nv17_fence.c
drivers/gpu/drm/nouveau/nv50_fence.c
drivers/gpu/drm/nouveau/nv84_fence.c

index 4310ad71870b109697cc07047cbc29f4a631272f..438e3ec6e1ca0b86aca8eb9efebcee13dcbc9d1c 100644 (file)
@@ -617,9 +617,15 @@ nv_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
 
        ret = nouveau_bo_pin(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, false);
        if (ret == 0) {
-               if (disp->image[nv_crtc->index])
-                       nouveau_bo_unpin(disp->image[nv_crtc->index]);
-               nouveau_bo_ref(nvbo, &disp->image[nv_crtc->index]);
+               if (disp->image[nv_crtc->index]) {
+                       struct nouveau_bo *bo = disp->image[nv_crtc->index];
+
+                       nouveau_bo_unpin(bo);
+                       drm_gem_object_put(&bo->bo.base);
+               }
+
+               drm_gem_object_get(&nvbo->bo.base);
+               disp->image[nv_crtc->index] = nvbo;
        }
 
        return ret;
@@ -754,13 +760,17 @@ static void nv_crtc_destroy(struct drm_crtc *crtc)
 
        drm_crtc_cleanup(crtc);
 
-       if (disp->image[nv_crtc->index])
-               nouveau_bo_unpin(disp->image[nv_crtc->index]);
-       nouveau_bo_ref(NULL, &disp->image[nv_crtc->index]);
+       if (disp->image[nv_crtc->index]) {
+               struct nouveau_bo *bo = disp->image[nv_crtc->index];
+
+               nouveau_bo_unpin(bo);
+               drm_gem_object_put(&bo->bo.base);
+               disp->image[nv_crtc->index] = NULL;
+       }
 
        nouveau_bo_unmap(nv_crtc->cursor.nvbo);
        nouveau_bo_unpin(nv_crtc->cursor.nvbo);
-       nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
+       nouveau_bo_fini(nv_crtc->cursor.nvbo);
        nvif_event_dtor(&nv_crtc->vblank);
        nvif_head_dtor(&nv_crtc->head);
        kfree(nv_crtc);
@@ -794,9 +804,14 @@ nv_crtc_disable(struct drm_crtc *crtc)
 {
        struct nv04_display *disp = nv04_display(crtc->dev);
        struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       if (disp->image[nv_crtc->index])
-               nouveau_bo_unpin(disp->image[nv_crtc->index]);
-       nouveau_bo_ref(NULL, &disp->image[nv_crtc->index]);
+
+       if (disp->image[nv_crtc->index]) {
+               struct nouveau_bo *bo = disp->image[nv_crtc->index];
+
+               nouveau_bo_unpin(bo);
+               drm_gem_object_put(&bo->bo.base);
+               disp->image[nv_crtc->index] = NULL;
+       }
 }
 
 static int
@@ -1210,7 +1225,11 @@ nv04_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
                PUSH_NVSQ(push, NV05F, 0x0130, 0);
        }
 
-       nouveau_bo_ref(new_bo, &dispnv04->image[head]);
+       if (dispnv04->image[head])
+               drm_gem_object_put(&dispnv04->image[head]->bo.base);
+
+       drm_gem_object_get(&new_bo->bo.base);
+       dispnv04->image[head] = new_bo;
 
        ret = nv04_page_flip_emit(chan, old_bo, new_bo, s, &fence);
        if (ret)
@@ -1329,7 +1348,7 @@ nv04_crtc_create(struct drm_device *dev, int crtc_num)
                                nouveau_bo_unpin(nv_crtc->cursor.nvbo);
                }
                if (ret)
-                       nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
+                       nouveau_bo_fini(nv_crtc->cursor.nvbo);
        }
 
        nv04_cursor_init(nv_crtc);
index ac9657d7e92d5fd5090e17d26454f76def2a0bed..6d20d3c68fa7c14eecf6ab8e5dd0c9361224b7cf 100644 (file)
@@ -2819,7 +2819,7 @@ nv50_display_destroy(struct drm_device *dev)
        nouveau_bo_unmap(disp->sync);
        if (disp->sync)
                nouveau_bo_unpin(disp->sync);
-       nouveau_bo_ref(NULL, &disp->sync);
+       nouveau_bo_fini(disp->sync);
 
        nouveau_display(dev)->priv = NULL;
        kfree(disp);
@@ -2862,7 +2862,7 @@ nv50_display_create(struct drm_device *dev)
                                nouveau_bo_unpin(disp->sync);
                }
                if (ret)
-                       nouveau_bo_ref(NULL, &disp->sync);
+                       nouveau_bo_fini(disp->sync);
        }
 
        if (ret)
index 3b8dfbb621daabba7a47badfb27604aa8a82d1c4..596a63a50a20602c431cec6b0a8d191e91b852b8 100644 (file)
@@ -53,25 +53,10 @@ nouveau_bo(struct ttm_buffer_object *bo)
        return container_of(bo, struct nouveau_bo, bo);
 }
 
-static inline int
-nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
+static inline void
+nouveau_bo_fini(struct nouveau_bo *bo)
 {
-       struct nouveau_bo *prev;
-
-       if (!pnvbo)
-               return -EINVAL;
-       prev = *pnvbo;
-
-       if (ref) {
-               ttm_bo_get(&ref->bo);
-               *pnvbo = nouveau_bo(&ref->bo);
-       } else {
-               *pnvbo = NULL;
-       }
-       if (prev)
-               ttm_bo_put(&prev->bo);
-
-       return 0;
+       ttm_bo_put(&bo->bo);
 }
 
 extern struct ttm_device_funcs nouveau_bo_driver;
index 66fca95c10c761ea597bbb742fc97b2bcd577511..f568ea251e3b03471e5f8f5af6aa6f7b0b7946cf 100644 (file)
@@ -110,7 +110,7 @@ nouveau_channel_del(struct nouveau_channel **pchan)
                nouveau_bo_unmap(chan->push.buffer);
                if (chan->push.buffer && chan->push.buffer->bo.pin_count)
                        nouveau_bo_unpin(chan->push.buffer);
-               nouveau_bo_ref(NULL, &chan->push.buffer);
+               nouveau_bo_fini(chan->push.buffer);
                kfree(chan);
        }
        *pchan = NULL;
index 6719353e2e13f997cdf9732fc6054b75f49f97ea..7b3b8f4630a2bb4c520b401ecce8ae8342d75d4c 100644 (file)
@@ -294,7 +294,7 @@ nouveau_dmem_chunk_alloc(struct nouveau_drm *drm, struct page **ppage)
 out_bo_unpin:
        nouveau_bo_unpin(chunk->bo);
 out_bo_free:
-       nouveau_bo_ref(NULL, &chunk->bo);
+       nouveau_bo_fini(chunk->bo);
 out_release:
        release_mem_region(chunk->pagemap.range.start, range_len(&chunk->pagemap.range));
 out_free:
@@ -426,7 +426,7 @@ nouveau_dmem_fini(struct nouveau_drm *drm)
        list_for_each_entry_safe(chunk, tmp, &drm->dmem->chunks, list) {
                nouveau_dmem_evict_chunk(chunk);
                nouveau_bo_unpin(chunk->bo);
-               nouveau_bo_ref(NULL, &chunk->bo);
+               nouveau_bo_fini(chunk->bo);
                WARN_ON(chunk->callocated);
                list_del(&chunk->list);
                memunmap_pages(&chunk->pagemap);
index c6a0db5b9e2174c3bad2b97215c1755bdb218513..1a53b8b804678100822cf516895606e5b6d540ab 100644 (file)
@@ -88,7 +88,7 @@ nv10_fence_destroy(struct nouveau_drm *drm)
        nouveau_bo_unmap(priv->bo);
        if (priv->bo)
                nouveau_bo_unpin(priv->bo);
-       nouveau_bo_ref(NULL, &priv->bo);
+       nouveau_bo_fini(priv->bo);
        drm->fence = NULL;
        kfree(priv);
 }
index 07c2e0878c244d684ad4c3bcf47c66f84b73fcc2..2c99f2c1ddcdb9a4870ec061dc7ae1c7870799d5 100644 (file)
@@ -141,7 +141,7 @@ nv17_fence_create(struct nouveau_drm *drm)
                                nouveau_bo_unpin(priv->bo);
                }
                if (ret)
-                       nouveau_bo_ref(NULL, &priv->bo);
+                       nouveau_bo_fini(priv->bo);
        }
 
        if (ret) {
index ea1e1f480bfebd875a44a30949e49c03b85e96ad..6fa18f9d26b608dd66079b7aab69dfaee3587cb9 100644 (file)
@@ -92,7 +92,7 @@ nv50_fence_create(struct nouveau_drm *drm)
                                nouveau_bo_unpin(priv->bo);
                }
                if (ret)
-                       nouveau_bo_ref(NULL, &priv->bo);
+                       nouveau_bo_fini(priv->bo);
        }
 
        if (ret) {
index 812b8c62eeba1ba126af737ec64f0246e7fa7420..9ce4c2d60fe382dfb474d87637990d3efcd1ebad 100644 (file)
@@ -188,7 +188,7 @@ nv84_fence_destroy(struct nouveau_drm *drm)
        nouveau_bo_unmap(priv->bo);
        if (priv->bo)
                nouveau_bo_unpin(priv->bo);
-       nouveau_bo_ref(NULL, &priv->bo);
+       nouveau_bo_fini(priv->bo);
        drm->fence = NULL;
        kfree(priv);
 }
@@ -232,7 +232,7 @@ nv84_fence_create(struct nouveau_drm *drm)
                                nouveau_bo_unpin(priv->bo);
                }
                if (ret)
-                       nouveau_bo_ref(NULL, &priv->bo);
+                       nouveau_bo_fini(priv->bo);
        }
 
        if (ret)