Skip to content

Commit 19be557

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/ttm: add operation ctx to ttm_bo_validate v2
Give moving a BO into place an operation context to work with. v2: rebased Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-by: Chunming Zhou <david1.zhou@amd.com> Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de> Tested-by: Michel Dänzer <michel.daenzer@amd.com> Acked-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 750a250 commit 19be557

27 files changed

+131
-76
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
343343
struct amdgpu_bo *bo)
344344
{
345345
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
346+
struct ttm_operation_ctx ctx = { true, false };
346347
u64 initial_bytes_moved, bytes_moved;
347348
uint32_t domain;
348349
int r;
@@ -374,7 +375,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
374375
retry:
375376
amdgpu_ttm_placement_from_domain(bo, domain);
376377
initial_bytes_moved = atomic64_read(&adev->num_bytes_moved);
377-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
378+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
378379
bytes_moved = atomic64_read(&adev->num_bytes_moved) -
379380
initial_bytes_moved;
380381
p->bytes_moved += bytes_moved;
@@ -396,6 +397,7 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
396397
struct amdgpu_bo *validated)
397398
{
398399
uint32_t domain = validated->allowed_domains;
400+
struct ttm_operation_ctx ctx = { true, false };
399401
int r;
400402

401403
if (!p->evictable)
@@ -437,7 +439,7 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
437439
bo->tbo.mem.mem_type == TTM_PL_VRAM &&
438440
bo->tbo.mem.start < adev->mc.visible_vram_size >> PAGE_SHIFT;
439441
initial_bytes_moved = atomic64_read(&adev->num_bytes_moved);
440-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
442+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
441443
bytes_moved = atomic64_read(&adev->num_bytes_moved) -
442444
initial_bytes_moved;
443445
p->bytes_moved += bytes_moved;
@@ -476,6 +478,7 @@ static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo)
476478
static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
477479
struct list_head *validated)
478480
{
481+
struct ttm_operation_ctx ctx = { true, false };
479482
struct amdgpu_bo_list_entry *lobj;
480483
int r;
481484

@@ -493,8 +496,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
493496
lobj->user_pages) {
494497
amdgpu_ttm_placement_from_domain(bo,
495498
AMDGPU_GEM_DOMAIN_CPU);
496-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true,
497-
false);
499+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
498500
if (r)
499501
return r;
500502
amdgpu_ttm_tt_set_user_pages(bo->tbo.ttm,
@@ -1575,6 +1577,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
15751577
struct amdgpu_bo_va_mapping **map)
15761578
{
15771579
struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
1580+
struct ttm_operation_ctx ctx = { false, false };
15781581
struct amdgpu_vm *vm = &fpriv->vm;
15791582
struct amdgpu_bo_va_mapping *mapping;
15801583
int r;
@@ -1595,8 +1598,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
15951598
if (!((*bo)->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)) {
15961599
(*bo)->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
15971600
amdgpu_ttm_placement_from_domain(*bo, (*bo)->allowed_domains);
1598-
r = ttm_bo_validate(&(*bo)->tbo, &(*bo)->placement, false,
1599-
false);
1601+
r = ttm_bo_validate(&(*bo)->tbo, &(*bo)->placement, &ctx);
16001602
if (r)
16011603
return r;
16021604
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
282282
int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
283283
struct drm_file *filp)
284284
{
285+
struct ttm_operation_ctx ctx = { true, false };
285286
struct amdgpu_device *adev = dev->dev_private;
286287
struct drm_amdgpu_gem_userptr *args = data;
287288
struct drm_gem_object *gobj;
@@ -335,7 +336,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
335336
goto free_pages;
336337

337338
amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
338-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
339+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
339340
amdgpu_bo_unreserve(bo);
340341
if (r)
341342
goto free_pages;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
552552

553553
int amdgpu_bo_validate(struct amdgpu_bo *bo)
554554
{
555+
struct ttm_operation_ctx ctx = { false, false };
555556
uint32_t domain;
556557
int r;
557558

@@ -562,7 +563,7 @@ int amdgpu_bo_validate(struct amdgpu_bo *bo)
562563

563564
retry:
564565
amdgpu_ttm_placement_from_domain(bo, domain);
565-
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
566+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
566567
if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
567568
domain = bo->allowed_domains;
568569
goto retry;
@@ -673,6 +674,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
673674
u64 *gpu_addr)
674675
{
675676
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
677+
struct ttm_operation_ctx ctx = { false, false };
676678
int r, i;
677679

678680
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
@@ -723,7 +725,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
723725
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
724726
}
725727

726-
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
728+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
727729
if (unlikely(r)) {
728730
dev_err(adev->dev, "%p pin failed\n", bo);
729731
goto error;
@@ -760,6 +762,7 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain, u64 *gpu_addr)
760762
int amdgpu_bo_unpin(struct amdgpu_bo *bo)
761763
{
762764
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
765+
struct ttm_operation_ctx ctx = { false, false };
763766
int r, i;
764767

765768
if (!bo->pin_count) {
@@ -773,7 +776,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
773776
bo->placements[i].lpfn = 0;
774777
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
775778
}
776-
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
779+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
777780
if (unlikely(r)) {
778781
dev_err(adev->dev, "%p validate failed for unpin\n", bo);
779782
goto error;
@@ -945,6 +948,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
945948
int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
946949
{
947950
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
951+
struct ttm_operation_ctx ctx = { false, false };
948952
struct amdgpu_bo *abo;
949953
unsigned long offset, size;
950954
int r;
@@ -978,7 +982,7 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
978982
abo->placement.num_busy_placement = 1;
979983
abo->placement.busy_placement = &abo->placements[1];
980984

981-
r = ttm_bo_validate(bo, &abo->placement, false, false);
985+
r = ttm_bo_validate(bo, &abo->placement, &ctx);
982986
if (unlikely(r != 0))
983987
return r;
984988

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ static u64 amdgpu_uvd_get_addr_from_ctx(struct amdgpu_uvd_cs_ctx *ctx)
408408
*/
409409
static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
410410
{
411+
struct ttm_operation_ctx tctx = { false, false };
411412
struct amdgpu_bo_va_mapping *mapping;
412413
struct amdgpu_bo *bo;
413414
uint32_t cmd;
@@ -430,7 +431,7 @@ static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
430431
}
431432
amdgpu_uvd_force_into_uvd_segment(bo);
432433

433-
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
434+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &tctx);
434435
}
435436

436437
return r;
@@ -949,6 +950,7 @@ int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)
949950
static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
950951
bool direct, struct dma_fence **fence)
951952
{
953+
struct ttm_operation_ctx ctx = { true, false };
952954
struct ttm_validate_buffer tv;
953955
struct ww_acquire_ctx ticket;
954956
struct list_head head;
@@ -975,7 +977,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
975977
amdgpu_uvd_force_into_uvd_segment(bo);
976978
}
977979

978-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
980+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
979981
if (r)
980982
goto err;
981983

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ static int amdgpu_vce_validate_bo(struct amdgpu_cs_parser *p, uint32_t ib_idx,
558558
int lo, int hi, unsigned size, int32_t index)
559559
{
560560
int64_t offset = ((uint64_t)size) * ((int64_t)index);
561+
struct ttm_operation_ctx ctx = { false, false };
561562
struct amdgpu_bo_va_mapping *mapping;
562563
unsigned i, fpfn, lpfn;
563564
struct amdgpu_bo *bo;
@@ -587,7 +588,7 @@ static int amdgpu_vce_validate_bo(struct amdgpu_cs_parser *p, uint32_t ib_idx,
587588
bo->placements[i].lpfn = bo->placements[i].fpfn ?
588589
min(bo->placements[i].fpfn, lpfn) : lpfn;
589590
}
590-
return ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
591+
return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
591592
}
592593

593594

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring)
274274
static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
275275
bool direct, struct dma_fence **fence)
276276
{
277+
struct ttm_operation_ctx ctx = { true, false };
277278
struct ttm_validate_buffer tv;
278279
struct ww_acquire_ctx ticket;
279280
struct list_head head;
@@ -294,7 +295,7 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *b
294295
if (r)
295296
return r;
296297

297-
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
298+
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
298299
if (r)
299300
goto err;
300301

drivers/gpu/drm/ast/ast_ttm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ static inline u64 ast_bo_gpu_offset(struct ast_bo *bo)
354354

355355
int ast_bo_pin(struct ast_bo *bo, u32 pl_flag, u64 *gpu_addr)
356356
{
357+
struct ttm_operation_ctx ctx = { false, false };
357358
int i, ret;
358359

359360
if (bo->pin_count) {
@@ -365,7 +366,7 @@ int ast_bo_pin(struct ast_bo *bo, u32 pl_flag, u64 *gpu_addr)
365366
ast_ttm_placement(bo, pl_flag);
366367
for (i = 0; i < bo->placement.num_placement; i++)
367368
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
368-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
369+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
369370
if (ret)
370371
return ret;
371372

@@ -377,6 +378,7 @@ int ast_bo_pin(struct ast_bo *bo, u32 pl_flag, u64 *gpu_addr)
377378

378379
int ast_bo_unpin(struct ast_bo *bo)
379380
{
381+
struct ttm_operation_ctx ctx = { false, false };
380382
int i;
381383
if (!bo->pin_count) {
382384
DRM_ERROR("unpin bad %p\n", bo);
@@ -388,11 +390,12 @@ int ast_bo_unpin(struct ast_bo *bo)
388390

389391
for (i = 0; i < bo->placement.num_placement ; i++)
390392
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
391-
return ttm_bo_validate(&bo->bo, &bo->placement, false, false);
393+
return ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
392394
}
393395

394396
int ast_bo_push_sysram(struct ast_bo *bo)
395397
{
398+
struct ttm_operation_ctx ctx = { false, false };
396399
int i, ret;
397400
if (!bo->pin_count) {
398401
DRM_ERROR("unpin bad %p\n", bo);
@@ -409,7 +412,7 @@ int ast_bo_push_sysram(struct ast_bo *bo)
409412
for (i = 0; i < bo->placement.num_placement ; i++)
410413
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
411414

412-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
415+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
413416
if (ret) {
414417
DRM_ERROR("pushing to VRAM failed\n");
415418
return ret;

drivers/gpu/drm/bochs/bochs_mm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static inline u64 bochs_bo_gpu_offset(struct bochs_bo *bo)
283283

284284
int bochs_bo_pin(struct bochs_bo *bo, u32 pl_flag, u64 *gpu_addr)
285285
{
286+
struct ttm_operation_ctx ctx = { false, false };
286287
int i, ret;
287288

288289
if (bo->pin_count) {
@@ -295,7 +296,7 @@ int bochs_bo_pin(struct bochs_bo *bo, u32 pl_flag, u64 *gpu_addr)
295296
bochs_ttm_placement(bo, pl_flag);
296297
for (i = 0; i < bo->placement.num_placement; i++)
297298
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
298-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
299+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
299300
if (ret)
300301
return ret;
301302

@@ -307,6 +308,7 @@ int bochs_bo_pin(struct bochs_bo *bo, u32 pl_flag, u64 *gpu_addr)
307308

308309
int bochs_bo_unpin(struct bochs_bo *bo)
309310
{
311+
struct ttm_operation_ctx ctx = { false, false };
310312
int i, ret;
311313

312314
if (!bo->pin_count) {
@@ -320,7 +322,7 @@ int bochs_bo_unpin(struct bochs_bo *bo)
320322

321323
for (i = 0; i < bo->placement.num_placement; i++)
322324
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
323-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
325+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
324326
if (ret)
325327
return ret;
326328

drivers/gpu/drm/cirrus/cirrus_ttm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ static inline u64 cirrus_bo_gpu_offset(struct cirrus_bo *bo)
358358

359359
int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
360360
{
361+
struct ttm_operation_ctx ctx = { false, false };
361362
int i, ret;
362363

363364
if (bo->pin_count) {
@@ -369,7 +370,7 @@ int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
369370
cirrus_ttm_placement(bo, pl_flag);
370371
for (i = 0; i < bo->placement.num_placement; i++)
371372
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
372-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
373+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
373374
if (ret)
374375
return ret;
375376

@@ -381,6 +382,7 @@ int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
381382

382383
int cirrus_bo_push_sysram(struct cirrus_bo *bo)
383384
{
385+
struct ttm_operation_ctx ctx = { false, false };
384386
int i, ret;
385387
if (!bo->pin_count) {
386388
DRM_ERROR("unpin bad %p\n", bo);
@@ -397,7 +399,7 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo)
397399
for (i = 0; i < bo->placement.num_placement ; i++)
398400
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
399401

400-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
402+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
401403
if (ret) {
402404
DRM_ERROR("pushing to VRAM failed\n");
403405
return ret;

drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ int hibmc_bo_create(struct drm_device *dev, int size, int align,
344344

345345
int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr)
346346
{
347+
struct ttm_operation_ctx ctx = { false, false };
347348
int i, ret;
348349

349350
if (bo->pin_count) {
@@ -356,7 +357,7 @@ int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr)
356357
hibmc_ttm_placement(bo, pl_flag);
357358
for (i = 0; i < bo->placement.num_placement; i++)
358359
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
359-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
360+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
360361
if (ret)
361362
return ret;
362363

@@ -368,6 +369,7 @@ int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr)
368369

369370
int hibmc_bo_unpin(struct hibmc_bo *bo)
370371
{
372+
struct ttm_operation_ctx ctx = { false, false };
371373
int i, ret;
372374

373375
if (!bo->pin_count) {
@@ -380,7 +382,7 @@ int hibmc_bo_unpin(struct hibmc_bo *bo)
380382

381383
for (i = 0; i < bo->placement.num_placement ; i++)
382384
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
383-
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
385+
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
384386
if (ret) {
385387
DRM_ERROR("validate failed for unpin: %d\n", ret);
386388
return ret;

0 commit comments

Comments
 (0)