drm/ttm: move ttm binding/unbinding out of ttm_tt paths.
authorDave Airlie <airlied@redhat.com>
Tue, 15 Sep 2020 01:34:51 +0000 (11:34 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 15 Sep 2020 23:35:30 +0000 (09:35 +1000)
Move these up to the bo level, moving ttm_tt to just being
backing store. Next step is to move the bound flag out.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200915024007.67163-6-airlied@gmail.com
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/radeon/radeon_mn.c
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/ttm/ttm_bo_util.c
drivers/gpu/drm/ttm/ttm_tt.c
include/drm/ttm/ttm_bo_driver.h
include/drm/ttm/ttm_tt.h

index 9353e41cf66925793ca7167912ae3dc854e08081..e86f8f6371c4cba322581fa1e26f599c5d7830dd 100644 (file)
@@ -552,7 +552,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
                goto out_cleanup;
 
        /* Bind the memory to the GTT space */
-       r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem);
+       r = ttm_bo_tt_bind(bo, &tmp_mem);
        if (unlikely(r)) {
                goto out_cleanup;
        }
index 1088de50c14cedd50f33024827479c4f509bc084..aea201d9c5137878c1d797cc74b509814c8f2e03 100644 (file)
@@ -924,7 +924,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
        if (ret)
                goto out;
 
-       ret = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_reg);
+       ret = ttm_bo_tt_bind(bo, &tmp_reg);
        if (ret)
                goto out;
 
index b6293fb91030067501bacedfa782f48ebf33511a..eb46d22202365a277c8f1616e5e2d46e604839fd 100644 (file)
@@ -53,7 +53,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,
        struct ttm_operation_ctx ctx = { false, false };
        long r;
 
-       if (!bo->tbo.ttm || !ttm_tt_is_bound(bo->tbo.ttm))
+       if (!bo->tbo.ttm || !ttm_bo_tt_is_bound(&bo->tbo))
                return true;
 
        if (!mmu_notifier_range_blockable(range))
index 2833028982010e16c4184395d7429cc27c4e7161..c6c1008fefd2280db572066926bc796ec9f47010 100644 (file)
@@ -238,7 +238,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
                goto out_cleanup;
        }
 
-       r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem);
+       r = ttm_bo_tt_bind(bo, &tmp_mem);
        if (unlikely(r)) {
                goto out_cleanup;
        }
index 654384c7aae1109be270efc1ac6355b6ecd62579..17010e7d0ea9757296ccb5190a4f0a2681527fc4 100644 (file)
@@ -264,7 +264,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
                        if (ret)
                                goto out_err;
 
-                       ret = ttm_tt_bind(bdev, bo->ttm, mem);
+                       ret = ttm_bo_tt_bind(bo, mem);
                        if (ret)
                                goto out_err;
                }
@@ -1619,6 +1619,35 @@ void ttm_bo_tt_destroy(struct ttm_buffer_object *bo)
 {
        if (bo->ttm == NULL)
                return;
+
+       ttm_bo_tt_unbind(bo);
        ttm_tt_destroy(bo->bdev, bo->ttm);
        bo->ttm = NULL;
 }
+
+int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem)
+{
+       int ret;
+
+       if (!bo->ttm)
+               return -EINVAL;
+
+       if (ttm_bo_tt_is_bound(bo))
+               return 0;
+
+       ret = bo->bdev->driver->ttm_tt_bind(bo->bdev, bo->ttm, mem);
+       if (unlikely(ret != 0))
+               return ret;
+
+       ttm_bo_tt_set_bound(bo);
+       return 0;
+}
+EXPORT_SYMBOL(ttm_bo_tt_bind);
+
+void ttm_bo_tt_unbind(struct ttm_buffer_object *bo)
+{
+       if (ttm_bo_tt_is_bound(bo)) {
+               bo->bdev->driver->ttm_tt_unbind(bo->bdev, bo->ttm);
+               ttm_bo_tt_set_unbound(bo);
+       }
+}
index 2ce97760a0892cb18c575f2766ceaa307305b4ce..d6634a5caba24c6dc4fd6e005920cb907a3c4da3 100644 (file)
@@ -67,7 +67,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
                        return ret;
                }
 
-               ttm_tt_unbind(bo->bdev, ttm);
+               ttm_bo_tt_unbind(bo);
                ttm_bo_free_old_node(bo);
                old_mem->mem_type = TTM_PL_SYSTEM;
        }
@@ -82,7 +82,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
                if (unlikely(ret != 0))
                        return ret;
 
