dmanv40.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "channv04.h"
  25. #include "regsnv04.h"
  26. #include <core/client.h>
  27. #include <core/ramht.h>
  28. #include <subdev/instmem.h>
  29. #include <nvif/class.h>
  30. #include <nvif/cl006b.h>
  31. #include <nvif/unpack.h>
  32. static bool
  33. nv40_fifo_dma_engine(struct nvkm_engine *engine, u32 *reg, u32 *ctx)
  34. {
  35. switch (engine->subdev.index) {
  36. case NVKM_ENGINE_DMAOBJ:
  37. case NVKM_ENGINE_SW:
  38. return false;
  39. case NVKM_ENGINE_GR:
  40. *reg = 0x0032e0;
  41. *ctx = 0x38;
  42. return true;
  43. case NVKM_ENGINE_MPEG:
  44. *reg = 0x00330c;
  45. *ctx = 0x54;
  46. return true;
  47. default:
  48. WARN_ON(1);
  49. return false;
  50. }
  51. }
  52. static int
  53. nv40_fifo_dma_engine_fini(struct nvkm_fifo_chan *base,
  54. struct nvkm_engine *engine, bool suspend)
  55. {
  56. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  57. struct nv04_fifo *fifo = chan->fifo;
  58. struct nvkm_device *device = fifo->base.engine.subdev.device;
  59. struct nvkm_instmem *imem = device->imem;
  60. unsigned long flags;
  61. u32 reg, ctx;
  62. int chid;
  63. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  64. return 0;
  65. spin_lock_irqsave(&fifo->base.lock, flags);
  66. nvkm_mask(device, 0x002500, 0x00000001, 0x00000000);
  67. chid = nvkm_rd32(device, 0x003204) & (fifo->base.nr - 1);
  68. if (chid == chan->base.chid)
  69. nvkm_wr32(device, reg, 0x00000000);
  70. nvkm_kmap(imem->ramfc);
  71. nvkm_wo32(imem->ramfc, chan->ramfc + ctx, 0x00000000);
  72. nvkm_done(imem->ramfc);
  73. nvkm_mask(device, 0x002500, 0x00000001, 0x00000001);
  74. spin_unlock_irqrestore(&fifo->base.lock, flags);
  75. return 0;
  76. }
  77. static int
  78. nv40_fifo_dma_engine_init(struct nvkm_fifo_chan *base,
  79. struct nvkm_engine *engine)
  80. {
  81. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  82. struct nv04_fifo *fifo = chan->fifo;
  83. struct nvkm_device *device = fifo->base.engine.subdev.device;
  84. struct nvkm_instmem *imem = device->imem;
  85. unsigned long flags;
  86. u32 inst, reg, ctx;
  87. int chid;
  88. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  89. return 0;
  90. inst = chan->engn[engine->subdev.index]->addr >> 4;
  91. spin_lock_irqsave(&fifo->base.lock, flags);
  92. nvkm_mask(device, 0x002500, 0x00000001, 0x00000000);
  93. chid = nvkm_rd32(device, 0x003204) & (fifo->base.nr - 1);
  94. if (chid == chan->base.chid)
  95. nvkm_wr32(device, reg, inst);
  96. nvkm_kmap(imem->ramfc);
  97. nvkm_wo32(imem->ramfc, chan->ramfc + ctx, inst);
  98. nvkm_done(imem->ramfc);
  99. nvkm_mask(device, 0x002500, 0x00000001, 0x00000001);
  100. spin_unlock_irqrestore(&fifo->base.lock, flags);
  101. return 0;
  102. }
  103. static void
  104. nv40_fifo_dma_engine_dtor(struct nvkm_fifo_chan *base,
  105. struct nvkm_engine *engine)
  106. {
  107. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  108. nvkm_gpuobj_del(&chan->engn[engine->subdev.index]);
  109. }
  110. static int
  111. nv40_fifo_dma_engine_ctor(struct nvkm_fifo_chan *base,
  112. struct nvkm_engine *engine,
  113. struct nvkm_object *object)
  114. {
  115. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  116. const int engn = engine->subdev.index;
  117. u32 reg, ctx;
  118. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  119. return 0;
  120. return nvkm_object_bind(object, NULL, 0, &chan->engn[engn]);
  121. }
  122. static int
  123. nv40_fifo_dma_object_ctor(struct nvkm_fifo_chan *base,
  124. struct nvkm_object *object)
  125. {
  126. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  127. struct nvkm_instmem *imem = chan->fifo->base.engine.subdev.device->imem;
  128. u32 context = chan->base.chid << 23;
  129. u32 handle = object->handle;
  130. int hash;
  131. switch (object->engine->subdev.index) {
  132. case NVKM_ENGINE_DMAOBJ:
  133. case NVKM_ENGINE_SW : context |= 0x00000000; break;
  134. case NVKM_ENGINE_GR : context |= 0x00100000; break;
  135. case NVKM_ENGINE_MPEG : context |= 0x00200000; break;
  136. default:
  137. WARN_ON(1);
  138. return -EINVAL;
  139. }
  140. mutex_lock(&chan->fifo->base.engine.subdev.mutex);
  141. hash = nvkm_ramht_insert(imem->ramht, object, chan->base.chid, 4,
  142. handle, context);
  143. mutex_unlock(&chan->fifo->base.engine.subdev.mutex);
  144. return hash;
  145. }
  146. static const struct nvkm_fifo_chan_func
  147. nv40_fifo_dma_func = {
  148. .dtor = nv04_fifo_dma_dtor,
  149. .init = nv04_fifo_dma_init,
  150. .fini = nv04_fifo_dma_fini,
  151. .engine_ctor = nv40_fifo_dma_engine_ctor,
  152. .engine_dtor = nv40_fifo_dma_engine_dtor,
  153. .engine_init = nv40_fifo_dma_engine_init,
  154. .engine_fini = nv40_fifo_dma_engine_fini,
  155. .object_ctor = nv40_fifo_dma_object_ctor,
  156. .object_dtor = nv04_fifo_dma_object_dtor,
  157. };
  158. static int
  159. nv40_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
  160. void *data, u32 size, struct nvkm_object **pobject)
  161. {
  162. struct nvkm_object *parent = oclass->parent;
  163. union {
  164. struct nv03_channel_dma_v0 v0;
  165. } *args = data;
  166. struct nv04_fifo *fifo = nv04_fifo(base);
  167. struct nv04_fifo_chan *chan = NULL;
  168. struct nvkm_device *device = fifo->base.engine.subdev.device;
  169. struct nvkm_instmem *imem = device->imem;
  170. int ret = -ENOSYS;
  171. nvif_ioctl(parent, "create channel dma size %d\n", size);
  172. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  173. nvif_ioctl(parent, "create channel dma vers %d pushbuf %llx "
  174. "offset %08x\n", args->v0.version,
  175. args->v0.pushbuf, args->v0.offset);
  176. if (!args->v0.pushbuf)
  177. return -EINVAL;
  178. } else
  179. return ret;
  180. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  181. return -ENOMEM;
  182. *pobject = &chan->base.object;
  183. ret = nvkm_fifo_chan_ctor(&nv40_fifo_dma_func, &fifo->base,
  184. 0x1000, 0x1000, false, 0, args->v0.pushbuf,
  185. (1ULL << NVKM_ENGINE_DMAOBJ) |
  186. (1ULL << NVKM_ENGINE_GR) |
  187. (1ULL << NVKM_ENGINE_MPEG) |
  188. (1ULL << NVKM_ENGINE_SW),
  189. 0, 0xc00000, 0x1000, oclass, &chan->base);
  190. chan->fifo = fifo;
  191. if (ret)
  192. return ret;
  193. args->v0.chid = chan->base.chid;
  194. chan->ramfc = chan->base.chid * 128;
  195. nvkm_kmap(imem->ramfc);
  196. nvkm_wo32(imem->ramfc, chan->ramfc + 0x00, args->v0.offset);
  197. nvkm_wo32(imem->ramfc, chan->ramfc + 0x04, args->v0.offset);
  198. nvkm_wo32(imem->ramfc, chan->ramfc + 0x0c, chan->base.push->addr >> 4);
  199. nvkm_wo32(imem->ramfc, chan->ramfc + 0x18, 0x30000000 |
  200. NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  201. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  202. #ifdef __BIG_ENDIAN
  203. NV_PFIFO_CACHE1_BIG_ENDIAN |
  204. #endif
  205. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8);
  206. nvkm_wo32(imem->ramfc, chan->ramfc + 0x3c, 0x0001ffff);
  207. nvkm_done(imem->ramfc);
  208. return 0;
  209. }
  210. const struct nvkm_fifo_chan_oclass
  211. nv40_fifo_dma_oclass = {
  212. .base.oclass = NV40_CHANNEL_DMA,
  213. .base.minver = 0,
  214. .base.maxver = 0,
  215. .ctor = nv40_fifo_dma_new,
  216. };