nv40_graph.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * Copyright (C) 2007 Ben Skeggs.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_grctx.h"
  30. #include "nouveau_ramht.h"
  31. struct nv40_graph_engine {
  32. struct nouveau_exec_engine base;
  33. u32 grctx_size;
  34. };
  35. static struct nouveau_channel *
  36. nv40_graph_channel(struct drm_device *dev)
  37. {
  38. struct drm_nouveau_private *dev_priv = dev->dev_private;
  39. struct nouveau_gpuobj *grctx;
  40. uint32_t inst;
  41. int i;
  42. inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR);
  43. if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED))
  44. return NULL;
  45. inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4;
  46. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  47. if (!dev_priv->channels.ptr[i])
  48. continue;
  49. grctx = dev_priv->channels.ptr[i]->engctx[NVOBJ_ENGINE_GR];
  50. if (grctx && grctx->pinst == inst)
  51. return dev_priv->channels.ptr[i];
  52. }
  53. return NULL;
  54. }
  55. static int
  56. nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save)
  57. {
  58. uint32_t old_cp, tv = 1000, tmp;
  59. int i;
  60. old_cp = nv_rd32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER);
  61. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
  62. tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0310);
  63. tmp |= save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE :
  64. NV40_PGRAPH_CTXCTL_0310_XFER_LOAD;
  65. nv_wr32(dev, NV40_PGRAPH_CTXCTL_0310, tmp);
  66. tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0304);
  67. tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX;
  68. nv_wr32(dev, NV40_PGRAPH_CTXCTL_0304, tmp);
  69. nouveau_wait_for_idle(dev);
  70. for (i = 0; i < tv; i++) {
  71. if (nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C) == 0)
  72. break;
  73. }
  74. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp);
  75. if (i == tv) {
  76. uint32_t ucstat = nv_rd32(dev, NV40_PGRAPH_CTXCTL_UCODE_STAT);
  77. NV_ERROR(dev, "Failed: Instance=0x%08x Save=%d\n", inst, save);
  78. NV_ERROR(dev, "IP: 0x%02x, Opcode: 0x%08x\n",
  79. ucstat >> NV40_PGRAPH_CTXCTL_UCODE_STAT_IP_SHIFT,
  80. ucstat & NV40_PGRAPH_CTXCTL_UCODE_STAT_OP_MASK);
  81. NV_ERROR(dev, "0x40030C = 0x%08x\n",
  82. nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C));
  83. return -EBUSY;
  84. }
  85. return 0;
  86. }
  87. static int
  88. nv40_graph_unload_context(struct drm_device *dev)
  89. {
  90. uint32_t inst;
  91. int ret;
  92. inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR);
  93. if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED))
  94. return 0;
  95. inst &= NV40_PGRAPH_CTXCTL_CUR_INSTANCE;
  96. ret = nv40_graph_transfer_context(dev, inst, 1);
  97. nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, inst);
  98. return ret;
  99. }
  100. static int
  101. nv40_graph_context_new(struct nouveau_channel *chan, int engine)
  102. {
  103. struct nv40_graph_engine *pgraph = nv_engine(chan->dev, engine);
  104. struct drm_device *dev = chan->dev;
  105. struct drm_nouveau_private *dev_priv = dev->dev_private;
  106. struct nouveau_gpuobj *grctx = NULL;
  107. struct nouveau_grctx ctx = {};
  108. unsigned long flags;
  109. int ret;
  110. ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 16,
  111. NVOBJ_FLAG_ZERO_ALLOC, &grctx);
  112. if (ret)
  113. return ret;
  114. /* Initialise default context values */
  115. ctx.dev = chan->dev;
  116. ctx.mode = NOUVEAU_GRCTX_VALS;
  117. ctx.data = grctx;
  118. nv40_grctx_init(&ctx);
  119. nv_wo32(grctx, 0, grctx->vinst);
  120. /* init grctx pointer in ramfc, and on PFIFO if channel is
  121. * already active there
  122. */
  123. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  124. nv_wo32(chan->ramfc, 0x38, grctx->vinst >> 4);
  125. nv_mask(dev, 0x002500, 0x00000001, 0x00000000);
  126. if ((nv_rd32(dev, 0x003204) & 0x0000001f) == chan->id)
  127. nv_wr32(dev, 0x0032e0, grctx->vinst >> 4);
  128. nv_mask(dev, 0x002500, 0x00000001, 0x00000001);
  129. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  130. chan->engctx[engine] = grctx;
  131. return 0;
  132. }
  133. static void
  134. nv40_graph_context_del(struct nouveau_channel *chan, int engine)
  135. {
  136. struct nouveau_gpuobj *grctx = chan->engctx[engine];
  137. struct drm_device *dev = chan->dev;
  138. struct drm_nouveau_private *dev_priv = dev->dev_private;
  139. unsigned long flags;
  140. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  141. nv04_graph_fifo_access(dev, false);
  142. /* Unload the context if it's the currently active one */
  143. if (nv40_graph_channel(dev) == chan)
  144. nv40_graph_unload_context(dev);
  145. nv04_graph_fifo_access(dev, true);
  146. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  147. /* Free the context resources */
  148. nouveau_gpuobj_ref(NULL, &grctx);
  149. chan->engctx[engine] = NULL;
  150. }
  151. int
  152. nv40_graph_object_new(struct nouveau_channel *chan, int engine,
  153. u32 handle, u16 class)
  154. {
  155. struct drm_device *dev = chan->dev;
  156. struct nouveau_gpuobj *obj = NULL;
  157. int ret;
  158. ret = nouveau_gpuobj_new(dev, chan, 20, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  159. if (ret)
  160. return ret;
  161. obj->engine = 1;
  162. obj->class = class;
  163. nv_wo32(obj, 0x00, class);
  164. nv_wo32(obj, 0x04, 0x00000000);
  165. #ifndef __BIG_ENDIAN
  166. nv_wo32(obj, 0x08, 0x00000000);
  167. #else
  168. nv_wo32(obj, 0x08, 0x01000000);
  169. #endif
  170. nv_wo32(obj, 0x0c, 0x00000000);
  171. nv_wo32(obj, 0x10, 0x00000000);
  172. ret = nouveau_ramht_insert(chan, handle, obj);
  173. nouveau_gpuobj_ref(NULL, &obj);
  174. return ret;
  175. }
  176. static void
  177. nv40_graph_set_tile_region(struct drm_device *dev, int i)
  178. {
  179. struct drm_nouveau_private *dev_priv = dev->dev_private;
  180. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  181. switch (dev_priv->chipset) {
  182. case 0x40:
  183. case 0x41: /* guess */
  184. case 0x42:
  185. case 0x43:
  186. case 0x45: /* guess */
  187. case 0x4e:
  188. nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch);
  189. nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit);
  190. nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr);
  191. nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch);
  192. nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit);
  193. nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr);
  194. break;
  195. case 0x44:
  196. case 0x4a:
  197. nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch);
  198. nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit);
  199. nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr);
  200. break;
  201. case 0x46:
  202. case 0x47:
  203. case 0x49:
  204. case 0x4b:
  205. case 0x4c:
  206. case 0x67:
  207. default:
  208. nv_wr32(dev, NV47_PGRAPH_TSIZE(i), tile->pitch);
  209. nv_wr32(dev, NV47_PGRAPH_TLIMIT(i), tile->limit);
  210. nv_wr32(dev, NV47_PGRAPH_TILE(i), tile->addr);
  211. nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch);
  212. nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit);
  213. nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr);
  214. break;
  215. }
  216. }
  217. /*
  218. * G70 0x47
  219. * G71 0x49
  220. * NV45 0x48
  221. * G72[M] 0x46
  222. * G73 0x4b
  223. * C51_G7X 0x4c
  224. * C51 0x4e
  225. */
  226. int
  227. nv40_graph_init(struct drm_device *dev, int engine)
  228. {
  229. struct nv40_graph_engine *pgraph = nv_engine(dev, engine);
  230. struct drm_nouveau_private *dev_priv = dev->dev_private;
  231. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  232. struct nouveau_grctx ctx = {};
  233. uint32_t vramsz, *cp;
  234. int i, j;
  235. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) &
  236. ~NV_PMC_ENABLE_PGRAPH);
  237. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  238. NV_PMC_ENABLE_PGRAPH);
  239. cp = kmalloc(sizeof(*cp) * 256, GFP_KERNEL);
  240. if (!cp)
  241. return -ENOMEM;
  242. ctx.dev = dev;
  243. ctx.mode = NOUVEAU_GRCTX_PROG;
  244. ctx.data = cp;
  245. ctx.ctxprog_max = 256;
  246. nv40_grctx_init(&ctx);
  247. pgraph->grctx_size = ctx.ctxvals_pos * 4;
  248. nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
  249. for (i = 0; i < ctx.ctxprog_len; i++)
  250. nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]);
  251. kfree(cp);
  252. /* No context present currently */
  253. nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000);
  254. nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  255. nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xFFFFFFFF);
  256. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  257. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000);
  258. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0);
  259. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xe0de8055);
  260. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000);
  261. nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0x00be3c5f);
  262. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
  263. nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF);
  264. j = nv_rd32(dev, 0x1540) & 0xff;
  265. if (j) {
  266. for (i = 0; !(j & 1); j >>= 1, i++)
  267. ;
  268. nv_wr32(dev, 0x405000, i);
  269. }
  270. if (dev_priv->chipset == 0x40) {
  271. nv_wr32(dev, 0x4009b0, 0x83280fff);
  272. nv_wr32(dev, 0x4009b4, 0x000000a0);
  273. } else {
  274. nv_wr32(dev, 0x400820, 0x83280eff);
  275. nv_wr32(dev, 0x400824, 0x000000a0);
  276. }
  277. switch (dev_priv->chipset) {
  278. case 0x40:
  279. case 0x45:
  280. nv_wr32(dev, 0x4009b8, 0x0078e366);
  281. nv_wr32(dev, 0x4009bc, 0x0000014c);
  282. break;
  283. case 0x41:
  284. case 0x42: /* pciid also 0x00Cx */
  285. /* case 0x0120: XXX (pciid) */
  286. nv_wr32(dev, 0x400828, 0x007596ff);
  287. nv_wr32(dev, 0x40082c, 0x00000108);
  288. break;
  289. case 0x43:
  290. nv_wr32(dev, 0x400828, 0x0072cb77);
  291. nv_wr32(dev, 0x40082c, 0x00000108);
  292. break;
  293. case 0x44:
  294. case 0x46: /* G72 */
  295. case 0x4a:
  296. case 0x4c: /* G7x-based C51 */
  297. case 0x4e:
  298. nv_wr32(dev, 0x400860, 0);
  299. nv_wr32(dev, 0x400864, 0);
  300. break;
  301. case 0x47: /* G70 */
  302. case 0x49: /* G71 */
  303. case 0x4b: /* G73 */
  304. nv_wr32(dev, 0x400828, 0x07830610);
  305. nv_wr32(dev, 0x40082c, 0x0000016A);
  306. break;
  307. default:
  308. break;
  309. }
  310. nv_wr32(dev, 0x400b38, 0x2ffff800);
  311. nv_wr32(dev, 0x400b3c, 0x00006000);
  312. /* Tiling related stuff. */
  313. switch (dev_priv->chipset) {
  314. case 0x44:
  315. case 0x4a:
  316. nv_wr32(dev, 0x400bc4, 0x1003d888);
  317. nv_wr32(dev, 0x400bbc, 0xb7a7b500);
  318. break;
  319. case 0x46:
  320. nv_wr32(dev, 0x400bc4, 0x0000e024);
  321. nv_wr32(dev, 0x400bbc, 0xb7a7b520);
  322. break;
  323. case 0x4c:
  324. case 0x4e:
  325. case 0x67:
  326. nv_wr32(dev, 0x400bc4, 0x1003d888);
  327. nv_wr32(dev, 0x400bbc, 0xb7a7b540);
  328. break;
  329. default:
  330. break;
  331. }
  332. /* Turn all the tiling regions off. */
  333. for (i = 0; i < pfb->num_tiles; i++)
  334. nv40_graph_set_tile_region(dev, i);
  335. /* begin RAM config */
  336. vramsz = pci_resource_len(dev->pdev, 0) - 1;
  337. switch (dev_priv->chipset) {
  338. case 0x40:
  339. nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0));
  340. nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1));
  341. nv_wr32(dev, 0x4069A4, nv_rd32(dev, NV04_PFB_CFG0));
  342. nv_wr32(dev, 0x4069A8, nv_rd32(dev, NV04_PFB_CFG1));
  343. nv_wr32(dev, 0x400820, 0);
  344. nv_wr32(dev, 0x400824, 0);
  345. nv_wr32(dev, 0x400864, vramsz);
  346. nv_wr32(dev, 0x400868, vramsz);
  347. break;
  348. default:
  349. switch (dev_priv->chipset) {
  350. case 0x41:
  351. case 0x42:
  352. case 0x43:
  353. case 0x45:
  354. case 0x4e:
  355. case 0x44:
  356. case 0x4a:
  357. nv_wr32(dev, 0x4009F0, nv_rd32(dev, NV04_PFB_CFG0));
  358. nv_wr32(dev, 0x4009F4, nv_rd32(dev, NV04_PFB_CFG1));
  359. break;
  360. default:
  361. nv_wr32(dev, 0x400DF0, nv_rd32(dev, NV04_PFB_CFG0));
  362. nv_wr32(dev, 0x400DF4, nv_rd32(dev, NV04_PFB_CFG1));
  363. break;
  364. }
  365. nv_wr32(dev, 0x4069F0, nv_rd32(dev, NV04_PFB_CFG0));
  366. nv_wr32(dev, 0x4069F4, nv_rd32(dev, NV04_PFB_CFG1));
  367. nv_wr32(dev, 0x400840, 0);
  368. nv_wr32(dev, 0x400844, 0);
  369. nv_wr32(dev, 0x4008A0, vramsz);
  370. nv_wr32(dev, 0x4008A4, vramsz);
  371. break;
  372. }
  373. return 0;
  374. }
  375. static int
  376. nv40_graph_fini(struct drm_device *dev, int engine)
  377. {
  378. nv40_graph_unload_context(dev);
  379. return 0;
  380. }
  381. static int
  382. nv40_graph_isr_chid(struct drm_device *dev, u32 inst)
  383. {
  384. struct drm_nouveau_private *dev_priv = dev->dev_private;
  385. struct nouveau_gpuobj *grctx;
  386. unsigned long flags;
  387. int i;
  388. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  389. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  390. if (!dev_priv->channels.ptr[i])
  391. continue;
  392. grctx = dev_priv->channels.ptr[i]->engctx[NVOBJ_ENGINE_GR];
  393. if (grctx && grctx->pinst == inst)
  394. break;
  395. }
  396. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  397. return i;
  398. }
  399. static void
  400. nv40_graph_isr(struct drm_device *dev)
  401. {
  402. u32 stat;
  403. while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) {
  404. u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
  405. u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
  406. u32 inst = (nv_rd32(dev, 0x40032c) & 0x000fffff) << 4;
  407. u32 chid = nv40_graph_isr_chid(dev, inst);
  408. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  409. u32 subc = (addr & 0x00070000) >> 16;
  410. u32 mthd = (addr & 0x00001ffc);
  411. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  412. u32 class = nv_rd32(dev, 0x400160 + subc * 4) & 0xffff;
  413. u32 show = stat;
  414. if (stat & NV_PGRAPH_INTR_ERROR) {
  415. if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
  416. if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data))
  417. show &= ~NV_PGRAPH_INTR_ERROR;
  418. } else
  419. if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) {
  420. nv_mask(dev, 0x402000, 0, 0);
  421. }
  422. }
  423. nv_wr32(dev, NV03_PGRAPH_INTR, stat);
  424. nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001);
  425. if (show && nouveau_ratelimit()) {
  426. NV_INFO(dev, "PGRAPH -");
  427. nouveau_bitfield_print(nv10_graph_intr, show);
  428. printk(" nsource:");
  429. nouveau_bitfield_print(nv04_graph_nsource, nsource);
  430. printk(" nstatus:");
  431. nouveau_bitfield_print(nv10_graph_nstatus, nstatus);
  432. printk("\n");
  433. NV_INFO(dev, "PGRAPH - ch %d (0x%08x) subc %d "
  434. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  435. chid, inst, subc, class, mthd, data);
  436. }
  437. }
  438. }
  439. static void
  440. nv40_graph_destroy(struct drm_device *dev, int engine)
  441. {
  442. struct nv40_graph_engine *pgraph = nv_engine(dev, engine);
  443. nouveau_irq_unregister(dev, 12);
  444. NVOBJ_ENGINE_DEL(dev, GR);
  445. kfree(pgraph);
  446. }
  447. int
  448. nv40_graph_create(struct drm_device *dev)
  449. {
  450. struct nv40_graph_engine *pgraph;
  451. pgraph = kzalloc(sizeof(*pgraph), GFP_KERNEL);
  452. if (!pgraph)
  453. return -ENOMEM;
  454. pgraph->base.destroy = nv40_graph_destroy;
  455. pgraph->base.init = nv40_graph_init;
  456. pgraph->base.fini = nv40_graph_fini;
  457. pgraph->base.context_new = nv40_graph_context_new;
  458. pgraph->base.context_del = nv40_graph_context_del;
  459. pgraph->base.object_new = nv40_graph_object_new;
  460. pgraph->base.set_tile_region = nv40_graph_set_tile_region;
  461. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  462. nouveau_irq_register(dev, 12, nv40_graph_isr);
  463. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  464. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  465. NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */
  466. NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */
  467. NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */
  468. NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */
  469. NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */
  470. NVOBJ_CLASS(dev, 0x3089, GR); /* sifm (nv40) */
  471. NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */
  472. NVOBJ_CLASS(dev, 0x3062, GR); /* surf2d (nv40) */
  473. NVOBJ_CLASS(dev, 0x0043, GR); /* rop */
  474. NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */
  475. NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */
  476. NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */
  477. NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */
  478. NVOBJ_CLASS(dev, 0x309e, GR); /* swzsurf */
  479. /* curie */
  480. if (nv44_graph_class(dev))
  481. NVOBJ_CLASS(dev, 0x4497, GR);
  482. else
  483. NVOBJ_CLASS(dev, 0x4097, GR);
  484. /* nvsw */
  485. NVOBJ_CLASS(dev, 0x506e, SW);
  486. NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip);
  487. return 0;
  488. }