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 uint32_t NVReadCRTC(NVPtr pNv, uint8_t head, uint32_t reg)
68 volatile const void *ptr = head ? pNv->PCRTC1 : pNv->PCRTC0;
69 DDXMMIOH("NVReadCRTC: head %d reg %08x val %08x\n", head, reg + NV_PCRTC0_OFFSET + (head ? NV_PCRTC0_SIZE : 0), (uint32_t)MMIO_IN32(ptr, reg));
70 return MMIO_IN32(ptr, reg);
73 void NVWriteCRTC(NVPtr pNv, uint8_t head, uint32_t reg, uint32_t val)
75 volatile const void *ptr = head ? pNv->PCRTC1 : pNv->PCRTC0;
76 DDXMMIOH("NVWriteCRTC: head %d reg %08x val %08x\n", head, reg + NV_PCRTC0_OFFSET + (head ? NV_PCRTC0_SIZE : 0), val);
77 MMIO_OUT32(ptr, reg, val);
80 uint32_t NVCrtcReadCRTC(xf86CrtcPtr crtc, uint32_t reg)
82 ScrnInfoPtr pScrn = crtc->scrn;
83 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
84 NVPtr pNv = NVPTR(pScrn);
86 return NVReadCRTC(pNv, nv_crtc->head, reg);
89 void NVCrtcWriteCRTC(xf86CrtcPtr crtc, uint32_t reg, uint32_t val)
91 ScrnInfoPtr pScrn = crtc->scrn;
92 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
93 NVPtr pNv = NVPTR(pScrn);
95 NVWriteCRTC(pNv, nv_crtc->head, reg, val);
98 uint32_t NVReadRAMDAC(NVPtr pNv, uint8_t head, uint32_t reg)
100 volatile const void *ptr = head ? pNv->PRAMDAC1 : pNv->PRAMDAC0;
101 DDXMMIOH("NVReadRamdac: head %d reg %08x val %08x\n", head, reg + NV_PRAMDAC0_OFFSET + (head ? NV_PRAMDAC0_SIZE : 0), (uint32_t)MMIO_IN32(ptr, reg));
102 return MMIO_IN32(ptr, reg);
105 void NVWriteRAMDAC(NVPtr pNv, uint8_t head, uint32_t reg, uint32_t val)
107 volatile const void *ptr = head ? pNv->PRAMDAC1 : pNv->PRAMDAC0;
108 DDXMMIOH("NVWriteRamdac: head %d reg %08x val %08x\n", head, reg + NV_PRAMDAC0_OFFSET + (head ? NV_PRAMDAC0_SIZE : 0), val);
109 MMIO_OUT32(ptr, reg, val);
112 uint32_t NVCrtcReadRAMDAC(xf86CrtcPtr crtc, uint32_t reg)
114 ScrnInfoPtr pScrn = crtc->scrn;
115 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
116 NVPtr pNv = NVPTR(pScrn);
118 return NVReadRAMDAC(pNv, nv_crtc->head, reg);
121 void NVCrtcWriteRAMDAC(xf86CrtcPtr crtc, uint32_t reg, uint32_t val)
123 ScrnInfoPtr pScrn = crtc->scrn;
124 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
125 NVPtr pNv = NVPTR(pScrn);
127 NVWriteRAMDAC(pNv, nv_crtc->head, reg, val);
130 static uint8_t NVReadPVIO(xf86CrtcPtr crtc, uint32_t address)
132 ScrnInfoPtr pScrn = crtc->scrn;
133 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
134 NVPtr pNv = NVPTR(pScrn);
136 /* Only NV4x have two pvio ranges */
137 if (nv_crtc->head == 1 && pNv->Architecture == NV_ARCH_40) {
138 DDXMMIOH("NVReadPVIO: head %d reg %08x val %02x\n", 1, address + NV_PVIO_OFFSET + NV_PVIO_SIZE, NV_RD08(pNv->PVIO1, address));
139 return NV_RD08(pNv->PVIO1, address);
141 DDXMMIOH("NVReadPVIO: head %d reg %08x val %02x\n", 0, address + NV_PVIO_OFFSET, NV_RD08(pNv->PVIO0, address));
142 return NV_RD08(pNv->PVIO0, address);
146 static void NVWritePVIO(xf86CrtcPtr crtc, uint32_t address, uint8_t value)
148 ScrnInfoPtr pScrn = crtc->scrn;
149 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
150 NVPtr pNv = NVPTR(pScrn);
152 DDXMMIOH("NVWritePVIO: head %d reg %08x val %02x\n", nv_crtc->head, address + NV_PVIO_OFFSET + (nv_crtc->head ? NV_PVIO_SIZE : 0), value);
153 /* Only NV4x have two pvio ranges */
154 if (nv_crtc->head == 1 && pNv->Architecture == NV_ARCH_40) {
155 NV_WR08(pNv->PVIO1, address, value);
157 NV_WR08(pNv->PVIO0, address, value);
161 static void NVWriteMiscOut(xf86CrtcPtr crtc, uint8_t value)
163 NVWritePVIO(crtc, VGA_MISC_OUT_W, value);
166 static uint8_t NVReadMiscOut(xf86CrtcPtr crtc)
168 return NVReadPVIO(crtc, VGA_MISC_OUT_R);
171 void NVWriteVGA(NVPtr pNv, int head, uint8_t index, uint8_t value)
173 volatile uint8_t *pCRTCReg = head ? pNv->PCIO1 : pNv->PCIO0;
175 DDXMMIOH("NVWriteVGA: head %d index 0x%02x data 0x%02x\n", head, index, value);
176 NV_WR08(pCRTCReg, CRTC_INDEX, index);
177 NV_WR08(pCRTCReg, CRTC_DATA, value);
180 uint8_t NVReadVGA(NVPtr pNv, int head, uint8_t index)
182 volatile uint8_t *pCRTCReg = head ? pNv->PCIO1 : pNv->PCIO0;
184 NV_WR08(pCRTCReg, CRTC_INDEX, index);
185 DDXMMIOH("NVReadVGA: head %d index 0x%02x data 0x%02x\n", head, index, NV_RD08(pCRTCReg, CRTC_DATA));
186 return NV_RD08(pCRTCReg, CRTC_DATA);
189 /* CR57 and CR58 are a fun pair of regs. CR57 provides an index (0-0xf) for CR58
190 * I suspect they in fact do nothing, but are merely a way to carry useful
191 * per-head variables around
195 * 0x00 index to the appropriate dcb entry (or 7f for inactive)
196 * 0x02 dcb entry's "or" value (or 00 for inactive)
197 * 0x03 bit0 set for dual link (LVDS, possibly elsewhere too)
198 * 0x08 or 0x09 pxclk in MHz
199 * 0x0f laptop panel info - low nibble for PEXTDEV_BOOT strap
200 * high nibble for xlat strap value
203 void NVWriteVGACR5758(NVPtr pNv, int head, uint8_t index, uint8_t value)
205 NVWriteVGA(pNv, head, 0x57, index);
206 NVWriteVGA(pNv, head, 0x58, value);
209 uint8_t NVReadVGACR5758(NVPtr pNv, int head, uint8_t index)
211 NVWriteVGA(pNv, head, 0x57, index);
212 return NVReadVGA(pNv, head, 0x58);
215 void NVWriteVgaCrtc(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
217 ScrnInfoPtr pScrn = crtc->scrn;
218 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
219 NVPtr pNv = NVPTR(pScrn);
221 NVWriteVGA(pNv, nv_crtc->head, index, value);
224 uint8_t NVReadVgaCrtc(xf86CrtcPtr crtc, uint8_t index)
226 ScrnInfoPtr pScrn = crtc->scrn;
227 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
228 NVPtr pNv = NVPTR(pScrn);
230 return NVReadVGA(pNv, nv_crtc->head, index);
233 static void NVWriteVgaSeq(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
235 NVWritePVIO(crtc, VGA_SEQ_INDEX, index);
236 NVWritePVIO(crtc, VGA_SEQ_DATA, value);
239 static uint8_t NVReadVgaSeq(xf86CrtcPtr crtc, uint8_t index)
241 NVWritePVIO(crtc, VGA_SEQ_INDEX, index);
242 return NVReadPVIO(crtc, VGA_SEQ_DATA);
245 static void NVWriteVgaGr(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
247 NVWritePVIO(crtc, VGA_GRAPH_INDEX, index);
248 NVWritePVIO(crtc, VGA_GRAPH_DATA, value);
251 static uint8_t NVReadVgaGr(xf86CrtcPtr crtc, uint8_t index)
253 NVWritePVIO(crtc, VGA_GRAPH_INDEX, index);
254 return NVReadPVIO(crtc, VGA_GRAPH_DATA);
258 static void NVWriteVgaAttr(xf86CrtcPtr crtc, uint8_t index, uint8_t value)
260 ScrnInfoPtr pScrn = crtc->scrn;
261 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
262 NVPtr pNv = NVPTR(pScrn);
263 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
265 DDXMMIOH("NVWriteVgaAttr: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, CRTC_IN_STAT_1, NV_RD08(pCRTCReg, CRTC_IN_STAT_1));
266 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
267 if (nv_crtc->paletteEnabled)
272 DDXMMIOH("NVWriteVgaAttr: head %d index 0x%02x data 0x%02x\n", nv_crtc->head, index, value);
273 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
274 NV_WR08(pCRTCReg, VGA_ATTR_DATA_W, value);
277 static uint8_t NVReadVgaAttr(xf86CrtcPtr crtc, uint8_t index)
279 ScrnInfoPtr pScrn = crtc->scrn;
280 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
281 NVPtr pNv = NVPTR(pScrn);
282 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
284 DDXMMIOH("NVReadVgaAttr: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, CRTC_IN_STAT_1, NV_RD08(pCRTCReg, CRTC_IN_STAT_1));
285 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
286 if (nv_crtc->paletteEnabled)
291 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
292 DDXMMIOH("NVReadVgaAttr: head %d index 0x%02x data 0x%02x\n", nv_crtc->head, index, NV_RD08(pCRTCReg, VGA_ATTR_DATA_R));
293 return NV_RD08(pCRTCReg, VGA_ATTR_DATA_R);
296 static void NVCrtcSetOwner(xf86CrtcPtr crtc)
298 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
299 ScrnInfoPtr pScrn = crtc->scrn;
300 NVPtr pNv = NVPTR(pScrn);
301 /* Non standard beheaviour required by NV11 */
303 uint8_t owner = NVReadVGA(pNv, 0, NV_VGA_CRTCX_OWNER);
304 ErrorF("pre-Owner: 0x%X\n", owner);
306 uint32_t pbus84 = nvReadMC(pNv, 0x1084);
307 ErrorF("pbus84: 0x%X\n", pbus84);
309 ErrorF("pbus84: 0x%X\n", pbus84);
310 nvWriteMC(pNv, 0x1084, pbus84);
312 /* The blob never writes owner to pcio1, so should we */
313 if (pNv->NVArch == 0x11) {
314 NVWriteVGA(pNv, 0, NV_VGA_CRTCX_OWNER, 0xff);
316 NVWriteVGA(pNv, 0, NV_VGA_CRTCX_OWNER, nv_crtc->head * 0x3);
317 owner = NVReadVGA(pNv, 0, NV_VGA_CRTCX_OWNER);
318 ErrorF("post-Owner: 0x%X\n", owner);
320 ErrorF("pNv pointer is NULL\n");
325 NVEnablePalette(xf86CrtcPtr crtc)
327 ScrnInfoPtr pScrn = crtc->scrn;
328 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
329 NVPtr pNv = NVPTR(pScrn);
330 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
332 DDXMMIOH("NVEnablePalette: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, CRTC_IN_STAT_1, NV_RD08(pCRTCReg, CRTC_IN_STAT_1));
333 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
334 DDXMMIOH("NVEnablePalette: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_ATTR_INDEX, 0);
335 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0);
336 nv_crtc->paletteEnabled = TRUE;
340 NVDisablePalette(xf86CrtcPtr crtc)
342 ScrnInfoPtr pScrn = crtc->scrn;
343 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
344 NVPtr pNv = NVPTR(pScrn);
345 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
347 DDXMMIOH("NVDisablePalette: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, CRTC_IN_STAT_1, NV_RD08(pCRTCReg, CRTC_IN_STAT_1));
348 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
349 DDXMMIOH("NVEnablePalette: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_ATTR_INDEX, 0x20);
350 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0x20);
351 nv_crtc->paletteEnabled = FALSE;
354 static void NVWriteVgaReg(xf86CrtcPtr crtc, uint32_t reg, uint8_t value)
356 ScrnInfoPtr pScrn = crtc->scrn;
357 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
358 NVPtr pNv = NVPTR(pScrn);
359 volatile uint8_t *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
361 DDXMMIOH("NVWriteVgaReg: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, reg, value);
362 NV_WR08(pCRTCReg, reg, value);
365 /* perform a sequencer reset */
366 static void NVVgaSeqReset(xf86CrtcPtr crtc, Bool start)
369 NVWriteVgaSeq(crtc, 0x00, 0x1);
371 NVWriteVgaSeq(crtc, 0x00, 0x3);
374 static void NVVgaProtect(xf86CrtcPtr crtc, Bool on)
379 tmp = NVReadVgaSeq(crtc, 0x1);
380 NVVgaSeqReset(crtc, TRUE);
381 NVWriteVgaSeq(crtc, 0x01, tmp | 0x20);
383 NVEnablePalette(crtc);
386 * Reenable sequencer, then turn on screen.
388 tmp = NVReadVgaSeq(crtc, 0x1);
389 NVWriteVgaSeq(crtc, 0x01, tmp & ~0x20); /* reenable display */
390 NVVgaSeqReset(crtc, FALSE);
392 NVDisablePalette(crtc);
396 void NVCrtcLockUnlock(xf86CrtcPtr crtc, Bool Lock)
398 NVPtr pNv = NVPTR(crtc->scrn);
402 NVCrtcSetOwner(crtc);
404 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LOCK, Lock ? 0x99 : 0x57);
405 cr11 = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE);
406 if (Lock) cr11 |= 0x80;
408 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE, cr11);
412 NVGetOutputFromCRTC(xf86CrtcPtr crtc)
414 ScrnInfoPtr pScrn = crtc->scrn;
415 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
417 for (i = 0; i < xf86_config->num_output; i++) {
418 xf86OutputPtr output = xf86_config->output[i];
420 if (output->crtc == crtc) {
429 nv_find_crtc_by_index(ScrnInfoPtr pScrn, int index)
431 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
434 for (i = 0; i < xf86_config->num_crtc; i++) {
435 xf86CrtcPtr crtc = xf86_config->crtc[i];
436 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
437 if (nv_crtc->head == index)
445 * Calculate the Video Clock parameters for the PLL.
447 /* Code taken from NVClock, with permission of the author (being a GPL->MIT code transfer). */
450 CalculateVClkNV4x_SingleVCO(NVPtr pNv, struct pll_lims *pll_lim, uint32_t clockIn, uint32_t *n1_best, uint32_t *m1_best, uint32_t *p_best)
452 uint32_t clock, M, N, P;
453 uint32_t delta, bestDelta, minM, maxM, minN, maxN, maxP;
454 uint32_t minVCOInputFreq, minVCOFreq, maxVCOFreq;
456 uint32_t refClk = pNv->CrystalFreqKHz;
459 minVCOInputFreq = pll_lim->vco1.min_inputfreq;
460 minVCOFreq = pll_lim->vco1.minfreq;
461 maxVCOFreq = pll_lim->vco1.maxfreq;
462 minM = pll_lim->vco1.min_m;
463 maxM = pll_lim->vco1.max_m;
464 minN = pll_lim->vco1.min_n;
465 maxN = pll_lim->vco1.max_n;
469 /* The optimal frequency for the PLL to work at is somewhere in the center of its range.
470 / Choose a post divider in such a way to achieve this.
471 / The G8x nv driver does something similar but they they derive a minP and maxP. That
472 / doesn't seem required as you get so many matching clocks that you don't enter a second
473 / iteration for P. (The minP / maxP values in the nv driver only differ at most 1, so it is for
474 / some rare corner cases.
476 for (P=0, VCOFreq=maxVCOFreq/2; clockIn<=VCOFreq && P <= maxP; P++)
481 /* Calculate the m and n values. There are a lot of values which give the same speed;
482 / We choose the speed for which the difference with the request speed is as small as possible.
484 for (M=minM; M<=maxM; M++)
486 /* The VCO has a minimum input frequency */
487 if ((refClk/M) < minVCOInputFreq)
490 for (N=minN; N<=maxN; N++)
492 /* Calculate the frequency generated by VCO1 */
493 clock = (int)(refClk * N / (float)M);
495 /* Verify if the clock lies within the output limits of VCO1 */
496 if (clock < minVCOFreq)
498 else if (clock > maxVCOFreq) /* It is no use to continue as the clock will only become higher */
502 delta = abs((int)(clockIn - clock));
503 /* When the difference is 0 or less than .5% accept the speed */
504 if (((delta == 0) || ((float)delta/(float)clockIn <= 0.005)))
512 /* When the new difference is smaller than the old one, use this one */
513 if (delta < bestDelta)
525 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)
527 uint32_t clock1, clock2, M, M2, N, N2, P;
528 uint32_t delta, bestDelta, minM, minM2, maxM, maxM2, minN, minN2, maxN, maxN2, maxP;
529 uint32_t minVCOInputFreq, minVCO2InputFreq, maxVCO2InputFreq, minVCOFreq, minVCO2Freq, maxVCOFreq, maxVCO2Freq;
530 uint32_t VCO2Freq, maxClock;
531 uint32_t refClk = pNv->CrystalFreqKHz;
534 minVCOInputFreq = pll_lim->vco1.min_inputfreq;
535 minVCOFreq = pll_lim->vco1.minfreq;
536 maxVCOFreq = pll_lim->vco1.maxfreq;
537 minM = pll_lim->vco1.min_m;
538 maxM = pll_lim->vco1.max_m;
539 minN = pll_lim->vco1.min_n;
540 maxN = pll_lim->vco1.max_n;
542 minVCO2InputFreq = pll_lim->vco2.min_inputfreq;
543 maxVCO2InputFreq = pll_lim->vco2.max_inputfreq;
544 minVCO2Freq = pll_lim->vco2.minfreq;
545 maxVCO2Freq = pll_lim->vco2.maxfreq;
546 minM2 = pll_lim->vco2.min_m;
547 maxM2 = pll_lim->vco2.max_m;
548 minN2 = pll_lim->vco2.min_n;
549 maxN2 = pll_lim->vco2.max_n;
553 maxClock = maxVCO2Freq;
554 /* If the requested clock is behind the bios limits, try it anyway */
555 if (clockIn > maxVCO2Freq)
556 maxClock = clockIn + clockIn/200; /* Add a .5% margin */
558 /* The optimal frequency for the PLL to work at is somewhere in the center of its range.
559 / Choose a post divider in such a way to achieve this.
560 / The G8x nv driver does something similar but they they derive a minP and maxP. That
561 / doesn't seem required as you get so many matching clocks that you don't enter a second
562 / iteration for P. (The minP / maxP values in the nv driver only differ at most 1, so it is for
563 / some rare corner cases.
565 for (P=0, VCO2Freq=maxClock/2; clockIn<=VCO2Freq && P <= maxP; P++)
570 /* The PLLs on Geforce6/7 hardware can operate in a single stage made with only 1 VCO
571 / and a cascade mode of two VCOs. This second mode is in general used for relatively high
572 / frequencies. The loop below calculates the divider and multiplier ratios for the cascade
573 / mode. The code takes into account limits defined in the video bios.
575 for (M=minM; M<=maxM; M++)
577 /* The VCO has a minimum input frequency */
578 if ((refClk/M) < minVCOInputFreq)
581 for (N=minN; N<=maxN; N++)
583 /* Calculate the frequency generated by VCO1 */
584 clock1 = (int)(refClk * N / (float)M);
585 /* Verify if the clock lies within the output limits of VCO1 */
586 if ( (clock1 < minVCOFreq) )
588 else if (clock1 > maxVCOFreq) /* For future N, the clock will only increase so stop; xorg nv continues but that is useless */
591 for (M2=minM2; M2<=maxM2; M2++)
593 /* The clock fed to the second VCO needs to lie within a certain input range */
594 if (clock1 / M2 < minVCO2InputFreq)
596 else if (clock1 / M2 > maxVCO2InputFreq)
599 N2 = (int)((float)((clockIn << P) * M * M2) / (float)(refClk * N)+.5);
600 if( (N2 < minN2) || (N2 > maxN2) )
603 /* The clock before being fed to the post-divider needs to lie within a certain range.
604 / Further there are some limits on N2/M2.
606 clock2 = (int)((float)(N*N2)/(M*M2) * refClk);
607 if( (clock2 < minVCO2Freq) || (clock2 > maxClock))// || ((N2 / M2) < 4) || ((N2 / M2) > 10) )
610 /* The post-divider delays the 'high' clock to create a low clock if requested.
611 / This post-divider exists because the VCOs can only generate frequencies within
612 / a limited frequency range. This range has been tuned to lie around half of its max
613 / input frequency. It tries to calculate all clocks (including lower ones) around this
614 / 'center' frequency.
617 delta = abs((int)(clockIn - clock2));
619 /* When the difference is 0 or less than .5% accept the speed */
620 if (((delta == 0) || ((float)delta/(float)clockIn <= 0.005)))
630 /* When the new difference is smaller than the old one, use this one */
631 if (delta < bestDelta)
645 /* BIG NOTE: modifying vpll1 and vpll2 does not work, what bit is the switch to allow it? */
647 /* Even though they are not yet used, i'm adding some notes about some of the 0x4000 regs */
648 /* They are only valid for NV4x, appearantly reordered for NV5x */
649 /* gpu pll: 0x4000 + 0x4004
650 * unknown pll: 0x4008 + 0x400c
651 * vpll1: 0x4010 + 0x4014
652 * vpll2: 0x4018 + 0x401c
653 * unknown pll: 0x4020 + 0x4024
654 * unknown pll: 0x4038 + 0x403c
655 * Some of the unknown's are probably memory pll's.
656 * The vpll's use two set's of multipliers and dividers. I refer to them as a and b.
657 * 1 and 2 refer to the registers of each pair. There is only one post divider.
658 * Logic: clock = reference_clock * ((n(a) * n(b))/(m(a) * m(b))) >> p
659 * 1) bit 0-7: familiar values, but redirected from were? (similar to PLL_SETUP_CONTROL)
660 * bit8: A switch that turns of the second divider and multiplier off.
661 * bit12: Also a switch, i haven't seen it yet.
662 * bit16-19: p-divider
663 * but 28-31: Something related to the mode that is used (see bit8).
664 * 2) bit0-7: m-divider (a)
665 * bit8-15: n-multiplier (a)
666 * bit16-23: m-divider (b)
667 * bit24-31: n-multiplier (b)
670 /* Modifying the gpu pll for example requires:
671 * - Disable value 0x333 (inverse AND mask) on the 0xc040 register.
672 * This is not needed for the vpll's which have their own bits.
678 uint32_t requested_clock,
679 uint32_t *given_clock,
687 NVPtr pNv = NVPTR(pScrn);
688 uint32_t pll_lim_reg;
689 struct pll_lims pll_lim;
690 /* We have 2 mulitpliers, 2 dividers and one post divider */
691 /* Note that p is only 3 bits */
692 int NM1 = 0xbeef, NM2 = 0xdead, log2P = 0;
693 uint32_t special_bits = 0;
696 if (!get_pll_limits_reg(pScrn, VPLL1, &pll_lim_reg))
699 if (!get_pll_limits_reg(pScrn, VPLL2, &pll_lim_reg))
702 get_pll_limits(pScrn, pll_lim_reg, &pll_lim);
704 if (requested_clock < pll_lim.vco1.maxfreq && pNv->NVArch > 0x40) { /* single VCO */
706 /* Turn the second set of divider and multiplier off */
707 /* Bogus data, the same nvidia uses */
709 *given_clock = getMNP_single(pScrn, pll_lim_reg, requested_clock, &NM1, &log2P);
710 } else { /* dual VCO */
712 *given_clock = getMNP_double(pScrn, pll_lim_reg, requested_clock, &NM1, &NM2, &log2P);
715 /* Are this all (relevant) G70 cards? */
716 if (pNv->NVArch == 0x4B || pNv->NVArch == 0x46 || pNv->NVArch == 0x47 || pNv->NVArch == 0x49) {
717 /* This is a big guess, but should be reasonable until we can narrow it down. */
725 /* What exactly are the purpose of the upper 2 bits of pll_a and pll_b? */
726 *pll_a = (special_bits << 30) | (log2P << 16) | NM1;
727 /* This VCO2 bit is an educated guess, but it needs to stay on for NV4x. */
728 *pll_b = NV31_RAMDAC_ENABLE_VCO2 | NM2;
732 *reg580 |= NV_RAMDAC_580_VPLL1_ACTIVE;
734 *reg580 |= NV_RAMDAC_580_VPLL2_ACTIVE;
738 *reg580 &= ~NV_RAMDAC_580_VPLL1_ACTIVE;
740 *reg580 &= ~NV_RAMDAC_580_VPLL2_ACTIVE;
745 ErrorF("vpll: n1 %d m1 %d p %d db1_ratio %d\n", NM1 >> 8, NM1 & 0xff, log2P, *db1_ratio);
747 ErrorF("vpll: n1 %d n2 %d m1 %d m2 %d p %d db1_ratio %d\n", NM1 >> 8, NM2 >> 8, NM1 & 0xff, NM2 & 0xff, log2P, *db1_ratio);
751 static void nv40_crtc_save_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
753 state->vpll1_a = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL);
754 state->vpll1_b = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL_B);
755 state->vpll2_a = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL2);
756 state->vpll2_b = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL2_B);
757 state->pllsel = NVReadRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT);
758 state->sel_clk = NVReadRAMDAC(pNv, 0, NV_RAMDAC_SEL_CLK);
759 state->reg580 = NVReadRAMDAC(pNv, 0, NV_RAMDAC_580);
760 state->reg594 = NVReadRAMDAC(pNv, 0, NV_RAMDAC_594);
763 static void nv40_crtc_load_state_pll(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
765 ScrnInfoPtr pScrn = crtc->scrn;
766 NVPtr pNv = NVPTR(pScrn);
767 uint32_t fp_debug_0[2];
769 fp_debug_0[0] = NVReadRAMDAC(pNv, 0, NV_RAMDAC_FP_DEBUG_0);
770 fp_debug_0[1] = NVReadRAMDAC(pNv, 1, NV_RAMDAC_FP_DEBUG_0);
772 /* The TMDS_PLL switch is on the actual ramdac */
773 if (state->crosswired) {
776 ErrorF("Crosswired pll state load\n");
782 if (state->vpll2_b && state->vpll_changed[1]) {
783 NVWriteRAMDAC(pNv, index[1], NV_RAMDAC_FP_DEBUG_0,
784 fp_debug_0[index[1]] | NV_RAMDAC_FP_DEBUG_0_PWRDOWN_TMDS_PLL);
786 /* Wait for the situation to stabilise */
789 uint32_t reg_c040 = pNv->misc_info.reg_c040;
790 /* for vpll2 change bits 18 and 19 are disabled */
791 reg_c040 &= ~(0x3 << 18);
792 nvWriteMC(pNv, 0xc040, reg_c040);
794 ErrorF("writing vpll2_a %08X\n", state->vpll2_a);
795 ErrorF("writing vpll2_b %08X\n", state->vpll2_b);
797 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL2, state->vpll2_a);
798 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL2_B, state->vpll2_b);
800 ErrorF("writing pllsel %08X\n", state->pllsel);
801 /* Don't turn vpll1 off. */
802 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT, state->pllsel);
804 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_580, state->reg580);
805 ErrorF("writing reg580 %08X\n", state->reg580);
807 /* We need to wait a while */
809 nvWriteMC(pNv, 0xc040, pNv->misc_info.reg_c040);
811 NVWriteRAMDAC(pNv, index[1], NV_RAMDAC_FP_DEBUG_0, fp_debug_0[index[1]]);
813 /* Wait for the situation to stabilise */
817 if (state->vpll1_b && state->vpll_changed[0]) {
818 NVWriteRAMDAC(pNv, index[0], NV_RAMDAC_FP_DEBUG_0,
819 fp_debug_0[index[0]] | NV_RAMDAC_FP_DEBUG_0_PWRDOWN_TMDS_PLL);
821 /* Wait for the situation to stabilise */
824 uint32_t reg_c040 = pNv->misc_info.reg_c040;
825 /* for vpll2 change bits 16 and 17 are disabled */
826 reg_c040 &= ~(0x3 << 16);
827 nvWriteMC(pNv, 0xc040, reg_c040);
829 ErrorF("writing vpll1_a %08X\n", state->vpll1_a);
830 ErrorF("writing vpll1_b %08X\n", state->vpll1_b);
832 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL, state->vpll1_a);
833 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL_B, state->vpll1_b);
835 ErrorF("writing pllsel %08X\n", state->pllsel);
836 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT, state->pllsel);
838 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_580, state->reg580);
839 ErrorF("writing reg580 %08X\n", state->reg580);
841 /* We need to wait a while */
843 nvWriteMC(pNv, 0xc040, pNv->misc_info.reg_c040);
845 NVWriteRAMDAC(pNv, index[0], NV_RAMDAC_FP_DEBUG_0, fp_debug_0[index[0]]);
847 /* Wait for the situation to stabilise */
851 ErrorF("writing sel_clk %08X\n", state->sel_clk);
852 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_SEL_CLK, state->sel_clk);
854 ErrorF("writing reg594 %08X\n", state->reg594);
855 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_594, state->reg594);
857 /* All clocks have been set at this point. */
858 state->vpll_changed[0] = FALSE;
859 state->vpll_changed[1] = FALSE;
862 static void nv_crtc_save_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
864 state->vpll1_a = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL);
866 state->vpll2_a = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL2);
868 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
869 state->vpll1_b = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL_B);
870 state->vpll2_b = NVReadRAMDAC(pNv, 0, NV_RAMDAC_VPLL2_B);
872 state->pllsel = NVReadRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT);
873 state->sel_clk = NVReadRAMDAC(pNv, 0, NV_RAMDAC_SEL_CLK);
877 static void nv_crtc_load_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
879 /* This sequence is important, the NV28 is very sensitive in this area. */
880 /* Keep pllsel last and sel_clk first. */
881 ErrorF("writing sel_clk %08X\n", state->sel_clk);
882 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_SEL_CLK, state->sel_clk);
884 if (state->vpll2_a && state->vpll_changed[1]) {
886 ErrorF("writing vpll2_a %08X\n", state->vpll2_a);
887 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL2, state->vpll2_a);
889 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
890 ErrorF("writing vpll2_b %08X\n", state->vpll2_b);
891 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL2_B, state->vpll2_b);
895 if (state->vpll1_a && state->vpll_changed[0]) {
896 ErrorF("writing vpll1_a %08X\n", state->vpll1_a);
897 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL, state->vpll1_a);
898 if (pNv->twoStagePLL && pNv->NVArch != 0x30) {
899 ErrorF("writing vpll1_b %08X\n", state->vpll1_b);
900 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_VPLL_B, state->vpll1_b);
904 ErrorF("writing pllsel %08X\n", state->pllsel);
905 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT, state->pllsel);
907 /* All clocks have been set at this point. */
908 state->vpll_changed[0] = FALSE;
909 state->vpll_changed[1] = FALSE;
912 #define IS_NV44P (pNv->NVArch >= 0x44 ? 1 : 0)
913 #define SEL_CLK_OFFSET (nv_get_sel_clk_offset(pNv->NVArch, nv_output->bus))
915 #define WIPE_OTHER_CLOCKS(_sel_clk, _head, _bus) (nv_wipe_other_clocks(_sel_clk, pNv->NVArch, _head, _bus))
918 * Calculate extended mode parameters (SVGA) and save in a
919 * mode state structure.
920 * State is not specific to a single crtc, but shared.
922 void nv_crtc_calc_state_ext(
926 int DisplayWidth, /* Does this change after setting the mode? */
933 ScrnInfoPtr pScrn = crtc->scrn;
934 uint32_t pixelDepth, VClk = 0;
935 uint32_t CursorStart;
936 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
937 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
939 NVPtr pNv = NVPTR(pScrn);
940 RIVA_HW_STATE *state;
941 int num_crtc_enabled, i;
942 uint32_t old_clock_a = 0, old_clock_b = 0;
944 state = &pNv->ModeReg;
946 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
948 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
949 NVOutputPrivatePtr nv_output = NULL;
952 nv_output = output->driver_private;
953 if (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS)
957 /* Store old clock. */
958 if (nv_crtc->head == 1) {
959 old_clock_a = state->vpll2_a;
960 old_clock_b = state->vpll2_b;
962 old_clock_a = state->vpll1_a;
963 old_clock_b = state->vpll1_b;
967 * Extended RIVA registers.
969 /* This is pitch related, not mode related. */
970 pixelDepth = (bpp + 1)/8;
971 if (pNv->Architecture == NV_ARCH_40) {
972 /* Does register 0x580 already have a value? */
973 if (!state->reg580) {
974 state->reg580 = pNv->misc_info.ramdac_0_reg_580;
976 if (nv_crtc->head == 1) {
977 CalculateVClkNV4x(pScrn, dotClock, &VClk, &state->vpll2_a, &state->vpll2_b, &state->reg580, &state->db1_ratio[1], FALSE);
979 CalculateVClkNV4x(pScrn, dotClock, &VClk, &state->vpll1_a, &state->vpll1_b, &state->reg580, &state->db1_ratio[0], TRUE);
981 } else if (pNv->twoStagePLL) {
983 VClk = getMNP_double(pScrn, 0, dotClock, &NM1, &NM2, &log2P);
984 if (pNv->NVArch == 0x30) {
985 /* See nvregisters.xml for details. */
986 state->pll = log2P << 16 | NM1 | (NM2 & 7) << 4 | ((NM2 >> 8) & 7) << 19 | ((NM2 >> 11) & 3) << 24 | NV30_RAMDAC_ENABLE_VCO2;
988 state->pll = log2P << 16 | NM1;
989 state->pllB = NV31_RAMDAC_ENABLE_VCO2 | NM2;
993 VClk = getMNP_single(pScrn, 0, dotClock, &NM, &log2P);
994 state->pll = log2P << 16 | NM;
997 if (pNv->Architecture < NV_ARCH_40) {
998 if (nv_crtc->head == 1) {
999 state->vpll2_a = state->pll;
1000 state->vpll2_b = state->pllB;
1002 state->vpll1_a = state->pll;
1003 state->vpll1_b = state->pllB;
1007 /* always reset vpll, just to be sure. */
1008 state->vpll_changed[nv_crtc->head] = TRUE;
1010 switch (pNv->Architecture) {
1012 nv4UpdateArbitrationSettings(VClk,
1014 &(state->arbitration0),
1015 &(state->arbitration1),
1017 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x00;
1018 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = 0xbC;
1019 if (flags & V_DBLSCAN)
1020 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
1021 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = 0x00000000;
1022 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2 | NV_RAMDAC_PLL_SELECT_PLL_SOURCE_ALL;
1023 state->config = 0x00001114;
1024 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
1030 if (((pNv->Chipset & 0xfff0) == CHIPSET_C51) ||
1031 ((pNv->Chipset & 0xfff0) == CHIPSET_C512)) {
1032 state->arbitration0 = 128;
1033 state->arbitration1 = 0x0480;
1034 } else if (((pNv->Chipset & 0xffff) == CHIPSET_NFORCE) ||
1035 ((pNv->Chipset & 0xffff) == CHIPSET_NFORCE2)) {
1036 nForceUpdateArbitrationSettings(VClk,
1038 &(state->arbitration0),
1039 &(state->arbitration1),
1041 } else if (pNv->Architecture < NV_ARCH_30) {
1042 nv10UpdateArbitrationSettings(VClk,
1044 &(state->arbitration0),
1045 &(state->arbitration1),
1048 nv30UpdateArbitrationSettings(pNv,
1049 &(state->arbitration0),
1050 &(state->arbitration1));
1053 if (nv_crtc->head == 1) {
1054 CursorStart = pNv->Cursor2->offset;
1056 CursorStart = pNv->Cursor->offset;
1059 if (!NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1060 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x80 | (CursorStart >> 17);
1061 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = (CursorStart >> 11) << 2;
1062 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = CursorStart >> 24;
1064 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x0;
1065 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = 0x0;
1066 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = 0x0;
1069 if (flags & V_DBLSCAN)
1070 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
1072 state->config = nvReadFB(pNv, NV_PFB_CFG0);
1073 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
1077 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1078 /* This is a bit of a guess. */
1079 regp->CRTC[NV_VGA_CRTCX_REPAINT1] |= 0xB8;
1082 /* okay do we have 2 CRTCs running ? */
1083 num_crtc_enabled = 0;
1084 for (i = 0; i < xf86_config->num_crtc; i++) {
1085 if (xf86_config->crtc[i]->enabled) {
1090 ErrorF("There are %d CRTC's enabled\n", num_crtc_enabled);
1092 /* The main stuff seems to be valid for NV3x also. */
1093 if (pNv->Architecture >= NV_ARCH_30) {
1094 /* This register is only used on the primary ramdac */
1095 /* This seems to be needed to select the proper clocks, otherwise bad things happen */
1097 if (!state->sel_clk)
1098 state->sel_clk = pNv->misc_info.sel_clk & ~(0xf << 16);
1100 if (output && (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS)) {
1101 /* Only wipe when are a relevant (digital) output. */
1102 state->sel_clk &= ~(0xf << 16);
1103 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1104 /* Even with two dvi, this should not conflict. */
1105 if (crossed_clocks) {
1106 state->sel_clk |= (0x1 << 16);
1108 state->sel_clk |= (0x4 << 16);
1112 /* Some cards, specifically dual dvi/lvds cards set another bitrange.
1113 * I suspect inverse beheaviour to the normal bitrange, but i am not a 100% certain about this.
1114 * This is all based on default settings found in mmio-traces.
1115 * The blob never changes these, as it doesn't run unusual output configurations.
1116 * It seems to prefer situations that avoid changing these bits (for a good reason?).
1117 * I still don't know the purpose of value 2, it's similar to 4, but what exactly does it do?
1122 * bit 0 NVClk spread spectrum on/off
1123 * bit 2 MemClk spread spectrum on/off
1124 * bit 4 PixClk1 spread spectrum on/off
1125 * bit 6 PixClk2 spread spectrum on/off
1128 * what causes setting of bits not obvious but:
1129 * bits 4&5 relate to headA
1130 * bits 6&7 relate to headB
1132 /* Only let digital outputs mess with this, otherwise strange output routings may mess it up. */
1133 if (output && (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS)) {
1134 if (pNv->Architecture == NV_ARCH_40) {
1135 for (i = 0; i < 4; i++) {
1136 uint32_t var = (state->sel_clk & (0xf << 4*i)) >> 4*i;
1137 if (var == 0x1 || var == 0x4) {
1138 state->sel_clk &= ~(0xf << 4*i);
1139 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1140 if (crossed_clocks) {
1141 state->sel_clk |= (0x4 << 4*i);
1143 state->sel_clk |= (0x1 << 4*i);
1145 break; /* This should only occur once. */
1148 /* Based on NV31M. */
1149 } else if (pNv->Architecture == NV_ARCH_30) {
1150 for (i = 0; i < 4; i++) {
1151 uint32_t var = (state->sel_clk & (0xf << 4*i)) >> 4*i;
1152 if (var == 0x4 || var == 0x5) {
1153 state->sel_clk &= ~(0xf << 4*i);
1154 Bool crossed_clocks = nv_output->preferred_output ^ nv_crtc->head;
1155 if (crossed_clocks) {
1156 state->sel_clk |= (0x4 << 4*i);
1158 state->sel_clk |= (0x5 << 4*i);
1160 break; /* This should only occur once. */
1166 /* Don't change SEL_CLK on NV0x/NV1x/NV2x cards */
1167 state->sel_clk = pNv->misc_info.sel_clk;
1168 state->crosswired = FALSE;
1171 /* Are we crosswired? */
1172 if (output && nv_crtc->head != nv_output->preferred_output) {
1173 state->crosswired = TRUE;
1175 state->crosswired = FALSE;
1178 if (nv_crtc->head == 1) {
1179 if (state->db1_ratio[1])
1180 ErrorF("We are a lover of the DB1 VCLK ratio\n");
1181 } else if (nv_crtc->head == 0) {
1182 if (state->db1_ratio[0])
1183 ErrorF("We are a lover of the DB1 VCLK ratio\n");
1186 /* The NV40 seems to have more similarities to NV3x than other cards. */
1187 if (pNv->NVArch < 0x41) {
1188 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_NVPLL;
1189 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_MPLL;
1192 if (nv_crtc->head == 1) {
1193 if (!state->db1_ratio[1]) {
1194 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK2_RATIO_DB2;
1196 state->pllsel &= ~NV_RAMDAC_PLL_SELECT_VCLK2_RATIO_DB2;
1198 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_VPLL2;
1200 if (!state->db1_ratio[0]) {
1201 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2;
1203 state->pllsel &= ~NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2;
1205 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_VPLL;
1208 /* The blob uses this always, so let's do the same */
1209 if (pNv->Architecture == NV_ARCH_40) {
1210 state->pllsel |= NV_RAMDAC_PLL_SELECT_USE_VPLL2_TRUE;
1213 /* The primary output resource doesn't seem to care */
1214 if (output && pNv->Architecture == NV_ARCH_40 && nv_output->output_resource == 1) { /* This is the "output" */
1215 /* non-zero values are for analog, don't know about tv-out and the likes */
1216 if (output && nv_output->type != OUTPUT_ANALOG) {
1217 state->reg594 = 0x0;
1218 } else if (output) {
1219 /* Are we a flexible output? */
1220 if (ffs(pNv->dcb_table.entry[nv_output->dcb_entry].or) & OUTPUT_0) {
1221 state->reg594 = 0x1;
1222 pNv->restricted_mode = FALSE;
1224 state->reg594 = 0x0;
1225 pNv->restricted_mode = TRUE;
1228 /* More values exist, but they seem related to the 3rd dac (tv-out?) somehow */
1229 /* bit 16-19 are bits that are set on some G70 cards */
1230 /* Those bits are also set to the 3rd OUTPUT register */
1231 if (nv_crtc->head == 1) {
1232 state->reg594 |= 0x100;
1237 regp->CRTC[NV_VGA_CRTCX_FIFO0] = state->arbitration0;
1238 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = state->arbitration1 & 0xff;
1239 if (pNv->Architecture >= NV_ARCH_30) {
1240 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = state->arbitration1 >> 8;
1243 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1244 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = ((CrtcHDisplay/16) & 0x700) >> 3;
1245 } else if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1246 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = (((CrtcHDisplay*bpp)/64) & 0x700) >> 3;
1247 } else { /* framebuffer can be larger than crtc scanout area. */
1248 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = (((DisplayWidth/8) * pixelDepth) & 0x700) >> 3;
1250 regp->CRTC[NV_VGA_CRTCX_PIXEL] = (pixelDepth > 2) ? 3 : pixelDepth;
1254 nv_crtc_dpms(xf86CrtcPtr crtc, int mode)
1256 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1258 ErrorF("nv_crtc_dpms is called for CRTC %d with mode %d\n", nv_crtc->head, mode);
1260 if (nv_crtc->last_dpms == mode) /* Don't do unnecesary mode changes. */
1263 nv_crtc->last_dpms = mode;
1265 ScrnInfoPtr pScrn = crtc->scrn;
1266 NVPtr pNv = NVPTR(pScrn);
1267 unsigned char seq1 = 0, crtc17 = 0;
1268 unsigned char crtc1A;
1271 NVCrtcSetOwner(crtc);
1273 crtc1A = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1) & ~0xC0;
1275 case DPMSModeStandby:
1276 /* Screen: Off; HSync: Off, VSync: On -- Not Supported */
1281 case DPMSModeSuspend:
1282 /* Screen: Off; HSync: On, VSync: Off -- Not Supported */
1288 /* Screen: Off; HSync: Off, VSync: Off */
1295 /* Screen: On; HSync: On, VSync: On */
1301 NVVgaSeqReset(crtc, TRUE);
1302 /* Each head has it's own sequencer, so we can turn it off when we want */
1303 seq1 |= (NVReadVgaSeq(crtc, 0x01) & ~0x20);
1304 NVWriteVgaSeq(crtc, 0x1, seq1);
1305 crtc17 |= (NVReadVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL) & ~0x80);
1307 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL, crtc17);
1308 NVVgaSeqReset(crtc, FALSE);
1310 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, crtc1A);
1312 /* I hope this is the right place */
1313 if (crtc->enabled && mode == DPMSModeOn) {
1314 pNv->crtc_active[nv_crtc->head] = TRUE;
1316 pNv->crtc_active[nv_crtc->head] = FALSE;
1321 nv_crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
1322 DisplayModePtr adjusted_mode)
1324 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1325 ErrorF("nv_crtc_mode_fixup is called for CRTC %d\n", nv_crtc->head);
1331 nv_crtc_mode_set_vga(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1333 ScrnInfoPtr pScrn = crtc->scrn;
1334 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1336 NVPtr pNv = NVPTR(pScrn);
1337 NVFBLayout *pLayout = &pNv->CurrentLayout;
1338 int depth = pScrn->depth;
1340 /* This is pitch/memory size related. */
1341 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE))
1342 depth = pNv->console_mode[nv_crtc->head].bpp;
1344 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1346 /* Calculate our timings */
1347 int horizDisplay = (mode->CrtcHDisplay >> 3) - 1;
1348 int horizStart = (mode->CrtcHSyncStart >> 3) - 1;
1349 int horizEnd = (mode->CrtcHSyncEnd >> 3) - 1;
1350 int horizTotal = (mode->CrtcHTotal >> 3) - 5;
1351 int horizBlankStart = (mode->CrtcHDisplay >> 3) - 1;
1352 int horizBlankEnd = (mode->CrtcHTotal >> 3) - 1;
1353 int vertDisplay = mode->CrtcVDisplay - 1;
1354 int vertStart = mode->CrtcVSyncStart - 1;
1355 int vertEnd = mode->CrtcVSyncEnd - 1;
1356 int vertTotal = mode->CrtcVTotal - 2;
1357 int vertBlankStart = mode->CrtcVDisplay - 1;
1358 int vertBlankEnd = mode->CrtcVTotal - 1;
1362 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1363 NVOutputPrivatePtr nv_output = NULL;
1365 nv_output = output->driver_private;
1367 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1371 ErrorF("Mode clock: %d\n", mode->Clock);
1372 ErrorF("Adjusted mode clock: %d\n", adjusted_mode->Clock);
1374 /* Reverted to what nv did, because that works for all resolutions on flatpanels */
1376 vertStart = vertTotal - 3;
1377 vertEnd = vertTotal - 2;
1378 vertBlankStart = vertStart;
1379 horizStart = horizTotal - 5;
1380 horizEnd = horizTotal - 2;
1381 horizBlankEnd = horizTotal + 4;
1382 if (pNv->overlayAdaptor && pNv->Architecture >= NV_ARCH_10) {
1383 /* This reportedly works around Xv some overlay bandwidth problems*/
1388 if (mode->Flags & V_INTERLACE)
1391 ErrorF("horizDisplay: 0x%X \n", horizDisplay);
1392 ErrorF("horizStart: 0x%X \n", horizStart);
1393 ErrorF("horizEnd: 0x%X \n", horizEnd);
1394 ErrorF("horizTotal: 0x%X \n", horizTotal);
1395 ErrorF("horizBlankStart: 0x%X \n", horizBlankStart);
1396 ErrorF("horizBlankEnd: 0x%X \n", horizBlankEnd);
1397 ErrorF("vertDisplay: 0x%X \n", vertDisplay);
1398 ErrorF("vertStart: 0x%X \n", vertStart);
1399 ErrorF("vertEnd: 0x%X \n", vertEnd);
1400 ErrorF("vertTotal: 0x%X \n", vertTotal);
1401 ErrorF("vertBlankStart: 0x%X \n", vertBlankStart);
1402 ErrorF("vertBlankEnd: 0x%X \n", vertBlankEnd);
1405 * compute correct Hsync & Vsync polarity
1407 if ((mode->Flags & (V_PHSYNC | V_NHSYNC))
1408 && (mode->Flags & (V_PVSYNC | V_NVSYNC))) {
1410 regp->MiscOutReg = 0x23;
1411 if (mode->Flags & V_NHSYNC) regp->MiscOutReg |= 0x40;
1412 if (mode->Flags & V_NVSYNC) regp->MiscOutReg |= 0x80;
1414 int VDisplay = mode->VDisplay;
1415 if (mode->Flags & V_DBLSCAN)
1417 if (mode->VScan > 1)
1418 VDisplay *= mode->VScan;
1419 if (VDisplay < 400) {
1420 regp->MiscOutReg = 0xA3; /* +hsync -vsync */
1421 } else if (VDisplay < 480) {
1422 regp->MiscOutReg = 0x63; /* -hsync +vsync */
1423 } else if (VDisplay < 768) {
1424 regp->MiscOutReg = 0xE3; /* -hsync -vsync */
1426 regp->MiscOutReg = 0x23; /* +hsync +vsync */
1430 regp->MiscOutReg |= (mode->ClockIndex & 0x03) << 2;
1435 regp->Sequencer[0] = 0x00;
1436 /* 0x20 disables the sequencer */
1437 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1438 if (mode->HDisplay == 720) {
1439 regp->Sequencer[1] = 0x21; /* enable 9/8 mode */
1441 regp->Sequencer[1] = 0x20;
1444 if (mode->Flags & V_CLKDIV2) {
1445 regp->Sequencer[1] = 0x29;
1447 regp->Sequencer[1] = 0x21;
1450 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1451 regp->Sequencer[2] = 0x03; /* select 2 out of 4 planes */
1453 regp->Sequencer[2] = 0x0F;
1455 regp->Sequencer[3] = 0x00; /* Font select */
1456 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1457 regp->Sequencer[4] = 0x02;
1459 regp->Sequencer[4] = 0x0E; /* Misc */
1465 regp->CRTC[NV_VGA_CRTCX_HTOTAL] = Set8Bits(horizTotal);
1466 regp->CRTC[NV_VGA_CRTCX_HDISPE] = Set8Bits(horizDisplay);
1467 regp->CRTC[NV_VGA_CRTCX_HBLANKS] = Set8Bits(horizBlankStart);
1468 regp->CRTC[NV_VGA_CRTCX_HBLANKE] = SetBitField(horizBlankEnd,4:0,4:0)
1470 regp->CRTC[NV_VGA_CRTCX_HSYNCS] = Set8Bits(horizStart);
1471 regp->CRTC[NV_VGA_CRTCX_HSYNCE] = SetBitField(horizBlankEnd,5:5,7:7)
1472 | SetBitField(horizEnd,4:0,4:0);
1473 regp->CRTC[NV_VGA_CRTCX_VTOTAL] = SetBitField(vertTotal,7:0,7:0);
1474 regp->CRTC[NV_VGA_CRTCX_OVERFLOW] = SetBitField(vertTotal,8:8,0:0)
1475 | SetBitField(vertDisplay,8:8,1:1)
1476 | SetBitField(vertStart,8:8,2:2)
1477 | SetBitField(vertBlankStart,8:8,3:3)
1479 | SetBitField(vertTotal,9:9,5:5)
1480 | SetBitField(vertDisplay,9:9,6:6)
1481 | SetBitField(vertStart,9:9,7:7);
1482 regp->CRTC[NV_VGA_CRTCX_PRROWSCN] = 0x00;
1483 regp->CRTC[NV_VGA_CRTCX_MAXSCLIN] = SetBitField(vertBlankStart,9:9,5:5)
1485 | ((mode->Flags & V_DBLSCAN) ? 0x80 : 0x00)
1486 | (NVMatchModePrivate(mode, NV_MODE_VGA) ? 0xF : 0x00); /* 8x15 chars */
1487 if (NVMatchModePrivate(mode, NV_MODE_VGA)) { /* Were do these cursor offsets come from? */
1488 regp->CRTC[NV_VGA_CRTCX_VGACURSTART] = 0xD; /* start scanline */
1489 regp->CRTC[NV_VGA_CRTCX_VGACUREND] = 0xE; /* end scanline */
1491 regp->CRTC[NV_VGA_CRTCX_VGACURSTART] = 0x00;
1492 regp->CRTC[NV_VGA_CRTCX_VGACUREND] = 0x00;
1494 regp->CRTC[NV_VGA_CRTCX_FBSTADDH] = 0x00;
1495 regp->CRTC[NV_VGA_CRTCX_FBSTADDL] = 0x00;
1496 regp->CRTC[0xe] = 0x00;
1497 regp->CRTC[0xf] = 0x00;
1498 regp->CRTC[NV_VGA_CRTCX_VSYNCS] = Set8Bits(vertStart);
1499 /* What is the meaning of bit5, it is empty in the vga spec. */
1500 regp->CRTC[NV_VGA_CRTCX_VSYNCE] = SetBitField(vertEnd,3:0,3:0) |
1501 (NVMatchModePrivate(mode, NV_MODE_VGA) ? 0 : SetBit(5));
1502 regp->CRTC[NV_VGA_CRTCX_VDISPE] = Set8Bits(vertDisplay);
1503 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1504 regp->CRTC[NV_VGA_CRTCX_PITCHL] = (mode->CrtcHDisplay/16);
1505 } else if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1506 regp->CRTC[NV_VGA_CRTCX_PITCHL] = ((mode->CrtcHDisplay*depth)/64);
1507 } else { /* framebuffer can be larger than crtc scanout area. */
1508 regp->CRTC[NV_VGA_CRTCX_PITCHL] = ((pScrn->displayWidth/8)*(pLayout->bitsPerPixel/8));
1510 if (depth == 4) { /* How can these values be calculated? */
1511 regp->CRTC[NV_VGA_CRTCX_UNDERLINE] = 0x1F;
1513 regp->CRTC[NV_VGA_CRTCX_UNDERLINE] = 0x00;
1515 regp->CRTC[NV_VGA_CRTCX_VBLANKS] = Set8Bits(vertBlankStart);
1516 regp->CRTC[NV_VGA_CRTCX_VBLANKE] = Set8Bits(vertBlankEnd);
1517 /* 0x80 enables the sequencer, we don't want that */
1518 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1519 regp->CRTC[NV_VGA_CRTCX_MODECTL] = 0xA3 & ~0x80;
1520 } else if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1521 regp->CRTC[NV_VGA_CRTCX_MODECTL] = 0xE3 & ~0x80;
1523 regp->CRTC[NV_VGA_CRTCX_MODECTL] = 0xC3 & ~0x80;
1525 regp->CRTC[NV_VGA_CRTCX_LINECOMP] = 0xff;
1528 * Some extended CRTC registers (they are not saved with the rest of the vga regs).
1531 regp->CRTC[NV_VGA_CRTCX_LSR] = SetBitField(horizBlankEnd,6:6,4:4)
1532 | SetBitField(vertBlankStart,10:10,3:3)
1533 | SetBitField(vertStart,10:10,2:2)
1534 | SetBitField(vertDisplay,10:10,1:1)
1535 | SetBitField(vertTotal,10:10,0:0);
1537 regp->CRTC[NV_VGA_CRTCX_HEB] = SetBitField(horizTotal,8:8,0:0)
1538 | SetBitField(horizDisplay,8:8,1:1)
1539 | SetBitField(horizBlankStart,8:8,2:2)
1540 | SetBitField(horizStart,8:8,3:3);
1542 regp->CRTC[NV_VGA_CRTCX_EXTRA] = SetBitField(vertTotal,11:11,0:0)
1543 | SetBitField(vertDisplay,11:11,2:2)
1544 | SetBitField(vertStart,11:11,4:4)
1545 | SetBitField(vertBlankStart,11:11,6:6);
1547 if(mode->Flags & V_INTERLACE) {
1548 horizTotal = (horizTotal >> 1) & ~1;
1549 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = Set8Bits(horizTotal);
1550 regp->CRTC[NV_VGA_CRTCX_HEB] |= SetBitField(horizTotal,8:8,4:4);
1552 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = 0xff; /* interlace off */
1556 * Theory resumes here....
1560 * Graphics Display Controller
1562 regp->Graphics[0] = 0x00;
1563 regp->Graphics[1] = 0x00;
1564 regp->Graphics[2] = 0x00;
1565 regp->Graphics[3] = 0x00;
1566 regp->Graphics[4] = 0x00;
1567 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1568 regp->Graphics[5] = 0x10;
1569 regp->Graphics[6] = 0x0E; /* map 32k mem */
1570 regp->Graphics[7] = 0x00;
1572 regp->Graphics[5] = 0x40; /* 256 color mode */
1573 regp->Graphics[6] = 0x05; /* map 64k mem + graphic mode */
1574 regp->Graphics[7] = 0x0F;
1576 regp->Graphics[8] = 0xFF;
1578 /* I ditched the mono stuff */
1579 regp->Attribute[0] = 0x00; /* standard colormap translation */
1580 regp->Attribute[1] = 0x01;
1581 regp->Attribute[2] = 0x02;
1582 regp->Attribute[3] = 0x03;
1583 regp->Attribute[4] = 0x04;
1584 regp->Attribute[5] = 0x05;
1585 regp->Attribute[6] = 0x06;
1586 regp->Attribute[7] = 0x07;
1587 regp->Attribute[8] = 0x08;
1588 regp->Attribute[9] = 0x09;
1589 regp->Attribute[10] = 0x0A;
1590 regp->Attribute[11] = 0x0B;
1591 regp->Attribute[12] = 0x0C;
1592 regp->Attribute[13] = 0x0D;
1593 regp->Attribute[14] = 0x0E;
1594 regp->Attribute[15] = 0x0F;
1595 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1596 regp->Attribute[16] = 0x0C; /* Line Graphics Enable + Blink enable */
1598 regp->Attribute[16] = 0x01; /* Enable graphic mode */
1601 regp->Attribute[17] = 0x00;
1602 regp->Attribute[18] = 0x0F; /* enable all color planes */
1603 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1604 regp->Attribute[19] = 0x08; /* shift bits by 8 */
1606 regp->Attribute[19] = 0x00;
1608 regp->Attribute[20] = 0x00;
1611 #define MAX_H_VALUE(i) ((0x1ff + i) << 3)
1612 #define MAX_V_VALUE(i) ((0xfff + i) << 0)
1615 * Sets up registers for the given mode/adjusted_mode pair.
1617 * The clocks, CRTCs and outputs attached to this CRTC must be off.
1619 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
1620 * be easily turned on/off after this.
1623 nv_crtc_mode_set_regs(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1625 ScrnInfoPtr pScrn = crtc->scrn;
1626 NVPtr pNv = NVPTR(pScrn);
1627 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1628 NVFBLayout *pLayout = &pNv->CurrentLayout;
1629 NVCrtcRegPtr regp, savep;
1632 Bool is_lvds = FALSE;
1634 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1635 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
1637 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1638 NVOutputPrivatePtr nv_output = NULL;
1640 nv_output = output->driver_private;
1642 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1645 if (nv_output->type == OUTPUT_LVDS)
1649 /* Registers not directly related to the (s)vga mode */
1651 /* bit2 = 0 -> fine pitched crtc granularity */
1652 /* The rest disables double buffering on CRTC access */
1653 regp->CRTC[NV_VGA_CRTCX_BUFFER] = 0xfa;
1655 if (savep->CRTC[NV_VGA_CRTCX_LCD] <= 0xb) {
1656 /* Common values are 0x0, 0x3, 0x8, 0xb, see logic below */
1657 if (nv_crtc->head == 0) {
1658 regp->CRTC[NV_VGA_CRTCX_LCD] = (1 << 3);
1662 regp->CRTC[NV_VGA_CRTCX_LCD] |= (1 << 0);
1663 if (!NVMatchModePrivate(mode, NV_MODE_VGA)) {
1664 regp->CRTC[NV_VGA_CRTCX_LCD] |= (1 << 1);
1668 /* Let's keep any abnormal value there may be, like 0x54 or 0x79 */
1669 regp->CRTC[NV_VGA_CRTCX_LCD] = savep->CRTC[NV_VGA_CRTCX_LCD];
1672 /* Sometimes 0x10 is used, what is this? */
1673 regp->CRTC[NV_VGA_CRTCX_59] = 0x0;
1674 /* Some kind of tmds switch for older cards */
1675 if (pNv->Architecture < NV_ARCH_40) {
1676 regp->CRTC[NV_VGA_CRTCX_59] |= 0x1;
1680 * Initialize DAC palette.
1681 * Will only be written when depth != 8.
1683 for (i = 0; i < 256; i++) {
1685 regp->DAC[(i*3)+1] = i;
1686 regp->DAC[(i*3)+2] = i;
1690 * Calculate the extended registers.
1693 if (pLayout->depth < 24) {
1694 depth = pLayout->depth;
1699 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1700 /* bpp is pitch related. */
1701 depth = pNv->console_mode[nv_crtc->head].bpp;
1704 /* What is the meaning of this register? */
1705 /* A few popular values are 0x18, 0x1c, 0x38, 0x3c */
1706 regp->CRTC[NV_VGA_CRTCX_FIFO1] = savep->CRTC[NV_VGA_CRTCX_FIFO1] & ~(1<<5);
1710 /* NV40's don't set FPP units, unless in special conditions (then they set both) */
1711 /* But what are those special conditions? */
1712 if (pNv->Architecture <= NV_ARCH_30) {
1714 if(nv_crtc->head == 1) {
1715 regp->head |= NV_CRTC_FSEL_FPP1;
1716 } else if (pNv->twoHeads) {
1717 regp->head |= NV_CRTC_FSEL_FPP2;
1721 /* Most G70 cards have FPP2 set on the secondary CRTC. */
1722 if (nv_crtc->head == 1 && pNv->NVArch > 0x44) {
1723 regp->head |= NV_CRTC_FSEL_FPP2;
1727 /* Except for rare conditions I2C is enabled on the primary crtc */
1728 if (nv_crtc->head == 0) {
1729 regp->head |= NV_CRTC_FSEL_I2C;
1732 /* Set overlay to desired crtc. */
1733 if (pNv->overlayAdaptor) {
1734 NVPortPrivPtr pPriv = GET_OVERLAY_PRIVATE(pNv);
1735 if (pPriv->overlayCRTC == nv_crtc->head)
1736 regp->head |= NV_CRTC_FSEL_OVERLAY;
1739 /* This is not what nv does, but it is what the blob does (for nv4x at least) */
1740 /* This fixes my cursor corruption issue */
1741 regp->cursorConfig = 0x0;
1742 if(mode->Flags & V_DBLSCAN)
1743 regp->cursorConfig |= NV_CRTC_CURSOR_CONFIG_DOUBLE_SCAN;
1744 if (pNv->alphaCursor && !NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1745 regp->cursorConfig |= (NV_CRTC_CURSOR_CONFIG_32BPP |
1746 NV_CRTC_CURSOR_CONFIG_64PIXELS |
1747 NV_CRTC_CURSOR_CONFIG_64LINES |
1748 NV_CRTC_CURSOR_CONFIG_ALPHA_BLEND);
1750 regp->cursorConfig |= NV_CRTC_CURSOR_CONFIG_32LINES;
1753 /* Unblock some timings */
1754 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = 0;
1755 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = 0;
1757 /* What is the purpose of this register? */
1758 /* 0x14 may be disabled? */
1759 regp->CRTC[NV_VGA_CRTCX_26] = 0x20;
1761 /* 0x00 is disabled, 0x11 is lvds, 0x22 crt and 0x88 tmds */
1763 regp->CRTC[NV_VGA_CRTCX_3B] = 0x11;
1765 regp->CRTC[NV_VGA_CRTCX_3B] = 0x88;
1767 regp->CRTC[NV_VGA_CRTCX_3B] = 0x22;
1770 /* These values seem to vary */
1771 /* This register seems to be used by the bios to make certain decisions on some G70 cards? */
1772 regp->CRTC[NV_VGA_CRTCX_3C] = savep->CRTC[NV_VGA_CRTCX_3C];
1774 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1775 regp->CRTC[NV_VGA_CRTCX_45] = 0x0;
1777 regp->CRTC[NV_VGA_CRTCX_45] = 0x80;
1780 /* What does this do?:
1783 * bit7: lvds + tmds (only in X)
1785 if (nv_crtc->head == 0)
1786 regp->CRTC[NV_VGA_CRTCX_4B] = 0x1;
1788 regp->CRTC[NV_VGA_CRTCX_4B] = 0x0;
1791 regp->CRTC[NV_VGA_CRTCX_4B] |= 0x40;
1793 if (is_fp && !NVMatchModePrivate(mode, NV_MODE_VGA))
1794 regp->CRTC[NV_VGA_CRTCX_4B] |= 0x80;
1796 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) { /* we need consistent restore. */
1797 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_reg_52[nv_crtc->head];
1799 /* The blob seems to take the current value from crtc 0, add 4 to that and reuse the old value for crtc 1.*/
1800 if (nv_crtc->head == 1) {
1801 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_reg_52[0];
1803 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_reg_52[0] + 4;
1808 /* The exact purpose of this register is unknown, but we copy value from crtc0 */
1809 regp->unk81c = NVReadCRTC(pNv, 0, NV_CRTC_081C);
1811 if (NVMatchModePrivate(mode, NV_MODE_VGA)) {
1815 regp->unk830 = mode->CrtcVDisplay - 3;
1816 regp->unk834 = mode->CrtcVDisplay - 1;
1820 /* This is what the blob does */
1821 regp->unk850 = NVReadCRTC(pNv, 0, NV_CRTC_0850);
1823 /* Never ever modify gpio, unless you know very well what you're doing */
1824 regp->gpio = NVReadCRTC(pNv, 0, NV_CRTC_GPIO);
1826 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
1827 regp->config = 0x0; /* VGA mode */
1829 regp->config = 0x2; /* HSYNC mode */
1832 /* Some misc regs */
1833 regp->CRTC[NV_VGA_CRTCX_43] = 0x1;
1834 if (pNv->Architecture == NV_ARCH_40) {
1835 regp->CRTC[NV_VGA_CRTCX_85] = 0xFF;
1836 regp->CRTC[NV_VGA_CRTCX_86] = 0x1;
1840 * Calculate the state that is common to all crtc's (stored in the state struct).
1842 ErrorF("crtc %d %d %d\n", nv_crtc->head, mode->CrtcHDisplay, pScrn->displayWidth);
1843 nv_crtc_calc_state_ext(crtc,
1846 pScrn->displayWidth,
1849 adjusted_mode->Clock,
1852 /* Enable slaved mode */
1854 regp->CRTC[NV_VGA_CRTCX_PIXEL] |= (1 << 7);
1859 nv_crtc_mode_set_ramdac_regs(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode)
1861 ScrnInfoPtr pScrn = crtc->scrn;
1862 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1863 NVCrtcRegPtr regp, savep;
1864 NVPtr pNv = NVPTR(pScrn);
1865 NVFBLayout *pLayout = &pNv->CurrentLayout;
1867 Bool is_lvds = FALSE;
1868 float aspect_ratio, panel_ratio;
1869 uint32_t h_scale, v_scale;
1871 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1872 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
1874 xf86OutputPtr output = NVGetOutputFromCRTC(crtc);
1875 NVOutputPrivatePtr nv_output = NULL;
1877 nv_output = output->driver_private;
1879 if ((nv_output->type == OUTPUT_LVDS) || (nv_output->type == OUTPUT_TMDS))
1882 if (nv_output->type == OUTPUT_LVDS)
1887 regp->fp_horiz_regs[REG_DISP_END] = adjusted_mode->HDisplay - 1;
1888 regp->fp_horiz_regs[REG_DISP_TOTAL] = adjusted_mode->HTotal - 1;
1889 /* This is what the blob does. */
1890 regp->fp_horiz_regs[REG_DISP_CRTC] = adjusted_mode->HSyncStart - 75 - 1;
1891 regp->fp_horiz_regs[REG_DISP_SYNC_START] = adjusted_mode->HSyncStart - 1;
1892 regp->fp_horiz_regs[REG_DISP_SYNC_END] = adjusted_mode->HSyncEnd - 1;
1893 regp->fp_horiz_regs[REG_DISP_VALID_START] = adjusted_mode->HSkew;
1894 regp->fp_horiz_regs[REG_DISP_VALID_END] = adjusted_mode->HDisplay - 1;
1896 regp->fp_vert_regs[REG_DISP_END] = adjusted_mode->VDisplay - 1;
1897 regp->fp_vert_regs[REG_DISP_TOTAL] = adjusted_mode->VTotal - 1;
1898 /* This is what the blob does. */
1899 regp->fp_vert_regs[REG_DISP_CRTC] = adjusted_mode->VTotal - 5 - 1;
1900 regp->fp_vert_regs[REG_DISP_SYNC_START] = adjusted_mode->VSyncStart - 1;
1901 regp->fp_vert_regs[REG_DISP_SYNC_END] = adjusted_mode->VSyncEnd - 1;
1902 regp->fp_vert_regs[REG_DISP_VALID_START] = 0;
1903 regp->fp_vert_regs[REG_DISP_VALID_END] = adjusted_mode->VDisplay - 1;
1905 ErrorF("Horizontal:\n");
1906 ErrorF("REG_DISP_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_END]);
1907 ErrorF("REG_DISP_TOTAL: 0x%X\n", regp->fp_horiz_regs[REG_DISP_TOTAL]);
1908 ErrorF("REG_DISP_CRTC: 0x%X\n", regp->fp_horiz_regs[REG_DISP_CRTC]);
1909 ErrorF("REG_DISP_SYNC_START: 0x%X\n", regp->fp_horiz_regs[REG_DISP_SYNC_START]);
1910 ErrorF("REG_DISP_SYNC_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_SYNC_END]);
1911 ErrorF("REG_DISP_VALID_START: 0x%X\n", regp->fp_horiz_regs[REG_DISP_VALID_START]);
1912 ErrorF("REG_DISP_VALID_END: 0x%X\n", regp->fp_horiz_regs[REG_DISP_VALID_END]);
1914 ErrorF("Vertical:\n");
1915 ErrorF("REG_DISP_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_END]);
1916 ErrorF("REG_DISP_TOTAL: 0x%X\n", regp->fp_vert_regs[REG_DISP_TOTAL]);
1917 ErrorF("REG_DISP_CRTC: 0x%X\n", regp->fp_vert_regs[REG_DISP_CRTC]);
1918 ErrorF("REG_DISP_SYNC_START: 0x%X\n", regp->fp_vert_regs[REG_DISP_SYNC_START]);
1919 ErrorF("REG_DISP_SYNC_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_SYNC_END]);
1920 ErrorF("REG_DISP_VALID_START: 0x%X\n", regp->fp_vert_regs[REG_DISP_VALID_START]);
1921 ErrorF("REG_DISP_VALID_END: 0x%X\n", regp->fp_vert_regs[REG_DISP_VALID_END]);
1925 * bit0: positive vsync
1926 * bit4: positive hsync
1927 * bit8: enable center mode
1928 * bit9: enable native mode
1929 * bit24: 12/24 bit interface (12bit=on, 24bit=off)
1930 * bit26: a bit sometimes seen on some g70 cards
1931 * bit28: fp display enable bit
1932 * bit31: set for dual link LVDS
1933 * nv10reg contains a few more things, but i don't quite get what it all means.
1936 if (pNv->Architecture >= NV_ARCH_30)
1937 regp->fp_control[nv_crtc->head] = 0x00100000;
1939 regp->fp_control[nv_crtc->head] = 0x00000000;
1941 /* Deal with vsync/hsync polarity */
1942 /* LVDS screens do set this, but modes with +ve syncs are very rare */
1944 if (adjusted_mode->Flags & V_PVSYNC)
1945 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_VSYNC_POS;
1946 if (adjusted_mode->Flags & V_PHSYNC)
1947 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_HSYNC_POS;
1949 /* The blob doesn't always do this, but often */
1950 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_VSYNC_DISABLE;
1951 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_HSYNC_DISABLE;
1955 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) /* seems to be used almost always */
1956 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_MODE_SCALE;
1957 else if (nv_output->scaling_mode == SCALE_PANEL) /* panel needs to scale */
1958 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_MODE_CENTER;
1959 /* This is also true for panel scaling, so we must put the panel scale check first */
1960 else if (mode->Clock == adjusted_mode->Clock) /* native mode */
1961 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_MODE_NATIVE;
1962 else /* gpu needs to scale */
1963 regp->fp_control[nv_crtc->head] |= NV_RAMDAC_FP_CONTROL_MODE_SCALE;
1966 if (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) & NV_PEXTDEV_BOOT_0_STRAP_FP_IFACE_12BIT)
1967 regp->fp_control[nv_crtc->head] |= NV_PRAMDAC_FP_TG_CONTROL_WIDTH_12;
1969 /* If the special bit exists, it exists on both ramdacs */
1970 regp->fp_control[nv_crtc->head] |= NVReadRAMDAC(pNv, 0, NV_RAMDAC_FP_CONTROL) & (1 << 26);
1973 regp->fp_control[nv_crtc->head] |= NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS;
1975 regp->fp_control[nv_crtc->head] |= NV_PRAMDAC_FP_TG_CONTROL_DISPEN_DISABLE;
1977 Bool lvds_use_straps = pNv->dcb_table.entry[nv_output->dcb_entry].lvdsconf.use_straps_for_mode;
1978 if (is_lvds && ((lvds_use_straps && pNv->VBIOS.fp.dual_link) || (!lvds_use_straps && adjusted_mode->Clock >= pNv->VBIOS.fp.duallink_transition_clk)))
1979 regp->fp_control[nv_crtc->head] |= (8 << 28);
1982 ErrorF("Pre-panel scaling\n");
1983 ErrorF("panel-size:%dx%d\n", nv_output->fpWidth, nv_output->fpHeight);
1984 panel_ratio = (nv_output->fpWidth)/(float)(nv_output->fpHeight);
1985 ErrorF("panel_ratio=%f\n", panel_ratio);
1986 aspect_ratio = (mode->HDisplay)/(float)(mode->VDisplay);
1987 ErrorF("aspect_ratio=%f\n", aspect_ratio);
1988 /* Scale factors is the so called 20.12 format, taken from Haiku */
1989 h_scale = ((1 << 12) * mode->HDisplay)/nv_output->fpWidth;
1990 v_scale = ((1 << 12) * mode->VDisplay)/nv_output->fpHeight;
1991 ErrorF("h_scale=%d\n", h_scale);
1992 ErrorF("v_scale=%d\n", v_scale);
1994 /* This can override HTOTAL and VTOTAL */
1997 /* We want automatic scaling */
2000 regp->fp_hvalid_start = 0;
2001 regp->fp_hvalid_end = (nv_output->fpWidth - 1);
2003 regp->fp_vvalid_start = 0;
2004 regp->fp_vvalid_end = (nv_output->fpHeight - 1);
2006 /* 0 = panel scaling */
2007 if (nv_output->scaling_mode == SCALE_PANEL) {
2008 ErrorF("Flat panel is doing the scaling.\n");
2010 ErrorF("GPU is doing the scaling.\n");
2012 if (nv_output->scaling_mode == SCALE_ASPECT) {
2013 /* GPU scaling happens automaticly at a ratio of 1.33 */
2014 /* A 1280x1024 panel has a ratio of 1.25, we don't want to scale that at 4:3 resolutions */
2015 if (h_scale != (1 << 12) && (panel_ratio > (aspect_ratio + 0.10))) {
2018 ErrorF("Scaling resolution on a widescreen panel\n");
2020 /* Scaling in both directions needs to the same */
2023 /* Set a new horizontal scale factor and enable testmode (bit12) */
2024 regp->debug_1 = ((h_scale >> 1) & 0xfff) | (1 << 12);
2026 diff = nv_output->fpWidth - (((1 << 12) * mode->HDisplay)/h_scale);
2027 regp->fp_hvalid_start = diff/2;
2028 regp->fp_hvalid_end = nv_output->fpWidth - (diff/2) - 1;
2031 /* Same scaling, just for panels with aspect ratio's smaller than 1 */
2032 if (v_scale != (1 << 12) && (panel_ratio < (aspect_ratio - 0.10))) {
2035 ErrorF("Scaling resolution on a portrait panel\n");
2037 /* Scaling in both directions needs to the same */
2040 /* Set a new vertical scale factor and enable testmode (bit28) */
2041 regp->debug_1 = (((v_scale >> 1) & 0xfff) << 16) | (1 << (12 + 16));
2043 diff = nv_output->fpHeight - (((1 << 12) * mode->VDisplay)/v_scale);
2044 regp->fp_vvalid_start = diff/2;
2045 regp->fp_vvalid_end = nv_output->fpHeight - (diff/2) - 1;
2050 ErrorF("Post-panel scaling\n");
2053 if (!is_fp && NVMatchModePrivate(mode, NV_MODE_VGA)) {
2054 regp->debug_1 = 0x08000800;
2057 if (pNv->Architecture >= NV_ARCH_10) {
2058 /* Only bit that bios and blob set. */
2059 regp->nv10_cursync = (1<<25);
2062 /* These are the common blob values, minus a few fp specific bit's */
2063 /* Let's keep the TMDS pll and fpclock running in all situations */
2064 regp->debug_0[nv_crtc->head] = 0x1101100;
2066 if (is_fp && nv_output->scaling_mode != SCALE_NOSCALE) {
2067 regp->debug_0[nv_crtc->head] |= NV_RAMDAC_FP_DEBUG_0_XSCALE_ENABLED;
2068 regp->debug_0[nv_crtc->head] |= NV_RAMDAC_FP_DEBUG_0_YSCALE_ENABLED;
2069 } else if (is_fp) { /* no_scale mode, so we must center it */
2072 diff = nv_output->fpWidth - mode->HDisplay;
2073 regp->fp_hvalid_start = diff/2;
2074 regp->fp_hvalid_end = (nv_output->fpWidth - diff/2 - 1);
2076 diff = nv_output->fpHeight - mode->VDisplay;
2077 regp->fp_vvalid_start = diff/2;
2078 regp->fp_vvalid_end = (nv_output->fpHeight - diff/2 - 1);
2081 /* Is this crtc bound or output bound? */
2082 /* Does the bios TMDS script try to change this sometimes? */
2084 /* I am not completely certain, but seems to be set only for dfp's */
2085 regp->debug_0[nv_crtc->head] |= NV_RAMDAC_FP_DEBUG_0_TMDS_ENABLED;
2089 ErrorF("output %d debug_0 %08X\n", nv_output->output_resource, regp->debug_0[nv_crtc->head]);
2091 /* Flatpanel support needs at least a NV10 */
2092 if (pNv->twoHeads) {
2093 /* The blob does this differently. */
2094 /* TODO: Find out what precisely and why. */
2095 /* Let's not destroy any bits that were already present. */
2096 if (pNv->FPDither || (is_lvds && pNv->VBIOS.fp.if_is_18bit)) {
2097 if (pNv->NVArch == 0x11) {
2098 regp->dither = savep->dither | 0x00010000;
2100 regp->dither = savep->dither | 0x00000001;
2103 regp->dither = savep->dither;
2108 /* This is mode related, not pitch. */
2109 if (NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
2110 depth = pNv->console_mode[nv_crtc->head].depth;
2112 depth = pLayout->depth;
2117 regp->general = 0x00000100;
2121 regp->general = 0x00100100;
2127 regp->general = 0x00101100;
2131 if (depth > 8 && !NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
2132 regp->general |= 0x30; /* enable palette mode */
2135 if (pNv->alphaCursor && !NVMatchModePrivate(mode, NV_MODE_CONSOLE)) {
2136 /* PIPE_LONG mode, something to do with the size of the cursor? */
2137 regp->general |= (1<<29);
2140 /* Some values the blob sets */
2141 /* This may apply to the real ramdac that is being used (for crosswired situations) */
2142 /* Nevertheless, it's unlikely to cause many problems, since the values are equal for both */
2143 regp->unk_a20 = 0x0;
2144 regp->unk_a24 = 0xfffff;
2145 regp->unk_a34 = 0x1;
2147 if (pNv->twoHeads) {
2148 /* Do we also "own" the other register pair? */
2149 /* If we own neither, they will just be ignored at load time. */
2150 uint8_t other_head = (~nv_crtc->head) & 1;
2151 if (pNv->fp_regs_owner[other_head] == nv_crtc->head) {
2152 if (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS) {
2153 regp->fp_control[other_head] = regp->fp_control[nv_crtc->head];
2154 regp->debug_0[other_head] = regp->debug_0[nv_crtc->head];
2155 /* Set TMDS_PLL and FPCLK, only seen for a NV31M so far. */
2156 regp->debug_0[nv_crtc->head] |= NV_RAMDAC_FP_DEBUG_0_PWRDOWN_FPCLK;
2157 regp->debug_0[other_head] |= NV_RAMDAC_FP_DEBUG_0_PWRDOWN_TMDS_PLL;
2159 ErrorF("This is BAD, we own more than one fp reg set, but are not a LVDS or TMDS output.\n");
2166 * Sets up registers for the given mode/adjusted_mode pair.
2168 * The clocks, CRTCs and outputs attached to this CRTC must be off.
2170 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
2171 * be easily turned on/off after this.
2174 nv_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
2175 DisplayModePtr adjusted_mode,
2178 ScrnInfoPtr pScrn = crtc->scrn;
2179 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2180 NVPtr pNv = NVPTR(pScrn);
2181 NVFBLayout *pLayout = &pNv->CurrentLayout;
2183 ErrorF("nv_crtc_mode_set is called for CRTC %d\n", nv_crtc->head);
2185 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode on CRTC %d\n", nv_crtc->head);
2186 xf86PrintModeline(pScrn->scrnIndex, mode);
2188 NVCrtcSetOwner(crtc);
2190 nv_crtc_mode_set_vga(crtc, mode, adjusted_mode);
2191 nv_crtc_mode_set_regs(crtc, mode, adjusted_mode);
2192 nv_crtc_mode_set_ramdac_regs(crtc, mode, adjusted_mode);
2194 NVVgaProtect(crtc, TRUE);
2195 nv_crtc_load_state_ramdac(crtc, &pNv->ModeReg);
2196 nv_crtc_load_state_ext(crtc, &pNv->ModeReg, FALSE);
2197 if (pLayout->depth > 8)
2198 NVCrtcLoadPalette(crtc);
2199 nv_crtc_load_state_vga(crtc, &pNv->ModeReg);
2200 if (pNv->Architecture == NV_ARCH_40) {
2201 nv40_crtc_load_state_pll(crtc, &pNv->ModeReg);
2203 nv_crtc_load_state_pll(pNv, &pNv->ModeReg);
2206 NVVgaProtect(crtc, FALSE);
2208 NVCrtcSetBase(crtc, x, y, NVMatchModePrivate(mode, NV_MODE_CONSOLE));
2210 #if X_BYTE_ORDER == X_BIG_ENDIAN
2211 /* turn on LFB swapping */
2215 tmp = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING);
2217 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING, tmp);
2222 /* This functions generates data that is not saved, but still is needed. */
2223 void nv_crtc_restore_generate(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2225 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2226 NVCrtcRegPtr regp = &state->crtc_reg[nv_crtc->head];
2229 /* It's a good idea to also save a default palette on shutdown. */
2230 for (i = 0; i < 256; i++) {
2232 regp->DAC[(i*3)+1] = i;
2233 regp->DAC[(i*3)+2] = i;
2237 void nv_crtc_save(xf86CrtcPtr crtc)
2239 ScrnInfoPtr pScrn = crtc->scrn;
2240 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2241 NVPtr pNv = NVPTR(pScrn);
2243 ErrorF("nv_crtc_save is called for CRTC %d\n", nv_crtc->head);
2245 /* We just came back from terminal, so unlock */
2246 NVCrtcLockUnlock(crtc, FALSE);
2249 NVCrtcSetOwner(crtc);
2250 nv_crtc_save_state_ramdac(crtc, &pNv->SavedReg);
2251 nv_crtc_save_state_vga(crtc, &pNv->SavedReg);
2252 nv_crtc_save_state_ext(crtc, &pNv->SavedReg);
2253 if (pNv->Architecture == NV_ARCH_40) {
2254 nv40_crtc_save_state_pll(pNv, &pNv->SavedReg);
2256 nv_crtc_save_state_pll(pNv, &pNv->SavedReg);
2260 void nv_crtc_restore(xf86CrtcPtr crtc)
2262 ScrnInfoPtr pScrn = crtc->scrn;
2263 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2264 NVPtr pNv = NVPTR(pScrn);
2265 RIVA_HW_STATE *state;
2268 state = &pNv->SavedReg;
2269 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
2271 ErrorF("nv_crtc_restore is called for CRTC %d\n", nv_crtc->head);
2274 NVCrtcSetOwner(crtc);
2276 /* Just to be safe */
2277 NVCrtcLockUnlock(crtc, FALSE);
2279 NVVgaProtect(crtc, TRUE);
2280 nv_crtc_restore_generate(crtc, &pNv->SavedReg);
2281 nv_crtc_load_state_ramdac(crtc, &pNv->SavedReg);
2282 nv_crtc_load_state_ext(crtc, &pNv->SavedReg, TRUE);
2283 if (savep->general & 0x30) /* Palette mode */
2284 NVCrtcLoadPalette(crtc);
2285 nv_crtc_load_state_vga(crtc, &pNv->SavedReg);
2287 /* Force restoring vpll. */
2288 state->vpll_changed[nv_crtc->head] = TRUE;
2290 if (pNv->Architecture == NV_ARCH_40) {
2291 nv40_crtc_load_state_pll(crtc, &pNv->SavedReg);
2293 nv_crtc_load_state_pll(pNv, &pNv->SavedReg);
2296 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
2297 NVVgaProtect(crtc, FALSE);
2299 nv_crtc->last_dpms = NV_DPMS_CLEARED;
2303 NVResetCrtcConfig(xf86CrtcPtr crtc, Bool set)
2305 ScrnInfoPtr pScrn = crtc->scrn;
2306 NVPtr pNv = NVPTR(pScrn);
2308 if (pNv->twoHeads) {
2311 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2316 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
2320 NVCrtcWriteCRTC(crtc, NV_CRTC_FSEL, val);
2324 void nv_crtc_prepare(xf86CrtcPtr crtc)
2326 ScrnInfoPtr pScrn = crtc->scrn;
2327 NVPtr pNv = NVPTR(pScrn);
2328 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2330 ErrorF("nv_crtc_prepare is called for CRTC %d\n", nv_crtc->head);
2333 NVCrtcLockUnlock(crtc, 0);
2335 NVResetCrtcConfig(crtc, FALSE);
2337 crtc->funcs->dpms(crtc, DPMSModeOff);
2339 /* Sync the engine before adjust mode */
2340 if (pNv->EXADriverPtr) {
2341 exaMarkSync(pScrn->pScreen);
2342 exaWaitSync(pScrn->pScreen);
2345 NVCrtcBlankScreen(crtc, FALSE); /* Blank screen */
2347 /* Some more preperation. */
2348 NVCrtcWriteCRTC(crtc, NV_CRTC_CONFIG, 0x1); /* Go to non-vga mode/out of enhanced mode */
2349 if (pNv->Architecture == NV_ARCH_40) {
2350 uint32_t reg900 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_900);
2351 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_900, reg900 & ~0x10000);
2355 void nv_crtc_commit(xf86CrtcPtr crtc)
2357 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2358 ErrorF("nv_crtc_commit for CRTC %d\n", nv_crtc->head);
2360 crtc->funcs->dpms (crtc, DPMSModeOn);
2362 if (crtc->scrn->pScreen != NULL)
2363 xf86_reload_cursors (crtc->scrn->pScreen);
2365 NVResetCrtcConfig(crtc, TRUE);
2368 static Bool nv_crtc_lock(xf86CrtcPtr crtc)
2370 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2371 ErrorF("nv_crtc_lock is called for CRTC %d\n", nv_crtc->head);
2376 static void nv_crtc_unlock(xf86CrtcPtr crtc)
2378 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2379 ErrorF("nv_crtc_unlock is called for CRTC %d\n", nv_crtc->head);
2383 nv_crtc_gamma_set(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
2386 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2387 ScrnInfoPtr pScrn = crtc->scrn;
2388 NVPtr pNv = NVPTR(pScrn);
2392 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
2394 switch (pNv->CurrentLayout.depth) {
2397 /* We've got 5 bit (32 values) colors and 256 registers for each color */
2398 for (i = 0; i < 32; i++) {
2399 for (j = 0; j < 8; j++) {
2400 regp->DAC[(i*8 + j) * 3 + 0] = red[i] >> 8;
2401 regp->DAC[(i*8 + j) * 3 + 1] = green[i] >> 8;
2402 regp->DAC[(i*8 + j) * 3 + 2] = blue[i] >> 8;
2408 /* First deal with the 5 bit colors */
2409 for (i = 0; i < 32; i++) {
2410 for (j = 0; j < 8; j++) {
2411 regp->DAC[(i*8 + j) * 3 + 0] = red[i] >> 8;
2412 regp->DAC[(i*8 + j) * 3 + 2] = blue[i] >> 8;
2415 /* Now deal with the 6 bit color */
2416 for (i = 0; i < 64; i++) {
2417 for (j = 0; j < 4; j++) {
2418 regp->DAC[(i*4 + j) * 3 + 1] = green[i] >> 8;
2424 for (i = 0; i < 256; i++) {
2425 regp->DAC[i * 3] = red[i] >> 8;
2426 regp->DAC[(i * 3) + 1] = green[i] >> 8;
2427 regp->DAC[(i * 3) + 2] = blue[i] >> 8;
2432 NVCrtcLoadPalette(crtc);
2436 * Allocates memory for a locked-in-framebuffer shadow of the given
2437 * width and height for this CRTC's rotated shadow framebuffer.
2441 nv_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
2443 ErrorF("nv_crtc_shadow_allocate is called\n");
2444 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2445 ScrnInfoPtr pScrn = crtc->scrn;
2446 #if !NOUVEAU_EXA_PIXMAPS
2447 ScreenPtr pScreen = pScrn->pScreen;
2448 #endif /* !NOUVEAU_EXA_PIXMAPS */
2449 NVPtr pNv = NVPTR(pScrn);
2452 unsigned long rotate_pitch;
2453 int size, align = 64;
2455 rotate_pitch = pScrn->displayWidth * (pScrn->bitsPerPixel/8);
2456 size = rotate_pitch * height;
2458 assert(nv_crtc->shadow == NULL);
2459 #if NOUVEAU_EXA_PIXMAPS
2460 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
2461 align, size, &nv_crtc->shadow)) {
2462 ErrorF("Failed to allocate memory for shadow buffer!\n");
2466 if (nv_crtc->shadow && nouveau_bo_map(nv_crtc->shadow, NOUVEAU_BO_RDWR)) {
2467 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2468 "Failed to map shadow buffer.\n");
2472 offset = nv_crtc->shadow->map;
2474 nv_crtc->shadow = exaOffscreenAlloc(pScreen, size, align, TRUE, NULL, NULL);
2475 if (nv_crtc->shadow == NULL) {
2476 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2477 "Couldn't allocate shadow memory for rotated CRTC\n");
2480 offset = pNv->FB->map + nv_crtc->shadow->offset;
2481 #endif /* NOUVEAU_EXA_PIXMAPS */
2487 * Creates a pixmap for this CRTC's rotated shadow framebuffer.
2490 nv_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
2492 ErrorF("nv_crtc_shadow_create is called\n");
2493 ScrnInfoPtr pScrn = crtc->scrn;
2494 #if NOUVEAU_EXA_PIXMAPS
2495 ScreenPtr pScreen = pScrn->pScreen;
2496 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2497 #endif /* NOUVEAU_EXA_PIXMAPS */
2498 unsigned long rotate_pitch;
2499 PixmapPtr rotate_pixmap;
2500 #if NOUVEAU_EXA_PIXMAPS
2501 struct nouveau_pixmap *nvpix;
2502 #endif /* NOUVEAU_EXA_PIXMAPS */
2505 data = crtc->funcs->shadow_allocate (crtc, width, height);
2507 rotate_pitch = pScrn->displayWidth * (pScrn->bitsPerPixel/8);
2509 #if NOUVEAU_EXA_PIXMAPS
2510 /* Create a dummy pixmap, to get a private that will be accepted by the system.*/
2511 rotate_pixmap = pScreen->CreatePixmap(pScreen,
2514 #ifdef CREATE_PIXMAP_USAGE_SCRATCH /* there seems to have been no api bump */
2519 #endif /* CREATE_PIXMAP_USAGE_SCRATCH */
2521 rotate_pixmap = GetScratchPixmapHeader(pScrn->pScreen,
2524 pScrn->bitsPerPixel,
2527 #endif /* NOUVEAU_EXA_PIXMAPS */
2529 if (rotate_pixmap == NULL) {
2530 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2531 "Couldn't allocate shadow pixmap for rotated CRTC\n");
2534 #if NOUVEAU_EXA_PIXMAPS
2535 nvpix = exaGetPixmapDriverPrivate(rotate_pixmap);
2537 ErrorF("No shadow private, stage 1\n");
2539 nvpix->bo = nv_crtc->shadow;
2540 nvpix->mapped = TRUE;
2543 /* Modify the pixmap to actually be the one we need. */
2544 pScreen->ModifyPixmapHeader(rotate_pixmap,
2548 pScrn->bitsPerPixel,
2552 nvpix = exaGetPixmapDriverPrivate(rotate_pixmap);
2553 if (!nvpix || !nvpix->bo)
2554 ErrorF("No shadow private, stage 2\n");
2555 #endif /* NOUVEAU_EXA_PIXMAPS */
2557 return rotate_pixmap;
2561 nv_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
2563 ErrorF("nv_crtc_shadow_destroy is called\n");
2564 ScrnInfoPtr pScrn = crtc->scrn;
2565 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2566 ScreenPtr pScreen = pScrn->pScreen;
2568 if (rotate_pixmap) { /* This should also unmap the buffer object if relevant. */
2569 pScreen->DestroyPixmap(rotate_pixmap);
2572 #if !NOUVEAU_EXA_PIXMAPS
2573 if (data && nv_crtc->shadow) {
2574 exaOffscreenFree(pScreen, nv_crtc->shadow);
2576 #endif /* !NOUVEAU_EXA_PIXMAPS */
2578 nv_crtc->shadow = NULL;
2581 /* NV04-NV10 doesn't support alpha cursors */
2582 static const xf86CrtcFuncsRec nv_crtc_funcs = {
2583 .dpms = nv_crtc_dpms,
2584 .save = nv_crtc_save, /* XXX */
2585 .restore = nv_crtc_restore, /* XXX */
2586 .mode_fixup = nv_crtc_mode_fixup,
2587 .mode_set = nv_crtc_mode_set,
2588 .prepare = nv_crtc_prepare,
2589 .commit = nv_crtc_commit,
2590 .destroy = NULL, /* XXX */
2591 .lock = nv_crtc_lock,
2592 .unlock = nv_crtc_unlock,
2593 .set_cursor_colors = nv_crtc_set_cursor_colors,
2594 .set_cursor_position = nv_crtc_set_cursor_position,
2595 .show_cursor = nv_crtc_show_cursor,
2596 .hide_cursor = nv_crtc_hide_cursor,
2597 .load_cursor_image = nv_crtc_load_cursor_image,
2598 .gamma_set = nv_crtc_gamma_set,
2599 .shadow_create = nv_crtc_shadow_create,
2600 .shadow_allocate = nv_crtc_shadow_allocate,
2601 .shadow_destroy = nv_crtc_shadow_destroy,
2604 /* NV11 and up has support for alpha cursors. */
2605 /* Due to different maximum sizes we cannot allow it to use normal cursors */
2606 static const xf86CrtcFuncsRec nv11_crtc_funcs = {
2607 .dpms = nv_crtc_dpms,
2608 .save = nv_crtc_save, /* XXX */
2609 .restore = nv_crtc_restore, /* XXX */
2610 .mode_fixup = nv_crtc_mode_fixup,
2611 .mode_set = nv_crtc_mode_set,
2612 .prepare = nv_crtc_prepare,
2613 .commit = nv_crtc_commit,
2614 .destroy = NULL, /* XXX */
2615 .lock = nv_crtc_lock,
2616 .unlock = nv_crtc_unlock,
2617 .set_cursor_colors = NULL, /* Alpha cursors do not need this */
2618 .set_cursor_position = nv_crtc_set_cursor_position,
2619 .show_cursor = nv_crtc_show_cursor,
2620 .hide_cursor = nv_crtc_hide_cursor,
2621 .load_cursor_argb = nv_crtc_load_cursor_argb,
2622 .gamma_set = nv_crtc_gamma_set,
2623 .shadow_create = nv_crtc_shadow_create,
2624 .shadow_allocate = nv_crtc_shadow_allocate,
2625 .shadow_destroy = nv_crtc_shadow_destroy,
2630 nv_crtc_init(ScrnInfoPtr pScrn, int crtc_num)
2632 NVPtr pNv = NVPTR(pScrn);
2634 NVCrtcPrivatePtr nv_crtc;
2636 if (pNv->NVArch >= 0x11) {
2637 crtc = xf86CrtcCreate (pScrn, &nv11_crtc_funcs);
2639 crtc = xf86CrtcCreate (pScrn, &nv_crtc_funcs);
2644 nv_crtc = xnfcalloc (sizeof (NVCrtcPrivateRec), 1);
2645 nv_crtc->head = crtc_num;
2646 nv_crtc->last_dpms = NV_DPMS_CLEARED;
2647 pNv->fp_regs_owner[nv_crtc->head] = nv_crtc->head;
2649 crtc->driver_private = nv_crtc;
2651 NVCrtcLockUnlock(crtc, FALSE);
2654 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2656 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2660 regp = &state->crtc_reg[nv_crtc->head];
2662 NVWriteMiscOut(crtc, regp->MiscOutReg);
2664 for (i = 1; i < 5; i++)
2665 NVWriteVgaSeq(crtc, i, regp->Sequencer[i]);
2667 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
2668 NVWriteVgaCrtc(crtc, 17, regp->CRTC[17] & ~0x80);
2670 for (i = 0; i < 25; i++)
2671 NVWriteVgaCrtc(crtc, i, regp->CRTC[i]);
2673 for (i = 0; i < 9; i++)
2674 NVWriteVgaGr(crtc, i, regp->Graphics[i]);
2676 NVEnablePalette(crtc);
2677 for (i = 0; i < 21; i++)
2678 NVWriteVgaAttr(crtc, i, regp->Attribute[i]);
2680 NVDisablePalette(crtc);
2683 static void nv_crtc_fix_nv40_hw_cursor(xf86CrtcPtr crtc)
2685 /* TODO - implement this properly */
2686 ScrnInfoPtr pScrn = crtc->scrn;
2687 NVPtr pNv = NVPTR(pScrn);
2689 if (pNv->Architecture == NV_ARCH_40) { /* HW bug */
2690 volatile uint32_t curpos = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_CURSOR_POS);
2691 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_CURSOR_POS, curpos);
2694 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state, Bool override)
2696 ScrnInfoPtr pScrn = crtc->scrn;
2697 NVPtr pNv = NVPTR(pScrn);
2698 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2702 regp = &state->crtc_reg[nv_crtc->head];
2704 if (pNv->Architecture >= NV_ARCH_10) {
2705 nvWriteVIDEO(pNv, NV_PVIDEO_STOP, 1);
2706 nvWriteVIDEO(pNv, NV_PVIDEO_INTR_EN, 0);
2707 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(0), 0);
2708 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(1), 0);
2709 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(0), pNv->VRAMPhysicalSize - 1);
2710 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(1), pNv->VRAMPhysicalSize - 1);
2711 nvWriteVIDEO(pNv, NV_PVIDEO_UVPLANE_LIMIT(0), pNv->VRAMPhysicalSize - 1);
2712 nvWriteVIDEO(pNv, NV_PVIDEO_UVPLANE_LIMIT(1), pNv->VRAMPhysicalSize - 1);
2713 nvWriteMC(pNv, 0x1588, 0);
2715 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, regp->CRTC[NV_VGA_CRTCX_BUFFER]);
2716 NVCrtcWriteCRTC(crtc, NV_CRTC_CURSOR_CONFIG, regp->cursorConfig);
2717 NVCrtcWriteCRTC(crtc, NV_CRTC_0830, regp->unk830);
2718 NVCrtcWriteCRTC(crtc, NV_CRTC_0834, regp->unk834);
2719 if (pNv->Architecture == NV_ARCH_40) {
2720 NVCrtcWriteCRTC(crtc, NV_CRTC_0850, regp->unk850);
2721 NVCrtcWriteCRTC(crtc, NV_CRTC_081C, regp->unk81c);
2724 if (pNv->Architecture == NV_ARCH_40) {
2725 uint32_t reg900 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_900);
2726 if (regp->config == 0x2) { /* enhanced "horizontal only" non-vga mode */
2727 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_900, reg900 | 0x10000);
2729 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_900, reg900 & ~0x10000);
2734 NVCrtcWriteCRTC(crtc, NV_CRTC_CONFIG, regp->config);
2735 NVCrtcWriteCRTC(crtc, NV_CRTC_GPIO, regp->gpio);
2737 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0, regp->CRTC[NV_VGA_CRTCX_REPAINT0]);
2738 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, regp->CRTC[NV_VGA_CRTCX_REPAINT1]);
2739 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LSR, regp->CRTC[NV_VGA_CRTCX_LSR]);
2740 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL, regp->CRTC[NV_VGA_CRTCX_PIXEL]);
2741 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LCD, regp->CRTC[NV_VGA_CRTCX_LCD]);
2742 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_HEB, regp->CRTC[NV_VGA_CRTCX_HEB]);
2743 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1, regp->CRTC[NV_VGA_CRTCX_FIFO1]);
2744 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0, regp->CRTC[NV_VGA_CRTCX_FIFO0]);
2745 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM]);
2746 if (pNv->Architecture >= NV_ARCH_30)
2747 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30]);
2749 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0, regp->CRTC[NV_VGA_CRTCX_CURCTL0]);
2750 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1, regp->CRTC[NV_VGA_CRTCX_CURCTL1]);
2751 nv_crtc_fix_nv40_hw_cursor(crtc);
2752 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2, regp->CRTC[NV_VGA_CRTCX_CURCTL2]);
2753 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE, regp->CRTC[NV_VGA_CRTCX_INTERLACE]);
2755 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_26, regp->CRTC[NV_VGA_CRTCX_26]);
2756 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3B, regp->CRTC[NV_VGA_CRTCX_3B]);
2757 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3C, regp->CRTC[NV_VGA_CRTCX_3C]);
2758 if (pNv->Architecture >= NV_ARCH_10) {
2759 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA, regp->CRTC[NV_VGA_CRTCX_EXTRA]);
2760 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_43, regp->CRTC[NV_VGA_CRTCX_43]);
2761 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_45, regp->CRTC[NV_VGA_CRTCX_45]);
2762 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_4B, regp->CRTC[NV_VGA_CRTCX_4B]);
2763 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_52, regp->CRTC[NV_VGA_CRTCX_52]);
2765 /* NV11 and NV20 stop at 0x52. */
2766 if (pNv->NVArch >= 0x17 && pNv->twoHeads) {
2768 for (i = 0; i < 0x10; i++)
2769 NVWriteVGACR5758(pNv, nv_crtc->head, i, regp->CR58[i]);
2771 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING, regp->CRTC[NV_VGA_CRTCX_FP_HTIMING]);
2772 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING, regp->CRTC[NV_VGA_CRTCX_FP_VTIMING]);
2774 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_59, regp->CRTC[NV_VGA_CRTCX_59]);
2776 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_85, regp->CRTC[NV_VGA_CRTCX_85]);
2777 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_86, regp->CRTC[NV_VGA_CRTCX_86]);
2780 /* Setting 1 on this value gives you interrupts for every vblank period. */
2781 NVCrtcWriteCRTC(crtc, NV_CRTC_INTR_EN_0, 0);
2782 NVCrtcWriteCRTC(crtc, NV_CRTC_INTR_0, NV_CRTC_INTR_VBLANK);
2784 pNv->CurrentState = state;
2787 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2789 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2793 regp = &state->crtc_reg[nv_crtc->head];
2795 regp->MiscOutReg = NVReadMiscOut(crtc);
2797 for (i = 0; i < 25; i++)
2798 regp->CRTC[i] = NVReadVgaCrtc(crtc, i);
2800 NVEnablePalette(crtc);
2801 for (i = 0; i < 21; i++)
2802 regp->Attribute[i] = NVReadVgaAttr(crtc, i);
2803 NVDisablePalette(crtc);
2805 for (i = 0; i < 9; i++)
2806 regp->Graphics[i] = NVReadVgaGr(crtc, i);
2808 for (i = 1; i < 5; i++)
2809 regp->Sequencer[i] = NVReadVgaSeq(crtc, i);
2812 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2814 ScrnInfoPtr pScrn = crtc->scrn;
2815 NVPtr pNv = NVPTR(pScrn);
2816 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2820 regp = &state->crtc_reg[nv_crtc->head];
2822 regp->CRTC[NV_VGA_CRTCX_LCD] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LCD);
2823 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0);
2824 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1);
2825 regp->CRTC[NV_VGA_CRTCX_LSR] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LSR);
2826 regp->CRTC[NV_VGA_CRTCX_PIXEL] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL);
2827 regp->CRTC[NV_VGA_CRTCX_HEB] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_HEB);
2828 regp->CRTC[NV_VGA_CRTCX_FIFO1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1);
2830 regp->CRTC[NV_VGA_CRTCX_FIFO0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0);
2831 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM);
2832 regp->CRTC[NV_VGA_CRTCX_BUFFER] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER);
2833 if (pNv->Architecture >= NV_ARCH_30)
2834 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30);
2835 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0);
2836 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1);
2837 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2);
2838 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE);
2840 if (pNv->Architecture >= NV_ARCH_10) {
2841 regp->unk830 = NVCrtcReadCRTC(crtc, NV_CRTC_0830);
2842 regp->unk834 = NVCrtcReadCRTC(crtc, NV_CRTC_0834);
2843 if (pNv->Architecture == NV_ARCH_40) {
2844 regp->unk850 = NVCrtcReadCRTC(crtc, NV_CRTC_0850);
2845 regp->unk81c = NVCrtcReadCRTC(crtc, NV_CRTC_081C);
2847 if (pNv->twoHeads) {
2848 regp->head = NVCrtcReadCRTC(crtc, NV_CRTC_FSEL);
2849 regp->crtcOwner = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_OWNER);
2851 regp->cursorConfig = NVCrtcReadCRTC(crtc, NV_CRTC_CURSOR_CONFIG);
2854 regp->gpio = NVCrtcReadCRTC(crtc, NV_CRTC_GPIO);
2855 regp->config = NVCrtcReadCRTC(crtc, NV_CRTC_CONFIG);
2857 regp->CRTC[NV_VGA_CRTCX_26] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_26);
2858 regp->CRTC[NV_VGA_CRTCX_3B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3B);
2859 regp->CRTC[NV_VGA_CRTCX_3C] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3C);
2860 if (pNv->Architecture >= NV_ARCH_10) {
2861 regp->CRTC[NV_VGA_CRTCX_EXTRA] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA);
2862 regp->CRTC[NV_VGA_CRTCX_43] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_43);
2863 regp->CRTC[NV_VGA_CRTCX_45] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_45);
2864 regp->CRTC[NV_VGA_CRTCX_4B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_4B);
2865 regp->CRTC[NV_VGA_CRTCX_52] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_52);
2867 /* NV11 and NV20 don't have this, they stop at 0x52. */
2868 if (pNv->NVArch >= 0x17 && pNv->twoHeads) {
2869 for (i = 0; i < 0x10; i++)
2870 regp->CR58[i] = NVReadVGACR5758(pNv, nv_crtc->head, i);
2872 regp->CRTC[NV_VGA_CRTCX_59] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_59);
2873 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING);
2874 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING);
2876 regp->CRTC[NV_VGA_CRTCX_85] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_85);
2877 regp->CRTC[NV_VGA_CRTCX_86] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_86);
2881 static void nv_crtc_save_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2883 ScrnInfoPtr pScrn = crtc->scrn;
2884 NVPtr pNv = NVPTR(pScrn);
2885 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2889 regp = &state->crtc_reg[nv_crtc->head];
2891 regp->general = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_GENERAL_CONTROL);
2893 regp->fp_control[0] = NVReadRAMDAC(pNv, 0, NV_RAMDAC_FP_CONTROL);
2894 regp->debug_0[0] = NVReadRAMDAC(pNv, 0, NV_RAMDAC_FP_DEBUG_0);
2896 if (pNv->twoHeads) {
2897 regp->fp_control[1] = NVReadRAMDAC(pNv, 1, NV_RAMDAC_FP_CONTROL);
2898 regp->debug_0[1] = NVReadRAMDAC(pNv, 1, NV_RAMDAC_FP_DEBUG_0);
2900 regp->debug_1 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_DEBUG_1);
2901 regp->debug_2 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_DEBUG_2);
2903 regp->unk_a20 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_A20);
2904 regp->unk_a24 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_A24);
2905 regp->unk_a34 = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_A34);
2908 if (pNv->NVArch == 0x11) {
2909 regp->dither = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_DITHER_NV11);
2910 } else if (pNv->twoHeads) {
2911 regp->dither = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_DITHER);
2913 if (pNv->Architecture >= NV_ARCH_10)
2914 regp->nv10_cursync = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_NV10_CURSYNC);
2916 /* The regs below are 0 for non-flatpanels, so you can load and save them */
2918 for (i = 0; i < 7; i++) {
2919 uint32_t ramdac_reg = NV_RAMDAC_FP_HDISP_END + (i * 4);
2920 regp->fp_horiz_regs[i] = NVCrtcReadRAMDAC(crtc, ramdac_reg);
2923 for (i = 0; i < 7; i++) {
2924 uint32_t ramdac_reg = NV_RAMDAC_FP_VDISP_END + (i * 4);
2925 regp->fp_vert_regs[i] = NVCrtcReadRAMDAC(crtc, ramdac_reg);
2928 regp->fp_hvalid_start = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_HVALID_START);
2929 regp->fp_hvalid_end = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_HVALID_END);
2930 regp->fp_vvalid_start = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_VVALID_START);
2931 regp->fp_vvalid_end = NVCrtcReadRAMDAC(crtc, NV_RAMDAC_FP_VVALID_END);
2934 static void nv_crtc_load_state_ramdac(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
2936 ScrnInfoPtr pScrn = crtc->scrn;
2937 NVPtr pNv = NVPTR(pScrn);
2938 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2942 regp = &state->crtc_reg[nv_crtc->head];
2944 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_GENERAL_CONTROL, regp->general);
2946 if (pNv->fp_regs_owner[0] == nv_crtc->head) {
2947 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_FP_CONTROL, regp->fp_control[0]);
2948 NVWriteRAMDAC(pNv, 0, NV_RAMDAC_FP_DEBUG_0, regp->debug_0[0]);
2950 if (pNv->twoHeads) {
2951 if (pNv->fp_regs_owner[1] == nv_crtc->head) {
2952 NVWriteRAMDAC(pNv, 1, NV_RAMDAC_FP_CONTROL, regp->fp_control[1]);
2953 NVWriteRAMDAC(pNv, 1, NV_RAMDAC_FP_DEBUG_0, regp->debug_0[1]);
2955 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_DEBUG_1, regp->debug_1);
2956 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_DEBUG_2, regp->debug_2);
2957 if (pNv->NVArch == 0x30) { /* For unknown purposes. */
2958 uint32_t reg890 = NVCrtcReadRAMDAC(crtc, NV30_RAMDAC_890);
2959 NVCrtcWriteRAMDAC(crtc, NV30_RAMDAC_89C, reg890);
2962 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_A20, regp->unk_a20);
2963 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_A24, regp->unk_a24);
2964 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_A34, regp->unk_a34);
2967 if (pNv->NVArch == 0x11) {
2968 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_DITHER_NV11, regp->dither);
2969 } else if (pNv->twoHeads) {
2970 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_DITHER, regp->dither);
2972 if (pNv->Architecture >= NV_ARCH_10)
2973 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_NV10_CURSYNC, regp->nv10_cursync);
2975 /* The regs below are 0 for non-flatpanels, so you can load and save them */
2977 for (i = 0; i < 7; i++) {
2978 uint32_t ramdac_reg = NV_RAMDAC_FP_HDISP_END + (i * 4);
2979 NVCrtcWriteRAMDAC(crtc, ramdac_reg, regp->fp_horiz_regs[i]);
2982 for (i = 0; i < 7; i++) {
2983 uint32_t ramdac_reg = NV_RAMDAC_FP_VDISP_END + (i * 4);
2984 NVCrtcWriteRAMDAC(crtc, ramdac_reg, regp->fp_vert_regs[i]);
2987 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_HVALID_START, regp->fp_hvalid_start);
2988 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_HVALID_END, regp->fp_hvalid_end);
2989 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_VVALID_START, regp->fp_vvalid_start);
2990 NVCrtcWriteRAMDAC(crtc, NV_RAMDAC_FP_VVALID_END, regp->fp_vvalid_end);
2994 NVCrtcSetBase (xf86CrtcPtr crtc, int x, int y, Bool bios_restore)
2996 ScrnInfoPtr pScrn = crtc->scrn;
2997 NVPtr pNv = NVPTR(pScrn);
2998 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
2999 NVFBLayout *pLayout = &pNv->CurrentLayout;
3002 ErrorF("NVCrtcSetBase: x: %d y: %d\n", x, y);
3005 start = pNv->console_mode[nv_crtc->head].fb_start;
3007 start += ((y * pScrn->displayWidth + x) * (pLayout->bitsPerPixel/8));
3008 if (crtc->rotatedData != NULL) { /* we do not exist on the real framebuffer */
3009 #if NOUVEAU_EXA_PIXMAPS
3010 start = nv_crtc->shadow->offset;
3012 start = pNv->FB->offset + nv_crtc->shadow->offset; /* We do exist relative to the framebuffer */
3015 start += pNv->FB->offset;
3019 /* 30 bits addresses in 32 bits according to haiku */
3020 NVCrtcWriteCRTC(crtc, NV_CRTC_START, start & 0xfffffffc);
3022 /* set NV4/NV10 byte adress: (bit0 - 1) */
3023 NVWriteVgaAttr(crtc, 0x13, (start & 0x3) << 1);
3029 static void NVCrtcWriteDacMask(xf86CrtcPtr crtc, uint8_t value)
3031 ScrnInfoPtr pScrn = crtc->scrn;
3032 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3033 NVPtr pNv = NVPTR(pScrn);
3034 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3036 DDXMMIOH("NVCrtcWriteDacMask: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_MASK, value);
3037 NV_WR08(pDACReg, VGA_DAC_MASK, value);
3040 static uint8_t NVCrtcReadDacMask(xf86CrtcPtr crtc)
3042 ScrnInfoPtr pScrn = crtc->scrn;
3043 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3044 NVPtr pNv = NVPTR(pScrn);
3045 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3047 DDXMMIOH("NVCrtcReadDacMask: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_MASK, NV_RD08(pDACReg, VGA_DAC_MASK));
3048 return NV_RD08(pDACReg, VGA_DAC_MASK);
3051 static void NVCrtcWriteDacReadAddr(xf86CrtcPtr crtc, uint8_t value)
3053 ScrnInfoPtr pScrn = crtc->scrn;
3054 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3055 NVPtr pNv = NVPTR(pScrn);
3056 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3058 DDXMMIOH("NVCrtcWriteDacReadAddr: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_READ_ADDR, value);
3059 NV_WR08(pDACReg, VGA_DAC_READ_ADDR, value);
3062 static void NVCrtcWriteDacWriteAddr(xf86CrtcPtr crtc, uint8_t value)
3064 ScrnInfoPtr pScrn = crtc->scrn;
3065 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3066 NVPtr pNv = NVPTR(pScrn);
3067 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3069 DDXMMIOH("NVCrtcWriteDacWriteAddr: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_WRITE_ADDR, value);
3070 NV_WR08(pDACReg, VGA_DAC_WRITE_ADDR, value);
3073 static void NVCrtcWriteDacData(xf86CrtcPtr crtc, uint8_t value)
3075 ScrnInfoPtr pScrn = crtc->scrn;
3076 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3077 NVPtr pNv = NVPTR(pScrn);
3078 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3080 DDXMMIOH("NVCrtcWriteDacData: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_DATA, value);
3081 NV_WR08(pDACReg, VGA_DAC_DATA, value);
3084 static uint8_t NVCrtcReadDacData(xf86CrtcPtr crtc, uint8_t value)
3086 ScrnInfoPtr pScrn = crtc->scrn;
3087 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3088 NVPtr pNv = NVPTR(pScrn);
3089 volatile uint8_t *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
3091 DDXMMIOH("NVCrtcReadDacData: head %d reg 0x%04x data 0x%02x\n", nv_crtc->head, VGA_DAC_DATA, NV_RD08(pDACReg, VGA_DAC_DATA));
3092 return NV_RD08(pDACReg, VGA_DAC_DATA);
3095 void NVCrtcLoadPalette(xf86CrtcPtr crtc)
3098 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3100 ScrnInfoPtr pScrn = crtc->scrn;
3101 NVPtr pNv = NVPTR(pScrn);
3103 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
3106 NVCrtcSetOwner(crtc);
3107 NVCrtcWriteDacMask(crtc, 0xff);
3108 NVCrtcWriteDacWriteAddr(crtc, 0x00);
3110 for (i = 0; i<768; i++) {
3111 NVCrtcWriteDacData(crtc, regp->DAC[i]);
3113 NVDisablePalette(crtc);
3117 void NVCrtcBlankScreen(xf86CrtcPtr crtc, Bool on)
3119 NVPtr pNv = NVPTR(crtc->scrn);
3123 NVCrtcSetOwner(crtc);
3125 scrn = NVReadVgaSeq(crtc, 0x01);
3132 NVVgaSeqReset(crtc, TRUE);
3133 NVWriteVgaSeq(crtc, 0x01, scrn);
3134 NVVgaSeqReset(crtc, FALSE);
3137 /* Reset a mode after a drastic output resource change for example. */
3138 void NVCrtcModeFix(xf86CrtcPtr crtc)
3140 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
3146 if (!xf86ModesEqual(&crtc->mode, &crtc->desiredMode)) /* not currently in X */
3149 DisplayModePtr adjusted_mode = xf86DuplicateMode(&crtc->mode);
3150 uint8_t dpms_mode = nv_crtc->last_dpms;
3152 /* Set the crtc mode again. */
3153 crtc->funcs->dpms(crtc, DPMSModeOff);
3154 need_unlock = crtc->funcs->lock(crtc);
3155 crtc->funcs->mode_fixup(crtc, &crtc->mode, adjusted_mode);
3156 crtc->funcs->prepare(crtc);
3157 crtc->funcs->mode_set(crtc, &crtc->mode, adjusted_mode, crtc->x, crtc->y);
3158 crtc->funcs->commit(crtc);
3160 crtc->funcs->unlock(crtc);
3161 crtc->funcs->dpms(crtc, dpms_mode);
3164 xfree(adjusted_mode);
3167 /*************************************************************************** \
3169 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
3171 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
3172 |* international laws. Users and possessors of this source code are *|
3173 |* hereby granted a nonexclusive, royalty-free copyright license to *|
3174 |* use this code in individual and commercial software. *|
3176 |* Any use of this source code must include, in the user documenta- *|
3177 |* tion and internal comments to the code, notices to the end user *|
3180 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
3182 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
3183 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
3184 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
3185 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
3186 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
3187 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
3188 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
3189 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
3190 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
3191 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
3192 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
3194 |* U.S. Government End Users. This source code is a "commercial *|
3195 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
3196 |* consisting of "commercial computer software" and "commercial *|
3197 |* computer software documentation," as such terms are used in *|
3198 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
3199 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
3200 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
3201 |* all U.S. Government End Users acquire the source code with only *|
3202 |* those rights set forth herein. *|
3204 \***************************************************************************/