aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index fee0a32ac56f..010d14195a5e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -328,9 +328,10 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
328 AMDGPU_GEM_CREATE_SHADOW); 328 AMDGPU_GEM_CREATE_SHADOW);
329 329
330 if (vm->pte_support_ats) { 330 if (vm->pte_support_ats) {
331 init_value = AMDGPU_PTE_SYSTEM; 331 init_value = AMDGPU_PTE_DEFAULT_ATC;
332 if (level != adev->vm_manager.num_level - 1) 332 if (level != adev->vm_manager.num_level - 1)
333 init_value |= AMDGPU_PDE_PTE; 333 init_value |= AMDGPU_PDE_PTE;
334
334 } 335 }
335 336
336 /* walk over the address space and allocate the page tables */ 337 /* walk over the address space and allocate the page tables */
@@ -1034,7 +1035,7 @@ static int amdgpu_vm_wait_pd(struct amdgpu_device *adev, struct amdgpu_vm *vm,
1034 int r; 1035 int r;
1035 1036
1036 amdgpu_sync_create(&sync); 1037 amdgpu_sync_create(&sync);
1037 amdgpu_sync_resv(adev, &sync, vm->root.base.bo->tbo.resv, owner); 1038 amdgpu_sync_resv(adev, &sync, vm->root.base.bo->tbo.resv, owner, false);
1038 r = amdgpu_sync_wait(&sync, true); 1039 r = amdgpu_sync_wait(&sync, true);
1039 amdgpu_sync_free(&sync); 1040 amdgpu_sync_free(&sync);
1040 1041
@@ -1175,11 +1176,11 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
1175 amdgpu_ring_pad_ib(ring, params.ib); 1176 amdgpu_ring_pad_ib(ring, params.ib);
1176 amdgpu_sync_resv(adev, &job->sync, 1177 amdgpu_sync_resv(adev, &job->sync,
1177 parent->base.bo->tbo.resv, 1178 parent->base.bo->tbo.resv,
1178 AMDGPU_FENCE_OWNER_VM); 1179 AMDGPU_FENCE_OWNER_VM, false);
1179 if (shadow) 1180 if (shadow)
1180 amdgpu_sync_resv(adev, &job->sync, 1181 amdgpu_sync_resv(adev, &job->sync,
1181 shadow->tbo.resv, 1182 shadow->tbo.resv,
1182 AMDGPU_FENCE_OWNER_VM); 1183 AMDGPU_FENCE_OWNER_VM, false);
1183 1184
1184 WARN_ON(params.ib->length_dw > ndw); 1185 WARN_ON(params.ib->length_dw > ndw);
1185 r = amdgpu_job_submit(job, ring, &vm->entity, 1186 r = amdgpu_job_submit(job, ring, &vm->entity,
@@ -1643,7 +1644,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
1643 goto error_free; 1644 goto error_free;
1644 1645
1645 r = amdgpu_sync_resv(adev, &job->sync, vm->root.base.bo->tbo.resv, 1646 r = amdgpu_sync_resv(adev, &job->sync, vm->root.base.bo->tbo.resv,
1646 owner); 1647 owner, false);
1647 if (r) 1648 if (r)
1648 goto error_free; 1649 goto error_free;
1649 1650
@@ -1698,6 +1699,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
1698 struct drm_mm_node *nodes, 1699 struct drm_mm_node *nodes,
1699 struct dma_fence **fence) 1700 struct dma_fence **fence)
1700{ 1701{
1702 unsigned min_linear_pages = 1 << adev->vm_manager.fragment_size;
1701 uint64_t pfn, start = mapping->start; 1703 uint64_t pfn, start = mapping->start;
1702 int r; 1704 int r;
1703 1705
@@ -1732,6 +1734,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
1732 } 1734 }
1733 1735
1734 do { 1736 do {
1737 dma_addr_t *dma_addr = NULL;
1735 uint64_t max_entries; 1738 uint64_t max_entries;
1736 uint64_t addr, last; 1739 uint64_t addr, last;
1737 1740
@@ -1745,15 +1748,32 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
1745 } 1748 }
1746 1749
1747 if (pages_addr) { 1750 if (pages_addr) {
1751 uint64_t count;
1752
1748 max_entries = min(max_entries, 16ull * 1024ull); 1753 max_entries = min(max_entries, 16ull * 1024ull);
1749 addr = 0; 1754 for (count = 1; count < max_entries; ++count) {
1755 uint64_t idx = pfn + count;
1756
1757 if (pages_addr[idx] !=
1758 (pages_addr[idx - 1] + PAGE_SIZE))
1759 break;
1760 }
1761
1762 if (count < min_linear_pages) {
1763 addr = pfn << PAGE_SHIFT;
1764 dma_addr = pages_addr;
1765 } else {
1766 addr = pages_addr[pfn];
1767 max_entries = count;
1768 }
1769
1750 } else if (flags & AMDGPU_PTE_VALID) { 1770 } else if (flags & AMDGPU_PTE_VALID) {
1751 addr += adev->vm_manager.vram_base_offset; 1771 addr += adev->vm_manager.vram_base_offset;
1772 addr += pfn << PAGE_SHIFT;
1752 } 1773 }
1753 addr += pfn << PAGE_SHIFT;
1754 1774
1755 last = min((uint64_t)mapping->last, start + max_entries - 1); 1775 last = min((uint64_t)mapping->last, start + max_entries - 1);
1756 r = amdgpu_vm_bo_update_mapping(adev, exclusive, pages_addr, vm, 1776 r = amdgpu_vm_bo_update_mapping(adev, exclusive, dma_addr, vm,
1757 start, last, flags, addr, 1777 start, last, flags, addr,
1758 fence); 1778 fence);
1759 if (r) 1779 if (r)
@@ -2017,7 +2037,7 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
2017 list_del(&mapping->list); 2037 list_del(&mapping->list);
2018 2038
2019 if (vm->pte_support_ats) 2039 if (vm->pte_support_ats)
2020 init_pte_value = AMDGPU_PTE_SYSTEM; 2040 init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
2021 2041
2022 r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm, 2042 r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
2023 mapping->start, mapping->last, 2043 mapping->start, mapping->last,
@@ -2629,7 +2649,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
2629 2649
2630 if (adev->asic_type == CHIP_RAVEN) { 2650 if (adev->asic_type == CHIP_RAVEN) {
2631 vm->pte_support_ats = true; 2651 vm->pte_support_ats = true;
2632 init_pde_value = AMDGPU_PTE_SYSTEM | AMDGPU_PDE_PTE; 2652 init_pde_value = AMDGPU_PTE_DEFAULT_ATC
2653 | AMDGPU_PDE_PTE;
2654
2633 } 2655 }
2634 } else 2656 } else
2635 vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & 2657 vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
@@ -2737,8 +2759,9 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
2737{ 2759{
2738 struct amdgpu_bo_va_mapping *mapping, *tmp; 2760 struct amdgpu_bo_va_mapping *mapping, *tmp;
2739 bool prt_fini_needed = !!adev->gart.gart_funcs->set_prt; 2761 bool prt_fini_needed = !!adev->gart.gart_funcs->set_prt;
2762 struct amdgpu_bo *root;
2740 u64 fault; 2763 u64 fault;
2741 int i; 2764 int i, r;
2742 2765
2743 /* Clear pending page faults from IH when the VM is destroyed */ 2766 /* Clear pending page faults from IH when the VM is destroyed */
2744 while (kfifo_get(&vm->faults, &fault)) 2767 while (kfifo_get(&vm->faults, &fault))
@@ -2773,7 +2796,15 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
2773 amdgpu_vm_free_mapping(adev, vm, mapping, NULL); 2796 amdgpu_vm_free_mapping(adev, vm, mapping, NULL);
2774 } 2797 }
2775 2798
2776 amdgpu_vm_free_levels(&vm->root); 2799 root = amdgpu_bo_ref(vm->root.base.bo);
2800 r = amdgpu_bo_reserve(root, true);
2801 if (r) {
2802 dev_err(adev->dev, "Leaking page tables because BO reservation failed\n");
2803 } else {
2804 amdgpu_vm_free_levels(&vm->root);
2805 amdgpu_bo_unreserve(root);
2806 }
2807 amdgpu_bo_unref(&root);
2777 dma_fence_put(vm->last_update); 2808 dma_fence_put(vm->last_update);
2778 for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) 2809 for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
2779 amdgpu_vm_free_reserved_vmid(adev, vm, i); 2810 amdgpu_vm_free_reserved_vmid(adev, vm, i);