nv50_evo.c 9.0 KB

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