nv10_graph.c 30 KB

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