Commit 2ddef176 authored by Christian König's avatar Christian König

drm/ttm: make TT creation purely optional v3

We only need the page array when the BO is about to be accessed.

So not only populate, but also create it on demand.

v2: move NULL check into ttm_tt_create()
v3: fix the occurrence in ttm_bo_kmap_ttm as well
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarMichael J. Ruhl <michael.j.ruhl@intel.com>
Link: https://patchwork.freedesktop.org/patch/373182/
parent 58e4d686
...@@ -292,12 +292,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, ...@@ -292,12 +292,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
*/ */
if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) { if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) {
if (bo->ttm == NULL) { bool zero = !(old_man->flags & TTM_MEMTYPE_FLAG_FIXED);
bool zero = !(old_man->flags & TTM_MEMTYPE_FLAG_FIXED);
ret = ttm_tt_create(bo, zero); ret = ttm_tt_create(bo, zero);
if (ret) if (ret)
goto out_err; goto out_err;
}
ret = ttm_tt_set_placement_caching(bo->ttm, mem->placement); ret = ttm_tt_set_placement_caching(bo->ttm, mem->placement);
if (ret) if (ret)
...@@ -660,13 +659,8 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, ...@@ -660,13 +659,8 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
placement.num_busy_placement = 0; placement.num_busy_placement = 0;
bdev->driver->evict_flags(bo, &placement); bdev->driver->evict_flags(bo, &placement);
if (!placement.num_placement && !placement.num_busy_placement) { if (!placement.num_placement && !placement.num_busy_placement)
ret = ttm_bo_pipeline_gutting(bo); return ttm_bo_pipeline_gutting(bo);
if (ret)
return ret;
return ttm_tt_create(bo, false);
}
evict_mem = bo->mem; evict_mem = bo->mem;
evict_mem.mm_node = NULL; evict_mem.mm_node = NULL;
...@@ -1195,13 +1189,8 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, ...@@ -1195,13 +1189,8 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
/* /*
* Remove the backing store if no placement is given. * Remove the backing store if no placement is given.
*/ */
if (!placement->num_placement && !placement->num_busy_placement) { if (!placement->num_placement && !placement->num_busy_placement)
ret = ttm_bo_pipeline_gutting(bo); return ttm_bo_pipeline_gutting(bo);
if (ret)
return ret;
return ttm_tt_create(bo, false);
}
/* /*
* Check whether we need to move buffer. * Check whether we need to move buffer.
...@@ -1218,14 +1207,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, ...@@ -1218,14 +1207,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
ttm_flag_masked(&bo->mem.placement, new_flags, ttm_flag_masked(&bo->mem.placement, new_flags,
~TTM_PL_MASK_MEMTYPE); ~TTM_PL_MASK_MEMTYPE);
} }
/*
* We might need to add a TTM.
*/
if (bo->mem.mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
ret = ttm_tt_create(bo, true);
if (ret)
return ret;
}
return 0; return 0;
} }
EXPORT_SYMBOL(ttm_bo_validate); EXPORT_SYMBOL(ttm_bo_validate);
......
...@@ -532,12 +532,15 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, ...@@ -532,12 +532,15 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
.interruptible = false, .interruptible = false,
.no_wait_gpu = false .no_wait_gpu = false
}; };
struct ttm_tt *ttm = bo->ttm; struct ttm_tt *ttm;
pgprot_t prot; pgprot_t prot;
int ret; int ret;
BUG_ON(!ttm); ret = ttm_tt_create(bo, true);
if (ret)
return ret;
ttm = bo->ttm;
ret = ttm_tt_populate(ttm, &ctx); ret = ttm_tt_populate(ttm, &ctx);
if (ret) if (ret)
return ret; return ret;
......
...@@ -349,6 +349,11 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, ...@@ -349,6 +349,11 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
}; };
if (ttm_tt_create(bo, true)) {
ret = VM_FAULT_OOM;
goto out_io_unlock;
}
ttm = bo->ttm; ttm = bo->ttm;
if (ttm_tt_populate(bo->ttm, &ctx)) { if (ttm_tt_populate(bo->ttm, &ctx)) {
ret = VM_FAULT_OOM; ret = VM_FAULT_OOM;
......
...@@ -50,6 +50,9 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc) ...@@ -50,6 +50,9 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)
dma_resv_assert_held(bo->base.resv); dma_resv_assert_held(bo->base.resv);
if (bo->ttm)
return 0;
if (bdev->need_dma32) if (bdev->need_dma32)
page_flags |= TTM_PAGE_FLAG_DMA32; page_flags |= TTM_PAGE_FLAG_DMA32;
...@@ -67,7 +70,6 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc) ...@@ -67,7 +70,6 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)
page_flags |= TTM_PAGE_FLAG_SG; page_flags |= TTM_PAGE_FLAG_SG;
break; break;
default: default:
bo->ttm = NULL;
pr_err("Illegal buffer object type\n"); pr_err("Illegal buffer object type\n");
return -EINVAL; return -EINVAL;
} }
......
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