nv50_evo.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. int
  44. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 class, u32 name,
  45. u32 tile_flags, u32 magic_flags, u32 offset, u32 limit,
  46. u32 flags5)
  47. {
  48. struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
  49. struct nv50_display *disp = nv50_display(evo->dev);
  50. struct nouveau_gpuobj *obj = NULL;
  51. int ret;
  52. ret = nouveau_gpuobj_new(evo->dev, disp->master, 6*4, 32, 0, &obj);
  53. if (ret)
  54. return ret;
  55. obj->engine = NVOBJ_ENGINE_DISPLAY;
  56. nv_wo32(obj, 0, (tile_flags << 22) | (magic_flags << 16) | class);
  57. nv_wo32(obj, 4, limit);
  58. nv_wo32(obj, 8, offset);
  59. nv_wo32(obj, 12, 0x00000000);
  60. nv_wo32(obj, 16, 0x00000000);
  61. nv_wo32(obj, 20, flags5);
  62. dev_priv->engine.instmem.flush(evo->dev);
  63. ret = nouveau_ramht_insert(evo, name, obj);
  64. nouveau_gpuobj_ref(NULL, &obj);
  65. if (ret) {
  66. return ret;
  67. }
  68. return 0;
  69. }
  70. static int
  71. nv50_evo_channel_new(struct drm_device *dev, int chid,
  72. struct nouveau_channel **pevo)
  73. {
  74. struct nv50_display *disp = nv50_display(dev);
  75. struct nouveau_channel *evo;
  76. int ret;
  77. evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  78. if (!evo)
  79. return -ENOMEM;
  80. *pevo = evo;
  81. evo->id = chid;
  82. evo->dev = dev;
  83. evo->user_get = 4;
  84. evo->user_put = 0;
  85. ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
  86. false, true, &evo->pushbuf_bo);
  87. if (ret == 0)
  88. ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
  89. if (ret) {
  90. NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
  91. nv50_evo_channel_del(pevo);
  92. return ret;
  93. }
  94. ret = nouveau_bo_map(evo->pushbuf_bo);
  95. if (ret) {
  96. NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
  97. nv50_evo_channel_del(pevo);
  98. return ret;
  99. }
  100. evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
  101. NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
  102. if (!evo->user) {
  103. NV_ERROR(dev, "Error mapping EVO control regs.\n");
  104. nv50_evo_channel_del(pevo);
  105. return -ENOMEM;
  106. }
  107. /* bind primary evo channel's ramht to the channel */
  108. if (disp->master && evo != disp->master)
  109. nouveau_ramht_ref(disp->master->ramht, &evo->ramht, NULL);
  110. return 0;
  111. }
  112. static int
  113. nv50_evo_channel_init(struct nouveau_channel *evo)
  114. {
  115. struct drm_device *dev = evo->dev;
  116. int id = evo->id, ret, i;
  117. u64 pushbuf = evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT;
  118. u32 tmp;
  119. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  120. if ((tmp & 0x009f0000) == 0x00020000)
  121. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
  122. tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
  123. if ((tmp & 0x003f0000) == 0x00030000)
  124. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
  125. /* initialise fifo */
  126. nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
  127. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  128. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  129. nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
  130. nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
  131. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
  132. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  133. nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
  134. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
  135. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  136. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
  137. NV_ERROR(dev, "EvoCh %d init timeout: 0x%08x\n", id,
  138. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  139. return -EBUSY;
  140. }
  141. /* enable error reporting on the channel */
  142. nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
  143. evo->dma.max = (4096/4) - 2;
  144. evo->dma.put = 0;
  145. evo->dma.cur = evo->dma.put;
  146. evo->dma.free = evo->dma.max - evo->dma.cur;
  147. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  148. if (ret)
  149. return ret;
  150. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  151. OUT_RING(evo, 0);
  152. return 0;
  153. }
  154. static void
  155. nv50_evo_channel_fini(struct nouveau_channel *evo)
  156. {
  157. struct drm_device *dev = evo->dev;
  158. int id = evo->id;
  159. nv_mask(dev, 0x610028, 0x00010001 << id, 0x00000000);
  160. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
  161. nv_wr32(dev, NV50_PDISPLAY_INTR_0, (1 << id));
  162. nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
  163. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
  164. NV_ERROR(dev, "EvoCh %d takedown timeout: 0x%08x\n", id,
  165. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  166. }
  167. }
  168. static int
  169. nv50_evo_create(struct drm_device *dev)
  170. {
  171. struct drm_nouveau_private *dev_priv = dev->dev_private;
  172. struct nv50_display *disp = nv50_display(dev);
  173. struct nouveau_gpuobj *ramht = NULL;
  174. struct nouveau_channel *evo;
  175. int ret;
  176. /* create primary evo channel, the one we use for modesetting
  177. * purporses
  178. */
  179. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  180. if (ret)
  181. return ret;
  182. evo = disp->master;
  183. /* setup object management on it, any other evo channel will
  184. * use this also as there's no per-channel support on the
  185. * hardware
  186. */
  187. ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
  188. NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
  189. if (ret) {
  190. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  191. nv50_evo_channel_del(&disp->master);
  192. return ret;
  193. }
  194. ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
  195. if (ret) {
  196. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  197. nv50_evo_channel_del(&disp->master);
  198. return ret;
  199. }
  200. ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
  201. if (ret) {
  202. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  203. nv50_evo_channel_del(&disp->master);
  204. return ret;
  205. }
  206. ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
  207. nouveau_gpuobj_ref(NULL, &ramht);
  208. if (ret) {
  209. nv50_evo_channel_del(&disp->master);
  210. return ret;
  211. }
  212. /* create some default objects for the scanout memtypes we support */
  213. if (dev_priv->card_type >= NV_C0) {
  214. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0xfe, 0x19,
  215. 0, 0xffffffff, 0x00000000);
  216. if (ret) {
  217. nv50_evo_channel_del(&disp->master);
  218. return ret;
  219. }
  220. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
  221. 0, dev_priv->vram_size, 0x00020000);
  222. if (ret) {
  223. nv50_evo_channel_del(&disp->master);
  224. return ret;
  225. }
  226. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
  227. 0, dev_priv->vram_size, 0x00000000);
  228. if (ret) {
  229. nv50_evo_channel_del(&disp->master);
  230. return ret;
  231. }
  232. } else {
  233. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB16, 0x70, 0x19,
  234. 0, 0xffffffff, 0x00010000);
  235. if (ret) {
  236. nv50_evo_channel_del(&disp->master);
  237. return ret;
  238. }
  239. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0x7a, 0x19,
  240. 0, 0xffffffff, 0x00010000);
  241. if (ret) {
  242. nv50_evo_channel_del(&disp->master);
  243. return ret;
  244. }
  245. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
  246. 0, dev_priv->vram_size, 0x00010000);
  247. if (ret) {
  248. nv50_evo_channel_del(&disp->master);
  249. return ret;
  250. }
  251. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
  252. 0, dev_priv->vram_size, 0x00010000);
  253. if (ret) {
  254. nv50_evo_channel_del(&disp->master);
  255. return ret;
  256. }
  257. }
  258. return 0;
  259. }
  260. int
  261. nv50_evo_init(struct drm_device *dev)
  262. {
  263. struct nv50_display *disp = nv50_display(dev);
  264. int ret;
  265. if (!disp->master) {
  266. ret = nv50_evo_create(dev);
  267. if (ret)
  268. return ret;
  269. }
  270. return nv50_evo_channel_init(disp->master);
  271. }
  272. void
  273. nv50_evo_fini(struct drm_device *dev)
  274. {
  275. struct nv50_display *disp = nv50_display(dev);
  276. if (disp->master) {
  277. nv50_evo_channel_fini(disp->master);
  278. nv50_evo_channel_del(&disp->master);
  279. }
  280. }