Skip to content

Commit 3f1a800

Browse files
ChristianKoenigAMDevadot
authored andcommitted
drm/ttm: give resource functions their own [ch] files
This is a separate object we work within TTM. Signed-off-by: Christian König <[email protected]> Reviewed-by: Dave Airlie <[email protected]> Link: https://patchwork.freedesktop.org/patch/384338/?series=80346&rev=1
1 parent 88798e7 commit 3f1a800

File tree

10 files changed

+443
-377
lines changed

10 files changed

+443
-377
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
384384
if (cpu_addr)
385385
amdgpu_bo_kunmap(*bo_ptr);
386386

387-
ttm_bo_mem_put(&(*bo_ptr)->tbo, &(*bo_ptr)->tbo.mem);
387+
ttm_resource_free(&(*bo_ptr)->tbo, &(*bo_ptr)->tbo.mem);
388388

389389
for (i = 0; i < (*bo_ptr)->placement.num_placement; ++i) {
390390
(*bo_ptr)->placements[i].fpfn = offset >> PAGE_SHIFT;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
583583
/* move BO (in tmp_mem) to new_mem */
584584
r = ttm_bo_move_ttm(bo, ctx, new_mem);
585585
out_cleanup:
586-
ttm_bo_mem_put(bo, &tmp_mem);
586+
ttm_resource_free(bo, &tmp_mem);
587587
return r;
588588
}
589589

@@ -630,7 +630,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, bool evict,
630630
goto out_cleanup;
631631
}
632632
out_cleanup:
633-
ttm_bo_mem_put(bo, &tmp_mem);
633+
ttm_resource_free(bo, &tmp_mem);
634634
return r;
635635
}
636636

@@ -1209,11 +1209,11 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
12091209
gtt->offset = (u64)tmp.start << PAGE_SHIFT;
12101210
r = amdgpu_ttm_gart_bind(adev, bo, flags);
12111211
if (unlikely(r)) {
1212-
ttm_bo_mem_put(bo, &tmp);
1212+
ttm_resource_free(bo, &tmp);
12131213
return r;
12141214
}
12151215

1216-
ttm_bo_mem_put(bo, &bo->mem);
1216+
ttm_resource_free(bo, &bo->mem);
12171217
bo->mem = tmp;
12181218
}
12191219

drivers/gpu/drm/radeon/radeon_ttm.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
271271
}
272272
r = ttm_bo_move_ttm(bo, &ctx, new_mem);
273273
out_cleanup:
274-
ttm_bo_mem_put(bo, &tmp_mem);
274+
ttm_resource_free(bo, &tmp_mem);
275275
return r;
276276
}
277277

@@ -309,7 +309,7 @@ static int radeon_move_ram_vram(struct ttm_buffer_object *bo,
309309
goto out_cleanup;
310310
}
311311
out_cleanup:
312-
ttm_bo_mem_put(bo, &tmp_mem);
312+
ttm_resource_free(bo, &tmp_mem);
313313
return r;
314314
}
315315

drivers/gpu/drm/ttm/ttm_bo.c

+11-117
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,6 @@ static inline int ttm_mem_type_from_place(const struct ttm_place *place,
7777
return 0;
7878
}
7979

80-
void ttm_resource_manager_debug(struct ttm_resource_manager *man,
81-
struct drm_printer *p)
82-
{
83-
drm_printf(p, " use_type: %d\n", man->use_type);
84-
#ifdef __linux__
85-
drm_printf(p, " use_tt: %d\n", man->use_tt);
86-
drm_printf(p, " size: %llu\n", man->size);
87-
#elif defined(__FreeBSD__)
88-
drm_printf(p, " size: %zu\n", man->size);
89-
#endif
90-
drm_printf(p, " available_caching: 0x%08X\n", man->available_caching);
91-
drm_printf(p, " default_caching: 0x%08X\n", man->default_caching);
92-
if (man->func && man->func->debug)
93-
(*man->func->debug)(man, p);
94-
}
95-
EXPORT_SYMBOL(ttm_resource_manager_debug);
96-
9780
static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo,
9881
struct ttm_placement *placement)
9982
{
@@ -367,7 +350,7 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
367350

368351
ttm_tt_destroy(bo->ttm);
369352
bo->ttm = NULL;
370-
ttm_bo_mem_put(bo, &bo->mem);
353+
ttm_resource_free(bo, &bo->mem);
371354
}
372355

373356
static int ttm_bo_individualize_resv(struct ttm_buffer_object *bo)
@@ -682,7 +665,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
682665
if (unlikely(ret)) {
683666
if (ret != -ERESTARTSYS)
684667
pr_err("Buffer eviction failed\n");
685-
ttm_bo_mem_put(bo, &evict_mem);
668+
ttm_resource_free(bo, &evict_mem);
686669
goto out;
687670
}
688671
bo->evicted = true;
@@ -771,11 +754,11 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
771754
return r == -EDEADLK ? -EBUSY : r;
772755
}
773756

774-
static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
775-
struct ttm_resource_manager *man,
776-
const struct ttm_place *place,
777-
struct ttm_operation_ctx *ctx,
778-
struct ww_acquire_ctx *ticket)
757+
int ttm_mem_evict_first(struct ttm_bo_device *bdev,
758+
struct ttm_resource_manager *man,
759+
const struct ttm_place *place,
760+
struct ttm_operation_ctx *ctx,
761+
struct ww_acquire_ctx *ticket)
779762
{
780763
struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
781764
bool locked = false;
@@ -843,32 +826,6 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
843826
return ret;
844827
}
845828

