1 /***************************************************************************\
3 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
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. *|
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 *|
14 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
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. *|
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. *|
38 \***************************************************************************/
39 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_hw.c,v 1.21 2006/06/16 00:19:33 mvojkovi Exp $ */
41 #include "nv_include.h"
45 uint8_t nvReadVGA(NVPtr pNv, uint8_t index)
47 volatile const uint8_t *ptr = pNv->cur_head ? pNv->PCIO1 : pNv->PCIO0;
48 VGA_WR08(ptr, 0x03D4, index);
49 return VGA_RD08(ptr, 0x03D5);
52 void nvWriteVGA(NVPtr pNv, uint8_t index, uint8_t data)
54 volatile const uint8_t *ptr = pNv->cur_head ? pNv->PCIO1 : pNv->PCIO0;
55 VGA_WR08(ptr, 0x03D4, index);
56 VGA_WR08(ptr, 0x03D5, data);
59 CARD32 nvReadRAMDAC(NVPtr pNv, uint8_t head, uint32_t ramdac_reg)
61 volatile const void *ptr = head ? pNv->PRAMDAC1 : pNv->PRAMDAC0;
62 return MMIO_IN32(ptr, ramdac_reg);
65 void nvWriteRAMDAC(NVPtr pNv, uint8_t head, uint32_t ramdac_reg, CARD32 val)
67 volatile const void *ptr = head ? pNv->PRAMDAC1 : pNv->PRAMDAC0;
68 MMIO_OUT32(ptr, ramdac_reg, val);
71 CARD32 nvReadCRTC(NVPtr pNv, uint8_t head, uint32_t reg)
73 volatile const void *ptr = head ? pNv->PCRTC1 : pNv->PCRTC0;
74 return MMIO_IN32(ptr, reg);
77 void nvWriteCRTC(NVPtr pNv, uint8_t head, uint32_t reg, CARD32 val)
79 volatile const void *ptr = head ? pNv->PCRTC1 : pNv->PCRTC0;
80 MMIO_OUT32(ptr, reg, val);
90 nvWriteVGA(pNv, 0x1f, Lock ? 0x99 : 0x57 );
92 cr11 = nvReadVGA(pNv, 0x11);
93 if(Lock) cr11 |= 0x80;
95 nvWriteVGA(pNv, 0x11, cr11);
98 int NVShowHideCursor (
103 int current = pNv->CurrentState->cursor1;
105 pNv->CurrentState->cursor1 = (pNv->CurrentState->cursor1 & 0xFE) |
108 nvWriteVGA(pNv, 0x31, pNv->CurrentState->cursor1);
110 if(pNv->Architecture == NV_ARCH_40) { /* HW bug */
111 volatile CARD32 curpos = nvReadCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS);
112 nvWriteCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS, curpos);
115 return (current & 0x01);
118 /****************************************************************************\
120 * The video arbitration routines calculate some "magic" numbers. Fixes *
121 * the snow seen when accessing the framebuffer without it. *
122 * It just works (I hope). *
124 \****************************************************************************/
129 int graphics_burst_size;
130 int video_burst_size;
151 int graphics_burst_size;
152 int video_burst_size;
172 static void nvGetClocks(NVPtr pNv, unsigned int *MClk, unsigned int *NVClk)
174 unsigned int pll, N, M, MB, NB, P;
176 if(pNv->Architecture >= NV_ARCH_40) {
177 pll = nvReadMC(pNv, 0x4020);
178 P = (pll >> 16) & 0x07;
179 pll = nvReadMC(pNv, 0x4024);
181 N = (pll >> 8) & 0xFF;
182 if(((pNv->Chipset & 0xfff0) == CHIPSET_G71) ||
183 ((pNv->Chipset & 0xfff0) == CHIPSET_G73))
188 MB = (pll >> 16) & 0xFF;
189 NB = (pll >> 24) & 0xFF;
191 *MClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
193 pll = nvReadMC(pNv, 0x4000);
194 P = (pll >> 16) & 0x07;
195 pll = nvReadMC(pNv, 0x4004);
197 N = (pll >> 8) & 0xFF;
198 MB = (pll >> 16) & 0xFF;
199 NB = (pll >> 24) & 0xFF;
201 *NVClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
203 if(pNv->twoStagePLL) {
204 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_MPLL);
206 N = (pll >> 8) & 0xFF;
207 P = (pll >> 16) & 0x0F;
208 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_MPLL_B);
209 if(pll & 0x80000000) {
211 NB = (pll >> 8) & 0xFF;
216 *MClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
218 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_NVPLL);
220 N = (pll >> 8) & 0xFF;
221 P = (pll >> 16) & 0x0F;
222 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_NVPLL_B);
223 if(pll & 0x80000000) {
225 NB = (pll >> 8) & 0xFF;
230 *NVClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
232 if(((pNv->Chipset & 0x0ff0) == CHIPSET_NV30) ||
233 ((pNv->Chipset & 0x0ff0) == CHIPSET_NV35))
235 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_MPLL);
237 N = (pll >> 8) & 0xFF;
238 P = (pll >> 16) & 0x07;
239 if(pll & 0x00000080) {
240 MB = (pll >> 4) & 0x07;
241 NB = (pll >> 19) & 0x1f;
246 *MClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
248 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_NVPLL);
250 N = (pll >> 8) & 0xFF;
251 P = (pll >> 16) & 0x07;
252 if(pll & 0x00000080) {
253 MB = (pll >> 4) & 0x07;
254 NB = (pll >> 19) & 0x1f;
259 *NVClk = ((N * NB * pNv->CrystalFreqKHz) / (M * MB)) >> P;
261 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_MPLL);
263 N = (pll >> 8) & 0xFF;
264 P = (pll >> 16) & 0x0F;
265 *MClk = (N * pNv->CrystalFreqKHz / M) >> P;
267 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_NVPLL);
269 N = (pll >> 8) & 0xFF;
270 P = (pll >> 16) & 0x0F;
271 *NVClk = (N * pNv->CrystalFreqKHz / M) >> P;
275 ErrorF("NVClock = %i MHz, MEMClock = %i MHz\n", *NVClk/1000, *MClk/1000);
280 static void nv4CalcArbitration (
285 int data, pagemiss, cas,width, video_enable, bpp;
286 int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
287 int found, mclk_extra, mclk_loop, cbs, m1, p1;
288 int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
289 int us_m, us_n, us_p, video_drain_rate, crtc_drain_rate;
290 int vpm_us, us_video, vlwm, video_fill_us, cpm_us, us_crt,clwm;
293 pclk_freq = arb->pclk_khz;
294 mclk_freq = arb->mclk_khz;
295 nvclk_freq = arb->nvclk_khz;
296 pagemiss = arb->mem_page_miss;
297 cas = arb->mem_latency;
298 width = arb->memory_width >> 6;
299 video_enable = arb->enable_video;
301 mp_enable = arb->enable_mp;
332 mclk_loop = mclks+mclk_extra;
333 us_m = mclk_loop *1000*1000 / mclk_freq;
334 us_n = nvclks*1000*1000 / nvclk_freq;
335 us_p = nvclks*1000*1000 / pclk_freq;
338 video_drain_rate = pclk_freq * 2;
339 crtc_drain_rate = pclk_freq * bpp/8;
343 vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
344 if (nvclk_freq * 2 > mclk_freq * width)
345 video_fill_us = cbs*1000*1000 / 16 / nvclk_freq ;
347 video_fill_us = cbs*1000*1000 / (8 * width) / mclk_freq;
348 us_video = vpm_us + us_m + us_n + us_p + video_fill_us;
349 vlwm = us_video * video_drain_rate/(1000*1000);
352 if (vlwm > 128) vbs = 64;
353 if (vlwm > (256-64)) vbs = 32;
354 if (nvclk_freq * 2 > mclk_freq * width)
355 video_fill_us = vbs *1000*1000/ 16 / nvclk_freq ;
357 video_fill_us = vbs*1000*1000 / (8 * width) / mclk_freq;
358 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
365 clwm = us_crt * crtc_drain_rate/(1000*1000);
370 crtc_drain_rate = pclk_freq * bpp/8;
373 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
374 us_crt = cpm_us + us_m + us_n + us_p ;
375 clwm = us_crt * crtc_drain_rate/(1000*1000);
378 m1 = clwm + cbs - 512;
379 p1 = m1 * pclk_freq / mclk_freq;
381 if ((p1 < m1) && (m1 > 0))
385 if (mclk_extra ==0) found = 1;
388 else if (video_enable)
390 if ((clwm > 511) || (vlwm > 255))
394 if (mclk_extra ==0) found = 1;
404 if (mclk_extra ==0) found = 1;
408 if (clwm < 384) clwm = 384;
409 if (vlwm < 128) vlwm = 128;
411 fifo->graphics_lwm = data;
412 fifo->graphics_burst_size = 128;
413 data = (int)((vlwm+15));
414 fifo->video_lwm = data;
415 fifo->video_burst_size = vbs;
419 static void nv4UpdateArbitrationSettings (
427 nv4_fifo_info fifo_data;
428 nv4_sim_state sim_data;
429 unsigned int MClk, NVClk, cfg1;
431 nvGetClocks(pNv, &MClk, &NVClk);
433 cfg1 = nvReadFB(pNv, NV_PFB_CFG1);
434 sim_data.pix_bpp = (char)pixelDepth;
435 sim_data.enable_video = 0;
436 sim_data.enable_mp = 0;
437 sim_data.memory_width = (nvReadEXTDEV(pNv, 0x0000) & 0x10) ? 128 : 64;
438 sim_data.mem_latency = (char)cfg1 & 0x0F;
439 sim_data.mem_aligned = 1;
440 sim_data.mem_page_miss = (char)(((cfg1 >> 4) &0x0F) + ((cfg1 >> 31) & 0x01));
441 sim_data.gr_during_vid = 0;
442 sim_data.pclk_khz = VClk;
443 sim_data.mclk_khz = MClk;
444 sim_data.nvclk_khz = NVClk;
445 nv4CalcArbitration(&fifo_data, &sim_data);
448 int b = fifo_data.graphics_burst_size >> 4;
450 while (b >>= 1) (*burst)++;
451 *lwm = fifo_data.graphics_lwm >> 3;
455 static void nv10CalcArbitration (
456 nv10_fifo_info *fifo,
460 int data, pagemiss, width, video_enable, bpp;
461 int nvclks, mclks, pclks, vpagemiss, crtpagemiss;
463 int found, mclk_extra, mclk_loop, cbs, m1;
464 int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
465 int us_m, us_m_min, us_n, us_p, crtc_drain_rate;
467 int vpm_us, us_video, cpm_us, us_crt,clwm;
469 int m2us, us_pipe_min, p1clk, p2;
471 int us_min_mclk_extra;
474 pclk_freq = arb->pclk_khz; /* freq in KHz */
475 mclk_freq = arb->mclk_khz;
476 nvclk_freq = arb->nvclk_khz;
477 pagemiss = arb->mem_page_miss;
478 width = arb->memory_width/64;
479 video_enable = arb->enable_video;
481 mp_enable = arb->enable_mp;
486 pclks = 4; /* lwm detect. */
488 nvclks = 3; /* lwm -> sync. */
489 nvclks += 2; /* fbi bus cycles (1 req + 1 busy) */
491 mclks = 1; /* 2 edge sync. may be very close to edge so just put one. */
493 mclks += 1; /* arb_hp_req */
494 mclks += 5; /* ap_hp_req tiling pipeline */
496 mclks += 2; /* tc_req latency fifo */
497 mclks += 2; /* fb_cas_n_ memory request to fbio block */
498 mclks += 7; /* sm_d_rdv data returned from fbio block */
500 /* fb.rd.d.Put_gc need to accumulate 256 bits for read */
501 if (arb->memory_type == 0)
502 if (arb->memory_width == 64) /* 64 bit bus */
507 if (arb->memory_width == 64) /* 64 bit bus */
512 if ((!video_enable) && (arb->memory_width == 128))
514 mclk_extra = (bpp == 32) ? 31 : 42; /* Margin of error */
519 mclk_extra = (bpp == 32) ? 8 : 4; /* Margin of error */
520 /* mclk_extra = 4; */ /* Margin of error */
524 nvclks += 1; /* 2 edge sync. may be very close to edge so just put one. */
525 nvclks += 1; /* fbi_d_rdv_n */
526 nvclks += 1; /* Fbi_d_rdata */
527 nvclks += 1; /* crtfifo load */
530 mclks+=4; /* Mp can get in with a burst of 8. */
531 /* Extra clocks determined by heuristics */
539 mclk_loop = mclks+mclk_extra;
540 us_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
541 us_m_min = mclks * 1000*1000 / mclk_freq; /* Minimum Mclk latency in us */
542 us_min_mclk_extra = min_mclk_extra *1000*1000 / mclk_freq;
543 us_n = nvclks*1000*1000 / nvclk_freq;/* nvclk latency in us */
544 us_p = pclks*1000*1000 / pclk_freq;/* nvclk latency in us */
545 us_pipe_min = us_m_min + us_n + us_p;
547 vus_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
550 crtc_drain_rate = pclk_freq * bpp/8; /* MB/s */
552 vpagemiss = 1; /* self generating page miss */
553 vpagemiss += 1; /* One higher priority before */
555 crtpagemiss = 2; /* self generating page miss */
557 crtpagemiss += 1; /* if MA0 conflict */
559 vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
561 us_video = vpm_us + vus_m; /* Video has separate read return path */
563 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
565 us_video /* Wait for video */
566 +cpm_us /* CRT Page miss */
567 +us_m + us_n +us_p /* other latency */
570 clwm = us_crt * crtc_drain_rate/(1000*1000);
571 clwm++; /* fixed point <= float_point - 1. Fixes that */
573 crtc_drain_rate = pclk_freq * bpp/8; /* bpp * pclk/8 */
575 crtpagemiss = 1; /* self generating page miss */
576 crtpagemiss += 1; /* MA0 page miss */
578 crtpagemiss += 1; /* if MA0 conflict */
579 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
580 us_crt = cpm_us + us_m + us_n + us_p ;
581 clwm = us_crt * crtc_drain_rate/(1000*1000);
582 clwm++; /* fixed point <= float_point - 1. Fixes that */
584 /* Finally, a heuristic check when width == 64 bits */
586 nvclk_fill = nvclk_freq * 8;
587 if(crtc_drain_rate * 100 >= nvclk_fill * 102)
588 clwm = 0xfff; /*Large number to fail */
590 else if(crtc_drain_rate * 100 >= nvclk_fill * 98) {
603 clwm_rnd_down = ((int)clwm/8)*8;
604 if (clwm_rnd_down < clwm)
607 m1 = clwm + cbs - 1024; /* Amount of overfill */
608 m2us = us_pipe_min + us_min_mclk_extra;
610 /* pclk cycles to drain */
611 p1clk = m2us * pclk_freq/(1000*1000);
612 p2 = p1clk * bpp / 8; /* bytes drained. */
614 if((p2 < m1) && (m1 > 0)) {
617 if(min_mclk_extra == 0) {
619 found = 1; /* Can't adjust anymore! */
621 cbs = cbs/2; /* reduce the burst size */
627 if (clwm > 1023){ /* Have some margin */
630 if(min_mclk_extra == 0)
631 found = 1; /* Can't adjust anymore! */
637 if(clwm < (1024-cbs+8)) clwm = 1024-cbs+8;
639 /* printf("CRT LWM: %f bytes, prog: 0x%x, bs: 256\n", clwm, data ); */
640 fifo->graphics_lwm = data; fifo->graphics_burst_size = cbs;
642 fifo->video_lwm = 1024; fifo->video_burst_size = 512;
646 static void nv10UpdateArbitrationSettings (
654 nv10_fifo_info fifo_data;
655 nv10_sim_state sim_data;
656 unsigned int MClk, NVClk, cfg1;
658 nvGetClocks(pNv, &MClk, &NVClk);
660 cfg1 = nvReadFB(pNv, NV_PFB_CFG1);
661 sim_data.pix_bpp = (char)pixelDepth;
662 sim_data.enable_video = 1;
663 sim_data.enable_mp = 0;
664 sim_data.memory_type = (nvReadFB(pNv, NV_PFB_CFG0) & 0x01) ? 1 : 0;
665 sim_data.memory_width = (nvReadEXTDEV(pNv, 0x0000) & 0x10) ? 128 : 64;
666 sim_data.mem_latency = (char)cfg1 & 0x0F;
667 sim_data.mem_aligned = 1;
668 sim_data.mem_page_miss = (char)(((cfg1>>4) &0x0F) + ((cfg1>>31) & 0x01));
669 sim_data.gr_during_vid = 0;
670 sim_data.pclk_khz = VClk;
671 sim_data.mclk_khz = MClk;
672 sim_data.nvclk_khz = NVClk;
673 nv10CalcArbitration(&fifo_data, &sim_data);
674 if (fifo_data.valid) {
675 int b = fifo_data.graphics_burst_size >> 4;
677 while (b >>= 1) (*burst)++;
678 *lwm = fifo_data.graphics_lwm >> 3;
683 static void nv30UpdateArbitrationSettings (
689 unsigned int MClk, NVClk;
690 unsigned int fifo_size, burst_size, graphics_lwm;
694 graphics_lwm = fifo_size - burst_size;
696 nvGetClocks(pNv, &MClk, &NVClk);
700 while(burst_size >>= 1) (*burst)++;
701 *lwm = graphics_lwm >> 3;
704 static void nForceUpdateArbitrationSettings (
712 nv10_fifo_info fifo_data;
713 nv10_sim_state sim_data;
714 unsigned int M, N, P, pll, MClk, NVClk, memctrl;
716 if((pNv->Chipset & 0x0FF0) == CHIPSET_NFORCE) {
717 unsigned int uMClkPostDiv;
719 uMClkPostDiv = (pciReadLong(pciTag(0, 0, 3), 0x6C) >> 8) & 0xf;
720 if(!uMClkPostDiv) uMClkPostDiv = 4;
721 MClk = 400000 / uMClkPostDiv;
723 MClk = pciReadLong(pciTag(0, 0, 5), 0x4C) / 1000;
726 pll = nvReadRAMDAC0(pNv, NV_RAMDAC_NVPLL);
727 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
728 NVClk = (N * pNv->CrystalFreqKHz / M) >> P;
729 sim_data.pix_bpp = (char)pixelDepth;
730 sim_data.enable_video = 0;
731 sim_data.enable_mp = 0;
732 sim_data.memory_type = (pciReadLong(pciTag(0, 0, 1), 0x7C) >> 12) & 1;
733 sim_data.memory_width = 64;
735 memctrl = pciReadLong(pciTag(0, 0, 3), 0x00) >> 16;
737 if((memctrl == 0x1A9) || (memctrl == 0x1AB) || (memctrl == 0x1ED)) {
740 dimm[0] = (pciReadLong(pciTag(0, 0, 2), 0x40) >> 8) & 0x4F;
741 dimm[1] = (pciReadLong(pciTag(0, 0, 2), 0x44) >> 8) & 0x4F;
742 dimm[2] = (pciReadLong(pciTag(0, 0, 2), 0x48) >> 8) & 0x4F;
744 if((dimm[0] + dimm[1]) != dimm[2]) {
746 "your nForce DIMMs are not arranged in optimal banks!\n");
750 sim_data.mem_latency = 3;
751 sim_data.mem_aligned = 1;
752 sim_data.mem_page_miss = 10;
753 sim_data.gr_during_vid = 0;
754 sim_data.pclk_khz = VClk;
755 sim_data.mclk_khz = MClk;
756 sim_data.nvclk_khz = NVClk;
757 nv10CalcArbitration(&fifo_data, &sim_data);
760 int b = fifo_data.graphics_burst_size >> 4;
762 while (b >>= 1) (*burst)++;
763 *lwm = fifo_data.graphics_lwm >> 3;
768 /****************************************************************************\
770 * RIVA Mode State Routines *
772 \****************************************************************************/
775 * Calculate the Video Clock parameters for the PLL.
777 static void CalcVClock (
784 unsigned lowM, highM;
785 unsigned DeltaNew, DeltaOld;
789 DeltaOld = 0xFFFFFFFF;
791 VClk = (unsigned)clockIn;
793 if (pNv->CrystalFreqKHz == 13500) {
801 for (P = 0; P <= 4; P++) {
803 if ((Freq >= 128000) && (Freq <= 350000)) {
804 for (M = lowM; M <= highM; M++) {
805 N = ((VClk << P) * M) / pNv->CrystalFreqKHz;
807 Freq = ((pNv->CrystalFreqKHz * N) / M) >> P;
809 DeltaNew = Freq - VClk;
811 DeltaNew = VClk - Freq;
812 if (DeltaNew < DeltaOld) {
813 *pllOut = (P << 16) | (N << 8) | M;
823 static void CalcVClock2Stage (
831 unsigned DeltaNew, DeltaOld;
835 DeltaOld = 0xFFFFFFFF;
837 *pllBOut = 0x80000401; /* fixed at x4 for now */
839 VClk = (unsigned)clockIn;
841 for (P = 0; P <= 6; P++) {
843 if ((Freq >= 400000) && (Freq <= 1000000)) {
844 for (M = 1; M <= 13; M++) {
845 N = ((VClk << P) * M) / (pNv->CrystalFreqKHz << 2);
846 if((N >= 5) && (N <= 255)) {
847 Freq = (((pNv->CrystalFreqKHz << 2) * N) / M) >> P;
849 DeltaNew = Freq - VClk;
851 DeltaNew = VClk - Freq;
852 if (DeltaNew < DeltaOld) {
853 *pllOut = (P << 16) | (N << 8) | M;
864 * Calculate extended mode parameters (SVGA) and save in a
865 * mode state structure.
867 void NVCalcStateExt (
869 RIVA_HW_STATE *state,
878 int pixelDepth, VClk;
882 * Save mode parameters.
884 state->bpp = bpp; /* this is not bitsPerPixel, it's 8,15,16,32 */
885 state->width = width;
886 state->height = height;
888 * Extended RIVA registers.
890 pixelDepth = (bpp + 1)/8;
892 CalcVClock2Stage(dotClock, &VClk, &state->pll, &state->pllB, pNv);
894 CalcVClock(dotClock, &VClk, &state->pll, pNv);
896 switch (pNv->Architecture)
899 nv4UpdateArbitrationSettings(VClk,
901 &(state->arbitration0),
902 &(state->arbitration1),
904 state->cursor0 = 0x00;
905 state->cursor1 = 0xbC;
906 if (flags & V_DBLSCAN)
908 state->cursor2 = 0x00000000;
909 state->pllsel = 0x10000700;
910 state->config = 0x00001114;
911 state->general = bpp == 16 ? 0x00101100 : 0x00100100;
912 state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
918 if(((pNv->Chipset & 0xfff0) == CHIPSET_C51) ||
919 ((pNv->Chipset & 0xfff0) == CHIPSET_C512))
921 state->arbitration0 = 128;
922 state->arbitration1 = 0x0480;
924 if(((pNv->Chipset & 0xffff) == CHIPSET_NFORCE) ||
925 ((pNv->Chipset & 0xffff) == CHIPSET_NFORCE2))
927 nForceUpdateArbitrationSettings(VClk,
929 &(state->arbitration0),
930 &(state->arbitration1),
932 } else if(pNv->Architecture < NV_ARCH_30) {
933 nv10UpdateArbitrationSettings(VClk,
935 &(state->arbitration0),
936 &(state->arbitration1),
939 nv30UpdateArbitrationSettings(pNv,
940 &(state->arbitration0),
941 &(state->arbitration1));
943 CursorStart = pNv->Cursor->offset - pNv->VRAMPhysical;
944 state->cursor0 = 0x80 | (CursorStart >> 17);
945 state->cursor1 = (CursorStart >> 11) << 2;
946 state->cursor2 = CursorStart >> 24;
947 if (flags & V_DBLSCAN)
949 state->pllsel = 0x10000700;
950 state->config = nvReadFB(pNv, NV_PFB_CFG0);
951 state->general = bpp == 16 ? 0x00101100 : 0x00100100;
952 state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
956 if(bpp != 8) /* DirectColor */
957 state->general |= 0x00000030;
959 state->repaint0 = (((width / 8) * pixelDepth) & 0x700) >> 3;
960 state->pixel = (pixelDepth > 2) ? 3 : pixelDepth;
964 void NVLoadStateExt (
969 NVPtr pNv = NVPTR(pScrn);
974 nvWriteMC(pNv, 0x140, 0);
976 nvWriteTIMER(pNv, 0x0200, 0x00000008);
977 nvWriteTIMER(pNv, 0x0210, 0x00000003);
978 /*TODO: DRM handle PTIMER interrupts */
979 nvWriteTIMER(pNv, 0x0140, 0x00000000);
980 nvWriteTIMER(pNv, 0x0100, 0xFFFFFFFF);
983 /* it seems those regions are equivalent to the radeon's SURFACEs. needs to go in-kernel just like the SURFACEs */
984 if(pNv->Architecture == NV_ARCH_04) {
985 nvWriteFB(pNv, NV_PFB_CFG0, state->config);
987 if((pNv->Architecture < NV_ARCH_40) ||
988 ((pNv->Chipset & 0xfff0) == CHIPSET_NV40))
990 for(i = 0; i < 8; i++) {
991 nvWriteFB(pNv, (NV_PFB_TILE_NV10 + (i * 0x10)), 0);
992 nvWriteFB(pNv, (NV_PFB_TILE_SIZE_NV10 + (i * 0x10)), pNv->VRAMPhysicalSize - 1);
997 if(((pNv->Chipset & 0xfff0) == CHIPSET_G70) ||
998 ((pNv->Chipset & 0xfff0) == CHIPSET_G71) ||
999 ((pNv->Chipset & 0xfff0) == CHIPSET_G72) ||
1000 ((pNv->Chipset & 0xfff0) == CHIPSET_G73) ||
1001 ((pNv->Chipset & 0xfff0) == CHIPSET_C512))
1006 for(i = 0; i < regions; i++) {
1007 nvWriteFB(pNv, (NV_PFB_TILE_NV40 + (i * 0x10)), 0);
1008 nvWriteFB(pNv, (NV_PFB_TILE_SIZE_NV40 + (i * 0x10)), pNv->VRAMPhysicalSize - 1);
1011 /* end of surfaces */
1013 if(pNv->Architecture < NV_ARCH_10) {
1014 if((pNv->Chipset & 0x0fff) == CHIPSET_NV04) {
1015 /*XXX: RAMIN access here, find out what it's for.
1016 * The DRM is handling RAMIN now
1018 pNv->PRAMIN[0x0824] |= 0x00020000;
1019 pNv->PRAMIN[0x0826] += pNv->VRAMPhysical;
1021 nvWriteGRAPH(pNv, 0x0080, 0x000001FF);
1022 nvWriteGRAPH(pNv, 0x0080, 0x1230C000);
1023 nvWriteGRAPH(pNv, 0x0084, 0x72111101);
1024 nvWriteGRAPH(pNv, 0x0088, 0x11D5F071);
1025 nvWriteGRAPH(pNv, 0x008C, 0x0004FF31);
1026 nvWriteGRAPH(pNv, 0x008C, 0x4004FF31);
1029 nvWriteGRAPH(pNv, 0x140, 0x0);
1030 nvWriteGRAPH(pNv, 0x100, 0xFFFFFFFF);
1032 nvWriteGRAPH(pNv, 0x0170, 0x10010100);
1033 nvWriteGRAPH(pNv, 0x0710, 0xFFFFFFFF);
1034 nvWriteGRAPH(pNv, 0x0720, 0x00000001);
1036 nvWriteGRAPH(pNv, 0x0810, 0x00000000);
1037 nvWriteGRAPH(pNv, 0x0608, 0xFFFFFFFF);
1039 nvWriteGRAPH(pNv, 0x0080, 0xFFFFFFFF);
1040 nvWriteGRAPH(pNv, 0x0080, 0x00000000);
1043 nvWriteGRAPH(pNv, 0x140, 0x0);
1044 nvWriteGRAPH(pNv, 0x100, 0xFFFFFFFF);
1046 nvWriteGRAPH(pNv, 0x0144, 0x10010100);
1047 nvWriteGRAPH(pNv, 0x0714, 0xFFFFFFFF);
1048 nvWriteGRAPH(pNv, 0x0720, 0x00000001);
1049 temp = nvReadGRAPH(pNv, 0x710);
1050 nvWriteGRAPH(pNv, 0x0710, temp & 0x0007ff00);
1051 temp = nvReadGRAPH(pNv, 0x710);
1052 nvWriteGRAPH(pNv, 0x0710, temp | 0x00020100);
1054 if(pNv->Architecture == NV_ARCH_10) {
1055 nvWriteGRAPH(pNv, 0x0084, 0x00118700);
1056 nvWriteGRAPH(pNv, 0x0088, 0x24E00810);
1057 nvWriteGRAPH(pNv, 0x008C, 0x55DE0030);
1059 /* nv10 second surfaces */
1060 /* this is a copy of the surfaces. What is it for ? */
1061 for(i = 0; i < 32; i++)
1062 nvWriteGRAPH(pNv, 0x0B00 + (i*4), nvReadFB(pNv, NV_PFB_TILE_NV10 + (i*4)));
1063 /* end of nv10 second surfaces */
1065 nvWriteGRAPH(pNv, 0x640, 0);
1066 nvWriteGRAPH(pNv, 0x644, 0);
1067 nvWriteGRAPH(pNv, 0x684, pNv->VRAMPhysicalSize - 1);
1068 nvWriteGRAPH(pNv, 0x688, pNv->VRAMPhysicalSize - 1);
1070 nvWriteGRAPH(pNv, 0x0810, 0x00000000);
1071 nvWriteGRAPH(pNv, 0x0608, 0xFFFFFFFF);
1073 if(pNv->Architecture >= NV_ARCH_40) {
1074 nvWriteGRAPH(pNv, 0x0084, 0x401287c0);
1075 nvWriteGRAPH(pNv, 0x008C, 0x60de8051);
1076 nvWriteGRAPH(pNv, 0x0090, 0x00008000);
1077 nvWriteGRAPH(pNv, 0x0610, 0x00be3c5f);
1079 j = pNv->REGS[0x1540/4] & 0xff;
1081 for(i = 0; !(j & 1); j >>= 1, i++);
1082 nvWriteGRAPH(pNv, 0x5000, i);
1085 if((pNv->Chipset & 0xfff0) == CHIPSET_NV40) {
1086 nvWriteGRAPH(pNv, 0x09b0, 0x83280fff);
1087 nvWriteGRAPH(pNv, 0x09b4, 0x000000a0);
1089 nvWriteGRAPH(pNv, 0x0820, 0x83280eff);
1090 nvWriteGRAPH(pNv, 0x0824, 0x000000a0);
1093 switch(pNv->Chipset & 0xfff0) {
1096 nvWriteGRAPH(pNv, 0x09b8, 0x0078e366);
1097 nvWriteGRAPH(pNv, 0x09bc, 0x0000014c);
1098 temp = nvReadFB(pNv, NV_PFB_CLOSE_PAGE2);
1099 nvWriteFB(pNv, NV_PFB_CLOSE_PAGE2, temp & 0xffff7fff);
1103 nvWriteGRAPH(pNv, 0x0828, 0x007596ff);
1104 nvWriteGRAPH(pNv, 0x082C, 0x00000108);
1110 nvWriteMC(pNv, 0x1700, nvReadFB(pNv, NV_PFB_020C));
1111 nvWriteMC(pNv, 0x1704, 0);
1112 nvWriteMC(pNv, 0x1708, 0);
1113 nvWriteMC(pNv, 0x170C, nvReadFB(pNv, NV_PFB_020C));
1114 nvWriteGRAPH(pNv, 0x0860, 0);
1115 nvWriteGRAPH(pNv, 0x0864, 0);
1116 temp = nvReadCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL);
1117 nvWriteCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL, temp | 0x00100000);
1120 nvWriteGRAPH(pNv, 0x0828, 0x0072cb77);
1121 nvWriteGRAPH(pNv, 0x082C, 0x00000108);
1124 nvWriteGRAPH(pNv, 0x0860, 0);
1125 nvWriteGRAPH(pNv, 0x0864, 0);
1126 temp = nvReadCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL);
1127 nvWriteCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL, temp | 0x00100000);
1132 temp = nvReadCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL);
1133 nvWriteCurRAMDAC(pNv, NV_RAMDAC_TEST_CONTROL, temp | 0x00100000);
1134 nvWriteGRAPH(pNv, 0x0828, 0x07830610);
1135 nvWriteGRAPH(pNv, 0x082C, 0x0000016A);
1141 nvWriteGRAPH(pNv, 0x0b38, 0x2ffff800);
1142 nvWriteGRAPH(pNv, 0x0b3c, 0x00006000);
1143 nvWriteGRAPH(pNv, 0x032C, 0x01000000);
1145 if(pNv->Architecture == NV_ARCH_30) {
1146 nvWriteGRAPH(pNv, 0x0084, 0x40108700);
1147 nvWriteGRAPH(pNv, 0x0890, 0x00140000);
1148 nvWriteGRAPH(pNv, 0x008C, 0xf00e0431);
1149 nvWriteGRAPH(pNv, 0x0090, 0x00008000);
1150 nvWriteGRAPH(pNv, 0x0610, 0xf04b1f36);
1151 nvWriteGRAPH(pNv, 0x0B80, 0x1002d888);
1152 nvWriteGRAPH(pNv, 0x0B88, 0x62ff007f);
1154 nvWriteGRAPH(pNv, 0x0084, 0x00118700);
1155 nvWriteGRAPH(pNv, 0x008C, 0xF20E0431);
1156 nvWriteGRAPH(pNv, 0x0090, 0x00000000);
1157 nvWriteGRAPH(pNv, 0x009C, 0x00000040);
1159 if((pNv->Chipset & 0x0ff0) >= CHIPSET_NV25) {
1160 nvWriteGRAPH(pNv, 0x0890, 0x00080000);
1161 nvWriteGRAPH(pNv, 0x0610, 0x304B1FB6);
1162 nvWriteGRAPH(pNv, 0x0B80, 0x18B82880);
1163 nvWriteGRAPH(pNv, 0x0B84, 0x44000000);
1164 nvWriteGRAPH(pNv, 0x0098, 0x40000080);
1165 nvWriteGRAPH(pNv, 0x0B88, 0x000000ff);
1167 nvWriteGRAPH(pNv, 0x0880, 0x00080000);
1168 nvWriteGRAPH(pNv, 0x0094, 0x00000005);
1169 nvWriteGRAPH(pNv, 0x0B80, 0x45CAA208);
1170 nvWriteGRAPH(pNv, 0x0B84, 0x24000000);
1171 nvWriteGRAPH(pNv, 0x0098, 0x00000040);
1172 nvWriteGRAPH(pNv, 0x0750, 0x00E00038);
1173 nvWriteGRAPH(pNv, 0x0754, 0x00000030);
1174 nvWriteGRAPH(pNv, 0x0750, 0x00E10038);
1175 nvWriteGRAPH(pNv, 0x0754, 0x00000030);
1179 /* begin nv20+ secondr surfaces */
1180 /* again, a copy of the surfaces. */
1181 if((pNv->Architecture < NV_ARCH_40) ||
1182 ((pNv->Chipset & 0xfff0) == CHIPSET_NV40))
1184 for(i = 0; i < 32; i++) {
1185 nvWriteGRAPH(pNv, 0x0900 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV10 + i*4));
1186 nvWriteGRAPH(pNv, 0x6900 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV10 + i*4));
1189 if(((pNv->Chipset & 0xfff0) == CHIPSET_G70) ||
1190 ((pNv->Chipset & 0xfff0) == CHIPSET_G71) ||
1191 ((pNv->Chipset & 0xfff0) == CHIPSET_G72) ||
1192 ((pNv->Chipset & 0xfff0) == CHIPSET_G73) ||
1193 ((pNv->Chipset & 0xfff0) == CHIPSET_C512))
1195 for(i = 0; i < 60; i++) {
1196 nvWriteGRAPH(pNv, 0x0D00 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV40 + i*4));
1197 nvWriteGRAPH(pNv, 0x6900 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV40 + i*4));
1200 for(i = 0; i < 48; i++) {
1201 nvWriteGRAPH(pNv, 0x0900 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV40 + i*4));
1202 if(((pNv->Chipset & 0xfff0) != CHIPSET_NV44) &&
1203 ((pNv->Chipset & 0xfff0) != CHIPSET_NV44A) &&
1204 ((pNv->Chipset & 0xfff0) != CHIPSET_C51))
1206 nvWriteGRAPH(pNv, 0x6900 + i*4, nvReadFB(pNv, NV_PFB_TILE_NV40 + i*4));
1211 /* end nv20+ second surfaces */
1213 /* begin RAM config */
1214 if(pNv->Architecture >= NV_ARCH_40) {
1215 if((pNv->Chipset & 0xfff0) == CHIPSET_NV40) {
1216 nvWriteGRAPH(pNv, 0x09A4, nvReadFB(pNv, NV_PFB_CFG0));
1217 nvWriteGRAPH(pNv, 0x09A8, nvReadFB(pNv, NV_PFB_CFG1));
1218 nvWriteGRAPH(pNv, 0x69A4, nvReadFB(pNv, NV_PFB_CFG0));
1219 nvWriteGRAPH(pNv, 0x69A8, nvReadFB(pNv, NV_PFB_CFG1));
1221 nvWriteGRAPH(pNv, 0x0820, 0);
1222 nvWriteGRAPH(pNv, 0x0824, 0);
1223 nvWriteGRAPH(pNv, 0x0864, pNv->VRAMPhysicalSize - 1);
1224 nvWriteGRAPH(pNv, 0x0868, pNv->VRAMPhysicalSize - 1);
1226 if(((pNv->Chipset & 0xfff0) == CHIPSET_G70) ||
1227 ((pNv->Chipset & 0xfff0) == CHIPSET_G71) ||
1228 ((pNv->Chipset & 0xfff0) == CHIPSET_G72) ||
1229 ((pNv->Chipset & 0xfff0) == CHIPSET_G73))
1231 nvWriteGRAPH(pNv, 0x0DF0, nvReadFB(pNv, NV_PFB_CFG0));
1232 nvWriteGRAPH(pNv, 0x0DF4, nvReadFB(pNv, NV_PFB_CFG1));
1234 nvWriteGRAPH(pNv, 0x09F0, nvReadFB(pNv, NV_PFB_CFG0));
1235 nvWriteGRAPH(pNv, 0x09F4, nvReadFB(pNv, NV_PFB_CFG1));
1237 nvWriteGRAPH(pNv, 0x69F0, nvReadFB(pNv, NV_PFB_CFG0));
1238 nvWriteGRAPH(pNv, 0x69F4, nvReadFB(pNv, NV_PFB_CFG1));
1240 nvWriteGRAPH(pNv, 0x0840, 0);
1241 nvWriteGRAPH(pNv, 0x0844, 0);
1242 nvWriteGRAPH(pNv, 0x08a0, pNv->VRAMPhysicalSize - 1);
1243 nvWriteGRAPH(pNv, 0x08a4, pNv->VRAMPhysicalSize - 1);
1246 nvWriteGRAPH(pNv, 0x09A4, nvReadFB(pNv, NV_PFB_CFG0));
1247 nvWriteGRAPH(pNv, 0x09A8, nvReadFB(pNv, NV_PFB_CFG1));
1248 nvWriteGRAPH(pNv, 0x0750, 0x00EA0000);
1249 nvWriteGRAPH(pNv, 0x0754, nvReadFB(pNv, NV_PFB_CFG0));
1250 nvWriteGRAPH(pNv, 0x0750, 0x00EA0004);
1251 nvWriteGRAPH(pNv, 0x0754, nvReadFB(pNv, NV_PFB_CFG1));
1253 nvWriteGRAPH(pNv, 0x0820, 0);
1254 nvWriteGRAPH(pNv, 0x0824, 0);
1255 nvWriteGRAPH(pNv, 0x0864, pNv->VRAMPhysicalSize - 1);
1256 nvWriteGRAPH(pNv, 0x0868, pNv->VRAMPhysicalSize - 1);
1258 /* end of RAM config */
1260 nvWriteGRAPH(pNv, 0x0B20, 0x00000000);
1261 nvWriteGRAPH(pNv, 0x0B04, 0xFFFFFFFF);
1265 /* begin clipping values */
1266 nvWriteGRAPH(pNv, 0x053C, 0);
1267 nvWriteGRAPH(pNv, 0x0540, 0);
1268 nvWriteGRAPH(pNv, 0x0544, 0x00007FFF);
1269 nvWriteGRAPH(pNv, 0x0548, 0x00007FFF);
1270 /* end of clipping values */
1272 if(pNv->Architecture >= NV_ARCH_10) {
1274 nvWriteCRTC(pNv, 0, NV_CRTC_HEAD_CONFIG, state->head);
1275 nvWriteCRTC(pNv, 1, NV_CRTC_HEAD_CONFIG, state->head2);
1277 temp = nvReadCurRAMDAC(pNv, NV_RAMDAC_0404);
1278 nvWriteCurRAMDAC(pNv, NV_RAMDAC_0404, temp | (1 << 25));
1280 nvWriteMC(pNv, 0x8704, 1);
1281 nvWriteMC(pNv, 0x8140, 0);
1282 nvWriteMC(pNv, 0x8920, 0);
1283 nvWriteMC(pNv, 0x8924, 0);
1284 nvWriteMC(pNv, 0x8908, pNv->VRAMPhysicalSize - 1);
1285 nvWriteMC(pNv, 0x890C, pNv->VRAMPhysicalSize - 1);
1286 nvWriteMC(pNv, 0x1588, 0);
1288 nvWriteCurCRTC(pNv, NV_CRTC_CURSOR_CONFIG, state->cursorConfig);
1289 nvWriteCurCRTC(pNv, NV_CRTC_0830, state->displayV - 3);
1290 nvWriteCurCRTC(pNv, NV_CRTC_0834, state->displayV - 1);
1292 if(pNv->FlatPanel) {
1293 if((pNv->Chipset & 0x0ff0) == CHIPSET_NV11) {
1294 nvWriteCurRAMDAC(pNv, NV_RAMDAC_DITHER_NV11, state->dither);
1297 nvWriteCurRAMDAC(pNv, NV_RAMDAC_FP_DITHER, state->dither);
1300 nvWriteVGA(pNv, 0x53, state->timingH);
1301 nvWriteVGA(pNv, 0x54, state->timingV);
1302 nvWriteVGA(pNv, 0x21, 0xfa);
1305 nvWriteVGA(pNv, 0x41, state->extra);
1308 nvWriteVGA(pNv, 0x19, state->repaint0);
1309 nvWriteVGA(pNv, 0x1A, state->repaint1);
1310 nvWriteVGA(pNv, 0x25, state->screen);
1311 nvWriteVGA(pNv, 0x28, state->pixel);
1312 nvWriteVGA(pNv, 0x2D, state->horiz);
1313 nvWriteVGA(pNv, 0x1C, state->fifo);
1314 nvWriteVGA(pNv, 0x1B, state->arbitration0);
1315 nvWriteVGA(pNv, 0x20, state->arbitration1);
1316 if(pNv->Architecture >= NV_ARCH_30) {
1317 nvWriteVGA(pNv, 0x47, state->arbitration1 >> 8);
1320 nvWriteVGA(pNv, 0x30, state->cursor0);
1321 nvWriteVGA(pNv, 0x31, state->cursor1);
1322 if(pNv->Architecture == NV_ARCH_40) { /* HW bug */
1323 volatile CARD32 curpos = nvReadCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS);
1324 nvWriteCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS, curpos);
1326 nvWriteVGA(pNv, 0x2F, state->cursor2);
1327 nvWriteVGA(pNv, 0x39, state->interlace);
1329 if(!pNv->FlatPanel) {
1330 nvWriteRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT, state->pllsel);
1331 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL, state->vpll);
1333 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2, state->vpll2);
1334 if(pNv->twoStagePLL) {
1335 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL_B, state->vpllB);
1336 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2_B, state->vpll2B);
1339 nvWriteCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL, state->scale);
1340 nvWriteCurRAMDAC(pNv, NV_RAMDAC_FP_HCRTC, state->crtcSync);
1342 nvWriteCurRAMDAC(pNv, NV_RAMDAC_GENERAL_CONTROL, state->general);
1344 nvWriteCurCRTC(pNv, NV_CRTC_INTR_EN_0, 0);
1345 nvWriteCurCRTC(pNv, NV_CRTC_INTR_0, NV_CRTC_INTR_VBLANK);
1347 pNv->CurrentState = state;
1350 void NVUnloadStateExt
1353 RIVA_HW_STATE *state
1356 state->repaint0 = nvReadVGA(pNv, 0x19);
1357 state->repaint1 = nvReadVGA(pNv, 0x1A);
1358 state->screen = nvReadVGA(pNv, 0x25);
1359 state->pixel = nvReadVGA(pNv, 0x28);
1360 state->horiz = nvReadVGA(pNv, 0x2D);
1361 state->fifo = nvReadVGA(pNv, 0x1C);
1362 state->arbitration0 = nvReadVGA(pNv, 0x1B);
1363 state->arbitration1 = nvReadVGA(pNv, 0x20);
1364 if(pNv->Architecture >= NV_ARCH_30) {
1365 state->arbitration1 |= (nvReadVGA(pNv, 0x47) & 1) << 8;
1367 state->cursor0 = nvReadVGA(pNv, 0x30);
1368 state->cursor1 = nvReadVGA(pNv, 0x31);
1369 state->cursor2 = nvReadVGA(pNv, 0x2F);
1370 state->interlace = nvReadVGA(pNv, 0x39);
1372 state->vpll = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL);
1374 state->vpll2 = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2);
1375 if(pNv->twoStagePLL) {
1376 state->vpllB = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL_B);
1377 state->vpll2B = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2_B);
1379 state->pllsel = nvReadRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT);
1380 state->general = nvReadCurRAMDAC(pNv, NV_RAMDAC_GENERAL_CONTROL);
1381 state->scale = nvReadCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL);
1382 state->config = nvReadFB(pNv, NV_PFB_CFG0);
1384 if(pNv->Architecture >= NV_ARCH_10) {
1386 state->head = nvReadCRTC(pNv, 0, NV_CRTC_HEAD_CONFIG);
1387 state->head2 = nvReadCRTC(pNv, 1, NV_CRTC_HEAD_CONFIG);
1388 state->crtcOwner = nvReadVGA(pNv, 0x44);
1390 state->extra = nvReadVGA(pNv, 0x41);
1392 state->cursorConfig = nvReadCurCRTC(pNv, NV_CRTC_CURSOR_CONFIG);
1394 if((pNv->Chipset & 0x0ff0) == CHIPSET_NV11) {
1395 state->dither = nvReadCurRAMDAC(pNv, NV_RAMDAC_DITHER_NV11);
1398 state->dither = nvReadCurRAMDAC(pNv, NV_RAMDAC_FP_DITHER);
1401 if(pNv->FlatPanel) {
1402 state->timingH = nvReadVGA(pNv, 0x53);
1403 state->timingV = nvReadVGA(pNv, 0x54);
1407 if(pNv->FlatPanel) {
1408 state->crtcSync = nvReadCurRAMDAC(pNv, NV_RAMDAC_FP_HCRTC);
1412 void NVSetStartAddress (
1417 nvWriteCurCRTC(pNv, NV_CRTC_START, start);