nv40_graph.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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_grctx.h"
  30. #include "nouveau_ramht.h"
  31. static int nv40_graph_register(struct drm_device *);
  32. static void nv40_graph_isr(struct drm_device *);
  33. struct nouveau_channel *
  34. nv40_graph_channel(struct drm_device *dev)
  35. {
  36. struct drm_nouveau_private *dev_priv = dev->dev_private;
  37. uint32_t inst;
  38. int i;
  39. inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR);
  40. if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED))
  41. return NULL;
  42. inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4;
  43. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  44. struct nouveau_channel *chan = dev_priv->channels.ptr[i];
  45. if (chan && chan->ramin_grctx &&
  46. chan->ramin_grctx->pinst == inst)
  47. return chan;
  48. }
  49. return NULL;
  50. }
  51. int
  52. nv40_graph_create_context(struct nouveau_channel *chan)
  53. {
  54. struct drm_device *dev = chan->dev;
  55. struct drm_nouveau_private *dev_priv = dev->dev_private;
  56. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  57. struct nouveau_grctx ctx = {};
  58. unsigned long flags;
  59. int ret;
  60. ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 16,
  61. NVOBJ_FLAG_ZERO_ALLOC, &chan->ramin_grctx);
  62. if (ret)
  63. return ret;
  64. /* Initialise default context values */
  65. ctx.dev = chan->dev;
  66. ctx.mode = NOUVEAU_GRCTX_VALS;
  67. ctx.data = chan->ramin_grctx;
  68. nv40_grctx_init(&ctx);
  69. nv_wo32(chan->ramin_grctx, 0, chan->ramin_grctx->pinst);
  70. /* init grctx pointer in ramfc, and on PFIFO if channel is
  71. * already active there
  72. */
  73. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  74. nv_wo32(chan->ramfc, 0x38, chan->ramin_grctx->pinst >> 4);
  75. nv_mask(dev, 0x002500, 0x00000001, 0x00000000);
  76. if ((nv_rd32(dev, 0x003204) & 0x0000001f) == chan->id)
  77. nv_wr32(dev, 0x0032e0, chan->ramin_grctx->pinst >> 4);
  78. nv_mask(dev, 0x002500, 0x00000001, 0x00000001);
  79. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  80. return 0;
  81. }
  82. void
  83. nv40_graph_destroy_context(struct nouveau_channel *chan)
  84. {
  85. struct drm_device *dev = chan->dev;
  86. struct drm_nouveau_private *dev_priv = dev->dev_private;
  87. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  88. unsigned long flags;
  89. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  90. pgraph->fifo_access(dev, false);
  91. /* Unload the context if it's the currently active one */
  92. if (pgraph->channel(dev) == chan)
  93. pgraph->unload_context(dev);
  94. pgraph->fifo_access(dev, true);
  95. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  96. /* Free the context resources */
  97. nouveau_gpuobj_ref(NULL, &chan->ramin_grctx);
  98. }
  99. static int
  100. nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save)
  101. {
  102. uint32_t old_cp, tv = 1000, tmp;
  103. int i;
  104. old_cp = nv_rd32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER);
  105. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
  106. tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0310);
  107. tmp |= save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE :
  108. NV40_PGRAPH_CTXCTL_0310_XFER_LOAD;
  109. nv_wr32(dev, NV40_PGRAPH_CTXCTL_0310, tmp);
  110. tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0304);
  111. tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX;
  112. nv_wr32(dev, NV40_PGRAPH_CTXCTL_0304, tmp);
  113. nouveau_wait_for_idle(dev);
  114. for (i = 0; i < tv; i++) {
  115. if (nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C) == 0)
  116. break;
  117. }
  118. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp);
  119. if (i == tv) {
  120. uint32_t ucstat = nv_rd32(dev, NV40_PGRAPH_CTXCTL_UCODE_STAT);
  121. NV_ERROR(dev, "Failed: Instance=0x%08x Save=%d\n", inst, save);
  122. NV_ERROR(dev, "IP: 0x%02x, Opcode: 0x%08x\n",
  123. ucstat >> NV40_PGRAPH_CTXCTL_UCODE_STAT_IP_SHIFT,
  124. ucstat & NV40_PGRAPH_CTXCTL_UCODE_STAT_OP_MASK);
  125. NV_ERROR(dev, "0x40030C = 0x%08x\n",
  126. nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C));
  127. return -EBUSY;
  128. }
  129. return 0;
  130. }
  131. /* Restore the context for a specific channel into PGRAPH */
  132. int
  133. nv40_graph_load_context(struct nouveau_channel *chan)
  134. {
  135. struct drm_device *dev = chan->dev;
  136. uint32_t inst;
  137. int ret;
  138. if (!chan->ramin_grctx)
  139. return -EINVAL;
  140. inst = chan->ramin_grctx->pinst >> 4;
  141. ret = nv40_graph_transfer_context(dev, inst, 0);
  142. if (ret)
  143. return ret;
  144. /* 0x40032C, no idea of it's exact function. Could simply be a
  145. * record of the currently active PGRAPH context. It's currently
  146. * unknown as to what bit 24 does. The nv ddx has it set, so we will
  147. * set it here too.
  148. */
  149. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
  150. nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR,
  151. (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) |
  152. NV40_PGRAPH_CTXCTL_CUR_LOADED);
  153. /* 0x32E0 records the instance address of the active FIFO's PGRAPH
  154. * context. If at any time this doesn't match 0x40032C, you will
  155. * receive PGRAPH_INTR_CONTEXT_SWITCH
  156. */
  157. nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, inst);
  158. return 0;
  159. }
  160. int
  161. nv40_graph_unload_context(struct drm_device *dev)
  162. {
  163. uint32_t inst;
  164. int ret;
  165. inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR);
  166. if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED))
  167. return 0;
  168. inst &= NV40_PGRAPH_CTXCTL_CUR_INSTANCE;
  169. ret = nv40_graph_transfer_context(dev, inst, 1);
  170. nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, inst);
  171. return ret;
  172. }
  173. int
  174. nv40_graph_object_new(struct nouveau_channel *chan, u32 handle, u16 class)
  175. {
  176. struct drm_device *dev = chan->dev;
  177. struct nouveau_gpuobj *obj = NULL;
  178. int ret;
  179. ret = nouveau_gpuobj_new(dev, chan, 20, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  180. if (ret)
  181. return ret;
  182. obj->engine = 1;
  183. obj->class = class;
  184. nv_wo32(obj, 0x00, class);
  185. nv_wo32(obj, 0x04, 0x00000000);
  186. #ifdef __BIG_ENDIAN
  187. nv_wo32(obj, 0x08, 0x01000000);
  188. #endif
  189. nv_wo32(obj, 0x0c, 0x00000000);
  190. nv_wo32(obj, 0x10, 0x00000000);
  191. ret = nouveau_ramht_insert(chan, handle, obj);
  192. nouveau_gpuobj_ref(NULL, &obj);
  193. return ret;
  194. }
  195. void
  196. nv40_graph_set_tile_region(struct drm_device *dev, int i)
  197. {
  198. struct drm_nouveau_private *dev_priv = dev->dev_private;
  199. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  200. switch (dev_priv->chipset) {
  201. case 0x40:
  202. case 0x41: /* guess */
  203. case 0x42:
  204. case 0x43:
  205. case 0x45: /* guess */
  206. case 0x4e:
  207. nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch);
  208. nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit);
  209. nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr);
  210. nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch);
  211. nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit);
  212. nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr);
  213. break;
  214. case 0x44:
  215. case 0x4a:
  216. nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch);
  217. nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit);
  218. nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr);
  219. break;
  220. case 0x46:
  221. case 0x47:
  222. case 0x49:
  223. case 0x4b:
  224. case 0x4c:
  225. case 0x67:
  226. default:
  227. nv_wr32(dev, NV47_PGRAPH_TSIZE(i), tile->pitch);
  228. nv_wr32(dev, NV47_PGRAPH_TLIMIT(i), tile->limit);
  229. nv_wr32(dev, NV47_PGRAPH_TILE(i), tile->addr);
  230. nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch);
  231. nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit);
  232. nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr);
  233. break;
  234. }
  235. }
  236. /*
  237. * G70 0x47
  238. * G71 0x49
  239. * NV45 0x48
  240. * G72[M] 0x46
  241. * G73 0x4b
  242. * C51_G7X 0x4c
  243. * C51 0x4e
  244. */
  245. int
  246. nv40_graph_init(struct drm_device *dev)
  247. {
  248. struct drm_nouveau_private *dev_priv =
  249. (struct drm_nouveau_private *)dev->dev_private;
  250. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  251. struct nouveau_grctx ctx = {};
  252. uint32_t vramsz, *cp;
  253. int ret, i, j;
  254. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) &
  255. ~NV_PMC_ENABLE_PGRAPH);
  256. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  257. NV_PMC_ENABLE_PGRAPH);
  258. cp = kmalloc(sizeof(*cp) * 256, GFP_KERNEL);
  259. if (!cp)
  260. return -ENOMEM;
  261. ctx.dev = dev;
  262. ctx.mode = NOUVEAU_GRCTX_PROG;
  263. ctx.data = cp;
  264. ctx.ctxprog_max = 256;
  265. nv40_grctx_init(&ctx);
  266. dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4;
  267. nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
  268. for (i = 0; i < ctx.ctxprog_len; i++)
  269. nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]);
  270. kfree(cp);
  271. ret = nv40_graph_register(dev);
  272. if (ret)
  273. return ret;
  274. /* No context present currently */
  275. nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000);
  276. nouveau_irq_register(dev, 12, nv40_graph_isr);
  277. nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  278. nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xFFFFFFFF);
  279. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  280. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000);
  281. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0);
  282. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xe0de8055);
  283. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000);
  284. nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0x00be3c5f);
  285. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
  286. nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF);
  287. j = nv_rd32(dev, 0x1540) & 0xff;
  288. if (j) {
  289. for (i = 0; !(j & 1); j >>= 1, i++)
  290. ;
  291. nv_wr32(dev, 0x405000, i);
  292. }
  293. if (dev_priv->chipset == 0x40) {
  294. nv_wr32(dev, 0x4009b0, 0x83280fff);
  295. nv_wr32(dev, 0x4009b4, 0x000000a0);
  296. } else {
  297. nv_wr32(dev, 0x400820, 0x83280eff);
  298. nv_wr32(dev, 0x400824, 0x000000a0);
  299. }
  300. switch (dev_priv->chipset) {
  301. case 0x40:
  302. case 0x45:
  303. nv_wr32(dev, 0x4009b8, 0x0078e366);
  304. nv_wr32(dev, 0x4009bc, 0x0000014c);
  305. break;
  306. case 0x41:
  307. case 0x42: /* pciid also 0x00Cx */
  308. /* case 0x0120: XXX (pciid) */
  309. nv_wr32(dev, 0x400828, 0x007596ff);
  310. nv_wr32(dev, 0x40082c, 0x00000108);
  311. break;
  312. case 0x43:
  313. nv_wr32(dev, 0x400828, 0x0072cb77);
  314. nv_wr32(dev, 0x40082c, 0x00000108);
  315. break;
  316. case 0x44:
  317. case 0x46: /* G72 */
  318. case 0x4a:
  319. case 0x4c: /* G7x-based C51 */
  320. case 0x4e:
  321. nv_wr32(dev, 0x400860, 0);
  322. nv_wr32(dev, 0x400864, 0);
  323. break;
  324. case 0x47: /* G70 */
  325. case 0x49: /* G71 */
  326. case 0x4b: /* G73 */
  327. nv_wr32(dev, 0x400828, 0x07830610);
  328. nv_wr32(dev, 0x40082c, 0x0000016A);
  329. break;
  330. default:
  331. break;
  332. }
  333. nv_wr32(dev, 0x400b38, 0x2ffff800);
  334. nv_wr32(dev, 0x400b3c, 0x00006000);
  335. /* Tiling related stuff. */
  336. switch (dev_priv->chipset) {
  337. case 0x44:
  338. case 0x4a:
  339. nv_wr32(dev, 0x400bc4, 0x1003d888);
  340. nv_wr32(dev, 0x400bbc, 0xb7a7b500);
  341. break;
  342. case 0x46:
  343. nv_wr32(dev, 0x400bc4, 0x0000e024);
  344. nv_wr32(dev, 0x400bbc, 0xb7a7b520);
  345. break;
  346. case 0x4c:
  347. case 0x4e:
  348. case 0x67:
  349. nv_wr32(dev, 0x400bc4, 0x1003d888);
  350. nv_wr32(dev, 0x400bbc, 0xb7a7b540);
  351. break;
  352. default:
  353. break;
  354. }
  355. /* Turn all the tiling regions off. */
  356. for (i = 0; i < pfb->num_tiles; i++)
  357. nv40_graph_set_tile_region(dev, i);
  358. /* begin RAM config */
  359. vramsz = pci_resource_len(dev->pdev, 0) - 1;
  360. switch (dev_priv->chipset) {
  361. case 0x40:
  362. nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0));
  363. nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1));
  364. nv_wr32(dev, 0x4069A4, nv_rd32(dev, NV04_PFB_CFG0));
  365. nv_wr32(dev, 0x4069A8, nv_rd32(dev, NV04_PFB_CFG1));
  366. nv_wr32(dev, 0x400820, 0);
  367. nv_wr32(dev, 0x400824, 0);
  368. nv_wr32(dev, 0x400864, vramsz);
  369. nv_wr32(dev, 0x400868, vramsz);
  370. break;
  371. default:
  372. switch (dev_priv->chipset) {
  373. case 0x41:
  374. case 0x42:
  375. case 0x43:
  376. case 0x45:
  377. case 0x4e:
  378. case 0x44:
  379. case 0x4a:
  380. nv_wr32(dev, 0x4009F0, nv_rd32(dev, NV04_PFB_CFG0));
  381. nv_wr32(dev, 0x4009F4, nv_rd32(dev, NV04_PFB_CFG1));
  382. break;
  383. default:
  384. nv_wr32(dev, 0x400DF0, nv_rd32(dev, NV04_PFB_CFG0));
  385. nv_wr32(dev, 0x400DF4, nv_rd32(dev, NV04_PFB_CFG1));
  386. break;
  387. }
  388. nv_wr32(dev, 0x4069F0, nv_rd32(dev, NV04_PFB_CFG0));
  389. nv_wr32(dev, 0x4069F4, nv_rd32(dev, NV04_PFB_CFG1));
  390. nv_wr32(dev, 0x400840, 0);
  391. nv_wr32(dev, 0x400844, 0);
  392. nv_wr32(dev, 0x4008A0, vramsz);
  393. nv_wr32(dev, 0x4008A4, vramsz);
  394. break;
  395. }
  396. return 0;
  397. }
  398. void nv40_graph_takedown(struct drm_device *dev)
  399. {
  400. nouveau_irq_unregister(dev, 12);
  401. }
  402. static int
  403. nv40_graph_register(struct drm_device *dev)
  404. {
  405. struct drm_nouveau_private *dev_priv = dev->dev_private;
  406. if (dev_priv->engine.graph.registered)
  407. return 0;
  408. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  409. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  410. NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */
  411. NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */
  412. NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */
  413. NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */
  414. NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */
  415. NVOBJ_CLASS(dev, 0x3089, GR); /* sifm (nv40) */
  416. NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */
  417. NVOBJ_CLASS(dev, 0x3062, GR); /* surf2d (nv40) */
  418. NVOBJ_CLASS(dev, 0x0043, GR); /* rop */
  419. NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */
  420. NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */
  421. NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */
  422. NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */
  423. NVOBJ_CLASS(dev, 0x309e, GR); /* swzsurf */
  424. /* curie */
  425. if (nv44_graph_class(dev))
  426. NVOBJ_CLASS(dev, 0x4497, GR);
  427. else
  428. NVOBJ_CLASS(dev, 0x4097, GR);
  429. /* nvsw */
  430. NVOBJ_CLASS(dev, 0x506e, SW);
  431. NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip);
  432. dev_priv->engine.graph.registered = true;
  433. return 0;
  434. }
  435. static int
  436. nv40_graph_isr_chid(struct drm_device *dev, u32 inst)
  437. {
  438. struct drm_nouveau_private *dev_priv = dev->dev_private;
  439. struct nouveau_channel *chan;
  440. unsigned long flags;
  441. int i;
  442. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  443. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  444. chan = dev_priv->channels.ptr[i];
  445. if (!chan || !chan->ramin_grctx)
  446. continue;
  447. if (inst == chan->ramin_grctx->pinst)
  448. break;
  449. }
  450. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  451. return i;
  452. }
  453. static void
  454. nv40_graph_isr(struct drm_device *dev)
  455. {
  456. u32 stat;
  457. while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) {
  458. u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
  459. u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
  460. u32 inst = (nv_rd32(dev, 0x40032c) & 0x000fffff) << 4;
  461. u32 chid = nv40_graph_isr_chid(dev, inst);
  462. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  463. u32 subc = (addr & 0x00070000) >> 16;
  464. u32 mthd = (addr & 0x00001ffc);
  465. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  466. u32 class = nv_rd32(dev, 0x400160 + subc * 4) & 0xffff;
  467. u32 show = stat;
  468. if (stat & NV_PGRAPH_INTR_ERROR) {
  469. if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
  470. if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data))
  471. show &= ~NV_PGRAPH_INTR_ERROR;
  472. } else
  473. if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) {
  474. nv_mask(dev, 0x402000, 0, 0);
  475. }
  476. }
  477. nv_wr32(dev, NV03_PGRAPH_INTR, stat);
  478. nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001);
  479. if (show && nouveau_ratelimit()) {
  480. NV_INFO(dev, "PGRAPH -");
  481. nouveau_bitfield_print(nv10_graph_intr, show);
  482. printk(" nsource:");
  483. nouveau_bitfield_print(nv04_graph_nsource, nsource);
  484. printk(" nstatus:");
  485. nouveau_bitfield_print(nv10_graph_nstatus, nstatus);
  486. printk("\n");
  487. NV_INFO(dev, "PGRAPH - ch %d (0x%08x) subc %d "
  488. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  489. chid, inst, subc, class, mthd, data);
  490. }
  491. }
  492. }