nv50_graph.c 30 KB

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