nv40_fifo.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright (C) 2007 Ben Skeggs.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_drm.h"
  29. #include "nouveau_ramht.h"
  30. #define NV40_RAMFC(c) (dev_priv->ramfc->pinst + ((c) * NV40_RAMFC__SIZE))
  31. #define NV40_RAMFC__SIZE 128
  32. int
  33. nv40_fifo_create_context(struct nouveau_channel *chan)
  34. {
  35. struct drm_device *dev = chan->dev;
  36. struct drm_nouveau_private *dev_priv = dev->dev_private;
  37. uint32_t fc = NV40_RAMFC(chan->id);
  38. unsigned long flags;
  39. int ret;
  40. ret = nouveau_gpuobj_new_fake(dev, NV40_RAMFC(chan->id), ~0,
  41. NV40_RAMFC__SIZE, NVOBJ_FLAG_ZERO_ALLOC |
  42. NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
  43. if (ret)
  44. return ret;
  45. chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
  46. NV40_USER(chan->id), PAGE_SIZE);
  47. if (!chan->user)
  48. return -ENOMEM;
  49. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  50. nv_wi32(dev, fc + 0, chan->pushbuf_base);
  51. nv_wi32(dev, fc + 4, chan->pushbuf_base);
  52. nv_wi32(dev, fc + 12, chan->pushbuf->pinst >> 4);
  53. nv_wi32(dev, fc + 24, NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  54. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  55. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 |
  56. #ifdef __BIG_ENDIAN
  57. NV_PFIFO_CACHE1_BIG_ENDIAN |
  58. #endif
  59. 0x30000000 /* no idea.. */);
  60. nv_wi32(dev, fc + 60, 0x0001FFFF);
  61. /* enable the fifo dma operation */
  62. nv_wr32(dev, NV04_PFIFO_MODE,
  63. nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id));
  64. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  65. return 0;
  66. }
  67. static void
  68. nv40_fifo_do_load_context(struct drm_device *dev, int chid)
  69. {
  70. struct drm_nouveau_private *dev_priv = dev->dev_private;
  71. uint32_t fc = NV40_RAMFC(chid), tmp, tmp2;
  72. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUT, nv_ri32(dev, fc + 0));
  73. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, nv_ri32(dev, fc + 4));
  74. nv_wr32(dev, NV10_PFIFO_CACHE1_REF_CNT, nv_ri32(dev, fc + 8));
  75. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE, nv_ri32(dev, fc + 12));
  76. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT, nv_ri32(dev, fc + 16));
  77. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, nv_ri32(dev, fc + 20));
  78. /* No idea what 0x2058 is.. */
  79. tmp = nv_ri32(dev, fc + 24);
  80. tmp2 = nv_rd32(dev, 0x2058) & 0xFFF;
  81. tmp2 |= (tmp & 0x30000000);
  82. nv_wr32(dev, 0x2058, tmp2);
  83. tmp &= ~0x30000000;
  84. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_FETCH, tmp);
  85. nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_ri32(dev, fc + 28));
  86. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL1, nv_ri32(dev, fc + 32));
  87. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE, nv_ri32(dev, fc + 36));
  88. tmp = nv_ri32(dev, fc + 40);
  89. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP, tmp);
  90. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT, nv_ri32(dev, fc + 44));
  91. nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, nv_ri32(dev, fc + 48));
  92. nv_wr32(dev, NV10_PFIFO_CACHE1_DMA_SUBROUTINE, nv_ri32(dev, fc + 52));
  93. nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, nv_ri32(dev, fc + 56));
  94. /* Don't clobber the TIMEOUT_ENABLED flag when restoring from RAMFC */
  95. tmp = nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & ~0x1FFFF;
  96. tmp |= nv_ri32(dev, fc + 60) & 0x1FFFF;
  97. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, tmp);
  98. nv_wr32(dev, 0x32e4, nv_ri32(dev, fc + 64));
  99. /* NVIDIA does this next line twice... */
  100. nv_wr32(dev, 0x32e8, nv_ri32(dev, fc + 68));
  101. nv_wr32(dev, 0x2088, nv_ri32(dev, fc + 76));
  102. nv_wr32(dev, 0x3300, nv_ri32(dev, fc + 80));
  103. nv_wr32(dev, 0x330c, nv_ri32(dev, fc + 84));
  104. nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
  105. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
  106. }
  107. int
  108. nv40_fifo_load_context(struct nouveau_channel *chan)
  109. {
  110. struct drm_device *dev = chan->dev;
  111. uint32_t tmp;
  112. nv40_fifo_do_load_context(dev, chan->id);
  113. /* Set channel active, and in DMA mode */
  114. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  115. NV40_PFIFO_CACHE1_PUSH1_DMA | chan->id);
  116. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
  117. /* Reset DMA_CTL_AT_INFO to INVALID */
  118. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
  119. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
  120. return 0;
  121. }
  122. int
  123. nv40_fifo_unload_context(struct drm_device *dev)
  124. {
  125. struct drm_nouveau_private *dev_priv = dev->dev_private;
  126. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  127. uint32_t fc, tmp;
  128. int chid;
  129. chid = pfifo->channel_id(dev);
  130. if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
  131. return 0;
  132. fc = NV40_RAMFC(chid);
  133. nv_wi32(dev, fc + 0, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
  134. nv_wi32(dev, fc + 4, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  135. nv_wi32(dev, fc + 8, nv_rd32(dev, NV10_PFIFO_CACHE1_REF_CNT));
  136. nv_wi32(dev, fc + 12, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE));
  137. nv_wi32(dev, fc + 16, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT));
  138. nv_wi32(dev, fc + 20, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
  139. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH);
  140. tmp |= nv_rd32(dev, 0x2058) & 0x30000000;
  141. nv_wi32(dev, fc + 24, tmp);
  142. nv_wi32(dev, fc + 28, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
  143. nv_wi32(dev, fc + 32, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
  144. nv_wi32(dev, fc + 36, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE));
  145. tmp = nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP);
  146. nv_wi32(dev, fc + 40, tmp);
  147. nv_wi32(dev, fc + 44, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT));
  148. nv_wi32(dev, fc + 48, nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE));
  149. /* NVIDIA read 0x3228 first, then write DMA_GET here.. maybe something
  150. * more involved depending on the value of 0x3228?
  151. */
  152. nv_wi32(dev, fc + 52, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  153. nv_wi32(dev, fc + 56, nv_rd32(dev, NV40_PFIFO_GRCTX_INSTANCE));
  154. nv_wi32(dev, fc + 60, nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & 0x1ffff);
  155. /* No idea what the below is for exactly, ripped from a mmio-trace */
  156. nv_wi32(dev, fc + 64, nv_rd32(dev, NV40_PFIFO_UNK32E4));
  157. /* NVIDIA do this next line twice.. bug? */
  158. nv_wi32(dev, fc + 68, nv_rd32(dev, 0x32e8));
  159. nv_wi32(dev, fc + 76, nv_rd32(dev, 0x2088));
  160. nv_wi32(dev, fc + 80, nv_rd32(dev, 0x3300));
  161. #if 0 /* no real idea which is PUT/GET in UNK_48.. */
  162. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_GET);
  163. tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_PUT) << 16);
  164. nv_wi32(dev, fc + 72, tmp);
  165. #endif
  166. nv_wi32(dev, fc + 84, nv_rd32(dev, 0x330c));
  167. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  168. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  169. NV40_PFIFO_CACHE1_PUSH1_DMA | (pfifo->channels - 1));
  170. return 0;
  171. }
  172. static void
  173. nv40_fifo_init_reset(struct drm_device *dev)
  174. {
  175. int i;
  176. nv_wr32(dev, NV03_PMC_ENABLE,
  177. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
  178. nv_wr32(dev, NV03_PMC_ENABLE,
  179. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
  180. nv_wr32(dev, 0x003224, 0x000f0078);
  181. nv_wr32(dev, 0x003210, 0x00000000);
  182. nv_wr32(dev, 0x003270, 0x00000000);
  183. nv_wr32(dev, 0x003240, 0x00000000);
  184. nv_wr32(dev, 0x003244, 0x00000000);
  185. nv_wr32(dev, 0x003258, 0x00000000);
  186. nv_wr32(dev, 0x002504, 0x00000000);
  187. for (i = 0; i < 16; i++)
  188. nv_wr32(dev, 0x002510 + (i * 4), 0x00000000);
  189. nv_wr32(dev, 0x00250c, 0x0000ffff);
  190. nv_wr32(dev, 0x002048, 0x00000000);
  191. nv_wr32(dev, 0x003228, 0x00000000);
  192. nv_wr32(dev, 0x0032e8, 0x00000000);
  193. nv_wr32(dev, 0x002410, 0x00000000);
  194. nv_wr32(dev, 0x002420, 0x00000000);
  195. nv_wr32(dev, 0x002058, 0x00000001);
  196. nv_wr32(dev, 0x00221c, 0x00000000);
  197. /* something with 0x2084, read/modify/write, no change */
  198. nv_wr32(dev, 0x002040, 0x000000ff);
  199. nv_wr32(dev, 0x002500, 0x00000000);
  200. nv_wr32(dev, 0x003200, 0x00000000);
  201. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, 0x2101ffff);
  202. }
  203. static void
  204. nv40_fifo_init_ramxx(struct drm_device *dev)
  205. {
  206. struct drm_nouveau_private *dev_priv = dev->dev_private;
  207. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  208. ((dev_priv->ramht->bits - 9) << 16) |
  209. (dev_priv->ramht->gpuobj->pinst >> 8));
  210. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
  211. switch (dev_priv->chipset) {
  212. case 0x47:
  213. case 0x49:
  214. case 0x4b:
  215. nv_wr32(dev, 0x2230, 1);
  216. break;
  217. default:
  218. break;
  219. }
  220. switch (dev_priv->chipset) {
  221. case 0x40:
  222. case 0x41:
  223. case 0x42:
  224. case 0x43:
  225. case 0x45:
  226. case 0x47:
  227. case 0x48:
  228. case 0x49:
  229. case 0x4b:
  230. nv_wr32(dev, NV40_PFIFO_RAMFC, 0x30002);
  231. break;
  232. default:
  233. nv_wr32(dev, 0x2230, 0);
  234. nv_wr32(dev, NV40_PFIFO_RAMFC,
  235. ((dev_priv->vram_size - 512 * 1024 +
  236. dev_priv->ramfc->pinst) >> 16) | (3 << 16));
  237. break;
  238. }
  239. }
  240. static void
  241. nv40_fifo_init_intr(struct drm_device *dev)
  242. {
  243. nouveau_irq_register(dev, 8, nv04_fifo_isr);
  244. nv_wr32(dev, 0x002100, 0xffffffff);
  245. nv_wr32(dev, 0x002140, 0xffffffff);
  246. }
  247. int
  248. nv40_fifo_init(struct drm_device *dev)
  249. {
  250. struct drm_nouveau_private *dev_priv = dev->dev_private;
  251. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  252. int i;
  253. nv40_fifo_init_reset(dev);
  254. nv40_fifo_init_ramxx(dev);
  255. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  256. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  257. nv40_fifo_init_intr(dev);
  258. pfifo->enable(dev);
  259. pfifo->reassign(dev, true);
  260. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  261. if (dev_priv->channels.ptr[i]) {
  262. uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
  263. nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
  264. }
  265. }
  266. return 0;
  267. }