nv_hw.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  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 = 0;
  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->Architecture < NV_ARCH_40) ||
  850. (par->Chipset & 0xfff0) == 0x0040) {
  851. for (i = 0; i < 8; i++) {
  852. NV_WR32(par->PFB, 0x0240 + (i * 0x10), 0);
  853. NV_WR32(par->PFB, 0x0244 + (i * 0x10),
  854. par->FbMapSize - 1);
  855. }
  856. } else {
  857. int regions = 12;
  858. if (((par->Chipset & 0xfff0) == 0x0090) ||
  859. ((par->Chipset & 0xfff0) == 0x01D0) ||
  860. ((par->Chipset & 0xfff0) == 0x0290))
  861. regions = 15;
  862. for(i = 0; i < regions; i++) {
  863. NV_WR32(par->PFB, 0x0600 + (i * 0x10), 0);
  864. NV_WR32(par->PFB, 0x0604 + (i * 0x10),
  865. par->FbMapSize - 1);
  866. }
  867. }
  868. if (par->Architecture >= NV_ARCH_40) {
  869. NV_WR32(par->PRAMIN, 0x0000 * 4, 0x80000010);
  870. NV_WR32(par->PRAMIN, 0x0001 * 4, 0x00101202);
  871. NV_WR32(par->PRAMIN, 0x0002 * 4, 0x80000011);
  872. NV_WR32(par->PRAMIN, 0x0003 * 4, 0x00101204);
  873. NV_WR32(par->PRAMIN, 0x0004 * 4, 0x80000012);
  874. NV_WR32(par->PRAMIN, 0x0005 * 4, 0x00101206);
  875. NV_WR32(par->PRAMIN, 0x0006 * 4, 0x80000013);
  876. NV_WR32(par->PRAMIN, 0x0007 * 4, 0x00101208);
  877. NV_WR32(par->PRAMIN, 0x0008 * 4, 0x80000014);
  878. NV_WR32(par->PRAMIN, 0x0009 * 4, 0x0010120A);
  879. NV_WR32(par->PRAMIN, 0x000A * 4, 0x80000015);
  880. NV_WR32(par->PRAMIN, 0x000B * 4, 0x0010120C);
  881. NV_WR32(par->PRAMIN, 0x000C * 4, 0x80000016);
  882. NV_WR32(par->PRAMIN, 0x000D * 4, 0x0010120E);
  883. NV_WR32(par->PRAMIN, 0x000E * 4, 0x80000017);
  884. NV_WR32(par->PRAMIN, 0x000F * 4, 0x00101210);
  885. NV_WR32(par->PRAMIN, 0x0800 * 4, 0x00003000);
  886. NV_WR32(par->PRAMIN, 0x0801 * 4, par->FbMapSize - 1);
  887. NV_WR32(par->PRAMIN, 0x0802 * 4, 0x00000002);
  888. NV_WR32(par->PRAMIN, 0x0808 * 4, 0x02080062);
  889. NV_WR32(par->PRAMIN, 0x0809 * 4, 0x00000000);
  890. NV_WR32(par->PRAMIN, 0x080A * 4, 0x00001200);
  891. NV_WR32(par->PRAMIN, 0x080B * 4, 0x00001200);
  892. NV_WR32(par->PRAMIN, 0x080C * 4, 0x00000000);
  893. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000000);
  894. NV_WR32(par->PRAMIN, 0x0810 * 4, 0x02080043);
  895. NV_WR32(par->PRAMIN, 0x0811 * 4, 0x00000000);
  896. NV_WR32(par->PRAMIN, 0x0812 * 4, 0x00000000);
  897. NV_WR32(par->PRAMIN, 0x0813 * 4, 0x00000000);
  898. NV_WR32(par->PRAMIN, 0x0814 * 4, 0x00000000);
  899. NV_WR32(par->PRAMIN, 0x0815 * 4, 0x00000000);
  900. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x02080044);
  901. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x02000000);
  902. NV_WR32(par->PRAMIN, 0x081A * 4, 0x00000000);
  903. NV_WR32(par->PRAMIN, 0x081B * 4, 0x00000000);
  904. NV_WR32(par->PRAMIN, 0x081C * 4, 0x00000000);
  905. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000000);
  906. NV_WR32(par->PRAMIN, 0x0820 * 4, 0x02080019);
  907. NV_WR32(par->PRAMIN, 0x0821 * 4, 0x00000000);
  908. NV_WR32(par->PRAMIN, 0x0822 * 4, 0x00000000);
  909. NV_WR32(par->PRAMIN, 0x0823 * 4, 0x00000000);
  910. NV_WR32(par->PRAMIN, 0x0824 * 4, 0x00000000);
  911. NV_WR32(par->PRAMIN, 0x0825 * 4, 0x00000000);
  912. NV_WR32(par->PRAMIN, 0x0828 * 4, 0x020A005C);
  913. NV_WR32(par->PRAMIN, 0x0829 * 4, 0x00000000);
  914. NV_WR32(par->PRAMIN, 0x082A * 4, 0x00000000);
  915. NV_WR32(par->PRAMIN, 0x082B * 4, 0x00000000);
  916. NV_WR32(par->PRAMIN, 0x082C * 4, 0x00000000);
  917. NV_WR32(par->PRAMIN, 0x082D * 4, 0x00000000);
  918. NV_WR32(par->PRAMIN, 0x0830 * 4, 0x0208009F);
  919. NV_WR32(par->PRAMIN, 0x0831 * 4, 0x00000000);
  920. NV_WR32(par->PRAMIN, 0x0832 * 4, 0x00001200);
  921. NV_WR32(par->PRAMIN, 0x0833 * 4, 0x00001200);
  922. NV_WR32(par->PRAMIN, 0x0834 * 4, 0x00000000);
  923. NV_WR32(par->PRAMIN, 0x0835 * 4, 0x00000000);
  924. NV_WR32(par->PRAMIN, 0x0838 * 4, 0x0208004A);
  925. NV_WR32(par->PRAMIN, 0x0839 * 4, 0x02000000);
  926. NV_WR32(par->PRAMIN, 0x083A * 4, 0x00000000);
  927. NV_WR32(par->PRAMIN, 0x083B * 4, 0x00000000);
  928. NV_WR32(par->PRAMIN, 0x083C * 4, 0x00000000);
  929. NV_WR32(par->PRAMIN, 0x083D * 4, 0x00000000);
  930. NV_WR32(par->PRAMIN, 0x0840 * 4, 0x02080077);
  931. NV_WR32(par->PRAMIN, 0x0841 * 4, 0x00000000);
  932. NV_WR32(par->PRAMIN, 0x0842 * 4, 0x00001200);
  933. NV_WR32(par->PRAMIN, 0x0843 * 4, 0x00001200);
  934. NV_WR32(par->PRAMIN, 0x0844 * 4, 0x00000000);
  935. NV_WR32(par->PRAMIN, 0x0845 * 4, 0x00000000);
  936. NV_WR32(par->PRAMIN, 0x084C * 4, 0x00003002);
  937. NV_WR32(par->PRAMIN, 0x084D * 4, 0x00007FFF);
  938. NV_WR32(par->PRAMIN, 0x084E * 4,
  939. par->FbUsableSize | 0x00000002);
  940. #ifdef __BIG_ENDIAN
  941. NV_WR32(par->PRAMIN, 0x080A * 4,
  942. NV_RD32(par->PRAMIN, 0x080A * 4) | 0x01000000);
  943. NV_WR32(par->PRAMIN, 0x0812 * 4,
  944. NV_RD32(par->PRAMIN, 0x0812 * 4) | 0x01000000);
  945. NV_WR32(par->PRAMIN, 0x081A * 4,
  946. NV_RD32(par->PRAMIN, 0x081A * 4) | 0x01000000);
  947. NV_WR32(par->PRAMIN, 0x0822 * 4,
  948. NV_RD32(par->PRAMIN, 0x0822 * 4) | 0x01000000);
  949. NV_WR32(par->PRAMIN, 0x082A * 4,
  950. NV_RD32(par->PRAMIN, 0x082A * 4) | 0x01000000);
  951. NV_WR32(par->PRAMIN, 0x0832 * 4,
  952. NV_RD32(par->PRAMIN, 0x0832 * 4) | 0x01000000);
  953. NV_WR32(par->PRAMIN, 0x083A * 4,
  954. NV_RD32(par->PRAMIN, 0x083A * 4) | 0x01000000);
  955. NV_WR32(par->PRAMIN, 0x0842 * 4,
  956. NV_RD32(par->PRAMIN, 0x0842 * 4) | 0x01000000);
  957. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x01000000);
  958. NV_WR32(par->PRAMIN, 0x0839 * 4, 0x01000000);
  959. #endif
  960. } else {
  961. NV_WR32(par->PRAMIN, 0x0000 * 4, 0x80000010);
  962. NV_WR32(par->PRAMIN, 0x0001 * 4, 0x80011201);
  963. NV_WR32(par->PRAMIN, 0x0002 * 4, 0x80000011);
  964. NV_WR32(par->PRAMIN, 0x0003 * 4, 0x80011202);
  965. NV_WR32(par->PRAMIN, 0x0004 * 4, 0x80000012);
  966. NV_WR32(par->PRAMIN, 0x0005 * 4, 0x80011203);
  967. NV_WR32(par->PRAMIN, 0x0006 * 4, 0x80000013);
  968. NV_WR32(par->PRAMIN, 0x0007 * 4, 0x80011204);
  969. NV_WR32(par->PRAMIN, 0x0008 * 4, 0x80000014);
  970. NV_WR32(par->PRAMIN, 0x0009 * 4, 0x80011205);
  971. NV_WR32(par->PRAMIN, 0x000A * 4, 0x80000015);
  972. NV_WR32(par->PRAMIN, 0x000B * 4, 0x80011206);
  973. NV_WR32(par->PRAMIN, 0x000C * 4, 0x80000016);
  974. NV_WR32(par->PRAMIN, 0x000D * 4, 0x80011207);
  975. NV_WR32(par->PRAMIN, 0x000E * 4, 0x80000017);
  976. NV_WR32(par->PRAMIN, 0x000F * 4, 0x80011208);
  977. NV_WR32(par->PRAMIN, 0x0800 * 4, 0x00003000);
  978. NV_WR32(par->PRAMIN, 0x0801 * 4, par->FbMapSize - 1);
  979. NV_WR32(par->PRAMIN, 0x0802 * 4, 0x00000002);
  980. NV_WR32(par->PRAMIN, 0x0803 * 4, 0x00000002);
  981. if (par->Architecture >= NV_ARCH_10)
  982. NV_WR32(par->PRAMIN, 0x0804 * 4, 0x01008062);
  983. else
  984. NV_WR32(par->PRAMIN, 0x0804 * 4, 0x01008042);
  985. NV_WR32(par->PRAMIN, 0x0805 * 4, 0x00000000);
  986. NV_WR32(par->PRAMIN, 0x0806 * 4, 0x12001200);
  987. NV_WR32(par->PRAMIN, 0x0807 * 4, 0x00000000);
  988. NV_WR32(par->PRAMIN, 0x0808 * 4, 0x01008043);
  989. NV_WR32(par->PRAMIN, 0x0809 * 4, 0x00000000);
  990. NV_WR32(par->PRAMIN, 0x080A * 4, 0x00000000);
  991. NV_WR32(par->PRAMIN, 0x080B * 4, 0x00000000);
  992. NV_WR32(par->PRAMIN, 0x080C * 4, 0x01008044);
  993. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000002);
  994. NV_WR32(par->PRAMIN, 0x080E * 4, 0x00000000);
  995. NV_WR32(par->PRAMIN, 0x080F * 4, 0x00000000);
  996. NV_WR32(par->PRAMIN, 0x0810 * 4, 0x01008019);
  997. NV_WR32(par->PRAMIN, 0x0811 * 4, 0x00000000);
  998. NV_WR32(par->PRAMIN, 0x0812 * 4, 0x00000000);
  999. NV_WR32(par->PRAMIN, 0x0813 * 4, 0x00000000);
  1000. NV_WR32(par->PRAMIN, 0x0814 * 4, 0x0100A05C);
  1001. NV_WR32(par->PRAMIN, 0x0815 * 4, 0x00000000);
  1002. NV_WR32(par->PRAMIN, 0x0816 * 4, 0x00000000);
  1003. NV_WR32(par->PRAMIN, 0x0817 * 4, 0x00000000);
  1004. if (par->WaitVSyncPossible)
  1005. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x0100809F);
  1006. else
  1007. NV_WR32(par->PRAMIN, 0x0818 * 4, 0x0100805F);
  1008. NV_WR32(par->PRAMIN, 0x0819 * 4, 0x00000000);
  1009. NV_WR32(par->PRAMIN, 0x081A * 4, 0x12001200);
  1010. NV_WR32(par->PRAMIN, 0x081B * 4, 0x00000000);
  1011. NV_WR32(par->PRAMIN, 0x081C * 4, 0x0100804A);
  1012. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000002);
  1013. NV_WR32(par->PRAMIN, 0x081E * 4, 0x00000000);
  1014. NV_WR32(par->PRAMIN, 0x081F * 4, 0x00000000);
  1015. NV_WR32(par->PRAMIN, 0x0820 * 4, 0x01018077);
  1016. NV_WR32(par->PRAMIN, 0x0821 * 4, 0x00000000);
  1017. NV_WR32(par->PRAMIN, 0x0822 * 4, 0x12001200);
  1018. NV_WR32(par->PRAMIN, 0x0823 * 4, 0x00000000);
  1019. NV_WR32(par->PRAMIN, 0x0824 * 4, 0x00003002);
  1020. NV_WR32(par->PRAMIN, 0x0825 * 4, 0x00007FFF);
  1021. NV_WR32(par->PRAMIN, 0x0826 * 4,
  1022. par->FbUsableSize | 0x00000002);
  1023. NV_WR32(par->PRAMIN, 0x0827 * 4, 0x00000002);
  1024. #ifdef __BIG_ENDIAN
  1025. NV_WR32(par->PRAMIN, 0x0804 * 4,
  1026. NV_RD32(par->PRAMIN, 0x0804 * 4) | 0x00080000);
  1027. NV_WR32(par->PRAMIN, 0x0808 * 4,
  1028. NV_RD32(par->PRAMIN, 0x0808 * 4) | 0x00080000);
  1029. NV_WR32(par->PRAMIN, 0x080C * 4,
  1030. NV_RD32(par->PRAMIN, 0x080C * 4) | 0x00080000);
  1031. NV_WR32(par->PRAMIN, 0x0810 * 4,
  1032. NV_RD32(par->PRAMIN, 0x0810 * 4) | 0x00080000);
  1033. NV_WR32(par->PRAMIN, 0x0814 * 4,
  1034. NV_RD32(par->PRAMIN, 0x0814 * 4) | 0x00080000);
  1035. NV_WR32(par->PRAMIN, 0x0818 * 4,
  1036. NV_RD32(par->PRAMIN, 0x0818 * 4) | 0x00080000);
  1037. NV_WR32(par->PRAMIN, 0x081C * 4,
  1038. NV_RD32(par->PRAMIN, 0x081C * 4) | 0x00080000);
  1039. NV_WR32(par->PRAMIN, 0x0820 * 4,
  1040. NV_RD32(par->PRAMIN, 0x0820 * 4) | 0x00080000);
  1041. NV_WR32(par->PRAMIN, 0x080D * 4, 0x00000001);
  1042. NV_WR32(par->PRAMIN, 0x081D * 4, 0x00000001);
  1043. #endif
  1044. }
  1045. if (par->Architecture < NV_ARCH_10) {
  1046. if ((par->Chipset & 0x0fff) == 0x0020) {
  1047. NV_WR32(par->PRAMIN, 0x0824 * 4,
  1048. NV_RD32(par->PRAMIN, 0x0824 * 4) | 0x00020000);
  1049. NV_WR32(par->PRAMIN, 0x0826 * 4,
  1050. NV_RD32(par->PRAMIN,
  1051. 0x0826 * 4) + par->FbAddress);
  1052. }
  1053. NV_WR32(par->PGRAPH, 0x0080, 0x000001FF);
  1054. NV_WR32(par->PGRAPH, 0x0080, 0x1230C000);
  1055. NV_WR32(par->PGRAPH, 0x0084, 0x72111101);
  1056. NV_WR32(par->PGRAPH, 0x0088, 0x11D5F071);
  1057. NV_WR32(par->PGRAPH, 0x008C, 0x0004FF31);
  1058. NV_WR32(par->PGRAPH, 0x008C, 0x4004FF31);
  1059. NV_WR32(par->PGRAPH, 0x0140, 0x00000000);
  1060. NV_WR32(par->PGRAPH, 0x0100, 0xFFFFFFFF);
  1061. NV_WR32(par->PGRAPH, 0x0170, 0x10010100);
  1062. NV_WR32(par->PGRAPH, 0x0710, 0xFFFFFFFF);
  1063. NV_WR32(par->PGRAPH, 0x0720, 0x00000001);
  1064. NV_WR32(par->PGRAPH, 0x0810, 0x00000000);
  1065. NV_WR32(par->PGRAPH, 0x0608, 0xFFFFFFFF);
  1066. } else {
  1067. NV_WR32(par->PGRAPH, 0x0080, 0xFFFFFFFF);
  1068. NV_WR32(par->PGRAPH, 0x0080, 0x00000000);
  1069. NV_WR32(par->PGRAPH, 0x0140, 0x00000000);
  1070. NV_WR32(par->PGRAPH, 0x0100, 0xFFFFFFFF);
  1071. NV_WR32(par->PGRAPH, 0x0144, 0x10010100);
  1072. NV_WR32(par->PGRAPH, 0x0714, 0xFFFFFFFF);
  1073. NV_WR32(par->PGRAPH, 0x0720, 0x00000001);
  1074. NV_WR32(par->PGRAPH, 0x0710,
  1075. NV_RD32(par->PGRAPH, 0x0710) & 0x0007ff00);
  1076. NV_WR32(par->PGRAPH, 0x0710,
  1077. NV_RD32(par->PGRAPH, 0x0710) | 0x00020100);
  1078. if (par->Architecture == NV_ARCH_10) {
  1079. NV_WR32(par->PGRAPH, 0x0084, 0x00118700);
  1080. NV_WR32(par->PGRAPH, 0x0088, 0x24E00810);
  1081. NV_WR32(par->PGRAPH, 0x008C, 0x55DE0030);
  1082. for (i = 0; i < 32; i++)
  1083. NV_WR32(&par->PGRAPH[(0x0B00 / 4) + i], 0,
  1084. NV_RD32(&par->PFB[(0x0240 / 4) + i],
  1085. 0));
  1086. NV_WR32(par->PGRAPH, 0x640, 0);
  1087. NV_WR32(par->PGRAPH, 0x644, 0);
  1088. NV_WR32(par->PGRAPH, 0x684, par->FbMapSize - 1);
  1089. NV_WR32(par->PGRAPH, 0x688, par->FbMapSize - 1);
  1090. NV_WR32(par->PGRAPH, 0x0810, 0x00000000);
  1091. NV_WR32(par->PGRAPH, 0x0608, 0xFFFFFFFF);
  1092. } else {
  1093. if (par->Architecture >= NV_ARCH_40) {
  1094. u32 tmp;
  1095. NV_WR32(par->PGRAPH, 0x0084, 0x401287c0);
  1096. NV_WR32(par->PGRAPH, 0x008C, 0x60de8051);
  1097. NV_WR32(par->PGRAPH, 0x0090, 0x00008000);
  1098. NV_WR32(par->PGRAPH, 0x0610, 0x00be3c5f);
  1099. tmp = NV_RD32(par->REGS, 0x1540) & 0xff;
  1100. for(i = 0; tmp && !(tmp & 1); tmp >>= 1, i++);
  1101. NV_WR32(par->PGRAPH, 0x5000, i);
  1102. if ((par->Chipset & 0xfff0) == 0x0040) {
  1103. NV_WR32(par->PGRAPH, 0x09b0,
  1104. 0x83280fff);
  1105. NV_WR32(par->PGRAPH, 0x09b4,
  1106. 0x000000a0);
  1107. } else {
  1108. NV_WR32(par->PGRAPH, 0x0820,
  1109. 0x83280eff);
  1110. NV_WR32(par->PGRAPH, 0x0824,
  1111. 0x000000a0);
  1112. }
  1113. switch (par->Chipset & 0xfff0) {
  1114. case 0x0040:
  1115. case 0x0210:
  1116. NV_WR32(par->PGRAPH, 0x09b8,
  1117. 0x0078e366);
  1118. NV_WR32(par->PGRAPH, 0x09bc,
  1119. 0x0000014c);
  1120. NV_WR32(par->PFB, 0x033C,
  1121. NV_RD32(par->PFB, 0x33C) &
  1122. 0xffff7fff);
  1123. break;
  1124. case 0x00C0:
  1125. case 0x0120:
  1126. NV_WR32(par->PGRAPH, 0x0828,
  1127. 0x007596ff);
  1128. NV_WR32(par->PGRAPH, 0x082C,
  1129. 0x00000108);
  1130. break;
  1131. case 0x0160:
  1132. case 0x01D0:
  1133. NV_WR32(par->PMC, 0x1700,
  1134. NV_RD32(par->PFB, 0x020C));
  1135. NV_WR32(par->PMC, 0x1704, 0);
  1136. NV_WR32(par->PMC, 0x1708, 0);
  1137. NV_WR32(par->PMC, 0x170C,
  1138. NV_RD32(par->PFB, 0x020C));
  1139. NV_WR32(par->PGRAPH, 0x0860, 0);
  1140. NV_WR32(par->PGRAPH, 0x0864, 0);
  1141. NV_WR32(par->PRAMDAC, 0x0608,
  1142. NV_RD32(par->PRAMDAC,
  1143. 0x0608) | 0x00100000);
  1144. break;
  1145. case 0x0140:
  1146. NV_WR32(par->PGRAPH, 0x0828,
  1147. 0x0072cb77);
  1148. NV_WR32(par->PGRAPH, 0x082C,
  1149. 0x00000108);
  1150. break;
  1151. case 0x0220:
  1152. case 0x0230:
  1153. NV_WR32(par->PGRAPH, 0x0860, 0);
  1154. NV_WR32(par->PGRAPH, 0x0864, 0);
  1155. NV_WR32(par->PRAMDAC, 0x0608,
  1156. NV_RD32(par->PRAMDAC, 0x0608) |
  1157. 0x00100000);
  1158. break;
  1159. case 0x0090:
  1160. case 0x0290:
  1161. NV_WR32(par->PRAMDAC, 0x0608,
  1162. NV_RD32(par->PRAMDAC, 0x0608) |
  1163. 0x00100000);
  1164. NV_WR32(par->PGRAPH, 0x0828,
  1165. 0x07830610);
  1166. NV_WR32(par->PGRAPH, 0x082C,
  1167. 0x0000016A);
  1168. break;
  1169. default:
  1170. break;
  1171. };
  1172. NV_WR32(par->PGRAPH, 0x0b38, 0x2ffff800);
  1173. NV_WR32(par->PGRAPH, 0x0b3c, 0x00006000);
  1174. NV_WR32(par->PGRAPH, 0x032C, 0x01000000);
  1175. NV_WR32(par->PGRAPH, 0x0220, 0x00001200);
  1176. } else if (par->Architecture == NV_ARCH_30) {
  1177. NV_WR32(par->PGRAPH, 0x0084, 0x40108700);
  1178. NV_WR32(par->PGRAPH, 0x0890, 0x00140000);
  1179. NV_WR32(par->PGRAPH, 0x008C, 0xf00e0431);
  1180. NV_WR32(par->PGRAPH, 0x0090, 0x00008000);
  1181. NV_WR32(par->PGRAPH, 0x0610, 0xf04b1f36);
  1182. NV_WR32(par->PGRAPH, 0x0B80, 0x1002d888);
  1183. NV_WR32(par->PGRAPH, 0x0B88, 0x62ff007f);
  1184. } else {
  1185. NV_WR32(par->PGRAPH, 0x0084, 0x00118700);
  1186. NV_WR32(par->PGRAPH, 0x008C, 0xF20E0431);
  1187. NV_WR32(par->PGRAPH, 0x0090, 0x00000000);
  1188. NV_WR32(par->PGRAPH, 0x009C, 0x00000040);
  1189. if ((par->Chipset & 0x0ff0) >= 0x0250) {
  1190. NV_WR32(par->PGRAPH, 0x0890,
  1191. 0x00080000);
  1192. NV_WR32(par->PGRAPH, 0x0610,
  1193. 0x304B1FB6);
  1194. NV_WR32(par->PGRAPH, 0x0B80,
  1195. 0x18B82880);
  1196. NV_WR32(par->PGRAPH, 0x0B84,
  1197. 0x44000000);
  1198. NV_WR32(par->PGRAPH, 0x0098,
  1199. 0x40000080);
  1200. NV_WR32(par->PGRAPH, 0x0B88,
  1201. 0x000000ff);
  1202. } else {
  1203. NV_WR32(par->PGRAPH, 0x0880,
  1204. 0x00080000);
  1205. NV_WR32(par->PGRAPH, 0x0094,
  1206. 0x00000005);
  1207. NV_WR32(par->PGRAPH, 0x0B80,
  1208. 0x45CAA208);
  1209. NV_WR32(par->PGRAPH, 0x0B84,
  1210. 0x24000000);
  1211. NV_WR32(par->PGRAPH, 0x0098,
  1212. 0x00000040);
  1213. NV_WR32(par->PGRAPH, 0x0750,
  1214. 0x00E00038);
  1215. NV_WR32(par->PGRAPH, 0x0754,
  1216. 0x00000030);
  1217. NV_WR32(par->PGRAPH, 0x0750,
  1218. 0x00E10038);
  1219. NV_WR32(par->PGRAPH, 0x0754,
  1220. 0x00000030);
  1221. }
  1222. }
  1223. if ((par->Architecture < NV_ARCH_40) ||
  1224. ((par->Chipset & 0xfff0) == 0x0040)) {
  1225. for (i = 0; i < 32; i++) {
  1226. NV_WR32(par->PGRAPH, 0x0900 + i*4,
  1227. NV_RD32(par->PFB, 0x0240 +i*4));
  1228. NV_WR32(par->PGRAPH, 0x6900 + i*4,
  1229. NV_RD32(par->PFB, 0x0240 +i*4));
  1230. }
  1231. } else {
  1232. if (((par->Chipset & 0xfff0) == 0x0090) ||
  1233. ((par->Chipset & 0xfff0) == 0x01D0) ||
  1234. ((par->Chipset & 0xfff0) == 0x0290)) {
  1235. for (i = 0; i < 60; i++) {
  1236. NV_WR32(par->PGRAPH,
  1237. 0x0D00 + i*4,
  1238. NV_RD32(par->PFB,
  1239. 0x0600 + i*4));
  1240. NV_WR32(par->PGRAPH,
  1241. 0x6900 + i*4,
  1242. NV_RD32(par->PFB,
  1243. 0x0600 + i*4));
  1244. }
  1245. } else {
  1246. for (i = 0; i < 48; i++) {
  1247. NV_WR32(par->PGRAPH,
  1248. 0x0900 + i*4,
  1249. NV_RD32(par->PFB,
  1250. 0x0600 + i*4));
  1251. if(((par->Chipset & 0xfff0)
  1252. != 0x0160) &&
  1253. ((par->Chipset & 0xfff0)
  1254. != 0x0220))
  1255. NV_WR32(par->PGRAPH,
  1256. 0x6900 + i*4,
  1257. NV_RD32(par->PFB,
  1258. 0x0600 + i*4));
  1259. }
  1260. }
  1261. }
  1262. if (par->Architecture >= NV_ARCH_40) {
  1263. if ((par->Chipset & 0xfff0) == 0x0040) {
  1264. NV_WR32(par->PGRAPH, 0x09A4,
  1265. NV_RD32(par->PFB, 0x0200));
  1266. NV_WR32(par->PGRAPH, 0x09A8,
  1267. NV_RD32(par->PFB, 0x0204));
  1268. NV_WR32(par->PGRAPH, 0x69A4,
  1269. NV_RD32(par->PFB, 0x0200));
  1270. NV_WR32(par->PGRAPH, 0x69A8,
  1271. NV_RD32(par->PFB, 0x0204));
  1272. NV_WR32(par->PGRAPH, 0x0820, 0);
  1273. NV_WR32(par->PGRAPH, 0x0824, 0);
  1274. NV_WR32(par->PGRAPH, 0x0864,
  1275. par->FbMapSize - 1);
  1276. NV_WR32(par->PGRAPH, 0x0868,
  1277. par->FbMapSize - 1);
  1278. } else {
  1279. if ((par->Chipset & 0xfff0) == 0x0090 ||
  1280. (par->Chipset & 0xfff0) == 0x01D0 ||
  1281. (par->Chipset & 0xfff0) == 0x0290) {
  1282. NV_WR32(par->PGRAPH, 0x0DF0,
  1283. NV_RD32(par->PFB, 0x0200));
  1284. NV_WR32(par->PGRAPH, 0x0DF4,
  1285. NV_RD32(par->PFB, 0x0204));
  1286. } else {
  1287. NV_WR32(par->PGRAPH, 0x09F0,
  1288. NV_RD32(par->PFB, 0x0200));
  1289. NV_WR32(par->PGRAPH, 0x09F4,
  1290. NV_RD32(par->PFB, 0x0204));
  1291. }
  1292. NV_WR32(par->PGRAPH, 0x69F0,
  1293. NV_RD32(par->PFB, 0x0200));
  1294. NV_WR32(par->PGRAPH, 0x69F4,
  1295. NV_RD32(par->PFB, 0x0204));
  1296. NV_WR32(par->PGRAPH, 0x0840, 0);
  1297. NV_WR32(par->PGRAPH, 0x0844, 0);
  1298. NV_WR32(par->PGRAPH, 0x08a0,
  1299. par->FbMapSize - 1);
  1300. NV_WR32(par->PGRAPH, 0x08a4,
  1301. par->FbMapSize - 1);
  1302. }
  1303. } else {
  1304. NV_WR32(par->PGRAPH, 0x09A4,
  1305. NV_RD32(par->PFB, 0x0200));
  1306. NV_WR32(par->PGRAPH, 0x09A8,
  1307. NV_RD32(par->PFB, 0x0204));
  1308. NV_WR32(par->PGRAPH, 0x0750, 0x00EA0000);
  1309. NV_WR32(par->PGRAPH, 0x0754,
  1310. NV_RD32(par->PFB, 0x0200));
  1311. NV_WR32(par->PGRAPH, 0x0750, 0x00EA0004);
  1312. NV_WR32(par->PGRAPH, 0x0754,
  1313. NV_RD32(par->PFB, 0x0204));
  1314. NV_WR32(par->PGRAPH, 0x0820, 0);
  1315. NV_WR32(par->PGRAPH, 0x0824, 0);
  1316. NV_WR32(par->PGRAPH, 0x0864,
  1317. par->FbMapSize - 1);
  1318. NV_WR32(par->PGRAPH, 0x0868,
  1319. par->FbMapSize - 1);
  1320. }
  1321. NV_WR32(par->PGRAPH, 0x0B20, 0x00000000);
  1322. NV_WR32(par->PGRAPH, 0x0B04, 0xFFFFFFFF);
  1323. }
  1324. }
  1325. NV_WR32(par->PGRAPH, 0x053C, 0);
  1326. NV_WR32(par->PGRAPH, 0x0540, 0);
  1327. NV_WR32(par->PGRAPH, 0x0544, 0x00007FFF);
  1328. NV_WR32(par->PGRAPH, 0x0548, 0x00007FFF);
  1329. NV_WR32(par->PFIFO, 0x0140 * 4, 0x00000000);
  1330. NV_WR32(par->PFIFO, 0x0141 * 4, 0x00000001);
  1331. NV_WR32(par->PFIFO, 0x0480 * 4, 0x00000000);
  1332. NV_WR32(par->PFIFO, 0x0494 * 4, 0x00000000);
  1333. if (par->Architecture >= NV_ARCH_40)
  1334. NV_WR32(par->PFIFO, 0x0481 * 4, 0x00010000);
  1335. else
  1336. NV_WR32(par->PFIFO, 0x0481 * 4, 0x00000100);
  1337. NV_WR32(par->PFIFO, 0x0490 * 4, 0x00000000);
  1338. NV_WR32(par->PFIFO, 0x0491 * 4, 0x00000000);
  1339. if (par->Architecture >= NV_ARCH_40)
  1340. NV_WR32(par->PFIFO, 0x048B * 4, 0x00001213);
  1341. else
  1342. NV_WR32(par->PFIFO, 0x048B * 4, 0x00001209);
  1343. NV_WR32(par->PFIFO, 0x0400 * 4, 0x00000000);
  1344. NV_WR32(par->PFIFO, 0x0414 * 4, 0x00000000);
  1345. NV_WR32(par->PFIFO, 0x0084 * 4, 0x03000100);
  1346. NV_WR32(par->PFIFO, 0x0085 * 4, 0x00000110);
  1347. NV_WR32(par->PFIFO, 0x0086 * 4, 0x00000112);
  1348. NV_WR32(par->PFIFO, 0x0143 * 4, 0x0000FFFF);
  1349. NV_WR32(par->PFIFO, 0x0496 * 4, 0x0000FFFF);
  1350. NV_WR32(par->PFIFO, 0x0050 * 4, 0x00000000);
  1351. NV_WR32(par->PFIFO, 0x0040 * 4, 0xFFFFFFFF);
  1352. NV_WR32(par->PFIFO, 0x0415 * 4, 0x00000001);
  1353. NV_WR32(par->PFIFO, 0x048C * 4, 0x00000000);
  1354. NV_WR32(par->PFIFO, 0x04A0 * 4, 0x00000000);
  1355. #ifdef __BIG_ENDIAN
  1356. NV_WR32(par->PFIFO, 0x0489 * 4, 0x800F0078);
  1357. #else
  1358. NV_WR32(par->PFIFO, 0x0489 * 4, 0x000F0078);
  1359. #endif
  1360. NV_WR32(par->PFIFO, 0x0488 * 4, 0x00000001);
  1361. NV_WR32(par->PFIFO, 0x0480 * 4, 0x00000001);
  1362. NV_WR32(par->PFIFO, 0x0494 * 4, 0x00000001);
  1363. NV_WR32(par->PFIFO, 0x0495 * 4, 0x00000001);
  1364. NV_WR32(par->PFIFO, 0x0140 * 4, 0x00000001);
  1365. if (par->Architecture >= NV_ARCH_10) {
  1366. if (par->twoHeads) {
  1367. NV_WR32(par->PCRTC0, 0x0860, state->head);
  1368. NV_WR32(par->PCRTC0, 0x2860, state->head2);
  1369. }
  1370. NV_WR32(par->PRAMDAC, 0x0404, NV_RD32(par->PRAMDAC, 0x0404) |
  1371. (1 << 25));
  1372. NV_WR32(par->PMC, 0x8704, 1);
  1373. NV_WR32(par->PMC, 0x8140, 0);
  1374. NV_WR32(par->PMC, 0x8920, 0);
  1375. NV_WR32(par->PMC, 0x8924, 0);
  1376. NV_WR32(par->PMC, 0x8908, par->FbMapSize - 1);
  1377. NV_WR32(par->PMC, 0x890C, par->FbMapSize - 1);
  1378. NV_WR32(par->PMC, 0x1588, 0);
  1379. NV_WR32(par->PCRTC, 0x0810, state->cursorConfig);
  1380. NV_WR32(par->PCRTC, 0x0830, state->displayV - 3);
  1381. NV_WR32(par->PCRTC, 0x0834, state->displayV - 1);
  1382. if (par->FlatPanel) {
  1383. if ((par->Chipset & 0x0ff0) == 0x0110) {
  1384. NV_WR32(par->PRAMDAC, 0x0528, state->dither);
  1385. } else if (par->twoHeads) {
  1386. NV_WR32(par->PRAMDAC, 0x083C, state->dither);
  1387. }
  1388. VGA_WR08(par->PCIO, 0x03D4, 0x53);
  1389. VGA_WR08(par->PCIO, 0x03D5, state->timingH);
  1390. VGA_WR08(par->PCIO, 0x03D4, 0x54);
  1391. VGA_WR08(par->PCIO, 0x03D5, state->timingV);
  1392. VGA_WR08(par->PCIO, 0x03D4, 0x21);
  1393. VGA_WR08(par->PCIO, 0x03D5, 0xfa);
  1394. }
  1395. VGA_WR08(par->PCIO, 0x03D4, 0x41);
  1396. VGA_WR08(par->PCIO, 0x03D5, state->extra);
  1397. }
  1398. VGA_WR08(par->PCIO, 0x03D4, 0x19);
  1399. VGA_WR08(par->PCIO, 0x03D5, state->repaint0);
  1400. VGA_WR08(par->PCIO, 0x03D4, 0x1A);
  1401. VGA_WR08(par->PCIO, 0x03D5, state->repaint1);
  1402. VGA_WR08(par->PCIO, 0x03D4, 0x25);
  1403. VGA_WR08(par->PCIO, 0x03D5, state->screen);
  1404. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  1405. VGA_WR08(par->PCIO, 0x03D5, state->pixel);
  1406. VGA_WR08(par->PCIO, 0x03D4, 0x2D);
  1407. VGA_WR08(par->PCIO, 0x03D5, state->horiz);
  1408. VGA_WR08(par->PCIO, 0x03D4, 0x1C);
  1409. VGA_WR08(par->PCIO, 0x03D5, state->fifo);
  1410. VGA_WR08(par->PCIO, 0x03D4, 0x1B);
  1411. VGA_WR08(par->PCIO, 0x03D5, state->arbitration0);
  1412. VGA_WR08(par->PCIO, 0x03D4, 0x20);
  1413. VGA_WR08(par->PCIO, 0x03D5, state->arbitration1);
  1414. if(par->Architecture >= NV_ARCH_30) {
  1415. VGA_WR08(par->PCIO, 0x03D4, 0x47);
  1416. VGA_WR08(par->PCIO, 0x03D5, state->arbitration1 >> 8);
  1417. }
  1418. VGA_WR08(par->PCIO, 0x03D4, 0x30);
  1419. VGA_WR08(par->PCIO, 0x03D5, state->cursor0);
  1420. VGA_WR08(par->PCIO, 0x03D4, 0x31);
  1421. VGA_WR08(par->PCIO, 0x03D5, state->cursor1);
  1422. VGA_WR08(par->PCIO, 0x03D4, 0x2F);
  1423. VGA_WR08(par->PCIO, 0x03D5, state->cursor2);
  1424. VGA_WR08(par->PCIO, 0x03D4, 0x39);
  1425. VGA_WR08(par->PCIO, 0x03D5, state->interlace);
  1426. if (!par->FlatPanel) {
  1427. NV_WR32(par->PRAMDAC0, 0x050C, state->pllsel);
  1428. NV_WR32(par->PRAMDAC0, 0x0508, state->vpll);
  1429. if (par->twoHeads)
  1430. NV_WR32(par->PRAMDAC0, 0x0520, state->vpll2);
  1431. if (par->twoStagePLL) {
  1432. NV_WR32(par->PRAMDAC0, 0x0578, state->vpllB);
  1433. NV_WR32(par->PRAMDAC0, 0x057C, state->vpll2B);
  1434. }
  1435. } else {
  1436. NV_WR32(par->PRAMDAC, 0x0848, state->scale);
  1437. NV_WR32(par->PRAMDAC, 0x0828, state->crtcSync +
  1438. par->PanelTweak);
  1439. }
  1440. NV_WR32(par->PRAMDAC, 0x0600, state->general);
  1441. NV_WR32(par->PCRTC, 0x0140, 0);
  1442. NV_WR32(par->PCRTC, 0x0100, 1);
  1443. par->CurrentState = state;
  1444. }
  1445. void NVUnloadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state) {
  1446. VGA_WR08(par->PCIO, 0x03D4, 0x19);
  1447. state->repaint0 = VGA_RD08(par->PCIO, 0x03D5);
  1448. VGA_WR08(par->PCIO, 0x03D4, 0x1A);
  1449. state->repaint1 = VGA_RD08(par->PCIO, 0x03D5);
  1450. VGA_WR08(par->PCIO, 0x03D4, 0x25);
  1451. state->screen = VGA_RD08(par->PCIO, 0x03D5);
  1452. VGA_WR08(par->PCIO, 0x03D4, 0x28);
  1453. state->pixel = VGA_RD08(par->PCIO, 0x03D5);
  1454. VGA_WR08(par->PCIO, 0x03D4, 0x2D);
  1455. state->horiz = VGA_RD08(par->PCIO, 0x03D5);
  1456. VGA_WR08(par->PCIO, 0x03D4, 0x1C);
  1457. state->fifo = VGA_RD08(par->PCIO, 0x03D5);
  1458. VGA_WR08(par->PCIO, 0x03D4, 0x1B);
  1459. state->arbitration0 = VGA_RD08(par->PCIO, 0x03D5);
  1460. VGA_WR08(par->PCIO, 0x03D4, 0x20);
  1461. state->arbitration1 = VGA_RD08(par->PCIO, 0x03D5);
  1462. if(par->Architecture >= NV_ARCH_30) {
  1463. VGA_WR08(par->PCIO, 0x03D4, 0x47);
  1464. state->arbitration1 |= (VGA_RD08(par->PCIO, 0x03D5) & 1) << 8;
  1465. }
  1466. VGA_WR08(par->PCIO, 0x03D4, 0x30);
  1467. state->cursor0 = VGA_RD08(par->PCIO, 0x03D5);
  1468. VGA_WR08(par->PCIO, 0x03D4, 0x31);
  1469. state->cursor1 = VGA_RD08(par->PCIO, 0x03D5);
  1470. VGA_WR08(par->PCIO, 0x03D4, 0x2F);
  1471. state->cursor2 = VGA_RD08(par->PCIO, 0x03D5);
  1472. VGA_WR08(par->PCIO, 0x03D4, 0x39);
  1473. state->interlace = VGA_RD08(par->PCIO, 0x03D5);
  1474. state->vpll = NV_RD32(par->PRAMDAC0, 0x0508);
  1475. if (par->twoHeads)
  1476. state->vpll2 = NV_RD32(par->PRAMDAC0, 0x0520);
  1477. if (par->twoStagePLL) {
  1478. state->vpllB = NV_RD32(par->PRAMDAC0, 0x0578);
  1479. state->vpll2B = NV_RD32(par->PRAMDAC0, 0x057C);
  1480. }
  1481. state->pllsel = NV_RD32(par->PRAMDAC0, 0x050C);
  1482. state->general = NV_RD32(par->PRAMDAC, 0x0600);
  1483. state->scale = NV_RD32(par->PRAMDAC, 0x0848);
  1484. state->config = NV_RD32(par->PFB, 0x0200);
  1485. if (par->Architecture >= NV_ARCH_10) {
  1486. if (par->twoHeads) {
  1487. state->head = NV_RD32(par->PCRTC0, 0x0860);
  1488. state->head2 = NV_RD32(par->PCRTC0, 0x2860);
  1489. VGA_WR08(par->PCIO, 0x03D4, 0x44);
  1490. state->crtcOwner = VGA_RD08(par->PCIO, 0x03D5);
  1491. }
  1492. VGA_WR08(par->PCIO, 0x03D4, 0x41);
  1493. state->extra = VGA_RD08(par->PCIO, 0x03D5);
  1494. state->cursorConfig = NV_RD32(par->PCRTC, 0x0810);
  1495. if ((par->Chipset & 0x0ff0) == 0x0110) {
  1496. state->dither = NV_RD32(par->PRAMDAC, 0x0528);
  1497. } else if (par->twoHeads) {
  1498. state->dither = NV_RD32(par->PRAMDAC, 0x083C);
  1499. }
  1500. if (par->FlatPanel) {
  1501. VGA_WR08(par->PCIO, 0x03D4, 0x53);
  1502. state->timingH = VGA_RD08(par->PCIO, 0x03D5);
  1503. VGA_WR08(par->PCIO, 0x03D4, 0x54);
  1504. state->timingV = VGA_RD08(par->PCIO, 0x03D5);
  1505. }
  1506. }
  1507. }
  1508. void NVSetStartAddress(struct nvidia_par *par, u32 start)
  1509. {
  1510. NV_WR32(par->PCRTC, 0x800, start);
  1511. }