gpfifogf100.c 9.2 KB

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