gpfifogf100.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 "changf100.h"
  25. #include <core/client.h>
  26. #include <core/gpuobj.h>
  27. #include <subdev/fb.h>
  28. #include <subdev/timer.h>
  29. #include <nvif/class.h>
  30. #include <nvif/unpack.h>
  31. static u32
  32. gf100_fifo_gpfifo_engine_addr(struct nvkm_engine *engine)
  33. {
  34. switch (engine->subdev.index) {
  35. case NVKM_ENGINE_SW : return 0;
  36. case NVKM_ENGINE_GR : return 0x0210;
  37. case NVKM_ENGINE_CE0 : return 0x0230;
  38. case NVKM_ENGINE_CE1 : return 0x0240;
  39. case NVKM_ENGINE_MSPDEC: return 0x0250;
  40. case NVKM_ENGINE_MSPPP : return 0x0260;
  41. case NVKM_ENGINE_MSVLD : return 0x0270;
  42. default:
  43. WARN_ON(1);
  44. return 0;
  45. }
  46. }
  47. static int
  48. gf100_fifo_gpfifo_engine_fini(struct nvkm_fifo_chan *base,
  49. struct nvkm_engine *engine, bool suspend)
  50. {
  51. const u32 offset = gf100_fifo_gpfifo_engine_addr(engine);
  52. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  53. struct nvkm_subdev *subdev = &chan->fifo->base.engine.subdev;
  54. struct nvkm_device *device = subdev->device;
  55. struct nvkm_gpuobj *inst = chan->base.inst;
  56. int ret = 0;
  57. nvkm_wr32(device, 0x002634, chan->base.chid);
  58. if (nvkm_msec(device, 2000,
  59. if (nvkm_rd32(device, 0x002634) == chan->base.chid)
  60. break;
  61. ) < 0) {
  62. nvkm_error(subdev, "channel %d [%s] kick timeout\n",
  63. chan->base.chid, chan->base.object.client->name);
  64. ret = -EBUSY;
  65. if (suspend)
  66. return ret;
  67. }
  68. if (offset) {
  69. nvkm_kmap(inst);
  70. nvkm_wo32(inst, offset + 0x00, 0x00000000);
  71. nvkm_wo32(inst, offset + 0x04, 0x00000000);
  72. nvkm_done(inst);
  73. }
  74. return ret;
  75. }
  76. static int
  77. gf100_fifo_gpfifo_engine_init(struct nvkm_fifo_chan *base,
  78. struct nvkm_engine *engine)
  79. {
  80. const u32 offset = gf100_fifo_gpfifo_engine_addr(engine);
  81. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  82. struct nvkm_gpuobj *inst = chan->base.inst;
  83. if (offset) {
  84. u64 addr = chan->engn[engine->subdev.index].vma.offset;
  85. nvkm_kmap(inst);
  86. nvkm_wo32(inst, offset + 0x00, lower_32_bits(addr) | 4);
  87. nvkm_wo32(inst, offset + 0x04, upper_32_bits(addr));
  88. nvkm_done(inst);
  89. }
  90. return 0;
  91. }
  92. static void
  93. gf100_fifo_gpfifo_engine_dtor(struct nvkm_fifo_chan *base,
  94. struct nvkm_engine *engine)
  95. {
  96. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  97. nvkm_gpuobj_unmap(&chan->engn[engine->subdev.index].vma);
  98. nvkm_gpuobj_del(&chan->engn[engine->subdev.index].inst);
  99. }
  100. static int
  101. gf100_fifo_gpfifo_engine_ctor(struct nvkm_fifo_chan *base,
  102. struct nvkm_engine *engine,
  103. struct nvkm_object *object)
  104. {
  105. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  106. int engn = engine->subdev.index;
  107. int ret;
  108. if (!gf100_fifo_gpfifo_engine_addr(engine))
  109. return 0;
  110. ret = nvkm_object_bind(object, NULL, 0, &chan->engn[engn].inst);
  111. if (ret)
  112. return ret;
  113. return nvkm_gpuobj_map(chan->engn[engn].inst, chan->vm,
  114. NV_MEM_ACCESS_RW, &chan->engn[engn].vma);
  115. }
  116. static void
  117. gf100_fifo_gpfifo_fini(struct nvkm_fifo_chan *base)
  118. {
  119. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  120. struct gf100_fifo *fifo = chan->fifo;
  121. struct nvkm_device *device = fifo->base.engine.subdev.device;
  122. u32 coff = chan->base.chid * 8;
  123. if (!list_empty(&chan->head) && !chan->killed) {
  124. list_del_init(&chan->head);
  125. nvkm_mask(device, 0x003004 + coff, 0x00000001, 0x00000000);
  126. gf100_fifo_runlist_update(fifo);
  127. }
  128. gf100_fifo_intr_engine(fifo);
  129. nvkm_wr32(device, 0x003000 + coff, 0x00000000);
  130. }
  131. static void
  132. gf100_fifo_gpfifo_init(struct nvkm_fifo_chan *base)
  133. {
  134. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  135. struct gf100_fifo *fifo = chan->fifo;
  136. struct nvkm_device *device = fifo->base.engine.subdev.device;
  137. u32 addr = chan->base.inst->addr >> 12;
  138. u32 coff = chan->base.chid * 8;
  139. nvkm_wr32(device, 0x003000 + coff, 0xc0000000 | addr);
  140. if (list_empty(&chan->head) && !chan->killed) {
  141. list_add_tail(&chan->head, &fifo->chan);
  142. nvkm_wr32(device, 0x003004 + coff, 0x001f0001);
  143. gf100_fifo_runlist_update(fifo);
  144. }
  145. }
  146. static void *
  147. gf100_fifo_gpfifo_dtor(struct nvkm_fifo_chan *base)
  148. {
  149. struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
  150. nvkm_vm_ref(NULL, &chan->vm, chan->pgd);
  151. nvkm_gpuobj_del(&chan->pgd);
  152. return chan;
  153. }
  154. static const struct nvkm_fifo_chan_func
  155. gf100_fifo_gpfifo_func = {
  156. .dtor = gf100_fifo_gpfifo_dtor,
  157. .init = gf100_fifo_gpfifo_init,
  158. .fini = gf100_fifo_gpfifo_fini,
  159. .ntfy = g84_fifo_chan_ntfy,
  160. .engine_ctor = gf100_fifo_gpfifo_engine_ctor,
  161. .engine_dtor = gf100_fifo_gpfifo_engine_dtor,
  162. .engine_init = gf100_fifo_gpfifo_engine_init,
  163. .engine_fini = gf100_fifo_gpfifo_engine_fini,
  164. };
  165. static int
  166. gf100_fifo_gpfifo_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
  167. void *data, u32 size, struct nvkm_object **pobject)
  168. {
  169. union {
  170. struct fermi_channel_gpfifo_v0 v0;
  171. } *args = data;
  172. struct gf100_fifo *fifo = gf100_fifo(base);
  173. struct nvkm_device *device = fifo->base.engine.subdev.device;
  174. struct nvkm_object *parent = oclass->parent;
  175. struct gf100_fifo_chan *chan;
  176. u64 usermem, ioffset, ilength;
  177. int ret, i;
  178. nvif_ioctl(parent, "create channel gpfifo size %d\n", size);
  179. if (nvif_unpack(args->v0, 0, 0, false)) {
  180. nvif_ioctl(parent, "create channel gpfifo vers %d vm %llx "
  181. "ioffset %016llx ilength %08x\n",
  182. args->v0.version, args->v0.vm, args->v0.ioffset,
  183. args->v0.ilength);
  184. } else
  185. return ret;
  186. /* allocate channel */
  187. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  188. return -ENOMEM;
  189. *pobject = &chan->base.object;
  190. chan->fifo = fifo;
  191. INIT_LIST_HEAD(&chan->head);
  192. ret = nvkm_fifo_chan_ctor(&gf100_fifo_gpfifo_func, &fifo->base,
  193. 0x1000, 0x1000, true, args->v0.vm, 0,
  194. (1ULL << NVKM_ENGINE_CE0) |
  195. (1ULL << NVKM_ENGINE_CE1) |
  196. (1ULL << NVKM_ENGINE_GR) |
  197. (1ULL << NVKM_ENGINE_MSPDEC) |
  198. (1ULL << NVKM_ENGINE_MSPPP) |
  199. (1ULL << NVKM_ENGINE_MSVLD) |
  200. (1ULL << NVKM_ENGINE_SW),
  201. 1, fifo->user.bar.offset, 0x1000,
  202. oclass, &chan->base);
  203. if (ret)
  204. return ret;
  205. args->v0.chid = chan->base.chid;
  206. /* page directory */
  207. ret = nvkm_gpuobj_new(device, 0x10000, 0x1000, false, NULL, &chan->pgd);
  208. if (ret)
  209. return ret;
  210. nvkm_kmap(chan->base.inst);
  211. nvkm_wo32(chan->base.inst, 0x0200, lower_32_bits(chan->pgd->addr));
  212. nvkm_wo32(chan->base.inst, 0x0204, upper_32_bits(chan->pgd->addr));
  213. nvkm_wo32(chan->base.inst, 0x0208, 0xffffffff);
  214. nvkm_wo32(chan->base.inst, 0x020c, 0x000000ff);
  215. nvkm_done(chan->base.inst);
  216. ret = nvkm_vm_ref(chan->base.vm, &chan->vm, chan->pgd);
  217. if (ret)
  218. return ret;
  219. /* clear channel control registers */
  220. usermem = chan->base.chid * 0x1000;
  221. ioffset = args->v0.ioffset;
  222. ilength = order_base_2(args->v0.ilength / 8);
  223. nvkm_kmap(fifo->user.mem);
  224. for (i = 0; i < 0x1000; i += 4)
  225. nvkm_wo32(fifo->user.mem, usermem + i, 0x00000000);
  226. nvkm_done(fifo->user.mem);
  227. usermem = nvkm_memory_addr(fifo->user.mem) + usermem;
  228. /* RAMFC */
  229. nvkm_kmap(chan->base.inst);
  230. nvkm_wo32(chan->base.inst, 0x08, lower_32_bits(usermem));
  231. nvkm_wo32(chan->base.inst, 0x0c, upper_32_bits(usermem));
  232. nvkm_wo32(chan->base.inst, 0x10, 0x0000face);
  233. nvkm_wo32(chan->base.inst, 0x30, 0xfffff902);
  234. nvkm_wo32(chan->base.inst, 0x48, lower_32_bits(ioffset));
  235. nvkm_wo32(chan->base.inst, 0x4c, upper_32_bits(ioffset) |
  236. (ilength << 16));
  237. nvkm_wo32(chan->base.inst, 0x54, 0x00000002);
  238. nvkm_wo32(chan->base.inst, 0x84, 0x20400000);
  239. nvkm_wo32(chan->base.inst, 0x94, 0x30000001);
  240. nvkm_wo32(chan->base.inst, 0x9c, 0x00000100);
  241. nvkm_wo32(chan->base.inst, 0xa4, 0x1f1f1f1f);
  242. nvkm_wo32(chan->base.inst, 0xa8, 0x1f1f1f1f);
  243. nvkm_wo32(chan->base.inst, 0xac, 0x0000001f);
  244. nvkm_wo32(chan->base.inst, 0xb8, 0xf8000000);
  245. nvkm_wo32(chan->base.inst, 0xf8, 0x10003080); /* 0x002310 */
  246. nvkm_wo32(chan->base.inst, 0xfc, 0x10000010); /* 0x002350 */
  247. nvkm_done(chan->base.inst);
  248. return 0;
  249. }
  250. const struct nvkm_fifo_chan_oclass
  251. gf100_fifo_gpfifo_oclass = {
  252. .base.oclass = FERMI_CHANNEL_GPFIFO,
  253. .base.minver = 0,
  254. .base.maxver = 0,
  255. .ctor = gf100_fifo_gpfifo_new,
  256. };