nv_hw.c 51 KB

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