nv50_graph.c 25 KB

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