nv_hw.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. /***************************************************************************\
  2. |* *|
  3. |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
  4. |* *|
  5. |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
  6. |* international laws. Users and possessors of this source code are *|
  7. |* hereby granted a nonexclusive, royalty-free copyright license to *|
  8. |* use this code in individual and commercial software. *|
  9. |* *|
  10. |* Any use of this source code must include, in the user documenta- *|
  11. |* tion and internal comments to the code, notices to the end user *|
  12. |* as follows: *|
  13. |* *|
  14. |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
  15. |* *|
  16. |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
  17. |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
  18. |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
  19. |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
  20. |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
  21. |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
  22. |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
  23. |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
  24. |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
  25. |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
  26. |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
  27. |* *|
  28. |* U.S. Government End Users. This source code is a "commercial *|
  29. |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
  30. |* consisting of "commercial computer software" and "commercial *|
  31. |* computer software documentation," as such terms are used in *|
  32. |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
  33. |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
  34. |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
  35. |* all U.S. Government End Users acquire the source code with only *|
  36. |* those rights set forth herein. *|
  37. |* *|
  38. \***************************************************************************/
  39. /*
  40. * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
  41. * XFree86 'nv' driver, this source code is provided under MIT-style licensing
  42. * where the source code is provided "as is" without warranty of any kind.
  43. * The only usage restriction is for the copyright notices to be retained
  44. * whenever code is used.
  45. *
  46. * Antonino Daplas <adaplas@pol.net> 2005-03-11
  47. */
  48. /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_hw.c,v 1.4 2003/11/03 05:11:25 tsi Exp $ */
  49. #include <linux/pci.h>
  50. #include "nv_type.h"
  51. #include "nv_local.h"
  52. void NVLockUnlock(struct nvidia_par *par, int Lock)
  53. {
  54. u8 cr11;
  55. VGA_WR08(par->PCIO, 0x3D4, 0x1F);
  56. VGA_WR08(par->PCIO, 0x3D5, Lock ? 0x99 : 0x57);
  57. VGA_WR08(par->PCIO, 0x3D4, 0x11);
  58. cr11 = VGA_RD08(par->PCIO, 0x3D5);
  59. if (Lock)
  60. cr11 |= 0x80;
  61. else
  62. cr11 &= ~0x80;
  63. VGA_WR08(par->PCIO, 0x3D5, cr11);
  64. }
  65. int NVShowHideCursor(struct nvidia_par *par, int ShowHide)
  66. {
  67. int cur = par->CurrentState->cursor1;
  68. par->CurrentState->cursor1 = (par->CurrentState->cursor1 & 0xFE) |
  69. (ShowHide & 0x01);
  70. VGA_WR08(par->PCIO, 0x3D4, 0x31);
  71. VGA_WR08(par->PCIO, 0x3D5, par->CurrentState->cursor1);
  72. if (par->Architecture == NV_ARCH_40)
  73. NV_WR32(par->PRAMDAC, 0x0300, NV_RD32(par->PRAMDAC, 0x0300));
  74. return (cur & 0x01);
  75. }
  76. /****************************************************************************\
  77. * *
  78. * The video arbitration routines calculate some "magic" numbers. Fixes *
  79. * the snow seen when accessing the framebuffer without it. *
  80. * It just works (I hope). *
  81. * *
  82. \****************************************************************************/
  83. typedef struct {
  84. int graphics_lwm;
  85. int video_lwm;
  86. int graphics_burst_size;
  87. int video_burst_size;
  88. int valid;
  89. } nv4_fifo_info;
  90. typedef struct {
  91. int pclk_khz;
  92. int mclk_khz;
  93. int nvclk_khz;
  94. char mem_page_miss;
  95. char mem_latency;
  96. int memory_width;
  97. char enable_video;
  98. char gr_during_vid;
  99. char pix_bpp;
  100. char mem_aligned;
  101. char enable_mp;
  102. } nv4_sim_state;
  103. typedef struct {
  104. int graphics_lwm;
  105. int video_lwm;
  106. int graphics_burst_size;
  107. int video_burst_size;
  108. int valid;
  109. } nv10_fifo_info;
  110. typedef struct {
  111. int pclk_khz;
  112. int mclk_khz;
  113. int nvclk_khz;
  114. char mem_page_miss;
  115. char mem_latency;
  116. int memory_type;
  117. int memory_width;
  118. char enable_video;
  119. char gr_during_vid;
  120. char pix_bpp;
  121. char mem_aligned;
  122. char enable_mp;
  123. } nv10_sim_state;
  124. static void nvGetClocks(struct nvidia_par *par, unsigned int *MClk,
  125. unsigned int *NVClk)
  126. {
  127. unsigned int pll, N, M, MB, NB, P;
  128. if (par->Architecture >= NV_ARCH_40) {
  129. pll = NV_RD32(par->PMC, 0x4020);
  130. P = (pll >> 16) & 0x03;
  131. pll = NV_RD32(par->PMC, 0x4024);
  132. M = pll & 0xFF;
  133. N = (pll >> 8) & 0xFF;
  134. MB = (pll >> 16) & 0xFF;
  135. NB = (pll >> 24) & 0xFF;
  136. *MClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  137. pll = NV_RD32(par->PMC, 0x4000);
  138. P = (pll >> 16) & 0x03;
  139. pll = NV_RD32(par->PMC, 0x4004);
  140. M = pll & 0xFF;
  141. N = (pll >> 8) & 0xFF;
  142. MB = (pll >> 16) & 0xFF;
  143. NB = (pll >> 24) & 0xFF;
  144. *NVClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  145. } else if (par->twoStagePLL) {
  146. pll = NV_RD32(par->PRAMDAC0, 0x0504);
  147. M = pll & 0xFF;
  148. N = (pll >> 8) & 0xFF;
  149. P = (pll >> 16) & 0x0F;
  150. pll = NV_RD32(par->PRAMDAC0, 0x0574);
  151. if (pll & 0x80000000) {
  152. MB = pll & 0xFF;
  153. NB = (pll >> 8) & 0xFF;
  154. } else {
  155. MB = 1;
  156. NB = 1;
  157. }
  158. *MClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  159. pll = NV_RD32(par->PRAMDAC0, 0x0500);
  160. M = pll & 0xFF;
  161. N = (pll >> 8) & 0xFF;
  162. P = (pll >> 16) & 0x0F;
  163. pll = NV_RD32(par->PRAMDAC0, 0x0570);
  164. if (pll & 0x80000000) {
  165. MB = pll & 0xFF;
  166. NB = (pll >> 8) & 0xFF;
  167. } else {
  168. MB = 1;
  169. NB = 1;
  170. }
  171. *NVClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  172. } else
  173. if (((par->Chipset & 0x0ff0) == 0x0300) ||
  174. ((par->Chipset & 0x0ff0) == 0x0330)) {
  175. pll = NV_RD32(par->PRAMDAC0, 0x0504);
  176. M = pll & 0x0F;
  177. N = (pll >> 8) & 0xFF;
  178. P = (pll >> 16) & 0x07;
  179. if (pll & 0x00000080) {
  180. MB = (pll >> 4) & 0x07;
  181. NB = (pll >> 19) & 0x1f;
  182. } else {
  183. MB = 1;
  184. NB = 1;
  185. }
  186. *MClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  187. pll = NV_RD32(par->PRAMDAC0, 0x0500);
  188. M = pll & 0x0F;
  189. N = (pll >> 8) & 0xFF;
  190. P = (pll >> 16) & 0x07;
  191. if (pll & 0x00000080) {
  192. MB = (pll >> 4) & 0x07;
  193. NB = (pll >> 19) & 0x1f;
  194. } else {
  195. MB = 1;
  196. NB = 1;
  197. }
  198. *NVClk = ((N * NB * par->CrystalFreqKHz) / (M * MB)) >> P;
  199. } else {
  200. pll = NV_RD32(par->PRAMDAC0, 0x0504);
  201. M = pll & 0xFF;
  202. N = (pll >> 8) & 0xFF;
  203. P = (pll >> 16) & 0x0F;
  204. *MClk = (N * par->CrystalFreqKHz / M) >> P;
  205. pll = NV_RD32(par->PRAMDAC0, 0x0500);
  206. M = pll & 0xFF;
  207. N = (pll >> 8) & 0xFF;
  208. P = (pll >> 16) & 0x0F;
  209. *NVClk = (N * par->CrystalFreqKHz / M) >> P;
  210. }
  211. }
  212. static void nv4CalcArbitration(nv4_fifo_info * fifo, nv4_sim_state * arb)
  213. {
  214. int data, pagemiss, cas, width, video_enable, bpp;
  215. int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
  216. int found, mclk_extra, mclk_loop, cbs, m1, p1;
  217. int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
  218. int us_m, us_n, us_p, video_drain_rate, crtc_drain_rate;
  219. int vpm_us, us_video, vlwm, video_fill_us, cpm_us, us_crt, clwm;
  220. fifo->valid = 1;
  221. pclk_freq = arb->pclk_khz;
  222. mclk_freq = arb->mclk_khz;
  223. nvclk_freq = arb->nvclk_khz;
  224. pagemiss = arb->mem_page_miss;
  225. cas = arb->mem_latency;
  226. width = arb->memory_width >> 6;
  227. video_enable = arb->enable_video;
  228. bpp = arb->pix_bpp;
  229. mp_enable = arb->enable_mp;
  230. clwm = 0;
  231. vlwm = 0;
  232. cbs = 128;
  233. pclks = 2;
  234. nvclks = 2;
  235. nvclks += 2;
  236. nvclks += 1;
  237. mclks = 5;
  238. mclks += 3;
  239. mclks += 1;
  240. mclks += cas;
  241. mclks += 1;
  242. mclks += 1;
  243. mclks += 1;
  244. mclks += 1;
  245. mclk_extra = 3;
  246. nvclks += 2;
  247. nvclks += 1;
  248. nvclks += 1;
  249. nvclks += 1;
  250. if (mp_enable)
  251. mclks += 4;
  252. nvclks += 0;
  253. pclks += 0;
  254. found = 0;
  255. vbs = 0;
  256. while (found != 1) {
  257. fifo->valid = 1;
  258. found = 1;
  259. mclk_loop = mclks + mclk_extra;
  260. us_m = mclk_loop * 1000 * 1000 / mclk_freq;
  261. us_n = nvclks * 1000 * 1000 / nvclk_freq;
  262. us_p = nvclks * 1000 * 1000 / pclk_freq;
  263. if (video_enable) {
  264. video_drain_rate = pclk_freq * 2;
  265. crtc_drain_rate = pclk_freq * bpp / 8;
  266. vpagemiss = 2;
  267. vpagemiss += 1;
  268. crtpagemiss = 2;
  269. vpm_us =
  270. (vpagemiss * pagemiss) * 1000 * 1000 / mclk_freq;
  271. if (nvclk_freq * 2 > mclk_freq * width)
  272. video_fill_us =
  273. cbs * 1000 * 1000 / 16 / nvclk_freq;
  274. else
  275. video_fill_us =
  276. cbs * 1000 * 1000 / (8 * width) /
  277. mclk_freq;
  278. us_video = vpm_us + us_m + us_n + us_p + video_fill_us;
  279. vlwm = us_video * video_drain_rate / (1000 * 1000);
  280. vlwm++;
  281. vbs = 128;
  282. if (vlwm > 128)
  283. vbs = 64;
  284. if (vlwm > (256 - 64))
  285. vbs = 32;
  286. if (nvclk_freq * 2 > mclk_freq * width)
  287. video_fill_us =
  288. vbs * 1000 * 1000 / 16 / nvclk_freq;
  289. else
  290. video_fill_us =
  291. vbs * 1000 * 1000 / (8 * width) /
  292. mclk_freq;
  293. cpm_us =
  294. crtpagemiss * pagemiss * 1000 * 1000 / mclk_freq;
  295. us_crt =
  296. us_video + video_fill_us + cpm_us + us_m + us_n +
  297. us_p;
  298. clwm = us_crt * crtc_drain_rate / (1000 * 1000);
  299. clwm++;
  300. } else {
  301. crtc_drain_rate = pclk_freq * bpp / 8;
  302. crtpagemiss = 2;
  303. crtpagemiss += 1;
  304. cpm_us =
  305. crtpagemiss * pagemiss * 1000 * 1000 / mclk_freq;
  306. us_crt = cpm_us + us_m + us_n + us_p;
  307. clwm = us_crt * crtc_drain_rate / (1000 * 1000);
  308. clwm++;
  309. }
  310. m1 = clwm + cbs - 512;
  311. p1 = m1 * pclk_freq / mclk_freq;
  312. p1 = p1 * bpp / 8;
  313. if ((p1 < m1) && (m1 > 0)) {
  314. fifo->valid = 0;
  315. found = 0;
  316. if (mclk_extra == 0)
  317. found = 1;
  318. mclk_extra--;
  319. } else if (video_enable) {
  320. if ((clwm > 511) || (vlwm > 255)) {
  321. fifo->valid = 0;
  322. found = 0;
  323. if (mclk_extra == 0)
  324. found = 1;
  325. mclk_extra--;
  326. }
  327. } else {
  328. if (clwm > 519) {
  329. fifo->valid = 0;
  330. found = 0;
  331. if (mclk_extra == 0)
  332. found = 1;
  333. mclk_extra--;
  334. }
  335. }
  336. if (clwm < 384)
  337. clwm = 384;
  338. if (vlwm < 128)
  339. vlwm = 128;
  340. data = (int)(clwm);
  341. fifo->graphics_lwm = data;
  342. fifo->graphics_burst_size = 128;
  343. data = (int)((vlwm + 15));
  344. fifo->video_lwm = data;
  345. fifo->video_burst_size = vbs;
  346. }
  347. }
  348. static void nv4UpdateArbitrationSettings(unsigned VClk,
  349. unsigned pixelDepth,
  350. unsigned *burst,
  351. unsigned *lwm, struct nvidia_par *par)
  352. {
  353. nv4_fifo_info fifo_data;
  354. nv4_sim_state sim_data;
  355. unsigned int MClk, NVClk, cfg1;
  356. nvGetClocks(par, &MClk, &NVClk);
  357. cfg1 = NV_RD32(par->PFB, 0x00000204);
  358. sim_data.pix_bpp = (char)pixelDepth;
  359. sim_data.enable_video = 0;
  360. sim_data.enable_mp = 0;
  361. sim_data.memory_width = (NV_RD32(par->PEXTDEV, 0x0000) & 0x10) ?
  362. 128 : 64;
  363. sim_data.mem_latency = (char)cfg1 & 0x0F;
  364. sim_data.mem_aligned = 1;
  365. sim_data.mem_page_miss =
  366. (char)(((cfg1 >> 4) & 0x0F) + ((cfg1 >> 31) & 0x01));
  367. sim_data.gr_during_vid = 0;
  368. sim_data.pclk_khz = VClk;
  369. sim_data.mclk_khz = MClk;
  370. sim_data.nvclk_khz = NVClk;
  371. nv4CalcArbitration(&fifo_data, &sim_data);
  372. if (fifo_data.valid) {
  373. int b = fifo_data.graphics_burst_size >> 4;
  374. *burst = 0;
  375. while (b >>= 1)
  376. (*burst)++;
  377. *lwm = fifo_data.graphics_lwm >> 3;
  378. }
  379. }
  380. static void nv10CalcArbitration(nv10_fifo_info * fifo, nv10_sim_state * arb)
  381. {
  382. int data, pagemiss, width, video_enable, bpp;
  383. int nvclks, mclks, pclks, vpagemiss, crtpagemiss;
  384. int nvclk_fill;
  385. int found, mclk_extra, mclk_loop, cbs, m1;
  386. int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
  387. int us_m, us_m_min, us_n, us_p, crtc_drain_rate;
  388. int vus_m;
  389. int vpm_us, us_video, cpm_us, us_crt, clwm;
  390. int clwm_rnd_down;
  391. int m2us, us_pipe_min, p1clk, p2;
  392. int min_mclk_extra;
  393. int us_min_mclk_extra;
  394. fifo->valid = 1;
  395. pclk_freq = arb->pclk_khz; /* freq in KHz */
  396. mclk_freq = arb->mclk_khz;
  397. nvclk_freq = arb->nvclk_khz;
  398. pagemiss = arb->mem_page_miss;
  399. width = arb->memory_width / 64;
  400. video_enable = arb->enable_video;
  401. bpp = arb->pix_bpp;
  402. mp_enable = arb->enable_mp;
  403. clwm = 0;
  404. cbs = 512;
  405. pclks = 4; /* lwm detect. */
  406. nvclks = 3; /* lwm -> sync. */
  407. nvclks += 2; /* fbi bus cycles (1 req + 1 busy) */
  408. /* 2 edge sync. may be very close to edge so just put one. */
  409. mclks = 1;
  410. mclks += 1; /* arb_hp_req */
  411. mclks += 5; /* ap_hp_req tiling pipeline */
  412. mclks += 2; /* tc_req latency fifo */
  413. mclks += 2; /* fb_cas_n_ memory request to fbio block */
  414. mclks += 7; /* sm_d_rdv data returned from fbio block */
  415. /* fb.rd.d.Put_gc need to accumulate 256 bits for read */
  416. if (arb->memory_type == 0)
  417. if (arb->memory_width == 64) /* 64 bit bus */
  418. mclks += 4;
  419. else
  420. mclks += 2;
  421. else if (arb->memory_width == 64) /* 64 bit bus */
  422. mclks += 2;
  423. else
  424. mclks += 1;
  425. if ((!video_enable) && (arb->memory_width == 128)) {
  426. mclk_extra = (bpp == 32) ? 31 : 42; /* Margin of error */
  427. min_mclk_extra = 17;
  428. } else {
  429. mclk_extra = (bpp == 32) ? 8 : 4; /* Margin of error */
  430. /* mclk_extra = 4; *//* Margin of error */
  431. min_mclk_extra = 18;
  432. }
  433. /* 2 edge sync. may be very close to edge so just put one. */
  434. nvclks += 1;
  435. nvclks += 1; /* fbi_d_rdv_n */
  436. nvclks += 1; /* Fbi_d_rdata */
  437. nvclks += 1; /* crtfifo load */
  438. if (mp_enable)
  439. mclks += 4; /* Mp can get in with a burst of 8. */
  440. /* Extra clocks determined by heuristics */
  441. nvclks += 0;
  442. pclks += 0;
  443. found = 0;
  444. while (found != 1) {
  445. fifo->valid = 1;
  446. found = 1;
  447. mclk_loop = mclks + mclk_extra;
  448. /* Mclk latency in us */
  449. us_m = mclk_loop * 1000 * 1000 / mclk_freq;
  450. /* Minimum Mclk latency in us */
  451. us_m_min = mclks * 1000 * 1000 / mclk_freq;
  452. us_min_mclk_extra = min_mclk_extra * 1000 * 1000 / mclk_freq;
  453. /* nvclk latency in us */
  454. us_n = nvclks * 1000 * 1000 / nvclk_freq;
  455. /* nvclk latency in us */
  456. us_p = pclks * 1000 * 1000 / pclk_freq;
  457. us_pipe_min = us_m_min + us_n + us_p;
  458. /* Mclk latency in us */
  459. vus_m = mclk_loop * 1000 * 1000 / mclk_freq;
  460. if (video_enable) {
  461. crtc_drain_rate = pclk_freq * bpp / 8; /* MB/s */
  462. vpagemiss = 1; /* self generating page miss */
  463. vpagemiss += 1; /* One higher priority before */
  464. crtpagemiss = 2; /* self generating page miss */
  465. if (mp_enable)
  466. crtpagemiss += 1; /* if MA0 conflict */
  467. vpm_us =
  468. (vpagemiss * pagemiss) * 1000 * 1000 / mclk_freq;
  469. /* Video has separate read return path */
  470. us_video = vpm_us + vus_m;
  471. cpm_us =
  472. crtpagemiss * pagemiss * 1000 * 1000 / mclk_freq;
  473. /* Wait for video */
  474. us_crt = us_video
  475. + cpm_us /* CRT Page miss */
  476. + us_m + us_n + us_p /* other latency */
  477. ;
  478. clwm = us_crt * crtc_drain_rate / (1000 * 1000);
  479. /* fixed point <= float_point - 1. Fixes that */
  480. clwm++;
  481. } else {
  482. /* bpp * pclk/8 */
  483. crtc_drain_rate = pclk_freq * bpp / 8;
  484. crtpagemiss = 1; /* self generating page miss */
  485. crtpagemiss += 1; /* MA0 page miss */
  486. if (mp_enable)
  487. crtpagemiss += 1; /* if MA0 conflict */
  488. cpm_us =
  489. crtpagemiss * pagemiss * 1000 * 1000 / mclk_freq;
  490. us_crt = cpm_us + us_m + us_n + us_p;
  491. clwm = us_crt * crtc_drain_rate / (1000 * 1000);
  492. /* fixed point <= float_point - 1. Fixes that */
  493. clwm++;
  494. /* Finally, a heuristic check when width == 64 bits */
  495. if (width == 1) {
  496. nvclk_fill = nvclk_freq * 8;
  497. if (crtc_drain_rate * 100 >= nvclk_fill * 102)
  498. /*Large number to fail */
  499. clwm = 0xfff;
  500. else if (crtc_drain_rate * 100 >=
  501. nvclk_fill * 98) {
  502. clwm = 1024;
  503. cbs = 512;
  504. }
  505. }
  506. }
  507. /*
  508. Overfill check:
  509. */
  510. clwm_rnd_down = ((int)clwm / 8) * 8;
  511. if (clwm_rnd_down < clwm)
  512. clwm += 8;
  513. m1 = clwm + cbs - 1024; /* Amount of overfill */
  514. m2us = us_pipe_min + us_min_mclk_extra;
  515. /* pclk cycles to drain */
  516. p1clk = m2us * pclk_freq / (1000 * 1000);
  517. p2 = p1clk * bpp / 8; /* bytes drained. */
  518. if ((p2 < m1) && (m1 > 0)) {
  519. fifo->valid = 0;
  520. found = 0;
  521. if (min_mclk_extra == 0) {
  522. if (cbs <= 32) {
  523. /* Can't adjust anymore! */
  524. found = 1;
  525. } else {
  526. /* reduce the burst size */
  527. cbs = cbs / 2;
  528. }
  529. } else {
  530. min_mclk_extra--;
  531. }
  532. } else {
  533. if (clwm > 1023) { /* Have some margin */
  534. fifo->valid = 0;
  535. found = 0;
  536. if (min_mclk_extra == 0)
  537. /* Can't adjust anymore! */
  538. found = 1;
  539. else
  540. min_mclk_extra--;
  541. }
  542. }
  543. if (clwm < (1024 - cbs + 8))
  544. clwm = 1024 - cbs + 8;
  545. data = (int)(clwm);
  546. /* printf("CRT LWM: %f bytes, prog: 0x%x, bs: 256\n",
  547. clwm, data ); */
  548. fifo->graphics_lwm = data;
  549. fifo->graphics_burst_size = cbs;
  550. fifo->video_lwm = 1024;
  551. fifo->video_burst_size = 512;
  552. }
  553. }
  554. static void nv10UpdateArbitrationSettings(unsigned VClk,
  555. unsigned pixelDepth,
  556. unsigned *burst,
  557. unsigned *lwm,
  558. struct nvidia_par *par)
  559. {
  560. nv10_fifo_info fifo_data;
  561. nv10_sim_state sim_data;
  562. unsigned int MClk, NVClk, cfg1;
  563. nvGetClocks(par, &MClk, &NVClk);
  564. cfg1 = NV_RD32(par->PFB, 0x0204);
  565. sim_data.pix_bpp = (char)pixelDepth;
  566. sim_data.enable_video = 1;
  567. sim_data.enable_mp = 0;
  568. sim_data.memory_type = (NV_RD32(par->PFB, 0x0200) & 0x01) ? 1 : 0;
  569. sim_data.memory_width = (NV_RD32(par->PEXTDEV, 0x0000) & 0x10) ?
  570. 128 : 64;
  571. sim_data.mem_latency = (char)cfg1 & 0x0F;
  572. sim_data.mem_aligned = 1;
  573. sim_data.mem_page_miss =
  574. (char)(((cfg1 >> 4) & 0x0F) + ((cfg1 >> 31) & 0x01));
  575. sim_data.gr_during_vid = 0;
  576. sim_data.pclk_khz = VClk;
  577. sim_data.mclk_khz = MClk;
  578. sim_data.nvclk_khz = NVClk;
  579. nv10CalcArbitration(&fifo_data, &sim_data);
  580. if (fifo_data.valid) {
  581. int b = fifo_data.graphics_burst_size >> 4;
  582. *burst = 0;
  583. while (b >>= 1)
  584. (*burst)++;
  585. *lwm = fifo_data.graphics_lwm >> 3;
  586. }
  587. }
  588. static void nv30UpdateArbitrationSettings (
  589. struct nvidia_par *par,
  590. unsigned int *burst,
  591. unsigned int *lwm
  592. )
  593. {
  594. unsigned int MClk, NVClk;
  595. unsigned int fifo_size, burst_size, graphics_lwm;
  596. fifo_size = 2048;
  597. burst_size = 512;
  598. graphics_lwm = fifo_size - burst_size;
  599. nvGetClocks(par, &MClk, &NVClk);
  600. *burst = 0;
  601. burst_size >>= 5;
  602. while(burst_size >>= 1) (*burst)++;
  603. *lwm = graphics_lwm >> 3;
  604. }
  605. static void nForceUpdateArbitrationSettings(unsigned VClk,
  606. unsigned pixelDepth,
  607. unsigned *burst,
  608. unsigned *lwm,
  609. struct nvidia_par *par)
  610. {
  611. nv10_fifo_info fifo_data;
  612. nv10_sim_state sim_data;
  613. unsigned int M, N, P, pll, MClk, NVClk, memctrl;
  614. struct pci_dev *dev;
  615. if ((par->Chipset & 0x0FF0) == 0x01A0) {
  616. unsigned int uMClkPostDiv;
  617. dev = pci_find_slot(0, 3);
  618. pci_read_config_dword(dev, 0x6C, &uMClkPostDiv);
  619. uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf;
  620. if (!uMClkPostDiv)
  621. uMClkPostDiv = 4;
  622. MClk = 400000 / uMClkPostDiv;
  623. } else {
  624. dev = pci_find_slot(0, 5);
  625. pci_read_config_dword(dev, 0x4c, &MClk);
  626. MClk /= 1000;
  627. }
  628. pll = NV_RD32(par->PRAMDAC0, 0x0500);
  629. M = (pll >> 0) & 0xFF;
  630. N = (pll >> 8) & 0xFF;
  631. P = (pll >> 16) & 0x0F;
  632. NVClk = (N * par->CrystalFreqKHz / M) >> P;
  633. sim_data.pix_bpp = (char)pixelDepth;
  634. sim_data.enable_video = 0;
  635. sim_data.enable_mp = 0;
  636. pci_find_slot(0, 1);
  637. pci_read_config_dword(dev, 0x7C, &sim_data.memory_type);
  638. sim_data.memory_type = (sim_data.memory_type >> 12) & 1;
  639. sim_data.memory_width = 64;
  640. dev = pci_find_slot(0, 3);
  641. pci_read_config_dword(dev, 0, &memctrl);
  642. memctrl >>= 16;
  643. if ((memctrl == 0x1A9) || (memctrl == 0x1AB) || (memctrl == 0x1ED)) {
  644. int dimm[3];
  645. pci_find_slot(0, 2);
  646. pci_read_config_dword(dev, 0x40, &dimm[0]);
  647. dimm[0] = (dimm[0] >> 8) & 0x4f;
  648. pci_read_config_dword(dev, 0x44, &dimm[1]);
  649. dimm[1] = (dimm[1] >> 8) & 0x4f;
  650. pci_read_config_dword(dev, 0x48, &dimm[2]);
  651. dimm[2] = (dimm[2] >> 8) & 0x4f;
  652. if ((dimm[0] + dimm[1]) != dimm[2]) {
  653. printk("nvidiafb: your nForce DIMMs are not arranged "
  654. "in optimal banks!\n");
  655. }
  656. }
  657. sim_data.mem_latency = 3;
  658. sim_data.mem_aligned = 1;
  659. sim_data.mem_page_miss = 10;
  660. sim_data.gr_during_vid = 0;
  661. sim_data.pclk_khz = VClk;
  662. sim_data.mclk_khz = MClk;
  663. sim_data.nvclk_khz = NVClk;
  664. nv10CalcArbitration(&fifo_data, &sim_data);
  665. if (fifo_data.valid) {
  666. int b = fifo_data.graphics_burst_size >> 4;
  667. *burst = 0;
  668. while (b >>= 1)
  669. (*burst)++;
  670. *lwm = fifo_data.graphics_lwm >> 3;
  671. }
  672. }
  673. /****************************************************************************\
  674. * *
  675. * RIVA Mode State Routines *
  676. * *
  677. \****************************************************************************/
  678. /*
  679. * Calculate the Video Clock parameters for the PLL.
  680. */
  681. static void CalcVClock(int clockIn,
  682. int *clockOut, u32 * pllOut, struct nvidia_par *par)
  683. {
  684. unsigned lowM, highM;
  685. unsigned DeltaNew, DeltaOld;
  686. unsigned VClk, Freq;
  687. unsigned M, N, P;
  688. DeltaOld = 0xFFFFFFFF;
  689. VClk = (unsigned)clockIn;
  690. if (par->CrystalFreqKHz == 13500) {
  691. lowM = 7;
  692. highM = 13;
  693. } else {
  694. lowM = 8;
  695. highM = 14;
  696. }
  697. for (P = 0; P <= 4; P++) {
  698. Freq = VClk << P;
  699. if ((Freq >= 128000) && (Freq <= 350000)) {
  700. for (M = lowM; M <= highM; M++) {
  701. N = ((VClk << P) * M) / par->CrystalFreqKHz;
  702. if (N <= 255) {
  703. Freq =
  704. ((par->CrystalFreqKHz * N) /
  705. M) >> P;
  706. if (Freq > VClk)
  707. DeltaNew = Freq - VClk;
  708. else
  709. DeltaNew = VClk - Freq;
  710. if (DeltaNew < DeltaOld) {
  711. *pllOut =
  712. (P << 16) | (N << 8) | M;
  713. *clockOut = Freq;
  714. DeltaOld = DeltaNew;
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. static void CalcVClock2Stage(int clockIn,
  722. int *clockOut,
  723. u32 * pllOut,
  724. u32 * pllBOut, struct nvidia_par *par)
  725. {
  726. unsigned DeltaNew, DeltaOld;
  727. unsigned VClk, Freq;
  728. unsigned M, N, P;
  729. DeltaOld = 0xFFFFFFFF;
  730. *pllBOut = 0x80000401; /* fixed at x4 for now */
  731. VClk = (unsigned)clockIn;
  732. for (P = 0; P <= 6; P++) {
  733. Freq = VClk << P;
  734. if ((Freq >= 400000) && (Freq <= 1000000)) {
  735. for (M = 1; M <= 13; M++) {
  736. N = ((VClk << P) * M) /
  737. (par->CrystalFreqKHz << 2);
  738. if ((N >= 5) && (N <= 255)) {
  739. Freq =
  740. (((par->CrystalFreqKHz << 2) * N) /
  741. M) >> P;
  742. if (Freq > VClk)
  743. DeltaNew = Freq - VClk;
  744. else
  745. DeltaNew = VClk - Freq;
  746. if (DeltaNew < DeltaOld) {
  747. *pllOut =
  748. (P << 16) | (N << 8) | M;
  749. *clockOut = Freq;
  750. DeltaOld = DeltaNew;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. }
  757. /*
  758. * Calculate extended mode parameters (SVGA) and save in a
  759. * mode state structure.
  760. */
  761. void NVCalcStateExt(struct nvidia_par *par,
  762. RIVA_HW_STATE * state,
  763. int bpp,
  764. int width,
  765. int hDisplaySize, int height, int dotClock, int flags)
  766. {
  767. int pixelDepth, VClk;
  768. /*
  769. * Save mode parameters.
  770. */
  771. state->bpp = bpp; /* this is not bitsPerPixel, it's 8,15,16,32 */
  772. state->width = width;
  773. state->height = height;
  774. /*
  775. * Extended RIVA registers.
  776. */
  777. pixelDepth = (bpp + 1) / 8;
  778. if (par->twoStagePLL)
  779. CalcVClock2Stage(dotClock, &VClk, &state->pll, &state->pllB,
  780. par);
  781. else
  782. CalcVClock(dotClock, &VClk, &state->pll, par);
  783. switch (par->Architecture) {
  784. case NV_ARCH_04:
  785. nv4UpdateArbitrationSettings(VClk,
  786. pixelDepth * 8,
  787. &(state->arbitration0),
  788. &(state->arbitration1), par);
  789. state->cursor0 = 0x00;
  790. state->cursor1 = 0xbC;
  791. if (flags & FB_VMODE_DOUBLE)
  792. state->cursor1 |= 2;
  793. state->cursor2 = 0x00000000;
  794. state->pllsel = 0x10000700;
  795. state->config = 0x00001114;
  796. state->general = bpp == 16 ? 0x00101100 : 0x00100100;
  797. state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
  798. break;
  799. case NV_ARCH_10:
  800. case NV_ARCH_20:
  801. case NV_ARCH_30:
  802. default:
  803. if (((par->Chipset & 0xffff) == 0x01A0) ||
  804. ((par->Chipset & 0xffff) == 0x01f0)) {
  805. nForceUpdateArbitrationSettings(VClk,
  806. pixelDepth * 8,
  807. &(state->arbitration0),
  808. &(state->arbitration1),
  809. par);
  810. } else if (par->Architecture < NV_ARCH_30) {
  811. nv10UpdateArbitrationSettings(VClk,
  812. pixelDepth * 8,
  813. &(state->arbitration0),
  814. &(state->arbitration1),
  815. par);
  816. } else {
  817. nv30UpdateArbitrationSettings(par,
  818. &(state->arbitration0),
  819. &(state->arbitration1));
  820. }
  821. state->cursor0 = 0x80 | (par->CursorStart >> 17);
  822. state->cursor1 = (par->CursorStart >> 11) << 2;
  823. state->cursor2 = par->CursorStart >> 24;
  824. if (flags & FB_VMODE_DOUBLE)
  825. state->cursor1 |= 2;
  826. state->pllsel = 0x10000700;
  827. state->config = NV_RD32(par->PFB, 0x00000200);
  828. state->general = bpp == 16 ? 0x00101100 : 0x00100100;
  829. state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
  830. break;
  831. }
  832. if (bpp != 8) /* DirectColor */
  833. state->general |= 0x00000030;
  834. state->repaint0 = (((width / 8) * pixelDepth) & 0x700) >> 3;
  835. state->pixel = (pixelDepth > 2) ? 3 : pixelDepth;
  836. }
  837. void NVLoadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state)
  838. {
  839. int i;
  840. NV_WR32(par->PMC, 0x0140, 0x00000000);
  841. NV_WR32(par->PMC, 0x0200, 0xFFFF00FF);
  842. NV_WR32(par->PMC, 0x0200, 0xFFFFFFFF);
  843. NV_WR32(par->PTIMER, 0x0200 * 4, 0x00000008);
  844. NV_WR32(par->PTIMER, 0x0210 * 4, 0x00000003);
  845. NV_WR32(par->PTIMER, 0x0140 * 4, 0x00000000);
  846. NV_WR32(par->PTIMER, 0x0100 * 4, 0xFFFFFFFF);
  847. if (par->Architecture == NV_ARCH_04) {
  848. NV_WR32(par->PFB, 0x0200, state->config);
  849. } else if ((par->Chipset & 0xfff0) == 0x0090) {
  850. for (i = 0; i < 15; i++) {
  851. NV_WR32(par->PFB, 0x0600 + (i * 0x10), 0);
  852. NV_WR32(par->PFB, 0x0604 + (i * 0x10), par->FbMapSize - 1);
  853. }
  854. } else {
  855. for (i = 0; i < 8; i++) {
  856. NV_WR32(par->PFB, 0x0240 + (i * 0x10), 0);
  857. NV_WR32(par->PFB, 0x0244 + (i * 0x10), par->FbMapSize - 1);
  858. }
  859. }
  860. if (par->Architecture >= NV_ARCH_40) {
  861. NV_WR32(par->PRAMIN, 0x0000 * 4, 0x80000010);
  862. NV_WR32(par->PRAMIN, 0x0001 * 4, 0x00101202);
  863. NV_WR32(par->PRAMIN, 0x0002 * 4, 0x80000011);
  864. NV_WR32(par->PRAMIN, 0x0003 * 4, 0x00101204);
  865. NV_WR32(par->PRAMIN, 0x0004 * 4, 0x80000012);
  866. NV_WR32(par->PRAMIN, 0x0005 * 4, 0x00101206);
  867. NV_WR32(par->PRAMIN, 0x0006 * 4, 0x80000013);
  868. NV_WR32(par->PRAMIN, 0x0007 * 4, 0x00101208);
  869. NV_WR32(par->PRAMIN, 0x0008 * 4, 0x80000014);
  870. NV_WR32(par->PRAMIN, 0x0009 * 4, 0x0010120A);
  871. NV_WR32(par->PRAMIN, 0x000A * 4, 0x80000015);
  872. NV_WR32(par->PRAMIN, 0x000B * 4, 0x0010120C);
  873. NV_WR32(par->PRAMIN, 0x000C * 4, 0x80000016);
  874. NV_WR32(par->PRAMIN, 0x000D * 4, 0x0010120E);
  875. NV_WR32(par->PRAMIN, 0x000E * 4, 0x80000017);
  876. NV_WR32(par->PRAMIN, 0x000F * 4, 0x00101210);
  877. NV_WR32(par->PRAMIN, 0x0800 * 4, 0x00003000);
  878. NV_WR32(par->PRAMIN, 0x0801 * 4, par->FbMapSize - 1);
  879. NV_WR32(par->PRAMIN, 0x0802 * 4, 0x00000002);
  880. NV_WR32(par->PRAMIN, 0x0808 * 4, 0x02080062);
  881. NV_WR32(par->PRAMIN, 0x0809 * 4, 0x00000000);
  882. NV_WR32(par->PRAMIN, 0x080A * 4, 0x00001200);
  883. NV_WR32(par->PRAMIN, 0x080B * 4, 0x00001200);
  884. NV_WR32(par->PRAMIN, 0x080C * 4, 0x00000000);
  885. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000000);
  886. NV_WR32(par->PRAMIN, 0x0810 * 4, 0x02080043);
  887. NV_WR32(par->PRAMIN, 0x0811 * 4, 0x00000000);
  888. NV_WR32(par->PRAMIN, 0x0812 * 4, 0x00000000);
  889. NV_WR32(par->PRAMIN, 0x0813 * 4, 0x00000000);
  890. NV_WR32(par->PRAMIN, 0x0814 * 4, 0x00000000);
  891. NV_WR32(par->PRAMIN, 0x0815 * 4, 0x00000000);
  892. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x02080044);
  893. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x02000000);
  894. NV_WR32(par->PRAMIN, 0x081A * 4, 0x00000000);
  895. NV_WR32(par->PRAMIN, 0x081B * 4, 0x00000000);
  896. NV_WR32(par->PRAMIN, 0x081C * 4, 0x00000000);
  897. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000000);
  898. NV_WR32(par->PRAMIN, 0x0820 * 4, 0x02080019);
  899. NV_WR32(par->PRAMIN, 0x0821 * 4, 0x00000000);
  900. NV_WR32(par->PRAMIN, 0x0822 * 4, 0x00000000);
  901. NV_WR32(par->PRAMIN, 0x0823 * 4, 0x00000000);
  902. NV_WR32(par->PRAMIN, 0x0824 * 4, 0x00000000);
  903. NV_WR32(par->PRAMIN, 0x0825 * 4, 0x00000000);
  904. NV_WR32(par->PRAMIN, 0x0828 * 4, 0x020A005C);
  905. NV_WR32(par->PRAMIN, 0x0829 * 4, 0x00000000);
  906. NV_WR32(par->PRAMIN, 0x082A * 4, 0x00000000);
  907. NV_WR32(par->PRAMIN, 0x082B * 4, 0x00000000);
  908. NV_WR32(par->PRAMIN, 0x082C * 4, 0x00000000);
  909. NV_WR32(par->PRAMIN, 0x082D * 4, 0x00000000);
  910. NV_WR32(par->PRAMIN, 0x0830 * 4, 0x0208009F);
  911. NV_WR32(par->PRAMIN, 0x0831 * 4, 0x00000000);
  912. NV_WR32(par->PRAMIN, 0x0832 * 4, 0x00001200);
  913. NV_WR32(par->PRAMIN, 0x0833 * 4, 0x00001200);
  914. NV_WR32(par->PRAMIN, 0x0834 * 4, 0x00000000);
  915. NV_WR32(par->PRAMIN, 0x0835 * 4, 0x00000000);
  916. NV_WR32(par->PRAMIN, 0x0838 * 4, 0x0208004A);
  917. NV_WR32(par->PRAMIN, 0x0839 * 4, 0x02000000);
  918. NV_WR32(par->PRAMIN, 0x083A * 4, 0x00000000);
  919. NV_WR32(par->PRAMIN, 0x083B * 4, 0x00000000);
  920. NV_WR32(par->PRAMIN, 0x083C * 4, 0x00000000);
  921. NV_WR32(par->PRAMIN, 0x083D * 4, 0x00000000);
  922. NV_WR32(par->PRAMIN, 0x0840 * 4, 0x02080077);
  923. NV_WR32(par->PRAMIN, 0x0841 * 4, 0x00000000);
  924. NV_WR32(par->PRAMIN, 0x0842 * 4, 0x00001200);
  925. NV_WR32(par->PRAMIN, 0x0843 * 4, 0x00001200);
  926. NV_WR32(par->PRAMIN, 0x0844 * 4, 0x00000000);
  927. NV_WR32(par->PRAMIN, 0x0845 * 4, 0x00000000);
  928. NV_WR32(par->PRAMIN, 0x084C * 4, 0x00003002);
  929. NV_WR32(par->PRAMIN, 0x084D * 4, 0x00007FFF);
  930. NV_WR32(par->PRAMIN, 0x084E * 4,
  931. par->FbUsableSize | 0x00000002);
  932. #ifdef __BIG_ENDIAN
  933. NV_WR32(par->PRAMIN, 0x080A * 4,
  934. NV_RD32(par->PRAMIN, 0x080A * 4) | 0x01000000);
  935. NV_WR32(par->PRAMIN, 0x0812 * 4,
  936. NV_RD32(par->PRAMIN, 0x0812 * 4) | 0x01000000);
  937. NV_WR32(par->PRAMIN, 0x081A * 4,
  938. NV_RD32(par->PRAMIN, 0x081A * 4) | 0x01000000);
  939. NV_WR32(par->PRAMIN, 0x0822 * 4,
  940. NV_RD32(par->PRAMIN, 0x0822 * 4) | 0x01000000);
  941. NV_WR32(par->PRAMIN, 0x082A * 4,
  942. NV_RD32(par->PRAMIN, 0x082A * 4) | 0x01000000);
  943. NV_WR32(par->PRAMIN, 0x0832 * 4,
  944. NV_RD32(par->PRAMIN, 0x0832 * 4) | 0x01000000);
  945. NV_WR32(par->PRAMIN, 0x083A * 4,
  946. NV_RD32(par->PRAMIN, 0x083A * 4) | 0x01000000);
  947. NV_WR32(par->PRAMIN, 0x0842 * 4,
  948. NV_RD32(par->PRAMIN, 0x0842 * 4) | 0x01000000);
  949. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x01000000);
  950. NV_WR32(par->PRAMIN, 0x0839 * 4, 0x01000000);
  951. #endif
  952. } else {
  953. NV_WR32(par->PRAMIN, 0x0000 * 4, 0x80000010);
  954. NV_WR32(par->PRAMIN, 0x0001 * 4, 0x80011201);
  955. NV_WR32(par->PRAMIN, 0x0002 * 4, 0x80000011);
  956. NV_WR32(par->PRAMIN, 0x0003 * 4, 0x80011202);
  957. NV_WR32(par->PRAMIN, 0x0004 * 4, 0x80000012);
  958. NV_WR32(par->PRAMIN, 0x0005 * 4, 0x80011203);
  959. NV_WR32(par->PRAMIN, 0x0006 * 4, 0x80000013);
  960. NV_WR32(par->PRAMIN, 0x0007 * 4, 0x80011204);
  961. NV_WR32(par->PRAMIN, 0x0008 * 4, 0x80000014);
  962. NV_WR32(par->PRAMIN, 0x0009 * 4, 0x80011205);
  963. NV_WR32(par->PRAMIN, 0x000A * 4, 0x80000015);
  964. NV_WR32(par->PRAMIN, 0x000B * 4, 0x80011206);
  965. NV_WR32(par->PRAMIN, 0x000C * 4, 0x80000016);
  966. NV_WR32(par->PRAMIN, 0x000D * 4, 0x80011207);
  967. NV_WR32(par->PRAMIN, 0x000E * 4, 0x80000017);
  968. NV_WR32(par->PRAMIN, 0x000F * 4, 0x80011208);
  969. NV_WR32(par->PRAMIN, 0x0800 * 4, 0x00003000);
  970. NV_WR32(par->PRAMIN, 0x0801 * 4, par->FbMapSize - 1);
  971. NV_WR32(par->PRAMIN, 0x0802 * 4, 0x00000002);
  972. NV_WR32(par->PRAMIN, 0x0803 * 4, 0x00000002);
  973. if (par->Architecture >= NV_ARCH_10)
  974. NV_WR32(par->PRAMIN, 0x0804 * 4, 0x01008062);
  975. else
  976. NV_WR32(par->PRAMIN, 0x0804 * 4, 0x01008042);
  977. NV_WR32(par->PRAMIN, 0x0805 * 4, 0x00000000);
  978. NV_WR32(par->PRAMIN, 0x0806 * 4, 0x12001200);
  979. NV_WR32(par->PRAMIN, 0x0807 * 4, 0x00000000);
  980. NV_WR32(par->PRAMIN, 0x0808 * 4, 0x01008043);
  981. NV_WR32(par->PRAMIN, 0x0809 * 4, 0x00000000);
  982. NV_WR32(par->PRAMIN, 0x080A * 4, 0x00000000);
  983. NV_WR32(par->PRAMIN, 0x080B * 4, 0x00000000);
  984. NV_WR32(par->PRAMIN, 0x080C * 4, 0x01008044);
  985. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000002);
  986. NV_WR32(par->PRAMIN, 0x080E * 4, 0x00000000);
  987. NV_WR32(par->PRAMIN, 0x080F * 4, 0x00000000);
  988. NV_WR32(par->PRAMIN, 0x0810 * 4, 0x01008019);
  989. NV_WR32(par->PRAMIN, 0x0811 * 4, 0x00000000);
  990. NV_WR32(par->PRAMIN, 0x0812 * 4, 0x00000000);
  991. NV_WR32(par->PRAMIN, 0x0813 * 4, 0x00000000);
  992. NV_WR32(par->PRAMIN, 0x0814 * 4, 0x0100A05C);
  993. NV_WR32(par->PRAMIN, 0x0815 * 4, 0x00000000);
  994. NV_WR32(par->PRAMIN, 0x0816 * 4, 0x00000000);
  995. NV_WR32(par->PRAMIN, 0x0817 * 4, 0x00000000);
  996. if (par->WaitVSyncPossible)
  997. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x0100809F);
  998. else
  999. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x0100805F);
  1000. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x00000000);
  1001. NV_WR32(par->PRAMIN, 0x081A * 4, 0x12001200);
  1002. NV_WR32(par->PRAMIN, 0x081B * 4, 0x00000000);
  1003. NV_WR32(par->PRAMIN, 0x081C * 4, 0x0100804A);
  1004. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000002);
  1005. NV_WR32(par->PRAMIN, 0x081E * 4, 0x00000000);
  1006. NV_WR32(par->PRAMIN, 0x081F * 4, 0x00000000);
  1007. NV_WR32(par->PRAMIN, 0x0820 * 4, 0x01018077);
  1008. NV_WR32(par->PRAMIN, 0x0821 * 4, 0x00000000);
  1009. NV_WR32(par->PRAMIN, 0x0822 * 4, 0x12001200);
  1010. NV_WR32(par->PRAMIN, 0x0823 * 4, 0x00000000);
  1011. NV_WR32(par->PRAMIN, 0x0824 * 4, 0x00003002);
  1012. NV_WR32(par->PRAMIN, 0x0825 * 4, 0x00007FFF);
  1013. NV_WR32(par->PRAMIN, 0x0826 * 4,
  1014. par->FbUsableSize | 0x00000002);
  1015. NV_WR32(par->PRAMIN, 0x0827 * 4, 0x00000002);
  1016. #ifdef __BIG_ENDIAN
  1017. NV_WR32(par->PRAMIN, 0x0804 * 4,
  1018. NV_RD32(par->PRAMIN, 0x0804 * 4) | 0x00080000);
  1019. NV_WR32(par->PRAMIN, 0x0808 * 4,
  1020. NV_RD32(par->PRAMIN, 0x0808 * 4) | 0x00080000);
  1021. NV_WR32(par->PRAMIN, 0x080C * 4,
  1022. NV_RD32(par->PRAMIN, 0x080C * 4) | 0x00080000);
  1023. NV_WR32(par->PRAMIN, 0x0810 * 4,
  1024. NV_RD32(par->PRAMIN, 0x0810 * 4) | 0x00080000);
  1025. NV_WR32(par->PRAMIN, 0x0814 * 4,
  1026. NV_RD32(par->PRAMIN, 0x0814 * 4) | 0x00080000);
  1027. NV_WR32(par->PRAMIN, 0x0818 * 4,
  1028. NV_RD32(par->PRAMIN, 0x0818 * 4) | 0x00080000);
  1029. NV_WR32(par->PRAMIN, 0x081C * 4,
  1030. NV_RD32(par->PRAMIN, 0x081C * 4) | 0x00080000);
  1031. NV_WR32(par->PRAMIN, 0x0820 * 4,
  1032. NV_RD32(par->PRAMIN, 0x0820 * 4) | 0x00080000);
  1033. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000001);
  1034. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000001);
  1035. #endif
  1036. }
  1037. if (par->Architecture < NV_ARCH_10) {
  1038. if ((par->Chipset & 0x0fff) == 0x0020) {
  1039. NV_WR32(par->PRAMIN, 0x0824 * 4,
  1040. NV_RD32(par->PRAMIN, 0x0824 * 4) | 0x00020000);
  1041. NV_WR32(par->PRAMIN, 0x0826 * 4,
  1042. NV_RD32(par->PRAMIN,
  1043. 0x0826 * 4) + par->FbAddress);
  1044. }
  1045. NV_WR32(par->PGRAPH, 0x0080, 0x000001FF);
  1046. NV_WR32(par->PGRAPH, 0x0080, 0x1230C000);
  1047. NV_WR32(par->PGRAPH, 0x0084, 0x72111101);
  1048. NV_WR32(par->PGRAPH, 0x0088, 0x11D5F071);
  1049. NV_WR32(par->PGRAPH, 0x008C, 0x0004FF31);
  1050. NV_WR32(par->PGRAPH, 0x008C, 0x4004FF31);
  1051. NV_WR32(par->PGRAPH, 0x0140, 0x00000000);
  1052. NV_WR32(par->PGRAPH, 0x0100, 0xFFFFFFFF);
  1053. NV_WR32(par->PGRAPH, 0x0170, 0x10010100);
  1054. NV_WR32(par->PGRAPH, 0x0710, 0xFFFFFFFF);
  1055. NV_WR32(par->PGRAPH, 0x0720, 0x00000001);
  1056. NV_WR32(par->PGRAPH, 0x0810, 0x00000000);
  1057. NV_WR32(par->PGRAPH, 0x0608, 0xFFFFFFFF);
  1058. } else {
  1059. NV_WR32(par->PGRAPH, 0x0080, 0xFFFFFFFF);
  1060. NV_WR32(par->PGRAPH, 0x0080, 0x00000000);
  1061. NV_WR32(par->PGRAPH, 0x0140, 0x00000000);
  1062. NV_WR32(par->PGRAPH, 0x0100, 0xFFFFFFFF);
  1063. NV_WR32(par->PGRAPH, 0x0144, 0x10010100);
  1064. NV_WR32(par->PGRAPH, 0x0714, 0xFFFFFFFF);
  1065. NV_WR32(par->PGRAPH, 0x0720, 0x00000001);
  1066. NV_WR32(par->PGRAPH, 0x0710,
  1067. NV_RD32(par->PGRAPH, 0x0710) & 0x0007ff00);
  1068. NV_WR32(par->PGRAPH, 0x0710,
  1069. NV_RD32(par->PGRAPH, 0x0710) | 0x00020100);
  1070. if (par->Architecture == NV_ARCH_10) {
  1071. NV_WR32(par->PGRAPH, 0x0084, 0x00118700);
  1072. NV_WR32(par->PGRAPH, 0x0088, 0x24E00810);
  1073. NV_WR32(par->PGRAPH, 0x008C, 0x55DE0030);
  1074. for (i = 0; i < 32; i++)
  1075. NV_WR32(&par->PGRAPH[(0x0B00 / 4) + i], 0,
  1076. NV_RD32(&par->PFB[(0x0240 / 4) + i],
  1077. 0));
  1078. NV_WR32(par->PGRAPH, 0x640, 0);
  1079. NV_WR32(par->PGRAPH, 0x644, 0);
  1080. NV_WR32(par->PGRAPH, 0x684, par->FbMapSize - 1);
  1081. NV_WR32(par->PGRAPH, 0x688, par->FbMapSize - 1);
  1082. NV_WR32(par->PGRAPH, 0x0810, 0x00000000);
  1083. NV_WR32(par->PGRAPH, 0x0608, 0xFFFFFFFF);
  1084. } else {
  1085. if (par->Architecture >= NV_ARCH_40) {
  1086. NV_WR32(par->PGRAPH, 0x0084, 0x401287c0);
  1087. NV_WR32(par->PGRAPH, 0x008C, 0x60de8051);
  1088. NV_WR32(par->PGRAPH, 0x0090, 0x00008000);
  1089. NV_WR32(par->PGRAPH, 0x0610, 0x00be3c5f);
  1090. if ((par->Chipset & 0xfff0) == 0x0040) {
  1091. NV_WR32(par->PGRAPH, 0x09b0,
  1092. 0x83280fff);
  1093. NV_WR32(par->PGRAPH, 0x09b4,
  1094. 0x000000a0);
  1095. } else {
  1096. NV_WR32(par->PGRAPH, 0x0820,
  1097. 0x83280eff);
  1098. NV_WR32(par->PGRAPH, 0x0824,
  1099. 0x000000a0);
  1100. }
  1101. switch (par->Chipset & 0xfff0) {
  1102. case 0x0040:
  1103. case 0x0210:
  1104. NV_WR32(par->PGRAPH, 0x09b8,
  1105. 0x0078e366);
  1106. NV_WR32(par->PGRAPH, 0x09bc,
  1107. 0x0000014c);
  1108. NV_WR32(par->PFB, 0x033C,
  1109. NV_RD32(par->PFB, 0x33C) &
  1110. 0xffff7fff);
  1111. break;
  1112. case 0x00C0:
  1113. NV_WR32(par->PGRAPH, 0x0828,
  1114. 0x007596ff);
  1115. NV_WR32(par->PGRAPH, 0x082C,
  1116. 0x00000108);
  1117. break;
  1118. case 0x0160:
  1119. case 0x01D0:
  1120. NV_WR32(par->PMC, 0x1700,
  1121. NV_RD32(par->PFB, 0x020C));
  1122. NV_WR32(par->PMC, 0x1704, 0);
  1123. NV_WR32(par->PMC, 0x1708, 0);
  1124. NV_WR32(par->PMC, 0x170C,
  1125. NV_RD32(par->PFB, 0x020C));
  1126. NV_WR32(par->PGRAPH, 0x0860, 0);
  1127. NV_WR32(par->PGRAPH, 0x0864, 0);
  1128. NV_WR32(par->PRAMDAC, 0x0608,
  1129. NV_RD32(par->PRAMDAC,
  1130. 0x0608) | 0x00100000);
  1131. break;
  1132. case 0x0140:
  1133. NV_WR32(par->PGRAPH, 0x0828,
  1134. 0x0072cb77);
  1135. NV_WR32(par->PGRAPH, 0x082C,
  1136. 0x00000108);
  1137. break;
  1138. case 0x0220:
  1139. case 0x0230:
  1140. NV_WR32(par->PGRAPH, 0x0860, 0);
  1141. NV_WR32(par->PGRAPH, 0x0864, 0);
  1142. NV_WR32(par->PRAMDAC, 0x0608,
  1143. NV_RD32(par->PRAMDAC, 0x0608) |
  1144. 0x00100000);
  1145. break;
  1146. case 0x0090:
  1147. NV_WR32(par->PRAMDAC, 0x0608,
  1148. NV_RD32(par->PRAMDAC, 0x0608) |
  1149. 0x00100000);
  1150. NV_WR32(par->PGRAPH, 0x0828,
  1151. 0x07830610);
  1152. NV_WR32(par->PGRAPH, 0x082C,
  1153. 0x0000016A);
  1154. break;
  1155. default:
  1156. break;
  1157. };
  1158. NV_WR32(par->PGRAPH, 0x0b38, 0x2ffff800);
  1159. NV_WR32(par->PGRAPH, 0x0b3c, 0x00006000);
  1160. NV_WR32(par->PGRAPH, 0x032C, 0x01000000);
  1161. NV_WR32(par->PGRAPH, 0x0220, 0x00001200);
  1162. } else if (par->Architecture == NV_ARCH_30) {
  1163. NV_WR32(par->PGRAPH, 0x0084, 0x40108700);
  1164. NV_WR32(par->PGRAPH, 0x0890, 0x00140000);
  1165. NV_WR32(par->PGRAPH, 0x008C, 0xf00e0431);
  1166. NV_WR32(par->PGRAPH, 0x0090, 0x00008000);
  1167. NV_WR32(par->PGRAPH, 0x0610, 0xf04b1f36);
  1168. NV_WR32(par->PGRAPH, 0x0B80, 0x1002d888);
  1169. NV_WR32(par->PGRAPH, 0x0B88, 0x62ff007f);
  1170. } else {
  1171. NV_WR32(par->PGRAPH, 0x0084, 0x00118700);
  1172. NV_WR32(par->PGRAPH, 0x008C, 0xF20E0431);
  1173. NV_WR32(par->PGRAPH, 0x0090, 0x00000000);
  1174. NV_WR32(par->PGRAPH, 0x009C, 0x00000040);
  1175. if ((par->Chipset & 0x0ff0) >= 0x0250) {
  1176. NV_WR32(par->PGRAPH, 0x0890,
  1177. 0x00080000);
  1178. NV_WR32(par->PGRAPH, 0x0610,
  1179. 0x304B1FB6);
  1180. NV_WR32(par->PGRAPH, 0x0B80,
  1181. 0x18B82880);
  1182. NV_WR32(par->PGRAPH, 0x0B84,
  1183. 0x44000000);
  1184. NV_WR32(par->PGRAPH, 0x0098,
  1185. 0x40000080);
  1186. NV_WR32(par->PGRAPH, 0x0B88,
  1187. 0x000000ff);
  1188. } else {
  1189. NV_WR32(par->PGRAPH, 0x0880,
  1190. 0x00080000);
  1191. NV_WR32(par->PGRAPH, 0x0094,
  1192. 0x00000005);
  1193. NV_WR32(par->PGRAPH, 0x0B80,
  1194. 0x45CAA208);
  1195. NV_WR32(par->PGRAPH, 0x0B84,
  1196. 0x24000000);
  1197. NV_WR32(par->PGRAPH, 0x0098,
  1198. 0x00000040);
  1199. NV_WR32(par->PGRAPH, 0x0750,
  1200. 0x00E00038);
  1201. NV_WR32(par->PGRAPH, 0x0754,
  1202. 0x00000030);
  1203. NV_WR32(par->PGRAPH, 0x0750,
  1204. 0x00E10038);
  1205. NV_WR32(par->PGRAPH, 0x0754,
  1206. 0x00000030);
  1207. }
  1208. }
  1209. if ((par->Chipset & 0xfff0) == 0x0090) {
  1210. for (i = 0; i < 60; i++)
  1211. NV_WR32(par->PGRAPH, 0x0D00 + i,
  1212. NV_RD32(par->PFB, 0x0600 + i));
  1213. } else {
  1214. for (i = 0; i < 32; i++)
  1215. NV_WR32(par->PGRAPH, 0x0900 + i,
  1216. NV_RD32(par->PFB, 0x0240 + i));
  1217. }
  1218. if (par->Architecture >= NV_ARCH_40) {
  1219. if ((par->Chipset & 0xfff0) == 0x0040) {
  1220. NV_WR32(par->PGRAPH, 0x09A4,
  1221. NV_RD32(par->PFB, 0x0200));
  1222. NV_WR32(par->PGRAPH, 0x09A8,
  1223. NV_RD32(par->PFB, 0x0204));
  1224. NV_WR32(par->PGRAPH, 0x69A4,
  1225. NV_RD32(par->PFB, 0x0200));
  1226. NV_WR32(par->PGRAPH, 0x69A8,
  1227. NV_RD32(par->PFB, 0x0204));
  1228. NV_WR32(par->PGRAPH, 0x0820, 0);
  1229. NV_WR32(par->PGRAPH, 0x0824, 0);
  1230. NV_WR32(par->PGRAPH, 0x0864,
  1231. par->FbMapSize - 1);
  1232. NV_WR32(par->PGRAPH, 0x0868,
  1233. par->FbMapSize - 1);
  1234. } else {
  1235. if((par->Chipset & 0xfff0) == 0x0090) {
  1236. NV_WR32(par->PGRAPH, 0x0DF0,
  1237. NV_RD32(par->PFB, 0x0200));
  1238. NV_WR32(par->PGRAPH, 0x0DF4,
  1239. NV_RD32(par->PFB, 0x0204));
  1240. } else {
  1241. NV_WR32(par->PGRAPH, 0x09F0,
  1242. NV_RD32(par->PFB, 0x0200));
  1243. NV_WR32(par->PGRAPH, 0x09F4,
  1244. NV_RD32(par->PFB, 0x0204));
  1245. }
  1246. NV_WR32(par->PGRAPH, 0x69F0,
  1247. NV_RD32(par->PFB, 0x0200));
  1248. NV_WR32(par->PGRAPH, 0x69F4,
  1249. NV_RD32(par->PFB, 0x0204));
  1250. NV_WR32(par->PGRAPH, 0x0840, 0);
  1251. NV_WR32(par->PGRAPH, 0x0844, 0);
  1252. NV_WR32(par->PGRAPH, 0x08a0,
  1253. par->FbMapSize - 1);
  1254. NV_WR32(par->PGRAPH, 0x08a4,
  1255. par->FbMapSize - 1);
  1256. }
  1257. } else {
  1258. NV_WR32(par->PGRAPH, 0x09A4,
  1259. NV_RD32(par->PFB, 0x0200));
  1260. NV_WR32(par->PGRAPH, 0x09A8,
  1261. NV_RD32(par->PFB, 0x0204));
  1262. NV_WR32(par->PGRAPH, 0x0750, 0x00EA0000);
  1263. NV_WR32(par->PGRAPH, 0x0754,
  1264. NV_RD32(par->PFB, 0x0200));
  1265. NV_WR32(par->PGRAPH, 0x0750, 0x00EA0004);
  1266. NV_WR32(par->PGRAPH, 0x0754,
  1267. NV_RD32(par->PFB, 0x0204));
  1268. NV_WR32(par->PGRAPH, 0x0820, 0);
  1269. NV_WR32(par->PGRAPH, 0x0824, 0);
  1270. NV_WR32(par->PGRAPH, 0x0864,
  1271. par->FbMapSize - 1);
  1272. NV_WR32(par->PGRAPH, 0x0868,
  1273. par->FbMapSize - 1);
  1274. }
  1275. NV_WR32(par->PGRAPH, 0x0B20, 0x00000000);
  1276. NV_WR32(par->PGRAPH, 0x0B04, 0xFFFFFFFF);
  1277. }
  1278. }
  1279. NV_WR32(par->PGRAPH, 0x053C, 0);
  1280. NV_WR32(par->PGRAPH, 0x0540, 0);
  1281. NV_WR32(par->PGRAPH, 0x0544, 0x00007FFF);
  1282. NV_WR32(par->PGRAPH, 0x0548, 0x00007FFF);
  1283. NV_WR32(par->PFIFO, 0x0140 * 4, 0x00000000);
  1284. NV_WR32(par->PFIFO, 0x0141 * 4, 0x00000001);
  1285. NV_WR32(par->PFIFO, 0x0480 * 4, 0x00000000);
  1286. NV_WR32(par->PFIFO, 0x0494 * 4, 0x00000000);
  1287. if (par->Architecture >= NV_ARCH_40)
  1288. NV_WR32(par->PFIFO, 0x0481 * 4, 0x00010000);
  1289. else
  1290. NV_WR32(par->PFIFO, 0x0481 * 4, 0x00000100);
  1291. NV_WR32(par->PFIFO, 0x0490 * 4, 0x00000000);
  1292. NV_WR32(par->PFIFO, 0x0491 * 4, 0x00000000);
  1293. if (par->Architecture >= NV_ARCH_40)
  1294. NV_WR32(par->PFIFO, 0x048B * 4, 0x00001213);
  1295. else
  1296. NV_WR32(par->PFIFO, 0x048B * 4, 0x00001209);
  1297. NV_WR32(par->PFIFO, 0x0400 * 4, 0x00000000);
  1298. NV_WR32(par->PFIFO, 0x0414 * 4, 0x00000000);
  1299. NV_WR32(par->PFIFO, 0x0084 * 4, 0x03000100);
  1300. NV_WR32(par->PFIFO, 0x0085 * 4, 0x00000110);
  1301. NV_WR32(par->PFIFO, 0x0086 * 4, 0x00000112);
  1302. NV_WR32(par->PFIFO, 0x0143 * 4, 0x0000FFFF);
  1303. NV_WR32(par->PFIFO, 0x0496 * 4, 0x0000FFFF);
  1304. NV_WR32(par->PFIFO, 0x0050 * 4, 0x00000000);
  1305. NV_WR32(par->PFIFO, 0x0040 * 4, 0xFFFFFFFF);
  1306. NV_WR32(par->PFIFO, 0x0415 * 4, 0x00000001);
  1307. NV_WR32(par->PFIFO, 0x048C * 4, 0x00000000);
  1308. NV_WR32(par->PFIFO, 0x04A0 * 4, 0x00000000);
  1309. #ifdef __BIG_ENDIAN
  1310. NV_WR32(par->PFIFO, 0x0489 * 4, 0x800F0078);
  1311. #else
  1312. NV_WR32(par->PFIFO, 0x0489 * 4, 0x000F0078);
  1313. #endif
  1314. NV_WR32(par->PFIFO, 0x0488 * 4, 0x00000001);
  1315. NV_WR32(par->PFIFO, 0x0480 * 4, 0x00000001);
  1316. NV_WR32(par->PFIFO, 0x0494 * 4, 0x00000001);
  1317. NV_WR32(par->PFIFO, 0x0495 * 4, 0x00000001);
  1318. NV_WR32(par->PFIFO, 0x0140 * 4, 0x00000001);
  1319. if (par->Architecture >= NV_ARCH_10) {
  1320. if (par->twoHeads) {
  1321. NV_WR32(par->PCRTC0, 0x0860, state->head);
  1322. NV_WR32(par->PCRTC0, 0x2860, state->head2);
  1323. }
  1324. NV_WR32(par->PRAMDAC, 0x0404, NV_RD32(par->PRAMDAC, 0x0404) |
  1325. (1 << 25));
  1326. NV_WR32(par->PMC, 0x8704, 1);
  1327. NV_WR32(par->PMC, 0x8140, 0);
  1328. NV_WR32(par->PMC, 0x8920, 0);
  1329. NV_WR32(par->PMC, 0x8924, 0);
  1330. NV_WR32(par->PMC, 0x8908, par->FbMapSize - 1);
  1331. NV_WR32(par->PMC, 0x890C, par->FbMapSize - 1);
  1332. NV_WR32(par->PMC, 0x1588, 0);
  1333. NV_WR32(par->PCRTC, 0x0810, state->cursorConfig);
  1334. NV_WR32(par->PCRTC, 0x0830, state->displayV - 3);
  1335. NV_WR32(par->PCRTC, 0x0834, state->displayV - 1);
  1336. if (par->FlatPanel) {
  1337. if ((par->Chipset & 0x0ff0) == 0x0110) {
  1338. NV_WR32(par->PRAMDAC, 0x0528, state->dither);
  1339. } else if (par->twoHeads) {
  1340. NV_WR32(par->PRAMDAC, 0x083C, state->dither);
  1341. }
  1342. VGA_WR08(par->PCIO, 0x03D4, 0x53);
  1343. VGA_WR08(par->PCIO, 0x03D5, state->timingH);
  1344. VGA_WR08(par->PCIO, 0x03D4, 0x54);
  1345. VGA_WR08(par->PCIO, 0x03D5, state->timingV);
  1346. VGA_WR08(par->PCIO, 0x03D4, 0x21);
  1347. VGA_WR08(par->PCIO, 0x03D5, 0xfa);
  1348. }
  1349. VGA_WR08(par->PCIO, 0x03D4, 0x41);
  1350. VGA_WR08(par->PCIO, 0x03D5, state->extra);
  1351. }
  1352. VGA_WR08(par->PCIO, 0x03D4, 0x19);
  1353. VGA_WR08(par->PCIO, 0x03D5, state->repaint0);
  1354. VGA_WR08(par->PCIO, 0x03D4, 0x1A);
  1355. VGA_WR08(par->PCIO, 0x03D5, state->repaint1);
  1356. VGA_WR08(par->PCIO, 0x03D4, 0x25);
  1357. VGA_WR08(par->PCIO, 0x03D5, state->screen);
  1358. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  1359. VGA_WR08(par->PCIO, 0x03D5, state->pixel);
  1360. VGA_WR08(par->PCIO, 0x03D4, 0x2D);
  1361. VGA_WR08(par->PCIO, 0x03D5, state->horiz);
  1362. VGA_WR08(par->PCIO, 0x03D4, 0x1C);
  1363. VGA_WR08(par->PCIO, 0x03D5, state->fifo);
  1364. VGA_WR08(par->PCIO, 0x03D4, 0x1B);
  1365. VGA_WR08(par->PCIO, 0x03D5, state->arbitration0);
  1366. VGA_WR08(par->PCIO, 0x03D4, 0x20);
  1367. VGA_WR08(par->PCIO, 0x03D5, state->arbitration1);
  1368. if(par->Architecture >= NV_ARCH_30) {
  1369. VGA_WR08(par->PCIO, 0x03D4, 0x47);
  1370. VGA_WR08(par->PCIO, 0x03D5, state->arbitration1 >> 8);
  1371. }
  1372. VGA_WR08(par->PCIO, 0x03D4, 0x30);
  1373. VGA_WR08(par->PCIO, 0x03D5, state->cursor0);
  1374. VGA_WR08(par->PCIO, 0x03D4, 0x31);
  1375. VGA_WR08(par->PCIO, 0x03D5, state->cursor1);
  1376. VGA_WR08(par->PCIO, 0x03D4, 0x2F);
  1377. VGA_WR08(par->PCIO, 0x03D5, state->cursor2);
  1378. VGA_WR08(par->PCIO, 0x03D4, 0x39);
  1379. VGA_WR08(par->PCIO, 0x03D5, state->interlace);
  1380. if (!par->FlatPanel) {
  1381. NV_WR32(par->PRAMDAC0, 0x050C, state->pllsel);
  1382. NV_WR32(par->PRAMDAC0, 0x0508, state->vpll);
  1383. if (par->twoHeads)
  1384. NV_WR32(par->PRAMDAC0, 0x0520, state->vpll2);
  1385. if (par->twoStagePLL) {
  1386. NV_WR32(par->PRAMDAC0, 0x0578, state->vpllB);
  1387. NV_WR32(par->PRAMDAC0, 0x057C, state->vpll2B);
  1388. }
  1389. } else {
  1390. NV_WR32(par->PRAMDAC, 0x0848, state->scale);
  1391. NV_WR32(par->PRAMDAC, 0x0828, state->crtcSync +
  1392. par->PanelTweak);
  1393. }
  1394. NV_WR32(par->PRAMDAC, 0x0600, state->general);
  1395. NV_WR32(par->PCRTC, 0x0140, 0);
  1396. NV_WR32(par->PCRTC, 0x0100, 1);
  1397. par->CurrentState = state;
  1398. }
  1399. void NVUnloadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state) {
  1400. VGA_WR08(par->PCIO, 0x03D4, 0x19);
  1401. state->repaint0 = VGA_RD08(par->PCIO, 0x03D5);
  1402. VGA_WR08(par->PCIO, 0x03D4, 0x1A);
  1403. state->repaint1 = VGA_RD08(par->PCIO, 0x03D5);
  1404. VGA_WR08(par->PCIO, 0x03D4, 0x25);
  1405. state->screen = VGA_RD08(par->PCIO, 0x03D5);
  1406. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  1407. state->pixel = VGA_RD08(par->PCIO, 0x03D5);
  1408. VGA_WR08(par->PCIO, 0x03D4, 0x2D);
  1409. state->horiz = VGA_RD08(par->PCIO, 0x03D5);
  1410. VGA_WR08(par->PCIO, 0x03D4, 0x1C);
  1411. state->fifo = VGA_RD08(par->PCIO, 0x03D5);
  1412. VGA_WR08(par->PCIO, 0x03D4, 0x1B);
  1413. state->arbitration0 = VGA_RD08(par->PCIO, 0x03D5);
  1414. VGA_WR08(par->PCIO, 0x03D4, 0x20);
  1415. state->arbitration1 = VGA_RD08(par->PCIO, 0x03D5);
  1416. if(par->Architecture >= NV_ARCH_30) {
  1417. VGA_WR08(par->PCIO, 0x03D4, 0x47);
  1418. state->arbitration1 |= (VGA_RD08(par->PCIO, 0x03D5) & 1) << 8;
  1419. }
  1420. VGA_WR08(par->PCIO, 0x03D4, 0x30);
  1421. state->cursor0 = VGA_RD08(par->PCIO, 0x03D5);
  1422. VGA_WR08(par->PCIO, 0x03D4, 0x31);
  1423. state->cursor1 = VGA_RD08(par->PCIO, 0x03D5);
  1424. VGA_WR08(par->PCIO, 0x03D4, 0x2F);
  1425. state->cursor2 = VGA_RD08(par->PCIO, 0x03D5);
  1426. VGA_WR08(par->PCIO, 0x03D4, 0x39);
  1427. state->interlace = VGA_RD08(par->PCIO, 0x03D5);
  1428. state->vpll = NV_RD32(par->PRAMDAC0, 0x0508);
  1429. if (par->twoHeads)
  1430. state->vpll2 = NV_RD32(par->PRAMDAC0, 0x0520);
  1431. if (par->twoStagePLL) {
  1432. state->vpllB = NV_RD32(par->PRAMDAC0, 0x0578);
  1433. state->vpll2B = NV_RD32(par->PRAMDAC0, 0x057C);
  1434. }
  1435. state->pllsel = NV_RD32(par->PRAMDAC0, 0x050C);
  1436. state->general = NV_RD32(par->PRAMDAC, 0x0600);
  1437. state->scale = NV_RD32(par->PRAMDAC, 0x0848);
  1438. state->config = NV_RD32(par->PFB, 0x0200);
  1439. if (par->Architecture >= NV_ARCH_10) {
  1440. if (par->twoHeads) {
  1441. state->head = NV_RD32(par->PCRTC0, 0x0860);
  1442. state->head2 = NV_RD32(par->PCRTC0, 0x2860);
  1443. VGA_WR08(par->PCIO, 0x03D4, 0x44);
  1444. state->crtcOwner = VGA_RD08(par->PCIO, 0x03D5);
  1445. }
  1446. VGA_WR08(par->PCIO, 0x03D4, 0x41);
  1447. state->extra = VGA_RD08(par->PCIO, 0x03D5);
  1448. state->cursorConfig = NV_RD32(par->PCRTC, 0x0810);
  1449. if ((par->Chipset & 0x0ff0) == 0x0110) {
  1450. state->dither = NV_RD32(par->PRAMDAC, 0x0528);
  1451. } else if (par->twoHeads) {
  1452. state->dither = NV_RD32(par->PRAMDAC, 0x083C);
  1453. }
  1454. if (par->FlatPanel) {
  1455. VGA_WR08(par->PCIO, 0x03D4, 0x53);
  1456. state->timingH = VGA_RD08(par->PCIO, 0x03D5);
  1457. VGA_WR08(par->PCIO, 0x03D4, 0x54);
  1458. state->timingV = VGA_RD08(par->PCIO, 0x03D5);
  1459. }
  1460. }
  1461. }
  1462. void NVSetStartAddress(struct nvidia_par *par, u32 start)
  1463. {
  1464. NV_WR32(par->PCRTC, 0x800, start);
  1465. }