diff mbox series

[10/10] drm/ttm: reverse move calling pattern.

Message ID 20200923030454.362731-11-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series ttm driver cleanups and invert move | expand

Commit Message

Dave Airlie Sept. 23, 2020, 3:04 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

Call the driver move function if it exists, otherwise use the
fallback ttm/memcpy paths.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

Comments

Christian König Sept. 23, 2020, 2:45 p.m. UTC | #1
Am 23.09.20 um 05:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Call the driver move function if it exists, otherwise use the
> fallback ttm/memcpy paths.

I would rather like to see the move callback made mandatory instead.

Christian.

>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 28 +++++++++++++++++++---------
>   1 file changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 993a87443c37..3d9c62cdf38d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -229,6 +229,23 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>   }
>   EXPORT_SYMBOL(ttm_bo_bulk_move_lru_tail);
>   
> +static int ttm_bo_move_fallback(struct ttm_buffer_object *bo,
> +				struct ttm_operation_ctx *ctx,
> +				struct ttm_resource *mem)
> +{
> +	struct ttm_resource_manager *old_man = ttm_manager_type(bo->bdev, bo->mem.mem_type);
> +	struct ttm_resource_manager *new_man = ttm_manager_type(bo->bdev, mem->mem_type);
> +
> +	if (old_man->use_tt && new_man->use_tt) {
> +		if (bo->mem.mem_type == TTM_PL_SYSTEM) {
> +			ttm_bo_assign_mem(bo, mem);
> +			return 0;
> +		} else
> +			return ttm_bo_move_ttm(bo, ctx, mem);
> +	} else
> +		return ttm_bo_move_memcpy(bo, ctx, mem);
> +}
> +
>   static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>   				  struct ttm_resource *mem, bool evict,
>   				  struct ttm_operation_ctx *ctx)
> @@ -270,17 +287,10 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>   	if (bdev->driver->move_notify)
>   		bdev->driver->move_notify(bo, evict, mem);
>   
> -	if (old_man->use_tt && new_man->use_tt) {
> -		if (bo->mem.mem_type == TTM_PL_SYSTEM) {
> -			ttm_bo_assign_mem(bo, mem);
> -			ret = 0;
> -		} else
> -			ret = ttm_bo_move_ttm(bo, ctx, mem);
> -	}
> -	else if (bdev->driver->move)
> +	if (bdev->driver->move)
>   		ret = bdev->driver->move(bo, evict, ctx, mem);
>   	else
> -		ret = ttm_bo_move_memcpy(bo, ctx, mem);
> +		ret = ttm_bo_move_fallback(bo, ctx, mem);
>   
>   	if (ret) {
>   		if (bdev->driver->move_notify) {
Dave Airlie Sept. 23, 2020, 8:43 p.m. UTC | #2
On Thu, 24 Sep 2020 at 00:45, Christian König <christian.koenig@amd.com> wrote:
>
> Am 23.09.20 um 05:04 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > Call the driver move function if it exists, otherwise use the
> > fallback ttm/memcpy paths.
>
> I would rather like to see the move callback made mandatory instead.

Indeed this makes some stuff just easier to deal with.

Dave.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 993a87443c37..3d9c62cdf38d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -229,6 +229,23 @@  void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
 }
 EXPORT_SYMBOL(ttm_bo_bulk_move_lru_tail);
 
+static int ttm_bo_move_fallback(struct ttm_buffer_object *bo,
+				struct ttm_operation_ctx *ctx,
+				struct ttm_resource *mem)
+{
+	struct ttm_resource_manager *old_man = ttm_manager_type(bo->bdev, bo->mem.mem_type);
+	struct ttm_resource_manager *new_man = ttm_manager_type(bo->bdev, mem->mem_type);
+
+	if (old_man->use_tt && new_man->use_tt) {
+		if (bo->mem.mem_type == TTM_PL_SYSTEM) {
+			ttm_bo_assign_mem(bo, mem);
+			return 0;
+		} else
+			return ttm_bo_move_ttm(bo, ctx, mem);
+	} else
+		return ttm_bo_move_memcpy(bo, ctx, mem);
+}
+
 static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 				  struct ttm_resource *mem, bool evict,
 				  struct ttm_operation_ctx *ctx)
@@ -270,17 +287,10 @@  static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 	if (bdev->driver->move_notify)
 		bdev->driver->move_notify(bo, evict, mem);
 
-	if (old_man->use_tt && new_man->use_tt) {
-		if (bo->mem.mem_type == TTM_PL_SYSTEM) {
-			ttm_bo_assign_mem(bo, mem);
-			ret = 0;
-		} else
-			ret = ttm_bo_move_ttm(bo, ctx, mem);
-	}
-	else if (bdev->driver->move)
+	if (bdev->driver->move)
 		ret = bdev->driver->move(bo, evict, ctx, mem);
 	else
-		ret = ttm_bo_move_memcpy(bo, ctx, mem);
+		ret = ttm_bo_move_fallback(bo, ctx, mem);
 
 	if (ret) {
 		if (bdev->driver->move_notify) {