nv50_fifo.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. #include "nouveau_vm.h"
  31. static void
  32. nv50_fifo_playlist_update(struct drm_device *dev)
  33. {
  34. struct drm_nouveau_private *dev_priv = dev->dev_private;
  35. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  36. struct nouveau_gpuobj *cur;
  37. int i, p;
  38. NV_DEBUG(dev, "\n");
  39. cur = pfifo->playlist[pfifo->cur_playlist];
  40. pfifo->cur_playlist = !pfifo->cur_playlist;
  41. for (i = 0, p = 0; i < pfifo->channels; i++) {
  42. if (nv_rd32(dev, 0x002600 + (i * 4)) & 0x80000000)
  43. nv_wo32(cur, p++ * 4, i);
  44. }
  45. dev_priv->engine.instmem.flush(dev);
  46. nv_wr32(dev, 0x32f4, cur->vinst >> 12);
  47. nv_wr32(dev, 0x32ec, p);
  48. nv_wr32(dev, 0x2500, 0x101);
  49. }
  50. static void
  51. nv50_fifo_channel_enable(struct drm_device *dev, int channel)
  52. {
  53. struct drm_nouveau_private *dev_priv = dev->dev_private;
  54. struct nouveau_channel *chan = dev_priv->channels.ptr[channel];
  55. uint32_t inst;
  56. NV_DEBUG(dev, "ch%d\n", channel);
  57. if (dev_priv->chipset == 0x50)
  58. inst = chan->ramfc->vinst >> 12;
  59. else
  60. inst = chan->ramfc->vinst >> 8;
  61. nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst |
  62. NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED);
  63. }
  64. static void
  65. nv50_fifo_channel_disable(struct drm_device *dev, int channel)
  66. {
  67. struct drm_nouveau_private *dev_priv = dev->dev_private;
  68. uint32_t inst;
  69. NV_DEBUG(dev, "ch%d\n", channel);
  70. if (dev_priv->chipset == 0x50)
  71. inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80;
  72. else
  73. inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84;
  74. nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst);
  75. }
  76. static void
  77. nv50_fifo_init_reset(struct drm_device *dev)
  78. {
  79. uint32_t pmc_e = NV_PMC_ENABLE_PFIFO;
  80. NV_DEBUG(dev, "\n");
  81. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
  82. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
  83. }
  84. static void
  85. nv50_fifo_init_intr(struct drm_device *dev)
  86. {
  87. NV_DEBUG(dev, "\n");
  88. nouveau_irq_register(dev, 8, nv04_fifo_isr);
  89. nv_wr32(dev, NV03_PFIFO_INTR_0, 0xFFFFFFFF);
  90. nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF);
  91. }
  92. static void
  93. nv50_fifo_init_context_table(struct drm_device *dev)
  94. {
  95. struct drm_nouveau_private *dev_priv = dev->dev_private;
  96. int i;
  97. NV_DEBUG(dev, "\n");
  98. for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) {
  99. if (dev_priv->channels.ptr[i])
  100. nv50_fifo_channel_enable(dev, i);
  101. else
  102. nv50_fifo_channel_disable(dev, i);
  103. }
  104. nv50_fifo_playlist_update(dev);
  105. }
  106. static void
  107. nv50_fifo_init_regs__nv(struct drm_device *dev)
  108. {
  109. NV_DEBUG(dev, "\n");
  110. nv_wr32(dev, 0x250c, 0x6f3cfc34);
  111. }
  112. static void
  113. nv50_fifo_init_regs(struct drm_device *dev)
  114. {
  115. NV_DEBUG(dev, "\n");
  116. nv_wr32(dev, 0x2500, 0);
  117. nv_wr32(dev, 0x3250, 0);
  118. nv_wr32(dev, 0x3220, 0);
  119. nv_wr32(dev, 0x3204, 0);
  120. nv_wr32(dev, 0x3210, 0);
  121. nv_wr32(dev, 0x3270, 0);
  122. nv_wr32(dev, 0x2044, 0x01003fff);
  123. /* Enable dummy channels setup by nv50_instmem.c */
  124. nv50_fifo_channel_enable(dev, 0);
  125. nv50_fifo_channel_enable(dev, 127);
  126. }
  127. int
  128. nv50_fifo_init(struct drm_device *dev)
  129. {
  130. struct drm_nouveau_private *dev_priv = dev->dev_private;
  131. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  132. int ret;
  133. NV_DEBUG(dev, "\n");
  134. if (pfifo->playlist[0]) {
  135. pfifo->cur_playlist = !pfifo->cur_playlist;
  136. goto just_reset;
  137. }
  138. ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
  139. NVOBJ_FLAG_ZERO_ALLOC,
  140. &pfifo->playlist[0]);
  141. if (ret) {
  142. NV_ERROR(dev, "error creating playlist 0: %d\n", ret);
  143. return ret;
  144. }
  145. ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
  146. NVOBJ_FLAG_ZERO_ALLOC,
  147. &pfifo->playlist[1]);
  148. if (ret) {
  149. nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
  150. NV_ERROR(dev, "error creating playlist 1: %d\n", ret);
  151. return ret;
  152. }
  153. just_reset:
  154. nv50_fifo_init_reset(dev);
  155. nv50_fifo_init_intr(dev);
  156. nv50_fifo_init_context_table(dev);
  157. nv50_fifo_init_regs__nv(dev);
  158. nv50_fifo_init_regs(dev);
  159. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 1);
  160. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
  161. nv_wr32(dev, NV03_PFIFO_CACHES, 1);
  162. return 0;
  163. }
  164. void
  165. nv50_fifo_takedown(struct drm_device *dev)
  166. {
  167. struct drm_nouveau_private *dev_priv = dev->dev_private;
  168. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  169. NV_DEBUG(dev, "\n");
  170. if (!pfifo->playlist[0])
  171. return;
  172. nv_wr32(dev, 0x2140, 0x00000000);
  173. nouveau_irq_unregister(dev, 8);
  174. nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
  175. nouveau_gpuobj_ref(NULL, &pfifo->playlist[1]);
  176. }
  177. int
  178. nv50_fifo_create_context(struct nouveau_channel *chan)
  179. {
  180. struct drm_device *dev = chan->dev;
  181. struct drm_nouveau_private *dev_priv = dev->dev_private;
  182. struct nouveau_gpuobj *ramfc = NULL;
  183. uint64_t ib_offset = chan->pushbuf_base + chan->dma.ib_base * 4;
  184. unsigned long flags;
  185. int ret;
  186. NV_DEBUG(dev, "ch%d\n", chan->id);
  187. if (dev_priv->chipset == 0x50) {
  188. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
  189. chan->ramin->vinst, 0x100,
  190. NVOBJ_FLAG_ZERO_ALLOC |
  191. NVOBJ_FLAG_ZERO_FREE,
  192. &chan->ramfc);
  193. if (ret)
  194. return ret;
  195. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst + 0x0400,
  196. chan->ramin->vinst + 0x0400,
  197. 4096, 0, &chan->cache);
  198. if (ret)
  199. return ret;
  200. } else {
  201. ret = nouveau_gpuobj_new(dev, chan, 0x100, 256,
  202. NVOBJ_FLAG_ZERO_ALLOC |
  203. NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
  204. if (ret)
  205. return ret;
  206. ret = nouveau_gpuobj_new(dev, chan, 4096, 1024,
  207. 0, &chan->cache);
  208. if (ret)
  209. return ret;
  210. }
  211. ramfc = chan->ramfc;
  212. chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
  213. NV50_USER(chan->id), PAGE_SIZE);
  214. if (!chan->user)
  215. return -ENOMEM;
  216. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  217. nv_wo32(ramfc, 0x48, chan->pushbuf->cinst >> 4);
  218. nv_wo32(ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
  219. (4 << 24) /* SEARCH_FULL */ |
  220. (chan->ramht->gpuobj->cinst >> 4));
  221. nv_wo32(ramfc, 0x44, 0x01003fff);
  222. nv_wo32(ramfc, 0x60, 0x7fffffff);
  223. nv_wo32(ramfc, 0x40, 0x00000000);
  224. nv_wo32(ramfc, 0x7c, 0x30000001);
  225. nv_wo32(ramfc, 0x78, 0x00000000);
  226. nv_wo32(ramfc, 0x3c, 0x403f6078);
  227. nv_wo32(ramfc, 0x50, lower_32_bits(ib_offset));
  228. nv_wo32(ramfc, 0x54, upper_32_bits(ib_offset) |
  229. drm_order(chan->dma.ib_max + 1) << 16);
  230. if (dev_priv->chipset != 0x50) {
  231. nv_wo32(chan->ramin, 0, chan->id);
  232. nv_wo32(chan->ramin, 4, chan->ramfc->vinst >> 8);
  233. nv_wo32(ramfc, 0x88, chan->cache->vinst >> 10);
  234. nv_wo32(ramfc, 0x98, chan->ramin->vinst >> 12);
  235. }
  236. dev_priv->engine.instmem.flush(dev);
  237. nv50_fifo_channel_enable(dev, chan->id);
  238. nv50_fifo_playlist_update(dev);
  239. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  240. return 0;
  241. }
  242. static bool
  243. nv50_fifo_wait_kickoff(void *data)
  244. {
  245. struct drm_nouveau_private *dev_priv = data;
  246. struct drm_device *dev = dev_priv->dev;
  247. if (dev_priv->chipset == 0x50) {
  248. u32 me_enable = nv_mask(dev, 0x00b860, 0x00000001, 0x00000001);
  249. nv_wr32(dev, 0x00b860, me_enable);
  250. }
  251. return nv_rd32(dev, 0x0032fc) != 0xffffffff;
  252. }
  253. void
  254. nv50_fifo_destroy_context(struct nouveau_channel *chan)
  255. {
  256. struct drm_device *dev = chan->dev;
  257. struct drm_nouveau_private *dev_priv = dev->dev_private;
  258. unsigned long flags;
  259. /* remove channel from playlist, will context switch if active */
  260. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  261. nv_mask(dev, 0x002600 + (chan->id * 4), 0x80000000, 0x00000000);
  262. nv50_fifo_playlist_update(dev);
  263. /* tell any engines on this channel to unload their contexts */
  264. nv_wr32(dev, 0x0032fc, chan->ramin->vinst >> 12);
  265. if (!nv_wait_cb(dev, nv50_fifo_wait_kickoff, dev_priv))
  266. NV_INFO(dev, "PFIFO: channel %d unload timeout\n", chan->id);
  267. nv_wr32(dev, 0x002600 + (chan->id * 4), 0x00000000);
  268. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  269. /* clean up */
  270. if (chan->user) {
  271. iounmap(chan->user);
  272. chan->user = NULL;
  273. }
  274. nouveau_gpuobj_ref(NULL, &chan->ramfc);
  275. nouveau_gpuobj_ref(NULL, &chan->cache);
  276. }
  277. int
  278. nv50_fifo_load_context(struct nouveau_channel *chan)
  279. {
  280. return 0;
  281. }
  282. int
  283. nv50_fifo_unload_context(struct drm_device *dev)
  284. {
  285. struct drm_nouveau_private *dev_priv = dev->dev_private;
  286. int i;
  287. /* set playlist length to zero, fifo will unload context */
  288. nv_wr32(dev, 0x0032ec, 0);
  289. /* tell all connected engines to unload their contexts */
  290. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  291. struct nouveau_channel *chan = dev_priv->channels.ptr[i];
  292. if (chan)
  293. nv_wr32(dev, 0x0032fc, chan->ramin->vinst >> 12);
  294. if (!nv_wait_cb(dev, nv50_fifo_wait_kickoff, dev_priv)) {
  295. NV_INFO(dev, "PFIFO: channel %d unload timeout\n", i);
  296. return -EBUSY;
  297. }
  298. }
  299. return 0;
  300. }
  301. void
  302. nv50_fifo_tlb_flush(struct drm_device *dev)
  303. {
  304. nv50_vm_flush_engine(dev, 5);
  305. }