nv04_graph.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. /*
  2. * Copyright 2007 Stephane Marchesin
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "drmP.h"
  25. #include "drm.h"
  26. #include "nouveau_drm.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_hw.h"
  29. #include "nouveau_util.h"
  30. #include "nouveau_ramht.h"
  31. struct nv04_graph_engine {
  32. struct nouveau_exec_engine base;
  33. };
  34. static uint32_t nv04_graph_ctx_regs[] = {
  35. 0x0040053c,
  36. 0x00400544,
  37. 0x00400540,
  38. 0x00400548,
  39. NV04_PGRAPH_CTX_SWITCH1,
  40. NV04_PGRAPH_CTX_SWITCH2,
  41. NV04_PGRAPH_CTX_SWITCH3,
  42. NV04_PGRAPH_CTX_SWITCH4,
  43. NV04_PGRAPH_CTX_CACHE1,
  44. NV04_PGRAPH_CTX_CACHE2,
  45. NV04_PGRAPH_CTX_CACHE3,
  46. NV04_PGRAPH_CTX_CACHE4,
  47. 0x00400184,
  48. 0x004001a4,
  49. 0x004001c4,
  50. 0x004001e4,
  51. 0x00400188,
  52. 0x004001a8,
  53. 0x004001c8,
  54. 0x004001e8,
  55. 0x0040018c,
  56. 0x004001ac,
  57. 0x004001cc,
  58. 0x004001ec,
  59. 0x00400190,
  60. 0x004001b0,
  61. 0x004001d0,
  62. 0x004001f0,
  63. 0x00400194,
  64. 0x004001b4,
  65. 0x004001d4,
  66. 0x004001f4,
  67. 0x00400198,
  68. 0x004001b8,
  69. 0x004001d8,
  70. 0x004001f8,
  71. 0x0040019c,
  72. 0x004001bc,
  73. 0x004001dc,
  74. 0x004001fc,
  75. 0x00400174,
  76. NV04_PGRAPH_DMA_START_0,
  77. NV04_PGRAPH_DMA_START_1,
  78. NV04_PGRAPH_DMA_LENGTH,
  79. NV04_PGRAPH_DMA_MISC,
  80. NV04_PGRAPH_DMA_PITCH,
  81. NV04_PGRAPH_BOFFSET0,
  82. NV04_PGRAPH_BBASE0,
  83. NV04_PGRAPH_BLIMIT0,
  84. NV04_PGRAPH_BOFFSET1,
  85. NV04_PGRAPH_BBASE1,
  86. NV04_PGRAPH_BLIMIT1,
  87. NV04_PGRAPH_BOFFSET2,
  88. NV04_PGRAPH_BBASE2,
  89. NV04_PGRAPH_BLIMIT2,
  90. NV04_PGRAPH_BOFFSET3,
  91. NV04_PGRAPH_BBASE3,
  92. NV04_PGRAPH_BLIMIT3,
  93. NV04_PGRAPH_BOFFSET4,
  94. NV04_PGRAPH_BBASE4,
  95. NV04_PGRAPH_BLIMIT4,
  96. NV04_PGRAPH_BOFFSET5,
  97. NV04_PGRAPH_BBASE5,
  98. NV04_PGRAPH_BLIMIT5,
  99. NV04_PGRAPH_BPITCH0,
  100. NV04_PGRAPH_BPITCH1,
  101. NV04_PGRAPH_BPITCH2,
  102. NV04_PGRAPH_BPITCH3,
  103. NV04_PGRAPH_BPITCH4,
  104. NV04_PGRAPH_SURFACE,
  105. NV04_PGRAPH_STATE,
  106. NV04_PGRAPH_BSWIZZLE2,
  107. NV04_PGRAPH_BSWIZZLE5,
  108. NV04_PGRAPH_BPIXEL,
  109. NV04_PGRAPH_NOTIFY,
  110. NV04_PGRAPH_PATT_COLOR0,
  111. NV04_PGRAPH_PATT_COLOR1,
  112. NV04_PGRAPH_PATT_COLORRAM+0x00,
  113. NV04_PGRAPH_PATT_COLORRAM+0x04,
  114. NV04_PGRAPH_PATT_COLORRAM+0x08,
  115. NV04_PGRAPH_PATT_COLORRAM+0x0c,
  116. NV04_PGRAPH_PATT_COLORRAM+0x10,
  117. NV04_PGRAPH_PATT_COLORRAM+0x14,
  118. NV04_PGRAPH_PATT_COLORRAM+0x18,
  119. NV04_PGRAPH_PATT_COLORRAM+0x1c,
  120. NV04_PGRAPH_PATT_COLORRAM+0x20,
  121. NV04_PGRAPH_PATT_COLORRAM+0x24,
  122. NV04_PGRAPH_PATT_COLORRAM+0x28,
  123. NV04_PGRAPH_PATT_COLORRAM+0x2c,
  124. NV04_PGRAPH_PATT_COLORRAM+0x30,
  125. NV04_PGRAPH_PATT_COLORRAM+0x34,
  126. NV04_PGRAPH_PATT_COLORRAM+0x38,
  127. NV04_PGRAPH_PATT_COLORRAM+0x3c,
  128. NV04_PGRAPH_PATT_COLORRAM+0x40,
  129. NV04_PGRAPH_PATT_COLORRAM+0x44,
  130. NV04_PGRAPH_PATT_COLORRAM+0x48,
  131. NV04_PGRAPH_PATT_COLORRAM+0x4c,
  132. NV04_PGRAPH_PATT_COLORRAM+0x50,
  133. NV04_PGRAPH_PATT_COLORRAM+0x54,
  134. NV04_PGRAPH_PATT_COLORRAM+0x58,
  135. NV04_PGRAPH_PATT_COLORRAM+0x5c,
  136. NV04_PGRAPH_PATT_COLORRAM+0x60,
  137. NV04_PGRAPH_PATT_COLORRAM+0x64,
  138. NV04_PGRAPH_PATT_COLORRAM+0x68,
  139. NV04_PGRAPH_PATT_COLORRAM+0x6c,
  140. NV04_PGRAPH_PATT_COLORRAM+0x70,
  141. NV04_PGRAPH_PATT_COLORRAM+0x74,
  142. NV04_PGRAPH_PATT_COLORRAM+0x78,
  143. NV04_PGRAPH_PATT_COLORRAM+0x7c,
  144. NV04_PGRAPH_PATT_COLORRAM+0x80,
  145. NV04_PGRAPH_PATT_COLORRAM+0x84,
  146. NV04_PGRAPH_PATT_COLORRAM+0x88,
  147. NV04_PGRAPH_PATT_COLORRAM+0x8c,
  148. NV04_PGRAPH_PATT_COLORRAM+0x90,
  149. NV04_PGRAPH_PATT_COLORRAM+0x94,
  150. NV04_PGRAPH_PATT_COLORRAM+0x98,
  151. NV04_PGRAPH_PATT_COLORRAM+0x9c,
  152. NV04_PGRAPH_PATT_COLORRAM+0xa0,
  153. NV04_PGRAPH_PATT_COLORRAM+0xa4,
  154. NV04_PGRAPH_PATT_COLORRAM+0xa8,
  155. NV04_PGRAPH_PATT_COLORRAM+0xac,
  156. NV04_PGRAPH_PATT_COLORRAM+0xb0,
  157. NV04_PGRAPH_PATT_COLORRAM+0xb4,
  158. NV04_PGRAPH_PATT_COLORRAM+0xb8,
  159. NV04_PGRAPH_PATT_COLORRAM+0xbc,
  160. NV04_PGRAPH_PATT_COLORRAM+0xc0,
  161. NV04_PGRAPH_PATT_COLORRAM+0xc4,
  162. NV04_PGRAPH_PATT_COLORRAM+0xc8,
  163. NV04_PGRAPH_PATT_COLORRAM+0xcc,
  164. NV04_PGRAPH_PATT_COLORRAM+0xd0,
  165. NV04_PGRAPH_PATT_COLORRAM+0xd4,
  166. NV04_PGRAPH_PATT_COLORRAM+0xd8,
  167. NV04_PGRAPH_PATT_COLORRAM+0xdc,
  168. NV04_PGRAPH_PATT_COLORRAM+0xe0,
  169. NV04_PGRAPH_PATT_COLORRAM+0xe4,
  170. NV04_PGRAPH_PATT_COLORRAM+0xe8,
  171. NV04_PGRAPH_PATT_COLORRAM+0xec,
  172. NV04_PGRAPH_PATT_COLORRAM+0xf0,
  173. NV04_PGRAPH_PATT_COLORRAM+0xf4,
  174. NV04_PGRAPH_PATT_COLORRAM+0xf8,
  175. NV04_PGRAPH_PATT_COLORRAM+0xfc,
  176. NV04_PGRAPH_PATTERN,
  177. 0x0040080c,
  178. NV04_PGRAPH_PATTERN_SHAPE,
  179. 0x00400600,
  180. NV04_PGRAPH_ROP3,
  181. NV04_PGRAPH_CHROMA,
  182. NV04_PGRAPH_BETA_AND,
  183. NV04_PGRAPH_BETA_PREMULT,
  184. NV04_PGRAPH_CONTROL0,
  185. NV04_PGRAPH_CONTROL1,
  186. NV04_PGRAPH_CONTROL2,
  187. NV04_PGRAPH_BLEND,
  188. NV04_PGRAPH_STORED_FMT,
  189. NV04_PGRAPH_SOURCE_COLOR,
  190. 0x00400560,
  191. 0x00400568,
  192. 0x00400564,
  193. 0x0040056c,
  194. 0x00400400,
  195. 0x00400480,
  196. 0x00400404,
  197. 0x00400484,
  198. 0x00400408,
  199. 0x00400488,
  200. 0x0040040c,
  201. 0x0040048c,
  202. 0x00400410,
  203. 0x00400490,
  204. 0x00400414,
  205. 0x00400494,
  206. 0x00400418,
  207. 0x00400498,
  208. 0x0040041c,
  209. 0x0040049c,
  210. 0x00400420,
  211. 0x004004a0,
  212. 0x00400424,
  213. 0x004004a4,
  214. 0x00400428,
  215. 0x004004a8,
  216. 0x0040042c,
  217. 0x004004ac,
  218. 0x00400430,
  219. 0x004004b0,
  220. 0x00400434,
  221. 0x004004b4,
  222. 0x00400438,
  223. 0x004004b8,
  224. 0x0040043c,
  225. 0x004004bc,
  226. 0x00400440,
  227. 0x004004c0,
  228. 0x00400444,
  229. 0x004004c4,
  230. 0x00400448,
  231. 0x004004c8,
  232. 0x0040044c,
  233. 0x004004cc,
  234. 0x00400450,
  235. 0x004004d0,
  236. 0x00400454,
  237. 0x004004d4,
  238. 0x00400458,
  239. 0x004004d8,
  240. 0x0040045c,
  241. 0x004004dc,
  242. 0x00400460,
  243. 0x004004e0,
  244. 0x00400464,
  245. 0x004004e4,
  246. 0x00400468,
  247. 0x004004e8,
  248. 0x0040046c,
  249. 0x004004ec,
  250. 0x00400470,
  251. 0x004004f0,
  252. 0x00400474,
  253. 0x004004f4,
  254. 0x00400478,
  255. 0x004004f8,
  256. 0x0040047c,
  257. 0x004004fc,
  258. 0x00400534,
  259. 0x00400538,
  260. 0x00400514,
  261. 0x00400518,
  262. 0x0040051c,
  263. 0x00400520,
  264. 0x00400524,
  265. 0x00400528,
  266. 0x0040052c,
  267. 0x00400530,
  268. 0x00400d00,
  269. 0x00400d40,
  270. 0x00400d80,
  271. 0x00400d04,
  272. 0x00400d44,
  273. 0x00400d84,
  274. 0x00400d08,
  275. 0x00400d48,
  276. 0x00400d88,
  277. 0x00400d0c,
  278. 0x00400d4c,
  279. 0x00400d8c,
  280. 0x00400d10,
  281. 0x00400d50,
  282. 0x00400d90,
  283. 0x00400d14,
  284. 0x00400d54,
  285. 0x00400d94,
  286. 0x00400d18,
  287. 0x00400d58,
  288. 0x00400d98,
  289. 0x00400d1c,
  290. 0x00400d5c,
  291. 0x00400d9c,
  292. 0x00400d20,
  293. 0x00400d60,
  294. 0x00400da0,
  295. 0x00400d24,
  296. 0x00400d64,
  297. 0x00400da4,
  298. 0x00400d28,
  299. 0x00400d68,
  300. 0x00400da8,
  301. 0x00400d2c,
  302. 0x00400d6c,
  303. 0x00400dac,
  304. 0x00400d30,
  305. 0x00400d70,
  306. 0x00400db0,
  307. 0x00400d34,
  308. 0x00400d74,
  309. 0x00400db4,
  310. 0x00400d38,
  311. 0x00400d78,
  312. 0x00400db8,
  313. 0x00400d3c,
  314. 0x00400d7c,
  315. 0x00400dbc,
  316. 0x00400590,
  317. 0x00400594,
  318. 0x00400598,
  319. 0x0040059c,
  320. 0x004005a8,
  321. 0x004005ac,
  322. 0x004005b0,
  323. 0x004005b4,
  324. 0x004005c0,
  325. 0x004005c4,
  326. 0x004005c8,
  327. 0x004005cc,
  328. 0x004005d0,
  329. 0x004005d4,
  330. 0x004005d8,
  331. 0x004005dc,
  332. 0x004005e0,
  333. NV04_PGRAPH_PASSTHRU_0,
  334. NV04_PGRAPH_PASSTHRU_1,
  335. NV04_PGRAPH_PASSTHRU_2,
  336. NV04_PGRAPH_DVD_COLORFMT,
  337. NV04_PGRAPH_SCALED_FORMAT,
  338. NV04_PGRAPH_MISC24_0,
  339. NV04_PGRAPH_MISC24_1,
  340. NV04_PGRAPH_MISC24_2,
  341. 0x00400500,
  342. 0x00400504,
  343. NV04_PGRAPH_VALID1,
  344. NV04_PGRAPH_VALID2,
  345. NV04_PGRAPH_DEBUG_3
  346. };
  347. struct graph_state {
  348. uint32_t nv04[ARRAY_SIZE(nv04_graph_ctx_regs)];
  349. };
  350. static struct nouveau_channel *
  351. nv04_graph_channel(struct drm_device *dev)
  352. {
  353. struct drm_nouveau_private *dev_priv = dev->dev_private;
  354. int chid = 15;
  355. if (nv_rd32(dev, NV04_PGRAPH_CTX_CONTROL) & 0x00010000)
  356. chid = nv_rd32(dev, NV04_PGRAPH_CTX_USER) >> 24;
  357. if (chid > 15)
  358. return NULL;
  359. return dev_priv->channels.ptr[chid];
  360. }
  361. static uint32_t *ctx_reg(struct graph_state *ctx, uint32_t reg)
  362. {
  363. int i;
  364. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++) {
  365. if (nv04_graph_ctx_regs[i] == reg)
  366. return &ctx->nv04[i];
  367. }
  368. return NULL;
  369. }
  370. static int
  371. nv04_graph_load_context(struct nouveau_channel *chan)
  372. {
  373. struct graph_state *pgraph_ctx = chan->engctx[NVOBJ_ENGINE_GR];
  374. struct drm_device *dev = chan->dev;
  375. uint32_t tmp;
  376. int i;
  377. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++)
  378. nv_wr32(dev, nv04_graph_ctx_regs[i], pgraph_ctx->nv04[i]);
  379. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL, 0x10010100);
  380. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  381. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp | chan->id << 24);
  382. tmp = nv_rd32(dev, NV04_PGRAPH_FFINTFC_ST2);
  383. nv_wr32(dev, NV04_PGRAPH_FFINTFC_ST2, tmp & 0x000fffff);
  384. return 0;
  385. }
  386. static int
  387. nv04_graph_unload_context(struct drm_device *dev)
  388. {
  389. struct nouveau_channel *chan = NULL;
  390. struct graph_state *ctx;
  391. uint32_t tmp;
  392. int i;
  393. chan = nv04_graph_channel(dev);
  394. if (!chan)
  395. return 0;
  396. ctx = chan->engctx[NVOBJ_ENGINE_GR];
  397. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++)
  398. ctx->nv04[i] = nv_rd32(dev, nv04_graph_ctx_regs[i]);
  399. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL, 0x10000000);
  400. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  401. tmp |= 15 << 24;
  402. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp);
  403. return 0;
  404. }
  405. static int
  406. nv04_graph_context_new(struct nouveau_channel *chan, int engine)
  407. {
  408. struct graph_state *pgraph_ctx;
  409. NV_DEBUG(chan->dev, "nv04_graph_context_create %d\n", chan->id);
  410. pgraph_ctx = kzalloc(sizeof(*pgraph_ctx), GFP_KERNEL);
  411. if (pgraph_ctx == NULL)
  412. return -ENOMEM;
  413. *ctx_reg(pgraph_ctx, NV04_PGRAPH_DEBUG_3) = 0xfad4ff31;
  414. chan->engctx[engine] = pgraph_ctx;
  415. return 0;
  416. }
  417. static void
  418. nv04_graph_context_del(struct nouveau_channel *chan, int engine)
  419. {
  420. struct drm_device *dev = chan->dev;
  421. struct drm_nouveau_private *dev_priv = dev->dev_private;
  422. struct graph_state *pgraph_ctx = chan->engctx[engine];
  423. unsigned long flags;
  424. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  425. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000000);
  426. /* Unload the context if it's the currently active one */
  427. if (nv04_graph_channel(dev) == chan)
  428. nv04_graph_unload_context(dev);
  429. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000001);
  430. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  431. /* Free the context resources */
  432. kfree(pgraph_ctx);
  433. chan->engctx[engine] = NULL;
  434. }
  435. int
  436. nv04_graph_object_new(struct nouveau_channel *chan, int engine,
  437. u32 handle, u16 class)
  438. {
  439. struct drm_device *dev = chan->dev;
  440. struct nouveau_gpuobj *obj = NULL;
  441. int ret;
  442. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  443. if (ret)
  444. return ret;
  445. obj->engine = 1;
  446. obj->class = class;
  447. #ifdef __BIG_ENDIAN
  448. nv_wo32(obj, 0x00, 0x00080000 | class);
  449. #else
  450. nv_wo32(obj, 0x00, class);
  451. #endif
  452. nv_wo32(obj, 0x04, 0x00000000);
  453. nv_wo32(obj, 0x08, 0x00000000);
  454. nv_wo32(obj, 0x0c, 0x00000000);
  455. ret = nouveau_ramht_insert(chan, handle, obj);
  456. nouveau_gpuobj_ref(NULL, &obj);
  457. return ret;
  458. }
  459. static int
  460. nv04_graph_init(struct drm_device *dev, int engine)
  461. {
  462. uint32_t tmp;
  463. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) &
  464. ~NV_PMC_ENABLE_PGRAPH);
  465. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  466. NV_PMC_ENABLE_PGRAPH);
  467. /* Enable PGRAPH interrupts */
  468. nv_wr32(dev, NV03_PGRAPH_INTR, 0xFFFFFFFF);
  469. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  470. nv_wr32(dev, NV04_PGRAPH_VALID1, 0);
  471. nv_wr32(dev, NV04_PGRAPH_VALID2, 0);
  472. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x000001FF);
  473. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x001FFFFF);*/
  474. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x1231c000);
  475. /*1231C000 blob, 001 haiku*/
  476. /*V_WRITE(NV04_PGRAPH_DEBUG_1, 0xf2d91100);*/
  477. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x72111100);
  478. /*0x72111100 blob , 01 haiku*/
  479. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x11d5f870);*/
  480. nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x11d5f071);
  481. /*haiku same*/
  482. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xfad4ff31);*/
  483. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xf0d4ff31);
  484. /*haiku and blob 10d4*/
  485. nv_wr32(dev, NV04_PGRAPH_STATE , 0xFFFFFFFF);
  486. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL , 0x10000100);
  487. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  488. tmp |= 15 << 24;
  489. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp);
  490. /* These don't belong here, they're part of a per-channel context */
  491. nv_wr32(dev, NV04_PGRAPH_PATTERN_SHAPE, 0x00000000);
  492. nv_wr32(dev, NV04_PGRAPH_BETA_AND , 0xFFFFFFFF);
  493. return 0;
  494. }
  495. static int
  496. nv04_graph_fini(struct drm_device *dev, int engine, bool suspend)
  497. {
  498. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000000);
  499. if (!nv_wait(dev, NV04_PGRAPH_STATUS, ~0, 0) && suspend) {
  500. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000001);
  501. return -EBUSY;
  502. }
  503. nv04_graph_unload_context(dev);
  504. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0x00000000);
  505. return 0;
  506. }
  507. /*
  508. * Software methods, why they are needed, and how they all work:
  509. *
  510. * NV04 and NV05 keep most of the state in PGRAPH context itself, but some
  511. * 2d engine settings are kept inside the grobjs themselves. The grobjs are
  512. * 3 words long on both. grobj format on NV04 is:
  513. *
  514. * word 0:
  515. * - bits 0-7: class
  516. * - bit 12: color key active
  517. * - bit 13: clip rect active
  518. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  519. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  520. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  521. * NV03_CONTEXT_SURFACE_DST].
  522. * - bits 15-17: 2d operation [aka patch config]
  523. * - bit 24: patch valid [enables rendering using this object]
  524. * - bit 25: surf3d valid [for tex_tri and multitex_tri only]
  525. * word 1:
  526. * - bits 0-1: mono format
  527. * - bits 8-13: color format
  528. * - bits 16-31: DMA_NOTIFY instance
  529. * word 2:
  530. * - bits 0-15: DMA_A instance
  531. * - bits 16-31: DMA_B instance
  532. *
  533. * On NV05 it's:
  534. *
  535. * word 0:
  536. * - bits 0-7: class
  537. * - bit 12: color key active
  538. * - bit 13: clip rect active
  539. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  540. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  541. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  542. * NV03_CONTEXT_SURFACE_DST].
  543. * - bits 15-17: 2d operation [aka patch config]
  544. * - bits 20-22: dither mode
  545. * - bit 24: patch valid [enables rendering using this object]
  546. * - bit 25: surface_dst/surface_color/surf2d/surf3d valid
  547. * - bit 26: surface_src/surface_zeta valid
  548. * - bit 27: pattern valid
  549. * - bit 28: rop valid
  550. * - bit 29: beta1 valid
  551. * - bit 30: beta4 valid
  552. * word 1:
  553. * - bits 0-1: mono format
  554. * - bits 8-13: color format
  555. * - bits 16-31: DMA_NOTIFY instance
  556. * word 2:
  557. * - bits 0-15: DMA_A instance
  558. * - bits 16-31: DMA_B instance
  559. *
  560. * NV05 will set/unset the relevant valid bits when you poke the relevant
  561. * object-binding methods with object of the proper type, or with the NULL
  562. * type. It'll only allow rendering using the grobj if all needed objects
  563. * are bound. The needed set of objects depends on selected operation: for
  564. * example rop object is needed by ROP_AND, but not by SRCCOPY_AND.
  565. *
  566. * NV04 doesn't have these methods implemented at all, and doesn't have the
  567. * relevant bits in grobj. Instead, it'll allow rendering whenever bit 24
  568. * is set. So we have to emulate them in software, internally keeping the
  569. * same bits as NV05 does. Since grobjs are aligned to 16 bytes on nv04,
  570. * but the last word isn't actually used for anything, we abuse it for this
  571. * purpose.
  572. *
  573. * Actually, NV05 can optionally check bit 24 too, but we disable this since
  574. * there's no use for it.
  575. *
  576. * For unknown reasons, NV04 implements surf3d binding in hardware as an
  577. * exception. Also for unknown reasons, NV04 doesn't implement the clipping
  578. * methods on the surf3d object, so we have to emulate them too.
  579. */
  580. static void
  581. nv04_graph_set_ctx1(struct nouveau_channel *chan, u32 mask, u32 value)
  582. {
  583. struct drm_device *dev = chan->dev;
  584. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  585. int subc = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7;
  586. u32 tmp;
  587. tmp = nv_ri32(dev, instance);
  588. tmp &= ~mask;
  589. tmp |= value;
  590. nv_wi32(dev, instance, tmp);
  591. nv_wr32(dev, NV04_PGRAPH_CTX_SWITCH1, tmp);
  592. nv_wr32(dev, NV04_PGRAPH_CTX_CACHE1 + (subc<<2), tmp);
  593. }
  594. static void
  595. nv04_graph_set_ctx_val(struct nouveau_channel *chan, u32 mask, u32 value)
  596. {
  597. struct drm_device *dev = chan->dev;
  598. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  599. u32 tmp, ctx1;
  600. int class, op, valid = 1;
  601. ctx1 = nv_ri32(dev, instance);
  602. class = ctx1 & 0xff;
  603. op = (ctx1 >> 15) & 7;
  604. tmp = nv_ri32(dev, instance + 0xc);
  605. tmp &= ~mask;
  606. tmp |= value;
  607. nv_wi32(dev, instance + 0xc, tmp);
  608. /* check for valid surf2d/surf_dst/surf_color */
  609. if (!(tmp & 0x02000000))
  610. valid = 0;
  611. /* check for valid surf_src/surf_zeta */
  612. if ((class == 0x1f || class == 0x48) && !(tmp & 0x04000000))
  613. valid = 0;
  614. switch (op) {
  615. /* SRCCOPY_AND, SRCCOPY: no extra objects required */
  616. case 0:
  617. case 3:
  618. break;
  619. /* ROP_AND: requires pattern and rop */
  620. case 1:
  621. if (!(tmp & 0x18000000))
  622. valid = 0;
  623. break;
  624. /* BLEND_AND: requires beta1 */
  625. case 2:
  626. if (!(tmp & 0x20000000))
  627. valid = 0;
  628. break;
  629. /* SRCCOPY_PREMULT, BLEND_PREMULT: beta4 required */
  630. case 4:
  631. case 5:
  632. if (!(tmp & 0x40000000))
  633. valid = 0;
  634. break;
  635. }
  636. nv04_graph_set_ctx1(chan, 0x01000000, valid << 24);
  637. }
  638. static int
  639. nv04_graph_mthd_set_operation(struct nouveau_channel *chan,
  640. u32 class, u32 mthd, u32 data)
  641. {
  642. if (data > 5)
  643. return 1;
  644. /* Old versions of the objects only accept first three operations. */
  645. if (data > 2 && class < 0x40)
  646. return 1;
  647. nv04_graph_set_ctx1(chan, 0x00038000, data << 15);
  648. /* changing operation changes set of objects needed for validation */
  649. nv04_graph_set_ctx_val(chan, 0, 0);
  650. return 0;
  651. }
  652. static int
  653. nv04_graph_mthd_surf3d_clip_h(struct nouveau_channel *chan,
  654. u32 class, u32 mthd, u32 data)
  655. {
  656. uint32_t min = data & 0xffff, max;
  657. uint32_t w = data >> 16;
  658. if (min & 0x8000)
  659. /* too large */
  660. return 1;
  661. if (w & 0x8000)
  662. /* yes, it accepts negative for some reason. */
  663. w |= 0xffff0000;
  664. max = min + w;
  665. max &= 0x3ffff;
  666. nv_wr32(chan->dev, 0x40053c, min);
  667. nv_wr32(chan->dev, 0x400544, max);
  668. return 0;
  669. }
  670. static int
  671. nv04_graph_mthd_surf3d_clip_v(struct nouveau_channel *chan,
  672. u32 class, u32 mthd, u32 data)
  673. {
  674. uint32_t min = data & 0xffff, max;
  675. uint32_t w = data >> 16;
  676. if (min & 0x8000)
  677. /* too large */
  678. return 1;
  679. if (w & 0x8000)
  680. /* yes, it accepts negative for some reason. */
  681. w |= 0xffff0000;
  682. max = min + w;
  683. max &= 0x3ffff;
  684. nv_wr32(chan->dev, 0x400540, min);
  685. nv_wr32(chan->dev, 0x400548, max);
  686. return 0;
  687. }
  688. static int
  689. nv04_graph_mthd_bind_surf2d(struct nouveau_channel *chan,
  690. u32 class, u32 mthd, u32 data)
  691. {
  692. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  693. case 0x30:
  694. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  695. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  696. return 0;
  697. case 0x42:
  698. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  699. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  700. return 0;
  701. }
  702. return 1;
  703. }
  704. static int
  705. nv04_graph_mthd_bind_surf2d_swzsurf(struct nouveau_channel *chan,
  706. u32 class, u32 mthd, u32 data)
  707. {
  708. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  709. case 0x30:
  710. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  711. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  712. return 0;
  713. case 0x42:
  714. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  715. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  716. return 0;
  717. case 0x52:
  718. nv04_graph_set_ctx1(chan, 0x00004000, 0x00004000);
  719. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  720. return 0;
  721. }
  722. return 1;
  723. }
  724. static int
  725. nv04_graph_mthd_bind_nv01_patt(struct nouveau_channel *chan,
  726. u32 class, u32 mthd, u32 data)
  727. {
  728. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  729. case 0x30:
  730. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  731. return 0;
  732. case 0x18:
  733. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  734. return 0;
  735. }
  736. return 1;
  737. }
  738. static int
  739. nv04_graph_mthd_bind_nv04_patt(struct nouveau_channel *chan,
  740. u32 class, u32 mthd, u32 data)
  741. {
  742. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  743. case 0x30:
  744. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  745. return 0;
  746. case 0x44:
  747. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  748. return 0;
  749. }
  750. return 1;
  751. }
  752. static int
  753. nv04_graph_mthd_bind_rop(struct nouveau_channel *chan,
  754. u32 class, u32 mthd, u32 data)
  755. {
  756. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  757. case 0x30:
  758. nv04_graph_set_ctx_val(chan, 0x10000000, 0);
  759. return 0;
  760. case 0x43:
  761. nv04_graph_set_ctx_val(chan, 0x10000000, 0x10000000);
  762. return 0;
  763. }
  764. return 1;
  765. }
  766. static int
  767. nv04_graph_mthd_bind_beta1(struct nouveau_channel *chan,
  768. u32 class, u32 mthd, u32 data)
  769. {
  770. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  771. case 0x30:
  772. nv04_graph_set_ctx_val(chan, 0x20000000, 0);
  773. return 0;
  774. case 0x12:
  775. nv04_graph_set_ctx_val(chan, 0x20000000, 0x20000000);
  776. return 0;
  777. }
  778. return 1;
  779. }
  780. static int
  781. nv04_graph_mthd_bind_beta4(struct nouveau_channel *chan,
  782. u32 class, u32 mthd, u32 data)
  783. {
  784. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  785. case 0x30:
  786. nv04_graph_set_ctx_val(chan, 0x40000000, 0);
  787. return 0;
  788. case 0x72:
  789. nv04_graph_set_ctx_val(chan, 0x40000000, 0x40000000);
  790. return 0;
  791. }
  792. return 1;
  793. }
  794. static int
  795. nv04_graph_mthd_bind_surf_dst(struct nouveau_channel *chan,
  796. u32 class, u32 mthd, u32 data)
  797. {
  798. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  799. case 0x30:
  800. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  801. return 0;
  802. case 0x58:
  803. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  804. return 0;
  805. }
  806. return 1;
  807. }
  808. static int
  809. nv04_graph_mthd_bind_surf_src(struct nouveau_channel *chan,
  810. u32 class, u32 mthd, u32 data)
  811. {
  812. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  813. case 0x30:
  814. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  815. return 0;
  816. case 0x59:
  817. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  818. return 0;
  819. }
  820. return 1;
  821. }
  822. static int
  823. nv04_graph_mthd_bind_surf_color(struct nouveau_channel *chan,
  824. u32 class, u32 mthd, u32 data)
  825. {
  826. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  827. case 0x30:
  828. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  829. return 0;
  830. case 0x5a:
  831. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  832. return 0;
  833. }
  834. return 1;
  835. }
  836. static int
  837. nv04_graph_mthd_bind_surf_zeta(struct nouveau_channel *chan,
  838. u32 class, u32 mthd, u32 data)
  839. {
  840. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  841. case 0x30:
  842. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  843. return 0;
  844. case 0x5b:
  845. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  846. return 0;
  847. }
  848. return 1;
  849. }
  850. static int
  851. nv04_graph_mthd_bind_clip(struct nouveau_channel *chan,
  852. u32 class, u32 mthd, u32 data)
  853. {
  854. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  855. case 0x30:
  856. nv04_graph_set_ctx1(chan, 0x2000, 0);
  857. return 0;
  858. case 0x19:
  859. nv04_graph_set_ctx1(chan, 0x2000, 0x2000);
  860. return 0;
  861. }
  862. return 1;
  863. }
  864. static int
  865. nv04_graph_mthd_bind_chroma(struct nouveau_channel *chan,
  866. u32 class, u32 mthd, u32 data)
  867. {
  868. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  869. case 0x30:
  870. nv04_graph_set_ctx1(chan, 0x1000, 0);
  871. return 0;
  872. /* Yes, for some reason even the old versions of objects
  873. * accept 0x57 and not 0x17. Consistency be damned.
  874. */
  875. case 0x57:
  876. nv04_graph_set_ctx1(chan, 0x1000, 0x1000);
  877. return 0;
  878. }
  879. return 1;
  880. }
  881. static struct nouveau_bitfield nv04_graph_intr[] = {
  882. { NV_PGRAPH_INTR_NOTIFY, "NOTIFY" },
  883. {}
  884. };
  885. static struct nouveau_bitfield nv04_graph_nstatus[] = {
  886. { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
  887. { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
  888. { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
  889. { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
  890. {}
  891. };
  892. struct nouveau_bitfield nv04_graph_nsource[] = {
  893. { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
  894. { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
  895. { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
  896. { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
  897. { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
  898. { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
  899. { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
  900. { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
  901. { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
  902. { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
  903. { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
  904. { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
  905. { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
  906. { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
  907. { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
  908. { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
  909. { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
  910. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
  911. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
  912. {}
  913. };
  914. static void
  915. nv04_graph_context_switch(struct drm_device *dev)
  916. {
  917. struct drm_nouveau_private *dev_priv = dev->dev_private;
  918. struct nouveau_channel *chan = NULL;
  919. int chid;
  920. nouveau_wait_for_idle(dev);
  921. /* If previous context is valid, we need to save it */
  922. nv04_graph_unload_context(dev);
  923. /* Load context for next channel */
  924. chid = nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) &
  925. NV03_PFIFO_CACHE1_PUSH1_CHID_MASK;
  926. chan = dev_priv->channels.ptr[chid];
  927. if (chan)
  928. nv04_graph_load_context(chan);
  929. }
  930. static void
  931. nv04_graph_isr(struct drm_device *dev)
  932. {
  933. u32 stat;
  934. while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) {
  935. u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
  936. u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
  937. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  938. u32 chid = (addr & 0x0f000000) >> 24;
  939. u32 subc = (addr & 0x0000e000) >> 13;
  940. u32 mthd = (addr & 0x00001ffc);
  941. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  942. u32 class = nv_rd32(dev, 0x400180 + subc * 4) & 0xff;
  943. u32 show = stat;
  944. if (stat & NV_PGRAPH_INTR_NOTIFY) {
  945. if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
  946. if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data))
  947. show &= ~NV_PGRAPH_INTR_NOTIFY;
  948. }
  949. }
  950. if (stat & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
  951. nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
  952. stat &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  953. show &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  954. nv04_graph_context_switch(dev);
  955. }
  956. nv_wr32(dev, NV03_PGRAPH_INTR, stat);
  957. nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001);
  958. if (show && nouveau_ratelimit()) {
  959. NV_INFO(dev, "PGRAPH -");
  960. nouveau_bitfield_print(nv04_graph_intr, show);
  961. printk(" nsource:");
  962. nouveau_bitfield_print(nv04_graph_nsource, nsource);
  963. printk(" nstatus:");
  964. nouveau_bitfield_print(nv04_graph_nstatus, nstatus);
  965. printk("\n");
  966. NV_INFO(dev, "PGRAPH - ch %d/%d class 0x%04x "
  967. "mthd 0x%04x data 0x%08x\n",
  968. chid, subc, class, mthd, data);
  969. }
  970. }
  971. }
  972. static void
  973. nv04_graph_destroy(struct drm_device *dev, int engine)
  974. {
  975. struct nv04_graph_engine *pgraph = nv_engine(dev, engine);
  976. nouveau_irq_unregister(dev, 12);
  977. NVOBJ_ENGINE_DEL(dev, GR);
  978. kfree(pgraph);
  979. }
  980. int
  981. nv04_graph_create(struct drm_device *dev)
  982. {
  983. struct nv04_graph_engine *pgraph;
  984. pgraph = kzalloc(sizeof(*pgraph), GFP_KERNEL);
  985. if (!pgraph)
  986. return -ENOMEM;
  987. pgraph->base.destroy = nv04_graph_destroy;
  988. pgraph->base.init = nv04_graph_init;
  989. pgraph->base.fini = nv04_graph_fini;
  990. pgraph->base.context_new = nv04_graph_context_new;
  991. pgraph->base.context_del = nv04_graph_context_del;
  992. pgraph->base.object_new = nv04_graph_object_new;
  993. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  994. nouveau_irq_register(dev, 12, nv04_graph_isr);
  995. /* dvd subpicture */
  996. NVOBJ_CLASS(dev, 0x0038, GR);
  997. /* m2mf */
  998. NVOBJ_CLASS(dev, 0x0039, GR);
  999. /* nv03 gdirect */
  1000. NVOBJ_CLASS(dev, 0x004b, GR);
  1001. NVOBJ_MTHD (dev, 0x004b, 0x0184, nv04_graph_mthd_bind_nv01_patt);
  1002. NVOBJ_MTHD (dev, 0x004b, 0x0188, nv04_graph_mthd_bind_rop);
  1003. NVOBJ_MTHD (dev, 0x004b, 0x018c, nv04_graph_mthd_bind_beta1);
  1004. NVOBJ_MTHD (dev, 0x004b, 0x0190, nv04_graph_mthd_bind_surf_dst);
  1005. NVOBJ_MTHD (dev, 0x004b, 0x02fc, nv04_graph_mthd_set_operation);
  1006. /* nv04 gdirect */
  1007. NVOBJ_CLASS(dev, 0x004a, GR);
  1008. NVOBJ_MTHD (dev, 0x004a, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1009. NVOBJ_MTHD (dev, 0x004a, 0x018c, nv04_graph_mthd_bind_rop);
  1010. NVOBJ_MTHD (dev, 0x004a, 0x0190, nv04_graph_mthd_bind_beta1);
  1011. NVOBJ_MTHD (dev, 0x004a, 0x0194, nv04_graph_mthd_bind_beta4);
  1012. NVOBJ_MTHD (dev, 0x004a, 0x0198, nv04_graph_mthd_bind_surf2d);
  1013. NVOBJ_MTHD (dev, 0x004a, 0x02fc, nv04_graph_mthd_set_operation);
  1014. /* nv01 imageblit */
  1015. NVOBJ_CLASS(dev, 0x001f, GR);
  1016. NVOBJ_MTHD (dev, 0x001f, 0x0184, nv04_graph_mthd_bind_chroma);
  1017. NVOBJ_MTHD (dev, 0x001f, 0x0188, nv04_graph_mthd_bind_clip);
  1018. NVOBJ_MTHD (dev, 0x001f, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1019. NVOBJ_MTHD (dev, 0x001f, 0x0190, nv04_graph_mthd_bind_rop);
  1020. NVOBJ_MTHD (dev, 0x001f, 0x0194, nv04_graph_mthd_bind_beta1);
  1021. NVOBJ_MTHD (dev, 0x001f, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1022. NVOBJ_MTHD (dev, 0x001f, 0x019c, nv04_graph_mthd_bind_surf_src);
  1023. NVOBJ_MTHD (dev, 0x001f, 0x02fc, nv04_graph_mthd_set_operation);
  1024. /* nv04 imageblit */
  1025. NVOBJ_CLASS(dev, 0x005f, GR);
  1026. NVOBJ_MTHD (dev, 0x005f, 0x0184, nv04_graph_mthd_bind_chroma);
  1027. NVOBJ_MTHD (dev, 0x005f, 0x0188, nv04_graph_mthd_bind_clip);
  1028. NVOBJ_MTHD (dev, 0x005f, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1029. NVOBJ_MTHD (dev, 0x005f, 0x0190, nv04_graph_mthd_bind_rop);
  1030. NVOBJ_MTHD (dev, 0x005f, 0x0194, nv04_graph_mthd_bind_beta1);
  1031. NVOBJ_MTHD (dev, 0x005f, 0x0198, nv04_graph_mthd_bind_beta4);
  1032. NVOBJ_MTHD (dev, 0x005f, 0x019c, nv04_graph_mthd_bind_surf2d);
  1033. NVOBJ_MTHD (dev, 0x005f, 0x02fc, nv04_graph_mthd_set_operation);
  1034. /* nv04 iifc */
  1035. NVOBJ_CLASS(dev, 0x0060, GR);
  1036. NVOBJ_MTHD (dev, 0x0060, 0x0188, nv04_graph_mthd_bind_chroma);
  1037. NVOBJ_MTHD (dev, 0x0060, 0x018c, nv04_graph_mthd_bind_clip);
  1038. NVOBJ_MTHD (dev, 0x0060, 0x0190, nv04_graph_mthd_bind_nv04_patt);
  1039. NVOBJ_MTHD (dev, 0x0060, 0x0194, nv04_graph_mthd_bind_rop);
  1040. NVOBJ_MTHD (dev, 0x0060, 0x0198, nv04_graph_mthd_bind_beta1);
  1041. NVOBJ_MTHD (dev, 0x0060, 0x019c, nv04_graph_mthd_bind_beta4);
  1042. NVOBJ_MTHD (dev, 0x0060, 0x01a0, nv04_graph_mthd_bind_surf2d_swzsurf);
  1043. NVOBJ_MTHD (dev, 0x0060, 0x03e4, nv04_graph_mthd_set_operation);
  1044. /* nv05 iifc */
  1045. NVOBJ_CLASS(dev, 0x0064, GR);
  1046. /* nv01 ifc */
  1047. NVOBJ_CLASS(dev, 0x0021, GR);
  1048. NVOBJ_MTHD (dev, 0x0021, 0x0184, nv04_graph_mthd_bind_chroma);
  1049. NVOBJ_MTHD (dev, 0x0021, 0x0188, nv04_graph_mthd_bind_clip);
  1050. NVOBJ_MTHD (dev, 0x0021, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1051. NVOBJ_MTHD (dev, 0x0021, 0x0190, nv04_graph_mthd_bind_rop);
  1052. NVOBJ_MTHD (dev, 0x0021, 0x0194, nv04_graph_mthd_bind_beta1);
  1053. NVOBJ_MTHD (dev, 0x0021, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1054. NVOBJ_MTHD (dev, 0x0021, 0x02fc, nv04_graph_mthd_set_operation);
  1055. /* nv04 ifc */
  1056. NVOBJ_CLASS(dev, 0x0061, GR);
  1057. NVOBJ_MTHD (dev, 0x0061, 0x0184, nv04_graph_mthd_bind_chroma);
  1058. NVOBJ_MTHD (dev, 0x0061, 0x0188, nv04_graph_mthd_bind_clip);
  1059. NVOBJ_MTHD (dev, 0x0061, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1060. NVOBJ_MTHD (dev, 0x0061, 0x0190, nv04_graph_mthd_bind_rop);
  1061. NVOBJ_MTHD (dev, 0x0061, 0x0194, nv04_graph_mthd_bind_beta1);
  1062. NVOBJ_MTHD (dev, 0x0061, 0x0198, nv04_graph_mthd_bind_beta4);
  1063. NVOBJ_MTHD (dev, 0x0061, 0x019c, nv04_graph_mthd_bind_surf2d);
  1064. NVOBJ_MTHD (dev, 0x0061, 0x02fc, nv04_graph_mthd_set_operation);
  1065. /* nv05 ifc */
  1066. NVOBJ_CLASS(dev, 0x0065, GR);
  1067. /* nv03 sifc */
  1068. NVOBJ_CLASS(dev, 0x0036, GR);
  1069. NVOBJ_MTHD (dev, 0x0036, 0x0184, nv04_graph_mthd_bind_chroma);
  1070. NVOBJ_MTHD (dev, 0x0036, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1071. NVOBJ_MTHD (dev, 0x0036, 0x018c, nv04_graph_mthd_bind_rop);
  1072. NVOBJ_MTHD (dev, 0x0036, 0x0190, nv04_graph_mthd_bind_beta1);
  1073. NVOBJ_MTHD (dev, 0x0036, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1074. NVOBJ_MTHD (dev, 0x0036, 0x02fc, nv04_graph_mthd_set_operation);
  1075. /* nv04 sifc */
  1076. NVOBJ_CLASS(dev, 0x0076, GR);
  1077. NVOBJ_MTHD (dev, 0x0076, 0x0184, nv04_graph_mthd_bind_chroma);
  1078. NVOBJ_MTHD (dev, 0x0076, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1079. NVOBJ_MTHD (dev, 0x0076, 0x018c, nv04_graph_mthd_bind_rop);
  1080. NVOBJ_MTHD (dev, 0x0076, 0x0190, nv04_graph_mthd_bind_beta1);
  1081. NVOBJ_MTHD (dev, 0x0076, 0x0194, nv04_graph_mthd_bind_beta4);
  1082. NVOBJ_MTHD (dev, 0x0076, 0x0198, nv04_graph_mthd_bind_surf2d);
  1083. NVOBJ_MTHD (dev, 0x0076, 0x02fc, nv04_graph_mthd_set_operation);
  1084. /* nv05 sifc */
  1085. NVOBJ_CLASS(dev, 0x0066, GR);
  1086. /* nv03 sifm */
  1087. NVOBJ_CLASS(dev, 0x0037, GR);
  1088. NVOBJ_MTHD (dev, 0x0037, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1089. NVOBJ_MTHD (dev, 0x0037, 0x018c, nv04_graph_mthd_bind_rop);
  1090. NVOBJ_MTHD (dev, 0x0037, 0x0190, nv04_graph_mthd_bind_beta1);
  1091. NVOBJ_MTHD (dev, 0x0037, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1092. NVOBJ_MTHD (dev, 0x0037, 0x0304, nv04_graph_mthd_set_operation);
  1093. /* nv04 sifm */
  1094. NVOBJ_CLASS(dev, 0x0077, GR);
  1095. NVOBJ_MTHD (dev, 0x0077, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1096. NVOBJ_MTHD (dev, 0x0077, 0x018c, nv04_graph_mthd_bind_rop);
  1097. NVOBJ_MTHD (dev, 0x0077, 0x0190, nv04_graph_mthd_bind_beta1);
  1098. NVOBJ_MTHD (dev, 0x0077, 0x0194, nv04_graph_mthd_bind_beta4);
  1099. NVOBJ_MTHD (dev, 0x0077, 0x0198, nv04_graph_mthd_bind_surf2d_swzsurf);
  1100. NVOBJ_MTHD (dev, 0x0077, 0x0304, nv04_graph_mthd_set_operation);
  1101. /* null */
  1102. NVOBJ_CLASS(dev, 0x0030, GR);
  1103. /* surf2d */
  1104. NVOBJ_CLASS(dev, 0x0042, GR);
  1105. /* rop */
  1106. NVOBJ_CLASS(dev, 0x0043, GR);
  1107. /* beta1 */
  1108. NVOBJ_CLASS(dev, 0x0012, GR);
  1109. /* beta4 */
  1110. NVOBJ_CLASS(dev, 0x0072, GR);
  1111. /* cliprect */
  1112. NVOBJ_CLASS(dev, 0x0019, GR);
  1113. /* nv01 pattern */
  1114. NVOBJ_CLASS(dev, 0x0018, GR);
  1115. /* nv04 pattern */
  1116. NVOBJ_CLASS(dev, 0x0044, GR);
  1117. /* swzsurf */
  1118. NVOBJ_CLASS(dev, 0x0052, GR);
  1119. /* surf3d */
  1120. NVOBJ_CLASS(dev, 0x0053, GR);
  1121. NVOBJ_MTHD (dev, 0x0053, 0x02f8, nv04_graph_mthd_surf3d_clip_h);
  1122. NVOBJ_MTHD (dev, 0x0053, 0x02fc, nv04_graph_mthd_surf3d_clip_v);
  1123. /* nv03 tex_tri */
  1124. NVOBJ_CLASS(dev, 0x0048, GR);
  1125. NVOBJ_MTHD (dev, 0x0048, 0x0188, nv04_graph_mthd_bind_clip);
  1126. NVOBJ_MTHD (dev, 0x0048, 0x018c, nv04_graph_mthd_bind_surf_color);
  1127. NVOBJ_MTHD (dev, 0x0048, 0x0190, nv04_graph_mthd_bind_surf_zeta);
  1128. /* tex_tri */
  1129. NVOBJ_CLASS(dev, 0x0054, GR);
  1130. /* multitex_tri */
  1131. NVOBJ_CLASS(dev, 0x0055, GR);
  1132. /* nv01 chroma */
  1133. NVOBJ_CLASS(dev, 0x0017, GR);
  1134. /* nv04 chroma */
  1135. NVOBJ_CLASS(dev, 0x0057, GR);
  1136. /* surf_dst */
  1137. NVOBJ_CLASS(dev, 0x0058, GR);
  1138. /* surf_src */
  1139. NVOBJ_CLASS(dev, 0x0059, GR);
  1140. /* surf_color */
  1141. NVOBJ_CLASS(dev, 0x005a, GR);
  1142. /* surf_zeta */
  1143. NVOBJ_CLASS(dev, 0x005b, GR);
  1144. /* nv01 line */
  1145. NVOBJ_CLASS(dev, 0x001c, GR);
  1146. NVOBJ_MTHD (dev, 0x001c, 0x0184, nv04_graph_mthd_bind_clip);
  1147. NVOBJ_MTHD (dev, 0x001c, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1148. NVOBJ_MTHD (dev, 0x001c, 0x018c, nv04_graph_mthd_bind_rop);
  1149. NVOBJ_MTHD (dev, 0x001c, 0x0190, nv04_graph_mthd_bind_beta1);
  1150. NVOBJ_MTHD (dev, 0x001c, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1151. NVOBJ_MTHD (dev, 0x001c, 0x02fc, nv04_graph_mthd_set_operation);
  1152. /* nv04 line */
  1153. NVOBJ_CLASS(dev, 0x005c, GR);
  1154. NVOBJ_MTHD (dev, 0x005c, 0x0184, nv04_graph_mthd_bind_clip);
  1155. NVOBJ_MTHD (dev, 0x005c, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1156. NVOBJ_MTHD (dev, 0x005c, 0x018c, nv04_graph_mthd_bind_rop);
  1157. NVOBJ_MTHD (dev, 0x005c, 0x0190, nv04_graph_mthd_bind_beta1);
  1158. NVOBJ_MTHD (dev, 0x005c, 0x0194, nv04_graph_mthd_bind_beta4);
  1159. NVOBJ_MTHD (dev, 0x005c, 0x0198, nv04_graph_mthd_bind_surf2d);
  1160. NVOBJ_MTHD (dev, 0x005c, 0x02fc, nv04_graph_mthd_set_operation);
  1161. /* nv01 tri */
  1162. NVOBJ_CLASS(dev, 0x001d, GR);
  1163. NVOBJ_MTHD (dev, 0x001d, 0x0184, nv04_graph_mthd_bind_clip);
  1164. NVOBJ_MTHD (dev, 0x001d, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1165. NVOBJ_MTHD (dev, 0x001d, 0x018c, nv04_graph_mthd_bind_rop);
  1166. NVOBJ_MTHD (dev, 0x001d, 0x0190, nv04_graph_mthd_bind_beta1);
  1167. NVOBJ_MTHD (dev, 0x001d, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1168. NVOBJ_MTHD (dev, 0x001d, 0x02fc, nv04_graph_mthd_set_operation);
  1169. /* nv04 tri */
  1170. NVOBJ_CLASS(dev, 0x005d, GR);
  1171. NVOBJ_MTHD (dev, 0x005d, 0x0184, nv04_graph_mthd_bind_clip);
  1172. NVOBJ_MTHD (dev, 0x005d, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1173. NVOBJ_MTHD (dev, 0x005d, 0x018c, nv04_graph_mthd_bind_rop);
  1174. NVOBJ_MTHD (dev, 0x005d, 0x0190, nv04_graph_mthd_bind_beta1);
  1175. NVOBJ_MTHD (dev, 0x005d, 0x0194, nv04_graph_mthd_bind_beta4);
  1176. NVOBJ_MTHD (dev, 0x005d, 0x0198, nv04_graph_mthd_bind_surf2d);
  1177. NVOBJ_MTHD (dev, 0x005d, 0x02fc, nv04_graph_mthd_set_operation);
  1178. /* nv01 rect */
  1179. NVOBJ_CLASS(dev, 0x001e, GR);
  1180. NVOBJ_MTHD (dev, 0x001e, 0x0184, nv04_graph_mthd_bind_clip);
  1181. NVOBJ_MTHD (dev, 0x001e, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1182. NVOBJ_MTHD (dev, 0x001e, 0x018c, nv04_graph_mthd_bind_rop);
  1183. NVOBJ_MTHD (dev, 0x001e, 0x0190, nv04_graph_mthd_bind_beta1);
  1184. NVOBJ_MTHD (dev, 0x001e, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1185. NVOBJ_MTHD (dev, 0x001e, 0x02fc, nv04_graph_mthd_set_operation);
  1186. /* nv04 rect */
  1187. NVOBJ_CLASS(dev, 0x005e, GR);
  1188. NVOBJ_MTHD (dev, 0x005e, 0x0184, nv04_graph_mthd_bind_clip);
  1189. NVOBJ_MTHD (dev, 0x005e, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1190. NVOBJ_MTHD (dev, 0x005e, 0x018c, nv04_graph_mthd_bind_rop);
  1191. NVOBJ_MTHD (dev, 0x005e, 0x0190, nv04_graph_mthd_bind_beta1);
  1192. NVOBJ_MTHD (dev, 0x005e, 0x0194, nv04_graph_mthd_bind_beta4);
  1193. NVOBJ_MTHD (dev, 0x005e, 0x0198, nv04_graph_mthd_bind_surf2d);
  1194. NVOBJ_MTHD (dev, 0x005e, 0x02fc, nv04_graph_mthd_set_operation);
  1195. return 0;
  1196. }