nouveau_mem.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
  3. * Copyright 2005 Stephane Marchesin
  4. *
  5. * The Weather Channel (TM) funded Tungsten Graphics to develop the
  6. * initial release of the Radeon 8500 driver under the XFree86 license.
  7. * This notice must be preserved.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the next
  17. * paragraph) shall be included in all copies or substantial portions of the
  18. * Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. * DEALINGS IN THE SOFTWARE.
  27. *
  28. * Authors:
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. */
  31. #include "drmP.h"
  32. #include "drm.h"
  33. #include "drm_sarea.h"
  34. #include "nouveau_drv.h"
  35. #include "nouveau_pm.h"
  36. #include "nouveau_mm.h"
  37. #include "nouveau_vm.h"
  38. /*
  39. * NV10-NV40 tiling helpers
  40. */
  41. static void
  42. nv10_mem_update_tile_region(struct drm_device *dev,
  43. struct nouveau_tile_reg *tile, uint32_t addr,
  44. uint32_t size, uint32_t pitch, uint32_t flags)
  45. {
  46. struct drm_nouveau_private *dev_priv = dev->dev_private;
  47. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  48. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  49. int i = tile - dev_priv->tile.reg, j;
  50. unsigned long save;
  51. nouveau_fence_unref(&tile->fence);
  52. if (tile->pitch)
  53. pfb->free_tile_region(dev, i);
  54. if (pitch)
  55. pfb->init_tile_region(dev, i, addr, size, pitch, flags);
  56. spin_lock_irqsave(&dev_priv->context_switch_lock, save);
  57. pfifo->reassign(dev, false);
  58. pfifo->cache_pull(dev, false);
  59. nouveau_wait_for_idle(dev);
  60. pfb->set_tile_region(dev, i);
  61. for (j = 0; j < NVOBJ_ENGINE_NR; j++) {
  62. if (dev_priv->eng[j] && dev_priv->eng[j]->set_tile_region)
  63. dev_priv->eng[j]->set_tile_region(dev, i);
  64. }
  65. pfifo->cache_pull(dev, true);
  66. pfifo->reassign(dev, true);
  67. spin_unlock_irqrestore(&dev_priv->context_switch_lock, save);
  68. }
  69. static struct nouveau_tile_reg *
  70. nv10_mem_get_tile_region(struct drm_device *dev, int i)
  71. {
  72. struct drm_nouveau_private *dev_priv = dev->dev_private;
  73. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  74. spin_lock(&dev_priv->tile.lock);
  75. if (!tile->used &&
  76. (!tile->fence || nouveau_fence_signalled(tile->fence)))
  77. tile->used = true;
  78. else
  79. tile = NULL;
  80. spin_unlock(&dev_priv->tile.lock);
  81. return tile;
  82. }
  83. void
  84. nv10_mem_put_tile_region(struct drm_device *dev, struct nouveau_tile_reg *tile,
  85. struct nouveau_fence *fence)
  86. {
  87. struct drm_nouveau_private *dev_priv = dev->dev_private;
  88. if (tile) {
  89. spin_lock(&dev_priv->tile.lock);
  90. if (fence) {
  91. /* Mark it as pending. */
  92. tile->fence = fence;
  93. nouveau_fence_ref(fence);
  94. }
  95. tile->used = false;
  96. spin_unlock(&dev_priv->tile.lock);
  97. }
  98. }
  99. struct nouveau_tile_reg *
  100. nv10_mem_set_tiling(struct drm_device *dev, uint32_t addr, uint32_t size,
  101. uint32_t pitch, uint32_t flags)
  102. {
  103. struct drm_nouveau_private *dev_priv = dev->dev_private;
  104. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  105. struct nouveau_tile_reg *tile, *found = NULL;
  106. int i;
  107. for (i = 0; i < pfb->num_tiles; i++) {
  108. tile = nv10_mem_get_tile_region(dev, i);
  109. if (pitch && !found) {
  110. found = tile;
  111. continue;
  112. } else if (tile && tile->pitch) {
  113. /* Kill an unused tile region. */
  114. nv10_mem_update_tile_region(dev, tile, 0, 0, 0, 0);
  115. }
  116. nv10_mem_put_tile_region(dev, tile, NULL);
  117. }
  118. if (found)
  119. nv10_mem_update_tile_region(dev, found, addr, size,
  120. pitch, flags);
  121. return found;
  122. }
  123. /*
  124. * Cleanup everything
  125. */
  126. void
  127. nouveau_mem_vram_fini(struct drm_device *dev)
  128. {
  129. struct drm_nouveau_private *dev_priv = dev->dev_private;
  130. ttm_bo_device_release(&dev_priv->ttm.bdev);
  131. nouveau_ttm_global_release(dev_priv);
  132. if (dev_priv->fb_mtrr >= 0) {
  133. drm_mtrr_del(dev_priv->fb_mtrr,
  134. pci_resource_start(dev->pdev, 1),
  135. pci_resource_len(dev->pdev, 1), DRM_MTRR_WC);
  136. dev_priv->fb_mtrr = -1;
  137. }
  138. }
  139. void
  140. nouveau_mem_gart_fini(struct drm_device *dev)
  141. {
  142. nouveau_sgdma_takedown(dev);
  143. if (drm_core_has_AGP(dev) && dev->agp) {
  144. struct drm_agp_mem *entry, *tempe;
  145. /* Remove AGP resources, but leave dev->agp
  146. intact until drv_cleanup is called. */
  147. list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
  148. if (entry->bound)
  149. drm_unbind_agp(entry->memory);
  150. drm_free_agp(entry->memory, entry->pages);
  151. kfree(entry);
  152. }
  153. INIT_LIST_HEAD(&dev->agp->memory);
  154. if (dev->agp->acquired)
  155. drm_agp_release(dev);
  156. dev->agp->acquired = 0;
  157. dev->agp->enabled = 0;
  158. }
  159. }
  160. bool
  161. nouveau_mem_flags_valid(struct drm_device *dev, u32 tile_flags)
  162. {
  163. if (!(tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK))
  164. return true;
  165. return false;
  166. }
  167. #if __OS_HAS_AGP
  168. static unsigned long
  169. get_agp_mode(struct drm_device *dev, unsigned long mode)
  170. {
  171. struct drm_nouveau_private *dev_priv = dev->dev_private;
  172. /*
  173. * FW seems to be broken on nv18, it makes the card lock up
  174. * randomly.
  175. */
  176. if (dev_priv->chipset == 0x18)
  177. mode &= ~PCI_AGP_COMMAND_FW;
  178. /*
  179. * AGP mode set in the command line.
  180. */
  181. if (nouveau_agpmode > 0) {
  182. bool agpv3 = mode & 0x8;
  183. int rate = agpv3 ? nouveau_agpmode / 4 : nouveau_agpmode;
  184. mode = (mode & ~0x7) | (rate & 0x7);
  185. }
  186. return mode;
  187. }
  188. #endif
  189. int
  190. nouveau_mem_reset_agp(struct drm_device *dev)
  191. {
  192. #if __OS_HAS_AGP
  193. uint32_t saved_pci_nv_1, pmc_enable;
  194. int ret;
  195. /* First of all, disable fast writes, otherwise if it's
  196. * already enabled in the AGP bridge and we disable the card's
  197. * AGP controller we might be locking ourselves out of it. */
  198. if ((nv_rd32(dev, NV04_PBUS_PCI_NV_19) |
  199. dev->agp->mode) & PCI_AGP_COMMAND_FW) {
  200. struct drm_agp_info info;
  201. struct drm_agp_mode mode;
  202. ret = drm_agp_info(dev, &info);
  203. if (ret)
  204. return ret;
  205. mode.mode = get_agp_mode(dev, info.mode) & ~PCI_AGP_COMMAND_FW;
  206. ret = drm_agp_enable(dev, mode);
  207. if (ret)
  208. return ret;
  209. }
  210. saved_pci_nv_1 = nv_rd32(dev, NV04_PBUS_PCI_NV_1);
  211. /* clear busmaster bit */
  212. nv_wr32(dev, NV04_PBUS_PCI_NV_1, saved_pci_nv_1 & ~0x4);
  213. /* disable AGP */
  214. nv_wr32(dev, NV04_PBUS_PCI_NV_19, 0);
  215. /* power cycle pgraph, if enabled */
  216. pmc_enable = nv_rd32(dev, NV03_PMC_ENABLE);
  217. if (pmc_enable & NV_PMC_ENABLE_PGRAPH) {
  218. nv_wr32(dev, NV03_PMC_ENABLE,
  219. pmc_enable & ~NV_PMC_ENABLE_PGRAPH);
  220. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  221. NV_PMC_ENABLE_PGRAPH);
  222. }
  223. /* and restore (gives effect of resetting AGP) */
  224. nv_wr32(dev, NV04_PBUS_PCI_NV_1, saved_pci_nv_1);
  225. #endif
  226. return 0;
  227. }
  228. int
  229. nouveau_mem_init_agp(struct drm_device *dev)
  230. {
  231. #if __OS_HAS_AGP
  232. struct drm_nouveau_private *dev_priv = dev->dev_private;
  233. struct drm_agp_info info;
  234. struct drm_agp_mode mode;
  235. int ret;
  236. if (!dev->agp->acquired) {
  237. ret = drm_agp_acquire(dev);
  238. if (ret) {
  239. NV_ERROR(dev, "Unable to acquire AGP: %d\n", ret);
  240. return ret;
  241. }
  242. }
  243. nouveau_mem_reset_agp(dev);
  244. ret = drm_agp_info(dev, &info);
  245. if (ret) {
  246. NV_ERROR(dev, "Unable to get AGP info: %d\n", ret);
  247. return ret;
  248. }
  249. /* see agp.h for the AGPSTAT_* modes available */
  250. mode.mode = get_agp_mode(dev, info.mode);
  251. ret = drm_agp_enable(dev, mode);
  252. if (ret) {
  253. NV_ERROR(dev, "Unable to enable AGP: %d\n", ret);
  254. return ret;
  255. }
  256. dev_priv->gart_info.type = NOUVEAU_GART_AGP;
  257. dev_priv->gart_info.aper_base = info.aperture_base;
  258. dev_priv->gart_info.aper_size = info.aperture_size;
  259. #endif
  260. return 0;
  261. }
  262. static const struct vram_types {
  263. int value;
  264. const char *name;
  265. } vram_type_map[] = {
  266. { NV_MEM_TYPE_STOLEN , "stolen system memory" },
  267. { NV_MEM_TYPE_SGRAM , "SGRAM" },
  268. { NV_MEM_TYPE_SDRAM , "SDRAM" },
  269. { NV_MEM_TYPE_DDR1 , "DDR1" },
  270. { NV_MEM_TYPE_DDR2 , "DDR2" },
  271. { NV_MEM_TYPE_DDR3 , "DDR3" },
  272. { NV_MEM_TYPE_GDDR2 , "GDDR2" },
  273. { NV_MEM_TYPE_GDDR3 , "GDDR3" },
  274. { NV_MEM_TYPE_GDDR4 , "GDDR4" },
  275. { NV_MEM_TYPE_GDDR5 , "GDDR5" },
  276. { NV_MEM_TYPE_UNKNOWN, "unknown type" }
  277. };
  278. int
  279. nouveau_mem_vram_init(struct drm_device *dev)
  280. {
  281. struct drm_nouveau_private *dev_priv = dev->dev_private;
  282. struct ttm_bo_device *bdev = &dev_priv->ttm.bdev;
  283. const struct vram_types *vram_type;
  284. int ret, dma_bits;
  285. dma_bits = 32;
  286. if (dev_priv->card_type >= NV_50) {
  287. if (pci_dma_supported(dev->pdev, DMA_BIT_MASK(40)))
  288. dma_bits = 40;
  289. } else
  290. if (0 && pci_is_pcie(dev->pdev) &&
  291. dev_priv->chipset > 0x40 &&
  292. dev_priv->chipset != 0x45) {
  293. if (pci_dma_supported(dev->pdev, DMA_BIT_MASK(39)))
  294. dma_bits = 39;
  295. }
  296. ret = pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(dma_bits));
  297. if (ret)
  298. return ret;
  299. ret = pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(dma_bits));
  300. if (ret) {
  301. /* Reset to default value. */
  302. pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32));
  303. }
  304. ret = nouveau_ttm_global_init(dev_priv);
  305. if (ret)
  306. return ret;
  307. ret = ttm_bo_device_init(&dev_priv->ttm.bdev,
  308. dev_priv->ttm.bo_global_ref.ref.object,
  309. &nouveau_bo_driver, DRM_FILE_PAGE_OFFSET,
  310. dma_bits <= 32 ? true : false);
  311. if (ret) {
  312. NV_ERROR(dev, "Error initialising bo driver: %d\n", ret);
  313. return ret;
  314. }
  315. vram_type = vram_type_map;
  316. while (vram_type->value != NV_MEM_TYPE_UNKNOWN) {
  317. if (nouveau_vram_type) {
  318. if (!strcasecmp(nouveau_vram_type, vram_type->name))
  319. break;
  320. dev_priv->vram_type = vram_type->value;
  321. } else {
  322. if (vram_type->value == dev_priv->vram_type)
  323. break;
  324. }
  325. vram_type++;
  326. }
  327. NV_INFO(dev, "Detected %dMiB VRAM (%s)\n",
  328. (int)(dev_priv->vram_size >> 20), vram_type->name);
  329. if (dev_priv->vram_sys_base) {
  330. NV_INFO(dev, "Stolen system memory at: 0x%010llx\n",
  331. dev_priv->vram_sys_base);
  332. }
  333. dev_priv->fb_available_size = dev_priv->vram_size;
  334. dev_priv->fb_mappable_pages = dev_priv->fb_available_size;
  335. if (dev_priv->fb_mappable_pages > pci_resource_len(dev->pdev, 1))
  336. dev_priv->fb_mappable_pages = pci_resource_len(dev->pdev, 1);
  337. dev_priv->fb_mappable_pages >>= PAGE_SHIFT;
  338. dev_priv->fb_available_size -= dev_priv->ramin_rsvd_vram;
  339. dev_priv->fb_aper_free = dev_priv->fb_available_size;
  340. /* mappable vram */
  341. ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM,
  342. dev_priv->fb_available_size >> PAGE_SHIFT);
  343. if (ret) {
  344. NV_ERROR(dev, "Failed VRAM mm init: %d\n", ret);
  345. return ret;
  346. }
  347. if (dev_priv->card_type < NV_50) {
  348. ret = nouveau_bo_new(dev, 256*1024, 0, TTM_PL_FLAG_VRAM,
  349. 0, 0, &dev_priv->vga_ram);
  350. if (ret == 0)
  351. ret = nouveau_bo_pin(dev_priv->vga_ram,
  352. TTM_PL_FLAG_VRAM);
  353. if (ret) {
  354. NV_WARN(dev, "failed to reserve VGA memory\n");
  355. nouveau_bo_ref(NULL, &dev_priv->vga_ram);
  356. }
  357. }
  358. dev_priv->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 1),
  359. pci_resource_len(dev->pdev, 1),
  360. DRM_MTRR_WC);
  361. return 0;
  362. }
  363. int
  364. nouveau_mem_gart_init(struct drm_device *dev)
  365. {
  366. struct drm_nouveau_private *dev_priv = dev->dev_private;
  367. struct ttm_bo_device *bdev = &dev_priv->ttm.bdev;
  368. int ret;
  369. dev_priv->gart_info.type = NOUVEAU_GART_NONE;
  370. #if !defined(__powerpc__) && !defined(__ia64__)
  371. if (drm_pci_device_is_agp(dev) && dev->agp && nouveau_agpmode) {
  372. ret = nouveau_mem_init_agp(dev);
  373. if (ret)
  374. NV_ERROR(dev, "Error initialising AGP: %d\n", ret);
  375. }
  376. #endif
  377. if (dev_priv->gart_info.type == NOUVEAU_GART_NONE) {
  378. ret = nouveau_sgdma_init(dev);
  379. if (ret) {
  380. NV_ERROR(dev, "Error initialising PCI(E): %d\n", ret);
  381. return ret;
  382. }
  383. }
  384. NV_INFO(dev, "%d MiB GART (aperture)\n",
  385. (int)(dev_priv->gart_info.aper_size >> 20));
  386. dev_priv->gart_info.aper_free = dev_priv->gart_info.aper_size;
  387. ret = ttm_bo_init_mm(bdev, TTM_PL_TT,
  388. dev_priv->gart_info.aper_size >> PAGE_SHIFT);
  389. if (ret) {
  390. NV_ERROR(dev, "Failed TT mm init: %d\n", ret);
  391. return ret;
  392. }
  393. return 0;
  394. }
  395. static int
  396. nv40_mem_timing_calc(struct drm_device *dev, u32 freq,
  397. struct nouveau_pm_tbl_entry *e, u8 len,
  398. struct nouveau_pm_memtiming *boot,
  399. struct nouveau_pm_memtiming *t)
  400. {
  401. t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC);
  402. /* XXX: I don't trust the -1's and +1's... they must come
  403. * from somewhere! */
  404. t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 |
  405. 1 << 16 |
  406. (e->tWTR + 2 + (t->tCWL - 1)) << 8 |
  407. (e->tCL + 2 - (t->tCWL - 1));
  408. t->reg[2] = 0x20200000 |
  409. ((t->tCWL - 1) << 24 |
  410. e->tRRD << 16 |
  411. e->tRCDWR << 8 |
  412. e->tRCDRD);
  413. NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x\n", t->id,
  414. t->reg[0], t->reg[1], t->reg[2]);
  415. return 0;
  416. }
  417. static int
  418. nv50_mem_timing_calc(struct drm_device *dev, u32 freq,
  419. struct nouveau_pm_tbl_entry *e, u8 len,
  420. struct nouveau_pm_memtiming *boot,
  421. struct nouveau_pm_memtiming *t)
  422. {
  423. struct drm_nouveau_private *dev_priv = dev->dev_private;
  424. struct bit_entry P;
  425. uint8_t unk18 = 1, unk20 = 0, unk21 = 0, tmp7_3;
  426. if (bit_table(dev, 'P', &P))
  427. return -EINVAL;
  428. switch (min(len, (u8) 22)) {
  429. case 22:
  430. unk21 = e->tUNK_21;
  431. case 21:
  432. unk20 = e->tUNK_20;
  433. case 20:
  434. if (e->tCWL > 0)
  435. t->tCWL = e->tCWL;
  436. case 19:
  437. unk18 = e->tUNK_18;
  438. break;
  439. }
  440. t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC);
  441. t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 |
  442. max(unk18, (u8) 1) << 16 |
  443. (e->tWTR + 2 + (t->tCWL - 1)) << 8;
  444. t->reg[2] = ((t->tCWL - 1) << 24 |
  445. e->tRRD << 16 |
  446. e->tRCDWR << 8 |
  447. e->tRCDRD);
  448. t->reg[4] = e->tUNK_13 << 8 | e->tUNK_13;
  449. t->reg[5] = (e->tRFC << 24 | max(e->tRCDRD, e->tRCDWR) << 16 | e->tRP);
  450. t->reg[8] = boot->reg[8] & 0xffffff00;
  451. if (P.version == 1) {
  452. t->reg[1] |= (e->tCL + 2 - (t->tCWL - 1));
  453. t->reg[3] = (0x14 + e->tCL) << 24 |
  454. 0x16 << 16 |
  455. (e->tCL - 1) << 8 |
  456. (e->tCL - 1);
  457. t->reg[4] |= boot->reg[4] & 0xffff0000;
  458. t->reg[6] = (0x33 - t->tCWL) << 16 |
  459. t->tCWL << 8 |
  460. (0x2e + e->tCL - t->tCWL);
  461. t->reg[7] = 0x4000202 | (e->tCL - 1) << 16;
  462. /* XXX: P.version == 1 only has DDR2 and GDDR3? */
  463. if (dev_priv->vram_type == NV_MEM_TYPE_DDR2) {
  464. t->reg[5] |= (e->tCL + 3) << 8;
  465. t->reg[6] |= (t->tCWL - 2) << 8;
  466. t->reg[8] |= (e->tCL - 4);
  467. } else {
  468. t->reg[5] |= (e->tCL + 2) << 8;
  469. t->reg[6] |= t->tCWL << 8;
  470. t->reg[8] |= (e->tCL - 2);
  471. }
  472. } else {
  473. t->reg[1] |= (5 + e->tCL - (t->tCWL));
  474. /* XXX: 0xb? 0x30? */
  475. t->reg[3] = (0x30 + e->tCL) << 24 |
  476. (boot->reg[3] & 0x00ff0000)|
  477. (0xb + e->tCL) << 8 |
  478. (e->tCL - 1);
  479. t->reg[4] |= (unk20 << 24 | unk21 << 16);
  480. /* XXX: +6? */
  481. t->reg[5] |= (t->tCWL + 6) << 8;
  482. t->reg[6] = (0x5a + e->tCL) << 16 |
  483. (6 - e->tCL + t->tCWL) << 8 |
  484. (0x50 + e->tCL - t->tCWL);
  485. tmp7_3 = (boot->reg[7] & 0xff000000) >> 24;
  486. t->reg[7] = (tmp7_3 << 24) |
  487. ((tmp7_3 - 6 + e->tCL) << 16) |
  488. 0x202;
  489. }
  490. NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x %08x\n", t->id,
  491. t->reg[0], t->reg[1], t->reg[2], t->reg[3]);
  492. NV_DEBUG(dev, " 230: %08x %08x %08x %08x\n",
  493. t->reg[4], t->reg[5], t->reg[6], t->reg[7]);
  494. NV_DEBUG(dev, " 240: %08x\n", t->reg[8]);
  495. return 0;
  496. }
  497. static int
  498. nvc0_mem_timing_calc(struct drm_device *dev, u32 freq,
  499. struct nouveau_pm_tbl_entry *e, u8 len,
  500. struct nouveau_pm_memtiming *boot,
  501. struct nouveau_pm_memtiming *t)
  502. {
  503. if (e->tCWL > 0)
  504. t->tCWL = e->tCWL;
  505. t->reg[0] = (e->tRP << 24 | (e->tRAS & 0x7f) << 17 |
  506. e->tRFC << 8 | e->tRC);
  507. t->reg[1] = (boot->reg[1] & 0xff000000) |
  508. (e->tRCDWR & 0x0f) << 20 |
  509. (e->tRCDRD & 0x0f) << 14 |
  510. (e->tCWL << 7) |
  511. (e->tCL & 0x0f);
  512. t->reg[2] = (boot->reg[2] & 0xff0000ff) |
  513. e->tWR << 16 | e->tWTR << 8;
  514. t->reg[3] = (e->tUNK_20 & 0xf) << 9 |
  515. (e->tUNK_21 & 0xf) << 5 |
  516. (e->tUNK_13 & 0x1f);
  517. t->reg[4] = (boot->reg[4] & 0xfff00fff) |
  518. (e->tRRD&0x1f) << 15;
  519. NV_DEBUG(dev, "Entry %d: 290: %08x %08x %08x %08x\n", t->id,
  520. t->reg[0], t->reg[1], t->reg[2], t->reg[3]);
  521. NV_DEBUG(dev, " 2a0: %08x\n", t->reg[4]);
  522. return 0;
  523. }
  524. /**
  525. * MR generation methods
  526. */
  527. static int
  528. nouveau_mem_ddr2_mr(struct drm_device *dev, u32 freq,
  529. struct nouveau_pm_tbl_entry *e, u8 len,
  530. struct nouveau_pm_memtiming *boot,
  531. struct nouveau_pm_memtiming *t)
  532. {
  533. t->drive_strength = 0;
  534. if (len < 15) {
  535. t->odt = boot->odt;
  536. } else {
  537. t->odt = e->RAM_FT1 & 0x07;
  538. }
  539. if (e->tCL >= NV_MEM_CL_DDR2_MAX) {
  540. NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL);
  541. return -ERANGE;
  542. }
  543. if (e->tWR >= NV_MEM_WR_DDR2_MAX) {
  544. NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR);
  545. return -ERANGE;
  546. }
  547. if (t->odt > 3) {
  548. NV_WARN(dev, "(%u) Invalid odt value, assuming disabled: %x",
  549. t->id, t->odt);
  550. t->odt = 0;
  551. }
  552. t->mr[0] = (boot->mr[0] & 0x100f) |
  553. (e->tCL) << 4 |
  554. (e->tWR - 1) << 9;
  555. t->mr[1] = (boot->mr[1] & 0x101fbb) |
  556. (t->odt & 0x1) << 2 |
  557. (t->odt & 0x2) << 5;
  558. NV_DEBUG(dev, "(%u) MR: %08x", t->id, t->mr[0]);
  559. return 0;
  560. }
  561. uint8_t nv_mem_wr_lut_ddr3[NV_MEM_WR_DDR3_MAX] = {
  562. 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0};
  563. static int
  564. nouveau_mem_ddr3_mr(struct drm_device *dev, u32 freq,
  565. struct nouveau_pm_tbl_entry *e, u8 len,
  566. struct nouveau_pm_memtiming *boot,
  567. struct nouveau_pm_memtiming *t)
  568. {
  569. u8 cl = e->tCL - 4;
  570. t->drive_strength = 0;
  571. if (len < 15) {
  572. t->odt = boot->odt;
  573. } else {
  574. t->odt = e->RAM_FT1 & 0x07;
  575. }
  576. if (e->tCL >= NV_MEM_CL_DDR3_MAX || e->tCL < 4) {
  577. NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL);
  578. return -ERANGE;
  579. }
  580. if (e->tWR >= NV_MEM_WR_DDR3_MAX || e->tWR < 4) {
  581. NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR);
  582. return -ERANGE;
  583. }
  584. if (e->tCWL < 5) {
  585. NV_WARN(dev, "(%u) Invalid tCWL: %u", t->id, e->tCWL);
  586. return -ERANGE;
  587. }
  588. t->mr[0] = (boot->mr[0] & 0x180b) |
  589. /* CAS */
  590. (cl & 0x7) << 4 |
  591. (cl & 0x8) >> 1 |
  592. (nv_mem_wr_lut_ddr3[e->tWR]) << 9;
  593. t->mr[1] = (boot->mr[1] & 0x101dbb) |
  594. (t->odt & 0x1) << 2 |
  595. (t->odt & 0x2) << 5 |
  596. (t->odt & 0x4) << 7;
  597. t->mr[2] = (boot->mr[2] & 0x20ffb7) | (e->tCWL - 5) << 3;
  598. NV_DEBUG(dev, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[2]);
  599. return 0;
  600. }
  601. uint8_t nv_mem_cl_lut_gddr3[NV_MEM_CL_GDDR3_MAX] = {
  602. 0, 0, 0, 0, 4, 5, 6, 7, 0, 1, 2, 3, 8, 9, 10, 11};
  603. uint8_t nv_mem_wr_lut_gddr3[NV_MEM_WR_GDDR3_MAX] = {
  604. 0, 0, 0, 0, 0, 2, 3, 8, 9, 10, 11, 0, 0, 1, 1, 0, 3};
  605. static int
  606. nouveau_mem_gddr3_mr(struct drm_device *dev, u32 freq,
  607. struct nouveau_pm_tbl_entry *e, u8 len,
  608. struct nouveau_pm_memtiming *boot,
  609. struct nouveau_pm_memtiming *t)
  610. {
  611. u8 rver, rlen, *ramcfg = nouveau_perf_ramcfg(dev, freq, &rver, &rlen);
  612. if (len < 15) {
  613. t->drive_strength = boot->drive_strength;
  614. t->odt = boot->odt;
  615. } else {
  616. t->drive_strength = (e->RAM_FT1 & 0x30) >> 4;
  617. t->odt = e->RAM_FT1 & 0x07;
  618. }
  619. if (e->tCL >= NV_MEM_CL_GDDR3_MAX) {
  620. NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL);
  621. return -ERANGE;
  622. }
  623. if (e->tWR >= NV_MEM_WR_GDDR3_MAX) {
  624. NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR);
  625. return -ERANGE;
  626. }
  627. if (t->odt > 3) {
  628. NV_WARN(dev, "(%u) Invalid odt value, assuming autocal: %x",
  629. t->id, t->odt);
  630. t->odt = 0;
  631. }
  632. t->mr[0] = (boot->mr[0] & 0xe0b) |
  633. /* CAS */
  634. ((nv_mem_cl_lut_gddr3[e->tCL] & 0x7) << 4) |
  635. ((nv_mem_cl_lut_gddr3[e->tCL] & 0x8) >> 2);
  636. t->mr[1] = (boot->mr[1] & 0x100f40) | t->drive_strength |
  637. (t->odt << 2) |
  638. (nv_mem_wr_lut_gddr3[e->tWR] & 0xf) << 4;
  639. if (ramcfg && rver == 0x00) {
  640. /* DLL enable/disable */
  641. t->mr[1] &= ~0x00000040;
  642. if (ramcfg[3] & 0x08)
  643. t->mr[1] |= 0x00000040;
  644. }
  645. t->mr[2] = boot->mr[2];
  646. NV_DEBUG(dev, "(%u) MR: %08x %08x %08x", t->id,
  647. t->mr[0], t->mr[1], t->mr[2]);
  648. return 0;
  649. }
  650. static int
  651. nouveau_mem_gddr5_mr(struct drm_device *dev, u32 freq,
  652. struct nouveau_pm_tbl_entry *e, u8 len,
  653. struct nouveau_pm_memtiming *boot,
  654. struct nouveau_pm_memtiming *t)
  655. {
  656. if (len < 15) {
  657. t->drive_strength = boot->drive_strength;
  658. t->odt = boot->odt;
  659. } else {
  660. t->drive_strength = (e->RAM_FT1 & 0x30) >> 4;
  661. t->odt = e->RAM_FT1 & 0x03;
  662. }
  663. if (e->tCL >= NV_MEM_CL_GDDR5_MAX) {
  664. NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL);
  665. return -ERANGE;
  666. }
  667. if (e->tWR >= NV_MEM_WR_GDDR5_MAX) {
  668. NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR);
  669. return -ERANGE;
  670. }
  671. if (t->odt > 3) {
  672. NV_WARN(dev, "(%u) Invalid odt value, assuming autocal: %x",
  673. t->id, t->odt);
  674. t->odt = 0;
  675. }
  676. t->mr[0] = (boot->mr[0] & 0x007) |
  677. ((e->tCL - 5) << 3) |
  678. ((e->tWR - 4) << 8);
  679. t->mr[1] = (boot->mr[1] & 0x1007f0) |
  680. t->drive_strength |
  681. (t->odt << 2);
  682. NV_DEBUG(dev, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[1]);
  683. return 0;
  684. }
  685. int
  686. nouveau_mem_timing_calc(struct drm_device *dev, u32 freq,
  687. struct nouveau_pm_memtiming *t)
  688. {
  689. struct drm_nouveau_private *dev_priv = dev->dev_private;
  690. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  691. struct nouveau_pm_memtiming *boot = &pm->boot.timing;
  692. struct nouveau_pm_tbl_entry *e;
  693. u8 ver, len, *ptr;
  694. int ret;
  695. ptr = nouveau_perf_timing(dev, freq, &ver, &len);
  696. if (!ptr || ptr[0] == 0x00) {
  697. *t = *boot;
  698. return 0;
  699. }
  700. e = (struct nouveau_pm_tbl_entry *)ptr;
  701. t->tCWL = boot->tCWL;
  702. switch (dev_priv->card_type) {
  703. case NV_40:
  704. ret = nv40_mem_timing_calc(dev, freq, e, len, boot, t);
  705. break;
  706. case NV_50:
  707. ret = nv50_mem_timing_calc(dev, freq, e, len, boot, t);
  708. break;
  709. case NV_C0:
  710. ret = nvc0_mem_timing_calc(dev, freq, e, len, boot, t);
  711. break;
  712. default:
  713. ret = -ENODEV;
  714. break;
  715. }
  716. switch (dev_priv->vram_type * !ret) {
  717. case NV_MEM_TYPE_GDDR3:
  718. ret = nouveau_mem_gddr3_mr(dev, freq, e, len, boot, t);
  719. break;
  720. case NV_MEM_TYPE_GDDR5:
  721. ret = nouveau_mem_gddr5_mr(dev, freq, e, len, boot, t);
  722. break;
  723. case NV_MEM_TYPE_DDR2:
  724. ret = nouveau_mem_ddr2_mr(dev, freq, e, len, boot, t);
  725. break;
  726. case NV_MEM_TYPE_DDR3:
  727. ret = nouveau_mem_ddr3_mr(dev, freq, e, len, boot, t);
  728. break;
  729. default:
  730. ret = -EINVAL;
  731. }
  732. return ret;
  733. }
  734. void
  735. nouveau_mem_timing_read(struct drm_device *dev, struct nouveau_pm_memtiming *t)
  736. {
  737. struct drm_nouveau_private *dev_priv = dev->dev_private;
  738. u32 timing_base, timing_regs, mr_base;
  739. int i;
  740. if (dev_priv->card_type >= 0xC0) {
  741. timing_base = 0x10f290;
  742. mr_base = 0x10f300;
  743. } else {
  744. timing_base = 0x100220;
  745. mr_base = 0x1002c0;
  746. }
  747. t->id = -1;
  748. switch (dev_priv->card_type) {
  749. case NV_50:
  750. timing_regs = 9;
  751. break;
  752. case NV_C0:
  753. case NV_D0:
  754. timing_regs = 5;
  755. break;
  756. case NV_30:
  757. case NV_40:
  758. timing_regs = 3;
  759. break;
  760. default:
  761. timing_regs = 0;
  762. return;
  763. }
  764. for(i = 0; i < timing_regs; i++)
  765. t->reg[i] = nv_rd32(dev, timing_base + (0x04 * i));
  766. t->tCWL = 0;
  767. if (dev_priv->card_type < NV_C0) {
  768. t->tCWL = ((nv_rd32(dev, 0x100228) & 0x0f000000) >> 24) + 1;
  769. }
  770. t->mr[0] = nv_rd32(dev, mr_base);
  771. t->mr[1] = nv_rd32(dev, mr_base + 0x04);
  772. t->mr[2] = nv_rd32(dev, mr_base + 0x20);
  773. t->mr[3] = nv_rd32(dev, mr_base + 0x24);
  774. t->odt = 0;
  775. t->drive_strength = 0;
  776. switch (dev_priv->vram_type) {
  777. case NV_MEM_TYPE_DDR3:
  778. t->odt |= (t->mr[1] & 0x200) >> 7;
  779. case NV_MEM_TYPE_DDR2:
  780. t->odt |= (t->mr[1] & 0x04) >> 2 |
  781. (t->mr[1] & 0x40) >> 5;
  782. break;
  783. case NV_MEM_TYPE_GDDR3:
  784. case NV_MEM_TYPE_GDDR5:
  785. t->drive_strength = t->mr[1] & 0x03;
  786. t->odt = (t->mr[1] & 0x0c) >> 2;
  787. break;
  788. default:
  789. break;
  790. }
  791. }
  792. int
  793. nouveau_mem_exec(struct nouveau_mem_exec_func *exec,
  794. struct nouveau_pm_level *perflvl)
  795. {
  796. struct drm_nouveau_private *dev_priv = exec->dev->dev_private;
  797. struct nouveau_pm_memtiming *info = &perflvl->timing;
  798. u32 tMRD = 1000, tCKSRE = 0, tCKSRX = 0, tXS = 0, tDLLK = 0;
  799. u32 mr[3] = { info->mr[0], info->mr[1], info->mr[2] };
  800. u32 mr1_dlloff;
  801. switch (dev_priv->vram_type) {
  802. case NV_MEM_TYPE_DDR2:
  803. tDLLK = 2000;
  804. mr1_dlloff = 0x00000001;
  805. break;
  806. case NV_MEM_TYPE_DDR3:
  807. tDLLK = 12000;
  808. mr1_dlloff = 0x00000001;
  809. break;
  810. case NV_MEM_TYPE_GDDR3:
  811. tDLLK = 40000;
  812. mr1_dlloff = 0x00000040;
  813. break;
  814. default:
  815. NV_ERROR(exec->dev, "cannot reclock unsupported memtype\n");
  816. return -ENODEV;
  817. }
  818. /* fetch current MRs */
  819. switch (dev_priv->vram_type) {
  820. case NV_MEM_TYPE_GDDR3:
  821. case NV_MEM_TYPE_DDR3:
  822. mr[2] = exec->mrg(exec, 2);
  823. default:
  824. mr[1] = exec->mrg(exec, 1);
  825. mr[0] = exec->mrg(exec, 0);
  826. break;
  827. }
  828. /* DLL 'on' -> DLL 'off' mode, disable before entering self-refresh */
  829. if (!(mr[1] & mr1_dlloff) && (info->mr[1] & mr1_dlloff)) {
  830. exec->precharge(exec);
  831. exec->mrs (exec, 1, mr[1] | mr1_dlloff);
  832. exec->wait(exec, tMRD);
  833. }
  834. /* enter self-refresh mode */
  835. exec->precharge(exec);
  836. exec->refresh(exec);
  837. exec->refresh(exec);
  838. exec->refresh_auto(exec, false);
  839. exec->refresh_self(exec, true);
  840. exec->wait(exec, tCKSRE);
  841. /* modify input clock frequency */
  842. exec->clock_set(exec);
  843. /* exit self-refresh mode */
  844. exec->wait(exec, tCKSRX);
  845. exec->precharge(exec);
  846. exec->refresh_self(exec, false);
  847. exec->refresh_auto(exec, true);
  848. exec->wait(exec, tXS);
  849. /* update MRs */
  850. if (mr[2] != info->mr[2]) {
  851. exec->mrs (exec, 2, info->mr[2]);
  852. exec->wait(exec, tMRD);
  853. }
  854. if (mr[1] != info->mr[1]) {
  855. exec->mrs (exec, 1, info->mr[1]);
  856. exec->wait(exec, tMRD);
  857. }
  858. if (mr[0] != info->mr[0]) {
  859. exec->mrs (exec, 0, info->mr[0]);
  860. exec->wait(exec, tMRD);
  861. }
  862. /* update PFB timing registers */
  863. exec->timing_set(exec);
  864. /* DLL reset */
  865. if (!(info->mr[1] & mr1_dlloff)) {
  866. exec->mrs (exec, 0, info->mr[0] | 0x00000100);
  867. exec->wait(exec, tMRD);
  868. exec->mrs (exec, 0, info->mr[0] | 0x00000000);
  869. exec->wait(exec, tMRD);
  870. exec->wait(exec, tDLLK);
  871. if (dev_priv->vram_type == NV_MEM_TYPE_GDDR3)
  872. exec->precharge(exec);
  873. }
  874. return 0;
  875. }
  876. int
  877. nouveau_mem_vbios_type(struct drm_device *dev)
  878. {
  879. struct bit_entry M;
  880. u8 ramcfg = (nv_rd32(dev, 0x101000) & 0x0000003c) >> 2;
  881. if (!bit_table(dev, 'M', &M) || M.version != 2 || M.length < 5) {
  882. u8 *table = ROMPTR(dev, M.data[3]);
  883. if (table && table[0] == 0x10 && ramcfg < table[3]) {
  884. u8 *entry = table + table[1] + (ramcfg * table[2]);
  885. switch (entry[0] & 0x0f) {
  886. case 0: return NV_MEM_TYPE_DDR2;
  887. case 1: return NV_MEM_TYPE_DDR3;
  888. case 2: return NV_MEM_TYPE_GDDR3;
  889. case 3: return NV_MEM_TYPE_GDDR5;
  890. default:
  891. break;
  892. }
  893. }
  894. }
  895. return NV_MEM_TYPE_UNKNOWN;
  896. }
  897. static int
  898. nouveau_vram_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
  899. {
  900. /* nothing to do */
  901. return 0;
  902. }
  903. static int
  904. nouveau_vram_manager_fini(struct ttm_mem_type_manager *man)
  905. {
  906. /* nothing to do */
  907. return 0;
  908. }
  909. static inline void
  910. nouveau_mem_node_cleanup(struct nouveau_mem *node)
  911. {
  912. if (node->vma[0].node) {
  913. nouveau_vm_unmap(&node->vma[0]);
  914. nouveau_vm_put(&node->vma[0]);
  915. }
  916. if (node->vma[1].node) {
  917. nouveau_vm_unmap(&node->vma[1]);
  918. nouveau_vm_put(&node->vma[1]);
  919. }
  920. }
  921. static void
  922. nouveau_vram_manager_del(struct ttm_mem_type_manager *man,
  923. struct ttm_mem_reg *mem)
  924. {
  925. struct drm_nouveau_private *dev_priv = nouveau_bdev(man->bdev);
  926. struct nouveau_vram_engine *vram = &dev_priv->engine.vram;
  927. struct drm_device *dev = dev_priv->dev;
  928. nouveau_mem_node_cleanup(mem->mm_node);
  929. vram->put(dev, (struct nouveau_mem **)&mem->mm_node);
  930. }
  931. static int
  932. nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
  933. struct ttm_buffer_object *bo,
  934. struct ttm_placement *placement,
  935. struct ttm_mem_reg *mem)
  936. {
  937. struct drm_nouveau_private *dev_priv = nouveau_bdev(man->bdev);
  938. struct nouveau_vram_engine *vram = &dev_priv->engine.vram;
  939. struct drm_device *dev = dev_priv->dev;
  940. struct nouveau_bo *nvbo = nouveau_bo(bo);
  941. struct nouveau_mem *node;
  942. u32 size_nc = 0;
  943. int ret;
  944. if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG)
  945. size_nc = 1 << nvbo->page_shift;
  946. ret = vram->get(dev, mem->num_pages << PAGE_SHIFT,
  947. mem->page_alignment << PAGE_SHIFT, size_nc,
  948. (nvbo->tile_flags >> 8) & 0x3ff, &node);
  949. if (ret) {
  950. mem->mm_node = NULL;
  951. return (ret == -ENOSPC) ? 0 : ret;
  952. }
  953. node->page_shift = nvbo->page_shift;
  954. mem->mm_node = node;
  955. mem->start = node->offset >> PAGE_SHIFT;
  956. return 0;
  957. }
  958. void
  959. nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
  960. {
  961. struct nouveau_mm *mm = man->priv;
  962. struct nouveau_mm_node *r;
  963. u32 total = 0, free = 0;
  964. mutex_lock(&mm->mutex);
  965. list_for_each_entry(r, &mm->nodes, nl_entry) {
  966. printk(KERN_DEBUG "%s %d: 0x%010llx 0x%010llx\n",
  967. prefix, r->type, ((u64)r->offset << 12),
  968. (((u64)r->offset + r->length) << 12));
  969. total += r->length;
  970. if (!r->type)
  971. free += r->length;
  972. }
  973. mutex_unlock(&mm->mutex);
  974. printk(KERN_DEBUG "%s total: 0x%010llx free: 0x%010llx\n",
  975. prefix, (u64)total << 12, (u64)free << 12);
  976. printk(KERN_DEBUG "%s block: 0x%08x\n",
  977. prefix, mm->block_size << 12);
  978. }
  979. const struct ttm_mem_type_manager_func nouveau_vram_manager = {
  980. nouveau_vram_manager_init,
  981. nouveau_vram_manager_fini,
  982. nouveau_vram_manager_new,
  983. nouveau_vram_manager_del,
  984. nouveau_vram_manager_debug
  985. };
  986. static int
  987. nouveau_gart_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
  988. {
  989. return 0;
  990. }
  991. static int
  992. nouveau_gart_manager_fini(struct ttm_mem_type_manager *man)
  993. {
  994. return 0;
  995. }
  996. static void
  997. nouveau_gart_manager_del(struct ttm_mem_type_manager *man,
  998. struct ttm_mem_reg *mem)
  999. {
  1000. nouveau_mem_node_cleanup(mem->mm_node);
  1001. kfree(mem->mm_node);
  1002. mem->mm_node = NULL;
  1003. }
  1004. static int
  1005. nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
  1006. struct ttm_buffer_object *bo,
  1007. struct ttm_placement *placement,
  1008. struct ttm_mem_reg *mem)
  1009. {
  1010. struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev);
  1011. struct nouveau_mem *node;
  1012. if (unlikely((mem->num_pages << PAGE_SHIFT) >=
  1013. dev_priv->gart_info.aper_size))
  1014. return -ENOMEM;
  1015. node = kzalloc(sizeof(*node), GFP_KERNEL);
  1016. if (!node)
  1017. return -ENOMEM;
  1018. node->page_shift = 12;
  1019. mem->mm_node = node;
  1020. mem->start = 0;
  1021. return 0;
  1022. }
  1023. void
  1024. nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
  1025. {
  1026. }
  1027. const struct ttm_mem_type_manager_func nouveau_gart_manager = {
  1028. nouveau_gart_manager_init,
  1029. nouveau_gart_manager_fini,
  1030. nouveau_gart_manager_new,
  1031. nouveau_gart_manager_del,
  1032. nouveau_gart_manager_debug
  1033. };