Lines Matching refs:mem
72 struct kgd_mem *mem) in kfd_mem_is_attached() argument
76 list_for_each_entry(entry, &mem->attachments, list) in kfd_mem_is_attached()
90 uint64_t mem; in amdgpu_amdkfd_gpuvm_init_mem_limits() local
93 mem = si.freeram - si.freehigh; in amdgpu_amdkfd_gpuvm_init_mem_limits()
94 mem *= si.mem_unit; in amdgpu_amdkfd_gpuvm_init_mem_limits()
97 kfd_mem_limit.max_system_mem_limit = mem - (mem >> 4); in amdgpu_amdkfd_gpuvm_init_mem_limits()
98 kfd_mem_limit.max_ttm_mem_limit = (mem >> 1) - (mem >> 3); in amdgpu_amdkfd_gpuvm_init_mem_limits()
251 struct kgd_mem *mem, struct amdgpu_bo **bo_out) in create_dmamap_sg_bo() argument
256 ret = amdgpu_bo_reserve(mem->bo, false); in create_dmamap_sg_bo()
261 ret = amdgpu_gem_object_create(adev, mem->bo->tbo.base.size, align, in create_dmamap_sg_bo()
263 ttm_bo_type_sg, mem->bo->tbo.base.resv, &gem_obj); in create_dmamap_sg_bo()
265 amdgpu_bo_unreserve(mem->bo); in create_dmamap_sg_bo()
273 (*bo_out)->parent = amdgpu_bo_ref(mem->bo); in create_dmamap_sg_bo()
404 static uint64_t get_pte_flags(struct amdgpu_device *adev, struct kgd_mem *mem) in get_pte_flags() argument
406 struct amdgpu_device *bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev); in get_pte_flags()
407 bool coherent = mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_COHERENT; in get_pte_flags()
408 bool uncached = mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_UNCACHED; in get_pte_flags()
414 if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE) in get_pte_flags()
416 if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE) in get_pte_flags()
422 if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) { in get_pte_flags()
455 if (!(mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)) in get_pte_flags()
498 kfd_mem_dmamap_userptr(struct kgd_mem *mem, in kfd_mem_dmamap_userptr() argument
502 mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? in kfd_mem_dmamap_userptr()
507 struct ttm_tt *src_ttm = mem->bo->tbo.ttm; in kfd_mem_dmamap_userptr()
588 kfd_mem_dmamap_sg_bo(struct kgd_mem *mem, in kfd_mem_dmamap_sg_bo() argument
601 mmio = (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP); in kfd_mem_dmamap_sg_bo()
607 dir = mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? in kfd_mem_dmamap_sg_bo()
609 dma_addr = mem->bo->tbo.sg->sgl->dma_address; in kfd_mem_dmamap_sg_bo()
610 pr_debug("%d BO size: %d\n", mmio, mem->bo->tbo.sg->sgl->length); in kfd_mem_dmamap_sg_bo()
613 mem->bo->tbo.sg->sgl->length, dir, DMA_ATTR_SKIP_CPU_SYNC); in kfd_mem_dmamap_sg_bo()
619 ttm->sg = create_sg_table(dma_addr, mem->bo->tbo.sg->sgl->length); in kfd_mem_dmamap_sg_bo()
637 dma_unmap_resource(adev->dev, dma_addr, mem->bo->tbo.sg->sgl->length, in kfd_mem_dmamap_sg_bo()
643 kfd_mem_dmamap_attachment(struct kgd_mem *mem, in kfd_mem_dmamap_attachment() argument
650 return kfd_mem_dmamap_userptr(mem, attachment); in kfd_mem_dmamap_attachment()
654 return kfd_mem_dmamap_sg_bo(mem, attachment); in kfd_mem_dmamap_attachment()
662 kfd_mem_dmaunmap_userptr(struct kgd_mem *mem, in kfd_mem_dmaunmap_userptr() argument
666 mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? in kfd_mem_dmaunmap_userptr()
712 kfd_mem_dmaunmap_sg_bo(struct kgd_mem *mem, in kfd_mem_dmaunmap_sg_bo() argument
729 dir = mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? in kfd_mem_dmaunmap_sg_bo()
740 kfd_mem_dmaunmap_attachment(struct kgd_mem *mem, in kfd_mem_dmaunmap_attachment() argument
747 kfd_mem_dmaunmap_userptr(mem, attachment); in kfd_mem_dmaunmap_attachment()
753 kfd_mem_dmaunmap_sg_bo(mem, attachment); in kfd_mem_dmaunmap_attachment()
761 kfd_mem_attach_dmabuf(struct amdgpu_device *adev, struct kgd_mem *mem, in kfd_mem_attach_dmabuf() argument
767 if (!mem->dmabuf) { in kfd_mem_attach_dmabuf()
768 mem->dmabuf = amdgpu_gem_prime_export(&mem->bo->tbo.base, in kfd_mem_attach_dmabuf()
769 mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? in kfd_mem_attach_dmabuf()
771 if (IS_ERR(mem->dmabuf)) { in kfd_mem_attach_dmabuf()
772 ret = PTR_ERR(mem->dmabuf); in kfd_mem_attach_dmabuf()
773 mem->dmabuf = NULL; in kfd_mem_attach_dmabuf()
778 gobj = amdgpu_gem_prime_import(adev_to_drm(adev), mem->dmabuf); in kfd_mem_attach_dmabuf()
801 static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, in kfd_mem_attach() argument
804 struct amdgpu_device *bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev); in kfd_mem_attach()
805 unsigned long bo_size = mem->bo->tbo.base.size; in kfd_mem_attach()
806 uint64_t va = mem->va; in kfd_mem_attach()
826 ((mem->domain == AMDGPU_GEM_DOMAIN_VRAM) || in kfd_mem_attach()
827 (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL) || in kfd_mem_attach()
828 (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP))) { in kfd_mem_attach()
829 if (mem->domain == AMDGPU_GEM_DOMAIN_VRAM) in kfd_mem_attach()
845 if ((adev == bo_adev && !(mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) || in kfd_mem_attach()
846 (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) && adev->ram_is_direct_mapped) || in kfd_mem_attach()
853 bo[i] = mem->bo; in kfd_mem_attach()
860 } else if (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)) { in kfd_mem_attach()
863 ret = create_dmamap_sg_bo(adev, mem, &bo[i]); in kfd_mem_attach()
867 } else if (mem->bo->tbo.type == ttm_bo_type_sg) { in kfd_mem_attach()
868 WARN_ONCE(!(mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL || in kfd_mem_attach()
869 mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP), in kfd_mem_attach()
872 ret = create_dmamap_sg_bo(adev, mem, &bo[i]); in kfd_mem_attach()
876 } else if (mem->domain == AMDGPU_GEM_DOMAIN_GTT || in kfd_mem_attach()
877 mem->domain == AMDGPU_GEM_DOMAIN_VRAM) { in kfd_mem_attach()
879 ret = kfd_mem_attach_dmabuf(adev, mem, &bo[i]); in kfd_mem_attach()
904 attachment[i]->pte_flags = get_pte_flags(adev, mem); in kfd_mem_attach()
906 list_add(&attachment[i]->list, &mem->attachments); in kfd_mem_attach()
942 static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem, in add_kgd_mem_to_kfd_bo_list() argument
946 struct ttm_validate_buffer *entry = &mem->validate_list; in add_kgd_mem_to_kfd_bo_list()
947 struct amdgpu_bo *bo = mem->bo; in add_kgd_mem_to_kfd_bo_list()
960 static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, in remove_kgd_mem_from_kfd_bo_list() argument
965 bo_list_entry = &mem->validate_list; in remove_kgd_mem_from_kfd_bo_list()
983 static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr, in init_user_pages() argument
986 struct amdkfd_process_info *process_info = mem->process_info; in init_user_pages()
987 struct amdgpu_bo *bo = mem->bo; in init_user_pages()
1014 atomic_inc(&mem->invalid); in init_user_pages()
1030 amdgpu_bo_placement_from_domain(bo, mem->domain); in init_user_pages()
1073 static int reserve_bo_and_vm(struct kgd_mem *mem, in reserve_bo_and_vm() argument
1077 struct amdgpu_bo *bo = mem->bo; in reserve_bo_and_vm()
1084 ctx->sync = &mem->sync; in reserve_bo_and_vm()
1123 static int reserve_bo_and_cond_vms(struct kgd_mem *mem, in reserve_bo_and_cond_vms() argument
1127 struct amdgpu_bo *bo = mem->bo; in reserve_bo_and_cond_vms()
1135 ctx->sync = &mem->sync; in reserve_bo_and_cond_vms()
1140 list_for_each_entry(entry, &mem->attachments, list) { in reserve_bo_and_cond_vms()
1162 list_for_each_entry(entry, &mem->attachments, list) { in reserve_bo_and_cond_vms()
1216 static void unmap_bo_from_gpuvm(struct kgd_mem *mem, in unmap_bo_from_gpuvm() argument
1230 kfd_mem_dmaunmap_attachment(mem, entry); in unmap_bo_from_gpuvm()
1233 static int update_gpuvm_pte(struct kgd_mem *mem, in update_gpuvm_pte() argument
1241 ret = kfd_mem_dmamap_attachment(mem, entry); in update_gpuvm_pte()
1255 static int map_bo_to_gpuvm(struct kgd_mem *mem, in map_bo_to_gpuvm() argument
1275 ret = update_gpuvm_pte(mem, entry, sync); in map_bo_to_gpuvm()
1284 unmap_bo_from_gpuvm(mem, entry, sync); in map_bo_to_gpuvm()
1646 void *drm_priv, struct kgd_mem **mem, in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu() argument
1693 *mem = kzalloc(sizeof(struct kgd_mem), GFP_KERNEL); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1694 if (!*mem) { in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1698 INIT_LIST_HEAD(&(*mem)->attachments); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1699 mutex_init(&(*mem)->lock); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1700 (*mem)->aql_queue = !!(flags & KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1706 if ((*mem)->aql_queue) in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1710 (*mem)->alloc_flags = flags; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1712 amdgpu_sync_create(&(*mem)->sync); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1721 va, (*mem)->aql_queue ? size << 1 : size, domain_string(alloc_domain)); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1740 bo->kfd_bo = *mem; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1741 (*mem)->bo = bo; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1745 (*mem)->va = va; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1746 (*mem)->domain = domain; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1747 (*mem)->mapped_to_gpu_memory = 0; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1748 (*mem)->process_info = avm->process_info; in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1749 add_kgd_mem_to_kfd_bo_list(*mem, avm->process_info, user_addr); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1753 ret = init_user_pages(*mem, user_addr, criu_resume); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1774 remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1782 mutex_destroy(&(*mem)->lock); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1786 kfree(*mem); in amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()
1796 struct amdgpu_device *adev, struct kgd_mem *mem, void *drm_priv, in amdgpu_amdkfd_gpuvm_free_memory_of_gpu() argument
1799 struct amdkfd_process_info *process_info = mem->process_info; in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1800 unsigned long bo_size = mem->bo->tbo.base.size; in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1801 bool use_release_notifier = (mem->bo->kfd_bo == mem); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1809 mutex_lock(&mem->lock); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1812 if (mem->alloc_flags & in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1815 amdgpu_amdkfd_gpuvm_unpin_bo(mem->bo); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1818 mapped_to_gpu_memory = mem->mapped_to_gpu_memory; in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1819 is_imported = mem->is_imported; in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1820 mutex_unlock(&mem->lock); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1827 mem->va, bo_size); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1832 bo_list_entry = &mem->validate_list; in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1838 amdgpu_mn_unregister(mem->bo); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1840 ret = reserve_bo_and_cond_vms(mem, NULL, BO_VM_ALL, &ctx); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1848 amdgpu_amdkfd_remove_eviction_fence(mem->bo, in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1850 pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va, in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1851 mem->va + bo_size * (1 + mem->aql_queue)); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1854 list_for_each_entry_safe(entry, tmp, &mem->attachments, list) in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1860 amdgpu_sync_free(&mem->sync); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1865 if (mem->bo->tbo.sg) { in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1866 sg_free_table(mem->bo->tbo.sg); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1867 kfree(mem->bo->tbo.sg); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1874 if ((mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM) && in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1882 drm_vma_node_revoke(&mem->bo->tbo.base.vma_node, drm_priv); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1883 if (mem->dmabuf) in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1884 dma_buf_put(mem->dmabuf); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1885 mutex_destroy(&mem->lock); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1891 drm_gem_object_put(&mem->bo->tbo.base); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1898 kfree(mem); in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
1904 struct amdgpu_device *adev, struct kgd_mem *mem, in amdgpu_amdkfd_gpuvm_map_memory_to_gpu() argument
1916 bo = mem->bo; in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1926 mutex_lock(&mem->process_info->lock); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1934 is_invalid_userptr = atomic_read(&mem->invalid); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1938 mutex_lock(&mem->lock); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1940 domain = mem->domain; in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1944 mem->va, in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1945 mem->va + bo_size * (1 + mem->aql_queue), in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1948 if (!kfd_mem_is_attached(avm, mem)) { in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1949 ret = kfd_mem_attach(adev, mem, avm, mem->aql_queue); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1954 ret = reserve_bo_and_vm(mem, avm, &ctx); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1971 if (mem->mapped_to_gpu_memory == 0 && in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1984 list_for_each_entry(entry, &mem->attachments, list) { in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
1991 ret = map_bo_to_gpuvm(mem, entry, ctx.sync, in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
2005 mem->mapped_to_gpu_memory++; in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
2007 mem->mapped_to_gpu_memory); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
2021 mutex_unlock(&mem->process_info->lock); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
2022 mutex_unlock(&mem->lock); in amdgpu_amdkfd_gpuvm_map_memory_to_gpu()
2027 struct amdgpu_device *adev, struct kgd_mem *mem, void *drm_priv) in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu() argument
2031 unsigned long bo_size = mem->bo->tbo.base.size; in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2036 mutex_lock(&mem->lock); in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2038 ret = reserve_bo_and_cond_vms(mem, avm, BO_VM_MAPPED, &ctx); in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2052 mem->va, in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2053 mem->va + bo_size * (1 + mem->aql_queue), in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2056 list_for_each_entry(entry, &mem->attachments, list) { in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2063 unmap_bo_from_gpuvm(mem, entry, ctx.sync); in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2066 mem->mapped_to_gpu_memory--; in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2068 mem->mapped_to_gpu_memory); in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2074 if (mem->mapped_to_gpu_memory == 0 && in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2075 !amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) && in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2076 !mem->bo->tbo.pin_count) in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2077 amdgpu_amdkfd_remove_eviction_fence(mem->bo, in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2083 mutex_unlock(&mem->lock); in amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu()
2088 struct amdgpu_device *adev, struct kgd_mem *mem, bool intr) in amdgpu_amdkfd_gpuvm_sync_memory() argument
2095 mutex_lock(&mem->lock); in amdgpu_amdkfd_gpuvm_sync_memory()
2096 amdgpu_sync_clone(&mem->sync, &sync); in amdgpu_amdkfd_gpuvm_sync_memory()
2097 mutex_unlock(&mem->lock); in amdgpu_amdkfd_gpuvm_sync_memory()
2165 int amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel(struct kgd_mem *mem, in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel() argument
2169 struct amdgpu_bo *bo = mem->bo; in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel()
2176 mutex_lock(&mem->process_info->lock); in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel()
2197 bo, mem->process_info->eviction_fence); in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel()
2204 mutex_unlock(&mem->process_info->lock); in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel()
2212 mutex_unlock(&mem->process_info->lock); in amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel()
2225 void amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel(struct kgd_mem *mem) in amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel() argument
2227 struct amdgpu_bo *bo = mem->bo; in amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel()
2236 struct kfd_vm_fault_info *mem) in amdgpu_amdkfd_gpuvm_get_vm_fault_info() argument
2239 *mem = *adev->gmc.vm_fault_info; in amdgpu_amdkfd_gpuvm_get_vm_fault_info()
2249 struct kgd_mem **mem, uint64_t *size, in amdgpu_amdkfd_gpuvm_import_dmabuf() argument
2272 *mem = kzalloc(sizeof(struct kgd_mem), GFP_KERNEL); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2273 if (!*mem) in amdgpu_amdkfd_gpuvm_import_dmabuf()
2278 kfree(*mem); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2288 INIT_LIST_HEAD(&(*mem)->attachments); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2289 mutex_init(&(*mem)->lock); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2291 (*mem)->alloc_flags = in amdgpu_amdkfd_gpuvm_import_dmabuf()
2298 (*mem)->bo = bo; in amdgpu_amdkfd_gpuvm_import_dmabuf()
2299 (*mem)->va = va; in amdgpu_amdkfd_gpuvm_import_dmabuf()
2300 (*mem)->domain = (bo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) ? in amdgpu_amdkfd_gpuvm_import_dmabuf()
2302 (*mem)->mapped_to_gpu_memory = 0; in amdgpu_amdkfd_gpuvm_import_dmabuf()
2303 (*mem)->process_info = avm->process_info; in amdgpu_amdkfd_gpuvm_import_dmabuf()
2304 add_kgd_mem_to_kfd_bo_list(*mem, avm->process_info, false); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2305 amdgpu_sync_create(&(*mem)->sync); in amdgpu_amdkfd_gpuvm_import_dmabuf()
2306 (*mem)->is_imported = true; in amdgpu_amdkfd_gpuvm_import_dmabuf()
2322 int amdgpu_amdkfd_evict_userptr(struct kgd_mem *mem, in amdgpu_amdkfd_evict_userptr() argument
2325 struct amdkfd_process_info *process_info = mem->process_info; in amdgpu_amdkfd_evict_userptr()
2333 atomic_inc(&mem->invalid); in amdgpu_amdkfd_evict_userptr()
2356 struct kgd_mem *mem, *tmp_mem; in update_invalid_user_pages() local
2364 list_for_each_entry_safe(mem, tmp_mem, in update_invalid_user_pages()
2367 if (!atomic_read(&mem->invalid)) in update_invalid_user_pages()
2370 bo = mem->bo; in update_invalid_user_pages()
2383 list_move_tail(&mem->validate_list.head, in update_invalid_user_pages()
2391 list_for_each_entry(mem, &process_info->userptr_inval_list, in update_invalid_user_pages()
2395 invalid = atomic_read(&mem->invalid); in update_invalid_user_pages()
2402 bo = mem->bo; in update_invalid_user_pages()
2431 if (atomic_cmpxchg(&mem->invalid, invalid, 0) != invalid) in update_invalid_user_pages()
2452 struct kgd_mem *mem, *tmp_mem; in validate_invalid_user_pages() local
2476 list_for_each_entry(mem, &process_info->userptr_inval_list, in validate_invalid_user_pages()
2478 list_add_tail(&mem->resv_list.head, &resv_list); in validate_invalid_user_pages()
2479 mem->resv_list.bo = mem->validate_list.bo; in validate_invalid_user_pages()
2480 mem->resv_list.num_shared = mem->validate_list.num_shared; in validate_invalid_user_pages()
2496 list_for_each_entry_safe(mem, tmp_mem, in validate_invalid_user_pages()
2501 bo = mem->bo; in validate_invalid_user_pages()
2505 amdgpu_bo_placement_from_domain(bo, mem->domain); in validate_invalid_user_pages()
2513 list_move_tail(&mem->validate_list.head, in validate_invalid_user_pages()
2522 list_for_each_entry(attachment, &mem->attachments, list) { in validate_invalid_user_pages()
2526 kfd_mem_dmaunmap_attachment(mem, attachment); in validate_invalid_user_pages()
2527 ret = update_gpuvm_pte(mem, attachment, &sync); in validate_invalid_user_pages()
2531 atomic_inc(&mem->invalid); in validate_invalid_user_pages()
2649 struct kgd_mem *mem; in amdgpu_amdkfd_gpuvm_restore_process_bos() local
2677 list_for_each_entry(mem, &process_info->kfd_bo_list, in amdgpu_amdkfd_gpuvm_restore_process_bos()
2680 list_add_tail(&mem->resv_list.head, &ctx.list); in amdgpu_amdkfd_gpuvm_restore_process_bos()
2681 mem->resv_list.bo = mem->validate_list.bo; in amdgpu_amdkfd_gpuvm_restore_process_bos()
2682 mem->resv_list.num_shared = mem->validate_list.num_shared; in amdgpu_amdkfd_gpuvm_restore_process_bos()
2706 list_for_each_entry(mem, &process_info->kfd_bo_list, in amdgpu_amdkfd_gpuvm_restore_process_bos()
2709 struct amdgpu_bo *bo = mem->bo; in amdgpu_amdkfd_gpuvm_restore_process_bos()
2710 uint32_t domain = mem->domain; in amdgpu_amdkfd_gpuvm_restore_process_bos()
2736 list_for_each_entry(attachment, &mem->attachments, list) { in amdgpu_amdkfd_gpuvm_restore_process_bos()
2743 kfd_mem_dmaunmap_attachment(mem, attachment); in amdgpu_amdkfd_gpuvm_restore_process_bos()
2744 ret = update_gpuvm_pte(mem, attachment, &sync_obj); in amdgpu_amdkfd_gpuvm_restore_process_bos()
2783 list_for_each_entry(mem, &process_info->kfd_bo_list, in amdgpu_amdkfd_gpuvm_restore_process_bos()
2785 if (mem->bo->tbo.pin_count) in amdgpu_amdkfd_gpuvm_restore_process_bos()
2788 dma_resv_add_fence(mem->bo->tbo.base.resv, in amdgpu_amdkfd_gpuvm_restore_process_bos()
2811 int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem) in amdgpu_amdkfd_add_gws_to_process() argument
2820 *mem = kzalloc(sizeof(struct kgd_mem), GFP_KERNEL); in amdgpu_amdkfd_add_gws_to_process()
2821 if (!*mem) in amdgpu_amdkfd_add_gws_to_process()
2824 mutex_init(&(*mem)->lock); in amdgpu_amdkfd_add_gws_to_process()
2825 INIT_LIST_HEAD(&(*mem)->attachments); in amdgpu_amdkfd_add_gws_to_process()
2826 (*mem)->bo = amdgpu_bo_ref(gws_bo); in amdgpu_amdkfd_add_gws_to_process()
2827 (*mem)->domain = AMDGPU_GEM_DOMAIN_GWS; in amdgpu_amdkfd_add_gws_to_process()
2828 (*mem)->process_info = process_info; in amdgpu_amdkfd_add_gws_to_process()
2829 add_kgd_mem_to_kfd_bo_list(*mem, process_info, false); in amdgpu_amdkfd_add_gws_to_process()
2830 amdgpu_sync_create(&(*mem)->sync); in amdgpu_amdkfd_add_gws_to_process()
2834 mutex_lock(&(*mem)->process_info->lock); in amdgpu_amdkfd_add_gws_to_process()
2857 mutex_unlock(&(*mem)->process_info->lock); in amdgpu_amdkfd_add_gws_to_process()
2865 mutex_unlock(&(*mem)->process_info->lock); in amdgpu_amdkfd_add_gws_to_process()
2866 amdgpu_sync_free(&(*mem)->sync); in amdgpu_amdkfd_add_gws_to_process()
2867 remove_kgd_mem_from_kfd_bo_list(*mem, process_info); in amdgpu_amdkfd_add_gws_to_process()
2869 mutex_destroy(&(*mem)->lock); in amdgpu_amdkfd_add_gws_to_process()
2870 kfree(*mem); in amdgpu_amdkfd_add_gws_to_process()
2871 *mem = NULL; in amdgpu_amdkfd_add_gws_to_process()
2875 int amdgpu_amdkfd_remove_gws_from_process(void *info, void *mem) in amdgpu_amdkfd_remove_gws_from_process() argument
2879 struct kgd_mem *kgd_mem = (struct kgd_mem *)mem; in amdgpu_amdkfd_remove_gws_from_process()
2899 kfree(mem); in amdgpu_amdkfd_remove_gws_from_process()
2923 bool amdgpu_amdkfd_bo_mapped_to_dev(struct amdgpu_device *adev, struct kgd_mem *mem) in amdgpu_amdkfd_bo_mapped_to_dev() argument
2927 list_for_each_entry(entry, &mem->attachments, list) { in amdgpu_amdkfd_bo_mapped_to_dev()