diff options
Diffstat (limited to 'drivers/gpu/drm/ttm/ttm_resource.c')
| -rw-r--r-- | drivers/gpu/drm/ttm/ttm_resource.c | 28 | 
1 files changed, 22 insertions, 6 deletions
| diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 6d764ba88aab..a87665eb28a6 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -30,6 +30,7 @@  #include <drm/ttm/ttm_bo.h>  #include <drm/ttm/ttm_placement.h>  #include <drm/ttm/ttm_resource.h> +#include <drm/ttm/ttm_tt.h>  #include <drm/drm_util.h> @@ -235,11 +236,26 @@ static void ttm_lru_bulk_move_del(struct ttm_lru_bulk_move *bulk,  	}  } +static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_object *bo) +{ +	/* +	 * Take care when creating a new resource for a bo, that it is not considered +	 * swapped if it's not the current resource for the bo and is thus logically +	 * associated with the ttm_tt. Think a VRAM resource created to move a +	 * swapped-out bo to VRAM. +	 */ +	if (bo->resource != res || !bo->ttm) +		return false; + +	dma_resv_assert_held(bo->base.resv); +	return ttm_tt_is_swapped(bo->ttm); +} +  /* Add the resource to a bulk move if the BO is configured for it */  void ttm_resource_add_bulk_move(struct ttm_resource *res,  				struct ttm_buffer_object *bo)  { -	if (bo->bulk_move && !bo->pin_count) +	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))  		ttm_lru_bulk_move_add(bo->bulk_move, res);  } @@ -247,7 +263,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res,  void ttm_resource_del_bulk_move(struct ttm_resource *res,  				struct ttm_buffer_object *bo)  { -	if (bo->bulk_move && !bo->pin_count) +	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))  		ttm_lru_bulk_move_del(bo->bulk_move, res);  } @@ -259,8 +275,8 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res)  	lockdep_assert_held(&bo->bdev->lru_lock); -	if (bo->pin_count) { -		list_move_tail(&res->lru.link, &bdev->pinned); +	if (bo->pin_count || ttm_resource_is_swapped(res, bo)) { +		list_move_tail(&res->lru.link, &bdev->unevictable);  	} else	if (bo->bulk_move) {  		struct ttm_lru_bulk_move_pos *pos = @@ -301,8 +317,8 @@ void ttm_resource_init(struct ttm_buffer_object *bo,  	man = ttm_manager_type(bo->bdev, place->mem_type);  	spin_lock(&bo->bdev->lru_lock); -	if (bo->pin_count) -		list_add_tail(&res->lru.link, &bo->bdev->pinned); +	if (bo->pin_count || ttm_resource_is_swapped(res, bo)) +		list_add_tail(&res->lru.link, &bo->bdev->unevictable);  	else  		list_add_tail(&res->lru.link, &man->lru[bo->priority]);  	man->usage += res->size; | 
