nv50_graph.c 28 KB

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