nv10_fifo.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 NV10_RAMFC(c) (dev_priv->ramfc->pinst + ((c) * NV10_RAMFC__SIZE))
  31. #define NV10_RAMFC__SIZE ((dev_priv->chipset) >= 0x17 ? 64 : 32)
  32. int
  33. nv10_fifo_channel_id(struct drm_device *dev)
  34. {
  35. return nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) &
  36. NV10_PFIFO_CACHE1_PUSH1_CHID_MASK;
  37. }
  38. int
  39. nv10_fifo_create_context(struct nouveau_channel *chan)
  40. {
  41. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  42. struct drm_device *dev = chan->dev;
  43. uint32_t fc = NV10_RAMFC(chan->id);
  44. int ret;
  45. ret = nouveau_gpuobj_new_fake(dev, NV10_RAMFC(chan->id), ~0,
  46. NV10_RAMFC__SIZE, NVOBJ_FLAG_ZERO_ALLOC |
  47. NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
  48. if (ret)
  49. return ret;
  50. /* Fill entries that are seen filled in dumps of nvidia driver just
  51. * after channel's is put into DMA mode
  52. */
  53. nv_wi32(dev, fc + 0, chan->pushbuf_base);
  54. nv_wi32(dev, fc + 4, chan->pushbuf_base);
  55. nv_wi32(dev, fc + 12, chan->pushbuf->pinst >> 4);
  56. nv_wi32(dev, fc + 20, NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  57. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  58. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 |
  59. #ifdef __BIG_ENDIAN
  60. NV_PFIFO_CACHE1_BIG_ENDIAN |
  61. #endif
  62. 0);
  63. /* enable the fifo dma operation */
  64. nv_wr32(dev, NV04_PFIFO_MODE,
  65. nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id));
  66. return 0;
  67. }
  68. void
  69. nv10_fifo_destroy_context(struct nouveau_channel *chan)
  70. {
  71. struct drm_device *dev = chan->dev;
  72. nv_wr32(dev, NV04_PFIFO_MODE,
  73. nv_rd32(dev, NV04_PFIFO_MODE) & ~(1 << chan->id));
  74. nouveau_gpuobj_ref(NULL, &chan->ramfc);
  75. }
  76. static void
  77. nv10_fifo_do_load_context(struct drm_device *dev, int chid)
  78. {
  79. struct drm_nouveau_private *dev_priv = dev->dev_private;
  80. uint32_t fc = NV10_RAMFC(chid), tmp;
  81. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUT, nv_ri32(dev, fc + 0));
  82. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, nv_ri32(dev, fc + 4));
  83. nv_wr32(dev, NV10_PFIFO_CACHE1_REF_CNT, nv_ri32(dev, fc + 8));
  84. tmp = nv_ri32(dev, fc + 12);
  85. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE, tmp & 0xFFFF);
  86. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT, tmp >> 16);
  87. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, nv_ri32(dev, fc + 16));
  88. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_FETCH, nv_ri32(dev, fc + 20));
  89. nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_ri32(dev, fc + 24));
  90. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL1, nv_ri32(dev, fc + 28));
  91. if (dev_priv->chipset < 0x17)
  92. goto out;
  93. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE, nv_ri32(dev, fc + 32));
  94. tmp = nv_ri32(dev, fc + 36);
  95. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP, tmp);
  96. nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT, nv_ri32(dev, fc + 40));
  97. nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, nv_ri32(dev, fc + 44));
  98. nv_wr32(dev, NV10_PFIFO_CACHE1_DMA_SUBROUTINE, nv_ri32(dev, fc + 48));
  99. out:
  100. nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
  101. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
  102. }
  103. int
  104. nv10_fifo_load_context(struct nouveau_channel *chan)
  105. {
  106. struct drm_device *dev = chan->dev;
  107. uint32_t tmp;
  108. nv10_fifo_do_load_context(dev, chan->id);
  109. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
  110. NV03_PFIFO_CACHE1_PUSH1_DMA | chan->id);
  111. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
  112. /* Reset NV04_PFIFO_CACHE1_DMA_CTL_AT_INFO to INVALID */
  113. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
  114. nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
  115. return 0;
  116. }
  117. int
  118. nv10_fifo_unload_context(struct drm_device *dev)
  119. {
  120. struct drm_nouveau_private *dev_priv = dev->dev_private;
  121. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  122. uint32_t fc, tmp;
  123. int chid;
  124. chid = pfifo->channel_id(dev);
  125. if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
  126. return 0;
  127. fc = NV10_RAMFC(chid);
  128. nv_wi32(dev, fc + 0, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
  129. nv_wi32(dev, fc + 4, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  130. nv_wi32(dev, fc + 8, nv_rd32(dev, NV10_PFIFO_CACHE1_REF_CNT));
  131. tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE) & 0xFFFF;
  132. tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT) << 16);
  133. nv_wi32(dev, fc + 12, tmp);
  134. nv_wi32(dev, fc + 16, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
  135. nv_wi32(dev, fc + 20, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH));
  136. nv_wi32(dev, fc + 24, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
  137. nv_wi32(dev, fc + 28, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
  138. if (dev_priv->chipset < 0x17)
  139. goto out;
  140. nv_wi32(dev, fc + 32, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE));
  141. tmp = nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP);
  142. nv_wi32(dev, fc + 36, tmp);
  143. nv_wi32(dev, fc + 40, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT));
  144. nv_wi32(dev, fc + 44, nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE));
  145. nv_wi32(dev, fc + 48, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
  146. out:
  147. nv10_fifo_do_load_context(dev, pfifo->channels - 1);
  148. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  149. return 0;
  150. }
  151. static void
  152. nv10_fifo_init_reset(struct drm_device *dev)
  153. {
  154. nv_wr32(dev, NV03_PMC_ENABLE,
  155. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
  156. nv_wr32(dev, NV03_PMC_ENABLE,
  157. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
  158. nv_wr32(dev, 0x003224, 0x000f0078);
  159. nv_wr32(dev, 0x002044, 0x0101ffff);
  160. nv_wr32(dev, 0x002040, 0x000000ff);
  161. nv_wr32(dev, 0x002500, 0x00000000);
  162. nv_wr32(dev, 0x003000, 0x00000000);
  163. nv_wr32(dev, 0x003050, 0x00000000);
  164. nv_wr32(dev, 0x003258, 0x00000000);
  165. nv_wr32(dev, 0x003210, 0x00000000);
  166. nv_wr32(dev, 0x003270, 0x00000000);
  167. }
  168. static void
  169. nv10_fifo_init_ramxx(struct drm_device *dev)
  170. {
  171. struct drm_nouveau_private *dev_priv = dev->dev_private;
  172. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  173. ((dev_priv->ramht->bits - 9) << 16) |
  174. (dev_priv->ramht->gpuobj->pinst >> 8));
  175. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
  176. if (dev_priv->chipset < 0x17) {
  177. nv_wr32(dev, NV03_PFIFO_RAMFC, dev_priv->ramfc->pinst >> 8);
  178. } else {
  179. nv_wr32(dev, NV03_PFIFO_RAMFC, (dev_priv->ramfc->pinst >> 8) |
  180. (1 << 16) /* 64 Bytes entry*/);
  181. /* XXX nvidia blob set bit 18, 21,23 for nv20 & nv30 */
  182. }
  183. }
  184. static void
  185. nv10_fifo_init_intr(struct drm_device *dev)
  186. {
  187. nv_wr32(dev, 0x002100, 0xffffffff);
  188. nv_wr32(dev, 0x002140, 0xffffffff);
  189. }
  190. int
  191. nv10_fifo_init(struct drm_device *dev)
  192. {
  193. struct drm_nouveau_private *dev_priv = dev->dev_private;
  194. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  195. int i;
  196. nv10_fifo_init_reset(dev);
  197. nv10_fifo_init_ramxx(dev);
  198. nv10_fifo_do_load_context(dev, pfifo->channels - 1);
  199. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
  200. nv10_fifo_init_intr(dev);
  201. pfifo->enable(dev);
  202. pfifo->reassign(dev, true);
  203. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  204. if (dev_priv->fifos[i]) {
  205. uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
  206. nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
  207. }
  208. }
  209. return 0;
  210. }