aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2017-04-12 08:24:39 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-12-06 12:48:01 -0500
commit19be5570107108fba772bc2e3a1eb22ec32fb021 (patch)
tree86b971706ea8fce92b58cac4ea73e8799564a6ef /drivers/gpu/drm/amd
parent750a25037cac56afeb48ab807ce80fa2cd518b8d (diff)
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>
Diffstat (limited to 'drivers/gpu/drm/amd')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c3
6 files changed, 26 insertions, 15 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 743875ad4404..faab662ce680 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -343,6 +343,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
343 struct amdgpu_bo *bo) 343 struct amdgpu_bo *bo)
344{ 344{
345 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); 345 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
346 struct ttm_operation_ctx ctx = { true, false };
346 u64 initial_bytes_moved, bytes_moved; 347 u64 initial_bytes_moved, bytes_moved;
347 uint32_t domain; 348 uint32_t domain;
348 int r; 349 int r;
@@ -374,7 +375,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
374retry: 375retry:
375 amdgpu_ttm_placement_from_domain(bo, domain); 376 amdgpu_ttm_placement_from_domain(bo, domain);
376 initial_bytes_moved = atomic64_read(&adev->num_bytes_moved); 377 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);
378 bytes_moved = atomic64_read(&adev->num_bytes_moved) - 379 bytes_moved = atomic64_read(&adev->num_bytes_moved) -
379 initial_bytes_moved; 380 initial_bytes_moved;
380 p->bytes_moved += bytes_moved; 381 p->bytes_moved += bytes_moved;
@@ -396,6 +397,7 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
396 struct amdgpu_bo *validated) 397 struct amdgpu_bo *validated)
397{ 398{
398 uint32_t domain = validated->allowed_domains; 399 uint32_t domain = validated->allowed_domains;
400 struct ttm_operation_ctx ctx = { true, false };
399 int r; 401 int r;
400 402
401 if (!p->evictable) 403 if (!p->evictable)
@@ -437,7 +439,7 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
437 bo->tbo.mem.mem_type == TTM_PL_VRAM && 439 bo->tbo.mem.mem_type == TTM_PL_VRAM &&
438 bo->tbo.mem.start < adev->mc.visible_vram_size >> PAGE_SHIFT; 440 bo->tbo.mem.start < adev->mc.visible_vram_size >> PAGE_SHIFT;
439 initial_bytes_moved = atomic64_read(&adev->num_bytes_moved); 441 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);
441 bytes_moved = atomic64_read(&adev->num_bytes_moved) - 443 bytes_moved = atomic64_read(&adev->num_bytes_moved) -
442 initial_bytes_moved; 444 initial_bytes_moved;
443 p->bytes_moved += bytes_moved; 445 p->bytes_moved += bytes_moved;
@@ -476,6 +478,7 @@ static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo)
476static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p, 478static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
477 struct list_head *validated) 479 struct list_head *validated)
478{ 480{
481 struct ttm_operation_ctx ctx = { true, false };
479 struct amdgpu_bo_list_entry *lobj; 482 struct amdgpu_bo_list_entry *lobj;
480 int r; 483 int r;
481 484
@@ -493,8 +496,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
493 lobj->user_pages) { 496 lobj->user_pages) {
494 amdgpu_ttm_placement_from_domain(bo, 497 amdgpu_ttm_placement_from_domain(bo,
495 AMDGPU_GEM_DOMAIN_CPU); 498 AMDGPU_GEM_DOMAIN_CPU);
496 r = ttm_bo_validate(&bo->tbo, &bo->placement, true, 499 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
497 false);
498 if (r) 500 if (r)
499 return r; 501 return r;
500 amdgpu_ttm_tt_set_user_pages(bo->tbo.ttm, 502 amdgpu_ttm_tt_set_user_pages(bo->tbo.ttm,
@@ -1575,6 +1577,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1575 struct amdgpu_bo_va_mapping **map) 1577 struct amdgpu_bo_va_mapping **map)
1576{ 1578{
1577 struct amdgpu_fpriv *fpriv = parser->filp->driver_priv; 1579 struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
1580 struct ttm_operation_ctx ctx = { false, false };
1578 struct amdgpu_vm *vm = &fpriv->vm; 1581 struct amdgpu_vm *vm = &fpriv->vm;
1579 struct amdgpu_bo_va_mapping *mapping; 1582 struct amdgpu_bo_va_mapping *mapping;
1580 int r; 1583 int r;
@@ -1595,8 +1598,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1595 if (!((*bo)->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)) { 1598 if (!((*bo)->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)) {
1596 (*bo)->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; 1599 (*bo)->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
1597 amdgpu_ttm_placement_from_domain(*bo, (*bo)->allowed_domains); 1600 amdgpu_ttm_placement_from_domain(*bo, (*bo)->allowed_domains);
1598 r = ttm_bo_validate(&(*bo)->tbo, &(*bo)->placement, false, 1601 r = ttm_bo_validate(&(*bo)->tbo, &(*bo)->placement, &ctx);
1599 false);
1600 if (r) 1602 if (r)
1601 return r; 1603 return r;
1602 } 1604 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 3ad4cf0f22f8..c16579287aee 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -282,6 +282,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
282int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, 282int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
283 struct drm_file *filp) 283 struct drm_file *filp)
284{ 284{
285 struct ttm_operation_ctx ctx = { true, false };
285 struct amdgpu_device *adev = dev->dev_private; 286 struct amdgpu_device *adev = dev->dev_private;
286 struct drm_amdgpu_gem_userptr *args = data; 287 struct drm_amdgpu_gem_userptr *args = data;
287 struct drm_gem_object *gobj; 288 struct drm_gem_object *gobj;
@@ -335,7 +336,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
335 goto free_pages; 336 goto free_pages;
336 337
337 amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT); 338 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);
339 amdgpu_bo_unreserve(bo); 340 amdgpu_bo_unreserve(bo);
340 if (r) 341 if (r)
341 goto free_pages; 342 goto free_pages;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 3233d5988f66..c2419bc6b3df 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -552,6 +552,7 @@ err:
552 552
553int amdgpu_bo_validate(struct amdgpu_bo *bo) 553int amdgpu_bo_validate(struct amdgpu_bo *bo)
554{ 554{
555 struct ttm_operation_ctx ctx = { false, false };
555 uint32_t domain; 556 uint32_t domain;
556 int r; 557 int r;
557 558
@@ -562,7 +563,7 @@ int amdgpu_bo_validate(struct amdgpu_bo *bo)
562 563
563retry: 564retry:
564 amdgpu_ttm_placement_from_domain(bo, domain); 565 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);
566 if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) { 567 if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
567 domain = bo->allowed_domains; 568 domain = bo->allowed_domains;
568 goto retry; 569 goto retry;
@@ -673,6 +674,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
673 u64 *gpu_addr) 674 u64 *gpu_addr)
674{ 675{
675 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); 676 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
677 struct ttm_operation_ctx ctx = { false, false };
676 int r, i; 678 int r, i;
677 679
678 if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) 680 if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
@@ -723,7 +725,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
723 bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT; 725 bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
724 } 726 }
725 727
726 r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 728 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
727 if (unlikely(r)) { 729 if (unlikely(r)) {
728 dev_err(adev->dev, "%p pin failed\n", bo); 730 dev_err(adev->dev, "%p pin failed\n", bo);
729 goto error; 731 goto error;
@@ -760,6 +762,7 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain, u64 *gpu_addr)
760int amdgpu_bo_unpin(struct amdgpu_bo *bo) 762int amdgpu_bo_unpin(struct amdgpu_bo *bo)
761{ 763{
762 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); 764 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
765 struct ttm_operation_ctx ctx = { false, false };
763 int r, i; 766 int r, i;
764 767
765 if (!bo->pin_count) { 768 if (!bo->pin_count) {
@@ -773,7 +776,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
773 bo->placements[i].lpfn = 0; 776 bo->placements[i].lpfn = 0;
774 bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT; 777 bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
775 } 778 }
776 r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 779 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
777 if (unlikely(r)) { 780 if (unlikely(r)) {
778 dev_err(adev->dev, "%p validate failed for unpin\n", bo); 781 dev_err(adev->dev, "%p validate failed for unpin\n", bo);
779 goto error; 782 goto error;
@@ -945,6 +948,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
945int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo) 948int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
946{ 949{
947 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); 950 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
951 struct ttm_operation_ctx ctx = { false, false };
948 struct amdgpu_bo *abo; 952 struct amdgpu_bo *abo;
949 unsigned long offset, size; 953 unsigned long offset, size;
950 int r; 954 int r;
@@ -978,7 +982,7 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
978 abo->placement.num_busy_placement = 1; 982 abo->placement.num_busy_placement = 1;
979 abo->placement.busy_placement = &abo->placements[1]; 983 abo->placement.busy_placement = &abo->placements[1];
980 984
981 r = ttm_bo_validate(bo, &abo->placement, false, false); 985 r = ttm_bo_validate(bo, &abo->placement, &ctx);
982 if (unlikely(r != 0)) 986 if (unlikely(r != 0))
983 return r; 987 return r;
984 988
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index be607b2be4e9..2f2a9e17fdb4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -408,6 +408,7 @@ static u64 amdgpu_uvd_get_addr_from_ctx(struct amdgpu_uvd_cs_ctx *ctx)
408 */ 408 */
409static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx) 409static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
410{ 410{
411 struct ttm_operation_ctx tctx = { false, false };
411 struct amdgpu_bo_va_mapping *mapping; 412 struct amdgpu_bo_va_mapping *mapping;
412 struct amdgpu_bo *bo; 413 struct amdgpu_bo *bo;
413 uint32_t cmd; 414 uint32_t cmd;
@@ -430,7 +431,7 @@ static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
430 } 431 }
431 amdgpu_uvd_force_into_uvd_segment(bo); 432 amdgpu_uvd_force_into_uvd_segment(bo);
432 433
433 r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 434 r = ttm_bo_validate(&bo->tbo, &bo->placement, &tctx);
434 } 435 }
435 436
436 return r; 437 return r;
@@ -949,6 +950,7 @@ int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)
949static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, 950static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
950 bool direct, struct dma_fence **fence) 951 bool direct, struct dma_fence **fence)
951{ 952{
953 struct ttm_operation_ctx ctx = { true, false };
952 struct ttm_validate_buffer tv; 954 struct ttm_validate_buffer tv;
953 struct ww_acquire_ctx ticket; 955 struct ww_acquire_ctx ticket;
954 struct list_head head; 956 struct list_head head;
@@ -975,7 +977,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
975 amdgpu_uvd_force_into_uvd_segment(bo); 977 amdgpu_uvd_force_into_uvd_segment(bo);
976 } 978 }
977 979
978 r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false); 980 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
979 if (r) 981 if (r)
980 goto err; 982 goto err;
981 983
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
index a91abfb32746..ba6d846b08ff 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
@@ -558,6 +558,7 @@ static int amdgpu_vce_validate_bo(struct amdgpu_cs_parser *p, uint32_t ib_idx,
558 int lo, int hi, unsigned size, int32_t index) 558 int lo, int hi, unsigned size, int32_t index)
559{ 559{
560 int64_t offset = ((uint64_t)size) * ((int64_t)index); 560 int64_t offset = ((uint64_t)size) * ((int64_t)index);
561 struct ttm_operation_ctx ctx = { false, false };
561 struct amdgpu_bo_va_mapping *mapping; 562 struct amdgpu_bo_va_mapping *mapping;
562 unsigned i, fpfn, lpfn; 563 unsigned i, fpfn, lpfn;
563 struct amdgpu_bo *bo; 564 struct amdgpu_bo *bo;
@@ -587,7 +588,7 @@ static int amdgpu_vce_validate_bo(struct amdgpu_cs_parser *p, uint32_t ib_idx,
587 bo->placements[i].lpfn = bo->placements[i].fpfn ? 588 bo->placements[i].lpfn = bo->placements[i].fpfn ?
588 min(bo->placements[i].fpfn, lpfn) : lpfn; 589 min(bo->placements[i].fpfn, lpfn) : lpfn;
589 } 590 }
590 return ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 591 return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
591} 592}
592 593
593 594
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index dabaca4da7f2..df218df332b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -274,6 +274,7 @@ int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring)
274static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, 274static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
275 bool direct, struct dma_fence **fence) 275 bool direct, struct dma_fence **fence)
276{ 276{
277 struct ttm_operation_ctx ctx = { true, false };
277 struct ttm_validate_buffer tv; 278 struct ttm_validate_buffer tv;
278 struct ww_acquire_ctx ticket; 279 struct ww_acquire_ctx ticket;
279 struct list_head head; 280 struct list_head head;
@@ -294,7 +295,7 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *b
294 if (r) 295 if (r)
295 return r; 296 return r;
296 297
297 r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false); 298 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
298 if (r) 299 if (r)
299 goto err; 300 goto err;
300 301