846-
static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
847-
const struct ttm_place *place,
848-
struct ttm_resource *mem)
849-
{
850-
struct ttm_resource_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
851-
852-
mem->mm_node = NULL;
853-
if (!man->func || !man->func->alloc)
854-
return 0;
855-
856-
return man->func->alloc(man, bo, place, mem);
857-
}
858-
859-
void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_resource *mem)
860-
{
861-
struct ttm_resource_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
862-
863-
if (!man->func || !man->func->free)
864-
return;
865-
866-
man->func->free(man, mem);
867-
mem->mm_node = NULL;
868-
mem->mem_type = TTM_PL_SYSTEM;
869-
}
870-
EXPORT_SYMBOL(ttm_bo_mem_put);
871-
872829
/**
873830
* Add the last move fence to the BO and reserve a new shared slot.
874831
*/
@@ -921,7 +878,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
921878

922879
ticket = dma_resv_locking_ctx(bo->base.resv);
923880
do {
924-
ret = ttm_bo_mem_get(bo, place, mem);
881+
ret = ttm_resource_alloc(bo, place, mem);
925882
if (likely(!ret))
926883
break;
927884
if (unlikely(ret != -ENOSPC))
@@ -1062,7 +1019,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
10621019
goto error;
10631020

10641021
type_found = true;
1065-
ret = ttm_bo_mem_get(bo, place, mem);
1022+
ret = ttm_resource_alloc(bo, place, mem);
10661023
if (ret == -ENOSPC)
10671024
continue;
10681025
if (unlikely(ret))
@@ -1071,7 +1028,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
10711028
man = ttm_manager_type(bdev, mem->mem_type);
10721029
ret = ttm_bo_add_move_fence(bo, man, mem, ctx->no_wait_gpu);
10731030
if (unlikely(ret)) {
1074-
ttm_bo_mem_put(bo, mem);
1031+
ttm_resource_free(bo, mem);
10751032
if (ret == -EBUSY)
10761033
continue;
10771034

@@ -1138,7 +1095,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
11381095
ret = ttm_bo_handle_move_mem(bo, &mem, false, ctx);
11391096
out_unlock:
11401097
if (ret)
1141-
ttm_bo_mem_put(bo, &mem);
1098+
ttm_resource_free(bo, &mem);
11421099
return ret;
11431100
}
11441101

@@ -1423,52 +1380,6 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
14231380
}
14241381
EXPORT_SYMBOL(ttm_bo_create);
14251382

1426-
int ttm_resource_manager_force_list_clean(struct ttm_bo_device *bdev,
1427-
struct ttm_resource_manager *man)
1428-
{
1429-
struct ttm_operation_ctx ctx = {
1430-
.interruptible = false,
1431-
.no_wait_gpu = false,
1432-
.flags = TTM_OPT_FLAG_FORCE_ALLOC
1433-
};
1434-
struct ttm_bo_global *glob = &ttm_bo_glob;
1435-
struct dma_fence *fence;
1436-
int ret;
1437-
unsigned i;
1438-
1439-
/*
1440-
* Can't use standard list traversal since we're unlocking.
1441-
*/
1442-
1443-
spin_lock(&glob->lru_lock);
1444-
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
1445-
while (!list_empty(&man->lru[i])) {
1446-
spin_unlock(&glob->lru_lock);
1447-
ret = ttm_mem_evict_first(bdev, man, NULL, &ctx,
1448-
NULL);
1449-
if (ret)
1450-
return ret;
1451-
spin_lock(&glob->lru_lock);
1452-
}
1453-
}
1454-
spin_unlock(&glob->lru_lock);
1455-
1456-
spin_lock(&man->move_lock);
1457-
fence = dma_fence_get(man->move);
1458-
spin_unlock(&man->move_lock);
1459-
1460-
if (fence) {
1461-
ret = dma_fence_wait(fence, false);
1462-
dma_fence_put(fence);
1463-
if (ret)
1464-
return ret;
1465-
}
1466-
1467-
return 0;
1468-
}
1469-
EXPORT_SYMBOL(ttm_resource_manager_force_list_clean);
1470-
1471-
14721383
int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
14731384
{
14741385
struct ttm_resource_manager *man = ttm_manager_type(bdev, mem_type);
@@ -1487,23 +1398,6 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
14871398
}
14881399
EXPORT_SYMBOL(ttm_bo_evict_mm);
14891400

1490-
void ttm_resource_manager_init(struct ttm_resource_manager *man,
1491-
unsigned long p_size)
1492-
{
1493-
unsigned i;
1494-
1495-
man->use_io_reserve_lru = false;
1496-
mutex_init(&man->io_reserve_mutex);
1497-
spin_lock_init(&man->move_lock);
1498-
INIT_LIST_HEAD(&man->io_reserve_lru);
1499-
man->size = p_size;
1500-
1501-
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
1502-
INIT_LIST_HEAD(&man->lru[i]);
1503-
man->move = NULL;
1504-
}
1505-
EXPORT_SYMBOL(ttm_resource_manager_init);
1506-
15071401
static void ttm_bo_global_kobj_release(struct kobject *kobj)
15081402
{
15091403
struct ttm_bo_global *glob =

drivers/gpu/drm/ttm/ttm_bo_util.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ttm_transfer_obj {
4747

4848
void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
4949
{
50-
ttm_bo_mem_put(bo, &bo->mem);
50+
ttm_resource_free(bo, &bo->mem);
5151
}
5252

5353
int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
@@ -398,7 +398,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
398398
* On error, keep the mm node!
399399
*/
400400
if (!ret)
401-
ttm_bo_mem_put(bo, &old_copy);
401+
ttm_resource_free(bo, &old_copy);
402402
return ret;
403403
}
404404
EXPORT_SYMBOL(ttm_bo_move_memcpy);

0 commit comments

Comments
 (0)