nv04_fifo.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 "drm.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_ramht.h"
  30. #define NV04_RAMFC(c) (dev_priv->ramfc->pinst + ((c) * NV04_RAMFC__SIZE))
  31. #define NV04_RAMFC__SIZE 32
  32. #define NV04_RAMFC_DMA_PUT 0x00
  33. #define NV04_RAMFC_DMA_GET 0x04
  34. #define NV04_RAMFC_DMA_INSTANCE 0x08
  35. #define NV04_RAMFC_DMA_STATE 0x0C
  36. #define NV04_RAMFC_DMA_FETCH 0x10
  37. #define NV04_RAMFC_ENGINE 0x14
  38. #define NV04_RAMFC_PULL1_ENGINE 0x18
  39. #define RAMFC_WR(offset, val) nv_wo32(chan->ramfc, NV04_RAMFC_##offset, (val))
  40. #define RAMFC_RD(offset) nv_ro32(chan->ramfc, NV04_RAMFC_##offset)
  41. void
  42. nv04_fifo_disable(struct drm_device *dev)
  43. {
  44. uint32_t tmp;
  45. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUSH);
  46. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, tmp & ~1);
  47. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 0);
  48. tmp = nv_rd32(dev, NV03_PFIFO_CACHE1_PULL1);
  49. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, tmp & ~1);
  50. }
  51. void
  52. nv04_fifo_enable(struct drm_device *dev)
  53. {
  54. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 1);
  55. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
  56. }
  57. bool
  58. nv04_fifo_reassign(struct drm_device *dev, bool enable)
  59. {
  60. uint32_t reassign = nv_rd32(dev, NV03_PFIFO_CACHES);
  61. nv_wr32(dev, NV03_PFIFO_CACHES, enable ? 1 : 0);
  62. return (reassign == 1);
  63. }
  64. bool
  65. nv04_fifo_cache_pull(struct drm_device *dev, bool enable)
  66. {
  67. int pull = nv_mask(dev, NV04_PFIFO_CACHE1_PULL0, 1, enable);
  68. if (!enable) {
  69. /* In some cases the PFIFO puller may be left in an
  70. * inconsistent state if you try to stop it when it's
  71. * busy translating handles. Sometimes you get a
  72. * PFIFO_CACHE_ERROR, sometimes it just fails silently
  73. * sending incorrect instance offsets to PGRAPH after
  74. * it's started up again. To avoid the latter we
  75. * invalidate the most recently calculated instance.
  76. */
  77. if (!nv_wait(dev, NV04_PFIFO_CACHE1_PULL0,
  78. NV04_PFIFO_CACHE1_PULL0_HASH_BUSY, 0))
  79. NV_ERROR(dev, "Timeout idling the PFIFO puller.\n");
  80. if (nv_rd32(dev, NV04_PFIFO_CACHE1_PULL0) &
  81. NV04_PFIFO_CACHE1_PULL0_HASH_FAILED)
  82. nv_wr32(dev, NV03_PFIFO_INTR_0,
  83. NV_PFIFO_INTR_CACHE_ERROR);
  84. nv_wr32(dev, NV04_PFIFO_CACHE1_HASH, 0);
  85. }
  86. return pull & 1;
  87. }
  88. int
  89. nv04_fifo_channel_id(struct drm_device *dev)
  90. {
  91. return nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) &
  92. NV03_PFIFO_CACHE1_PUSH1_CHID_MASK;
  93. }
  94. #ifdef __BIG_ENDIAN
  95. #define DMA_FETCH_ENDIANNESS NV_PFIFO_CACHE1_BIG_ENDIAN
  96. #else
  97. #define DMA_FETCH_ENDIANNESS 0
  98. #endif
  99. int
  100. nv04_fifo_create_context(struct nouveau_channel *chan)
  101. {
  102. struct drm_device *dev = chan->dev;
  103. struct drm_nouveau_private *dev_priv = dev->dev_private;
  104. unsigned long flags;
  105. int ret;
  106. ret = nouveau_gpuobj_new_fake(dev, NV04_RAMFC(chan->id), ~0,
  107. NV04_RAMFC__SIZE,
  108. NVOBJ_FLAG_ZERO_ALLOC |
  109. NVOBJ_FLAG_ZERO_FREE,
  110. &chan->ramfc);
  111. if (ret)
  112. return ret;
  113. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  114. /* Setup initial state */
  115. RAMFC_WR(DMA_PUT, chan->pushbuf_base);
  116. RAMFC_WR(DMA_GET, chan->pushbuf_base);
  117. RAMFC_WR(DMA_INSTANCE, chan->pushbuf->pinst >> 4);
  118. RAMFC_WR(DMA_FETCH, (NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  119. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  120. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 |
  121. DMA_FETCH_ENDIANNESS));
  122. /* enable the fifo dma operation */
  123. nv_wr32(dev, NV04_PFIFO_MODE,
  124. nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id));
  125. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  126. return 0;
  127. }
  128. void
  129. nv04_fifo_destroy_context(struct nouveau_channel *chan)
  130. {
  131. struct drm_device *dev = chan->dev;
  132. nv_wr32(dev, NV04_PFIFO_MODE,
  133. nv_rd32(dev, NV04_PFIFO_MODE) & ~(1 << chan->id));
  134. nouveau_gpuobj_ref(NULL, &chan->ramfc);
  135. }
  136. static void
  137. nv04_fifo_do_load_context(struct drm_device *dev, int chid)
  138. {
  139. struct drm_nouveau_private *dev_priv = dev->dev_private;
  140. uint32_t fc = NV04_RAMFC(chid), tmp;
  141. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUT, nv_ri32(dev, fc + 0));
  142. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, nv_ri32(dev, fc + 4));
  143. tmp = nv_ri32(dev, fc + 8);
  144. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE, tmp & 0xFFFF);
  145. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT, tmp >> 16);
  146. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, nv_ri32(dev, fc + 12));
  147. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_FETCH, nv_ri32(dev, fc + 16));
  148. nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_ri32(dev, fc + 20));
  149. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL1, nv_ri32(dev, fc + 24));
  150. nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
  151. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
  152. }
  153. int
  154. nv04_fifo_load_context(struct nouveau_channel *chan)
  155. {
  156. uint32_t tmp;
  157. nv_wr32(chan->dev, NV03_PFIFO_CACHE1_PUSH1,
  158. NV03_PFIFO_CACHE1_PUSH1_DMA | chan->id);
  159. nv04_fifo_do_load_context(chan->dev, chan->id);
  160. nv_wr32(chan->dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
  161. /* Reset NV04_PFIFO_CACHE1_DMA_CTL_AT_INFO to INVALID */
  162. tmp = nv_rd32(chan->dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
  163. nv_wr32(chan->dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
  164. return 0;
  165. }
  166. int
  167. nv04_fifo_unload_context(struct drm_device *dev)
  168. {
  169. struct drm_nouveau_private *dev_priv = dev->dev_private;
  170. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  171. struct nouveau_channel *chan = NULL;
  172. uint32_t tmp;
  173. int chid;
  174. chid = pfifo->channel_id(dev);
  175. if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
  176. return 0;
  177. chan = dev_priv->fifos[chid];
  178. if (!chan) {
  179. NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
  180. return -EINVAL;
  181. }
  182. RAMFC_WR(DMA_PUT, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
  183. RAMFC_WR(DMA_GET, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  184. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT) << 16;
  185. tmp |= nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE);
  186. RAMFC_WR(DMA_INSTANCE, tmp);
  187. RAMFC_WR(DMA_STATE, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
  188. RAMFC_WR(DMA_FETCH, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH));
  189. RAMFC_WR(ENGINE, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
  190. RAMFC_WR(PULL1_ENGINE, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
  191. nv04_fifo_do_load_context(dev, pfifo->channels - 1);
  192. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  193. return 0;
  194. }
  195. static void
  196. nv04_fifo_init_reset(struct drm_device *dev)
  197. {
  198. nv_wr32(dev, NV03_PMC_ENABLE,
  199. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
  200. nv_wr32(dev, NV03_PMC_ENABLE,
  201. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
  202. nv_wr32(dev, 0x003224, 0x000f0078);
  203. nv_wr32(dev, 0x002044, 0x0101ffff);
  204. nv_wr32(dev, 0x002040, 0x000000ff);
  205. nv_wr32(dev, 0x002500, 0x00000000);
  206. nv_wr32(dev, 0x003000, 0x00000000);
  207. nv_wr32(dev, 0x003050, 0x00000000);
  208. nv_wr32(dev, 0x003200, 0x00000000);
  209. nv_wr32(dev, 0x003250, 0x00000000);
  210. nv_wr32(dev, 0x003220, 0x00000000);
  211. nv_wr32(dev, 0x003250, 0x00000000);
  212. nv_wr32(dev, 0x003270, 0x00000000);
  213. nv_wr32(dev, 0x003210, 0x00000000);
  214. }
  215. static void
  216. nv04_fifo_init_ramxx(struct drm_device *dev)
  217. {
  218. struct drm_nouveau_private *dev_priv = dev->dev_private;
  219. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  220. ((dev_priv->ramht->bits - 9) << 16) |
  221. (dev_priv->ramht->gpuobj->pinst >> 8));
  222. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
  223. nv_wr32(dev, NV03_PFIFO_RAMFC, dev_priv->ramfc->pinst >> 8);
  224. }
  225. static void
  226. nv04_fifo_init_intr(struct drm_device *dev)
  227. {
  228. nv_wr32(dev, 0x002100, 0xffffffff);
  229. nv_wr32(dev, 0x002140, 0xffffffff);
  230. }
  231. int
  232. nv04_fifo_init(struct drm_device *dev)
  233. {
  234. struct drm_nouveau_private *dev_priv = dev->dev_private;
  235. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  236. int i;
  237. nv04_fifo_init_reset(dev);
  238. nv04_fifo_init_ramxx(dev);
  239. nv04_fifo_do_load_context(dev, pfifo->channels - 1);
  240. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  241. nv04_fifo_init_intr(dev);
  242. pfifo->enable(dev);
  243. pfifo->reassign(dev, true);
  244. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  245. if (dev_priv->fifos[i]) {
  246. uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
  247. nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
  248. }
  249. }
  250. return 0;
  251. }