nv40_fifo.c 10 KB

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