Commit 018b7fc3 authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/ttm: cleanup and optimize ttm_bo_mem_compat v2

No need to implement the same logic twice. Also check if the busy placements
are identical to the already scanned placements before checking them.

v2: improve check even more as suggested by Michel.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarNicolai Hähnle <nicolai.haehnle@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 76e15e02
...@@ -1020,16 +1020,17 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, ...@@ -1020,16 +1020,17 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
return ret; return ret;
} }
bool ttm_bo_mem_compat(struct ttm_placement *placement, static bool ttm_bo_places_compat(const struct ttm_place *places,
unsigned num_placement,
struct ttm_mem_reg *mem, struct ttm_mem_reg *mem,
uint32_t *new_flags) uint32_t *new_flags)
{ {
int i; unsigned i;
for (i = 0; i < placement->num_placement; i++) { for (i = 0; i < num_placement; i++) {
const struct ttm_place *heap = &placement->placement[i]; const struct ttm_place *heap = &places[i];
if (mem->mm_node &&
(mem->start < heap->fpfn || if (mem->mm_node && (mem->start < heap->fpfn ||
(heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn))) (heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn)))
continue; continue;
...@@ -1038,19 +1039,23 @@ bool ttm_bo_mem_compat(struct ttm_placement *placement, ...@@ -1038,19 +1039,23 @@ bool ttm_bo_mem_compat(struct ttm_placement *placement,
(*new_flags & mem->placement & TTM_PL_MASK_MEM)) (*new_flags & mem->placement & TTM_PL_MASK_MEM))
return true; return true;
} }
return false;
}
for (i = 0; i < placement->num_busy_placement; i++) { bool ttm_bo_mem_compat(struct ttm_placement *placement,
const struct ttm_place *heap = &placement->busy_placement[i]; struct ttm_mem_reg *mem,
if (mem->mm_node && uint32_t *new_flags)
(mem->start < heap->fpfn || {
(heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn))) if (ttm_bo_places_compat(placement->placement, placement->num_placement,
continue; mem, new_flags))
return true;
*new_flags = heap->flags; if ((placement->busy_placement != placement->placement ||
if ((*new_flags & mem->placement & TTM_PL_MASK_CACHING) && placement->num_busy_placement > placement->num_placement) &&
(*new_flags & mem->placement & TTM_PL_MASK_MEM)) ttm_bo_places_compat(placement->busy_placement,
placement->num_busy_placement,
mem, new_flags))
return true; return true;
}
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment