nv84_fifo.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2012 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_fifo.h"
  30. #include "nouveau_ramht.h"
  31. #include "nouveau_vm.h"
  32. struct nv84_fifo_priv {
  33. struct nouveau_fifo_priv base;
  34. struct nouveau_gpuobj *playlist[2];
  35. int cur_playlist;
  36. };
  37. struct nv84_fifo_chan {
  38. struct nouveau_fifo_chan base;
  39. struct nouveau_gpuobj *ramfc;
  40. struct nouveau_gpuobj *cache;
  41. };
  42. static int
  43. nv84_fifo_context_new(struct nouveau_channel *chan, int engine)
  44. {
  45. struct nv84_fifo_priv *priv = nv_engine(chan->dev, engine);
  46. struct nv84_fifo_chan *fctx;
  47. struct drm_device *dev = chan->dev;
  48. struct drm_nouveau_private *dev_priv = dev->dev_private;
  49. u64 ib_offset = chan->pushbuf_base + chan->dma.ib_base * 4;
  50. u64 instance;
  51. unsigned long flags;
  52. int ret;
  53. fctx = chan->engctx[engine] = kzalloc(sizeof(*fctx), GFP_KERNEL);
  54. if (!fctx)
  55. return -ENOMEM;
  56. atomic_inc(&chan->vm->engref[engine]);
  57. chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
  58. NV50_USER(chan->id), PAGE_SIZE);
  59. if (!chan->user) {
  60. ret = -ENOMEM;
  61. goto error;
  62. }
  63. ret = nouveau_gpuobj_new(dev, chan, 256, 256, NVOBJ_FLAG_ZERO_ALLOC |
  64. NVOBJ_FLAG_ZERO_FREE, &fctx->ramfc);
  65. if (ret)
  66. goto error;
  67. instance = fctx->ramfc->vinst >> 8;
  68. ret = nouveau_gpuobj_new(dev, chan, 4096, 1024, 0, &fctx->cache);
  69. if (ret)
  70. goto error;
  71. nv_wo32(fctx->ramfc, 0x3c, 0x403f6078);
  72. nv_wo32(fctx->ramfc, 0x40, 0x00000000);
  73. nv_wo32(fctx->ramfc, 0x44, 0x01003fff);
  74. nv_wo32(fctx->ramfc, 0x48, chan->pushbuf->cinst >> 4);
  75. nv_wo32(fctx->ramfc, 0x50, lower_32_bits(ib_offset));
  76. nv_wo32(fctx->ramfc, 0x54, upper_32_bits(ib_offset) |
  77. drm_order(chan->dma.ib_max + 1) << 16);
  78. nv_wo32(fctx->ramfc, 0x60, 0x7fffffff);
  79. nv_wo32(fctx->ramfc, 0x78, 0x00000000);
  80. nv_wo32(fctx->ramfc, 0x7c, 0x30000001);
  81. nv_wo32(fctx->ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
  82. (4 << 24) /* SEARCH_FULL */ |
  83. (chan->ramht->gpuobj->cinst >> 4));
  84. nv_wo32(fctx->ramfc, 0x88, fctx->cache->vinst >> 10);
  85. nv_wo32(fctx->ramfc, 0x98, chan->ramin->vinst >> 12);
  86. nv_wo32(chan->ramin, 0x00, chan->id);
  87. nv_wo32(chan->ramin, 0x04, fctx->ramfc->vinst >> 8);
  88. dev_priv->engine.instmem.flush(dev);
  89. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  90. nv_wr32(dev, 0x002600 + (chan->id * 4), 0x80000000 | instance);
  91. nv50_fifo_playlist_update(dev);
  92. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  93. error:
  94. if (ret)
  95. priv->base.base.context_del(chan, engine);
  96. return ret;
  97. }
  98. static void
  99. nv84_fifo_context_del(struct nouveau_channel *chan, int engine)
  100. {
  101. struct nv84_fifo_chan *fctx = chan->engctx[engine];
  102. struct drm_device *dev = chan->dev;
  103. struct drm_nouveau_private *dev_priv = dev->dev_private;
  104. unsigned long flags;
  105. /* remove channel from playlist, will context switch if active */
  106. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  107. nv_mask(dev, 0x002600 + (chan->id * 4), 0x80000000, 0x00000000);
  108. nv50_fifo_playlist_update(dev);
  109. /* tell any engines on this channel to unload their contexts */
  110. nv_wr32(dev, 0x0032fc, chan->ramin->vinst >> 12);
  111. if (!nv_wait_ne(dev, 0x0032fc, 0xffffffff, 0xffffffff))
  112. NV_INFO(dev, "PFIFO: channel %d unload timeout\n", chan->id);
  113. nv_wr32(dev, 0x002600 + (chan->id * 4), 0x00000000);
  114. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  115. /* clean up */
  116. if (chan->user) {
  117. iounmap(chan->user);
  118. chan->user = NULL;
  119. }
  120. nouveau_gpuobj_ref(NULL, &fctx->ramfc);
  121. nouveau_gpuobj_ref(NULL, &fctx->cache);
  122. atomic_dec(&chan->vm->engref[engine]);
  123. chan->engctx[engine] = NULL;
  124. kfree(fctx);
  125. }
  126. static int
  127. nv84_fifo_init(struct drm_device *dev, int engine)
  128. {
  129. struct drm_nouveau_private *dev_priv = dev->dev_private;
  130. struct nv84_fifo_chan *fctx;
  131. u32 instance;
  132. int i;
  133. nv_mask(dev, 0x000200, 0x00000100, 0x00000000);
  134. nv_mask(dev, 0x000200, 0x00000100, 0x00000100);
  135. nv_wr32(dev, 0x00250c, 0x6f3cfc34);
  136. nv_wr32(dev, 0x002044, 0x01003fff);
  137. nv_wr32(dev, 0x002100, 0xffffffff);
  138. nv_wr32(dev, 0x002140, 0xffffffff);
  139. for (i = 0; i < 128; i++) {
  140. struct nouveau_channel *chan = dev_priv->channels.ptr[i];
  141. if (chan && (fctx = chan->engctx[engine]))
  142. instance = 0x80000000 | fctx->ramfc->vinst >> 8;
  143. else
  144. instance = 0x00000000;
  145. nv_wr32(dev, 0x002600 + (i * 4), instance);
  146. }
  147. nv50_fifo_playlist_update(dev);
  148. nv_wr32(dev, 0x003200, 1);
  149. nv_wr32(dev, 0x003250, 1);
  150. nv_wr32(dev, 0x002500, 1);
  151. return 0;
  152. }
  153. static int
  154. nv84_fifo_fini(struct drm_device *dev, int engine, bool suspend)
  155. {
  156. struct drm_nouveau_private *dev_priv = dev->dev_private;
  157. struct nv84_fifo_priv *priv = nv_engine(dev, engine);
  158. int i;
  159. /* set playlist length to zero, fifo will unload context */
  160. nv_wr32(dev, 0x0032ec, 0);
  161. /* tell all connected engines to unload their contexts */
  162. for (i = 0; i < priv->base.channels; i++) {
  163. struct nouveau_channel *chan = dev_priv->channels.ptr[i];
  164. if (chan)
  165. nv_wr32(dev, 0x0032fc, chan->ramin->vinst >> 12);
  166. if (!nv_wait_ne(dev, 0x0032fc, 0xffffffff, 0xffffffff)) {
  167. NV_INFO(dev, "PFIFO: channel %d unload timeout\n", i);
  168. return -EBUSY;
  169. }
  170. }
  171. nv_wr32(dev, 0x002140, 0);
  172. return 0;
  173. }
  174. int
  175. nv84_fifo_create(struct drm_device *dev)
  176. {
  177. struct drm_nouveau_private *dev_priv = dev->dev_private;
  178. struct nv84_fifo_priv *priv;
  179. int ret;
  180. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  181. if (!priv)
  182. return -ENOMEM;
  183. priv->base.base.destroy = nv50_fifo_destroy;
  184. priv->base.base.init = nv84_fifo_init;
  185. priv->base.base.fini = nv84_fifo_fini;
  186. priv->base.base.context_new = nv84_fifo_context_new;
  187. priv->base.base.context_del = nv84_fifo_context_del;
  188. priv->base.base.tlb_flush = nv50_fifo_tlb_flush;
  189. priv->base.channels = 127;
  190. dev_priv->eng[NVOBJ_ENGINE_FIFO] = &priv->base.base;
  191. ret = nouveau_gpuobj_new(dev, NULL, priv->base.channels * 4, 0x1000,
  192. NVOBJ_FLAG_ZERO_ALLOC, &priv->playlist[0]);
  193. if (ret)
  194. goto error;
  195. ret = nouveau_gpuobj_new(dev, NULL, priv->base.channels * 4, 0x1000,
  196. NVOBJ_FLAG_ZERO_ALLOC, &priv->playlist[1]);
  197. if (ret)
  198. goto error;
  199. nouveau_irq_register(dev, 8, nv04_fifo_isr);
  200. error:
  201. if (ret)
  202. priv->base.base.destroy(dev, NVOBJ_ENGINE_FIFO);
  203. return ret;
  204. }