nv10_fifo.c 8.1 KB

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