| @@ -189,14 +189,18 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · 188 unmodified lines |
| 189 | spin_unlock(&glob->lru_lock); | 189 | spin_unlock(&glob->lru_lock); |
| 190 | } | 190 | } |
| 191 | | 191 | |
| 192 | if (vm->use_cpu_for_update) { | 192 | if (bo->tbo.type == ttm_bo_type_kernel && |
| | 193 | vm->use_cpu_for_update) { |
| 193 | r = amdgpu_bo_kmap(bo, NULL); | 194 | r = amdgpu_bo_kmap(bo, NULL); |
| 194 | if (r) | 195 | if (r) |
| 195 | return r; | 196 | return r; |
| 196 | } | 197 | } |
| 197 | | 198 | |
| 198 | spin_lock(&vm->status_lock); | 199 | spin_lock(&vm->status_lock); |
| 199 | list_move(&bo_base->vm_status, &vm->relocated); | 200 | if (bo->tbo.type != ttm_bo_type_kernel) |
| | 201 | list_move(&bo_base->vm_status, &vm->moved); |
| | 202 | else |
| | 203 | list_move(&bo_base->vm_status, &vm->relocated); |
| 200 | } | 204 | } |
| 201 | spin_unlock(&vm->status_lock); | 205 | spin_unlock(&vm->status_lock); |
| 202 | | 206 | |
| @@ -1985,20 +1989,23 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev, · 1782 unmodified lines |
| 1985 | } | 1989 | } |
| 1986 | | 1990 | |
| 1987 | /** | 1991 | /** |
| 1988 | * amdgpu_vm_clear_moved - clear moved BOs in the PT | 1992 | * amdgpu_vm_handle_moved - handle moved BOs in the PT |
| 1989 | * | 1993 | * |
| 1990 | * @adev: amdgpu_device pointer | 1994 | * @adev: amdgpu_device pointer |
| 1991 | * @vm: requested vm | 1995 | * @vm: requested vm |
| | 1996 | * @sync: sync object to add fences to |
| 1992 | * | 1997 | * |
| 1993 | * Make sure all moved BOs are cleared in the PT. | 1998 | * Make sure all BOs which are moved are updated in the PTs. |
| 1994 | * Returns 0 for success. | 1999 | * Returns 0 for success. |
| 1995 | * | 2000 | * |
| 1996 | * PTs have to be reserved and mutex must be locked! | 2001 | * PTs have to be reserved! |
| 1997 | */ | 2002 | */ |
| 1998 | int amdgpu_vm_clear_moved(struct amdgpu_device *adev, struct amdgpu_vm *vm, | 2003 | int amdgpu_vm_handle_moved(struct amdgpu_device *adev, |
| 1999 | struct amdgpu_sync *sync) | 2004 | struct amdgpu_vm *vm, |
| | 2005 | struct amdgpu_sync *sync) |
| 2000 | { | 2006 | { |
| 2001 | struct amdgpu_bo_va *bo_va = NULL; | 2007 | struct amdgpu_bo_va *bo_va = NULL; |
| | 2008 | bool clear; |
| 2002 | int r = 0; | 2009 | int r = 0; |
| 2003 | | 2010 | |
| 2004 | spin_lock(&vm->status_lock); | 2011 | spin_lock(&vm->status_lock); |
| @@ -2007,7 +2014,10 @@ int amdgpu_vm_clear_moved(struct amdgpu_device *adev, struct amdgpu_vm *vm, · 2 unmodified lines |
| 2007 | struct amdgpu_bo_va, base.vm_status); | 2014 | struct amdgpu_bo_va, base.vm_status); |
| 2008 | spin_unlock(&vm->status_lock); | 2015 | spin_unlock(&vm->status_lock); |
| 2009 | | 2016 | |
| 2010 | r = amdgpu_vm_bo_update(adev, bo_va, true); | 2017 | /* Per VM BOs never need to bo cleared in the page tables */ |
| | 2018 | clear = bo_va->base.bo->tbo.resv != vm->root.base.bo->tbo.resv; |
| | 2019 | |
| | 2020 | r = amdgpu_vm_bo_update(adev, bo_va, clear); |
| 2011 | if (r) | 2021 | if (r) |
| 2012 | return r; | 2022 | return r; |
| 2013 | | 2023 | |
| @@ -2059,6 +2069,37 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · 45 unmodified lines |
| 2059 | return bo_va; | 2069 | return bo_va; |
| 2060 | } | 2070 | } |
| 2061 | | 2071 | |
| | 2072 | |
| | 2073 | /** |
| | 2074 | * amdgpu_vm_bo_insert_mapping - insert a new mapping |
| | 2075 | * |
| | 2076 | * @adev: amdgpu_device pointer |
| | 2077 | * @bo_va: bo_va to store the address |
| | 2078 | * @mapping: the mapping to insert |
| | 2079 | * |
| | 2080 | * Insert a new mapping into all structures. |
| | 2081 | */ |
| | 2082 | static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, |
| | 2083 | struct amdgpu_bo_va *bo_va, |
| | 2084 | struct amdgpu_bo_va_mapping *mapping) |
| | 2085 | { |
| | 2086 | struct amdgpu_vm *vm = bo_va->base.vm; |
| | 2087 | struct amdgpu_bo *bo = bo_va->base.bo; |
| | 2088 | |
| | 2089 | list_add(&mapping->list, &bo_va->invalids); |
| | 2090 | amdgpu_vm_it_insert(mapping, &vm->va); |
| | 2091 | |
| | 2092 | if (mapping->flags & AMDGPU_PTE_PRT) |
| | 2093 | amdgpu_vm_prt_get(adev); |
| | 2094 | |
| | 2095 | if (bo && bo->tbo.resv == vm->root.base.bo->tbo.resv) { |
| | 2096 | spin_lock(&vm->status_lock); |
| | 2097 | list_move(&bo_va->base.vm_status, &vm->moved); |
| | 2098 | spin_unlock(&vm->status_lock); |
| | 2099 | } |
| | 2100 | trace_amdgpu_vm_bo_map(bo_va, mapping); |
| | 2101 | } |
| | 2102 | |
| 2062 | /** | 2103 | /** |
| 2063 | * amdgpu_vm_bo_map - map bo inside a vm | 2104 | * amdgpu_vm_bo_map - map bo inside a vm |
| 2064 | * | 2105 | * |
| @@ -2110,18 +2151,12 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, · 45 unmodified lines |
| 2110 | if (!mapping) | 2151 | if (!mapping) |
| 2111 | return -ENOMEM; | 2152 | return -ENOMEM; |
| 2112 | | 2153 | |
| 2113 | INIT_LIST_HEAD(&mapping->list); | | |
| 2114 | mapping->start = saddr; | 2154 | mapping->start = saddr; |
| 2115 | mapping->last = eaddr; | 2155 | mapping->last = eaddr; |
| 2116 | mapping->offset = offset; | 2156 | mapping->offset = offset; |
| 2117 | mapping->flags = flags; | 2157 | mapping->flags = flags; |
| 2118 | | 2158 | |
| 2119 | list_add(&mapping->list, &bo_va->invalids); | 2159 | amdgpu_vm_bo_insert_map(adev, bo_va, mapping); |
| 2120 | amdgpu_vm_it_insert(mapping, &vm->va); | | |
| 2121 | | | |
| 2122 | if (flags & AMDGPU_PTE_PRT) | | |
| 2123 | amdgpu_vm_prt_get(adev); | | |
| 2124 | trace_amdgpu_vm_bo_map(bo_va, mapping); | | |
| 2125 | | 2160 | |
| 2126 | return 0; | 2161 | return 0; |
| 2127 | } | 2162 | } |
| @@ -2148,7 +2183,6 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 20 unmodified lines |
| 2148 | { | 2183 | { |
| 2149 | struct amdgpu_bo_va_mapping *mapping; | 2184 | struct amdgpu_bo_va_mapping *mapping; |
| 2150 | struct amdgpu_bo *bo = bo_va->base.bo; | 2185 | struct amdgpu_bo *bo = bo_va->base.bo; |
| 2151 | struct amdgpu_vm *vm = bo_va->base.vm; | | |
| 2152 | uint64_t eaddr; | 2186 | uint64_t eaddr; |
| 2153 | int r; | 2187 | int r; |
| 2154 | | 2188 | |
| @@ -2182,12 +2216,7 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 27 unmodified lines |
| 2182 | mapping->offset = offset; | 2216 | mapping->offset = offset; |
| 2183 | mapping->flags = flags; | 2217 | mapping->flags = flags; |
| 2184 | | 2218 | |
| 2185 | list_add(&mapping->list, &bo_va->invalids); | 2219 | amdgpu_vm_bo_insert_map(adev, bo_va, mapping); |
| 2186 | amdgpu_vm_it_insert(mapping, &vm->va); | | |
| 2187 | | | |
| 2188 | if (flags & AMDGPU_PTE_PRT) | | |
| 2189 | amdgpu_vm_prt_get(adev); | | |
| 2190 | trace_amdgpu_vm_bo_map(bo_va, mapping); | | |
| 2191 | | 2220 | |
| 2192 | return 0; | 2221 | return 0; |
| 2193 | } | 2222 | } |
| @@ -2402,7 +2431,11 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · 208 unmodified lines |
| 2402 | bo_base->moved = true; | 2431 | bo_base->moved = true; |
| 2403 | if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { | 2432 | if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { |
| 2404 | spin_lock(&bo_base->vm->status_lock); | 2433 | spin_lock(&bo_base->vm->status_lock); |
| 2405 | list_move(&bo_base->vm_status, &vm->evicted); | 2434 | if (bo->tbo.type == ttm_bo_type_kernel) |
| | 2435 | list_move(&bo_base->vm_status, &vm->evicted); |
| | 2436 | else |
| | 2437 | list_move_tail(&bo_base->vm_status, |
| | 2438 | &vm->evicted); |
| 2406 | spin_unlock(&bo_base->vm->status_lock); | 2439 | spin_unlock(&bo_base->vm->status_lock); |
| 2407 | continue; | 2440 | continue; |
| 2408 | } | 2441 | } |