.. | .. |
---|
38 | 38 | #include <linux/slab.h> |
---|
39 | 39 | #include <linux/vmalloc.h> |
---|
40 | 40 | #include <linux/module.h> |
---|
41 | | -#include <linux/reservation.h> |
---|
| 41 | +#include <linux/dma-resv.h> |
---|
42 | 42 | |
---|
43 | 43 | struct ttm_transfer_obj { |
---|
44 | 44 | struct ttm_buffer_object base; |
---|
.. | .. |
---|
47 | 47 | |
---|
48 | 48 | void ttm_bo_free_old_node(struct ttm_buffer_object *bo) |
---|
49 | 49 | { |
---|
50 | | - ttm_bo_mem_put(bo, &bo->mem); |
---|
| 50 | + ttm_resource_free(bo, &bo->mem); |
---|
51 | 51 | } |
---|
52 | 52 | |
---|
53 | 53 | int ttm_bo_move_ttm(struct ttm_buffer_object *bo, |
---|
54 | 54 | struct ttm_operation_ctx *ctx, |
---|
55 | | - struct ttm_mem_reg *new_mem) |
---|
| 55 | + struct ttm_resource *new_mem) |
---|
56 | 56 | { |
---|
57 | 57 | struct ttm_tt *ttm = bo->ttm; |
---|
58 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
---|
| 58 | + struct ttm_resource *old_mem = &bo->mem; |
---|
59 | 59 | int ret; |
---|
60 | 60 | |
---|
61 | 61 | if (old_mem->mem_type != TTM_PL_SYSTEM) { |
---|
.. | .. |
---|
67 | 67 | return ret; |
---|
68 | 68 | } |
---|
69 | 69 | |
---|
70 | | - ttm_tt_unbind(ttm); |
---|
| 70 | + ttm_bo_tt_unbind(bo); |
---|
71 | 71 | ttm_bo_free_old_node(bo); |
---|
72 | | - ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM, |
---|
73 | | - TTM_PL_MASK_MEM); |
---|
74 | 72 | old_mem->mem_type = TTM_PL_SYSTEM; |
---|
75 | 73 | } |
---|
76 | 74 | |
---|
.. | .. |
---|
79 | 77 | return ret; |
---|
80 | 78 | |
---|
81 | 79 | if (new_mem->mem_type != TTM_PL_SYSTEM) { |
---|
82 | | - ret = ttm_tt_bind(ttm, new_mem, ctx); |
---|
| 80 | + |
---|
| 81 | + ret = ttm_tt_populate(bo->bdev, ttm, ctx); |
---|
| 82 | + if (unlikely(ret != 0)) |
---|
| 83 | + return ret; |
---|
| 84 | + |
---|
| 85 | + ret = ttm_bo_tt_bind(bo, new_mem); |
---|
83 | 86 | if (unlikely(ret != 0)) |
---|
84 | 87 | return ret; |
---|
85 | 88 | } |
---|
86 | 89 | |
---|
87 | | - *old_mem = *new_mem; |
---|
88 | | - new_mem->mm_node = NULL; |
---|
89 | | - |
---|
| 90 | + ttm_bo_assign_mem(bo, new_mem); |
---|
90 | 91 | return 0; |
---|
91 | 92 | } |
---|
92 | 93 | EXPORT_SYMBOL(ttm_bo_move_ttm); |
---|
93 | 94 | |
---|
94 | | -int ttm_mem_io_lock(struct ttm_mem_type_manager *man, bool interruptible) |
---|
| 95 | +int ttm_mem_io_reserve(struct ttm_bo_device *bdev, |
---|
| 96 | + struct ttm_resource *mem) |
---|
95 | 97 | { |
---|
96 | | - if (likely(man->io_reserve_fastpath)) |
---|
| 98 | + if (mem->bus.offset || mem->bus.addr) |
---|
97 | 99 | return 0; |
---|
98 | 100 | |
---|
99 | | - if (interruptible) |
---|
100 | | - return mutex_lock_interruptible(&man->io_reserve_mutex); |
---|
101 | | - |
---|
102 | | - mutex_lock(&man->io_reserve_mutex); |
---|
103 | | - return 0; |
---|
104 | | -} |
---|
105 | | -EXPORT_SYMBOL(ttm_mem_io_lock); |
---|
106 | | - |
---|
107 | | -void ttm_mem_io_unlock(struct ttm_mem_type_manager *man) |
---|
108 | | -{ |
---|
109 | | - if (likely(man->io_reserve_fastpath)) |
---|
110 | | - return; |
---|
111 | | - |
---|
112 | | - mutex_unlock(&man->io_reserve_mutex); |
---|
113 | | -} |
---|
114 | | -EXPORT_SYMBOL(ttm_mem_io_unlock); |
---|
115 | | - |
---|
116 | | -static int ttm_mem_io_evict(struct ttm_mem_type_manager *man) |
---|
117 | | -{ |
---|
118 | | - struct ttm_buffer_object *bo; |
---|
119 | | - |
---|
120 | | - if (!man->use_io_reserve_lru || list_empty(&man->io_reserve_lru)) |
---|
121 | | - return -EAGAIN; |
---|
122 | | - |
---|
123 | | - bo = list_first_entry(&man->io_reserve_lru, |
---|
124 | | - struct ttm_buffer_object, |
---|
125 | | - io_reserve_lru); |
---|
126 | | - list_del_init(&bo->io_reserve_lru); |
---|
127 | | - ttm_bo_unmap_virtual_locked(bo); |
---|
128 | | - |
---|
129 | | - return 0; |
---|
130 | | -} |
---|
131 | | - |
---|
132 | | - |
---|
133 | | -int ttm_mem_io_reserve(struct ttm_bo_device *bdev, |
---|
134 | | - struct ttm_mem_reg *mem) |
---|
135 | | -{ |
---|
136 | | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
---|
137 | | - int ret = 0; |
---|
138 | | - |
---|
| 101 | + mem->bus.is_iomem = false; |
---|
139 | 102 | if (!bdev->driver->io_mem_reserve) |
---|
140 | 103 | return 0; |
---|
141 | | - if (likely(man->io_reserve_fastpath)) |
---|
142 | | - return bdev->driver->io_mem_reserve(bdev, mem); |
---|
143 | 104 | |
---|
144 | | - if (bdev->driver->io_mem_reserve && |
---|
145 | | - mem->bus.io_reserved_count++ == 0) { |
---|
146 | | -retry: |
---|
147 | | - ret = bdev->driver->io_mem_reserve(bdev, mem); |
---|
148 | | - if (ret == -EAGAIN) { |
---|
149 | | - ret = ttm_mem_io_evict(man); |
---|
150 | | - if (ret == 0) |
---|
151 | | - goto retry; |
---|
152 | | - } |
---|
153 | | - } |
---|
154 | | - return ret; |
---|
| 105 | + return bdev->driver->io_mem_reserve(bdev, mem); |
---|
155 | 106 | } |
---|
156 | | -EXPORT_SYMBOL(ttm_mem_io_reserve); |
---|
157 | 107 | |
---|
158 | 108 | void ttm_mem_io_free(struct ttm_bo_device *bdev, |
---|
159 | | - struct ttm_mem_reg *mem) |
---|
| 109 | + struct ttm_resource *mem) |
---|
160 | 110 | { |
---|
161 | | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
---|
162 | | - |
---|
163 | | - if (likely(man->io_reserve_fastpath)) |
---|
| 111 | + if (!mem->bus.offset && !mem->bus.addr) |
---|
164 | 112 | return; |
---|
165 | 113 | |
---|
166 | | - if (bdev->driver->io_mem_reserve && |
---|
167 | | - --mem->bus.io_reserved_count == 0 && |
---|
168 | | - bdev->driver->io_mem_free) |
---|
| 114 | + if (bdev->driver->io_mem_free) |
---|
169 | 115 | bdev->driver->io_mem_free(bdev, mem); |
---|
170 | 116 | |
---|
171 | | -} |
---|
172 | | -EXPORT_SYMBOL(ttm_mem_io_free); |
---|
173 | | - |
---|
174 | | -int ttm_mem_io_reserve_vm(struct ttm_buffer_object *bo) |
---|
175 | | -{ |
---|
176 | | - struct ttm_mem_reg *mem = &bo->mem; |
---|
177 | | - int ret; |
---|
178 | | - |
---|
179 | | - if (!mem->bus.io_reserved_vm) { |
---|
180 | | - struct ttm_mem_type_manager *man = |
---|
181 | | - &bo->bdev->man[mem->mem_type]; |
---|
182 | | - |
---|
183 | | - ret = ttm_mem_io_reserve(bo->bdev, mem); |
---|
184 | | - if (unlikely(ret != 0)) |
---|
185 | | - return ret; |
---|
186 | | - mem->bus.io_reserved_vm = true; |
---|
187 | | - if (man->use_io_reserve_lru) |
---|
188 | | - list_add_tail(&bo->io_reserve_lru, |
---|
189 | | - &man->io_reserve_lru); |
---|
190 | | - } |
---|
191 | | - return 0; |
---|
| 117 | + mem->bus.offset = 0; |
---|
| 118 | + mem->bus.addr = NULL; |
---|
192 | 119 | } |
---|
193 | 120 | |
---|
194 | | -void ttm_mem_io_free_vm(struct ttm_buffer_object *bo) |
---|
| 121 | +static int ttm_resource_ioremap(struct ttm_bo_device *bdev, |
---|
| 122 | + struct ttm_resource *mem, |
---|
| 123 | + void **virtual) |
---|
195 | 124 | { |
---|
196 | | - struct ttm_mem_reg *mem = &bo->mem; |
---|
197 | | - |
---|
198 | | - if (mem->bus.io_reserved_vm) { |
---|
199 | | - mem->bus.io_reserved_vm = false; |
---|
200 | | - list_del_init(&bo->io_reserve_lru); |
---|
201 | | - ttm_mem_io_free(bo->bdev, mem); |
---|
202 | | - } |
---|
203 | | -} |
---|
204 | | - |
---|
205 | | -static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem, |
---|
206 | | - void **virtual) |
---|
207 | | -{ |
---|
208 | | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
---|
209 | 125 | int ret; |
---|
210 | 126 | void *addr; |
---|
211 | 127 | |
---|
212 | 128 | *virtual = NULL; |
---|
213 | | - (void) ttm_mem_io_lock(man, false); |
---|
214 | 129 | ret = ttm_mem_io_reserve(bdev, mem); |
---|
215 | | - ttm_mem_io_unlock(man); |
---|
216 | 130 | if (ret || !mem->bus.is_iomem) |
---|
217 | 131 | return ret; |
---|
218 | 132 | |
---|
219 | 133 | if (mem->bus.addr) { |
---|
220 | 134 | addr = mem->bus.addr; |
---|
221 | 135 | } else { |
---|
| 136 | + size_t bus_size = (size_t)mem->num_pages << PAGE_SHIFT; |
---|
| 137 | + |
---|
222 | 138 | if (mem->placement & TTM_PL_FLAG_WC) |
---|
223 | | - addr = ioremap_wc(mem->bus.base + mem->bus.offset, mem->bus.size); |
---|
| 139 | + addr = ioremap_wc(mem->bus.offset, bus_size); |
---|
224 | 140 | else |
---|
225 | | - addr = ioremap_nocache(mem->bus.base + mem->bus.offset, mem->bus.size); |
---|
| 141 | + addr = ioremap(mem->bus.offset, bus_size); |
---|
226 | 142 | if (!addr) { |
---|
227 | | - (void) ttm_mem_io_lock(man, false); |
---|
228 | 143 | ttm_mem_io_free(bdev, mem); |
---|
229 | | - ttm_mem_io_unlock(man); |
---|
230 | 144 | return -ENOMEM; |
---|
231 | 145 | } |
---|
232 | 146 | } |
---|
.. | .. |
---|
234 | 148 | return 0; |
---|
235 | 149 | } |
---|
236 | 150 | |
---|
237 | | -static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem, |
---|
238 | | - void *virtual) |
---|
| 151 | +static void ttm_resource_iounmap(struct ttm_bo_device *bdev, |
---|
| 152 | + struct ttm_resource *mem, |
---|
| 153 | + void *virtual) |
---|
239 | 154 | { |
---|
240 | | - struct ttm_mem_type_manager *man; |
---|
241 | | - |
---|
242 | | - man = &bdev->man[mem->mem_type]; |
---|
243 | | - |
---|
244 | 155 | if (virtual && mem->bus.addr == NULL) |
---|
245 | 156 | iounmap(virtual); |
---|
246 | | - (void) ttm_mem_io_lock(man, false); |
---|
247 | 157 | ttm_mem_io_free(bdev, mem); |
---|
248 | | - ttm_mem_io_unlock(man); |
---|
249 | 158 | } |
---|
250 | 159 | |
---|
251 | 160 | static int ttm_copy_io_page(void *dst, void *src, unsigned long page) |
---|
.. | .. |
---|
261 | 170 | return 0; |
---|
262 | 171 | } |
---|
263 | 172 | |
---|
264 | | -#ifdef CONFIG_X86 |
---|
265 | | -#define __ttm_kmap_atomic_prot(__page, __prot) kmap_atomic_prot(__page, __prot) |
---|
266 | | -#define __ttm_kunmap_atomic(__addr) kunmap_atomic(__addr) |
---|
267 | | -#else |
---|
268 | | -#define __ttm_kmap_atomic_prot(__page, __prot) vmap(&__page, 1, 0, __prot) |
---|
269 | | -#define __ttm_kunmap_atomic(__addr) vunmap(__addr) |
---|
270 | | -#endif |
---|
271 | | - |
---|
272 | | - |
---|
273 | | -/** |
---|
274 | | - * ttm_kmap_atomic_prot - Efficient kernel map of a single page with |
---|
275 | | - * specified page protection. |
---|
276 | | - * |
---|
277 | | - * @page: The page to map. |
---|
278 | | - * @prot: The page protection. |
---|
279 | | - * |
---|
280 | | - * This function maps a TTM page using the kmap_atomic api if available, |
---|
281 | | - * otherwise falls back to vmap. The user must make sure that the |
---|
282 | | - * specified page does not have an aliased mapping with a different caching |
---|
283 | | - * policy unless the architecture explicitly allows it. Also mapping and |
---|
284 | | - * unmapping using this api must be correctly nested. Unmapping should |
---|
285 | | - * occur in the reverse order of mapping. |
---|
286 | | - */ |
---|
287 | | -void *ttm_kmap_atomic_prot(struct page *page, pgprot_t prot) |
---|
288 | | -{ |
---|
289 | | - if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) |
---|
290 | | - return kmap_atomic(page); |
---|
291 | | - else |
---|
292 | | - return __ttm_kmap_atomic_prot(page, prot); |
---|
293 | | -} |
---|
294 | | -EXPORT_SYMBOL(ttm_kmap_atomic_prot); |
---|
295 | | - |
---|
296 | | -/** |
---|
297 | | - * ttm_kunmap_atomic_prot - Unmap a page that was mapped using |
---|
298 | | - * ttm_kmap_atomic_prot. |
---|
299 | | - * |
---|
300 | | - * @addr: The virtual address from the map. |
---|
301 | | - * @prot: The page protection. |
---|
302 | | - */ |
---|
303 | | -void ttm_kunmap_atomic_prot(void *addr, pgprot_t prot) |
---|
304 | | -{ |
---|
305 | | - if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) |
---|
306 | | - kunmap_atomic(addr); |
---|
307 | | - else |
---|
308 | | - __ttm_kunmap_atomic(addr); |
---|
309 | | -} |
---|
310 | | -EXPORT_SYMBOL(ttm_kunmap_atomic_prot); |
---|
311 | | - |
---|
312 | 173 | static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, |
---|
313 | 174 | unsigned long page, |
---|
314 | 175 | pgprot_t prot) |
---|
.. | .. |
---|
320 | 181 | return -ENOMEM; |
---|
321 | 182 | |
---|
322 | 183 | src = (void *)((unsigned long)src + (page << PAGE_SHIFT)); |
---|
323 | | - dst = ttm_kmap_atomic_prot(d, prot); |
---|
| 184 | + dst = kmap_atomic_prot(d, prot); |
---|
324 | 185 | if (!dst) |
---|
325 | 186 | return -ENOMEM; |
---|
326 | 187 | |
---|
327 | 188 | memcpy_fromio(dst, src, PAGE_SIZE); |
---|
328 | 189 | |
---|
329 | | - ttm_kunmap_atomic_prot(dst, prot); |
---|
| 190 | + kunmap_atomic(dst); |
---|
330 | 191 | |
---|
331 | 192 | return 0; |
---|
332 | 193 | } |
---|
.. | .. |
---|
342 | 203 | return -ENOMEM; |
---|
343 | 204 | |
---|
344 | 205 | dst = (void *)((unsigned long)dst + (page << PAGE_SHIFT)); |
---|
345 | | - src = ttm_kmap_atomic_prot(s, prot); |
---|
| 206 | + src = kmap_atomic_prot(s, prot); |
---|
346 | 207 | if (!src) |
---|
347 | 208 | return -ENOMEM; |
---|
348 | 209 | |
---|
349 | 210 | memcpy_toio(dst, src, PAGE_SIZE); |
---|
350 | 211 | |
---|
351 | | - ttm_kunmap_atomic_prot(src, prot); |
---|
| 212 | + kunmap_atomic(src); |
---|
352 | 213 | |
---|
353 | 214 | return 0; |
---|
354 | 215 | } |
---|
355 | 216 | |
---|
356 | 217 | int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, |
---|
357 | 218 | struct ttm_operation_ctx *ctx, |
---|
358 | | - struct ttm_mem_reg *new_mem) |
---|
| 219 | + struct ttm_resource *new_mem) |
---|
359 | 220 | { |
---|
360 | 221 | struct ttm_bo_device *bdev = bo->bdev; |
---|
361 | | - struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type]; |
---|
| 222 | + struct ttm_resource_manager *man = ttm_manager_type(bdev, new_mem->mem_type); |
---|
362 | 223 | struct ttm_tt *ttm = bo->ttm; |
---|
363 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
---|
364 | | - struct ttm_mem_reg old_copy = *old_mem; |
---|
| 224 | + struct ttm_resource *old_mem = &bo->mem; |
---|
| 225 | + struct ttm_resource old_copy = *old_mem; |
---|
365 | 226 | void *old_iomap; |
---|
366 | 227 | void *new_iomap; |
---|
367 | 228 | int ret; |
---|
.. | .. |
---|
374 | 235 | if (ret) |
---|
375 | 236 | return ret; |
---|
376 | 237 | |
---|
377 | | - ret = ttm_mem_reg_ioremap(bdev, old_mem, &old_iomap); |
---|
| 238 | + ret = ttm_resource_ioremap(bdev, old_mem, &old_iomap); |
---|
378 | 239 | if (ret) |
---|
379 | 240 | return ret; |
---|
380 | | - ret = ttm_mem_reg_ioremap(bdev, new_mem, &new_iomap); |
---|
| 241 | + ret = ttm_resource_ioremap(bdev, new_mem, &new_iomap); |
---|
381 | 242 | if (ret) |
---|
382 | 243 | goto out; |
---|
383 | 244 | |
---|
.. | .. |
---|
391 | 252 | * Don't move nonexistent data. Clear destination instead. |
---|
392 | 253 | */ |
---|
393 | 254 | if (old_iomap == NULL && |
---|
394 | | - (ttm == NULL || (ttm->state == tt_unpopulated && |
---|
| 255 | + (ttm == NULL || (!ttm_tt_is_populated(ttm) && |
---|
395 | 256 | !(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)))) { |
---|
396 | 257 | memset_io(new_iomap, 0, new_mem->num_pages*PAGE_SIZE); |
---|
397 | 258 | goto out2; |
---|
.. | .. |
---|
401 | 262 | * TTM might be null for moves within the same region. |
---|
402 | 263 | */ |
---|
403 | 264 | if (ttm) { |
---|
404 | | - ret = ttm_tt_populate(ttm, ctx); |
---|
| 265 | + ret = ttm_tt_populate(bdev, ttm, ctx); |
---|
405 | 266 | if (ret) |
---|
406 | 267 | goto out1; |
---|
407 | 268 | } |
---|
.. | .. |
---|
436 | 297 | mb(); |
---|
437 | 298 | out2: |
---|
438 | 299 | old_copy = *old_mem; |
---|
439 | | - *old_mem = *new_mem; |
---|
440 | | - new_mem->mm_node = NULL; |
---|
441 | 300 | |
---|
442 | | - if (man->flags & TTM_MEMTYPE_FLAG_FIXED) { |
---|
443 | | - ttm_tt_destroy(ttm); |
---|
444 | | - bo->ttm = NULL; |
---|
445 | | - } |
---|
| 301 | + ttm_bo_assign_mem(bo, new_mem); |
---|
| 302 | + |
---|
| 303 | + if (!man->use_tt) |
---|
| 304 | + ttm_bo_tt_destroy(bo); |
---|
446 | 305 | |
---|
447 | 306 | out1: |
---|
448 | | - ttm_mem_reg_iounmap(bdev, old_mem, new_iomap); |
---|
| 307 | + ttm_resource_iounmap(bdev, old_mem, new_iomap); |
---|
449 | 308 | out: |
---|
450 | | - ttm_mem_reg_iounmap(bdev, &old_copy, old_iomap); |
---|
| 309 | + ttm_resource_iounmap(bdev, &old_copy, old_iomap); |
---|
451 | 310 | |
---|
452 | 311 | /* |
---|
453 | 312 | * On error, keep the mm node! |
---|
454 | 313 | */ |
---|
455 | 314 | if (!ret) |
---|
456 | | - ttm_bo_mem_put(bo, &old_copy); |
---|
| 315 | + ttm_resource_free(bo, &old_copy); |
---|
457 | 316 | return ret; |
---|
458 | 317 | } |
---|
459 | 318 | EXPORT_SYMBOL(ttm_bo_move_memcpy); |
---|
.. | .. |
---|
503 | 362 | * TODO: Explicit member copy would probably be better here. |
---|
504 | 363 | */ |
---|
505 | 364 | |
---|
506 | | - atomic_inc(&bo->bdev->glob->bo_count); |
---|
| 365 | + atomic_inc(&ttm_bo_glob.bo_count); |
---|
507 | 366 | INIT_LIST_HEAD(&fbo->base.ddestroy); |
---|
508 | 367 | INIT_LIST_HEAD(&fbo->base.lru); |
---|
509 | 368 | INIT_LIST_HEAD(&fbo->base.swap); |
---|
510 | | - INIT_LIST_HEAD(&fbo->base.io_reserve_lru); |
---|
511 | | - mutex_init(&fbo->base.wu_mutex); |
---|
512 | 369 | fbo->base.moving = NULL; |
---|
513 | | - drm_vma_node_reset(&fbo->base.vma_node); |
---|
514 | | - atomic_set(&fbo->base.cpu_writers, 0); |
---|
| 370 | + drm_vma_node_reset(&fbo->base.base.vma_node); |
---|
515 | 371 | |
---|
516 | | - kref_init(&fbo->base.list_kref); |
---|
517 | 372 | kref_init(&fbo->base.kref); |
---|
518 | 373 | fbo->base.destroy = &ttm_transfered_destroy; |
---|
519 | 374 | fbo->base.acc_size = 0; |
---|
520 | | - fbo->base.resv = &fbo->base.ttm_resv; |
---|
521 | | - reservation_object_init(fbo->base.resv); |
---|
522 | | - ret = reservation_object_trylock(fbo->base.resv); |
---|
| 375 | + if (bo->type != ttm_bo_type_sg) |
---|
| 376 | + fbo->base.base.resv = &fbo->base.base._resv; |
---|
| 377 | + |
---|
| 378 | + dma_resv_init(&fbo->base.base._resv); |
---|
| 379 | + fbo->base.base.dev = NULL; |
---|
| 380 | + ret = dma_resv_trylock(&fbo->base.base._resv); |
---|
523 | 381 | WARN_ON(!ret); |
---|
524 | 382 | |
---|
525 | 383 | *new_obj = &fbo->base; |
---|
.. | .. |
---|
539 | 397 | tmp = pgprot_noncached(tmp); |
---|
540 | 398 | #endif |
---|
541 | 399 | #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \ |
---|
542 | | - defined(__powerpc__) |
---|
| 400 | + defined(__powerpc__) || defined(__mips__) |
---|
543 | 401 | if (caching_flags & TTM_PL_FLAG_WC) |
---|
544 | 402 | tmp = pgprot_writecombine(tmp); |
---|
545 | 403 | else |
---|
546 | 404 | tmp = pgprot_noncached(tmp); |
---|
547 | 405 | #endif |
---|
548 | | -#if defined(__sparc__) || defined(__mips__) |
---|
| 406 | +#if defined(__sparc__) |
---|
549 | 407 | tmp = pgprot_noncached(tmp); |
---|
550 | 408 | #endif |
---|
551 | 409 | return tmp; |
---|
.. | .. |
---|
557 | 415 | unsigned long size, |
---|
558 | 416 | struct ttm_bo_kmap_obj *map) |
---|
559 | 417 | { |
---|
560 | | - struct ttm_mem_reg *mem = &bo->mem; |
---|
| 418 | + struct ttm_resource *mem = &bo->mem; |
---|
561 | 419 | |
---|
562 | 420 | if (bo->mem.bus.addr) { |
---|
563 | 421 | map->bo_kmap_type = ttm_bo_map_premapped; |
---|
.. | .. |
---|
565 | 423 | } else { |
---|
566 | 424 | map->bo_kmap_type = ttm_bo_map_iomap; |
---|
567 | 425 | if (mem->placement & TTM_PL_FLAG_WC) |
---|
568 | | - map->virtual = ioremap_wc(bo->mem.bus.base + bo->mem.bus.offset + offset, |
---|
| 426 | + map->virtual = ioremap_wc(bo->mem.bus.offset + offset, |
---|
569 | 427 | size); |
---|
570 | 428 | else |
---|
571 | | - map->virtual = ioremap_nocache(bo->mem.bus.base + bo->mem.bus.offset + offset, |
---|
572 | | - size); |
---|
| 429 | + map->virtual = ioremap(bo->mem.bus.offset + offset, |
---|
| 430 | + size); |
---|
573 | 431 | } |
---|
574 | 432 | return (!map->virtual) ? -ENOMEM : 0; |
---|
575 | 433 | } |
---|
.. | .. |
---|
579 | 437 | unsigned long num_pages, |
---|
580 | 438 | struct ttm_bo_kmap_obj *map) |
---|
581 | 439 | { |
---|
582 | | - struct ttm_mem_reg *mem = &bo->mem; |
---|
| 440 | + struct ttm_resource *mem = &bo->mem; |
---|
583 | 441 | struct ttm_operation_ctx ctx = { |
---|
584 | 442 | .interruptible = false, |
---|
585 | 443 | .no_wait_gpu = false |
---|
.. | .. |
---|
590 | 448 | |
---|
591 | 449 | BUG_ON(!ttm); |
---|
592 | 450 | |
---|
593 | | - ret = ttm_tt_populate(ttm, &ctx); |
---|
| 451 | + ret = ttm_tt_populate(bo->bdev, ttm, &ctx); |
---|
594 | 452 | if (ret) |
---|
595 | 453 | return ret; |
---|
596 | 454 | |
---|
.. | .. |
---|
620 | 478 | unsigned long start_page, unsigned long num_pages, |
---|
621 | 479 | struct ttm_bo_kmap_obj *map) |
---|
622 | 480 | { |
---|
623 | | - struct ttm_mem_type_manager *man = |
---|
624 | | - &bo->bdev->man[bo->mem.mem_type]; |
---|
625 | 481 | unsigned long offset, size; |
---|
626 | 482 | int ret; |
---|
627 | 483 | |
---|
.. | .. |
---|
631 | 487 | return -EINVAL; |
---|
632 | 488 | if (start_page > bo->num_pages) |
---|
633 | 489 | return -EINVAL; |
---|
634 | | -#if 0 |
---|
635 | | - if (num_pages > 1 && !capable(CAP_SYS_ADMIN)) |
---|
636 | | - return -EPERM; |
---|
637 | | -#endif |
---|
638 | | - (void) ttm_mem_io_lock(man, false); |
---|
| 490 | + |
---|
639 | 491 | ret = ttm_mem_io_reserve(bo->bdev, &bo->mem); |
---|
640 | | - ttm_mem_io_unlock(man); |
---|
641 | 492 | if (ret) |
---|
642 | 493 | return ret; |
---|
643 | 494 | if (!bo->mem.bus.is_iomem) { |
---|
.. | .. |
---|
652 | 503 | |
---|
653 | 504 | void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map) |
---|
654 | 505 | { |
---|
655 | | - struct ttm_buffer_object *bo = map->bo; |
---|
656 | | - struct ttm_mem_type_manager *man = |
---|
657 | | - &bo->bdev->man[bo->mem.mem_type]; |
---|
658 | | - |
---|
659 | 506 | if (!map->virtual) |
---|
660 | 507 | return; |
---|
661 | 508 | switch (map->bo_kmap_type) { |
---|
.. | .. |
---|
673 | 520 | default: |
---|
674 | 521 | BUG(); |
---|
675 | 522 | } |
---|
676 | | - (void) ttm_mem_io_lock(man, false); |
---|
677 | 523 | ttm_mem_io_free(map->bo->bdev, &map->bo->mem); |
---|
678 | | - ttm_mem_io_unlock(man); |
---|
679 | 524 | map->virtual = NULL; |
---|
680 | 525 | map->page = NULL; |
---|
681 | 526 | } |
---|
682 | 527 | EXPORT_SYMBOL(ttm_bo_kunmap); |
---|
683 | 528 | |
---|
| 529 | +static int ttm_bo_wait_free_node(struct ttm_buffer_object *bo, |
---|
| 530 | + bool dst_use_tt) |
---|
| 531 | +{ |
---|
| 532 | + int ret; |
---|
| 533 | + ret = ttm_bo_wait(bo, false, false); |
---|
| 534 | + if (ret) |
---|
| 535 | + return ret; |
---|
| 536 | + |
---|
| 537 | + if (!dst_use_tt) |
---|
| 538 | + ttm_bo_tt_destroy(bo); |
---|
| 539 | + ttm_bo_free_old_node(bo); |
---|
| 540 | + return 0; |
---|
| 541 | +} |
---|
| 542 | + |
---|
| 543 | +static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo, |
---|
| 544 | + struct dma_fence *fence, |
---|
| 545 | + bool dst_use_tt) |
---|
| 546 | +{ |
---|
| 547 | + struct ttm_buffer_object *ghost_obj; |
---|
| 548 | + int ret; |
---|
| 549 | + |
---|
| 550 | + /** |
---|
| 551 | + * This should help pipeline ordinary buffer moves. |
---|
| 552 | + * |
---|
| 553 | + * Hang old buffer memory on a new buffer object, |
---|
| 554 | + * and leave it to be released when the GPU |
---|
| 555 | + * operation has completed. |
---|
| 556 | + */ |
---|
| 557 | + |
---|
| 558 | + dma_fence_put(bo->moving); |
---|
| 559 | + bo->moving = dma_fence_get(fence); |
---|
| 560 | + |
---|
| 561 | + ret = ttm_buffer_object_transfer(bo, &ghost_obj); |
---|
| 562 | + if (ret) |
---|
| 563 | + return ret; |
---|
| 564 | + |
---|
| 565 | + dma_resv_add_excl_fence(&ghost_obj->base._resv, fence); |
---|
| 566 | + |
---|
| 567 | + /** |
---|
| 568 | + * If we're not moving to fixed memory, the TTM object |
---|
| 569 | + * needs to stay alive. Otherwhise hang it on the ghost |
---|
| 570 | + * bo to be unbound and destroyed. |
---|
| 571 | + */ |
---|
| 572 | + |
---|
| 573 | + if (dst_use_tt) |
---|
| 574 | + ghost_obj->ttm = NULL; |
---|
| 575 | + else |
---|
| 576 | + bo->ttm = NULL; |
---|
| 577 | + |
---|
| 578 | + dma_resv_unlock(&ghost_obj->base._resv); |
---|
| 579 | + ttm_bo_put(ghost_obj); |
---|
| 580 | + return 0; |
---|
| 581 | +} |
---|
| 582 | + |
---|
| 583 | +static void ttm_bo_move_pipeline_evict(struct ttm_buffer_object *bo, |
---|
| 584 | + struct dma_fence *fence) |
---|
| 585 | +{ |
---|
| 586 | + struct ttm_bo_device *bdev = bo->bdev; |
---|
| 587 | + struct ttm_resource_manager *from = ttm_manager_type(bdev, bo->mem.mem_type); |
---|
| 588 | + |
---|
| 589 | + /** |
---|
| 590 | + * BO doesn't have a TTM we need to bind/unbind. Just remember |
---|
| 591 | + * this eviction and free up the allocation |
---|
| 592 | + */ |
---|
| 593 | + spin_lock(&from->move_lock); |
---|
| 594 | + if (!from->move || dma_fence_is_later(fence, from->move)) { |
---|
| 595 | + dma_fence_put(from->move); |
---|
| 596 | + from->move = dma_fence_get(fence); |
---|
| 597 | + } |
---|
| 598 | + spin_unlock(&from->move_lock); |
---|
| 599 | + |
---|
| 600 | + ttm_bo_free_old_node(bo); |
---|
| 601 | + |
---|
| 602 | + dma_fence_put(bo->moving); |
---|
| 603 | + bo->moving = dma_fence_get(fence); |
---|
| 604 | +} |
---|
| 605 | + |
---|
684 | 606 | int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, |
---|
685 | 607 | struct dma_fence *fence, |
---|
686 | 608 | bool evict, |
---|
687 | | - struct ttm_mem_reg *new_mem) |
---|
| 609 | + bool pipeline, |
---|
| 610 | + struct ttm_resource *new_mem) |
---|
688 | 611 | { |
---|
689 | 612 | struct ttm_bo_device *bdev = bo->bdev; |
---|
690 | | - struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type]; |
---|
691 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
---|
692 | | - int ret; |
---|
693 | | - struct ttm_buffer_object *ghost_obj; |
---|
| 613 | + struct ttm_resource_manager *from = ttm_manager_type(bdev, bo->mem.mem_type); |
---|
| 614 | + struct ttm_resource_manager *man = ttm_manager_type(bdev, new_mem->mem_type); |
---|
| 615 | + int ret = 0; |
---|
694 | 616 | |
---|
695 | | - reservation_object_add_excl_fence(bo->resv, fence); |
---|
696 | | - if (evict) { |
---|
697 | | - ret = ttm_bo_wait(bo, false, false); |
---|
698 | | - if (ret) |
---|
699 | | - return ret; |
---|
| 617 | + dma_resv_add_excl_fence(bo->base.resv, fence); |
---|
| 618 | + if (!evict) |
---|
| 619 | + ret = ttm_bo_move_to_ghost(bo, fence, man->use_tt); |
---|
| 620 | + else if (!from->use_tt && pipeline) |
---|
| 621 | + ttm_bo_move_pipeline_evict(bo, fence); |
---|
| 622 | + else |
---|
| 623 | + ret = ttm_bo_wait_free_node(bo, man->use_tt); |
---|
700 | 624 | |
---|
701 | | - if (man->flags & TTM_MEMTYPE_FLAG_FIXED) { |
---|
702 | | - ttm_tt_destroy(bo->ttm); |
---|
703 | | - bo->ttm = NULL; |
---|
704 | | - } |
---|
705 | | - ttm_bo_free_old_node(bo); |
---|
706 | | - } else { |
---|
707 | | - /** |
---|
708 | | - * This should help pipeline ordinary buffer moves. |
---|
709 | | - * |
---|
710 | | - * Hang old buffer memory on a new buffer object, |
---|
711 | | - * and leave it to be released when the GPU |
---|
712 | | - * operation has completed. |
---|
713 | | - */ |
---|
| 625 | + if (ret) |
---|
| 626 | + return ret; |
---|
714 | 627 | |
---|
715 | | - dma_fence_put(bo->moving); |
---|
716 | | - bo->moving = dma_fence_get(fence); |
---|
717 | | - |
---|
718 | | - ret = ttm_buffer_object_transfer(bo, &ghost_obj); |
---|
719 | | - if (ret) |
---|
720 | | - return ret; |
---|
721 | | - |
---|
722 | | - reservation_object_add_excl_fence(ghost_obj->resv, fence); |
---|
723 | | - |
---|
724 | | - /** |
---|
725 | | - * If we're not moving to fixed memory, the TTM object |
---|
726 | | - * needs to stay alive. Otherwhise hang it on the ghost |
---|
727 | | - * bo to be unbound and destroyed. |
---|
728 | | - */ |
---|
729 | | - |
---|
730 | | - if (!(man->flags & TTM_MEMTYPE_FLAG_FIXED)) |
---|
731 | | - ghost_obj->ttm = NULL; |
---|
732 | | - else |
---|
733 | | - bo->ttm = NULL; |
---|
734 | | - |
---|
735 | | - ttm_bo_unreserve(ghost_obj); |
---|
736 | | - ttm_bo_put(ghost_obj); |
---|
737 | | - } |
---|
738 | | - |
---|
739 | | - *old_mem = *new_mem; |
---|
740 | | - new_mem->mm_node = NULL; |
---|
| 628 | + ttm_bo_assign_mem(bo, new_mem); |
---|
741 | 629 | |
---|
742 | 630 | return 0; |
---|
743 | 631 | } |
---|
744 | 632 | EXPORT_SYMBOL(ttm_bo_move_accel_cleanup); |
---|
745 | | - |
---|
746 | | -int ttm_bo_pipeline_move(struct ttm_buffer_object *bo, |
---|
747 | | - struct dma_fence *fence, bool evict, |
---|
748 | | - struct ttm_mem_reg *new_mem) |
---|
749 | | -{ |
---|
750 | | - struct ttm_bo_device *bdev = bo->bdev; |
---|
751 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
---|
752 | | - |
---|
753 | | - struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type]; |
---|
754 | | - struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type]; |
---|
755 | | - |
---|
756 | | - int ret; |
---|
757 | | - |
---|
758 | | - reservation_object_add_excl_fence(bo->resv, fence); |
---|
759 | | - |
---|
760 | | - if (!evict) { |
---|
761 | | - struct ttm_buffer_object *ghost_obj; |
---|
762 | | - |
---|
763 | | - /** |
---|
764 | | - * This should help pipeline ordinary buffer moves. |
---|
765 | | - * |
---|
766 | | - * Hang old buffer memory on a new buffer object, |
---|
767 | | - * and leave it to be released when the GPU |
---|
768 | | - * operation has completed. |
---|
769 | | - */ |
---|
770 | | - |
---|
771 | | - dma_fence_put(bo->moving); |
---|
772 | | - bo->moving = dma_fence_get(fence); |
---|
773 | | - |
---|
774 | | - ret = ttm_buffer_object_transfer(bo, &ghost_obj); |
---|
775 | | - if (ret) |
---|
776 | | - return ret; |
---|
777 | | - |
---|
778 | | - reservation_object_add_excl_fence(ghost_obj->resv, fence); |
---|
779 | | - |
---|
780 | | - /** |
---|
781 | | - * If we're not moving to fixed memory, the TTM object |
---|
782 | | - * needs to stay alive. Otherwhise hang it on the ghost |
---|
783 | | - * bo to be unbound and destroyed. |
---|
784 | | - */ |
---|
785 | | - |
---|
786 | | - if (!(to->flags & TTM_MEMTYPE_FLAG_FIXED)) |
---|
787 | | - ghost_obj->ttm = NULL; |
---|
788 | | - else |
---|
789 | | - bo->ttm = NULL; |
---|
790 | | - |
---|
791 | | - ttm_bo_unreserve(ghost_obj); |
---|
792 | | - ttm_bo_put(ghost_obj); |
---|
793 | | - |
---|
794 | | - } else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) { |
---|
795 | | - |
---|
796 | | - /** |
---|
797 | | - * BO doesn't have a TTM we need to bind/unbind. Just remember |
---|
798 | | - * this eviction and free up the allocation |
---|
799 | | - */ |
---|
800 | | - |
---|
801 | | - spin_lock(&from->move_lock); |
---|
802 | | - if (!from->move || dma_fence_is_later(fence, from->move)) { |
---|
803 | | - dma_fence_put(from->move); |
---|
804 | | - from->move = dma_fence_get(fence); |
---|
805 | | - } |
---|
806 | | - spin_unlock(&from->move_lock); |
---|
807 | | - |
---|
808 | | - ttm_bo_free_old_node(bo); |
---|
809 | | - |
---|
810 | | - dma_fence_put(bo->moving); |
---|
811 | | - bo->moving = dma_fence_get(fence); |
---|
812 | | - |
---|
813 | | - } else { |
---|
814 | | - /** |
---|
815 | | - * Last resort, wait for the move to be completed. |
---|
816 | | - * |
---|
817 | | - * Should never happen in pratice. |
---|
818 | | - */ |
---|
819 | | - |
---|
820 | | - ret = ttm_bo_wait(bo, false, false); |
---|
821 | | - if (ret) |
---|
822 | | - return ret; |
---|
823 | | - |
---|
824 | | - if (to->flags & TTM_MEMTYPE_FLAG_FIXED) { |
---|
825 | | - ttm_tt_destroy(bo->ttm); |
---|
826 | | - bo->ttm = NULL; |
---|
827 | | - } |
---|
828 | | - ttm_bo_free_old_node(bo); |
---|
829 | | - } |
---|
830 | | - |
---|
831 | | - *old_mem = *new_mem; |
---|
832 | | - new_mem->mm_node = NULL; |
---|
833 | | - |
---|
834 | | - return 0; |
---|
835 | | -} |
---|
836 | | -EXPORT_SYMBOL(ttm_bo_pipeline_move); |
---|
837 | 633 | |
---|
838 | 634 | int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo) |
---|
839 | 635 | { |
---|
.. | .. |
---|
844 | 640 | if (ret) |
---|
845 | 641 | return ret; |
---|
846 | 642 | |
---|
847 | | - ret = reservation_object_copy_fences(ghost->resv, bo->resv); |
---|
| 643 | + ret = dma_resv_copy_fences(&ghost->base._resv, bo->base.resv); |
---|
848 | 644 | /* Last resort, wait for the BO to be idle when we are OOM */ |
---|
849 | 645 | if (ret) |
---|
850 | 646 | ttm_bo_wait(bo, false, false); |
---|
.. | .. |
---|
853 | 649 | bo->mem.mem_type = TTM_PL_SYSTEM; |
---|
854 | 650 | bo->ttm = NULL; |
---|
855 | 651 | |
---|
856 | | - ttm_bo_unreserve(ghost); |
---|
| 652 | + dma_resv_unlock(&ghost->base._resv); |
---|
857 | 653 | ttm_bo_put(ghost); |
---|
858 | 654 | |
---|
859 | 655 | return 0; |
---|