nv50_graph.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /*
  2. * Copyright (C) 2007 Ben Skeggs.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_fifo.h"
  29. #include "nouveau_ramht.h"
  30. #include "nouveau_dma.h"
  31. #include "nouveau_vm.h"
  32. #include "nv50_evo.h"
  33. struct nv50_graph_engine {
  34. struct nouveau_exec_engine base;
  35. u32 ctxprog[512];
  36. u32 ctxprog_size;
  37. u32 grctx_size;
  38. };
  39. static int
  40. nv50_graph_init(struct drm_device *dev, int engine)
  41. {
  42. struct drm_nouveau_private *dev_priv = dev->dev_private;
  43. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  44. u32 units = nv_rd32(dev, 0x001540);
  45. int i;
  46. NV_DEBUG(dev, "\n");
  47. /* master reset */
  48. nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
  49. nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
  50. nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
  51. /* reset/enable traps and interrupts */
  52. nv_wr32(dev, 0x400804, 0xc0000000);
  53. nv_wr32(dev, 0x406800, 0xc0000000);
  54. nv_wr32(dev, 0x400c04, 0xc0000000);
  55. nv_wr32(dev, 0x401800, 0xc0000000);
  56. nv_wr32(dev, 0x405018, 0xc0000000);
  57. nv_wr32(dev, 0x402000, 0xc0000000);
  58. for (i = 0; i < 16; i++) {
  59. if (!(units & (1 << i)))
  60. continue;
  61. if (dev_priv->chipset < 0xa0) {
  62. nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
  63. nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
  64. nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
  65. } else {
  66. nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
  67. nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
  68. nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
  69. }
  70. }
  71. nv_wr32(dev, 0x400108, 0xffffffff);
  72. nv_wr32(dev, 0x400138, 0xffffffff);
  73. nv_wr32(dev, 0x400100, 0xffffffff);
  74. nv_wr32(dev, 0x40013c, 0xffffffff);
  75. nv_wr32(dev, 0x400500, 0x00010001);
  76. /* upload context program, initialise ctxctl defaults */
  77. nv_wr32(dev, 0x400324, 0x00000000);
  78. for (i = 0; i < pgraph->ctxprog_size; i++)
  79. nv_wr32(dev, 0x400328, pgraph->ctxprog[i]);
  80. nv_wr32(dev, 0x400824, 0x00000000);
  81. nv_wr32(dev, 0x400828, 0x00000000);
  82. nv_wr32(dev, 0x40082c, 0x00000000);
  83. nv_wr32(dev, 0x400830, 0x00000000);
  84. nv_wr32(dev, 0x400724, 0x00000000);
  85. nv_wr32(dev, 0x40032c, 0x00000000);
  86. nv_wr32(dev, 0x400320, 4); /* CTXCTL_CMD = NEWCTXDMA */
  87. /* some unknown zcull magic */
  88. switch (dev_priv->chipset & 0xf0) {
  89. case 0x50:
  90. case 0x80:
  91. case 0x90:
  92. nv_wr32(dev, 0x402ca8, 0x00000800);
  93. break;
  94. case 0xa0:
  95. default:
  96. nv_wr32(dev, 0x402cc0, 0x00000000);
  97. if (dev_priv->chipset == 0xa0 ||
  98. dev_priv->chipset == 0xaa ||
  99. dev_priv->chipset == 0xac) {
  100. nv_wr32(dev, 0x402ca8, 0x00000802);
  101. } else {
  102. nv_wr32(dev, 0x402cc0, 0x00000000);
  103. nv_wr32(dev, 0x402ca8, 0x00000002);
  104. }
  105. break;
  106. }
  107. /* zero out zcull regions */
  108. for (i = 0; i < 8; i++) {
  109. nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
  110. nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
  111. nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
  112. nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
  113. }
  114. return 0;
  115. }
  116. static int
  117. nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
  118. {
  119. nv_wr32(dev, 0x40013c, 0x00000000);
  120. return 0;
  121. }
  122. static int
  123. nv50_graph_context_new(struct nouveau_channel *chan, int engine)
  124. {
  125. struct drm_device *dev = chan->dev;
  126. struct drm_nouveau_private *dev_priv = dev->dev_private;
  127. struct nouveau_gpuobj *ramin = chan->ramin;
  128. struct nouveau_gpuobj *grctx = NULL;
  129. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  130. int hdr, ret;
  131. NV_DEBUG(dev, "ch%d\n", chan->id);
  132. ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
  133. NVOBJ_FLAG_ZERO_ALLOC |
  134. NVOBJ_FLAG_ZERO_FREE, &grctx);
  135. if (ret)
  136. return ret;
  137. hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
  138. nv_wo32(ramin, hdr + 0x00, 0x00190002);
  139. nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
  140. nv_wo32(ramin, hdr + 0x08, grctx->vinst);
  141. nv_wo32(ramin, hdr + 0x0c, 0);
  142. nv_wo32(ramin, hdr + 0x10, 0);
  143. nv_wo32(ramin, hdr + 0x14, 0x00010000);
  144. nv50_grctx_fill(dev, grctx);
  145. nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
  146. dev_priv->engine.instmem.flush(dev);
  147. atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
  148. chan->engctx[NVOBJ_ENGINE_GR] = grctx;
  149. return 0;
  150. }
  151. static void
  152. nv50_graph_context_del(struct nouveau_channel *chan, int engine)
  153. {
  154. struct nouveau_gpuobj *grctx = chan->engctx[engine];
  155. struct drm_device *dev = chan->dev;
  156. struct drm_nouveau_private *dev_priv = dev->dev_private;
  157. int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
  158. for (i = hdr; i < hdr + 24; i += 4)
  159. nv_wo32(chan->ramin, i, 0);
  160. dev_priv->engine.instmem.flush(dev);
  161. atomic_dec(&chan->vm->engref[engine]);
  162. nouveau_gpuobj_ref(NULL, &grctx);
  163. chan->engctx[engine] = NULL;
  164. }
  165. static int
  166. nv50_graph_object_new(struct nouveau_channel *chan, int engine,
  167. u32 handle, u16 class)
  168. {
  169. struct drm_device *dev = chan->dev;
  170. struct drm_nouveau_private *dev_priv = dev->dev_private;
  171. struct nouveau_gpuobj *obj = NULL;
  172. int ret;
  173. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  174. if (ret)
  175. return ret;
  176. obj->engine = 1;
  177. obj->class = class;
  178. nv_wo32(obj, 0x00, class);
  179. nv_wo32(obj, 0x04, 0x00000000);
  180. nv_wo32(obj, 0x08, 0x00000000);
  181. nv_wo32(obj, 0x0c, 0x00000000);
  182. dev_priv->engine.instmem.flush(dev);
  183. ret = nouveau_ramht_insert(chan, handle, obj);
  184. nouveau_gpuobj_ref(NULL, &obj);
  185. return ret;
  186. }
  187. static void
  188. nv50_graph_tlb_flush(struct drm_device *dev, int engine)
  189. {
  190. nv50_vm_flush_engine(dev, 0);
  191. }
  192. static void
  193. nv84_graph_tlb_flush(struct drm_device *dev, int engine)
  194. {
  195. struct drm_nouveau_private *dev_priv = dev->dev_private;
  196. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  197. bool idle, timeout = false;
  198. unsigned long flags;
  199. u64 start;
  200. u32 tmp;
  201. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  202. nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
  203. start = ptimer->read(dev);
  204. do {
  205. idle = true;
  206. for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
  207. if ((tmp & 7) == 1)
  208. idle = false;
  209. }
  210. for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
  211. if ((tmp & 7) == 1)
  212. idle = false;
  213. }
  214. for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
  215. if ((tmp & 7) == 1)
  216. idle = false;
  217. }
  218. } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
  219. if (timeout) {
  220. NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
  221. "0x%08x 0x%08x 0x%08x 0x%08x\n",
  222. nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
  223. nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
  224. }
  225. nv50_vm_flush_engine(dev, 0);
  226. nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
  227. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  228. }
  229. static struct nouveau_enum nv50_mp_exec_error_names[] = {
  230. { 3, "STACK_UNDERFLOW", NULL },
  231. { 4, "QUADON_ACTIVE", NULL },
  232. { 8, "TIMEOUT", NULL },
  233. { 0x10, "INVALID_OPCODE", NULL },
  234. { 0x40, "BREAKPOINT", NULL },
  235. {}
  236. };
  237. static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
  238. { 0x00000001, "NOTIFY" },
  239. { 0x00000002, "IN" },
  240. { 0x00000004, "OUT" },
  241. {}
  242. };
  243. static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
  244. { 0x00000001, "FAULT" },
  245. {}
  246. };
  247. static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
  248. { 0x00000001, "FAULT" },
  249. {}
  250. };
  251. static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
  252. { 0x00000001, "FAULT" },
  253. {}
  254. };
  255. /* There must be a *lot* of these. Will take some time to gather them up. */
  256. struct nouveau_enum nv50_data_error_names[] = {
  257. { 0x00000003, "INVALID_OPERATION", NULL },
  258. { 0x00000004, "INVALID_VALUE", NULL },
  259. { 0x00000005, "INVALID_ENUM", NULL },
  260. { 0x00000008, "INVALID_OBJECT", NULL },
  261. { 0x00000009, "READ_ONLY_OBJECT", NULL },
  262. { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
  263. { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
  264. { 0x0000000c, "INVALID_BITFIELD", NULL },
  265. { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
  266. { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
  267. { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
  268. { 0x00000010, "RT_DOUBLE_BIND", NULL },
  269. { 0x00000011, "RT_TYPES_MISMATCH", NULL },
  270. { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
  271. { 0x00000015, "FP_TOO_FEW_REGS", NULL },
  272. { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
  273. { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
  274. { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
  275. { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
  276. { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
  277. { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
  278. { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
  279. { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
  280. { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
  281. { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
  282. { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
  283. { 0x00000024, "VP_ZERO_INPUTS", NULL },
  284. { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
  285. { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
  286. { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
  287. { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
  288. { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
  289. { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
  290. { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
  291. { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
  292. { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
  293. { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
  294. { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
  295. { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
  296. { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
  297. { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
  298. { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
  299. {}
  300. };
  301. static struct nouveau_bitfield nv50_graph_intr[] = {
  302. { 0x00000001, "NOTIFY" },
  303. { 0x00000002, "COMPUTE_QUERY" },
  304. { 0x00000010, "ILLEGAL_MTHD" },
  305. { 0x00000020, "ILLEGAL_CLASS" },
  306. { 0x00000040, "DOUBLE_NOTIFY" },
  307. { 0x00001000, "CONTEXT_SWITCH" },
  308. { 0x00010000, "BUFFER_NOTIFY" },
  309. { 0x00100000, "DATA_ERROR" },
  310. { 0x00200000, "TRAP" },
  311. { 0x01000000, "SINGLE_STEP" },
  312. {}
  313. };
  314. static void
  315. nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
  316. {
  317. struct drm_nouveau_private *dev_priv = dev->dev_private;
  318. uint32_t units = nv_rd32(dev, 0x1540);
  319. uint32_t addr, mp10, status, pc, oplow, ophigh;
  320. int i;
  321. int mps = 0;
  322. for (i = 0; i < 4; i++) {
  323. if (!(units & 1 << (i+24)))
  324. continue;
  325. if (dev_priv->chipset < 0xa0)
  326. addr = 0x408200 + (tpid << 12) + (i << 7);
  327. else
  328. addr = 0x408100 + (tpid << 11) + (i << 7);
  329. mp10 = nv_rd32(dev, addr + 0x10);
  330. status = nv_rd32(dev, addr + 0x14);
  331. if (!status)
  332. continue;
  333. if (display) {
  334. nv_rd32(dev, addr + 0x20);
  335. pc = nv_rd32(dev, addr + 0x24);
  336. oplow = nv_rd32(dev, addr + 0x70);
  337. ophigh = nv_rd32(dev, addr + 0x74);
  338. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
  339. "TP %d MP %d: ", tpid, i);
  340. nouveau_enum_print(nv50_mp_exec_error_names, status);
  341. printk(" at %06x warp %d, opcode %08x %08x\n",
  342. pc&0xffffff, pc >> 24,
  343. oplow, ophigh);
  344. }
  345. nv_wr32(dev, addr + 0x10, mp10);
  346. nv_wr32(dev, addr + 0x14, 0);
  347. mps++;
  348. }
  349. if (!mps && display)
  350. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
  351. "No MPs claiming errors?\n", tpid);
  352. }
  353. static void
  354. nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
  355. uint32_t ustatus_new, int display, const char *name)
  356. {
  357. struct drm_nouveau_private *dev_priv = dev->dev_private;
  358. int tps = 0;
  359. uint32_t units = nv_rd32(dev, 0x1540);
  360. int i, r;
  361. uint32_t ustatus_addr, ustatus;
  362. for (i = 0; i < 16; i++) {
  363. if (!(units & (1 << i)))
  364. continue;
  365. if (dev_priv->chipset < 0xa0)
  366. ustatus_addr = ustatus_old + (i << 12);
  367. else
  368. ustatus_addr = ustatus_new + (i << 11);
  369. ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
  370. if (!ustatus)
  371. continue;
  372. tps++;
  373. switch (type) {
  374. case 6: /* texture error... unknown for now */
  375. if (display) {
  376. NV_ERROR(dev, "magic set %d:\n", i);
  377. for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
  378. NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
  379. nv_rd32(dev, r));
  380. }
  381. break;
  382. case 7: /* MP error */
  383. if (ustatus & 0x04030000) {
  384. nv50_pgraph_mp_trap(dev, i, display);
  385. ustatus &= ~0x04030000;
  386. }
  387. break;
  388. case 8: /* TPDMA error */
  389. {
  390. uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
  391. uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
  392. uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
  393. uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
  394. uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
  395. uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
  396. uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
  397. /* 2d engine destination */
  398. if (ustatus & 0x00000010) {
  399. if (display) {
  400. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
  401. i, e14, e10);
  402. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  403. i, e0c, e18, e1c, e20, e24);
  404. }
  405. ustatus &= ~0x00000010;
  406. }
  407. /* Render target */
  408. if (ustatus & 0x00000040) {
  409. if (display) {
  410. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
  411. i, e14, e10);
  412. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  413. i, e0c, e18, e1c, e20, e24);
  414. }
  415. ustatus &= ~0x00000040;
  416. }
  417. /* CUDA memory: l[], g[] or stack. */
  418. if (ustatus & 0x00000080) {
  419. if (display) {
  420. if (e18 & 0x80000000) {
  421. /* g[] read fault? */
  422. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
  423. i, e14, e10 | ((e18 >> 24) & 0x1f));
  424. e18 &= ~0x1f000000;
  425. } else if (e18 & 0xc) {
  426. /* g[] write fault? */
  427. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
  428. i, e14, e10 | ((e18 >> 7) & 0x1f));
  429. e18 &= ~0x00000f80;
  430. } else {
  431. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
  432. i, e14, e10);
  433. }
  434. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  435. i, e0c, e18, e1c, e20, e24);
  436. }
  437. ustatus &= ~0x00000080;
  438. }
  439. }
  440. break;
  441. }
  442. if (ustatus) {
  443. if (display)
  444. NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
  445. }
  446. nv_wr32(dev, ustatus_addr, 0xc0000000);
  447. }
  448. if (!tps && display)
  449. NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
  450. }
  451. static int
  452. nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
  453. {
  454. u32 status = nv_rd32(dev, 0x400108);
  455. u32 ustatus;
  456. if (!status && display) {
  457. NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
  458. return 1;
  459. }
  460. /* DISPATCH: Relays commands to other units and handles NOTIFY,
  461. * COND, QUERY. If you get a trap from it, the command is still stuck
  462. * in DISPATCH and you need to do something about it. */
  463. if (status & 0x001) {
  464. ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
  465. if (!ustatus && display) {
  466. NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
  467. }
  468. nv_wr32(dev, 0x400500, 0x00000000);
  469. /* Known to be triggered by screwed up NOTIFY and COND... */
  470. if (ustatus & 0x00000001) {
  471. u32 addr = nv_rd32(dev, 0x400808);
  472. u32 subc = (addr & 0x00070000) >> 16;
  473. u32 mthd = (addr & 0x00001ffc);
  474. u32 datal = nv_rd32(dev, 0x40080c);
  475. u32 datah = nv_rd32(dev, 0x400810);
  476. u32 class = nv_rd32(dev, 0x400814);
  477. u32 r848 = nv_rd32(dev, 0x400848);
  478. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
  479. if (display && (addr & 0x80000000)) {
  480. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  481. "subc %d class 0x%04x mthd 0x%04x "
  482. "data 0x%08x%08x "
  483. "400808 0x%08x 400848 0x%08x\n",
  484. chid, inst, subc, class, mthd, datah,
  485. datal, addr, r848);
  486. } else
  487. if (display) {
  488. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  489. }
  490. nv_wr32(dev, 0x400808, 0);
  491. nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
  492. nv_wr32(dev, 0x400848, 0);
  493. ustatus &= ~0x00000001;
  494. }
  495. if (ustatus & 0x00000002) {
  496. u32 addr = nv_rd32(dev, 0x40084c);
  497. u32 subc = (addr & 0x00070000) >> 16;
  498. u32 mthd = (addr & 0x00001ffc);
  499. u32 data = nv_rd32(dev, 0x40085c);
  500. u32 class = nv_rd32(dev, 0x400814);
  501. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
  502. if (display && (addr & 0x80000000)) {
  503. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  504. "subc %d class 0x%04x mthd 0x%04x "
  505. "data 0x%08x 40084c 0x%08x\n",
  506. chid, inst, subc, class, mthd,
  507. data, addr);
  508. } else
  509. if (display) {
  510. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  511. }
  512. nv_wr32(dev, 0x40084c, 0);
  513. ustatus &= ~0x00000002;
  514. }
  515. if (ustatus && display) {
  516. NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
  517. "0x%08x)\n", ustatus);
  518. }
  519. nv_wr32(dev, 0x400804, 0xc0000000);
  520. nv_wr32(dev, 0x400108, 0x001);
  521. status &= ~0x001;
  522. if (!status)
  523. return 0;
  524. }
  525. /* M2MF: Memory to memory copy engine. */
  526. if (status & 0x002) {
  527. u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
  528. if (display) {
  529. NV_INFO(dev, "PGRAPH - TRAP_M2MF");
  530. nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
  531. printk("\n");
  532. NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
  533. nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
  534. nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
  535. }
  536. /* No sane way found yet -- just reset the bugger. */
  537. nv_wr32(dev, 0x400040, 2);
  538. nv_wr32(dev, 0x400040, 0);
  539. nv_wr32(dev, 0x406800, 0xc0000000);
  540. nv_wr32(dev, 0x400108, 0x002);
  541. status &= ~0x002;
  542. }
  543. /* VFETCH: Fetches data from vertex buffers. */
  544. if (status & 0x004) {
  545. u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
  546. if (display) {
  547. NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
  548. nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
  549. printk("\n");
  550. NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
  551. nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
  552. nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
  553. }
  554. nv_wr32(dev, 0x400c04, 0xc0000000);
  555. nv_wr32(dev, 0x400108, 0x004);
  556. status &= ~0x004;
  557. }
  558. /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
  559. if (status & 0x008) {
  560. ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
  561. if (display) {
  562. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
  563. nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
  564. printk("\n");
  565. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
  566. nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
  567. nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
  568. }
  569. /* No sane way found yet -- just reset the bugger. */
  570. nv_wr32(dev, 0x400040, 0x80);
  571. nv_wr32(dev, 0x400040, 0);
  572. nv_wr32(dev, 0x401800, 0xc0000000);
  573. nv_wr32(dev, 0x400108, 0x008);
  574. status &= ~0x008;
  575. }
  576. /* CCACHE: Handles code and c[] caches and fills them. */
  577. if (status & 0x010) {
  578. ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
  579. if (display) {
  580. NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
  581. nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
  582. printk("\n");
  583. NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
  584. " %08x %08x %08x\n",
  585. nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
  586. nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
  587. nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
  588. nv_rd32(dev, 0x40501c));
  589. }
  590. nv_wr32(dev, 0x405018, 0xc0000000);
  591. nv_wr32(dev, 0x400108, 0x010);
  592. status &= ~0x010;
  593. }
  594. /* Unknown, not seen yet... 0x402000 is the only trap status reg
  595. * remaining, so try to handle it anyway. Perhaps related to that
  596. * unknown DMA slot on tesla? */
  597. if (status & 0x20) {
  598. ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
  599. if (display)
  600. NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
  601. nv_wr32(dev, 0x402000, 0xc0000000);
  602. /* no status modifiction on purpose */
  603. }
  604. /* TEXTURE: CUDA texturing units */
  605. if (status & 0x040) {
  606. nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
  607. "PGRAPH - TRAP_TEXTURE");
  608. nv_wr32(dev, 0x400108, 0x040);
  609. status &= ~0x040;
  610. }
  611. /* MP: CUDA execution engines. */
  612. if (status & 0x080) {
  613. nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
  614. "PGRAPH - TRAP_MP");
  615. nv_wr32(dev, 0x400108, 0x080);
  616. status &= ~0x080;
  617. }
  618. /* TPDMA: Handles TP-initiated uncached memory accesses:
  619. * l[], g[], stack, 2d surfaces, render targets. */
  620. if (status & 0x100) {
  621. nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
  622. "PGRAPH - TRAP_TPDMA");
  623. nv_wr32(dev, 0x400108, 0x100);
  624. status &= ~0x100;
  625. }
  626. if (status) {
  627. if (display)
  628. NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
  629. nv_wr32(dev, 0x400108, status);
  630. }
  631. return 1;
  632. }
  633. int
  634. nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
  635. {
  636. struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
  637. struct drm_nouveau_private *dev_priv = dev->dev_private;
  638. struct nouveau_channel *chan;
  639. unsigned long flags;
  640. int i;
  641. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  642. for (i = 0; i < pfifo->channels; i++) {
  643. chan = dev_priv->channels.ptr[i];
  644. if (!chan || !chan->ramin)
  645. continue;
  646. if (inst == chan->ramin->vinst)
  647. break;
  648. }
  649. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  650. return i;
  651. }
  652. static void
  653. nv50_graph_isr(struct drm_device *dev)
  654. {
  655. u32 stat;
  656. while ((stat = nv_rd32(dev, 0x400100))) {
  657. u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
  658. u32 chid = nv50_graph_isr_chid(dev, inst);
  659. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  660. u32 subc = (addr & 0x00070000) >> 16;
  661. u32 mthd = (addr & 0x00001ffc);
  662. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  663. u32 class = nv_rd32(dev, 0x400814);
  664. u32 show = stat;
  665. if (stat & 0x00000010) {
  666. if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
  667. mthd, data))
  668. show &= ~0x00000010;
  669. }
  670. show = (show && nouveau_ratelimit()) ? show : 0;
  671. if (show & 0x00100000) {
  672. u32 ecode = nv_rd32(dev, 0x400110);
  673. NV_INFO(dev, "PGRAPH - DATA_ERROR ");
  674. nouveau_enum_print(nv50_data_error_names, ecode);
  675. printk("\n");
  676. }
  677. if (stat & 0x00200000) {
  678. if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
  679. show &= ~0x00200000;
  680. }
  681. nv_wr32(dev, 0x400100, stat);
  682. nv_wr32(dev, 0x400500, 0x00010001);
  683. if (show) {
  684. NV_INFO(dev, "PGRAPH -");
  685. nouveau_bitfield_print(nv50_graph_intr, show);
  686. printk("\n");
  687. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
  688. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  689. chid, inst, subc, class, mthd, data);
  690. nv50_fb_vm_trap(dev, 1);
  691. }
  692. }
  693. if (nv_rd32(dev, 0x400824) & (1 << 31))
  694. nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
  695. }
  696. static void
  697. nv50_graph_destroy(struct drm_device *dev, int engine)
  698. {
  699. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  700. NVOBJ_ENGINE_DEL(dev, GR);
  701. nouveau_irq_unregister(dev, 12);
  702. kfree(pgraph);
  703. }
  704. int
  705. nv50_graph_create(struct drm_device *dev)
  706. {
  707. struct drm_nouveau_private *dev_priv = dev->dev_private;
  708. struct nv50_graph_engine *pgraph;
  709. int ret;
  710. pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
  711. if (!pgraph)
  712. return -ENOMEM;
  713. ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
  714. &pgraph->ctxprog_size,
  715. &pgraph->grctx_size);
  716. if (ret) {
  717. NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
  718. kfree(pgraph);
  719. return 0;
  720. }
  721. pgraph->base.destroy = nv50_graph_destroy;
  722. pgraph->base.init = nv50_graph_init;
  723. pgraph->base.fini = nv50_graph_fini;
  724. pgraph->base.context_new = nv50_graph_context_new;
  725. pgraph->base.context_del = nv50_graph_context_del;
  726. pgraph->base.object_new = nv50_graph_object_new;
  727. if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
  728. pgraph->base.tlb_flush = nv50_graph_tlb_flush;
  729. else
  730. pgraph->base.tlb_flush = nv84_graph_tlb_flush;
  731. nouveau_irq_register(dev, 12, nv50_graph_isr);
  732. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  733. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  734. NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
  735. NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
  736. /* tesla */
  737. if (dev_priv->chipset == 0x50)
  738. NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
  739. else
  740. if (dev_priv->chipset < 0xa0)
  741. NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
  742. else {
  743. switch (dev_priv->chipset) {
  744. case 0xa0:
  745. case 0xaa:
  746. case 0xac:
  747. NVOBJ_CLASS(dev, 0x8397, GR);
  748. break;
  749. case 0xa3:
  750. case 0xa5:
  751. case 0xa8:
  752. NVOBJ_CLASS(dev, 0x8597, GR);
  753. break;
  754. case 0xaf:
  755. NVOBJ_CLASS(dev, 0x8697, GR);
  756. break;
  757. }
  758. }
  759. /* compute */
  760. NVOBJ_CLASS(dev, 0x50c0, GR);
  761. if (dev_priv->chipset > 0xa0 &&
  762. dev_priv->chipset != 0xaa &&
  763. dev_priv->chipset != 0xac)
  764. NVOBJ_CLASS(dev, 0x85c0, GR);
  765. return 0;
  766. }