nv50_evo.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. static void
  29. nv50_evo_channel_del(struct nouveau_channel **pchan)
  30. {
  31. struct nouveau_channel *chan = *pchan;
  32. if (!chan)
  33. return;
  34. *pchan = NULL;
  35. nouveau_gpuobj_channel_takedown(chan);
  36. nouveau_bo_unmap(chan->pushbuf_bo);
  37. nouveau_bo_ref(NULL, &chan->pushbuf_bo);
  38. if (chan->user)
  39. iounmap(chan->user);
  40. kfree(chan);
  41. }
  42. int
  43. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 class, u32 name,
  44. u32 tile_flags, u32 magic_flags, u32 offset, u32 limit)
  45. {
  46. struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
  47. struct drm_device *dev = evo->dev;
  48. struct nouveau_gpuobj *obj = NULL;
  49. int ret;
  50. ret = nouveau_gpuobj_new(dev, evo, 6*4, 32, 0, &obj);
  51. if (ret)
  52. return ret;
  53. obj->engine = NVOBJ_ENGINE_DISPLAY;
  54. nv_wo32(obj, 0, (tile_flags << 22) | (magic_flags << 16) | class);
  55. nv_wo32(obj, 4, limit);
  56. nv_wo32(obj, 8, offset);
  57. nv_wo32(obj, 12, 0x00000000);
  58. nv_wo32(obj, 16, 0x00000000);
  59. if (dev_priv->card_type < NV_C0)
  60. nv_wo32(obj, 20, 0x00010000);
  61. else
  62. nv_wo32(obj, 20, 0x00020000);
  63. dev_priv->engine.instmem.flush(dev);
  64. ret = nouveau_ramht_insert(evo, name, obj);
  65. nouveau_gpuobj_ref(NULL, &obj);
  66. if (ret) {
  67. return ret;
  68. }
  69. return 0;
  70. }
  71. static int
  72. nv50_evo_channel_new(struct drm_device *dev, struct nouveau_channel **pchan)
  73. {
  74. struct drm_nouveau_private *dev_priv = dev->dev_private;
  75. struct nouveau_gpuobj *ramht = NULL;
  76. struct nouveau_channel *chan;
  77. int ret;
  78. chan = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  79. if (!chan)
  80. return -ENOMEM;
  81. *pchan = chan;
  82. chan->id = -1;
  83. chan->dev = dev;
  84. chan->user_get = 4;
  85. chan->user_put = 0;
  86. ret = nouveau_gpuobj_new(dev, NULL, 32768, 0x1000,
  87. NVOBJ_FLAG_ZERO_ALLOC, &chan->ramin);
  88. if (ret) {
  89. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  90. nv50_evo_channel_del(pchan);
  91. return ret;
  92. }
  93. ret = drm_mm_init(&chan->ramin_heap, 0, 32768);
  94. if (ret) {
  95. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  96. nv50_evo_channel_del(pchan);
  97. return ret;
  98. }
  99. ret = nouveau_gpuobj_new(dev, chan, 4096, 16, 0, &ramht);
  100. if (ret) {
  101. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  102. nv50_evo_channel_del(pchan);
  103. return ret;
  104. }
  105. ret = nouveau_ramht_new(dev, ramht, &chan->ramht);
  106. nouveau_gpuobj_ref(NULL, &ramht);
  107. if (ret) {
  108. nv50_evo_channel_del(pchan);
  109. return ret;
  110. }
  111. if (dev_priv->chipset != 0x50) {
  112. ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoFB16, 0x70, 0x19,
  113. 0, 0xffffffff);
  114. if (ret) {
  115. nv50_evo_channel_del(pchan);
  116. return ret;
  117. }
  118. ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoFB32, 0x7a, 0x19,
  119. 0, 0xffffffff);
  120. if (ret) {
  121. nv50_evo_channel_del(pchan);
  122. return ret;
  123. }
  124. }
  125. ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoVRAM, 0, 0x19,
  126. 0, dev_priv->vram_size);
  127. if (ret) {
  128. nv50_evo_channel_del(pchan);
  129. return ret;
  130. }
  131. ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
  132. false, true, &chan->pushbuf_bo);
  133. if (ret == 0)
  134. ret = nouveau_bo_pin(chan->pushbuf_bo, TTM_PL_FLAG_VRAM);
  135. if (ret) {
  136. NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
  137. nv50_evo_channel_del(pchan);
  138. return ret;
  139. }
  140. ret = nouveau_bo_map(chan->pushbuf_bo);
  141. if (ret) {
  142. NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
  143. nv50_evo_channel_del(pchan);
  144. return ret;
  145. }
  146. chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
  147. NV50_PDISPLAY_USER(0), PAGE_SIZE);
  148. if (!chan->user) {
  149. NV_ERROR(dev, "Error mapping EVO control regs.\n");
  150. nv50_evo_channel_del(pchan);
  151. return -ENOMEM;
  152. }
  153. return 0;
  154. }
  155. static int
  156. nv50_evo_channel_init(struct nouveau_channel *evo)
  157. {
  158. struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
  159. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  160. struct drm_device *dev = evo->dev;
  161. int ret, i;
  162. u64 start;
  163. u32 tmp;
  164. /* taken from nv bug #12637, attempts to un-wedge the hw if it's
  165. * stuck in some unspecified state
  166. */
  167. start = ptimer->read(dev);
  168. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), 0x2b00);
  169. while ((tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(0))) & 0x1e0000) {
  170. if ((tmp & 0x9f0000) == 0x20000)
  171. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), tmp | 0x800000);
  172. if ((tmp & 0x3f0000) == 0x30000)
  173. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), tmp | 0x200000);
  174. if (ptimer->read(dev) - start > 1000000000ULL) {
  175. NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) != 0\n");
  176. NV_ERROR(dev, "0x610200 = 0x%08x\n", tmp);
  177. return -EBUSY;
  178. }
  179. }
  180. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), 0x1000b03);
  181. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(0),
  182. 0x40000000, 0x40000000)) {
  183. NV_ERROR(dev, "timeout: (0x610200 & 0x40000000) == 0x40000000\n");
  184. NV_ERROR(dev, "0x610200 = 0x%08x\n",
  185. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(0)));
  186. return -EBUSY;
  187. }
  188. /* initialise fifo */
  189. nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(0),
  190. ((evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT) >> 8) |
  191. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  192. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  193. nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(0), 0x00010000);
  194. nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(0), 0x00000002);
  195. if (!nv_wait(dev, 0x610200, 0x80000000, 0x00000000)) {
  196. NV_ERROR(dev, "timeout: (0x610200 & 0x80000000) == 0\n");
  197. NV_ERROR(dev, "0x610200 = 0x%08x\n", nv_rd32(dev, 0x610200));
  198. return -EBUSY;
  199. }
  200. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0),
  201. (nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(0)) & ~0x00000003) |
  202. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  203. nv_wr32(dev, NV50_PDISPLAY_USER_PUT(0), 0);
  204. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), 0x01000003 |
  205. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  206. /* enable error reporting on the channel */
  207. nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << 0);
  208. evo->dma.max = (4096/4) - 2;
  209. evo->dma.put = 0;
  210. evo->dma.cur = evo->dma.put;
  211. evo->dma.free = evo->dma.max - evo->dma.cur;
  212. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  213. if (ret)
  214. return ret;
  215. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  216. OUT_RING(evo, 0);
  217. return 0;
  218. }
  219. static void
  220. nv50_evo_channel_fini(struct nouveau_channel *evo)
  221. {
  222. struct drm_device *dev = evo->dev;
  223. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(0), 0);
  224. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(0), 0x1e0000, 0)) {
  225. NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) == 0\n");
  226. NV_ERROR(dev, "0x610200 = 0x%08x\n",
  227. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(0)));
  228. }
  229. }
  230. int
  231. nv50_evo_init(struct drm_device *dev)
  232. {
  233. struct drm_nouveau_private *dev_priv = dev->dev_private;
  234. int ret;
  235. if (!dev_priv->evo) {
  236. ret = nv50_evo_channel_new(dev, &dev_priv->evo);
  237. if (ret)
  238. return ret;
  239. }
  240. return nv50_evo_channel_init(dev_priv->evo);
  241. }
  242. void
  243. nv50_evo_fini(struct drm_device *dev)
  244. {
  245. struct drm_nouveau_private *dev_priv = dev->dev_private;
  246. if (dev_priv->evo) {
  247. nv50_evo_channel_fini(dev_priv->evo);
  248. nv50_evo_channel_del(&dev_priv->evo);
  249. }
  250. }