nv50_graph.c 26 KB

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