Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
| 28 | #include <drm/drmP.h> |
| 29 | #include <drm/amdgpu_drm.h> |
| 30 | #include "amdgpu.h" |
| 31 | #include "amdgpu_trace.h" |
| 32 | |
| 33 | /* |
| 34 | * GPUVM |
| 35 | * GPUVM is similar to the legacy gart on older asics, however |
| 36 | * rather than there being a single global gart table |
| 37 | * for the entire GPU, there are multiple VM page tables active |
| 38 | * at any given time. The VM page tables can contain a mix |
| 39 | * vram pages and system memory pages and system memory pages |
| 40 | * can be mapped as snooped (cached system pages) or unsnooped |
| 41 | * (uncached system pages). |
| 42 | * Each VM has an ID associated with it and there is a page table |
| 43 | * associated with each VMID. When execting a command buffer, |
| 44 | * the kernel tells the the ring what VMID to use for that command |
| 45 | * buffer. VMIDs are allocated dynamically as commands are submitted. |
| 46 | * The userspace drivers maintain their own address space and the kernel |
| 47 | * sets up their pages tables accordingly when they submit their |
| 48 | * command buffers and a VMID is assigned. |
| 49 | * Cayman/Trinity support up to 8 active VMs at any given time; |
| 50 | * SI supports 16. |
| 51 | */ |
| 52 | |
| 53 | /** |
| 54 | * amdgpu_vm_num_pde - return the number of page directory entries |
| 55 | * |
| 56 | * @adev: amdgpu_device pointer |
| 57 | * |
| 58 | * Calculate the number of page directory entries (cayman+). |
| 59 | */ |
| 60 | static unsigned amdgpu_vm_num_pdes(struct amdgpu_device *adev) |
| 61 | { |
| 62 | return adev->vm_manager.max_pfn >> amdgpu_vm_block_size; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * amdgpu_vm_directory_size - returns the size of the page directory in bytes |
| 67 | * |
| 68 | * @adev: amdgpu_device pointer |
| 69 | * |
| 70 | * Calculate the size of the page directory in bytes (cayman+). |
| 71 | */ |
| 72 | static unsigned amdgpu_vm_directory_size(struct amdgpu_device *adev) |
| 73 | { |
| 74 | return AMDGPU_GPU_PAGE_ALIGN(amdgpu_vm_num_pdes(adev) * 8); |
| 75 | } |
| 76 | |
| 77 | /** |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 78 | * amdgpu_vm_get_pd_bo - add the VM PD to a validation list |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 79 | * |
| 80 | * @vm: vm providing the BOs |
Christian König | 3c0eea6 | 2015-12-11 14:39:05 +0100 | [diff] [blame] | 81 | * @validated: head of validation list |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 82 | * @entry: entry to add |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 83 | * |
| 84 | * Add the page directory to the list of BOs to |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 85 | * validate for command submission. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 86 | */ |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 87 | void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, |
| 88 | struct list_head *validated, |
| 89 | struct amdgpu_bo_list_entry *entry) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 90 | { |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 91 | entry->robj = vm->page_directory; |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 92 | entry->priority = 0; |
| 93 | entry->tv.bo = &vm->page_directory->tbo; |
| 94 | entry->tv.shared = true; |
| 95 | list_add(&entry->tv.head, validated); |
| 96 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 97 | |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 98 | /** |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 99 | * amdgpu_vm_get_bos - add the vm BOs to a duplicates list |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 100 | * |
| 101 | * @vm: vm providing the BOs |
Christian König | 3c0eea6 | 2015-12-11 14:39:05 +0100 | [diff] [blame] | 102 | * @duplicates: head of duplicates list |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 103 | * |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 104 | * Add the page directory to the BO duplicates list |
| 105 | * for command submission. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 106 | */ |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 107 | void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 108 | { |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 109 | unsigned i; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 110 | |
| 111 | /* add the vm page table to the list */ |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 112 | for (i = 0; i <= vm->max_pde_used; ++i) { |
| 113 | struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 114 | |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 115 | if (!entry->robj) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 116 | continue; |
| 117 | |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 118 | list_add(&entry->tv.head, duplicates); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 119 | } |
Christian König | eceb8a1 | 2016-01-11 15:35:21 +0100 | [diff] [blame] | 120 | |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * amdgpu_vm_move_pt_bos_in_lru - move the PT BOs to the LRU tail |
| 125 | * |
| 126 | * @adev: amdgpu device instance |
| 127 | * @vm: vm providing the BOs |
| 128 | * |
| 129 | * Move the PT BOs to the tail of the LRU. |
| 130 | */ |
| 131 | void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev, |
| 132 | struct amdgpu_vm *vm) |
| 133 | { |
| 134 | struct ttm_bo_global *glob = adev->mman.bdev.glob; |
| 135 | unsigned i; |
| 136 | |
| 137 | spin_lock(&glob->lru_lock); |
| 138 | for (i = 0; i <= vm->max_pde_used; ++i) { |
| 139 | struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry; |
| 140 | |
| 141 | if (!entry->robj) |
| 142 | continue; |
| 143 | |
| 144 | ttm_bo_move_to_lru_tail(&entry->robj->tbo); |
| 145 | } |
| 146 | spin_unlock(&glob->lru_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * amdgpu_vm_grab_id - allocate the next free VMID |
| 151 | * |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 152 | * @vm: vm to allocate id for |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 153 | * @ring: ring we want to submit job to |
| 154 | * @sync: sync object where we add dependencies |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 155 | * |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 156 | * Allocate an id for the vm, adding fences to the sync obj as necessary. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 157 | * |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 158 | * Global mutex must be locked! |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 159 | */ |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 160 | int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, |
| 161 | struct amdgpu_sync *sync) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 162 | { |
Christian König | d528329 | 2015-10-22 11:55:58 +0200 | [diff] [blame] | 163 | struct fence *best[AMDGPU_MAX_RINGS] = {}; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 164 | struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx]; |
| 165 | struct amdgpu_device *adev = ring->adev; |
| 166 | |
| 167 | unsigned choices[2] = {}; |
| 168 | unsigned i; |
| 169 | |
| 170 | /* check if the id is still valid */ |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 171 | if (vm_id->id) { |
| 172 | unsigned id = vm_id->id; |
| 173 | long owner; |
| 174 | |
| 175 | owner = atomic_long_read(&adev->vm_manager.ids[id].owner); |
| 176 | if (owner == (long)vm) { |
| 177 | trace_amdgpu_vm_grab_id(vm_id->id, ring->idx); |
| 178 | return 0; |
| 179 | } |
Christian König | 39ff844 | 2015-09-28 12:01:20 +0200 | [diff] [blame] | 180 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 181 | |
| 182 | /* we definately need to flush */ |
| 183 | vm_id->pd_gpu_addr = ~0ll; |
| 184 | |
| 185 | /* skip over VMID 0, since it is the system VM */ |
| 186 | for (i = 1; i < adev->vm_manager.nvm; ++i) { |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 187 | struct fence *fence = adev->vm_manager.ids[i].active; |
Christian König | d528329 | 2015-10-22 11:55:58 +0200 | [diff] [blame] | 188 | struct amdgpu_ring *fring; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 189 | |
| 190 | if (fence == NULL) { |
| 191 | /* found a free one */ |
| 192 | vm_id->id = i; |
| 193 | trace_amdgpu_vm_grab_id(i, ring->idx); |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 194 | return 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Christian König | d528329 | 2015-10-22 11:55:58 +0200 | [diff] [blame] | 197 | fring = amdgpu_ring_from_fence(fence); |
| 198 | if (best[fring->idx] == NULL || |
| 199 | fence_is_later(best[fring->idx], fence)) { |
| 200 | best[fring->idx] = fence; |
| 201 | choices[fring == ring ? 0 : 1] = i; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | for (i = 0; i < 2; ++i) { |
| 206 | if (choices[i]) { |
Christian König | d528329 | 2015-10-22 11:55:58 +0200 | [diff] [blame] | 207 | struct fence *fence; |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 208 | |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 209 | fence = adev->vm_manager.ids[choices[i]].active; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 210 | vm_id->id = choices[i]; |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 211 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 212 | trace_amdgpu_vm_grab_id(choices[i], ring->idx); |
Christian König | d528329 | 2015-10-22 11:55:58 +0200 | [diff] [blame] | 213 | return amdgpu_sync_fence(ring->adev, sync, fence); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | /* should never happen */ |
| 218 | BUG(); |
Christian König | 7f8a529 | 2015-07-20 16:09:40 +0200 | [diff] [blame] | 219 | return -EINVAL; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
| 223 | * amdgpu_vm_flush - hardware flush the vm |
| 224 | * |
| 225 | * @ring: ring to use for flush |
| 226 | * @vm: vm we want to flush |
| 227 | * @updates: last vm update that we waited for |
| 228 | * |
| 229 | * Flush the vm (cayman+). |
| 230 | * |
| 231 | * Global and local mutex must be locked! |
| 232 | */ |
| 233 | void amdgpu_vm_flush(struct amdgpu_ring *ring, |
| 234 | struct amdgpu_vm *vm, |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 235 | struct fence *updates) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 236 | { |
| 237 | uint64_t pd_addr = amdgpu_bo_gpu_offset(vm->page_directory); |
| 238 | struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx]; |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 239 | struct fence *flushed_updates = vm_id->flushed_updates; |
Christian König | b56c228 | 2015-10-29 17:01:19 +0100 | [diff] [blame] | 240 | bool is_later; |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 241 | |
Christian König | b56c228 | 2015-10-29 17:01:19 +0100 | [diff] [blame] | 242 | if (!flushed_updates) |
| 243 | is_later = true; |
| 244 | else if (!updates) |
| 245 | is_later = false; |
| 246 | else |
| 247 | is_later = fence_is_later(updates, flushed_updates); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 248 | |
Christian König | b56c228 | 2015-10-29 17:01:19 +0100 | [diff] [blame] | 249 | if (pd_addr != vm_id->pd_gpu_addr || is_later) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 250 | trace_amdgpu_vm_flush(pd_addr, ring->idx, vm_id->id); |
Christian König | b56c228 | 2015-10-29 17:01:19 +0100 | [diff] [blame] | 251 | if (is_later) { |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 252 | vm_id->flushed_updates = fence_get(updates); |
| 253 | fence_put(flushed_updates); |
| 254 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 255 | vm_id->pd_gpu_addr = pd_addr; |
| 256 | amdgpu_ring_emit_vm_flush(ring, vm_id->id, vm_id->pd_gpu_addr); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * amdgpu_vm_fence - remember fence for vm |
| 262 | * |
| 263 | * @adev: amdgpu_device pointer |
| 264 | * @vm: vm we want to fence |
| 265 | * @fence: fence to remember |
| 266 | * |
| 267 | * Fence the vm (cayman+). |
| 268 | * Set the fence used to protect page table and id. |
| 269 | * |
| 270 | * Global and local mutex must be locked! |
| 271 | */ |
| 272 | void amdgpu_vm_fence(struct amdgpu_device *adev, |
| 273 | struct amdgpu_vm *vm, |
Christian König | 16ae42f | 2015-11-03 14:53:28 +0100 | [diff] [blame] | 274 | struct fence *fence) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 275 | { |
Christian König | 16ae42f | 2015-11-03 14:53:28 +0100 | [diff] [blame] | 276 | struct amdgpu_ring *ring = amdgpu_ring_from_fence(fence); |
| 277 | unsigned vm_id = vm->ids[ring->idx].id; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 278 | |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 279 | fence_put(adev->vm_manager.ids[vm_id].active); |
| 280 | adev->vm_manager.ids[vm_id].active = fence_get(fence); |
| 281 | atomic_long_set(&adev->vm_manager.ids[vm_id].owner, (long)vm); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
| 285 | * amdgpu_vm_bo_find - find the bo_va for a specific vm & bo |
| 286 | * |
| 287 | * @vm: requested vm |
| 288 | * @bo: requested buffer object |
| 289 | * |
| 290 | * Find @bo inside the requested vm (cayman+). |
| 291 | * Search inside the @bos vm list for the requested vm |
| 292 | * Returns the found bo_va or NULL if none is found |
| 293 | * |
| 294 | * Object has to be reserved! |
| 295 | */ |
| 296 | struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, |
| 297 | struct amdgpu_bo *bo) |
| 298 | { |
| 299 | struct amdgpu_bo_va *bo_va; |
| 300 | |
| 301 | list_for_each_entry(bo_va, &bo->va, bo_list) { |
| 302 | if (bo_va->vm == vm) { |
| 303 | return bo_va; |
| 304 | } |
| 305 | } |
| 306 | return NULL; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * amdgpu_vm_update_pages - helper to call the right asic function |
| 311 | * |
| 312 | * @adev: amdgpu_device pointer |
| 313 | * @ib: indirect buffer to fill with commands |
| 314 | * @pe: addr of the page entry |
| 315 | * @addr: dst addr to write into pe |
| 316 | * @count: number of page entries to update |
| 317 | * @incr: increase next addr by incr bytes |
| 318 | * @flags: hw access flags |
| 319 | * @gtt_flags: GTT hw access flags |
| 320 | * |
| 321 | * Traces the parameters and calls the right asic functions |
| 322 | * to setup the page table using the DMA. |
| 323 | */ |
| 324 | static void amdgpu_vm_update_pages(struct amdgpu_device *adev, |
| 325 | struct amdgpu_ib *ib, |
| 326 | uint64_t pe, uint64_t addr, |
| 327 | unsigned count, uint32_t incr, |
| 328 | uint32_t flags, uint32_t gtt_flags) |
| 329 | { |
| 330 | trace_amdgpu_vm_set_page(pe, addr, count, incr, flags); |
| 331 | |
| 332 | if ((flags & AMDGPU_PTE_SYSTEM) && (flags == gtt_flags)) { |
| 333 | uint64_t src = adev->gart.table_addr + (addr >> 12) * 8; |
| 334 | amdgpu_vm_copy_pte(adev, ib, pe, src, count); |
| 335 | |
| 336 | } else if ((flags & AMDGPU_PTE_SYSTEM) || (count < 3)) { |
| 337 | amdgpu_vm_write_pte(adev, ib, pe, addr, |
| 338 | count, incr, flags); |
| 339 | |
| 340 | } else { |
| 341 | amdgpu_vm_set_pte_pde(adev, ib, pe, addr, |
| 342 | count, incr, flags); |
| 343 | } |
| 344 | } |
| 345 | |
Junwei Zhang | 4c7eb91 | 2015-09-09 09:05:55 +0800 | [diff] [blame] | 346 | int amdgpu_vm_free_job(struct amdgpu_job *job) |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 347 | { |
| 348 | int i; |
Junwei Zhang | 4c7eb91 | 2015-09-09 09:05:55 +0800 | [diff] [blame] | 349 | for (i = 0; i < job->num_ibs; i++) |
| 350 | amdgpu_ib_free(job->adev, &job->ibs[i]); |
| 351 | kfree(job->ibs); |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 352 | return 0; |
| 353 | } |
| 354 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 355 | /** |
| 356 | * amdgpu_vm_clear_bo - initially clear the page dir/table |
| 357 | * |
| 358 | * @adev: amdgpu_device pointer |
| 359 | * @bo: bo to clear |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 360 | * |
| 361 | * need to reserve bo first before calling it. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 362 | */ |
| 363 | static int amdgpu_vm_clear_bo(struct amdgpu_device *adev, |
| 364 | struct amdgpu_bo *bo) |
| 365 | { |
| 366 | struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring; |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 367 | struct fence *fence = NULL; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 368 | struct amdgpu_ib *ib; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 369 | unsigned entries; |
| 370 | uint64_t addr; |
| 371 | int r; |
| 372 | |
monk.liu | ca95261 | 2015-05-25 14:44:05 +0800 | [diff] [blame] | 373 | r = reservation_object_reserve_shared(bo->tbo.resv); |
| 374 | if (r) |
| 375 | return r; |
| 376 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 377 | r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false); |
| 378 | if (r) |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 379 | goto error; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 380 | |
| 381 | addr = amdgpu_bo_gpu_offset(bo); |
| 382 | entries = amdgpu_bo_size(bo) / 8; |
| 383 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 384 | ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL); |
| 385 | if (!ib) |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 386 | goto error; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 387 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 388 | r = amdgpu_ib_get(ring, NULL, entries * 2 + 64, ib); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 389 | if (r) |
| 390 | goto error_free; |
| 391 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 392 | ib->length_dw = 0; |
| 393 | |
| 394 | amdgpu_vm_update_pages(adev, ib, addr, 0, entries, 0, 0, 0); |
| 395 | amdgpu_vm_pad_ib(adev, ib); |
| 396 | WARN_ON(ib->length_dw > 64); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 397 | r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1, |
| 398 | &amdgpu_vm_free_job, |
| 399 | AMDGPU_FENCE_OWNER_VM, |
| 400 | &fence); |
| 401 | if (!r) |
| 402 | amdgpu_bo_fence(bo, fence, true); |
Chunming Zhou | 281b422 | 2015-08-12 12:58:31 +0800 | [diff] [blame] | 403 | fence_put(fence); |
Chunming Zhou | cadf97b | 2016-01-15 11:25:00 +0800 | [diff] [blame^] | 404 | return 0; |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 405 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 406 | error_free: |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 407 | amdgpu_ib_free(adev, ib); |
| 408 | kfree(ib); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 409 | |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 410 | error: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 411 | return r; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * amdgpu_vm_map_gart - get the physical address of a gart page |
| 416 | * |
| 417 | * @adev: amdgpu_device pointer |
| 418 | * @addr: the unmapped addr |
| 419 | * |
| 420 | * Look up the physical address of the page that the pte resolves |
| 421 | * to (cayman+). |
| 422 | * Returns the physical address of the page. |
| 423 | */ |
| 424 | uint64_t amdgpu_vm_map_gart(struct amdgpu_device *adev, uint64_t addr) |
| 425 | { |
| 426 | uint64_t result; |
| 427 | |
| 428 | /* page table offset */ |
| 429 | result = adev->gart.pages_addr[addr >> PAGE_SHIFT]; |
| 430 | |
| 431 | /* in case cpu page size != gpu page size*/ |
| 432 | result |= addr & (~PAGE_MASK); |
| 433 | |
| 434 | return result; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * amdgpu_vm_update_pdes - make sure that page directory is valid |
| 439 | * |
| 440 | * @adev: amdgpu_device pointer |
| 441 | * @vm: requested vm |
| 442 | * @start: start of GPU address range |
| 443 | * @end: end of GPU address range |
| 444 | * |
| 445 | * Allocates new page tables if necessary |
| 446 | * and updates the page directory (cayman+). |
| 447 | * Returns 0 for success, error for failure. |
| 448 | * |
| 449 | * Global and local mutex must be locked! |
| 450 | */ |
| 451 | int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, |
| 452 | struct amdgpu_vm *vm) |
| 453 | { |
| 454 | struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring; |
| 455 | struct amdgpu_bo *pd = vm->page_directory; |
| 456 | uint64_t pd_addr = amdgpu_bo_gpu_offset(pd); |
| 457 | uint32_t incr = AMDGPU_VM_PTE_COUNT * 8; |
| 458 | uint64_t last_pde = ~0, last_pt = ~0; |
| 459 | unsigned count = 0, pt_idx, ndw; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 460 | struct amdgpu_ib *ib; |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 461 | struct fence *fence = NULL; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 462 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 463 | int r; |
| 464 | |
| 465 | /* padding, etc. */ |
| 466 | ndw = 64; |
| 467 | |
| 468 | /* assume the worst case */ |
| 469 | ndw += vm->max_pde_used * 6; |
| 470 | |
| 471 | /* update too big for an IB */ |
| 472 | if (ndw > 0xfffff) |
| 473 | return -ENOMEM; |
| 474 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 475 | ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL); |
| 476 | if (!ib) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | r = amdgpu_ib_get(ring, NULL, ndw * 4, ib); |
Sudip Mukherjee | 7a57455 | 2015-10-08 19:28:01 +0530 | [diff] [blame] | 480 | if (r) { |
| 481 | kfree(ib); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 482 | return r; |
Sudip Mukherjee | 7a57455 | 2015-10-08 19:28:01 +0530 | [diff] [blame] | 483 | } |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 484 | ib->length_dw = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 485 | |
| 486 | /* walk over the address space and update the page directory */ |
| 487 | for (pt_idx = 0; pt_idx <= vm->max_pde_used; ++pt_idx) { |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 488 | struct amdgpu_bo *bo = vm->page_tables[pt_idx].entry.robj; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 489 | uint64_t pde, pt; |
| 490 | |
| 491 | if (bo == NULL) |
| 492 | continue; |
| 493 | |
| 494 | pt = amdgpu_bo_gpu_offset(bo); |
| 495 | if (vm->page_tables[pt_idx].addr == pt) |
| 496 | continue; |
| 497 | vm->page_tables[pt_idx].addr = pt; |
| 498 | |
| 499 | pde = pd_addr + pt_idx * 8; |
| 500 | if (((last_pde + 8 * count) != pde) || |
| 501 | ((last_pt + incr * count) != pt)) { |
| 502 | |
| 503 | if (count) { |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 504 | amdgpu_vm_update_pages(adev, ib, last_pde, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 505 | last_pt, count, incr, |
| 506 | AMDGPU_PTE_VALID, 0); |
| 507 | } |
| 508 | |
| 509 | count = 1; |
| 510 | last_pde = pde; |
| 511 | last_pt = pt; |
| 512 | } else { |
| 513 | ++count; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if (count) |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 518 | amdgpu_vm_update_pages(adev, ib, last_pde, last_pt, count, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 519 | incr, AMDGPU_PTE_VALID, 0); |
| 520 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 521 | if (ib->length_dw != 0) { |
| 522 | amdgpu_vm_pad_ib(adev, ib); |
| 523 | amdgpu_sync_resv(adev, &ib->sync, pd->tbo.resv, AMDGPU_FENCE_OWNER_VM); |
| 524 | WARN_ON(ib->length_dw > ndw); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 525 | r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1, |
| 526 | &amdgpu_vm_free_job, |
| 527 | AMDGPU_FENCE_OWNER_VM, |
| 528 | &fence); |
| 529 | if (r) |
| 530 | goto error_free; |
Bas Nieuwenhuizen | 05906de | 2015-08-14 20:08:40 +0200 | [diff] [blame] | 531 | |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 532 | amdgpu_bo_fence(pd, fence, true); |
Bas Nieuwenhuizen | 05906de | 2015-08-14 20:08:40 +0200 | [diff] [blame] | 533 | fence_put(vm->page_directory_fence); |
| 534 | vm->page_directory_fence = fence_get(fence); |
Chunming Zhou | 281b422 | 2015-08-12 12:58:31 +0800 | [diff] [blame] | 535 | fence_put(fence); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 536 | } |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 537 | |
Chunming Zhou | cadf97b | 2016-01-15 11:25:00 +0800 | [diff] [blame^] | 538 | if (ib->length_dw == 0) { |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 539 | amdgpu_ib_free(adev, ib); |
| 540 | kfree(ib); |
| 541 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 542 | |
| 543 | return 0; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 544 | |
| 545 | error_free: |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 546 | amdgpu_ib_free(adev, ib); |
| 547 | kfree(ib); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 548 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
| 552 | * amdgpu_vm_frag_ptes - add fragment information to PTEs |
| 553 | * |
| 554 | * @adev: amdgpu_device pointer |
| 555 | * @ib: IB for the update |
| 556 | * @pe_start: first PTE to handle |
| 557 | * @pe_end: last PTE to handle |
| 558 | * @addr: addr those PTEs should point to |
| 559 | * @flags: hw mapping flags |
| 560 | * @gtt_flags: GTT hw mapping flags |
| 561 | * |
| 562 | * Global and local mutex must be locked! |
| 563 | */ |
| 564 | static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev, |
| 565 | struct amdgpu_ib *ib, |
| 566 | uint64_t pe_start, uint64_t pe_end, |
| 567 | uint64_t addr, uint32_t flags, |
| 568 | uint32_t gtt_flags) |
| 569 | { |
| 570 | /** |
| 571 | * The MC L1 TLB supports variable sized pages, based on a fragment |
| 572 | * field in the PTE. When this field is set to a non-zero value, page |
| 573 | * granularity is increased from 4KB to (1 << (12 + frag)). The PTE |
| 574 | * flags are considered valid for all PTEs within the fragment range |
| 575 | * and corresponding mappings are assumed to be physically contiguous. |
| 576 | * |
| 577 | * The L1 TLB can store a single PTE for the whole fragment, |
| 578 | * significantly increasing the space available for translation |
| 579 | * caching. This leads to large improvements in throughput when the |
| 580 | * TLB is under pressure. |
| 581 | * |
| 582 | * The L2 TLB distributes small and large fragments into two |
| 583 | * asymmetric partitions. The large fragment cache is significantly |
| 584 | * larger. Thus, we try to use large fragments wherever possible. |
| 585 | * Userspace can support this by aligning virtual base address and |
| 586 | * allocation size to the fragment size. |
| 587 | */ |
| 588 | |
| 589 | /* SI and newer are optimized for 64KB */ |
| 590 | uint64_t frag_flags = AMDGPU_PTE_FRAG_64KB; |
| 591 | uint64_t frag_align = 0x80; |
| 592 | |
| 593 | uint64_t frag_start = ALIGN(pe_start, frag_align); |
| 594 | uint64_t frag_end = pe_end & ~(frag_align - 1); |
| 595 | |
| 596 | unsigned count; |
| 597 | |
| 598 | /* system pages are non continuously */ |
| 599 | if ((flags & AMDGPU_PTE_SYSTEM) || !(flags & AMDGPU_PTE_VALID) || |
| 600 | (frag_start >= frag_end)) { |
| 601 | |
| 602 | count = (pe_end - pe_start) / 8; |
| 603 | amdgpu_vm_update_pages(adev, ib, pe_start, addr, count, |
| 604 | AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags); |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | /* handle the 4K area at the beginning */ |
| 609 | if (pe_start != frag_start) { |
| 610 | count = (frag_start - pe_start) / 8; |
| 611 | amdgpu_vm_update_pages(adev, ib, pe_start, addr, count, |
| 612 | AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags); |
| 613 | addr += AMDGPU_GPU_PAGE_SIZE * count; |
| 614 | } |
| 615 | |
| 616 | /* handle the area in the middle */ |
| 617 | count = (frag_end - frag_start) / 8; |
| 618 | amdgpu_vm_update_pages(adev, ib, frag_start, addr, count, |
| 619 | AMDGPU_GPU_PAGE_SIZE, flags | frag_flags, |
| 620 | gtt_flags); |
| 621 | |
| 622 | /* handle the 4K area at the end */ |
| 623 | if (frag_end != pe_end) { |
| 624 | addr += AMDGPU_GPU_PAGE_SIZE * count; |
| 625 | count = (pe_end - frag_end) / 8; |
| 626 | amdgpu_vm_update_pages(adev, ib, frag_end, addr, count, |
| 627 | AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * amdgpu_vm_update_ptes - make sure that page tables are valid |
| 633 | * |
| 634 | * @adev: amdgpu_device pointer |
| 635 | * @vm: requested vm |
| 636 | * @start: start of GPU address range |
| 637 | * @end: end of GPU address range |
| 638 | * @dst: destination address to map to |
| 639 | * @flags: mapping flags |
| 640 | * |
| 641 | * Update the page tables in the range @start - @end (cayman+). |
| 642 | * |
| 643 | * Global and local mutex must be locked! |
| 644 | */ |
| 645 | static int amdgpu_vm_update_ptes(struct amdgpu_device *adev, |
| 646 | struct amdgpu_vm *vm, |
| 647 | struct amdgpu_ib *ib, |
| 648 | uint64_t start, uint64_t end, |
| 649 | uint64_t dst, uint32_t flags, |
| 650 | uint32_t gtt_flags) |
| 651 | { |
| 652 | uint64_t mask = AMDGPU_VM_PTE_COUNT - 1; |
| 653 | uint64_t last_pte = ~0, last_dst = ~0; |
Christian König | a60c423 | 2015-09-01 15:33:25 +0200 | [diff] [blame] | 654 | void *owner = AMDGPU_FENCE_OWNER_VM; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 655 | unsigned count = 0; |
| 656 | uint64_t addr; |
| 657 | |
Christian König | a60c423 | 2015-09-01 15:33:25 +0200 | [diff] [blame] | 658 | /* sync to everything on unmapping */ |
| 659 | if (!(flags & AMDGPU_PTE_VALID)) |
| 660 | owner = AMDGPU_FENCE_OWNER_UNDEFINED; |
| 661 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 662 | /* walk over the address space and update the page tables */ |
| 663 | for (addr = start; addr < end; ) { |
| 664 | uint64_t pt_idx = addr >> amdgpu_vm_block_size; |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 665 | struct amdgpu_bo *pt = vm->page_tables[pt_idx].entry.robj; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 666 | unsigned nptes; |
| 667 | uint64_t pte; |
| 668 | int r; |
| 669 | |
Christian König | a60c423 | 2015-09-01 15:33:25 +0200 | [diff] [blame] | 670 | amdgpu_sync_resv(adev, &ib->sync, pt->tbo.resv, owner); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 671 | r = reservation_object_reserve_shared(pt->tbo.resv); |
| 672 | if (r) |
| 673 | return r; |
| 674 | |
| 675 | if ((addr & ~mask) == (end & ~mask)) |
| 676 | nptes = end - addr; |
| 677 | else |
| 678 | nptes = AMDGPU_VM_PTE_COUNT - (addr & mask); |
| 679 | |
| 680 | pte = amdgpu_bo_gpu_offset(pt); |
| 681 | pte += (addr & mask) * 8; |
| 682 | |
| 683 | if ((last_pte + 8 * count) != pte) { |
| 684 | |
| 685 | if (count) { |
| 686 | amdgpu_vm_frag_ptes(adev, ib, last_pte, |
| 687 | last_pte + 8 * count, |
| 688 | last_dst, flags, |
| 689 | gtt_flags); |
| 690 | } |
| 691 | |
| 692 | count = nptes; |
| 693 | last_pte = pte; |
| 694 | last_dst = dst; |
| 695 | } else { |
| 696 | count += nptes; |
| 697 | } |
| 698 | |
| 699 | addr += nptes; |
| 700 | dst += nptes * AMDGPU_GPU_PAGE_SIZE; |
| 701 | } |
| 702 | |
| 703 | if (count) { |
| 704 | amdgpu_vm_frag_ptes(adev, ib, last_pte, |
| 705 | last_pte + 8 * count, |
| 706 | last_dst, flags, gtt_flags); |
| 707 | } |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | /** |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 713 | * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table |
| 714 | * |
| 715 | * @adev: amdgpu_device pointer |
| 716 | * @vm: requested vm |
| 717 | * @mapping: mapped range and flags to use for the update |
| 718 | * @addr: addr to set the area to |
| 719 | * @gtt_flags: flags as they are used for GTT |
| 720 | * @fence: optional resulting fence |
| 721 | * |
| 722 | * Fill in the page table entries for @mapping. |
| 723 | * Returns 0 for success, -EINVAL for failure. |
| 724 | * |
| 725 | * Object have to be reserved and mutex must be locked! |
| 726 | */ |
| 727 | static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, |
| 728 | struct amdgpu_vm *vm, |
| 729 | struct amdgpu_bo_va_mapping *mapping, |
| 730 | uint64_t addr, uint32_t gtt_flags, |
Chunming Zhou | bb1e38a4 | 2015-08-03 18:19:38 +0800 | [diff] [blame] | 731 | struct fence **fence) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 732 | { |
| 733 | struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring; |
| 734 | unsigned nptes, ncmds, ndw; |
| 735 | uint32_t flags = gtt_flags; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 736 | struct amdgpu_ib *ib; |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 737 | struct fence *f = NULL; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 738 | int r; |
| 739 | |
| 740 | /* normally,bo_va->flags only contians READABLE and WIRTEABLE bit go here |
| 741 | * but in case of something, we filter the flags in first place |
| 742 | */ |
| 743 | if (!(mapping->flags & AMDGPU_PTE_READABLE)) |
| 744 | flags &= ~AMDGPU_PTE_READABLE; |
| 745 | if (!(mapping->flags & AMDGPU_PTE_WRITEABLE)) |
| 746 | flags &= ~AMDGPU_PTE_WRITEABLE; |
| 747 | |
| 748 | trace_amdgpu_vm_bo_update(mapping); |
| 749 | |
| 750 | nptes = mapping->it.last - mapping->it.start + 1; |
| 751 | |
| 752 | /* |
| 753 | * reserve space for one command every (1 << BLOCK_SIZE) |
| 754 | * entries or 2k dwords (whatever is smaller) |
| 755 | */ |
| 756 | ncmds = (nptes >> min(amdgpu_vm_block_size, 11)) + 1; |
| 757 | |
| 758 | /* padding, etc. */ |
| 759 | ndw = 64; |
| 760 | |
| 761 | if ((flags & AMDGPU_PTE_SYSTEM) && (flags == gtt_flags)) { |
| 762 | /* only copy commands needed */ |
| 763 | ndw += ncmds * 7; |
| 764 | |
| 765 | } else if (flags & AMDGPU_PTE_SYSTEM) { |
| 766 | /* header for write data commands */ |
| 767 | ndw += ncmds * 4; |
| 768 | |
| 769 | /* body of write data command */ |
| 770 | ndw += nptes * 2; |
| 771 | |
| 772 | } else { |
| 773 | /* set page commands needed */ |
| 774 | ndw += ncmds * 10; |
| 775 | |
| 776 | /* two extra commands for begin/end of fragment */ |
| 777 | ndw += 2 * 10; |
| 778 | } |
| 779 | |
| 780 | /* update too big for an IB */ |
| 781 | if (ndw > 0xfffff) |
| 782 | return -ENOMEM; |
| 783 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 784 | ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL); |
| 785 | if (!ib) |
| 786 | return -ENOMEM; |
| 787 | |
| 788 | r = amdgpu_ib_get(ring, NULL, ndw * 4, ib); |
| 789 | if (r) { |
| 790 | kfree(ib); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 791 | return r; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | ib->length_dw = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 795 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 796 | r = amdgpu_vm_update_ptes(adev, vm, ib, mapping->it.start, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 797 | mapping->it.last + 1, addr + mapping->offset, |
| 798 | flags, gtt_flags); |
| 799 | |
| 800 | if (r) { |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 801 | amdgpu_ib_free(adev, ib); |
| 802 | kfree(ib); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 803 | return r; |
| 804 | } |
| 805 | |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 806 | amdgpu_vm_pad_ib(adev, ib); |
| 807 | WARN_ON(ib->length_dw > ndw); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 808 | r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1, |
| 809 | &amdgpu_vm_free_job, |
| 810 | AMDGPU_FENCE_OWNER_VM, |
| 811 | &f); |
| 812 | if (r) |
| 813 | goto error_free; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 814 | |
Christian König | bf60efd | 2015-09-04 10:47:56 +0200 | [diff] [blame] | 815 | amdgpu_bo_fence(vm->page_directory, f, true); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 816 | if (fence) { |
| 817 | fence_put(*fence); |
| 818 | *fence = fence_get(f); |
| 819 | } |
Chunming Zhou | 281b422 | 2015-08-12 12:58:31 +0800 | [diff] [blame] | 820 | fence_put(f); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 821 | return 0; |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 822 | |
| 823 | error_free: |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 824 | amdgpu_ib_free(adev, ib); |
| 825 | kfree(ib); |
Chunming Zhou | 4af9f07 | 2015-08-03 12:57:31 +0800 | [diff] [blame] | 826 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
| 830 | * amdgpu_vm_bo_update - update all BO mappings in the vm page table |
| 831 | * |
| 832 | * @adev: amdgpu_device pointer |
| 833 | * @bo_va: requested BO and VM object |
| 834 | * @mem: ttm mem |
| 835 | * |
| 836 | * Fill in the page table entries for @bo_va. |
| 837 | * Returns 0 for success, -EINVAL for failure. |
| 838 | * |
| 839 | * Object have to be reserved and mutex must be locked! |
| 840 | */ |
| 841 | int amdgpu_vm_bo_update(struct amdgpu_device *adev, |
| 842 | struct amdgpu_bo_va *bo_va, |
| 843 | struct ttm_mem_reg *mem) |
| 844 | { |
| 845 | struct amdgpu_vm *vm = bo_va->vm; |
| 846 | struct amdgpu_bo_va_mapping *mapping; |
| 847 | uint32_t flags; |
| 848 | uint64_t addr; |
| 849 | int r; |
| 850 | |
| 851 | if (mem) { |
Christian König | b7d698d | 2015-09-07 12:32:09 +0200 | [diff] [blame] | 852 | addr = (u64)mem->start << PAGE_SHIFT; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 853 | if (mem->mem_type != TTM_PL_TT) |
| 854 | addr += adev->vm_manager.vram_base_offset; |
| 855 | } else { |
| 856 | addr = 0; |
| 857 | } |
| 858 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 859 | flags = amdgpu_ttm_tt_pte_flags(adev, bo_va->bo->tbo.ttm, mem); |
| 860 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 861 | spin_lock(&vm->status_lock); |
| 862 | if (!list_empty(&bo_va->vm_status)) |
| 863 | list_splice_init(&bo_va->valids, &bo_va->invalids); |
| 864 | spin_unlock(&vm->status_lock); |
| 865 | |
| 866 | list_for_each_entry(mapping, &bo_va->invalids, list) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 867 | r = amdgpu_vm_bo_update_mapping(adev, vm, mapping, addr, |
| 868 | flags, &bo_va->last_pt_update); |
| 869 | if (r) |
| 870 | return r; |
| 871 | } |
| 872 | |
Christian König | d6c10f6 | 2015-09-28 12:00:23 +0200 | [diff] [blame] | 873 | if (trace_amdgpu_vm_bo_mapping_enabled()) { |
| 874 | list_for_each_entry(mapping, &bo_va->valids, list) |
| 875 | trace_amdgpu_vm_bo_mapping(mapping); |
| 876 | |
| 877 | list_for_each_entry(mapping, &bo_va->invalids, list) |
| 878 | trace_amdgpu_vm_bo_mapping(mapping); |
| 879 | } |
| 880 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 881 | spin_lock(&vm->status_lock); |
monk.liu | 6d1d0ef | 2015-08-14 13:36:41 +0800 | [diff] [blame] | 882 | list_splice_init(&bo_va->invalids, &bo_va->valids); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 883 | list_del_init(&bo_va->vm_status); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 884 | if (!mem) |
| 885 | list_add(&bo_va->vm_status, &vm->cleared); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 886 | spin_unlock(&vm->status_lock); |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * amdgpu_vm_clear_freed - clear freed BOs in the PT |
| 893 | * |
| 894 | * @adev: amdgpu_device pointer |
| 895 | * @vm: requested vm |
| 896 | * |
| 897 | * Make sure all freed BOs are cleared in the PT. |
| 898 | * Returns 0 for success. |
| 899 | * |
| 900 | * PTs have to be reserved and mutex must be locked! |
| 901 | */ |
| 902 | int amdgpu_vm_clear_freed(struct amdgpu_device *adev, |
| 903 | struct amdgpu_vm *vm) |
| 904 | { |
| 905 | struct amdgpu_bo_va_mapping *mapping; |
| 906 | int r; |
| 907 | |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 908 | spin_lock(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 909 | while (!list_empty(&vm->freed)) { |
| 910 | mapping = list_first_entry(&vm->freed, |
| 911 | struct amdgpu_bo_va_mapping, list); |
| 912 | list_del(&mapping->list); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 913 | spin_unlock(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 914 | r = amdgpu_vm_bo_update_mapping(adev, vm, mapping, 0, 0, NULL); |
| 915 | kfree(mapping); |
| 916 | if (r) |
| 917 | return r; |
| 918 | |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 919 | spin_lock(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 920 | } |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 921 | spin_unlock(&vm->freed_lock); |
| 922 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 923 | return 0; |
| 924 | |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * amdgpu_vm_clear_invalids - clear invalidated BOs in the PT |
| 929 | * |
| 930 | * @adev: amdgpu_device pointer |
| 931 | * @vm: requested vm |
| 932 | * |
| 933 | * Make sure all invalidated BOs are cleared in the PT. |
| 934 | * Returns 0 for success. |
| 935 | * |
| 936 | * PTs have to be reserved and mutex must be locked! |
| 937 | */ |
| 938 | int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, |
monk.liu | cfe2c97 | 2015-05-26 15:01:54 +0800 | [diff] [blame] | 939 | struct amdgpu_vm *vm, struct amdgpu_sync *sync) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 940 | { |
monk.liu | cfe2c97 | 2015-05-26 15:01:54 +0800 | [diff] [blame] | 941 | struct amdgpu_bo_va *bo_va = NULL; |
Christian König | 91e1a52 | 2015-07-06 22:06:40 +0200 | [diff] [blame] | 942 | int r = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 943 | |
| 944 | spin_lock(&vm->status_lock); |
| 945 | while (!list_empty(&vm->invalidated)) { |
| 946 | bo_va = list_first_entry(&vm->invalidated, |
| 947 | struct amdgpu_bo_va, vm_status); |
| 948 | spin_unlock(&vm->status_lock); |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 949 | mutex_lock(&bo_va->mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 950 | r = amdgpu_vm_bo_update(adev, bo_va, NULL); |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 951 | mutex_unlock(&bo_va->mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 952 | if (r) |
| 953 | return r; |
| 954 | |
| 955 | spin_lock(&vm->status_lock); |
| 956 | } |
| 957 | spin_unlock(&vm->status_lock); |
| 958 | |
monk.liu | cfe2c97 | 2015-05-26 15:01:54 +0800 | [diff] [blame] | 959 | if (bo_va) |
Chunming Zhou | bb1e38a4 | 2015-08-03 18:19:38 +0800 | [diff] [blame] | 960 | r = amdgpu_sync_fence(adev, sync, bo_va->last_pt_update); |
Christian König | 91e1a52 | 2015-07-06 22:06:40 +0200 | [diff] [blame] | 961 | |
| 962 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /** |
| 966 | * amdgpu_vm_bo_add - add a bo to a specific vm |
| 967 | * |
| 968 | * @adev: amdgpu_device pointer |
| 969 | * @vm: requested vm |
| 970 | * @bo: amdgpu buffer object |
| 971 | * |
| 972 | * Add @bo into the requested vm (cayman+). |
| 973 | * Add @bo to the list of bos associated with the vm |
| 974 | * Returns newly added bo_va or NULL for failure |
| 975 | * |
| 976 | * Object has to be reserved! |
| 977 | */ |
| 978 | struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, |
| 979 | struct amdgpu_vm *vm, |
| 980 | struct amdgpu_bo *bo) |
| 981 | { |
| 982 | struct amdgpu_bo_va *bo_va; |
| 983 | |
| 984 | bo_va = kzalloc(sizeof(struct amdgpu_bo_va), GFP_KERNEL); |
| 985 | if (bo_va == NULL) { |
| 986 | return NULL; |
| 987 | } |
| 988 | bo_va->vm = vm; |
| 989 | bo_va->bo = bo; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 990 | bo_va->ref_count = 1; |
| 991 | INIT_LIST_HEAD(&bo_va->bo_list); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 992 | INIT_LIST_HEAD(&bo_va->valids); |
| 993 | INIT_LIST_HEAD(&bo_va->invalids); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 994 | INIT_LIST_HEAD(&bo_va->vm_status); |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 995 | mutex_init(&bo_va->mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 996 | list_add_tail(&bo_va->bo_list, &bo->va); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 997 | |
| 998 | return bo_va; |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * amdgpu_vm_bo_map - map bo inside a vm |
| 1003 | * |
| 1004 | * @adev: amdgpu_device pointer |
| 1005 | * @bo_va: bo_va to store the address |
| 1006 | * @saddr: where to map the BO |
| 1007 | * @offset: requested offset in the BO |
| 1008 | * @flags: attributes of pages (read/write/valid/etc.) |
| 1009 | * |
| 1010 | * Add a mapping of the BO at the specefied addr into the VM. |
| 1011 | * Returns 0 for success, error for failure. |
| 1012 | * |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1013 | * Object has to be reserved and unreserved outside! |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1014 | */ |
| 1015 | int amdgpu_vm_bo_map(struct amdgpu_device *adev, |
| 1016 | struct amdgpu_bo_va *bo_va, |
| 1017 | uint64_t saddr, uint64_t offset, |
| 1018 | uint64_t size, uint32_t flags) |
| 1019 | { |
| 1020 | struct amdgpu_bo_va_mapping *mapping; |
| 1021 | struct amdgpu_vm *vm = bo_va->vm; |
| 1022 | struct interval_tree_node *it; |
| 1023 | unsigned last_pfn, pt_idx; |
| 1024 | uint64_t eaddr; |
| 1025 | int r; |
| 1026 | |
Christian König | 0be52de | 2015-05-18 14:37:27 +0200 | [diff] [blame] | 1027 | /* validate the parameters */ |
| 1028 | if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK || |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1029 | size == 0 || size & AMDGPU_GPU_PAGE_MASK) |
Christian König | 0be52de | 2015-05-18 14:37:27 +0200 | [diff] [blame] | 1030 | return -EINVAL; |
Christian König | 0be52de | 2015-05-18 14:37:27 +0200 | [diff] [blame] | 1031 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1032 | /* make sure object fit at this offset */ |
Felix Kuehling | 005ae95 | 2015-11-23 17:43:48 -0500 | [diff] [blame] | 1033 | eaddr = saddr + size - 1; |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1034 | if ((saddr >= eaddr) || (offset + size > amdgpu_bo_size(bo_va->bo))) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1035 | return -EINVAL; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1036 | |
| 1037 | last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE; |
Felix Kuehling | 005ae95 | 2015-11-23 17:43:48 -0500 | [diff] [blame] | 1038 | if (last_pfn >= adev->vm_manager.max_pfn) { |
| 1039 | dev_err(adev->dev, "va above limit (0x%08X >= 0x%08X)\n", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1040 | last_pfn, adev->vm_manager.max_pfn); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1041 | return -EINVAL; |
| 1042 | } |
| 1043 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1044 | saddr /= AMDGPU_GPU_PAGE_SIZE; |
| 1045 | eaddr /= AMDGPU_GPU_PAGE_SIZE; |
| 1046 | |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1047 | spin_lock(&vm->it_lock); |
Felix Kuehling | 005ae95 | 2015-11-23 17:43:48 -0500 | [diff] [blame] | 1048 | it = interval_tree_iter_first(&vm->va, saddr, eaddr); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1049 | spin_unlock(&vm->it_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1050 | if (it) { |
| 1051 | struct amdgpu_bo_va_mapping *tmp; |
| 1052 | tmp = container_of(it, struct amdgpu_bo_va_mapping, it); |
| 1053 | /* bo and tmp overlap, invalid addr */ |
| 1054 | dev_err(adev->dev, "bo %p va 0x%010Lx-0x%010Lx conflict with " |
| 1055 | "0x%010lx-0x%010lx\n", bo_va->bo, saddr, eaddr, |
| 1056 | tmp->it.start, tmp->it.last + 1); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1057 | r = -EINVAL; |
Chunming Zhou | f48b265 | 2015-10-16 14:06:19 +0800 | [diff] [blame] | 1058 | goto error; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | mapping = kmalloc(sizeof(*mapping), GFP_KERNEL); |
| 1062 | if (!mapping) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1063 | r = -ENOMEM; |
Chunming Zhou | f48b265 | 2015-10-16 14:06:19 +0800 | [diff] [blame] | 1064 | goto error; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | INIT_LIST_HEAD(&mapping->list); |
| 1068 | mapping->it.start = saddr; |
Felix Kuehling | 005ae95 | 2015-11-23 17:43:48 -0500 | [diff] [blame] | 1069 | mapping->it.last = eaddr; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1070 | mapping->offset = offset; |
| 1071 | mapping->flags = flags; |
| 1072 | |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1073 | mutex_lock(&bo_va->mutex); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1074 | list_add(&mapping->list, &bo_va->invalids); |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1075 | mutex_unlock(&bo_va->mutex); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1076 | spin_lock(&vm->it_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1077 | interval_tree_insert(&mapping->it, &vm->va); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1078 | spin_unlock(&vm->it_lock); |
Christian König | 93e3e43 | 2015-06-09 16:58:33 +0200 | [diff] [blame] | 1079 | trace_amdgpu_vm_bo_map(bo_va, mapping); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1080 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1081 | /* Make sure the page tables are allocated */ |
| 1082 | saddr >>= amdgpu_vm_block_size; |
| 1083 | eaddr >>= amdgpu_vm_block_size; |
| 1084 | |
| 1085 | BUG_ON(eaddr >= amdgpu_vm_num_pdes(adev)); |
| 1086 | |
| 1087 | if (eaddr > vm->max_pde_used) |
| 1088 | vm->max_pde_used = eaddr; |
| 1089 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1090 | /* walk over the address space and allocate the page tables */ |
| 1091 | for (pt_idx = saddr; pt_idx <= eaddr; ++pt_idx) { |
Christian König | bf60efd | 2015-09-04 10:47:56 +0200 | [diff] [blame] | 1092 | struct reservation_object *resv = vm->page_directory->tbo.resv; |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 1093 | struct amdgpu_bo_list_entry *entry; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1094 | struct amdgpu_bo *pt; |
| 1095 | |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 1096 | entry = &vm->page_tables[pt_idx].entry; |
| 1097 | if (entry->robj) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1098 | continue; |
| 1099 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1100 | r = amdgpu_bo_create(adev, AMDGPU_VM_PTE_COUNT * 8, |
| 1101 | AMDGPU_GPU_PAGE_SIZE, true, |
Alex Deucher | 857d913 | 2015-08-27 00:14:16 -0400 | [diff] [blame] | 1102 | AMDGPU_GEM_DOMAIN_VRAM, |
| 1103 | AMDGPU_GEM_CREATE_NO_CPU_ACCESS, |
Christian König | bf60efd | 2015-09-04 10:47:56 +0200 | [diff] [blame] | 1104 | NULL, resv, &pt); |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1105 | if (r) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1106 | goto error_free; |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1107 | |
Christian König | 82b9c55 | 2015-11-27 16:49:00 +0100 | [diff] [blame] | 1108 | /* Keep a reference to the page table to avoid freeing |
| 1109 | * them up in the wrong order. |
| 1110 | */ |
| 1111 | pt->parent = amdgpu_bo_ref(vm->page_directory); |
| 1112 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1113 | r = amdgpu_vm_clear_bo(adev, pt); |
| 1114 | if (r) { |
| 1115 | amdgpu_bo_unref(&pt); |
| 1116 | goto error_free; |
| 1117 | } |
| 1118 | |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 1119 | entry->robj = pt; |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 1120 | entry->priority = 0; |
| 1121 | entry->tv.bo = &entry->robj->tbo; |
| 1122 | entry->tv.shared = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1123 | vm->page_tables[pt_idx].addr = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1126 | return 0; |
| 1127 | |
| 1128 | error_free: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1129 | list_del(&mapping->list); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1130 | spin_lock(&vm->it_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1131 | interval_tree_remove(&mapping->it, &vm->va); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1132 | spin_unlock(&vm->it_lock); |
Christian König | 93e3e43 | 2015-06-09 16:58:33 +0200 | [diff] [blame] | 1133 | trace_amdgpu_vm_bo_unmap(bo_va, mapping); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1134 | kfree(mapping); |
| 1135 | |
Chunming Zhou | f48b265 | 2015-10-16 14:06:19 +0800 | [diff] [blame] | 1136 | error: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1137 | return r; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * amdgpu_vm_bo_unmap - remove bo mapping from vm |
| 1142 | * |
| 1143 | * @adev: amdgpu_device pointer |
| 1144 | * @bo_va: bo_va to remove the address from |
| 1145 | * @saddr: where to the BO is mapped |
| 1146 | * |
| 1147 | * Remove a mapping of the BO at the specefied addr from the VM. |
| 1148 | * Returns 0 for success, error for failure. |
| 1149 | * |
Chunming Zhou | 49b02b1 | 2015-11-13 14:18:38 +0800 | [diff] [blame] | 1150 | * Object has to be reserved and unreserved outside! |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1151 | */ |
| 1152 | int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, |
| 1153 | struct amdgpu_bo_va *bo_va, |
| 1154 | uint64_t saddr) |
| 1155 | { |
| 1156 | struct amdgpu_bo_va_mapping *mapping; |
| 1157 | struct amdgpu_vm *vm = bo_va->vm; |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1158 | bool valid = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1159 | |
Christian König | 6c7fc50 | 2015-06-05 20:56:17 +0200 | [diff] [blame] | 1160 | saddr /= AMDGPU_GPU_PAGE_SIZE; |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1161 | mutex_lock(&bo_va->mutex); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1162 | list_for_each_entry(mapping, &bo_va->valids, list) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1163 | if (mapping->it.start == saddr) |
| 1164 | break; |
| 1165 | } |
| 1166 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1167 | if (&mapping->list == &bo_va->valids) { |
| 1168 | valid = false; |
| 1169 | |
| 1170 | list_for_each_entry(mapping, &bo_va->invalids, list) { |
| 1171 | if (mapping->it.start == saddr) |
| 1172 | break; |
| 1173 | } |
| 1174 | |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1175 | if (&mapping->list == &bo_va->invalids) { |
| 1176 | mutex_unlock(&bo_va->mutex); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1177 | return -ENOENT; |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1178 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1179 | } |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1180 | mutex_unlock(&bo_va->mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1181 | list_del(&mapping->list); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1182 | spin_lock(&vm->it_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1183 | interval_tree_remove(&mapping->it, &vm->va); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1184 | spin_unlock(&vm->it_lock); |
Christian König | 93e3e43 | 2015-06-09 16:58:33 +0200 | [diff] [blame] | 1185 | trace_amdgpu_vm_bo_unmap(bo_va, mapping); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1186 | |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1187 | if (valid) { |
| 1188 | spin_lock(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1189 | list_add(&mapping->list, &vm->freed); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1190 | spin_unlock(&vm->freed_lock); |
| 1191 | } else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1192 | kfree(mapping); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1193 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * amdgpu_vm_bo_rmv - remove a bo to a specific vm |
| 1200 | * |
| 1201 | * @adev: amdgpu_device pointer |
| 1202 | * @bo_va: requested bo_va |
| 1203 | * |
| 1204 | * Remove @bo_va->bo from the requested vm (cayman+). |
| 1205 | * |
| 1206 | * Object have to be reserved! |
| 1207 | */ |
| 1208 | void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, |
| 1209 | struct amdgpu_bo_va *bo_va) |
| 1210 | { |
| 1211 | struct amdgpu_bo_va_mapping *mapping, *next; |
| 1212 | struct amdgpu_vm *vm = bo_va->vm; |
| 1213 | |
| 1214 | list_del(&bo_va->bo_list); |
| 1215 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1216 | spin_lock(&vm->status_lock); |
| 1217 | list_del(&bo_va->vm_status); |
| 1218 | spin_unlock(&vm->status_lock); |
| 1219 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1220 | list_for_each_entry_safe(mapping, next, &bo_va->valids, list) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1221 | list_del(&mapping->list); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1222 | spin_lock(&vm->it_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1223 | interval_tree_remove(&mapping->it, &vm->va); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1224 | spin_unlock(&vm->it_lock); |
Christian König | 93e3e43 | 2015-06-09 16:58:33 +0200 | [diff] [blame] | 1225 | trace_amdgpu_vm_bo_unmap(bo_va, mapping); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1226 | spin_lock(&vm->freed_lock); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1227 | list_add(&mapping->list, &vm->freed); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1228 | spin_unlock(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1229 | } |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1230 | list_for_each_entry_safe(mapping, next, &bo_va->invalids, list) { |
| 1231 | list_del(&mapping->list); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1232 | spin_lock(&vm->it_lock); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1233 | interval_tree_remove(&mapping->it, &vm->va); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1234 | spin_unlock(&vm->it_lock); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1235 | kfree(mapping); |
| 1236 | } |
Chunming Zhou | bb1e38a4 | 2015-08-03 18:19:38 +0800 | [diff] [blame] | 1237 | fence_put(bo_va->last_pt_update); |
Chunming Zhou | 69b576a | 2015-11-18 11:17:39 +0800 | [diff] [blame] | 1238 | mutex_destroy(&bo_va->mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1239 | kfree(bo_va); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * amdgpu_vm_bo_invalidate - mark the bo as invalid |
| 1244 | * |
| 1245 | * @adev: amdgpu_device pointer |
| 1246 | * @vm: requested vm |
| 1247 | * @bo: amdgpu buffer object |
| 1248 | * |
| 1249 | * Mark @bo as invalid (cayman+). |
| 1250 | */ |
| 1251 | void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, |
| 1252 | struct amdgpu_bo *bo) |
| 1253 | { |
| 1254 | struct amdgpu_bo_va *bo_va; |
| 1255 | |
| 1256 | list_for_each_entry(bo_va, &bo->va, bo_list) { |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1257 | spin_lock(&bo_va->vm->status_lock); |
| 1258 | if (list_empty(&bo_va->vm_status)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1259 | list_add(&bo_va->vm_status, &bo_va->vm->invalidated); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1260 | spin_unlock(&bo_va->vm->status_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | /** |
| 1265 | * amdgpu_vm_init - initialize a vm instance |
| 1266 | * |
| 1267 | * @adev: amdgpu_device pointer |
| 1268 | * @vm: requested vm |
| 1269 | * |
| 1270 | * Init @vm fields (cayman+). |
| 1271 | */ |
| 1272 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) |
| 1273 | { |
| 1274 | const unsigned align = min(AMDGPU_VM_PTB_ALIGN_SIZE, |
| 1275 | AMDGPU_VM_PTE_COUNT * 8); |
Michel Dänzer | 9571e1d | 2016-01-19 17:59:46 +0900 | [diff] [blame] | 1276 | unsigned pd_size, pd_entries; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1277 | int i, r; |
| 1278 | |
| 1279 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 1280 | vm->ids[i].id = 0; |
| 1281 | vm->ids[i].flushed_updates = NULL; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1282 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1283 | vm->va = RB_ROOT; |
| 1284 | spin_lock_init(&vm->status_lock); |
| 1285 | INIT_LIST_HEAD(&vm->invalidated); |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 1286 | INIT_LIST_HEAD(&vm->cleared); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1287 | INIT_LIST_HEAD(&vm->freed); |
Chunming Zhou | c25867d | 2015-11-13 13:32:01 +0800 | [diff] [blame] | 1288 | spin_lock_init(&vm->it_lock); |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 1289 | spin_lock_init(&vm->freed_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1290 | pd_size = amdgpu_vm_directory_size(adev); |
| 1291 | pd_entries = amdgpu_vm_num_pdes(adev); |
| 1292 | |
| 1293 | /* allocate page table array */ |
Michel Dänzer | 9571e1d | 2016-01-19 17:59:46 +0900 | [diff] [blame] | 1294 | vm->page_tables = drm_calloc_large(pd_entries, sizeof(struct amdgpu_vm_pt)); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1295 | if (vm->page_tables == NULL) { |
| 1296 | DRM_ERROR("Cannot allocate memory for page table array\n"); |
| 1297 | return -ENOMEM; |
| 1298 | } |
| 1299 | |
Bas Nieuwenhuizen | 05906de | 2015-08-14 20:08:40 +0200 | [diff] [blame] | 1300 | vm->page_directory_fence = NULL; |
| 1301 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1302 | r = amdgpu_bo_create(adev, pd_size, align, true, |
Alex Deucher | 857d913 | 2015-08-27 00:14:16 -0400 | [diff] [blame] | 1303 | AMDGPU_GEM_DOMAIN_VRAM, |
| 1304 | AMDGPU_GEM_CREATE_NO_CPU_ACCESS, |
Christian König | 72d7668 | 2015-09-03 17:34:59 +0200 | [diff] [blame] | 1305 | NULL, NULL, &vm->page_directory); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1306 | if (r) |
| 1307 | return r; |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 1308 | r = amdgpu_bo_reserve(vm->page_directory, false); |
| 1309 | if (r) { |
| 1310 | amdgpu_bo_unref(&vm->page_directory); |
| 1311 | vm->page_directory = NULL; |
| 1312 | return r; |
| 1313 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1314 | r = amdgpu_vm_clear_bo(adev, vm->page_directory); |
Chunming Zhou | ef9f0a8 | 2015-11-13 13:43:22 +0800 | [diff] [blame] | 1315 | amdgpu_bo_unreserve(vm->page_directory); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1316 | if (r) { |
| 1317 | amdgpu_bo_unref(&vm->page_directory); |
| 1318 | vm->page_directory = NULL; |
| 1319 | return r; |
| 1320 | } |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * amdgpu_vm_fini - tear down a vm instance |
| 1327 | * |
| 1328 | * @adev: amdgpu_device pointer |
| 1329 | * @vm: requested vm |
| 1330 | * |
| 1331 | * Tear down @vm (cayman+). |
| 1332 | * Unbind the VM and remove all bos from the vm bo list |
| 1333 | */ |
| 1334 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) |
| 1335 | { |
| 1336 | struct amdgpu_bo_va_mapping *mapping, *tmp; |
| 1337 | int i; |
| 1338 | |
| 1339 | if (!RB_EMPTY_ROOT(&vm->va)) { |
| 1340 | dev_err(adev->dev, "still active bo inside vm\n"); |
| 1341 | } |
| 1342 | rbtree_postorder_for_each_entry_safe(mapping, tmp, &vm->va, it.rb) { |
| 1343 | list_del(&mapping->list); |
| 1344 | interval_tree_remove(&mapping->it, &vm->va); |
| 1345 | kfree(mapping); |
| 1346 | } |
| 1347 | list_for_each_entry_safe(mapping, tmp, &vm->freed, list) { |
| 1348 | list_del(&mapping->list); |
| 1349 | kfree(mapping); |
| 1350 | } |
| 1351 | |
| 1352 | for (i = 0; i < amdgpu_vm_num_pdes(adev); i++) |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 1353 | amdgpu_bo_unref(&vm->page_tables[i].entry.robj); |
Michel Dänzer | 9571e1d | 2016-01-19 17:59:46 +0900 | [diff] [blame] | 1354 | drm_free_large(vm->page_tables); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1355 | |
| 1356 | amdgpu_bo_unref(&vm->page_directory); |
Bas Nieuwenhuizen | 05906de | 2015-08-14 20:08:40 +0200 | [diff] [blame] | 1357 | fence_put(vm->page_directory_fence); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1358 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 1359 | unsigned id = vm->ids[i].id; |
| 1360 | |
| 1361 | atomic_long_cmpxchg(&adev->vm_manager.ids[id].owner, |
| 1362 | (long)vm, 0); |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 1363 | fence_put(vm->ids[i].flushed_updates); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1364 | } |
| 1365 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1366 | } |
Christian König | ea89f8c | 2015-11-15 20:52:06 +0100 | [diff] [blame] | 1367 | |
| 1368 | /** |
| 1369 | * amdgpu_vm_manager_fini - cleanup VM manager |
| 1370 | * |
| 1371 | * @adev: amdgpu_device pointer |
| 1372 | * |
| 1373 | * Cleanup the VM manager and free resources. |
| 1374 | */ |
| 1375 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev) |
| 1376 | { |
| 1377 | unsigned i; |
| 1378 | |
| 1379 | for (i = 0; i < AMDGPU_NUM_VM; ++i) |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 1380 | fence_put(adev->vm_manager.ids[i].active); |
Christian König | ea89f8c | 2015-11-15 20:52:06 +0100 | [diff] [blame] | 1381 | } |