channv50.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 "channv50.h"
  25. #include <core/client.h>
  26. #include <core/ramht.h>
  27. #include <subdev/mmu.h>
  28. #include <subdev/timer.h>
  29. static int
  30. nv50_fifo_chan_engine_addr(struct nvkm_engine *engine)
  31. {
  32. switch (engine->subdev.index) {
  33. case NVKM_ENGINE_DMAOBJ:
  34. case NVKM_ENGINE_SW : return -1;
  35. case NVKM_ENGINE_GR : return 0x0000;
  36. case NVKM_ENGINE_MPEG : return 0x0060;
  37. default:
  38. WARN_ON(1);
  39. return -1;
  40. }
  41. }
  42. static int
  43. nv50_fifo_chan_engine_fini(struct nvkm_fifo_chan *base,
  44. struct nvkm_engine *engine, bool suspend)
  45. {
  46. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  47. struct nv50_fifo *fifo = chan->fifo;
  48. struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
  49. struct nvkm_device *device = subdev->device;
  50. int offset, ret = 0;
  51. u32 me;
  52. offset = nv50_fifo_chan_engine_addr(engine);
  53. if (offset < 0)
  54. return 0;
  55. /* HW bug workaround:
  56. *
  57. * PFIFO will hang forever if the connected engines don't report
  58. * that they've processed the context switch request.
  59. *
  60. * In order for the kickoff to work, we need to ensure all the
  61. * connected engines are in a state where they can answer.
  62. *
  63. * Newer chipsets don't seem to suffer from this issue, and well,
  64. * there's also a "ignore these engines" bitmask reg we can use
  65. * if we hit the issue there..
  66. */
  67. me = nvkm_mask(device, 0x00b860, 0x00000001, 0x00000001);
  68. /* do the kickoff... */
  69. nvkm_wr32(device, 0x0032fc, chan->base.inst->addr >> 12);
  70. if (nvkm_msec(device, 2000,
  71. if (nvkm_rd32(device, 0x0032fc) != 0xffffffff)
  72. break;
  73. ) < 0) {
  74. nvkm_error(subdev, "channel %d [%s] unload timeout\n",
  75. chan->base.chid, chan->base.object.client->name);
  76. if (suspend)
  77. ret = -EBUSY;
  78. }
  79. nvkm_wr32(device, 0x00b860, me);
  80. if (ret == 0) {
  81. nvkm_kmap(chan->eng);
  82. nvkm_wo32(chan->eng, offset + 0x00, 0x00000000);
  83. nvkm_wo32(chan->eng, offset + 0x04, 0x00000000);
  84. nvkm_wo32(chan->eng, offset + 0x08, 0x00000000);
  85. nvkm_wo32(chan->eng, offset + 0x0c, 0x00000000);
  86. nvkm_wo32(chan->eng, offset + 0x10, 0x00000000);
  87. nvkm_wo32(chan->eng, offset + 0x14, 0x00000000);
  88. nvkm_done(chan->eng);
  89. }
  90. return ret;
  91. }
  92. static int
  93. nv50_fifo_chan_engine_init(struct nvkm_fifo_chan *base,
  94. struct nvkm_engine *engine)
  95. {
  96. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  97. struct nvkm_gpuobj *engn = chan->engn[engine->subdev.index];
  98. u64 limit, start;
  99. int offset;
  100. offset = nv50_fifo_chan_engine_addr(engine);
  101. if (offset < 0)
  102. return 0;
  103. limit = engn->addr + engn->size - 1;
  104. start = engn->addr;
  105. nvkm_kmap(chan->eng);
  106. nvkm_wo32(chan->eng, offset + 0x00, 0x00190000);
  107. nvkm_wo32(chan->eng, offset + 0x04, lower_32_bits(limit));
  108. nvkm_wo32(chan->eng, offset + 0x08, lower_32_bits(start));
  109. nvkm_wo32(chan->eng, offset + 0x0c, upper_32_bits(limit) << 24 |
  110. upper_32_bits(start));
  111. nvkm_wo32(chan->eng, offset + 0x10, 0x00000000);
  112. nvkm_wo32(chan->eng, offset + 0x14, 0x00000000);
  113. nvkm_done(chan->eng);
  114. return 0;
  115. }
  116. void
  117. nv50_fifo_chan_engine_dtor(struct nvkm_fifo_chan *base,
  118. struct nvkm_engine *engine)
  119. {
  120. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  121. nvkm_gpuobj_del(&chan->engn[engine->subdev.index]);
  122. }
  123. static int
  124. nv50_fifo_chan_engine_ctor(struct nvkm_fifo_chan *base,
  125. struct nvkm_engine *engine,
  126. struct nvkm_object *object)
  127. {
  128. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  129. int engn = engine->subdev.index;
  130. if (nv50_fifo_chan_engine_addr(engine) < 0)
  131. return 0;
  132. return nvkm_object_bind(object, NULL, 0, &chan->engn[engn]);
  133. }
  134. void
  135. nv50_fifo_chan_object_dtor(struct nvkm_fifo_chan *base, int cookie)
  136. {
  137. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  138. nvkm_ramht_remove(chan->ramht, cookie);
  139. }
  140. static int
  141. nv50_fifo_chan_object_ctor(struct nvkm_fifo_chan *base,
  142. struct nvkm_object *object)
  143. {
  144. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  145. u32 handle = object->handle;
  146. u32 context;
  147. switch (object->engine->subdev.index) {
  148. case NVKM_ENGINE_DMAOBJ:
  149. case NVKM_ENGINE_SW : context = 0x00000000; break;
  150. case NVKM_ENGINE_GR : context = 0x00100000; break;
  151. case NVKM_ENGINE_MPEG : context = 0x00200000; break;
  152. default:
  153. WARN_ON(1);
  154. return -EINVAL;
  155. }
  156. return nvkm_ramht_insert(chan->ramht, object, 0, 4, handle, context);
  157. }
  158. void
  159. nv50_fifo_chan_fini(struct nvkm_fifo_chan *base)
  160. {
  161. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  162. struct nv50_fifo *fifo = chan->fifo;
  163. struct nvkm_device *device = fifo->base.engine.subdev.device;
  164. u32 chid = chan->base.chid;
  165. /* remove channel from runlist, fifo will unload context */
  166. nvkm_mask(device, 0x002600 + (chid * 4), 0x80000000, 0x00000000);
  167. nv50_fifo_runlist_update(fifo);
  168. nvkm_wr32(device, 0x002600 + (chid * 4), 0x00000000);
  169. }
  170. static void
  171. nv50_fifo_chan_init(struct nvkm_fifo_chan *base)
  172. {
  173. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  174. struct nv50_fifo *fifo = chan->fifo;
  175. struct nvkm_device *device = fifo->base.engine.subdev.device;
  176. u64 addr = chan->ramfc->addr >> 12;
  177. u32 chid = chan->base.chid;
  178. nvkm_wr32(device, 0x002600 + (chid * 4), 0x80000000 | addr);
  179. nv50_fifo_runlist_update(fifo);
  180. }
  181. void *
  182. nv50_fifo_chan_dtor(struct nvkm_fifo_chan *base)
  183. {
  184. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  185. nvkm_vm_ref(NULL, &chan->vm, chan->pgd);
  186. nvkm_ramht_del(&chan->ramht);
  187. nvkm_gpuobj_del(&chan->pgd);
  188. nvkm_gpuobj_del(&chan->eng);
  189. nvkm_gpuobj_del(&chan->cache);
  190. nvkm_gpuobj_del(&chan->ramfc);
  191. return chan;
  192. }
  193. static const struct nvkm_fifo_chan_func
  194. nv50_fifo_chan_func = {
  195. .dtor = nv50_fifo_chan_dtor,
  196. .init = nv50_fifo_chan_init,
  197. .fini = nv50_fifo_chan_fini,
  198. .engine_ctor = nv50_fifo_chan_engine_ctor,
  199. .engine_dtor = nv50_fifo_chan_engine_dtor,
  200. .engine_init = nv50_fifo_chan_engine_init,
  201. .engine_fini = nv50_fifo_chan_engine_fini,
  202. .object_ctor = nv50_fifo_chan_object_ctor,
  203. .object_dtor = nv50_fifo_chan_object_dtor,
  204. };
  205. int
  206. nv50_fifo_chan_ctor(struct nv50_fifo *fifo, u64 vm, u64 push,
  207. const struct nvkm_oclass *oclass,
  208. struct nv50_fifo_chan *chan)
  209. {
  210. struct nvkm_device *device = fifo->base.engine.subdev.device;
  211. int ret;
  212. ret = nvkm_fifo_chan_ctor(&nv50_fifo_chan_func, &fifo->base,
  213. 0x10000, 0x1000, false, vm, push,
  214. (1ULL << NVKM_ENGINE_DMAOBJ) |
  215. (1ULL << NVKM_ENGINE_SW) |
  216. (1ULL << NVKM_ENGINE_GR) |
  217. (1ULL << NVKM_ENGINE_MPEG),
  218. 0, 0xc00000, 0x2000, oclass, &chan->base);
  219. chan->fifo = fifo;
  220. if (ret)
  221. return ret;
  222. ret = nvkm_gpuobj_new(device, 0x0200, 0x1000, true, chan->base.inst,
  223. &chan->ramfc);
  224. if (ret)
  225. return ret;
  226. ret = nvkm_gpuobj_new(device, 0x1200, 0, true, chan->base.inst,
  227. &chan->eng);
  228. if (ret)
  229. return ret;
  230. ret = nvkm_gpuobj_new(device, 0x4000, 0, false, chan->base.inst,
  231. &chan->pgd);
  232. if (ret)
  233. return ret;
  234. ret = nvkm_ramht_new(device, 0x8000, 16, chan->base.inst, &chan->ramht);
  235. if (ret)
  236. return ret;
  237. return nvkm_vm_ref(chan->base.vm, &chan->vm, chan->pgd);
  238. }