nv50_graph.c 26 KB

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