nv50_graph.c 28 KB

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