-               ret = ttm_tt_bind(bo->bdev, ttm, new_mem);
+               ret = ttm_bo_tt_bind(bo, new_mem);
                if (unlikely(ret != 0))
                        return ret;
        }
@@ -701,4 +701,3 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 
        return 0;
 }
-
index 93d65e5e4205a7916e8135db91de22f583d13776..a4f0296effaca95a8c0e33f630f6aa8f49e54145 100644 (file)
@@ -209,8 +209,6 @@ EXPORT_SYMBOL(ttm_tt_set_placement_caching);
 
 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-       ttm_tt_unbind(bdev, ttm);
-
        ttm_tt_unpopulate(bdev, ttm);
 
        if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
@@ -303,35 +301,6 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
 }
 EXPORT_SYMBOL(ttm_dma_tt_fini);
 
-void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
-{
-       if (ttm_tt_is_bound(ttm)) {
-               bdev->driver->ttm_tt_unbind(bdev, ttm);
-               ttm_tt_set_unbound(ttm);
-       }
-}
-
-int ttm_tt_bind(struct ttm_bo_device *bdev,
-               struct ttm_tt *ttm, struct ttm_resource *bo_mem)
-{
-       int ret = 0;
-
-       if (!ttm)
-               return -EINVAL;
-
-       if (ttm_tt_is_bound(ttm))
-               return 0;
-
-       ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
-       if (unlikely(ret != 0))
-               return ret;
-
-       ttm_tt_set_bound(ttm);
-
-       return 0;
-}
-EXPORT_SYMBOL(ttm_tt_bind);
-
 int ttm_tt_swapin(struct ttm_tt *ttm)
 {
        struct address_space *swap_space;
index 70557e2de9be73e49c02e7cec38140fff5c7be8f..d2bea22f35ae0472e8696fee8057ff5186f4e3c7 100644 (file)
@@ -684,6 +684,34 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
  */
 pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 
+/**
+ * ttm_bo_tt_bind
+ *
+ * Bind the object tt to a memory resource.
+ */
+int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem);
+
+/**
+ * ttm_bo_tt_bind
+ *
+ * Unbind the object tt from a memory resource.
+ */
+void ttm_bo_tt_unbind(struct ttm_buffer_object *bo);
+
+static inline bool ttm_bo_tt_is_bound(struct ttm_buffer_object *bo)
+{
+       return bo->ttm->_state == tt_bound;
+}
+
+static inline void ttm_bo_tt_set_unbound(struct ttm_buffer_object *bo)
+{
+       bo->ttm->_state = tt_unbound;
+}
+
+static inline void ttm_bo_tt_set_bound(struct ttm_buffer_object *bo)
+{
+       bo->ttm->_state = tt_bound;
+}
 /**
  * ttm_bo_tt_destroy.
  */
index 8f57d86ee67b532fa4e69061f0302cb40ba8c7c5..1ac56730d9524a5234bee5c62aeb8a40d6caa5ae 100644 (file)
@@ -82,11 +82,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
        return tt->_state != tt_unpopulated;
 }
 
-static inline bool ttm_tt_is_bound(struct ttm_tt *tt)
-{
-       return tt->_state == tt_bound;
-}
-
 static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt)
 {
        tt->_state = tt_unpopulated;
@@ -97,16 +92,6 @@ static inline void ttm_tt_set_populated(struct ttm_tt *tt)
        tt->_state = tt_unbound;
 }
 
-static inline void ttm_tt_set_unbound(struct ttm_tt *tt)
-{
-       tt->_state = tt_unbound;
-}
-
-static inline void ttm_tt_set_bound(struct ttm_tt *tt)
-{
-       tt->_state = tt_bound;
-}
-
 /**
  * struct ttm_dma_tt
  *
@@ -164,17 +149,6 @@ int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
 void ttm_tt_fini(struct ttm_tt *ttm);
 void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
 
-/**
- * ttm_ttm_bind:
- *
- * @ttm: The struct ttm_tt containing backing pages.
- * @bo_mem: The struct ttm_resource identifying the binding location.
- *
- * Bind the pages of @ttm to an aperture location identified by @bo_mem
- */
-int ttm_tt_bind(struct ttm_bo_device *bdev,
-               struct ttm_tt *ttm, struct ttm_resource *bo_mem);
-
 /**
  * ttm_ttm_destroy:
  *
@@ -184,15 +158,6 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
  */
 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
-/**
- * ttm_ttm_unbind:
- *
- * @ttm: The struct ttm_tt.
- *
- * Unbind a struct ttm_tt.
- */
-void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
-
 /**
  * ttm_tt_swapin:
  *