nv50_graph.c 30 KB

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