Skip to content

Commit

Permalink
ttm: Fix caching mode selection.
Browse files Browse the repository at this point in the history
A bug caused a new caching state to be selected on each buffer object
validation regardless of the current caching state.
Moreover, a caching state could be selected that wasn't supported by
the memory type.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Thomas Hellstrom authored and Dave Airlie committed Jul 15, 2009
1 parent d172407 commit ae3e812
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions drivers/gpu/drm/ttm/ttm_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,31 +655,52 @@ static int ttm_bo_mem_force_space(struct ttm_bo_device *bdev,
return 0;
}

static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man,
uint32_t cur_placement,
uint32_t proposed_placement)
{
uint32_t caching = proposed_placement & TTM_PL_MASK_CACHING;
uint32_t result = proposed_placement & ~TTM_PL_MASK_CACHING;

/**
* Keep current caching if possible.
*/

if ((cur_placement & caching) != 0)
result |= (cur_placement & caching);
else if ((man->default_caching & caching) != 0)
result |= man->default_caching;
else if ((TTM_PL_FLAG_CACHED & caching) != 0)
result |= TTM_PL_FLAG_CACHED;
else if ((TTM_PL_FLAG_WC & caching) != 0)
result |= TTM_PL_FLAG_WC;
else if ((TTM_PL_FLAG_UNCACHED & caching) != 0)
result |= TTM_PL_FLAG_UNCACHED;

return result;
}


static bool ttm_bo_mt_compatible(struct ttm_mem_type_manager *man,
bool disallow_fixed,
uint32_t mem_type,
uint32_t mask, uint32_t *res_mask)
uint32_t proposed_placement,
uint32_t *masked_placement)
{
uint32_t cur_flags = ttm_bo_type_flags(mem_type);

if ((man->flags & TTM_MEMTYPE_FLAG_FIXED) && disallow_fixed)
return false;

if ((cur_flags & mask & TTM_PL_MASK_MEM) == 0)
if ((cur_flags & proposed_placement & TTM_PL_MASK_MEM) == 0)
return false;

if ((mask & man->available_caching) == 0)
if ((proposed_placement & man->available_caching) == 0)
return false;
if (mask & man->default_caching)
cur_flags |= man->default_caching;
else if (mask & TTM_PL_FLAG_CACHED)
cur_flags |= TTM_PL_FLAG_CACHED;
else if (mask & TTM_PL_FLAG_WC)
cur_flags |= TTM_PL_FLAG_WC;
else
cur_flags |= TTM_PL_FLAG_UNCACHED;

*res_mask = cur_flags;
cur_flags |= (proposed_placement & man->available_caching);

*masked_placement = cur_flags;
return true;
}

Expand Down Expand Up @@ -723,6 +744,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
if (!type_ok)
continue;

cur_flags = ttm_bo_select_caching(man, bo->mem.placement,
cur_flags);

if (mem_type == TTM_PL_SYSTEM)
break;

Expand Down Expand Up @@ -779,6 +803,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
proposed_placement, &cur_flags))
continue;

cur_flags = ttm_bo_select_caching(man, bo->mem.placement,
cur_flags);

ret = ttm_bo_mem_force_space(bdev, mem, mem_type,
interruptible, no_wait);

Expand Down

0 comments on commit ae3e812

Please sign in to comment.