chang84.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. #include <nvif/cl826e.h>
  30. static int
  31. g84_fifo_chan_ntfy(struct nvkm_fifo_chan *chan, u32 type,
  32. struct nvkm_event **pevent)
  33. {
  34. switch (type) {
  35. case NV826E_V0_NTFY_NON_STALL_INTERRUPT:
  36. *pevent = &chan->fifo->uevent;
  37. return 0;
  38. default:
  39. break;
  40. }
  41. return -EINVAL;
  42. }
  43. static int
  44. g84_fifo_chan_engine(struct nvkm_engine *engine)
  45. {
  46. switch (engine->subdev.index) {
  47. case NVKM_ENGINE_GR : return 0;
  48. case NVKM_ENGINE_MPEG :
  49. case NVKM_ENGINE_MSPPP : return 1;
  50. case NVKM_ENGINE_CE0 : return 2;
  51. case NVKM_ENGINE_VP :
  52. case NVKM_ENGINE_MSPDEC: return 3;
  53. case NVKM_ENGINE_CIPHER:
  54. case NVKM_ENGINE_SEC : return 4;
  55. case NVKM_ENGINE_BSP :
  56. case NVKM_ENGINE_MSVLD : return 5;
  57. default:
  58. WARN_ON(1);
  59. return 0;
  60. }
  61. }
  62. static int
  63. g84_fifo_chan_engine_addr(struct nvkm_engine *engine)
  64. {
  65. switch (engine->subdev.index) {
  66. case NVKM_ENGINE_DMAOBJ:
  67. case NVKM_ENGINE_SW : return -1;
  68. case NVKM_ENGINE_GR : return 0x0020;
  69. case NVKM_ENGINE_VP :
  70. case NVKM_ENGINE_MSPDEC: return 0x0040;
  71. case NVKM_ENGINE_MPEG :
  72. case NVKM_ENGINE_MSPPP : return 0x0060;
  73. case NVKM_ENGINE_BSP :
  74. case NVKM_ENGINE_MSVLD : return 0x0080;
  75. case NVKM_ENGINE_CIPHER:
  76. case NVKM_ENGINE_SEC : return 0x00a0;
  77. case NVKM_ENGINE_CE0 : return 0x00c0;
  78. default:
  79. WARN_ON(1);
  80. return -1;
  81. }
  82. }
  83. static int
  84. g84_fifo_chan_engine_fini(struct nvkm_fifo_chan *base,
  85. struct nvkm_engine *engine, bool suspend)
  86. {
  87. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  88. struct nv50_fifo *fifo = chan->fifo;
  89. struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
  90. struct nvkm_device *device = subdev->device;
  91. u32 engn, save;
  92. int offset;
  93. bool done;
  94. offset = g84_fifo_chan_engine_addr(engine);
  95. if (offset < 0)
  96. return 0;
  97. engn = g84_fifo_chan_engine(engine);
  98. save = nvkm_mask(device, 0x002520, 0x0000003f, 1 << engn);
  99. nvkm_wr32(device, 0x0032fc, chan->base.inst->addr >> 12);
  100. done = nvkm_msec(device, 2000,
  101. if (nvkm_rd32(device, 0x0032fc) != 0xffffffff)
  102. break;
  103. ) >= 0;
  104. nvkm_wr32(device, 0x002520, save);
  105. if (!done) {
  106. nvkm_error(subdev, "channel %d [%s] unload timeout\n",
  107. chan->base.chid, chan->base.object.client->name);
  108. if (suspend)
  109. return -EBUSY;
  110. }
  111. nvkm_kmap(chan->eng);
  112. nvkm_wo32(chan->eng, offset + 0x00, 0x00000000);
  113. nvkm_wo32(chan->eng, offset + 0x04, 0x00000000);
  114. nvkm_wo32(chan->eng, offset + 0x08, 0x00000000);
  115. nvkm_wo32(chan->eng, offset + 0x0c, 0x00000000);
  116. nvkm_wo32(chan->eng, offset + 0x10, 0x00000000);
  117. nvkm_wo32(chan->eng, offset + 0x14, 0x00000000);
  118. nvkm_done(chan->eng);
  119. return 0;
  120. }
  121. static int
  122. g84_fifo_chan_engine_init(struct nvkm_fifo_chan *base,
  123. struct nvkm_engine *engine)
  124. {
  125. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  126. struct nvkm_gpuobj *engn = chan->engn[engine->subdev.index];
  127. u64 limit, start;
  128. int offset;
  129. offset = g84_fifo_chan_engine_addr(engine);
  130. if (offset < 0)
  131. return 0;
  132. limit = engn->addr + engn->size - 1;
  133. start = engn->addr;
  134. nvkm_kmap(chan->eng);
  135. nvkm_wo32(chan->eng, offset + 0x00, 0x00190000);
  136. nvkm_wo32(chan->eng, offset + 0x04, lower_32_bits(limit));
  137. nvkm_wo32(chan->eng, offset + 0x08, lower_32_bits(start));
  138. nvkm_wo32(chan->eng, offset + 0x0c, upper_32_bits(limit) << 24 |
  139. upper_32_bits(start));
  140. nvkm_wo32(chan->eng, offset + 0x10, 0x00000000);
  141. nvkm_wo32(chan->eng, offset + 0x14, 0x00000000);
  142. nvkm_done(chan->eng);
  143. return 0;
  144. }
  145. static int
  146. g84_fifo_chan_engine_ctor(struct nvkm_fifo_chan *base,
  147. struct nvkm_engine *engine,
  148. struct nvkm_object *object)
  149. {
  150. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  151. int engn = engine->subdev.index;
  152. if (g84_fifo_chan_engine_addr(engine) < 0)
  153. return 0;
  154. return nvkm_object_bind(object, NULL, 0, &chan->engn[engn]);
  155. }
  156. static int
  157. g84_fifo_chan_object_ctor(struct nvkm_fifo_chan *base,
  158. struct nvkm_object *object)
  159. {
  160. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  161. u32 handle = object->handle;
  162. u32 context;
  163. switch (object->engine->subdev.index) {
  164. case NVKM_ENGINE_DMAOBJ:
  165. case NVKM_ENGINE_SW : context = 0x00000000; break;
  166. case NVKM_ENGINE_GR : context = 0x00100000; break;
  167. case NVKM_ENGINE_MPEG :
  168. case NVKM_ENGINE_MSPPP : context = 0x00200000; break;
  169. case NVKM_ENGINE_ME :
  170. case NVKM_ENGINE_CE0 : context = 0x00300000; break;
  171. case NVKM_ENGINE_VP :
  172. case NVKM_ENGINE_MSPDEC: context = 0x00400000; break;
  173. case NVKM_ENGINE_CIPHER:
  174. case NVKM_ENGINE_SEC :
  175. case NVKM_ENGINE_VIC : context = 0x00500000; break;
  176. case NVKM_ENGINE_BSP :
  177. case NVKM_ENGINE_MSVLD : context = 0x00600000; break;
  178. default:
  179. WARN_ON(1);
  180. return -EINVAL;
  181. }
  182. return nvkm_ramht_insert(chan->ramht, object, 0, 4, handle, context);
  183. }
  184. static void
  185. g84_fifo_chan_init(struct nvkm_fifo_chan *base)
  186. {
  187. struct nv50_fifo_chan *chan = nv50_fifo_chan(base);
  188. struct nv50_fifo *fifo = chan->fifo;
  189. struct nvkm_device *device = fifo->base.engine.subdev.device;
  190. u64 addr = chan->ramfc->addr >> 8;
  191. u32 chid = chan->base.chid;
  192. nvkm_wr32(device, 0x002600 + (chid * 4), 0x80000000 | addr);
  193. nv50_fifo_runlist_update(fifo);
  194. }
  195. static const struct nvkm_fifo_chan_func
  196. g84_fifo_chan_func = {
  197. .dtor = nv50_fifo_chan_dtor,
  198. .init = g84_fifo_chan_init,
  199. .fini = nv50_fifo_chan_fini,
  200. .ntfy = g84_fifo_chan_ntfy,
  201. .engine_ctor = g84_fifo_chan_engine_ctor,
  202. .engine_dtor = nv50_fifo_chan_engine_dtor,
  203. .engine_init = g84_fifo_chan_engine_init,
  204. .engine_fini = g84_fifo_chan_engine_fini,
  205. .object_ctor = g84_fifo_chan_object_ctor,
  206. .object_dtor = nv50_fifo_chan_object_dtor,
  207. };
  208. int
  209. g84_fifo_chan_ctor(struct nv50_fifo *fifo, u64 vm, u64 push,
  210. const struct nvkm_oclass *oclass,
  211. struct nv50_fifo_chan *chan)
  212. {
  213. struct nvkm_device *device = fifo->base.engine.subdev.device;
  214. int ret;
  215. ret = nvkm_fifo_chan_ctor(&g84_fifo_chan_func, &fifo->base,
  216. 0x10000, 0x1000, false, vm, push,
  217. (1ULL << NVKM_ENGINE_BSP) |
  218. (1ULL << NVKM_ENGINE_CE0) |
  219. (1ULL << NVKM_ENGINE_CIPHER) |
  220. (1ULL << NVKM_ENGINE_DMAOBJ) |
  221. (1ULL << NVKM_ENGINE_GR) |
  222. (1ULL << NVKM_ENGINE_ME) |
  223. (1ULL << NVKM_ENGINE_MPEG) |
  224. (1ULL << NVKM_ENGINE_MSPDEC) |
  225. (1ULL << NVKM_ENGINE_MSPPP) |
  226. (1ULL << NVKM_ENGINE_MSVLD) |
  227. (1ULL << NVKM_ENGINE_SEC) |
  228. (1ULL << NVKM_ENGINE_SW) |
  229. (1ULL << NVKM_ENGINE_VIC) |
  230. (1ULL << NVKM_ENGINE_VP),
  231. 0, 0xc00000, 0x2000, oclass, &chan->base);
  232. chan->fifo = fifo;
  233. if (ret)
  234. return ret;
  235. ret = nvkm_gpuobj_new(device, 0x0200, 0, true, chan->base.inst,
  236. &chan->eng);
  237. if (ret)
  238. return ret;
  239. ret = nvkm_gpuobj_new(device, 0x4000, 0, false, chan->base.inst,
  240. &chan->pgd);
  241. if (ret)
  242. return ret;
  243. ret = nvkm_gpuobj_new(device, 0x1000, 0x400, true, chan->base.inst,
  244. &chan->cache);
  245. if (ret)
  246. return ret;
  247. ret = nvkm_gpuobj_new(device, 0x100, 0x100, true, chan->base.inst,
  248. &chan->ramfc);
  249. if (ret)
  250. return ret;
  251. ret = nvkm_ramht_new(device, 0x8000, 16, chan->base.inst, &chan->ramht);
  252. if (ret)
  253. return ret;
  254. return nvkm_vm_ref(chan->base.vm, &chan->vm, chan->pgd);
  255. }