nv50_graph.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. static struct nouveau_enum nv50_data_error_names[] = {
  455. { 4, "INVALID_VALUE" },
  456. { 5, "INVALID_ENUM" },
  457. { 8, "INVALID_OBJECT" },
  458. { 0xc, "INVALID_BITFIELD" },
  459. { 0x28, "MP_NO_REG_SPACE" },
  460. { 0x2b, "MP_BLOCK_SIZE_MISMATCH" },
  461. {}
  462. };
  463. static struct nouveau_bitfield nv50_graph_intr[] = {
  464. { 0x00000001, "NOTIFY" },
  465. { 0x00000002, "COMPUTE_QUERY" },
  466. { 0x00000010, "ILLEGAL_MTHD" },
  467. { 0x00000020, "ILLEGAL_CLASS" },
  468. { 0x00000040, "DOUBLE_NOTIFY" },
  469. { 0x00001000, "CONTEXT_SWITCH" },
  470. { 0x00010000, "BUFFER_NOTIFY" },
  471. { 0x00100000, "DATA_ERROR" },
  472. { 0x00200000, "TRAP" },
  473. { 0x01000000, "SINGLE_STEP" },
  474. {}
  475. };
  476. static void
  477. nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
  478. {
  479. struct drm_nouveau_private *dev_priv = dev->dev_private;
  480. uint32_t units = nv_rd32(dev, 0x1540);
  481. uint32_t addr, mp10, status, pc, oplow, ophigh;
  482. int i;
  483. int mps = 0;
  484. for (i = 0; i < 4; i++) {
  485. if (!(units & 1 << (i+24)))
  486. continue;
  487. if (dev_priv->chipset < 0xa0)
  488. addr = 0x408200 + (tpid << 12) + (i << 7);
  489. else
  490. addr = 0x408100 + (tpid << 11) + (i << 7);
  491. mp10 = nv_rd32(dev, addr + 0x10);
  492. status = nv_rd32(dev, addr + 0x14);
  493. if (!status)
  494. continue;
  495. if (display) {
  496. nv_rd32(dev, addr + 0x20);
  497. pc = nv_rd32(dev, addr + 0x24);
  498. oplow = nv_rd32(dev, addr + 0x70);
  499. ophigh= nv_rd32(dev, addr + 0x74);
  500. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
  501. "TP %d MP %d: ", tpid, i);
  502. nouveau_enum_print(nv50_mp_exec_error_names, status);
  503. printk(" at %06x warp %d, opcode %08x %08x\n",
  504. pc&0xffffff, pc >> 24,
  505. oplow, ophigh);
  506. }
  507. nv_wr32(dev, addr + 0x10, mp10);
  508. nv_wr32(dev, addr + 0x14, 0);
  509. mps++;
  510. }
  511. if (!mps && display)
  512. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
  513. "No MPs claiming errors?\n", tpid);
  514. }
  515. static void
  516. nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
  517. uint32_t ustatus_new, int display, const char *name)
  518. {
  519. struct drm_nouveau_private *dev_priv = dev->dev_private;
  520. int tps = 0;
  521. uint32_t units = nv_rd32(dev, 0x1540);
  522. int i, r;
  523. uint32_t ustatus_addr, ustatus;
  524. for (i = 0; i < 16; i++) {
  525. if (!(units & (1 << i)))
  526. continue;
  527. if (dev_priv->chipset < 0xa0)
  528. ustatus_addr = ustatus_old + (i << 12);
  529. else
  530. ustatus_addr = ustatus_new + (i << 11);
  531. ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
  532. if (!ustatus)
  533. continue;
  534. tps++;
  535. switch (type) {
  536. case 6: /* texture error... unknown for now */
  537. nv50_fb_vm_trap(dev, display, name);
  538. if (display) {
  539. NV_ERROR(dev, "magic set %d:\n", i);
  540. for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
  541. NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
  542. nv_rd32(dev, r));
  543. }
  544. break;
  545. case 7: /* MP error */
  546. if (ustatus & 0x00010000) {
  547. nv50_pgraph_mp_trap(dev, i, display);
  548. ustatus &= ~0x00010000;
  549. }
  550. break;
  551. case 8: /* TPDMA error */
  552. {
  553. uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
  554. uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
  555. uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
  556. uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
  557. uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
  558. uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
  559. uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
  560. nv50_fb_vm_trap(dev, display, name);
  561. /* 2d engine destination */
  562. if (ustatus & 0x00000010) {
  563. if (display) {
  564. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
  565. i, e14, e10);
  566. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  567. i, e0c, e18, e1c, e20, e24);
  568. }
  569. ustatus &= ~0x00000010;
  570. }
  571. /* Render target */
  572. if (ustatus & 0x00000040) {
  573. if (display) {
  574. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
  575. i, e14, e10);
  576. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  577. i, e0c, e18, e1c, e20, e24);
  578. }
  579. ustatus &= ~0x00000040;
  580. }
  581. /* CUDA memory: l[], g[] or stack. */
  582. if (ustatus & 0x00000080) {
  583. if (display) {
  584. if (e18 & 0x80000000) {
  585. /* g[] read fault? */
  586. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
  587. i, e14, e10 | ((e18 >> 24) & 0x1f));
  588. e18 &= ~0x1f000000;
  589. } else if (e18 & 0xc) {
  590. /* g[] write fault? */
  591. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
  592. i, e14, e10 | ((e18 >> 7) & 0x1f));
  593. e18 &= ~0x00000f80;
  594. } else {
  595. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
  596. i, e14, e10);
  597. }
  598. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  599. i, e0c, e18, e1c, e20, e24);
  600. }
  601. ustatus &= ~0x00000080;
  602. }
  603. }
  604. break;
  605. }
  606. if (ustatus) {
  607. if (display)
  608. NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
  609. }
  610. nv_wr32(dev, ustatus_addr, 0xc0000000);
  611. }
  612. if (!tps && display)
  613. NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
  614. }
  615. static int
  616. nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
  617. {
  618. u32 status = nv_rd32(dev, 0x400108);
  619. u32 ustatus;
  620. if (!status && display) {
  621. NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
  622. return 1;
  623. }
  624. /* DISPATCH: Relays commands to other units and handles NOTIFY,
  625. * COND, QUERY. If you get a trap from it, the command is still stuck
  626. * in DISPATCH and you need to do something about it. */
  627. if (status & 0x001) {
  628. ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
  629. if (!ustatus && display) {
  630. NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
  631. }
  632. nv_wr32(dev, 0x400500, 0x00000000);
  633. /* Known to be triggered by screwed up NOTIFY and COND... */
  634. if (ustatus & 0x00000001) {
  635. u32 addr = nv_rd32(dev, 0x400808);
  636. u32 subc = (addr & 0x00070000) >> 16;
  637. u32 mthd = (addr & 0x00001ffc);
  638. u32 datal = nv_rd32(dev, 0x40080c);
  639. u32 datah = nv_rd32(dev, 0x400810);
  640. u32 class = nv_rd32(dev, 0x400814);
  641. u32 r848 = nv_rd32(dev, 0x400848);
  642. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
  643. if (display && (addr & 0x80000000)) {
  644. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  645. "subc %d class 0x%04x mthd 0x%04x "
  646. "data 0x%08x%08x "
  647. "400808 0x%08x 400848 0x%08x\n",
  648. chid, inst, subc, class, mthd, datah,
  649. datal, addr, r848);
  650. } else
  651. if (display) {
  652. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  653. }
  654. nv_wr32(dev, 0x400808, 0);
  655. nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
  656. nv_wr32(dev, 0x400848, 0);
  657. ustatus &= ~0x00000001;
  658. }
  659. if (ustatus & 0x00000002) {
  660. u32 addr = nv_rd32(dev, 0x40084c);
  661. u32 subc = (addr & 0x00070000) >> 16;
  662. u32 mthd = (addr & 0x00001ffc);
  663. u32 data = nv_rd32(dev, 0x40085c);
  664. u32 class = nv_rd32(dev, 0x400814);
  665. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
  666. if (display && (addr & 0x80000000)) {
  667. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  668. "subc %d class 0x%04x mthd 0x%04x "
  669. "data 0x%08x 40084c 0x%08x\n",
  670. chid, inst, subc, class, mthd,
  671. data, addr);
  672. } else
  673. if (display) {
  674. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  675. }
  676. nv_wr32(dev, 0x40084c, 0);
  677. ustatus &= ~0x00000002;
  678. }
  679. if (ustatus && display) {
  680. NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
  681. "0x%08x)\n", ustatus);
  682. }
  683. nv_wr32(dev, 0x400804, 0xc0000000);
  684. nv_wr32(dev, 0x400108, 0x001);
  685. status &= ~0x001;
  686. if (!status)
  687. return 0;
  688. }
  689. /* M2MF: Memory to memory copy engine. */
  690. if (status & 0x002) {
  691. u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
  692. if (display) {
  693. NV_INFO(dev, "PGRAPH - TRAP_M2MF");
  694. nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
  695. printk("\n");
  696. NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
  697. nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
  698. nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
  699. }
  700. /* No sane way found yet -- just reset the bugger. */
  701. nv_wr32(dev, 0x400040, 2);
  702. nv_wr32(dev, 0x400040, 0);
  703. nv_wr32(dev, 0x406800, 0xc0000000);
  704. nv_wr32(dev, 0x400108, 0x002);
  705. status &= ~0x002;
  706. }
  707. /* VFETCH: Fetches data from vertex buffers. */
  708. if (status & 0x004) {
  709. u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
  710. if (display) {
  711. NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
  712. nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
  713. printk("\n");
  714. NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
  715. nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
  716. nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
  717. }
  718. nv_wr32(dev, 0x400c04, 0xc0000000);
  719. nv_wr32(dev, 0x400108, 0x004);
  720. status &= ~0x004;
  721. }
  722. /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
  723. if (status & 0x008) {
  724. ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
  725. if (display) {
  726. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
  727. nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
  728. printk("\n");
  729. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
  730. nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
  731. nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
  732. }
  733. /* No sane way found yet -- just reset the bugger. */
  734. nv_wr32(dev, 0x400040, 0x80);
  735. nv_wr32(dev, 0x400040, 0);
  736. nv_wr32(dev, 0x401800, 0xc0000000);
  737. nv_wr32(dev, 0x400108, 0x008);
  738. status &= ~0x008;
  739. }
  740. /* CCACHE: Handles code and c[] caches and fills them. */
  741. if (status & 0x010) {
  742. ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
  743. if (display) {
  744. NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
  745. nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
  746. printk("\n");
  747. NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
  748. " %08x %08x %08x\n",
  749. nv_rd32(dev, 0x405800), nv_rd32(dev, 0x405804),
  750. nv_rd32(dev, 0x405808), nv_rd32(dev, 0x40580c),
  751. nv_rd32(dev, 0x405810), nv_rd32(dev, 0x405814),
  752. nv_rd32(dev, 0x40581c));
  753. }
  754. nv_wr32(dev, 0x405018, 0xc0000000);
  755. nv_wr32(dev, 0x400108, 0x010);
  756. status &= ~0x010;
  757. }
  758. /* Unknown, not seen yet... 0x402000 is the only trap status reg
  759. * remaining, so try to handle it anyway. Perhaps related to that
  760. * unknown DMA slot on tesla? */
  761. if (status & 0x20) {
  762. ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
  763. if (display)
  764. NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
  765. nv_wr32(dev, 0x402000, 0xc0000000);
  766. /* no status modifiction on purpose */
  767. }
  768. /* TEXTURE: CUDA texturing units */
  769. if (status & 0x040) {
  770. nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
  771. "PGRAPH - TRAP_TEXTURE");
  772. nv_wr32(dev, 0x400108, 0x040);
  773. status &= ~0x040;
  774. }
  775. /* MP: CUDA execution engines. */
  776. if (status & 0x080) {
  777. nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
  778. "PGRAPH - TRAP_MP");
  779. nv_wr32(dev, 0x400108, 0x080);
  780. status &= ~0x080;
  781. }
  782. /* TPDMA: Handles TP-initiated uncached memory accesses:
  783. * l[], g[], stack, 2d surfaces, render targets. */
  784. if (status & 0x100) {
  785. nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
  786. "PGRAPH - TRAP_TPDMA");
  787. nv_wr32(dev, 0x400108, 0x100);
  788. status &= ~0x100;
  789. }
  790. if (status) {
  791. if (display)
  792. NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
  793. nv_wr32(dev, 0x400108, status);
  794. }
  795. return 1;
  796. }
  797. static int
  798. nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
  799. {
  800. struct drm_nouveau_private *dev_priv = dev->dev_private;
  801. struct nouveau_channel *chan;
  802. unsigned long flags;
  803. int i;
  804. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  805. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  806. chan = dev_priv->channels.ptr[i];
  807. if (!chan || !chan->ramin)
  808. continue;
  809. if (inst == chan->ramin->vinst)
  810. break;
  811. }
  812. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  813. return i;
  814. }
  815. static void
  816. nv50_graph_isr(struct drm_device *dev)
  817. {
  818. u32 stat;
  819. while ((stat = nv_rd32(dev, 0x400100))) {
  820. u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
  821. u32 chid = nv50_graph_isr_chid(dev, inst);
  822. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  823. u32 subc = (addr & 0x00070000) >> 16;
  824. u32 mthd = (addr & 0x00001ffc);
  825. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  826. u32 class = nv_rd32(dev, 0x400814);
  827. u32 show = stat;
  828. if (stat & 0x00000010) {
  829. if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
  830. mthd, data))
  831. show &= ~0x00000010;
  832. }
  833. if (stat & 0x00001000) {
  834. nv_wr32(dev, 0x400500, 0x00000000);
  835. nv_wr32(dev, 0x400100, 0x00001000);
  836. nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
  837. nv50_graph_context_switch(dev);
  838. stat &= ~0x00001000;
  839. show &= ~0x00001000;
  840. }
  841. show = (show && nouveau_ratelimit()) ? show : 0;
  842. if (show & 0x00100000) {
  843. u32 ecode = nv_rd32(dev, 0x400110);
  844. NV_INFO(dev, "PGRAPH - DATA_ERROR ");
  845. nouveau_enum_print(nv50_data_error_names, ecode);
  846. printk("\n");
  847. }
  848. if (stat & 0x00200000) {
  849. if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
  850. show &= ~0x00200000;
  851. }
  852. nv_wr32(dev, 0x400100, stat);
  853. nv_wr32(dev, 0x400500, 0x00010001);
  854. if (show) {
  855. NV_INFO(dev, "PGRAPH -");
  856. nouveau_bitfield_print(nv50_graph_intr, show);
  857. printk("\n");
  858. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
  859. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  860. chid, inst, subc, class, mthd, data);
  861. }
  862. }
  863. if (nv_rd32(dev, 0x400824) & (1 << 31))
  864. nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
  865. }