nv17_fifo.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_util.h"
  31. #include "nouveau_ramht.h"
  32. static struct ramfc_desc {
  33. unsigned bits:6;
  34. unsigned ctxs:5;
  35. unsigned ctxp:8;
  36. unsigned regs:5;
  37. unsigned regp;
  38. } nv17_ramfc[] = {
  39. { 32, 0, 0x00, 0, NV04_PFIFO_CACHE1_DMA_PUT },
  40. { 32, 0, 0x04, 0, NV04_PFIFO_CACHE1_DMA_GET },
  41. { 32, 0, 0x08, 0, NV10_PFIFO_CACHE1_REF_CNT },
  42. { 16, 0, 0x0c, 0, NV04_PFIFO_CACHE1_DMA_INSTANCE },
  43. { 16, 16, 0x0c, 0, NV04_PFIFO_CACHE1_DMA_DCOUNT },
  44. { 32, 0, 0x10, 0, NV04_PFIFO_CACHE1_DMA_STATE },
  45. { 32, 0, 0x14, 0, NV04_PFIFO_CACHE1_DMA_FETCH },
  46. { 32, 0, 0x18, 0, NV04_PFIFO_CACHE1_ENGINE },
  47. { 32, 0, 0x1c, 0, NV04_PFIFO_CACHE1_PULL1 },
  48. { 32, 0, 0x20, 0, NV10_PFIFO_CACHE1_ACQUIRE_VALUE },
  49. { 32, 0, 0x24, 0, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP },
  50. { 32, 0, 0x28, 0, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT },
  51. { 32, 0, 0x2c, 0, NV10_PFIFO_CACHE1_SEMAPHORE },
  52. { 32, 0, 0x30, 0, NV10_PFIFO_CACHE1_DMA_SUBROUTINE },
  53. {}
  54. };
  55. struct nv17_fifo_priv {
  56. struct nouveau_fifo_priv base;
  57. struct ramfc_desc *ramfc_desc;
  58. };
  59. struct nv17_fifo_chan {
  60. struct nouveau_fifo_chan base;
  61. struct nouveau_gpuobj *ramfc;
  62. };
  63. static int
  64. nv17_fifo_context_new(struct nouveau_channel *chan, int engine)
  65. {
  66. struct drm_device *dev = chan->dev;
  67. struct drm_nouveau_private *dev_priv = dev->dev_private;
  68. struct nv17_fifo_priv *priv = nv_engine(dev, engine);
  69. struct nv17_fifo_chan *fctx;
  70. unsigned long flags;
  71. int ret;
  72. fctx = chan->engctx[engine] = kzalloc(sizeof(*fctx), GFP_KERNEL);
  73. if (!fctx)
  74. return -ENOMEM;
  75. /* map channel control registers */
  76. chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
  77. NV03_USER(chan->id), PAGE_SIZE);
  78. if (!chan->user) {
  79. ret = -ENOMEM;
  80. goto error;
  81. }
  82. /* initialise default fifo context */
  83. ret = nouveau_gpuobj_new_fake(dev, dev_priv->ramfc->pinst +
  84. chan->id * 64, ~0, 64,
  85. NVOBJ_FLAG_ZERO_ALLOC |
  86. NVOBJ_FLAG_ZERO_FREE, &fctx->ramfc);
  87. if (ret)
  88. goto error;
  89. nv_wo32(fctx->ramfc, 0x00, chan->pushbuf_base);
  90. nv_wo32(fctx->ramfc, 0x04, chan->pushbuf_base);
  91. nv_wo32(fctx->ramfc, 0x0c, chan->pushbuf->pinst >> 4);
  92. nv_wo32(fctx->ramfc, 0x14, NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  93. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  94. #ifdef __BIG_ENDIAN
  95. NV_PFIFO_CACHE1_BIG_ENDIAN |
  96. #endif
  97. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8);
  98. /* enable dma mode on the channel */
  99. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  100. nv_mask(dev, NV04_PFIFO_MODE, (1 << chan->id), (1 << chan->id));
  101. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  102. error:
  103. if (ret)
  104. priv->base.base.context_del(chan, engine);
  105. return ret;
  106. }
  107. static int
  108. nv17_fifo_init(struct drm_device *dev, int engine)
  109. {
  110. struct drm_nouveau_private *dev_priv = dev->dev_private;
  111. struct nv17_fifo_priv *priv = nv_engine(dev, engine);
  112. int i;
  113. nv_mask(dev, NV03_PMC_ENABLE, NV_PMC_ENABLE_PFIFO, 0);
  114. nv_mask(dev, NV03_PMC_ENABLE, NV_PMC_ENABLE_PFIFO, NV_PMC_ENABLE_PFIFO);
  115. nv_wr32(dev, NV04_PFIFO_DELAY_0, 0x000000ff);
  116. nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, 0x0101ffff);
  117. nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  118. ((dev_priv->ramht->bits - 9) << 16) |
  119. (dev_priv->ramht->gpuobj->pinst >> 8));
  120. nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
  121. nv_wr32(dev, NV03_PFIFO_RAMFC, 0x00010000 |
  122. dev_priv->ramfc->pinst >> 8);
  123. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, priv->base.channels);
  124. nv_wr32(dev, NV03_PFIFO_INTR_0, 0xffffffff);
  125. nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xffffffff);
  126. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 1);
  127. nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
  128. nv_wr32(dev, NV03_PFIFO_CACHES, 1);
  129. for (i = 0; i < priv->base.channels; i++) {
  130. if (dev_priv->channels.ptr[i])
  131. nv_mask(dev, NV04_PFIFO_MODE, (1 << i), (1 << i));
  132. }
  133. return 0;
  134. }
  135. int
  136. nv17_fifo_create(struct drm_device *dev)
  137. {
  138. struct drm_nouveau_private *dev_priv = dev->dev_private;
  139. struct nv17_fifo_priv *priv;
  140. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  141. if (!priv)
  142. return -ENOMEM;
  143. priv->base.base.destroy = nv04_fifo_destroy;
  144. priv->base.base.init = nv17_fifo_init;
  145. priv->base.base.fini = nv04_fifo_fini;
  146. priv->base.base.context_new = nv17_fifo_context_new;
  147. priv->base.base.context_del = nv04_fifo_context_del;
  148. priv->base.channels = 31;
  149. priv->ramfc_desc = nv17_ramfc;
  150. dev_priv->eng[NVOBJ_ENGINE_FIFO] = &priv->base.base;
  151. nouveau_irq_register(dev, 8, nv04_fifo_isr);
  152. return 0;
  153. }