diff mbox series

[16/45] drm/radeon/ttm: do move notify actions inside move.

Message ID 20200924051845.397177-17-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series TTM move refactoring | expand

Commit Message

Dave Airlie Sept. 24, 2020, 5:18 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

move notify can be gotten done inside moves instead of a separate
callback for radeon. move notify is now only called from one other
place where new_mem == NULL, so handle that properly.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/radeon/radeon_object.c | 28 +++++++++++++++++---------
 drivers/gpu/drm/radeon/radeon_object.h |  4 ++++
 drivers/gpu/drm/radeon/radeon_ttm.c    |  8 +++++++-
 3 files changed, 30 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 689426dd8480..36a16d7a24b2 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -754,6 +754,21 @@  int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
 	return radeon_bo_get_surface_reg(bo);
 }
 
+
+void radeon_bo_invalidate(struct radeon_bo *rbo)
+{
+	radeon_bo_check_tiling(rbo, 0, 1);
+	radeon_vm_bo_invalidate(rbo->rdev, rbo);
+}
+
+void radeon_bo_memory_usage(struct radeon_bo *rbo,
+			    uint32_t old_mem_type,
+			    uint32_t new_mem_type)
+{
+	radeon_update_memory_usage(rbo, old_mem_type, -1);
+	radeon_update_memory_usage(rbo, new_mem_type, 1);
+}
+
 void radeon_bo_move_notify(struct ttm_buffer_object *bo,
 			   bool evict,
 			   struct ttm_resource *new_mem)
@@ -763,16 +778,11 @@  void radeon_bo_move_notify(struct ttm_buffer_object *bo,
 	if (!radeon_ttm_bo_is_radeon_bo(bo))
 		return;
 
-	rbo = container_of(bo, struct radeon_bo, tbo);
-	radeon_bo_check_tiling(rbo, 0, 1);
-	radeon_vm_bo_invalidate(rbo->rdev, rbo);
-
-	/* update statistics */
-	if (!new_mem)
+	/* the new_mem path is handled via the move callback now */
+	if (new_mem)
 		return;
-
-	radeon_update_memory_usage(rbo, bo->mem.mem_type, -1);
-	radeon_update_memory_usage(rbo, new_mem->mem_type, 1);
+	rbo = container_of(bo, struct radeon_bo, tbo);
+	radeon_bo_invalidate(rbo);
 }
 
 int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h
index 27cfb64057fe..6f886e2ffaf3 100644
--- a/drivers/gpu/drm/radeon/radeon_object.h
+++ b/drivers/gpu/drm/radeon/radeon_object.h
@@ -160,6 +160,10 @@  extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
 				u32 *tiling_flags, u32 *pitch);
 extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
 				bool force_drop);
+void radeon_bo_memory_usage(struct radeon_bo *rbo,
+			    uint32_t old_mem_type,
+			    uint32_t new_mem_type);
+void radeon_bo_invalidate(struct radeon_bo *rbo);
 extern void radeon_bo_move_notify(struct ttm_buffer_object *bo,
 				  bool evict,
 				  struct ttm_resource *new_mem);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 10d25d3b83f2..e814b11187b3 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -316,12 +316,16 @@  static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 	struct ttm_resource *old_mem = &bo->mem;
 	int r;
 
+	rbo = container_of(bo, struct radeon_bo, tbo);
+
+	radeon_bo_invalidate(rbo);
+	radeon_bo_memory_usage(rbo, bo->mem.mem_type, new_mem->mem_type);
+
 	r = ttm_bo_wait_ctx(bo, ctx);
 	if (r)
 		return r;
 
 	/* Can't move a pinned BO */
-	rbo = container_of(bo, struct radeon_bo, tbo);
 	if (WARN_ON_ONCE(rbo->tbo.pin_count > 0))
 		return -EINVAL;
 
@@ -361,6 +365,8 @@  static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 memcpy:
 		r = ttm_bo_move_memcpy(bo, ctx, new_mem);
 		if (r) {
+			radeon_bo_invalidate(rbo);
+			radeon_bo_memory_usage(rbo, new_mem->mem_type, old_mem->mem_type);
 			return r;
 		}
 	}