nv50.c 8.1 KB

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