nv50_graph.c 30 KB

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