nv50_evo.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 void
  169. nv50_evo_destroy(struct drm_device *dev)
  170. {
  171. struct nv50_display *disp = nv50_display(dev);
  172. nouveau_gpuobj_ref(NULL, &disp->ntfy);
  173. nv50_evo_channel_del(&disp->master);
  174. }
  175. static int
  176. nv50_evo_create(struct drm_device *dev)
  177. {
  178. struct drm_nouveau_private *dev_priv = dev->dev_private;
  179. struct nv50_display *disp = nv50_display(dev);
  180. struct nouveau_gpuobj *ramht = NULL;
  181. struct nouveau_channel *evo;
  182. int ret;
  183. /* create primary evo channel, the one we use for modesetting
  184. * purporses
  185. */
  186. ret = nv50_evo_channel_new(dev, 0, &disp->master);
  187. if (ret)
  188. return ret;
  189. evo = disp->master;
  190. /* setup object management on it, any other evo channel will
  191. * use this also as there's no per-channel support on the
  192. * hardware
  193. */
  194. ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
  195. NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
  196. if (ret) {
  197. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  198. goto err;
  199. }
  200. ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
  201. if (ret) {
  202. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  203. goto err;
  204. }
  205. ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
  206. if (ret) {
  207. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  208. goto err;
  209. }
  210. ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
  211. nouveau_gpuobj_ref(NULL, &ramht);
  212. if (ret)
  213. goto err;
  214. /* not sure exactly what this is..
  215. *
  216. * the first dword of the structure is used by nvidia to wait on
  217. * full completion of an EVO "update" command.
  218. *
  219. * method 0x8c on the master evo channel will fill a lot more of
  220. * this structure with some undefined info
  221. */
  222. ret = nouveau_gpuobj_new(dev, disp->master, 0x1000, 0,
  223. NVOBJ_FLAG_ZERO_ALLOC, &disp->ntfy);
  224. if (ret)
  225. goto err;
  226. ret = nv50_evo_dmaobj_new(disp->master, 0x3d, NvEvoSync, 0, 0x19,
  227. disp->ntfy->vinst, disp->ntfy->vinst +
  228. disp->ntfy->size, 0x00010000);
  229. if (ret)
  230. goto err;
  231. /* create some default objects for the scanout memtypes we support */
  232. if (dev_priv->card_type >= NV_C0) {
  233. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0xfe, 0x19,
  234. 0, 0xffffffff, 0x00000000);
  235. if (ret)
  236. goto err;
  237. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
  238. 0, dev_priv->vram_size, 0x00020000);
  239. if (ret)
  240. goto err;
  241. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
  242. 0, dev_priv->vram_size, 0x00000000);
  243. if (ret)
  244. goto err;
  245. } else {
  246. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB16, 0x70, 0x19,
  247. 0, 0xffffffff, 0x00010000);
  248. if (ret)
  249. goto err;
  250. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0x7a, 0x19,
  251. 0, 0xffffffff, 0x00010000);
  252. if (ret)
  253. goto err;
  254. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
  255. 0, dev_priv->vram_size, 0x00010000);
  256. if (ret)
  257. goto err;
  258. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
  259. 0, dev_priv->vram_size, 0x00010000);
  260. if (ret)
  261. goto err;
  262. }
  263. return 0;
  264. err:
  265. nv50_evo_destroy(dev);
  266. return ret;
  267. }
  268. int
  269. nv50_evo_init(struct drm_device *dev)
  270. {
  271. struct nv50_display *disp = nv50_display(dev);
  272. int ret;
  273. if (!disp->master) {
  274. ret = nv50_evo_create(dev);
  275. if (ret)
  276. return ret;
  277. }
  278. return nv50_evo_channel_init(disp->master);
  279. }
  280. void
  281. nv50_evo_fini(struct drm_device *dev)
  282. {
  283. struct nv50_display *disp = nv50_display(dev);
  284. if (disp->master)
  285. nv50_evo_channel_fini(disp->master);
  286. nv50_evo_destroy(dev);
  287. }