nv40_fifo.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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, NV03_PFIFO_CACHE1_GET, 0);
  104. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
  105. }
  106. int
  107. nv40_fifo_load_context(struct nouveau_channel *chan)
  108. {
  109. struct drm_device *dev = chan->dev;
  110. uint32_t tmp;
  111. nv40_fifo_do_load_context(dev, chan->id);
  112. /* Set channel active, and in DMA mode */
  113. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  114. NV40_PFIFO_CACHE1_PUSH1_DMA | chan->id);
  115. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
  116. /* Reset DMA_CTL_AT_INFO to INVALID */
  117. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
  118. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
  119. return 0;
  120. }
  121. int
  122. nv40_fifo_unload_context(struct drm_device *dev)
  123. {
  124. struct drm_nouveau_private *dev_priv = dev->dev_private;
  125. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  126. uint32_t fc, tmp;
  127. int chid;
  128. chid = pfifo->channel_id(dev);
  129. if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
  130. return 0;
  131. fc = NV40_RAMFC(chid);
  132. nv_wi32(dev, fc + 0, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
  133. nv_wi32(dev, fc + 4, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  134. nv_wi32(dev, fc + 8, nv_rd32(dev, NV10_PFIFO_CACHE1_REF_CNT));
  135. nv_wi32(dev, fc + 12, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE));
  136. nv_wi32(dev, fc + 16, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT));
  137. nv_wi32(dev, fc + 20, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
  138. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH);
  139. tmp |= nv_rd32(dev, 0x2058) & 0x30000000;
  140. nv_wi32(dev, fc + 24, tmp);
  141. nv_wi32(dev, fc + 28, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
  142. nv_wi32(dev, fc + 32, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
  143. nv_wi32(dev, fc + 36, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE));
  144. tmp = nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP);
  145. nv_wi32(dev, fc + 40, tmp);
  146. nv_wi32(dev, fc + 44, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT));
  147. nv_wi32(dev, fc + 48, nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE));
  148. /* NVIDIA read 0x3228 first, then write DMA_GET here.. maybe something
  149. * more involved depending on the value of 0x3228?
  150. */
  151. nv_wi32(dev, fc + 52, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  152. nv_wi32(dev, fc + 56, nv_rd32(dev, NV40_PFIFO_GRCTX_INSTANCE));
  153. nv_wi32(dev, fc + 60, nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & 0x1ffff);
  154. /* No idea what the below is for exactly, ripped from a mmio-trace */
  155. nv_wi32(dev, fc + 64, nv_rd32(dev, NV40_PFIFO_UNK32E4));
  156. /* NVIDIA do this next line twice.. bug? */
  157. nv_wi32(dev, fc + 68, nv_rd32(dev, 0x32e8));
  158. nv_wi32(dev, fc + 76, nv_rd32(dev, 0x2088));
  159. nv_wi32(dev, fc + 80, nv_rd32(dev, 0x3300));
  160. #if 0 /* no real idea which is PUT/GET in UNK_48.. */
  161. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_GET);
  162. tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_PUT) << 16);
  163. nv_wi32(dev, fc + 72, tmp);
  164. #endif
  165. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  166. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  167. NV40_PFIFO_CACHE1_PUSH1_DMA | (pfifo->channels - 1));
  168. return 0;
  169. }
  170. static void
  171. nv40_fifo_init_reset(struct drm_device *dev)
  172. {
  173. int i;
  174. nv_wr32(dev, NV03_PMC_ENABLE,
  175. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
  176. nv_wr32(dev, NV03_PMC_ENABLE,
  177. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
  178. nv_wr32(dev, 0x003224, 0x000f0078);
  179. nv_wr32(dev, 0x003210, 0x00000000);
  180. nv_wr32(dev, 0x003270, 0x00000000);
  181. nv_wr32(dev, 0x003240, 0x00000000);
  182. nv_wr32(dev, 0x003244, 0x00000000);
  183. nv_wr32(dev, 0x003258, 0x00000000);
  184. nv_wr32(dev, 0x002504, 0x00000000);
  185. for (i = 0; i < 16; i++)
  186. nv_wr32(dev, 0x002510 + (i * 4), 0x00000000);
  187. nv_wr32(dev, 0x00250c, 0x0000ffff);
  188. nv_wr32(dev, 0x002048, 0x00000000);
  189. nv_wr32(dev, 0x003228, 0x00000000);
  190. nv_wr32(dev, 0x0032e8, 0x00000000);
  191. nv_wr32(dev, 0x002410, 0x00000000);
  192. nv_wr32(dev, 0x002420, 0x00000000);
  193. nv_wr32(dev, 0x002058, 0x00000001);
  194. nv_wr32(dev, 0x00221c, 0x00000000);
  195. /* something with 0x2084, read/modify/write, no change */
  196. nv_wr32(dev, 0x002040, 0x000000ff);
  197. nv_wr32(dev, 0x002500, 0x00000000);
  198. nv_wr32(dev, 0x003200, 0x00000000);
  199. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, 0x2101ffff);
  200. }
  201. static void
  202. nv40_fifo_init_ramxx(struct drm_device *dev)
  203. {
  204. struct drm_nouveau_private *dev_priv = dev->dev_private;
  205. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  206. ((dev_priv->ramht->bits - 9) << 16) |
  207. (dev_priv->ramht->gpuobj->pinst >> 8));
  208. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
  209. switch (dev_priv->chipset) {
  210. case 0x47:
  211. case 0x49:
  212. case 0x4b:
  213. nv_wr32(dev, 0x2230, 1);
  214. break;
  215. default:
  216. break;
  217. }
  218. switch (dev_priv->chipset) {
  219. case 0x40:
  220. case 0x41:
  221. case 0x42:
  222. case 0x43:
  223. case 0x45:
  224. case 0x47:
  225. case 0x48:
  226. case 0x49:
  227. case 0x4b:
  228. nv_wr32(dev, NV40_PFIFO_RAMFC, 0x30002);
  229. break;
  230. default:
  231. nv_wr32(dev, 0x2230, 0);
  232. nv_wr32(dev, NV40_PFIFO_RAMFC,
  233. ((dev_priv->vram_size - 512 * 1024 +
  234. dev_priv->ramfc->pinst) >> 16) | (3 << 16));
  235. break;
  236. }
  237. }
  238. static void
  239. nv40_fifo_init_intr(struct drm_device *dev)
  240. {
  241. nouveau_irq_register(dev, 8, nv04_fifo_isr);
  242. nv_wr32(dev, 0x002100, 0xffffffff);
  243. nv_wr32(dev, 0x002140, 0xffffffff);
  244. }
  245. int
  246. nv40_fifo_init(struct drm_device *dev)
  247. {
  248. struct drm_nouveau_private *dev_priv = dev->dev_private;
  249. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  250. int i;
  251. nv40_fifo_init_reset(dev);
  252. nv40_fifo_init_ramxx(dev);
  253. nv40_fifo_do_load_context(dev, pfifo->channels - 1);
  254. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  255. nv40_fifo_init_intr(dev);
  256. pfifo->enable(dev);
  257. pfifo->reassign(dev, true);
  258. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  259. if (dev_priv->channels.ptr[i]) {
  260. uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
  261. nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
  262. }
  263. }
  264. return 0;
  265. }