blob: d9553d38b44e9dc6512ec7a3cbe4549fe723e1df [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 */
Christian König1fbb2e92016-06-01 10:47:36 +020028#include <linux/fence-array.h>
Alex Deucherd38ceaf2015-04-20 16:55:21 -040029#include <drm/drmP.h>
30#include <drm/amdgpu_drm.h>
31#include "amdgpu.h"
32#include "amdgpu_trace.h"
33
34/*
35 * GPUVM
36 * GPUVM is similar to the legacy gart on older asics, however
37 * rather than there being a single global gart table
38 * for the entire GPU, there are multiple VM page tables active
39 * at any given time. The VM page tables can contain a mix
40 * vram pages and system memory pages and system memory pages
41 * can be mapped as snooped (cached system pages) or unsnooped
42 * (uncached system pages).
43 * Each VM has an ID associated with it and there is a page table
44 * associated with each VMID. When execting a command buffer,
45 * the kernel tells the the ring what VMID to use for that command
46 * buffer. VMIDs are allocated dynamically as commands are submitted.
47 * The userspace drivers maintain their own address space and the kernel
48 * sets up their pages tables accordingly when they submit their
49 * command buffers and a VMID is assigned.
50 * Cayman/Trinity support up to 8 active VMs at any given time;
51 * SI supports 16.
52 */
53
Christian König4ff37a82016-02-26 16:18:26 +010054/* Special value that no flush is necessary */
55#define AMDGPU_VM_NO_FLUSH (~0ll)
56
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -040057/* Local structure. Encapsulate some VM table update parameters to reduce
58 * the number of function parameters
59 */
60struct amdgpu_vm_update_params {
61 /* address where to copy page table entries from */
62 uint64_t src;
63 /* DMA addresses to use for mapping */
64 dma_addr_t *pages_addr;
65 /* indirect buffer to fill with commands */
66 struct amdgpu_ib *ib;
67};
68
Alex Deucherd38ceaf2015-04-20 16:55:21 -040069/**
70 * amdgpu_vm_num_pde - return the number of page directory entries
71 *
72 * @adev: amdgpu_device pointer
73 *
Christian König8843dbb2016-01-26 12:17:11 +010074 * Calculate the number of page directory entries.
Alex Deucherd38ceaf2015-04-20 16:55:21 -040075 */
76static unsigned amdgpu_vm_num_pdes(struct amdgpu_device *adev)
77{
78 return adev->vm_manager.max_pfn >> amdgpu_vm_block_size;
79}
80
81/**
82 * amdgpu_vm_directory_size - returns the size of the page directory in bytes
83 *
84 * @adev: amdgpu_device pointer
85 *
Christian König8843dbb2016-01-26 12:17:11 +010086 * Calculate the size of the page directory in bytes.
Alex Deucherd38ceaf2015-04-20 16:55:21 -040087 */
88static unsigned amdgpu_vm_directory_size(struct amdgpu_device *adev)
89{
90 return AMDGPU_GPU_PAGE_ALIGN(amdgpu_vm_num_pdes(adev) * 8);
91}
92
93/**
Christian König56467eb2015-12-11 15:16:32 +010094 * amdgpu_vm_get_pd_bo - add the VM PD to a validation list
Alex Deucherd38ceaf2015-04-20 16:55:21 -040095 *
96 * @vm: vm providing the BOs
Christian König3c0eea62015-12-11 14:39:05 +010097 * @validated: head of validation list
Christian König56467eb2015-12-11 15:16:32 +010098 * @entry: entry to add
Alex Deucherd38ceaf2015-04-20 16:55:21 -040099 *
100 * Add the page directory to the list of BOs to
Christian König56467eb2015-12-11 15:16:32 +0100101 * validate for command submission.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400102 */
Christian König56467eb2015-12-11 15:16:32 +0100103void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
104 struct list_head *validated,
105 struct amdgpu_bo_list_entry *entry)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400106{
Christian König56467eb2015-12-11 15:16:32 +0100107 entry->robj = vm->page_directory;
Christian König56467eb2015-12-11 15:16:32 +0100108 entry->priority = 0;
109 entry->tv.bo = &vm->page_directory->tbo;
110 entry->tv.shared = true;
Christian König2f568db2016-02-23 12:36:59 +0100111 entry->user_pages = NULL;
Christian König56467eb2015-12-11 15:16:32 +0100112 list_add(&entry->tv.head, validated);
113}
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400114
Christian König56467eb2015-12-11 15:16:32 +0100115/**
Christian Königee1782c2015-12-11 21:01:23 +0100116 * amdgpu_vm_get_bos - add the vm BOs to a duplicates list
Christian König56467eb2015-12-11 15:16:32 +0100117 *
Christian König5a712a82016-06-21 16:28:15 +0200118 * @adev: amdgpu device pointer
Christian König56467eb2015-12-11 15:16:32 +0100119 * @vm: vm providing the BOs
Christian König3c0eea62015-12-11 14:39:05 +0100120 * @duplicates: head of duplicates list
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400121 *
Christian Königee1782c2015-12-11 21:01:23 +0100122 * Add the page directory to the BO duplicates list
123 * for command submission.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400124 */
Christian König5a712a82016-06-21 16:28:15 +0200125void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
126 struct list_head *duplicates)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400127{
Christian König5a712a82016-06-21 16:28:15 +0200128 uint64_t num_evictions;
Christian Königee1782c2015-12-11 21:01:23 +0100129 unsigned i;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400130
Christian König5a712a82016-06-21 16:28:15 +0200131 /* We only need to validate the page tables
132 * if they aren't already valid.
133 */
134 num_evictions = atomic64_read(&adev->num_evictions);
135 if (num_evictions == vm->last_eviction_counter)
136 return;
137
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400138 /* add the vm page table to the list */
Christian Königee1782c2015-12-11 21:01:23 +0100139 for (i = 0; i <= vm->max_pde_used; ++i) {
140 struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400141
Christian Königee1782c2015-12-11 21:01:23 +0100142 if (!entry->robj)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400143 continue;
144
Christian Königee1782c2015-12-11 21:01:23 +0100145 list_add(&entry->tv.head, duplicates);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400146 }
Christian Königeceb8a12016-01-11 15:35:21 +0100147
148}
149
150/**
151 * amdgpu_vm_move_pt_bos_in_lru - move the PT BOs to the LRU tail
152 *
153 * @adev: amdgpu device instance
154 * @vm: vm providing the BOs
155 *
156 * Move the PT BOs to the tail of the LRU.
157 */
158void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
159 struct amdgpu_vm *vm)
160{
161 struct ttm_bo_global *glob = adev->mman.bdev.glob;
162 unsigned i;
163
164 spin_lock(&glob->lru_lock);
165 for (i = 0; i <= vm->max_pde_used; ++i) {
166 struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry;
167
168 if (!entry->robj)
169 continue;
170
171 ttm_bo_move_to_lru_tail(&entry->robj->tbo);
172 }
173 spin_unlock(&glob->lru_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400174}
175
176/**
177 * amdgpu_vm_grab_id - allocate the next free VMID
178 *
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400179 * @vm: vm to allocate id for
Christian König7f8a5292015-07-20 16:09:40 +0200180 * @ring: ring we want to submit job to
181 * @sync: sync object where we add dependencies
Christian König94dd0a42016-01-18 17:01:42 +0100182 * @fence: fence protecting ID from reuse
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400183 *
Christian König7f8a5292015-07-20 16:09:40 +0200184 * Allocate an id for the vm, adding fences to the sync obj as necessary.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400185 */
Christian König7f8a5292015-07-20 16:09:40 +0200186int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100187 struct amdgpu_sync *sync, struct fence *fence,
188 unsigned *vm_id, uint64_t *vm_pd_addr)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400189{
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400190 struct amdgpu_device *adev = ring->adev;
Christian König4ff37a82016-02-26 16:18:26 +0100191 struct fence *updates = sync->last_vm_update;
Christian König8d76001e2016-05-23 16:00:32 +0200192 struct amdgpu_vm_id *id, *idle;
Christian König1fbb2e92016-06-01 10:47:36 +0200193 struct fence **fences;
194 unsigned i;
195 int r = 0;
196
197 fences = kmalloc_array(sizeof(void *), adev->vm_manager.num_ids,
198 GFP_KERNEL);
199 if (!fences)
200 return -ENOMEM;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400201
Christian König94dd0a42016-01-18 17:01:42 +0100202 mutex_lock(&adev->vm_manager.lock);
203
Christian König36fd7c52016-05-23 15:30:08 +0200204 /* Check if we have an idle VMID */
Christian König1fbb2e92016-06-01 10:47:36 +0200205 i = 0;
Christian König8d76001e2016-05-23 16:00:32 +0200206 list_for_each_entry(idle, &adev->vm_manager.ids_lru, list) {
Christian König1fbb2e92016-06-01 10:47:36 +0200207 fences[i] = amdgpu_sync_peek_fence(&idle->active, ring);
208 if (!fences[i])
Christian König36fd7c52016-05-23 15:30:08 +0200209 break;
Christian König1fbb2e92016-06-01 10:47:36 +0200210 ++i;
Christian König36fd7c52016-05-23 15:30:08 +0200211 }
Christian Königbcb1ba32016-03-08 15:40:11 +0100212
Christian König1fbb2e92016-06-01 10:47:36 +0200213 /* If we can't find a idle VMID to use, wait till one becomes available */
Christian König8d76001e2016-05-23 16:00:32 +0200214 if (&idle->list == &adev->vm_manager.ids_lru) {
Christian König1fbb2e92016-06-01 10:47:36 +0200215 u64 fence_context = adev->vm_manager.fence_context + ring->idx;
216 unsigned seqno = ++adev->vm_manager.seqno[ring->idx];
217 struct fence_array *array;
218 unsigned j;
Christian König8d76001e2016-05-23 16:00:32 +0200219
Christian König1fbb2e92016-06-01 10:47:36 +0200220 for (j = 0; j < i; ++j)
221 fence_get(fences[j]);
Christian König8d76001e2016-05-23 16:00:32 +0200222
Christian König1fbb2e92016-06-01 10:47:36 +0200223 array = fence_array_create(i, fences, fence_context,
224 seqno, true);
225 if (!array) {
226 for (j = 0; j < i; ++j)
227 fence_put(fences[j]);
228 kfree(fences);
229 r = -ENOMEM;
230 goto error;
231 }
Christian König8d76001e2016-05-23 16:00:32 +0200232
Christian König8d76001e2016-05-23 16:00:32 +0200233
Christian König1fbb2e92016-06-01 10:47:36 +0200234 r = amdgpu_sync_fence(ring->adev, sync, &array->base);
235 fence_put(&array->base);
236 if (r)
237 goto error;
Christian König8d76001e2016-05-23 16:00:32 +0200238
Christian König1fbb2e92016-06-01 10:47:36 +0200239 mutex_unlock(&adev->vm_manager.lock);
240 return 0;
Christian König8d76001e2016-05-23 16:00:32 +0200241
Christian König1fbb2e92016-06-01 10:47:36 +0200242 }
243 kfree(fences);
Christian König8d76001e2016-05-23 16:00:32 +0200244
Christian König1fbb2e92016-06-01 10:47:36 +0200245 /* Check if we can use a VMID already assigned to this VM */
246 i = ring->idx;
247 do {
248 struct fence *flushed;
Christian König3dab83b2016-06-01 13:31:17 +0200249 bool same_ring = ring->idx == i;
Christian König8d76001e2016-05-23 16:00:32 +0200250
Christian König1fbb2e92016-06-01 10:47:36 +0200251 id = vm->ids[i++];
252 if (i == AMDGPU_MAX_RINGS)
253 i = 0;
254
255 /* Check all the prerequisites to using this VMID */
256 if (!id)
257 continue;
Chunming Zhou6adb0512016-06-27 17:06:01 +0800258 if (id->current_gpu_reset_count != atomic_read(&adev->gpu_reset_counter))
259 continue;
Christian König1fbb2e92016-06-01 10:47:36 +0200260
261 if (atomic64_read(&id->owner) != vm->client_id)
262 continue;
263
Christian König281d1442016-06-15 13:44:04 +0200264 if (*vm_pd_addr != id->pd_gpu_addr)
Christian König1fbb2e92016-06-01 10:47:36 +0200265 continue;
266
Christian König3dab83b2016-06-01 13:31:17 +0200267 if (!same_ring &&
Christian König1fbb2e92016-06-01 10:47:36 +0200268 (!id->last_flush || !fence_is_signaled(id->last_flush)))
269 continue;
270
271 flushed = id->flushed_updates;
272 if (updates &&
273 (!flushed || fence_is_later(updates, flushed)))
274 continue;
275
Christian König3dab83b2016-06-01 13:31:17 +0200276 /* Good we can use this VMID. Remember this submission as
277 * user of the VMID.
278 */
Christian König1fbb2e92016-06-01 10:47:36 +0200279 r = amdgpu_sync_fence(ring->adev, &id->active, fence);
280 if (r)
281 goto error;
Christian König8d76001e2016-05-23 16:00:32 +0200282
Chunming Zhou6adb0512016-06-27 17:06:01 +0800283 id->current_gpu_reset_count = atomic_read(&adev->gpu_reset_counter);
Christian König1fbb2e92016-06-01 10:47:36 +0200284 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
285 vm->ids[ring->idx] = id;
Christian König8d76001e2016-05-23 16:00:32 +0200286
Christian König1fbb2e92016-06-01 10:47:36 +0200287 *vm_id = id - adev->vm_manager.ids;
288 *vm_pd_addr = AMDGPU_VM_NO_FLUSH;
289 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, *vm_pd_addr);
Christian König8d76001e2016-05-23 16:00:32 +0200290
Christian König1fbb2e92016-06-01 10:47:36 +0200291 mutex_unlock(&adev->vm_manager.lock);
292 return 0;
Christian König8d76001e2016-05-23 16:00:32 +0200293
Christian König1fbb2e92016-06-01 10:47:36 +0200294 } while (i != ring->idx);
Chunming Zhou8e9fbeb2016-03-17 11:41:37 +0800295
Christian König1fbb2e92016-06-01 10:47:36 +0200296 /* Still no ID to use? Then use the idle one found earlier */
297 id = idle;
298
299 /* Remember this submission as user of the VMID */
300 r = amdgpu_sync_fence(ring->adev, &id->active, fence);
Christian König832a9022016-02-15 12:33:02 +0100301 if (r)
302 goto error;
Christian König4ff37a82016-02-26 16:18:26 +0100303
Christian König832a9022016-02-15 12:33:02 +0100304 fence_put(id->first);
305 id->first = fence_get(fence);
Christian König4ff37a82016-02-26 16:18:26 +0100306
Christian König41d9eb22016-03-01 16:46:18 +0100307 fence_put(id->last_flush);
308 id->last_flush = NULL;
309
Christian König832a9022016-02-15 12:33:02 +0100310 fence_put(id->flushed_updates);
311 id->flushed_updates = fence_get(updates);
Christian König4ff37a82016-02-26 16:18:26 +0100312
Christian König281d1442016-06-15 13:44:04 +0200313 id->pd_gpu_addr = *vm_pd_addr;
Christian König4ff37a82016-02-26 16:18:26 +0100314
Chunming Zhoub46b8a82016-06-27 17:04:23 +0800315 id->current_gpu_reset_count = atomic_read(&adev->gpu_reset_counter);
Christian König832a9022016-02-15 12:33:02 +0100316 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
Christian König0ea54b92016-05-04 10:20:01 +0200317 atomic64_set(&id->owner, vm->client_id);
Christian König832a9022016-02-15 12:33:02 +0100318 vm->ids[ring->idx] = id;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400319
Christian König832a9022016-02-15 12:33:02 +0100320 *vm_id = id - adev->vm_manager.ids;
Christian König832a9022016-02-15 12:33:02 +0100321 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, *vm_pd_addr);
322
323error:
Christian König94dd0a42016-01-18 17:01:42 +0100324 mutex_unlock(&adev->vm_manager.lock);
Christian Königa9a78b32016-01-21 10:19:11 +0100325 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400326}
327
Alex Deucher93dcc372016-06-17 17:05:15 -0400328static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring *ring)
329{
330 struct amdgpu_device *adev = ring->adev;
331 const struct amdgpu_ip_block_version *ip_block;
332
333 if (ring->type != AMDGPU_RING_TYPE_COMPUTE)
334 /* only compute rings */
335 return false;
336
337 ip_block = amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_GFX);
338 if (!ip_block)
339 return false;
340
341 if (ip_block->major <= 7) {
342 /* gfx7 has no workaround */
343 return true;
344 } else if (ip_block->major == 8) {
345 if (adev->gfx.mec_fw_version >= 673)
346 /* gfx8 is fixed in MEC firmware 673 */
347 return false;
348 else
349 return true;
350 }
351 return false;
352}
353
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400354/**
355 * amdgpu_vm_flush - hardware flush the vm
356 *
357 * @ring: ring to use for flush
Christian Königcffadc82016-03-01 13:34:49 +0100358 * @vm_id: vmid number to use
Christian König4ff37a82016-02-26 16:18:26 +0100359 * @pd_addr: address of the page directory
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400360 *
Christian König4ff37a82016-02-26 16:18:26 +0100361 * Emit a VM flush when it is necessary.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400362 */
Christian König41d9eb22016-03-01 16:46:18 +0100363int amdgpu_vm_flush(struct amdgpu_ring *ring,
364 unsigned vm_id, uint64_t pd_addr,
365 uint32_t gds_base, uint32_t gds_size,
366 uint32_t gws_base, uint32_t gws_size,
367 uint32_t oa_base, uint32_t oa_size)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400368{
Christian König971fe9a92016-03-01 15:09:25 +0100369 struct amdgpu_device *adev = ring->adev;
Christian Königbcb1ba32016-03-08 15:40:11 +0100370 struct amdgpu_vm_id *id = &adev->vm_manager.ids[vm_id];
Christian Königd564a062016-03-01 15:51:53 +0100371 bool gds_switch_needed = ring->funcs->emit_gds_switch && (
Christian Königbcb1ba32016-03-08 15:40:11 +0100372 id->gds_base != gds_base ||
373 id->gds_size != gds_size ||
374 id->gws_base != gws_base ||
375 id->gws_size != gws_size ||
376 id->oa_base != oa_base ||
377 id->oa_size != oa_size);
Christian König41d9eb22016-03-01 16:46:18 +0100378 int r;
Christian Königd564a062016-03-01 15:51:53 +0100379
380 if (ring->funcs->emit_pipeline_sync && (
Chunming Zhoufe707662016-04-27 18:07:41 +0800381 pd_addr != AMDGPU_VM_NO_FLUSH || gds_switch_needed ||
Alex Deucher93dcc372016-06-17 17:05:15 -0400382 amdgpu_vm_ring_has_compute_vm_bug(ring)))
Christian Königd564a062016-03-01 15:51:53 +0100383 amdgpu_ring_emit_pipeline_sync(ring);
Christian König971fe9a92016-03-01 15:09:25 +0100384
Monk Liuc5637832016-04-19 20:11:32 +0800385 if (ring->funcs->emit_vm_flush &&
386 pd_addr != AMDGPU_VM_NO_FLUSH) {
Christian König41d9eb22016-03-01 16:46:18 +0100387 struct fence *fence;
388
Christian Königcffadc82016-03-01 13:34:49 +0100389 trace_amdgpu_vm_flush(pd_addr, ring->idx, vm_id);
390 amdgpu_ring_emit_vm_flush(ring, vm_id, pd_addr);
Christian König41d9eb22016-03-01 16:46:18 +0100391
Christian König3dab83b2016-06-01 13:31:17 +0200392 r = amdgpu_fence_emit(ring, &fence);
393 if (r)
394 return r;
395
Christian König41d9eb22016-03-01 16:46:18 +0100396 mutex_lock(&adev->vm_manager.lock);
Christian König3dab83b2016-06-01 13:31:17 +0200397 fence_put(id->last_flush);
398 id->last_flush = fence;
Christian König41d9eb22016-03-01 16:46:18 +0100399 mutex_unlock(&adev->vm_manager.lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400400 }
Christian Königcffadc82016-03-01 13:34:49 +0100401
Christian Königd564a062016-03-01 15:51:53 +0100402 if (gds_switch_needed) {
Christian Königbcb1ba32016-03-08 15:40:11 +0100403 id->gds_base = gds_base;
404 id->gds_size = gds_size;
405 id->gws_base = gws_base;
406 id->gws_size = gws_size;
407 id->oa_base = oa_base;
408 id->oa_size = oa_size;
Christian Königcffadc82016-03-01 13:34:49 +0100409 amdgpu_ring_emit_gds_switch(ring, vm_id,
410 gds_base, gds_size,
411 gws_base, gws_size,
412 oa_base, oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100413 }
Christian König41d9eb22016-03-01 16:46:18 +0100414
415 return 0;
Christian König971fe9a92016-03-01 15:09:25 +0100416}
417
418/**
419 * amdgpu_vm_reset_id - reset VMID to zero
420 *
421 * @adev: amdgpu device structure
422 * @vm_id: vmid number to use
423 *
424 * Reset saved GDW, GWS and OA to force switch on next flush.
425 */
426void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id)
427{
Christian Königbcb1ba32016-03-08 15:40:11 +0100428 struct amdgpu_vm_id *id = &adev->vm_manager.ids[vm_id];
Christian König971fe9a92016-03-01 15:09:25 +0100429
Christian Königbcb1ba32016-03-08 15:40:11 +0100430 id->gds_base = 0;
431 id->gds_size = 0;
432 id->gws_base = 0;
433 id->gws_size = 0;
434 id->oa_base = 0;
435 id->oa_size = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400436}
437
438/**
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400439 * amdgpu_vm_bo_find - find the bo_va for a specific vm & bo
440 *
441 * @vm: requested vm
442 * @bo: requested buffer object
443 *
Christian König8843dbb2016-01-26 12:17:11 +0100444 * Find @bo inside the requested vm.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400445 * Search inside the @bos vm list for the requested vm
446 * Returns the found bo_va or NULL if none is found
447 *
448 * Object has to be reserved!
449 */
450struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
451 struct amdgpu_bo *bo)
452{
453 struct amdgpu_bo_va *bo_va;
454
455 list_for_each_entry(bo_va, &bo->va, bo_list) {
456 if (bo_va->vm == vm) {
457 return bo_va;
458 }
459 }
460 return NULL;
461}
462
463/**
464 * amdgpu_vm_update_pages - helper to call the right asic function
465 *
466 * @adev: amdgpu_device pointer
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400467 * @vm_update_params: see amdgpu_vm_update_params definition
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400468 * @pe: addr of the page entry
469 * @addr: dst addr to write into pe
470 * @count: number of page entries to update
471 * @incr: increase next addr by incr bytes
472 * @flags: hw access flags
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400473 *
474 * Traces the parameters and calls the right asic functions
475 * to setup the page table using the DMA.
476 */
477static void amdgpu_vm_update_pages(struct amdgpu_device *adev,
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400478 struct amdgpu_vm_update_params
479 *vm_update_params,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400480 uint64_t pe, uint64_t addr,
481 unsigned count, uint32_t incr,
Christian König9ab21462015-11-30 14:19:26 +0100482 uint32_t flags)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400483{
484 trace_amdgpu_vm_set_page(pe, addr, count, incr, flags);
485
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400486 if (vm_update_params->src) {
487 amdgpu_vm_copy_pte(adev, vm_update_params->ib,
488 pe, (vm_update_params->src + (addr >> 12) * 8), count);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400489
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400490 } else if (vm_update_params->pages_addr) {
491 amdgpu_vm_write_pte(adev, vm_update_params->ib,
492 vm_update_params->pages_addr,
493 pe, addr, count, incr, flags);
Christian Königb07c9d22015-11-30 13:26:07 +0100494
495 } else if (count < 3) {
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400496 amdgpu_vm_write_pte(adev, vm_update_params->ib, NULL, pe, addr,
Christian Königb07c9d22015-11-30 13:26:07 +0100497 count, incr, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400498
499 } else {
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400500 amdgpu_vm_set_pte_pde(adev, vm_update_params->ib, pe, addr,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400501 count, incr, flags);
502 }
503}
504
505/**
506 * amdgpu_vm_clear_bo - initially clear the page dir/table
507 *
508 * @adev: amdgpu_device pointer
509 * @bo: bo to clear
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800510 *
511 * need to reserve bo first before calling it.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400512 */
513static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
Christian König2bd9ccf2016-02-01 12:53:58 +0100514 struct amdgpu_vm *vm,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400515 struct amdgpu_bo *bo)
516{
Christian König2d55e452016-02-08 17:37:38 +0100517 struct amdgpu_ring *ring;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800518 struct fence *fence = NULL;
Christian Königd71518b2016-02-01 12:20:25 +0100519 struct amdgpu_job *job;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400520 struct amdgpu_vm_update_params vm_update_params;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400521 unsigned entries;
522 uint64_t addr;
523 int r;
524
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400525 memset(&vm_update_params, 0, sizeof(vm_update_params));
Christian König2d55e452016-02-08 17:37:38 +0100526 ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
527
monk.liuca952612015-05-25 14:44:05 +0800528 r = reservation_object_reserve_shared(bo->tbo.resv);
529 if (r)
530 return r;
531
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400532 r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
533 if (r)
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800534 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400535
536 addr = amdgpu_bo_gpu_offset(bo);
537 entries = amdgpu_bo_size(bo) / 8;
538
Christian Königd71518b2016-02-01 12:20:25 +0100539 r = amdgpu_job_alloc_with_ib(adev, 64, &job);
540 if (r)
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800541 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400542
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400543 vm_update_params.ib = &job->ibs[0];
544 amdgpu_vm_update_pages(adev, &vm_update_params, addr, 0, entries,
Christian Königd71518b2016-02-01 12:20:25 +0100545 0, 0);
546 amdgpu_ring_pad_ib(ring, &job->ibs[0]);
547
548 WARN_ON(job->ibs[0].length_dw > 64);
Christian König2bd9ccf2016-02-01 12:53:58 +0100549 r = amdgpu_job_submit(job, ring, &vm->entity,
550 AMDGPU_FENCE_OWNER_VM, &fence);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400551 if (r)
552 goto error_free;
553
Christian Königd71518b2016-02-01 12:20:25 +0100554 amdgpu_bo_fence(bo, fence, true);
Chunming Zhou281b4222015-08-12 12:58:31 +0800555 fence_put(fence);
Chunming Zhoucadf97b2016-01-15 11:25:00 +0800556 return 0;
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800557
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400558error_free:
Christian Königd71518b2016-02-01 12:20:25 +0100559 amdgpu_job_free(job);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400560
Chunming Zhouef9f0a82015-11-13 13:43:22 +0800561error:
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400562 return r;
563}
564
565/**
Christian Königb07c9d22015-11-30 13:26:07 +0100566 * amdgpu_vm_map_gart - Resolve gart mapping of addr
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400567 *
Christian Königb07c9d22015-11-30 13:26:07 +0100568 * @pages_addr: optional DMA address to use for lookup
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400569 * @addr: the unmapped addr
570 *
571 * Look up the physical address of the page that the pte resolves
Christian Königb07c9d22015-11-30 13:26:07 +0100572 * to and return the pointer for the page table entry.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400573 */
Christian Königb07c9d22015-11-30 13:26:07 +0100574uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400575{
576 uint64_t result;
577
Christian Königb07c9d22015-11-30 13:26:07 +0100578 if (pages_addr) {
579 /* page table offset */
580 result = pages_addr[addr >> PAGE_SHIFT];
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400581
Christian Königb07c9d22015-11-30 13:26:07 +0100582 /* in case cpu page size != gpu page size*/
583 result |= addr & (~PAGE_MASK);
584
585 } else {
586 /* No mapping required */
587 result = addr;
588 }
589
590 result &= 0xFFFFFFFFFFFFF000ULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400591
592 return result;
593}
594
595/**
596 * amdgpu_vm_update_pdes - make sure that page directory is valid
597 *
598 * @adev: amdgpu_device pointer
599 * @vm: requested vm
600 * @start: start of GPU address range
601 * @end: end of GPU address range
602 *
603 * Allocates new page tables if necessary
Christian König8843dbb2016-01-26 12:17:11 +0100604 * and updates the page directory.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400605 * Returns 0 for success, error for failure.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400606 */
607int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
608 struct amdgpu_vm *vm)
609{
Christian König2d55e452016-02-08 17:37:38 +0100610 struct amdgpu_ring *ring;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400611 struct amdgpu_bo *pd = vm->page_directory;
612 uint64_t pd_addr = amdgpu_bo_gpu_offset(pd);
613 uint32_t incr = AMDGPU_VM_PTE_COUNT * 8;
614 uint64_t last_pde = ~0, last_pt = ~0;
615 unsigned count = 0, pt_idx, ndw;
Christian Königd71518b2016-02-01 12:20:25 +0100616 struct amdgpu_job *job;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400617 struct amdgpu_vm_update_params vm_update_params;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800618 struct fence *fence = NULL;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800619
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400620 int r;
621
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400622 memset(&vm_update_params, 0, sizeof(vm_update_params));
Christian König2d55e452016-02-08 17:37:38 +0100623 ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
624
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400625 /* padding, etc. */
626 ndw = 64;
627
628 /* assume the worst case */
629 ndw += vm->max_pde_used * 6;
630
Christian Königd71518b2016-02-01 12:20:25 +0100631 r = amdgpu_job_alloc_with_ib(adev, ndw * 4, &job);
632 if (r)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400633 return r;
Christian Königd71518b2016-02-01 12:20:25 +0100634
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400635 vm_update_params.ib = &job->ibs[0];
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400636
637 /* walk over the address space and update the page directory */
638 for (pt_idx = 0; pt_idx <= vm->max_pde_used; ++pt_idx) {
Christian Königee1782c2015-12-11 21:01:23 +0100639 struct amdgpu_bo *bo = vm->page_tables[pt_idx].entry.robj;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400640 uint64_t pde, pt;
641
642 if (bo == NULL)
643 continue;
644
645 pt = amdgpu_bo_gpu_offset(bo);
646 if (vm->page_tables[pt_idx].addr == pt)
647 continue;
648 vm->page_tables[pt_idx].addr = pt;
649
650 pde = pd_addr + pt_idx * 8;
651 if (((last_pde + 8 * count) != pde) ||
652 ((last_pt + incr * count) != pt)) {
653
654 if (count) {
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400655 amdgpu_vm_update_pages(adev, &vm_update_params,
Christian König9ab21462015-11-30 14:19:26 +0100656 last_pde, last_pt,
657 count, incr,
658 AMDGPU_PTE_VALID);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400659 }
660
661 count = 1;
662 last_pde = pde;
663 last_pt = pt;
664 } else {
665 ++count;
666 }
667 }
668
669 if (count)
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400670 amdgpu_vm_update_pages(adev, &vm_update_params,
671 last_pde, last_pt,
672 count, incr, AMDGPU_PTE_VALID);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400673
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400674 if (vm_update_params.ib->length_dw != 0) {
675 amdgpu_ring_pad_ib(ring, vm_update_params.ib);
Christian Könige86f9ce2016-02-08 12:13:05 +0100676 amdgpu_sync_resv(adev, &job->sync, pd->tbo.resv,
677 AMDGPU_FENCE_OWNER_VM);
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400678 WARN_ON(vm_update_params.ib->length_dw > ndw);
Christian König2bd9ccf2016-02-01 12:53:58 +0100679 r = amdgpu_job_submit(job, ring, &vm->entity,
680 AMDGPU_FENCE_OWNER_VM, &fence);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800681 if (r)
682 goto error_free;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200683
Chunming Zhou4af9f072015-08-03 12:57:31 +0800684 amdgpu_bo_fence(pd, fence, true);
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200685 fence_put(vm->page_directory_fence);
686 vm->page_directory_fence = fence_get(fence);
Chunming Zhou281b4222015-08-12 12:58:31 +0800687 fence_put(fence);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800688
Christian Königd71518b2016-02-01 12:20:25 +0100689 } else {
690 amdgpu_job_free(job);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800691 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400692
693 return 0;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800694
695error_free:
Christian Königd71518b2016-02-01 12:20:25 +0100696 amdgpu_job_free(job);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800697 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400698}
699
700/**
701 * amdgpu_vm_frag_ptes - add fragment information to PTEs
702 *
703 * @adev: amdgpu_device pointer
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400704 * @vm_update_params: see amdgpu_vm_update_params definition
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400705 * @pe_start: first PTE to handle
706 * @pe_end: last PTE to handle
707 * @addr: addr those PTEs should point to
708 * @flags: hw mapping flags
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400709 */
710static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400711 struct amdgpu_vm_update_params
712 *vm_update_params,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400713 uint64_t pe_start, uint64_t pe_end,
Christian König9ab21462015-11-30 14:19:26 +0100714 uint64_t addr, uint32_t flags)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400715{
716 /**
717 * The MC L1 TLB supports variable sized pages, based on a fragment
718 * field in the PTE. When this field is set to a non-zero value, page
719 * granularity is increased from 4KB to (1 << (12 + frag)). The PTE
720 * flags are considered valid for all PTEs within the fragment range
721 * and corresponding mappings are assumed to be physically contiguous.
722 *
723 * The L1 TLB can store a single PTE for the whole fragment,
724 * significantly increasing the space available for translation
725 * caching. This leads to large improvements in throughput when the
726 * TLB is under pressure.
727 *
728 * The L2 TLB distributes small and large fragments into two
729 * asymmetric partitions. The large fragment cache is significantly
730 * larger. Thus, we try to use large fragments wherever possible.
731 * Userspace can support this by aligning virtual base address and
732 * allocation size to the fragment size.
733 */
734
735 /* SI and newer are optimized for 64KB */
736 uint64_t frag_flags = AMDGPU_PTE_FRAG_64KB;
737 uint64_t frag_align = 0x80;
738
739 uint64_t frag_start = ALIGN(pe_start, frag_align);
740 uint64_t frag_end = pe_end & ~(frag_align - 1);
741
742 unsigned count;
743
Christian König31f6c1f2016-01-26 12:37:49 +0100744 /* Abort early if there isn't anything to do */
745 if (pe_start == pe_end)
746 return;
747
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400748 /* system pages are non continuously */
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400749 if (vm_update_params->src || vm_update_params->pages_addr ||
750 !(flags & AMDGPU_PTE_VALID) || (frag_start >= frag_end)) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400751
752 count = (pe_end - pe_start) / 8;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400753 amdgpu_vm_update_pages(adev, vm_update_params, pe_start,
Christian König9ab21462015-11-30 14:19:26 +0100754 addr, count, AMDGPU_GPU_PAGE_SIZE,
755 flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400756 return;
757 }
758
759 /* handle the 4K area at the beginning */
760 if (pe_start != frag_start) {
761 count = (frag_start - pe_start) / 8;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400762 amdgpu_vm_update_pages(adev, vm_update_params, pe_start, addr,
Christian König9ab21462015-11-30 14:19:26 +0100763 count, AMDGPU_GPU_PAGE_SIZE, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400764 addr += AMDGPU_GPU_PAGE_SIZE * count;
765 }
766
767 /* handle the area in the middle */
768 count = (frag_end - frag_start) / 8;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400769 amdgpu_vm_update_pages(adev, vm_update_params, frag_start, addr, count,
Christian König9ab21462015-11-30 14:19:26 +0100770 AMDGPU_GPU_PAGE_SIZE, flags | frag_flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400771
772 /* handle the 4K area at the end */
773 if (frag_end != pe_end) {
774 addr += AMDGPU_GPU_PAGE_SIZE * count;
775 count = (pe_end - frag_end) / 8;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400776 amdgpu_vm_update_pages(adev, vm_update_params, frag_end, addr,
Christian König9ab21462015-11-30 14:19:26 +0100777 count, AMDGPU_GPU_PAGE_SIZE, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400778 }
779}
780
781/**
782 * amdgpu_vm_update_ptes - make sure that page tables are valid
783 *
784 * @adev: amdgpu_device pointer
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400785 * @vm_update_params: see amdgpu_vm_update_params definition
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400786 * @vm: requested vm
787 * @start: start of GPU address range
788 * @end: end of GPU address range
Alex Xie677131a2016-06-06 18:13:26 -0400789 * @dst: destination address to map to, the next dst inside the function
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400790 * @flags: mapping flags
791 *
Christian König8843dbb2016-01-26 12:17:11 +0100792 * Update the page tables in the range @start - @end.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400793 */
Christian Königa1e08d32016-01-26 11:40:46 +0100794static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400795 struct amdgpu_vm_update_params
796 *vm_update_params,
Christian Königa1e08d32016-01-26 11:40:46 +0100797 struct amdgpu_vm *vm,
Christian Königa1e08d32016-01-26 11:40:46 +0100798 uint64_t start, uint64_t end,
799 uint64_t dst, uint32_t flags)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400800{
Christian König31f6c1f2016-01-26 12:37:49 +0100801 const uint64_t mask = AMDGPU_VM_PTE_COUNT - 1;
802
Alex Xie21718492016-06-06 18:21:09 -0400803 uint64_t cur_pe_start, cur_pe_end, cur_dst;
Alex Xie677131a2016-06-06 18:13:26 -0400804 uint64_t addr; /* next GPU address to be updated */
Alex Xie21718492016-06-06 18:21:09 -0400805 uint64_t pt_idx;
806 struct amdgpu_bo *pt;
807 unsigned nptes; /* next number of ptes to be updated */
808 uint64_t next_pe_start;
809
810 /* initialize the variables */
811 addr = start;
812 pt_idx = addr >> amdgpu_vm_block_size;
813 pt = vm->page_tables[pt_idx].entry.robj;
814
815 if ((addr & ~mask) == (end & ~mask))
816 nptes = end - addr;
817 else
818 nptes = AMDGPU_VM_PTE_COUNT - (addr & mask);
819
820 cur_pe_start = amdgpu_bo_gpu_offset(pt);
821 cur_pe_start += (addr & mask) * 8;
822 cur_pe_end = cur_pe_start + 8 * nptes;
823 cur_dst = dst;
824
825 /* for next ptb*/
826 addr += nptes;
827 dst += nptes * AMDGPU_GPU_PAGE_SIZE;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400828
829 /* walk over the address space and update the page tables */
Alex Xie21718492016-06-06 18:21:09 -0400830 while (addr < end) {
831 pt_idx = addr >> amdgpu_vm_block_size;
832 pt = vm->page_tables[pt_idx].entry.robj;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400833
834 if ((addr & ~mask) == (end & ~mask))
835 nptes = end - addr;
836 else
837 nptes = AMDGPU_VM_PTE_COUNT - (addr & mask);
838
Alex Xie677131a2016-06-06 18:13:26 -0400839 next_pe_start = amdgpu_bo_gpu_offset(pt);
840 next_pe_start += (addr & mask) * 8;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400841
Alex Xie3a6f8e02016-06-06 18:14:57 -0400842 if (cur_pe_end == next_pe_start) {
843 /* The next ptb is consecutive to current ptb.
844 * Don't call amdgpu_vm_frag_ptes now.
845 * Will update two ptbs together in future.
846 */
847 cur_pe_end += 8 * nptes;
848 } else {
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400849 amdgpu_vm_frag_ptes(adev, vm_update_params,
Alex Xie677131a2016-06-06 18:13:26 -0400850 cur_pe_start, cur_pe_end,
851 cur_dst, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400852
Alex Xie677131a2016-06-06 18:13:26 -0400853 cur_pe_start = next_pe_start;
854 cur_pe_end = next_pe_start + 8 * nptes;
855 cur_dst = dst;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400856 }
857
Alex Xie21718492016-06-06 18:21:09 -0400858 /* for next ptb*/
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400859 addr += nptes;
860 dst += nptes * AMDGPU_GPU_PAGE_SIZE;
861 }
862
Alex Xie677131a2016-06-06 18:13:26 -0400863 amdgpu_vm_frag_ptes(adev, vm_update_params, cur_pe_start,
864 cur_pe_end, cur_dst, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400865}
866
867/**
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400868 * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table
869 *
870 * @adev: amdgpu_device pointer
Christian König3cabaa52016-06-06 10:17:58 +0200871 * @exclusive: fence we need to sync to
Christian Königfa3ab3c2016-03-18 21:00:35 +0100872 * @src: address where to copy page table entries from
873 * @pages_addr: DMA addresses to use for mapping
Christian Königa14faa62016-01-25 14:27:31 +0100874 * @vm: requested vm
875 * @start: start of mapped range
876 * @last: last mapped entry
877 * @flags: flags for the entries
878 * @addr: addr to set the area to
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400879 * @fence: optional resulting fence
880 *
Christian Königa14faa62016-01-25 14:27:31 +0100881 * Fill in the page table entries between @start and @last.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400882 * Returns 0 for success, -EINVAL for failure.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400883 */
884static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
Christian König3cabaa52016-06-06 10:17:58 +0200885 struct fence *exclusive,
Christian Königfa3ab3c2016-03-18 21:00:35 +0100886 uint64_t src,
887 dma_addr_t *pages_addr,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400888 struct amdgpu_vm *vm,
Christian Königa14faa62016-01-25 14:27:31 +0100889 uint64_t start, uint64_t last,
890 uint32_t flags, uint64_t addr,
891 struct fence **fence)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400892{
Christian König2d55e452016-02-08 17:37:38 +0100893 struct amdgpu_ring *ring;
Christian Königa1e08d32016-01-26 11:40:46 +0100894 void *owner = AMDGPU_FENCE_OWNER_VM;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400895 unsigned nptes, ncmds, ndw;
Christian Königd71518b2016-02-01 12:20:25 +0100896 struct amdgpu_job *job;
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400897 struct amdgpu_vm_update_params vm_update_params;
Chunming Zhou4af9f072015-08-03 12:57:31 +0800898 struct fence *f = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400899 int r;
900
Christian König2d55e452016-02-08 17:37:38 +0100901 ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400902 memset(&vm_update_params, 0, sizeof(vm_update_params));
903 vm_update_params.src = src;
904 vm_update_params.pages_addr = pages_addr;
Christian König2d55e452016-02-08 17:37:38 +0100905
Christian Königa1e08d32016-01-26 11:40:46 +0100906 /* sync to everything on unmapping */
907 if (!(flags & AMDGPU_PTE_VALID))
908 owner = AMDGPU_FENCE_OWNER_UNDEFINED;
909
Christian Königa14faa62016-01-25 14:27:31 +0100910 nptes = last - start + 1;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400911
912 /*
913 * reserve space for one command every (1 << BLOCK_SIZE)
914 * entries or 2k dwords (whatever is smaller)
915 */
916 ncmds = (nptes >> min(amdgpu_vm_block_size, 11)) + 1;
917
918 /* padding, etc. */
919 ndw = 64;
920
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400921 if (vm_update_params.src) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400922 /* only copy commands needed */
923 ndw += ncmds * 7;
924
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400925 } else if (vm_update_params.pages_addr) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400926 /* header for write data commands */
927 ndw += ncmds * 4;
928
929 /* body of write data command */
930 ndw += nptes * 2;
931
932 } else {
933 /* set page commands needed */
934 ndw += ncmds * 10;
935
936 /* two extra commands for begin/end of fragment */
937 ndw += 2 * 10;
938 }
939
Christian Königd71518b2016-02-01 12:20:25 +0100940 r = amdgpu_job_alloc_with_ib(adev, ndw * 4, &job);
941 if (r)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400942 return r;
Christian Königd71518b2016-02-01 12:20:25 +0100943
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400944 vm_update_params.ib = &job->ibs[0];
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800945
Christian König3cabaa52016-06-06 10:17:58 +0200946 r = amdgpu_sync_fence(adev, &job->sync, exclusive);
947 if (r)
948 goto error_free;
949
Christian Könige86f9ce2016-02-08 12:13:05 +0100950 r = amdgpu_sync_resv(adev, &job->sync, vm->page_directory->tbo.resv,
Christian Königa1e08d32016-01-26 11:40:46 +0100951 owner);
952 if (r)
953 goto error_free;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400954
Christian Königa1e08d32016-01-26 11:40:46 +0100955 r = reservation_object_reserve_shared(vm->page_directory->tbo.resv);
956 if (r)
957 goto error_free;
958
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400959 amdgpu_vm_update_ptes(adev, &vm_update_params, vm, start,
Christian Königfa3ab3c2016-03-18 21:00:35 +0100960 last + 1, addr, flags);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400961
Harish Kasiviswanathanf4833c42016-04-21 10:40:18 -0400962 amdgpu_ring_pad_ib(ring, vm_update_params.ib);
963 WARN_ON(vm_update_params.ib->length_dw > ndw);
Christian König2bd9ccf2016-02-01 12:53:58 +0100964 r = amdgpu_job_submit(job, ring, &vm->entity,
965 AMDGPU_FENCE_OWNER_VM, &f);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800966 if (r)
967 goto error_free;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400968
Christian Königbf60efd2015-09-04 10:47:56 +0200969 amdgpu_bo_fence(vm->page_directory, f, true);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800970 if (fence) {
971 fence_put(*fence);
972 *fence = fence_get(f);
973 }
Chunming Zhou281b4222015-08-12 12:58:31 +0800974 fence_put(f);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400975 return 0;
Chunming Zhoud5fc5e82015-07-21 16:52:10 +0800976
977error_free:
Christian Königd71518b2016-02-01 12:20:25 +0100978 amdgpu_job_free(job);
Chunming Zhou4af9f072015-08-03 12:57:31 +0800979 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400980}
981
982/**
Christian Königa14faa62016-01-25 14:27:31 +0100983 * amdgpu_vm_bo_split_mapping - split a mapping into smaller chunks
984 *
985 * @adev: amdgpu_device pointer
Christian König3cabaa52016-06-06 10:17:58 +0200986 * @exclusive: fence we need to sync to
Christian König8358dce2016-03-30 10:50:25 +0200987 * @gtt_flags: flags as they are used for GTT
988 * @pages_addr: DMA addresses to use for mapping
Christian Königa14faa62016-01-25 14:27:31 +0100989 * @vm: requested vm
990 * @mapping: mapped range and flags to use for the update
991 * @addr: addr to set the area to
Christian König8358dce2016-03-30 10:50:25 +0200992 * @flags: HW flags for the mapping
Christian Königa14faa62016-01-25 14:27:31 +0100993 * @fence: optional resulting fence
994 *
995 * Split the mapping into smaller chunks so that each update fits
996 * into a SDMA IB.
997 * Returns 0 for success, -EINVAL for failure.
998 */
999static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
Christian König3cabaa52016-06-06 10:17:58 +02001000 struct fence *exclusive,
Christian Königa14faa62016-01-25 14:27:31 +01001001 uint32_t gtt_flags,
Christian König8358dce2016-03-30 10:50:25 +02001002 dma_addr_t *pages_addr,
Christian Königa14faa62016-01-25 14:27:31 +01001003 struct amdgpu_vm *vm,
1004 struct amdgpu_bo_va_mapping *mapping,
Christian Königfa3ab3c2016-03-18 21:00:35 +01001005 uint32_t flags, uint64_t addr,
1006 struct fence **fence)
Christian Königa14faa62016-01-25 14:27:31 +01001007{
1008 const uint64_t max_size = 64ULL * 1024ULL * 1024ULL / AMDGPU_GPU_PAGE_SIZE;
1009
Christian Königfa3ab3c2016-03-18 21:00:35 +01001010 uint64_t src = 0, start = mapping->it.start;
Christian Königa14faa62016-01-25 14:27:31 +01001011 int r;
1012
1013 /* normally,bo_va->flags only contians READABLE and WIRTEABLE bit go here
1014 * but in case of something, we filter the flags in first place
1015 */
1016 if (!(mapping->flags & AMDGPU_PTE_READABLE))
1017 flags &= ~AMDGPU_PTE_READABLE;
1018 if (!(mapping->flags & AMDGPU_PTE_WRITEABLE))
1019 flags &= ~AMDGPU_PTE_WRITEABLE;
1020
1021 trace_amdgpu_vm_bo_update(mapping);
1022
Christian König8358dce2016-03-30 10:50:25 +02001023 if (pages_addr) {
Christian Königfa3ab3c2016-03-18 21:00:35 +01001024 if (flags == gtt_flags)
1025 src = adev->gart.table_addr + (addr >> 12) * 8;
Christian Königfa3ab3c2016-03-18 21:00:35 +01001026 addr = 0;
1027 }
Christian Königa14faa62016-01-25 14:27:31 +01001028 addr += mapping->offset;
1029
Christian König8358dce2016-03-30 10:50:25 +02001030 if (!pages_addr || src)
Christian König3cabaa52016-06-06 10:17:58 +02001031 return amdgpu_vm_bo_update_mapping(adev, exclusive,
1032 src, pages_addr, vm,
Christian Königa14faa62016-01-25 14:27:31 +01001033 start, mapping->it.last,
1034 flags, addr, fence);
1035
1036 while (start != mapping->it.last + 1) {
1037 uint64_t last;
1038
Felix Kuehlingfb29b572016-03-03 19:13:20 -05001039 last = min((uint64_t)mapping->it.last, start + max_size - 1);
Christian König3cabaa52016-06-06 10:17:58 +02001040 r = amdgpu_vm_bo_update_mapping(adev, exclusive,
1041 src, pages_addr, vm,
Christian Königa14faa62016-01-25 14:27:31 +01001042 start, last, flags, addr,
1043 fence);
1044 if (r)
1045 return r;
1046
1047 start = last + 1;
Felix Kuehlingfb29b572016-03-03 19:13:20 -05001048 addr += max_size * AMDGPU_GPU_PAGE_SIZE;
Christian Königa14faa62016-01-25 14:27:31 +01001049 }
1050
1051 return 0;
1052}
1053
1054/**
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001055 * amdgpu_vm_bo_update - update all BO mappings in the vm page table
1056 *
1057 * @adev: amdgpu_device pointer
1058 * @bo_va: requested BO and VM object
1059 * @mem: ttm mem
1060 *
1061 * Fill in the page table entries for @bo_va.
1062 * Returns 0 for success, -EINVAL for failure.
1063 *
1064 * Object have to be reserved and mutex must be locked!
1065 */
1066int amdgpu_vm_bo_update(struct amdgpu_device *adev,
1067 struct amdgpu_bo_va *bo_va,
1068 struct ttm_mem_reg *mem)
1069{
1070 struct amdgpu_vm *vm = bo_va->vm;
1071 struct amdgpu_bo_va_mapping *mapping;
Christian König8358dce2016-03-30 10:50:25 +02001072 dma_addr_t *pages_addr = NULL;
Christian Königfa3ab3c2016-03-18 21:00:35 +01001073 uint32_t gtt_flags, flags;
Christian König3cabaa52016-06-06 10:17:58 +02001074 struct fence *exclusive;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001075 uint64_t addr;
1076 int r;
1077
1078 if (mem) {
Christian König8358dce2016-03-30 10:50:25 +02001079 struct ttm_dma_tt *ttm;
1080
Christian Königb7d698d2015-09-07 12:32:09 +02001081 addr = (u64)mem->start << PAGE_SHIFT;
Christian König9ab21462015-11-30 14:19:26 +01001082 switch (mem->mem_type) {
1083 case TTM_PL_TT:
Christian König8358dce2016-03-30 10:50:25 +02001084 ttm = container_of(bo_va->bo->tbo.ttm, struct
1085 ttm_dma_tt, ttm);
1086 pages_addr = ttm->dma_address;
Christian König9ab21462015-11-30 14:19:26 +01001087 break;
1088
1089 case TTM_PL_VRAM:
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001090 addr += adev->vm_manager.vram_base_offset;
Christian König9ab21462015-11-30 14:19:26 +01001091 break;
1092
1093 default:
1094 break;
1095 }
Christian König3cabaa52016-06-06 10:17:58 +02001096
1097 exclusive = reservation_object_get_excl(bo_va->bo->tbo.resv);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001098 } else {
1099 addr = 0;
Christian König3cabaa52016-06-06 10:17:58 +02001100 exclusive = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001101 }
1102
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001103 flags = amdgpu_ttm_tt_pte_flags(adev, bo_va->bo->tbo.ttm, mem);
Christian Königfa3ab3c2016-03-18 21:00:35 +01001104 gtt_flags = (adev == bo_va->bo->adev) ? flags : 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001105
Christian König7fc11952015-07-30 11:53:42 +02001106 spin_lock(&vm->status_lock);
1107 if (!list_empty(&bo_va->vm_status))
1108 list_splice_init(&bo_va->valids, &bo_va->invalids);
1109 spin_unlock(&vm->status_lock);
1110
1111 list_for_each_entry(mapping, &bo_va->invalids, list) {
Christian König3cabaa52016-06-06 10:17:58 +02001112 r = amdgpu_vm_bo_split_mapping(adev, exclusive,
1113 gtt_flags, pages_addr, vm,
Christian König8358dce2016-03-30 10:50:25 +02001114 mapping, flags, addr,
1115 &bo_va->last_pt_update);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001116 if (r)
1117 return r;
1118 }
1119
Christian Königd6c10f62015-09-28 12:00:23 +02001120 if (trace_amdgpu_vm_bo_mapping_enabled()) {
1121 list_for_each_entry(mapping, &bo_va->valids, list)
1122 trace_amdgpu_vm_bo_mapping(mapping);
1123
1124 list_for_each_entry(mapping, &bo_va->invalids, list)
1125 trace_amdgpu_vm_bo_mapping(mapping);
1126 }
1127
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001128 spin_lock(&vm->status_lock);
monk.liu6d1d0ef2015-08-14 13:36:41 +08001129 list_splice_init(&bo_va->invalids, &bo_va->valids);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001130 list_del_init(&bo_va->vm_status);
Christian König7fc11952015-07-30 11:53:42 +02001131 if (!mem)
1132 list_add(&bo_va->vm_status, &vm->cleared);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001133 spin_unlock(&vm->status_lock);
1134
1135 return 0;
1136}
1137
1138/**
1139 * amdgpu_vm_clear_freed - clear freed BOs in the PT
1140 *
1141 * @adev: amdgpu_device pointer
1142 * @vm: requested vm
1143 *
1144 * Make sure all freed BOs are cleared in the PT.
1145 * Returns 0 for success.
1146 *
1147 * PTs have to be reserved and mutex must be locked!
1148 */
1149int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
1150 struct amdgpu_vm *vm)
1151{
1152 struct amdgpu_bo_va_mapping *mapping;
1153 int r;
1154
1155 while (!list_empty(&vm->freed)) {
1156 mapping = list_first_entry(&vm->freed,
1157 struct amdgpu_bo_va_mapping, list);
1158 list_del(&mapping->list);
Christian Könige17841b2016-03-08 17:52:01 +01001159
Christian König3cabaa52016-06-06 10:17:58 +02001160 r = amdgpu_vm_bo_split_mapping(adev, NULL, 0, NULL, vm, mapping,
Christian Königfa3ab3c2016-03-18 21:00:35 +01001161 0, 0, NULL);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001162 kfree(mapping);
1163 if (r)
1164 return r;
1165
1166 }
1167 return 0;
1168
1169}
1170
1171/**
1172 * amdgpu_vm_clear_invalids - clear invalidated BOs in the PT
1173 *
1174 * @adev: amdgpu_device pointer
1175 * @vm: requested vm
1176 *
1177 * Make sure all invalidated BOs are cleared in the PT.
1178 * Returns 0 for success.
1179 *
1180 * PTs have to be reserved and mutex must be locked!
1181 */
1182int amdgpu_vm_clear_invalids(struct amdgpu_device *adev,
monk.liucfe2c972015-05-26 15:01:54 +08001183 struct amdgpu_vm *vm, struct amdgpu_sync *sync)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001184{
monk.liucfe2c972015-05-26 15:01:54 +08001185 struct amdgpu_bo_va *bo_va = NULL;
Christian König91e1a522015-07-06 22:06:40 +02001186 int r = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001187
1188 spin_lock(&vm->status_lock);
1189 while (!list_empty(&vm->invalidated)) {
1190 bo_va = list_first_entry(&vm->invalidated,
1191 struct amdgpu_bo_va, vm_status);
1192 spin_unlock(&vm->status_lock);
Christian König32b41ac2016-03-08 18:03:27 +01001193
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001194 r = amdgpu_vm_bo_update(adev, bo_va, NULL);
1195 if (r)
1196 return r;
1197
1198 spin_lock(&vm->status_lock);
1199 }
1200 spin_unlock(&vm->status_lock);
1201
monk.liucfe2c972015-05-26 15:01:54 +08001202 if (bo_va)
Chunming Zhoubb1e38a42015-08-03 18:19:38 +08001203 r = amdgpu_sync_fence(adev, sync, bo_va->last_pt_update);
Christian König91e1a522015-07-06 22:06:40 +02001204
1205 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001206}
1207
1208/**
1209 * amdgpu_vm_bo_add - add a bo to a specific vm
1210 *
1211 * @adev: amdgpu_device pointer
1212 * @vm: requested vm
1213 * @bo: amdgpu buffer object
1214 *
Christian König8843dbb2016-01-26 12:17:11 +01001215 * Add @bo into the requested vm.
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001216 * Add @bo to the list of bos associated with the vm
1217 * Returns newly added bo_va or NULL for failure
1218 *
1219 * Object has to be reserved!
1220 */
1221struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
1222 struct amdgpu_vm *vm,
1223 struct amdgpu_bo *bo)
1224{
1225 struct amdgpu_bo_va *bo_va;
1226
1227 bo_va = kzalloc(sizeof(struct amdgpu_bo_va), GFP_KERNEL);
1228 if (bo_va == NULL) {
1229 return NULL;
1230 }
1231 bo_va->vm = vm;
1232 bo_va->bo = bo;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001233 bo_va->ref_count = 1;
1234 INIT_LIST_HEAD(&bo_va->bo_list);
Christian König7fc11952015-07-30 11:53:42 +02001235 INIT_LIST_HEAD(&bo_va->valids);
1236 INIT_LIST_HEAD(&bo_va->invalids);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001237 INIT_LIST_HEAD(&bo_va->vm_status);
Christian König32b41ac2016-03-08 18:03:27 +01001238
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001239 list_add_tail(&bo_va->bo_list, &bo->va);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001240
1241 return bo_va;
1242}
1243
1244/**
1245 * amdgpu_vm_bo_map - map bo inside a vm
1246 *
1247 * @adev: amdgpu_device pointer
1248 * @bo_va: bo_va to store the address
1249 * @saddr: where to map the BO
1250 * @offset: requested offset in the BO
1251 * @flags: attributes of pages (read/write/valid/etc.)
1252 *
1253 * Add a mapping of the BO at the specefied addr into the VM.
1254 * Returns 0 for success, error for failure.
1255 *
Chunming Zhou49b02b12015-11-13 14:18:38 +08001256 * Object has to be reserved and unreserved outside!
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001257 */
1258int amdgpu_vm_bo_map(struct amdgpu_device *adev,
1259 struct amdgpu_bo_va *bo_va,
1260 uint64_t saddr, uint64_t offset,
1261 uint64_t size, uint32_t flags)
1262{
1263 struct amdgpu_bo_va_mapping *mapping;
1264 struct amdgpu_vm *vm = bo_va->vm;
1265 struct interval_tree_node *it;
1266 unsigned last_pfn, pt_idx;
1267 uint64_t eaddr;
1268 int r;
1269
Christian König0be52de2015-05-18 14:37:27 +02001270 /* validate the parameters */
1271 if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK ||
Chunming Zhou49b02b12015-11-13 14:18:38 +08001272 size == 0 || size & AMDGPU_GPU_PAGE_MASK)
Christian König0be52de2015-05-18 14:37:27 +02001273 return -EINVAL;
Christian König0be52de2015-05-18 14:37:27 +02001274
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001275 /* make sure object fit at this offset */
Felix Kuehling005ae952015-11-23 17:43:48 -05001276 eaddr = saddr + size - 1;
Chunming Zhou49b02b12015-11-13 14:18:38 +08001277 if ((saddr >= eaddr) || (offset + size > amdgpu_bo_size(bo_va->bo)))
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001278 return -EINVAL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001279
1280 last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
Felix Kuehling005ae952015-11-23 17:43:48 -05001281 if (last_pfn >= adev->vm_manager.max_pfn) {
1282 dev_err(adev->dev, "va above limit (0x%08X >= 0x%08X)\n",
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001283 last_pfn, adev->vm_manager.max_pfn);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001284 return -EINVAL;
1285 }
1286
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001287 saddr /= AMDGPU_GPU_PAGE_SIZE;
1288 eaddr /= AMDGPU_GPU_PAGE_SIZE;
1289
Felix Kuehling005ae952015-11-23 17:43:48 -05001290 it = interval_tree_iter_first(&vm->va, saddr, eaddr);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001291 if (it) {
1292 struct amdgpu_bo_va_mapping *tmp;
1293 tmp = container_of(it, struct amdgpu_bo_va_mapping, it);
1294 /* bo and tmp overlap, invalid addr */
1295 dev_err(adev->dev, "bo %p va 0x%010Lx-0x%010Lx conflict with "
1296 "0x%010lx-0x%010lx\n", bo_va->bo, saddr, eaddr,
1297 tmp->it.start, tmp->it.last + 1);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001298 r = -EINVAL;
Chunming Zhouf48b2652015-10-16 14:06:19 +08001299 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001300 }
1301
1302 mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
1303 if (!mapping) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001304 r = -ENOMEM;
Chunming Zhouf48b2652015-10-16 14:06:19 +08001305 goto error;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001306 }
1307
1308 INIT_LIST_HEAD(&mapping->list);
1309 mapping->it.start = saddr;
Felix Kuehling005ae952015-11-23 17:43:48 -05001310 mapping->it.last = eaddr;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001311 mapping->offset = offset;
1312 mapping->flags = flags;
1313
Christian König7fc11952015-07-30 11:53:42 +02001314 list_add(&mapping->list, &bo_va->invalids);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001315 interval_tree_insert(&mapping->it, &vm->va);
1316
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001317 /* Make sure the page tables are allocated */
1318 saddr >>= amdgpu_vm_block_size;
1319 eaddr >>= amdgpu_vm_block_size;
1320
1321 BUG_ON(eaddr >= amdgpu_vm_num_pdes(adev));
1322
1323 if (eaddr > vm->max_pde_used)
1324 vm->max_pde_used = eaddr;
1325
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001326 /* walk over the address space and allocate the page tables */
1327 for (pt_idx = saddr; pt_idx <= eaddr; ++pt_idx) {
Christian Königbf60efd2015-09-04 10:47:56 +02001328 struct reservation_object *resv = vm->page_directory->tbo.resv;
Christian Königee1782c2015-12-11 21:01:23 +01001329 struct amdgpu_bo_list_entry *entry;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001330 struct amdgpu_bo *pt;
1331
Christian Königee1782c2015-12-11 21:01:23 +01001332 entry = &vm->page_tables[pt_idx].entry;
1333 if (entry->robj)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001334 continue;
1335
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001336 r = amdgpu_bo_create(adev, AMDGPU_VM_PTE_COUNT * 8,
1337 AMDGPU_GPU_PAGE_SIZE, true,
Alex Deucher857d9132015-08-27 00:14:16 -04001338 AMDGPU_GEM_DOMAIN_VRAM,
1339 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
Christian Königbf60efd2015-09-04 10:47:56 +02001340 NULL, resv, &pt);
Chunming Zhou49b02b12015-11-13 14:18:38 +08001341 if (r)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001342 goto error_free;
Chunming Zhou49b02b12015-11-13 14:18:38 +08001343
Christian König82b9c552015-11-27 16:49:00 +01001344 /* Keep a reference to the page table to avoid freeing
1345 * them up in the wrong order.
1346 */
1347 pt->parent = amdgpu_bo_ref(vm->page_directory);
1348
Christian König2bd9ccf2016-02-01 12:53:58 +01001349 r = amdgpu_vm_clear_bo(adev, vm, pt);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001350 if (r) {
1351 amdgpu_bo_unref(&pt);
1352 goto error_free;
1353 }
1354
Christian Königee1782c2015-12-11 21:01:23 +01001355 entry->robj = pt;
Christian Königee1782c2015-12-11 21:01:23 +01001356 entry->priority = 0;
1357 entry->tv.bo = &entry->robj->tbo;
1358 entry->tv.shared = true;
Christian König2f568db2016-02-23 12:36:59 +01001359 entry->user_pages = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001360 vm->page_tables[pt_idx].addr = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001361 }
1362
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001363 return 0;
1364
1365error_free:
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001366 list_del(&mapping->list);
1367 interval_tree_remove(&mapping->it, &vm->va);
Christian König93e3e432015-06-09 16:58:33 +02001368 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001369 kfree(mapping);
1370
Chunming Zhouf48b2652015-10-16 14:06:19 +08001371error:
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001372 return r;
1373}
1374
1375/**
1376 * amdgpu_vm_bo_unmap - remove bo mapping from vm
1377 *
1378 * @adev: amdgpu_device pointer
1379 * @bo_va: bo_va to remove the address from
1380 * @saddr: where to the BO is mapped
1381 *
1382 * Remove a mapping of the BO at the specefied addr from the VM.
1383 * Returns 0 for success, error for failure.
1384 *
Chunming Zhou49b02b12015-11-13 14:18:38 +08001385 * Object has to be reserved and unreserved outside!
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001386 */
1387int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
1388 struct amdgpu_bo_va *bo_va,
1389 uint64_t saddr)
1390{
1391 struct amdgpu_bo_va_mapping *mapping;
1392 struct amdgpu_vm *vm = bo_va->vm;
Christian König7fc11952015-07-30 11:53:42 +02001393 bool valid = true;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001394
Christian König6c7fc502015-06-05 20:56:17 +02001395 saddr /= AMDGPU_GPU_PAGE_SIZE;
Christian König32b41ac2016-03-08 18:03:27 +01001396
Christian König7fc11952015-07-30 11:53:42 +02001397 list_for_each_entry(mapping, &bo_va->valids, list) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001398 if (mapping->it.start == saddr)
1399 break;
1400 }
1401
Christian König7fc11952015-07-30 11:53:42 +02001402 if (&mapping->list == &bo_va->valids) {
1403 valid = false;
1404
1405 list_for_each_entry(mapping, &bo_va->invalids, list) {
1406 if (mapping->it.start == saddr)
1407 break;
1408 }
1409
Christian König32b41ac2016-03-08 18:03:27 +01001410 if (&mapping->list == &bo_va->invalids)
Christian König7fc11952015-07-30 11:53:42 +02001411 return -ENOENT;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001412 }
Christian König32b41ac2016-03-08 18:03:27 +01001413
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001414 list_del(&mapping->list);
1415 interval_tree_remove(&mapping->it, &vm->va);
Christian König93e3e432015-06-09 16:58:33 +02001416 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001417
Christian Könige17841b2016-03-08 17:52:01 +01001418 if (valid)
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001419 list_add(&mapping->list, &vm->freed);
Christian Könige17841b2016-03-08 17:52:01 +01001420 else
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001421 kfree(mapping);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001422
1423 return 0;
1424}
1425
1426/**
1427 * amdgpu_vm_bo_rmv - remove a bo to a specific vm
1428 *
1429 * @adev: amdgpu_device pointer
1430 * @bo_va: requested bo_va
1431 *
Christian König8843dbb2016-01-26 12:17:11 +01001432 * Remove @bo_va->bo from the requested vm.
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001433 *
1434 * Object have to be reserved!
1435 */
1436void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
1437 struct amdgpu_bo_va *bo_va)
1438{
1439 struct amdgpu_bo_va_mapping *mapping, *next;
1440 struct amdgpu_vm *vm = bo_va->vm;
1441
1442 list_del(&bo_va->bo_list);
1443
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001444 spin_lock(&vm->status_lock);
1445 list_del(&bo_va->vm_status);
1446 spin_unlock(&vm->status_lock);
1447
Christian König7fc11952015-07-30 11:53:42 +02001448 list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001449 list_del(&mapping->list);
1450 interval_tree_remove(&mapping->it, &vm->va);
Christian König93e3e432015-06-09 16:58:33 +02001451 trace_amdgpu_vm_bo_unmap(bo_va, mapping);
Christian König7fc11952015-07-30 11:53:42 +02001452 list_add(&mapping->list, &vm->freed);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001453 }
Christian König7fc11952015-07-30 11:53:42 +02001454 list_for_each_entry_safe(mapping, next, &bo_va->invalids, list) {
1455 list_del(&mapping->list);
1456 interval_tree_remove(&mapping->it, &vm->va);
1457 kfree(mapping);
1458 }
Christian König32b41ac2016-03-08 18:03:27 +01001459
Chunming Zhoubb1e38a42015-08-03 18:19:38 +08001460 fence_put(bo_va->last_pt_update);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001461 kfree(bo_va);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001462}
1463
1464/**
1465 * amdgpu_vm_bo_invalidate - mark the bo as invalid
1466 *
1467 * @adev: amdgpu_device pointer
1468 * @vm: requested vm
1469 * @bo: amdgpu buffer object
1470 *
Christian König8843dbb2016-01-26 12:17:11 +01001471 * Mark @bo as invalid.
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001472 */
1473void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
1474 struct amdgpu_bo *bo)
1475{
1476 struct amdgpu_bo_va *bo_va;
1477
1478 list_for_each_entry(bo_va, &bo->va, bo_list) {
Christian König7fc11952015-07-30 11:53:42 +02001479 spin_lock(&bo_va->vm->status_lock);
1480 if (list_empty(&bo_va->vm_status))
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001481 list_add(&bo_va->vm_status, &bo_va->vm->invalidated);
Christian König7fc11952015-07-30 11:53:42 +02001482 spin_unlock(&bo_va->vm->status_lock);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001483 }
1484}
1485
1486/**
1487 * amdgpu_vm_init - initialize a vm instance
1488 *
1489 * @adev: amdgpu_device pointer
1490 * @vm: requested vm
1491 *
Christian König8843dbb2016-01-26 12:17:11 +01001492 * Init @vm fields.
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001493 */
1494int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1495{
1496 const unsigned align = min(AMDGPU_VM_PTB_ALIGN_SIZE,
1497 AMDGPU_VM_PTE_COUNT * 8);
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001498 unsigned pd_size, pd_entries;
Christian König2d55e452016-02-08 17:37:38 +01001499 unsigned ring_instance;
1500 struct amdgpu_ring *ring;
Christian König2bd9ccf2016-02-01 12:53:58 +01001501 struct amd_sched_rq *rq;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001502 int i, r;
1503
Christian Königbcb1ba32016-03-08 15:40:11 +01001504 for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
1505 vm->ids[i] = NULL;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001506 vm->va = RB_ROOT;
Chunming Zhou031e2982016-04-25 10:19:13 +08001507 vm->client_id = atomic64_inc_return(&adev->vm_manager.client_counter);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001508 spin_lock_init(&vm->status_lock);
1509 INIT_LIST_HEAD(&vm->invalidated);
Christian König7fc11952015-07-30 11:53:42 +02001510 INIT_LIST_HEAD(&vm->cleared);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001511 INIT_LIST_HEAD(&vm->freed);
Christian König20250212016-03-08 17:58:35 +01001512
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001513 pd_size = amdgpu_vm_directory_size(adev);
1514 pd_entries = amdgpu_vm_num_pdes(adev);
1515
1516 /* allocate page table array */
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001517 vm->page_tables = drm_calloc_large(pd_entries, sizeof(struct amdgpu_vm_pt));
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001518 if (vm->page_tables == NULL) {
1519 DRM_ERROR("Cannot allocate memory for page table array\n");
1520 return -ENOMEM;
1521 }
1522
Christian König2bd9ccf2016-02-01 12:53:58 +01001523 /* create scheduler entity for page table updates */
Christian König2d55e452016-02-08 17:37:38 +01001524
1525 ring_instance = atomic_inc_return(&adev->vm_manager.vm_pte_next_ring);
1526 ring_instance %= adev->vm_manager.vm_pte_num_rings;
1527 ring = adev->vm_manager.vm_pte_rings[ring_instance];
Christian König2bd9ccf2016-02-01 12:53:58 +01001528 rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_KERNEL];
1529 r = amd_sched_entity_init(&ring->sched, &vm->entity,
1530 rq, amdgpu_sched_jobs);
1531 if (r)
1532 return r;
1533
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +02001534 vm->page_directory_fence = NULL;
1535
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001536 r = amdgpu_bo_create(adev, pd_size, align, true,
Alex Deucher857d9132015-08-27 00:14:16 -04001537 AMDGPU_GEM_DOMAIN_VRAM,
1538 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
Christian König72d76682015-09-03 17:34:59 +02001539 NULL, NULL, &vm->page_directory);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001540 if (r)
Christian König2bd9ccf2016-02-01 12:53:58 +01001541 goto error_free_sched_entity;
1542
Chunming Zhouef9f0a82015-11-13 13:43:22 +08001543 r = amdgpu_bo_reserve(vm->page_directory, false);
Christian König2bd9ccf2016-02-01 12:53:58 +01001544 if (r)
1545 goto error_free_page_directory;
1546
1547 r = amdgpu_vm_clear_bo(adev, vm, vm->page_directory);
Chunming Zhouef9f0a82015-11-13 13:43:22 +08001548 amdgpu_bo_unreserve(vm->page_directory);
Christian König2bd9ccf2016-02-01 12:53:58 +01001549 if (r)
1550 goto error_free_page_directory;
Christian König5a712a82016-06-21 16:28:15 +02001551 vm->last_eviction_counter = atomic64_read(&adev->num_evictions);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001552
1553 return 0;
Christian König2bd9ccf2016-02-01 12:53:58 +01001554
1555error_free_page_directory:
1556 amdgpu_bo_unref(&vm->page_directory);
1557 vm->page_directory = NULL;
1558
1559error_free_sched_entity:
1560 amd_sched_entity_fini(&ring->sched, &vm->entity);
1561
1562 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001563}
1564
1565/**
1566 * amdgpu_vm_fini - tear down a vm instance
1567 *
1568 * @adev: amdgpu_device pointer
1569 * @vm: requested vm
1570 *
Christian König8843dbb2016-01-26 12:17:11 +01001571 * Tear down @vm.
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001572 * Unbind the VM and remove all bos from the vm bo list
1573 */
1574void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1575{
1576 struct amdgpu_bo_va_mapping *mapping, *tmp;
1577 int i;
1578
Christian König2d55e452016-02-08 17:37:38 +01001579 amd_sched_entity_fini(vm->entity.sched, &vm->entity);
Christian König2bd9ccf2016-02-01 12:53:58 +01001580
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001581 if (!RB_EMPTY_ROOT(&vm->va)) {
1582 dev_err(adev->dev, "still active bo inside vm\n");
1583 }
1584 rbtree_postorder_for_each_entry_safe(mapping, tmp, &vm->va, it.rb) {
1585 list_del(&mapping->list);
1586 interval_tree_remove(&mapping->it, &vm->va);
1587 kfree(mapping);
1588 }
1589 list_for_each_entry_safe(mapping, tmp, &vm->freed, list) {
1590 list_del(&mapping->list);
1591 kfree(mapping);
1592 }
1593
1594 for (i = 0; i < amdgpu_vm_num_pdes(adev); i++)
Christian Königee1782c2015-12-11 21:01:23 +01001595 amdgpu_bo_unref(&vm->page_tables[i].entry.robj);
Michel Dänzer9571e1d2016-01-19 17:59:46 +09001596 drm_free_large(vm->page_tables);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001597
1598 amdgpu_bo_unref(&vm->page_directory);
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +02001599 fence_put(vm->page_directory_fence);
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001600}
Christian Königea89f8c2015-11-15 20:52:06 +01001601
1602/**
Christian Königa9a78b32016-01-21 10:19:11 +01001603 * amdgpu_vm_manager_init - init the VM manager
1604 *
1605 * @adev: amdgpu_device pointer
1606 *
1607 * Initialize the VM manager structures
1608 */
1609void amdgpu_vm_manager_init(struct amdgpu_device *adev)
1610{
1611 unsigned i;
1612
1613 INIT_LIST_HEAD(&adev->vm_manager.ids_lru);
1614
1615 /* skip over VMID 0, since it is the system VM */
Christian König971fe9a92016-03-01 15:09:25 +01001616 for (i = 1; i < adev->vm_manager.num_ids; ++i) {
1617 amdgpu_vm_reset_id(adev, i);
Christian König832a9022016-02-15 12:33:02 +01001618 amdgpu_sync_create(&adev->vm_manager.ids[i].active);
Christian Königa9a78b32016-01-21 10:19:11 +01001619 list_add_tail(&adev->vm_manager.ids[i].list,
1620 &adev->vm_manager.ids_lru);
Christian König971fe9a92016-03-01 15:09:25 +01001621 }
Christian König2d55e452016-02-08 17:37:38 +01001622
Christian König1fbb2e92016-06-01 10:47:36 +02001623 adev->vm_manager.fence_context = fence_context_alloc(AMDGPU_MAX_RINGS);
1624 for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
1625 adev->vm_manager.seqno[i] = 0;
1626
Christian König2d55e452016-02-08 17:37:38 +01001627 atomic_set(&adev->vm_manager.vm_pte_next_ring, 0);
Christian Königb1c8a812016-05-04 10:34:03 +02001628 atomic64_set(&adev->vm_manager.client_counter, 0);
Christian Königa9a78b32016-01-21 10:19:11 +01001629}
1630
1631/**
Christian Königea89f8c2015-11-15 20:52:06 +01001632 * amdgpu_vm_manager_fini - cleanup VM manager
1633 *
1634 * @adev: amdgpu_device pointer
1635 *
1636 * Cleanup the VM manager and free resources.
1637 */
1638void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
1639{
1640 unsigned i;
1641
Christian Königbcb1ba32016-03-08 15:40:11 +01001642 for (i = 0; i < AMDGPU_NUM_VM; ++i) {
1643 struct amdgpu_vm_id *id = &adev->vm_manager.ids[i];
1644
Christian König832a9022016-02-15 12:33:02 +01001645 fence_put(adev->vm_manager.ids[i].first);
1646 amdgpu_sync_free(&adev->vm_manager.ids[i].active);
Christian Königbcb1ba32016-03-08 15:40:11 +01001647 fence_put(id->flushed_updates);
1648 }
Christian Königea89f8c2015-11-15 20:52:06 +01001649}