nv50_evo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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, u32 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, u32 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. nouveau_gpuobj_ref(NULL, &disp->ramin);
  213. }
  214. int
  215. nv50_evo_create(struct drm_device *dev)
  216. {
  217. struct nouveau_drm *drm = nouveau_drm(dev);
  218. struct nouveau_fb *pfb = nouveau_fb(drm->device);
  219. struct nv50_display *disp = nv50_display(dev);
  220. struct nouveau_channel *evo;
  221. int ret, i, j;
  222. /* setup object management on it, any other evo channel will
  223. * use this also as there's no per-channel support on the
  224. * hardware
  225. */
  226. ret = nouveau_gpuobj_new(drm->device, NULL, 32768, 65536,
  227. NVOBJ_FLAG_ZERO_ALLOC, &disp->ramin);
  228. if (ret) {
  229. NV_ERROR(drm, "Error allocating EVO channel memory: %d\n", ret);
  230. goto err;
  231. }
  232. disp->hash = 0x0000;
  233. disp->dmao = 0x1000;
  234. /* create primary evo channel, the one we use for modesetting
  235. * purporses
  236. */
  237. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  238. if (ret)
  239. return ret;
  240. evo = disp->master;
  241. ret = nv50_evo_dmaobj_new(disp->master, NvEvoSync, 0x0000,
  242. disp->ramin->addr + 0x2000, 0x1000, NULL);
  243. if (ret)
  244. goto err;
  245. /* create some default objects for the scanout memtypes we support */
  246. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM, 0x0000,
  247. 0, pfb->ram.size, NULL);
  248. if (ret)
  249. goto err;
  250. ret = nv50_evo_dmaobj_new(disp->master, NvEvoVRAM_LP, 0x80000000,
  251. 0, pfb->ram.size, NULL);
  252. if (ret)
  253. goto err;
  254. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB32, 0x80000000 |
  255. (nv_device(drm->device)->chipset < 0xc0 ? 0x7a : 0xfe),
  256. 0, pfb->ram.size, NULL);
  257. if (ret)
  258. goto err;
  259. ret = nv50_evo_dmaobj_new(disp->master, NvEvoFB16, 0x80000000 |
  260. (nv_device(drm->device)->chipset < 0xc0 ? 0x70 : 0xfe),
  261. 0, pfb->ram.size, NULL);
  262. if (ret)
  263. goto err;
  264. /* create "display sync" channels and other structures we need
  265. * to implement page flipping
  266. */
  267. for (i = 0; i < 2; i++) {
  268. struct nv50_display_crtc *dispc = &disp->crtc[i];
  269. u64 offset;
  270. ret = nv50_evo_channel_new(dev, 1 + i, &dispc->sync);
  271. if (ret)
  272. goto err;
  273. ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  274. 0, 0x0000, NULL, &dispc->sem.bo);
  275. if (!ret) {
  276. ret = nouveau_bo_pin(dispc->sem.bo, TTM_PL_FLAG_VRAM);
  277. if (!ret)
  278. ret = nouveau_bo_map(dispc->sem.bo);
  279. if (ret)
  280. nouveau_bo_ref(NULL, &dispc->sem.bo);
  281. offset = dispc->sem.bo->bo.offset;
  282. }
  283. if (ret)
  284. goto err;
  285. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoSync, 0x0000,
  286. offset, 4096, NULL);
  287. if (ret)
  288. goto err;
  289. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoVRAM_LP, 0x80000000,
  290. 0, pfb->ram.size, NULL);
  291. if (ret)
  292. goto err;
  293. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB32, 0x80000000 |
  294. (nv_device(drm->device)->chipset < 0xc0 ?
  295. 0x7a : 0xfe),
  296. 0, pfb->ram.size, NULL);
  297. if (ret)
  298. goto err;
  299. ret = nv50_evo_dmaobj_new(dispc->sync, NvEvoFB16, 0x80000000 |
  300. (nv_device(drm->device)->chipset < 0xc0 ?
  301. 0x70 : 0xfe),
  302. 0, pfb->ram.size, NULL);
  303. if (ret)
  304. goto err;
  305. for (j = 0; j < 4096; j += 4)
  306. nouveau_bo_wr32(dispc->sem.bo, j / 4, 0x74b1e000);
  307. dispc->sem.offset = 0;
  308. }
  309. return 0;
  310. err:
  311. nv50_evo_destroy(dev);
  312. return ret;
  313. }
  314. int
  315. nv50_evo_init(struct drm_device *dev)
  316. {
  317. struct nv50_display *disp = nv50_display(dev);
  318. int ret, i;
  319. ret = nv50_evo_channel_init(disp->master);
  320. if (ret)
  321. return ret;
  322. for (i = 0; i < 2; i++) {
  323. ret = nv50_evo_channel_init(disp->crtc[i].sync);
  324. if (ret)
  325. return ret;
  326. }
  327. return 0;
  328. }
  329. void
  330. nv50_evo_fini(struct drm_device *dev)
  331. {
  332. struct nv50_display *disp = nv50_display(dev);
  333. int i;
  334. for (i = 0; i < 2; i++) {
  335. if (disp->crtc[i].sync)
  336. nv50_evo_channel_fini(disp->crtc[i].sync);
  337. }
  338. if (disp->master)
  339. nv50_evo_channel_fini(disp->master);
  340. }