aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c96
1 files changed, 35 insertions, 61 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index b0e14a3d54ef..904014dc5915 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -51,18 +51,6 @@
51 * 51 *
52 */ 52 */
53 53
54static bool amdgpu_bo_need_backup(struct amdgpu_device *adev)
55{
56 if (adev->flags & AMD_IS_APU)
57 return false;
58
59 if (amdgpu_gpu_recovery == 0 ||
60 (amdgpu_gpu_recovery == -1 && !amdgpu_sriov_vf(adev)))
61 return false;
62
63 return true;
64}
65
66/** 54/**
67 * amdgpu_bo_subtract_pin_size - Remove BO from pin_size accounting 55 * amdgpu_bo_subtract_pin_size - Remove BO from pin_size accounting
68 * 56 *
@@ -163,10 +151,7 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
163 151
164 if (domain & AMDGPU_GEM_DOMAIN_GTT) { 152 if (domain & AMDGPU_GEM_DOMAIN_GTT) {
165 places[c].fpfn = 0; 153 places[c].fpfn = 0;
166 if (flags & AMDGPU_GEM_CREATE_SHADOW) 154 places[c].lpfn = 0;
167 places[c].lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
168 else
169 places[c].lpfn = 0;
170 places[c].flags = TTM_PL_FLAG_TT; 155 places[c].flags = TTM_PL_FLAG_TT;
171 if (flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC) 156 if (flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC)
172 places[c].flags |= TTM_PL_FLAG_WC | 157 places[c].flags |= TTM_PL_FLAG_WC |
@@ -253,6 +238,11 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
253 bool free = false; 238 bool free = false;
254 int r; 239 int r;
255 240
241 if (!size) {
242 amdgpu_bo_unref(bo_ptr);
243 return 0;
244 }
245
256 memset(&bp, 0, sizeof(bp)); 246 memset(&bp, 0, sizeof(bp));
257 bp.size = size; 247 bp.size = size;
258 bp.byte_align = align; 248 bp.byte_align = align;
@@ -346,7 +336,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
346 if (r) 336 if (r)
347 return r; 337 return r;
348 338
349 amdgpu_bo_unreserve(*bo_ptr); 339 if (*bo_ptr)
340 amdgpu_bo_unreserve(*bo_ptr);
350 341
351 return 0; 342 return 0;
352} 343}
@@ -436,7 +427,11 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
436 int r; 427 int r;
437 428
438 page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT; 429 page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;
439 size = ALIGN(size, PAGE_SIZE); 430 if (bp->domain & (AMDGPU_GEM_DOMAIN_GDS | AMDGPU_GEM_DOMAIN_GWS |
431 AMDGPU_GEM_DOMAIN_OA))
432 size <<= PAGE_SHIFT;
433 else
434 size = ALIGN(size, PAGE_SIZE);
440 435
441 if (!amdgpu_bo_validate_size(adev, size, bp->domain)) 436 if (!amdgpu_bo_validate_size(adev, size, bp->domain))
442 return -ENOMEM; 437 return -ENOMEM;
@@ -451,7 +446,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
451 return -ENOMEM; 446 return -ENOMEM;
452 drm_gem_private_object_init(adev->ddev, &bo->gem_base, size); 447 drm_gem_private_object_init(adev->ddev, &bo->gem_base, size);
453 INIT_LIST_HEAD(&bo->shadow_list); 448 INIT_LIST_HEAD(&bo->shadow_list);
454 INIT_LIST_HEAD(&bo->va); 449 bo->vm_bo = NULL;
455 bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain : 450 bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain :
456 bp->domain; 451 bp->domain;
457 bo->allowed_domains = bo->preferred_domains; 452 bo->allowed_domains = bo->preferred_domains;
@@ -541,7 +536,7 @@ fail_unreserve:
541} 536}
542 537
543static int amdgpu_bo_create_shadow(struct amdgpu_device *adev, 538static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
544 unsigned long size, int byte_align, 539 unsigned long size,
545 struct amdgpu_bo *bo) 540 struct amdgpu_bo *bo)
546{ 541{
547 struct amdgpu_bo_param bp; 542 struct amdgpu_bo_param bp;
@@ -552,7 +547,6 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
552 547
553 memset(&bp, 0, sizeof(bp)); 548 memset(&bp, 0, sizeof(bp));
554 bp.size = size; 549 bp.size = size;
555 bp.byte_align = byte_align;
556 bp.domain = AMDGPU_GEM_DOMAIN_GTT; 550 bp.domain = AMDGPU_GEM_DOMAIN_GTT;
557 bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC | 551 bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
558 AMDGPU_GEM_CREATE_SHADOW; 552 AMDGPU_GEM_CREATE_SHADOW;
@@ -563,7 +557,7 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
563 if (!r) { 557 if (!r) {
564 bo->shadow->parent = amdgpu_bo_ref(bo); 558 bo->shadow->parent = amdgpu_bo_ref(bo);
565 mutex_lock(&adev->shadow_list_lock); 559 mutex_lock(&adev->shadow_list_lock);
566 list_add_tail(&bo->shadow_list, &adev->shadow_list); 560 list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
567 mutex_unlock(&adev->shadow_list_lock); 561 mutex_unlock(&adev->shadow_list_lock);
568 } 562 }
569 563
@@ -596,12 +590,12 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
596 if (r) 590 if (r)
597 return r; 591 return r;
598 592
599 if ((flags & AMDGPU_GEM_CREATE_SHADOW) && amdgpu_bo_need_backup(adev)) { 593 if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags & AMD_IS_APU)) {
600 if (!bp->resv) 594 if (!bp->resv)
601 WARN_ON(reservation_object_lock((*bo_ptr)->tbo.resv, 595 WARN_ON(reservation_object_lock((*bo_ptr)->tbo.resv,
602 NULL)); 596 NULL));
603 597
604 r = amdgpu_bo_create_shadow(adev, bp->size, bp->byte_align, (*bo_ptr)); 598 r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr);
605 599
606 if (!bp->resv) 600 if (!bp->resv)
607 reservation_object_unlock((*bo_ptr)->tbo.resv); 601 reservation_object_unlock((*bo_ptr)->tbo.resv);
@@ -695,13 +689,10 @@ retry:
695} 689}
696 690
697/** 691/**
698 * amdgpu_bo_restore_from_shadow - restore an &amdgpu_bo buffer object 692 * amdgpu_bo_restore_shadow - restore an &amdgpu_bo shadow
699 * @adev: amdgpu device object 693 *
700 * @ring: amdgpu_ring for the engine handling the buffer operations 694 * @shadow: &amdgpu_bo shadow to be restored
701 * @bo: &amdgpu_bo buffer to be restored
702 * @resv: reservation object with embedded fence
703 * @fence: dma_fence associated with the operation 695 * @fence: dma_fence associated with the operation
704 * @direct: whether to submit the job directly
705 * 696 *
706 * Copies a buffer object's shadow content back to the object. 697 * Copies a buffer object's shadow content back to the object.
707 * This is used for recovering a buffer from its shadow in case of a gpu 698 * This is used for recovering a buffer from its shadow in case of a gpu
@@ -710,36 +701,19 @@ retry:
710 * Returns: 701 * Returns:
711 * 0 for success or a negative error code on failure. 702 * 0 for success or a negative error code on failure.
712 */ 703 */
713int amdgpu_bo_restore_from_shadow(struct amdgpu_device *adev, 704int amdgpu_bo_restore_shadow(struct amdgpu_bo *shadow, struct dma_fence **fence)
714 struct amdgpu_ring *ring,
715 struct amdgpu_bo *bo,
716 struct reservation_object *resv,
717 struct dma_fence **fence,
718 bool direct)
719 705
720{ 706{
721 struct amdgpu_bo *shadow = bo->shadow; 707 struct amdgpu_device *adev = amdgpu_ttm_adev(shadow->tbo.bdev);
722 uint64_t bo_addr, shadow_addr; 708 struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
723 int r; 709 uint64_t shadow_addr, parent_addr;
724
725 if (!shadow)
726 return -EINVAL;
727 710
728 bo_addr = amdgpu_bo_gpu_offset(bo); 711 shadow_addr = amdgpu_bo_gpu_offset(shadow);
729 shadow_addr = amdgpu_bo_gpu_offset(bo->shadow); 712 parent_addr = amdgpu_bo_gpu_offset(shadow->parent);
730 713
731 r = reservation_object_reserve_shared(bo->tbo.resv); 714 return amdgpu_copy_buffer(ring, shadow_addr, parent_addr,
732 if (r)