nvd0_display.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Copyright 2011 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 <linux/dma-mapping.h>
  25. #include "drmP.h"
  26. #include "nouveau_drv.h"
  27. #include "nouveau_connector.h"
  28. #include "nouveau_encoder.h"
  29. #include "nouveau_crtc.h"
  30. #define MEM_SYNC 0xe0000001
  31. #define MEM_VRAM 0xe0010000
  32. struct nvd0_display {
  33. struct nouveau_gpuobj *mem;
  34. struct {
  35. dma_addr_t handle;
  36. u32 *ptr;
  37. } evo[1];
  38. };
  39. static struct nvd0_display *
  40. nvd0_display(struct drm_device *dev)
  41. {
  42. struct drm_nouveau_private *dev_priv = dev->dev_private;
  43. return dev_priv->engine.display.priv;
  44. }
  45. static int
  46. evo_icmd(struct drm_device *dev, int id, u32 mthd, u32 data)
  47. {
  48. int ret = 0;
  49. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000001);
  50. nv_wr32(dev, 0x610704 + (id * 0x10), data);
  51. nv_mask(dev, 0x610704 + (id * 0x10), 0x80000ffc, 0x80000000 | mthd);
  52. if (!nv_wait(dev, 0x610704 + (id * 0x10), 0x80000000, 0x00000000))
  53. ret = -EBUSY;
  54. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000000);
  55. return ret;
  56. }
  57. static u32 *
  58. evo_wait(struct drm_device *dev, int id, int nr)
  59. {
  60. struct nvd0_display *disp = nvd0_display(dev);
  61. u32 put = nv_rd32(dev, 0x640000 + (id * 0x1000)) / 4;
  62. if (put + nr >= (PAGE_SIZE / 4)) {
  63. disp->evo[id].ptr[put] = 0x20000000;
  64. nv_wr32(dev, 0x640000 + (id * 0x1000), 0x00000000);
  65. if (!nv_wait(dev, 0x640004 + (id * 0x1000), ~0, 0x00000000)) {
  66. NV_ERROR(dev, "evo %d dma stalled\n", id);
  67. return NULL;
  68. }
  69. put = 0;
  70. }
  71. return disp->evo[id].ptr + put;
  72. }
  73. static void
  74. evo_kick(u32 *push, struct drm_device *dev, int id)
  75. {
  76. struct nvd0_display *disp = nvd0_display(dev);
  77. nv_wr32(dev, 0x640000 + (id * 0x1000), (push - disp->evo[id].ptr) << 2);
  78. }
  79. #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
  80. #define evo_data(p,d) *((p)++) = (d)
  81. /******************************************************************************
  82. * DAC
  83. *****************************************************************************/
  84. /******************************************************************************
  85. * SOR
  86. *****************************************************************************/
  87. /******************************************************************************
  88. * IRQ
  89. *****************************************************************************/
  90. static void
  91. nvd0_display_intr(struct drm_device *dev)
  92. {
  93. u32 intr = nv_rd32(dev, 0x610088);
  94. if (intr & 0x00000002) {
  95. u32 stat = nv_rd32(dev, 0x61009c);
  96. int chid = ffs(stat) - 1;
  97. if (chid >= 0) {
  98. u32 mthd = nv_rd32(dev, 0x6101f0 + (chid * 12));
  99. u32 data = nv_rd32(dev, 0x6101f4 + (chid * 12));
  100. u32 unkn = nv_rd32(dev, 0x6101f8 + (chid * 12));
  101. NV_INFO(dev, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
  102. "0x%08x 0x%08x\n",
  103. chid, (mthd & 0x0000ffc), data, mthd, unkn);
  104. nv_wr32(dev, 0x61009c, (1 << chid));
  105. nv_wr32(dev, 0x6101f0 + (chid * 12), 0x90000000);
  106. }
  107. intr &= ~0x00000002;
  108. }
  109. if (intr & 0x01000000) {
  110. u32 stat = nv_rd32(dev, 0x6100bc);
  111. nv_wr32(dev, 0x6100bc, stat);
  112. intr &= ~0x01000000;
  113. }
  114. if (intr & 0x02000000) {
  115. u32 stat = nv_rd32(dev, 0x6108bc);
  116. nv_wr32(dev, 0x6108bc, stat);
  117. intr &= ~0x02000000;
  118. }
  119. if (intr)
  120. NV_INFO(dev, "PDISP: unknown intr 0x%08x\n", intr);
  121. }
  122. /******************************************************************************
  123. * Init
  124. *****************************************************************************/
  125. static void
  126. nvd0_display_fini(struct drm_device *dev)
  127. {
  128. int i;
  129. /* fini cursors */
  130. for (i = 14; i >= 13; i--) {
  131. if (!(nv_rd32(dev, 0x610490 + (i * 0x10)) & 0x00000001))
  132. continue;
  133. nv_mask(dev, 0x610490 + (i * 0x10), 0x00000001, 0x00000000);
  134. nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00000000);
  135. nv_mask(dev, 0x610090, 1 << i, 0x00000000);
  136. nv_mask(dev, 0x6100a0, 1 << i, 0x00000000);
  137. }
  138. /* fini master */
  139. if (nv_rd32(dev, 0x610490) & 0x00000010) {
  140. nv_mask(dev, 0x610490, 0x00000010, 0x00000000);
  141. nv_mask(dev, 0x610490, 0x00000003, 0x00000000);
  142. nv_wait(dev, 0x610490, 0x80000000, 0x00000000);
  143. nv_mask(dev, 0x610090, 0x00000001, 0x00000000);
  144. nv_mask(dev, 0x6100a0, 0x00000001, 0x00000000);
  145. }
  146. }
  147. int
  148. nvd0_display_init(struct drm_device *dev)
  149. {
  150. struct nvd0_display *disp = nvd0_display(dev);
  151. u32 *push;
  152. int i;
  153. if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
  154. nv_wr32(dev, 0x6100ac, 0x00000100);
  155. nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
  156. if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
  157. NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
  158. nv_rd32(dev, 0x6194e8));
  159. return -EBUSY;
  160. }
  161. }
  162. nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
  163. /* init master */
  164. nv_wr32(dev, 0x610494, (disp->evo[0].handle >> 8) | 3);
  165. nv_wr32(dev, 0x610498, 0x00010000);
  166. nv_wr32(dev, 0x61049c, 0x00000001);
  167. nv_mask(dev, 0x610490, 0x00000010, 0x00000010);
  168. nv_wr32(dev, 0x640000, 0x00000000);
  169. nv_wr32(dev, 0x610490, 0x01000013);
  170. if (!nv_wait(dev, 0x610490, 0x80000000, 0x00000000)) {
  171. NV_ERROR(dev, "PDISP: master 0x%08x\n",
  172. nv_rd32(dev, 0x610490));
  173. return -EBUSY;
  174. }
  175. nv_mask(dev, 0x610090, 0x00000001, 0x00000001);
  176. nv_mask(dev, 0x6100a0, 0x00000001, 0x00000001);
  177. /* init cursors */
  178. for (i = 13; i <= 14; i++) {
  179. nv_wr32(dev, 0x610490 + (i * 0x10), 0x00000001);
  180. if (!nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00010000)) {
  181. NV_ERROR(dev, "PDISP: curs%d 0x%08x\n", i,
  182. nv_rd32(dev, 0x610490 + (i * 0x10)));
  183. return -EBUSY;
  184. }
  185. nv_mask(dev, 0x610090, 1 << i, 1 << i);
  186. nv_mask(dev, 0x6100a0, 1 << i, 1 << i);
  187. }
  188. push = evo_wait(dev, 0, 32);
  189. if (!push)
  190. return -EBUSY;
  191. evo_mthd(push, 0x0088, 1);
  192. evo_data(push, MEM_SYNC);
  193. evo_mthd(push, 0x0084, 1);
  194. evo_data(push, 0x00000000);
  195. evo_mthd(push, 0x0084, 1);
  196. evo_data(push, 0x80000000);
  197. evo_mthd(push, 0x008c, 1);
  198. evo_data(push, 0x00000000);
  199. evo_kick(push, dev, 0);
  200. return 0;
  201. }
  202. void
  203. nvd0_display_destroy(struct drm_device *dev)
  204. {
  205. struct drm_nouveau_private *dev_priv = dev->dev_private;
  206. struct nvd0_display *disp = nvd0_display(dev);
  207. struct pci_dev *pdev = dev->pdev;
  208. nvd0_display_fini(dev);
  209. pci_free_consistent(pdev, PAGE_SIZE, disp->evo[0].ptr, disp->evo[0].handle);
  210. nouveau_gpuobj_ref(NULL, &disp->mem);
  211. nouveau_irq_unregister(dev, 26);
  212. dev_priv->engine.display.priv = NULL;
  213. kfree(disp);
  214. }
  215. int
  216. nvd0_display_create(struct drm_device *dev)
  217. {
  218. struct drm_nouveau_private *dev_priv = dev->dev_private;
  219. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  220. struct pci_dev *pdev = dev->pdev;
  221. struct nvd0_display *disp;
  222. int ret;
  223. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  224. if (!disp)
  225. return -ENOMEM;
  226. dev_priv->engine.display.priv = disp;
  227. /* setup interrupt handling */
  228. nouveau_irq_register(dev, 26, nvd0_display_intr);
  229. /* hash table and dma objects for the memory areas we care about */
  230. ret = nouveau_gpuobj_new(dev, NULL, 0x4000, 0x10000,
  231. NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
  232. if (ret)
  233. goto out;
  234. nv_wo32(disp->mem, 0x1000, 0x00000049);
  235. nv_wo32(disp->mem, 0x1004, (disp->mem->vinst + 0x2000) >> 8);
  236. nv_wo32(disp->mem, 0x1008, (disp->mem->vinst + 0x2fff) >> 8);
  237. nv_wo32(disp->mem, 0x100c, 0x00000000);
  238. nv_wo32(disp->mem, 0x1010, 0x00000000);
  239. nv_wo32(disp->mem, 0x1014, 0x00000000);
  240. nv_wo32(disp->mem, 0x0000, MEM_SYNC);
  241. nv_wo32(disp->mem, 0x0004, (0x1000 << 9) | 0x00000001);
  242. nv_wo32(disp->mem, 0x1020, 0x00000009);
  243. nv_wo32(disp->mem, 0x1024, 0x00000000);
  244. nv_wo32(disp->mem, 0x1028, (dev_priv->vram_size - 1) >> 8);
  245. nv_wo32(disp->mem, 0x102c, 0x00000000);
  246. nv_wo32(disp->mem, 0x1030, 0x00000000);
  247. nv_wo32(disp->mem, 0x1034, 0x00000000);
  248. nv_wo32(disp->mem, 0x0008, MEM_VRAM);
  249. nv_wo32(disp->mem, 0x000c, (0x1020 << 9) | 0x00000001);
  250. pinstmem->flush(dev);
  251. /* push buffers for evo channels */
  252. disp->evo[0].ptr =
  253. pci_alloc_consistent(pdev, PAGE_SIZE, &disp->evo[0].handle);
  254. if (!disp->evo[0].ptr) {
  255. ret = -ENOMEM;
  256. goto out;
  257. }
  258. ret = nvd0_display_init(dev);
  259. if (ret)
  260. goto out;
  261. out:
  262. if (ret)
  263. nvd0_display_destroy(dev);
  264. return ret;
  265. }