nv40_fifo.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. #define NV40_RAMFC(c) (dev_priv->ramfc_offset + ((c) * NV40_RAMFC__SIZE))
  30. #define NV40_RAMFC__SIZE 128
  31. int
  32. nv40_fifo_create_context(struct nouveau_channel *chan)
  33. {
  34. struct drm_device *dev = chan->dev;
  35. struct drm_nouveau_private *dev_priv = dev->dev_private;
  36. uint32_t fc = NV40_RAMFC(chan->id);
  37. unsigned long flags;
  38. int ret;
  39. ret = nouveau_gpuobj_new_fake(dev, NV40_RAMFC(chan->id), ~0,
  40. NV40_RAMFC__SIZE, NVOBJ_FLAG_ZERO_ALLOC |
  41. NVOBJ_FLAG_ZERO_FREE, NULL, &chan->ramfc);
  42. if (ret)
  43. return ret;
  44. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  45. dev_priv->engine.instmem.prepare_access(dev, true);
  46. nv_wi32(dev, fc + 0, chan->pushbuf_base);
  47. nv_wi32(dev, fc + 4, chan->pushbuf_base);
  48. nv_wi32(dev, fc + 12, chan->pushbuf->instance >> 4);
  49. nv_wi32(dev, fc + 24, NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  50. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  51. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 |
  52. #ifdef __BIG_ENDIAN
  53. NV_PFIFO_CACHE1_BIG_ENDIAN |
  54. #endif
  55. 0x30000000 /* no idea.. */);
  56. nv_wi32(dev, fc + 56, chan->ramin_grctx->instance >> 4);
  57. nv_wi32(dev, fc + 60, 0x0001FFFF);
  58. dev_priv->engine.instmem.finish_access(dev);
  59. /* enable the fifo dma operation */
  60. nv_wr32(dev, NV04_PFIFO_MODE,
  61. nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id));
  62. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  63. return 0;
  64. }
  65. void
  66. nv40_fifo_destroy_context(struct nouveau_channel *chan)
  67. {
  68. struct drm_device *dev = chan->dev;
  69. nv_wr32(dev, NV04_PFIFO_MODE,
  70. nv_rd32(dev, NV04_PFIFO_MODE) & ~(1 << chan->id));
  71. if (chan->ramfc)
  72. nouveau_gpuobj_ref_del(dev, &chan->ramfc);
  73. }
  74. static void
  75. nv40_fifo_do_load_context(struct drm_device *dev, int chid)
  76. {
  77. struct drm_nouveau_private *dev_priv = dev->dev_private;
  78. uint32_t fc = NV40_RAMFC(chid), tmp, tmp2;
  79. dev_priv->engine.instmem.prepare_access(dev, false);
  80. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUT, nv_ri32(dev, fc + 0));
  81. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, nv_ri32(dev, fc + 4));
  82. nv_wr32(dev, NV10_PFIFO_CACHE1_REF_CNT, nv_ri32(dev, fc + 8));
  83. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE, nv_ri32(dev, fc + 12));
  84. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT, nv_ri32(dev, fc + 16));
  85. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, nv_ri32(dev, fc + 20));
  86. /* No idea what 0x2058 is.. */
  87. tmp = nv_ri32(dev, fc + 24);
  88. tmp2 = nv_rd32(dev, 0x2058) & 0xFFF;
  89. tmp2 |= (tmp & 0x30000000);
  90. nv_wr32(dev, 0x2058, tmp2);
  91. tmp &= ~0x30000000;
  92. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_FETCH, tmp);
  93. nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_ri32(dev, fc + 28));
  94. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL1, nv_ri32(dev, fc + 32));
  95. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE, nv_ri32(dev, fc + 36));
  96. tmp = nv_ri32(dev, fc + 40);
  97. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP, tmp);
  98. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT, nv_ri32(dev, fc + 44));
  99. nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, nv_ri32(dev, fc + 48));
  100. nv_wr32(dev, NV10_PFIFO_CACHE1_DMA_SUBROUTINE, nv_ri32(dev, fc + 52));
  101. nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, nv_ri32(dev, fc + 56));
  102. /* Don't clobber the TIMEOUT_ENABLED flag when restoring from RAMFC */
  103. tmp = nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & ~0x1FFFF;
  104. tmp |= nv_ri32(dev, fc + 60) & 0x1FFFF;
  105. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, tmp);
  106. nv_wr32(dev, 0x32e4, nv_ri32(dev, fc + 64));
  107. /* NVIDIA does this next line twice... */
  108. nv_wr32(dev, 0x32e8, nv_ri32(dev, fc + 68));
  109. nv_wr32(dev, 0x2088, nv_ri32(dev, fc + 76));
  110. nv_wr32(dev, 0x3300, nv_ri32(dev, fc + 80));
  111. dev_priv->engine.instmem.finish_access(dev);
  112. nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
  113. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
  114. }
  115. int
  116. nv40_fifo_load_context(struct nouveau_channel *chan)
  117. {
  118. struct drm_device *dev = chan->dev;
  119. uint32_t tmp;
  120. nv40_fifo_do_load_context(dev, chan->id);
  121. /* Set channel active, and in DMA mode */
  122. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  123. NV40_PFIFO_CACHE1_PUSH1_DMA | chan->id);
  124. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
  125. /* Reset DMA_CTL_AT_INFO to INVALID */
  126. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
  127. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
  128. return 0;
  129. }
  130. int
  131. nv40_fifo_unload_context(struct drm_device *dev)
  132. {
  133. struct drm_nouveau_private *dev_priv = dev->dev_private;
  134. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  135. uint32_t fc, tmp;
  136. int chid;
  137. chid = pfifo->channel_id(dev);
  138. if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
  139. return 0;
  140. fc = NV40_RAMFC(chid);
  141. dev_priv->engine.instmem.prepare_access(dev, true);
  142. nv_wi32(dev, fc + 0, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
  143. nv_wi32(dev, fc + 4, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  144. nv_wi32(dev, fc + 8, nv_rd32(dev, NV10_PFIFO_CACHE1_REF_CNT));
  145. nv_wi32(dev, fc + 12, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE));
  146. nv_wi32(dev, fc + 16, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT));
  147. nv_wi32(dev, fc + 20, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
  148. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH);
  149. tmp |= nv_rd32(dev, 0x2058) & 0x30000000;
  150. nv_wi32(dev, fc + 24, tmp);
  151. nv_wi32(dev, fc + 28, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
  152. nv_wi32(dev, fc + 32, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
  153. nv_wi32(dev, fc + 36, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE));
  154. tmp = nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP);
  155. nv_wi32(dev, fc + 40, tmp);
  156. nv_wi32(dev, fc + 44, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT));
  157. nv_wi32(dev, fc + 48, nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE));
  158. /* NVIDIA read 0x3228 first, then write DMA_GET here.. maybe something
  159. * more involved depending on the value of 0x3228?
  160. */
  161. nv_wi32(dev, fc + 52, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  162. nv_wi32(dev, fc + 56, nv_rd32(dev, NV40_PFIFO_GRCTX_INSTANCE));
  163. nv_wi32(dev, fc + 60, nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & 0x1ffff);
  164. /* No idea what the below is for exactly, ripped from a mmio-trace */
  165. nv_wi32(dev, fc + 64, nv_rd32(dev, NV40_PFIFO_UNK32E4));
  166. /* NVIDIA do this next line twice.. bug? */
  167. nv_wi32(dev, fc + 68, nv_rd32(dev, 0x32e8));
  168. nv_wi32(dev, fc + 76, nv_rd32(dev, 0x2088));
  169. nv_wi32(dev, fc + 80, nv_rd32(dev, 0x3300));
  170. #if 0 /* no real idea which is PUT/GET in UNK_48.. */
  171. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_GET);
  172. tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_PUT) << 16);
  173. nv_wi32(dev, fc + 72, tmp);
  174. #endif
  175. dev_priv->engine.instmem.finish_access(dev);
  176. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  177. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  178. NV40_PFIFO_CACHE1_PUSH1_DMA | (pfifo->channels - 1));
  179. return 0;
  180. }
  181. static void
  182. nv40_fifo_init_reset(struct drm_device *dev)
  183. {
  184. int i;
  185. nv_wr32(dev, NV03_PMC_ENABLE,
  186. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
  187. nv_wr32(dev, NV03_PMC_ENABLE,
  188. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
  189. nv_wr32(dev, 0x003224, 0x000f0078);
  190. nv_wr32(dev, 0x003210, 0x00000000);
  191. nv_wr32(dev, 0x003270, 0x00000000);
  192. nv_wr32(dev, 0x003240, 0x00000000);
  193. nv_wr32(dev, 0x003244, 0x00000000);
  194. nv_wr32(dev, 0x003258, 0x00000000);
  195. nv_wr32(dev, 0x002504, 0x00000000);
  196. for (i = 0; i < 16; i++)
  197. nv_wr32(dev, 0x002510 + (i * 4), 0x00000000);
  198. nv_wr32(dev, 0x00250c, 0x0000ffff);
  199. nv_wr32(dev, 0x002048, 0x00000000);
  200. nv_wr32(dev, 0x003228, 0x00000000);
  201. nv_wr32(dev, 0x0032e8, 0x00000000);
  202. nv_wr32(dev, 0x002410, 0x00000000);
  203. nv_wr32(dev, 0x002420, 0x00000000);
  204. nv_wr32(dev, 0x002058, 0x00000001);
  205. nv_wr32(dev, 0x00221c, 0x00000000);
  206. /* something with 0x2084, read/modify/write, no change */
  207. nv_wr32(dev, 0x002040, 0x000000ff);
  208. nv_wr32(dev, 0x002500, 0x00000000);
  209. nv_wr32(dev, 0x003200, 0x00000000);
  210. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, 0x2101ffff);
  211. }
  212. static void
  213. nv40_fifo_init_ramxx(struct drm_device *dev)
  214. {
  215. struct drm_nouveau_private *dev_priv = dev->dev_private;
  216. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  217. ((dev_priv->ramht_bits - 9) << 16) |
  218. (dev_priv->ramht_offset >> 8));
  219. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro_offset>>8);
  220. switch (dev_priv->chipset) {
  221. case 0x47:
  222. case 0x49:
  223. case 0x4b:
  224. nv_wr32(dev, 0x2230, 1);
  225. break;
  226. default:
  227. break;
  228. }
  229. switch (dev_priv->chipset) {
  230. case 0x40:
  231. case 0x41:
  232. case 0x42:
  233. case 0x43:
  234. case 0x45:
  235. case 0x47:
  236. case 0x48:
  237. case 0x49:
  238. case 0x4b:
  239. nv_wr32(dev, NV40_PFIFO_RAMFC, 0x30002);
  240. break;
  241. default:
  242. nv_wr32(dev, 0x2230, 0);
  243. nv_wr32(dev, NV40_PFIFO_RAMFC,
  244. ((nouveau_mem_fb_amount(dev) - 512 * 1024 +
  245. dev_priv->ramfc_offset) >> 16) | (3 << 16));
  246. break;
  247. }
  248. }
  249. static void
  250. nv40_fifo_init_intr(struct drm_device *dev)
  251. {
  252. nv_wr32(dev, 0x002100, 0xffffffff);
  253. nv_wr32(dev, 0x002140, 0xffffffff);
  254. }
  255. int
  256. nv40_fifo_init(struct drm_device *dev)
  257. {
  258. struct drm_nouveau_private *dev_priv = dev->dev_private;
  259. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  260. int i;
  261. nv40_fifo_init_reset(dev);
  262. nv40_fifo_init_ramxx(dev);
  263. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  264. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  265. nv40_fifo_init_intr(dev);
  266. pfifo->enable(dev);
  267. pfifo->reassign(dev, true);
  268. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  269. if (dev_priv->fifos[i]) {
  270. uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
  271. nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
  272. }
  273. }
  274. return 0;
  275. }