nv_hw.c 50 KB

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