nv_hw.c 50 KB

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