diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 8ee69652be8c..3ec43cf9ad78 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |||
@@ -93,6 +93,7 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) | |||
93 | 93 | ||
94 | bo = container_of(tbo, struct amdgpu_bo, tbo); | 94 | bo = container_of(tbo, struct amdgpu_bo, tbo); |
95 | 95 | ||
96 | amdgpu_bo_kunmap(bo); | ||
96 | amdgpu_update_memory_usage(adev, &bo->tbo.mem, NULL); | 97 | amdgpu_update_memory_usage(adev, &bo->tbo.mem, NULL); |
97 | 98 | ||
98 | drm_gem_object_release(&bo->gem_base); | 99 | drm_gem_object_release(&bo->gem_base); |
@@ -322,7 +323,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, | |||
322 | struct amdgpu_bo *bo; | 323 | struct amdgpu_bo *bo; |
323 | enum ttm_bo_type type; | 324 | enum ttm_bo_type type; |
324 | unsigned long page_align; | 325 | unsigned long page_align; |
325 | u64 initial_bytes_moved; | 326 | u64 initial_bytes_moved, bytes_moved; |
326 | size_t acc_size; | 327 | size_t acc_size; |
327 | int r; | 328 | int r; |
328 | 329 | ||
@@ -398,8 +399,14 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, | |||
398 | r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type, | 399 | r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type, |
399 | &bo->placement, page_align, !kernel, NULL, | 400 | &bo->placement, page_align, !kernel, NULL, |
400 | acc_size, sg, resv, &amdgpu_ttm_bo_destroy); | 401 | acc_size, sg, resv, &amdgpu_ttm_bo_destroy); |
401 | amdgpu_cs_report_moved_bytes(adev, | 402 | bytes_moved = atomic64_read(&adev->num_bytes_moved) - |
402 | atomic64_read(&adev->num_bytes_moved) - initial_bytes_moved); | 403 | initial_bytes_moved; |
404 | if (adev->mc.visible_vram_size < adev->mc.real_vram_size && | ||
405 | bo->tbo.mem.mem_type == TTM_PL_VRAM && | ||
406 | bo->tbo.mem.start < adev->mc.visible_vram_size >> PAGE_SHIFT) | ||
407 | amdgpu_cs_report_moved_bytes(adev, bytes_moved, bytes_moved); | ||
408 | else | ||
409 | amdgpu_cs_report_moved_bytes(adev, bytes_moved, 0); | ||
403 | 410 | ||
404 | if (unlikely(r != 0)) | 411 | if (unlikely(r != 0)) |
405 | return r; | 412 | return r; |
@@ -426,6 +433,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, | |||
426 | 433 | ||
427 | trace_amdgpu_bo_create(bo); | 434 | trace_amdgpu_bo_create(bo); |
428 | 435 | ||
436 | /* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */ | ||
437 | if (type == ttm_bo_type_device) | ||
438 | bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | ||
439 | |||
429 | return 0; | 440 | return 0; |
430 | 441 | ||
431 | fail_unreserve: | 442 | fail_unreserve: |
@@ -535,7 +546,7 @@ int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev, | |||
535 | 546 | ||
536 | r = amdgpu_copy_buffer(ring, bo_addr, shadow_addr, | 547 | r = amdgpu_copy_buffer(ring, bo_addr, shadow_addr, |
537 | amdgpu_bo_size(bo), resv, fence, | 548 | amdgpu_bo_size(bo), resv, fence, |
538 | direct); | 549 | direct, false); |
539 | if (!r) | 550 | if (!r) |
540 | amdgpu_bo_fence(bo, *fence, true); | 551 | amdgpu_bo_fence(bo, *fence, true); |
541 | 552 | ||
@@ -588,7 +599,7 @@ int amdgpu_bo_restore_from_shadow(struct amdgpu_device *adev, | |||
588 | 599 | ||
589 | r = amdgpu_copy_buffer(ring, shadow_addr, bo_addr, | 600 | r = amdgpu_copy_buffer(ring, shadow_addr, bo_addr, |
590 | amdgpu_bo_size(bo), resv, fence, | 601 | amdgpu_bo_size(bo), resv, fence, |
591 | direct); | 602 | direct, false); |
592 | if (!r) | 603 | if (!r) |
593 | amdgpu_bo_fence(bo, *fence, true); | 604 | amdgpu_bo_fence(bo, *fence, true); |
594 | 605 | ||
@@ -724,15 +735,16 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, | |||
724 | dev_err(adev->dev, "%p pin failed\n", bo); | 735 | dev_err(adev->dev, "%p pin failed\n", bo); |
725 | goto error; | 736 | goto error; |
726 | } | 737 | } |
727 | r = amdgpu_ttm_bind(&bo->tbo, &bo->tbo.mem); | ||
728 | if (unlikely(r)) { | ||
729 | dev_err(adev->dev, "%p bind failed\n", bo); | ||
730 | goto error; | ||
731 | } | ||
732 | 738 | ||
733 | bo->pin_count = 1; | 739 | bo->pin_count = 1; |
734 | if (gpu_addr != NULL) | 740 | if (gpu_addr != NULL) { |
741 | r = amdgpu_ttm_bind(&bo->tbo, &bo->tbo.mem); | ||
742 | if (unlikely(r)) { | ||
743 | dev_err(adev->dev, "%p bind failed\n", bo); | ||
744 | goto error; | ||
745 | } | ||
735 | *gpu_addr = amdgpu_bo_gpu_offset(bo); | 746 | *gpu_addr = amdgpu_bo_gpu_offset(bo); |
747 | } | ||
736 | if (domain == AMDGPU_GEM_DOMAIN_VRAM) { | 748 | if (domain == AMDGPU_GEM_DOMAIN_VRAM) { |
737 | adev->vram_pin_size += amdgpu_bo_size(bo); | 749 | adev->vram_pin_size += amdgpu_bo_size(bo); |
738 | if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) | 750 | if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) |
@@ -921,6 +933,8 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, | |||
921 | abo = container_of(bo, struct amdgpu_bo, tbo); | 933 | abo = container_of(bo, struct amdgpu_bo, tbo); |
922 | amdgpu_vm_bo_invalidate(adev, abo); | 934 | amdgpu_vm_bo_invalidate(adev, abo); |
923 | 935 | ||
936 | amdgpu_bo_kunmap(abo); | ||
937 | |||
924 | /* remember the eviction */ | 938 | /* remember the eviction */ |
925 | if (evict) | 939 | if (evict) |
926 | atomic64_inc(&adev->num_evictions); | 940 | atomic64_inc(&adev->num_evictions); |
@@ -939,19 +953,22 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo) | |||
939 | { | 953 | { |
940 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); | 954 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); |
941 | struct amdgpu_bo *abo; | 955 | struct amdgpu_bo *abo; |
942 | unsigned long offset, size, lpfn; | 956 | unsigned long offset, size; |
943 | int i, r; | 957 | int r; |
944 | 958 | ||
945 | if (!amdgpu_ttm_bo_is_amdgpu_bo(bo)) | 959 | if (!amdgpu_ttm_bo_is_amdgpu_bo(bo)) |
946 | return 0; | 960 | return 0; |
947 | 961 | ||
948 | abo = container_of(bo, struct amdgpu_bo, tbo); | 962 | abo = container_of(bo, struct amdgpu_bo, tbo); |
963 | |||
964 | /* Remember that this BO was accessed by the CPU */ | ||
965 | abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | ||
966 | |||
949 | if (bo->mem.mem_type != TTM_PL_VRAM) | 967 | if (bo->mem.mem_type != TTM_PL_VRAM) |
950 | return 0; | 968 | return 0; |
951 | 969 | ||
952 | size = bo->mem.num_pages << PAGE_SHIFT; | 970 | size = bo->mem.num_pages << PAGE_SHIFT; |
953 | offset = bo->mem.start << PAGE_SHIFT; | 971 | offset = bo->mem.start << PAGE_SHIFT; |
954 | /* TODO: figure out how to map scattered VRAM to the CPU */ | ||
955 | if ((offset + size) <= adev->mc.visible_vram_size) | 972 | if ((offset + size) <= adev->mc.visible_vram_size) |
956 | return 0; | 973 | return 0; |
957 | 974 | ||
@@ -961,26 +978,21 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo) | |||
961 | 978 | ||
962 | /* hurrah the memory is not visible ! */ | 979 | /* hurrah the memory is not visible ! */ |
963 | atomic64_inc(&adev->num_vram_cpu_page_faults); | 980 | atomic64_inc(&adev->num_vram_cpu_page_faults); |
964 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM); | 981 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM | |
965 | lpfn = adev->mc.visible_vram_size >> PAGE_SHIFT; | 982 | AMDGPU_GEM_DOMAIN_GTT); |
966 | for (i = 0; i < abo->placement.num_placement; i++) { | 983 | |
967 | /* Force into visible VRAM */ | 984 | /* Avoid costly evictions; only set GTT as a busy placement */ |
968 | if ((abo->placements[i].flags & TTM_PL_FLAG_VRAM) && | 985 | abo->placement.num_busy_placement = 1; |
969 | (!abo->placements[i].lpfn || | 986 | abo->placement.busy_placement = &abo->placements[1]; |
970 | abo->placements[i].lpfn > lpfn)) | 987 | |
971 | abo->placements[i].lpfn = lpfn; | ||
972 | } | ||
973 | r = ttm_bo_validate(bo, &abo->placement, false, false); | 988 | r = ttm_bo_validate(bo, &abo->placement, false, false); |
974 | if (unlikely(r == -ENOMEM)) { | 989 | if (unlikely(r != 0)) |
975 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT); | ||
976 | return ttm_bo_validate(bo, &abo->placement, false, false); | ||
977 | } else if (unlikely(r != 0)) { | ||
978 | return r; | 990 | return r; |
979 | } | ||
980 | 991 | ||
981 | offset = bo->mem.start << PAGE_SHIFT; | 992 | offset = bo->mem.start << PAGE_SHIFT; |
982 | /* this should never happen */ | 993 | /* this should never happen */ |
983 | if ((offset + size) > adev->mc.visible_vram_size) | 994 | if (bo->mem.mem_type == TTM_PL_VRAM && |
995 | (offset + size) > adev->mc.visible_vram_size) | ||
984 | return -EINVAL; | 996 | return -EINVAL; |
985 | 997 | ||
986 | return 0; | 998 | return 0; |