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_ramht_ref(NULL, &evo->ramht, evo);
  37. nouveau_gpuobj_channel_takedown(evo);
  38. nouveau_bo_unmap(evo->pushbuf_bo);
  39. nouveau_bo_ref(NULL, &evo->pushbuf_bo);
  40. if (evo->user)
  41. iounmap(evo->user);
  42. kfree(evo);
  43. }
  44. void
  45. nv50_evo_dmaobj_init(struct nouveau_gpuobj *obj, u32 memtype, u64 base, u64 size)
  46. {
  47. struct drm_nouveau_private *dev_priv = obj->dev->dev_private;
  48. u32 flags5;
  49. if (dev_priv->chipset < 0xc0) {
  50. /* not supported on 0x50, specified in format mthd */
  51. if (dev_priv->chipset == 0x50)
  52. memtype = 0;
  53. flags5 = 0x00010000;
  54. } else {
  55. if (memtype & 0x80000000)
  56. flags5 = 0x00000000; /* large pages */
  57. else
  58. flags5 = 0x00020000;
  59. }
  60. nv50_gpuobj_dma_init(obj, 0, 0x3d, base, size, NV_MEM_TARGET_VRAM,
  61. NV_MEM_ACCESS_RW, (memtype >> 8) & 0xff, 0);
  62. nv_wo32(obj, 0x14, flags5);
  63. dev_priv->engine.instmem.flush(obj->dev);
  64. }
  65. int
  66. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 handle, u32 memtype,
  67. u64 base, u64 size, struct nouveau_gpuobj **pobj)
  68. {
  69. struct nv50_display *disp = nv50_display(evo->dev);
  70. struct nouveau_gpuobj *obj = NULL;
  71. int ret;
  72. ret = nouveau_gpuobj_new(evo->dev, disp->master, 6*4, 32, 0, &obj);
  73. if (ret)
  74. return ret;
  75. obj->engine = NVOBJ_ENGINE_DISPLAY;
  76. nv50_evo_dmaobj_init(obj, memtype, base, size);
  77. ret = nouveau_ramht_insert(evo, handle, obj);
  78. if (ret)
  79. goto out;
  80. if (pobj)
  81. nouveau_gpuobj_ref(obj, pobj);
  82. out:
  83. nouveau_gpuobj_ref(NULL, &obj);
  84. return ret;
  85. }
  86. static int
  87. nv50_evo_channel_new(struct drm_device *dev, int chid,
  88. struct nouveau_channel **pevo)
  89. {
  90. struct nv50_display *disp = nv50_display(dev);
  91. struct nouveau_channel *evo;
  92. int ret;
  93. evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  94. if (!evo)
  95. return -ENOMEM;
  96. *pevo = evo;
  97. evo->id = chid;
  98. evo->dev = dev;
  99. evo->user_get = 4;
  100. evo->user_put = 0;
  101. ret = nouveau_bo_new(dev, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
  102. &evo->pushbuf_bo);
  103. if (ret == 0)
  104. ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
  105. if (ret) {
  106. NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
  107. nv50_evo_channel_del(pevo);
  108. return ret;
  109. }
  110. ret = nouveau_bo_map(evo->pushbuf_bo);
  111. if (ret) {
  112. NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
  113. nv50_evo_channel_del(pevo);
  114. return ret;
  115. }
  116. evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
  117. NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
  118. if (!evo->user) {
  119. NV_ERROR(dev, "Error mapping EVO control regs.\n");
  120. nv50_evo_channel_del(pevo);
  121. return -ENOMEM;
  122. }
  123. /* bind primary evo channel's ramht to the channel */
  124. if (disp->master && evo != disp->master)
  125. nouveau_ramht_ref(disp->master->ramht, &evo->ramht, NULL);
  126. return 0;
  127. }
  128. static int
  129. nv50_evo_channel_init(struct nouveau_channel *evo)
  130. {
  131. struct drm_device *dev = evo->dev;
  132. int id = evo->id, ret, i;
  133. u64 pushbuf = evo->pushbuf_bo->bo.offset;
  134. u32 tmp;
  135. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  136. if ((tmp & 0x009f0000) == 0x00020000)
  137. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
  138. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  139. if ((tmp & 0x003f0000) == 0x00030000)
  140. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
  141. /* initialise fifo */
  142. nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
  143. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  144. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  145. nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
  146. nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
  147. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
  148. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  149. nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
  150. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
  151. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  152. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
  153. NV_ERROR(dev, "EvoCh %d init timeout: 0x%08x\n", id,
  154. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  155. return -EBUSY;
  156. }
  157. /* enable error reporting on the channel */
  158. nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
  159. evo->dma.max = (4096/4) - 2;
  160. evo->dma.max &= ~7;
  161. evo->dma.put = 0;
  162. evo->dma.cur = evo->dma.put;
  163. evo->dma.free = evo->dma.max - evo->dma.cur;
  164. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  165. if (ret)
  166. return ret;
  167. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  168. OUT_RING(evo, 0);
  169. return 0;
  170. }
  171. static void
  172. nv50_evo_channel_fini(struct nouveau_channel *evo)
  173. {
  174. struct drm_device *dev = evo->dev;
  175. int id = evo->id;
  176. nv_mask(dev, 0x610028, 0x00010001 << id, 0x00000000);
  177. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
  178. nv_wr32(dev, NV50_PDISPLAY_INTR_0, (1 << id));
  179. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
  180. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
  181. NV_ERROR(dev, "EvoCh %d takedown timeout: 0x%08x\n", id,
  182. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  183. }
  184. }
  185. static void
  186. nv50_evo_destroy(struct drm_device *dev)
  187. {
  188. struct nv50_display *disp = nv50_display(dev);
  189. int i;
  190. for (i = 0; i < 2; i++) {
  191. if (disp->crtc[i].sem.bo) {
  192. nouveau_bo_unmap(disp->crtc[i].sem.bo);
  193. nouveau_bo_ref(NULL, &disp->crtc[i].sem.bo);
  194. }
  195. nv50_evo_channel_del(&disp->crtc[i].sync);
  196. }
  197. nouveau_gpuobj_ref(NULL, &disp->ntfy);
  198. nv50_evo_channel_del(&disp->master);
  199. }
  200. static int
  201. nv50_evo_create(struct drm_device *dev)
  202. {
  203. struct drm_nouveau_private *dev_priv = dev->dev_private;
  204. struct nv50_display *disp = nv50_display(dev);
  205. struct nouveau_gpuobj *ramht = NULL;
  206. struct nouveau_channel *evo;
  207. int ret, i, j;
  208. /* create primary evo channel, the one we use for modesetting
  209. * purporses
  210. */
  211. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  212. if (ret)
  213. return ret;
  214. evo = disp->master;
  215. /* setup object management on it, any other evo channel will
  216. * use this also as there's no per-channel support on the
  217. * hardware
  218. */
  219. ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
  220. NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
  221. if (ret) {
  222. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  223. goto err;
  224. }
  225. ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
  226. if (ret) {
  227. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  228. goto err;
  229. }
  230. ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
  231. if (ret) {
  232. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  233. goto err;
  234. }
  235. ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
  236. nouveau_gpuobj_ref(NULL, &ramht);
  237. if (ret)
  238. goto err;
  239. /* not sure exactly what this is..
  240. *
  241. * the first dword of the structure is used by nvidia to wait on
  242. * full completion of an EVO "update" command.
  243. *
  244. * method 0x8c on the master evo channel will fill a lot more of
  245. * this structure with some undefined info
  246. */
  247. ret = nouveau_gpuobj_new(dev, disp->master, 0x1000, 0,
  248. NVOBJ_FLAG_ZERO_ALLOC, &disp->ntfy);
  249. if (ret)
  250. goto err;
  251. ret = nv50_evo_dmaobj_new(disp->master, NvEvoSync, 0x0000,
  252. disp->ntfy->vinst, disp->ntfy->size, NULL);
  253. if (ret)
  254. goto err;
  255. /* create some default objects for the scanout memtypes we support */
  256. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM, 0x0000,
  257. 0, dev_priv->vram_size, NULL);
  258. if (ret)
  259. goto err;
  260. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM_LP, 0x80000000,
  261. 0, dev_priv->vram_size, NULL);
  262. if (ret)
  263. goto err;
  264. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB32, 0x80000000 |
  265. (dev_priv->chipset < 0xc0 ? 0x7a00 : 0xfe00),
  266. 0, dev_priv->vram_size, NULL);
  267. if (ret)
  268. goto err;
  269. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB16, 0x80000000 |
  270. (dev_priv->chipset < 0xc0 ? 0x7000 : 0xfe00),
  271. 0, dev_priv->vram_size, NULL);
  272. if (ret)
  273. goto err;
  274. /* create "display sync" channels and other structures we need
  275. * to implement page flipping
  276. */
  277. for (i = 0; i < 2; i++) {
  278. struct nv50_display_crtc *dispc = &disp->crtc[i];
  279. u64 offset;
  280. ret = nv50_evo_channel_new(dev, 1 + i, &dispc->sync);
  281. if (ret)
  282. goto err;
  283. ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  284. 0, 0x0000, &dispc->sem.bo);
  285. if (!ret) {
  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. offset = dispc->sem.bo->bo.offset;
  292. }
  293. if (ret)
  294. goto err;
  295. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoSync, 0x0000,
  296. offset, 4096, NULL);
  297. if (ret)
  298. goto err;
  299. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoVRAM_LP, 0x80000000,
  300. 0, dev_priv->vram_size, NULL);
  301. if (ret)
  302. goto err;
  303. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB32, 0x80000000 |
  304. (dev_priv->chipset < 0xc0 ?
  305. 0x7a00 : 0xfe00),
  306. 0, dev_priv->vram_size, NULL);
  307. if (ret)
  308. goto err;
  309. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB16, 0x80000000 |
  310. (dev_priv->chipset < 0xc0 ?
  311. 0x7000 : 0xfe00),
  312. 0, dev_priv->vram_size, NULL);
  313. if (ret)
  314. goto err;
  315. for (j = 0; j < 4096; j += 4)
  316. nouveau_bo_wr32(dispc->sem.bo, j / 4, 0x74b1e000);
  317. dispc->sem.offset = 0;
  318. }
  319. return 0;
  320. err:
  321. nv50_evo_destroy(dev);
  322. return ret;
  323. }
  324. int
  325. nv50_evo_init(struct drm_device *dev)
  326. {
  327. struct nv50_display *disp = nv50_display(dev);
  328. int ret, i;
  329. if (!disp->master) {
  330. ret = nv50_evo_create(dev);
  331. if (ret)
  332. return ret;
  333. }
  334. ret = nv50_evo_channel_init(disp->master);
  335. if (ret)
  336. return ret;
  337. for (i = 0; i < 2; i++) {
  338. ret = nv50_evo_channel_init(disp->crtc[i].sync);
  339. if (ret)
  340. return ret;
  341. }
  342. return 0;
  343. }
  344. void
  345. nv50_evo_fini(struct drm_device *dev)
  346. {
  347. struct nv50_display *disp = nv50_display(dev);
  348. int i;
  349. for (i = 0; i < 2; i++) {
  350. if (disp->crtc[i].sync)
  351. nv50_evo_channel_fini(disp->crtc[i].sync);
  352. }
  353. if (disp->master)
  354. nv50_evo_channel_fini(disp->master);
  355. nv50_evo_destroy(dev);
  356. }