nv50_graph.c 30 KB

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