drm/ttm: add a simple assign mem to bo wrapper
authorDave Airlie <airlied@redhat.com>
Thu, 17 Sep 2020 04:03:46 +0000 (14:03 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 17 Sep 2020 20:16:39 +0000 (06:16 +1000)
This pattern is called in a few places, just clean it up.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200917043040.146575-6-airlied@gmail.com
drivers/gpu/drm/ttm/ttm_bo_util.c
include/drm/ttm/ttm_bo_driver.h

index 919489f6a5a33e21b8fb29a0c89886404e1b3dab..5a8d77ef504f23eeefc060a2453b543204821929 100644 (file)
@@ -87,9 +87,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
                        return ret;
        }
 
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
-
+       ttm_bo_assign_mem(bo, new_mem);
        return 0;
 }
 EXPORT_SYMBOL(ttm_bo_move_ttm);
@@ -299,8 +297,8 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
        mb();
 out2:
        old_copy = *old_mem;
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
+
+       ttm_bo_assign_mem(bo, new_mem);
 
        if (!man->use_tt)
                ttm_bo_tt_destroy(bo);
@@ -535,7 +533,6 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 {
        struct ttm_bo_device *bdev = bo->bdev;
        struct ttm_resource_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
-       struct ttm_resource *old_mem = &bo->mem;
        int ret;
        struct ttm_buffer_object *ghost_obj;
 
@@ -582,8 +579,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
                ttm_bo_put(ghost_obj);
        }
 
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
+       ttm_bo_assign_mem(bo, new_mem);
 
        return 0;
 }
@@ -594,9 +590,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
                         struct ttm_resource *new_mem)
 {
        struct ttm_bo_device *bdev = bo->bdev;
-       struct ttm_resource *old_mem = &bo->mem;
 
-       struct ttm_resource_manager *from = ttm_manager_type(bdev, old_mem->mem_type);
+       struct ttm_resource_manager *from = ttm_manager_type(bdev, bo->mem.mem_type);
        struct ttm_resource_manager *to = ttm_manager_type(bdev, new_mem->mem_type);
 
        int ret;
@@ -673,8 +668,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
                ttm_bo_free_old_node(bo);
        }
 
-       *old_mem = *new_mem;
-       new_mem->mm_node = NULL;
+       ttm_bo_assign_mem(bo, new_mem);
 
        return 0;
 }
index 7846dfa507f7f1bcd6bd1d9c53803a0977be780d..25cc932d63f1d5bacb7597b6351fd3f7ee5a3c21 100644 (file)
@@ -539,6 +539,13 @@ static inline void ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo
        spin_unlock(&ttm_bo_glob.lru_lock);
 }
 
+static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
+                                    struct ttm_resource *new_mem)
+{
+       bo->mem = *new_mem;
+       new_mem->mm_node = NULL;
+}
+
 /**
  * ttm_bo_move_null = assign memory for a buffer object.
  * @bo: The bo to assign the memory to
@@ -552,8 +559,7 @@ static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
        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_assign_mem(bo, new_mem);
 }
 
 /**