Commit 83876c1b authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/ttm: use the operation context inside TTM

Instead of passing down the parameters manually to every function.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarMichel Dänzer <michel.daenzer@amd.com>
Reviewed-by: default avatarChunming Zhou <david1.zhou@amd.com>
Tested-by: default avatarDieter Nützel <Dieter@nuetzel-hh.de>
Tested-by: default avatarMichel Dänzer <michel.daenzer@amd.com>
Acked-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent c13c55d6
...@@ -269,9 +269,8 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc) ...@@ -269,9 +269,8 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc)
} }
static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
struct ttm_mem_reg *mem, struct ttm_mem_reg *mem, bool evict,
bool evict, bool interruptible, struct ttm_operation_ctx *ctx)
bool no_wait_gpu)
{ {
struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_device *bdev = bo->bdev;
bool old_is_pci = ttm_mem_reg_is_pci(bdev, &bo->mem); bool old_is_pci = ttm_mem_reg_is_pci(bdev, &bo->mem);
...@@ -325,12 +324,14 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, ...@@ -325,12 +324,14 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) && if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) &&
!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) !(new_man->flags & TTM_MEMTYPE_FLAG_FIXED))
ret = ttm_bo_move_ttm(bo, interruptible, no_wait_gpu, mem); ret = ttm_bo_move_ttm(bo, ctx->interruptible,
ctx->no_wait_gpu, mem);
else if (bdev->driver->move) else if (bdev->driver->move)
ret = bdev->driver->move(bo, evict, interruptible, ret = bdev->driver->move(bo, evict, ctx->interruptible,
no_wait_gpu, mem); ctx->no_wait_gpu, mem);
else else
ret = ttm_bo_move_memcpy(bo, interruptible, no_wait_gpu, mem); ret = ttm_bo_move_memcpy(bo, ctx->interruptible,
ctx->no_wait_gpu, mem);
if (ret) { if (ret) {
if (bdev->driver->move_notify) { if (bdev->driver->move_notify) {
...@@ -653,10 +654,9 @@ void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched) ...@@ -653,10 +654,9 @@ void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched)
} }
EXPORT_SYMBOL(ttm_bo_unlock_delayed_workqueue); EXPORT_SYMBOL(ttm_bo_unlock_delayed_workqueue);
static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, static int ttm_bo_evict(struct ttm_buffer_object *bo,
bool no_wait_gpu) struct ttm_operation_ctx *ctx)
{ {
struct ttm_operation_ctx ctx = { interruptible, no_wait_gpu };
struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_device *bdev = bo->bdev;
struct ttm_mem_reg evict_mem; struct ttm_mem_reg evict_mem;
struct ttm_placement placement; struct ttm_placement placement;
...@@ -672,7 +672,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, ...@@ -672,7 +672,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
placement.num_placement = 0; placement.num_placement = 0;
placement.num_busy_placement = 0; placement.num_busy_placement = 0;
bdev->driver->evict_flags(bo, &placement); bdev->driver->evict_flags(bo, &placement);
ret = ttm_bo_mem_space(bo, &placement, &evict_mem, &ctx); ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx);
if (ret) { if (ret) {
if (ret != -ERESTARTSYS) { if (ret != -ERESTARTSYS) {
pr_err("Failed to find memory space for buffer 0x%p eviction\n", pr_err("Failed to find memory space for buffer 0x%p eviction\n",
...@@ -682,8 +682,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, ...@@ -682,8 +682,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
goto out; goto out;
} }
ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, ctx);
interruptible, no_wait_gpu);
if (unlikely(ret)) { if (unlikely(ret)) {
if (ret != -ERESTARTSYS) if (ret != -ERESTARTSYS)
pr_err("Buffer eviction failed\n"); pr_err("Buffer eviction failed\n");
...@@ -713,8 +712,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ...@@ -713,8 +712,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
struct reservation_object *resv, struct reservation_object *resv,
uint32_t mem_type, uint32_t mem_type,
const struct ttm_place *place, const struct ttm_place *place,
bool interruptible, struct ttm_operation_ctx *ctx)
bool no_wait_gpu)
{ {
struct ttm_bo_global *glob = bdev->glob; struct ttm_bo_global *glob = bdev->glob;
struct ttm_mem_type_manager *man = &bdev->man[mem_type]; struct ttm_mem_type_manager *man = &bdev->man[mem_type];
...@@ -759,8 +757,8 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ...@@ -759,8 +757,8 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
kref_get(&bo->list_kref); kref_get(&bo->list_kref);
if (!list_empty(&bo->ddestroy)) { if (!list_empty(&bo->ddestroy)) {
ret = ttm_bo_cleanup_refs(bo, interruptible, no_wait_gpu, ret = ttm_bo_cleanup_refs(bo, ctx->interruptible,
locked); ctx->no_wait_gpu, locked);
kref_put(&bo->list_kref, ttm_bo_release_list); kref_put(&bo->list_kref, ttm_bo_release_list);
return ret; return ret;
} }
...@@ -768,7 +766,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ...@@ -768,7 +766,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
ttm_bo_del_from_lru(bo); ttm_bo_del_from_lru(bo);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
ret = ttm_bo_evict(bo, interruptible, no_wait_gpu); ret = ttm_bo_evict(bo, ctx);
if (locked) { if (locked) {
ttm_bo_unreserve(bo); ttm_bo_unreserve(bo);
} else { } else {
...@@ -826,8 +824,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, ...@@ -826,8 +824,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
uint32_t mem_type, uint32_t mem_type,
const struct ttm_place *place, const struct ttm_place *place,
struct ttm_mem_reg *mem, struct ttm_mem_reg *mem,
bool interruptible, struct ttm_operation_ctx *ctx)
bool no_wait_gpu)
{ {
struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_device *bdev = bo->bdev;
struct ttm_mem_type_manager *man = &bdev->man[mem_type]; struct ttm_mem_type_manager *man = &bdev->man[mem_type];
...@@ -839,8 +836,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, ...@@ -839,8 +836,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
return ret; return ret;
if (mem->mm_node) if (mem->mm_node)
break; break;
ret = ttm_mem_evict_first(bdev, bo->resv, mem_type, place, ret = ttm_mem_evict_first(bdev, bo->resv, mem_type, place, ctx);
interruptible, no_wait_gpu);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
return ret; return ret;
} while (1); } while (1);
...@@ -997,9 +993,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, ...@@ -997,9 +993,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
return 0; return 0;
} }
ret = ttm_bo_mem_force_space(bo, mem_type, place, mem, ret = ttm_bo_mem_force_space(bo, mem_type, place, mem, ctx);
ctx->interruptible,
ctx->no_wait_gpu);
if (ret == 0 && mem->mm_node) { if (ret == 0 && mem->mm_node) {
mem->placement = cur_flags; mem->placement = cur_flags;
return 0; return 0;
...@@ -1019,10 +1013,8 @@ EXPORT_SYMBOL(ttm_bo_mem_space); ...@@ -1019,10 +1013,8 @@ EXPORT_SYMBOL(ttm_bo_mem_space);
static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
struct ttm_placement *placement, struct ttm_placement *placement,
bool interruptible, struct ttm_operation_ctx *ctx)
bool no_wait_gpu)
{ {
struct ttm_operation_ctx ctx = { interruptible, no_wait_gpu };
int ret = 0; int ret = 0;
struct ttm_mem_reg mem; struct ttm_mem_reg mem;
...@@ -1036,11 +1028,10 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, ...@@ -1036,11 +1028,10 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
/* /*
* Determine where to move the buffer. * Determine where to move the buffer.
*/ */
ret = ttm_bo_mem_space(bo, placement, &mem, &ctx); ret = ttm_bo_mem_space(bo, placement, &mem, ctx);
if (ret) if (ret)
goto out_unlock; goto out_unlock;
ret = ttm_bo_handle_move_mem(bo, &mem, false, interruptible, ret = ttm_bo_handle_move_mem(bo, &mem, false, ctx);
no_wait_gpu);
out_unlock: out_unlock:
if (ret && mem.mm_node) if (ret && mem.mm_node)
ttm_bo_mem_put(bo, &mem); ttm_bo_mem_put(bo, &mem);
...@@ -1102,8 +1093,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, ...@@ -1102,8 +1093,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->mem, &new_flags)) { if (!ttm_bo_mem_compat(placement, &bo->mem, &new_flags)) {
ret = ttm_bo_move_buffer(bo, placement, ctx->interruptible, ret = ttm_bo_move_buffer(bo, placement, ctx);
ctx->no_wait_gpu);
if (ret) if (ret)
return ret; return ret;
} else { } else {
...@@ -1328,6 +1318,7 @@ EXPORT_SYMBOL(ttm_bo_create); ...@@ -1328,6 +1318,7 @@ EXPORT_SYMBOL(ttm_bo_create);
static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
unsigned mem_type) unsigned mem_type)
{ {
struct ttm_operation_ctx ctx = { false, false };
struct ttm_mem_type_manager *man = &bdev->man[mem_type]; struct ttm_mem_type_manager *man = &bdev->man[mem_type];
struct ttm_bo_global *glob = bdev->glob; struct ttm_bo_global *glob = bdev->glob;
struct dma_fence *fence; struct dma_fence *fence;
...@@ -1342,8 +1333,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, ...@@ -1342,8 +1333,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
while (!list_empty(&man->lru[i])) { while (!list_empty(&man->lru[i])) {
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
ret = ttm_mem_evict_first(bdev, NULL, mem_type, NULL, ret = ttm_mem_evict_first(bdev, NULL, mem_type,
false, false); NULL, &ctx);
if (ret) if (ret)
return ret; return ret;
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
...@@ -1740,6 +1731,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) ...@@ -1740,6 +1731,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
if (bo->mem.mem_type != TTM_PL_SYSTEM || if (bo->mem.mem_type != TTM_PL_SYSTEM ||
bo->ttm->caching_state != tt_cached) { bo->ttm->caching_state != tt_cached) {
struct ttm_operation_ctx ctx = { false, false };
struct ttm_mem_reg evict_mem; struct ttm_mem_reg evict_mem;
evict_mem = bo->mem; evict_mem = bo->mem;
...@@ -1747,8 +1739,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) ...@@ -1747,8 +1739,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
evict_mem.placement = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED; evict_mem.placement = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED;
evict_mem.mem_type = TTM_PL_SYSTEM; evict_mem.mem_type = TTM_PL_SYSTEM;
ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, &ctx);
false, false);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out; goto out;
} }
......
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