blob: ae3b275f2a38ac22de2585d347efb3b406aa827d [file] [log] [blame]
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001/*
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 */
60static 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 */
72static 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önig56467eb2015-12-11 15:16:32 +010078 * amdgpu_vm_get_pd_bo - add the VM PD to a validation list
Alex Deucherd38ceaf2015-04-20 16:55:21 -040079 *
80 * @vm: vm providing the BOs
Christian König3c0eea62015-12-11 14:39:05 +010081 * @validated: head of validation list
Christian König56467eb2015-12-11 15:16:32 +010082 * @entry: entry to add
Alex Deucherd38ceaf2015-04-20 16:55:21 -040083 *
84 * Add the page directory to the list of BOs to
Christian König56467eb2015-12-11 15:16:32 +010085 * validate for command submission.
Alex Deucherd38ceaf2015-04-20 16:55:21 -040086 */
Christian König56467eb2015-12-11 15:16:32 +010087void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
88 struct list_head *validated,
89 struct amdgpu_bo_list_entry *entry)
Alex Deucherd38ceaf2015-04-20 16:55:21 -040090{
Christian König56467eb2015-12-11 15:16:32 +010091 entry->robj = vm->page_directory;
Christian König56467eb2015-12-11 15:16:32 +010092 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 Deucherd38ceaf2015-04-20 16:55:21 -040097
Christian König56467eb2015-12-11 15:16:32 +010098/**
Christian Königee1782c2015-12-11 21:01:23 +010099 * amdgpu_vm_get_bos - add the vm BOs to a duplicates list
Christian König56467eb2015-12-11 15:16:32 +0100100 *
101 * @vm: vm providing the BOs
Christian König3c0eea62015-12-11 14:39:05 +0100102 * @duplicates: head of duplicates list
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400103 *
Christian Königee1782c2015-12-11 21:01:23 +0100104 * Add the page directory to the BO duplicates list
105 * for command submission.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400106 */
Christian Königee1782c2015-12-11 21:01:23 +0100107void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400108{
Christian Königee1782c2015-12-11 21:01:23 +0100109 unsigned i;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400110
111 /* add the vm page table to the list */
Christian Königee1782c2015-12-11 21:01:23 +0100112 for (i = 0; i <= vm->max_pde_used; ++i) {
113 struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400114
Christian Königee1782c2015-12-11 21:01:23 +0100115 if (!entry->robj)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400116 continue;
117
Christian Königee1782c2015-12-11 21:01:23 +0100118 list_add(&entry->tv.head, duplicates);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400119 }
Christian Königeceb8a12016-01-11 15:35:21 +0100120
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 */
131void 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 Deucherd38ceaf2015-04-20 16:55:21 -0400147}
148
149/**
150 * amdgpu_vm_grab_id - allocate the next free VMID
151 *
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400152 * @vm: vm to allocate id for
Christian König7f8a5292015-07-20 16:09:40 +0200153 * @ring: ring we want to submit job to
154 * @sync: sync object where we add dependencies
Christian König94dd0a42016-01-18 17:01:42 +0100155 * @fence: fence protecting ID from reuse
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400156 *
Christian König7f8a5292015-07-20 16:09:40 +0200157 * Allocate an id for the vm, adding fences to the sync obj as necessary.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400158 *
Christian König7f8a5292015-07-20 16:09:40 +0200159 * Global mutex must be locked!
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400160 */
Christian König7f8a5292015-07-20 16:09:40 +0200161int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König94dd0a42016-01-18 17:01:42 +0100162 struct amdgpu_sync *sync, struct fence *fence)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400163{
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400164 struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx];
165 struct amdgpu_device *adev = ring->adev;
Christian Königa9a78b32016-01-21 10:19:11 +0100166 struct amdgpu_vm_manager_id *id;
167 int r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400168
Christian König94dd0a42016-01-18 17:01:42 +0100169 mutex_lock(&adev->vm_manager.lock);
170
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400171 /* check if the id is still valid */
Christian König1c16c0a2015-11-14 21:31:40 +0100172 if (vm_id->id) {
Christian König1c16c0a2015-11-14 21:31:40 +0100173 long owner;
174
Christian Königa9a78b32016-01-21 10:19:11 +0100175 id = &adev->vm_manager.ids[vm_id->id];
176 owner = atomic_long_read(&id->owner);
Christian König1c16c0a2015-11-14 21:31:40 +0100177 if (owner == (long)vm) {
Christian Königa9a78b32016-01-21 10:19:11 +0100178 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
Christian König165e4e02016-01-07 18:15:22 +0100179 trace_amdgpu_vm_grab_id(vm, vm_id->id, ring->idx);
Christian Königa9a78b32016-01-21 10:19:11 +0100180
181 fence_put(id->active);
182 id->active = fence_get(fence);
183
Christian König94dd0a42016-01-18 17:01:42 +0100184 mutex_unlock(&adev->vm_manager.lock);
Christian König1c16c0a2015-11-14 21:31:40 +0100185 return 0;
186 }
Christian König39ff8442015-09-28 12:01:20 +0200187 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400188
189 /* we definately need to flush */
190 vm_id->pd_gpu_addr = ~0ll;
191
Christian Königa9a78b32016-01-21 10:19:11 +0100192 id = list_first_entry(&adev->vm_manager.ids_lru,
193 struct amdgpu_vm_manager_id,
194 list);
195 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
196 atomic_long_set(&id->owner, (long)vm);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400197
Christian Königa9a78b32016-01-21 10:19:11 +0100198 vm_id->id = id - adev->vm_manager.ids;
199 trace_amdgpu_vm_grab_id(vm, vm_id->id, ring->idx);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400200
Christian Königa9a78b32016-01-21 10:19:11 +0100201 r = amdgpu_sync_fence(ring->adev, sync, id->active);
202
203 if (!r) {
204 fence_put(id->active);
205 id->active = fence_get(fence);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400206 }
207
Christian König94dd0a42016-01-18 17:01:42 +0100208 mutex_unlock(&adev->vm_manager.lock);
Christian Königa9a78b32016-01-21 10:19:11 +0100209 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400210}
211
212/**
213 * amdgpu_vm_flush - hardware flush the vm
214 *
215 * @ring: ring to use for flush
216 * @vm: vm we want to flush
217 * @updates: last vm update that we waited for
218 *
219 * Flush the vm (cayman+).
220 *
221 * Global and local mutex must be locked!
222 */
223void amdgpu_vm_flush(struct amdgpu_ring *ring,
224 struct amdgpu_vm *vm,
Chunming Zhou3c623382015-08-20 18:33:59 +0800225 struct fence *updates)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400226{
227 uint64_t pd_addr = amdgpu_bo_gpu_offset(vm->page_directory);
228 struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx];
Chunming Zhou3c623382015-08-20 18:33:59 +0800229 struct fence *flushed_updates = vm_id->flushed_updates;
Christian Königb56c2282015-10-29 17:01:19 +0100230 bool is_later;
Chunming Zhou3c623382015-08-20 18:33:59 +0800231
Christian Königb56c2282015-10-29 17:01:19 +0100232 if (!flushed_updates)
233 is_later = true;
234 else if (!updates)
235 is_later = false;
236 else
237 is_later = fence_is_later(updates, flushed_updates);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400238
Christian Königb56c2282015-10-29 17:01:19 +0100239 if (pd_addr != vm_id->pd_gpu_addr || is_later) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400240 trace_amdgpu_vm_flush(pd_addr, ring->idx, vm_id->id);
Christian Königb56c2282015-10-29 17:01:19 +0100241 if (is_later) {
Chunming Zhou3c623382015-08-20 18:33:59 +0800242 vm_id->flushed_updates = fence_get(updates);
243 fence_put(flushed_updates);
244 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400245 vm_id->pd_gpu_addr = pd_addr;
246 amdgpu_ring_emit_vm_flush(ring, vm_id->id, vm_id->pd_gpu_addr);
247 }
248}
249
250/**
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400251 * amdgpu_vm_bo_find - find the bo_va for a specific vm & bo
252 *
253 * @vm: requested vm
254 * @bo: requested buffer object
255 *
256 * Find @bo inside the requested vm (cayman+).
257 * Search inside the @bos vm list for the requested vm
258 * Returns the found bo_va or NULL if none is found
259 *
260 * Object has to be reserved!
261 */
262struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
263 struct amdgpu_bo *bo)
264{
265 struct amdgpu_bo_va *bo_va;
266
267 list_for_each_entry(bo_va, &bo->va, bo_list) {
268 if (bo_va->vm == vm) {
269 return bo_va;
270 }
271 }
272 return NULL;
273}
274
275/**
276 * amdgpu_vm_update_pages - helper to call the right asic function
277 *
278 * @adev: amdgpu_device pointer
279 * @ib: indirect buffer to fill with commands
280 * @pe: addr of the page entry
281 * @addr: dst addr to write into pe
282 * @count: number of page entries to update
283 * @incr: increase next addr by incr bytes
284 * @flags: hw access flags
285 * @gtt_flags: GTT hw access flags
286 *
287 * Traces the parameters and calls the right asic functions
288 * to setup the page table using the DMA.
289 */
290static void amdgpu_vm_update_pages(struct amdgpu_device *adev,
291 struct amdgpu_ib *ib,
292 uint64_t pe, uint64_t addr,
293 unsigned count, uint32_t incr,
294 uint32_t flags, uint32_t gtt_flags)
295{
296 trace_amdgpu_vm_set_page(pe, addr, count, incr, flags);
297
298 if ((flags & AMDGPU_PTE_SYSTEM) && (flags == gtt_flags)) {
299 uint64_t src = adev->gart.table_addr + (addr >> 12) * 8;
300 amdgpu_vm_copy_pte(adev, ib, pe, src, count);
301
Christian Königb07c9d22015-11-30 13:26:07 +0100302 } else if (flags & AMDGPU_PTE_SYSTEM) {
303 dma_addr_t *pages_addr = adev->gart.pages_addr;
304 amdgpu_vm_write_pte(adev, ib, pages_addr, pe, addr,
305 count, incr, flags);
306
307 } else if (count < 3) {
308 amdgpu_vm_write_pte(adev, ib, NULL, pe, addr,
309 count, incr, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400310
311 } else {
312 amdgpu_vm_set_pte_pde(adev, ib, pe, addr,
313 count, incr, flags);
314 }
315}
316
Junwei Zhang4c7eb912015-09-09 09:05:55 +0800317int amdgpu_vm_free_job(struct amdgpu_job *job)
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800318{
319 int i;
Junwei Zhang4c7eb912015-09-09 09:05:55 +0800320 for (i = 0; i < job->num_ibs; i++)
321 amdgpu_ib_free(job->adev, &job->ibs[i]);
322 kfree(job->ibs);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800323 return 0;
324}
325
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400326/**
327 * amdgpu_vm_clear_bo - initially clear the page dir/table
328 *
329 * @adev: amdgpu_device pointer
330 * @bo: bo to clear
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800331 *
332 * need to reserve bo first before calling it.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400333 */
334static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
335 struct amdgpu_bo *bo)
336{
337 struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800338 struct fence *fence = NULL;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800339 struct amdgpu_ib *ib;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400340 unsigned entries;
341 uint64_t addr;
342 int r;
343
monk.liuca952612015-05-25 14:44:05 +0800344 r = reservation_object_reserve_shared(bo->tbo.resv);
345 if (r)
346 return r;
347
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400348 r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
349 if (r)
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800350 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400351
352 addr = amdgpu_bo_gpu_offset(bo);
353 entries = amdgpu_bo_size(bo) / 8;
354
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800355 ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL);
356 if (!ib)
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800357 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400358
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800359 r = amdgpu_ib_get(ring, NULL, entries * 2 + 64, ib);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400360 if (r)
361 goto error_free;
362
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800363 ib->length_dw = 0;
364
365 amdgpu_vm_update_pages(adev, ib, addr, 0, entries, 0, 0, 0);
366 amdgpu_vm_pad_ib(adev, ib);
367 WARN_ON(ib->length_dw > 64);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800368 r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1,
369 &amdgpu_vm_free_job,
370 AMDGPU_FENCE_OWNER_VM,
371 &fence);
372 if (!r)
373 amdgpu_bo_fence(bo, fence, true);
Chunming Zhou281b4222015-08-12 12:58:31 +0800374 fence_put(fence);
Chunming Zhoucadf97b2016-01-15 11:25:00 +0800375 return 0;
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800376
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400377error_free:
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800378 amdgpu_ib_free(adev, ib);
379 kfree(ib);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400380
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800381error:
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400382 return r;
383}
384
385/**
Christian Königb07c9d22015-11-30 13:26:07 +0100386 * amdgpu_vm_map_gart - Resolve gart mapping of addr
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400387 *
Christian Königb07c9d22015-11-30 13:26:07 +0100388 * @pages_addr: optional DMA address to use for lookup
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400389 * @addr: the unmapped addr
390 *
391 * Look up the physical address of the page that the pte resolves
Christian Königb07c9d22015-11-30 13:26:07 +0100392 * to and return the pointer for the page table entry.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400393 */
Christian Königb07c9d22015-11-30 13:26:07 +0100394uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400395{
396 uint64_t result;
397
Christian Königb07c9d22015-11-30 13:26:07 +0100398 if (pages_addr) {
399 /* page table offset */
400 result = pages_addr[addr >> PAGE_SHIFT];
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400401
Christian Königb07c9d22015-11-30 13:26:07 +0100402 /* in case cpu page size != gpu page size*/
403 result |= addr & (~PAGE_MASK);
404
405 } else {
406 /* No mapping required */
407 result = addr;
408 }
409
410 result &= 0xFFFFFFFFFFFFF000ULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400411
412 return result;
413}
414
415/**
416 * amdgpu_vm_update_pdes - make sure that page directory is valid
417 *
418 * @adev: amdgpu_device pointer
419 * @vm: requested vm
420 * @start: start of GPU address range
421 * @end: end of GPU address range
422 *
423 * Allocates new page tables if necessary
424 * and updates the page directory (cayman+).
425 * Returns 0 for success, error for failure.
426 *
427 * Global and local mutex must be locked!
428 */
429int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
430 struct amdgpu_vm *vm)
431{
432 struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring;
433 struct amdgpu_bo *pd = vm->page_directory;
434 uint64_t pd_addr = amdgpu_bo_gpu_offset(pd);
435 uint32_t incr = AMDGPU_VM_PTE_COUNT * 8;
436 uint64_t last_pde = ~0, last_pt = ~0;
437 unsigned count = 0, pt_idx, ndw;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800438 struct amdgpu_ib *ib;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800439 struct fence *fence = NULL;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800440
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400441 int r;
442
443 /* padding, etc. */
444 ndw = 64;
445
446 /* assume the worst case */
447 ndw += vm->max_pde_used * 6;
448
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800449 ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL);
450 if (!ib)
451 return -ENOMEM;
452
453 r = amdgpu_ib_get(ring, NULL, ndw * 4, ib);
Sudip Mukherjee7a574552015-10-08 19:28:01 +0530454 if (r) {
455 kfree(ib);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400456 return r;
Sudip Mukherjee7a574552015-10-08 19:28:01 +0530457 }
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800458 ib->length_dw = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400459
460 /* walk over the address space and update the page directory */
461 for (pt_idx = 0; pt_idx <= vm->max_pde_used; ++pt_idx) {
Christian Königee1782c2015-12-11 21:01:23 +0100462 struct amdgpu_bo *bo = vm->page_tables[pt_idx].entry.robj;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400463 uint64_t pde, pt;
464
465 if (bo == NULL)
466 continue;
467
468 pt = amdgpu_bo_gpu_offset(bo);
469 if (vm->page_tables[pt_idx].addr == pt)
470 continue;
471 vm->page_tables[pt_idx].addr = pt;
472
473 pde = pd_addr + pt_idx * 8;
474 if (((last_pde + 8 * count) != pde) ||
475 ((last_pt + incr * count) != pt)) {
476
477 if (count) {
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800478 amdgpu_vm_update_pages(adev, ib, last_pde,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400479 last_pt, count, incr,
480 AMDGPU_PTE_VALID, 0);
481 }
482
483 count = 1;
484 last_pde = pde;
485 last_pt = pt;
486 } else {
487 ++count;
488 }
489 }
490
491 if (count)
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800492 amdgpu_vm_update_pages(adev, ib, last_pde, last_pt, count,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400493 incr, AMDGPU_PTE_VALID, 0);
494
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800495 if (ib->length_dw != 0) {
496 amdgpu_vm_pad_ib(adev, ib);
497 amdgpu_sync_resv(adev, &ib->sync, pd->tbo.resv, AMDGPU_FENCE_OWNER_VM);
498 WARN_ON(ib->length_dw > ndw);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800499 r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1,
500 &amdgpu_vm_free_job,
501 AMDGPU_FENCE_OWNER_VM,
502 &fence);
503 if (r)
504 goto error_free;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200505
Chunming Zhou4af9f072015-08-03 12:57:31 +0800506 amdgpu_bo_fence(pd, fence, true);
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200507 fence_put(vm->page_directory_fence);
508 vm->page_directory_fence = fence_get(fence);
Chunming Zhou281b4222015-08-12 12:58:31 +0800509 fence_put(fence);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400510 }
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800511
Chunming Zhoucadf97b2016-01-15 11:25:00 +0800512 if (ib->length_dw == 0) {
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800513 amdgpu_ib_free(adev, ib);
514 kfree(ib);
515 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400516
517 return 0;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800518
519error_free:
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800520 amdgpu_ib_free(adev, ib);
521 kfree(ib);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800522 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400523}
524
525/**
526 * amdgpu_vm_frag_ptes - add fragment information to PTEs
527 *
528 * @adev: amdgpu_device pointer
529 * @ib: IB for the update
530 * @pe_start: first PTE to handle
531 * @pe_end: last PTE to handle
532 * @addr: addr those PTEs should point to
533 * @flags: hw mapping flags
534 * @gtt_flags: GTT hw mapping flags
535 *
536 * Global and local mutex must be locked!
537 */
538static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
539 struct amdgpu_ib *ib,
540 uint64_t pe_start, uint64_t pe_end,
541 uint64_t addr, uint32_t flags,
542 uint32_t gtt_flags)
543{
544 /**
545 * The MC L1 TLB supports variable sized pages, based on a fragment
546 * field in the PTE. When this field is set to a non-zero value, page
547 * granularity is increased from 4KB to (1 << (12 + frag)). The PTE
548 * flags are considered valid for all PTEs within the fragment range
549 * and corresponding mappings are assumed to be physically contiguous.
550 *
551 * The L1 TLB can store a single PTE for the whole fragment,
552 * significantly increasing the space available for translation
553 * caching. This leads to large improvements in throughput when the
554 * TLB is under pressure.
555 *
556 * The L2 TLB distributes small and large fragments into two
557 * asymmetric partitions. The large fragment cache is significantly
558 * larger. Thus, we try to use large fragments wherever possible.
559 * Userspace can support this by aligning virtual base address and
560 * allocation size to the fragment size.
561 */
562
563 /* SI and newer are optimized for 64KB */
564 uint64_t frag_flags = AMDGPU_PTE_FRAG_64KB;
565 uint64_t frag_align = 0x80;
566
567 uint64_t frag_start = ALIGN(pe_start, frag_align);
568 uint64_t frag_end = pe_end & ~(frag_align - 1);
569
570 unsigned count;
571
572 /* system pages are non continuously */
573 if ((flags & AMDGPU_PTE_SYSTEM) || !(flags & AMDGPU_PTE_VALID) ||
574 (frag_start >= frag_end)) {
575
576 count = (pe_end - pe_start) / 8;
577 amdgpu_vm_update_pages(adev, ib, pe_start, addr, count,
578 AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags);
579 return;
580 }
581
582 /* handle the 4K area at the beginning */
583 if (pe_start != frag_start) {
584 count = (frag_start - pe_start) / 8;
585 amdgpu_vm_update_pages(adev, ib, pe_start, addr, count,
586 AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags);
587 addr += AMDGPU_GPU_PAGE_SIZE * count;
588 }
589
590 /* handle the area in the middle */
591 count = (frag_end - frag_start) / 8;
592 amdgpu_vm_update_pages(adev, ib, frag_start, addr, count,
593 AMDGPU_GPU_PAGE_SIZE, flags | frag_flags,
594 gtt_flags);
595
596 /* handle the 4K area at the end */
597 if (frag_end != pe_end) {
598 addr += AMDGPU_GPU_PAGE_SIZE * count;
599 count = (pe_end - frag_end) / 8;
600 amdgpu_vm_update_pages(adev, ib, frag_end, addr, count,
601 AMDGPU_GPU_PAGE_SIZE, flags, gtt_flags);
602 }
603}
604
605/**
606 * amdgpu_vm_update_ptes - make sure that page tables are valid
607 *
608 * @adev: amdgpu_device pointer
609 * @vm: requested vm
610 * @start: start of GPU address range
611 * @end: end of GPU address range
612 * @dst: destination address to map to
613 * @flags: mapping flags
614 *
615 * Update the page tables in the range @start - @end (cayman+).
616 *
617 * Global and local mutex must be locked!
618 */
619static int amdgpu_vm_update_ptes(struct amdgpu_device *adev,
620 struct amdgpu_vm *vm,
621 struct amdgpu_ib *ib,
622 uint64_t start, uint64_t end,
623 uint64_t dst, uint32_t flags,
624 uint32_t gtt_flags)
625{
626 uint64_t mask = AMDGPU_VM_PTE_COUNT - 1;
627 uint64_t last_pte = ~0, last_dst = ~0;
Christian Königa60c4232015-09-01 15:33:25 +0200628 void *owner = AMDGPU_FENCE_OWNER_VM;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400629 unsigned count = 0;
630 uint64_t addr;
631
Christian Königa60c4232015-09-01 15:33:25 +0200632 /* sync to everything on unmapping */
633 if (!(flags & AMDGPU_PTE_VALID))
634 owner = AMDGPU_FENCE_OWNER_UNDEFINED;
635
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400636 /* walk over the address space and update the page tables */
637 for (addr = start; addr < end; ) {
638 uint64_t pt_idx = addr >> amdgpu_vm_block_size;
Christian Königee1782c2015-12-11 21:01:23 +0100639 struct amdgpu_bo *pt = vm->page_tables[pt_idx].entry.robj;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400640 unsigned nptes;
641 uint64_t pte;
642 int r;
643
Christian Königa60c4232015-09-01 15:33:25 +0200644 amdgpu_sync_resv(adev, &ib->sync, pt->tbo.resv, owner);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400645 r = reservation_object_reserve_shared(pt->tbo.resv);
646 if (r)
647 return r;
648
649 if ((addr & ~mask) == (end & ~mask))
650 nptes = end - addr;
651 else
652 nptes = AMDGPU_VM_PTE_COUNT - (addr & mask);
653
654 pte = amdgpu_bo_gpu_offset(pt);
655 pte += (addr & mask) * 8;
656
657 if ((last_pte + 8 * count) != pte) {
658
659 if (count) {
660 amdgpu_vm_frag_ptes(adev, ib, last_pte,
661 last_pte + 8 * count,
662 last_dst, flags,
663 gtt_flags);
664 }
665
666 count = nptes;
667 last_pte = pte;
668 last_dst = dst;
669 } else {
670 count += nptes;
671 }
672
673 addr += nptes;
674 dst += nptes * AMDGPU_GPU_PAGE_SIZE;
675 }
676
677 if (count) {
678 amdgpu_vm_frag_ptes(adev, ib, last_pte,
679 last_pte + 8 * count,
680 last_dst, flags, gtt_flags);
681 }
682
683 return 0;
684}
685
686/**
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400687 * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table
688 *
689 * @adev: amdgpu_device pointer
690 * @vm: requested vm
691 * @mapping: mapped range and flags to use for the update
692 * @addr: addr to set the area to
693 * @gtt_flags: flags as they are used for GTT
694 * @fence: optional resulting fence
695 *
696 * Fill in the page table entries for @mapping.
697 * Returns 0 for success, -EINVAL for failure.
698 *
699 * Object have to be reserved and mutex must be locked!
700 */
701static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
702 struct amdgpu_vm *vm,
703 struct amdgpu_bo_va_mapping *mapping,
704 uint64_t addr, uint32_t gtt_flags,
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800705 struct fence **fence)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400706{
707 struct amdgpu_ring *ring = adev->vm_manager.vm_pte_funcs_ring;
708 unsigned nptes, ncmds, ndw;
709 uint32_t flags = gtt_flags;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800710 struct amdgpu_ib *ib;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800711 struct fence *f = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400712 int r;
713
714 /* normally,bo_va->flags only contians READABLE and WIRTEABLE bit go here
715 * but in case of something, we filter the flags in first place
716 */
717 if (!(mapping->flags & AMDGPU_PTE_READABLE))
718 flags &= ~AMDGPU_PTE_READABLE;
719 if (!(mapping->flags & AMDGPU_PTE_WRITEABLE))
720 flags &= ~AMDGPU_PTE_WRITEABLE;
721
722 trace_amdgpu_vm_bo_update(mapping);
723
724 nptes = mapping->it.last - mapping->it.start + 1;
725
726 /*
727 * reserve space for one command every (1 << BLOCK_SIZE)
728 * entries or 2k dwords (whatever is smaller)
729 */
730 ncmds = (nptes >> min(amdgpu_vm_block_size, 11)) + 1;
731
732 /* padding, etc. */
733 ndw = 64;
734
735 if ((flags & AMDGPU_PTE_SYSTEM) && (flags == gtt_flags)) {
736 /* only copy commands needed */
737 ndw += ncmds * 7;
738
739 } else if (flags & AMDGPU_PTE_SYSTEM) {
740 /* header for write data commands */
741 ndw += ncmds * 4;
742
743 /* body of write data command */
744 ndw += nptes * 2;
745
746 } else {
747 /* set page commands needed */
748 ndw += ncmds * 10;
749
750 /* two extra commands for begin/end of fragment */
751 ndw += 2 * 10;
752 }
753
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800754 ib = kzalloc(sizeof(struct amdgpu_ib), GFP_KERNEL);
755 if (!ib)
756 return -ENOMEM;
757
758 r = amdgpu_ib_get(ring, NULL, ndw * 4, ib);
759 if (r) {
760 kfree(ib);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400761 return r;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800762 }
763
764 ib->length_dw = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400765
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800766 r = amdgpu_vm_update_ptes(adev, vm, ib, mapping->it.start,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400767 mapping->it.last + 1, addr + mapping->offset,
768 flags, gtt_flags);
769
770 if (r) {
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800771 amdgpu_ib_free(adev, ib);
772 kfree(ib);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400773 return r;
774 }
775
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800776 amdgpu_vm_pad_ib(adev, ib);
777 WARN_ON(ib->length_dw > ndw);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800778 r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1,
779 &amdgpu_vm_free_job,
780 AMDGPU_FENCE_OWNER_VM,
781 &f);
782 if (r)
783 goto error_free;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400784
Christian Königbf60efd2015-09-04 10:47:56 +0200785 amdgpu_bo_fence(vm->page_directory, f, true);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800786 if (fence) {
787 fence_put(*fence);
788 *fence = fence_get(f);
789 }
Chunming Zhou281b4222015-08-12 12:58:31 +0800790 fence_put(f);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400791 return 0;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800792
793error_free:
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800794 amdgpu_ib_free(adev, ib);
795 kfree(ib);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800796 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400797}
798
799/**
800 * amdgpu_vm_bo_update - update all BO mappings in the vm page table
801 *
802 * @adev: amdgpu_device pointer
803 * @bo_va: requested BO and VM object
804 * @mem: ttm mem
805 *
806 * Fill in the page table entries for @bo_va.
807 * Returns 0 for success, -EINVAL for failure.
808 *
809 * Object have to be reserved and mutex must be locked!
810 */
811int amdgpu_vm_bo_update(struct amdgpu_device *adev,
812 struct amdgpu_bo_va *bo_va,
813 struct ttm_mem_reg *mem)
814{
815 struct amdgpu_vm *vm = bo_va->vm;
816 struct amdgpu_bo_va_mapping *mapping;
817 uint32_t flags;
818 uint64_t addr;
819 int r;
820
821 if (mem) {
Christian Königb7d698d2015-09-07 12:32:09 +0200822 addr = (u64)mem->start << PAGE_SHIFT;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400823 if (mem->mem_type != TTM_PL_TT)
824 addr += adev->vm_manager.vram_base_offset;
825 } else {
826 addr = 0;
827 }
828
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400829 flags = amdgpu_ttm_tt_pte_flags(adev, bo_va->bo->tbo.ttm, mem);
830
Christian König7fc11952015-07-30 11:53:42 +0200831 spin_lock(&vm->status_lock);
832 if (!list_empty(&bo_va->vm_status))
833 list_splice_init(&bo_va->valids, &bo_va->invalids);
834 spin_unlock(&vm->status_lock);
835
836 list_for_each_entry(mapping, &bo_va->invalids, list) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400837 r = amdgpu_vm_bo_update_mapping(adev, vm, mapping, addr,
838 flags, &bo_va->last_pt_update);
839 if (r)
840 return r;
841 }
842
Christian Königd6c10f62015-09-28 12:00:23 +0200843 if (trace_amdgpu_vm_bo_mapping_enabled()) {
844 list_for_each_entry(mapping, &bo_va->valids, list)
845 trace_amdgpu_vm_bo_mapping(mapping);
846
847 list_for_each_entry(mapping, &bo_va->invalids, list)
848 trace_amdgpu_vm_bo_mapping(mapping);
849 }
850
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400851 spin_lock(&vm->status_lock);
monk.liu6d1d0ef2015-08-14 13:36:41 +0800852 list_splice_init(&bo_va->invalids, &bo_va->valids);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400853 list_del_init(&bo_va->vm_status);
Christian König7fc11952015-07-30 11:53:42 +0200854 if (!mem)
855 list_add(&bo_va->vm_status, &vm->cleared);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400856 spin_unlock(&vm->status_lock);
857
858 return 0;
859}
860
861/**
862 * amdgpu_vm_clear_freed - clear freed BOs in the PT
863 *
864 * @adev: amdgpu_device pointer
865 * @vm: requested vm
866 *
867 * Make sure all freed BOs are cleared in the PT.
868 * Returns 0 for success.
869 *
870 * PTs have to be reserved and mutex must be locked!
871 */
872int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
873 struct amdgpu_vm *vm)
874{
875 struct amdgpu_bo_va_mapping *mapping;
876 int r;
877
jimqu81d75a32015-12-04 17:17:00 +0800878 spin_lock(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400879 while (!list_empty(&vm->freed)) {
880 mapping = list_first_entry(&vm->freed,
881 struct amdgpu_bo_va_mapping, list);
882 list_del(&mapping->list);
jimqu81d75a32015-12-04 17:17:00 +0800883 spin_unlock(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400884 r = amdgpu_vm_bo_update_mapping(adev, vm, mapping, 0, 0, NULL);
885 kfree(mapping);
886 if (r)
887 return r;
888
jimqu81d75a32015-12-04 17:17:00 +0800889 spin_lock(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400890 }
jimqu81d75a32015-12-04 17:17:00 +0800891 spin_unlock(&vm->freed_lock);
892
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400893 return 0;
894
895}
896
897/**
898 * amdgpu_vm_clear_invalids - clear invalidated BOs in the PT
899 *
900 * @adev: amdgpu_device pointer
901 * @vm: requested vm
902 *
903 * Make sure all invalidated BOs are cleared in the PT.
904 * Returns 0 for success.
905 *
906 * PTs have to be reserved and mutex must be locked!
907 */
908int amdgpu_vm_clear_invalids(struct amdgpu_device *adev,
monk.liucfe2c972015-05-26 15:01:54 +0800909 struct amdgpu_vm *vm, struct amdgpu_sync *sync)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400910{
monk.liucfe2c972015-05-26 15:01:54 +0800911 struct amdgpu_bo_va *bo_va = NULL;
Christian König91e1a522015-07-06 22:06:40 +0200912 int r = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400913
914 spin_lock(&vm->status_lock);
915 while (!list_empty(&vm->invalidated)) {
916 bo_va = list_first_entry(&vm->invalidated,
917 struct amdgpu_bo_va, vm_status);
918 spin_unlock(&vm->status_lock);
Chunming Zhou69b576a2015-11-18 11:17:39 +0800919 mutex_lock(&bo_va->mutex);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400920 r = amdgpu_vm_bo_update(adev, bo_va, NULL);
Chunming Zhou69b576a2015-11-18 11:17:39 +0800921 mutex_unlock(&bo_va->mutex);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400922 if (r)
923 return r;
924
925 spin_lock(&vm->status_lock);
926 }
927 spin_unlock(&vm->status_lock);
928
monk.liucfe2c972015-05-26 15:01:54 +0800929 if (bo_va)
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800930 r = amdgpu_sync_fence(adev, sync, bo_va->last_pt_update);
Christian König91e1a522015-07-06 22:06:40 +0200931
932 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400933}
934
935/**
936 * amdgpu_vm_bo_add - add a bo to a specific vm
937 *
938 * @adev: amdgpu_device pointer
939 * @vm: requested vm
940 * @bo: amdgpu buffer object
941 *
942 * Add @bo into the requested vm (cayman+).
943 * Add @bo to the list of bos associated with the vm
944 * Returns newly added bo_va or NULL for failure
945 *
946 * Object has to be reserved!
947 */
948struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
949 struct amdgpu_vm *vm,
950 struct amdgpu_bo *bo)
951{
952 struct amdgpu_bo_va *bo_va;
953
954 bo_va = kzalloc(sizeof(struct amdgpu_bo_va), GFP_KERNEL);
955 if (bo_va == NULL) {
956 return NULL;
957 }
958 bo_va->vm = vm;
959 bo_va->bo = bo;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400960 bo_va->ref_count = 1;
961 INIT_LIST_HEAD(&bo_va->bo_list);
Christian König7fc11952015-07-30 11:53:42 +0200962 INIT_LIST_HEAD(&bo_va->valids);
963 INIT_LIST_HEAD(&bo_va->invalids);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400964 INIT_LIST_HEAD(&bo_va->vm_status);
Chunming Zhou69b576a2015-11-18 11:17:39 +0800965 mutex_init(&bo_va->mutex);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400966 list_add_tail(&bo_va->bo_list, &bo->va);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400967
968 return bo_va;
969}
970
971/**
972 * amdgpu_vm_bo_map - map bo inside a vm
973 *
974 * @adev: amdgpu_device pointer
975 * @bo_va: bo_va to store the address
976 * @saddr: where to map the BO
977 * @offset: requested offset in the BO
978 * @flags: attributes of pages (read/write/valid/etc.)
979 *
980 * Add a mapping of the BO at the specefied addr into the VM.
981 * Returns 0 for success, error for failure.
982 *
Chunming Zhou49b02b12015-11-13 14:18:38 +0800983 * Object has to be reserved and unreserved outside!
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400984 */
985int amdgpu_vm_bo_map(struct amdgpu_device *adev,
986 struct amdgpu_bo_va *bo_va,
987 uint64_t saddr, uint64_t offset,
988 uint64_t size, uint32_t flags)
989{
990 struct amdgpu_bo_va_mapping *mapping;
991 struct amdgpu_vm *vm = bo_va->vm;
992 struct interval_tree_node *it;
993 unsigned last_pfn, pt_idx;
994 uint64_t eaddr;
995 int r;
996
Christian König0be52de2015-05-18 14:37:27 +0200997 /* validate the parameters */
998 if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK ||
Chunming Zhou49b02b12015-11-13 14:18:38 +0800999 size == 0 || size & AMDGPU_GPU_PAGE_MASK)
Christian König0be52de2015-05-18 14:37:27 +02001000 return -EINVAL;
Christian König0be52de2015-05-18 14:37:27 +02001001
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001002 /* make sure object fit at this offset */
Felix Kuehling005ae952015-11-23 17:43:48 -05001003 eaddr = saddr + size - 1;
Chunming Zhou49b02b12015-11-13 14:18:38 +08001004 if ((saddr >= eaddr) || (offset + size > amdgpu_bo_size(bo_va->bo)))
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001005 return -EINVAL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001006
1007 last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
Felix Kuehling005ae952015-11-23 17:43:48 -05001008 if (last_pfn >= adev->vm_manager.max_pfn) {
1009 dev_err(adev->dev, "va above limit (0x%08X >= 0x%08X)\n",
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001010 last_pfn, adev->vm_manager.max_pfn);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001011 return -EINVAL;
1012 }
1013
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001014 saddr /= AMDGPU_GPU_PAGE_SIZE;
1015 eaddr /= AMDGPU_GPU_PAGE_SIZE;
1016
Chunming Zhouc25867d2015-11-13 13:32:01 +08001017 spin_lock(&vm->it_lock);
Felix Kuehling005ae952015-11-23 17:43:48 -05001018 it = interval_tree_iter_first(&vm->va, saddr, eaddr);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001019 spin_unlock(&vm->it_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001020 if (it) {
1021 struct amdgpu_bo_va_mapping *tmp;
1022 tmp = container_of(it, struct amdgpu_bo_va_mapping, it);
1023 /* bo and tmp overlap, invalid addr */
1024 dev_err(adev->dev, "bo %p va 0x%010Lx-0x%010Lx conflict with "
1025 "0x%010lx-0x%010lx\n", bo_va->bo, saddr, eaddr,
1026 tmp->it.start, tmp->it.last + 1);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001027 r = -EINVAL;
Chunming Zhouf48b2652015-10-16 14:06:19 +08001028 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001029 }
1030
1031 mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
1032 if (!mapping) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001033 r = -ENOMEM;
Chunming Zhouf48b2652015-10-16 14:06:19 +08001034 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001035 }
1036
1037 INIT_LIST_HEAD(&mapping->list);
1038 mapping->it.start = saddr;
Felix Kuehling005ae952015-11-23 17:43:48 -05001039 mapping->it.last = eaddr;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001040 mapping->offset = offset;
1041 mapping->flags = flags;
1042
Chunming Zhou69b576a2015-11-18 11:17:39 +08001043 mutex_lock(&bo_va->mutex);
Christian König7fc11952015-07-30 11:53:42 +02001044 list_add(&mapping->list, &bo_va->invalids);
Chunming Zhou69b576a2015-11-18 11:17:39 +08001045 mutex_unlock(&bo_va->mutex);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001046 spin_lock(&vm->it_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001047 interval_tree_insert(&mapping->it, &vm->va);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001048 spin_unlock(&vm->it_lock);
Christian König93e3e432015-06-09 16:58:33 +02001049 trace_amdgpu_vm_bo_map(bo_va, mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001050
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001051 /* Make sure the page tables are allocated */
1052 saddr >>= amdgpu_vm_block_size;
1053 eaddr >>= amdgpu_vm_block_size;
1054
1055 BUG_ON(eaddr >= amdgpu_vm_num_pdes(adev));
1056
1057 if (eaddr > vm->max_pde_used)
1058 vm->max_pde_used = eaddr;
1059
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001060 /* walk over the address space and allocate the page tables */
1061 for (pt_idx = saddr; pt_idx <= eaddr; ++pt_idx) {
Christian Königbf60efd2015-09-04 10:47:56 +02001062 struct reservation_object *resv = vm->page_directory->tbo.resv;
Christian Königee1782c2015-12-11 21:01:23 +01001063 struct amdgpu_bo_list_entry *entry;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001064 struct amdgpu_bo *pt;
1065
Christian Königee1782c2015-12-11 21:01:23 +01001066 entry = &vm->page_tables[pt_idx].entry;
1067 if (entry->robj)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001068 continue;
1069
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001070 r = amdgpu_bo_create(adev, AMDGPU_VM_PTE_COUNT * 8,
1071 AMDGPU_GPU_PAGE_SIZE, true,
Alex Deucher857d9132015-08-27 00:14:16 -04001072 AMDGPU_GEM_DOMAIN_VRAM,
1073 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
Christian Königbf60efd2015-09-04 10:47:56 +02001074 NULL, resv, &pt);
Chunming Zhou49b02b12015-11-13 14:18:38 +08001075 if (r)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001076 goto error_free;
Chunming Zhou49b02b12015-11-13 14:18:38 +08001077
Christian König82b9c552015-11-27 16:49:00 +01001078 /* Keep a reference to the page table to avoid freeing
1079 * them up in the wrong order.
1080 */
1081 pt->parent = amdgpu_bo_ref(vm->page_directory);
1082
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001083 r = amdgpu_vm_clear_bo(adev, pt);
1084 if (r) {
1085 amdgpu_bo_unref(&pt);
1086 goto error_free;
1087 }
1088
Christian Königee1782c2015-12-11 21:01:23 +01001089 entry->robj = pt;
Christian Königee1782c2015-12-11 21:01:23 +01001090 entry->priority = 0;
1091 entry->tv.bo = &entry->robj->tbo;
1092 entry->tv.shared = true;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001093 vm->page_tables[pt_idx].addr = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001094 }
1095
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001096 return 0;
1097
1098error_free:
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001099 list_del(&mapping->list);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001100 spin_lock(&vm->it_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001101 interval_tree_remove(&mapping->it, &vm->va);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001102 spin_unlock(&vm->it_lock);
Christian König93e3e432015-06-09 16:58:33 +02001103 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001104 kfree(mapping);
1105
Chunming Zhouf48b2652015-10-16 14:06:19 +08001106error:
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001107 return r;
1108}
1109
1110/**
1111 * amdgpu_vm_bo_unmap - remove bo mapping from vm
1112 *
1113 * @adev: amdgpu_device pointer
1114 * @bo_va: bo_va to remove the address from
1115 * @saddr: where to the BO is mapped
1116 *
1117 * Remove a mapping of the BO at the specefied addr from the VM.
1118 * Returns 0 for success, error for failure.
1119 *
Chunming Zhou49b02b12015-11-13 14:18:38 +08001120 * Object has to be reserved and unreserved outside!
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001121 */
1122int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
1123 struct amdgpu_bo_va *bo_va,
1124 uint64_t saddr)
1125{
1126 struct amdgpu_bo_va_mapping *mapping;
1127 struct amdgpu_vm *vm = bo_va->vm;
Christian König7fc11952015-07-30 11:53:42 +02001128 bool valid = true;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001129
Christian König6c7fc502015-06-05 20:56:17 +02001130 saddr /= AMDGPU_GPU_PAGE_SIZE;
Chunming Zhou69b576a2015-11-18 11:17:39 +08001131 mutex_lock(&bo_va->mutex);
Christian König7fc11952015-07-30 11:53:42 +02001132 list_for_each_entry(mapping, &bo_va->valids, list) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001133 if (mapping->it.start == saddr)
1134 break;
1135 }
1136
Christian König7fc11952015-07-30 11:53:42 +02001137 if (&mapping->list == &bo_va->valids) {
1138 valid = false;
1139
1140 list_for_each_entry(mapping, &bo_va->invalids, list) {
1141 if (mapping->it.start == saddr)
1142 break;
1143 }
1144
Chunming Zhou69b576a2015-11-18 11:17:39 +08001145 if (&mapping->list == &bo_va->invalids) {
1146 mutex_unlock(&bo_va->mutex);
Christian König7fc11952015-07-30 11:53:42 +02001147 return -ENOENT;
Chunming Zhou69b576a2015-11-18 11:17:39 +08001148 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001149 }
Chunming Zhou69b576a2015-11-18 11:17:39 +08001150 mutex_unlock(&bo_va->mutex);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001151 list_del(&mapping->list);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001152 spin_lock(&vm->it_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001153 interval_tree_remove(&mapping->it, &vm->va);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001154 spin_unlock(&vm->it_lock);
Christian König93e3e432015-06-09 16:58:33 +02001155 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001156
jimqu81d75a32015-12-04 17:17:00 +08001157 if (valid) {
1158 spin_lock(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001159 list_add(&mapping->list, &vm->freed);
jimqu81d75a32015-12-04 17:17:00 +08001160 spin_unlock(&vm->freed_lock);
1161 } else {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001162 kfree(mapping);
jimqu81d75a32015-12-04 17:17:00 +08001163 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001164
1165 return 0;
1166}
1167
1168/**
1169 * amdgpu_vm_bo_rmv - remove a bo to a specific vm
1170 *
1171 * @adev: amdgpu_device pointer
1172 * @bo_va: requested bo_va
1173 *
1174 * Remove @bo_va->bo from the requested vm (cayman+).
1175 *
1176 * Object have to be reserved!
1177 */
1178void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
1179 struct amdgpu_bo_va *bo_va)
1180{
1181 struct amdgpu_bo_va_mapping *mapping, *next;
1182 struct amdgpu_vm *vm = bo_va->vm;
1183
1184 list_del(&bo_va->bo_list);
1185
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001186 spin_lock(&vm->status_lock);
1187 list_del(&bo_va->vm_status);
1188 spin_unlock(&vm->status_lock);
1189
Christian König7fc11952015-07-30 11:53:42 +02001190 list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001191 list_del(&mapping->list);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001192 spin_lock(&vm->it_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001193 interval_tree_remove(&mapping->it, &vm->va);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001194 spin_unlock(&vm->it_lock);
Christian König93e3e432015-06-09 16:58:33 +02001195 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
jimqu81d75a32015-12-04 17:17:00 +08001196 spin_lock(&vm->freed_lock);
Christian König7fc11952015-07-30 11:53:42 +02001197 list_add(&mapping->list, &vm->freed);
jimqu81d75a32015-12-04 17:17:00 +08001198 spin_unlock(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001199 }
Christian König7fc11952015-07-30 11:53:42 +02001200 list_for_each_entry_safe(mapping, next, &bo_va->invalids, list) {
1201 list_del(&mapping->list);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001202 spin_lock(&vm->it_lock);
Christian König7fc11952015-07-30 11:53:42 +02001203 interval_tree_remove(&mapping->it, &vm->va);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001204 spin_unlock(&vm->it_lock);
Christian König7fc11952015-07-30 11:53:42 +02001205 kfree(mapping);
1206 }
Chunming Zhoubb1e38a42015-08-03 18:19:38 +08001207 fence_put(bo_va->last_pt_update);
Chunming Zhou69b576a2015-11-18 11:17:39 +08001208 mutex_destroy(&bo_va->mutex);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001209 kfree(bo_va);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001210}
1211
1212/**
1213 * amdgpu_vm_bo_invalidate - mark the bo as invalid
1214 *
1215 * @adev: amdgpu_device pointer
1216 * @vm: requested vm
1217 * @bo: amdgpu buffer object
1218 *
1219 * Mark @bo as invalid (cayman+).
1220 */
1221void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
1222 struct amdgpu_bo *bo)
1223{
1224 struct amdgpu_bo_va *bo_va;
1225
1226 list_for_each_entry(bo_va, &bo->va, bo_list) {
Christian König7fc11952015-07-30 11:53:42 +02001227 spin_lock(&bo_va->vm->status_lock);
1228 if (list_empty(&bo_va->vm_status))
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001229 list_add(&bo_va->vm_status, &bo_va->vm->invalidated);
Christian König7fc11952015-07-30 11:53:42 +02001230 spin_unlock(&bo_va->vm->status_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001231 }
1232}
1233
1234/**
1235 * amdgpu_vm_init - initialize a vm instance
1236 *
1237 * @adev: amdgpu_device pointer
1238 * @vm: requested vm
1239 *
1240 * Init @vm fields (cayman+).
1241 */
1242int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1243{
1244 const unsigned align = min(AMDGPU_VM_PTB_ALIGN_SIZE,
1245 AMDGPU_VM_PTE_COUNT * 8);
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001246 unsigned pd_size, pd_entries;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001247 int i, r;
1248
1249 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
1250 vm->ids[i].id = 0;
1251 vm->ids[i].flushed_updates = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001252 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001253 vm->va = RB_ROOT;
1254 spin_lock_init(&vm->status_lock);
1255 INIT_LIST_HEAD(&vm->invalidated);
Christian König7fc11952015-07-30 11:53:42 +02001256 INIT_LIST_HEAD(&vm->cleared);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001257 INIT_LIST_HEAD(&vm->freed);
Chunming Zhouc25867d2015-11-13 13:32:01 +08001258 spin_lock_init(&vm->it_lock);
jimqu81d75a32015-12-04 17:17:00 +08001259 spin_lock_init(&vm->freed_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001260 pd_size = amdgpu_vm_directory_size(adev);
1261 pd_entries = amdgpu_vm_num_pdes(adev);
1262
1263 /* allocate page table array */
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001264 vm->page_tables = drm_calloc_large(pd_entries, sizeof(struct amdgpu_vm_pt));
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001265 if (vm->page_tables == NULL) {
1266 DRM_ERROR("Cannot allocate memory for page table array\n");
1267 return -ENOMEM;
1268 }
1269
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +02001270 vm->page_directory_fence = NULL;
1271
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001272 r = amdgpu_bo_create(adev, pd_size, align, true,
Alex Deucher857d9132015-08-27 00:14:16 -04001273 AMDGPU_GEM_DOMAIN_VRAM,
1274 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
Christian König72d76682015-09-03 17:34:59 +02001275 NULL, NULL, &vm->page_directory);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001276 if (r)
1277 return r;
Chunming Zhouef9f0a82015-11-13 13:43:22 +08001278 r = amdgpu_bo_reserve(vm->page_directory, false);
1279 if (r) {
1280 amdgpu_bo_unref(&vm->page_directory);
1281 vm->page_directory = NULL;
1282 return r;
1283 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001284 r = amdgpu_vm_clear_bo(adev, vm->page_directory);
Chunming Zhouef9f0a82015-11-13 13:43:22 +08001285 amdgpu_bo_unreserve(vm->page_directory);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001286 if (r) {
1287 amdgpu_bo_unref(&vm->page_directory);
1288 vm->page_directory = NULL;
1289 return r;
1290 }
1291
1292 return 0;
1293}
1294
1295/**
1296 * amdgpu_vm_fini - tear down a vm instance
1297 *
1298 * @adev: amdgpu_device pointer
1299 * @vm: requested vm
1300 *
1301 * Tear down @vm (cayman+).
1302 * Unbind the VM and remove all bos from the vm bo list
1303 */
1304void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1305{
1306 struct amdgpu_bo_va_mapping *mapping, *tmp;
1307 int i;
1308
1309 if (!RB_EMPTY_ROOT(&vm->va)) {
1310 dev_err(adev->dev, "still active bo inside vm\n");
1311 }
1312 rbtree_postorder_for_each_entry_safe(mapping, tmp, &vm->va, it.rb) {
1313 list_del(&mapping->list);
1314 interval_tree_remove(&mapping->it, &vm->va);
1315 kfree(mapping);
1316 }
1317 list_for_each_entry_safe(mapping, tmp, &vm->freed, list) {
1318 list_del(&mapping->list);
1319 kfree(mapping);
1320 }
1321
1322 for (i = 0; i < amdgpu_vm_num_pdes(adev); i++)
Christian Königee1782c2015-12-11 21:01:23 +01001323 amdgpu_bo_unref(&vm->page_tables[i].entry.robj);
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001324 drm_free_large(vm->page_tables);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001325
1326 amdgpu_bo_unref(&vm->page_directory);
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +02001327 fence_put(vm->page_directory_fence);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001328 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
Christian König1c16c0a2015-11-14 21:31:40 +01001329 unsigned id = vm->ids[i].id;
1330
1331 atomic_long_cmpxchg(&adev->vm_manager.ids[id].owner,
1332 (long)vm, 0);
Chunming Zhou3c623382015-08-20 18:33:59 +08001333 fence_put(vm->ids[i].flushed_updates);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001334 }
1335
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001336}
Christian Königea89f8c2015-11-15 20:52:06 +01001337
1338/**
Christian Königa9a78b32016-01-21 10:19:11 +01001339 * amdgpu_vm_manager_init - init the VM manager
1340 *
1341 * @adev: amdgpu_device pointer
1342 *
1343 * Initialize the VM manager structures
1344 */
1345void amdgpu_vm_manager_init(struct amdgpu_device *adev)
1346{
1347 unsigned i;
1348
1349 INIT_LIST_HEAD(&adev->vm_manager.ids_lru);
1350
1351 /* skip over VMID 0, since it is the system VM */
1352 for (i = 1; i < adev->vm_manager.num_ids; ++i)
1353 list_add_tail(&adev->vm_manager.ids[i].list,
1354 &adev->vm_manager.ids_lru);
1355}
1356
1357/**
Christian Königea89f8c2015-11-15 20:52:06 +01001358 * amdgpu_vm_manager_fini - cleanup VM manager
1359 *
1360 * @adev: amdgpu_device pointer
1361 *
1362 * Cleanup the VM manager and free resources.
1363 */
1364void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
1365{
1366 unsigned i;
1367
1368 for (i = 0; i < AMDGPU_NUM_VM; ++i)
Christian König1c16c0a2015-11-14 21:31:40 +01001369 fence_put(adev->vm_manager.ids[i].active);
Christian Königea89f8c2015-11-15 20:52:06 +01001370}