nv04_graph.c 36 KB

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