From: Dave Airlie <airlied@xxxxxxxxxx> This is a pretty common pattern in the drivers. Signed-off-by: Dave Airlie <airlied@xxxxxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 13 ++----------- drivers/gpu/drm/nouveau/nouveau_bo.c | 14 +++----------- drivers/gpu/drm/radeon/radeon_ttm.c | 13 ++----------- drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++++++ include/drm/ttm/ttm_bo_driver.h | 3 +++ 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index efb74ddc1877..72a1c06ef15c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -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 || diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 08beb92b0571..9b5acb7dae50 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -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. */ diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 6698e288cfbc..83ca0a519752 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -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 || diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 7ea7ed85e289..a3955fde448b 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -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); diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index a7507dfaa89d..a89149b440b0 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -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 * -- 2.27.0 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel