Commit fda8d552 authored by Christian König's avatar Christian König

drm/ttm: add a weak BO reference to the resource v3

Keep track for which BO a resource was allocated.
This is necessary to move the LRU handling into the resources.

A bit problematic is i915 since it tries to use the resource
interface without a BO which is illegal from the conceptional
point of view.

v2: Document that this is a weak reference and add a workaround for i915
v3: further document that this is protected by ttm_device::lru_lock and
    clarify the i915 workaround
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Acked-by: default avatarHuang Rui <ray.huang@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220124122514.1832-4-christian.koenig@amd.com
parent 3f268ef0
...@@ -241,6 +241,11 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, ...@@ -241,6 +241,11 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
if (bo->type != ttm_bo_type_sg) if (bo->type != ttm_bo_type_sg)
fbo->base.base.resv = &fbo->base.base._resv; fbo->base.base.resv = &fbo->base.base._resv;
if (fbo->base.resource) {
ttm_resource_set_bo(fbo->base.resource, &fbo->base);
bo->resource = NULL;
}
dma_resv_init(&fbo->base.base._resv); dma_resv_init(&fbo->base.base._resv);
fbo->base.base.dev = NULL; fbo->base.base.dev = NULL;
ret = dma_resv_trylock(&fbo->base.base._resv); ret = dma_resv_trylock(&fbo->base.base._resv);
...@@ -509,7 +514,6 @@ static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo, ...@@ -509,7 +514,6 @@ static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo,
ghost_obj->ttm = NULL; ghost_obj->ttm = NULL;
else else
bo->ttm = NULL; bo->ttm = NULL;
bo->resource = NULL;
dma_resv_unlock(&ghost_obj->base._resv); dma_resv_unlock(&ghost_obj->base._resv);
ttm_bo_put(ghost_obj); ttm_bo_put(ghost_obj);
...@@ -637,7 +641,6 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo) ...@@ -637,7 +641,6 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
dma_resv_unlock(&ghost->base._resv); dma_resv_unlock(&ghost->base._resv);
ttm_bo_put(ghost); ttm_bo_put(ghost);
bo->ttm = ttm; bo->ttm = ttm;
bo->resource = NULL;
ttm_bo_assign_mem(bo, sys_res); ttm_bo_assign_mem(bo, sys_res);
return 0; return 0;
......
...@@ -49,6 +49,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo, ...@@ -49,6 +49,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
res->bus.offset = 0; res->bus.offset = 0;
res->bus.is_iomem = false; res->bus.is_iomem = false;
res->bus.caching = ttm_cached; res->bus.caching = ttm_cached;
res->bo = bo;
} }
EXPORT_SYMBOL(ttm_resource_init); EXPORT_SYMBOL(ttm_resource_init);
...@@ -139,6 +140,14 @@ bool ttm_resource_compat(struct ttm_resource *res, ...@@ -139,6 +140,14 @@ bool ttm_resource_compat(struct ttm_resource *res,
} }
EXPORT_SYMBOL(ttm_resource_compat); EXPORT_SYMBOL(ttm_resource_compat);
void ttm_resource_set_bo(struct ttm_resource *res,
struct ttm_buffer_object *bo)
{
spin_lock(&bo->bdev->lru_lock);
res->bo = bo;
spin_unlock(&bo->bdev->lru_lock);
}
/** /**
* ttm_resource_manager_init * ttm_resource_manager_init
* *
......
...@@ -161,6 +161,7 @@ struct ttm_bus_placement { ...@@ -161,6 +161,7 @@ struct ttm_bus_placement {
* @mem_type: Resource type of the allocation. * @mem_type: Resource type of the allocation.
* @placement: Placement flags. * @placement: Placement flags.
* @bus: Placement on io bus accessible to the CPU * @bus: Placement on io bus accessible to the CPU
* @bo: weak reference to the BO, protected by ttm_device::lru_lock
* *
* Structure indicating the placement and space resources used by a * Structure indicating the placement and space resources used by a
* buffer object. * buffer object.
...@@ -171,6 +172,7 @@ struct ttm_resource { ...@@ -171,6 +172,7 @@ struct ttm_resource {
uint32_t mem_type; uint32_t mem_type;
uint32_t placement; uint32_t placement;
struct ttm_bus_placement bus; struct ttm_bus_placement bus;
struct ttm_buffer_object *bo;
}; };
/** /**
...@@ -271,6 +273,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo, ...@@ -271,6 +273,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
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, bool ttm_resource_compat(struct ttm_resource *res,
struct ttm_placement *placement); struct ttm_placement *placement);
void ttm_resource_set_bo(struct ttm_resource *res,
struct ttm_buffer_object *bo);
void ttm_resource_manager_init(struct ttm_resource_manager *man, void ttm_resource_manager_init(struct ttm_resource_manager *man,
struct ttm_device *bdev, struct ttm_device *bdev,
......
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