diff mbox series

[11/45] drm/ttm: split out the move to system from move ttm code

Message ID 20200924051845.397177-12-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>

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

Comments

Christian König Sept. 24, 2020, 11:22 a.m. UTC | #1
What should that be good for?

Am 24.09.20 um 07:18 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 39 ++++++++++++++++++++-----------
>   1 file changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index aecdb2d92a54..0ad02e27865d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -73,27 +73,38 @@ int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
>   	return 0;
>   }
>   
> -int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
> -		   struct ttm_operation_ctx *ctx,
> -		    struct ttm_resource *new_mem)
> +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) {
> -		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;
> -		}
> +	if (old_mem->mem_type == TTM_PL_SYSTEM)
> +		return 0;
>   
> -		ttm_bo_tt_unbind(bo);
> -		ttm_bo_free_old_node(bo);
> -		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_bo_free_old_node(bo);
> +	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)
> +{
> +	int ret;
> +
> +	ret = ttm_bo_move_old_to_system(bo, ctx);
> +	if (ret)
> +		return ret;
> +
>   	ret = ttm_bo_move_to_new_tt_mem(bo, ctx, new_mem);
>   	if (ret)
>   		return ret;
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 aecdb2d92a54..0ad02e27865d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -73,27 +73,38 @@  int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
 	return 0;
 }
 
-int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
-		   struct ttm_operation_ctx *ctx,
-		    struct ttm_resource *new_mem)
+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) {
-		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;
-		}
+	if (old_mem->mem_type == TTM_PL_SYSTEM)
+		return 0;
 
-		ttm_bo_tt_unbind(bo);
-		ttm_bo_free_old_node(bo);
-		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_bo_free_old_node(bo);
+	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)
+{
+	int ret;
+
+	ret = ttm_bo_move_old_to_system(bo, ctx);
+	if (ret)
+		return ret;
+
 	ret = ttm_bo_move_to_new_tt_mem(bo, ctx, new_mem);
 	if (ret)
 		return ret;