2 * Copyright 2006 Dave Airlie
3 * Copyright 2007 Maarten Maathuis
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * this code uses ideas taken from the NVIDIA nv driver - the nvidia license
26 * decleration is at the bottom of this file as it is rather ugly
41 #include "mipointer.h"
42 #include "windowstr.h"
44 #include <X11/extensions/render.h>
47 #include "nv_include.h"
51 #define CRTC_INDEX 0x3d4
52 #define CRTC_DATA 0x3d5
53 #define CRTC_IN_STAT_1 0x3da
55 #define WHITE_VALUE 0x3F
56 #define BLACK_VALUE 0x00
57 #define OVERSCAN_VALUE 0x01
59 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
60 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state, Bool override);
61 static void nv_crtc_load_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
62 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
63 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
64 static void nv_crtc_save_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
66 static uint8_t NVReadPVIO(xf86CrtcPtr crtc, uint32_t address)
68 ScrnInfoPtr pScrn = crtc->scrn;
69 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
70 NVPtr pNv = NVPTR(pScrn);
72 /* Only NV4x have two pvio ranges */
73 if (nv_crtc->head == 1 && pNv->Architecture == NV_ARCH_40) {
74 return NV_RD08(pNv->PVIO1, address);
76 return NV_RD08(pNv->PVIO0, address);
80 static void NVWritePVIO(xf86CrtcPtr crtc, uint32_t address, uint8_t value)
82 ScrnInfoPtr pScrn = crtc->scrn;
83 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
84 NVPtr pNv = NVPTR(pScrn);
86 /* Only NV4x have two pvio ranges */
87 if (nv_crtc->head == 1 && pNv->Architecture == NV_ARCH_40) {
88 NV_WR08(pNv->PVIO1, address, value);
90 NV_WR08(pNv->PVIO0, address, value);
94 static void NVWriteMiscOut(xf86CrtcPtr crtc, uint8_t value)
96 NVWritePVIO(crtc, VGA_MISC_OUT_W, value);
99 static uint8_t NVReadMiscOut(xf86CrtcPtr crtc)
101 return NVReadPVIO(crtc, VGA_MISC_OUT_R);
104 void NVWriteVGA(NVPtr pNv, int head, uint8_t index, uint8_t value)
106 volatile uint8_t *pCRTCReg = head ? pNv->PCIO1 : pNv->PCIO0;
108 #ifdef NOUVEAU_MODESET_TRACE
109 ErrorF("NVWriteVGA: idx %d data 0x%x head %d\n", index, value, head);
112 NV_WR08(pCRTCReg, CRTC_INDEX, index);
113 NV_WR08(pCRTCReg, CRTC_DATA, value);
116 uint8_t NVReadVGA(NVPtr pNv, int head, uint8_t index)
118 volatile uint8_t *pCRTCReg = head ? pNv->PCIO1 : pNv->PCIO0;
120 NV_WR08(pCRTCReg, CRTC_INDEX, index);
121 return NV_RD08(pCRTCReg, CRTC_DATA);
124 /* CR57 and CR58 are a fun pair of regs. CR57 provides an index (0-0xf) for CR58
125 * I suspect they in fact do nothing, but are merely a way to carry useful
126 * per-head variables around
130 * 0x00 index to the appropriate dcb entry (or 7f for inactive)
131 * 0x02 dcb entry's "or" value (or 00 for inactive)
132 * 0x03 bit0 set for dual link (LVDS, possibly elsewhere too)
133 * 0x08 or 0x09 pxclk in MHz
134 * 0x0f laptop panel info - low nibble for PEXTDEV_BOOT strap
135 * high nibble for xlat strap value
138 void NVWriteVGACR5758(NVPtr pNv, int head, uint8_t index, uint8_t value)
140 NVWriteVGA(pNv, head, 0x57, index);
141 NVWriteVGA(pNv, head, 0x58, value);
144 uint8_t NVReadVGACR5758(NVPtr pNv, int head, uint8_t index)
146 NVWriteVGA(pNv, head, 0x57, index);
147 return NVReadVGA(pNv, head, 0x58);
150 void NVWriteVgaCrtc(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
152 ScrnInfoPtr pScrn = crtc->scrn;
153 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
154 NVPtr pNv = NVPTR(pScrn);
156 NVWriteVGA(pNv, nv_crtc->head, index, value);
159 uint8_t NVReadVgaCrtc(xf86CrtcPtr crtc, uint8_t index)
161 ScrnInfoPtr pScrn = crtc->scrn;
162 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
163 NVPtr pNv = NVPTR(pScrn);
165 return NVReadVGA(pNv, nv_crtc->head, index);
168 static void NVWriteVgaSeq(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
170 NVWritePVIO(crtc, VGA_SEQ_INDEX, index);
171 NVWritePVIO(crtc, VGA_SEQ_DATA, value);
174 static uint8_t NVReadVgaSeq(xf86CrtcPtr crtc, uint8_t index)
176 NVWritePVIO(crtc, VGA_SEQ_INDEX, index);
177 return NVReadPVIO(crtc, VGA_SEQ_DATA);
180 static void NVWriteVgaGr(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
182 NVWritePVIO(crtc, VGA_GRAPH_INDEX, index);
183 NVWritePVIO(crtc, VGA_GRAPH_DATA, value);
186 static uint8_t NVReadVgaGr(xf86CrtcPtr crtc, uint8_t index)
188 NVWritePVIO(crtc, VGA_GRAPH_INDEX, index);
189 return NVReadPVIO(crtc, VGA_GRAPH_DATA);
193 static void NVWriteVgaAttr(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
195 ScrnInfoPtr pScrn = crtc->scrn;
196 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
197 NVPtr pNv = NVPTR(pScrn);
198 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
200 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
201 if (nv_crtc->paletteEnabled)
205 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
206 NV_WR08(pCRTCReg, VGA_ATTR_DATA_W, value);
209 static uint8_t NVReadVgaAttr(xf86CrtcPtr crtc, uint8_t index)
211 ScrnInfoPtr pScrn = crtc->scrn;
212 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
213 NVPtr pNv = NVPTR(pScrn);
214 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
216 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
217 if (nv_crtc->paletteEnabled)
221 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
222 return NV_RD08(pCRTCReg, VGA_ATTR_DATA_R);
225 void NVCrtcSetOwner(xf86CrtcPtr crtc)
227 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
228 ScrnInfoPtr pScrn = crtc->scrn;
229 NVPtr pNv = NVPTR(pScrn);
230 /* Non standard beheaviour required by NV11 */
232 uint8_t owner = NVReadVGA0(pNv, NV_VGA_CRTCX_OWNER);
233 ErrorF("pre-Owner: 0x%X\n", owner);
235 uint32_t pbus84 = nvReadMC(pNv, 0x1084);
236 ErrorF("pbus84: 0x%X\n", pbus84);
238 ErrorF("pbus84: 0x%X\n", pbus84);
239 nvWriteMC(pNv, 0x1084, pbus84);
241 /* The blob never writes owner to pcio1, so should we */
242 if (pNv->NVArch == 0x11) {
243 NVWriteVGA0(pNv, NV_VGA_CRTCX_OWNER, 0xff);
245 NVWriteVGA0(pNv, NV_VGA_CRTCX_OWNER, nv_crtc->head * 0x3);
246 owner = NVReadVGA0(pNv, NV_VGA_CRTCX_OWNER);
247 ErrorF("post-Owner: 0x%X\n", owner);
249 ErrorF("pNv pointer is NULL\n");
254 NVEnablePalette(xf86CrtcPtr crtc)
256 ScrnInfoPtr pScrn = crtc->scrn;
257 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
258 NVPtr pNv = NVPTR(pScrn);
259 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
261 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
262 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0);
263 nv_crtc->paletteEnabled = TRUE;
267 NVDisablePalette(xf86CrtcPtr crtc)
269 ScrnInfoPtr pScrn = crtc->scrn;
270 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
271 NVPtr pNv = NVPTR(pScrn);
272 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
274 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
275 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0x20);
276 nv_crtc->paletteEnabled = FALSE;
279 static void NVWriteVgaReg(xf86CrtcPtr crtc, uint32_t reg, uint8_t value)
281 ScrnInfoPtr pScrn = crtc->scrn;
282 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
283 NVPtr pNv = NVPTR(pScrn);
284 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
286 NV_WR08(pCRTCReg, reg, value);
289 /* perform a sequencer reset */
290 static void NVVgaSeqReset(xf86CrtcPtr crtc, Bool start)
293 NVWriteVgaSeq(crtc, 0x00, 0x1);
295 NVWriteVgaSeq(crtc, 0x00, 0x3);
298 static void NVVgaProtect(xf86CrtcPtr crtc, Bool on)
303 tmp = NVReadVgaSeq(crtc, 0x1);
304 NVVgaSeqReset(crtc, TRUE);
305 NVWriteVgaSeq(crtc, 0x01, tmp | 0x20);
307 NVEnablePalette(crtc);
310 * Reenable sequencer, then turn on screen.
312 tmp = NVReadVgaSeq(crtc, 0x1);
313 NVWriteVgaSeq(crtc, 0x01, tmp & ~0x20); /* reenable display */
314 NVVgaSeqReset(crtc, FALSE);
316 NVDisablePalette(crtc);
320 void NVCrtcLockUnlock(xf86CrtcPtr crtc, Bool Lock)
324 NVCrtcSetOwner(crtc);
326 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LOCK, Lock ? 0x99 : 0x57);
327 cr11 = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE);
328 if (Lock) cr11 |= 0x80;
330 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE, cr11);
334 NVGetOutputFromCRTC(xf86CrtcPtr crtc)
336 ScrnInfoPtr pScrn = crtc->scrn;
337 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
339 for (i = 0; i < xf86_config->num_output; i++) {
340 xf86OutputPtr output = xf86_config->output[i];
342 if (output->crtc == crtc) {
351 nv_find_crtc_by_index(ScrnInfoPtr pScrn, int index)
353 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
356 for (i = 0; i < xf86_config->num_crtc; i++) {
357 xf86CrtcPtr crtc = xf86_config->crtc[i];
358 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
359 if (nv_crtc->head == index)
367 * Calculate the Video Clock parameters for the PLL.
369 /* Code taken from NVClock, with permission of the author (being a GPL->MIT code transfer). */
372 CalculateVClkNV4x_SingleVCO(NVPtr pNv, struct pll_lims *pll_lim, uint32_t clockIn, uint32_t *n1_best, uint32_t *m1_best, uint32_t *p_best)
374 uint32_t clock, M, N, P;
375 uint32_t delta, bestDelta, minM, maxM, minN, maxN, maxP;
376 uint32_t minVCOInputFreq, minVCOFreq, maxVCOFreq;
378 uint32_t refClk = pNv->CrystalFreqKHz;
381 /* bios clocks are in MHz, we use KHz */
382 minVCOInputFreq = pll_lim->vco1.min_inputfreq*1000;
383 minVCOFreq = pll_lim->vco1.minfreq*1000;
384 maxVCOFreq = pll_lim->vco1.maxfreq*1000;
385 minM = pll_lim->vco1.min_m;
386 maxM = pll_lim->vco1.max_m;
387 minN = pll_lim->vco1.min_n;
388 maxN = pll_lim->vco1.max_n;
392 /* The optimal frequency for the PLL to work at is somewhere in the center of its range.
393 / Choose a post divider in such a way to achieve this.
394 / The G8x nv driver does something similar but they they derive a minP and maxP. That
395 / doesn't seem required as you get so many matching clocks that you don't enter a second
396 / iteration for P. (The minP / maxP values in the nv driver only differ at most 1, so it is for
397 / some rare corner cases.
399 for (P=0, VCOFreq=maxVCOFreq/2; clockIn<=VCOFreq && P <= maxP; P++)
404 /* Calculate the m and n values. There are a lot of values which give the same speed;
405 / We choose the speed for which the difference with the request speed is as small as possible.
407 for (M=minM; M<=maxM; M++)
409 /* The VCO has a minimum input frequency */
410 if ((refClk/M) < minVCOInputFreq)
413 for (N=minN; N<=maxN; N++)
415 /* Calculate the frequency generated by VCO1 */
416 clock = (int)(refClk * N / (float)M);
418 /* Verify if the clock lies within the output limits of VCO1 */
419 if (clock < minVCOFreq)
421 else if (clock > maxVCOFreq) /* It is no use to continue as the clock will only become higher */
425 delta = abs((int)(clockIn - clock));
426 /* When the difference is 0 or less than .5% accept the speed */
427 if (((delta == 0) || ((float)delta/(float)clockIn <= 0.005)))
435 /* When the new difference is smaller than the old one, use this one */
436 if (delta < bestDelta)
448 CalculateVClkNV4x_DoubleVCO(NVPtr pNv, struct pll_lims *pll_lim, uint32_t clockIn, uint32_t *n1_best, uint32_t *n2_best, uint32_t *m1_best, uint32_t *m2_best, uint32_t *p_best)
450 uint32_t clock1, clock2, M, M2, N, N2, P;
451 uint32_t delta, bestDelta, minM, minM2, maxM, maxM2, minN, minN2, maxN, maxN2, maxP;
452 uint32_t minVCOInputFreq, minVCO2InputFreq, maxVCO2InputFreq, minVCOFreq, minVCO2Freq, maxVCOFreq, maxVCO2Freq;
453 uint32_t VCO2Freq, maxClock;
454 uint32_t refClk = pNv->CrystalFreqKHz;
457 /* bios clocks are in MHz, we use KHz */
458 minVCOInputFreq = pll_lim->vco1.min_inputfreq*1000;
459 minVCOFreq = pll_lim->vco1.minfreq*1000;
460 maxVCOFreq = pll_lim->vco1.maxfreq*1000;
461 minM = pll_lim->vco1.min_m;
462 maxM = pll_lim->vco1.max_m;
463 minN = pll_lim->vco1.min_n;
464 maxN = pll_lim->vco1.max_n;
466 minVCO2InputFreq = pll_lim->vco2.min_inputfreq*1000;
467 maxVCO2InputFreq = pll_lim->vco2.max_inputfreq*1000;
468 minVCO2Freq = pll_lim->vco2.minfreq*1000;
469 maxVCO2Freq = pll_lim->vco2.maxfreq*1000;
470 minM2 = pll_lim->vco2.min_m;
471 maxM2 = pll_lim->vco2.max_m;
472 minN2 = pll_lim->vco2.min_n;
473 maxN2 = pll_lim->vco2.max_n;
477 maxClock = maxVCO2Freq;
478 /* If the requested clock is behind the bios limits, try it anyway */
479 if (clockIn > maxVCO2Freq)
480 maxClock = clockIn + clockIn/200; /* Add a .5% margin */
482 /* The optimal frequency for the PLL to work at is somewhere in the center of its range.
483 / Choose a post divider in such a way to achieve this.
484 / The G8x nv driver does something similar but they they derive a minP and maxP. That
485 / doesn't seem required as you get so many matching clocks that you don't enter a second
486 / iteration for P. (The minP / maxP values in the nv driver only differ at most 1, so it is for
487 / some rare corner cases.
489 for (P=0, VCO2Freq=maxClock/2; clockIn<=VCO2Freq && P <= maxP; P++)
494 /* The PLLs on Geforce6/7 hardware can operate in a single stage made with only 1 VCO
495 / and a cascade mode of two VCOs. This second mode is in general used for relatively high
496 / frequencies. The loop below calculates the divider and multiplier ratios for the cascade
497 / mode. The code takes into account limits defined in the video bios.
499 for (M=minM; M<=maxM; M++)
501 /* The VCO has a minimum input frequency */
502 if ((refClk/M) < minVCOInputFreq)
505 for (N=minN; N<=maxN; N++)
507 /* Calculate the frequency generated by VCO1 */
508 clock1 = (int)(refClk * N / (float)M);
509 /* Verify if the clock lies within the output limits of VCO1 */
510 if ( (clock1 < minVCOFreq) )
512 else if (clock1 > maxVCOFreq) /* For future N, the clock will only increase so stop; xorg nv continues but that is useless */
515 for (M2=minM2; M2<=maxM2; M2++)
517 /* The clock fed to the second VCO needs to lie within a certain input range */
518 if (clock1 / M2 < minVCO2InputFreq)
520 else if (clock1 / M2 > maxVCO2InputFreq)
523 N2 = (int)((float)((clockIn << P) * M * M2) / (float)(refClk * N)+.5);
524 if( (N2 < minN2) || (N2 > maxN2) )
527 /* The clock before being fed to the post-divider needs to lie within a certain range.
528 / Further there are some limits on N2/M2.
530 clock2 = (int)((float)(N*N2)/(M*M2) * refClk);
531 if( (clock2 < minVCO2Freq) || (clock2 > maxClock))// || ((N2 / M2) < 4) || ((N2 / M2) > 10) )
534 /* The post-divider delays the 'high' clock to create a low clock if requested.
535 / This post-divider exists because the VCOs can only generate frequencies within
536 / a limited frequency range. This range has been tuned to lie around half of its max
537 / input frequency. It tries to calculate all clocks (including lower ones) around this
538 / 'center' frequency.
541 delta = abs((int)(clockIn - clock2));
543 /* When the difference is 0 or less than .5% accept the speed */
544 if (((delta == 0) || ((float)delta/(float)clockIn <= 0.005)))
554 /* When the new difference is smaller than the old one, use this one */
555 if (delta < bestDelta)
569 /* BIG NOTE: modifying vpll1 and vpll2 does not work, what bit is the switch to allow it? */
571 /* Even though they are not yet used, i'm adding some notes about some of the 0x4000 regs */
572 /* They are only valid for NV4x, appearantly reordered for NV5x */
573 /* gpu pll: 0x4000 + 0x4004
574 * unknown pll: 0x4008 + 0x400c
575 * vpll1: 0x4010 + 0x4014
576 * vpll2: 0x4018 + 0x401c
577 * unknown pll: 0x4020 + 0x4024
578 * unknown pll: 0x4038 + 0x403c
579 * Some of the unknown's are probably memory pll's.
580 * The vpll's use two set's of multipliers and dividers. I refer to them as a and b.
581 * 1 and 2 refer to the registers of each pair. There is only one post divider.
582 * Logic: clock = reference_clock * ((n(a) * n(b))/(m(a) * m(b))) >> p
583 * 1) bit 0-7: familiar values, but redirected from were? (similar to PLL_SETUP_CONTROL)
584 * bit8: A switch that turns of the second divider and multiplier off.
585 * bit12: Also a switch, i haven't seen it yet.
586 * bit16-19: p-divider
587 * but 28-31: Something related to the mode that is used (see bit8).
588 * 2) bit0-7: m-divider (a)
589 * bit8-15: n-multiplier (a)
590 * bit16-23: m-divider (b)
591 * bit24-31: n-multiplier (b)
594 /* Modifying the gpu pll for example requires:
595 * - Disable value 0x333 (inverse AND mask) on the 0xc040 register.
596 * This is not needed for the vpll's which have their own bits.
602 uint32_t requested_clock,
603 uint32_t *given_clock,
611 NVPtr pNv = NVPTR(pScrn);
612 struct pll_lims pll_lim;
613 /* We have 2 mulitpliers, 2 dividers and one post divider */
614 /* Note that p is only 3 bits */
615 uint32_t m1_best = 0, m2_best = 0, n1_best = 0, n2_best = 0, p_best = 0;
616 uint32_t special_bits = 0;
619 if (!get_pll_limits(pScrn, VPLL1, &pll_lim))
622 if (!get_pll_limits(pScrn, VPLL2, &pll_lim))
625 if (requested_clock < pll_lim.vco1.maxfreq*1000 && pNv->NVArch > 0x40) { /* single VCO */
627 /* Turn the second set of divider and multiplier off */
628 /* Bogus data, the same nvidia uses */
631 CalculateVClkNV4x_SingleVCO(pNv, &pll_lim, requested_clock, &n1_best, &m1_best, &p_best);
632 } else { /* dual VCO */
634 CalculateVClkNV4x_DoubleVCO(pNv, &pll_lim, requested_clock, &n1_best, &n2_best, &m1_best, &m2_best, &p_best);
637 /* Are this all (relevant) G70 cards? */
638 if (pNv->NVArch == 0x4B || pNv->NVArch == 0x46 || pNv->NVArch == 0x47 || pNv->NVArch == 0x49) {
639 /* This is a big guess, but should be reasonable until we can narrow it down. */
647 /* What exactly are the purpose of the upper 2 bits of pll_a and pll_b? */
648 *pll_a = (special_bits << 30) | (p_best << 16) | (n1_best << 8) | (m1_best << 0);
649 /* This VCO2 bit is an educated guess, but it needs to stay on for NV4x. */
650 *pll_b = NV31_RAMDAC_ENABLE_VCO2 | (n2_best << 8) | (m2_best << 0);
654 *reg580 |= NV_RAMDAC_580_VPLL1_ACTIVE;
656 *reg580 |= NV_RAMDAC_580_VPLL2_ACTIVE;
660 *reg580 &= ~NV_RAMDAC_580_VPLL1_ACTIVE;
662 *reg580 &= ~NV_RAMDAC_580_VPLL2_ACTIVE;
667 ErrorF("vpll: n1 %d m1 %d p %d db1_ratio %d\n", n1_best, m1_best, p_best, *db1_ratio);
669 ErrorF("vpll: n1 %d n2 %d m1 %d m2 %d p %d db1_ratio %d\n", n1_best, n2_best, m1_best, m2_best, p_best, *db1_ratio);
673 static void nv40_crtc_save_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
675 state->vpll1_a = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL);
676 state->vpll1_b = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL_B);
677 state->vpll2_a = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2);
678 state->vpll2_b = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2_B);
679 state->pllsel = nvReadRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT);
680 state->sel_clk = nvReadRAMDAC0(pNv, NV_RAMDAC_SEL_CLK);
681 state->reg580 = nvReadRAMDAC0(pNv, NV_RAMDAC_580);
682 state->reg594 = nvReadRAMDAC0(pNv, NV_RAMDAC_594);
685 static void nv40_crtc_load_state_pll(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
687 ScrnInfoPtr pScrn = crtc->scrn;
688 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
689 NVPtr pNv = NVPTR(pScrn);
690 uint32_t fp_debug_0[2];
692 fp_debug_0[0] = nvReadRAMDAC(pNv, 0, NV_RAMDAC_FP_DEBUG_0);
693 fp_debug_0[1] = nvReadRAMDAC(pNv, 1, NV_RAMDAC_FP_DEBUG_0);
695 uint32_t reg_c040_old = nvReadMC(pNv, 0xc040);
697 /* The TMDS_PLL switch is on the actual ramdac */
698 if (state->crosswired) {
701 ErrorF("Crosswired pll state load\n");
707 if (state->vpll2_b && state->vpll_changed[1]) {
708 nvWriteRAMDAC(pNv, index[1], NV_RAMDAC_FP_DEBUG_0,
709 fp_debug_0[index[1]] | NV_RAMDAC_FP_DEBUG_0_PWRDOWN_TMDS_PLL);
711 /* Wait for the situation to stabilise */
714 uint32_t reg_c040 = pNv->misc_info.reg_c040;
715 /* for vpll2 change bits 18 and 19 are disabled */
716 reg_c040 &= ~(0x3 << 18);
717 nvWriteMC(pNv, 0xc040, reg_c040);
719 ErrorF("writing vpll2_a %08X\n", state->vpll2_a);
720 ErrorF("writing vpll2_b %08X\n", state->vpll2_b);
722 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2, state->vpll2_a);
723 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2_B, state->vpll2_b);
725 ErrorF("writing pllsel %08X\n", state->pllsel);
726 /* Don't turn vpll1 off. */
727 nvWriteRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT, state->pllsel);
729 nvWriteRAMDAC0(pNv, NV_RAMDAC_580, state->reg580);
730 ErrorF("writing reg580 %08X\n", state->reg580);
732 /* We need to wait a while */
734 nvWriteMC(pNv, 0xc040, pNv->misc_info.reg_c040);
736 nvWriteRAMDAC(pNv, index[1], NV_RAMDAC_FP_DEBUG_0, fp_debug_0[index[1]]);
738 /* Wait for the situation to stabilise */
742 if (state->vpll1_b && state->vpll_changed[0]) {
743 nvWriteRAMDAC(pNv, index[0], NV_RAMDAC_FP_DEBUG_0,
744 fp_debug_0[index[0]] | NV_RAMDAC_FP_DEBUG_0_PWRDOWN_TMDS_PLL);
746 /* Wait for the situation to stabilise */
749 uint32_t reg_c040 = pNv->misc_info.reg_c040;
750 /* for vpll2 change bits 16 and 17 are disabled */
751 reg_c040 &= ~(0x3 << 16);
752 nvWriteMC(pNv, 0xc040, reg_c040);
754 ErrorF("writing vpll1_a %08X\n", state->vpll1_a);
755 ErrorF("writing vpll1_b %08X\n", state->vpll1_b);
757 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL, state->vpll1_a);
758 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL_B, state->vpll1_b);
760 ErrorF("writing pllsel %08X\n", state->pllsel);
761 nvWriteRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT, state->pllsel);
763 nvWriteRAMDAC0(pNv, NV_RAMDAC_580, state->reg580);
764 ErrorF("writing reg580 %08X\n", state->reg580);
766 /* We need to wait a while */
768 nvWriteMC(pNv, 0xc040, pNv->misc_info.reg_c040);
770 nvWriteRAMDAC(pNv, index[0], NV_RAMDAC_FP_DEBUG_0, fp_debug_0[index[0]]);
772 /* Wait for the situation to stabilise */
776 /* Let's be sure not to wake up any crtc's from dpms. */
777 /* But we do want to keep our newly set crtc awake. */
778 if (nv_crtc->head == 1) {
779 nvWriteMC(pNv, 0xc040, reg_c040_old | (pNv->misc_info.reg_c040 & (0x3 << 18)));
781 nvWriteMC(pNv, 0xc040, reg_c040_old | (pNv->misc_info.reg_c040 & (0x3 << 16)));
784 ErrorF("writing sel_clk %08X\n", state->sel_clk);
785 nvWriteRAMDAC0(pNv, NV_RAMDAC_SEL_CLK, state->sel_clk);
787 ErrorF("writing reg594 %08X\n", state->reg594);
788 nvWriteRAMDAC0(pNv, NV_RAMDAC_594, state->reg594);
790 /* All clocks have been set at this point. */
791 state->vpll_changed[0] = FALSE;
792 state->vpll_changed[1] = FALSE;
795 static void nv_crtc_save_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
797 state->vpll1_a = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL);
799 state->vpll2_a = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2);
801 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
802 state->vpll1_b = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL_B);
803 state->vpll2_b = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2_B);
805 state->pllsel = nvReadRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT);
806 state->sel_clk = nvReadRAMDAC0(pNv, NV_RAMDAC_SEL_CLK);
810 static void nv_crtc_load_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
812 /* This sequence is important, the NV28 is very sensitive in this area. */
813 /* Keep pllsel last and sel_clk first. */
814 ErrorF("writing sel_clk %08X\n", state->sel_clk);
815 nvWriteRAMDAC0(pNv, NV_RAMDAC_SEL_CLK, state->sel_clk);
817 if (state->vpll2_a && state->vpll_changed[1]) {
819 ErrorF("writing vpll2_a %08X\n", state->vpll2_a);
820 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2, state->vpll2_a);
822 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
823 ErrorF("writing vpll2_b %08X\n", state->vpll2_b);
824 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2_B, state->vpll2_b);
828 if (state->vpll1_a && state->vpll_changed[0]) {
829 ErrorF("writing vpll1_a %08X\n", state->vpll1_a);
830 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL, state->vpll1_a);
831 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
832 ErrorF("writing vpll1_b %08X\n", state->vpll1_b);
833 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL_B, state->vpll1_b);
837 ErrorF("writing pllsel %08X\n", state->pllsel);
838 nvWriteRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT, state->pllsel);
840 /* All clocks have been set at this point. */
841 state->vpll_changed[0] = FALSE;
842 state->vpll_changed[1] = FALSE;
845 #define IS_NV44P (pNv->NVArch >= 0x44 ? 1 : 0)
846 #define SEL_CLK_OFFSET (nv_get_sel_clk_offset(pNv->NVArch, nv_output->bus))
848 #define WIPE_OTHER_CLOCKS(_sel_clk, _head, _bus) (nv_wipe_other_clocks(_sel_clk, pNv->NVArch, _head, _bus))
851 * Calculate extended mode parameters (SVGA) and save in a
852 * mode state structure.
853 * State is not specific to a single crtc, but shared.
855 void nv_crtc_calc_state_ext(
858 int DisplayWidth, /* Does this change after setting the mode? */
865 ScrnInfoPtr pScrn = crtc->scrn;
866 uint32_t pixelDepth, VClk = 0;
867 uint32_t CursorStart;
868 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
869 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
871 NVPtr pNv = NVPTR(pScrn);
872 RIVA_HW_STATE *state;
873 int num_crtc_enabled, i;
874 uint32_t old_clock_a = 0, old_clock_b = 0;
876 state = &pNv->ModeReg;
878 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
880 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
881 NVOutputPrivatePtr nv_output = NULL;
883 nv_output = output->driver_private;
886 /* Store old clock. */
887 if (nv_crtc->head == 1) {
888 old_clock_a = state->vpll2_a;
889 old_clock_b = state->vpll2_b;
891 old_clock_a = state->vpll1_a;
892 old_clock_b = state->vpll1_b;
896 * Extended RIVA registers.
898 pixelDepth = (bpp + 1)/8;
899 if (pNv->Architecture == NV_ARCH_40) {
900 /* Does register 0x580 already have a value? */
901 if (!state->reg580) {
902 state->reg580 = pNv->misc_info.ramdac_0_reg_580;
904 if (nv_crtc->head == 1) {
905 CalculateVClkNV4x(pScrn, dotClock, &VClk, &state->vpll2_a, &state->vpll2_b, &state->reg580, &state->db1_ratio[1], FALSE);
907 CalculateVClkNV4x(pScrn, dotClock, &VClk, &state->vpll1_a, &state->vpll1_b, &state->reg580, &state->db1_ratio[0], TRUE);
909 } else if (pNv->twoStagePLL) {
910 struct pll_lims pll_lim;
912 get_pll_limits(pScrn, 0, &pll_lim);
913 VClk = getMNP_double(pScrn, &pll_lim, dotClock, &NM1, &NM2, &log2P);
914 if (pNv->NVArch == 0x30) {
915 /* See nvregisters.xml for details. */
916 state->pll = log2P << 16 | NM1 | (NM2 & 7) << 4 | ((NM2 >> 8) & 7) << 19 | ((NM2 >> 11) & 3) << 24 | NV30_RAMDAC_ENABLE_VCO2;
918 state->pll = log2P << 16 | NM1;
919 state->pllB = NV31_RAMDAC_ENABLE_VCO2 | NM2;
923 VClk = getMNP_single(pScrn, dotClock, &NM, &log2P);
924 state->pll = log2P << 16 | NM;
927 if (pNv->Architecture < NV_ARCH_40) {
928 if (nv_crtc->head == 1) {
929 state->vpll2_a = state->pll;
930 state->vpll2_b = state->pllB;
932 state->vpll1_a = state->pll;
933 state->vpll1_b = state->pllB;
937 if (nv_crtc->head == 1) {
938 state->vpll_changed[1] = ((state->vpll2_a == old_clock_a) && (state->vpll2_b == old_clock_b)) ? FALSE : TRUE;
940 state->vpll_changed[0] = ((state->vpll1_a == old_clock_a) && (state->vpll1_b == old_clock_b)) ? FALSE : TRUE;
943 switch (pNv->Architecture) {
945 nv4UpdateArbitrationSettings(VClk,
947 &(state->arbitration0),
948 &(state->arbitration1),
950 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x00;
951 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = 0xbC;
952 if (flags & V_DBLSCAN)
953 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
954 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = 0x00000000;
955 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2 | NV_RAMDAC_PLL_SELECT_PLL_SOURCE_ALL;
956 state->config = 0x00001114;
957 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
963 if (((pNv->Chipset & 0xfff0) == CHIPSET_C51) ||
964 ((pNv->Chipset & 0xfff0) == CHIPSET_C512)) {
965 state->arbitration0 = 128;
966 state->arbitration1 = 0x0480;
967 } else if (((pNv->Chipset & 0xffff) == CHIPSET_NFORCE) ||
968 ((pNv->Chipset & 0xffff) == CHIPSET_NFORCE2)) {
969 nForceUpdateArbitrationSettings(VClk,
971 &(state->arbitration0),
972 &(state->arbitration1),
974 } else if (pNv->Architecture < NV_ARCH_30) {
975 nv10UpdateArbitrationSettings(VClk,
977 &(state->arbitration0),
978 &(state->arbitration1),
981 nv30UpdateArbitrationSettings(pNv,
982 &(state->arbitration0),
983 &(state->arbitration1));
986 if (nv_crtc->head == 1) {
987 CursorStart = pNv->Cursor2->offset;
989 CursorStart = pNv->Cursor->offset;
992 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x80 | (CursorStart >> 17);
993 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = (CursorStart >> 11) << 2;
994 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = CursorStart >> 24;
996 if (flags & V_DBLSCAN)
997 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
999 state->config = nvReadFB(pNv, NV_PFB_CFG0);
1000 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
1004 /* okay do we have 2 CRTCs running ? */
1005 num_crtc_enabled = 0;
1006 for (i = 0; i < xf86_config->num_crtc; i++) {
1007 if (xf86_config->crtc[i]->enabled) {
1012 ErrorF("There are %d CRTC's enabled\n", num_crtc_enabled);
1014 /* The main stuff seems to be valid for NV3x also. */
1015 if (pNv->Architecture >= NV_ARCH_30) {
1016 /* This register is only used on the primary ramdac */
1017 /* This seems to be needed to select the proper clocks, otherwise bad things happen */
1019 if (!state->sel_clk)
1020 state->sel_clk = pNv->misc_info.sel_clk & ~(0xf << 16);
1022 if (output && (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS)) {
1023 /* Only wipe when are a relevant (digital) output. */
1024 state->sel_clk &= ~(0xf << 16);
1025 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1026 /* Even with two dvi, this should not conflict. */
1027 if (crossed_clocks) {
1028 state->sel_clk |= (0x1 << 16);
1030 state->sel_clk |= (0x4 << 16);
1034 /* Some cards, specifically dual dvi/lvds cards set another bitrange.
1035 * I suspect inverse beheaviour to the normal bitrange, but i am not a 100% certain about this.
1036 * This is all based on default settings found in mmio-traces.
1037 * The blob never changes these, as it doesn't run unusual output configurations.
1038 * It seems to prefer situations that avoid changing these bits (for a good reason?).
1039 * I still don't know the purpose of value 2, it's similar to 4, but what exactly does it do?
1044 * bit 0 NVClk spread spectrum on/off
1045 * bit 2 MemClk spread spectrum on/off
1046 * bit 4 PixClk1 spread spectrum on/off
1047 * bit 6 PixClk2 spread spectrum on/off
1050 * what causes setting of bits not obvious but:
1051 * bits 4&5 relate to headA
1052 * bits 6&7 relate to headB
1054 /* Only let digital outputs mess with this, otherwise strange output routings may mess it up. */
1055 if (output && (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS)) {
1056 if (pNv->Architecture == NV_ARCH_40) {
1057 for (i = 0; i < 4; i++) {
1058 uint32_t var = (state->sel_clk & (0xf << 4*i)) >> 4*i;
1059 if (var == 0x1 || var == 0x4) {
1060 state->sel_clk &= ~(0xf << 4*i);
1061 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1062 if (crossed_clocks) {
1063 state->sel_clk |= (0x4 << 4*i);
1065 state->sel_clk |= (0x1 << 4*i);
1067 break; /* This should only occur once. */
1070 /* Based on NV31M. */
1071 } else if (pNv->Architecture == NV_ARCH_30) {
1072 for (i = 0; i < 4; i++) {
1073 uint32_t var = (state->sel_clk & (0xf << 4*i)) >> 4*i;
1074 if (var == 0x4 || var == 0x5) {
1075 state->sel_clk &= ~(0xf << 4*i);
1076 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1077 if (crossed_clocks) {
1078 state->sel_clk |= (0x4 << 4*i);
1080 state->sel_clk |= (0x5 << 4*i);
1082 break; /* This should only occur once. */
1088 /* Are we crosswired? */
1089 if (output && nv_crtc->head != nv_output->preferred_output) {
1090 state->crosswired = TRUE;
1092 state->crosswired = FALSE;
1095 if (nv_crtc->head == 1) {
1096 if (state->db1_ratio[1])
1097 ErrorF("We are a lover of the DB1 VCLK ratio\n");
1098 } else if (nv_crtc->head == 0) {
1099 if (state->db1_ratio[0])
1100 ErrorF("We are a lover of the DB1 VCLK ratio\n");
1103 /* Do NV1x/NV2x cards need anything in sel_clk? */
1104 state->sel_clk = 0x0;
1105 state->crosswired = FALSE;
1108 /* The NV40 seems to have more similarities to NV3x than other cards. */
1109 if (pNv->NVArch < 0x41) {
1110 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_NVPLL;
1111 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_MPLL;
1114 if (nv_crtc->head == 1) {
1115 if (!state->db1_ratio[1]) {
1116 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK2_RATIO_DB2;
1118 state->pllsel &= ~NV_RAMDAC_PLL_SELECT_VCLK2_RATIO_DB2;
1120 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_VPLL2;
1122 if (!state->db1_ratio[0]) {
1123 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2;
1125 state->pllsel &= ~NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2;
1127 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_VPLL;
1130 /* The blob uses this always, so let's do the same */
1131 if (pNv->Architecture == NV_ARCH_40) {
1132 state->pllsel |= NV_RAMDAC_PLL_SELECT_USE_VPLL2_TRUE;
1135 /* The primary output resource doesn't seem to care */
1136 if (output && pNv->Architecture == NV_ARCH_40 && nv_output->output_resource == 1) { /* This is the "output" */
1137 /* non-zero values are for analog, don't know about tv-out and the likes */
1138 if (output && nv_output->type != OUTPUT_ANALOG) {
1139 state->reg594 = 0x0;
1140 } else if (output) {
1141 /* Are we a flexible output? */
1142 if (ffs(pNv->dcb_table.entry[nv_output->dcb_entry].or) & OUTPUT_0) {
1143 state->reg594 = 0x1;
1144 pNv->restricted_mode = FALSE;
1146 state->reg594 = 0x0;
1147 pNv->restricted_mode = TRUE;
1150 /* More values exist, but they seem related to the 3rd dac (tv-out?) somehow */
1151 /* bit 16-19 are bits that are set on some G70 cards */
1152 /* Those bits are also set to the 3rd OUTPUT register */
1153 if (nv_crtc->head == 1) {
1154 state->reg594 |= 0x100;
1159 regp->CRTC[NV_VGA_CRTCX_FIFO0] = state->arbitration0;
1160 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = state->arbitration1 & 0xff;
1161 if (pNv->Architecture >= NV_ARCH_30) {
1162 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = state->arbitration1 >> 8;
1165 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = (((DisplayWidth/8) * pixelDepth) & 0x700) >> 3;
1166 regp->CRTC[NV_VGA_CRTCX_PIXEL] = (pixelDepth > 2) ? 3 : pixelDepth;
1170 nv_crtc_dpms(xf86CrtcPtr crtc, int mode)
1172 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1174 ErrorF("nv_crtc_dpms is called for CRTC %d with mode %d\n", nv_crtc->head, mode);
1176 if (nv_crtc->last_dpms == mode) /* Don't do unnecesary mode changes. */
1179 nv_crtc->last_dpms = mode;
1181 ScrnInfoPtr pScrn = crtc->scrn;
1182 NVPtr pNv = NVPTR(pScrn);
1183 unsigned char seq1 = 0, crtc17 = 0;
1184 unsigned char crtc1A;
1186 NVCrtcSetOwner(crtc);
1188 crtc1A = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1) & ~0xC0;
1190 case DPMSModeStandby:
1191 /* Screen: Off; HSync: Off, VSync: On -- Not Supported */
1196 case DPMSModeSuspend:
1197 /* Screen: Off; HSync: On, VSync: Off -- Not Supported */
1203 /* Screen: Off; HSync: Off, VSync: Off */
1210 /* Screen: On; HSync: On, VSync: On */
1216 NVVgaSeqReset(crtc, TRUE);
1217 /* Each head has it's own sequencer, so we can turn it off when we want */
1218 seq1 |= (NVReadVgaSeq(crtc, 0x01) & ~0x20);
1219 NVWriteVgaSeq(crtc, 0x1, seq1);
1220 crtc17 |= (NVReadVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL) & ~0x80);
1222 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL, crtc17);
1223 NVVgaSeqReset(crtc, FALSE);
1225 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, crtc1A);
1227 /* We can completely disable a vpll if the crtc is off. */
1228 if (pNv->Architecture == NV_ARCH_40) {
1229 uint32_t reg_c040_old = nvReadMC(pNv, 0xc040);
1230 if (mode == DPMSModeOn) {
1231 nvWriteMC(pNv, 0xc040, reg_c040_old | (pNv->misc_info.reg_c040 & (0x3 << (16 + 2*nv_crtc->head))));
1233 nvWriteMC(pNv, 0xc040, reg_c040_old & ~(pNv->misc_info.reg_c040 & (0x3 << (16 + 2*nv_crtc->head))));
1237 /* I hope this is the right place */
1238 if (crtc->enabled && mode == DPMSModeOn) {
1239 pNv->crtc_active[nv_crtc->head] = TRUE;
1241 pNv->crtc_active[nv_crtc->head] = FALSE;
1246 nv_crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
1247 DisplayModePtr adjusted_mode)
1249 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1250 ErrorF("nv_crtc_mode_fixup is called for CRTC %d\n", nv_crtc->head);
1256 nv_crtc_mode_set_vga(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1258 ScrnInfoPtr pScrn = crtc->scrn;
1259 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1261 NVPtr pNv = NVPTR(pScrn);
1262 NVFBLayout *pLayout = &pNv->CurrentLayout;
1263 int depth = pScrn->depth;
1265 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1267 /* Calculate our timings */
1268 int horizDisplay = (mode->CrtcHDisplay >> 3) - 1;
1269 int horizStart = (mode->CrtcHSyncStart >> 3) - 1;
1270 int horizEnd = (mode->CrtcHSyncEnd >> 3) - 1;
1271 int horizTotal = (mode->CrtcHTotal >> 3) - 5;
1272 int horizBlankStart = (mode->CrtcHDisplay >> 3) - 1;
1273 int horizBlankEnd = (mode->CrtcHTotal >> 3) - 1;
1274 int vertDisplay = mode->CrtcVDisplay - 1;
1275 int vertStart = mode->CrtcVSyncStart - 1;
1276 int vertEnd = mode->CrtcVSyncEnd - 1;
1277 int vertTotal = mode->CrtcVTotal - 2;
1278 int vertBlankStart = mode->CrtcVDisplay - 1;
1279 int vertBlankEnd = mode->CrtcVTotal - 1;
1283 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1284 NVOutputPrivatePtr nv_output = NULL;
1286 nv_output = output->driver_private;
1288 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1292 ErrorF("Mode clock: %d\n", mode->Clock);
1293 ErrorF("Adjusted mode clock: %d\n", adjusted_mode->Clock);
1295 /* Reverted to what nv did, because that works for all resolutions on flatpanels */
1297 vertStart = vertTotal - 3;
1298 vertEnd = vertTotal - 2;
1299 vertBlankStart = vertStart;
1300 horizStart = horizTotal - 5;
1301 horizEnd = horizTotal - 2;
1302 horizBlankEnd = horizTotal + 4;
1303 if (pNv->overlayAdaptor) {
1304 /* This reportedly works around Xv some overlay bandwidth problems*/
1309 if(mode->Flags & V_INTERLACE)
1312 ErrorF("horizDisplay: 0x%X \n", horizDisplay);
1313 ErrorF("horizStart: 0x%X \n", horizStart);
1314 ErrorF("horizEnd: 0x%X \n", horizEnd);
1315 ErrorF("horizTotal: 0x%X \n", horizTotal);
1316 ErrorF("horizBlankStart: 0x%X \n", horizBlankStart);
1317 ErrorF("horizBlankEnd: 0x%X \n", horizBlankEnd);
1318 ErrorF("vertDisplay: 0x%X \n", vertDisplay);
1319 ErrorF("vertStart: 0x%X \n", vertStart);
1320 ErrorF("vertEnd: 0x%X \n", vertEnd);
1321 ErrorF("vertTotal: 0x%X \n", vertTotal);
1322 ErrorF("vertBlankStart: 0x%X \n", vertBlankStart);
1323 ErrorF("vertBlankEnd: 0x%X \n", vertBlankEnd);
1326 * compute correct Hsync & Vsync polarity
1328 if ((mode->Flags & (V_PHSYNC | V_NHSYNC))
1329 && (mode->Flags & (V_PVSYNC | V_NVSYNC))) {
1331 regp->MiscOutReg = 0x23;
1332 if (mode->Flags & V_NHSYNC) regp->MiscOutReg |= 0x40;
1333 if (mode->Flags & V_NVSYNC) regp->MiscOutReg |= 0x80;
1335 int VDisplay = mode->VDisplay;
1336 if (mode->Flags & V_DBLSCAN)
1338 if (mode->VScan > 1)
1339 VDisplay *= mode->VScan;
1340 if (VDisplay < 400) {
1341 regp->MiscOutReg = 0xA3; /* +hsync -vsync */
1342 } else if (VDisplay < 480) {
1343 regp->MiscOutReg = 0x63; /* -hsync +vsync */
1344 } else if (VDisplay < 768) {
1345 regp->MiscOutReg = 0xE3; /* -hsync -vsync */
1347 regp->MiscOutReg = 0x23; /* +hsync +vsync */
1351 regp->MiscOutReg |= (mode->ClockIndex & 0x03) << 2;
1357 regp->Sequencer[0] = 0x02;
1359 regp->Sequencer[0] = 0x00;
1361 /* 0x20 disables the sequencer */
1362 if (mode->Flags & V_CLKDIV2) {
1363 regp->Sequencer[1] = 0x29;
1365 regp->Sequencer[1] = 0x21;
1368 regp->Sequencer[2] = 1 << BIT_PLANE;
1370 regp->Sequencer[2] = 0x0F;
1371 regp->Sequencer[3] = 0x00; /* Font select */
1374 regp->Sequencer[4] = 0x06; /* Misc */
1376 regp->Sequencer[4] = 0x0E; /* Misc */
1382 regp->CRTC[NV_VGA_CRTCX_HTOTAL] = Set8Bits(horizTotal);
1383 regp->CRTC[NV_VGA_CRTCX_HDISPE] = Set8Bits(horizDisplay);
1384 regp->CRTC[NV_VGA_CRTCX_HBLANKS] = Set8Bits(horizBlankStart);
1385 regp->CRTC[NV_VGA_CRTCX_HBLANKE] = SetBitField(horizBlankEnd,4:0,4:0)
1387 regp->CRTC[NV_VGA_CRTCX_HSYNCS] = Set8Bits(horizStart);
1388 regp->CRTC[NV_VGA_CRTCX_HSYNCE] = SetBitField(horizBlankEnd,5:5,7:7)
1389 | SetBitField(horizEnd,4:0,4:0);
1390 regp->CRTC[NV_VGA_CRTCX_VTOTAL] = SetBitField(vertTotal,7:0,7:0);
1391 regp->CRTC[NV_VGA_CRTCX_OVERFLOW] = SetBitField(vertTotal,8:8,0:0)
1392 | SetBitField(vertDisplay,8:8,1:1)
1393 | SetBitField(vertStart,8:8,2:2)
1394 | SetBitField(vertBlankStart,8:8,3:3)
1396 | SetBitField(vertTotal,9:9,5:5)
1397 | SetBitField(vertDisplay,9:9,6:6)
1398 | SetBitField(vertStart,9:9,7:7);
1399 regp->CRTC[NV_VGA_CRTCX_PRROWSCN] = 0x00;
1400 regp->CRTC[NV_VGA_CRTCX_MAXSCLIN] = SetBitField(vertBlankStart,9:9,5:5)
1402 | ((mode->Flags & V_DBLSCAN) ? 0x80 : 0x00);
1403 regp->CRTC[NV_VGA_CRTCX_VGACURCTRL] = 0x00;
1404 regp->CRTC[0xb] = 0x00;
1405 regp->CRTC[NV_VGA_CRTCX_FBSTADDH] = 0x00;
1406 regp->CRTC[NV_VGA_CRTCX_FBSTADDL] = 0x00;
1407 regp->CRTC[0xe] = 0x00;
1408 regp->CRTC[0xf] = 0x00;
1409 regp->CRTC[NV_VGA_CRTCX_VSYNCS] = Set8Bits(vertStart);
1410 regp->CRTC[NV_VGA_CRTCX_VSYNCE] = SetBitField(vertEnd,3:0,3:0) | SetBit(5);
1411 regp->CRTC[NV_VGA_CRTCX_VDISPE] = Set8Bits(vertDisplay);
1412 regp->CRTC[0x14] = 0x00;
1413 regp->CRTC[NV_VGA_CRTCX_PITCHL] = ((pScrn->displayWidth/8)*(pLayout->bitsPerPixel/8));
1414 regp->CRTC[NV_VGA_CRTCX_VBLANKS] = Set8Bits(vertBlankStart);
1415 regp->CRTC[NV_VGA_CRTCX_VBLANKE] = Set8Bits(vertBlankEnd);
1416 /* 0x80 enables the sequencer, we don't want that */
1418 regp->CRTC[NV_VGA_CRTCX_MODECTL] = 0xE3 & ~0x80;
1420 regp->CRTC[NV_VGA_CRTCX_MODECTL] = 0xC3 & ~0x80;
1422 regp->CRTC[NV_VGA_CRTCX_LINECOMP] = 0xff;
1425 * Some extended CRTC registers (they are not saved with the rest of the vga regs).
1428 regp->CRTC[NV_VGA_CRTCX_LSR] = SetBitField(horizBlankEnd,6:6,4:4)
1429 | SetBitField(vertBlankStart,10:10,3:3)
1430 | SetBitField(vertStart,10:10,2:2)
1431 | SetBitField(vertDisplay,10:10,1:1)
1432 | SetBitField(vertTotal,10:10,0:0);
1434 regp->CRTC[NV_VGA_CRTCX_HEB] = SetBitField(horizTotal,8:8,0:0)
1435 | SetBitField(horizDisplay,8:8,1:1)
1436 | SetBitField(horizBlankStart,8:8,2:2)
1437 | SetBitField(horizStart,8:8,3:3);
1439 regp->CRTC[NV_VGA_CRTCX_EXTRA] = SetBitField(vertTotal,11:11,0:0)
1440 | SetBitField(vertDisplay,11:11,2:2)
1441 | SetBitField(vertStart,11:11,4:4)
1442 | SetBitField(vertBlankStart,11:11,6:6);
1444 if(mode->Flags & V_INTERLACE) {
1445 horizTotal = (horizTotal >> 1) & ~1;
1446 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = Set8Bits(horizTotal);
1447 regp->CRTC[NV_VGA_CRTCX_HEB] |= SetBitField(horizTotal,8:8,4:4);
1449 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = 0xff; /* interlace off */
1453 * Theory resumes here....
1457 * Graphics Display Controller
1459 regp->Graphics[0] = 0x00;
1460 regp->Graphics[1] = 0x00;
1461 regp->Graphics[2] = 0x00;
1462 regp->Graphics[3] = 0x00;
1464 regp->Graphics[4] = BIT_PLANE;
1465 regp->Graphics[5] = 0x00;
1467 regp->Graphics[4] = 0x00;
1469 regp->Graphics[5] = 0x02;
1471 regp->Graphics[5] = 0x40;
1474 regp->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
1475 regp->Graphics[7] = 0x0F;
1476 regp->Graphics[8] = 0xFF;
1478 /* I ditched the mono stuff */
1479 regp->Attribute[0] = 0x00; /* standard colormap translation */
1480 regp->Attribute[1] = 0x01;
1481 regp->Attribute[2] = 0x02;
1482 regp->Attribute[3] = 0x03;
1483 regp->Attribute[4] = 0x04;
1484 regp->Attribute[5] = 0x05;
1485 regp->Attribute[6] = 0x06;
1486 regp->Attribute[7] = 0x07;
1487 regp->Attribute[8] = 0x08;
1488 regp->Attribute[9] = 0x09;
1489 regp->Attribute[10] = 0x0A;
1490 regp->Attribute[11] = 0x0B;
1491 regp->Attribute[12] = 0x0C;
1492 regp->Attribute[13] = 0x0D;
1493 regp->Attribute[14] = 0x0E;
1494 regp->Attribute[15] = 0x0F;
1495 /* These two below are non-vga */
1496 regp->Attribute[16] = 0x01;
1497 regp->Attribute[17] = 0x00;
1498 regp->Attribute[18] = 0x0F;
1499 regp->Attribute[19] = 0x00;
1500 regp->Attribute[20] = 0x00;
1503 #define MAX_H_VALUE(i) ((0x1ff + i) << 3)
1504 #define MAX_V_VALUE(i) ((0xfff + i) << 0)
1507 * Sets up registers for the given mode/adjusted_mode pair.
1509 * The clocks, CRTCs and outputs attached to this CRTC must be off.
1511 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
1512 * be easily turned on/off after this.
1515 nv_crtc_mode_set_regs(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1517 ScrnInfoPtr pScrn = crtc->scrn;
1518 NVPtr pNv = NVPTR(pScrn);
1519 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1520 NVFBLayout *pLayout = &pNv->CurrentLayout;
1521 NVCrtcRegPtr regp, savep;
1524 Bool is_lvds = FALSE;
1526 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1527 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
1529 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1530 NVOutputPrivatePtr nv_output = NULL;
1532 nv_output = output->driver_private;
1534 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1537 if (nv_output->type == OUTPUT_LVDS)
1541 /* Registers not directly related to the (s)vga mode */
1543 /* bit2 = 0 -> fine pitched crtc granularity */
1544 /* The rest disables double buffering on CRTC access */
1545 regp->CRTC[NV_VGA_CRTCX_BUFFER] = 0xfa;
1547 if (savep->CRTC[NV_VGA_CRTCX_LCD] <= 0xb) {
1548 /* Common values are 0x0, 0x3, 0x8, 0xb, see logic below */
1549 if (nv_crtc->head == 0) {
1550 regp->CRTC[NV_VGA_CRTCX_LCD] = (1 << 3);
1554 regp->CRTC[NV_VGA_CRTCX_LCD] |= (1 << 0) | (1 << 1);
1557 /* Let's keep any abnormal value there may be, like 0x54 or 0x79 */
1558 regp->CRTC[NV_VGA_CRTCX_LCD] = savep->CRTC[NV_VGA_CRTCX_LCD];
1561 /* Sometimes 0x10 is used, what is this? */
1562 regp->CRTC[NV_VGA_CRTCX_59] = 0x0;
1563 /* Some kind of tmds switch for older cards */
1564 if (pNv->Architecture < NV_ARCH_40) {
1565 regp->CRTC[NV_VGA_CRTCX_59] |= 0x1;
1569 * Initialize DAC palette.
1570 * Will only be written when depth != 8.
1572 for (i = 0; i < 256; i++) {
1574 regp->DAC[(i*3)+1] = i;
1575 regp->DAC[(i*3)+2] = i;
1579 * Calculate the extended registers.
1582 if(pLayout->depth < 24) {
1588 /* What is the meaning of this register? */
1589 /* A few popular values are 0x18, 0x1c, 0x38, 0x3c */
1590 regp->CRTC[NV_VGA_CRTCX_FIFO1] = savep->CRTC[NV_VGA_CRTCX_FIFO1] & ~(1<<5);
1592 /* NV40's don't set FPP units, unless in special conditions (then they set both) */
1593 /* But what are those special conditions? */
1594 if (pNv->Architecture <= NV_ARCH_30) {
1596 if(nv_crtc->head == 1) {
1597 regp->head |= NV_CRTC_FSEL_FPP1;
1598 } else if (pNv->twoHeads) {
1599 regp->head |= NV_CRTC_FSEL_FPP2;
1603 /* Most G70 cards have FPP2 set on the secondary CRTC. */
1604 if (nv_crtc->head == 1 && pNv->NVArch > 0x44) {
1605 regp->head |= NV_CRTC_FSEL_FPP2;
1609 /* Except for rare conditions I2C is enabled on the primary crtc */
1610 if (nv_crtc->head == 0) {
1611 if (pNv->overlayAdaptor) {
1612 regp->head |= NV_CRTC_FSEL_OVERLAY;
1614 regp->head |= NV_CRTC_FSEL_I2C;
1617 /* This is not what nv does, but it is what the blob does (for nv4x at least) */
1618 /* This fixes my cursor corruption issue */
1619 regp->cursorConfig = 0x0;
1620 if(mode->Flags & V_DBLSCAN)
1621 regp->cursorConfig |= (1 << 4);
1622 if (pNv->alphaCursor) {
1623 /* bit28 means we go into alpha blend mode and not rely on the current ROP */
1624 regp->cursorConfig |= 0x14011000;
1626 regp->cursorConfig |= 0x02000000;
1629 /* Unblock some timings */
1630 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = 0;
1631 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = 0;
1633 /* What is the purpose of this register? */
1634 /* 0x14 may be disabled? */
1635 regp->CRTC[NV_VGA_CRTCX_26] = 0x20;
1637 /* 0x00 is disabled, 0x11 is lvds, 0x22 crt and 0x88 tmds */
1639 regp->CRTC[NV_VGA_CRTCX_3B] = 0x11;
1641 regp->CRTC[NV_VGA_CRTCX_3B] = 0x88;
1643 regp->CRTC[NV_VGA_CRTCX_3B] = 0x22;
1646 /* These values seem to vary */
1647 /* This register seems to be used by the bios to make certain decisions on some G70 cards? */
1648 regp->CRTC[NV_VGA_CRTCX_3C] = savep->CRTC[NV_VGA_CRTCX_3C];
1650 /* 0x80 seems to be used very often, if not always */
1651 regp->CRTC[NV_VGA_CRTCX_45] = 0x80;
1653 /* Some cards have 0x41 instead of 0x1 (for crtc 0), it doesn't hurt to just use the old value. */
1654 regp->CRTC[NV_VGA_CRTCX_4B] = savep->CRTC[NV_VGA_CRTCX_4B];
1657 regp->CRTC[NV_VGA_CRTCX_4B] |= 0x80;
1659 /* The blob seems to take the current value from crtc 0, add 4 to that and reuse the old value for crtc 1*/
1660 if (nv_crtc->head == 1) {
1661 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52;
1663 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52 + 4;
1666 /* The exact purpose of this register is unknown, but we copy value from crtc0 */
1667 regp->unk81c = nvReadCRTC0(pNv, NV_CRTC_081C);
1669 regp->unk830 = mode->CrtcVDisplay - 3;
1670 regp->unk834 = mode->CrtcVDisplay - 1;
1672 /* This is what the blob does */
1673 regp->unk850 = nvReadCRTC(pNv, 0, NV_CRTC_0850);
1675 /* Never ever modify gpio, unless you know very well what you're doing */
1676 regp->gpio = nvReadCRTC(pNv, 0, NV_CRTC_GPIO);
1678 /* Switch to non-vga mode (the so called HSYNC mode) */
1681 /* Some misc regs */
1682 regp->CRTC[NV_VGA_CRTCX_43] = 0x1;
1683 if (pNv->Architecture == NV_ARCH_40) {
1684 regp->CRTC[NV_VGA_CRTCX_85] = 0xFF;
1685 regp->CRTC[NV_VGA_CRTCX_86] = 0x1;
1689 * Calculate the state that is common to all crtc's (stored in the state struct).
1691 ErrorF("crtc %d %d %d\n", nv_crtc->head, mode->CrtcHDisplay, pScrn->displayWidth);
1692 nv_crtc_calc_state_ext(crtc,
1694 pScrn->displayWidth,
1697 adjusted_mode->Clock,
1700 /* Enable slaved mode */
1702 regp->CRTC[NV_VGA_CRTCX_PIXEL] |= (1 << 7);
1707 nv_crtc_mode_set_ramdac_regs(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1709 ScrnInfoPtr pScrn = crtc->scrn;
1710 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1711 NVCrtcRegPtr regp, savep;
1712 NVPtr pNv = NVPTR(pScrn);
1713 NVFBLayout *pLayout = &pNv->CurrentLayout;
1715 Bool is_lvds = FALSE;
1716 float aspect_ratio, panel_ratio;
1717 uint32_t h_scale, v_scale;
1719 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1720 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
1722 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1723 NVOutputPrivatePtr nv_output = NULL;
1725 nv_output = output->driver_private;
1727 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1730 if (nv_output->type == OUTPUT_LVDS)
1735 regp->fp_horiz_regs[REG_DISP_END] = adjusted_mode->HDisplay - 1;
1736 regp->fp_horiz_regs[REG_DISP_TOTAL] = adjusted_mode->HTotal - 1;
1737 /* This is what the blob does. */
1738 regp->fp_horiz_regs[REG_DISP_CRTC] = adjusted_mode->HSyncStart - 75 - 1;
1739 regp->fp_horiz_regs[REG_DISP_SYNC_START] = adjusted_mode->HSyncStart - 1;
1740 regp->fp_horiz_regs[REG_DISP_SYNC_END] = adjusted_mode->HSyncEnd - 1;
1741 regp->fp_horiz_regs[REG_DISP_VALID_START] = adjusted_mode->HSkew;
1742 regp->fp_horiz_regs[REG_DISP_VALID_END] = adjusted_mode->HDisplay - 1;
1744 regp->fp_vert_regs[REG_DISP_END] = adjusted_mode->VDisplay - 1;
1745 regp->fp_vert_regs[REG_DISP_TOTAL] = adjusted_mode->VTotal - 1;
1746 /* This is what the blob does. */
1747 regp->fp_vert_regs[REG_DISP_CRTC] = adjusted_mode->VTotal - 5 - 1;
1748 regp->fp_vert_regs[REG_DISP_SYNC_START] = adjusted_mode->VSyncStart - 1;
1749 regp->fp_vert_regs[REG_DISP_SYNC_END] = adjusted_mode->VSyncEnd - 1;
1750 regp->fp_vert_regs[REG_DISP_VALID_START] = 0;
1751 regp->fp_vert_regs[REG_DISP_VALID_END] = adjusted_mode->VDisplay - 1;
1753 /* Quirks, maybe move them somewere else? */
1755 switch(pNv->NVArch) {
1756 case 0x46: /* 7300GO */
1757 /* Only native mode needed, is there some logic to this? */
1758 if (mode->HDisplay == 1280 && mode->VDisplay == 800) {
1759 regp->fp_horiz_regs[REG_DISP_CRTC] = 0x4c6;
1767 ErrorF("Horizontal:\n");
1768 ErrorF("REG_DISP_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_END]);
1769 ErrorF("REG_DISP_TOTAL: 0x%X\n", regp->fp_horiz_regs[REG_DISP_TOTAL]);
1770 ErrorF("REG_DISP_CRTC: 0x%X\n", regp->fp_horiz_regs[REG_DISP_CRTC]);
1771 ErrorF("REG_DISP_SYNC_START: 0x%X\n", regp->fp_horiz_regs[REG_DISP_SYNC_START]);
1772 ErrorF("REG_DISP_SYNC_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_SYNC_END]);
1773 ErrorF("REG_DISP_VALID_START: 0x%X\n", regp->fp_horiz_regs[REG_DISP_VALID_START]);
1774 ErrorF("REG_DISP_VALID_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_VALID_END]);
1776 ErrorF("Vertical:\n");
1777 ErrorF("REG_DISP_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_END]);
1778 ErrorF("REG_DISP_TOTAL: 0x%X\n", regp->fp_vert_regs[REG_DISP_TOTAL]);
1779 ErrorF("REG_DISP_CRTC: 0x%X\n", regp->fp_vert_regs[REG_DISP_CRTC]);
1780 ErrorF("REG_DISP_SYNC_START: 0x%X\n", regp->fp_vert_regs[REG_DISP_SYNC_START]);
1781 ErrorF("REG_DISP_SYNC_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_SYNC_END]);
1782 ErrorF("REG_DISP_VALID_START: 0x%X\n", regp->fp_vert_regs[REG_DISP_VALID_START]);
1783 ErrorF("REG_DISP_VALID_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_VALID_END]);
1787 * bit0: positive vsync
1788 * bit4: positive hsync
1789 * bit8: enable center mode
1790 * bit9: enable native mode
1791 * bit26: a bit sometimes seen on some g70 cards
1792 * bit31: set for dual link LVDS
1793 * nv10reg contains a few more things, but i don't quite get what it all means.
1796 if (pNv->Architecture >= NV_ARCH_30) {
1797 regp->fp_control = 0x01100000;
1799 regp->fp_control = 0x00000000;
1803 regp->fp_control |= (1 << 28);
1805 regp->fp_control |= (2 << 28);
1806 if (pNv->Architecture < NV_ARCH_30)
1807 regp->fp_control |= (1 << 24);
1810 /* Some 7300GO cards get a quad view if this bit is set, even though they are duallink. */
1811 /* This was seen on 2 cards. */
1812 if (is_lvds && pNv->VBIOS.fp.dual_link && pNv->NVArch != 0x46) {
1813 regp->fp_control |= (8 << 28);
1816 /* If the special bit exists, it exists on both ramdac's */
1817 regp->fp_control |= nvReadRAMDAC0(pNv, NV_RAMDAC_FP_CONTROL) & (1 << 26);
1820 if (nv_output->scaling_mode == SCALE_PANEL) { /* panel needs to scale */
1821 regp->fp_control |= NV_RAMDAC_FP_CONTROL_MODE_CENTER;
1822 /* This is also true for panel scaling, so we must put the panel scale check first */
1823 } else if (mode->Clock == adjusted_mode->Clock) { /* native mode */
1824 regp->fp_control |= NV_RAMDAC_FP_CONTROL_MODE_NATIVE;
1825 } else { /* gpu needs to scale */
1826 regp->fp_control |= NV_RAMDAC_FP_CONTROL_MODE_SCALE;
1830 /* Deal with vsync/hsync polarity */
1831 /* LVDS screens don't set this. */
1832 if (is_fp && !is_lvds) {
1833 if (adjusted_mode->Flags & V_PVSYNC) {
1834 regp->fp_control |= NV_RAMDAC_FP_CONTROL_VSYNC_POS;
1837 if (adjusted_mode->Flags & V_PHSYNC) {
1838 regp->fp_control |= NV_RAMDAC_FP_CONTROL_HSYNC_POS;
1840 } else if (!is_lvds) {
1841 /* The blob doesn't always do this, but often */
1842 regp->fp_control |= NV_RAMDAC_FP_CONTROL_VSYNC_DISABLE;
1843 regp->fp_control |= NV_RAMDAC_FP_CONTROL_HSYNC_DISABLE;
1847 ErrorF("Pre-panel scaling\n");
1848 ErrorF("panel-size:%dx%d\n", nv_output->fpWidth, nv_output->fpHeight);
1849 panel_ratio = (nv_output->fpWidth)/(float)(nv_output->fpHeight);
1850 ErrorF("panel_ratio=%f\n", panel_ratio);
1851 aspect_ratio = (mode->HDisplay)/(float)(mode->VDisplay);
1852 ErrorF("aspect_ratio=%f\n", aspect_ratio);
1853 /* Scale factors is the so called 20.12 format, taken from Haiku */
1854 h_scale = ((1 << 12) * mode->HDisplay)/nv_output->fpWidth;
1855 v_scale = ((1 << 12) * mode->VDisplay)/nv_output->fpHeight;
1856 ErrorF("h_scale=%d\n", h_scale);
1857 ErrorF("v_scale=%d\n", v_scale);
1859 /* This can override HTOTAL and VTOTAL */
1862 /* We want automatic scaling */
1865 regp->fp_hvalid_start = 0;
1866 regp->fp_hvalid_end = (nv_output->fpWidth - 1);
1868 regp->fp_vvalid_start = 0;
1869 regp->fp_vvalid_end = (nv_output->fpHeight - 1);
1871 /* 0 = panel scaling */
1872 if (nv_output->scaling_mode == SCALE_PANEL) {
1873 ErrorF("Flat panel is doing the scaling.\n");
1875 ErrorF("GPU is doing the scaling.\n");
1877 if (nv_output->scaling_mode == SCALE_ASPECT) {
1878 /* GPU scaling happens automaticly at a ratio of 1.33 */
1879 /* A 1280x1024 panel has a ratio of 1.25, we don't want to scale that at 4:3 resolutions */
1880 if (h_scale != (1 << 12) && (panel_ratio > (aspect_ratio + 0.10))) {
1883 ErrorF("Scaling resolution on a widescreen panel\n");
1885 /* Scaling in both directions needs to the same */
1888 /* Set a new horizontal scale factor and enable testmode (bit12) */
1889 regp->debug_1 = ((h_scale >> 1) & 0xfff) | (1 << 12);
1891 diff = nv_output->fpWidth - (((1 << 12) * mode->HDisplay)/h_scale);
1892 regp->fp_hvalid_start = diff/2;
1893 regp->fp_hvalid_end = nv_output->fpWidth - (diff/2) - 1;
1896 /* Same scaling, just for panels with aspect ratio's smaller than 1 */
1897 if (v_scale != (1 << 12) && (panel_ratio < (aspect_ratio - 0.10))) {
1900 ErrorF("Scaling resolution on a portrait panel\n");
1902 /* Scaling in both directions needs to the same */
1905 /* Set a new vertical scale factor and enable testmode (bit28) */
1906 regp->debug_1 = (((v_scale >> 1) & 0xfff) << 16) | (1 << (12 + 16));
1908 diff = nv_output->fpHeight - (((1 << 12) * mode->VDisplay)/v_scale);
1909 regp->fp_vvalid_start = diff/2;
1910 regp->fp_vvalid_end = nv_output->fpHeight - (diff/2) - 1;
1915 ErrorF("Post-panel scaling\n");
1918 if (pNv->Architecture >= NV_ARCH_10) {
1919 /* Bios and blob don't seem to do anything (else) */
1920 regp->nv10_cursync = (1<<25);
1923 /* These are the common blob values, minus a few fp specific bit's */
1924 /* Let's keep the TMDS pll and fpclock running in all situations */
1925 regp->debug_0 = 0x1101100;
1927 if (is_fp && nv_output->scaling_mode != SCALE_NOSCALE) {
1928 regp->debug_0 |= NV_RAMDAC_FP_DEBUG_0_XSCALE_ENABLED;
1929 regp->debug_0 |= NV_RAMDAC_FP_DEBUG_0_YSCALE_ENABLED;
1930 } else if (is_fp) { /* no_scale mode, so we must center it */
1933 diff = nv_output->fpWidth - mode->HDisplay;
1934 regp->fp_hvalid_start = diff/2;
1935 regp->fp_hvalid_end = (nv_output->fpWidth - diff/2 - 1);
1937 diff = nv_output->fpHeight - mode->VDisplay;
1938 regp->fp_vvalid_start = diff/2;
1939 regp->fp_vvalid_end = (nv_output->fpHeight - diff/2 - 1);
1942 /* Is this crtc bound or output bound? */
1943 /* Does the bios TMDS script try to change this sometimes? */
1945 /* I am not completely certain, but seems to be set only for dfp's */
1946 regp->debug_0 |= NV_RAMDAC_FP_DEBUG_0_TMDS_ENABLED;
1950 ErrorF("output %d debug_0 %08X\n", nv_output->output_resource, regp->debug_0);
1952 /* Flatpanel support needs at least a NV10 */
1953 if (pNv->twoHeads) {
1954 /* The blob does this differently. */
1955 /* TODO: Find out what precisely and why. */
1956 /* Let's not destroy any bits that were already present. */
1957 if (pNv->FPDither || (is_lvds && pNv->VBIOS.fp.if_is_18bit)) {
1958 if (pNv->NVArch == 0x11) {
1959 regp->dither = savep->dither | 0x00010000;
1961 regp->dither = savep->dither | 0x00000001;
1964 regp->dither = savep->dither;
1968 /* Kindly borrowed from haiku driver */
1969 /* bit4 and bit5 activate indirect mode trough color palette */
1970 switch (pLayout->depth) {
1973 regp->general = 0x00101130;
1977 regp->general = 0x00100130;
1981 regp->general = 0x00101100;
1985 if (pNv->alphaCursor) {
1986 /* PIPE_LONG mode, something to do with the size of the cursor? */
1987 regp->general |= (1<<29);
1990 /* Some values the blob sets */
1991 /* This may apply to the real ramdac that is being used (for crosswired situations) */
1992 /* Nevertheless, it's unlikely to cause many problems, since the values are equal for both */
1993 regp->unk_a20 = 0x0;
1994 regp->unk_a24 = 0xfffff;
1995 regp->unk_a34 = 0x1;
1999 * Sets up registers for the given mode/adjusted_mode pair.
2001 * The clocks, CRTCs and outputs attached to this CRTC must be off.
2003 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
2004 * be easily turned on/off after this.
2007 nv_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
2008 DisplayModePtr adjusted_mode,
2011 ScrnInfoPtr pScrn = crtc->scrn;
2012 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2013 NVPtr pNv = NVPTR(pScrn);
2014 NVFBLayout *pLayout = &pNv->CurrentLayout;
2016 ErrorF("nv_crtc_mode_set is called for CRTC %d\n", nv_crtc->head);
2018 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode on CRTC %d\n", nv_crtc->head);
2019 xf86PrintModeline(pScrn->scrnIndex, mode);
2020 NVCrtcSetOwner(crtc);
2022 nv_crtc_mode_set_vga(crtc, mode, adjusted_mode);
2023 nv_crtc_mode_set_regs(crtc, mode, adjusted_mode);
2024 nv_crtc_mode_set_ramdac_regs(crtc, mode, adjusted_mode);
2026 NVVgaProtect(crtc, TRUE);
2027 nv_crtc_load_state_ramdac(crtc, &pNv->ModeReg);
2028 nv_crtc_load_state_ext(crtc, &pNv->ModeReg, FALSE);
2029 if (pLayout->depth != 8)
2030 NVCrtcLoadPalette(crtc);
2031 nv_crtc_load_state_vga(crtc, &pNv->ModeReg);
2032 if (pNv->Architecture == NV_ARCH_40) {
2033 nv40_crtc_load_state_pll(crtc, &pNv->ModeReg);
2035 nv_crtc_load_state_pll(pNv, &pNv->ModeReg);
2038 NVVgaProtect(crtc, FALSE);
2040 NVCrtcSetBase(crtc, x, y);
2042 #if X_BYTE_ORDER == X_BIG_ENDIAN
2043 /* turn on LFB swapping */
2047 tmp = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING);
2049 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING, tmp);
2054 /* This functions generates data that is not saved, but still is needed. */
2055 void nv_crtc_restore_generate(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2057 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2058 ScrnInfoPtr pScrn = crtc->scrn;
2059 NVPtr pNv = NVPTR(pScrn);
2061 NVCrtcRegPtr regp = &state->crtc_reg[nv_crtc->head];
2063 /* It's a good idea to also save a default palette on shutdown. */
2064 for (i = 0; i < 256; i++) {
2066 regp->DAC[(i*3)+1] = i;
2067 regp->DAC[(i*3)+2] = i;
2070 /* Noticed that reading this variable is problematic on one card. */
2071 if (pNv->NVArch == 0x11)
2072 state->sel_clk = 0x0;
2075 void nv_crtc_save(xf86CrtcPtr crtc)
2077 ScrnInfoPtr pScrn = crtc->scrn;
2078 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2079 NVPtr pNv = NVPTR(pScrn);
2081 ErrorF("nv_crtc_save is called for CRTC %d\n", nv_crtc->head);
2083 /* We just came back from terminal, so unlock */
2084 NVCrtcLockUnlock(crtc, FALSE);
2086 NVCrtcSetOwner(crtc);
2087 nv_crtc_save_state_ramdac(crtc, &pNv->SavedReg);
2088 nv_crtc_save_state_vga(crtc, &pNv->SavedReg);
2089 nv_crtc_save_state_ext(crtc, &pNv->SavedReg);
2090 if (pNv->Architecture == NV_ARCH_40) {
2091 nv40_crtc_save_state_pll(pNv, &pNv->SavedReg);
2093 nv_crtc_save_state_pll(pNv, &pNv->SavedReg);
2097 void nv_crtc_restore(xf86CrtcPtr crtc)
2099 ScrnInfoPtr pScrn = crtc->scrn;
2100 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2101 NVPtr pNv = NVPTR(pScrn);
2102 RIVA_HW_STATE *state;
2105 state = &pNv->SavedReg;
2106 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
2108 ErrorF("nv_crtc_restore is called for CRTC %d\n", nv_crtc->head);
2110 NVCrtcSetOwner(crtc);
2112 /* Just to be safe */
2113 NVCrtcLockUnlock(crtc, FALSE);
2115 NVVgaProtect(crtc, TRUE);
2116 nv_crtc_restore_generate(crtc, &pNv->SavedReg);
2117 nv_crtc_load_state_ramdac(crtc, &pNv->SavedReg);
2118 nv_crtc_load_state_ext(crtc, &pNv->SavedReg, TRUE);
2119 if (savep->general & 0x30) /* Palette mode */
2120 NVCrtcLoadPalette(crtc);
2121 nv_crtc_load_state_vga(crtc, &pNv->SavedReg);
2123 /* Force restoring pll's. */
2124 state->vpll_changed[0] = TRUE;
2125 state->vpll_changed[1] = TRUE;
2127 if (pNv->Architecture == NV_ARCH_40) {
2128 nv40_crtc_load_state_pll(crtc, &pNv->SavedReg);
2130 nv_crtc_load_state_pll(pNv, &pNv->SavedReg);
2132 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
2133 NVVgaProtect(crtc, FALSE);
2135 nv_crtc->last_dpms = NV_DPMS_CLEARED;
2139 NVResetCrtcConfig(xf86CrtcPtr crtc, Bool set)
2141 ScrnInfoPtr pScrn = crtc->scrn;
2142 NVPtr pNv = NVPTR(pScrn);
2145 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2150 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
2154 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL, val);
2157 void nv_crtc_prepare(xf86CrtcPtr crtc)
2159 ScrnInfoPtr pScrn = crtc->scrn;
2160 NVPtr pNv = NVPTR(pScrn);
2161 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2163 ErrorF("nv_crtc_prepare is called for CRTC %d\n", nv_crtc->head);
2166 NVCrtcLockUnlock(crtc, 0);
2168 NVResetCrtcConfig(crtc, FALSE);
2170 crtc->funcs->dpms(crtc, DPMSModeOff);
2172 /* Sync the engine before adjust mode */
2173 if (pNv->EXADriverPtr) {
2174 exaMarkSync(pScrn->pScreen);
2175 exaWaitSync(pScrn->pScreen);
2178 NVCrtcBlankScreen(crtc, FALSE); /* Blank screen */
2180 /* Some more preperation. */
2181 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_CONFIG, 0x1); /* Go to non-vga mode/out of enhanced mode */
2182 if (pNv->Architecture == NV_ARCH_40) {
2183 uint32_t reg900 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_900);
2184 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_900, reg900 & ~0x10000);
2188 void nv_crtc_commit(xf86CrtcPtr crtc)
2190 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2191 ErrorF("nv_crtc_commit for CRTC %d\n", nv_crtc->head);
2193 crtc->funcs->dpms (crtc, DPMSModeOn);
2195 if (crtc->scrn->pScreen != NULL)
2196 xf86_reload_cursors (crtc->scrn->pScreen);
2198 NVResetCrtcConfig(crtc, TRUE);
2201 static Bool nv_crtc_lock(xf86CrtcPtr crtc)
2203 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2204 ErrorF("nv_crtc_lock is called for CRTC %d\n", nv_crtc->head);
2209 static void nv_crtc_unlock(xf86CrtcPtr crtc)
2211 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2212 ErrorF("nv_crtc_unlock is called for CRTC %d\n", nv_crtc->head);
2216 nv_crtc_gamma_set(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
2219 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2220 ScrnInfoPtr pScrn = crtc->scrn;
2221 NVPtr pNv = NVPTR(pScrn);
2225 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
2227 switch (pNv->CurrentLayout.depth) {
2230 /* We've got 5 bit (32 values) colors and 256 registers for each color */
2231 for (i = 0; i < 32; i++) {
2232 for (j = 0; j < 8; j++) {
2233 regp->DAC[(i*8 + j) * 3 + 0] = red[i] >> 8;
2234 regp->DAC[(i*8 + j) * 3 + 1] = green[i] >> 8;
2235 regp->DAC[(i*8 + j) * 3 + 2] = blue[i] >> 8;
2241 /* First deal with the 5 bit colors */
2242 for (i = 0; i < 32; i++) {
2243 for (j = 0; j < 8; j++) {
2244 regp->DAC[(i*8 + j) * 3 + 0] = red[i] >> 8;
2245 regp->DAC[(i*8 + j) * 3 + 2] = blue[i] >> 8;
2248 /* Now deal with the 6 bit color */
2249 for (i = 0; i < 64; i++) {
2250 for (j = 0; j < 4; j++) {
2251 regp->DAC[(i*4 + j) * 3 + 1] = green[i] >> 8;
2257 for (i = 0; i < 256; i++) {
2258 regp->DAC[i * 3] = red[i] >> 8;
2259 regp->DAC[(i * 3) + 1] = green[i] >> 8;
2260 regp->DAC[(i * 3) + 2] = blue[i] >> 8;
2265 NVCrtcLoadPalette(crtc);
2269 * Allocates memory for a locked-in-framebuffer shadow of the given
2270 * width and height for this CRTC's rotated shadow framebuffer.
2274 nv_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
2276 ErrorF("nv_crtc_shadow_allocate is called\n");
2277 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2278 ScrnInfoPtr pScrn = crtc->scrn;
2279 #if !NOUVEAU_EXA_PIXMAPS
2280 ScreenPtr pScreen = pScrn->pScreen;
2281 #endif /* !NOUVEAU_EXA_PIXMAPS */
2282 NVPtr pNv = NVPTR(pScrn);
2285 unsigned long rotate_pitch;
2286 int size, align = 64;
2288 rotate_pitch = pScrn->displayWidth * (pScrn->bitsPerPixel/8);
2289 size = rotate_pitch * height;
2291 assert(nv_crtc->shadow == NULL);
2292 #if NOUVEAU_EXA_PIXMAPS
2293 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
2294 align, size, &nv_crtc->shadow)) {
2295 ErrorF("Failed to allocate memory for shadow buffer!\n");
2299 if (nv_crtc->shadow && nouveau_bo_map(nv_crtc->shadow, NOUVEAU_BO_RDWR)) {
2300 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2301 "Failed to map shadow buffer.\n");
2305 offset = nv_crtc->shadow->map;
2307 nv_crtc->shadow = exaOffscreenAlloc(pScreen, size, align, TRUE, NULL, NULL);
2308 if (nv_crtc->shadow == NULL) {
2309 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2310 "Couldn't allocate shadow memory for rotated CRTC\n");
2313 offset = pNv->FB->map + nv_crtc->shadow->offset;
2314 #endif /* NOUVEAU_EXA_PIXMAPS */
2320 * Creates a pixmap for this CRTC's rotated shadow framebuffer.
2323 nv_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
2325 ErrorF("nv_crtc_shadow_create is called\n");
2326 ScrnInfoPtr pScrn = crtc->scrn;
2327 #if NOUVEAU_EXA_PIXMAPS
2328 ScreenPtr pScreen = pScrn->pScreen;
2329 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2330 #endif /* NOUVEAU_EXA_PIXMAPS */
2331 unsigned long rotate_pitch;
2332 PixmapPtr rotate_pixmap;
2333 #if NOUVEAU_EXA_PIXMAPS
2334 struct nouveau_pixmap *nvpix;
2335 #endif /* NOUVEAU_EXA_PIXMAPS */
2338 data = crtc->funcs->shadow_allocate (crtc, width, height);
2340 rotate_pitch = pScrn->displayWidth * (pScrn->bitsPerPixel/8);
2342 #if NOUVEAU_EXA_PIXMAPS
2343 /* Create a dummy pixmap, to get a private that will be accepted by the system.*/
2344 rotate_pixmap = pScreen->CreatePixmap(pScreen,
2347 #ifdef CREATE_PIXMAP_USAGE_SCRATCH /* there seems to have been no api bump */
2352 #endif /* CREATE_PIXMAP_USAGE_SCRATCH */
2354 rotate_pixmap = GetScratchPixmapHeader(pScrn->pScreen,
2357 pScrn->bitsPerPixel,
2360 #endif /* NOUVEAU_EXA_PIXMAPS */
2362 if (rotate_pixmap == NULL) {
2363 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2364 "Couldn't allocate shadow pixmap for rotated CRTC\n");
2367 #if NOUVEAU_EXA_PIXMAPS
2368 nvpix = exaGetPixmapDriverPrivate(rotate_pixmap);
2370 ErrorF("No shadow private, stage 1\n");
2372 nvpix->bo = nv_crtc->shadow;
2373 nvpix->mapped = TRUE;
2376 /* Modify the pixmap to actually be the one we need. */
2377 pScreen->ModifyPixmapHeader(rotate_pixmap,
2381 pScrn->bitsPerPixel,
2385 nvpix = exaGetPixmapDriverPrivate(rotate_pixmap);
2386 if (!nvpix || !nvpix->bo)
2387 ErrorF("No shadow private, stage 2\n");
2388 #endif /* NOUVEAU_EXA_PIXMAPS */
2390 return rotate_pixmap;
2394 nv_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
2396 ErrorF("nv_crtc_shadow_destroy is called\n");
2397 ScrnInfoPtr pScrn = crtc->scrn;
2398 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2399 ScreenPtr pScreen = pScrn->pScreen;
2401 if (rotate_pixmap) { /* This should also unmap the buffer object if relevant. */
2402 pScreen->DestroyPixmap(rotate_pixmap);
2405 #if !NOUVEAU_EXA_PIXMAPS
2406 if (data && nv_crtc->shadow) {
2407 exaOffscreenFree(pScreen, nv_crtc->shadow);
2409 #endif /* !NOUVEAU_EXA_PIXMAPS */
2411 nv_crtc->shadow = NULL;
2414 /* NV04-NV10 doesn't support alpha cursors */
2415 static const xf86CrtcFuncsRec nv_crtc_funcs = {
2416 .dpms = nv_crtc_dpms,
2417 .save = nv_crtc_save, /* XXX */
2418 .restore = nv_crtc_restore, /* XXX */
2419 .mode_fixup = nv_crtc_mode_fixup,
2420 .mode_set = nv_crtc_mode_set,
2421 .prepare = nv_crtc_prepare,
2422 .commit = nv_crtc_commit,
2423 .destroy = NULL, /* XXX */
2424 .lock = nv_crtc_lock,
2425 .unlock = nv_crtc_unlock,
2426 .set_cursor_colors = nv_crtc_set_cursor_colors,
2427 .set_cursor_position = nv_crtc_set_cursor_position,
2428 .show_cursor = nv_crtc_show_cursor,
2429 .hide_cursor = nv_crtc_hide_cursor,
2430 .load_cursor_image = nv_crtc_load_cursor_image,
2431 .gamma_set = nv_crtc_gamma_set,
2432 .shadow_create = nv_crtc_shadow_create,
2433 .shadow_allocate = nv_crtc_shadow_allocate,
2434 .shadow_destroy = nv_crtc_shadow_destroy,
2437 /* NV11 and up has support for alpha cursors. */
2438 /* Due to different maximum sizes we cannot allow it to use normal cursors */
2439 static const xf86CrtcFuncsRec nv11_crtc_funcs = {
2440 .dpms = nv_crtc_dpms,
2441 .save = nv_crtc_save, /* XXX */
2442 .restore = nv_crtc_restore, /* XXX */
2443 .mode_fixup = nv_crtc_mode_fixup,
2444 .mode_set = nv_crtc_mode_set,
2445 .prepare = nv_crtc_prepare,
2446 .commit = nv_crtc_commit,
2447 .destroy = NULL, /* XXX */
2448 .lock = nv_crtc_lock,
2449 .unlock = nv_crtc_unlock,
2450 .set_cursor_colors = NULL, /* Alpha cursors do not need this */
2451 .set_cursor_position = nv_crtc_set_cursor_position,
2452 .show_cursor = nv_crtc_show_cursor,
2453 .hide_cursor = nv_crtc_hide_cursor,
2454 .load_cursor_argb = nv_crtc_load_cursor_argb,
2455 .gamma_set = nv_crtc_gamma_set,
2456 .shadow_create = nv_crtc_shadow_create,
2457 .shadow_allocate = nv_crtc_shadow_allocate,
2458 .shadow_destroy = nv_crtc_shadow_destroy,
2463 nv_crtc_init(ScrnInfoPtr pScrn, int crtc_num)
2465 NVPtr pNv = NVPTR(pScrn);
2467 NVCrtcPrivatePtr nv_crtc;
2469 if (pNv->NVArch >= 0x11) {
2470 crtc = xf86CrtcCreate (pScrn, &nv11_crtc_funcs);
2472 crtc = xf86CrtcCreate (pScrn, &nv_crtc_funcs);
2477 nv_crtc = xnfcalloc (sizeof (NVCrtcPrivateRec), 1);
2478 nv_crtc->head = crtc_num;
2479 nv_crtc->last_dpms = NV_DPMS_CLEARED;
2481 crtc->driver_private = nv_crtc;
2483 NVCrtcLockUnlock(crtc, FALSE);
2486 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2488 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2492 regp = &state->crtc_reg[nv_crtc->head];
2494 NVWriteMiscOut(crtc, regp->MiscOutReg);
2496 for (i = 1; i < 5; i++)
2497 NVWriteVgaSeq(crtc, i, regp->Sequencer[i]);
2499 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
2500 NVWriteVgaCrtc(crtc, 17, regp->CRTC[17] & ~0x80);
2502 for (i = 0; i < 25; i++)
2503 NVWriteVgaCrtc(crtc, i, regp->CRTC[i]);
2505 for (i = 0; i < 9; i++)
2506 NVWriteVgaGr(crtc, i, regp->Graphics[i]);
2508 NVEnablePalette(crtc);
2509 for (i = 0; i < 21; i++)
2510 NVWriteVgaAttr(crtc, i, regp->Attribute[i]);
2512 NVDisablePalette(crtc);
2515 static void nv_crtc_fix_nv40_hw_cursor(xf86CrtcPtr crtc)
2517 /* TODO - implement this properly */
2518 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2519 ScrnInfoPtr pScrn = crtc->scrn;
2520 NVPtr pNv = NVPTR(pScrn);
2522 if (pNv->Architecture == NV_ARCH_40) { /* HW bug */
2523 volatile uint32_t curpos = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_CURSOR_POS);
2524 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_CURSOR_POS, curpos);
2527 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state, Bool override)
2529 ScrnInfoPtr pScrn = crtc->scrn;
2530 NVPtr pNv = NVPTR(pScrn);
2531 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2535 regp = &state->crtc_reg[nv_crtc->head];
2537 /* If we ever get down to pre-nv10 cards, then we must reinstate some limits. */
2538 nvWriteVIDEO(pNv, NV_PVIDEO_STOP, 1);
2539 nvWriteVIDEO(pNv, NV_PVIDEO_INTR_EN, 0);
2540 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(0), 0);
2541 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(1), 0);
2542 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(0), pNv->VRAMPhysicalSize - 1);
2543 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(1), pNv->VRAMPhysicalSize - 1);
2544 nvWriteMC(pNv, 0x1588, 0);
2546 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, regp->CRTC[NV_VGA_CRTCX_BUFFER]);
2547 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG, regp->cursorConfig);
2548 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_GPIO, regp->gpio);
2549 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0830, regp->unk830);
2550 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0834, regp->unk834);
2551 if (pNv->Architecture == NV_ARCH_40) {
2552 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0850, regp->unk850);
2553 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_081C, regp->unk81c);
2556 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_CONFIG, regp->config);
2557 if (pNv->Architecture == NV_ARCH_40) {
2558 uint32_t reg900 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_900);
2559 if (regp->config == 0x2) { /* enhanced "horizontal only" non-vga mode */
2560 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_900, reg900 | 0x10000);
2562 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_900, reg900 & ~0x10000);
2566 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0, regp->CRTC[NV_VGA_CRTCX_REPAINT0]);
2567 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, regp->CRTC[NV_VGA_CRTCX_REPAINT1]);
2568 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LSR, regp->CRTC[NV_VGA_CRTCX_LSR]);
2569 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL, regp->CRTC[NV_VGA_CRTCX_PIXEL]);
2570 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LCD, regp->CRTC[NV_VGA_CRTCX_LCD]);
2571 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_HEB, regp->CRTC[NV_VGA_CRTCX_HEB]);
2572 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1, regp->CRTC[NV_VGA_CRTCX_FIFO1]);
2573 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0, regp->CRTC[NV_VGA_CRTCX_FIFO0]);
2574 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM]);
2575 if (pNv->Architecture >= NV_ARCH_30) {
2576 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30]);
2579 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0, regp->CRTC[NV_VGA_CRTCX_CURCTL0]);
2580 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1, regp->CRTC[NV_VGA_CRTCX_CURCTL1]);
2581 nv_crtc_fix_nv40_hw_cursor(crtc);
2582 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2, regp->CRTC[NV_VGA_CRTCX_CURCTL2]);
2583 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE, regp->CRTC[NV_VGA_CRTCX_INTERLACE]);
2585 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_26, regp->CRTC[NV_VGA_CRTCX_26]);
2586 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3B, regp->CRTC[NV_VGA_CRTCX_3B]);
2587 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3C, regp->CRTC[NV_VGA_CRTCX_3C]);
2588 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA, regp->CRTC[NV_VGA_CRTCX_EXTRA]);
2589 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_43, regp->CRTC[NV_VGA_CRTCX_43]);
2590 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_45, regp->CRTC[NV_VGA_CRTCX_45]);
2591 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_4B, regp->CRTC[NV_VGA_CRTCX_4B]);
2592 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_52, regp->CRTC[NV_VGA_CRTCX_52]);
2593 /* NV11 and NV20 stop at 0x52. */
2594 if (pNv->NVArch >= 0x17 && pNv->twoHeads) {
2596 for (i = 0; i < 0x10; i++)
2597 NVWriteVGACR5758(pNv, nv_crtc->head, i, regp->CR58[i]);
2599 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING, regp->CRTC[NV_VGA_CRTCX_FP_HTIMING]);
2600 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING, regp->CRTC[NV_VGA_CRTCX_FP_VTIMING]);
2602 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_59, regp->CRTC[NV_VGA_CRTCX_59]);
2604 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_85, regp->CRTC[NV_VGA_CRTCX_85]);
2605 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_86, regp->CRTC[NV_VGA_CRTCX_86]);
2608 /* Setting 1 on this value gives you interrupts for every vblank period. */
2609 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_EN_0, 0);
2610 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_0, NV_CRTC_INTR_VBLANK);
2612 pNv->CurrentState = state;
2615 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2617 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2621 regp = &state->crtc_reg[nv_crtc->head];
2623 regp->MiscOutReg = NVReadMiscOut(crtc);
2625 for (i = 0; i < 25; i++)
2626 regp->CRTC[i] = NVReadVgaCrtc(crtc, i);
2628 NVEnablePalette(crtc);
2629 for (i = 0; i < 21; i++)
2630 regp->Attribute[i] = NVReadVgaAttr(crtc, i);
2631 NVDisablePalette(crtc);
2633 for (i = 0; i < 9; i++)
2634 regp->Graphics[i] = NVReadVgaGr(crtc, i);
2636 for (i = 1; i < 5; i++)
2637 regp->Sequencer[i] = NVReadVgaSeq(crtc, i);
2641 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2643 ScrnInfoPtr pScrn = crtc->scrn;
2644 NVPtr pNv = NVPTR(pScrn);
2645 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2649 regp = &state->crtc_reg[nv_crtc->head];
2651 /* If we ever get down to pre-nv10 cards, then we must reinstate some limits. */
2652 regp->CRTC[NV_VGA_CRTCX_LCD] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LCD);
2653 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0);
2654 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1);
2655 regp->CRTC[NV_VGA_CRTCX_LSR] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LSR);
2656 regp->CRTC[NV_VGA_CRTCX_PIXEL] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL);
2657 regp->CRTC[NV_VGA_CRTCX_HEB] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_HEB);
2658 regp->CRTC[NV_VGA_CRTCX_FIFO1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1);
2660 regp->CRTC[NV_VGA_CRTCX_FIFO0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0);
2661 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM);
2662 regp->CRTC[NV_VGA_CRTCX_BUFFER] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER);
2663 if (pNv->Architecture >= NV_ARCH_30) {
2664 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30);
2666 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0);
2667 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1);
2668 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2);
2669 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE);
2671 regp->gpio = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_GPIO);
2672 regp->unk830 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0830);
2673 regp->unk834 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0834);
2674 if (pNv->Architecture == NV_ARCH_40) {
2675 regp->unk850 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0850);
2676 regp->unk81c = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_081C);
2679 regp->config = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_CONFIG);
2681 regp->head = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL);
2682 regp->crtcOwner = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_OWNER);
2683 regp->CRTC[NV_VGA_CRTCX_EXTRA] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA);
2685 regp->cursorConfig = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG);
2687 regp->CRTC[NV_VGA_CRTCX_26] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_26);
2688 regp->CRTC[NV_VGA_CRTCX_3B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3B);
2689 regp->CRTC[NV_VGA_CRTCX_3C] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3C);
2690 regp->CRTC[NV_VGA_CRTCX_43] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_43);
2691 regp->CRTC[NV_VGA_CRTCX_45] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_45);
2692 regp->CRTC[NV_VGA_CRTCX_4B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_4B);
2693 regp->CRTC[NV_VGA_CRTCX_52] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_52);
2694 /* NV11 and NV20 don't have this, they stop at 0x52. */
2695 if (pNv->NVArch >= 0x17 && pNv->twoHeads) {
2696 for (i = 0; i < 0x10; i++)
2697 regp->CR58[i] = NVReadVGACR5758(pNv, nv_crtc->head, i);
2699 regp->CRTC[NV_VGA_CRTCX_59] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_59);
2700 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING);
2701 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING);
2703 regp->CRTC[NV_VGA_CRTCX_85] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_85);
2704 regp->CRTC[NV_VGA_CRTCX_86] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_86);
2708 static void nv_crtc_save_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2710 ScrnInfoPtr pScrn = crtc->scrn;
2711 NVPtr pNv = NVPTR(pScrn);
2712 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2716 regp = &state->crtc_reg[nv_crtc->head];
2718 regp->general = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_GENERAL_CONTROL);
2720 regp->fp_control = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_CONTROL);
2721 regp->debug_0 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_0);
2722 regp->debug_1 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_1);
2723 regp->debug_2 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_2);
2725 regp->unk_a20 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A20);
2726 regp->unk_a24 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A24);
2727 regp->unk_a34 = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A34);
2729 if (pNv->NVArch == 0x11) {
2730 regp->dither = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_DITHER_NV11);
2731 } else if (pNv->twoHeads) {
2732 regp->dither = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DITHER);
2734 regp->nv10_cursync = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_NV10_CURSYNC);
2736 /* The regs below are 0 for non-flatpanels, so you can load and save them */
2738 for (i = 0; i < 7; i++) {
2739 uint32_t ramdac_reg = NV_RAMDAC_FP_HDISP_END + (i * 4);
2740 regp->fp_horiz_regs[i] = nvReadRAMDAC(pNv, nv_crtc->head, ramdac_reg);
2743 for (i = 0; i < 7; i++) {
2744 uint32_t ramdac_reg = NV_RAMDAC_FP_VDISP_END + (i * 4);
2745 regp->fp_vert_regs[i] = nvReadRAMDAC(pNv, nv_crtc->head, ramdac_reg);
2748 regp->fp_hvalid_start = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_HVALID_START);
2749 regp->fp_hvalid_end = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_HVALID_END);
2750 regp->fp_vvalid_start = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_VVALID_START);
2751 regp->fp_vvalid_end = nvReadRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_VVALID_END);
2754 static void nv_crtc_load_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2756 ScrnInfoPtr pScrn = crtc->scrn;
2757 NVPtr pNv = NVPTR(pScrn);
2758 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2762 regp = &state->crtc_reg[nv_crtc->head];
2764 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_GENERAL_CONTROL, regp->general);
2766 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_CONTROL, regp->fp_control);
2767 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_0, regp->debug_0);
2768 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_1, regp->debug_1);
2769 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DEBUG_2, regp->debug_2);
2770 if (pNv->NVArch == 0x30) { /* For unknown purposes. */
2771 uint32_t reg890 = nvReadRAMDAC(pNv, nv_crtc->head, NV30_RAMDAC_890);
2772 nvWriteRAMDAC(pNv, nv_crtc->head, NV30_RAMDAC_89C, reg890);
2775 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A20, regp->unk_a20);
2776 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A24, regp->unk_a24);
2777 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_A34, regp->unk_a34);
2779 if (pNv->NVArch == 0x11) {
2780 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_DITHER_NV11, regp->dither);
2781 } else if (pNv->twoHeads) {
2782 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_DITHER, regp->dither);
2784 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_NV10_CURSYNC, regp->nv10_cursync);
2786 /* The regs below are 0 for non-flatpanels, so you can load and save them */
2788 for (i = 0; i < 7; i++) {
2789 uint32_t ramdac_reg = NV_RAMDAC_FP_HDISP_END + (i * 4);
2790 nvWriteRAMDAC(pNv, nv_crtc->head, ramdac_reg, regp->fp_horiz_regs[i]);
2793 for (i = 0; i < 7; i++) {
2794 uint32_t ramdac_reg = NV_RAMDAC_FP_VDISP_END + (i * 4);
2795 nvWriteRAMDAC(pNv, nv_crtc->head, ramdac_reg, regp->fp_vert_regs[i]);
2798 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_HVALID_START, regp->fp_hvalid_start);
2799 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_HVALID_END, regp->fp_hvalid_end);
2800 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_VVALID_START, regp->fp_vvalid_start);
2801 nvWriteRAMDAC(pNv, nv_crtc->head, NV_RAMDAC_FP_VVALID_END, regp->fp_vvalid_end);
2805 NVCrtcSetBase (xf86CrtcPtr crtc, int x, int y)
2807 ScrnInfoPtr pScrn = crtc->scrn;
2808 NVPtr pNv = NVPTR(pScrn);
2809 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2810 NVFBLayout *pLayout = &pNv->CurrentLayout;
2813 ErrorF("NVCrtcSetBase: x: %d y: %d\n", x, y);
2815 start += ((y * pScrn->displayWidth + x) * (pLayout->bitsPerPixel/8));
2816 if (crtc->rotatedData != NULL) { /* we do not exist on the real framebuffer */
2817 #if NOUVEAU_EXA_PIXMAPS
2818 start = nv_crtc->shadow->offset;
2820 start = pNv->FB->offset + nv_crtc->shadow->offset; /* We do exist relative to the framebuffer */
2823 start += pNv->FB->offset;
2826 /* 30 bits addresses in 32 bits according to haiku */
2827 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_START, start & 0xfffffffc);
2829 /* set NV4/NV10 byte adress: (bit0 - 1) */
2830 NVWriteVgaAttr(crtc, 0x13, (start & 0x3) << 1);
2836 static void NVCrtcWriteDacMask(xf86CrtcPtr crtc, uint8_t value)
2838 ScrnInfoPtr pScrn = crtc->scrn;
2839 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2840 NVPtr pNv = NVPTR(pScrn);
2841 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2843 NV_WR08(pDACReg, VGA_DAC_MASK, value);
2846 static uint8_t NVCrtcReadDacMask(xf86CrtcPtr crtc)
2848 ScrnInfoPtr pScrn = crtc->scrn;
2849 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2850 NVPtr pNv = NVPTR(pScrn);
2851 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2853 return NV_RD08(pDACReg, VGA_DAC_MASK);
2856 static void NVCrtcWriteDacReadAddr(xf86CrtcPtr crtc, uint8_t value)
2858 ScrnInfoPtr pScrn = crtc->scrn;
2859 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2860 NVPtr pNv = NVPTR(pScrn);
2861 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2863 NV_WR08(pDACReg, VGA_DAC_READ_ADDR, value);
2866 static void NVCrtcWriteDacWriteAddr(xf86CrtcPtr crtc, uint8_t value)
2868 ScrnInfoPtr pScrn = crtc->scrn;
2869 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2870 NVPtr pNv = NVPTR(pScrn);
2871 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2873 NV_WR08(pDACReg, VGA_DAC_WRITE_ADDR, value);
2876 static void NVCrtcWriteDacData(xf86CrtcPtr crtc, uint8_t value)
2878 ScrnInfoPtr pScrn = crtc->scrn;
2879 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2880 NVPtr pNv = NVPTR(pScrn);
2881 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2883 NV_WR08(pDACReg, VGA_DAC_DATA, value);
2886 static uint8_t NVCrtcReadDacData(xf86CrtcPtr crtc, uint8_t value)
2888 ScrnInfoPtr pScrn = crtc->scrn;
2889 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2890 NVPtr pNv = NVPTR(pScrn);
2891 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
2893 return NV_RD08(pDACReg, VGA_DAC_DATA);
2896 void NVCrtcLoadPalette(xf86CrtcPtr crtc)
2899 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2901 ScrnInfoPtr pScrn = crtc->scrn;
2902 NVPtr pNv = NVPTR(pScrn);
2904 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
2906 NVCrtcSetOwner(crtc);
2907 NVCrtcWriteDacMask(crtc, 0xff);
2908 NVCrtcWriteDacWriteAddr(crtc, 0x00);
2910 for (i = 0; i<768; i++) {
2911 NVCrtcWriteDacData(crtc, regp->DAC[i]);
2913 NVDisablePalette(crtc);
2917 void NVCrtcBlankScreen(xf86CrtcPtr crtc, Bool on)
2921 NVCrtcSetOwner(crtc);
2923 scrn = NVReadVgaSeq(crtc, 0x01);
2930 NVVgaSeqReset(crtc, TRUE);
2931 NVWriteVgaSeq(crtc, 0x01, scrn);
2932 NVVgaSeqReset(crtc, FALSE);
2935 /*************************************************************************** \
2937 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
2939 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
2940 |* international laws. Users and possessors of this source code are *|
2941 |* hereby granted a nonexclusive, royalty-free copyright license to *|
2942 |* use this code in individual and commercial software. *|
2944 |* Any use of this source code must include, in the user documenta- *|
2945 |* tion and internal comments to the code, notices to the end user *|
2948 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
2950 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
2951 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
2952 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
2953 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
2954 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
2955 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
2956 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
2957 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
2958 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
2959 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
2960 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
2962 |* U.S. Government End Users. This source code is a "commercial *|
2963 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
2964 |* consisting of "commercial computer software" and "commercial *|
2965 |* computer software documentation," as such terms are used in *|
2966 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
2967 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
2968 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
2969 |* all U.S. Government End Users acquire the source code with only *|
2970 |* those rights set forth herein. *|
2972 \***************************************************************************/