drm/ttm: introduce ttm_bo_move_null
authorDave Airlie <airlied@redhat.com>
Mon, 7 Sep 2020 20:46:18 +0000 (06:46 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 8 Sep 2020 22:28:53 +0000 (08:28 +1000)
This pattern is cut-n-pasted across 4 drivers, switch it to
a WARN_ON instead, as BUG_ON is considered a bad idea usually.

Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200907204630.1406528-2-airlied@gmail.com
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/qxl/qxl_ttm.c
drivers/gpu/drm/radeon/radeon_ttm.c
include/drm/ttm/ttm_bo_driver.h

index c6f4d9ede0e0d9d76bf5ace1424374c89ccfb571..5f7a8e23ed9d4ce7a2b749427d5dd161cc228074 100644 (file)
@@ -174,24 +174,6 @@ static int amdgpu_verify_access(struct ttm_buffer_object *bo, struct file *filp)
                                          filp->private_data);
 }
 
-/**
- * amdgpu_move_null - Register memory for a buffer object
- *
- * @bo: The bo to assign the memory to
- * @new_mem: The memory to be assigned.
- *
- * Assign the memory from new_mem to the memory of the buffer object bo.
- */
-static void amdgpu_move_null(struct ttm_buffer_object *bo,
-                            struct ttm_resource *new_mem)
-{
-       struct ttm_resource *old_mem = &bo->mem;
-
-       BUG_ON(old_mem->mm_node != NULL);
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
-}
-
 /**
  * amdgpu_mm_node_addr - Compute the GPU relative offset of a GTT buffer.
  *
@@ -676,7 +658,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
        adev = amdgpu_ttm_adev(bo->bdev);
 
        if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
-               amdgpu_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
        if ((old_mem->mem_type == TTM_PL_TT &&
@@ -684,7 +666,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
            (old_mem->mem_type == TTM_PL_SYSTEM &&
             new_mem->mem_type == TTM_PL_TT)) {
                /* bind is enough */
-               amdgpu_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
        if (old_mem->mem_type == AMDGPU_PL_GDS ||
@@ -694,7 +676,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
            new_mem->mem_type == AMDGPU_PL_GWS ||
            new_mem->mem_type == AMDGPU_PL_OA) {
                /* Nothing to save here */
-               amdgpu_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
 
index 83fdd169a27a56f6f9f38d340af7d6d4ae862aa9..2c230e0b34dac2225d189dbfe3164d1fe6313b4b 100644 (file)
@@ -993,9 +993,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
 
        /* Fake bo copy. */
        if (old_reg->mem_type == TTM_PL_SYSTEM && !bo->ttm) {
-               BUG_ON(bo->mem.mm_node != NULL);
-               bo->mem = *new_reg;
-               new_reg->mm_node = NULL;
+               ttm_bo_move_null(bo, new_reg);
                goto out;
        }
 
index 19b18ea38c34067603978a04cd94d065dc484c24..b19b9641470ce835172328b9c1edb72bad780d67 100644 (file)
@@ -158,16 +158,6 @@ static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo,
        return &gtt->ttm;
 }
 
-static void qxl_move_null(struct ttm_buffer_object *bo,
-                            struct ttm_resource *new_mem)
-{
-       struct ttm_resource *old_mem = &bo->mem;
-
-       BUG_ON(old_mem->mm_node != NULL);
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
-}
-
 static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict,
                       struct ttm_operation_ctx *ctx,
                       struct ttm_resource *new_mem)
@@ -180,7 +170,7 @@ static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict,
                return ret;
 
        if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
-               qxl_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
        return ttm_bo_move_memcpy(bo, ctx, new_mem);
index 375ffd4a56abf08f3d408a79902a5737b26244f4..155e7b971afa8e06382a6150e532f9aa213c4a80 100644 (file)
@@ -148,16 +148,6 @@ static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp)
                                          filp->private_data);
 }
 
-static void radeon_move_null(struct ttm_buffer_object *bo,
-                            struct ttm_resource *new_mem)
-{
-       struct ttm_resource *old_mem = &bo->mem;
-
-       BUG_ON(old_mem->mm_node != NULL);
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
-}
-
 static int radeon_move_blit(struct ttm_buffer_object *bo,
                        bool evict, bool no_wait_gpu,
                        struct ttm_resource *new_mem,
@@ -316,7 +306,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 
        rdev = radeon_get_rdev(bo->bdev);
        if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
-               radeon_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
        if ((old_mem->mem_type == TTM_PL_TT &&
@@ -324,7 +314,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
            (old_mem->mem_type == TTM_PL_SYSTEM &&
             new_mem->mem_type == TTM_PL_TT)) {
                /* bind is enough */
-               radeon_move_null(bo, new_mem);
+               ttm_bo_move_null(bo, new_mem);
                return 0;
        }
        if (!rdev->ring[radeon_copy_ring_index(rdev)].ready ||
index a694388f7b13c90a2520a1a1ba6ee5546b04be1b..ebba282667ba60b8d8d700b5c01e5fe084e4959f 100644 (file)
@@ -520,6 +520,23 @@ static inline void ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo
        spin_unlock(&ttm_bo_glob.lru_lock);
 }
 
+/**
+ * ttm_bo_move_null = assign memory for a buffer object.
+ * @bo: The bo to assign the memory to
+ * @new_mem: The memory to be assigned.
+ *
+ * Assign the memory from new_mem to the memory of the buffer object bo.
+ */
+static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
+                                   struct ttm_resource *new_mem)
+{
+       struct ttm_resource *old_mem = &bo->mem;
+
+       WARN_ON(old_mem->mm_node != NULL);
+       *old_mem = *new_mem;
+       new_mem->mm_node = NULL;
+}
+
 /**
  * ttm_bo_unreserve
  *