dmanv40.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/unpack.h>
  31. static bool
  32. nv40_fifo_dma_engine(struct nvkm_engine *engine, u32 *reg, u32 *ctx)
  33. {
  34. switch (engine->subdev.index) {
  35. case NVKM_ENGINE_DMAOBJ:
  36. case NVKM_ENGINE_SW:
  37. return false;
  38. case NVKM_ENGINE_GR:
  39. *reg = 0x0032e0;
  40. *ctx = 0x38;
  41. return true;
  42. case NVKM_ENGINE_MPEG:
  43. *reg = 0x00330c;
  44. *ctx = 0x54;
  45. return true;
  46. default:
  47. WARN_ON(1);
  48. return false;
  49. }
  50. }
  51. static int
  52. nv40_fifo_dma_engine_fini(struct nvkm_fifo_chan *base,
  53. struct nvkm_engine *engine, bool suspend)
  54. {
  55. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  56. struct nv04_fifo *fifo = chan->fifo;
  57. struct nvkm_device *device = fifo->base.engine.subdev.device;
  58. struct nvkm_instmem *imem = device->imem;
  59. unsigned long flags;
  60. u32 reg, ctx;
  61. int chid;
  62. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  63. return 0;
  64. spin_lock_irqsave(&fifo->base.lock, flags);
  65. nvkm_mask(device, 0x002500, 0x00000001, 0x00000000);
  66. chid = nvkm_rd32(device, 0x003204) & (fifo->base.nr - 1);
  67. if (chid == chan->base.chid)
  68. nvkm_wr32(device, reg, 0x00000000);
  69. nvkm_kmap(imem->ramfc);
  70. nvkm_wo32(imem->ramfc, chan->ramfc + ctx, 0x00000000);
  71. nvkm_done(imem->ramfc);
  72. nvkm_mask(device, 0x002500, 0x00000001, 0x00000001);
  73. spin_unlock_irqrestore(&fifo->base.lock, flags);
  74. return 0;
  75. }
  76. static int
  77. nv40_fifo_dma_engine_init(struct nvkm_fifo_chan *base,
  78. struct nvkm_engine *engine)
  79. {
  80. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  81. struct nv04_fifo *fifo = chan->fifo;
  82. struct nvkm_device *device = fifo->base.engine.subdev.device;
  83. struct nvkm_instmem *imem = device->imem;
  84. unsigned long flags;
  85. u32 inst, reg, ctx;
  86. int chid;
  87. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  88. return 0;
  89. inst = chan->engn[engine->subdev.index]->addr >> 4;
  90. spin_lock_irqsave(&fifo->base.lock, flags);
  91. nvkm_mask(device, 0x002500, 0x00000001, 0x00000000);
  92. chid = nvkm_rd32(device, 0x003204) & (fifo->base.nr - 1);
  93. if (chid == chan->base.chid)
  94. nvkm_wr32(device, reg, inst);
  95. nvkm_kmap(imem->ramfc);
  96. nvkm_wo32(imem->ramfc, chan->ramfc + ctx, inst);
  97. nvkm_done(imem->ramfc);
  98. nvkm_mask(device, 0x002500, 0x00000001, 0x00000001);
  99. spin_unlock_irqrestore(&fifo->base.lock, flags);
  100. return 0;
  101. }
  102. static void
  103. nv40_fifo_dma_engine_dtor(struct nvkm_fifo_chan *base,
  104. struct nvkm_engine *engine)
  105. {
  106. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  107. nvkm_gpuobj_del(&chan->engn[engine->subdev.index]);
  108. }
  109. static int
  110. nv40_fifo_dma_engine_ctor(struct nvkm_fifo_chan *base,
  111. struct nvkm_engine *engine,
  112. struct nvkm_object *object)
  113. {
  114. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  115. const int engn = engine->subdev.index;
  116. u32 reg, ctx;
  117. if (!nv40_fifo_dma_engine(engine, &reg, &ctx))
  118. return 0;
  119. return nvkm_object_bind(object, NULL, 0, &chan->engn[engn]);
  120. }
  121. static int
  122. nv40_fifo_dma_object_ctor(struct nvkm_fifo_chan *base,
  123. struct nvkm_object *object)
  124. {
  125. struct nv04_fifo_chan *chan = nv04_fifo_chan(base);
  126. struct nvkm_instmem *imem = chan->fifo->base.engine.subdev.device->imem;
  127. u32 context = chan->base.chid << 23;
  128. u32 handle = object->handle;
  129. int hash;
  130. switch (object->engine->subdev.index) {
  131. case NVKM_ENGINE_DMAOBJ:
  132. case NVKM_ENGINE_SW : context |= 0x00000000; break;
  133. case NVKM_ENGINE_GR : context |= 0x00100000; break;
  134. case NVKM_ENGINE_MPEG : context |= 0x00200000; break;
  135. default:
  136. WARN_ON(1);
  137. return -EINVAL;
  138. }
  139. mutex_lock(&chan->fifo->base.engine.subdev.mutex);
  140. hash = nvkm_ramht_insert(imem->ramht, object, chan->base.chid, 4,
  141. handle, context);
  142. mutex_unlock(&chan->fifo->base.engine.subdev.mutex);
  143. return hash;
  144. }
  145. static const struct nvkm_fifo_chan_func
  146. nv40_fifo_dma_func = {
  147. .dtor = nv04_fifo_dma_dtor,
  148. .init = nv04_fifo_dma_init,
  149. .fini = nv04_fifo_dma_fini,
  150. .engine_ctor = nv40_fifo_dma_engine_ctor,
  151. .engine_dtor = nv40_fifo_dma_engine_dtor,
  152. .engine_init = nv40_fifo_dma_engine_init,
  153. .engine_fini = nv40_fifo_dma_engine_fini,
  154. .object_ctor = nv40_fifo_dma_object_ctor,
  155. .object_dtor = nv04_fifo_dma_object_dtor,
  156. };
  157. static int
  158. nv40_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
  159. void *data, u32 size, struct nvkm_object **pobject)
  160. {
  161. struct nvkm_object *parent = oclass->parent;
  162. union {
  163. struct nv03_channel_dma_v0 v0;
  164. } *args = data;
  165. struct nv04_fifo *fifo = nv04_fifo(base);
  166. struct nv04_fifo_chan *chan = NULL;
  167. struct nvkm_device *device = fifo->base.engine.subdev.device;
  168. struct nvkm_instmem *imem = device->imem;
  169. int ret;
  170. nvif_ioctl(parent, "create channel dma size %d\n", size);
  171. if (nvif_unpack(args->v0, 0, 0, false)) {
  172. nvif_ioctl(parent, "create channel dma vers %d pushbuf %llx "
  173. "offset %08x\n", args->v0.version,
  174. args->v0.pushbuf, args->v0.offset);
  175. if (!args->v0.pushbuf)
  176. return -EINVAL;
  177. } else
  178. return ret;
  179. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  180. return -ENOMEM;
  181. *pobject = &chan->base.object;
  182. ret = nvkm_fifo_chan_ctor(&nv40_fifo_dma_func, &fifo->base,
  183. 0x1000, 0x1000, false, 0, args->v0.pushbuf,
  184. (1ULL << NVKM_ENGINE_DMAOBJ) |
  185. (1ULL << NVKM_ENGINE_GR) |
  186. (1ULL << NVKM_ENGINE_MPEG) |
  187. (1ULL << NVKM_ENGINE_SW),
  188. 0, 0xc00000, 0x1000, oclass, &chan->base);
  189. chan->fifo = fifo;
  190. if (ret)
  191. return ret;
  192. args->v0.chid = chan->base.chid;
  193. chan->ramfc = chan->base.chid * 128;
  194. nvkm_kmap(imem->ramfc);
  195. nvkm_wo32(imem->ramfc, chan->ramfc + 0x00, args->v0.offset);
  196. nvkm_wo32(imem->ramfc, chan->ramfc + 0x04, args->v0.offset);
  197. nvkm_wo32(imem->ramfc, chan->ramfc + 0x0c, chan->base.push->addr >> 4);
  198. nvkm_wo32(imem->ramfc, chan->ramfc + 0x18, 0x30000000 |
  199. NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
  200. NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
  201. #ifdef __BIG_ENDIAN
  202. NV_PFIFO_CACHE1_BIG_ENDIAN |
  203. #endif
  204. NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8);
  205. nvkm_wo32(imem->ramfc, chan->ramfc + 0x3c, 0x0001ffff);
  206. nvkm_done(imem->ramfc);
  207. return 0;
  208. }
  209. const struct nvkm_fifo_chan_oclass
  210. nv40_fifo_dma_oclass = {
  211. .base.oclass = NV40_CHANNEL_DMA,
  212. .base.minver = 0,
  213. .base.maxver = 0,
  214. .ctor = nv40_fifo_dma_new,
  215. };