diff options
author | Christian König <christian.koenig@amd.com> | 2017-08-18 09:50:17 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-08-29 15:27:40 -0400 |
commit | cf273a59ca3068caced2adaf2deeb44d2013c8a9 (patch) | |
tree | 1cff68f7bef6c0c112137954dafd259aff323764 /drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |
parent | 83e74db6a81daff277732bdd00b438ede2107c68 (diff) |
drm/amdgpu: fix and cleanup shadow handling
Set the shadow flag on the shadow and not the parent, always bind shadow BOs
during allocation instead of manually, use the reservation_object wrappers
to grab the lock.
This fixes a couple of issues with binding the shadow BOs as well as correctly
evicting them when memory becomes tight.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index e7e899190bef..9e495da0bb03 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |||
@@ -91,7 +91,10 @@ static void amdgpu_ttm_placement_init(struct amdgpu_device *adev, | |||
91 | 91 | ||
92 | if (domain & AMDGPU_GEM_DOMAIN_GTT) { | 92 | if (domain & AMDGPU_GEM_DOMAIN_GTT) { |
93 | places[c].fpfn = 0; | 93 | places[c].fpfn = 0; |
94 | places[c].lpfn = 0; | 94 | if (flags & AMDGPU_GEM_CREATE_SHADOW) |
95 | places[c].lpfn = adev->mc.gart_size >> PAGE_SHIFT; | ||
96 | else | ||
97 | places[c].lpfn = 0; | ||
95 | places[c].flags = TTM_PL_FLAG_TT; | 98 | places[c].flags = TTM_PL_FLAG_TT; |
96 | if (flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC) | 99 | if (flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC) |
97 | places[c].flags |= TTM_PL_FLAG_WC | | 100 | places[c].flags |= TTM_PL_FLAG_WC | |
@@ -446,17 +449,16 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev, | |||
446 | if (bo->shadow) | 449 | if (bo->shadow) |
447 | return 0; | 450 | return 0; |
448 | 451 | ||
449 | bo->flags |= AMDGPU_GEM_CREATE_SHADOW; | 452 | memset(&placements, 0, sizeof(placements)); |
450 | memset(&placements, 0, | 453 | amdgpu_ttm_placement_init(adev, &placement, placements, |
451 | (AMDGPU_GEM_DOMAIN_MAX + 1) * sizeof(struct ttm_place)); | 454 | AMDGPU_GEM_DOMAIN_GTT, |
452 | 455 | AMDGPU_GEM_CREATE_CPU_GTT_USWC | | |
453 | amdgpu_ttm_placement_init(adev, &placement, | 456 | AMDGPU_GEM_CREATE_SHADOW); |
454 | placements, AMDGPU_GEM_DOMAIN_GTT, | ||
455 | AMDGPU_GEM_CREATE_CPU_GTT_USWC); | ||
456 | 457 | ||
457 | r = amdgpu_bo_create_restricted(adev, size, byte_align, true, | 458 | r = amdgpu_bo_create_restricted(adev, size, byte_align, true, |
458 | AMDGPU_GEM_DOMAIN_GTT, | 459 | AMDGPU_GEM_DOMAIN_GTT, |
459 | AMDGPU_GEM_CREATE_CPU_GTT_USWC, | 460 | AMDGPU_GEM_CREATE_CPU_GTT_USWC | |
461 | AMDGPU_GEM_CREATE_SHADOW, | ||
460 | NULL, &placement, | 462 | NULL, &placement, |
461 | bo->tbo.resv, | 463 | bo->tbo.resv, |
462 | 0, | 464 | 0, |
@@ -484,30 +486,28 @@ int amdgpu_bo_create(struct amdgpu_device *adev, | |||
484 | { | 486 | { |
485 | struct ttm_placement placement = {0}; | 487 | struct ttm_placement placement = {0}; |
486 | struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1]; | 488 | struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1]; |
489 | uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW; | ||
487 | int r; | 490 | int r; |
488 | 491 | ||
489 | memset(&placements, 0, | 492 | memset(&placements, 0, sizeof(placements)); |
490 | (AMDGPU_GEM_DOMAIN_MAX + 1) * sizeof(struct ttm_place)); | 493 | amdgpu_ttm_placement_init(adev, &placement, placements, |
494 | domain, parent_flags); | ||
491 | 495 | ||
492 | amdgpu_ttm_placement_init(adev, &placement, | 496 | r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel, domain, |
493 | placements, domain, flags); | 497 | parent_flags, sg, &placement, resv, |
494 | 498 | init_value, bo_ptr); | |
495 | r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel, | ||
496 | domain, flags, sg, &placement, | ||
497 | resv, init_value, bo_ptr); | ||
498 | if (r) | 499 | if (r) |
499 | return r; | 500 | return r; |
500 | 501 | ||
501 | if (amdgpu_need_backup(adev) && (flags & AMDGPU_GEM_CREATE_SHADOW)) { | 502 | if ((flags & AMDGPU_GEM_CREATE_SHADOW) && amdgpu_need_backup(adev)) { |
502 | if (!resv) { | 503 | if (!resv) |
503 | r = ww_mutex_lock(&(*bo_ptr)->tbo.resv->lock, NULL); | 504 | WARN_ON(reservation_object_lock((*bo_ptr)->tbo.resv, |
504 | WARN_ON(r != 0); | 505 | NULL)); |
505 | } | ||
506 | 506 | ||
507 | r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr)); | 507 | r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr)); |
508 | 508 | ||
509 | if (!resv) | 509 | if (!resv) |
510 | ww_mutex_unlock(&(*bo_ptr)->tbo.resv->lock); | 510 | reservation_object_unlock((*bo_ptr)->tbo.resv); |
511 | 511 | ||
512 | if (r) | 512 | if (r) |
513 | amdgpu_bo_unref(bo_ptr); | 513 | amdgpu_bo_unref(bo_ptr); |