nouveau_bo.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /*
  2. * Copyright 2007 Dave Airlied
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * 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. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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. /*
  25. * Authors: Dave Airlied <airlied@linux.ie>
  26. * Ben Skeggs <darktama@iinet.net.au>
  27. * Jeremy Kolb <jkolb@brandeis.edu>
  28. */
  29. #include "drmP.h"
  30. #include "ttm/ttm_page_alloc.h"
  31. #include "nouveau_drm.h"
  32. #include "nouveau_drv.h"
  33. #include "nouveau_dma.h"
  34. #include "nouveau_mm.h"
  35. #include "nouveau_vm.h"
  36. #include <linux/log2.h>
  37. #include <linux/slab.h>
  38. static void
  39. nouveau_bo_del_ttm(struct ttm_buffer_object *bo)
  40. {
  41. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  42. struct drm_device *dev = dev_priv->dev;
  43. struct nouveau_bo *nvbo = nouveau_bo(bo);
  44. if (unlikely(nvbo->gem))
  45. DRM_ERROR("bo %p still attached to GEM object\n", bo);
  46. nv10_mem_put_tile_region(dev, nvbo->tile, NULL);
  47. kfree(nvbo);
  48. }
  49. static void
  50. nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags,
  51. int *align, int *size)
  52. {
  53. struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev);
  54. if (dev_priv->card_type < NV_50) {
  55. if (nvbo->tile_mode) {
  56. if (dev_priv->chipset >= 0x40) {
  57. *align = 65536;
  58. *size = roundup(*size, 64 * nvbo->tile_mode);
  59. } else if (dev_priv->chipset >= 0x30) {
  60. *align = 32768;
  61. *size = roundup(*size, 64 * nvbo->tile_mode);
  62. } else if (dev_priv->chipset >= 0x20) {
  63. *align = 16384;
  64. *size = roundup(*size, 64 * nvbo->tile_mode);
  65. } else if (dev_priv->chipset >= 0x10) {
  66. *align = 16384;
  67. *size = roundup(*size, 32 * nvbo->tile_mode);
  68. }
  69. }
  70. } else {
  71. *size = roundup(*size, (1 << nvbo->page_shift));
  72. *align = max((1 << nvbo->page_shift), *align);
  73. }
  74. *size = roundup(*size, PAGE_SIZE);
  75. }
  76. int
  77. nouveau_bo_new(struct drm_device *dev, int size, int align,
  78. uint32_t flags, uint32_t tile_mode, uint32_t tile_flags,
  79. struct nouveau_bo **pnvbo)
  80. {
  81. struct drm_nouveau_private *dev_priv = dev->dev_private;
  82. struct nouveau_bo *nvbo;
  83. int ret;
  84. nvbo = kzalloc(sizeof(struct nouveau_bo), GFP_KERNEL);
  85. if (!nvbo)
  86. return -ENOMEM;
  87. INIT_LIST_HEAD(&nvbo->head);
  88. INIT_LIST_HEAD(&nvbo->entry);
  89. INIT_LIST_HEAD(&nvbo->vma_list);
  90. nvbo->tile_mode = tile_mode;
  91. nvbo->tile_flags = tile_flags;
  92. nvbo->bo.bdev = &dev_priv->ttm.bdev;
  93. nvbo->page_shift = 12;
  94. if (dev_priv->bar1_vm) {
  95. if (!(flags & TTM_PL_FLAG_TT) && size > 256 * 1024)
  96. nvbo->page_shift = dev_priv->bar1_vm->lpg_shift;
  97. }
  98. nouveau_bo_fixup_align(nvbo, flags, &align, &size);
  99. nvbo->bo.mem.num_pages = size >> PAGE_SHIFT;
  100. nouveau_bo_placement_set(nvbo, flags, 0);
  101. ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size,
  102. ttm_bo_type_device, &nvbo->placement,
  103. align >> PAGE_SHIFT, 0, false, NULL, size,
  104. nouveau_bo_del_ttm);
  105. if (ret) {
  106. /* ttm will call nouveau_bo_del_ttm if it fails.. */
  107. return ret;
  108. }
  109. *pnvbo = nvbo;
  110. return 0;
  111. }
  112. static void
  113. set_placement_list(uint32_t *pl, unsigned *n, uint32_t type, uint32_t flags)
  114. {
  115. *n = 0;
  116. if (type & TTM_PL_FLAG_VRAM)
  117. pl[(*n)++] = TTM_PL_FLAG_VRAM | flags;
  118. if (type & TTM_PL_FLAG_TT)
  119. pl[(*n)++] = TTM_PL_FLAG_TT | flags;
  120. if (type & TTM_PL_FLAG_SYSTEM)
  121. pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags;
  122. }
  123. static void
  124. set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
  125. {
  126. struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev);
  127. int vram_pages = dev_priv->vram_size >> PAGE_SHIFT;
  128. if (dev_priv->card_type == NV_10 &&
  129. nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) &&
  130. nvbo->bo.mem.num_pages < vram_pages / 2) {
  131. /*
  132. * Make sure that the color and depth buffers are handled
  133. * by independent memory controller units. Up to a 9x
  134. * speed up when alpha-blending and depth-test are enabled
  135. * at the same time.
  136. */
  137. if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) {
  138. nvbo->placement.fpfn = vram_pages / 2;
  139. nvbo->placement.lpfn = ~0;
  140. } else {
  141. nvbo->placement.fpfn = 0;
  142. nvbo->placement.lpfn = vram_pages / 2;
  143. }
  144. }
  145. }
  146. void
  147. nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy)
  148. {
  149. struct ttm_placement *pl = &nvbo->placement;
  150. uint32_t flags = TTM_PL_MASK_CACHING |
  151. (nvbo->pin_refcnt ? TTM_PL_FLAG_NO_EVICT : 0);
  152. pl->placement = nvbo->placements;
  153. set_placement_list(nvbo->placements, &pl->num_placement,
  154. type, flags);
  155. pl->busy_placement = nvbo->busy_placements;
  156. set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
  157. type | busy, flags);
  158. set_placement_range(nvbo, type);
  159. }
  160. int
  161. nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype)
  162. {
  163. struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev);
  164. struct ttm_buffer_object *bo = &nvbo->bo;
  165. int ret;
  166. if (nvbo->pin_refcnt && !(memtype & (1 << bo->mem.mem_type))) {
  167. NV_ERROR(nouveau_bdev(bo->bdev)->dev,
  168. "bo %p pinned elsewhere: 0x%08x vs 0x%08x\n", bo,
  169. 1 << bo->mem.mem_type, memtype);
  170. return -EINVAL;
  171. }
  172. if (nvbo->pin_refcnt++)
  173. return 0;
  174. ret = ttm_bo_reserve(bo, false, false, false, 0);
  175. if (ret)
  176. goto out;
  177. nouveau_bo_placement_set(nvbo, memtype, 0);
  178. ret = nouveau_bo_validate(nvbo, false, false, false);
  179. if (ret == 0) {
  180. switch (bo->mem.mem_type) {
  181. case TTM_PL_VRAM:
  182. dev_priv->fb_aper_free -= bo->mem.size;
  183. break;
  184. case TTM_PL_TT:
  185. dev_priv->gart_info.aper_free -= bo->mem.size;
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. ttm_bo_unreserve(bo);
  192. out:
  193. if (unlikely(ret))
  194. nvbo->pin_refcnt--;
  195. return ret;
  196. }
  197. int
  198. nouveau_bo_unpin(struct nouveau_bo *nvbo)
  199. {
  200. struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev);
  201. struct ttm_buffer_object *bo = &nvbo->bo;
  202. int ret;
  203. if (--nvbo->pin_refcnt)
  204. return 0;
  205. ret = ttm_bo_reserve(bo, false, false, false, 0);
  206. if (ret)
  207. return ret;
  208. nouveau_bo_placement_set(nvbo, bo->mem.placement, 0);
  209. ret = nouveau_bo_validate(nvbo, false, false, false);
  210. if (ret == 0) {
  211. switch (bo->mem.mem_type) {
  212. case TTM_PL_VRAM:
  213. dev_priv->fb_aper_free += bo->mem.size;
  214. break;
  215. case TTM_PL_TT:
  216. dev_priv->gart_info.aper_free += bo->mem.size;
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. ttm_bo_unreserve(bo);
  223. return ret;
  224. }
  225. int
  226. nouveau_bo_map(struct nouveau_bo *nvbo)
  227. {
  228. int ret;
  229. ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
  230. if (ret)
  231. return ret;
  232. ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, &nvbo->kmap);
  233. ttm_bo_unreserve(&nvbo->bo);
  234. return ret;
  235. }
  236. void
  237. nouveau_bo_unmap(struct nouveau_bo *nvbo)
  238. {
  239. if (nvbo)
  240. ttm_bo_kunmap(&nvbo->kmap);
  241. }
  242. int
  243. nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible,
  244. bool no_wait_reserve, bool no_wait_gpu)
  245. {
  246. int ret;
  247. ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement, interruptible,
  248. no_wait_reserve, no_wait_gpu);
  249. if (ret)
  250. return ret;
  251. return 0;
  252. }
  253. u16
  254. nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index)
  255. {
  256. bool is_iomem;
  257. u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem);
  258. mem = &mem[index];
  259. if (is_iomem)
  260. return ioread16_native((void __force __iomem *)mem);
  261. else
  262. return *mem;
  263. }
  264. void
  265. nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val)
  266. {
  267. bool is_iomem;
  268. u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem);
  269. mem = &mem[index];
  270. if (is_iomem)
  271. iowrite16_native(val, (void __force __iomem *)mem);
  272. else
  273. *mem = val;
  274. }
  275. u32
  276. nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index)
  277. {
  278. bool is_iomem;
  279. u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem);
  280. mem = &mem[index];
  281. if (is_iomem)
  282. return ioread32_native((void __force __iomem *)mem);
  283. else
  284. return *mem;
  285. }
  286. void
  287. nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val)
  288. {
  289. bool is_iomem;
  290. u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem);
  291. mem = &mem[index];
  292. if (is_iomem)
  293. iowrite32_native(val, (void __force __iomem *)mem);
  294. else
  295. *mem = val;
  296. }
  297. static struct ttm_tt *
  298. nouveau_ttm_tt_create(struct ttm_bo_device *bdev,
  299. unsigned long size, uint32_t page_flags,
  300. struct page *dummy_read_page)
  301. {
  302. struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
  303. struct drm_device *dev = dev_priv->dev;
  304. switch (dev_priv->gart_info.type) {
  305. #if __OS_HAS_AGP
  306. case NOUVEAU_GART_AGP:
  307. return ttm_agp_tt_create(bdev, dev->agp->bridge,
  308. size, page_flags, dummy_read_page);
  309. #endif
  310. case NOUVEAU_GART_PDMA:
  311. case NOUVEAU_GART_HW:
  312. return nouveau_sgdma_create_ttm(bdev, size, page_flags,
  313. dummy_read_page);
  314. default:
  315. NV_ERROR(dev, "Unknown GART type %d\n",
  316. dev_priv->gart_info.type);
  317. break;
  318. }
  319. return NULL;
  320. }
  321. static int
  322. nouveau_bo_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags)
  323. {
  324. /* We'll do this from user space. */
  325. return 0;
  326. }
  327. static int
  328. nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
  329. struct ttm_mem_type_manager *man)
  330. {
  331. struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
  332. struct drm_device *dev = dev_priv->dev;
  333. switch (type) {
  334. case TTM_PL_SYSTEM:
  335. man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
  336. man->available_caching = TTM_PL_MASK_CACHING;
  337. man->default_caching = TTM_PL_FLAG_CACHED;
  338. break;
  339. case TTM_PL_VRAM:
  340. if (dev_priv->card_type >= NV_50) {
  341. man->func = &nouveau_vram_manager;
  342. man->io_reserve_fastpath = false;
  343. man->use_io_reserve_lru = true;
  344. } else {
  345. man->func = &ttm_bo_manager_func;
  346. }
  347. man->flags = TTM_MEMTYPE_FLAG_FIXED |
  348. TTM_MEMTYPE_FLAG_MAPPABLE;
  349. man->available_caching = TTM_PL_FLAG_UNCACHED |
  350. TTM_PL_FLAG_WC;
  351. man->default_caching = TTM_PL_FLAG_WC;
  352. break;
  353. case TTM_PL_TT:
  354. if (dev_priv->card_type >= NV_50)
  355. man->func = &nouveau_gart_manager;
  356. else
  357. man->func = &ttm_bo_manager_func;
  358. switch (dev_priv->gart_info.type) {
  359. case NOUVEAU_GART_AGP:
  360. man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
  361. man->available_caching = TTM_PL_FLAG_UNCACHED |
  362. TTM_PL_FLAG_WC;
  363. man->default_caching = TTM_PL_FLAG_WC;
  364. break;
  365. case NOUVEAU_GART_PDMA:
  366. case NOUVEAU_GART_HW:
  367. man->flags = TTM_MEMTYPE_FLAG_MAPPABLE |
  368. TTM_MEMTYPE_FLAG_CMA;
  369. man->available_caching = TTM_PL_MASK_CACHING;
  370. man->default_caching = TTM_PL_FLAG_CACHED;
  371. break;
  372. default:
  373. NV_ERROR(dev, "Unknown GART type: %d\n",
  374. dev_priv->gart_info.type);
  375. return -EINVAL;
  376. }
  377. break;
  378. default:
  379. NV_ERROR(dev, "Unsupported memory type %u\n", (unsigned)type);
  380. return -EINVAL;
  381. }
  382. return 0;
  383. }
  384. static void
  385. nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl)
  386. {
  387. struct nouveau_bo *nvbo = nouveau_bo(bo);
  388. switch (bo->mem.mem_type) {
  389. case TTM_PL_VRAM:
  390. nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT,
  391. TTM_PL_FLAG_SYSTEM);
  392. break;
  393. default:
  394. nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM, 0);
  395. break;
  396. }
  397. *pl = nvbo->placement;
  398. }
  399. /* GPU-assisted copy using NV_MEMORY_TO_MEMORY_FORMAT, can access
  400. * TTM_PL_{VRAM,TT} directly.
  401. */
  402. static int
  403. nouveau_bo_move_accel_cleanup(struct nouveau_channel *chan,
  404. struct nouveau_bo *nvbo, bool evict,
  405. bool no_wait_reserve, bool no_wait_gpu,
  406. struct ttm_mem_reg *new_mem)
  407. {
  408. struct nouveau_fence *fence = NULL;
  409. int ret;
  410. ret = nouveau_fence_new(chan, &fence, true);
  411. if (ret)
  412. return ret;
  413. ret = ttm_bo_move_accel_cleanup(&nvbo->bo, fence, NULL, evict,
  414. no_wait_reserve, no_wait_gpu, new_mem);
  415. nouveau_fence_unref(&fence);
  416. return ret;
  417. }
  418. static int
  419. nvc0_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
  420. struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem)
  421. {
  422. struct nouveau_mem *node = old_mem->mm_node;
  423. u64 src_offset = node->vma[0].offset;
  424. u64 dst_offset = node->vma[1].offset;
  425. u32 page_count = new_mem->num_pages;
  426. int ret;
  427. page_count = new_mem->num_pages;
  428. while (page_count) {
  429. int line_count = (page_count > 2047) ? 2047 : page_count;
  430. ret = RING_SPACE(chan, 12);
  431. if (ret)
  432. return ret;
  433. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0238, 2);
  434. OUT_RING (chan, upper_32_bits(dst_offset));
  435. OUT_RING (chan, lower_32_bits(dst_offset));
  436. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x030c, 6);
  437. OUT_RING (chan, upper_32_bits(src_offset));
  438. OUT_RING (chan, lower_32_bits(src_offset));
  439. OUT_RING (chan, PAGE_SIZE); /* src_pitch */
  440. OUT_RING (chan, PAGE_SIZE); /* dst_pitch */
  441. OUT_RING (chan, PAGE_SIZE); /* line_length */
  442. OUT_RING (chan, line_count);
  443. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0300, 1);
  444. OUT_RING (chan, 0x00100110);
  445. page_count -= line_count;
  446. src_offset += (PAGE_SIZE * line_count);
  447. dst_offset += (PAGE_SIZE * line_count);
  448. }
  449. return 0;
  450. }
  451. static int
  452. nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
  453. struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem)
  454. {
  455. struct nouveau_mem *node = old_mem->mm_node;
  456. struct nouveau_bo *nvbo = nouveau_bo(bo);
  457. u64 length = (new_mem->num_pages << PAGE_SHIFT);
  458. u64 src_offset = node->vma[0].offset;
  459. u64 dst_offset = node->vma[1].offset;
  460. int ret;
  461. while (length) {
  462. u32 amount, stride, height;
  463. amount = min(length, (u64)(4 * 1024 * 1024));
  464. stride = 16 * 4;
  465. height = amount / stride;
  466. if (new_mem->mem_type == TTM_PL_VRAM &&
  467. nouveau_bo_tile_layout(nvbo)) {
  468. ret = RING_SPACE(chan, 8);
  469. if (ret)
  470. return ret;
  471. BEGIN_RING(chan, NvSubM2MF, 0x0200, 7);
  472. OUT_RING (chan, 0);
  473. OUT_RING (chan, 0);
  474. OUT_RING (chan, stride);
  475. OUT_RING (chan, height);
  476. OUT_RING (chan, 1);
  477. OUT_RING (chan, 0);
  478. OUT_RING (chan, 0);
  479. } else {
  480. ret = RING_SPACE(chan, 2);
  481. if (ret)
  482. return ret;
  483. BEGIN_RING(chan, NvSubM2MF, 0x0200, 1);
  484. OUT_RING (chan, 1);
  485. }
  486. if (old_mem->mem_type == TTM_PL_VRAM &&
  487. nouveau_bo_tile_layout(nvbo)) {
  488. ret = RING_SPACE(chan, 8);
  489. if (ret)
  490. return ret;
  491. BEGIN_RING(chan, NvSubM2MF, 0x021c, 7);
  492. OUT_RING (chan, 0);
  493. OUT_RING (chan, 0);
  494. OUT_RING (chan, stride);
  495. OUT_RING (chan, height);
  496. OUT_RING (chan, 1);
  497. OUT_RING (chan, 0);
  498. OUT_RING (chan, 0);
  499. } else {
  500. ret = RING_SPACE(chan, 2);
  501. if (ret)
  502. return ret;
  503. BEGIN_RING(chan, NvSubM2MF, 0x021c, 1);
  504. OUT_RING (chan, 1);
  505. }
  506. ret = RING_SPACE(chan, 14);
  507. if (ret)
  508. return ret;
  509. BEGIN_RING(chan, NvSubM2MF, 0x0238, 2);
  510. OUT_RING (chan, upper_32_bits(src_offset));
  511. OUT_RING (chan, upper_32_bits(dst_offset));
  512. BEGIN_RING(chan, NvSubM2MF, 0x030c, 8);
  513. OUT_RING (chan, lower_32_bits(src_offset));
  514. OUT_RING (chan, lower_32_bits(dst_offset));
  515. OUT_RING (chan, stride);
  516. OUT_RING (chan, stride);
  517. OUT_RING (chan, stride);
  518. OUT_RING (chan, height);
  519. OUT_RING (chan, 0x00000101);
  520. OUT_RING (chan, 0x00000000);
  521. BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1);
  522. OUT_RING (chan, 0);
  523. length -= amount;
  524. src_offset += amount;
  525. dst_offset += amount;
  526. }
  527. return 0;
  528. }
  529. static inline uint32_t
  530. nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo,
  531. struct nouveau_channel *chan, struct ttm_mem_reg *mem)
  532. {
  533. if (mem->mem_type == TTM_PL_TT)
  534. return chan->gart_handle;
  535. return chan->vram_handle;
  536. }
  537. static int
  538. nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
  539. struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem)
  540. {
  541. u32 src_offset = old_mem->start << PAGE_SHIFT;
  542. u32 dst_offset = new_mem->start << PAGE_SHIFT;
  543. u32 page_count = new_mem->num_pages;
  544. int ret;
  545. ret = RING_SPACE(chan, 3);
  546. if (ret)
  547. return ret;
  548. BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_SOURCE, 2);
  549. OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, old_mem));
  550. OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, new_mem));
  551. page_count = new_mem->num_pages;
  552. while (page_count) {
  553. int line_count = (page_count > 2047) ? 2047 : page_count;
  554. ret = RING_SPACE(chan, 11);
  555. if (ret)
  556. return ret;
  557. BEGIN_RING(chan, NvSubM2MF,
  558. NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
  559. OUT_RING (chan, src_offset);
  560. OUT_RING (chan, dst_offset);
  561. OUT_RING (chan, PAGE_SIZE); /* src_pitch */
  562. OUT_RING (chan, PAGE_SIZE); /* dst_pitch */
  563. OUT_RING (chan, PAGE_SIZE); /* line_length */
  564. OUT_RING (chan, line_count);
  565. OUT_RING (chan, 0x00000101);
  566. OUT_RING (chan, 0x00000000);
  567. BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1);
  568. OUT_RING (chan, 0);
  569. page_count -= line_count;
  570. src_offset += (PAGE_SIZE * line_count);
  571. dst_offset += (PAGE_SIZE * line_count);
  572. }
  573. return 0;
  574. }
  575. static int
  576. nouveau_vma_getmap(struct nouveau_channel *chan, struct nouveau_bo *nvbo,
  577. struct ttm_mem_reg *mem, struct nouveau_vma *vma)
  578. {
  579. struct nouveau_mem *node = mem->mm_node;
  580. int ret;
  581. ret = nouveau_vm_get(chan->vm, mem->num_pages << PAGE_SHIFT,
  582. node->page_shift, NV_MEM_ACCESS_RO, vma);
  583. if (ret)
  584. return ret;
  585. if (mem->mem_type == TTM_PL_VRAM)
  586. nouveau_vm_map(vma, node);
  587. else
  588. nouveau_vm_map_sg(vma, 0, mem->num_pages << PAGE_SHIFT,
  589. node, node->pages);
  590. return 0;
  591. }
  592. static int
  593. nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,
  594. bool no_wait_reserve, bool no_wait_gpu,
  595. struct ttm_mem_reg *new_mem)
  596. {
  597. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  598. struct nouveau_bo *nvbo = nouveau_bo(bo);
  599. struct ttm_mem_reg *old_mem = &bo->mem;
  600. struct nouveau_channel *chan;
  601. int ret;
  602. chan = nvbo->channel;
  603. if (!chan) {
  604. chan = dev_priv->channel;
  605. mutex_lock_nested(&chan->mutex, NOUVEAU_KCHANNEL_MUTEX);
  606. }
  607. /* create temporary vmas for the transfer and attach them to the
  608. * old nouveau_mem node, these will get cleaned up after ttm has
  609. * destroyed the ttm_mem_reg
  610. */
  611. if (dev_priv->card_type >= NV_50) {
  612. struct nouveau_mem *node = old_mem->mm_node;
  613. ret = nouveau_vma_getmap(chan, nvbo, old_mem, &node->vma[0]);
  614. if (ret)
  615. goto out;
  616. ret = nouveau_vma_getmap(chan, nvbo, new_mem, &node->vma[1]);
  617. if (ret)
  618. goto out;
  619. }
  620. if (dev_priv->card_type < NV_50)
  621. ret = nv04_bo_move_m2mf(chan, bo, &bo->mem, new_mem);
  622. else
  623. if (dev_priv->card_type < NV_C0)
  624. ret = nv50_bo_move_m2mf(chan, bo, &bo->mem, new_mem);
  625. else
  626. ret = nvc0_bo_move_m2mf(chan, bo, &bo->mem, new_mem);
  627. if (ret == 0) {
  628. ret = nouveau_bo_move_accel_cleanup(chan, nvbo, evict,
  629. no_wait_reserve,
  630. no_wait_gpu, new_mem);
  631. }
  632. out:
  633. if (chan == dev_priv->channel)
  634. mutex_unlock(&chan->mutex);
  635. return ret;
  636. }
  637. static int
  638. nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
  639. bool no_wait_reserve, bool no_wait_gpu,
  640. struct ttm_mem_reg *new_mem)
  641. {
  642. u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
  643. struct ttm_placement placement;
  644. struct ttm_mem_reg tmp_mem;
  645. int ret;
  646. placement.fpfn = placement.lpfn = 0;
  647. placement.num_placement = placement.num_busy_placement = 1;
  648. placement.placement = placement.busy_placement = &placement_memtype;
  649. tmp_mem = *new_mem;
  650. tmp_mem.mm_node = NULL;
  651. ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_reserve, no_wait_gpu);
  652. if (ret)
  653. return ret;
  654. ret = ttm_tt_bind(bo->ttm, &tmp_mem);
  655. if (ret)
  656. goto out;
  657. ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_reserve, no_wait_gpu, &tmp_mem);
  658. if (ret)
  659. goto out;
  660. ret = ttm_bo_move_ttm(bo, true, no_wait_reserve, no_wait_gpu, new_mem);
  661. out:
  662. ttm_bo_mem_put(bo, &tmp_mem);
  663. return ret;
  664. }
  665. static int
  666. nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr,
  667. bool no_wait_reserve, bool no_wait_gpu,
  668. struct ttm_mem_reg *new_mem)
  669. {
  670. u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
  671. struct ttm_placement placement;
  672. struct ttm_mem_reg tmp_mem;
  673. int ret;
  674. placement.fpfn = placement.lpfn = 0;
  675. placement.num_placement = placement.num_busy_placement = 1;
  676. placement.placement = placement.busy_placement = &placement_memtype;
  677. tmp_mem = *new_mem;
  678. tmp_mem.mm_node = NULL;
  679. ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_reserve, no_wait_gpu);
  680. if (ret)
  681. return ret;
  682. ret = ttm_bo_move_ttm(bo, true, no_wait_reserve, no_wait_gpu, &tmp_mem);
  683. if (ret)
  684. goto out;
  685. ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_reserve, no_wait_gpu, new_mem);
  686. if (ret)
  687. goto out;
  688. out:
  689. ttm_bo_mem_put(bo, &tmp_mem);
  690. return ret;
  691. }
  692. static void
  693. nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem)
  694. {
  695. struct nouveau_mem *node = new_mem->mm_node;
  696. struct nouveau_bo *nvbo = nouveau_bo(bo);
  697. struct nouveau_vma *vma;
  698. list_for_each_entry(vma, &nvbo->vma_list, head) {
  699. if (new_mem->mem_type == TTM_PL_VRAM) {
  700. nouveau_vm_map(vma, new_mem->mm_node);
  701. } else
  702. if (new_mem->mem_type == TTM_PL_TT &&
  703. nvbo->page_shift == vma->vm->spg_shift) {
  704. nouveau_vm_map_sg(vma, 0, new_mem->
  705. num_pages << PAGE_SHIFT,
  706. node, node->pages);
  707. } else {
  708. nouveau_vm_unmap(vma);
  709. }
  710. }
  711. }
  712. static int
  713. nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem,
  714. struct nouveau_tile_reg **new_tile)
  715. {
  716. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  717. struct drm_device *dev = dev_priv->dev;
  718. struct nouveau_bo *nvbo = nouveau_bo(bo);
  719. u64 offset = new_mem->start << PAGE_SHIFT;
  720. *new_tile = NULL;
  721. if (new_mem->mem_type != TTM_PL_VRAM)
  722. return 0;
  723. if (dev_priv->card_type >= NV_10) {
  724. *new_tile = nv10_mem_set_tiling(dev, offset, new_mem->size,
  725. nvbo->tile_mode,
  726. nvbo->tile_flags);
  727. }
  728. return 0;
  729. }
  730. static void
  731. nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo,
  732. struct nouveau_tile_reg *new_tile,
  733. struct nouveau_tile_reg **old_tile)
  734. {
  735. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  736. struct drm_device *dev = dev_priv->dev;
  737. nv10_mem_put_tile_region(dev, *old_tile, bo->sync_obj);
  738. *old_tile = new_tile;
  739. }
  740. static int
  741. nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr,
  742. bool no_wait_reserve, bool no_wait_gpu,
  743. struct ttm_mem_reg *new_mem)
  744. {
  745. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  746. struct nouveau_bo *nvbo = nouveau_bo(bo);
  747. struct ttm_mem_reg *old_mem = &bo->mem;
  748. struct nouveau_tile_reg *new_tile = NULL;
  749. int ret = 0;
  750. if (dev_priv->card_type < NV_50) {
  751. ret = nouveau_bo_vm_bind(bo, new_mem, &new_tile);
  752. if (ret)
  753. return ret;
  754. }
  755. /* Fake bo copy. */
  756. if (old_mem->mem_type == TTM_PL_SYSTEM && !bo->ttm) {
  757. BUG_ON(bo->mem.mm_node != NULL);
  758. bo->mem = *new_mem;
  759. new_mem->mm_node = NULL;
  760. goto out;
  761. }
  762. /* Software copy if the card isn't up and running yet. */
  763. if (!dev_priv->channel) {
  764. ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, new_mem);
  765. goto out;
  766. }
  767. /* Hardware assisted copy. */
  768. if (new_mem->mem_type == TTM_PL_SYSTEM)
  769. ret = nouveau_bo_move_flipd(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem);
  770. else if (old_mem->mem_type == TTM_PL_SYSTEM)
  771. ret = nouveau_bo_move_flips(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem);
  772. else
  773. ret = nouveau_bo_move_m2mf(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem);
  774. if (!ret)
  775. goto out;
  776. /* Fallback to software copy. */
  777. ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, new_mem);
  778. out:
  779. if (dev_priv->card_type < NV_50) {
  780. if (ret)
  781. nouveau_bo_vm_cleanup(bo, NULL, &new_tile);
  782. else
  783. nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile);
  784. }
  785. return ret;
  786. }
  787. static int
  788. nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp)
  789. {
  790. return 0;
  791. }
  792. static int
  793. nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
  794. {
  795. struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
  796. struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
  797. struct drm_device *dev = dev_priv->dev;
  798. int ret;
  799. mem->bus.addr = NULL;
  800. mem->bus.offset = 0;
  801. mem->bus.size = mem->num_pages << PAGE_SHIFT;
  802. mem->bus.base = 0;
  803. mem->bus.is_iomem = false;
  804. if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE))
  805. return -EINVAL;
  806. switch (mem->mem_type) {
  807. case TTM_PL_SYSTEM:
  808. /* System memory */
  809. return 0;
  810. case TTM_PL_TT:
  811. #if __OS_HAS_AGP
  812. if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {
  813. mem->bus.offset = mem->start << PAGE_SHIFT;
  814. mem->bus.base = dev_priv->gart_info.aper_base;
  815. mem->bus.is_iomem = true;
  816. }
  817. #endif
  818. break;
  819. case TTM_PL_VRAM:
  820. {
  821. struct nouveau_mem *node = mem->mm_node;
  822. u8 page_shift;
  823. if (!dev_priv->bar1_vm) {
  824. mem->bus.offset = mem->start << PAGE_SHIFT;
  825. mem->bus.base = pci_resource_start(dev->pdev, 1);
  826. mem->bus.is_iomem = true;
  827. break;
  828. }
  829. if (dev_priv->card_type >= NV_C0)
  830. page_shift = node->page_shift;
  831. else
  832. page_shift = 12;
  833. ret = nouveau_vm_get(dev_priv->bar1_vm, mem->bus.size,
  834. page_shift, NV_MEM_ACCESS_RW,
  835. &node->bar_vma);
  836. if (ret)
  837. return ret;
  838. nouveau_vm_map(&node->bar_vma, node);
  839. if (ret) {
  840. nouveau_vm_put(&node->bar_vma);
  841. return ret;
  842. }
  843. mem->bus.offset = node->bar_vma.offset;
  844. if (dev_priv->card_type == NV_50) /*XXX*/
  845. mem->bus.offset -= 0x0020000000ULL;
  846. mem->bus.base = pci_resource_start(dev->pdev, 1);
  847. mem->bus.is_iomem = true;
  848. }
  849. break;
  850. default:
  851. return -EINVAL;
  852. }
  853. return 0;
  854. }
  855. static void
  856. nouveau_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
  857. {
  858. struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
  859. struct nouveau_mem *node = mem->mm_node;
  860. if (!dev_priv->bar1_vm || mem->mem_type != TTM_PL_VRAM)
  861. return;
  862. if (!node->bar_vma.node)
  863. return;
  864. nouveau_vm_unmap(&node->bar_vma);
  865. nouveau_vm_put(&node->bar_vma);
  866. }
  867. static int
  868. nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
  869. {
  870. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  871. struct nouveau_bo *nvbo = nouveau_bo(bo);
  872. /* as long as the bo isn't in vram, and isn't tiled, we've got
  873. * nothing to do here.
  874. */
  875. if (bo->mem.mem_type != TTM_PL_VRAM) {
  876. if (dev_priv->card_type < NV_50 ||
  877. !nouveau_bo_tile_layout(nvbo))
  878. return 0;
  879. }
  880. /* make sure bo is in mappable vram */
  881. if (bo->mem.start + bo->mem.num_pages < dev_priv->fb_mappable_pages)
  882. return 0;
  883. nvbo->placement.fpfn = 0;
  884. nvbo->placement.lpfn = dev_priv->fb_mappable_pages;
  885. nouveau_bo_placement_set(nvbo, TTM_PL_VRAM, 0);
  886. return nouveau_bo_validate(nvbo, false, true, false);
  887. }
  888. void
  889. nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)
  890. {
  891. struct nouveau_fence *old_fence;
  892. if (likely(fence))
  893. nouveau_fence_ref(fence);
  894. spin_lock(&nvbo->bo.bdev->fence_lock);
  895. old_fence = nvbo->bo.sync_obj;
  896. nvbo->bo.sync_obj = fence;
  897. spin_unlock(&nvbo->bo.bdev->fence_lock);
  898. nouveau_fence_unref(&old_fence);
  899. }
  900. static int
  901. nouveau_ttm_tt_populate(struct ttm_tt *ttm)
  902. {
  903. struct drm_nouveau_private *dev_priv;
  904. struct drm_device *dev;
  905. unsigned i;
  906. int r;
  907. if (ttm->state != tt_unpopulated)
  908. return 0;
  909. dev_priv = nouveau_bdev(ttm->bdev);
  910. dev = dev_priv->dev;
  911. #ifdef CONFIG_SWIOTLB
  912. if (swiotlb_nr_tbl()) {
  913. return ttm_dma_populate(ttm, dev->dev);
  914. }
  915. #endif
  916. r = ttm_pool_populate(ttm);
  917. if (r) {
  918. return r;
  919. }
  920. for (i = 0; i < ttm->num_pages; i++) {
  921. ttm->dma_address[i] = pci_map_page(dev->pdev, ttm->pages[i],
  922. 0, PAGE_SIZE,
  923. PCI_DMA_BIDIRECTIONAL);
  924. if (pci_dma_mapping_error(dev->pdev, ttm->dma_address[i])) {
  925. while (--i) {
  926. pci_unmap_page(dev->pdev, ttm->dma_address[i],
  927. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  928. ttm->dma_address[i] = 0;
  929. }
  930. ttm_pool_unpopulate(ttm);
  931. return -EFAULT;
  932. }
  933. }
  934. return 0;
  935. }
  936. static void
  937. nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
  938. {
  939. struct drm_nouveau_private *dev_priv;
  940. struct drm_device *dev;
  941. unsigned i;
  942. dev_priv = nouveau_bdev(ttm->bdev);
  943. dev = dev_priv->dev;
  944. #ifdef CONFIG_SWIOTLB
  945. if (swiotlb_nr_tbl()) {
  946. ttm_dma_unpopulate(ttm, dev->dev);
  947. return;
  948. }
  949. #endif
  950. for (i = 0; i < ttm->num_pages; i++) {
  951. if (ttm->dma_address[i]) {
  952. pci_unmap_page(dev->pdev, ttm->dma_address[i],
  953. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  954. }
  955. }
  956. ttm_pool_unpopulate(ttm);
  957. }
  958. struct ttm_bo_driver nouveau_bo_driver = {
  959. .ttm_tt_create = &nouveau_ttm_tt_create,
  960. .ttm_tt_populate = &nouveau_ttm_tt_populate,
  961. .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
  962. .invalidate_caches = nouveau_bo_invalidate_caches,
  963. .init_mem_type = nouveau_bo_init_mem_type,
  964. .evict_flags = nouveau_bo_evict_flags,
  965. .move_notify = nouveau_bo_move_ntfy,
  966. .move = nouveau_bo_move,
  967. .verify_access = nouveau_bo_verify_access,
  968. .sync_obj_signaled = __nouveau_fence_signalled,
  969. .sync_obj_wait = __nouveau_fence_wait,
  970. .sync_obj_flush = __nouveau_fence_flush,
  971. .sync_obj_unref = __nouveau_fence_unref,
  972. .sync_obj_ref = __nouveau_fence_ref,
  973. .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify,
  974. .io_mem_reserve = &nouveau_ttm_io_mem_reserve,
  975. .io_mem_free = &nouveau_ttm_io_mem_free,
  976. };
  977. struct nouveau_vma *
  978. nouveau_bo_vma_find(struct nouveau_bo *nvbo, struct nouveau_vm *vm)
  979. {
  980. struct nouveau_vma *vma;
  981. list_for_each_entry(vma, &nvbo->vma_list, head) {
  982. if (vma->vm == vm)
  983. return vma;
  984. }
  985. return NULL;
  986. }
  987. int
  988. nouveau_bo_vma_add(struct nouveau_bo *nvbo, struct nouveau_vm *vm,
  989. struct nouveau_vma *vma)
  990. {
  991. const u32 size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
  992. struct nouveau_mem *node = nvbo->bo.mem.mm_node;
  993. int ret;
  994. ret = nouveau_vm_get(vm, size, nvbo->page_shift,
  995. NV_MEM_ACCESS_RW, vma);
  996. if (ret)
  997. return ret;
  998. if (nvbo->bo.mem.mem_type == TTM_PL_VRAM)
  999. nouveau_vm_map(vma, nvbo->bo.mem.mm_node);
  1000. else
  1001. if (nvbo->bo.mem.mem_type == TTM_PL_TT)
  1002. nouveau_vm_map_sg(vma, 0, size, node, node->pages);
  1003. list_add_tail(&vma->head, &nvbo->vma_list);
  1004. vma->refcount = 1;
  1005. return 0;
  1006. }
  1007. void
  1008. nouveau_bo_vma_del(struct nouveau_bo *nvbo, struct nouveau_vma *vma)
  1009. {
  1010. if (vma->node) {
  1011. if (nvbo->bo.mem.mem_type != TTM_PL_SYSTEM) {
  1012. spin_lock(&nvbo->bo.bdev->fence_lock);
  1013. ttm_bo_wait(&nvbo->bo, false, false, false);
  1014. spin_unlock(&nvbo->bo.bdev->fence_lock);
  1015. nouveau_vm_unmap(vma);
  1016. }
  1017. nouveau_vm_put(vma);
  1018. list_del(&vma->head);
  1019. }
  1020. }