nv50_graph.c 30 KB

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