nv10_fifo.c 7.8 KB

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