[PATCH 10/45] drm/ttm: refactor out common code to setup a new tt backed resource

Christian König christian.koenig at amd.com
Thu Sep 24 11:17:20 UTC 2020


Am 24.09.20 um 07:18 schrieb Dave Airlie:
> From: Dave Airlie <airlied at redhat.com>
>
> This factors out the code to set the new caching and for non-system
> tt populate and bind things.
>
> The same code was used twice in the move paths.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>

Reviewed-by: Christian König <christian.koenig at amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c      | 12 +---------
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 40 +++++++++++++++++++------------
>   include/drm/ttm/ttm_bo_driver.h   |  3 +++
>   3 files changed, 29 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 6a7f4c028801..c8dffc8b40fc 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -252,19 +252,9 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>   		if (ret)
>   			goto out_err;
>   
> -		ret = ttm_tt_set_placement_caching(bo->ttm, mem->placement);
> +		ret = ttm_bo_move_to_new_tt_mem(bo, ctx, mem);
>   		if (ret)
>   			goto out_err;
> -
> -		if (mem->mem_type != TTM_PL_SYSTEM) {
> -			ret = ttm_tt_populate(bdev, bo->ttm, ctx);
> -			if (ret)
> -				goto out_err;
> -
> -			ret = ttm_bo_tt_bind(bo, mem);
> -			if (ret)
> -				goto out_err;
> -		}
>   	}
>   
>   	if (bdev->driver->move_notify)
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index bdee4df1f3f2..aecdb2d92a54 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -50,11 +50,33 @@ void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
>   	ttm_resource_free(bo, &bo->mem);
>   }
>   
> +int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
> +			      struct ttm_operation_ctx *ctx,
> +			      struct ttm_resource *new_mem)
> +{
> +	struct ttm_tt *ttm = bo->ttm;
> +	int ret;
> +
> +	ret = ttm_tt_set_placement_caching(ttm, new_mem->placement);
> +	if (unlikely(ret != 0))
> +		return ret;
> +
> +	if (new_mem->mem_type != TTM_PL_SYSTEM) {
> +		ret = ttm_tt_populate(bo->bdev, ttm, ctx);
> +		if (unlikely(ret != 0))
> +			return ret;
> +
> +		ret = ttm_bo_tt_bind(bo, new_mem);
> +		if (unlikely(ret != 0))
> +			return ret;
> +	}
> +	return 0;
> +}
> +
>   int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
>   		   struct ttm_operation_ctx *ctx,
>   		    struct ttm_resource *new_mem)
>   {
> -	struct ttm_tt *ttm = bo->ttm;
>   	struct ttm_resource *old_mem = &bo->mem;
>   	int ret;
>   
> @@ -72,21 +94,9 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
>   		old_mem->mem_type = TTM_PL_SYSTEM;
>   	}
>   
> -	ret = ttm_tt_set_placement_caching(ttm, new_mem->placement);
> -	if (unlikely(ret != 0))
> +	ret = ttm_bo_move_to_new_tt_mem(bo, ctx, new_mem);
> +	if (ret)
>   		return ret;
> -
> -	if (new_mem->mem_type != TTM_PL_SYSTEM) {
> -
> -		ret = ttm_tt_populate(bo->bdev, ttm, ctx);
> -		if (unlikely(ret != 0))
> -			return ret;
> -
> -		ret = ttm_bo_tt_bind(bo, new_mem);
> -		if (unlikely(ret != 0))
> -			return ret;
> -	}
> -
>   	ttm_bo_assign_mem(bo, new_mem);
>   	return 0;
>   }
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 864afa8f6f18..20e6839e9b73 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -605,6 +605,9 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
>   		    struct ttm_operation_ctx *ctx,
>   		    struct ttm_resource *new_mem);
>   
> +int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
> +			      struct ttm_operation_ctx *ctx,
> +			      struct ttm_resource *new_mem);
>   /**
>    * ttm_bo_move_memcpy
>    *



More information about the dri-devel mailing list