nv10_graph.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /*
  2. * Copyright 2007 Matthieu CASTET <castet.matthieu@free.fr>
  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. #define NV10_FIFO_NUMBER 32
  29. struct pipe_state {
  30. uint32_t pipe_0x0000[0x040/4];
  31. uint32_t pipe_0x0040[0x010/4];
  32. uint32_t pipe_0x0200[0x0c0/4];
  33. uint32_t pipe_0x4400[0x080/4];
  34. uint32_t pipe_0x6400[0x3b0/4];
  35. uint32_t pipe_0x6800[0x2f0/4];
  36. uint32_t pipe_0x6c00[0x030/4];
  37. uint32_t pipe_0x7000[0x130/4];
  38. uint32_t pipe_0x7400[0x0c0/4];
  39. uint32_t pipe_0x7800[0x0c0/4];
  40. };
  41. static int nv10_graph_ctx_regs[] = {
  42. NV10_PGRAPH_CTX_SWITCH(0),
  43. NV10_PGRAPH_CTX_SWITCH(1),
  44. NV10_PGRAPH_CTX_SWITCH(2),
  45. NV10_PGRAPH_CTX_SWITCH(3),
  46. NV10_PGRAPH_CTX_SWITCH(4),
  47. NV10_PGRAPH_CTX_CACHE(0, 0),
  48. NV10_PGRAPH_CTX_CACHE(0, 1),
  49. NV10_PGRAPH_CTX_CACHE(0, 2),
  50. NV10_PGRAPH_CTX_CACHE(0, 3),
  51. NV10_PGRAPH_CTX_CACHE(0, 4),
  52. NV10_PGRAPH_CTX_CACHE(1, 0),
  53. NV10_PGRAPH_CTX_CACHE(1, 1),
  54. NV10_PGRAPH_CTX_CACHE(1, 2),
  55. NV10_PGRAPH_CTX_CACHE(1, 3),
  56. NV10_PGRAPH_CTX_CACHE(1, 4),
  57. NV10_PGRAPH_CTX_CACHE(2, 0),
  58. NV10_PGRAPH_CTX_CACHE(2, 1),
  59. NV10_PGRAPH_CTX_CACHE(2, 2),
  60. NV10_PGRAPH_CTX_CACHE(2, 3),
  61. NV10_PGRAPH_CTX_CACHE(2, 4),
  62. NV10_PGRAPH_CTX_CACHE(3, 0),
  63. NV10_PGRAPH_CTX_CACHE(3, 1),
  64. NV10_PGRAPH_CTX_CACHE(3, 2),
  65. NV10_PGRAPH_CTX_CACHE(3, 3),
  66. NV10_PGRAPH_CTX_CACHE(3, 4),
  67. NV10_PGRAPH_CTX_CACHE(4, 0),
  68. NV10_PGRAPH_CTX_CACHE(4, 1),
  69. NV10_PGRAPH_CTX_CACHE(4, 2),
  70. NV10_PGRAPH_CTX_CACHE(4, 3),
  71. NV10_PGRAPH_CTX_CACHE(4, 4),
  72. NV10_PGRAPH_CTX_CACHE(5, 0),
  73. NV10_PGRAPH_CTX_CACHE(5, 1),
  74. NV10_PGRAPH_CTX_CACHE(5, 2),
  75. NV10_PGRAPH_CTX_CACHE(5, 3),
  76. NV10_PGRAPH_CTX_CACHE(5, 4),
  77. NV10_PGRAPH_CTX_CACHE(6, 0),
  78. NV10_PGRAPH_CTX_CACHE(6, 1),
  79. NV10_PGRAPH_CTX_CACHE(6, 2),
  80. NV10_PGRAPH_CTX_CACHE(6, 3),
  81. NV10_PGRAPH_CTX_CACHE(6, 4),
  82. NV10_PGRAPH_CTX_CACHE(7, 0),
  83. NV10_PGRAPH_CTX_CACHE(7, 1),
  84. NV10_PGRAPH_CTX_CACHE(7, 2),
  85. NV10_PGRAPH_CTX_CACHE(7, 3),
  86. NV10_PGRAPH_CTX_CACHE(7, 4),
  87. NV10_PGRAPH_CTX_USER,
  88. NV04_PGRAPH_DMA_START_0,
  89. NV04_PGRAPH_DMA_START_1,
  90. NV04_PGRAPH_DMA_LENGTH,
  91. NV04_PGRAPH_DMA_MISC,
  92. NV10_PGRAPH_DMA_PITCH,
  93. NV04_PGRAPH_BOFFSET0,
  94. NV04_PGRAPH_BBASE0,
  95. NV04_PGRAPH_BLIMIT0,
  96. NV04_PGRAPH_BOFFSET1,
  97. NV04_PGRAPH_BBASE1,
  98. NV04_PGRAPH_BLIMIT1,
  99. NV04_PGRAPH_BOFFSET2,
  100. NV04_PGRAPH_BBASE2,
  101. NV04_PGRAPH_BLIMIT2,
  102. NV04_PGRAPH_BOFFSET3,
  103. NV04_PGRAPH_BBASE3,
  104. NV04_PGRAPH_BLIMIT3,
  105. NV04_PGRAPH_BOFFSET4,
  106. NV04_PGRAPH_BBASE4,
  107. NV04_PGRAPH_BLIMIT4,
  108. NV04_PGRAPH_BOFFSET5,
  109. NV04_PGRAPH_BBASE5,
  110. NV04_PGRAPH_BLIMIT5,
  111. NV04_PGRAPH_BPITCH0,
  112. NV04_PGRAPH_BPITCH1,
  113. NV04_PGRAPH_BPITCH2,
  114. NV04_PGRAPH_BPITCH3,
  115. NV04_PGRAPH_BPITCH4,
  116. NV10_PGRAPH_SURFACE,
  117. NV10_PGRAPH_STATE,
  118. NV04_PGRAPH_BSWIZZLE2,
  119. NV04_PGRAPH_BSWIZZLE5,
  120. NV04_PGRAPH_BPIXEL,
  121. NV10_PGRAPH_NOTIFY,
  122. NV04_PGRAPH_PATT_COLOR0,
  123. NV04_PGRAPH_PATT_COLOR1,
  124. NV04_PGRAPH_PATT_COLORRAM, /* 64 values from 0x400900 to 0x4009fc */
  125. 0x00400904,
  126. 0x00400908,
  127. 0x0040090c,
  128. 0x00400910,
  129. 0x00400914,
  130. 0x00400918,
  131. 0x0040091c,
  132. 0x00400920,
  133. 0x00400924,
  134. 0x00400928,
  135. 0x0040092c,
  136. 0x00400930,
  137. 0x00400934,
  138. 0x00400938,
  139. 0x0040093c,
  140. 0x00400940,
  141. 0x00400944,
  142. 0x00400948,
  143. 0x0040094c,
  144. 0x00400950,
  145. 0x00400954,
  146. 0x00400958,
  147. 0x0040095c,
  148. 0x00400960,
  149. 0x00400964,
  150. 0x00400968,
  151. 0x0040096c,
  152. 0x00400970,
  153. 0x00400974,
  154. 0x00400978,
  155. 0x0040097c,
  156. 0x00400980,
  157. 0x00400984,
  158. 0x00400988,
  159. 0x0040098c,
  160. 0x00400990,
  161. 0x00400994,
  162. 0x00400998,
  163. 0x0040099c,
  164. 0x004009a0,
  165. 0x004009a4,
  166. 0x004009a8,
  167. 0x004009ac,
  168. 0x004009b0,
  169. 0x004009b4,
  170. 0x004009b8,
  171. 0x004009bc,
  172. 0x004009c0,
  173. 0x004009c4,
  174. 0x004009c8,
  175. 0x004009cc,
  176. 0x004009d0,
  177. 0x004009d4,
  178. 0x004009d8,
  179. 0x004009dc,
  180. 0x004009e0,
  181. 0x004009e4,
  182. 0x004009e8,
  183. 0x004009ec,
  184. 0x004009f0,
  185. 0x004009f4,
  186. 0x004009f8,
  187. 0x004009fc,
  188. NV04_PGRAPH_PATTERN, /* 2 values from 0x400808 to 0x40080c */
  189. 0x0040080c,
  190. NV04_PGRAPH_PATTERN_SHAPE,
  191. NV03_PGRAPH_MONO_COLOR0,
  192. NV04_PGRAPH_ROP3,
  193. NV04_PGRAPH_CHROMA,
  194. NV04_PGRAPH_BETA_AND,
  195. NV04_PGRAPH_BETA_PREMULT,
  196. 0x00400e70,
  197. 0x00400e74,
  198. 0x00400e78,
  199. 0x00400e7c,
  200. 0x00400e80,
  201. 0x00400e84,
  202. 0x00400e88,
  203. 0x00400e8c,
  204. 0x00400ea0,
  205. 0x00400ea4,
  206. 0x00400ea8,
  207. 0x00400e90,
  208. 0x00400e94,
  209. 0x00400e98,
  210. 0x00400e9c,
  211. NV10_PGRAPH_WINDOWCLIP_HORIZONTAL, /* 8 values from 0x400f00-0x400f1c */
  212. NV10_PGRAPH_WINDOWCLIP_VERTICAL, /* 8 values from 0x400f20-0x400f3c */
  213. 0x00400f04,
  214. 0x00400f24,
  215. 0x00400f08,
  216. 0x00400f28,
  217. 0x00400f0c,
  218. 0x00400f2c,
  219. 0x00400f10,
  220. 0x00400f30,
  221. 0x00400f14,
  222. 0x00400f34,
  223. 0x00400f18,
  224. 0x00400f38,
  225. 0x00400f1c,
  226. 0x00400f3c,
  227. NV10_PGRAPH_XFMODE0,
  228. NV10_PGRAPH_XFMODE1,
  229. NV10_PGRAPH_GLOBALSTATE0,
  230. NV10_PGRAPH_GLOBALSTATE1,
  231. NV04_PGRAPH_STORED_FMT,
  232. NV04_PGRAPH_SOURCE_COLOR,
  233. NV03_PGRAPH_ABS_X_RAM, /* 32 values from 0x400400 to 0x40047c */
  234. NV03_PGRAPH_ABS_Y_RAM, /* 32 values from 0x400480 to 0x4004fc */
  235. 0x00400404,
  236. 0x00400484,
  237. 0x00400408,
  238. 0x00400488,
  239. 0x0040040c,
  240. 0x0040048c,
  241. 0x00400410,
  242. 0x00400490,
  243. 0x00400414,
  244. 0x00400494,
  245. 0x00400418,
  246. 0x00400498,
  247. 0x0040041c,
  248. 0x0040049c,
  249. 0x00400420,
  250. 0x004004a0,
  251. 0x00400424,
  252. 0x004004a4,
  253. 0x00400428,
  254. 0x004004a8,
  255. 0x0040042c,
  256. 0x004004ac,
  257. 0x00400430,
  258. 0x004004b0,
  259. 0x00400434,
  260. 0x004004b4,
  261. 0x00400438,
  262. 0x004004b8,
  263. 0x0040043c,
  264. 0x004004bc,
  265. 0x00400440,
  266. 0x004004c0,
  267. 0x00400444,
  268. 0x004004c4,
  269. 0x00400448,
  270. 0x004004c8,
  271. 0x0040044c,
  272. 0x004004cc,
  273. 0x00400450,
  274. 0x004004d0,
  275. 0x00400454,
  276. 0x004004d4,
  277. 0x00400458,
  278. 0x004004d8,
  279. 0x0040045c,
  280. 0x004004dc,
  281. 0x00400460,
  282. 0x004004e0,
  283. 0x00400464,
  284. 0x004004e4,
  285. 0x00400468,
  286. 0x004004e8,
  287. 0x0040046c,
  288. 0x004004ec,
  289. 0x00400470,
  290. 0x004004f0,
  291. 0x00400474,
  292. 0x004004f4,
  293. 0x00400478,
  294. 0x004004f8,
  295. 0x0040047c,
  296. 0x004004fc,
  297. NV03_PGRAPH_ABS_UCLIP_XMIN,
  298. NV03_PGRAPH_ABS_UCLIP_XMAX,
  299. NV03_PGRAPH_ABS_UCLIP_YMIN,
  300. NV03_PGRAPH_ABS_UCLIP_YMAX,
  301. 0x00400550,
  302. 0x00400558,
  303. 0x00400554,
  304. 0x0040055c,
  305. NV03_PGRAPH_ABS_UCLIPA_XMIN,
  306. NV03_PGRAPH_ABS_UCLIPA_XMAX,
  307. NV03_PGRAPH_ABS_UCLIPA_YMIN,
  308. NV03_PGRAPH_ABS_UCLIPA_YMAX,
  309. NV03_PGRAPH_ABS_ICLIP_XMAX,
  310. NV03_PGRAPH_ABS_ICLIP_YMAX,
  311. NV03_PGRAPH_XY_LOGIC_MISC0,
  312. NV03_PGRAPH_XY_LOGIC_MISC1,
  313. NV03_PGRAPH_XY_LOGIC_MISC2,
  314. NV03_PGRAPH_XY_LOGIC_MISC3,
  315. NV03_PGRAPH_CLIPX_0,
  316. NV03_PGRAPH_CLIPX_1,
  317. NV03_PGRAPH_CLIPY_0,
  318. NV03_PGRAPH_CLIPY_1,
  319. NV10_PGRAPH_COMBINER0_IN_ALPHA,
  320. NV10_PGRAPH_COMBINER1_IN_ALPHA,
  321. NV10_PGRAPH_COMBINER0_IN_RGB,
  322. NV10_PGRAPH_COMBINER1_IN_RGB,
  323. NV10_PGRAPH_COMBINER_COLOR0,
  324. NV10_PGRAPH_COMBINER_COLOR1,
  325. NV10_PGRAPH_COMBINER0_OUT_ALPHA,
  326. NV10_PGRAPH_COMBINER1_OUT_ALPHA,
  327. NV10_PGRAPH_COMBINER0_OUT_RGB,
  328. NV10_PGRAPH_COMBINER1_OUT_RGB,
  329. NV10_PGRAPH_COMBINER_FINAL0,
  330. NV10_PGRAPH_COMBINER_FINAL1,
  331. 0x00400e00,
  332. 0x00400e04,
  333. 0x00400e08,
  334. 0x00400e0c,
  335. 0x00400e10,
  336. 0x00400e14,
  337. 0x00400e18,
  338. 0x00400e1c,
  339. 0x00400e20,
  340. 0x00400e24,
  341. 0x00400e28,
  342. 0x00400e2c,
  343. 0x00400e30,
  344. 0x00400e34,
  345. 0x00400e38,
  346. 0x00400e3c,
  347. NV04_PGRAPH_PASSTHRU_0,
  348. NV04_PGRAPH_PASSTHRU_1,
  349. NV04_PGRAPH_PASSTHRU_2,
  350. NV10_PGRAPH_DIMX_TEXTURE,
  351. NV10_PGRAPH_WDIMX_TEXTURE,
  352. NV10_PGRAPH_DVD_COLORFMT,
  353. NV10_PGRAPH_SCALED_FORMAT,
  354. NV04_PGRAPH_MISC24_0,
  355. NV04_PGRAPH_MISC24_1,
  356. NV04_PGRAPH_MISC24_2,
  357. NV03_PGRAPH_X_MISC,
  358. NV03_PGRAPH_Y_MISC,
  359. NV04_PGRAPH_VALID1,
  360. NV04_PGRAPH_VALID2,
  361. };
  362. static int nv17_graph_ctx_regs[] = {
  363. NV10_PGRAPH_DEBUG_4,
  364. 0x004006b0,
  365. 0x00400eac,
  366. 0x00400eb0,
  367. 0x00400eb4,
  368. 0x00400eb8,
  369. 0x00400ebc,
  370. 0x00400ec0,
  371. 0x00400ec4,
  372. 0x00400ec8,
  373. 0x00400ecc,
  374. 0x00400ed0,
  375. 0x00400ed4,
  376. 0x00400ed8,
  377. 0x00400edc,
  378. 0x00400ee0,
  379. 0x00400a00,
  380. 0x00400a04,
  381. };
  382. struct graph_state {
  383. int nv10[ARRAY_SIZE(nv10_graph_ctx_regs)];
  384. int nv17[ARRAY_SIZE(nv17_graph_ctx_regs)];
  385. struct pipe_state pipe_state;
  386. uint32_t lma_window[4];
  387. };
  388. #define PIPE_SAVE(dev, state, addr) \
  389. do { \
  390. int __i; \
  391. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, addr); \
  392. for (__i = 0; __i < ARRAY_SIZE(state); __i++) \
  393. state[__i] = nv_rd32(dev, NV10_PGRAPH_PIPE_DATA); \
  394. } while (0)
  395. #define PIPE_RESTORE(dev, state, addr) \
  396. do { \
  397. int __i; \
  398. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, addr); \
  399. for (__i = 0; __i < ARRAY_SIZE(state); __i++) \
  400. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, state[__i]); \
  401. } while (0)
  402. static void nv10_graph_save_pipe(struct nouveau_channel *chan)
  403. {
  404. struct drm_device *dev = chan->dev;
  405. struct graph_state *pgraph_ctx = chan->pgraph_ctx;
  406. struct pipe_state *pipe = &pgraph_ctx->pipe_state;
  407. PIPE_SAVE(dev, pipe->pipe_0x4400, 0x4400);
  408. PIPE_SAVE(dev, pipe->pipe_0x0200, 0x0200);
  409. PIPE_SAVE(dev, pipe->pipe_0x6400, 0x6400);
  410. PIPE_SAVE(dev, pipe->pipe_0x6800, 0x6800);
  411. PIPE_SAVE(dev, pipe->pipe_0x6c00, 0x6c00);
  412. PIPE_SAVE(dev, pipe->pipe_0x7000, 0x7000);
  413. PIPE_SAVE(dev, pipe->pipe_0x7400, 0x7400);
  414. PIPE_SAVE(dev, pipe->pipe_0x7800, 0x7800);
  415. PIPE_SAVE(dev, pipe->pipe_0x0040, 0x0040);
  416. PIPE_SAVE(dev, pipe->pipe_0x0000, 0x0000);
  417. }
  418. static void nv10_graph_load_pipe(struct nouveau_channel *chan)
  419. {
  420. struct drm_device *dev = chan->dev;
  421. struct graph_state *pgraph_ctx = chan->pgraph_ctx;
  422. struct pipe_state *pipe = &pgraph_ctx->pipe_state;
  423. uint32_t xfmode0, xfmode1;
  424. int i;
  425. nouveau_wait_for_idle(dev);
  426. /* XXX check haiku comments */
  427. xfmode0 = nv_rd32(dev, NV10_PGRAPH_XFMODE0);
  428. xfmode1 = nv_rd32(dev, NV10_PGRAPH_XFMODE1);
  429. nv_wr32(dev, NV10_PGRAPH_XFMODE0, 0x10000000);
  430. nv_wr32(dev, NV10_PGRAPH_XFMODE1, 0x00000000);
  431. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x000064c0);
  432. for (i = 0; i < 4; i++)
  433. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x3f800000);
  434. for (i = 0; i < 4; i++)
  435. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000000);
  436. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00006ab0);
  437. for (i = 0; i < 3; i++)
  438. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x3f800000);
  439. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00006a80);
  440. for (i = 0; i < 3; i++)
  441. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000000);
  442. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00000040);
  443. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000008);
  444. PIPE_RESTORE(dev, pipe->pipe_0x0200, 0x0200);
  445. nouveau_wait_for_idle(dev);
  446. /* restore XFMODE */
  447. nv_wr32(dev, NV10_PGRAPH_XFMODE0, xfmode0);
  448. nv_wr32(dev, NV10_PGRAPH_XFMODE1, xfmode1);
  449. PIPE_RESTORE(dev, pipe->pipe_0x6400, 0x6400);
  450. PIPE_RESTORE(dev, pipe->pipe_0x6800, 0x6800);
  451. PIPE_RESTORE(dev, pipe->pipe_0x6c00, 0x6c00);
  452. PIPE_RESTORE(dev, pipe->pipe_0x7000, 0x7000);
  453. PIPE_RESTORE(dev, pipe->pipe_0x7400, 0x7400);
  454. PIPE_RESTORE(dev, pipe->pipe_0x7800, 0x7800);
  455. PIPE_RESTORE(dev, pipe->pipe_0x4400, 0x4400);
  456. PIPE_RESTORE(dev, pipe->pipe_0x0000, 0x0000);
  457. PIPE_RESTORE(dev, pipe->pipe_0x0040, 0x0040);
  458. nouveau_wait_for_idle(dev);
  459. }
  460. static void nv10_graph_create_pipe(struct nouveau_channel *chan)
  461. {
  462. struct drm_device *dev = chan->dev;
  463. struct graph_state *pgraph_ctx = chan->pgraph_ctx;
  464. struct pipe_state *fifo_pipe_state = &pgraph_ctx->pipe_state;
  465. uint32_t *fifo_pipe_state_addr;
  466. int i;
  467. #define PIPE_INIT(addr) \
  468. do { \
  469. fifo_pipe_state_addr = fifo_pipe_state->pipe_##addr; \
  470. } while (0)
  471. #define PIPE_INIT_END(addr) \
  472. do { \
  473. uint32_t *__end_addr = fifo_pipe_state->pipe_##addr + \
  474. ARRAY_SIZE(fifo_pipe_state->pipe_##addr); \
  475. if (fifo_pipe_state_addr != __end_addr) \
  476. NV_ERROR(dev, "incomplete pipe init for 0x%x : %p/%p\n", \
  477. addr, fifo_pipe_state_addr, __end_addr); \
  478. } while (0)
  479. #define NV_WRITE_PIPE_INIT(value) *(fifo_pipe_state_addr++) = value
  480. PIPE_INIT(0x0200);
  481. for (i = 0; i < 48; i++)
  482. NV_WRITE_PIPE_INIT(0x00000000);
  483. PIPE_INIT_END(0x0200);
  484. PIPE_INIT(0x6400);
  485. for (i = 0; i < 211; i++)
  486. NV_WRITE_PIPE_INIT(0x00000000);
  487. NV_WRITE_PIPE_INIT(0x3f800000);
  488. NV_WRITE_PIPE_INIT(0x40000000);
  489. NV_WRITE_PIPE_INIT(0x40000000);
  490. NV_WRITE_PIPE_INIT(0x40000000);
  491. NV_WRITE_PIPE_INIT(0x40000000);
  492. NV_WRITE_PIPE_INIT(0x00000000);
  493. NV_WRITE_PIPE_INIT(0x00000000);
  494. NV_WRITE_PIPE_INIT(0x3f800000);
  495. NV_WRITE_PIPE_INIT(0x00000000);
  496. NV_WRITE_PIPE_INIT(0x3f000000);
  497. NV_WRITE_PIPE_INIT(0x3f000000);
  498. NV_WRITE_PIPE_INIT(0x00000000);
  499. NV_WRITE_PIPE_INIT(0x00000000);
  500. NV_WRITE_PIPE_INIT(0x00000000);
  501. NV_WRITE_PIPE_INIT(0x00000000);
  502. NV_WRITE_PIPE_INIT(0x3f800000);
  503. NV_WRITE_PIPE_INIT(0x00000000);
  504. NV_WRITE_PIPE_INIT(0x00000000);
  505. NV_WRITE_PIPE_INIT(0x00000000);
  506. NV_WRITE_PIPE_INIT(0x00000000);
  507. NV_WRITE_PIPE_INIT(0x00000000);
  508. NV_WRITE_PIPE_INIT(0x3f800000);
  509. NV_WRITE_PIPE_INIT(0x3f800000);
  510. NV_WRITE_PIPE_INIT(0x3f800000);
  511. NV_WRITE_PIPE_INIT(0x3f800000);
  512. PIPE_INIT_END(0x6400);
  513. PIPE_INIT(0x6800);
  514. for (i = 0; i < 162; i++)
  515. NV_WRITE_PIPE_INIT(0x00000000);
  516. NV_WRITE_PIPE_INIT(0x3f800000);
  517. for (i = 0; i < 25; i++)
  518. NV_WRITE_PIPE_INIT(0x00000000);
  519. PIPE_INIT_END(0x6800);
  520. PIPE_INIT(0x6c00);
  521. NV_WRITE_PIPE_INIT(0x00000000);
  522. NV_WRITE_PIPE_INIT(0x00000000);
  523. NV_WRITE_PIPE_INIT(0x00000000);
  524. NV_WRITE_PIPE_INIT(0x00000000);
  525. NV_WRITE_PIPE_INIT(0xbf800000);
  526. NV_WRITE_PIPE_INIT(0x00000000);
  527. NV_WRITE_PIPE_INIT(0x00000000);
  528. NV_WRITE_PIPE_INIT(0x00000000);
  529. NV_WRITE_PIPE_INIT(0x00000000);
  530. NV_WRITE_PIPE_INIT(0x00000000);
  531. NV_WRITE_PIPE_INIT(0x00000000);
  532. NV_WRITE_PIPE_INIT(0x00000000);
  533. PIPE_INIT_END(0x6c00);
  534. PIPE_INIT(0x7000);
  535. NV_WRITE_PIPE_INIT(0x00000000);
  536. NV_WRITE_PIPE_INIT(0x00000000);
  537. NV_WRITE_PIPE_INIT(0x00000000);
  538. NV_WRITE_PIPE_INIT(0x00000000);
  539. NV_WRITE_PIPE_INIT(0x00000000);
  540. NV_WRITE_PIPE_INIT(0x00000000);
  541. NV_WRITE_PIPE_INIT(0x00000000);
  542. NV_WRITE_PIPE_INIT(0x00000000);
  543. NV_WRITE_PIPE_INIT(0x00000000);
  544. NV_WRITE_PIPE_INIT(0x00000000);
  545. NV_WRITE_PIPE_INIT(0x00000000);
  546. NV_WRITE_PIPE_INIT(0x00000000);
  547. NV_WRITE_PIPE_INIT(0x7149f2ca);
  548. NV_WRITE_PIPE_INIT(0x00000000);
  549. NV_WRITE_PIPE_INIT(0x00000000);
  550. NV_WRITE_PIPE_INIT(0x00000000);
  551. NV_WRITE_PIPE_INIT(0x7149f2ca);
  552. NV_WRITE_PIPE_INIT(0x00000000);
  553. NV_WRITE_PIPE_INIT(0x00000000);
  554. NV_WRITE_PIPE_INIT(0x00000000);
  555. NV_WRITE_PIPE_INIT(0x7149f2ca);
  556. NV_WRITE_PIPE_INIT(0x00000000);
  557. NV_WRITE_PIPE_INIT(0x00000000);
  558. NV_WRITE_PIPE_INIT(0x00000000);
  559. NV_WRITE_PIPE_INIT(0x7149f2ca);
  560. NV_WRITE_PIPE_INIT(0x00000000);
  561. NV_WRITE_PIPE_INIT(0x00000000);
  562. NV_WRITE_PIPE_INIT(0x00000000);
  563. NV_WRITE_PIPE_INIT(0x7149f2ca);
  564. NV_WRITE_PIPE_INIT(0x00000000);
  565. NV_WRITE_PIPE_INIT(0x00000000);
  566. NV_WRITE_PIPE_INIT(0x00000000);
  567. NV_WRITE_PIPE_INIT(0x7149f2ca);
  568. NV_WRITE_PIPE_INIT(0x00000000);
  569. NV_WRITE_PIPE_INIT(0x00000000);
  570. NV_WRITE_PIPE_INIT(0x00000000);
  571. NV_WRITE_PIPE_INIT(0x7149f2ca);
  572. NV_WRITE_PIPE_INIT(0x00000000);
  573. NV_WRITE_PIPE_INIT(0x00000000);
  574. NV_WRITE_PIPE_INIT(0x00000000);
  575. NV_WRITE_PIPE_INIT(0x7149f2ca);
  576. for (i = 0; i < 35; i++)
  577. NV_WRITE_PIPE_INIT(0x00000000);
  578. PIPE_INIT_END(0x7000);
  579. PIPE_INIT(0x7400);
  580. for (i = 0; i < 48; i++)
  581. NV_WRITE_PIPE_INIT(0x00000000);
  582. PIPE_INIT_END(0x7400);
  583. PIPE_INIT(0x7800);
  584. for (i = 0; i < 48; i++)
  585. NV_WRITE_PIPE_INIT(0x00000000);
  586. PIPE_INIT_END(0x7800);
  587. PIPE_INIT(0x4400);
  588. for (i = 0; i < 32; i++)
  589. NV_WRITE_PIPE_INIT(0x00000000);
  590. PIPE_INIT_END(0x4400);
  591. PIPE_INIT(0x0000);
  592. for (i = 0; i < 16; i++)
  593. NV_WRITE_PIPE_INIT(0x00000000);
  594. PIPE_INIT_END(0x0000);
  595. PIPE_INIT(0x0040);
  596. for (i = 0; i < 4; i++)
  597. NV_WRITE_PIPE_INIT(0x00000000);
  598. PIPE_INIT_END(0x0040);
  599. #undef PIPE_INIT
  600. #undef PIPE_INIT_END
  601. #undef NV_WRITE_PIPE_INIT
  602. }
  603. static int nv10_graph_ctx_regs_find_offset(struct drm_device *dev, int reg)
  604. {
  605. int i;
  606. for (i = 0; i < ARRAY_SIZE(nv10_graph_ctx_regs); i++) {
  607. if (nv10_graph_ctx_regs[i] == reg)
  608. return i;
  609. }
  610. NV_ERROR(dev, "unknow offset nv10_ctx_regs %d\n", reg);
  611. return -1;
  612. }
  613. static int nv17_graph_ctx_regs_find_offset(struct drm_device *dev, int reg)
  614. {
  615. int i;
  616. for (i = 0; i < ARRAY_SIZE(nv17_graph_ctx_regs); i++) {
  617. if (nv17_graph_ctx_regs[i] == reg)
  618. return i;
  619. }
  620. NV_ERROR(dev, "unknow offset nv17_ctx_regs %d\n", reg);
  621. return -1;
  622. }
  623. static void nv10_graph_load_dma_vtxbuf(struct nouveau_channel *chan,
  624. uint32_t inst)
  625. {
  626. struct drm_device *dev = chan->dev;
  627. struct drm_nouveau_private *dev_priv = dev->dev_private;
  628. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  629. uint32_t st2, st2_dl, st2_dh, fifo_ptr, fifo[0x60/4];
  630. uint32_t ctx_user, ctx_switch[5];
  631. int i, subchan = -1;
  632. /* NV10TCL_DMA_VTXBUF (method 0x18c) modifies hidden state
  633. * that cannot be restored via MMIO. Do it through the FIFO
  634. * instead.
  635. */
  636. /* Look for a celsius object */
  637. for (i = 0; i < 8; i++) {
  638. int class = nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(i, 0)) & 0xfff;
  639. if (class == 0x56 || class == 0x96 || class == 0x99) {
  640. subchan = i;
  641. break;
  642. }
  643. }
  644. if (subchan < 0 || !inst)
  645. return;
  646. /* Save the current ctx object */
  647. ctx_user = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
  648. for (i = 0; i < 5; i++)
  649. ctx_switch[i] = nv_rd32(dev, NV10_PGRAPH_CTX_SWITCH(i));
  650. /* Save the FIFO state */
  651. st2 = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2);
  652. st2_dl = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DL);
  653. st2_dh = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DH);
  654. fifo_ptr = nv_rd32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR);
  655. for (i = 0; i < ARRAY_SIZE(fifo); i++)
  656. fifo[i] = nv_rd32(dev, 0x4007a0 + 4 * i);
  657. /* Switch to the celsius subchannel */
  658. for (i = 0; i < 5; i++)
  659. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i),
  660. nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(subchan, i)));
  661. nv_mask(dev, NV10_PGRAPH_CTX_USER, 0xe000, subchan << 13);
  662. /* Inject NV10TCL_DMA_VTXBUF */
  663. nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, 0);
  664. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2,
  665. 0x2c000000 | chan->id << 20 | subchan << 16 | 0x18c);
  666. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, inst);
  667. nv_mask(dev, NV10_PGRAPH_CTX_CONTROL, 0, 0x10000);
  668. pgraph->fifo_access(dev, true);
  669. pgraph->fifo_access(dev, false);
  670. /* Restore the FIFO state */
  671. for (i = 0; i < ARRAY_SIZE(fifo); i++)
  672. nv_wr32(dev, 0x4007a0 + 4 * i, fifo[i]);
  673. nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, fifo_ptr);
  674. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2, st2);
  675. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, st2_dl);
  676. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DH, st2_dh);
  677. /* Restore the current ctx object */
  678. for (i = 0; i < 5; i++)
  679. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i), ctx_switch[i]);
  680. nv_wr32(dev, NV10_PGRAPH_CTX_USER, ctx_user);
  681. }
  682. int nv10_graph_load_context(struct nouveau_channel *chan)
  683. {
  684. struct drm_device *dev = chan->dev;
  685. struct drm_nouveau_private *dev_priv = dev->dev_private;
  686. struct graph_state *pgraph_ctx = chan->pgraph_ctx;
  687. uint32_t tmp;
  688. int i;
  689. for (i = 0; i < ARRAY_SIZE(nv10_graph_ctx_regs); i++)
  690. nv_wr32(dev, nv10_graph_ctx_regs[i], pgraph_ctx->nv10[i]);
  691. if (dev_priv->chipset >= 0x17) {
  692. for (i = 0; i < ARRAY_SIZE(nv17_graph_ctx_regs); i++)
  693. nv_wr32(dev, nv17_graph_ctx_regs[i],
  694. pgraph_ctx->nv17[i]);
  695. }
  696. nv10_graph_load_pipe(chan);
  697. nv10_graph_load_dma_vtxbuf(chan, (nv_rd32(dev, NV10_PGRAPH_GLOBALSTATE1)
  698. & 0xffff));
  699. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
  700. tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
  701. nv_wr32(dev, NV10_PGRAPH_CTX_USER, (tmp & 0xffffff) | chan->id << 24);
  702. tmp = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2);
  703. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2, tmp & 0xcfffffff);
  704. return 0;
  705. }
  706. int
  707. nv10_graph_unload_context(struct drm_device *dev)
  708. {
  709. struct drm_nouveau_private *dev_priv = dev->dev_private;
  710. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  711. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  712. struct nouveau_channel *chan;
  713. struct graph_state *ctx;
  714. uint32_t tmp;
  715. int i;
  716. chan = pgraph->channel(dev);
  717. if (!chan)
  718. return 0;
  719. ctx = chan->pgraph_ctx;
  720. for (i = 0; i < ARRAY_SIZE(nv10_graph_ctx_regs); i++)
  721. ctx->nv10[i] = nv_rd32(dev, nv10_graph_ctx_regs[i]);
  722. if (dev_priv->chipset >= 0x17) {
  723. for (i = 0; i < ARRAY_SIZE(nv17_graph_ctx_regs); i++)
  724. ctx->nv17[i] = nv_rd32(dev, nv17_graph_ctx_regs[i]);
  725. }
  726. nv10_graph_save_pipe(chan);
  727. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10000000);
  728. tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff;
  729. tmp |= (pfifo->channels - 1) << 24;
  730. nv_wr32(dev, NV10_PGRAPH_CTX_USER, tmp);
  731. return 0;
  732. }
  733. void
  734. nv10_graph_context_switch(struct drm_device *dev)
  735. {
  736. struct drm_nouveau_private *dev_priv = dev->dev_private;
  737. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  738. struct nouveau_channel *chan = NULL;
  739. int chid;
  740. pgraph->fifo_access(dev, false);
  741. nouveau_wait_for_idle(dev);
  742. /* If previous context is valid, we need to save it */
  743. nv10_graph_unload_context(dev);
  744. /* Load context for next channel */
  745. chid = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f;
  746. chan = dev_priv->fifos[chid];
  747. if (chan)
  748. nv10_graph_load_context(chan);
  749. pgraph->fifo_access(dev, true);
  750. }
  751. #define NV_WRITE_CTX(reg, val) do { \
  752. int offset = nv10_graph_ctx_regs_find_offset(dev, reg); \
  753. if (offset > 0) \
  754. pgraph_ctx->nv10[offset] = val; \
  755. } while (0)
  756. #define NV17_WRITE_CTX(reg, val) do { \
  757. int offset = nv17_graph_ctx_regs_find_offset(dev, reg); \
  758. if (offset > 0) \
  759. pgraph_ctx->nv17[offset] = val; \
  760. } while (0)
  761. struct nouveau_channel *
  762. nv10_graph_channel(struct drm_device *dev)
  763. {
  764. struct drm_nouveau_private *dev_priv = dev->dev_private;
  765. int chid = dev_priv->engine.fifo.channels;
  766. if (nv_rd32(dev, NV10_PGRAPH_CTX_CONTROL) & 0x00010000)
  767. chid = nv_rd32(dev, NV10_PGRAPH_CTX_USER) >> 24;
  768. if (chid >= dev_priv->engine.fifo.channels)
  769. return NULL;
  770. return dev_priv->fifos[chid];
  771. }
  772. int nv10_graph_create_context(struct nouveau_channel *chan)
  773. {
  774. struct drm_device *dev = chan->dev;
  775. struct drm_nouveau_private *dev_priv = dev->dev_private;
  776. struct graph_state *pgraph_ctx;
  777. NV_DEBUG(dev, "nv10_graph_context_create %d\n", chan->id);
  778. chan->pgraph_ctx = pgraph_ctx = kzalloc(sizeof(*pgraph_ctx),
  779. GFP_KERNEL);
  780. if (pgraph_ctx == NULL)
  781. return -ENOMEM;
  782. NV_WRITE_CTX(0x00400e88, 0x08000000);
  783. NV_WRITE_CTX(0x00400e9c, 0x4b7fffff);
  784. NV_WRITE_CTX(NV03_PGRAPH_XY_LOGIC_MISC0, 0x0001ffff);
  785. NV_WRITE_CTX(0x00400e10, 0x00001000);
  786. NV_WRITE_CTX(0x00400e14, 0x00001000);
  787. NV_WRITE_CTX(0x00400e30, 0x00080008);
  788. NV_WRITE_CTX(0x00400e34, 0x00080008);
  789. if (dev_priv->chipset >= 0x17) {
  790. /* is it really needed ??? */
  791. NV17_WRITE_CTX(NV10_PGRAPH_DEBUG_4,
  792. nv_rd32(dev, NV10_PGRAPH_DEBUG_4));
  793. NV17_WRITE_CTX(0x004006b0, nv_rd32(dev, 0x004006b0));
  794. NV17_WRITE_CTX(0x00400eac, 0x0fff0000);
  795. NV17_WRITE_CTX(0x00400eb0, 0x0fff0000);
  796. NV17_WRITE_CTX(0x00400ec0, 0x00000080);
  797. NV17_WRITE_CTX(0x00400ed0, 0x00000080);
  798. }
  799. NV_WRITE_CTX(NV10_PGRAPH_CTX_USER, chan->id << 24);
  800. nv10_graph_create_pipe(chan);
  801. return 0;
  802. }
  803. void nv10_graph_destroy_context(struct nouveau_channel *chan)
  804. {
  805. struct graph_state *pgraph_ctx = chan->pgraph_ctx;
  806. kfree(pgraph_ctx);
  807. chan->pgraph_ctx = NULL;
  808. }
  809. void
  810. nv10_graph_set_region_tiling(struct drm_device *dev, int i, uint32_t addr,
  811. uint32_t size, uint32_t pitch)
  812. {
  813. uint32_t limit = max(1u, addr + size) - 1;
  814. if (pitch)
  815. addr |= 1 << 31;
  816. nv_wr32(dev, NV10_PGRAPH_TLIMIT(i), limit);
  817. nv_wr32(dev, NV10_PGRAPH_TSIZE(i), pitch);
  818. nv_wr32(dev, NV10_PGRAPH_TILE(i), addr);
  819. }
  820. int nv10_graph_init(struct drm_device *dev)
  821. {
  822. struct drm_nouveau_private *dev_priv = dev->dev_private;
  823. uint32_t tmp;
  824. int i;
  825. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) &
  826. ~NV_PMC_ENABLE_PGRAPH);
  827. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  828. NV_PMC_ENABLE_PGRAPH);
  829. nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  830. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  831. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  832. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000);
  833. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x00118700);
  834. /* nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x24E00810); */ /* 0x25f92ad9 */
  835. nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x25f92ad9);
  836. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0x55DE0830 |
  837. (1<<29) |
  838. (1<<31));
  839. if (dev_priv->chipset >= 0x17) {
  840. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x1f000000);
  841. nv_wr32(dev, 0x400a10, 0x3ff3fb6);
  842. nv_wr32(dev, 0x400838, 0x2f8684);
  843. nv_wr32(dev, 0x40083c, 0x115f3f);
  844. nv_wr32(dev, 0x004006b0, 0x40000020);
  845. } else
  846. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00000000);
  847. /* Turn all the tiling regions off. */
  848. for (i = 0; i < NV10_PFB_TILE__SIZE; i++)
  849. nv10_graph_set_region_tiling(dev, i, 0, 0, 0);
  850. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(0), 0x00000000);
  851. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(1), 0x00000000);
  852. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(2), 0x00000000);
  853. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(3), 0x00000000);
  854. nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(4), 0x00000000);
  855. nv_wr32(dev, NV10_PGRAPH_STATE, 0xFFFFFFFF);
  856. tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff;
  857. tmp |= (dev_priv->engine.fifo.channels - 1) << 24;
  858. nv_wr32(dev, NV10_PGRAPH_CTX_USER, tmp);
  859. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
  860. nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2, 0x08000000);
  861. return 0;
  862. }
  863. void nv10_graph_takedown(struct drm_device *dev)
  864. {
  865. }
  866. static int
  867. nv17_graph_mthd_lma_window(struct nouveau_channel *chan, int grclass,
  868. int mthd, uint32_t data)
  869. {
  870. struct drm_device *dev = chan->dev;
  871. struct graph_state *ctx = chan->pgraph_ctx;
  872. struct pipe_state *pipe = &ctx->pipe_state;
  873. struct drm_nouveau_private *dev_priv = dev->dev_private;
  874. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  875. uint32_t pipe_0x0040[1], pipe_0x64c0[8], pipe_0x6a80[3], pipe_0x6ab0[3];
  876. uint32_t xfmode0, xfmode1;
  877. int i;
  878. ctx->lma_window[(mthd - 0x1638) / 4] = data;
  879. if (mthd != 0x1644)
  880. return 0;
  881. nouveau_wait_for_idle(dev);
  882. PIPE_SAVE(dev, pipe_0x0040, 0x0040);
  883. PIPE_SAVE(dev, pipe->pipe_0x0200, 0x0200);
  884. PIPE_RESTORE(dev, ctx->lma_window, 0x6790);
  885. nouveau_wait_for_idle(dev);
  886. xfmode0 = nv_rd32(dev, NV10_PGRAPH_XFMODE0);
  887. xfmode1 = nv_rd32(dev, NV10_PGRAPH_XFMODE1);
  888. PIPE_SAVE(dev, pipe->pipe_0x4400, 0x4400);
  889. PIPE_SAVE(dev, pipe_0x64c0, 0x64c0);
  890. PIPE_SAVE(dev, pipe_0x6ab0, 0x6ab0);
  891. PIPE_SAVE(dev, pipe_0x6a80, 0x6a80);
  892. nouveau_wait_for_idle(dev);
  893. nv_wr32(dev, NV10_PGRAPH_XFMODE0, 0x10000000);
  894. nv_wr32(dev, NV10_PGRAPH_XFMODE1, 0x00000000);
  895. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x000064c0);
  896. for (i = 0; i < 4; i++)
  897. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x3f800000);
  898. for (i = 0; i < 4; i++)
  899. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000000);
  900. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00006ab0);
  901. for (i = 0; i < 3; i++)
  902. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x3f800000);
  903. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00006a80);
  904. for (i = 0; i < 3; i++)
  905. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000000);
  906. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x00000040);
  907. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000008);
  908. PIPE_RESTORE(dev, pipe->pipe_0x0200, 0x0200);
  909. nouveau_wait_for_idle(dev);
  910. PIPE_RESTORE(dev, pipe_0x0040, 0x0040);
  911. nv_wr32(dev, NV10_PGRAPH_XFMODE0, xfmode0);
  912. nv_wr32(dev, NV10_PGRAPH_XFMODE1, xfmode1);
  913. PIPE_RESTORE(dev, pipe_0x64c0, 0x64c0);
  914. PIPE_RESTORE(dev, pipe_0x6ab0, 0x6ab0);
  915. PIPE_RESTORE(dev, pipe_0x6a80, 0x6a80);
  916. PIPE_RESTORE(dev, pipe->pipe_0x4400, 0x4400);
  917. nv_wr32(dev, NV10_PGRAPH_PIPE_ADDRESS, 0x000000c0);
  918. nv_wr32(dev, NV10_PGRAPH_PIPE_DATA, 0x00000000);
  919. nouveau_wait_for_idle(dev);
  920. pgraph->fifo_access(dev, true);
  921. return 0;
  922. }
  923. static int
  924. nv17_graph_mthd_lma_enable(struct nouveau_channel *chan, int grclass,
  925. int mthd, uint32_t data)
  926. {
  927. struct drm_device *dev = chan->dev;
  928. struct drm_nouveau_private *dev_priv = dev->dev_private;
  929. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  930. nouveau_wait_for_idle(dev);
  931. nv_wr32(dev, NV10_PGRAPH_DEBUG_4,
  932. nv_rd32(dev, NV10_PGRAPH_DEBUG_4) | 0x1 << 8);
  933. nv_wr32(dev, 0x004006b0,
  934. nv_rd32(dev, 0x004006b0) | 0x8 << 24);
  935. pgraph->fifo_access(dev, true);
  936. return 0;
  937. }
  938. static struct nouveau_pgraph_object_method nv17_graph_celsius_mthds[] = {
  939. { 0x1638, nv17_graph_mthd_lma_window },
  940. { 0x163c, nv17_graph_mthd_lma_window },
  941. { 0x1640, nv17_graph_mthd_lma_window },
  942. { 0x1644, nv17_graph_mthd_lma_window },
  943. { 0x1658, nv17_graph_mthd_lma_enable },
  944. {}
  945. };
  946. struct nouveau_pgraph_object_class nv10_graph_grclass[] = {
  947. { 0x0030, false, NULL }, /* null */
  948. { 0x0039, false, NULL }, /* m2mf */
  949. { 0x004a, false, NULL }, /* gdirect */
  950. { 0x005f, false, NULL }, /* imageblit */
  951. { 0x009f, false, NULL }, /* imageblit (nv12) */
  952. { 0x008a, false, NULL }, /* ifc */
  953. { 0x0089, false, NULL }, /* sifm */
  954. { 0x0062, false, NULL }, /* surf2d */
  955. { 0x0043, false, NULL }, /* rop */
  956. { 0x0012, false, NULL }, /* beta1 */
  957. { 0x0072, false, NULL }, /* beta4 */
  958. { 0x0019, false, NULL }, /* cliprect */
  959. { 0x0044, false, NULL }, /* pattern */
  960. { 0x0052, false, NULL }, /* swzsurf */
  961. { 0x0093, false, NULL }, /* surf3d */
  962. { 0x0094, false, NULL }, /* tex_tri */
  963. { 0x0095, false, NULL }, /* multitex_tri */
  964. { 0x0056, false, NULL }, /* celcius (nv10) */
  965. { 0x0096, false, NULL }, /* celcius (nv11) */
  966. { 0x0099, false, nv17_graph_celsius_mthds }, /* celcius (nv17) */
  967. {}
  968. };