nv50.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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 <core/client.h>
  26. #include <core/gpuobj.h>
  27. #include <engine/fifo.h>
  28. #include <nvif/class.h>
  29. u64
  30. nv50_gr_units(struct nvkm_gr *gr)
  31. {
  32. return nvkm_rd32(gr->engine.subdev.device, 0x1540);
  33. }
  34. /*******************************************************************************
  35. * Graphics object classes
  36. ******************************************************************************/
  37. static int
  38. nv50_gr_object_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  39. int align, struct nvkm_gpuobj **pgpuobj)
  40. {
  41. int ret = nvkm_gpuobj_new(object->engine->subdev.device, 16,
  42. align, false, parent, pgpuobj);
  43. if (ret == 0) {
  44. nvkm_kmap(*pgpuobj);
  45. nvkm_wo32(*pgpuobj, 0x00, object->oclass);
  46. nvkm_wo32(*pgpuobj, 0x04, 0x00000000);
  47. nvkm_wo32(*pgpuobj, 0x08, 0x00000000);
  48. nvkm_wo32(*pgpuobj, 0x0c, 0x00000000);
  49. nvkm_done(*pgpuobj);
  50. }
  51. return ret;
  52. }
  53. const struct nvkm_object_func
  54. nv50_gr_object = {
  55. .bind = nv50_gr_object_bind,
  56. };
  57. /*******************************************************************************
  58. * PGRAPH context
  59. ******************************************************************************/
  60. static int
  61. nv50_gr_chan_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  62. int align, struct nvkm_gpuobj **pgpuobj)
  63. {
  64. struct nv50_gr *gr = nv50_gr_chan(object)->gr;
  65. int ret = nvkm_gpuobj_new(gr->base.engine.subdev.device, gr->size,
  66. align, true, parent, pgpuobj);
  67. if (ret == 0) {
  68. nvkm_kmap(*pgpuobj);
  69. nv50_grctx_fill(gr->base.engine.subdev.device, *pgpuobj);
  70. nvkm_done(*pgpuobj);
  71. }
  72. return ret;
  73. }
  74. static const struct nvkm_object_func
  75. nv50_gr_chan = {
  76. .bind = nv50_gr_chan_bind,
  77. };
  78. int
  79. nv50_gr_chan_new(struct nvkm_gr *base, struct nvkm_fifo_chan *fifoch,
  80. const struct nvkm_oclass *oclass, struct nvkm_object **pobject)
  81. {
  82. struct nv50_gr *gr = nv50_gr(base);
  83. struct nv50_gr_chan *chan;
  84. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  85. return -ENOMEM;
  86. nvkm_object_ctor(&nv50_gr_chan, oclass, &chan->object);
  87. chan->gr = gr;
  88. *pobject = &chan->object;
  89. return 0;
  90. }
  91. /*******************************************************************************
  92. * PGRAPH engine/subdev functions
  93. ******************************************************************************/
  94. static const struct nvkm_bitfield nv50_mp_exec_errors[] = {
  95. { 0x01, "STACK_UNDERFLOW" },
  96. { 0x02, "STACK_MISMATCH" },
  97. { 0x04, "QUADON_ACTIVE" },
  98. { 0x08, "TIMEOUT" },
  99. { 0x10, "INVALID_OPCODE" },
  100. { 0x20, "PM_OVERFLOW" },
  101. { 0x40, "BREAKPOINT" },
  102. {}
  103. };
  104. static const struct nvkm_bitfield nv50_mpc_traps[] = {
  105. { 0x0000001, "LOCAL_LIMIT_READ" },
  106. { 0x0000010, "LOCAL_LIMIT_WRITE" },
  107. { 0x0000040, "STACK_LIMIT" },
  108. { 0x0000100, "GLOBAL_LIMIT_READ" },
  109. { 0x0001000, "GLOBAL_LIMIT_WRITE" },
  110. { 0x0010000, "MP0" },
  111. { 0x0020000, "MP1" },
  112. { 0x0040000, "GLOBAL_LIMIT_RED" },
  113. { 0x0400000, "GLOBAL_LIMIT_ATOM" },
  114. { 0x4000000, "MP2" },
  115. {}
  116. };
  117. static const struct nvkm_bitfield nv50_tex_traps[] = {
  118. { 0x00000001, "" }, /* any bit set? */
  119. { 0x00000002, "FAULT" },
  120. { 0x00000004, "STORAGE_TYPE_MISMATCH" },
  121. { 0x00000008, "LINEAR_MISMATCH" },
  122. { 0x00000020, "WRONG_MEMTYPE" },
  123. {}
  124. };
  125. static const struct nvkm_bitfield nv50_gr_trap_m2mf[] = {
  126. { 0x00000001, "NOTIFY" },
  127. { 0x00000002, "IN" },
  128. { 0x00000004, "OUT" },
  129. {}
  130. };
  131. static const struct nvkm_bitfield nv50_gr_trap_vfetch[] = {
  132. { 0x00000001, "FAULT" },
  133. {}
  134. };
  135. static const struct nvkm_bitfield nv50_gr_trap_strmout[] = {
  136. { 0x00000001, "FAULT" },
  137. {}
  138. };
  139. static const struct nvkm_bitfield nv50_gr_trap_ccache[] = {
  140. { 0x00000001, "FAULT" },
  141. {}
  142. };
  143. /* There must be a *lot* of these. Will take some time to gather them up. */
  144. const struct nvkm_enum nv50_data_error_names[] = {
  145. { 0x00000003, "INVALID_OPERATION", NULL },
  146. { 0x00000004, "INVALID_VALUE", NULL },
  147. { 0x00000005, "INVALID_ENUM", NULL },
  148. { 0x00000008, "INVALID_OBJECT", NULL },
  149. { 0x00000009, "READ_ONLY_OBJECT", NULL },
  150. { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
  151. { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
  152. { 0x0000000c, "INVALID_BITFIELD", NULL },
  153. { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
  154. { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
  155. { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
  156. { 0x00000010, "RT_DOUBLE_BIND", NULL },
  157. { 0x00000011, "RT_TYPES_MISMATCH", NULL },
  158. { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
  159. { 0x00000015, "FP_TOO_FEW_REGS", NULL },
  160. { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
  161. { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
  162. { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
  163. { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
  164. { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
  165. { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
  166. { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
  167. { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
  168. { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
  169. { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
  170. { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
  171. { 0x00000024, "VP_ZERO_INPUTS", NULL },
  172. { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
  173. { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
  174. { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
  175. { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
  176. { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
  177. { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
  178. { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
  179. { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
  180. { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
  181. { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
  182. { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
  183. { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
  184. { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
  185. { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
  186. { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
  187. {}
  188. };
  189. static const struct nvkm_bitfield nv50_gr_intr_name[] = {
  190. { 0x00000001, "NOTIFY" },
  191. { 0x00000002, "COMPUTE_QUERY" },
  192. { 0x00000010, "ILLEGAL_MTHD" },
  193. { 0x00000020, "ILLEGAL_CLASS" },
  194. { 0x00000040, "DOUBLE_NOTIFY" },
  195. { 0x00001000, "CONTEXT_SWITCH" },
  196. { 0x00010000, "BUFFER_NOTIFY" },
  197. { 0x00100000, "DATA_ERROR" },
  198. { 0x00200000, "TRAP" },
  199. { 0x01000000, "SINGLE_STEP" },
  200. {}
  201. };
  202. static const struct nvkm_bitfield nv50_gr_trap_prop[] = {
  203. { 0x00000004, "SURF_WIDTH_OVERRUN" },
  204. { 0x00000008, "SURF_HEIGHT_OVERRUN" },
  205. { 0x00000010, "DST2D_FAULT" },
  206. { 0x00000020, "ZETA_FAULT" },
  207. { 0x00000040, "RT_FAULT" },
  208. { 0x00000080, "CUDA_FAULT" },
  209. { 0x00000100, "DST2D_STORAGE_TYPE_MISMATCH" },
  210. { 0x00000200, "ZETA_STORAGE_TYPE_MISMATCH" },
  211. { 0x00000400, "RT_STORAGE_TYPE_MISMATCH" },
  212. { 0x00000800, "DST2D_LINEAR_MISMATCH" },
  213. { 0x00001000, "RT_LINEAR_MISMATCH" },
  214. {}
  215. };
  216. static void
  217. nv50_gr_prop_trap(struct nv50_gr *gr, u32 ustatus_addr, u32 ustatus, u32 tp)
  218. {
  219. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  220. struct nvkm_device *device = subdev->device;
  221. u32 e0c = nvkm_rd32(device, ustatus_addr + 0x04);
  222. u32 e10 = nvkm_rd32(device, ustatus_addr + 0x08);
  223. u32 e14 = nvkm_rd32(device, ustatus_addr + 0x0c);
  224. u32 e18 = nvkm_rd32(device, ustatus_addr + 0x10);
  225. u32 e1c = nvkm_rd32(device, ustatus_addr + 0x14);
  226. u32 e20 = nvkm_rd32(device, ustatus_addr + 0x18);
  227. u32 e24 = nvkm_rd32(device, ustatus_addr + 0x1c);
  228. char msg[128];
  229. /* CUDA memory: l[], g[] or stack. */
  230. if (ustatus & 0x00000080) {
  231. if (e18 & 0x80000000) {
  232. /* g[] read fault? */
  233. nvkm_error(subdev, "TRAP_PROP - TP %d - CUDA_FAULT - Global read fault at address %02x%08x\n",
  234. tp, e14, e10 | ((e18 >> 24) & 0x1f));
  235. e18 &= ~0x1f000000;
  236. } else if (e18 & 0xc) {
  237. /* g[] write fault? */
  238. nvkm_error(subdev, "TRAP_PROP - TP %d - CUDA_FAULT - Global write fault at address %02x%08x\n",
  239. tp, e14, e10 | ((e18 >> 7) & 0x1f));
  240. e18 &= ~0x00000f80;
  241. } else {
  242. nvkm_error(subdev, "TRAP_PROP - TP %d - Unknown CUDA fault at address %02x%08x\n",
  243. tp, e14, e10);
  244. }
  245. ustatus &= ~0x00000080;
  246. }
  247. if (ustatus) {
  248. nvkm_snprintbf(msg, sizeof(msg), nv50_gr_trap_prop, ustatus);
  249. nvkm_error(subdev, "TRAP_PROP - TP %d - %08x [%s] - "
  250. "Address %02x%08x\n",
  251. tp, ustatus, msg, e14, e10);
  252. }
  253. nvkm_error(subdev, "TRAP_PROP - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  254. tp, e0c, e18, e1c, e20, e24);
  255. }
  256. static void
  257. nv50_gr_mp_trap(struct nv50_gr *gr, int tpid, int display)
  258. {
  259. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  260. struct nvkm_device *device = subdev->device;
  261. u32 units = nvkm_rd32(device, 0x1540);
  262. u32 addr, mp10, status, pc, oplow, ophigh;
  263. char msg[128];
  264. int i;
  265. int mps = 0;
  266. for (i = 0; i < 4; i++) {
  267. if (!(units & 1 << (i+24)))
  268. continue;
  269. if (device->chipset < 0xa0)
  270. addr = 0x408200 + (tpid << 12) + (i << 7);
  271. else
  272. addr = 0x408100 + (tpid << 11) + (i << 7);
  273. mp10 = nvkm_rd32(device, addr + 0x10);
  274. status = nvkm_rd32(device, addr + 0x14);
  275. if (!status)
  276. continue;
  277. if (display) {
  278. nvkm_rd32(device, addr + 0x20);
  279. pc = nvkm_rd32(device, addr + 0x24);
  280. oplow = nvkm_rd32(device, addr + 0x70);
  281. ophigh = nvkm_rd32(device, addr + 0x74);
  282. nvkm_snprintbf(msg, sizeof(msg),
  283. nv50_mp_exec_errors, status);
  284. nvkm_error(subdev, "TRAP_MP_EXEC - TP %d MP %d: "
  285. "%08x [%s] at %06x warp %d, "
  286. "opcode %08x %08x\n",
  287. tpid, i, status, msg, pc & 0xffffff,
  288. pc >> 24, oplow, ophigh);
  289. }
  290. nvkm_wr32(device, addr + 0x10, mp10);
  291. nvkm_wr32(device, addr + 0x14, 0);
  292. mps++;
  293. }
  294. if (!mps && display)
  295. nvkm_error(subdev, "TRAP_MP_EXEC - TP %d: "
  296. "No MPs claiming errors?\n", tpid);
  297. }
  298. static void
  299. nv50_gr_tp_trap(struct nv50_gr *gr, int type, u32 ustatus_old,
  300. u32 ustatus_new, int display, const char *name)
  301. {
  302. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  303. struct nvkm_device *device = subdev->device;
  304. u32 units = nvkm_rd32(device, 0x1540);
  305. int tps = 0;
  306. int i, r;
  307. char msg[128];
  308. u32 ustatus_addr, ustatus;
  309. for (i = 0; i < 16; i++) {
  310. if (!(units & (1 << i)))
  311. continue;
  312. if (device->chipset < 0xa0)
  313. ustatus_addr = ustatus_old + (i << 12);
  314. else
  315. ustatus_addr = ustatus_new + (i << 11);
  316. ustatus = nvkm_rd32(device, ustatus_addr) & 0x7fffffff;
  317. if (!ustatus)
  318. continue;
  319. tps++;
  320. switch (type) {
  321. case 6: /* texture error... unknown for now */
  322. if (display) {
  323. nvkm_error(subdev, "magic set %d:\n", i);
  324. for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
  325. nvkm_error(subdev, "\t%08x: %08x\n", r,
  326. nvkm_rd32(device, r));
  327. if (ustatus) {
  328. nvkm_snprintbf(msg, sizeof(msg),
  329. nv50_tex_traps, ustatus);
  330. nvkm_error(subdev,
  331. "%s - TP%d: %08x [%s]\n",
  332. name, i, ustatus, msg);
  333. ustatus = 0;
  334. }
  335. }
  336. break;
  337. case 7: /* MP error */
  338. if (ustatus & 0x04030000) {
  339. nv50_gr_mp_trap(gr, i, display);
  340. ustatus &= ~0x04030000;
  341. }
  342. if (ustatus && display) {
  343. nvkm_snprintbf(msg, sizeof(msg),
  344. nv50_mpc_traps, ustatus);
  345. nvkm_error(subdev, "%s - TP%d: %08x [%s]\n",
  346. name, i, ustatus, msg);
  347. ustatus = 0;
  348. }
  349. break;
  350. case 8: /* PROP error */
  351. if (display)
  352. nv50_gr_prop_trap(
  353. gr, ustatus_addr, ustatus, i);
  354. ustatus = 0;
  355. break;
  356. }
  357. if (ustatus) {
  358. if (display)
  359. nvkm_error(subdev, "%s - TP%d: Unhandled ustatus %08x\n", name, i, ustatus);
  360. }
  361. nvkm_wr32(device, ustatus_addr, 0xc0000000);
  362. }
  363. if (!tps && display)
  364. nvkm_warn(subdev, "%s - No TPs claiming errors?\n", name);
  365. }
  366. static int
  367. nv50_gr_trap_handler(struct nv50_gr *gr, u32 display,
  368. int chid, u64 inst, const char *name)
  369. {
  370. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  371. struct nvkm_device *device = subdev->device;
  372. u32 status = nvkm_rd32(device, 0x400108);
  373. u32 ustatus;
  374. char msg[128];
  375. if (!status && display) {
  376. nvkm_error(subdev, "TRAP: no units reporting traps?\n");
  377. return 1;
  378. }
  379. /* DISPATCH: Relays commands to other units and handles NOTIFY,
  380. * COND, QUERY. If you get a trap from it, the command is still stuck
  381. * in DISPATCH and you need to do something about it. */
  382. if (status & 0x001) {
  383. ustatus = nvkm_rd32(device, 0x400804) & 0x7fffffff;
  384. if (!ustatus && display) {
  385. nvkm_error(subdev, "TRAP_DISPATCH - no ustatus?\n");
  386. }
  387. nvkm_wr32(device, 0x400500, 0x00000000);
  388. /* Known to be triggered by screwed up NOTIFY and COND... */
  389. if (ustatus & 0x00000001) {
  390. u32 addr = nvkm_rd32(device, 0x400808);
  391. u32 subc = (addr & 0x00070000) >> 16;
  392. u32 mthd = (addr & 0x00001ffc);
  393. u32 datal = nvkm_rd32(device, 0x40080c);
  394. u32 datah = nvkm_rd32(device, 0x400810);
  395. u32 class = nvkm_rd32(device, 0x400814);
  396. u32 r848 = nvkm_rd32(device, 0x400848);
  397. nvkm_error(subdev, "TRAP DISPATCH_FAULT\n");
  398. if (display && (addr & 0x80000000)) {
  399. nvkm_error(subdev,
  400. "ch %d [%010llx %s] subc %d "
  401. "class %04x mthd %04x data %08x%08x "
  402. "400808 %08x 400848 %08x\n",
  403. chid, inst, name, subc, class, mthd,
  404. datah, datal, addr, r848);
  405. } else
  406. if (display) {
  407. nvkm_error(subdev, "no stuck command?\n");
  408. }
  409. nvkm_wr32(device, 0x400808, 0);
  410. nvkm_wr32(device, 0x4008e8, nvkm_rd32(device, 0x4008e8) & 3);
  411. nvkm_wr32(device, 0x400848, 0);
  412. ustatus &= ~0x00000001;
  413. }
  414. if (ustatus & 0x00000002) {
  415. u32 addr = nvkm_rd32(device, 0x40084c);
  416. u32 subc = (addr & 0x00070000) >> 16;
  417. u32 mthd = (addr & 0x00001ffc);
  418. u32 data = nvkm_rd32(device, 0x40085c);
  419. u32 class = nvkm_rd32(device, 0x400814);
  420. nvkm_error(subdev, "TRAP DISPATCH_QUERY\n");
  421. if (display && (addr & 0x80000000)) {
  422. nvkm_error(subdev,
  423. "ch %d [%010llx %s] subc %d "
  424. "class %04x mthd %04x data %08x "
  425. "40084c %08x\n", chid, inst, name,
  426. subc, class, mthd, data, addr);
  427. } else
  428. if (display) {
  429. nvkm_error(subdev, "no stuck command?\n");
  430. }
  431. nvkm_wr32(device, 0x40084c, 0);
  432. ustatus &= ~0x00000002;
  433. }
  434. if (ustatus && display) {
  435. nvkm_error(subdev, "TRAP_DISPATCH "
  436. "(unknown %08x)\n", ustatus);
  437. }
  438. nvkm_wr32(device, 0x400804, 0xc0000000);
  439. nvkm_wr32(device, 0x400108, 0x001);
  440. status &= ~0x001;
  441. if (!status)
  442. return 0;
  443. }
  444. /* M2MF: Memory to memory copy engine. */
  445. if (status & 0x002) {
  446. u32 ustatus = nvkm_rd32(device, 0x406800) & 0x7fffffff;
  447. if (display) {
  448. nvkm_snprintbf(msg, sizeof(msg),
  449. nv50_gr_trap_m2mf, ustatus);
  450. nvkm_error(subdev, "TRAP_M2MF %08x [%s]\n",
  451. ustatus, msg);
  452. nvkm_error(subdev, "TRAP_M2MF %08x %08x %08x %08x\n",
  453. nvkm_rd32(device, 0x406804),
  454. nvkm_rd32(device, 0x406808),
  455. nvkm_rd32(device, 0x40680c),
  456. nvkm_rd32(device, 0x406810));
  457. }
  458. /* No sane way found yet -- just reset the bugger. */
  459. nvkm_wr32(device, 0x400040, 2);
  460. nvkm_wr32(device, 0x400040, 0);
  461. nvkm_wr32(device, 0x406800, 0xc0000000);
  462. nvkm_wr32(device, 0x400108, 0x002);
  463. status &= ~0x002;
  464. }
  465. /* VFETCH: Fetches data from vertex buffers. */
  466. if (status & 0x004) {
  467. u32 ustatus = nvkm_rd32(device, 0x400c04) & 0x7fffffff;
  468. if (display) {
  469. nvkm_snprintbf(msg, sizeof(msg),
  470. nv50_gr_trap_vfetch, ustatus);
  471. nvkm_error(subdev, "TRAP_VFETCH %08x [%s]\n",
  472. ustatus, msg);
  473. nvkm_error(subdev, "TRAP_VFETCH %08x %08x %08x %08x\n",
  474. nvkm_rd32(device, 0x400c00),
  475. nvkm_rd32(device, 0x400c08),
  476. nvkm_rd32(device, 0x400c0c),
  477. nvkm_rd32(device, 0x400c10));
  478. }
  479. nvkm_wr32(device, 0x400c04, 0xc0000000);
  480. nvkm_wr32(device, 0x400108, 0x004);
  481. status &= ~0x004;
  482. }
  483. /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
  484. if (status & 0x008) {
  485. ustatus = nvkm_rd32(device, 0x401800) & 0x7fffffff;
  486. if (display) {
  487. nvkm_snprintbf(msg, sizeof(msg),
  488. nv50_gr_trap_strmout, ustatus);
  489. nvkm_error(subdev, "TRAP_STRMOUT %08x [%s]\n",
  490. ustatus, msg);
  491. nvkm_error(subdev, "TRAP_STRMOUT %08x %08x %08x %08x\n",
  492. nvkm_rd32(device, 0x401804),
  493. nvkm_rd32(device, 0x401808),
  494. nvkm_rd32(device, 0x40180c),
  495. nvkm_rd32(device, 0x401810));
  496. }
  497. /* No sane way found yet -- just reset the bugger. */
  498. nvkm_wr32(device, 0x400040, 0x80);
  499. nvkm_wr32(device, 0x400040, 0);
  500. nvkm_wr32(device, 0x401800, 0xc0000000);
  501. nvkm_wr32(device, 0x400108, 0x008);
  502. status &= ~0x008;
  503. }
  504. /* CCACHE: Handles code and c[] caches and fills them. */
  505. if (status & 0x010) {
  506. ustatus = nvkm_rd32(device, 0x405018) & 0x7fffffff;
  507. if (display) {
  508. nvkm_snprintbf(msg, sizeof(msg),
  509. nv50_gr_trap_ccache, ustatus);
  510. nvkm_error(subdev, "TRAP_CCACHE %08x [%s]\n",
  511. ustatus, msg);
  512. nvkm_error(subdev, "TRAP_CCACHE %08x %08x %08x %08x "
  513. "%08x %08x %08x\n",
  514. nvkm_rd32(device, 0x405000),
  515. nvkm_rd32(device, 0x405004),
  516. nvkm_rd32(device, 0x405008),
  517. nvkm_rd32(device, 0x40500c),
  518. nvkm_rd32(device, 0x405010),
  519. nvkm_rd32(device, 0x405014),
  520. nvkm_rd32(device, 0x40501c));
  521. }
  522. nvkm_wr32(device, 0x405018, 0xc0000000);
  523. nvkm_wr32(device, 0x400108, 0x010);
  524. status &= ~0x010;
  525. }
  526. /* Unknown, not seen yet... 0x402000 is the only trap status reg
  527. * remaining, so try to handle it anyway. Perhaps related to that
  528. * unknown DMA slot on tesla? */
  529. if (status & 0x20) {
  530. ustatus = nvkm_rd32(device, 0x402000) & 0x7fffffff;
  531. if (display)
  532. nvkm_error(subdev, "TRAP_UNKC04 %08x\n", ustatus);
  533. nvkm_wr32(device, 0x402000, 0xc0000000);
  534. /* no status modifiction on purpose */
  535. }
  536. /* TEXTURE: CUDA texturing units */
  537. if (status & 0x040) {
  538. nv50_gr_tp_trap(gr, 6, 0x408900, 0x408600, display,
  539. "TRAP_TEXTURE");
  540. nvkm_wr32(device, 0x400108, 0x040);
  541. status &= ~0x040;
  542. }
  543. /* MP: CUDA execution engines. */
  544. if (status & 0x080) {
  545. nv50_gr_tp_trap(gr, 7, 0x408314, 0x40831c, display,
  546. "TRAP_MP");
  547. nvkm_wr32(device, 0x400108, 0x080);
  548. status &= ~0x080;
  549. }
  550. /* PROP: Handles TP-initiated uncached memory accesses:
  551. * l[], g[], stack, 2d surfaces, render targets. */
  552. if (status & 0x100) {
  553. nv50_gr_tp_trap(gr, 8, 0x408e08, 0x408708, display,
  554. "TRAP_PROP");
  555. nvkm_wr32(device, 0x400108, 0x100);
  556. status &= ~0x100;
  557. }
  558. if (status) {
  559. if (display)
  560. nvkm_error(subdev, "TRAP: unknown %08x\n", status);
  561. nvkm_wr32(device, 0x400108, status);
  562. }
  563. return 1;
  564. }
  565. void
  566. nv50_gr_intr(struct nvkm_gr *base)
  567. {
  568. struct nv50_gr *gr = nv50_gr(base);
  569. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  570. struct nvkm_device *device = subdev->device;
  571. struct nvkm_fifo_chan *chan;
  572. u32 stat = nvkm_rd32(device, 0x400100);
  573. u32 inst = nvkm_rd32(device, 0x40032c) & 0x0fffffff;
  574. u32 addr = nvkm_rd32(device, 0x400704);
  575. u32 subc = (addr & 0x00070000) >> 16;
  576. u32 mthd = (addr & 0x00001ffc);
  577. u32 data = nvkm_rd32(device, 0x400708);
  578. u32 class = nvkm_rd32(device, 0x400814);
  579. u32 show = stat, show_bitfield = stat;
  580. const struct nvkm_enum *en;
  581. unsigned long flags;
  582. const char *name = "unknown";
  583. char msg[128];
  584. int chid = -1;
  585. chan = nvkm_fifo_chan_inst(device->fifo, (u64)inst << 12, &flags);
  586. if (chan) {
  587. name = chan->object.client->name;
  588. chid = chan->chid;
  589. }
  590. if (show & 0x00100000) {
  591. u32 ecode = nvkm_rd32(device, 0x400110);
  592. en = nvkm_enum_find(nv50_data_error_names, ecode);
  593. nvkm_error(subdev, "DATA_ERROR %08x [%s]\n",
  594. ecode, en ? en->name : "");
  595. show_bitfield &= ~0x00100000;
  596. }
  597. if (stat & 0x00200000) {
  598. if (!nv50_gr_trap_handler(gr, show, chid, (u64)inst << 12, name))
  599. show &= ~0x00200000;
  600. show_bitfield &= ~0x00200000;
  601. }
  602. nvkm_wr32(device, 0x400100, stat);
  603. nvkm_wr32(device, 0x400500, 0x00010001);
  604. if (show) {
  605. show &= show_bitfield;
  606. nvkm_snprintbf(msg, sizeof(msg), nv50_gr_intr_name, show);
  607. nvkm_error(subdev, "%08x [%s] ch %d [%010llx %s] subc %d "
  608. "class %04x mthd %04x data %08x\n",
  609. stat, msg, chid, (u64)inst << 12, name,
  610. subc, class, mthd, data);
  611. }
  612. if (nvkm_rd32(device, 0x400824) & (1 << 31))
  613. nvkm_wr32(device, 0x400824, nvkm_rd32(device, 0x400824) & ~(1 << 31));
  614. nvkm_fifo_chan_put(device->fifo, flags, &chan);
  615. }
  616. int
  617. nv50_gr_init(struct nvkm_gr *base)
  618. {
  619. struct nv50_gr *gr = nv50_gr(base);
  620. struct nvkm_device *device = gr->base.engine.subdev.device;
  621. int ret, units, i;
  622. /* NV_PGRAPH_DEBUG_3_HW_CTX_SWITCH_ENABLED */
  623. nvkm_wr32(device, 0x40008c, 0x00000004);
  624. /* reset/enable traps and interrupts */
  625. nvkm_wr32(device, 0x400804, 0xc0000000);
  626. nvkm_wr32(device, 0x406800, 0xc0000000);
  627. nvkm_wr32(device, 0x400c04, 0xc0000000);
  628. nvkm_wr32(device, 0x401800, 0xc0000000);
  629. nvkm_wr32(device, 0x405018, 0xc0000000);
  630. nvkm_wr32(device, 0x402000, 0xc0000000);
  631. units = nvkm_rd32(device, 0x001540);
  632. for (i = 0; i < 16; i++) {
  633. if (!(units & (1 << i)))
  634. continue;
  635. if (device->chipset < 0xa0) {
  636. nvkm_wr32(device, 0x408900 + (i << 12), 0xc0000000);
  637. nvkm_wr32(device, 0x408e08 + (i << 12), 0xc0000000);
  638. nvkm_wr32(device, 0x408314 + (i << 12), 0xc0000000);
  639. } else {
  640. nvkm_wr32(device, 0x408600 + (i << 11), 0xc0000000);
  641. nvkm_wr32(device, 0x408708 + (i << 11), 0xc0000000);
  642. nvkm_wr32(device, 0x40831c + (i << 11), 0xc0000000);
  643. }
  644. }
  645. nvkm_wr32(device, 0x400108, 0xffffffff);
  646. nvkm_wr32(device, 0x400138, 0xffffffff);
  647. nvkm_wr32(device, 0x400100, 0xffffffff);
  648. nvkm_wr32(device, 0x40013c, 0xffffffff);
  649. nvkm_wr32(device, 0x400500, 0x00010001);
  650. /* upload context program, initialise ctxctl defaults */
  651. ret = nv50_grctx_init(device, &gr->size);
  652. if (ret)
  653. return ret;
  654. nvkm_wr32(device, 0x400824, 0x00000000);
  655. nvkm_wr32(device, 0x400828, 0x00000000);
  656. nvkm_wr32(device, 0x40082c, 0x00000000);
  657. nvkm_wr32(device, 0x400830, 0x00000000);
  658. nvkm_wr32(device, 0x40032c, 0x00000000);
  659. nvkm_wr32(device, 0x400330, 0x00000000);
  660. /* some unknown zcull magic */
  661. switch (device->chipset & 0xf0) {
  662. case 0x50:
  663. case 0x80:
  664. case 0x90:
  665. nvkm_wr32(device, 0x402ca8, 0x00000800);
  666. break;
  667. case 0xa0:
  668. default:
  669. if (device->chipset == 0xa0 ||
  670. device->chipset == 0xaa ||
  671. device->chipset == 0xac) {
  672. nvkm_wr32(device, 0x402ca8, 0x00000802);
  673. } else {
  674. nvkm_wr32(device, 0x402cc0, 0x00000000);
  675. nvkm_wr32(device, 0x402ca8, 0x00000002);
  676. }
  677. break;
  678. }
  679. /* zero out zcull regions */
  680. for (i = 0; i < 8; i++) {
  681. nvkm_wr32(device, 0x402c20 + (i * 0x10), 0x00000000);
  682. nvkm_wr32(device, 0x402c24 + (i * 0x10), 0x00000000);
  683. nvkm_wr32(device, 0x402c28 + (i * 0x10), 0x00000000);
  684. nvkm_wr32(device, 0x402c2c + (i * 0x10), 0x00000000);
  685. }
  686. return 0;
  687. }
  688. int
  689. nv50_gr_new_(const struct nvkm_gr_func *func, struct nvkm_device *device,
  690. int index, struct nvkm_gr **pgr)
  691. {
  692. struct nv50_gr *gr;
  693. if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
  694. return -ENOMEM;
  695. spin_lock_init(&gr->lock);
  696. *pgr = &gr->base;
  697. return nvkm_gr_ctor(func, device, index, true, &gr->base);
  698. }
  699. static const struct nvkm_gr_func
  700. nv50_gr = {
  701. .init = nv50_gr_init,
  702. .intr = nv50_gr_intr,
  703. .chan_new = nv50_gr_chan_new,
  704. .units = nv50_gr_units,
  705. .sclass = {
  706. { -1, -1, NV_NULL_CLASS, &nv50_gr_object },
  707. { -1, -1, NV50_TWOD, &nv50_gr_object },
  708. { -1, -1, NV50_MEMORY_TO_MEMORY_FORMAT, &nv50_gr_object },
  709. { -1, -1, NV50_TESLA, &nv50_gr_object },
  710. { -1, -1, NV50_COMPUTE, &nv50_gr_object },
  711. {}
  712. }
  713. };
  714. int
  715. nv50_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  716. {
  717. return nv50_gr_new_(&nv50_gr, device, index, pgr);
  718. }