diff mbox series

[2/5] drm/ttm: split out the move to system from move ttm code

Message ID 20201019071314.1671485-3-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series ttm get rid of ttm_bo_move_ttm | expand

Commit Message

Dave Airlie Oct. 19, 2020, 7:13 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

Reviewed-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 38 ++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 13 deletions(-)

Comments

Christian König Oct. 19, 2020, 9:57 a.m. UTC | #1
Am 19.10.20 um 09:13 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Reviewed-by: Ben Skeggs <bskeggs@redhat.com>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Maybe just call it ...move_to_system(), but either way Reviewed-by: 
Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 38 ++++++++++++++++++++-----------
>   1 file changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index a36c615bdf24..29726652fef7 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -65,6 +65,28 @@ int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
>   	return 0;
>   }
>   
> +static int ttm_bo_move_old_to_system(struct ttm_buffer_object *bo,
> +				     struct ttm_operation_ctx *ctx)
> +{
> +	struct ttm_resource *old_mem = &bo->mem;
> +	int ret;
> +
> +	if (old_mem->mem_type == TTM_PL_SYSTEM)
> +		return 0;
> +
> +	ret = ttm_bo_wait_ctx(bo, ctx);
> +	if (unlikely(ret != 0)) {
> +		if (ret != -ERESTARTSYS)
> +			pr_err("Failed to expire sync object before unbinding TTM\n");
> +		return ret;
> +	}
> +
> +	ttm_bo_tt_unbind(bo);
> +	ttm_resource_free(bo, &bo->mem);
> +	old_mem->mem_type = TTM_PL_SYSTEM;
> +	return 0;
> +}
> +
>   int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
>   		   struct ttm_operation_ctx *ctx,
>   		    struct ttm_resource *new_mem)
> @@ -72,19 +94,9 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
>   	struct ttm_resource *old_mem = &bo->mem;
>   	int ret;
>   
> -	if (old_mem->mem_type != TTM_PL_SYSTEM) {
> -		ret = ttm_bo_wait_ctx(bo, ctx);
> -
> -		if (unlikely(ret != 0)) {
> -			if (ret != -ERESTARTSYS)
> -				pr_err("Failed to expire sync object before unbinding TTM\n");
> -			return ret;
> -		}
> -
> -		ttm_bo_tt_unbind(bo);
> -		ttm_resource_free(bo, &bo->mem);
> -		old_mem->mem_type = TTM_PL_SYSTEM;
> -	}
> +	ret = ttm_bo_move_old_to_system(bo, ctx);
> +	if (unlikely(ret != 0))
> +		return ret;
>   
>   	ret = ttm_bo_move_to_new_tt_mem(bo, ctx, new_mem);
>   	if (unlikely(ret != 0))
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index a36c615bdf24..29726652fef7 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -65,6 +65,28 @@  int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
 	return 0;
 }
 
+static int ttm_bo_move_old_to_system(struct ttm_buffer_object *bo,
+				     struct ttm_operation_ctx *ctx)
+{
+	struct ttm_resource *old_mem = &bo->mem;
+	int ret;
+
+	if (old_mem->mem_type == TTM_PL_SYSTEM)
+		return 0;
+
+	ret = ttm_bo_wait_ctx(bo, ctx);
+	if (unlikely(ret != 0)) {
+		if (ret != -ERESTARTSYS)
+			pr_err("Failed to expire sync object before unbinding TTM\n");
+		return ret;
+	}
+
+	ttm_bo_tt_unbind(bo);
+	ttm_resource_free(bo, &bo->mem);
+	old_mem->mem_type = TTM_PL_SYSTEM;
+	return 0;
+}
+
 int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		   struct ttm_operation_ctx *ctx,
 		    struct ttm_resource *new_mem)
@@ -72,19 +94,9 @@  int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 	struct ttm_resource *old_mem = &bo->mem;
 	int ret;
 
-	if (old_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_bo_wait_ctx(bo, ctx);
-
-		if (unlikely(ret != 0)) {
-			if (ret != -ERESTARTSYS)
-				pr_err("Failed to expire sync object before unbinding TTM\n");
-			return ret;
-		}
-
-		ttm_bo_tt_unbind(bo);
-		ttm_resource_free(bo, &bo->mem);
-		old_mem->mem_type = TTM_PL_SYSTEM;
-	}
+	ret = ttm_bo_move_old_to_system(bo, ctx);
+	if (unlikely(ret != 0))
+		return ret;
 
 	ret = ttm_bo_move_to_new_tt_mem(bo, ctx, new_mem);
 	if (unlikely(ret != 0))