Commit 98cca519 authored by Christian König's avatar Christian König

drm/ttm: cleanup ttm_resource_compat

Move that function into the resource handling and remove an unused parameter.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarHuang Rui <ray.huang@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210831112110.113196-1-christian.koenig@amd.com
parent 044e55b1
...@@ -924,57 +924,11 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, ...@@ -924,57 +924,11 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
return ret; return ret;
} }
static bool ttm_bo_places_compat(const struct ttm_place *places,
unsigned num_placement,
struct ttm_resource *mem,
uint32_t *new_flags)
{
unsigned i;
if (mem->placement & TTM_PL_FLAG_TEMPORARY)
return false;
for (i = 0; i < num_placement; i++) {
const struct ttm_place *heap = &places[i];
if ((mem->start < heap->fpfn ||
(heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn)))
continue;
*new_flags = heap->flags;
if ((mem->mem_type == heap->mem_type) &&
(!(*new_flags & TTM_PL_FLAG_CONTIGUOUS) ||
(mem->placement & TTM_PL_FLAG_CONTIGUOUS)))
return true;
}
return false;
}
bool ttm_bo_mem_compat(struct ttm_placement *placement,
struct ttm_resource *mem,
uint32_t *new_flags)
{
if (ttm_bo_places_compat(placement->placement, placement->num_placement,
mem, new_flags))
return true;
if ((placement->busy_placement != placement->placement ||
placement->num_busy_placement > placement->num_placement) &&
ttm_bo_places_compat(placement->busy_placement,
placement->num_busy_placement,
mem, new_flags))
return true;
return false;
}
EXPORT_SYMBOL(ttm_bo_mem_compat);
int ttm_bo_validate(struct ttm_buffer_object *bo, int ttm_bo_validate(struct ttm_buffer_object *bo,
struct ttm_placement *placement, struct ttm_placement *placement,
struct ttm_operation_ctx *ctx) struct ttm_operation_ctx *ctx)
{ {
int ret; int ret;
uint32_t new_flags;
dma_resv_assert_held(bo->base.resv); dma_resv_assert_held(bo->base.resv);
...@@ -987,7 +941,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, ...@@ -987,7 +941,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
/* /*
* Check whether we need to move buffer. * Check whether we need to move buffer.
*/ */
if (!ttm_bo_mem_compat(placement, bo->resource, &new_flags)) { if (!ttm_resource_compat(bo->resource, placement)) {
ret = ttm_bo_move_buffer(bo, placement, ctx); ret = ttm_bo_move_buffer(bo, placement, ctx);
if (ret) if (ret)
return ret; return ret;
......
...@@ -67,6 +67,55 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res) ...@@ -67,6 +67,55 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
} }
EXPORT_SYMBOL(ttm_resource_free); EXPORT_SYMBOL(ttm_resource_free);
static bool ttm_resource_places_compat(struct ttm_resource *res,
const struct ttm_place *places,
unsigned num_placement)
{
unsigned i;
if (res->placement & TTM_PL_FLAG_TEMPORARY)
return false;
for (i = 0; i < num_placement; i++) {
const struct ttm_place *heap = &places[i];
if (res->start < heap->fpfn || (heap->lpfn &&
(res->start + res->num_pages) > heap->lpfn))
continue;
if ((res->mem_type == heap->mem_type) &&
(!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
(res->placement & TTM_PL_FLAG_CONTIGUOUS)))
return true;
}
return false;
}
/**
* ttm_resource_compat - check if resource is compatible with placement
*
* @res: the resource to check
* @placement: the placement to check against
*
* Returns true if the placement is compatible.
*/
bool ttm_resource_compat(struct ttm_resource *res,
struct ttm_placement *placement)
{
if (ttm_resource_places_compat(res, placement->placement,
placement->num_placement))
return true;
if ((placement->busy_placement != placement->placement ||
placement->num_busy_placement > placement->num_placement) &&
ttm_resource_places_compat(res, placement->busy_placement,
placement->num_busy_placement))
return true;
return false;
}
EXPORT_SYMBOL(ttm_resource_compat);
/** /**
* ttm_resource_manager_init * ttm_resource_manager_init
* *
......
...@@ -94,7 +94,6 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv, ...@@ -94,7 +94,6 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
struct ttm_operation_ctx ctx = {interruptible, false }; struct ttm_operation_ctx ctx = {interruptible, false };
struct ttm_buffer_object *bo = &buf->base; struct ttm_buffer_object *bo = &buf->base;
int ret; int ret;
uint32_t new_flags;
vmw_execbuf_release_pinned_bo(dev_priv); vmw_execbuf_release_pinned_bo(dev_priv);
...@@ -103,8 +102,8 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv, ...@@ -103,8 +102,8 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
goto err; goto err;
if (buf->base.pin_count > 0) if (buf->base.pin_count > 0)
ret = ttm_bo_mem_compat(placement, bo->resource, ret = ttm_resource_compat(bo->resource, placement)
&new_flags) == true ? 0 : -EINVAL; ? 0 : -EINVAL;
else else
ret = ttm_bo_validate(bo, placement, &ctx); ret = ttm_bo_validate(bo, placement, &ctx);
...@@ -136,7 +135,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, ...@@ -136,7 +135,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
struct ttm_operation_ctx ctx = {interruptible, false }; struct ttm_operation_ctx ctx = {interruptible, false };
struct ttm_buffer_object *bo = &buf->base; struct ttm_buffer_object *bo = &buf->base;
int ret; int ret;
uint32_t new_flags;
vmw_execbuf_release_pinned_bo(dev_priv); vmw_execbuf_release_pinned_bo(dev_priv);
...@@ -145,8 +143,8 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, ...@@ -145,8 +143,8 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
goto err; goto err;
if (buf->base.pin_count > 0) { if (buf->base.pin_count > 0) {
ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, bo->resource, ret = ttm_resource_compat(bo->resource, &vmw_vram_gmr_placement)
&new_flags) == true ? 0 : -EINVAL; ? 0 : -EINVAL;
goto out_unreserve; goto out_unreserve;
} }
...@@ -208,7 +206,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv, ...@@ -208,7 +206,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
struct ttm_placement placement; struct ttm_placement placement;
struct ttm_place place; struct ttm_place place;
int ret = 0; int ret = 0;
uint32_t new_flags;
place = vmw_vram_placement.placement[0]; place = vmw_vram_placement.placement[0];
place.lpfn = bo->resource->num_pages; place.lpfn = bo->resource->num_pages;
...@@ -236,8 +233,8 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv, ...@@ -236,8 +233,8 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
} }
if (buf->base.pin_count > 0) if (buf->base.pin_count > 0)
ret = ttm_bo_mem_compat(&placement, bo->resource, ret = ttm_resource_compat(bo->resource, &placement)
&new_flags) == true ? 0 : -EINVAL; ? 0 : -EINVAL;
else else
ret = ttm_bo_validate(bo, &placement, &ctx); ret = ttm_bo_validate(bo, &placement, &ctx);
......
...@@ -264,18 +264,6 @@ static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_opera ...@@ -264,18 +264,6 @@ static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_opera
return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu); return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
} }
/**
* ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
*
* @placement: Return immediately if buffer is busy.
* @mem: The struct ttm_resource indicating the region where the bo resides
* @new_flags: Describes compatible placement found
*
* Returns true if the placement is compatible
*/
bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
uint32_t *new_flags);
/** /**
* ttm_bo_validate * ttm_bo_validate
* *
......
...@@ -40,6 +40,7 @@ struct ttm_resource_manager; ...@@ -40,6 +40,7 @@ struct ttm_resource_manager;
struct ttm_resource; struct ttm_resource;
struct ttm_place; struct ttm_place;
struct ttm_buffer_object; struct ttm_buffer_object;
struct ttm_placement;
struct dma_buf_map; struct dma_buf_map;
struct io_mapping; struct io_mapping;
struct sg_table; struct sg_table;
...@@ -266,6 +267,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo, ...@@ -266,6 +267,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
const struct ttm_place *place, const struct ttm_place *place,
struct ttm_resource **res); struct ttm_resource **res);
void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res); void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
bool ttm_resource_compat(struct ttm_resource *res,
struct ttm_placement *placement);
void ttm_resource_manager_init(struct ttm_resource_manager *man, void ttm_resource_manager_init(struct ttm_resource_manager *man,
unsigned long p_size); unsigned long p_size);
......
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