nv50.c 23 KB

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