aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/ttm/ttm_bo.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/ttm/ttm_bo.c')
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f1a857ec1021..8d5a646ebe6a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -429,8 +429,20 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
429 sync_obj = driver->sync_obj_ref(bo->sync_obj); 429 sync_obj = driver->sync_obj_ref(bo->sync_obj);
430 spin_unlock(&bdev->fence_lock); 430 spin_unlock(&bdev->fence_lock);
431 431
432 if (!ret) 432 if (!ret) {
433
434 /*
435 * Make NO_EVICT bos immediately available to
436 * shrinkers, now that they are queued for
437 * destruction.
438 */
439 if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
440 bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
441 ttm_bo_add_to_lru(bo);
442 }
443
433 ww_mutex_unlock(&bo->resv->lock); 444 ww_mutex_unlock(&bo->resv->lock);
445 }
434 446
435 kref_get(&bo->list_kref); 447 kref_get(&bo->list_kref);
436 list_add_tail(&bo->ddestroy, &bdev->ddestroy); 448 list_add_tail(&bo->ddestroy, &bdev->ddestroy);
@@ -986,24 +998,32 @@ out_unlock:
986 return ret; 998 return ret;
987} 999}
988 1000
989static int ttm_bo_mem_compat(struct ttm_placement *placement, 1001static bool ttm_bo_mem_compat(struct ttm_placement *placement,
990 struct ttm_mem_reg *mem) 1002 struct ttm_mem_reg *mem,
1003 uint32_t *new_flags)
991{ 1004{
992 int i; 1005 int i;
993 1006
994 if (mem->mm_node && placement->lpfn != 0 && 1007 if (mem->mm_node && placement->lpfn != 0 &&
995 (mem->start < placement->fpfn || 1008 (mem->start < placement->fpfn ||
996 mem->start + mem->num_pages > placement->lpfn)) 1009 mem->start + mem->num_pages > placement->lpfn))
997 return -1; 1010 return false;
998 1011
999 for (i = 0; i < placement->num_placement; i++) { 1012 for (i = 0; i < placement->num_placement; i++) {
1000 if ((placement->placement[i] & mem->placement & 1013 *new_flags = placement->placement[i];
1001 TTM_PL_MASK_CACHING) && 1014 if ((*new_flags & mem->placement & TTM_PL_MASK_CACHING) &&
1002 (placement->placement[i] & mem->placement & 1015 (*new_flags & mem->placement & TTM_PL_MASK_MEM))
1003 TTM_PL_MASK_MEM)) 1016 return true;
1004 return i;
1005 } 1017 }
1006 return -1; 1018
1019 for (i = 0; i < placement->num_busy_placement; i++) {
1020 *new_flags = placement->busy_placement[i];
1021 if ((*new_flags & mem->placement & TTM_PL_MASK_CACHING) &&
1022 (*new_flags & mem->placement & TTM_PL_MASK_MEM))
1023 return true;
1024 }
1025
1026 return false;
1007} 1027}
1008 1028
1009int ttm_bo_validate(struct ttm_buffer_object *bo, 1029int ttm_bo_validate(struct ttm_buffer_object *bo,
@@ -1012,6 +1032,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
1012 bool no_wait_gpu) 1032 bool no_wait_gpu)
1013{ 1033{
1014 int ret; 1034 int ret;
1035 uint32_t new_flags;
1015 1036
1016 lockdep_assert_held(&bo->resv->lock.base); 1037 lockdep_assert_held(&bo->resv->lock.base);
1017 /* Check that range is valid */ 1038 /* Check that range is valid */
@@ -1022,8 +1043,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
1022 /* 1043 /*
1023 * Check whether we need to move buffer. 1044 * Check whether we need to move buffer.
1024 */ 1045 */
1025 ret = ttm_bo_mem_compat(placement, &bo->mem); 1046 if (!ttm_bo_mem_compat(placement, &bo->mem, &new_flags)) {
1026 if (ret < 0) {
1027 ret = ttm_bo_move_buffer(bo, placement, interruptible, 1047 ret = ttm_bo_move_buffer(bo, placement, interruptible,
1028 no_wait_gpu); 1048 no_wait_gpu);
1029 if (ret) 1049 if (ret)
@@ -1033,7 +1053,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
1033 * Use the access and other non-mapping-related flag bits from 1053 * Use the access and other non-mapping-related flag bits from
1034 * the compatible memory placement flags to the active flags 1054 * the compatible memory placement flags to the active flags
1035 */ 1055 */
1036 ttm_flag_masked(&bo->mem.placement, placement->placement[ret], 1056 ttm_flag_masked(&bo->mem.placement, new_flags,
1037 ~TTM_PL_MASK_MEMTYPE); 1057 ~TTM_PL_MASK_MEMTYPE);
1038 } 1058 }
1039 /* 1059 /*