nv50.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 "nv50.h"
  25. #include "ram.h"
  26. #include <core/client.h>
  27. #include <core/enum.h>
  28. #include <engine/fifo.h>
  29. static int
  30. nv50_fb_ram_new(struct nvkm_fb *base, struct nvkm_ram **pram)
  31. {
  32. struct nv50_fb *fb = nv50_fb(base);
  33. return fb->func->ram_new(&fb->base, pram);
  34. }
  35. static const struct nvkm_enum vm_dispatch_subclients[] = {
  36. { 0x00000000, "GRCTX" },
  37. { 0x00000001, "NOTIFY" },
  38. { 0x00000002, "QUERY" },
  39. { 0x00000003, "COND" },
  40. { 0x00000004, "M2M_IN" },
  41. { 0x00000005, "M2M_OUT" },
  42. { 0x00000006, "M2M_NOTIFY" },
  43. {}
  44. };
  45. static const struct nvkm_enum vm_ccache_subclients[] = {
  46. { 0x00000000, "CB" },
  47. { 0x00000001, "TIC" },
  48. { 0x00000002, "TSC" },
  49. {}
  50. };
  51. static const struct nvkm_enum vm_prop_subclients[] = {
  52. { 0x00000000, "RT0" },
  53. { 0x00000001, "RT1" },
  54. { 0x00000002, "RT2" },
  55. { 0x00000003, "RT3" },
  56. { 0x00000004, "RT4" },
  57. { 0x00000005, "RT5" },
  58. { 0x00000006, "RT6" },
  59. { 0x00000007, "RT7" },
  60. { 0x00000008, "ZETA" },
  61. { 0x00000009, "LOCAL" },
  62. { 0x0000000a, "GLOBAL" },
  63. { 0x0000000b, "STACK" },
  64. { 0x0000000c, "DST2D" },
  65. {}
  66. };
  67. static const struct nvkm_enum vm_pfifo_subclients[] = {
  68. { 0x00000000, "PUSHBUF" },
  69. { 0x00000001, "SEMAPHORE" },
  70. {}
  71. };
  72. static const struct nvkm_enum vm_bar_subclients[] = {
  73. { 0x00000000, "FB" },
  74. { 0x00000001, "IN" },
  75. {}
  76. };
  77. static const struct nvkm_enum vm_client[] = {
  78. { 0x00000000, "STRMOUT" },
  79. { 0x00000003, "DISPATCH", vm_dispatch_subclients },
  80. { 0x00000004, "PFIFO_WRITE" },
  81. { 0x00000005, "CCACHE", vm_ccache_subclients },
  82. { 0x00000006, "PMSPPP" },
  83. { 0x00000007, "CLIPID" },
  84. { 0x00000008, "PFIFO_READ" },
  85. { 0x00000009, "VFETCH" },
  86. { 0x0000000a, "TEXTURE" },
  87. { 0x0000000b, "PROP", vm_prop_subclients },
  88. { 0x0000000c, "PVP" },
  89. { 0x0000000d, "PBSP" },
  90. { 0x0000000e, "PCRYPT" },
  91. { 0x0000000f, "PCOUNTER" },
  92. { 0x00000011, "PDAEMON" },
  93. {}
  94. };
  95. static const struct nvkm_enum vm_engine[] = {
  96. { 0x00000000, "PGRAPH" },
  97. { 0x00000001, "PVP" },
  98. { 0x00000004, "PEEPHOLE" },
  99. { 0x00000005, "PFIFO", vm_pfifo_subclients },
  100. { 0x00000006, "BAR", vm_bar_subclients },
  101. { 0x00000008, "PMSPPP" },
  102. { 0x00000008, "PMPEG" },
  103. { 0x00000009, "PBSP" },
  104. { 0x0000000a, "PCRYPT" },
  105. { 0x0000000b, "PCOUNTER" },
  106. { 0x0000000c, "SEMAPHORE_BG" },
  107. { 0x0000000d, "PCE0" },
  108. { 0x0000000e, "PMU" },
  109. {}
  110. };
  111. static const struct nvkm_enum vm_fault[] = {
  112. { 0x00000000, "PT_NOT_PRESENT" },
  113. { 0x00000001, "PT_TOO_SHORT" },
  114. { 0x00000002, "PAGE_NOT_PRESENT" },
  115. { 0x00000003, "PAGE_SYSTEM_ONLY" },
  116. { 0x00000004, "PAGE_READ_ONLY" },
  117. { 0x00000006, "NULL_DMAOBJ" },
  118. { 0x00000007, "WRONG_MEMTYPE" },
  119. { 0x0000000b, "VRAM_LIMIT" },
  120. { 0x0000000f, "DMAOBJ_LIMIT" },
  121. {}
  122. };
  123. static void
  124. nv50_fb_intr(struct nvkm_fb *base)
  125. {
  126. struct nv50_fb *fb = nv50_fb(base);
  127. struct nvkm_subdev *subdev = &fb->base.subdev;
  128. struct nvkm_device *device = subdev->device;
  129. struct nvkm_fifo *fifo = device->fifo;
  130. struct nvkm_fifo_chan *chan;
  131. const struct nvkm_enum *en, *re, *cl, *sc;
  132. u32 trap[6], idx, inst;
  133. u8 st0, st1, st2, st3;
  134. unsigned long flags;
  135. int i;
  136. idx = nvkm_rd32(device, 0x100c90);
  137. if (!(idx & 0x80000000))
  138. return;
  139. idx &= 0x00ffffff;
  140. for (i = 0; i < 6; i++) {
  141. nvkm_wr32(device, 0x100c90, idx | i << 24);
  142. trap[i] = nvkm_rd32(device, 0x100c94);
  143. }
  144. nvkm_wr32(device, 0x100c90, idx | 0x80000000);
  145. /* decode status bits into something more useful */
  146. if (device->chipset < 0xa3 ||
  147. device->chipset == 0xaa || device->chipset == 0xac) {
  148. st0 = (trap[0] & 0x0000000f) >> 0;
  149. st1 = (trap[0] & 0x000000f0) >> 4;
  150. st2 = (trap[0] & 0x00000f00) >> 8;
  151. st3 = (trap[0] & 0x0000f000) >> 12;
  152. } else {
  153. st0 = (trap[0] & 0x000000ff) >> 0;
  154. st1 = (trap[0] & 0x0000ff00) >> 8;
  155. st2 = (trap[0] & 0x00ff0000) >> 16;
  156. st3 = (trap[0] & 0xff000000) >> 24;
  157. }
  158. inst = ((trap[2] << 16) | trap[1]) << 12;
  159. en = nvkm_enum_find(vm_engine, st0);
  160. re = nvkm_enum_find(vm_fault , st1);
  161. cl = nvkm_enum_find(vm_client, st2);
  162. if (cl && cl->data) sc = nvkm_enum_find(cl->data, st3);
  163. else if (en && en->data) sc = nvkm_enum_find(en->data, st3);
  164. else sc = NULL;
  165. chan = nvkm_fifo_chan_inst(fifo, inst, &flags);
  166. nvkm_error(subdev, "trapped %s at %02x%04x%04x on channel %d [%08x %s] "
  167. "engine %02x [%s] client %02x [%s] "
  168. "subclient %02x [%s] reason %08x [%s]\n",
  169. (trap[5] & 0x00000100) ? "read" : "write",
  170. trap[5] & 0xff, trap[4] & 0xffff, trap[3] & 0xffff,
  171. chan ? chan->chid : -1, inst,
  172. chan ? chan->object.client->name : "unknown",
  173. st0, en ? en->name : "",
  174. st2, cl ? cl->name : "", st3, sc ? sc->name : "",
  175. st1, re ? re->name : "");
  176. nvkm_fifo_chan_put(fifo, flags, &chan);
  177. }
  178. static int
  179. nv50_fb_oneinit(struct nvkm_fb *base)
  180. {
  181. struct nv50_fb *fb = nv50_fb(base);
  182. struct nvkm_device *device = fb->base.subdev.device;
  183. fb->r100c08_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
  184. if (fb->r100c08_page) {
  185. fb->r100c08 = dma_map_page(device->dev, fb->r100c08_page, 0,
  186. PAGE_SIZE, DMA_BIDIRECTIONAL);
  187. if (dma_mapping_error(device->dev, fb->r100c08))
  188. return -EFAULT;
  189. }
  190. return 0;
  191. }
  192. static void
  193. nv50_fb_init(struct nvkm_fb *base)
  194. {
  195. struct nv50_fb *fb = nv50_fb(base);
  196. struct nvkm_device *device = fb->base.subdev.device;
  197. /* Not a clue what this is exactly. Without pointing it at a
  198. * scratch page, VRAM->GART blits with M2MF (as in DDX DFS)
  199. * cause IOMMU "read from address 0" errors (rh#561267)
  200. */
  201. nvkm_wr32(device, 0x100c08, fb->r100c08 >> 8);
  202. /* This is needed to get meaningful information from 100c90
  203. * on traps. No idea what these values mean exactly. */
  204. nvkm_wr32(device, 0x100c90, fb->func->trap);
  205. }
  206. static u32
  207. nv50_fb_tags(struct nvkm_fb *base)
  208. {
  209. struct nv50_fb *fb = nv50_fb(base);
  210. if (fb->func->tags)
  211. return fb->func->tags(&fb->base);
  212. return 0;
  213. }
  214. static void *
  215. nv50_fb_dtor(struct nvkm_fb *base)
  216. {
  217. struct nv50_fb *fb = nv50_fb(base);
  218. struct nvkm_device *device = fb->base.subdev.device;
  219. if (fb->r100c08_page) {
  220. dma_unmap_page(device->dev, fb->r100c08, PAGE_SIZE,
  221. DMA_BIDIRECTIONAL);
  222. __free_page(fb->r100c08_page);
  223. }
  224. return fb;
  225. }
  226. static const struct nvkm_fb_func
  227. nv50_fb_ = {
  228. .dtor = nv50_fb_dtor,
  229. .tags = nv50_fb_tags,
  230. .oneinit = nv50_fb_oneinit,
  231. .init = nv50_fb_init,
  232. .intr = nv50_fb_intr,
  233. .ram_new = nv50_fb_ram_new,
  234. };
  235. int
  236. nv50_fb_new_(const struct nv50_fb_func *func, struct nvkm_device *device,
  237. int index, struct nvkm_fb **pfb)
  238. {
  239. struct nv50_fb *fb;
  240. if (!(fb = kzalloc(sizeof(*fb), GFP_KERNEL)))
  241. return -ENOMEM;
  242. nvkm_fb_ctor(&nv50_fb_, device, index, &fb->base);
  243. fb->func = func;
  244. *pfb = &fb->base;
  245. return 0;
  246. }
  247. static const struct nv50_fb_func
  248. nv50_fb = {
  249. .ram_new = nv50_ram_new,
  250. .tags = nv20_fb_tags,
  251. .trap = 0x000707ff,
  252. };
  253. int
  254. nv50_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
  255. {
  256. return nv50_fb_new_(&nv50_fb, device, index, pfb);
  257. }