Lines Matching full:vm

119 	 * @vm: pointer to the amdgpu_vm structure to set the fence sequence on
121 struct amdgpu_vm *vm; member
130 * amdgpu_vm_set_pasid - manage pasid and vm ptr mapping
133 * @vm: amdgpu_vm pointer
134 * @pasid: the pasid the VM is using on this GPU
136 * Set the pasid this VM is using on this GPU, can also be used to remove the
140 int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm, in amdgpu_vm_set_pasid() argument
145 if (vm->pasid == pasid) in amdgpu_vm_set_pasid()
148 if (vm->pasid) { in amdgpu_vm_set_pasid()
149 r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid)); in amdgpu_vm_set_pasid()
153 vm->pasid = 0; in amdgpu_vm_set_pasid()
157 r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm, in amdgpu_vm_set_pasid()
162 vm->pasid = pasid; in amdgpu_vm_set_pasid()
174 * State for PDs/PTs and per VM BOs which are not at the location they should
179 struct amdgpu_vm *vm = vm_bo->vm; in amdgpu_vm_bo_evicted() local
183 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_evicted()
185 list_move(&vm_bo->vm_status, &vm->evicted); in amdgpu_vm_bo_evicted()
187 list_move_tail(&vm_bo->vm_status, &vm->evicted); in amdgpu_vm_bo_evicted()
188 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_evicted()
195 * State for per VM BOs which are moved, but that change is not yet reflected
200 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_moved()
201 list_move(&vm_bo->vm_status, &vm_bo->vm->moved); in amdgpu_vm_bo_moved()
202 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_moved()
210 * State for PDs/PTs and per VM BOs which have gone through the state machine
215 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_idle()
216 list_move(&vm_bo->vm_status, &vm_bo->vm->idle); in amdgpu_vm_bo_idle()
217 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_idle()
231 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_invalidated()
232 list_move(&vm_bo->vm_status, &vm_bo->vm->invalidated); in amdgpu_vm_bo_invalidated()
233 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_invalidated()
247 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_relocated()
248 list_move(&vm_bo->vm_status, &vm_bo->vm->relocated); in amdgpu_vm_bo_relocated()
249 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_relocated()
265 spin_lock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_done()
266 list_move(&vm_bo->vm_status, &vm_bo->vm->done); in amdgpu_vm_bo_done()
267 spin_unlock(&vm_bo->vm->status_lock); in amdgpu_vm_bo_done()
272 * @vm: the VM which state machine to reset
274 * Move all vm_bo object in the VM into a state where they will be updated
277 static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm) in amdgpu_vm_bo_reset_state_machine() argument
281 spin_lock(&vm->status_lock); in amdgpu_vm_bo_reset_state_machine()
282 list_splice_init(&vm->done, &vm->invalidated); in amdgpu_vm_bo_reset_state_machine()
283 list_for_each_entry(vm_bo, &vm->invalidated, vm_status) in amdgpu_vm_bo_reset_state_machine()
285 list_for_each_entry_safe(vm_bo, tmp, &vm->idle, vm_status) { in amdgpu_vm_bo_reset_state_machine()
290 list_move(&vm_bo->vm_status, &vm_bo->vm->moved); in amdgpu_vm_bo_reset_state_machine()
292 list_move(&vm_bo->vm_status, &vm_bo->vm->relocated); in amdgpu_vm_bo_reset_state_machine()
294 spin_unlock(&vm->status_lock); in amdgpu_vm_bo_reset_state_machine()
298 * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm
300 * @base: base structure for tracking BO usage in a VM
301 * @vm: vm to which bo is to be added
308 struct amdgpu_vm *vm, struct amdgpu_bo *bo) in amdgpu_vm_bo_base_init() argument
310 base->vm = vm; in amdgpu_vm_bo_base_init()
320 if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) in amdgpu_vm_bo_base_init()
323 dma_resv_assert_held(vm->root.bo->tbo.base.resv); in amdgpu_vm_bo_base_init()
325 ttm_bo_set_bulk_move(&bo->tbo, &vm->lru_bulk_move); in amdgpu_vm_bo_base_init()
336 * we checked all the prerequisites, but it looks like this per vm bo in amdgpu_vm_bo_base_init()
338 * is validated on next vm use to avoid fault. in amdgpu_vm_bo_base_init()
346 * @vm: vm providing the BOs
350 * Lock the VM root PD in the DRM execution context.
352 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec, in amdgpu_vm_lock_pd() argument
355 /* We need at least two fences for the VM PD/PT updates */ in amdgpu_vm_lock_pd()
356 return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base, in amdgpu_vm_lock_pd()
364 * @vm: vm providing the BOs
370 struct amdgpu_vm *vm) in amdgpu_vm_move_to_lru_tail() argument
373 ttm_lru_bulk_move_tail(&vm->lru_bulk_move); in amdgpu_vm_move_to_lru_tail()
379 struct amdgpu_vm *vm) in amdgpu_vm_init_entities() argument
383 r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL, in amdgpu_vm_init_entities()
389 return drm_sched_entity_init(&vm->delayed, DRM_SCHED_PRIORITY_NORMAL, in amdgpu_vm_init_entities()
394 drm_sched_entity_destroy(&vm->immediate); in amdgpu_vm_init_entities()
399 static void amdgpu_vm_fini_entities(struct amdgpu_vm *vm) in amdgpu_vm_fini_entities() argument
401 drm_sched_entity_destroy(&vm->immediate); in amdgpu_vm_fini_entities()
402 drm_sched_entity_destroy(&vm->delayed); in amdgpu_vm_fini_entities()
408 * @vm: optional VM to check, might be NULL
411 * are still valid to use this VM. The VM parameter might be NULL in which case
414 uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) in amdgpu_vm_generation() argument
418 if (!vm) in amdgpu_vm_generation()
421 result += lower_32_bits(vm->generation); in amdgpu_vm_generation()
423 if (drm_sched_entity_error(&vm->delayed)) in amdgpu_vm_generation()
433 * @vm: vm providing the BOs
442 int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, in amdgpu_vm_validate_pt_bos() argument
446 uint64_t new_vm_generation = amdgpu_vm_generation(adev, vm); in amdgpu_vm_validate_pt_bos()
452 if (vm->generation != new_vm_generation) { in amdgpu_vm_validate_pt_bos()
453 vm->generation = new_vm_generation; in amdgpu_vm_validate_pt_bos()
454 amdgpu_vm_bo_reset_state_machine(vm); in amdgpu_vm_validate_pt_bos()
455 amdgpu_vm_fini_entities(vm); in amdgpu_vm_validate_pt_bos()
456 r = amdgpu_vm_init_entities(adev, vm); in amdgpu_vm_validate_pt_bos()
461 spin_lock(&vm->status_lock); in amdgpu_vm_validate_pt_bos()
462 while (!list_empty(&vm->evicted)) { in amdgpu_vm_validate_pt_bos()
463 bo_base = list_first_entry(&vm->evicted, in amdgpu_vm_validate_pt_bos()
466 spin_unlock(&vm->status_lock); in amdgpu_vm_validate_pt_bos()
483 vm->update_funcs->map_table(to_amdgpu_bo_vm(bo)); in amdgpu_vm_validate_pt_bos()
486 spin_lock(&vm->status_lock); in amdgpu_vm_validate_pt_bos()
488 spin_unlock(&vm->status_lock); in amdgpu_vm_validate_pt_bos()
490 amdgpu_vm_eviction_lock(vm); in amdgpu_vm_validate_pt_bos()
491 vm->evicting = false; in amdgpu_vm_validate_pt_bos()
492 amdgpu_vm_eviction_unlock(vm); in amdgpu_vm_validate_pt_bos()
498 * amdgpu_vm_ready - check VM is ready for updates
500 * @vm: VM to check
502 * Check if all VM PDs/PTs are ready for updates
505 * True if VM is not evicting.
507 bool amdgpu_vm_ready(struct amdgpu_vm *vm) in amdgpu_vm_ready() argument
512 amdgpu_vm_eviction_lock(vm); in amdgpu_vm_ready()
513 ret = !vm->evicting; in amdgpu_vm_ready()
514 amdgpu_vm_eviction_unlock(vm); in amdgpu_vm_ready()
516 spin_lock(&vm->status_lock); in amdgpu_vm_ready()
517 empty = list_empty(&vm->evicted); in amdgpu_vm_ready()
518 spin_unlock(&vm->status_lock); in amdgpu_vm_ready()
524 * amdgpu_vm_check_compute_bug - check whether asic has compute vm bug
539 /* Compute has a VM bug for GFX version < 7. in amdgpu_vm_check_compute_bug()
540 Compute has a VM bug for GFX 8 MEC firmware version < 673.*/ in amdgpu_vm_check_compute_bug()
590 * amdgpu_vm_flush - hardware flush the vm
596 * Emit a VM flush when it is necessary.
702 * amdgpu_vm_bo_find - find the bo_va for a specific vm & bo
704 * @vm: requested vm
707 * Find @bo inside the requested vm.
708 * Search inside the @bos vm list for the requested vm
716 struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, in amdgpu_vm_bo_find() argument
722 if (base->vm != vm) in amdgpu_vm_bo_find()
761 * @vm: requested vm
770 struct amdgpu_vm *vm, bool immediate) in amdgpu_vm_update_pdes() argument
778 spin_lock(&vm->status_lock); in amdgpu_vm_update_pdes()
779 list_splice_init(&vm->relocated, &relocated); in amdgpu_vm_update_pdes()
780 spin_unlock(&vm->status_lock); in amdgpu_vm_update_pdes()
790 params.vm = vm; in amdgpu_vm_update_pdes()
793 r = vm->update_funcs->prepare(&params, NULL, AMDGPU_SYNC_EXPLICIT); in amdgpu_vm_update_pdes()
806 r = vm->update_funcs->commit(&params, &vm->last_update); in amdgpu_vm_update_pdes()
811 atomic64_inc(&vm->tlb_seq); in amdgpu_vm_update_pdes()
829 * Increments the tlb sequence to make sure that future CS execute a VM flush.
837 atomic64_inc(&tlb_cb->vm->tlb_seq); in amdgpu_vm_tlb_seq_cb()
842 * amdgpu_vm_update_range - update a range in the vm page table
845 * @vm: the VM to update the range
864 int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm, in amdgpu_vm_update_range() argument
899 params.vm = vm; in amdgpu_vm_update_range()
904 /* Implicitly sync to command submissions in the same VM before in amdgpu_vm_update_range()
912 amdgpu_vm_eviction_lock(vm); in amdgpu_vm_update_range()
913 if (vm->evicting) { in amdgpu_vm_update_range()
918 if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) { in amdgpu_vm_update_range()
921 amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true); in amdgpu_vm_update_range()
922 swap(vm->last_unlocked, tmp); in amdgpu_vm_update_range()
926 r = vm->update_funcs->prepare(&params, resv, sync_mode); in amdgpu_vm_update_range()
984 r = vm->update_funcs->commit(&params, fence); in amdgpu_vm_update_range()
987 tlb_cb->vm = vm; in amdgpu_vm_update_range()
991 dma_fence_put(vm->last_tlb_flush); in amdgpu_vm_update_range()
992 vm->last_tlb_flush = dma_fence_get(*fence); in amdgpu_vm_update_range()
1003 amdgpu_vm_eviction_unlock(vm); in amdgpu_vm_update_range()
1011 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_get_memory() local
1021 if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && in amdgpu_vm_bo_get_memory()
1026 if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) in amdgpu_vm_bo_get_memory()
1030 void amdgpu_vm_get_memory(struct amdgpu_vm *vm, in amdgpu_vm_get_memory() argument
1035 spin_lock(&vm->status_lock); in amdgpu_vm_get_memory()
1036 list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status) in amdgpu_vm_get_memory()
1039 list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status) in amdgpu_vm_get_memory()
1042 list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status) in amdgpu_vm_get_memory()
1045 list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status) in amdgpu_vm_get_memory()
1048 list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status) in amdgpu_vm_get_memory()
1051 list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status) in amdgpu_vm_get_memory()
1053 spin_unlock(&vm->status_lock); in amdgpu_vm_get_memory()
1057 * amdgpu_vm_bo_update - update all BO mappings in the vm page table
1060 * @bo_va: requested BO and VM object
1072 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_update() local
1085 resv = vm->root.bo->tbo.base.resv; in amdgpu_vm_bo_update()
1121 vm->root.bo->tbo.base.resv)) in amdgpu_vm_bo_update()
1122 last_update = &vm->last_update; in amdgpu_vm_bo_update()
1150 r = amdgpu_vm_update_range(adev, vm, false, false, flush_tlb, in amdgpu_vm_bo_update()
1163 if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { in amdgpu_vm_bo_update()
1274 * @vm: requested vm
1281 struct amdgpu_vm *vm, in amdgpu_vm_free_mapping() argument
1294 * @vm: requested vm
1296 * Register a cleanup callback to disable PRT support after VM dies.
1298 static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) in amdgpu_vm_prt_fini() argument
1300 struct dma_resv *resv = vm->root.bo->tbo.base.resv; in amdgpu_vm_prt_fini()
1315 * @vm: requested vm
1327 struct amdgpu_vm *vm, in amdgpu_vm_clear_freed() argument
1330 struct dma_resv *resv = vm->root.bo->tbo.base.resv; in amdgpu_vm_clear_freed()
1336 while (!list_empty(&vm->freed)) { in amdgpu_vm_clear_freed()
1337 mapping = list_first_entry(&vm->freed, in amdgpu_vm_clear_freed()
1341 if (vm->pte_support_ats && in amdgpu_vm_clear_freed()
1345 r = amdgpu_vm_update_range(adev, vm, false, false, true, resv, in amdgpu_vm_clear_freed()
1349 amdgpu_vm_free_mapping(adev, vm, mapping, f); in amdgpu_vm_clear_freed()
1371 * @vm: requested vm
1381 struct amdgpu_vm *vm) in amdgpu_vm_handle_moved() argument
1388 spin_lock(&vm->status_lock); in amdgpu_vm_handle_moved()
1389 while (!list_empty(&vm->moved)) { in amdgpu_vm_handle_moved()
1390 bo_va = list_first_entry(&vm->moved, struct amdgpu_bo_va, in amdgpu_vm_handle_moved()
1392 spin_unlock(&vm->status_lock); in amdgpu_vm_handle_moved()
1394 /* Per VM BOs never need to bo cleared in the page tables */ in amdgpu_vm_handle_moved()
1398 spin_lock(&vm->status_lock); in amdgpu_vm_handle_moved()
1401 while (!list_empty(&vm->invalidated)) { in amdgpu_vm_handle_moved()
1402 bo_va = list_first_entry(&vm->invalidated, struct amdgpu_bo_va, in amdgpu_vm_handle_moved()
1405 spin_unlock(&vm->status_lock); in amdgpu_vm_handle_moved()
1420 spin_lock(&vm->status_lock); in amdgpu_vm_handle_moved()
1422 spin_unlock(&vm->status_lock); in amdgpu_vm_handle_moved()
1428 * amdgpu_vm_bo_add - add a bo to a specific vm
1431 * @vm: requested vm
1434 * Add @bo into the requested vm.
1435 * Add @bo to the list of bos associated with the vm
1443 struct amdgpu_vm *vm, in amdgpu_vm_bo_add() argument
1452 amdgpu_vm_bo_base_init(&bo_va->base, vm, bo); in amdgpu_vm_bo_add()
1486 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_insert_map() local
1491 amdgpu_vm_it_insert(mapping, &vm->va); in amdgpu_vm_bo_insert_map()
1496 if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && in amdgpu_vm_bo_insert_map()
1535 * amdgpu_vm_bo_map - map bo inside a vm
1544 * Add a mapping of the BO at the specefied addr into the VM.
1558 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_map() local
1569 tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr); in amdgpu_vm_bo_map()
1593 * amdgpu_vm_bo_replace_map - map bo inside a vm, replacing existing mappings
1602 * Add a mapping of the BO at the specefied addr into the VM. Replace existing
1629 r = amdgpu_vm_bo_clear_mappings(adev, bo_va->base.vm, saddr, size); in amdgpu_vm_bo_replace_map()
1649 * amdgpu_vm_bo_unmap - remove bo mapping from vm
1655 * Remove a mapping of the BO at the specefied addr from the VM.
1667 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_unmap() local
1690 amdgpu_vm_it_remove(mapping, &vm->va); in amdgpu_vm_bo_unmap()
1695 list_add(&mapping->list, &vm->freed); in amdgpu_vm_bo_unmap()
1697 amdgpu_vm_free_mapping(adev, vm, mapping, in amdgpu_vm_bo_unmap()
1707 * @vm: VM structure to use
1717 struct amdgpu_vm *vm, in amdgpu_vm_bo_clear_mappings() argument
1746 tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr); in amdgpu_vm_bo_clear_mappings()
1777 amdgpu_vm_it_remove(tmp, &vm->va); in amdgpu_vm_bo_clear_mappings()
1786 list_add(&tmp->list, &vm->freed); in amdgpu_vm_bo_clear_mappings()
1794 amdgpu_vm_it_insert(before, &vm->va); in amdgpu_vm_bo_clear_mappings()
1798 if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && in amdgpu_vm_bo_clear_mappings()
1809 amdgpu_vm_it_insert(after, &vm->va); in amdgpu_vm_bo_clear_mappings()
1813 if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && in amdgpu_vm_bo_clear_mappings()
1826 * @vm: the requested VM
1835 struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm, in amdgpu_vm_bo_lookup_mapping() argument
1838 return amdgpu_vm_it_iter_first(&vm->va, addr, addr); in amdgpu_vm_bo_lookup_mapping()
1844 * @vm: the requested vm
1849 void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket) in amdgpu_vm_bo_trace_cs() argument
1856 for (mapping = amdgpu_vm_it_iter_first(&vm->va, 0, U64_MAX); mapping; in amdgpu_vm_bo_trace_cs()
1872 * amdgpu_vm_bo_del - remove a bo from a specific vm
1877 * Remove @bo_va->bo from the requested vm.
1886 struct amdgpu_vm *vm = bo_va->base.vm; in amdgpu_vm_bo_del() local
1889 dma_resv_assert_held(vm->root.bo->tbo.base.resv); in amdgpu_vm_bo_del()
1893 if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) in amdgpu_vm_bo_del()
1906 spin_lock(&vm->status_lock); in amdgpu_vm_bo_del()
1908 spin_unlock(&vm->status_lock); in amdgpu_vm_bo_del()
1912 amdgpu_vm_it_remove(mapping, &vm->va); in amdgpu_vm_bo_del()
1915 list_add(&mapping->list, &vm->freed); in amdgpu_vm_bo_del()
1919 amdgpu_vm_it_remove(mapping, &vm->va); in amdgpu_vm_bo_del()
1920 amdgpu_vm_free_mapping(adev, vm, mapping, in amdgpu_vm_bo_del()
1933 * amdgpu_vm_evictable - check if we can evict a VM
1935 * @bo: A page table of the VM.
1937 * Check if it is possible to evict a VM.
1943 /* Page tables of a destroyed VM can go away immediately */ in amdgpu_vm_evictable()
1944 if (!bo_base || !bo_base->vm) in amdgpu_vm_evictable()
1947 /* Don't evict VM page tables while they are busy */ in amdgpu_vm_evictable()
1952 if (!amdgpu_vm_eviction_trylock(bo_base->vm)) in amdgpu_vm_evictable()
1955 /* Don't evict VM page tables while they are updated */ in amdgpu_vm_evictable()
1956 if (!dma_fence_is_signaled(bo_base->vm->last_unlocked)) { in amdgpu_vm_evictable()
1957 amdgpu_vm_eviction_unlock(bo_base->vm); in amdgpu_vm_evictable()
1961 bo_base->vm->evicting = true; in amdgpu_vm_evictable()
1962 amdgpu_vm_eviction_unlock(bo_base->vm); in amdgpu_vm_evictable()
1985 struct amdgpu_vm *vm = bo_base->vm; in amdgpu_vm_bo_invalidate() local
1987 if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { in amdgpu_vm_bo_invalidate()
1998 else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) in amdgpu_vm_bo_invalidate()
2006 * amdgpu_vm_get_block_size - calculate VM page table size as power of two
2008 * @vm_size: VM size
2011 * VM page table as power of two
2027 * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
2030 * @min_vm_size: the minimum vm size in GB if it's set auto
2044 /* adjust vm size first */ in amdgpu_vm_adjust_size()
2048 dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n", in amdgpu_vm_adjust_size()
2056 /* Optimal VM size depends on the amount of physical in amdgpu_vm_adjust_size()
2063 * - On GFX8 and older, VM space can be segmented for in amdgpu_vm_adjust_size()
2069 * VM size with the given page table size. in amdgpu_vm_adjust_size()
2098 /* block size depends on vm size and hw setup*/ in amdgpu_vm_adjust_size()
2114 DRM_INFO("vm size is %u GB, %u levels, block size is %u-bit, fragment size is %u-bit\n", in amdgpu_vm_adjust_size()
2121 * amdgpu_vm_wait_idle - wait for the VM to become idle
2123 * @vm: VM object to wait for
2124 * @timeout: timeout to wait for VM to become idle
2126 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout) in amdgpu_vm_wait_idle() argument
2128 timeout = dma_resv_wait_timeout(vm->root.bo->tbo.base.resv, in amdgpu_vm_wait_idle()
2134 return dma_fence_wait_timeout(vm->last_unlocked, true, timeout); in amdgpu_vm_wait_idle()
2138 * amdgpu_vm_init - initialize a vm instance
2141 * @vm: requested vm
2144 * Init @vm fields.
2149 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, in amdgpu_vm_init() argument
2156 vm->va = RB_ROOT_CACHED; in amdgpu_vm_init()
2158 vm->reserved_vmid[i] = NULL; in amdgpu_vm_init()
2159 INIT_LIST_HEAD(&vm->evicted); in amdgpu_vm_init()
2160 INIT_LIST_HEAD(&vm->relocated); in amdgpu_vm_init()
2161 INIT_LIST_HEAD(&vm->moved); in amdgpu_vm_init()
2162 INIT_LIST_HEAD(&vm->idle); in amdgpu_vm_init()
2163 INIT_LIST_HEAD(&vm->invalidated); in amdgpu_vm_init()
2164 spin_lock_init(&vm->status_lock); in amdgpu_vm_init()
2165 INIT_LIST_HEAD(&vm->freed); in amdgpu_vm_init()
2166 INIT_LIST_HEAD(&vm->done); in amdgpu_vm_init()
2167 INIT_LIST_HEAD(&vm->pt_freed); in amdgpu_vm_init()
2168 INIT_WORK(&vm->pt_free_work, amdgpu_vm_pt_free_work); in amdgpu_vm_init()
2169 INIT_KFIFO(vm->faults); in amdgpu_vm_init()
2171 r = amdgpu_vm_init_entities(adev, vm); in amdgpu_vm_init()
2175 vm->pte_support_ats = false; in amdgpu_vm_init()
2176 vm->is_compute_context = false; in amdgpu_vm_init()
2178 vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & in amdgpu_vm_init()
2181 DRM_DEBUG_DRIVER("VM update mode is %s\n", in amdgpu_vm_init()
2182 vm->use_cpu_for_update ? "CPU" : "SDMA"); in amdgpu_vm_init()
2183 WARN_ONCE((vm->use_cpu_for_update && in amdgpu_vm_init()
2185 "CPU update of VM recommended only for large BAR system\n"); in amdgpu_vm_init()
2187 if (vm->use_cpu_for_update) in amdgpu_vm_init()
2188 vm->update_funcs = &amdgpu_vm_cpu_funcs; in amdgpu_vm_init()
2190 vm->update_funcs = &amdgpu_vm_sdma_funcs; in amdgpu_vm_init()
2192 vm->last_update = dma_fence_get_stub(); in amdgpu_vm_init()
2193 vm->last_unlocked = dma_fence_get_stub(); in amdgpu_vm_init()
2194 vm->last_tlb_flush = dma_fence_get_stub(); in amdgpu_vm_init()
2195 vm->generation = amdgpu_vm_generation(adev, NULL); in amdgpu_vm_init()
2197 mutex_init(&vm->eviction_lock); in amdgpu_vm_init()
2198 vm->evicting = false; in amdgpu_vm_init()
2200 r = amdgpu_vm_pt_create(adev, vm, adev->vm_manager.root_level, in amdgpu_vm_init()
2213 amdgpu_vm_bo_base_init(&vm->root, vm, root_bo); in amdgpu_vm_init()
2218 r = amdgpu_vm_pt_clear(adev, vm, root, false); in amdgpu_vm_init()
2222 amdgpu_bo_unreserve(vm->root.bo); in amdgpu_vm_init()
2228 amdgpu_vm_pt_free_root(adev, vm); in amdgpu_vm_init()
2229 amdgpu_bo_unreserve(vm->root.bo); in amdgpu_vm_init()
2233 dma_fence_put(vm->last_tlb_flush); in amdgpu_vm_init()
2234 dma_fence_put(vm->last_unlocked); in amdgpu_vm_init()
2235 amdgpu_vm_fini_entities(vm); in amdgpu_vm_init()
2241 * amdgpu_vm_make_compute - Turn a GFX VM into a compute VM
2244 * @vm: requested vm
2249 * Changes the following VM parameters:
2259 int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) in amdgpu_vm_make_compute() argument
2264 r = amdgpu_bo_reserve(vm->root.bo, true); in amdgpu_vm_make_compute()
2271 if (pte_support_ats != vm->pte_support_ats) { in amdgpu_vm_make_compute()
2273 if (!amdgpu_vm_pt_is_root_clean(adev, vm)) { in amdgpu_vm_make_compute()
2278 vm->pte_support_ats = pte_support_ats; in amdgpu_vm_make_compute()
2279 r = amdgpu_vm_pt_clear(adev, vm, to_amdgpu_bo_vm(vm->root.bo), in amdgpu_vm_make_compute()
2285 /* Update VM state */ in amdgpu_vm_make_compute()
2286 vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & in amdgpu_vm_make_compute()
2288 DRM_DEBUG_DRIVER("VM update mode is %s\n", in amdgpu_vm_make_compute()
2289 vm->use_cpu_for_update ? "CPU" : "SDMA"); in amdgpu_vm_make_compute()
2290 WARN_ONCE((vm->use_cpu_for_update && in amdgpu_vm_make_compute()
2292 "CPU update of VM recommended only for large BAR system\n"); in amdgpu_vm_make_compute()
2294 if (vm->use_cpu_for_update) { in amdgpu_vm_make_compute()
2296 r = amdgpu_bo_sync_wait(vm->root.bo, in amdgpu_vm_make_compute()
2301 vm->update_funcs = &amdgpu_vm_cpu_funcs; in amdgpu_vm_make_compute()
2302 r = amdgpu_vm_pt_map_tables(adev, vm); in amdgpu_vm_make_compute()
2307 vm->update_funcs = &amdgpu_vm_sdma_funcs; in amdgpu_vm_make_compute()
2310 dma_fence_put(vm->last_update); in amdgpu_vm_make_compute()
2311 vm->last_update = dma_fence_get_stub(); in amdgpu_vm_make_compute()
2312 vm->is_compute_context = true; in amdgpu_vm_make_compute()
2314 /* Free the shadow bo for compute VM */ in amdgpu_vm_make_compute()
2315 amdgpu_bo_unref(&to_amdgpu_bo_vm(vm->root.bo)->shadow); in amdgpu_vm_make_compute()
2320 amdgpu_bo_unreserve(vm->root.bo); in amdgpu_vm_make_compute()
2325 * amdgpu_vm_release_compute - release a compute vm
2327 * @vm: a vm turned into compute vm by calling amdgpu_vm_make_compute
2330 * pasid from vm. Compute should stop use of vm after this call.
2332 void amdgpu_vm_release_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) in amdgpu_vm_release_compute() argument
2334 amdgpu_vm_set_pasid(adev, vm, 0); in amdgpu_vm_release_compute()
2335 vm->is_compute_context = false; in amdgpu_vm_release_compute()
2339 * amdgpu_vm_fini - tear down a vm instance
2342 * @vm: requested vm
2344 * Tear down @vm.
2345 * Unbind the VM and remove all bos from the vm bo list
2347 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) in amdgpu_vm_fini() argument
2355 amdgpu_amdkfd_gpuvm_destroy_cb(adev, vm); in amdgpu_vm_fini()
2357 flush_work(&vm->pt_free_work); in amdgpu_vm_fini()
2359 root = amdgpu_bo_ref(vm->root.bo); in amdgpu_vm_fini()
2361 amdgpu_vm_set_pasid(adev, vm, 0); in amdgpu_vm_fini()
2362 dma_fence_wait(vm->last_unlocked, false); in amdgpu_vm_fini()
2363 dma_fence_put(vm->last_unlocked); in amdgpu_vm_fini()
2364 dma_fence_wait(vm->last_tlb_flush, false); in amdgpu_vm_fini()
2366 spin_lock_irqsave(vm->last_tlb_flush->lock, flags); in amdgpu_vm_fini()
2367 spin_unlock_irqrestore(vm->last_tlb_flush->lock, flags); in amdgpu_vm_fini()
2368 dma_fence_put(vm->last_tlb_flush); in amdgpu_vm_fini()
2370 list_for_each_entry_safe(mapping, tmp, &vm->freed, list) { in amdgpu_vm_fini()
2372 amdgpu_vm_prt_fini(adev, vm); in amdgpu_vm_fini()
2377 amdgpu_vm_free_mapping(adev, vm, mapping, NULL); in amdgpu_vm_fini()
2380 amdgpu_vm_pt_free_root(adev, vm); in amdgpu_vm_fini()
2383 WARN_ON(vm->root.bo); in amdgpu_vm_fini()
2385 amdgpu_vm_fini_entities(vm); in amdgpu_vm_fini()
2387 if (!RB_EMPTY_ROOT(&vm->va.rb_root)) { in amdgpu_vm_fini()
2388 dev_err(adev->dev, "still active bo inside vm\n"); in amdgpu_vm_fini()
2391 &vm->va.rb_root, rb) { in amdgpu_vm_fini()
2399 dma_fence_put(vm->last_update); in amdgpu_vm_fini()
2402 if (vm->reserved_vmid[i]) { in amdgpu_vm_fini()
2404 vm->reserved_vmid[i] = false; in amdgpu_vm_fini()
2411 * amdgpu_vm_manager_init - init the VM manager
2415 * Initialize the VM manager structures
2438 * Compute VM tables will be updated by CPU in amdgpu_vm_manager_init()
2443 * avoid using CPU for VM table updates in amdgpu_vm_manager_init()
2461 * amdgpu_vm_manager_fini - cleanup VM manager
2465 * Cleanup the VM manager and free resources.
2476 * amdgpu_vm_ioctl - Manages VMID reservation for vm hubs.
2498 if (!fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) { in amdgpu_vm_ioctl()
2500 fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = true; in amdgpu_vm_ioctl()
2505 if (fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) { in amdgpu_vm_ioctl()
2507 fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = false; in amdgpu_vm_ioctl()
2521 * @pasid: PASID identifier for VM
2527 struct amdgpu_vm *vm; in amdgpu_vm_get_task_info() local
2532 vm = xa_load(&adev->vm_manager.pasids, pasid); in amdgpu_vm_get_task_info()
2533 if (vm) in amdgpu_vm_get_task_info()
2534 *task_info = vm->task_info; in amdgpu_vm_get_task_info()
2542 * @vm: vm for which to set the info
2544 void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) in amdgpu_vm_set_task_info() argument
2546 if (vm->task_info.pid) in amdgpu_vm_set_task_info()
2549 vm->task_info.pid = current->pid; in amdgpu_vm_set_task_info()
2550 get_task_comm(vm->task_info.task_name, current); in amdgpu_vm_set_task_info()
2555 vm->task_info.tgid = current->group_leader->pid; in amdgpu_vm_set_task_info()
2556 get_task_comm(vm->task_info.process_name, current->group_leader); in amdgpu_vm_set_task_info()
2560 * amdgpu_vm_handle_fault - graceful handling of VM faults.
2562 * @pasid: PASID of the VM
2569 * Try to gracefully handle a VM fault. Return true if the fault was handled and
2580 struct amdgpu_vm *vm; in amdgpu_vm_handle_fault() local
2584 vm = xa_load(&adev->vm_manager.pasids, pasid); in amdgpu_vm_handle_fault()
2585 if (vm) { in amdgpu_vm_handle_fault()
2586 root = amdgpu_bo_ref(vm->root.bo); in amdgpu_vm_handle_fault()
2587 is_compute_context = vm->is_compute_context; in amdgpu_vm_handle_fault()
2608 /* Double check that the VM still exists */ in amdgpu_vm_handle_fault()
2610 vm = xa_load(&adev->vm_manager.pasids, pasid); in amdgpu_vm_handle_fault()
2611 if (vm && vm->root.bo != root) in amdgpu_vm_handle_fault()
2612 vm = NULL; in amdgpu_vm_handle_fault()
2614 if (!vm) in amdgpu_vm_handle_fault()
2643 r = amdgpu_vm_update_range(adev, vm, true, false, false, NULL, addr, in amdgpu_vm_handle_fault()
2648 r = amdgpu_vm_update_pdes(adev, vm, true); in amdgpu_vm_handle_fault()
2663 * amdgpu_debugfs_vm_bo_info - print BO info for the VM
2665 * @vm: Requested VM for printing BO info
2668 * Print BO information in debugfs file for the VM
2670 void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m) in amdgpu_debugfs_vm_bo_info() argument
2687 spin_lock(&vm->status_lock); in amdgpu_debugfs_vm_bo_info()
2689 list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2698 list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2707 list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2716 list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2725 list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2734 list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status) { in amdgpu_debugfs_vm_bo_info()
2739 spin_unlock(&vm->status_lock); in amdgpu_debugfs_vm_bo_info()