@@ -552,12 +552,8 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
goto out_cleanup;
amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
- r = ttm_tt_set_placement_caching(bo->ttm, new_mem->placement);
- if (unlikely(r))
- goto out_cleanup;
- ttm_bo_assign_mem(bo, new_mem);
+ r = ttm_bo_cleanup_ram_move(bo, new_mem);
out_cleanup:
ttm_resource_free(bo, &tmp_mem);
return r;
@@ -674,13 +670,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
if (r)
return r;
amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
- r = ttm_tt_set_placement_caching(bo->ttm, new_mem->placement);
- if (r)
- return r;
- ttm_bo_assign_mem(bo, new_mem);
- return 0;
+ return ttm_bo_cleanup_ram_move(bo, new_mem);
}
if (old_mem->mem_type == AMDGPU_PL_GDS ||
@@ -904,12 +904,8 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict,
goto out;
nouveau_ttm_tt_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
- ret = ttm_tt_set_placement_caching(bo->ttm, new_reg->placement);
- if (ret)
- goto out;
- ttm_bo_assign_mem(bo, new_reg);
+ ret = ttm_bo_cleanup_ram_move(bo, new_reg);
out:
ttm_resource_free(bo, &tmp_reg);
return ret;
@@ -1072,13 +1068,9 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
if (old_reg->mem_type == TTM_PL_TT &&
new_reg->mem_type == TTM_PL_SYSTEM) {
nouveau_ttm_tt_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
- ret = ttm_tt_set_placement_caching(bo->ttm, new_reg->placement);
- if (ret)
- goto out;
- ttm_bo_assign_mem(bo, new_reg);
- return 0;
+ ret = ttm_bo_cleanup_ram_move(bo, new_reg);
+ goto out;
}
/* Hardware assisted copy. */
@@ -234,13 +234,8 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
goto out_cleanup;
radeon_ttm_tt_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
-
- r = ttm_tt_set_placement_caching(bo->ttm, new_mem->placement);
- if (unlikely(r))
- goto out_cleanup;
- ttm_bo_assign_mem(bo, new_mem);
+ r = ttm_bo_cleanup_ram_move(bo, new_mem);
out_cleanup:
ttm_resource_free(bo, &tmp_mem);
return r;
@@ -314,12 +309,8 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
if (old_mem->mem_type == TTM_PL_TT &&
new_mem->mem_type == TTM_PL_SYSTEM) {
radeon_ttm_tt_unbind(bo->bdev, bo->ttm);
- ttm_resource_free(bo, &bo->mem);
- r = ttm_tt_set_placement_caching(bo->ttm, new_mem->placement);
- if (r)
- return r;
- goto out_assign;
+ return ttm_bo_cleanup_ram_move(bo, new_mem);
}
if (!rdev->ring[radeon_copy_ring_index(rdev)].ready ||
@@ -1573,3 +1573,18 @@ int ttm_bo_create_tt_tmp(struct ttm_buffer_object *bo,
return 0;
}
EXPORT_SYMBOL(ttm_bo_create_tt_tmp);
+
+int ttm_bo_cleanup_ram_move(struct ttm_buffer_object *bo,
+ struct ttm_resource *new_mem)
+{
+ int ret;
+
+ ttm_resource_free(bo, &bo->mem);
+
+ ret = ttm_tt_set_placement_caching(bo->ttm, new_mem->placement);
+ if (ret)
+ return ret;
+ ttm_bo_assign_mem(bo, new_mem);
+ return 0;
+}
+EXPORT_SYMBOL(ttm_bo_cleanup_ram_move);
@@ -563,6 +563,9 @@ int ttm_bo_create_tt_tmp(struct ttm_buffer_object *bo,
struct ttm_operation_ctx *ctx,
struct ttm_resource *new_mem,
struct ttm_resource *new_temp);
+
+int ttm_bo_cleanup_ram_move(struct ttm_buffer_object *bo,
+ struct ttm_resource *new_mem);
/**
* ttm_bo_move_memcpy
*