2 * Copyright 2005-2006 Erik Waling
3 * Copyright 2006 Stephane Marchesin
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 shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include "nv_include.h"
28 /* FIXME: put these somewhere */
29 #define CRTC_INDEX_COLOR VGA_IOBASE_COLOR + VGA_CRTC_INDEX_OFFSET
30 #define NV_VGA_CRTCX_OWNER_HEADA 0x0
31 #define NV_VGA_CRTCX_OWNER_HEADB 0x3
32 #define NV_PBUS_PCI_NV_19 0x0000184C
33 #define NV_PBUS_PCI_NV_20 0x00001850
34 #define NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED 0x00000000
35 #define NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED 0x00000001
36 #define NV_PRAMIN_ROM_OFFSET 0x00700000
44 static int crtchead = 0;
51 static uint16_t le16_to_cpu(const uint16_t x)
53 #if X_BYTE_ORDER == X_BIG_ENDIAN
60 static uint32_t le32_to_cpu(const uint32_t x)
62 #if X_BYTE_ORDER == X_BIG_ENDIAN
69 static Bool nv_cksum(const uint8_t *data, unsigned int length)
71 /* there's a few checksums in the BIOS, so here's a generic checking function */
75 for (i = 0; i < length; i++)
84 static int NVValidVBIOS(ScrnInfoPtr pScrn, const uint8_t *data)
86 /* check for BIOS signature */
87 if (!(data[0] == 0x55 && data[1] == 0xAA)) {
88 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
89 "... BIOS signature not found\n");
93 if (nv_cksum(data, data[2] * 512)) {
94 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
95 "... BIOS checksum invalid\n");
96 /* probably ought to set a do_not_execute flag for table parsing here,
97 * assuming most BIOSen are valid */
100 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "... appears to be valid\n");
105 static void NVShadowVBIOS_PROM(ScrnInfoPtr pScrn, uint8_t *data)
107 NVPtr pNv = NVPTR(pScrn);
110 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
111 "Attempting to locate BIOS image in PROM\n");
113 /* enable ROM access */
114 nvWriteMC(pNv, NV_PBUS_PCI_NV_20, NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED);
115 for (i = 0; i < NV_PROM_SIZE; i++) {
116 /* according to nvclock, we need that to work around a 6600GT/6800LE bug */
117 data[i] = pNv->PROM[i];
118 data[i] = pNv->PROM[i];
119 data[i] = pNv->PROM[i];
120 data[i] = pNv->PROM[i];
121 data[i] = pNv->PROM[i];
123 /* disable ROM access */
124 nvWriteMC(pNv, NV_PBUS_PCI_NV_20, NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED);
127 static void NVShadowVBIOS_PRAMIN(ScrnInfoPtr pScrn, uint32_t *data)
129 NVPtr pNv = NVPTR(pScrn);
130 const uint32_t *pramin = (uint32_t *)&pNv->REGS[NV_PRAMIN_ROM_OFFSET/4];
131 uint32_t old_bar0_pramin = 0;
133 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
134 "Attempting to locate BIOS image in PRAMIN\n");
136 if (pNv->Architecture >= NV_ARCH_50) {
139 vbios_vram = (pNv->REGS[0x619f04/4] & ~0xff) << 8;
141 vbios_vram = pNv->REGS[0x1700/4] << 16;
142 vbios_vram += 0xf0000;
145 old_bar0_pramin = pNv->REGS[0x1700/4];
146 pNv->REGS[0x1700/4] = vbios_vram >> 16;
149 memcpy(data, pramin, NV_PROM_SIZE);
151 if (pNv->Architecture >= NV_ARCH_50) {
152 pNv->REGS[0x1700/4] = old_bar0_pramin;
156 static Bool NVShadowVBIOS(ScrnInfoPtr pScrn, uint8_t *data)
158 NVShadowVBIOS_PROM(pScrn, data);
159 if (NVValidVBIOS(pScrn, data) == 2)
162 NVShadowVBIOS_PRAMIN(pScrn, (uint32_t *)data);
163 if (NVValidVBIOS(pScrn, data))
174 int length_multiplier;
175 Bool (*handler)(ScrnInfoPtr pScrn, bios_t *, uint16_t, init_exec_t *);
184 static void parse_init_table(ScrnInfoPtr pScrn, bios_t *bios, unsigned int offset, init_exec_t *iexec);
186 #define MACRO_INDEX_SIZE 2
188 #define CONDITION_SIZE 12
189 #define IO_FLAG_CONDITION_SIZE 9
197 static int nv_valid_reg(uint32_t reg)
199 #define WITHIN(x,y,z) ((x>=y)&&(x<y+z))
200 if (WITHIN(reg,NV_PRAMIN_OFFSET,NV_PRAMIN_SIZE))
202 if (WITHIN(reg,NV_PCRTC0_OFFSET,NV_PCRTC0_SIZE))
204 if (WITHIN(reg,NV_PRAMDAC0_OFFSET,NV_PRAMDAC0_SIZE))
206 if (WITHIN(reg,NV_PFB_OFFSET,NV_PFB_SIZE))
208 if (WITHIN(reg,NV_PFIFO_OFFSET,NV_PFIFO_SIZE))
210 if (WITHIN(reg,NV_PGRAPH_OFFSET,NV_PGRAPH_SIZE))
212 if (WITHIN(reg,NV_PEXTDEV_OFFSET,NV_PEXTDEV_SIZE))
214 if (WITHIN(reg,NV_PTIMER_OFFSET,NV_PTIMER_SIZE))
216 if (WITHIN(reg,NV_PVIDEO_OFFSET,NV_PVIDEO_SIZE))
218 if (WITHIN(reg,NV_PMC_OFFSET,NV_PMC_SIZE))
220 if (WITHIN(reg,NV_FIFO_OFFSET,NV_FIFO_SIZE))
222 if (WITHIN(reg,NV_PCIO0_OFFSET,NV_PCIO0_SIZE))
224 if (WITHIN(reg,NV_PDIO0_OFFSET,NV_PDIO0_SIZE))
226 if (WITHIN(reg,NV_PVIO_OFFSET,NV_PVIO_SIZE))
228 if (WITHIN(reg,NV_PROM_OFFSET,NV_PROM_SIZE))
230 if (WITHIN(reg,NV_PRAMIN_ROM_OFFSET,NV_PROM_SIZE))
233 if (WITHIN(reg,0x88000,0x1000))
239 static void nv32_rd(ScrnInfoPtr pScrn, uint32_t reg, uint32_t *data)
241 NVPtr pNv = NVPTR(pScrn);
243 if (!nv_valid_reg(reg)) {
244 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
245 "========= unknown reg 0x%08X ==========\n", reg);
248 *data = pNv->REGS[reg/4];
250 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
251 " Read: Reg: 0x%08X, Data: 0x%08X\n", reg, *data);
254 static int nv32_wr(ScrnInfoPtr pScrn, uint32_t reg, uint32_t data)
256 NVPtr pNv = NVPTR(pScrn);
258 uint8_t saved1 = 0, saved2 = 0;
259 volatile uint8_t *crtcptr = crtchead ? pNv->PCIO1 : pNv->PCIO0;
261 if (DEBUGLEVEL >= 8) {
263 nv32_rd(pScrn, reg, &tmp);
266 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
267 " Write: Reg: 0x%08X, Data: 0x%08X\n", reg, data);
268 if (!nv_valid_reg(reg)) {
269 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
270 "========= unknown reg 0x%08X ==========\n", reg);
274 if (pNv->VBIOS.execute) {
277 if ((reg & 0xffc) == 0x3c0) {
279 saved1 = VGA_RD08(crtcptr, VGA_MISC_OUT_R);
280 saved2 = VGA_RD08(crtcptr, VGA_ENABLE);
282 if ((reg & 0xffc) == 0x3cc) {
284 saved1 = VGA_RD08(crtcptr, VGA_GRAPH_INDEX);
285 VGA_WR08(crtcptr, VGA_GRAPH_INDEX, 0x06);
286 saved2 = VGA_RD08(crtcptr, VGA_GRAPH_DATA);
289 pNv->REGS[reg/4] = data;
291 if (specialcase == 1) {
292 VGA_WR08(crtcptr, VGA_ENABLE, saved2);
293 VGA_WR08(crtcptr, VGA_MISC_OUT_W, saved1);
295 if (specialcase == 2) {
296 VGA_WR08(crtcptr, VGA_GRAPH_INDEX, 0x06);
297 VGA_WR08(crtcptr, VGA_GRAPH_DATA, saved2);
298 VGA_WR08(crtcptr, VGA_GRAPH_INDEX, saved1);
305 static void nv_idx_port_rd(ScrnInfoPtr pScrn, uint16_t port, uint8_t index, uint8_t *data)
307 NVPtr pNv = NVPTR(pScrn);
308 volatile uint8_t *ptr = crtchead ? pNv->PCIO1 : pNv->PCIO0;
310 VGA_WR08(ptr, port, index);
311 *data = VGA_RD08(ptr, port + 1);
314 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
315 " Indexed read: Port: 0x%04X, Index: 0x%02X, Head: 0x%02X, Data: 0x%02X\n",
316 port, index, crtchead, *data);
319 static void nv_idx_port_wr(ScrnInfoPtr pScrn, uint16_t port, uint8_t index, uint8_t data)
321 NVPtr pNv = NVPTR(pScrn);
322 volatile uint8_t *ptr;
324 /* The current head is maintained in a file scope variable crtchead.
325 * We trap changes to CRTCX_OWNER and update the head variable
326 * and hence the register set written.
327 * As CRTCX_OWNER only exists on CRTC0, we update crtchead to head0
328 * in advance of the write, and to head1 after the write
330 if (port == CRTC_INDEX_COLOR && index == NV_VGA_CRTCX_OWNER && data != NV_VGA_CRTCX_OWNER_HEADB)
332 ptr = crtchead ? pNv->PCIO1 : pNv->PCIO0;
334 if (DEBUGLEVEL >= 8) {
336 nv_idx_port_rd(pScrn, port, index, &tmp);
339 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
340 " Indexed write: Port: 0x%04X, Index: 0x%02X, Head: 0x%02X, Data: 0x%02X\n",
341 port, index, crtchead, data);
343 if (pNv->VBIOS.execute) {
345 VGA_WR08(ptr, port, index);
346 VGA_WR08(ptr, port + 1, data);
349 if (port == CRTC_INDEX_COLOR && index == NV_VGA_CRTCX_OWNER && data == NV_VGA_CRTCX_OWNER_HEADB)
353 static Bool io_flag_condition(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, uint8_t cond)
355 /* The IO flag condition entry has 2 bytes for the CRTC port; 1 byte
356 * for the CRTC index; 1 byte for the mask to apply to the value
357 * retrieved from the CRTC; 1 byte for the shift right to apply to the
358 * masked CRTC value; 2 bytes for the offset to the flag array, to
359 * which the shifted value is added; 1 byte for the mask applied to the
360 * value read from the flag array; and 1 byte for the value to compare
361 * against the masked byte from the flag table.
364 uint16_t condptr = bios->io_flag_condition_tbl_ptr + cond * IO_FLAG_CONDITION_SIZE;
365 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[condptr])));
366 uint8_t crtcindex = bios->data[condptr + 2];
367 uint8_t mask = bios->data[condptr + 3];
368 uint8_t shift = bios->data[condptr + 4];
369 uint16_t flagarray = le16_to_cpu(*((uint16_t *)(&bios->data[condptr + 5])));
370 uint8_t flagarraymask = bios->data[condptr + 7];
371 uint8_t cmpval = bios->data[condptr + 8];
375 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
376 "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, Shift: 0x%02X, FlagArray: 0x%04X, FAMask: 0x%02X, Cmpval: 0x%02X\n",
377 offset, crtcport, crtcindex, mask, shift, flagarray, flagarraymask, cmpval);
379 nv_idx_port_rd(pScrn, crtcport, crtcindex, &data);
381 data = bios->data[flagarray + ((data & mask) >> shift)];
382 data &= flagarraymask;
385 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
386 "0x%04X: Checking if 0x%02X equals 0x%02X\n",
387 offset, data, cmpval);
395 uint32_t getMNP_single(NVPtr pNv, uint32_t clk, int *bestNM, int *bestlog2P)
397 /* Find M, N and P for a single stage PLL
399 * Note that some bioses (NV3x) have lookup tables of precomputed MNP values,
400 * but we're too lazy to use those atm
402 * "clk" parameter in kHz
403 * returns calculated clock
406 bios_t *bios = &pNv->VBIOS;
408 int maxlog2P, log2P, P;
410 uint32_t minvco = bios->fminvco;
411 uint32_t maxvco = bios->fmaxvco;
414 unsigned int bestdelta = UINT_MAX;
415 uint32_t bestclk = 0;
417 int crystal_strap_mask = 1 << 6;
418 /* open coded pNv->twoHeads test */
419 if (bios->chip_version > 0x10 && bios->chip_version != 0x15 &&
420 bios->chip_version != 0x1a && bios->chip_version != 0x20)
421 crystal_strap_mask |= 1 << 22;
422 switch (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) & crystal_strap_mask) {
432 case (1 << 22 | 1 << 6):
438 /* this division verified for nv20, nv28 (Haiku), nv34 -- nv17 is guessed */
439 /* possibly correlated with introduction of 27MHz crystal */
440 if (bios->chip_version <= 0x16 || bios->chip_version == 0x20) {
456 if ((clk << maxlog2P) < minvco) {
457 minvco = clk << maxlog2P;
460 if (clk + clk/200 > maxvco) /* +0.5% */
461 maxvco = clk + clk/200;
463 /* NV34 goes maxlog2P->0, NV20 goes 0->maxlog2P */
464 for (log2P = 0; log2P <= maxlog2P; log2P++) {
472 /* nv_hw.c in nv driver uses 7 and 8 for minM */
473 for (M = 1; M <= maxM; M++) {
474 /* add crystal/2 to round better */
475 N = (clkP * M + crystal/2) / crystal;
476 if (N > 256) /* we lost */
479 /* more rounding additions */
480 calcclk = ((N * crystal + P/2) / P + M/2) / M;
481 delta = abs(calcclk - clk);
482 /* we do an exhaustive search rather than terminating
483 * on an optimality condition...
485 if (delta < bestdelta) {
488 *bestNM = N << 8 | M;
490 if (delta == 0) /* except this one */
501 uint32_t getMNP_double(NVPtr pNv, struct pll_lims *pll_lim, uint32_t clk, int *bestNM1, int *bestNM2, int *bestlog2P)
503 /* Find M, N and P for a two stage PLL
505 * Note that some bioses (NV30+) have lookup tables of precomputed MNP values,
506 * but we're too lazy to use those atm
508 * "clk" parameter in kHz
509 * returns calculated clock
513 uint32_t minvco1 = pll_lim->vco1.minfreq, maxvco1 = pll_lim->vco1.maxfreq;
514 uint32_t minvco2 = pll_lim->vco2.minfreq, maxvco2 = pll_lim->vco2.maxfreq, vco2;
515 int maxM1 = 13, M1, N1;
516 int maxM2 = 4, M2, N2;
517 uint32_t minU1 = pll_lim->vco1.min_inputfreq, minU2 = pll_lim->vco2.min_inputfreq;
520 int calcclk1, calcclk2, calcclkout, delta;
521 unsigned int bestdelta = UINT_MAX;
522 uint32_t bestclk = 0;
525 *bestNM1 = 0xff << 8 | 13;
526 *bestNM2 = 0xff << 8 | 5;
529 switch (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) & (1 << 22 | 1 << 6)) {
537 case (1 << 22 | 1 << 6):
542 if (maxvco2 < clk + clk/200) /* +0.5% */
543 maxvco2 = clk + clk/200;
544 vco2 = (maxvco2 - maxvco2/200) / 2;
546 for (log2P = 0; log2P < 6 && clk <= (vco2 >> log2P); log2P++) /* log2P is maximum of 6 */
550 for (M1 = 1; M1 <= maxM1; M1++) {
551 if (crystal/M1 < minU1)
554 for (N1 = 1; N1 <= 0xff; N1++) {
555 calcclk1 = crystal * N1 / M1;
556 if (calcclk1 < minvco1)
558 if (calcclk1 > maxvco1)
561 for (M2 = 1; M2 <= maxM2; M2++) {
562 if (calcclk1/M2 < minU2)
565 /* add calcclk1/2 to round better */
566 N2 = (clkP * M2 + calcclk1/2) / calcclk1;
567 /* this N2 > maxM2 test is a bit weird, but it's correct for nv31 */
568 if (N2 < 4 || N2 > 0x46 || N2 > maxM2)
570 if (N2/M2 < 4 || N2/M2 > 10)
573 calcclk2 = calcclk1 * N2 / M2;
574 if (calcclk2 < minvco2 || calcclk2 > maxvco2)
577 calcclkout = calcclk2 >> log2P;
578 delta = abs(calcclkout - clk);
579 /* we do an exhaustive search rather than terminating
580 * on an optimality condition...
582 if (delta < bestdelta) {
584 bestclk = calcclkout;
585 *bestNM1 = N1 << 8 | M1;
586 *bestNM2 = N2 << 8 | M2;
588 if (delta == 0) /* except this one */
598 static void setPLL_single(ScrnInfoPtr pScrn, uint32_t reg, int NM, int log2P)
602 nv32_rd(pScrn, reg, &pll);
603 if (pll == (log2P << 16 | NM))
604 return; /* already set */
607 //this stuff is present on my nv34 and something similar on the nv31
608 //it is not on nv20, and I don't know how useful or necessary it is
610 uint32_t saved_1584, shift_1584;
611 Bool frob1584 = FALSE;
632 nv32_rd(pScrn, 0x00001584, &saved_1584);
633 nv32_wr(pScrn, 0x00001584, (saved_1584 & ~(0xf << shift_1584)) | 1 << shift_1584);
638 nv32_wr(pScrn, reg, (pll & 0xffff0000) | NM);
642 nv32_rd(pScrn, reg, &pll);
644 /* then write P as well */
645 nv32_wr(pScrn, reg, (pll & 0xfff8ffff) | log2P << 16);
649 nv32_wr(pScrn, 0x00001584, saved_1584);
653 static void setPLL_double(ScrnInfoPtr pScrn, uint32_t reg1, int NM1, int NM2, int log2P)
655 uint32_t reg2, pll1, pll2;
658 if (reg2 == 0x680590)
659 reg2 = NV_RAMDAC_VPLL2_B;
661 nv32_rd(pScrn, reg1, &pll1);
662 nv32_rd(pScrn, reg2, &pll2);
663 if (pll1 == (log2P << 16 | NM1) && pll2 == (1 << 31 | NM2))
664 return; /* already set */
667 //this stuff is present on my nv31
668 //I don't know how useful or necessary it is
670 uint32_t saved_1584, shift_1584;
671 Bool frob1584 = FALSE;
684 nv32_rd(pScrn, 0x00001584, &saved_1584);
685 nv32_wr(pScrn, 0x00001584, (saved_1584 & ~(0xf << shift_1584)) | 1 << shift_1584);
689 nv32_wr(pScrn, reg2, (pll2 & 0x7fff0000) | NM2);
690 nv32_wr(pScrn, reg1, (pll1 & 0xfff80000) | log2P << 16 | NM1);
694 nv32_wr(pScrn, 0x00001584, saved_1584);
698 Bool get_pll_limits(ScrnInfoPtr pScrn, enum pll_types plltype, struct pll_lims *pll_lim);
700 static void setPLL(ScrnInfoPtr pScrn, bios_t *bios, uint32_t reg, uint32_t clk)
703 NVPtr pNv = NVPTR(pScrn);
706 // FIXME: both getMNP versions will need some alterations for nv40 type stuff
707 if (bios->chip_version >= 0x40 || bios->chip_version == 0x31 || bios->chip_version == 0x36) {
708 struct pll_lims pll_lim;
709 // for NV40, pll_type will need setting
710 get_pll_limits(pScrn, 0, &pll_lim);
711 getMNP_double(pNv, &pll_lim, clk, &NM1, &NM2, &log2P);
712 setPLL_double(pScrn, reg, NM1, NM2, log2P);
714 getMNP_single(pNv, clk, &NM1, &log2P);
715 setPLL_single(pScrn, reg, NM1, log2P);
719 static Bool init_prog(ScrnInfoPtr pScrn, bios_t *bios, CARD16 offset, init_exec_t *iexec)
721 /* INIT_PROG opcode: 0x31
723 * offset (8 bit): opcode
724 * offset + 1 (32 bit): reg
725 * offset + 5 (32 bit): and mask
726 * offset + 9 (8 bit): shift right
727 * offset + 10 (8 bit): number of configurations
728 * offset + 11 (32 bit): register
729 * offset + 15 (32 bit): configuration 1
732 * Starting at offset + 15 there are "number of configurations"
733 * 32 bit values. To find out which configuration value to use
734 * read "CRTC reg" on the CRTC controller with index "CRTC index"
735 * and bitwise AND this value with "and mask" and then bit shift the
736 * result "shift right" bits to the right.
737 * Assign "register" with appropriate configuration value.
740 CARD32 reg = *((CARD32 *) (&bios->data[offset + 1]));
741 CARD32 and = *((CARD32 *) (&bios->data[offset + 5]));
742 CARD8 shiftr = *((CARD8 *) (&bios->data[offset + 9]));
743 CARD8 nr = *((CARD8 *) (&bios->data[offset + 10]));
744 CARD32 reg2 = *((CARD32 *) (&bios->data[offset + 11]));
746 CARD32 configval, tmp;
748 if (iexec->execute) {
749 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: REG: 0x%04X\n", offset,
752 nv32_rd(pScrn, reg, &tmp);
753 configuration = (tmp & and) >> shiftr;
755 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CONFIGURATION TO USE: 0x%02X\n",
756 offset, configuration);
758 if (configuration <= nr) {
761 *((CARD32 *) (&bios->data[offset + 15 + configuration * 4]));
763 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: REG: 0x%08X, VALUE: 0x%08X\n", offset,
766 nv32_rd(pScrn, reg2, &tmp);
767 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CURRENT VALUE IS: 0x%08X\n",
769 nv32_wr(pScrn, reg2, configval);
775 static Bool init_io_restrict_prog(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
777 /* INIT_IO_RESTRICT_PROG opcode: 0x32 ('2')
779 * offset (8 bit): opcode
780 * offset + 1 (16 bit): CRTC port
781 * offset + 3 (8 bit): CRTC index
782 * offset + 4 (8 bit): mask
783 * offset + 5 (8 bit): shift
784 * offset + 6 (8 bit): count
785 * offset + 7 (32 bit): register
786 * offset + 11 (32 bit): configuration 1
789 * Starting at offset + 11 there are "count" 32 bit values.
790 * To find out which value to use read index "CRTC index" on "CRTC port",
791 * AND this value with "mask" and then bit shift right "shift" bits.
792 * Read the appropriate value using this index and write to "register"
795 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
796 uint8_t crtcindex = bios->data[offset + 3];
797 uint8_t mask = bios->data[offset + 4];
798 uint8_t shift = bios->data[offset + 5];
799 uint8_t count = bios->data[offset + 6];
800 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 7])));
808 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
809 "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
810 offset, crtcport, crtcindex, mask, shift, count, reg);
812 nv_idx_port_rd(pScrn, crtcport, crtcindex, &config);
813 config = (config & mask) >> shift;
814 if (config > count) {
815 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
816 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
817 offset, config, count);
821 configval = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 11 + config * 4])));
824 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
825 "0x%04X: Writing config %02X\n", offset, config);
827 nv32_wr(pScrn, reg, configval);
832 static Bool init_repeat(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
834 /* INIT_REPEAT opcode: 0x33 ('3')
836 * offset (8 bit): opcode
837 * offset + 1 (8 bit): count
839 * Execute script following this opcode up to INIT_REPEAT_END
843 uint8_t count = bios->data[offset + 1];
846 /* no iexec->execute check by design */
848 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
849 "0x%04X: REPEATING FOLLOWING SEGMENT %d TIMES\n",
852 iexec->repeat = TRUE;
854 /* count - 1, as the script block will execute once when we leave this
855 * opcode -- this is compatible with bios behaviour as:
856 * a) the block is always executed at least once, even if count == 0
857 * b) the bios interpreter skips to the op following INIT_END_REPEAT,
860 for (i = 0; i < count - 1; i++)
861 parse_init_table(pScrn, bios, offset + 2, iexec);
863 iexec->repeat = FALSE;
868 static Bool init_io_restrict_pll(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
870 /* INIT_IO_RESTRICT_PLL opcode: 0x34 ('4')
872 * offset (8 bit): opcode
873 * offset + 1 (16 bit): CRTC port
874 * offset + 3 (8 bit): CRTC index
875 * offset + 4 (8 bit): mask
876 * offset + 5 (8 bit): shift
877 * offset + 6 (8 bit): IO flag condition index
878 * offset + 7 (8 bit): count
879 * offset + 8 (32 bit): register
880 * offset + 12 (16 bit): frequency 1
883 * Starting at offset + 12 there are "count" 16 bit frequencies (10kHz).
884 * Set PLL register "register" to coefficients for frequency n,
885 * selected by reading index "CRTC index" of "CRTC port" ANDed with
886 * "mask" and shifted right by "shift". If "IO flag condition index" > 0,
887 * and condition met, double frequency before setting it.
890 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
891 uint8_t crtcindex = bios->data[offset + 3];
892 uint8_t mask = bios->data[offset + 4];
893 uint8_t shift = bios->data[offset + 5];
894 int8_t io_flag_condition_idx = bios->data[offset + 6];
895 uint8_t count = bios->data[offset + 7];
896 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 8])));
904 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
905 "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, Shift: 0x%02X, IO Flag Condition: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
906 offset, crtcport, crtcindex, mask, shift, io_flag_condition_idx, count, reg);
908 nv_idx_port_rd(pScrn, crtcport, crtcindex, &config);
909 config = (config & mask) >> shift;
910 if (config > count) {
911 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
912 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
913 offset, config, count);
917 freq = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 12 + config * 2])));
919 if (io_flag_condition_idx > 0) {
920 if (io_flag_condition(pScrn, bios, offset, io_flag_condition_idx)) {
921 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
922 "0x%04X: CONDITION FULFILLED - FREQ DOUBLED\n", offset);
925 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
926 "0x%04X: CONDITION IS NOT FULFILLED. FREQ UNCHANGED\n", offset);
930 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
931 "0x%04X: Reg: 0x%08X, Config: 0x%02X, Freq: %d0kHz\n",
932 offset, reg, config, freq);
934 setPLL(pScrn, bios, reg, freq * 10);
939 static Bool init_end_repeat(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
941 /* INIT_END_REPEAT opcode: 0x36 ('6')
943 * offset (8 bit): opcode
945 * Marks the end of the block for INIT_REPEAT to repeat
948 /* no iexec->execute check by design */
950 /* iexec->repeat flag necessary to go past INIT_END_REPEAT opcode when
951 * we're not in repeat mode
959 static Bool init_copy(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
961 /* INIT_COPY opcode: 0x37 ('7')
963 * offset (8 bit): opcode
964 * offset + 1 (32 bit): register
965 * offset + 5 (8 bit): shift
966 * offset + 6 (8 bit): srcmask
967 * offset + 7 (16 bit): CRTC port
968 * offset + 9 (8 bit): CRTC index
969 * offset + 10 (8 bit): mask
971 * Read index "CRTC index" on "CRTC port", AND with "mask", OR with
972 * (REGVAL("register") >> "shift" & "srcmask") and write-back to CRTC port
975 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
976 uint8_t shift = bios->data[offset + 5];
977 uint8_t srcmask = bios->data[offset + 6];
978 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 7])));
979 uint8_t crtcindex = bios->data[offset + 9];
980 uint8_t mask = bios->data[offset + 10];
988 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
989 "0x%04X: Reg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%02X, Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X\n",
990 offset, reg, shift, srcmask, crtcport, crtcindex, mask);
992 nv32_rd(pScrn, reg, &data);
997 data <<= (0x100 - shift);
1001 nv_idx_port_rd(pScrn, crtcport, crtcindex, &crtcdata);
1002 crtcdata = (crtcdata & mask) | (uint8_t)data;
1003 nv_idx_port_wr(pScrn, crtcport, crtcindex, crtcdata);
1008 static Bool init_not(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1010 /* INIT_NOT opcode: 0x38 ('8')
1012 * offset (8 bit): opcode
1014 * Invert the current execute / no-execute condition (i.e. "else")
1017 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1018 "0x%04X: ------ SKIPPING FOLLOWING COMMANDS ------\n", offset);
1020 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1021 "0x%04X: ------ EXECUTING FOLLOWING COMMANDS ------\n", offset);
1023 iexec->execute = !iexec->execute;
1027 static Bool init_io_flag_condition(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1029 /* INIT_IO_FLAG_CONDITION opcode: 0x39 ('9')
1031 * offset (8 bit): opcode
1032 * offset + 1 (8 bit): condition number
1034 * Check condition "condition number" in the IO flag condition table.
1035 * If condition not met skip subsequent opcodes until condition
1036 * is inverted (INIT_NOT), or we hit INIT_RESUME
1039 uint8_t cond = bios->data[offset + 1];
1041 if (!iexec->execute)
1044 if (io_flag_condition(pScrn, bios, offset, cond))
1045 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1046 "0x%04X: CONDITION FULFILLED - CONTINUING TO EXECUTE\n", offset);
1048 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1049 "0x%04X: CONDITION IS NOT FULFILLED\n", offset);
1050 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1051 "0x%04X: ------ SKIPPING FOLLOWING COMMANDS ------\n", offset);
1052 iexec->execute = FALSE;
1058 Bool init_idx_addr_latched(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1060 /* INIT_INDEX_ADDRESS_LATCHED opcode: 0x49 ('I')
1062 * offset (8 bit): opcode
1063 * offset + 1 (32 bit): control register
1064 * offset + 5 (32 bit): data register
1065 * offset + 9 (32 bit): mask
1066 * offset + 13 (32 bit): data
1067 * offset + 17 (8 bit): count
1068 * offset + 18 (8 bit): address 1
1069 * offset + 19 (8 bit): data 1
1072 * For each of "count" address and data pairs, write "data n" to "data register",
1073 * read the current value of "control register", and write it back once ANDed
1074 * with "mask", ORed with "data", and ORed with "address n"
1077 uint32_t controlreg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1078 uint32_t datareg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
1079 uint32_t mask = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 9])));
1080 uint32_t data = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 13])));
1081 uint8_t count = bios->data[offset + 17];
1085 if (!iexec->execute)
1088 if (DEBUGLEVEL >= 6)
1089 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1090 "0x%04X: ControlReg: 0x%08X, DataReg: 0x%08X, Mask: 0x%08X, Data: 0x%08X, Count: 0x%02X\n",
1091 offset, controlreg, datareg, mask, data, count);
1093 for (i = 0; i < count; i++) {
1094 uint8_t instaddress = bios->data[offset + 18 + i * 2];
1095 uint8_t instdata = bios->data[offset + 19 + i * 2];
1097 if (DEBUGLEVEL >= 6)
1098 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1099 "0x%04X: Address: 0x%02X, Data: 0x%02X\n", offset, instaddress, instdata);
1101 nv32_wr(pScrn, datareg, instdata);
1103 nv32_rd(pScrn, controlreg, &value);
1104 value = (value & mask) | data | instaddress;
1106 nv32_wr(pScrn, controlreg, value);
1112 static Bool init_io_restrict_pll2(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1114 /* INIT_IO_RESTRICT_PLL2 opcode: 0x4A ('J')
1116 * offset (8 bit): opcode
1117 * offset + 1 (16 bit): CRTC port
1118 * offset + 3 (8 bit): CRTC index
1119 * offset + 4 (8 bit): mask
1120 * offset + 5 (8 bit): shift
1121 * offset + 6 (8 bit): count
1122 * offset + 7 (32 bit): register
1123 * offset + 11 (32 bit): frequency 1
1126 * Starting at offset + 11 there are "count" 32 bit frequencies (kHz).
1127 * Set PLL register "register" to coefficients for frequency n,
1128 * selected by reading index "CRTC index" of "CRTC port" ANDed with
1129 * "mask" and shifted right by "shift".
1132 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
1133 uint8_t crtcindex = bios->data[offset + 3];
1134 uint8_t mask = bios->data[offset + 4];
1135 uint8_t shift = bios->data[offset + 5];
1136 uint8_t count = bios->data[offset + 6];
1137 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 7])));
1141 if (!iexec->execute)
1144 if (DEBUGLEVEL >= 6)
1145 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1146 "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
1147 offset, crtcport, crtcindex, mask, shift, count, reg);
1152 nv_idx_port_rd(pScrn, crtcport, crtcindex, &config);
1153 config = (config & mask) >> shift;
1154 if (config > count) {
1155 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1156 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
1157 offset, config, count);
1161 freq = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 11 + config * 4])));
1163 if (DEBUGLEVEL >= 6)
1164 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1165 "0x%04X: Reg: 0x%08X, Config: 0x%02X, Freq: %dkHz\n",
1166 offset, reg, config, freq);
1168 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: [ NOT YET IMPLEMENTED ]\n", offset);
1173 static Bool init_pll2(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1175 /* INIT_PLL2 opcode: 0x4B ('K')
1177 * offset (8 bit): opcode
1178 * offset + 1 (32 bit): register
1179 * offset + 5 (32 bit): freq
1181 * Set PLL register "register" to coefficients for frequency "freq"
1184 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1185 uint32_t freq = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
1187 if (!iexec->execute)
1190 if (DEBUGLEVEL >= 6)
1191 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1192 "0x%04X: Reg: 0x%04X, Freq: %dkHz\n",
1195 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: [ NOT YET IMPLEMENTED ]\n", offset);
1200 static uint32_t get_tmds_index_reg(ScrnInfoPtr pScrn, uint8_t mlv)
1202 /* For mlv < 0x80, it is an index into a table of TMDS base addresses
1203 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by CR58 for CR57 = 0
1204 * to index a table of offsets to the basic 0x6808b0 address
1205 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by CR58 for CR57 = 0
1206 * to index a table of offsets to the basic 0x6808b0 address, and then flip the offset by 8
1209 NVPtr pNv = NVPTR(pScrn);
1210 int pramdac_offset[13] = {0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000};
1211 uint32_t pramdac_table[4] = {0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8};
1214 /* here we assume that the DCB table has already been parsed */
1217 /* This register needs to be written to set index for reading CR58 */
1218 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, 0x57, 0);
1219 nv_idx_port_rd(pScrn, CRTC_INDEX_COLOR, 0x58, &dcb_entry);
1220 if (dcb_entry > pNv->dcb_table.entries) {
1221 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1222 "CR58 doesn't have a valid DCB entry currently (%02X)\n", dcb_entry);
1225 dacoffset = pramdac_offset[pNv->dcb_table.entry[dcb_entry].or];
1228 return (0x6808b0 + dacoffset);
1230 if (mlv > (sizeof(pramdac_table) / sizeof(uint32_t))) {
1231 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1232 "Magic Lookup Value too big (%02X)\n", mlv);
1235 return pramdac_table[mlv];
1239 static Bool init_tmds(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1241 /* INIT_TMDS opcode: 0x4F ('O') (non-canon name)
1243 * offset (8 bit): opcode
1244 * offset + 1 (8 bit): magic lookup value
1245 * offset + 2 (8 bit): TMDS address
1246 * offset + 3 (8 bit): mask
1247 * offset + 4 (8 bit): data
1249 * Read the data reg for TMDS address "TMDS address", AND it with mask
1250 * and OR it with data, then write it back
1251 * "magic lookup value" determines which TMDS base address register is used --
1252 * see get_tmds_index_reg()
1255 uint8_t mlv = bios->data[offset + 1];
1256 uint32_t tmdsaddr = bios->data[offset + 2];
1257 uint8_t mask = bios->data[offset + 3];
1258 uint8_t data = bios->data[offset + 4];
1259 uint32_t reg, value;
1261 if (!iexec->execute)
1264 if (DEBUGLEVEL >= 6)
1265 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1266 "0x%04X: MagicLookupValue: 0x%02X, TMDSAddr: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n",
1267 offset, mlv, tmdsaddr, mask, data);
1269 reg = get_tmds_index_reg(pScrn, mlv);
1271 nv32_wr(pScrn, reg, tmdsaddr | 0x10000);
1272 nv32_rd(pScrn, reg + 4, &value);
1273 value = (value & mask) | data;
1274 nv32_wr(pScrn, reg + 4, value);
1275 nv32_wr(pScrn, reg, tmdsaddr);
1280 Bool init_zm_tmds_group(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1282 /* INIT_ZM_TMDS_GROUP opcode: 0x50 ('P') (non-canon name)
1284 * offset (8 bit): opcode
1285 * offset + 1 (8 bit): magic lookup value
1286 * offset + 2 (8 bit): count
1287 * offset + 3 (8 bit): addr 1
1288 * offset + 4 (8 bit): data 1
1291 * For each of "count" TMDS address and data pairs write "data n" to "addr n"
1292 * "magic lookup value" determines which TMDS base address register is used --
1293 * see get_tmds_index_reg()
1296 uint8_t mlv = bios->data[offset + 1];
1297 uint8_t count = bios->data[offset + 2];
1301 if (!iexec->execute)
1304 if (DEBUGLEVEL >= 6)
1305 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1306 "0x%04X: MagicLookupValue: 0x%02X, Count: 0x%02X\n",
1307 offset, mlv, count);
1309 reg = get_tmds_index_reg(pScrn, mlv);
1311 for (i = 0; i < count; i++) {
1312 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2];
1313 uint8_t tmdsdata = bios->data[offset + 4 + i * 2];
1315 nv32_wr(pScrn, reg + 4, tmdsdata);
1316 nv32_wr(pScrn, reg, tmdsaddr);
1322 Bool init_cr_idx_adr_latch(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1324 /* INIT_CR_INDEX_ADDRESS_LATCHED opcode: 0x51 ('Q')
1326 * offset (8 bit): opcode
1327 * offset + 1 (8 bit): CRTC index1
1328 * offset + 2 (8 bit): CRTC index2
1329 * offset + 3 (8 bit): baseaddr
1330 * offset + 4 (8 bit): count
1331 * offset + 5 (8 bit): data 1
1334 * For each of "count" address and data pairs, write "baseaddr + n" to
1335 * "CRTC index1" and "data n" to "CRTC index2"
1336 * Once complete, restore initial value read from "CRTC index1"
1338 uint8_t crtcindex1 = bios->data[offset + 1];
1339 uint8_t crtcindex2 = bios->data[offset + 2];
1340 uint8_t baseaddr = bios->data[offset + 3];
1341 uint8_t count = bios->data[offset + 4];
1342 uint8_t oldaddr, data;
1345 if (!iexec->execute)
1348 if (DEBUGLEVEL >= 6)
1349 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1350 "0x%04X: Index1: 0x%02X, Index2: 0x%02X, BaseAddr: 0x%02X, Count: 0x%02X\n",
1351 offset, crtcindex1, crtcindex2, baseaddr, count);
1353 nv_idx_port_rd(pScrn, CRTC_INDEX_COLOR, crtcindex1, &oldaddr);
1355 for (i = 0; i < count; i++) {
1356 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, crtcindex1, baseaddr + i);
1358 data = bios->data[offset + 5 + i];
1359 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, crtcindex2, data);
1362 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, crtcindex1, oldaddr);
1367 Bool init_cr(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1369 /* INIT_CR opcode: 0x52 ('R')
1371 * offset (8 bit): opcode
1372 * offset + 1 (8 bit): CRTC index
1373 * offset + 2 (8 bit): mask
1374 * offset + 3 (8 bit): data
1376 * Assign the value of at "CRTC index" ANDed with mask and ORed with data
1377 * back to "CRTC index"
1380 uint8_t crtcindex = bios->data[offset + 1];
1381 uint8_t mask = bios->data[offset + 2];
1382 uint8_t data = bios->data[offset + 3];
1385 if (!iexec->execute)
1388 if (DEBUGLEVEL >= 6)
1389 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1390 "0x%04X: Index: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n",
1391 offset, crtcindex, mask, data);
1393 nv_idx_port_rd(pScrn, CRTC_INDEX_COLOR, crtcindex, &value);
1395 value = (value & mask) | data;
1397 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, crtcindex, value);
1402 static Bool init_zm_cr(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1404 /* INIT_ZM_CR opcode: 0x53 ('S')
1406 * offset (8 bit): opcode
1407 * offset + 1 (8 bit): CRTC index
1408 * offset + 2 (8 bit): value
1410 * Assign "value" to CRTC register with index "CRTC index".
1413 uint8_t crtcindex = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1414 uint8_t data = bios->data[offset + 2];
1416 if (!iexec->execute)
1419 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, crtcindex, data);
1424 static Bool init_zm_cr_group(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1426 /* INIT_ZM_CR_GROUP opcode: 0x54 ('T')
1428 * offset (8 bit): opcode
1429 * offset + 1 (8 bit): count
1430 * offset + 2 (8 bit): CRTC index 1
1431 * offset + 3 (8 bit): value 1
1434 * For "count", assign "value n" to CRTC register with index "CRTC index n".
1437 uint8_t count = bios->data[offset + 1];
1440 if (!iexec->execute)
1443 for (i = 0; i < count; i++)
1444 init_zm_cr(pScrn, bios, offset + 2 + 2 * i - 1, iexec);
1449 static Bool init_condition_time(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1451 /* INIT_CONDITION_TIME opcode: 0x56 ('V')
1453 * offset (8 bit): opcode
1454 * offset + 1 (8 bit): condition number
1456 * Check condition "condition number" in the condition table.
1457 * The condition table entry has 4 bytes for the address of the
1458 * register to check, 4 bytes for a mask and 4 for a test value.
1459 * If condition not met sleep for 2ms
1462 // this opcode makes no sense. it seems to do some competely useless things
1463 uint8_t cond = bios->data[offset + 1];
1464 // uint16_t b = bios->data[offset + 2]; // this needs printing
1465 uint16_t condptr = bios->condition_tbl_ptr + cond * CONDITION_SIZE;
1466 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[condptr])));
1467 uint32_t mask = le32_to_cpu(*((uint32_t *)(&bios->data[condptr + 4])));
1468 uint32_t cmpval = le32_to_cpu(*((uint32_t *)(&bios->data[condptr + 8])));
1471 if (!iexec->execute)
1474 if (DEBUGLEVEL >= 6)
1475 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1476 "0x%04X: Cond: 0x%02X, Reg: 0x%08X, Mask: 0x%08X, Cmpval: 0x%08X\n",
1477 offset, cond, reg, mask, cmpval);
1480 reg &= 0xfffffffc; // FIXME: this not in init_condition() - should it be?
1482 nv32_rd(pScrn, reg, &data);
1485 if (DEBUGLEVEL >= 6)
1486 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1487 "0x%04X: Checking if 0x%08X equals 0x%08X\n",
1488 offset, data, cmpval);
1490 if (data != cmpval) {
1491 if (DEBUGLEVEL >= 6)
1492 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1493 "0x%04X: Condition not met, sleeping for 2ms\n", offset);
1497 if (DEBUGLEVEL >= 6)
1498 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1499 "0x%04X: Condition met, continuing\n", offset);
1504 static Bool init_zm_reg_sequence(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1506 /* INIT_ZM_REG_SEQUENCE opcode: 0x58 ('X')
1508 * offset (8 bit): opcode
1509 * offset + 1 (32 bit): base register
1510 * offset + 5 (8 bit): count
1511 * offset + 6 (32 bit): value 1
1514 * Starting at offset + 6 there are "count" 32 bit values.
1515 * For "count" iterations set "base register" + 4 * current_iteration
1516 * to "value current_iteration"
1519 uint32_t basereg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1520 uint32_t count = bios->data[offset + 5];
1523 if (!iexec->execute)
1526 if (DEBUGLEVEL >= 6)
1527 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1528 "0x%04X: BaseReg: 0x%08X, Count: 0x%02X\n",
1529 offset, basereg, count);
1531 for (i = 0; i < count; i++) {
1532 uint32_t reg = basereg + i * 4;
1533 uint32_t data = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 6 + i * 4])));
1535 nv32_wr(pScrn, reg, data);
1541 static Bool init_indirect_reg(ScrnInfoPtr pScrn, bios_t *bios, CARD16 offset, init_exec_t *iexec)
1543 /* INIT_INDIRECT_REG opcode: 0x5A
1545 * offset (8 bit): opcode
1546 * offset + 1 (32 bit): register
1547 * offset + 5 (16 bit): adress offset (in bios)
1549 * Lookup value at offset data in the bios and write it to reg
1551 CARD32 reg = *((CARD32 *) (&bios->data[offset + 1]));
1552 CARD16 data = le16_to_cpu(*((CARD16 *) (&bios->data[offset + 5])));
1553 CARD32 data2 = bios->data[data];
1555 if (iexec->execute) {
1556 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1557 "0x%04X: REG: 0x%04X, DATA AT: 0x%04X, VALUE IS: 0x%08X\n",
1558 offset, reg, data, data2);
1560 if (DEBUGLEVEL >= 6) {
1562 nv32_rd(pScrn, reg, &tmpval);
1563 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CURRENT VALUE IS: 0x%08X\n", offset, tmpval);
1566 nv32_wr(pScrn, reg, data2);
1571 static Bool init_sub_direct(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1573 /* INIT_SUB_DIRECT opcode: 0x5B ('[')
1575 * offset (8 bit): opcode
1576 * offset + 1 (16 bit): subroutine offset (in bios)
1578 * Calls a subroutine that will execute commands until INIT_DONE
1582 uint16_t sub_offset = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
1584 if (!iexec->execute)
1587 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: EXECUTING SUB-ROUTINE AT 0x%04X\n",
1588 offset, sub_offset);
1590 parse_init_table(pScrn, bios, sub_offset, iexec);
1592 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: END OF SUB-ROUTINE AT 0x%04X\n",
1593 offset, sub_offset);
1598 static Bool init_copy_nv_reg(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1600 /* INIT_COPY_NV_REG opcode: 0x5F ('_')
1602 * offset (8 bit): opcode
1603 * offset + 1 (32 bit): src reg
1604 * offset + 5 (8 bit): shift
1605 * offset + 6 (32 bit): src mask
1606 * offset + 10 (32 bit): xor
1607 * offset + 14 (32 bit): dst reg
1608 * offset + 18 (32 bit): dst mask
1610 * Shift REGVAL("src reg") right by (signed) "shift", AND result with
1611 * "src mask", then XOR with "xor". Write this OR'd with
1612 * (REGVAL("dst reg") AND'd with "dst mask") to "dst reg"
1615 uint32_t srcreg = *((uint32_t *)(&bios->data[offset + 1]));
1616 uint8_t shift = bios->data[offset + 5];
1617 uint32_t srcmask = *((uint32_t *)(&bios->data[offset + 6]));
1618 uint32_t xor = *((uint32_t *)(&bios->data[offset + 10]));
1619 uint32_t dstreg = *((uint32_t *)(&bios->data[offset + 14]));
1620 uint32_t dstmask = *((uint32_t *)(&bios->data[offset + 18]));
1621 uint32_t srcvalue, dstvalue;
1623 if (!iexec->execute)
1626 if (DEBUGLEVEL >= 6)
1627 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1628 "0x%04X: SrcReg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%08X, Xor: 0x%08X, DstReg: 0x%08X, DstMask: 0x%08X\n",
1629 offset, srcreg, shift, srcmask, xor, dstreg, dstmask);
1631 nv32_rd(pScrn, srcreg, &srcvalue);
1636 srcvalue <<= (0x100 - shift);
1638 srcvalue = (srcvalue & srcmask) ^ xor;
1640 nv32_rd(pScrn, dstreg, &dstvalue);
1641 dstvalue &= dstmask;
1643 nv32_wr(pScrn, dstreg, dstvalue | srcvalue);
1648 static Bool init_zm_index_io(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1650 /* INIT_ZM_INDEX_IO opcode: 0x62 ('b')
1652 * offset (8 bit): opcode
1653 * offset + 1 (16 bit): CRTC port
1654 * offset + 3 (8 bit): CRTC index
1655 * offset + 4 (8 bit): data
1657 * Write "data" to index "CRTC index" of "CRTC port"
1659 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
1660 uint8_t crtcindex = bios->data[offset + 3];
1661 uint8_t data = bios->data[offset + 4];
1663 if (!iexec->execute)
1666 nv_idx_port_wr(pScrn, crtcport, crtcindex, data);
1671 static Bool init_compute_mem(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1673 /* INIT_COMPUTE_MEM opcode: 0x63 ('c')
1675 * offset (8 bit): opcode
1680 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: [ NOT YET IMPLEMENTED ]\n", offset);
1682 uint16_t ramcfg = le16_to_cpu(*((uint16_t *)(&bios->data[bios->ram_table_offset])));
1687 if (!iexec->execute)
1690 nv32_rd(pScrn, 0x00101000, &strapinfo);
1691 nv32_rd(pScrn, 0x00100080, &pfb_debug);
1693 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "STRAPINFO: 0x%08X\n", strapinfo);
1694 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PFB_DEBUG: 0x%08X\n", pfb_debug);
1695 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "RAM CFG: 0x%04X\n", ramcfg);
1697 pfb_debug &= 0xffffffef;
1699 strapinfo &= 0x0000000f;
1700 ramcfg2 = le16_to_cpu(*((uint16_t *)
1701 (&bios->data[bios->ram_table_offset + (2 * strapinfo)])));
1703 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "AFTER MANIPULATION\n");
1704 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "STRAPINFO: 0x%08X\n", strapinfo);
1705 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PFB_DEBUG: 0x%08X\n", pfb_debug);
1706 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "RAM CFG2: 0x%08X\n", ramcfg2);
1712 nv32_rd(pScrn, 0x00100200, ®1);
1713 nv32_rd(pScrn, 0x0010020C, ®2);
1715 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x00100200: 0x%08X\n", reg1);
1716 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x0010020C: 0x%08X\n", reg2);
1722 static Bool init_reset(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1724 /* INIT_RESET opcode: 0x65 ('e')
1726 * offset (8 bit): opcode
1727 * offset + 1 (32 bit): register
1728 * offset + 5 (32 bit): value1
1729 * offset + 9 (32 bit): value2
1731 * Assign "value1" to "register", then assign "value2" to "register"
1734 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1735 uint32_t value1 = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
1736 uint32_t value2 = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 9])));
1737 uint32_t pci_nv_19, pci_nv_20;
1739 /* no iexec->execute check by design */
1741 nv32_rd(pScrn, NV_PBUS_PCI_NV_19, &pci_nv_19);
1742 nv32_wr(pScrn, NV_PBUS_PCI_NV_19, 0);
1743 nv32_wr(pScrn, reg, value1);
1747 nv32_wr(pScrn, reg, value2);
1748 nv32_wr(pScrn, NV_PBUS_PCI_NV_19, pci_nv_19);
1750 nv32_rd(pScrn, NV_PBUS_PCI_NV_20, &pci_nv_20);
1751 pci_nv_20 &= !NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; /* 0xfffffffe */
1752 nv32_wr(pScrn, NV_PBUS_PCI_NV_20, pci_nv_20);
1757 static Bool init_index_io8(ScrnInfoPtr pScrn, bios_t *bios, CARD16 offset, init_exec_t *iexec)
1759 /* INIT_INDEX_IO8 opcode: 0x69
1761 * offset (8 bit): opcode
1762 * offset + 1 (16 bit): CRTC reg
1763 * offset + 3 (8 bit): and mask
1764 * offset + 4 (8 bit): or with
1769 NVPtr pNv = NVPTR(pScrn);
1770 volatile CARD8 *ptr = crtchead ? pNv->PCIO1 : pNv->PCIO0;
1771 CARD16 reg = le16_to_cpu(*((CARD16 *)(&bios->data[offset + 1])));
1772 CARD8 and = *((CARD8 *)(&bios->data[offset + 3]));
1773 CARD8 or = *((CARD8 *)(&bios->data[offset + 4]));
1776 if (iexec->execute) {
1777 data = (VGA_RD08(ptr, reg) & and) | or;
1779 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1780 "0x%04X: CRTC REG: 0x%04X, VALUE: 0x%02X\n",
1782 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CURRENT VALUE IS: 0x%02X\n", offset,
1783 VGA_RD08(ptr, reg));
1785 #ifdef PERFORM_WRITE
1786 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "init_index_io8 crtcreg 0x%X value 0x%X\n",reg,data);
1788 VGA_WR08(ptr, reg, data);
1794 static Bool init_sub(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1796 /* INIT_SUB opcode: 0x6B ('k')
1798 * offset (8 bit): opcode
1799 * offset + 1 (8 bit): script number
1801 * Execute script number "script number", as a subroutine
1804 uint8_t sub = bios->data[offset + 1];
1806 if (!iexec->execute)
1809 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1810 "0x%04X: EXECUTING SUB-SCRIPT %d\n", offset, sub);
1812 parse_init_table(pScrn, bios,
1813 le16_to_cpu(*((uint16_t *)(&bios->data[bios->init_script_tbls_ptr + sub * 2]))),
1816 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1817 "0x%04X: END OF SUB-SCRIPT %d\n", offset, sub);
1822 static Bool init_ram_condition(ScrnInfoPtr pScrn, bios_t *bios, CARD16 offset, init_exec_t *iexec)
1824 /* INIT_RAM_CONDITION opcode: 0x6D
1826 * offset (8 bit): opcode
1827 * offset + 1 (8 bit): and mask
1828 * offset + 2 (8 bit): cmpval
1830 * Test if (NV_PFB_BOOT & and mask) matches cmpval
1832 NVPtr pNv = NVPTR(pScrn);
1833 CARD8 and = *((CARD8 *) (&bios->data[offset + 1]));
1834 CARD8 cmpval = *((CARD8 *) (&bios->data[offset + 2]));
1837 if (iexec->execute) {
1838 data=(pNv->PFB[NV_PFB_BOOT/4])∧
1840 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1841 "0x%04X: CHECKING IF REGVAL: 0x%08X equals COND: 0x%08X\n",
1842 offset, data, cmpval);
1844 if (data == cmpval) {
1845 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1846 "0x%04X: CONDITION FULFILLED - CONTINUING TO EXECUTE\n",
1849 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CONDITION IS NOT FULFILLED\n", offset);
1850 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1851 "0x%04X: ------ SKIPPING FOLLOWING COMMANDS ------\n", offset);
1852 iexec->execute = FALSE;
1858 static Bool init_nv_reg(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1860 /* INIT_NV_REG opcode: 0x6E ('n')
1862 * offset (8 bit): opcode
1863 * offset + 1 (32 bit): register
1864 * offset + 5 (32 bit): mask
1865 * offset + 9 (32 bit): data
1867 * Assign ((REGVAL("register") & "mask") | "data") to "register"
1870 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
1871 uint32_t mask = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
1872 uint32_t data = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 9])));
1875 if (!iexec->execute)
1878 if (DEBUGLEVEL >= 6)
1879 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1880 "0x%04X: Reg: 0x%08X, Mask: 0x%08X, Data: 0x%08X\n",
1881 offset, reg, mask, data);
1883 nv32_rd(pScrn, reg, &value);
1885 value = (value & mask) | data;
1887 nv32_wr(pScrn, reg, value);
1892 static Bool init_macro(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1894 /* INIT_MACRO opcode: 0x6F ('o')
1896 * offset (8 bit): opcode
1897 * offset + 1 (8 bit): macro number
1899 * Look up macro index "macro number" in the macro index table.
1900 * The macro index table entry has 1 byte for the index in the macro table,
1901 * and 1 byte for the number of times to repeat the macro.
1902 * The macro table entry has 4 bytes for the register address and
1903 * 4 bytes for the value to write to that register
1906 uint8_t macro_index_tbl_idx = bios->data[offset + 1];
1907 uint16_t tmp = bios->macro_index_tbl_ptr + (macro_index_tbl_idx * MACRO_INDEX_SIZE);
1908 uint8_t macro_tbl_idx = bios->data[tmp];
1909 uint8_t count = bios->data[tmp + 1];
1913 if (!iexec->execute)
1916 if (DEBUGLEVEL >= 6)
1917 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1918 "0x%04X: Macro: 0x%02X, MacroTableIndex: 0x%02X, Count: 0x%02X\n",
1919 offset, macro_index_tbl_idx, macro_tbl_idx, count);
1921 for (i = 0; i < count; i++) {
1922 uint16_t macroentryptr = bios->macro_tbl_ptr + (macro_tbl_idx + i) * MACRO_SIZE;
1924 reg = le32_to_cpu(*((uint32_t *)(&bios->data[macroentryptr])));
1925 data = le32_to_cpu(*((uint32_t *)(&bios->data[macroentryptr + 4])));
1927 nv32_wr(pScrn, reg, data);
1933 static Bool init_done(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1935 /* INIT_DONE opcode: 0x71 ('q')
1937 * offset (8 bit): opcode
1939 * End the current script
1942 /* mild retval abuse to stop parsing this table */
1946 static Bool init_resume(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
1948 /* INIT_RESUME opcode: 0x72 ('r')
1950 * offset (8 bit): opcode
1952 * End the current execute / no-execute condition
1958 iexec->execute = TRUE;;
1959 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1960 "0x%04X: ---- EXECUTING FOLLOWING COMMANDS ----\n", offset);
1965 static Bool init_ram_condition2(ScrnInfoPtr pScrn, bios_t *bios, CARD16 offset, init_exec_t *iexec)
1967 /* INIT_RAM_CONDITION2 opcode: 0x73
1969 * offset (8 bit): opcode
1970 * offset + 1 (8 bit): and mask
1971 * offset + 2 (8 bit): cmpval
1973 * Test if (NV_EXTDEV_BOOT & and mask) matches cmpval
1975 NVPtr pNv = NVPTR(pScrn);
1976 CARD32 and = *((CARD32 *) (&bios->data[offset + 1]));
1977 CARD32 cmpval = *((CARD32 *) (&bios->data[offset + 5]));
1980 if (iexec->execute) {
1981 data=(nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT))∧
1983 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1984 "0x%04X: CHECKING IF REGVAL: 0x%08X equals COND: 0x%08X\n",
1985 offset, data, cmpval);
1987 if (data == cmpval) {
1988 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1989 "0x%04X: CONDITION FULFILLED - CONTINUING TO EXECUTE\n",
1992 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: CONDITION IS NOT FULFILLED\n", offset);
1993 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1994 "0x%04X: ------ SKIPPING FOLLOWING COMMANDS ------\n", offset);
1995 iexec->execute = FALSE;
2001 static Bool init_time(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2003 /* INIT_TIME opcode: 0x74 ('t')
2005 * offset (8 bit): opcode
2006 * offset + 1 (16 bit): time
2008 * Sleep for "time" microseconds.
2011 uint16_t time = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
2013 if (!iexec->execute)
2016 if (DEBUGLEVEL >= 6)
2017 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2018 "0x%04X: Sleeping for 0x%04X microseconds\n", offset, time);
2025 static Bool init_condition(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2027 /* INIT_CONDITION opcode: 0x75 ('u')
2029 * offset (8 bit): opcode
2030 * offset + 1 (8 bit): condition number
2032 * Check condition "condition number" in the condition table.
2033 * The condition table entry has 4 bytes for the address of the
2034 * register to check, 4 bytes for a mask and 4 for a test value.
2035 * If condition not met skip subsequent opcodes until condition
2036 * is inverted (INIT_NOT), or we hit INIT_RESUME
2039 uint8_t cond = bios->data[offset + 1];
2040 uint16_t condptr = bios->condition_tbl_ptr + cond * CONDITION_SIZE;
2041 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[condptr])));
2042 uint32_t mask = le32_to_cpu(*((uint32_t *)(&bios->data[condptr + 4])));
2043 uint32_t cmpval = le32_to_cpu(*((uint32_t *)(&bios->data[condptr + 8])));
2046 if (!iexec->execute)
2049 if (DEBUGLEVEL >= 6)
2050 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2051 "0x%04X: Cond: 0x%02X, Reg: 0x%08X, Mask: 0x%08X, Cmpval: 0x%08X\n",
2052 offset, cond, reg, mask, cmpval);
2054 nv32_rd(pScrn, reg, &data);
2057 if (DEBUGLEVEL >= 6)
2058 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2059 "0x%04X: Checking if 0x%08X equals 0x%08X\n",
2060 offset, data, cmpval);
2062 if (data == cmpval) {
2063 if (DEBUGLEVEL >= 6)
2064 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2065 "0x%04X: CONDITION FULFILLED - CONTINUING TO EXECUTE\n", offset);
2067 if (DEBUGLEVEL >= 6)
2068 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2069 "0x%04X: CONDITION IS NOT FULFILLED\n", offset);
2070 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2071 "0x%04X: ------ SKIPPING FOLLOWING COMMANDS ------\n", offset);
2072 iexec->execute = FALSE;
2078 static Bool init_index_io(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2080 /* INIT_INDEX_IO opcode: 0x78 ('x')
2082 * offset (8 bit): opcode
2083 * offset + 1 (16 bit): CRTC port
2084 * offset + 3 (8 bit): CRTC index
2085 * offset + 4 (8 bit): mask
2086 * offset + 5 (8 bit): data
2088 * Read value at index "CRTC index" on "CRTC port", AND with "mask", OR with "data", write-back
2091 uint16_t crtcport = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 1])));
2092 uint8_t crtcindex = bios->data[offset + 3];
2093 uint8_t mask = bios->data[offset + 4];
2094 uint8_t data = bios->data[offset + 5];
2097 if (!iexec->execute)
2100 if (DEBUGLEVEL >= 6)
2101 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2102 "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n",
2103 offset, crtcport, crtcindex, mask, data);
2105 nv_idx_port_rd(pScrn, crtcport, crtcindex, &value);
2106 value = (value & mask) | data;
2107 nv_idx_port_wr(pScrn, crtcport, crtcindex, value);
2112 static Bool init_pll(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2114 /* INIT_PLL opcode: 0x79 ('y')
2116 * offset (8 bit): opcode
2117 * offset + 1 (32 bit): register
2118 * offset + 5 (16 bit): freq
2120 * Set PLL register "register" to coefficients for frequency (10kHz) "freq"
2123 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
2124 uint16_t freq = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 5])));
2126 if (!iexec->execute)
2129 if (DEBUGLEVEL >= 6)
2130 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2131 "0x%04X: Reg: 0x%08X, Freq: %d0kHz\n",
2134 setPLL(pScrn, bios, reg, freq * 10);
2139 static Bool init_zm_reg(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2141 /* INIT_ZM_REG opcode: 0x7A ('z')
2143 * offset (8 bit): opcode
2144 * offset + 1 (32 bit): register
2145 * offset + 5 (32 bit): value
2147 * Assign "value" to "register"
2150 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
2151 uint32_t value = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
2153 if (!iexec->execute)
2156 nv32_wr(pScrn, reg, value);
2161 /* hack to avoid moving the itbl_entry array before this function */
2162 int init_ram_restrict_zm_reg_group_blocklen = 0;
2164 static Bool init_ram_restrict_zm_reg_group(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2166 /* INIT_RAM_RESTRICT_ZM_REG_GROUP opcode: 0x8F ('')
2168 * offset (8 bit): opcode
2169 * offset + 1 (32 bit): reg
2170 * offset + 5 (8 bit): regincrement
2171 * offset + 6 (8 bit): count
2172 * offset + 7 (32 bit): value 1,1
2175 * Use the RAMCFG strap of PEXTDEV_BOOT as an index into the table at
2176 * ram_restrict_table_ptr. The value read from here is 'n', and
2177 * "value 1,n" gets written to "reg". This repeats "count" times and on
2178 * each iteration 'm', "reg" increases by "regincrement" and
2179 * "value m,n" is used. The extent of n is limited by a number read
2180 * from the 'M' BIT table, herein called "blocklen"
2183 NVPtr pNv = NVPTR(pScrn);
2184 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
2185 uint8_t regincrement = bios->data[offset + 5];
2186 uint8_t count = bios->data[offset + 6];
2187 uint32_t strap_ramcfg, data;
2192 /* previously set by 'M' BIT table */
2193 blocklen = init_ram_restrict_zm_reg_group_blocklen;
2195 if (!iexec->execute)
2199 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2200 "0x%04X: Zero block length - has the M table been parsed?\n", offset);
2204 strap_ramcfg = (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) >> 2) & 0xf;
2205 index = bios->data[bios->ram_restrict_tbl_ptr + strap_ramcfg];
2207 if (DEBUGLEVEL >= 6)
2208 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2209 "0x%04X: Reg: 0x%08X, RegIncrement: 0x%02X, Count: 0x%02X, StrapRamCfg: 0x%02X, Index: 0x%02X\n",
2210 offset, reg, regincrement, count, strap_ramcfg, index);
2212 for (i = 0; i < count; i++) {
2213 data = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 7 + index * 4 + blocklen * i])));
2215 nv32_wr(pScrn, reg, data);
2217 reg += regincrement;
2223 static Bool init_copy_zm_reg(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2225 /* INIT_COPY_ZM_REG opcode: 0x90 ('')
2227 * offset (8 bit): opcode
2228 * offset + 1 (32 bit): src reg
2229 * offset + 5 (32 bit): dst reg
2231 * Put contents of "src reg" into "dst reg"
2234 uint32_t srcreg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
2235 uint32_t dstreg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 5])));
2238 if (!iexec->execute)
2241 nv32_rd(pScrn, srcreg, &data);
2242 nv32_wr(pScrn, dstreg, data);
2247 static Bool init_zm_reg_group_addr_latched(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2249 /* INIT_ZM_REG_GROUP_ADDRESS_LATCHED opcode: 0x91 ('')
2251 * offset (8 bit): opcode
2252 * offset + 1 (32 bit): src reg
2253 * offset + 5 (8 bit): count
2254 * offset + 6 (32 bit): data 1
2257 * For each of "count" values write "data n" to "src reg"
2260 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 1])));
2261 uint8_t count = bios->data[offset + 5];
2264 if (!iexec->execute)
2267 for (i = 0; i < count; i++) {
2268 uint32_t data = le32_to_cpu(*((uint32_t *)(&bios->data[offset + 6 + 4 * i])));
2269 nv32_wr(pScrn, reg, data);
2275 static Bool init_reserved(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset, init_exec_t *iexec)
2277 /* INIT_RESERVED opcode: 0x92 ('')
2279 * offset (8 bit): opcode
2281 * Seemingly does nothing
2287 static init_tbl_entry_t itbl_entry[] = {
2288 /* command name , id , length , offset , mult , command handler */
2289 // { "INIT_PROG" , 0x31, 15 , 10 , 4 , init_prog },
2290 { "INIT_IO_RESTRICT_PROG" , 0x32, 11 , 6 , 4 , init_io_restrict_prog },
2291 { "INIT_REPEAT" , 0x33, 2 , 0 , 0 , init_repeat },
2292 { "INIT_IO_RESTRICT_PLL" , 0x34, 12 , 7 , 2 , init_io_restrict_pll },
2293 { "INIT_END_REPEAT" , 0x36, 1 , 0 , 0 , init_end_repeat },
2294 { "INIT_COPY" , 0x37, 11 , 0 , 0 , init_copy },
2295 { "INIT_NOT" , 0x38, 1 , 0 , 0 , init_not },
2296 { "INIT_IO_FLAG_CONDITION" , 0x39, 2 , 0 , 0 , init_io_flag_condition },
2297 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, 18 , 17 , 2 , init_idx_addr_latched },
2298 { "INIT_IO_RESTRICT_PLL2" , 0x4A, 11 , 6 , 4 , init_io_restrict_pll2 },
2299 { "INIT_PLL2" , 0x4B, 9 , 0 , 0 , init_pll2 },
2300 /* { "INIT_I2C_BYTE" , 0x4C, x , x , x , init_i2c_byte }, */
2301 /* { "INIT_ZM_I2C_BYTE" , 0x4D, x , x , x , init_zm_i2c_byte }, */
2302 /* { "INIT_ZM_I2C" , 0x4E, x , x , x , init_zm_i2c }, */
2303 { "INIT_TMDS" , 0x4F, 5 , 0 , 0 , init_tmds },
2304 { "INIT_ZM_TMDS_GROUP" , 0x50, 3 , 2 , 2 , init_zm_tmds_group },
2305 { "INIT_CR_INDEX_ADDRESS_LATCHED" , 0x51, 5 , 4 , 1 , init_cr_idx_adr_latch },
2306 { "INIT_CR" , 0x52, 4 , 0 , 0 , init_cr },
2307 { "INIT_ZM_CR" , 0x53, 3 , 0 , 0 , init_zm_cr },
2308 { "INIT_ZM_CR_GROUP" , 0x54, 2 , 1 , 2 , init_zm_cr_group },
2309 { "INIT_CONDITION_TIME" , 0x56, 3 , 0 , 0 , init_condition_time },
2310 { "INIT_ZM_REG_SEQUENCE" , 0x58, 6 , 5 , 4 , init_zm_reg_sequence },
2311 // { "INIT_INDIRECT_REG" , 0x5A, 7 , 0 , 0 , init_indirect_reg },
2312 { "INIT_SUB_DIRECT" , 0x5B, 3 , 0 , 0 , init_sub_direct },
2313 { "INIT_COPY_NV_REG" , 0x5F, 22 , 0 , 0 , init_copy_nv_reg },
2314 { "INIT_ZM_INDEX_IO" , 0x62, 5 , 0 , 0 , init_zm_index_io },
2315 { "INIT_COMPUTE_MEM" , 0x63, 1 , 0 , 0 , init_compute_mem },
2316 { "INIT_RESET" , 0x65, 13 , 0 , 0 , init_reset },
2317 /* { "INIT_NEXT" , 0x66, x , x , x , init_next }, */
2318 /* { "INIT_NEXT" , 0x67, x , x , x , init_next }, */
2319 /* { "INIT_NEXT" , 0x68, x , x , x , init_next }, */
2320 // { "INIT_INDEX_IO8" , 0x69, 5 , 0 , 0 , init_index_io8 },
2321 { "INIT_SUB" , 0x6B, 2 , 0 , 0 , init_sub },
2322 // { "INIT_RAM_CONDITION" , 0x6D, 3 , 0 , 0 , init_ram_condition },
2323 { "INIT_NV_REG" , 0x6E, 13 , 0 , 0 , init_nv_reg },
2324 { "INIT_MACRO" , 0x6F, 2 , 0 , 0 , init_macro },
2325 { "INIT_DONE" , 0x71, 1 , 0 , 0 , init_done },
2326 { "INIT_RESUME" , 0x72, 1 , 0 , 0 , init_resume },
2327 // { "INIT_RAM_CONDITION2" , 0x73, 9 , 0 , 0 , init_ram_condition2 },
2328 { "INIT_TIME" , 0x74, 3 , 0 , 0 , init_time },
2329 { "INIT_CONDITION" , 0x75, 2 , 0 , 0 , init_condition },
2330 /* { "INIT_IO_CONDITION" , 0x76, x , x , x , init_io_condition }, */
2331 { "INIT_INDEX_IO" , 0x78, 6 , 0 , 0 , init_index_io },
2332 { "INIT_PLL" , 0x79, 7 , 0 , 0 , init_pll },
2333 { "INIT_ZM_REG" , 0x7A, 9 , 0 , 0 , init_zm_reg },
2334 /* INIT_RAM_RESTRICT_ZM_REG_GROUP's mult is loaded by M table in BIT */
2335 { "INIT_RAM_RESTRICT_ZM_REG_GROUP" , 0x8F, 7 , 6 , 0 , init_ram_restrict_zm_reg_group },
2336 { "INIT_COPY_ZM_REG" , 0x90, 9 , 0 , 0 , init_copy_zm_reg },
2337 { "INIT_ZM_REG_GROUP_ADDRESS_LATCHED" , 0x91, 6 , 5 , 4 , init_zm_reg_group_addr_latched },
2338 { "INIT_RESERVED" , 0x92, 1 , 0 , 0 , init_reserved },
2339 { 0 , 0 , 0 , 0 , 0 , 0 }
2342 static unsigned int get_init_table_entry_length(bios_t *bios, unsigned int offset, int i)
2344 /* Calculates the length of a given init table entry. */
2345 return itbl_entry[i].length + bios->data[offset + itbl_entry[i].length_offset]*itbl_entry[i].length_multiplier;
2348 static void parse_init_table(ScrnInfoPtr pScrn, bios_t *bios, unsigned int offset, init_exec_t *iexec)
2350 /* Parses all commands in a init table. */
2352 /* We start out executing all commands found in the
2353 * init table. Some op codes may change the status
2354 * of this variable to SKIP, which will cause
2355 * the following op codes to perform no operation until
2356 * the value is changed back to EXECUTE.
2362 /* Loop until INIT_DONE causes us to break out of the loop
2363 * (or until offset > bios length just in case... )
2364 * (and no more than 10000 iterations just in case... ) */
2365 while ((offset < bios->length) && (count++ < 10000)) {
2366 id = bios->data[offset];
2368 /* Find matching id in itbl_entry */
2369 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != id); i++)
2372 if (itbl_entry[i].name) {
2373 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: [ (0x%02X) - %s ]\n",
2374 offset, itbl_entry[i].id, itbl_entry[i].name);
2376 /* execute eventual command handler */
2377 if (itbl_entry[i].handler)
2378 if (!(*itbl_entry[i].handler)(pScrn, bios, offset, iexec))
2381 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2382 "0x%04X: Init table command not found: 0x%02X\n", offset, id);
2386 /* Add the offset of the current command including all data
2387 * of that command. The offset will then be pointing on the
2390 offset += get_init_table_entry_length(bios, offset, i);
2394 static void parse_init_tables(ScrnInfoPtr pScrn, bios_t *bios)
2396 /* Loops and calls parse_init_table() for each present table. */
2400 init_exec_t iexec = {TRUE, FALSE};
2402 while ((table = le16_to_cpu(*((uint16_t *)(&bios->data[bios->init_script_tbls_ptr + i]))))) {
2404 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: Parsing init table %d\n",
2407 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2408 "0x%04X: ------ EXECUTING FOLLOWING COMMANDS ------\n", table);
2410 parse_init_table(pScrn, bios, table, &iexec);
2415 void link_head_and_output(ScrnInfoPtr pScrn, int head, int dcb_entry, Bool overrideval)
2417 /* The BIOS scripts don't do this for us, sadly
2418 * Luckily we do know the values ;-)
2420 * head < 0 indicates we wish to force a setting with the overrideval
2421 * (for VT restore etc.)
2424 NVPtr pNv = NVPTR(pScrn);
2425 int preferred_output = (ffs(pNv->dcb_table.entry[dcb_entry].or) & OUTPUT_1) >> 1;
2426 uint8_t tmds04 = 0x80;
2427 uint32_t tmds_ctrl, tmds_ctrl2;
2429 /* Bit 3 crosswires output and bus. */
2430 if (head >= 0 && head != preferred_output)
2432 if (head < 0 && overrideval)
2435 if (pNv->dcb_table.entry[dcb_entry].type == OUTPUT_LVDS)
2438 tmds_ctrl = NV_PRAMDAC0_OFFSET + (preferred_output ? NV_PRAMDAC0_SIZE : 0) + NV_RAMDAC_FP_TMDS_CONTROL;
2439 tmds_ctrl2 = NV_PRAMDAC0_OFFSET + (preferred_output ? NV_PRAMDAC0_SIZE : 0) + NV_RAMDAC_FP_TMDS_CONTROL_2;
2441 Bool oldexecute = pNv->VBIOS.execute;
2442 pNv->VBIOS.execute = TRUE;
2443 nv32_wr(pScrn, tmds_ctrl + 4, tmds04);
2444 nv32_wr(pScrn, tmds_ctrl, 0x04);
2445 if (pNv->dcb_table.entry[dcb_entry].type == OUTPUT_LVDS && pNv->VBIOS.fp.dual_link)
2446 nv32_wr(pScrn, tmds_ctrl2 + 4, tmds04 ^ 0x08);
2448 /* I have encountered no dvi (dual-link or not) that sets to anything else. */
2449 /* Does this change beyond the 165 MHz boundary? */
2450 nv32_wr(pScrn, tmds_ctrl2 + 4, 0x0);
2452 nv32_wr(pScrn, tmds_ctrl2, 0x04);
2453 pNv->VBIOS.execute = oldexecute;
2456 static void call_lvds_manufacturer_script(ScrnInfoPtr pScrn, int head, int dcb_entry, enum LVDS_script script)
2458 NVPtr pNv = NVPTR(pScrn);
2459 bios_t *bios = &pNv->VBIOS;
2460 init_exec_t iexec = {TRUE, FALSE};
2462 uint8_t sub = bios->data[bios->fp.xlated_entry + script];
2463 uint16_t scriptofs = le16_to_cpu(*((CARD16 *)(&bios->data[bios->init_script_tbls_ptr + sub * 2])));
2464 Bool power_off_for_reset, reset_after_pclk_change;
2465 uint16_t off_on_delay;
2467 if (!bios->fp.xlated_entry || !sub || !scriptofs)
2470 if (script == LVDS_INIT && bios->data[scriptofs] != 'q') {
2471 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "LVDS init script not stubbed\n");
2475 power_off_for_reset = bios->data[bios->fp.xlated_entry] & 1;
2476 reset_after_pclk_change = bios->data[bios->fp.xlated_entry] & 2;
2477 off_on_delay = le16_to_cpu(*(uint16_t *)&bios->data[bios->fp.xlated_entry + 7]);
2479 if (script == LVDS_PANEL_ON && reset_after_pclk_change)
2480 call_lvds_manufacturer_script(pScrn, head, dcb_entry, LVDS_RESET);
2481 if (script == LVDS_RESET && power_off_for_reset)
2482 call_lvds_manufacturer_script(pScrn, head, dcb_entry, LVDS_PANEL_OFF);
2484 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Calling LVDS script %d:\n", script);
2485 pNv->VBIOS.execute = TRUE;
2486 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, NV_VGA_CRTCX_OWNER,
2487 head ? NV_VGA_CRTCX_OWNER_HEADB : NV_VGA_CRTCX_OWNER_HEADA);
2488 parse_init_table(pScrn, bios, scriptofs, &iexec);
2489 pNv->VBIOS.execute = FALSE;
2491 if (script == LVDS_PANEL_OFF)
2492 usleep(off_on_delay * 1000);
2493 if (script == LVDS_RESET)
2494 link_head_and_output(pScrn, head, dcb_entry, FALSE);
2497 static uint16_t clkcmptable(bios_t *bios, uint16_t clktable, uint16_t pxclk)
2499 int compare_record_len, i = 0;
2500 uint16_t compareclk, scriptptr = 0;
2502 if (bios->major_version < 5) /* pre BIT */
2503 compare_record_len = 3;
2505 compare_record_len = 4;
2508 compareclk = le16_to_cpu(*((uint16_t *)&bios->data[clktable + compare_record_len * i]));
2509 if (pxclk >= compareclk) {
2510 if (bios->major_version < 5) {
2511 uint8_t tmdssub = bios->data[clktable + 2 + compare_record_len * i];
2512 scriptptr = le16_to_cpu(*((uint16_t *)(&bios->data[bios->init_script_tbls_ptr + tmdssub * 2])));
2514 scriptptr = le16_to_cpu(*((uint16_t *)&bios->data[clktable + 2 + compare_record_len * i]));
2518 } while (compareclk);
2523 static void rundigitaloutscript(ScrnInfoPtr pScrn, uint16_t scriptptr, int head, int dcb_entry)
2525 NVPtr pNv = NVPTR(pScrn);
2526 bios_t *bios = &pNv->VBIOS;
2527 init_exec_t iexec = {TRUE, FALSE};
2529 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "0x%04X: Parsing digital output script table\n", scriptptr);
2530 bios->execute = TRUE;
2531 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, NV_VGA_CRTCX_OWNER,
2532 head ? NV_VGA_CRTCX_OWNER_HEADB : NV_VGA_CRTCX_OWNER_HEADA);
2533 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, 0x57, 0);
2534 nv_idx_port_wr(pScrn, CRTC_INDEX_COLOR, 0x58, dcb_entry);
2535 parse_init_table(pScrn, bios, scriptptr, &iexec);
2536 bios->execute = FALSE;
2538 link_head_and_output(pScrn, head, dcb_entry, FALSE);
2541 static void run_lvds_table(ScrnInfoPtr pScrn, int head, int dcb_entry, enum LVDS_script script, uint16_t pxclk)
2543 /* The BIT LVDS table's header has the information to setup the
2544 * necessary registers. Following the standard 4 byte header are:
2545 * A bitmask byte and a dual-link transition pxclk valur for use in
2546 * selecting the init script when not using straps; 4 script pointers
2547 * for panel power, selected by output and on/off; and 8 table pointers
2548 * for panel init, the needed one determined by output, and bits in the
2549 * conf byte. These tables are similar to the TMDS tables, consisting
2550 * of a list of pxclks and script pointers.
2553 NVPtr pNv = NVPTR(pScrn);
2554 bios_t *bios = &pNv->VBIOS;
2555 int fpstrapping, outputset = (pNv->dcb_table.entry[dcb_entry].or == 4) ? 1 : 0;
2556 uint16_t scriptptr = 0, clktable;
2557 uint8_t clktableptr = 0;
2559 fpstrapping = (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) >> 16) & 0xf;
2561 /* for now we assume version 3.0 table - g80 support will need some changes */
2566 case LVDS_BACKLIGHT_ON: // check applicability of the script for this
2568 scriptptr = le16_to_cpu(*(uint16_t *)&bios->data[bios->fp.lvdsmanufacturerpointer + 7 + outputset * 2]);
2570 case LVDS_BACKLIGHT_OFF: // check applicability of the script for this
2571 case LVDS_PANEL_OFF:
2572 scriptptr = le16_to_cpu(*(uint16_t *)&bios->data[bios->fp.lvdsmanufacturerpointer + 11 + outputset * 2]);
2575 if (pNv->dcb_table.entry[dcb_entry].lvdsconf.use_straps_for_mode ||
2576 (fpstrapping != 0x0f && bios->data[bios->fp.xlated_entry + 1] != 0x0f)) {
2577 if (bios->fp.dual_link)
2579 if (bios->fp.BITbit1)
2582 uint8_t fallback = bios->data[bios->fp.lvdsmanufacturerpointer + 4];
2583 int fallbackcmpval = (pNv->dcb_table.entry[dcb_entry].or == 4) ? 4 : 1;
2584 uint8_t dltransitionclk = le16_to_cpu(*(uint16_t *)&bios->data[bios->fp.lvdsmanufacturerpointer + 5]);
2585 if (pxclk > dltransitionclk) { // dual-link
2587 fallbackcmpval *= 2;
2589 if (fallbackcmpval & fallback)
2593 /* adding outputset * 8 may not be correct */
2594 clktable = le16_to_cpu(*(uint16_t *)&bios->data[bios->fp.lvdsmanufacturerpointer + 15 + clktableptr * 2 + outputset * 8]);
2596 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Pixel clock comparison table not found\n");
2599 scriptptr = clkcmptable(bios, clktable, pxclk);
2603 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "LVDS output init script not found\n");
2606 rundigitaloutscript(pScrn, scriptptr, head, dcb_entry);
2609 void call_lvds_script(ScrnInfoPtr pScrn, int head, int dcb_entry, enum LVDS_script script, uint16_t pxclk)
2611 /* LVDS operations are multiplexed in an effort to present a single API
2612 * which works with two vastly differing underlying structures.
2613 * This acts as the demux
2616 NVPtr pNv = NVPTR(pScrn);
2617 bios_t *bios = &pNv->VBIOS;
2618 uint8_t lvds_ver = bios->data[bios->fp.lvdsmanufacturerpointer];
2623 if (lvds_ver < 0x30)
2624 call_lvds_manufacturer_script(pScrn, head, dcb_entry, script);
2626 run_lvds_table(pScrn, head, dcb_entry, script, pxclk);
2630 uint16_t fptablepointer;
2631 uint16_t fpxlatetableptr;
2632 uint16_t fpxlatemanufacturertableptr;
2636 static void parse_fp_mode_table(ScrnInfoPtr pScrn, bios_t *bios, struct fppointers *fpp)
2638 NVPtr pNv = NVPTR(pScrn);
2639 unsigned int fpstrapping;
2641 uint8_t fptable_ver, headerlen = 0, recordlen, fpentries = 0xf, fpindex;
2643 DisplayModePtr mode;
2645 fpstrapping = (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) >> 16) & 0xf;
2647 if (fpp->fptablepointer == 0x0 || fpp->fpxlatetableptr == 0x0) {
2648 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2649 "Pointers to flat panel table invalid\n");
2653 fptable = &bios->data[fpp->fptablepointer];
2655 fptable_ver = fptable[0];
2657 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2658 "Found flat panel mode table revision %d.%d\n",
2659 fptable_ver >> 4, fptable_ver & 0xf);
2661 switch (fptable_ver) {
2662 /* BMP version 0x5.0x11 BIOSen have version 1 like tables, but no version field,
2663 * and miss one of the spread spectrum/PWM bytes.
2664 * This could affect early GF2Go parts (not seen any appropriate ROMs though).
2665 * Here we assume that a version of 0x05 matches this case (combining with a
2666 * BMP version check would be better), as the common case for the panel type
2667 * field is 0x0005, and that is in fact what we are reading the first byte of. */
2668 case 0x05: /* some NV10, 11, 15, 16 */
2672 case 0x10: /* some NV15/16, and NV11+ */
2676 case 0x20: /* NV40+ */
2677 headerlen = fptable[1];
2678 recordlen = fptable[2];
2679 fpentries = fptable[3];
2683 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2684 "FP Table revision not currently supported\n");
2688 fpindex = bios->data[fpp->fpxlatetableptr + fpstrapping * fpp->xlatwidth];
2689 if (fpindex > fpentries) {
2690 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2691 "Bad flat panel table index\n");
2695 if (!(mode = xcalloc(1, sizeof(DisplayModeRec))))
2698 int modeofs = headerlen + recordlen * fpindex + ofs;
2699 mode->Clock = le16_to_cpu(*(uint16_t *)&fptable[modeofs]) * 10;
2700 mode->HDisplay = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 2]);
2701 mode->HSyncStart = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 10] + 1);
2702 mode->HSyncEnd = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 12] + 1);
2703 mode->HTotal = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 14] + 1);
2704 mode->VDisplay = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 16]);
2705 mode->VSyncStart = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 24] + 1);
2706 mode->VSyncEnd = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 26] + 1);
2707 mode->VTotal = le16_to_cpu(*(uint16_t *)&fptable[modeofs + 28] + 1);
2708 mode->Flags |= (fptable[modeofs + 30] & 0x10) ? V_PHSYNC : V_NHSYNC;
2709 mode->Flags |= (fptable[modeofs + 30] & 0x1) ? V_PVSYNC : V_NVSYNC;
2712 * bytes 1-2 are "panel type", including bits on whether Colour/mono, single/dual link, and type (TFT etc.)
2713 * bytes 3-6 are bits per colour in RGBX
2715 * 13-14 is HValid Start
2716 * 15-16 is HValid End
2717 * bytes 38-39 relate to spread spectrum settings
2718 * bytes 40-43 are something to do with PWM */
2720 mode->prev = mode->next = NULL;
2721 mode->status = MODE_OK;
2722 mode->type = M_T_DRIVER | M_T_PREFERRED;
2723 xf86SetModeDefaultName(mode);
2725 // if (XF86_CRTC_CONFIG_PTR(pScrn)->debug_modes) {
2726 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2727 "Found flat panel mode in BIOS tables:\n");
2728 xf86PrintModeline(pScrn->scrnIndex, mode);
2731 bios->fp.native_mode = mode;
2734 static void parse_lvds_manufacturer_table_init(ScrnInfoPtr pScrn, bios_t *bios, struct fppointers *fpp)
2736 /* The LVDS table changed considerably with BIT bioses. Previously
2737 * there was a header of version and record length, followed by several
2738 * records, indexed by a seperate xlat table, indexed in turn by the fp
2739 * strap in EXTDEV_BOOT. Each record had a config byte, followed by 6
2740 * script numbers for use by INIT_SUB which controlled panel init and
2741 * power, and finally a dword of ms to sleep between power off and on
2744 * The BIT LVDS table has the typical BIT table header: version byte,
2745 * header length byte, record length byte, and a byte for the maximum
2746 * number of records that can be held in the table.
2748 * The table following the header serves as an integrated config and
2749 * xlat table: the records in the table are indexed by the FP strap
2750 * nibble in EXTDEV_BOOT, and each record has two bytes - the first as
2751 * a config byte, the second for indexing the fp mode table pointed to
2752 * by the BIT 'D' table
2755 NVPtr pNv = NVPTR(pScrn);
2756 unsigned int fpstrapping, lvdsmanufacturerindex = 0;
2757 uint8_t lvds_ver, headerlen, recordlen;
2759 fpstrapping = (nvReadEXTDEV(pNv, NV_PEXTDEV_BOOT) >> 16) & 0xf;
2761 if (bios->fp.lvdsmanufacturerpointer == 0x0) {
2762 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2763 "Pointer to LVDS manufacturer table invalid\n");
2767 lvds_ver = bios->data[bios->fp.lvdsmanufacturerpointer];
2769 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2770 "Found LVDS manufacturer table revision %d.%d\n",
2771 lvds_ver >> 4, lvds_ver & 0xf);
2774 case 0x0a: /* pre NV40 */
2775 lvdsmanufacturerindex = bios->data[fpp->fpxlatemanufacturertableptr + fpstrapping];
2778 recordlen = bios->data[bios->fp.lvdsmanufacturerpointer + 1];
2781 case 0x30: /* NV4x */
2782 lvdsmanufacturerindex = fpstrapping;
2783 headerlen = bios->data[bios->fp.lvdsmanufacturerpointer + 1];
2784 if (headerlen < 0x1f) {
2785 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2786 "LVDS table header not understood\n");
2789 recordlen = bios->data[bios->fp.lvdsmanufacturerpointer + 2];
2791 case 0x40: /* It changed again with gf8 :o( */
2793 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2794 "LVDS table revision not currently supported\n");
2798 uint16_t lvdsofs = bios->fp.xlated_entry = bios->fp.lvdsmanufacturerpointer + headerlen + recordlen * lvdsmanufacturerindex;
2801 bios->fp.dual_link = bios->data[lvdsofs] & 4;
2802 bios->fp.if_is_18bit = !(bios->data[lvdsofs] & 16);
2805 bios->fp.dual_link = bios->data[lvdsofs] & 1;
2806 bios->fp.BITbit1 = bios->data[lvdsofs] & 2;
2807 fpp->fpxlatetableptr = bios->fp.lvdsmanufacturerpointer + headerlen + 1;
2808 fpp->xlatwidth = recordlen;
2813 void run_tmds_table(ScrnInfoPtr pScrn, int dcb_entry, int head, uint16_t pxclk)
2815 /* the dcb_entry parameter is the index of the appropriate DCB entry
2816 * the pxclk parameter is in 10s of kHz (eg. 108Mhz is 10800, or 0x2a30)
2818 * This runs the TMDS regs setting code found on BIT bios cards
2820 * For ffs(or) == 1 use the first table, for ffs(or) == 2 and
2821 * ffs(or) == 3, use the second.
2824 NVPtr pNv = NVPTR(pScrn);
2825 bios_t *bios = &pNv->VBIOS;
2826 uint16_t clktable = 0, scriptptr;
2828 if (pNv->dcb_table.entry[dcb_entry].location) /* off chip */
2831 switch (ffs(pNv->dcb_table.entry[dcb_entry].or)) {
2833 clktable = bios->tmds.output0_script_ptr;
2837 clktable = bios->tmds.output1_script_ptr;
2842 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Pixel clock comparison table not found\n");
2846 scriptptr = clkcmptable(bios, clktable, pxclk);
2849 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "TMDS output init script not found\n");
2853 rundigitaloutscript(pScrn, scriptptr, head, dcb_entry);
2856 static void parse_bios_version(ScrnInfoPtr pScrn, bios_t *bios, uint16_t offset)
2858 /* offset + 0 (8 bits): Micro version
2859 * offset + 1 (8 bits): Minor version
2860 * offset + 2 (8 bits): Chip version
2861 * offset + 3 (8 bits): Major version
2864 bios->major_version = bios->data[offset + 3];
2865 bios->chip_version = bios->data[offset + 2];
2866 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Bios version %02x.%02x.%02x.%02x\n",
2867 bios->data[offset + 3], bios->data[offset + 2],
2868 bios->data[offset + 1], bios->data[offset]);
2871 Bool get_pll_limits(ScrnInfoPtr pScrn, enum pll_types plltype, struct pll_lims *pll_lim)
2875 * Version 0x10: NV31
2876 * One byte header (version), one record of 24 bytes
2877 * Version 0x11: NV36 - Not implemented
2878 * Seems to have same record style as 0x10, but 3 records rather than 1
2879 * Version 0x20: Found on Geforce 6 cards
2880 * Trivial 4 byte BIT header. 31 (0x1f) byte record length
2881 * Version 0x21: Found on Geforce 7, 8 and some Geforce 6 cards
2882 * 5 byte header, fifth byte of unknown purpose. 35 (0x23) byte record length
2885 NVPtr pNv = NVPTR(pScrn);
2886 bios_t *bios = &pNv->VBIOS;
2887 uint8_t pll_lim_ver, headerlen, recordlen, entries;
2888 int pllindex = 0, i;
2890 if (!bios->pll_limit_tbl_ptr) {
2891 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Pointer to PLL limits table invalid\n");
2895 pll_lim_ver = bios->data[bios->pll_limit_tbl_ptr + 0];
2897 if (DEBUGLEVEL >= 6)
2898 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2899 "Found BIT PLL limits table version 0x%X\n", pll_lim_ver);
2901 switch (pll_lim_ver) {
2910 headerlen = bios->data[bios->pll_limit_tbl_ptr + 1];
2911 recordlen = bios->data[bios->pll_limit_tbl_ptr + 2];
2912 entries = bios->data[bios->pll_limit_tbl_ptr + 3];
2915 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2916 "PLL limits table revision not currently supported\n");
2920 /* initialize all members to zero */
2921 memset (pll_lim, 0, sizeof(struct pll_lims));
2923 if (pll_lim_ver == 0x10) {
2924 uint16_t plloffs = bios->pll_limit_tbl_ptr + headerlen + recordlen * pllindex;
2926 pll_lim->vco1.minfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs])));
2927 pll_lim->vco1.maxfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + 4])));
2928 pll_lim->vco2.minfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + 8])));
2929 pll_lim->vco2.maxfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + 12])));
2930 pll_lim->vco1.min_inputfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + 16])));
2931 pll_lim->vco2.min_inputfreq = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + 20])));
2932 } else { /* ver 0x20, 0x21 */
2933 uint16_t plloffs = bios->pll_limit_tbl_ptr + headerlen;
2935 for (i = 0; i < entries; i++) {
2936 uint32_t reg = le32_to_cpu(*((uint32_t *)(&bios->data[plloffs + recordlen * i])));
2938 if (plltype == VPLL1 && (reg == 0x680508 || reg == 0x4010)) {
2942 if (plltype == VPLL2 && (reg == 0x680520 || reg == 0x4018)) {
2946 if (reg == 0x0000) /* generic pll settings */
2950 plloffs += recordlen * pllindex;
2952 if (DEBUGLEVEL >= 6)
2953 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Loading PLL limits for reg 0x%08x\n",
2954 le32_to_cpu(*((uint32_t *)(&bios->data[plloffs]))));
2956 /* What output frequencies can each VCO generate? */
2957 pll_lim->vco1.minfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 4])));
2958 pll_lim->vco1.maxfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 6])));
2959 pll_lim->vco2.minfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 8])));
2960 pll_lim->vco2.maxfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 10])));
2962 /* What input frequencies do they accept (past the m-divider)? */
2963 pll_lim->vco1.min_inputfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 12])));
2964 pll_lim->vco1.max_inputfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 14])));
2965 pll_lim->vco2.min_inputfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 16])));
2966 pll_lim->vco2.max_inputfreq = le16_to_cpu(*((uint16_t *)(&bios->data[plloffs + 18])));
2968 /* What values are accepted as multiplier and divider? */
2969 pll_lim->vco1.min_n = bios->data[plloffs + 20];
2970 pll_lim->vco1.max_n = bios->data[plloffs + 21];
2971 pll_lim->vco1.min_m = bios->data[plloffs + 22];
2972 pll_lim->vco1.max_m = bios->data[plloffs + 23];
2973 pll_lim->vco2.min_n = bios->data[plloffs + 24];
2974 pll_lim->vco2.max_n = bios->data[plloffs + 25];
2975 pll_lim->vco2.min_m = bios->data[plloffs + 26];
2976 pll_lim->vco2.max_m = bios->data[plloffs + 27];
2978 pll_lim->unk1c = bios->data[plloffs + 28];
2979 pll_lim->unk1d = bios->data[plloffs + 29];
2980 pll_lim->unk1e = bios->data[plloffs + 30];
2983 #if 1 /* for easy debugging */
2984 ErrorF("pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq);
2985 ErrorF("pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq);
2986 ErrorF("pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq);
2987 ErrorF("pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq);
2989 ErrorF("pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq);
2990 ErrorF("pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq);
2991 ErrorF("pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq);
2992 ErrorF("pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq);
2994 ErrorF("pll.vco1.min_n: %d\n", pll_lim->vco1.min_n);
2995 ErrorF("pll.vco1.max_n: %d\n", pll_lim->vco1.max_n);
2996 ErrorF("pll.vco1.min_m: %d\n", pll_lim->vco1.min_m);
2997 ErrorF("pll.vco1.max_m: %d\n", pll_lim->vco1.max_m);
2998 ErrorF("pll.vco2.min_n: %d\n", pll_lim->vco2.min_n);
2999 ErrorF("pll.vco2.max_n: %d\n", pll_lim->vco2.max_n);
3000 ErrorF("pll.vco2.min_m: %d\n", pll_lim->vco2.min_m);
3001 ErrorF("pll.vco2.max_m: %d\n", pll_lim->vco2.max_m);
3003 ErrorF("pll.unk1c: %d\n", pll_lim->unk1c);
3004 ErrorF("pll.unk1d: %d\n", pll_lim->unk1d);
3005 ErrorF("pll.unk1e: %d\n", pll_lim->unk1e);
3011 static int parse_bit_B_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry)
3013 /* offset + 0 (32 bits): BIOS version dword
3015 * There's a bunch of bits in this table other than the bios version
3016 * that we don't use - their use currently unknown
3019 if (bitentry->length < 0x4) {
3020 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3021 "Do not understand B table entry\n");
3025 parse_bios_version(pScrn, bios, bitentry->offset);
3030 static int parse_bit_C_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry)
3032 /* offset + 8 (16 bits): PLL limits table pointer
3034 * There's more in here, but that's unknown.
3037 if (bitentry->length < 10) {
3038 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Do not understand C table entry\n");
3042 bios->pll_limit_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 8])));
3047 static int parse_bit_display_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry, struct fppointers *fpp)
3049 /* Parses the flat panel table segment that the bit entry points to.
3050 * Starting at bitentry->offset:
3052 * offset + 0 (16 bits): FIXME table pointer
3053 * offset + 2 (16 bits): mode table pointer
3056 if (bitentry->length != 4) {
3057 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3058 "Do not understand BIT display table entry\n");
3062 fpp->fptablepointer = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 2])));
3067 static unsigned int parse_bit_init_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry)
3069 /* Parses the init table segment that the bit entry points to.
3070 * Starting at bitentry->offset:
3072 * offset + 0 (16 bits): init script tables pointer
3073 * offset + 2 (16 bits): macro index table pointer
3074 * offset + 4 (16 bits): macro table pointer
3075 * offset + 6 (16 bits): condition table pointer
3076 * offset + 8 (16 bits): io condition table pointer
3077 * offset + 10 (16 bits): io flag condition table pointer
3078 * offset + 12 (16 bits): init function table pointer
3081 * * Are 'I' bit entries always of length 0xE?
3085 if (bitentry->length < 14) {
3086 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3087 "Unable to recognize BIT init table entry\n");
3091 bios->init_script_tbls_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset])));
3092 bios->macro_index_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 2])));
3093 bios->macro_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 4])));
3094 bios->condition_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 6])));
3095 bios->io_condition_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 8])));
3096 bios->io_flag_condition_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 10])));
3097 bios->init_function_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 12])));
3102 static int parse_bit_lvds_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry, struct fppointers *fpp)
3104 /* Parses the LVDS table segment that the bit entry points to.
3105 * Starting at bitentry->offset:
3107 * offset + 0 (16 bits): LVDS strap xlate table pointer
3110 if (bitentry->length != 2) {
3111 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3112 "Do not understand BIT LVDS table entry\n");
3116 /* no idea if it's still called the LVDS manufacturer table, but the concept's close enough */
3117 bios->fp.lvdsmanufacturerpointer = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset])));
3119 parse_lvds_manufacturer_table_init(pScrn, bios, fpp);
3124 static int parse_bit_M_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry)
3126 /* offset + 2 (8 bits): number of options in an INIT_RAM_RESTRICT_ZM_REG_GROUP opcode option set
3127 * offset + 3 (16 bits): pointer to strap xlate table for RAM restrict option selection
3129 * There's a bunch of bits in this table other than the RAM restrict
3130 * stuff that we don't use - their use currently unknown
3135 /* Older bios versions don't have a sufficiently long table for what we want */
3136 if (bitentry->length < 0x5)
3139 /* set up multiplier for INIT_RAM_RESTRICT_ZM_REG_GROUP */
3140 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != 0x8f); i++)
3142 itbl_entry[i].length_multiplier = bios->data[bitentry->offset + 2] * 4;
3143 init_ram_restrict_zm_reg_group_blocklen = itbl_entry[i].length_multiplier;
3145 bios->ram_restrict_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset + 3])));
3150 static int parse_bit_tmds_tbl_entry(ScrnInfoPtr pScrn, bios_t *bios, bit_entry_t *bitentry)
3152 /* Parses the pointer to the TMDS table
3154 * Starting at bitentry->offset:
3156 * offset + 0 (16 bits): TMDS table pointer
3158 * The TMDS table is typically found just before the DCB table, with a
3159 * characteristic signature of 0x11,0x13 (1.1 being version, 0x13 being
3162 * At offset +7 is a pointer to a script, which I don't know how to run yet
3163 * At offset +9 is a pointer to another script, likewise
3164 * Offset +11 has a pointer to a table where the first word is a pxclk
3165 * frequency and the second word a pointer to a script, which should be
3166 * run if the comparison pxclk frequency is less than the pxclk desired.
3167 * This repeats for decreasing comparison frequencies
3168 * Offset +13 has a pointer to a similar table
3169 * The selection of table (and possibly +7/+9 script) is dictated by
3170 * "or" from the DCB.
3173 uint16_t tmdstableptr, script1, script2;
3175 if (bitentry->length != 2) {
3176 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3177 "Do not understand BIT TMDS table entry\n");
3181 tmdstableptr = le16_to_cpu(*((uint16_t *)(&bios->data[bitentry->offset])));
3183 if (tmdstableptr == 0x0) {
3184 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Pointer to TMDS table invalid\n");
3188 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Found TMDS table revision %d.%d\n",
3189 bios->data[tmdstableptr] >> 4, bios->data[tmdstableptr] & 0xf);
3191 /* These two scripts are odd: they don't seem to get run even when they are not stubbed */
3192 script1 = le16_to_cpu(*((uint16_t *)&bios->data[tmdstableptr + 7]));
3193 script2 = le16_to_cpu(*((uint16_t *)&bios->data[tmdstableptr + 9]));
3194 if (bios->data[script1] != 'q' || bios->data[script2] != 'q')
3195 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "TMDS table script pointers not stubbed\n");
3197 bios->tmds.output0_script_ptr = le16_to_cpu(*((uint16_t *)&bios->data[tmdstableptr + 11]));
3198 bios->tmds.output1_script_ptr = le16_to_cpu(*((uint16_t *)&bios->data[tmdstableptr + 13]));
3203 static void parse_bit_structure(ScrnInfoPtr pScrn, bios_t *bios, unsigned int offset)
3205 bit_entry_t bitentry;
3207 struct fppointers fpp;
3208 NVPtr pNv = NVPTR(pScrn);
3210 memset(&fpp, 0, sizeof(struct fppointers));
3213 bitentry.id[0] = bios->data[offset];
3214 bitentry.id[1] = bios->data[offset + 1];
3215 bitentry.length = le16_to_cpu(*((uint16_t *)&bios->data[offset + 2]));
3216 bitentry.offset = le16_to_cpu(*((uint16_t *)&bios->data[offset + 4]));
3218 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3219 "0x%04X: Found BIT command with id 0x%02X (%c)\n",
3220 offset, bitentry.id[0], bitentry.id[0]);
3222 switch (bitentry.id[0]) {
3224 /* id[0] = 0 and id[1] = 0 ==> end of BIT struture */
3225 if (bitentry.id[1] == 0)
3229 parse_bit_B_tbl_entry(pScrn, bios, &bitentry);
3232 parse_bit_C_tbl_entry(pScrn, bios, &bitentry);
3235 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3236 "0x%04X: Found flat panel display table entry in BIT structure\n", offset);
3237 parse_bit_display_tbl_entry(pScrn, bios, &bitentry, &fpp);
3240 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3241 "0x%04X: Found init table entry in BIT structure\n", offset);
3242 parse_bit_init_tbl_entry(pScrn, bios, &bitentry);
3245 parse_bit_lvds_tbl_entry(pScrn, bios, &bitentry, &fpp);
3247 case 'M': /* memory? */
3248 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3249 "0x%04X: Found M table entry in BIT structure\n", offset);
3250 parse_bit_M_tbl_entry(pScrn, bios, &bitentry);
3253 parse_bit_tmds_tbl_entry(pScrn, bios, &bitentry);
3256 /* TODO: What kind of information does the other BIT entrys point to?
3257 * 'P' entry is probably performance tables, but there are
3258 * quite a few others...
3262 offset += sizeof(bit_entry_t);
3265 /* C and M tables have to be parsed before init can run */
3266 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3267 "Parsing previously deferred init table entry\n");
3268 parse_init_tables(pScrn, bios);
3270 /* If it's not a laptop, you probably don't care about LVDS */
3271 /* FIXME: detect mobile BIOS? */
3275 /* Need D and L tables parsed before doing this */
3276 parse_fp_mode_table(pScrn, bios, &fpp);
3279 static void parse_bmp_structure(ScrnInfoPtr pScrn, bios_t *bios, unsigned int offset)
3281 /* Parse the BMP structure for useful things
3283 * offset + 5: BMP major version
3284 * offset + 6: BMP minor version
3285 * offset + 10: BCD encoded BIOS version
3287 * offset + 18: init script table pointer (for bios versions < 5.10h)
3288 * offset + 20: extra init script table pointer (for bios versions < 5.10h)
3290 * offset + 24: FIXME
3291 * offset + 26: FIXME
3292 * offset + 28: FIXME
3294 * offset + 54: index of I2C CRTC pair to use for CRT output
3295 * offset + 55: index of I2C CRTC pair to use for TV output
3296 * offset + 56: index of I2C CRTC pair to use for flat panel output
3297 * offset + 58: write CRTC index for I2C pair 0
3298 * offset + 59: read CRTC index for I2C pair 0
3299 * offset + 60: write CRTC index for I2C pair 1
3300 * offset + 61: read CRTC index for I2C pair 1
3302 * offset + 67: maximum internal PLL frequency (single stage PLL)
3303 * offset + 71: minimum internal PLL frequency (single stage PLL)
3305 * offset + 75: script table pointers, as for parse_bit_init_tbl_entry
3307 * offset + 89: TMDS single link output A table pointer
3308 * offset + 91: TMDS single link output B table pointer
3309 * offset + 105: flat panel timings table pointer
3310 * offset + 107: flat panel strapping translation table pointer
3311 * offset + 117: LVDS manufacturer panel config table pointer
3312 * offset + 119: LVDS manufacturer strapping translation table pointer
3314 * offset + 142: PLL limits table pointer
3317 NVPtr pNv = NVPTR(pScrn);
3319 struct fppointers fpp;
3320 memset(&fpp, 0, sizeof(struct fppointers));
3322 uint8_t bmp_version_major = bios->data[offset + 5];
3323 uint8_t bmp_version_minor = bios->data[offset + 6];
3325 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BMP version %d.%d\n",
3326 bmp_version_major, bmp_version_minor);
3328 /* version 6 could theoretically exist, but I suspect BIT happened instead */
3329 if (bmp_version_major < 2 || bmp_version_major > 5) {
3330 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "You have an unsupported BMP version. Please send in your bios\n");
3334 if (bmp_version_major == 2)
3335 bmplength = 48; /* exact for 2.01 - not sure if minor version used in versions < 5 */
3336 else if (bmp_version_major == 3)
3337 bmplength = 54; /* guessed - mem init tables added in this version */
3338 else if (bmp_version_major == 4 || bmp_version_minor < 0x1) /* don't know if 5.0 exists... */
3339 bmplength = 62; /* guessed - BMP I2C indices added in version 4*/
3340 else if (bmp_version_minor < 0x6)
3341 bmplength = 67; /* exact for 5.01 */
3342 else if (bmp_version_minor < 0x10)
3343 bmplength = 75; /* exact for 5.06 */
3344 else if (bmp_version_minor == 0x10)
3345 bmplength = 89; /* exact for 5.10h */
3346 else if (bmp_version_minor < 0x14)
3347 bmplength = 118; /* exact for 5.11h */
3348 else if (bmp_version_minor < 0x24) /* not sure of version where pll limits came in;
3349 * certainly exist by 0x24 though */
3350 /* length not exact: this is long enough to get lvds members */
3353 /* length not exact: this is long enough to get pll limit member */
3357 if (nv_cksum(bios->data + offset, 8)) {
3358 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Bad BMP checksum\n");
3362 parse_bios_version(pScrn, bios, offset + 10);
3364 bios->init_script_tbls_ptr = le16_to_cpu(*(uint16_t *)&bios->data[offset + 18]);
3365 bios->extra_init_script_tbl_ptr = le16_to_cpu(*(uint16_t *)&bios->data[offset + 20]);
3368 // FIXME needed for pre v16? - haiku uses this in its COMPUTE_MEM on early biosen
3369 if (bmp_version_major > 2) {
3370 uint16_t meminittbl = le16_to_cpu(*(uint16_t *)&bios->data[offset + 24]);
3371 uint16_t sdrmemseqtbl = le16_to_cpu(*(uint16_t *)&bios->data[offset + 26]);
3372 uint16_t ddrmemseqtbl = le16_to_cpu(*(uint16_t *)&bios->data[offset + 28]);
3376 uint16_t legacy_i2c_offset = 0x48; /* BMP version 2 & 3 */
3378 legacy_i2c_offset = offset + 54;
3379 bios->legacy_i2c_indices.crt = bios->data[legacy_i2c_offset];
3380 bios->legacy_i2c_indices.tv = bios->data[legacy_i2c_offset + 1];
3381 bios->legacy_i2c_indices.panel = bios->data[legacy_i2c_offset + 2];
3382 pNv->dcb_table.i2c_write[0] = bios->data[legacy_i2c_offset + 4];
3383 pNv->dcb_table.i2c_read[0] = bios->data[legacy_i2c_offset + 5];
3384 pNv->dcb_table.i2c_write[1] = bios->data[legacy_i2c_offset + 6];
3385 pNv->dcb_table.i2c_read[1] = bios->data[legacy_i2c_offset + 7];
3387 if (bmplength > 74) {
3388 bios->fmaxvco = le32_to_cpu(*((uint32_t *)&bios->data[offset + 67]));
3389 bios->fminvco = le32_to_cpu(*((uint32_t *)&bios->data[offset + 71]));
3391 if (bmplength > 88) {
3392 bit_entry_t initbitentry;
3393 initbitentry.length = bmplength - 75;
3394 initbitentry.offset = offset + 75;
3395 parse_bit_init_tbl_entry(pScrn, bios, &initbitentry);
3397 if (bmplength > 92) {
3398 bios->tmds.output0_script_ptr = le16_to_cpu(*((uint16_t *)&bios->data[offset + 89]));
3399 bios->tmds.output1_script_ptr = le16_to_cpu(*((uint16_t *)&bios->data[offset + 91]));
3401 if (bmplength > 108) {
3402 fpp.fptablepointer = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 105])));
3403 fpp.fpxlatetableptr = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 107])));
3406 if (bmplength > 120) {
3407 bios->fp.lvdsmanufacturerpointer = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 117])));
3408 fpp.fpxlatemanufacturertableptr = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 119])));
3410 if (bmplength > 143)
3411 bios->pll_limit_tbl_ptr = le16_to_cpu(*((uint16_t *)(&bios->data[offset + 142])));
3413 /* want pll_limit_tbl_ptr set (if available) before init is run */
3414 if (bmp_version_major < 5 || bmp_version_minor < 0x10) {
3415 init_exec_t iexec = {TRUE, FALSE};
3416 parse_init_table(pScrn, bios, bios->init_script_tbls_ptr, &iexec);
3417 parse_init_table(pScrn, bios, bios->extra_init_script_tbl_ptr, &iexec);
3419 parse_init_tables(pScrn, bios);
3421 /* If it's not a laptop, you probably don't care about fptables */
3422 /* FIXME: detect mobile BIOS? */
3426 parse_fp_mode_table(pScrn, bios, &fpp);
3427 parse_lvds_manufacturer_table_init(pScrn, bios, &fpp);
3428 /* I've never seen a valid LVDS_INIT script, so we'll do a test for it here */
3429 call_lvds_script(pScrn, 0, 0, LVDS_INIT, 0);
3432 static unsigned int findstr(bios_t *bios, unsigned char *str, int len)
3436 for (i = 2; i <= (bios->length - len); i++)
3437 if (strncmp((char *)&bios->data[i], (char *)str, len) == 0)
3443 static Bool parse_dcb_entry(ScrnInfoPtr pScrn, uint8_t dcb_version, uint32_t conn, uint32_t conf, struct dcb_entry *entry)
3445 NVPtr pNv = NVPTR(pScrn);
3447 memset(entry, 0, sizeof (struct dcb_entry));
3449 /* safe defaults for a crt */
3451 entry->i2c_index = 0;
3454 entry->location = 0;
3456 entry->duallink_possible = FALSE;
3458 if (dcb_version >= 0x20) {
3459 entry->type = conn & 0xf;
3460 entry->i2c_index = (conn >> 4) & 0xf;
3461 entry->heads = (conn >> 8) & 0xf;
3462 entry->bus = (conn >> 16) & 0xf;
3463 entry->location = (conn >> 20) & 0xf;
3464 entry->or = (conn >> 24) & 0xf;
3465 if ((1 << ffs(entry->or)) * 3 == entry->or)
3466 entry->duallink_possible = TRUE;
3468 switch (entry->type) {
3470 if (conf & 0xfffffffa)
3471 ErrorF("Unknown LVDS configuration bits, please report\n");
3473 entry->lvdsconf.use_straps_for_mode = TRUE;
3475 entry->lvdsconf.use_power_scripts = TRUE;
3478 } else if (dcb_version >= 0x14 ) {
3479 if (conn != 0xf0003f00) {
3480 ErrorF("Unknown DCB 1.4 entry, please report\n");
3481 /* cause output setting to fail, so message is seen */
3482 pNv->dcb_table.entries = 0;
3485 /* use the safe defaults for a crt */
3486 entry->type = conn & 0xf;
3487 } else if (dcb_version >= 0x12) {
3488 /* use the defaults for a crt
3489 * v1.2 tables often have other entries though - need a trace
3491 entry->type = conn & 0xf; // this is valid, but will probably confuse the randr stuff
3493 } else { /* pre DCB / v1.1 - use the safe defaults for a crt */
3494 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3495 "No information in BIOS output table; assuming a CRT output exists\n");
3496 entry->i2c_index = pNv->VBIOS.legacy_i2c_indices.crt;
3499 pNv->dcb_table.entries++;
3505 read_dcb_i2c_table(ScrnInfoPtr pScrn, bios_t *bios, uint8_t dcb_version, uint16_t i2ctabptr)
3507 NVPtr pNv = NVPTR(pScrn);
3509 uint8_t headerlen = 0;
3511 int recordoffset = 0, rdofs = 1, wrofs = 0;
3514 i2c_entries = MAX_NUM_DCB_ENTRIES;
3515 memset(pNv->dcb_table.i2c_read, 0, sizeof(pNv->dcb_table.i2c_read));
3516 memset(pNv->dcb_table.i2c_write, 0, sizeof(pNv->dcb_table.i2c_write));
3518 i2ctable = &bios->data[i2ctabptr];
3520 if (dcb_version >= 0x30) {
3521 if (i2ctable[0] != dcb_version) { /* necessary? */
3522 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3523 "DCB I2C table version mismatch (%02X vs %02X)\n",
3524 i2ctable[0], dcb_version);
3527 headerlen = i2ctable[1];
3528 i2c_entries = i2ctable[2];
3529 if (i2ctable[0] >= 0x40) {
3530 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3531 "G80 DCB I2C table detected, arrgh\n"); /* they're plain weird */
3535 /* it's your own fault if you call this function on a DCB 1.1 BIOS --
3536 * the below assumes DCB 1.2
3538 if (dcb_version < 0x14) {
3544 for (i = 0; i < i2c_entries; i++)
3545 if (i2ctable[headerlen + 4 * i + 3] != 0xff) {
3546 pNv->dcb_table.i2c_read[i] = i2ctable[headerlen + recordoffset + rdofs + 4 * i];
3547 pNv->dcb_table.i2c_write[i] = i2ctable[headerlen + recordoffset + wrofs + 4 * i];
3551 static unsigned int parse_dcb_table(ScrnInfoPtr pScrn, bios_t *bios)
3553 NVPtr pNv = NVPTR(pScrn);
3554 uint16_t dcbptr, i2ctabptr = 0;
3556 uint8_t dcb_version, headerlen = 0x4, entries = MAX_NUM_DCB_ENTRIES;
3557 Bool configblock = TRUE;
3558 int recordlength = 8, confofs = 4;
3561 pNv->dcb_table.entries = 0;
3563 /* get the offset from 0x36 */
3564 dcbptr = le16_to_cpu(*(uint16_t *)&bios->data[0x36]);
3566 if (dcbptr == 0x0) {
3567 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3568 "No Display Configuration Block pointer found\n");
3569 /* this situation likely means a really old card, pre DCB, so we'll add the safe CRT entry */
3570 parse_dcb_entry(pScrn, 0, 0, 0, &pNv->dcb_table.entry[0]);
3574 dcbtable = &bios->data[dcbptr];
3576 /* get DCB version */
3577 dcb_version = dcbtable[0];
3578 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3579 "Display Configuration Block version %d.%d found\n",
3580 dcb_version >> 4, dcb_version & 0xf);
3582 if (dcb_version >= 0x20) { /* NV17+ */
3585 if (dcb_version >= 0x30) { /* NV40+ */
3586 headerlen = dcbtable[1];
3587 entries = dcbtable[2];
3588 i2ctabptr = le16_to_cpu(*(uint16_t *)&dcbtable[4]);
3589 sig = le32_to_cpu(*(uint32_t *)&dcbtable[6]);
3591 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3592 "DCB header length %02X, with %02X possible entries\n",
3593 headerlen, entries);
3595 /* dcb_block_count = *(dcbtable[1]); */
3596 i2ctabptr = le16_to_cpu(*(uint16_t *)&dcbtable[2]);
3597 sig = le32_to_cpu(*(uint32_t *)&dcbtable[4]);
3601 if (sig != 0x4edcbdcb) {
3602 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3603 "Bad Display Configuration Block signature (%08X)\n", sig);
3606 } else if (dcb_version >= 0x14) { /* some NV15/16, and NV11+ */
3610 strncpy(sig, (char *)&dcbtable[-7], 7);
3611 /* dcb_block_count = *(dcbtable[1]); */
3612 i2ctabptr = le16_to_cpu(*(uint16_t *)&dcbtable[2]);
3616 if (strcmp(sig, "DEV_REC")) {
3617 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3618 "Bad Display Configuration Block signature (%s)\n", sig);
3621 } else if (dcb_version >= 0x12) { /* some NV6/10, and NV15+ */
3622 /* dcb_block_count = *(dcbtable[1]); */
3623 i2ctabptr = le16_to_cpu(*(uint16_t *)&dcbtable[2]);
3624 configblock = FALSE;
3625 } else { /* NV5+, maybe NV4 */
3626 /* DCB 1.1 seems to be quite unhelpful - we'll just add the safe CRT entry */
3627 parse_dcb_entry(pScrn, dcb_version, 0, 0, &pNv->dcb_table.entry[0]);
3631 if (entries >= MAX_NUM_DCB_ENTRIES)
3632 entries = MAX_NUM_DCB_ENTRIES;
3634 for (i = 0; i < entries; i++) {
3635 uint32_t connection, config = 0;
3637 connection = le32_to_cpu(*(uint32_t *)&dcbtable[headerlen + recordlength * i]);
3639 config = le32_to_cpu(*(uint32_t *)&dcbtable[headerlen + confofs + recordlength * i]);
3641 /* Should we allow discontinuous DCBs? Certainly DCB I2C tables
3642 * can be discontinuous */
3643 if ((connection & 0x0000000f) == 0x0000000f) /* end of records */
3646 ErrorF("Raw DCB entry %d: %08x %08x\n", i, connection, config);
3647 if (!parse_dcb_entry(pScrn, dcb_version, connection, config, &pNv->dcb_table.entry[i]))
3651 read_dcb_i2c_table(pScrn, bios, dcb_version, i2ctabptr);
3653 /* This is needed for DCB version 2.0 */
3654 /* Otherwise you end up with multiple outputs that are trying to be activated */
3655 for ( i = 0; i < pNv->dcb_table.entries; i ++) {
3657 int cur_i2c = pNv->dcb_table.entry[i].i2c_index;
3658 int cur_type = pNv->dcb_table.entry[i].type;
3659 for ( j = 0; j < pNv->dcb_table.entries; j ++ ) {
3660 if ( i == j ) continue;
3661 if ( pNv->dcb_table.entry[j].type == 100) continue; /* merged entry */
3662 if (( pNv->dcb_table.entry[j].i2c_index == cur_i2c ) && ( pNv->dcb_table.entry[j].type == cur_type )) {
3663 /* We can only merge entries with the same allowed crtc's. */
3664 /* This has not occured so far and needs some logic (to merge dual link properly). */
3665 /* So this remains TODO for the moment. */
3667 /* We also merge entries with the same allowed output routes */
3668 if (pNv->dcb_table.entry[i].or == pNv->dcb_table.entry[j].or) {
3669 xf86DrvMsg(0, X_INFO, "Merging DCB entries %d and %d!\n", i, j);
3670 pNv->dcb_table.entry[i].heads |= pNv->dcb_table.entry[j].heads;
3672 pNv->dcb_table.entry[j].type = 100; /* dummy value */
3678 /* Remove "disabled" entries (merged) */
3679 int valid_entries[pNv->dcb_table.entries];
3681 for ( i = 0; i < pNv->dcb_table.entries; i ++) valid_entries[i] = -1;
3682 for ( i = 0; i < pNv->dcb_table.entries; i ++)
3683 if ( pNv->dcb_table.entry[i].type != 100 ) {
3684 valid_entries[cent] = i;
3687 for ( i = 0; i < cent; i++) {
3688 memmove(&pNv->dcb_table.entry[i], &pNv->dcb_table.entry[valid_entries[i]], sizeof(pNv->dcb_table.entry[i]));
3689 memmove(&pNv->dcb_table.i2c_read[i], &pNv->dcb_table.i2c_read[valid_entries[i]], sizeof(pNv->dcb_table.i2c_read[i]));
3690 memmove(&pNv->dcb_table.i2c_write[i], &pNv->dcb_table.i2c_write[valid_entries[i]], sizeof(pNv->dcb_table.i2c_write[i]));
3693 pNv->dcb_table.entries = cent;
3695 return pNv->dcb_table.entries;
3698 unsigned int NVParseBios(ScrnInfoPtr pScrn)
3700 unsigned int bit_offset;
3701 uint8_t nv_signature[]={0xff,0x7f,'N','V',0x0};
3702 uint8_t bit_signature[]={'B','I','T'};
3706 pNv->dcb_table.entries = 0;
3708 memset(&pNv->VBIOS, 0, sizeof(bios_t));
3709 pNv->VBIOS.execute = FALSE;
3710 pNv->VBIOS.data = xalloc(64 * 1024);
3711 if (!NVShadowVBIOS(pScrn, pNv->VBIOS.data)) {
3712 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
3713 "No valid BIOS image found\n");
3714 xfree(pNv->VBIOS.data);
3717 pNv->VBIOS.length = pNv->VBIOS.data[2] * 512;
3718 if (pNv->VBIOS.length > NV_PROM_SIZE)
3719 pNv->VBIOS.length = NV_PROM_SIZE;
3721 /* check for known signatures */
3722 if ((bit_offset = findstr(&pNv->VBIOS, bit_signature, sizeof(bit_signature)))) {
3723 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BIT signature found\n");
3724 parse_bit_structure(pScrn, &pNv->VBIOS, bit_offset + 4);
3725 } else if ((bit_offset = findstr(&pNv->VBIOS, nv_signature, sizeof(nv_signature)))) {
3726 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NV signature found\n");
3727 parse_bmp_structure(pScrn, &pNv->VBIOS, bit_offset);
3729 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3730 "No known script signature found\n");
3732 /* parse Display Configuration Block (DCB) table */
3733 if (parse_dcb_table(pScrn, &pNv->VBIOS))
3734 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
3735 "Found %d entries in DCB\n", pNv->dcb_table.entries);