nv50_evo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 <drm/drmP.h>
  25. #include "nouveau_drm.h"
  26. #include "nouveau_dma.h"
  27. #include "nv50_display.h"
  28. #include <core/gpuobj.h>
  29. #include <subdev/timer.h>
  30. #include <subdev/fb.h>
  31. static u32
  32. nv50_evo_rd32(struct nouveau_object *object, u64 addr)
  33. {
  34. void __iomem *iomem = object->oclass->ofuncs->rd08;
  35. return ioread32_native(iomem + addr);
  36. }
  37. static void
  38. nv50_evo_wr32(struct nouveau_object *object, u64 addr, u32 data)
  39. {
  40. void __iomem *iomem = object->oclass->ofuncs->rd08;
  41. iowrite32_native(data, iomem + addr);
  42. }
  43. static void
  44. nv50_evo_channel_del(struct nouveau_channel **pevo)
  45. {
  46. struct nouveau_channel *evo = *pevo;
  47. if (!evo)
  48. return;
  49. *pevo = NULL;
  50. nouveau_bo_unmap(evo->push.buffer);
  51. nouveau_bo_ref(NULL, &evo->push.buffer);
  52. if (evo->object)
  53. iounmap(evo->object->oclass->ofuncs);
  54. kfree(evo);
  55. }
  56. int
  57. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 handle, u32 memtype,
  58. u64 base, u64 size, struct nouveau_gpuobj **pobj)
  59. {
  60. struct drm_device *dev = evo->fence;
  61. struct nouveau_drm *drm = nouveau_drm(dev);
  62. struct nv50_display *disp = nv50_display(dev);
  63. u32 dmao = disp->dmao;
  64. u32 hash = disp->hash;
  65. u32 flags5;
  66. if (nv_device(drm->device)->chipset < 0xc0) {
  67. /* not supported on 0x50, specified in format mthd */
  68. if (nv_device(drm->device)->chipset == 0x50)
  69. memtype = 0;
  70. flags5 = 0x00010000;
  71. } else {
  72. if (memtype & 0x80000000)
  73. flags5 = 0x00000000; /* large pages */
  74. else
  75. flags5 = 0x00020000;
  76. }
  77. nv_wo32(disp->ramin, dmao + 0x00, 0x0019003d | (memtype << 22));
  78. nv_wo32(disp->ramin, dmao + 0x04, lower_32_bits(base + size - 1));
  79. nv_wo32(disp->ramin, dmao + 0x08, lower_32_bits(base));
  80. nv_wo32(disp->ramin, dmao + 0x0c, upper_32_bits(base + size - 1) << 24 |
  81. upper_32_bits(base));
  82. nv_wo32(disp->ramin, dmao + 0x10, 0x00000000);
  83. nv_wo32(disp->ramin, dmao + 0x14, flags5);
  84. nv_wo32(disp->ramin, hash + 0x00, handle);
  85. nv_wo32(disp->ramin, hash + 0x04, (evo->handle << 28) | (dmao << 10) |
  86. evo->handle);
  87. disp->dmao += 0x20;
  88. disp->hash += 0x08;
  89. return 0;
  90. }
  91. static int
  92. nv50_evo_channel_new(struct drm_device *dev, int chid,
  93. struct nouveau_channel **pevo)
  94. {
  95. struct nouveau_drm *drm = nouveau_drm(dev);
  96. struct nv50_display *disp = nv50_display(dev);
  97. struct nouveau_channel *evo;
  98. int ret;
  99. evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  100. if (!evo)
  101. return -ENOMEM;
  102. *pevo = evo;
  103. evo->drm = drm;
  104. evo->handle = chid;
  105. evo->fence = dev;
  106. evo->user_get = 4;
  107. evo->user_put = 0;
  108. ret = nouveau_bo_new(dev, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0, NULL,
  109. &evo->push.buffer);
  110. if (ret == 0)
  111. ret = nouveau_bo_pin(evo->push.buffer, TTM_PL_FLAG_VRAM);
  112. if (ret) {
  113. NV_ERROR(drm, "Error creating EVO DMA push buffer: %d\n", ret);
  114. nv50_evo_channel_del(pevo);
  115. return ret;
  116. }
  117. ret = nouveau_bo_map(evo->push.buffer);
  118. if (ret) {
  119. NV_ERROR(drm, "Error mapping EVO DMA push buffer: %d\n", ret);
  120. nv50_evo_channel_del(pevo);
  121. return ret;
  122. }
  123. evo->object = kzalloc(sizeof(*evo->object), GFP_KERNEL);
  124. #ifdef NOUVEAU_OBJECT_MAGIC
  125. evo->object->_magic = NOUVEAU_OBJECT_MAGIC;
  126. #endif
  127. evo->object->parent = nv_object(disp->ramin)->parent;
  128. evo->object->engine = nv_object(disp->ramin)->engine;
  129. evo->object->oclass =
  130. kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
  131. evo->object->oclass->ofuncs =
  132. kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
  133. evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
  134. evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
  135. evo->object->oclass->ofuncs->rd08 =
  136. ioremap(pci_resource_start(dev->pdev, 0) +
  137. NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
  138. return 0;
  139. }
  140. static int
  141. nv50_evo_channel_init(struct nouveau_channel *evo)
  142. {
  143. struct nouveau_drm *drm = evo->drm;
  144. struct nouveau_device *device = nv_device(drm->device);
  145. int id = evo->handle, ret, i;
  146. u64 pushbuf = evo->push.buffer->bo.offset;
  147. u32 tmp;
  148. tmp = nv_rd32(device, NV50_PDISPLAY_EVO_CTRL(id));
  149. if ((tmp & 0x009f0000) == 0x00020000)
  150. nv_wr32(device, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
  151. tmp = nv_rd32(device, NV50_PDISPLAY_EVO_CTRL(id));
  152. if ((tmp & 0x003f0000) == 0x00030000)
  153. nv_wr32(device, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
  154. /* initialise fifo */
  155. nv_wr32(device, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
  156. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  157. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  158. nv_wr32(device, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
  159. nv_wr32(device, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
  160. nv_mask(device, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
  161. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  162. nv_wr32(device, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
  163. nv_wr32(device, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
  164. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  165. if (!nv_wait(device, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
  166. NV_ERROR(drm, "EvoCh %d init timeout: 0x%08x\n", id,
  167. nv_rd32(device, NV50_PDISPLAY_EVO_CTRL(id)));
  168. return -EBUSY;
  169. }
  170. /* enable error reporting on the channel */
  171. nv_mask(device, 0x610028, 0x00000000, 0x00010001 << id);
  172. evo->dma.max = (4096/4) - 2;
  173. evo->dma.max &= ~7;
  174. evo->dma.put = 0;
  175. evo->dma.cur = evo->dma.put;
  176. evo->dma.free = evo->dma.max - evo->dma.cur;
  177. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  178. if (ret)
  179. return ret;
  180. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  181. OUT_RING(evo, 0);
  182. return 0;
  183. }
  184. static void
  185. nv50_evo_channel_fini(struct nouveau_channel *evo)
  186. {
  187. struct nouveau_drm *drm = evo->drm;
  188. struct nouveau_device *device = nv_device(drm->device);
  189. int id = evo->handle;
  190. nv_mask(device, 0x610028, 0x00010001 << id, 0x00000000);
  191. nv_mask(device, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
  192. nv_wr32(device, NV50_PDISPLAY_INTR_0, (1 << id));
  193. nv_mask(device, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
  194. if (!nv_wait(device, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
  195. NV_ERROR(drm, "EvoCh %d takedown timeout: 0x%08x\n", id,
  196. nv_rd32(device, NV50_PDISPLAY_EVO_CTRL(id)));
  197. }
  198. }
  199. void
  200. nv50_evo_destroy(struct drm_device *dev)
  201. {
  202. struct nv50_display *disp = nv50_display(dev);
  203. int i;
  204. for (i = 0; i < 2; i++) {
  205. if (disp->crtc[i].sem.bo) {
  206. nouveau_bo_unmap(disp->crtc[i].sem.bo);
  207. nouveau_bo_ref(NULL, &disp->crtc[i].sem.bo);
  208. }
  209. nv50_evo_channel_del(&disp->crtc[i].sync);
  210. }
  211. nv50_evo_channel_del(&disp->master);
  212. }
  213. int
  214. nv50_evo_create(struct drm_device *dev)
  215. {
  216. struct nouveau_drm *drm = nouveau_drm(dev);
  217. struct nouveau_fb *pfb = nouveau_fb(drm->device);
  218. struct nv50_display *disp = nv50_display(dev);
  219. struct nouveau_channel *evo;
  220. int ret, i, j;
  221. /* setup object management on it, any other evo channel will
  222. * use this also as there's no per-channel support on the
  223. * hardware
  224. */
  225. disp->ramin = nv_gpuobj(disp->core->parent);
  226. disp->hash = 0x0000;
  227. disp->dmao = 0x1000;
  228. /* create primary evo channel, the one we use for modesetting
  229. * purporses
  230. */
  231. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  232. if (ret)
  233. return ret;
  234. evo = disp->master;
  235. ret = nv50_evo_dmaobj_new(disp->master, NvEvoSync, 0x0000,
  236. disp->ramin->addr + 0x2000, 0x1000, NULL);
  237. if (ret)
  238. goto err;
  239. /* create some default objects for the scanout memtypes we support */
  240. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM, 0x0000,
  241. 0, pfb->ram.size, NULL);
  242. if (ret)
  243. goto err;
  244. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM_LP, 0x80000000,
  245. 0, pfb->ram.size, NULL);
  246. if (ret)
  247. goto err;
  248. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB32, 0x80000000 |
  249. (nv_device(drm->device)->chipset < 0xc0 ? 0x7a : 0xfe),
  250. 0, pfb->ram.size, NULL);
  251. if (ret)
  252. goto err;
  253. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB16, 0x80000000 |
  254. (nv_device(drm->device)->chipset < 0xc0 ? 0x70 : 0xfe),
  255. 0, pfb->ram.size, NULL);
  256. if (ret)
  257. goto err;
  258. /* create "display sync" channels and other structures we need
  259. * to implement page flipping
  260. */
  261. for (i = 0; i < 2; i++) {
  262. struct nv50_display_crtc *dispc = &disp->crtc[i];
  263. u64 offset;
  264. ret = nv50_evo_channel_new(dev, 1 + i, &dispc->sync);
  265. if (ret)
  266. goto err;
  267. ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  268. 0, 0x0000, NULL, &dispc->sem.bo);
  269. if (!ret) {
  270. ret = nouveau_bo_pin(dispc->sem.bo, TTM_PL_FLAG_VRAM);
  271. if (!ret)
  272. ret = nouveau_bo_map(dispc->sem.bo);
  273. if (ret)
  274. nouveau_bo_ref(NULL, &dispc->sem.bo);
  275. offset = dispc->sem.bo->bo.offset;
  276. }
  277. if (ret)
  278. goto err;
  279. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoSync, 0x0000,
  280. offset, 4096, NULL);
  281. if (ret)
  282. goto err;
  283. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoVRAM_LP, 0x80000000,
  284. 0, pfb->ram.size, NULL);
  285. if (ret)
  286. goto err;
  287. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB32, 0x80000000 |
  288. (nv_device(drm->device)->chipset < 0xc0 ?
  289. 0x7a : 0xfe),
  290. 0, pfb->ram.size, NULL);
  291. if (ret)
  292. goto err;
  293. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB16, 0x80000000 |
  294. (nv_device(drm->device)->chipset < 0xc0 ?
  295. 0x70 : 0xfe),
  296. 0, pfb->ram.size, NULL);
  297. if (ret)
  298. goto err;
  299. for (j = 0; j < 4096; j += 4)
  300. nouveau_bo_wr32(dispc->sem.bo, j / 4, 0x74b1e000);
  301. dispc->sem.offset = 0;
  302. }
  303. return 0;
  304. err:
  305. nv50_evo_destroy(dev);
  306. return ret;
  307. }
  308. int
  309. nv50_evo_init(struct drm_device *dev)
  310. {
  311. struct nv50_display *disp = nv50_display(dev);
  312. int ret, i;
  313. ret = nv50_evo_channel_init(disp->master);
  314. if (ret)
  315. return ret;
  316. for (i = 0; i < 2; i++) {
  317. ret = nv50_evo_channel_init(disp->crtc[i].sync);
  318. if (ret)
  319. return ret;
  320. }
  321. return 0;
  322. }
  323. void
  324. nv50_evo_fini(struct drm_device *dev)
  325. {
  326. struct nv50_display *disp = nv50_display(dev);
  327. int i;
  328. for (i = 0; i < 2; i++) {
  329. if (disp->crtc[i].sync)
  330. nv50_evo_channel_fini(disp->crtc[i].sync);
  331. }
  332. if (disp->master)
  333. nv50_evo_channel_fini(disp->master);
  334. }