nv50_evo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * Copyright 2010 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_dma.h"
  27. #include "nouveau_ramht.h"
  28. #include "nv50_display.h"
  29. static void
  30. nv50_evo_channel_del(struct nouveau_channel **pevo)
  31. {
  32. struct nouveau_channel *evo = *pevo;
  33. if (!evo)
  34. return;
  35. *pevo = NULL;
  36. nouveau_gpuobj_channel_takedown(evo);
  37. nouveau_bo_unmap(evo->pushbuf_bo);
  38. nouveau_bo_ref(NULL, &evo->pushbuf_bo);
  39. if (evo->user)
  40. iounmap(evo->user);
  41. kfree(evo);
  42. }
  43. void
  44. nv50_evo_dmaobj_init(struct nouveau_gpuobj *obj, u32 memtype, u64 base, u64 size)
  45. {
  46. struct drm_nouveau_private *dev_priv = obj->dev->dev_private;
  47. u32 flags5;
  48. if (dev_priv->chipset < 0xc0) {
  49. /* not supported on 0x50, specified in format mthd */
  50. if (dev_priv->chipset == 0x50)
  51. memtype = 0;
  52. flags5 = 0x00010000;
  53. } else {
  54. if (memtype & 0x80000000)
  55. flags5 = 0x00000000; /* large pages */
  56. else
  57. flags5 = 0x00020000;
  58. }
  59. nv50_gpuobj_dma_init(obj, 0, 0x3d, base, size, NV_MEM_TARGET_VRAM,
  60. NV_MEM_ACCESS_RW, (memtype >> 8) & 0xff, 0);
  61. nv_wo32(obj, 0x14, flags5);
  62. dev_priv->engine.instmem.flush(obj->dev);
  63. }
  64. int
  65. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 handle, u32 memtype,
  66. u64 base, u64 size, struct nouveau_gpuobj **pobj)
  67. {
  68. struct nv50_display *disp = nv50_display(evo->dev);
  69. struct nouveau_gpuobj *obj = NULL;
  70. int ret;
  71. ret = nouveau_gpuobj_new(evo->dev, disp->master, 6*4, 32, 0, &obj);
  72. if (ret)
  73. return ret;
  74. obj->engine = NVOBJ_ENGINE_DISPLAY;
  75. nv50_evo_dmaobj_init(obj, memtype, base, size);
  76. ret = nouveau_ramht_insert(evo, handle, obj);
  77. if (ret)
  78. goto out;
  79. if (pobj)
  80. nouveau_gpuobj_ref(obj, pobj);
  81. out:
  82. nouveau_gpuobj_ref(NULL, &obj);
  83. return ret;
  84. }
  85. static int
  86. nv50_evo_channel_new(struct drm_device *dev, int chid,
  87. struct nouveau_channel **pevo)
  88. {
  89. struct nv50_display *disp = nv50_display(dev);
  90. struct nouveau_channel *evo;
  91. int ret;
  92. evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  93. if (!evo)
  94. return -ENOMEM;
  95. *pevo = evo;
  96. evo->id = chid;
  97. evo->dev = dev;
  98. evo->user_get = 4;
  99. evo->user_put = 0;
  100. ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
  101. &evo->pushbuf_bo);
  102. if (ret == 0)
  103. ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
  104. if (ret) {
  105. NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
  106. nv50_evo_channel_del(pevo);
  107. return ret;
  108. }
  109. ret = nouveau_bo_map(evo->pushbuf_bo);
  110. if (ret) {
  111. NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
  112. nv50_evo_channel_del(pevo);
  113. return ret;
  114. }
  115. evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
  116. NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
  117. if (!evo->user) {
  118. NV_ERROR(dev, "Error mapping EVO control regs.\n");
  119. nv50_evo_channel_del(pevo);
  120. return -ENOMEM;
  121. }
  122. /* bind primary evo channel's ramht to the channel */
  123. if (disp->master && evo != disp->master)
  124. nouveau_ramht_ref(disp->master->ramht, &evo->ramht, NULL);
  125. return 0;
  126. }
  127. static int
  128. nv50_evo_channel_init(struct nouveau_channel *evo)
  129. {
  130. struct drm_device *dev = evo->dev;
  131. int id = evo->id, ret, i;
  132. u64 pushbuf = evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT;
  133. u32 tmp;
  134. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  135. if ((tmp & 0x009f0000) == 0x00020000)
  136. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
  137. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  138. if ((tmp & 0x003f0000) == 0x00030000)
  139. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
  140. /* initialise fifo */
  141. nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
  142. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  143. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  144. nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
  145. nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
  146. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
  147. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  148. nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
  149. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
  150. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  151. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
  152. NV_ERROR(dev, "EvoCh %d init timeout: 0x%08x\n", id,
  153. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  154. return -EBUSY;
  155. }
  156. /* enable error reporting on the channel */
  157. nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
  158. evo->dma.max = (4096/4) - 2;
  159. evo->dma.max &= ~7;
  160. evo->dma.put = 0;
  161. evo->dma.cur = evo->dma.put;
  162. evo->dma.free = evo->dma.max - evo->dma.cur;
  163. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  164. if (ret)
  165. return ret;
  166. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  167. OUT_RING(evo, 0);
  168. return 0;
  169. }
  170. static void
  171. nv50_evo_channel_fini(struct nouveau_channel *evo)
  172. {
  173. struct drm_device *dev = evo->dev;
  174. int id = evo->id;
  175. nv_mask(dev, 0x610028, 0x00010001 << id, 0x00000000);
  176. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
  177. nv_wr32(dev, NV50_PDISPLAY_INTR_0, (1 << id));
  178. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
  179. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
  180. NV_ERROR(dev, "EvoCh %d takedown timeout: 0x%08x\n", id,
  181. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  182. }
  183. }
  184. static void
  185. nv50_evo_destroy(struct drm_device *dev)
  186. {
  187. struct nv50_display *disp = nv50_display(dev);
  188. int i;
  189. for (i = 0; i < 2; i++) {
  190. if (disp->crtc[i].sem.bo) {
  191. nouveau_bo_unmap(disp->crtc[i].sem.bo);
  192. nouveau_bo_ref(NULL, &disp->crtc[i].sem.bo);
  193. }
  194. nv50_evo_channel_del(&disp->crtc[i].sync);
  195. }
  196. nouveau_gpuobj_ref(NULL, &disp->ntfy);
  197. nv50_evo_channel_del(&disp->master);
  198. }
  199. static int
  200. nv50_evo_create(struct drm_device *dev)
  201. {
  202. struct drm_nouveau_private *dev_priv = dev->dev_private;
  203. struct nv50_display *disp = nv50_display(dev);
  204. struct nouveau_gpuobj *ramht = NULL;
  205. struct nouveau_channel *evo;
  206. int ret, i, j;
  207. /* create primary evo channel, the one we use for modesetting
  208. * purporses
  209. */
  210. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  211. if (ret)
  212. return ret;
  213. evo = disp->master;
  214. /* setup object management on it, any other evo channel will
  215. * use this also as there's no per-channel support on the
  216. * hardware
  217. */
  218. ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
  219. NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
  220. if (ret) {
  221. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  222. goto err;
  223. }
  224. ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
  225. if (ret) {
  226. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  227. goto err;
  228. }
  229. ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
  230. if (ret) {
  231. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  232. goto err;
  233. }
  234. ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
  235. nouveau_gpuobj_ref(NULL, &ramht);
  236. if (ret)
  237. goto err;
  238. /* not sure exactly what this is..
  239. *
  240. * the first dword of the structure is used by nvidia to wait on
  241. * full completion of an EVO "update" command.
  242. *
  243. * method 0x8c on the master evo channel will fill a lot more of
  244. * this structure with some undefined info
  245. */
  246. ret = nouveau_gpuobj_new(dev, disp->master, 0x1000, 0,
  247. NVOBJ_FLAG_ZERO_ALLOC, &disp->ntfy);
  248. if (ret)
  249. goto err;
  250. ret = nv50_evo_dmaobj_new(disp->master, NvEvoSync, 0x0000,
  251. disp->ntfy->vinst, disp->ntfy->size, NULL);
  252. if (ret)
  253. goto err;
  254. /* create some default objects for the scanout memtypes we support */
  255. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM, 0x0000,
  256. 0, dev_priv->vram_size, NULL);
  257. if (ret)
  258. goto err;
  259. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM_LP, 0x80000000,
  260. 0, dev_priv->vram_size, NULL);
  261. if (ret)
  262. goto err;
  263. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB32, 0x80000000 |
  264. (dev_priv->chipset < 0xc0 ? 0x7a00 : 0xfe00),
  265. 0, dev_priv->vram_size, NULL);
  266. if (ret)
  267. goto err;
  268. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB16, 0x80000000 |
  269. (dev_priv->chipset < 0xc0 ? 0x7000 : 0xfe00),
  270. 0, dev_priv->vram_size, NULL);
  271. if (ret)
  272. goto err;
  273. /* create "display sync" channels and other structures we need
  274. * to implement page flipping
  275. */
  276. for (i = 0; i < 2; i++) {
  277. struct nv50_display_crtc *dispc = &disp->crtc[i];
  278. u64 offset;
  279. ret = nv50_evo_channel_new(dev, 1 + i, &dispc->sync);
  280. if (ret)
  281. goto err;
  282. ret = nouveau_bo_new(dev, NULL, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  283. 0, 0x0000, &dispc->sem.bo);
  284. if (!ret) {
  285. offset = dispc->sem.bo->bo.mem.start << PAGE_SHIFT;
  286. ret = nouveau_bo_pin(dispc->sem.bo, TTM_PL_FLAG_VRAM);
  287. if (!ret)
  288. ret = nouveau_bo_map(dispc->sem.bo);
  289. if (ret)
  290. nouveau_bo_ref(NULL, &dispc->sem.bo);
  291. }
  292. if (ret)
  293. goto err;
  294. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoSync, 0x0000,
  295. offset, 4096, NULL);
  296. if (ret)
  297. goto err;
  298. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoVRAM_LP, 0x80000000,
  299. 0, dev_priv->vram_size, NULL);
  300. if (ret)
  301. goto err;
  302. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB32, 0x80000000 |
  303. (dev_priv->chipset < 0xc0 ?
  304. 0x7a00 : 0xfe00),
  305. 0, dev_priv->vram_size, NULL);
  306. if (ret)
  307. goto err;
  308. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB16, 0x80000000 |
  309. (dev_priv->chipset < 0xc0 ?
  310. 0x7000 : 0xfe00),
  311. 0, dev_priv->vram_size, NULL);
  312. if (ret)
  313. goto err;
  314. for (j = 0; j < 4096; j += 4)
  315. nouveau_bo_wr32(dispc->sem.bo, j / 4, 0x74b1e000);
  316. dispc->sem.offset = 0;
  317. }
  318. return 0;
  319. err:
  320. nv50_evo_destroy(dev);
  321. return ret;
  322. }
  323. int
  324. nv50_evo_init(struct drm_device *dev)
  325. {
  326. struct nv50_display *disp = nv50_display(dev);
  327. int ret, i;
  328. if (!disp->master) {
  329. ret = nv50_evo_create(dev);
  330. if (ret)
  331. return ret;
  332. }
  333. ret = nv50_evo_channel_init(disp->master);
  334. if (ret)
  335. return ret;
  336. for (i = 0; i < 2; i++) {
  337. ret = nv50_evo_channel_init(disp->crtc[i].sync);
  338. if (ret)
  339. return ret;
  340. }
  341. return 0;
  342. }
  343. void
  344. nv50_evo_fini(struct drm_device *dev)
  345. {
  346. struct nv50_display *disp = nv50_display(dev);
  347. int i;
  348. for (i = 0; i < 2; i++) {
  349. if (disp->crtc[i].sync)
  350. nv50_evo_channel_fini(disp->crtc[i].sync);
  351. }
  352. if (disp->master)
  353. nv50_evo_channel_fini(disp->master);
  354. nv50_evo_destroy(dev);
  355. }