2 * Copyright 2005-2006 Erik Waling
3 * Copyright 2006 Stephane Marchesin
4 * Copyright 2007-2009 Stuart Bennett
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #define NV_DEBUG_NOTRACE
27 #include "nouveau_drv.h"
28 #include "nouveau_hw.h"
29 #include "nouveau_encoder.h"
31 /* these defines are made up */
32 #define NV_CIO_CRE_44_HEADA 0x0
33 #define NV_CIO_CRE_44_HEADB 0x3
34 #define FEATURE_MOBILE 0x10 /* also FEATURE_QUADRO for BMP */
35 #define LEGACY_I2C_CRT 0x80
36 #define LEGACY_I2C_PANEL 0x81
37 #define LEGACY_I2C_TV 0x82
41 #define BIOSLOG(sip, fmt, arg...) NV_DEBUG(sip->dev, fmt, ##arg)
42 #define LOG_OLD_VALUE(x)
44 #define ROM16(x) le16_to_cpu(*(uint16_t *)&(x))
45 #define ROM32(x) le32_to_cpu(*(uint32_t *)&(x))
52 static bool nv_cksum(const uint8_t *data, unsigned int length)
55 * There's a few checksums in the BIOS, so here's a generic checking
61 for (i = 0; i < length; i++)
71 score_vbios(struct drm_device *dev, const uint8_t *data, const bool writeable)
73 if (!(data[0] == 0x55 && data[1] == 0xAA)) {
74 NV_TRACEWARN(dev, "... BIOS signature not found\n");
78 if (nv_cksum(data, data[2] * 512)) {
79 NV_TRACEWARN(dev, "... BIOS checksum invalid\n");
80 /* if a ro image is somewhat bad, it's probably all rubbish */
81 return writeable ? 2 : 1;
83 NV_TRACE(dev, "... appears to be valid\n");
88 static void load_vbios_prom(struct drm_device *dev, uint8_t *data)
90 struct drm_nouveau_private *dev_priv = dev->dev_private;
91 uint32_t pci_nv_20, save_pci_nv_20;
95 if (dev_priv->card_type >= NV_50)
98 pci_nv_20 = NV_PBUS_PCI_NV_20;
100 /* enable ROM access */
101 save_pci_nv_20 = nvReadMC(dev, pci_nv_20);
102 nvWriteMC(dev, pci_nv_20,
103 save_pci_nv_20 & ~NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED);
105 /* bail if no rom signature */
106 if (nv_rd08(dev, NV_PROM_OFFSET) != 0x55 ||
107 nv_rd08(dev, NV_PROM_OFFSET + 1) != 0xaa)
110 /* additional check (see note below) - read PCI record header */
111 pcir_ptr = nv_rd08(dev, NV_PROM_OFFSET + 0x18) |
112 nv_rd08(dev, NV_PROM_OFFSET + 0x19) << 8;
113 if (nv_rd08(dev, NV_PROM_OFFSET + pcir_ptr) != 'P' ||
114 nv_rd08(dev, NV_PROM_OFFSET + pcir_ptr + 1) != 'C' ||
115 nv_rd08(dev, NV_PROM_OFFSET + pcir_ptr + 2) != 'I' ||
116 nv_rd08(dev, NV_PROM_OFFSET + pcir_ptr + 3) != 'R')
119 /* on some 6600GT/6800LE prom reads are messed up. nvclock alleges a
120 * a good read may be obtained by waiting or re-reading (cargocult: 5x)
121 * each byte. we'll hope pramin has something usable instead
123 for (i = 0; i < NV_PROM_SIZE; i++)
124 data[i] = nv_rd08(dev, NV_PROM_OFFSET + i);
127 /* disable ROM access */
128 nvWriteMC(dev, pci_nv_20,
129 save_pci_nv_20 | NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED);
132 static void load_vbios_pramin(struct drm_device *dev, uint8_t *data)
134 struct drm_nouveau_private *dev_priv = dev->dev_private;
135 uint32_t old_bar0_pramin = 0;
138 if (dev_priv->card_type >= NV_50) {
139 uint32_t vbios_vram = (nv_rd32(dev, 0x619f04) & ~0xff) << 8;
142 vbios_vram = (nv_rd32(dev, 0x1700) << 16) + 0xf0000;
144 old_bar0_pramin = nv_rd32(dev, 0x1700);
145 nv_wr32(dev, 0x1700, vbios_vram >> 16);
148 /* bail if no rom signature */
149 if (nv_rd08(dev, NV_PRAMIN_OFFSET) != 0x55 ||
150 nv_rd08(dev, NV_PRAMIN_OFFSET + 1) != 0xaa)
153 for (i = 0; i < NV_PROM_SIZE; i++)
154 data[i] = nv_rd08(dev, NV_PRAMIN_OFFSET + i);
157 if (dev_priv->card_type >= NV_50)
158 nv_wr32(dev, 0x1700, old_bar0_pramin);
161 static void load_vbios_pci(struct drm_device *dev, uint8_t *data)
163 void __iomem *rom = NULL;
167 ret = pci_enable_rom(dev->pdev);
171 rom = pci_map_rom(dev->pdev, &rom_len);
174 memcpy_fromio(data, rom, rom_len);
175 pci_unmap_rom(dev->pdev, rom);
178 pci_disable_rom(dev->pdev);
181 static void load_vbios_acpi(struct drm_device *dev, uint8_t *data)
185 int size = 64 * 1024;
187 if (!nouveau_acpi_rom_supported(dev->pdev))
190 for (i = 0; i < (size / ROM_BIOS_PAGE); i++) {
191 ret = nouveau_acpi_get_bios_chunk(data,
202 void (*loadbios)(struct drm_device *, uint8_t *);
206 static struct methods shadow_methods[] = {
207 { "PRAMIN", load_vbios_pramin, true },
208 { "PROM", load_vbios_prom, false },
209 { "PCIROM", load_vbios_pci, true },
210 { "ACPI", load_vbios_acpi, true },
213 static bool NVShadowVBIOS(struct drm_device *dev, uint8_t *data)
215 const int nr_methods = ARRAY_SIZE(shadow_methods);
216 struct methods *methods = shadow_methods;
218 int scores[nr_methods], i;
221 for (i = 0; i < nr_methods; i++)
222 if (!strcasecmp(nouveau_vbios, methods[i].desc))
225 if (i < nr_methods) {
226 NV_INFO(dev, "Attempting to use BIOS image from %s\n",
229 methods[i].loadbios(dev, data);
230 if (score_vbios(dev, data, methods[i].rw))
234 NV_ERROR(dev, "VBIOS source \'%s\' invalid\n", nouveau_vbios);
237 for (i = 0; i < nr_methods; i++) {
238 NV_TRACE(dev, "Attempting to load BIOS image from %s\n",
240 data[0] = data[1] = 0; /* avoid reuse of previous image */
241 methods[i].loadbios(dev, data);
242 scores[i] = score_vbios(dev, data, methods[i].rw);
243 if (scores[i] == testscore)
247 while (--testscore > 0) {
248 for (i = 0; i < nr_methods; i++) {
249 if (scores[i] == testscore) {
250 NV_TRACE(dev, "Using BIOS image from %s\n",
252 methods[i].loadbios(dev, data);
258 NV_ERROR(dev, "No valid BIOS image found\n");
262 struct init_tbl_entry {
266 * > 0: success, length of opcode
267 * 0: success, but abort further parsing of table (INIT_DONE etc)
268 * < 0: failure, table parsing will be aborted
270 int (*handler)(struct nvbios *, uint16_t, struct init_exec *);
279 static int parse_init_table(struct nvbios *, unsigned int, struct init_exec *);
281 #define MACRO_INDEX_SIZE 2
283 #define CONDITION_SIZE 12
284 #define IO_FLAG_CONDITION_SIZE 9
285 #define IO_CONDITION_SIZE 5
286 #define MEM_INIT_SIZE 66
288 static void still_alive(void)
297 munge_reg(struct nvbios *bios, uint32_t reg)
299 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
300 struct dcb_entry *dcbent = bios->display.output;
302 if (dev_priv->card_type < NV_50)
305 if (reg & 0x40000000) {
308 reg += (ffs(dcbent->or) - 1) * 0x800;
309 if ((reg & 0x20000000) && !(dcbent->sorconf.link & 1))
318 valid_reg(struct nvbios *bios, uint32_t reg)
320 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
321 struct drm_device *dev = bios->dev;
323 /* C51 has misaligned regs on purpose. Marvellous */
325 (reg & 0x1 && dev_priv->vbios.chip_version != 0x51))
326 NV_ERROR(dev, "======= misaligned reg 0x%08X =======\n", reg);
328 /* warn on C51 regs that haven't been verified accessible in tracing */
329 if (reg & 0x1 && dev_priv->vbios.chip_version == 0x51 &&
330 reg != 0x130d && reg != 0x1311 && reg != 0x60081d)
331 NV_WARN(dev, "=== C51 misaligned reg 0x%08X not verified ===\n",
334 if (reg >= (8*1024*1024)) {
335 NV_ERROR(dev, "=== reg 0x%08x out of mapped bounds ===\n", reg);
343 valid_idx_port(struct nvbios *bios, uint16_t port)
345 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
346 struct drm_device *dev = bios->dev;
349 * If adding more ports here, the read/write functions below will need
350 * updating so that the correct mmio range (PRMCIO, PRMDIO, PRMVIO) is
351 * used for the port in question
353 if (dev_priv->card_type < NV_50) {
354 if (port == NV_CIO_CRX__COLOR)
356 if (port == NV_VIO_SRX)
359 if (port == NV_CIO_CRX__COLOR)
363 NV_ERROR(dev, "========== unknown indexed io port 0x%04X ==========\n",
370 valid_port(struct nvbios *bios, uint16_t port)
372 struct drm_device *dev = bios->dev;
375 * If adding more ports here, the read/write functions below will need
376 * updating so that the correct mmio range (PRMCIO, PRMDIO, PRMVIO) is
377 * used for the port in question
379 if (port == NV_VIO_VSE2)
382 NV_ERROR(dev, "========== unknown io port 0x%04X ==========\n", port);
388 bios_rd32(struct nvbios *bios, uint32_t reg)
392 reg = munge_reg(bios, reg);
393 if (!valid_reg(bios, reg))
397 * C51 sometimes uses regs with bit0 set in the address. For these
398 * cases there should exist a translation in a BIOS table to an IO
399 * port address which the BIOS uses for accessing the reg
401 * These only seem to appear for the power control regs to a flat panel,
402 * and the GPIO regs at 0x60081*. In C51 mmio traces the normal regs
403 * for 0x1308 and 0x1310 are used - hence the mask below. An S3
404 * suspend-resume mmio trace from a C51 will be required to see if this
405 * is true for the power microcode in 0x14.., or whether the direct IO
406 * port access method is needed
411 data = nv_rd32(bios->dev, reg);
413 BIOSLOG(bios, " Read: Reg: 0x%08X, Data: 0x%08X\n", reg, data);
419 bios_wr32(struct nvbios *bios, uint32_t reg, uint32_t data)
421 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
423 reg = munge_reg(bios, reg);
424 if (!valid_reg(bios, reg))
427 /* see note in bios_rd32 */
431 LOG_OLD_VALUE(bios_rd32(bios, reg));
432 BIOSLOG(bios, " Write: Reg: 0x%08X, Data: 0x%08X\n", reg, data);
434 if (dev_priv->vbios.execute) {
436 nv_wr32(bios->dev, reg, data);
441 bios_idxprt_rd(struct nvbios *bios, uint16_t port, uint8_t index)
443 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
444 struct drm_device *dev = bios->dev;
447 if (!valid_idx_port(bios, port))
450 if (dev_priv->card_type < NV_50) {
451 if (port == NV_VIO_SRX)
452 data = NVReadVgaSeq(dev, bios->state.crtchead, index);
453 else /* assume NV_CIO_CRX__COLOR */
454 data = NVReadVgaCrtc(dev, bios->state.crtchead, index);
458 data32 = bios_rd32(bios, NV50_PDISPLAY_VGACRTC(index & ~3));
459 data = (data32 >> ((index & 3) << 3)) & 0xff;
462 BIOSLOG(bios, " Indexed IO read: Port: 0x%04X, Index: 0x%02X, "
463 "Head: 0x%02X, Data: 0x%02X\n",
464 port, index, bios->state.crtchead, data);
469 bios_idxprt_wr(struct nvbios *bios, uint16_t port, uint8_t index, uint8_t data)
471 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
472 struct drm_device *dev = bios->dev;
474 if (!valid_idx_port(bios, port))
478 * The current head is maintained in the nvbios member state.crtchead.
479 * We trap changes to CR44 and update the head variable and hence the
480 * register set written.
481 * As CR44 only exists on CRTC0, we update crtchead to head0 in advance
482 * of the write, and to head1 after the write
484 if (port == NV_CIO_CRX__COLOR && index == NV_CIO_CRE_44 &&
485 data != NV_CIO_CRE_44_HEADB)
486 bios->state.crtchead = 0;
488 LOG_OLD_VALUE(bios_idxprt_rd(bios, port, index));
489 BIOSLOG(bios, " Indexed IO write: Port: 0x%04X, Index: 0x%02X, "
490 "Head: 0x%02X, Data: 0x%02X\n",
491 port, index, bios->state.crtchead, data);
493 if (bios->execute && dev_priv->card_type < NV_50) {
495 if (port == NV_VIO_SRX)
496 NVWriteVgaSeq(dev, bios->state.crtchead, index, data);
497 else /* assume NV_CIO_CRX__COLOR */
498 NVWriteVgaCrtc(dev, bios->state.crtchead, index, data);
501 uint32_t data32, shift = (index & 3) << 3;
505 data32 = bios_rd32(bios, NV50_PDISPLAY_VGACRTC(index & ~3));
506 data32 &= ~(0xff << shift);
507 data32 |= (data << shift);
508 bios_wr32(bios, NV50_PDISPLAY_VGACRTC(index & ~3), data32);
511 if (port == NV_CIO_CRX__COLOR &&
512 index == NV_CIO_CRE_44 && data == NV_CIO_CRE_44_HEADB)
513 bios->state.crtchead = 1;
517 bios_port_rd(struct nvbios *bios, uint16_t port)
519 uint8_t data, head = bios->state.crtchead;
521 if (!valid_port(bios, port))
524 data = NVReadPRMVIO(bios->dev, head, NV_PRMVIO0_OFFSET + port);
526 BIOSLOG(bios, " IO read: Port: 0x%04X, Head: 0x%02X, Data: 0x%02X\n",
533 bios_port_wr(struct nvbios *bios, uint16_t port, uint8_t data)
535 int head = bios->state.crtchead;
537 if (!valid_port(bios, port))
540 LOG_OLD_VALUE(bios_port_rd(bios, port));
541 BIOSLOG(bios, " IO write: Port: 0x%04X, Head: 0x%02X, Data: 0x%02X\n",
548 NVWritePRMVIO(bios->dev, head, NV_PRMVIO0_OFFSET + port, data);
552 io_flag_condition_met(struct nvbios *bios, uint16_t offset, uint8_t cond)
555 * The IO flag condition entry has 2 bytes for the CRTC port; 1 byte
556 * for the CRTC index; 1 byte for the mask to apply to the value
557 * retrieved from the CRTC; 1 byte for the shift right to apply to the
558 * masked CRTC value; 2 bytes for the offset to the flag array, to
559 * which the shifted value is added; 1 byte for the mask applied to the
560 * value read from the flag array; and 1 byte for the value to compare
561 * against the masked byte from the flag table.
564 uint16_t condptr = bios->io_flag_condition_tbl_ptr + cond * IO_FLAG_CONDITION_SIZE;
565 uint16_t crtcport = ROM16(bios->data[condptr]);
566 uint8_t crtcindex = bios->data[condptr + 2];
567 uint8_t mask = bios->data[condptr + 3];
568 uint8_t shift = bios->data[condptr + 4];
569 uint16_t flagarray = ROM16(bios->data[condptr + 5]);
570 uint8_t flagarraymask = bios->data[condptr + 7];
571 uint8_t cmpval = bios->data[condptr + 8];
574 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
575 "Shift: 0x%02X, FlagArray: 0x%04X, FAMask: 0x%02X, "
577 offset, crtcport, crtcindex, mask, shift, flagarray, flagarraymask, cmpval);
579 data = bios_idxprt_rd(bios, crtcport, crtcindex);
581 data = bios->data[flagarray + ((data & mask) >> shift)];
582 data &= flagarraymask;
584 BIOSLOG(bios, "0x%04X: Checking if 0x%02X equals 0x%02X\n",
585 offset, data, cmpval);
587 return (data == cmpval);
591 bios_condition_met(struct nvbios *bios, uint16_t offset, uint8_t cond)
594 * The condition table entry has 4 bytes for the address of the
595 * register to check, 4 bytes for a mask to apply to the register and
596 * 4 for a test comparison value
599 uint16_t condptr = bios->condition_tbl_ptr + cond * CONDITION_SIZE;
600 uint32_t reg = ROM32(bios->data[condptr]);
601 uint32_t mask = ROM32(bios->data[condptr + 4]);
602 uint32_t cmpval = ROM32(bios->data[condptr + 8]);
605 BIOSLOG(bios, "0x%04X: Cond: 0x%02X, Reg: 0x%08X, Mask: 0x%08X\n",
606 offset, cond, reg, mask);
608 data = bios_rd32(bios, reg) & mask;
610 BIOSLOG(bios, "0x%04X: Checking if 0x%08X equals 0x%08X\n",
611 offset, data, cmpval);
613 return (data == cmpval);
617 io_condition_met(struct nvbios *bios, uint16_t offset, uint8_t cond)
620 * The IO condition entry has 2 bytes for the IO port address; 1 byte
621 * for the index to write to io_port; 1 byte for the mask to apply to
622 * the byte read from io_port+1; and 1 byte for the value to compare
623 * against the masked byte.
626 uint16_t condptr = bios->io_condition_tbl_ptr + cond * IO_CONDITION_SIZE;
627 uint16_t io_port = ROM16(bios->data[condptr]);
628 uint8_t port_index = bios->data[condptr + 2];
629 uint8_t mask = bios->data[condptr + 3];
630 uint8_t cmpval = bios->data[condptr + 4];
632 uint8_t data = bios_idxprt_rd(bios, io_port, port_index) & mask;
634 BIOSLOG(bios, "0x%04X: Checking if 0x%02X equals 0x%02X\n",
635 offset, data, cmpval);
637 return (data == cmpval);
641 nv50_pll_set(struct drm_device *dev, uint32_t reg, uint32_t clk)
643 struct drm_nouveau_private *dev_priv = dev->dev_private;
644 uint32_t reg0 = nv_rd32(dev, reg + 0);
645 uint32_t reg1 = nv_rd32(dev, reg + 4);
646 struct nouveau_pll_vals pll;
647 struct pll_lims pll_limits;
650 ret = get_pll_limits(dev, reg, &pll_limits);
654 clk = nouveau_calc_pll_mnp(dev, &pll_limits, clk, &pll);
658 reg0 = (reg0 & 0xfff8ffff) | (pll.log2P << 16);
659 reg1 = (reg1 & 0xffff0000) | (pll.N1 << 8) | pll.M1;
661 if (dev_priv->vbios.execute) {
663 nv_wr32(dev, reg + 4, reg1);
664 nv_wr32(dev, reg + 0, reg0);
671 setPLL(struct nvbios *bios, uint32_t reg, uint32_t clk)
673 struct drm_device *dev = bios->dev;
674 struct drm_nouveau_private *dev_priv = dev->dev_private;
676 struct pll_lims pll_lim;
677 struct nouveau_pll_vals pllvals;
680 if (dev_priv->card_type >= NV_50)
681 return nv50_pll_set(dev, reg, clk);
683 /* high regs (such as in the mac g5 table) are not -= 4 */
684 ret = get_pll_limits(dev, reg > 0x405c ? reg : reg - 4, &pll_lim);
688 clk = nouveau_calc_pll_mnp(dev, &pll_lim, clk, &pllvals);
694 nouveau_hw_setpll(dev, reg, &pllvals);
700 static int dcb_entry_idx_from_crtchead(struct drm_device *dev)
702 struct drm_nouveau_private *dev_priv = dev->dev_private;
703 struct nvbios *bios = &dev_priv->vbios;
706 * For the results of this function to be correct, CR44 must have been
707 * set (using bios_idxprt_wr to set crtchead), CR58 set for CR57 = 0,
708 * and the DCB table parsed, before the script calling the function is
709 * run. run_digital_op_script is example of how to do such setup
712 uint8_t dcb_entry = NVReadVgaCrtc5758(dev, bios->state.crtchead, 0);
714 if (dcb_entry > bios->dcb.entries) {
715 NV_ERROR(dev, "CR58 doesn't have a valid DCB entry currently "
716 "(%02X)\n", dcb_entry);
717 dcb_entry = 0x7f; /* unused / invalid marker */
724 read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c)
726 uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4;
727 int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES;
728 int recordoffset = 0, rdofs = 1, wrofs = 0;
729 uint8_t port_type = 0;
734 if (dcb_version >= 0x30) {
735 if (i2ctable[0] != dcb_version) /* necessary? */
737 "DCB I2C table version mismatch (%02X vs %02X)\n",
738 i2ctable[0], dcb_version);
739 dcb_i2c_ver = i2ctable[0];
740 headerlen = i2ctable[1];
741 if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES)
742 i2c_entries = i2ctable[2];
745 "DCB I2C table has more entries than indexable "
746 "(%d entries, max %d)\n", i2ctable[2],
747 DCB_MAX_NUM_I2C_ENTRIES);
748 entry_len = i2ctable[3];
749 /* [4] is i2c_default_indices, read in parse_dcb_table() */
752 * It's your own fault if you call this function on a DCB 1.1 BIOS --
753 * the test below is for DCB 1.2
755 if (dcb_version < 0x14) {
763 if (index >= i2c_entries) {
764 NV_ERROR(dev, "DCB I2C index too big (%d >= %d)\n",
768 if (i2ctable[headerlen + entry_len * index + 3] == 0xff) {
769 NV_ERROR(dev, "DCB I2C entry invalid\n");
773 if (dcb_i2c_ver >= 0x30) {
774 port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index];
777 * Fixup for chips using same address offset for read and
780 if (port_type == 4) /* seen on C51 */
782 if (port_type >= 5) /* G80+ */
786 if (dcb_i2c_ver >= 0x40) {
787 if (port_type != 5 && port_type != 6)
788 NV_WARN(dev, "DCB I2C table has port type %d\n", port_type);
790 i2c->entry = ROM32(i2ctable[headerlen + recordoffset + entry_len * index]);
793 i2c->port_type = port_type;
794 i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index];
795 i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index];
800 static struct nouveau_i2c_chan *
801 init_i2c_device_find(struct drm_device *dev, int i2c_index)
803 struct drm_nouveau_private *dev_priv = dev->dev_private;
804 struct dcb_table *dcb = &dev_priv->vbios.dcb;
806 if (i2c_index == 0xff) {
807 /* note: dcb_entry_idx_from_crtchead needs pre-script set-up */
808 int idx = dcb_entry_idx_from_crtchead(dev), shift = 0;
809 int default_indices = dcb->i2c_default_indices;
811 if (idx != 0x7f && dcb->entry[idx].i2c_upper_default)
814 i2c_index = (default_indices >> shift) & 0xf;
816 if (i2c_index == 0x80) /* g80+ */
817 i2c_index = dcb->i2c_default_indices & 0xf;
819 if (i2c_index == 0x81)
820 i2c_index = (dcb->i2c_default_indices & 0xf0) >> 4;
822 if (i2c_index >= DCB_MAX_NUM_I2C_ENTRIES) {
823 NV_ERROR(dev, "invalid i2c_index 0x%x\n", i2c_index);
827 /* Make sure i2c table entry has been parsed, it may not
828 * have been if this is a bus not referenced by a DCB encoder
830 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
831 i2c_index, &dcb->i2c[i2c_index]);
833 return nouveau_i2c_find(dev, i2c_index);
837 get_tmds_index_reg(struct drm_device *dev, uint8_t mlv)
840 * For mlv < 0x80, it is an index into a table of TMDS base addresses.
841 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by
842 * CR58 for CR57 = 0 to index a table of offsets to the basic
844 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by
845 * CR58 for CR57 = 0 to index a table of offsets to the basic
846 * 0x6808b0 address, and then flip the offset by 8.
849 struct drm_nouveau_private *dev_priv = dev->dev_private;
850 struct nvbios *bios = &dev_priv->vbios;
851 const int pramdac_offset[13] = {
852 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 };
853 const uint32_t pramdac_table[4] = {
854 0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8 };
857 int dcb_entry, dacoffset;
859 /* note: dcb_entry_idx_from_crtchead needs pre-script set-up */
860 dcb_entry = dcb_entry_idx_from_crtchead(dev);
861 if (dcb_entry == 0x7f)
863 dacoffset = pramdac_offset[bios->dcb.entry[dcb_entry].or];
866 return 0x6808b0 + dacoffset;
868 if (mlv >= ARRAY_SIZE(pramdac_table)) {
869 NV_ERROR(dev, "Magic Lookup Value too big (%02X)\n",
873 return pramdac_table[mlv];
878 init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
879 struct init_exec *iexec)
882 * INIT_IO_RESTRICT_PROG opcode: 0x32 ('2')
884 * offset (8 bit): opcode
885 * offset + 1 (16 bit): CRTC port
886 * offset + 3 (8 bit): CRTC index
887 * offset + 4 (8 bit): mask
888 * offset + 5 (8 bit): shift
889 * offset + 6 (8 bit): count
890 * offset + 7 (32 bit): register
891 * offset + 11 (32 bit): configuration 1
894 * Starting at offset + 11 there are "count" 32 bit values.
895 * To find out which value to use read index "CRTC index" on "CRTC
896 * port", AND this value with "mask" and then bit shift right "shift"
897 * bits. Read the appropriate value using this index and write to
901 uint16_t crtcport = ROM16(bios->data[offset + 1]);
902 uint8_t crtcindex = bios->data[offset + 3];
903 uint8_t mask = bios->data[offset + 4];
904 uint8_t shift = bios->data[offset + 5];
905 uint8_t count = bios->data[offset + 6];
906 uint32_t reg = ROM32(bios->data[offset + 7]);
909 int len = 11 + count * 4;
914 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
915 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
916 offset, crtcport, crtcindex, mask, shift, count, reg);
918 config = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) >> shift;
919 if (config > count) {
921 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
922 offset, config, count);
926 configval = ROM32(bios->data[offset + 11 + config * 4]);
928 BIOSLOG(bios, "0x%04X: Writing config %02X\n", offset, config);
930 bios_wr32(bios, reg, configval);
936 init_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
939 * INIT_REPEAT opcode: 0x33 ('3')
941 * offset (8 bit): opcode
942 * offset + 1 (8 bit): count
944 * Execute script following this opcode up to INIT_REPEAT_END
948 uint8_t count = bios->data[offset + 1];
951 /* no iexec->execute check by design */
953 BIOSLOG(bios, "0x%04X: Repeating following segment %d times\n",
956 iexec->repeat = true;
959 * count - 1, as the script block will execute once when we leave this
960 * opcode -- this is compatible with bios behaviour as:
961 * a) the block is always executed at least once, even if count == 0
962 * b) the bios interpreter skips to the op following INIT_END_REPEAT,
965 for (i = 0; i < count - 1; i++)
966 parse_init_table(bios, offset + 2, iexec);
968 iexec->repeat = false;
974 init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
975 struct init_exec *iexec)
978 * INIT_IO_RESTRICT_PLL opcode: 0x34 ('4')
980 * offset (8 bit): opcode
981 * offset + 1 (16 bit): CRTC port
982 * offset + 3 (8 bit): CRTC index
983 * offset + 4 (8 bit): mask
984 * offset + 5 (8 bit): shift
985 * offset + 6 (8 bit): IO flag condition index
986 * offset + 7 (8 bit): count
987 * offset + 8 (32 bit): register
988 * offset + 12 (16 bit): frequency 1
991 * Starting at offset + 12 there are "count" 16 bit frequencies (10kHz).
992 * Set PLL register "register" to coefficients for frequency n,
993 * selected by reading index "CRTC index" of "CRTC port" ANDed with
994 * "mask" and shifted right by "shift".
996 * If "IO flag condition index" > 0, and condition met, double
997 * frequency before setting it.
1000 uint16_t crtcport = ROM16(bios->data[offset + 1]);
1001 uint8_t crtcindex = bios->data[offset + 3];
1002 uint8_t mask = bios->data[offset + 4];
1003 uint8_t shift = bios->data[offset + 5];
1004 int8_t io_flag_condition_idx = bios->data[offset + 6];
1005 uint8_t count = bios->data[offset + 7];
1006 uint32_t reg = ROM32(bios->data[offset + 8]);
1009 int len = 12 + count * 2;
1011 if (!iexec->execute)
1014 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
1015 "Shift: 0x%02X, IO Flag Condition: 0x%02X, "
1016 "Count: 0x%02X, Reg: 0x%08X\n",
1017 offset, crtcport, crtcindex, mask, shift,
1018 io_flag_condition_idx, count, reg);
1020 config = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) >> shift;
1021 if (config > count) {
1023 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
1024 offset, config, count);
1028 freq = ROM16(bios->data[offset + 12 + config * 2]);
1030 if (io_flag_condition_idx > 0) {
1031 if (io_flag_condition_met(bios, offset, io_flag_condition_idx)) {
1032 BIOSLOG(bios, "0x%04X: Condition fulfilled -- "
1033 "frequency doubled\n", offset);
1036 BIOSLOG(bios, "0x%04X: Condition not fulfilled -- "
1037 "frequency unchanged\n", offset);
1040 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Config: 0x%02X, Freq: %d0kHz\n",
1041 offset, reg, config, freq);
1043 setPLL(bios, reg, freq * 10);
1049 init_end_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1052 * INIT_END_REPEAT opcode: 0x36 ('6')
1054 * offset (8 bit): opcode
1056 * Marks the end of the block for INIT_REPEAT to repeat
1059 /* no iexec->execute check by design */
1062 * iexec->repeat flag necessary to go past INIT_END_REPEAT opcode when
1063 * we're not in repeat mode
1072 init_copy(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1075 * INIT_COPY opcode: 0x37 ('7')
1077 * offset (8 bit): opcode
1078 * offset + 1 (32 bit): register
1079 * offset + 5 (8 bit): shift
1080 * offset + 6 (8 bit): srcmask
1081 * offset + 7 (16 bit): CRTC port
1082 * offset + 9 (8 bit): CRTC index
1083 * offset + 10 (8 bit): mask
1085 * Read index "CRTC index" on "CRTC port", AND with "mask", OR with
1086 * (REGVAL("register") >> "shift" & "srcmask") and write-back to CRTC
1090 uint32_t reg = ROM32(bios->data[offset + 1]);
1091 uint8_t shift = bios->data[offset + 5];
1092 uint8_t srcmask = bios->data[offset + 6];
1093 uint16_t crtcport = ROM16(bios->data[offset + 7]);
1094 uint8_t crtcindex = bios->data[offset + 9];
1095 uint8_t mask = bios->data[offset + 10];
1099 if (!iexec->execute)
1102 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%02X, "
1103 "Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X\n",
1104 offset, reg, shift, srcmask, crtcport, crtcindex, mask);
1106 data = bios_rd32(bios, reg);
1111 data <<= (0x100 - shift);
1115 crtcdata = bios_idxprt_rd(bios, crtcport, crtcindex) & mask;
1116 crtcdata |= (uint8_t)data;
1117 bios_idxprt_wr(bios, crtcport, crtcindex, crtcdata);
1123 init_not(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1126 * INIT_NOT opcode: 0x38 ('8')
1128 * offset (8 bit): opcode
1130 * Invert the current execute / no-execute condition (i.e. "else")
1133 BIOSLOG(bios, "0x%04X: ------ Skipping following commands ------\n", offset);
1135 BIOSLOG(bios, "0x%04X: ------ Executing following commands ------\n", offset);
1137 iexec->execute = !iexec->execute;
1142 init_io_flag_condition(struct nvbios *bios, uint16_t offset,
1143 struct init_exec *iexec)
1146 * INIT_IO_FLAG_CONDITION opcode: 0x39 ('9')
1148 * offset (8 bit): opcode
1149 * offset + 1 (8 bit): condition number
1151 * Check condition "condition number" in the IO flag condition table.
1152 * If condition not met skip subsequent opcodes until condition is
1153 * inverted (INIT_NOT), or we hit INIT_RESUME
1156 uint8_t cond = bios->data[offset + 1];
1158 if (!iexec->execute)
1161 if (io_flag_condition_met(bios, offset, cond))
1162 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset);
1164 BIOSLOG(bios, "0x%04X: Condition not fulfilled -- skipping following commands\n", offset);
1165 iexec->execute = false;
1172 init_dp_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1175 * INIT_DP_CONDITION opcode: 0x3A ('')
1177 * offset (8 bit): opcode
1178 * offset + 1 (8 bit): "sub" opcode
1179 * offset + 2 (8 bit): unknown
1183 struct bit_displayport_encoder_table *dpe = NULL;
1184 struct dcb_entry *dcb = bios->display.output;
1185 struct drm_device *dev = bios->dev;
1186 uint8_t cond = bios->data[offset + 1];
1189 BIOSLOG(bios, "0x%04X: subop 0x%02X\n", offset, cond);
1191 if (!iexec->execute)
1194 dpe = nouveau_bios_dp_table(dev, dcb, &dummy);
1196 NV_ERROR(dev, "0x%04X: INIT_3A: no encoder table!!\n", offset);
1203 struct dcb_connector_table_entry *ent =
1204 &bios->dcb.connector.entry[dcb->connector];
1206 if (ent->type != DCB_CONNECTOR_eDP)
1207 iexec->execute = false;
1212 if (!(dpe->unknown & cond))
1213 iexec->execute = false;
1217 struct nouveau_i2c_chan *auxch;
1220 auxch = nouveau_i2c_find(dev, bios->display.output->i2c_index);
1224 ret = nouveau_dp_auxch(auxch, 9, 0xd, &cond, 1);
1229 iexec->execute = false;
1233 NV_WARN(dev, "0x%04X: unknown INIT_3A op: %d\n", offset, cond);
1238 BIOSLOG(bios, "0x%04X: continuing to execute\n", offset);
1240 BIOSLOG(bios, "0x%04X: skipping following commands\n", offset);
1246 init_op_3b(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1249 * INIT_3B opcode: 0x3B ('')
1251 * offset (8 bit): opcode
1252 * offset + 1 (8 bit): crtc index
1256 uint8_t or = ffs(bios->display.output->or) - 1;
1257 uint8_t index = bios->data[offset + 1];
1260 if (!iexec->execute)
1263 data = bios_idxprt_rd(bios, 0x3d4, index);
1264 bios_idxprt_wr(bios, 0x3d4, index, data & ~(1 << or));
1269 init_op_3c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1272 * INIT_3C opcode: 0x3C ('')
1274 * offset (8 bit): opcode
1275 * offset + 1 (8 bit): crtc index
1279 uint8_t or = ffs(bios->display.output->or) - 1;
1280 uint8_t index = bios->data[offset + 1];
1283 if (!iexec->execute)
1286 data = bios_idxprt_rd(bios, 0x3d4, index);
1287 bios_idxprt_wr(bios, 0x3d4, index, data | (1 << or));
1292 init_idx_addr_latched(struct nvbios *bios, uint16_t offset,
1293 struct init_exec *iexec)
1296 * INIT_INDEX_ADDRESS_LATCHED opcode: 0x49 ('I')
1298 * offset (8 bit): opcode
1299 * offset + 1 (32 bit): control register
1300 * offset + 5 (32 bit): data register
1301 * offset + 9 (32 bit): mask
1302 * offset + 13 (32 bit): data
1303 * offset + 17 (8 bit): count
1304 * offset + 18 (8 bit): address 1
1305 * offset + 19 (8 bit): data 1
1308 * For each of "count" address and data pairs, write "data n" to
1309 * "data register", read the current value of "control register",
1310 * and write it back once ANDed with "mask", ORed with "data",
1311 * and ORed with "address n"
1314 uint32_t controlreg = ROM32(bios->data[offset + 1]);
1315 uint32_t datareg = ROM32(bios->data[offset + 5]);
1316 uint32_t mask = ROM32(bios->data[offset + 9]);
1317 uint32_t data = ROM32(bios->data[offset + 13]);
1318 uint8_t count = bios->data[offset + 17];
1319 int len = 18 + count * 2;
1323 if (!iexec->execute)
1326 BIOSLOG(bios, "0x%04X: ControlReg: 0x%08X, DataReg: 0x%08X, "
1327 "Mask: 0x%08X, Data: 0x%08X, Count: 0x%02X\n",
1328 offset, controlreg, datareg, mask, data, count);
1330 for (i = 0; i < count; i++) {
1331 uint8_t instaddress = bios->data[offset + 18 + i * 2];
1332 uint8_t instdata = bios->data[offset + 19 + i * 2];
1334 BIOSLOG(bios, "0x%04X: Address: 0x%02X, Data: 0x%02X\n",
1335 offset, instaddress, instdata);
1337 bios_wr32(bios, datareg, instdata);
1338 value = bios_rd32(bios, controlreg) & mask;
1340 value |= instaddress;
1341 bios_wr32(bios, controlreg, value);
1348 init_io_restrict_pll2(struct nvbios *bios, uint16_t offset,
1349 struct init_exec *iexec)
1352 * INIT_IO_RESTRICT_PLL2 opcode: 0x4A ('J')
1354 * offset (8 bit): opcode
1355 * offset + 1 (16 bit): CRTC port
1356 * offset + 3 (8 bit): CRTC index
1357 * offset + 4 (8 bit): mask
1358 * offset + 5 (8 bit): shift
1359 * offset + 6 (8 bit): count
1360 * offset + 7 (32 bit): register
1361 * offset + 11 (32 bit): frequency 1
1364 * Starting at offset + 11 there are "count" 32 bit frequencies (kHz).
1365 * Set PLL register "register" to coefficients for frequency n,
1366 * selected by reading index "CRTC index" of "CRTC port" ANDed with
1367 * "mask" and shifted right by "shift".
1370 uint16_t crtcport = ROM16(bios->data[offset + 1]);
1371 uint8_t crtcindex = bios->data[offset + 3];
1372 uint8_t mask = bios->data[offset + 4];
1373 uint8_t shift = bios->data[offset + 5];
1374 uint8_t count = bios->data[offset + 6];
1375 uint32_t reg = ROM32(bios->data[offset + 7]);
1376 int len = 11 + count * 4;
1380 if (!iexec->execute)
1383 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
1384 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
1385 offset, crtcport, crtcindex, mask, shift, count, reg);
1390 config = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) >> shift;
1391 if (config > count) {
1393 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
1394 offset, config, count);
1398 freq = ROM32(bios->data[offset + 11 + config * 4]);
1400 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Config: 0x%02X, Freq: %dkHz\n",
1401 offset, reg, config, freq);
1403 setPLL(bios, reg, freq);
1409 init_pll2(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1412 * INIT_PLL2 opcode: 0x4B ('K')
1414 * offset (8 bit): opcode
1415 * offset + 1 (32 bit): register
1416 * offset + 5 (32 bit): freq
1418 * Set PLL register "register" to coefficients for frequency "freq"
1421 uint32_t reg = ROM32(bios->data[offset + 1]);
1422 uint32_t freq = ROM32(bios->data[offset + 5]);
1424 if (!iexec->execute)
1427 BIOSLOG(bios, "0x%04X: Reg: 0x%04X, Freq: %dkHz\n",
1430 setPLL(bios, reg, freq);
1435 init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1438 * INIT_I2C_BYTE opcode: 0x4C ('L')
1440 * offset (8 bit): opcode
1441 * offset + 1 (8 bit): DCB I2C table entry index
1442 * offset + 2 (8 bit): I2C slave address
1443 * offset + 3 (8 bit): count
1444 * offset + 4 (8 bit): I2C register 1
1445 * offset + 5 (8 bit): mask 1
1446 * offset + 6 (8 bit): data 1
1449 * For each of "count" registers given by "I2C register n" on the device
1450 * addressed by "I2C slave address" on the I2C bus given by
1451 * "DCB I2C table entry index", read the register, AND the result with
1452 * "mask n" and OR it with "data n" before writing it back to the device
1455 uint8_t i2c_index = bios->data[offset + 1];
1456 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1457 uint8_t count = bios->data[offset + 3];
1458 struct nouveau_i2c_chan *chan;
1459 int len = 4 + count * 3;
1462 if (!iexec->execute)
1465 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1467 offset, i2c_index, i2c_address, count);
1469 chan = init_i2c_device_find(bios->dev, i2c_index);
1473 for (i = 0; i < count; i++) {
1474 uint8_t reg = bios->data[offset + 4 + i * 3];
1475 uint8_t mask = bios->data[offset + 5 + i * 3];
1476 uint8_t data = bios->data[offset + 6 + i * 3];
1477 union i2c_smbus_data val;
1479 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1480 I2C_SMBUS_READ, reg,
1481 I2C_SMBUS_BYTE_DATA, &val);
1485 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, "
1486 "Mask: 0x%02X, Data: 0x%02X\n",
1487 offset, reg, val.byte, mask, data);
1494 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1495 I2C_SMBUS_WRITE, reg,
1496 I2C_SMBUS_BYTE_DATA, &val);
1505 init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1508 * INIT_ZM_I2C_BYTE opcode: 0x4D ('M')
1510 * offset (8 bit): opcode
1511 * offset + 1 (8 bit): DCB I2C table entry index
1512 * offset + 2 (8 bit): I2C slave address
1513 * offset + 3 (8 bit): count
1514 * offset + 4 (8 bit): I2C register 1
1515 * offset + 5 (8 bit): data 1
1518 * For each of "count" registers given by "I2C register n" on the device
1519 * addressed by "I2C slave address" on the I2C bus given by
1520 * "DCB I2C table entry index", set the register to "data n"
1523 uint8_t i2c_index = bios->data[offset + 1];
1524 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1525 uint8_t count = bios->data[offset + 3];
1526 struct nouveau_i2c_chan *chan;
1527 int len = 4 + count * 2;
1530 if (!iexec->execute)
1533 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1535 offset, i2c_index, i2c_address, count);
1537 chan = init_i2c_device_find(bios->dev, i2c_index);
1541 for (i = 0; i < count; i++) {
1542 uint8_t reg = bios->data[offset + 4 + i * 2];
1543 union i2c_smbus_data val;
1545 val.byte = bios->data[offset + 5 + i * 2];
1547 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Data: 0x%02X\n",
1548 offset, reg, val.byte);
1553 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1554 I2C_SMBUS_WRITE, reg,
1555 I2C_SMBUS_BYTE_DATA, &val);
1564 init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1567 * INIT_ZM_I2C opcode: 0x4E ('N')
1569 * offset (8 bit): opcode
1570 * offset + 1 (8 bit): DCB I2C table entry index
1571 * offset + 2 (8 bit): I2C slave address
1572 * offset + 3 (8 bit): count
1573 * offset + 4 (8 bit): data 1
1576 * Send "count" bytes ("data n") to the device addressed by "I2C slave
1577 * address" on the I2C bus given by "DCB I2C table entry index"
1580 uint8_t i2c_index = bios->data[offset + 1];
1581 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1582 uint8_t count = bios->data[offset + 3];
1583 int len = 4 + count;
1584 struct nouveau_i2c_chan *chan;
1589 if (!iexec->execute)
1592 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1594 offset, i2c_index, i2c_address, count);
1596 chan = init_i2c_device_find(bios->dev, i2c_index);
1600 for (i = 0; i < count; i++) {
1601 data[i] = bios->data[offset + 4 + i];
1603 BIOSLOG(bios, "0x%04X: Data: 0x%02X\n", offset, data[i]);
1606 if (bios->execute) {
1607 msg.addr = i2c_address;
1611 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1619 init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1622 * INIT_TMDS opcode: 0x4F ('O') (non-canon name)
1624 * offset (8 bit): opcode
1625 * offset + 1 (8 bit): magic lookup value
1626 * offset + 2 (8 bit): TMDS address
1627 * offset + 3 (8 bit): mask
1628 * offset + 4 (8 bit): data
1630 * Read the data reg for TMDS address "TMDS address", AND it with mask
1631 * and OR it with data, then write it back
1632 * "magic lookup value" determines which TMDS base address register is
1633 * used -- see get_tmds_index_reg()
1636 uint8_t mlv = bios->data[offset + 1];
1637 uint32_t tmdsaddr = bios->data[offset + 2];
1638 uint8_t mask = bios->data[offset + 3];
1639 uint8_t data = bios->data[offset + 4];
1640 uint32_t reg, value;
1642 if (!iexec->execute)
1645 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, TMDSAddr: 0x%02X, "
1646 "Mask: 0x%02X, Data: 0x%02X\n",
1647 offset, mlv, tmdsaddr, mask, data);
1649 reg = get_tmds_index_reg(bios->dev, mlv);
1653 bios_wr32(bios, reg,
1654 tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE);
1655 value = (bios_rd32(bios, reg + 4) & mask) | data;
1656 bios_wr32(bios, reg + 4, value);
1657 bios_wr32(bios, reg, tmdsaddr);
1663 init_zm_tmds_group(struct nvbios *bios, uint16_t offset,
1664 struct init_exec *iexec)
1667 * INIT_ZM_TMDS_GROUP opcode: 0x50 ('P') (non-canon name)
1669 * offset (8 bit): opcode
1670 * offset + 1 (8 bit): magic lookup value
1671 * offset + 2 (8 bit): count
1672 * offset + 3 (8 bit): addr 1
1673 * offset + 4 (8 bit): data 1
1676 * For each of "count" TMDS address and data pairs write "data n" to
1677 * "addr n". "magic lookup value" determines which TMDS base address
1678 * register is used -- see get_tmds_index_reg()
1681 uint8_t mlv = bios->data[offset + 1];
1682 uint8_t count = bios->data[offset + 2];
1683 int len = 3 + count * 2;
1687 if (!iexec->execute)
1690 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, Count: 0x%02X\n",
1691 offset, mlv, count);
1693 reg = get_tmds_index_reg(bios->dev, mlv);
1697 for (i = 0; i < count; i++) {
1698 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2];
1699 uint8_t tmdsdata = bios->data[offset + 4 + i * 2];
1701 bios_wr32(bios, reg + 4, tmdsdata);
1702 bios_wr32(bios, reg, tmdsaddr);
1709 init_cr_idx_adr_latch(struct nvbios *bios, uint16_t offset,
1710 struct init_exec *iexec)
1713 * INIT_CR_INDEX_ADDRESS_LATCHED opcode: 0x51 ('Q')
1715 * offset (8 bit): opcode
1716 * offset + 1 (8 bit): CRTC index1
1717 * offset + 2 (8 bit): CRTC index2
1718 * offset + 3 (8 bit): baseaddr
1719 * offset + 4 (8 bit): count
1720 * offset + 5 (8 bit): data 1
1723 * For each of "count" address and data pairs, write "baseaddr + n" to
1724 * "CRTC index1" and "data n" to "CRTC index2"
1725 * Once complete, restore initial value read from "CRTC index1"
1727 uint8_t crtcindex1 = bios->data[offset + 1];
1728 uint8_t crtcindex2 = bios->data[offset + 2];
1729 uint8_t baseaddr = bios->data[offset + 3];
1730 uint8_t count = bios->data[offset + 4];
1731 int len = 5 + count;
1732 uint8_t oldaddr, data;
1735 if (!iexec->execute)
1738 BIOSLOG(bios, "0x%04X: Index1: 0x%02X, Index2: 0x%02X, "
1739 "BaseAddr: 0x%02X, Count: 0x%02X\n",
1740 offset, crtcindex1, crtcindex2, baseaddr, count);
1742 oldaddr = bios_idxprt_rd(bios, NV_CIO_CRX__COLOR, crtcindex1);
1744 for (i = 0; i < count; i++) {
1745 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex1,
1747 data = bios->data[offset + 5 + i];
1748 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex2, data);
1751 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex1, oldaddr);
1757 init_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1760 * INIT_CR opcode: 0x52 ('R')
1762 * offset (8 bit): opcode
1763 * offset + 1 (8 bit): CRTC index
1764 * offset + 2 (8 bit): mask
1765 * offset + 3 (8 bit): data
1767 * Assign the value of at "CRTC index" ANDed with mask and ORed with
1768 * data back to "CRTC index"
1771 uint8_t crtcindex = bios->data[offset + 1];
1772 uint8_t mask = bios->data[offset + 2];
1773 uint8_t data = bios->data[offset + 3];
1776 if (!iexec->execute)
1779 BIOSLOG(bios, "0x%04X: Index: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n",
1780 offset, crtcindex, mask, data);
1782 value = bios_idxprt_rd(bios, NV_CIO_CRX__COLOR, crtcindex) & mask;
1784 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, value);
1790 init_zm_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1793 * INIT_ZM_CR opcode: 0x53 ('S')
1795 * offset (8 bit): opcode
1796 * offset + 1 (8 bit): CRTC index
1797 * offset + 2 (8 bit): value
1799 * Assign "value" to CRTC register with index "CRTC index".
1802 uint8_t crtcindex = ROM32(bios->data[offset + 1]);
1803 uint8_t data = bios->data[offset + 2];
1805 if (!iexec->execute)
1808 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, data);
1814 init_zm_cr_group(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1817 * INIT_ZM_CR_GROUP opcode: 0x54 ('T')
1819 * offset (8 bit): opcode
1820 * offset + 1 (8 bit): count
1821 * offset + 2 (8 bit): CRTC index 1
1822 * offset + 3 (8 bit): value 1
1825 * For "count", assign "value n" to CRTC register with index
1829 uint8_t count = bios->data[offset + 1];
1830 int len = 2 + count * 2;
1833 if (!iexec->execute)
1836 for (i = 0; i < count; i++)
1837 init_zm_cr(bios, offset + 2 + 2 * i - 1, iexec);
1843 init_condition_time(struct nvbios *bios, uint16_t offset,
1844 struct init_exec *iexec)
1847 * INIT_CONDITION_TIME opcode: 0x56 ('V')
1849 * offset (8 bit): opcode
1850 * offset + 1 (8 bit): condition number
1851 * offset + 2 (8 bit): retries / 50
1853 * Check condition "condition number" in the condition table.
1854 * Bios code then sleeps for 2ms if the condition is not met, and
1855 * repeats up to "retries" times, but on one C51 this has proved
1856 * insufficient. In mmiotraces the driver sleeps for 20ms, so we do
1857 * this, and bail after "retries" times, or 2s, whichever is less.
1858 * If still not met after retries, clear execution flag for this table.
1861 uint8_t cond = bios->data[offset + 1];
1862 uint16_t retries = bios->data[offset + 2] * 50;
1865 if (!iexec->execute)
1871 BIOSLOG(bios, "0x%04X: Condition: 0x%02X, Retries: 0x%02X\n",
1872 offset, cond, retries);
1874 if (!bios->execute) /* avoid 2s delays when "faking" execution */
1877 for (cnt = 0; cnt < retries; cnt++) {
1878 if (bios_condition_met(bios, offset, cond)) {
1879 BIOSLOG(bios, "0x%04X: Condition met, continuing\n",
1883 BIOSLOG(bios, "0x%04X: "
1884 "Condition not met, sleeping for 20ms\n",
1890 if (!bios_condition_met(bios, offset, cond)) {
1892 "0x%04X: Condition still not met after %dms, "
1893 "skipping following opcodes\n", offset, 20 * retries);
1894 iexec->execute = false;
1901 init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1902 struct init_exec *iexec)
1905 * INIT_ZM_REG_SEQUENCE opcode: 0x58 ('X')
1907 * offset (8 bit): opcode
1908 * offset + 1 (32 bit): base register
1909 * offset + 5 (8 bit): count
1910 * offset + 6 (32 bit): value 1
1913 * Starting at offset + 6 there are "count" 32 bit values.
1914 * For "count" iterations set "base register" + 4 * current_iteration
1915 * to "value current_iteration"
1918 uint32_t basereg = ROM32(bios->data[offset + 1]);
1919 uint32_t count = bios->data[offset + 5];
1920 int len = 6 + count * 4;
1923 if (!iexec->execute)
1926 BIOSLOG(bios, "0x%04X: BaseReg: 0x%08X, Count: 0x%02X\n",
1927 offset, basereg, count);
1929 for (i = 0; i < count; i++) {
1930 uint32_t reg = basereg + i * 4;
1931 uint32_t data = ROM32(bios->data[offset + 6 + i * 4]);
1933 bios_wr32(bios, reg, data);
1940 init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1943 * INIT_SUB_DIRECT opcode: 0x5B ('[')
1945 * offset (8 bit): opcode
1946 * offset + 1 (16 bit): subroutine offset (in bios)
1948 * Calls a subroutine that will execute commands until INIT_DONE
1952 uint16_t sub_offset = ROM16(bios->data[offset + 1]);
1954 if (!iexec->execute)
1957 BIOSLOG(bios, "0x%04X: Executing subroutine at 0x%04X\n",
1958 offset, sub_offset);
1960 parse_init_table(bios, sub_offset, iexec);
1962 BIOSLOG(bios, "0x%04X: End of 0x%04X subroutine\n", offset, sub_offset);
1968 init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1971 * INIT_COPY_NV_REG opcode: 0x5F ('_')
1973 * offset (8 bit): opcode
1974 * offset + 1 (32 bit): src reg
1975 * offset + 5 (8 bit): shift
1976 * offset + 6 (32 bit): src mask
1977 * offset + 10 (32 bit): xor
1978 * offset + 14 (32 bit): dst reg
1979 * offset + 18 (32 bit): dst mask
1981 * Shift REGVAL("src reg") right by (signed) "shift", AND result with
1982 * "src mask", then XOR with "xor". Write this OR'd with
1983 * (REGVAL("dst reg") AND'd with "dst mask") to "dst reg"
1986 uint32_t srcreg = *((uint32_t *)(&bios->data[offset + 1]));
1987 uint8_t shift = bios->data[offset + 5];
1988 uint32_t srcmask = *((uint32_t *)(&bios->data[offset + 6]));
1989 uint32_t xor = *((uint32_t *)(&bios->data[offset + 10]));
1990 uint32_t dstreg = *((uint32_t *)(&bios->data[offset + 14]));
1991 uint32_t dstmask = *((uint32_t *)(&bios->data[offset + 18]));
1992 uint32_t srcvalue, dstvalue;
1994 if (!iexec->execute)
1997 BIOSLOG(bios, "0x%04X: SrcReg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%08X, "
1998 "Xor: 0x%08X, DstReg: 0x%08X, DstMask: 0x%08X\n",
1999 offset, srcreg, shift, srcmask, xor, dstreg, dstmask);
2001 srcvalue = bios_rd32(bios, srcreg);
2006 srcvalue <<= (0x100 - shift);
2008 srcvalue = (srcvalue & srcmask) ^ xor;
2010 dstvalue = bios_rd32(bios, dstreg) & dstmask;
2012 bios_wr32(bios, dstreg, dstvalue | srcvalue);
2018 init_zm_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2021 * INIT_ZM_INDEX_IO opcode: 0x62 ('b')
2023 * offset (8 bit): opcode
2024 * offset + 1 (16 bit): CRTC port
2025 * offset + 3 (8 bit): CRTC index
2026 * offset + 4 (8 bit): data
2028 * Write "data" to index "CRTC index" of "CRTC port"
2030 uint16_t crtcport = ROM16(bios->data[offset + 1]);
2031 uint8_t crtcindex = bios->data[offset + 3];
2032 uint8_t data = bios->data[offset + 4];
2034 if (!iexec->execute)
2037 bios_idxprt_wr(bios, crtcport, crtcindex, data);
2043 init_compute_mem(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2046 * INIT_COMPUTE_MEM opcode: 0x63 ('c')
2048 * offset (8 bit): opcode
2050 * This opcode is meant to set NV_PFB_CFG0 (0x100200) appropriately so
2051 * that the hardware can correctly calculate how much VRAM it has
2052 * (and subsequently report that value in NV_PFB_CSTATUS (0x10020C))
2054 * The implementation of this opcode in general consists of two parts:
2055 * 1) determination of the memory bus width
2056 * 2) determination of how many of the card's RAM pads have ICs attached
2058 * 1) is done by a cunning combination of writes to offsets 0x1c and
2059 * 0x3c in the framebuffer, and seeing whether the written values are
2060 * read back correctly. This then affects bits 4-7 of NV_PFB_CFG0
2062 * 2) is done by a cunning combination of writes to an offset slightly
2063 * less than the maximum memory reported by NV_PFB_CSTATUS, then seeing
2064 * if the test pattern can be read back. This then affects bits 12-15 of
2067 * In this context a "cunning combination" may include multiple reads
2068 * and writes to varying locations, often alternating the test pattern
2069 * and 0, doubtless to make sure buffers are filled, residual charges
2070 * on tracks are removed etc.
2072 * Unfortunately, the "cunning combination"s mentioned above, and the
2073 * changes to the bits in NV_PFB_CFG0 differ with nearly every bios
2076 * Therefore, we cheat and assume the value of NV_PFB_CFG0 with which
2077 * we started was correct, and use that instead
2080 /* no iexec->execute check by design */
2083 * This appears to be a NOP on G8x chipsets, both io logs of the VBIOS
2084 * and kmmio traces of the binary driver POSTing the card show nothing
2085 * being done for this opcode. why is it still listed in the table?!
2088 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
2090 if (dev_priv->card_type >= NV_40)
2094 * On every card I've seen, this step gets done for us earlier in
2096 uint8_t crdata = bios_idxprt_rd(dev, NV_VIO_SRX, 0x01);
2097 bios_idxprt_wr(dev, NV_VIO_SRX, 0x01, crdata | 0x20);
2101 * This also has probably been done in the scripts, but an mmio trace of
2102 * s3 resume shows nvidia doing it anyway (unlike the NV_VIO_SRX write)
2104 bios_wr32(bios, NV_PFB_REFCTRL, NV_PFB_REFCTRL_VALID_1);
2106 /* write back the saved configuration value */
2107 bios_wr32(bios, NV_PFB_CFG0, bios->state.saved_nv_pfb_cfg0);
2113 init_reset(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2116 * INIT_RESET opcode: 0x65 ('e')
2118 * offset (8 bit): opcode
2119 * offset + 1 (32 bit): register
2120 * offset + 5 (32 bit): value1
2121 * offset + 9 (32 bit): value2
2123 * Assign "value1" to "register", then assign "value2" to "register"
2126 uint32_t reg = ROM32(bios->data[offset + 1]);
2127 uint32_t value1 = ROM32(bios->data[offset + 5]);
2128 uint32_t value2 = ROM32(bios->data[offset + 9]);
2129 uint32_t pci_nv_19, pci_nv_20;
2131 /* no iexec->execute check by design */
2133 pci_nv_19 = bios_rd32(bios, NV_PBUS_PCI_NV_19);
2134 bios_wr32(bios, NV_PBUS_PCI_NV_19, 0);
2135 bios_wr32(bios, reg, value1);
2139 bios_wr32(bios, reg, value2);
2140 bios_wr32(bios, NV_PBUS_PCI_NV_19, pci_nv_19);
2142 pci_nv_20 = bios_rd32(bios, NV_PBUS_PCI_NV_20);
2143 pci_nv_20 &= ~NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; /* 0xfffffffe */
2144 bios_wr32(bios, NV_PBUS_PCI_NV_20, pci_nv_20);
2150 init_configure_mem(struct nvbios *bios, uint16_t offset,
2151 struct init_exec *iexec)
2154 * INIT_CONFIGURE_MEM opcode: 0x66 ('f')
2156 * offset (8 bit): opcode
2158 * Equivalent to INIT_DONE on bios version 3 or greater.
2159 * For early bios versions, sets up the memory registers, using values
2160 * taken from the memory init table
2163 /* no iexec->execute check by design */
2165 uint16_t meminitoffs = bios->legacy.mem_init_tbl_ptr + MEM_INIT_SIZE * (bios_idxprt_rd(bios, NV_CIO_CRX__COLOR, NV_CIO_CRE_SCRATCH4__INDEX) >> 4);
2166 uint16_t seqtbloffs = bios->legacy.sdr_seq_tbl_ptr, meminitdata = meminitoffs + 6;
2169 if (bios->major_version > 2)
2172 bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd(
2173 bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20);
2175 if (bios->data[meminitoffs] & 1)
2176 seqtbloffs = bios->legacy.ddr_seq_tbl_ptr;
2178 for (reg = ROM32(bios->data[seqtbloffs]);
2180 reg = ROM32(bios->data[seqtbloffs += 4])) {
2184 data = NV_PFB_PRE_CMD_PRECHARGE;
2187 data = NV_PFB_PAD_CKE_NORMAL;
2190 data = NV_PFB_REF_CMD_REFRESH;
2193 data = ROM32(bios->data[meminitdata]);
2195 if (data == 0xffffffff)
2199 bios_wr32(bios, reg, data);
2206 init_configure_clk(struct nvbios *bios, uint16_t offset,
2207 struct init_exec *iexec)
2210 * INIT_CONFIGURE_CLK opcode: 0x67 ('g')
2212 * offset (8 bit): opcode
2214 * Equivalent to INIT_DONE on bios version 3 or greater.
2215 * For early bios versions, sets up the NVClk and MClk PLLs, using
2216 * values taken from the memory init table
2219 /* no iexec->execute check by design */
2221 uint16_t meminitoffs = bios->legacy.mem_init_tbl_ptr + MEM_INIT_SIZE * (bios_idxprt_rd(bios, NV_CIO_CRX__COLOR, NV_CIO_CRE_SCRATCH4__INDEX) >> 4);
2224 if (bios->major_version > 2)
2227 clock = ROM16(bios->data[meminitoffs + 4]) * 10;
2228 setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock);
2230 clock = ROM16(bios->data[meminitoffs + 2]) * 10;
2231 if (bios->data[meminitoffs] & 1) /* DDR */
2233 setPLL(bios, NV_PRAMDAC_MPLL_COEFF, clock);
2239 init_configure_preinit(struct nvbios *bios, uint16_t offset,
2240 struct init_exec *iexec)
2243 * INIT_CONFIGURE_PREINIT opcode: 0x68 ('h')
2245 * offset (8 bit): opcode
2247 * Equivalent to INIT_DONE on bios version 3 or greater.
2248 * For early bios versions, does early init, loading ram and crystal
2249 * configuration from straps into CR3C
2252 /* no iexec->execute check by design */
2254 uint32_t straps = bios_rd32(bios, NV_PEXTDEV_BOOT_0);
2255 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6));
2257 if (bios->major_version > 2)
2260 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR,
2261 NV_CIO_CRE_SCRATCH4__INDEX, cr3c);
2267 init_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2270 * INIT_IO opcode: 0x69 ('i')
2272 * offset (8 bit): opcode
2273 * offset + 1 (16 bit): CRTC port
2274 * offset + 3 (8 bit): mask
2275 * offset + 4 (8 bit): data
2277 * Assign ((IOVAL("crtc port") & "mask") | "data") to "crtc port"
2280 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
2281 uint16_t crtcport = ROM16(bios->data[offset + 1]);
2282 uint8_t mask = bios->data[offset + 3];
2283 uint8_t data = bios->data[offset + 4];
2285 if (!iexec->execute)
2288 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Mask: 0x%02X, Data: 0x%02X\n",
2289 offset, crtcport, mask, data);
2292 * I have no idea what this does, but NVIDIA do this magic sequence
2293 * in the places where this INIT_IO happens..
2295 if (dev_priv->card_type >= NV_50 && crtcport == 0x3c3 && data == 1) {
2298 bios_wr32(bios, 0x614100, (bios_rd32(
2299 bios, 0x614100) & 0x0fffffff) | 0x00800000);
2301 bios_wr32(bios, 0x00e18c, bios_rd32(
2302 bios, 0x00e18c) | 0x00020000);
2304 bios_wr32(bios, 0x614900, (bios_rd32(
2305 bios, 0x614900) & 0x0fffffff) | 0x00800000);
2307 bios_wr32(bios, 0x000200, bios_rd32(
2308 bios, 0x000200) & ~0x40000000);
2312 bios_wr32(bios, 0x00e18c, bios_rd32(
2313 bios, 0x00e18c) & ~0x00020000);
2315 bios_wr32(bios, 0x000200, bios_rd32(
2316 bios, 0x000200) | 0x40000000);
2318 bios_wr32(bios, 0x614100, 0x00800018);
2319 bios_wr32(bios, 0x614900, 0x00800018);
2323 bios_wr32(bios, 0x614100, 0x10000018);
2324 bios_wr32(bios, 0x614900, 0x10000018);
2326 for (i = 0; i < 3; i++)
2327 bios_wr32(bios, 0x614280 + (i*0x800), bios_rd32(
2328 bios, 0x614280 + (i*0x800)) & 0xf0f0f0f0);
2330 for (i = 0; i < 2; i++)
2331 bios_wr32(bios, 0x614300 + (i*0x800), bios_rd32(
2332 bios, 0x614300 + (i*0x800)) & 0xfffff0f0);
2334 for (i = 0; i < 3; i++)
2335 bios_wr32(bios, 0x614380 + (i*0x800), bios_rd32(
2336 bios, 0x614380 + (i*0x800)) & 0xfffff0f0);
2338 for (i = 0; i < 2; i++)
2339 bios_wr32(bios, 0x614200 + (i*0x800), bios_rd32(
2340 bios, 0x614200 + (i*0x800)) & 0xfffffff0);
2342 for (i = 0; i < 2; i++)
2343 bios_wr32(bios, 0x614108 + (i*0x800), bios_rd32(
2344 bios, 0x614108 + (i*0x800)) & 0x0fffffff);
2348 bios_port_wr(bios, crtcport, (bios_port_rd(bios, crtcport) & mask) |
2354 init_sub(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2357 * INIT_SUB opcode: 0x6B ('k')
2359 * offset (8 bit): opcode
2360 * offset + 1 (8 bit): script number
2362 * Execute script number "script number", as a subroutine
2365 uint8_t sub = bios->data[offset + 1];
2367 if (!iexec->execute)
2370 BIOSLOG(bios, "0x%04X: Calling script %d\n", offset, sub);
2372 parse_init_table(bios,
2373 ROM16(bios->data[bios->init_script_tbls_ptr + sub * 2]),
2376 BIOSLOG(bios, "0x%04X: End of script %d\n", offset, sub);
2382 init_ram_condition(struct nvbios *bios, uint16_t offset,
2383 struct init_exec *iexec)
2386 * INIT_RAM_CONDITION opcode: 0x6D ('m')
2388 * offset (8 bit): opcode
2389 * offset + 1 (8 bit): mask
2390 * offset + 2 (8 bit): cmpval
2392 * Test if (NV_PFB_BOOT_0 & "mask") equals "cmpval".
2393 * If condition not met skip subsequent opcodes until condition is
2394 * inverted (INIT_NOT), or we hit INIT_RESUME
2397 uint8_t mask = bios->data[offset + 1];
2398 uint8_t cmpval = bios->data[offset + 2];
2401 if (!iexec->execute)
2404 data = bios_rd32(bios, NV_PFB_BOOT_0) & mask;
2406 BIOSLOG(bios, "0x%04X: Checking if 0x%08X equals 0x%08X\n",
2407 offset, data, cmpval);
2410 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset);
2412 BIOSLOG(bios, "0x%04X: Condition not fulfilled -- skipping following commands\n", offset);
2413 iexec->execute = false;
2420 init_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2423 * INIT_NV_REG opcode: 0x6E ('n')
2425 * offset (8 bit): opcode
2426 * offset + 1 (32 bit): register
2427 * offset + 5 (32 bit): mask
2428 * offset + 9 (32 bit): data
2430 * Assign ((REGVAL("register") & "mask") | "data") to "register"
2433 uint32_t reg = ROM32(bios->data[offset + 1]);
2434 uint32_t mask = ROM32(bios->data[offset + 5]);
2435 uint32_t data = ROM32(bios->data[offset + 9]);
2437 if (!iexec->execute)
2440 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Mask: 0x%08X, Data: 0x%08X\n",
2441 offset, reg, mask, data);
2443 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | data);
2449 init_macro(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2452 * INIT_MACRO opcode: 0x6F ('o')
2454 * offset (8 bit): opcode
2455 * offset + 1 (8 bit): macro number
2457 * Look up macro index "macro number" in the macro index table.
2458 * The macro index table entry has 1 byte for the index in the macro
2459 * table, and 1 byte for the number of times to repeat the macro.
2460 * The macro table entry has 4 bytes for the register address and
2461 * 4 bytes for the value to write to that register
2464 uint8_t macro_index_tbl_idx = bios->data[offset + 1];
2465 uint16_t tmp = bios->macro_index_tbl_ptr + (macro_index_tbl_idx * MACRO_INDEX_SIZE);
2466 uint8_t macro_tbl_idx = bios->data[tmp];
2467 uint8_t count = bios->data[tmp + 1];
2471 if (!iexec->execute)
2474 BIOSLOG(bios, "0x%04X: Macro: 0x%02X, MacroTableIndex: 0x%02X, "
2476 offset, macro_index_tbl_idx, macro_tbl_idx, count);
2478 for (i = 0; i < count; i++) {
2479 uint16_t macroentryptr = bios->macro_tbl_ptr + (macro_tbl_idx + i) * MACRO_SIZE;
2481 reg = ROM32(bios->data[macroentryptr]);
2482 data = ROM32(bios->data[macroentryptr + 4]);
2484 bios_wr32(bios, reg, data);
2491 init_done(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2494 * INIT_DONE opcode: 0x71 ('q')
2496 * offset (8 bit): opcode
2498 * End the current script
2501 /* mild retval abuse to stop parsing this table */
2506 init_resume(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2509 * INIT_RESUME opcode: 0x72 ('r')
2511 * offset (8 bit): opcode
2513 * End the current execute / no-execute condition
2519 iexec->execute = true;
2520 BIOSLOG(bios, "0x%04X: ---- Executing following commands ----\n", offset);
2526 init_time(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2529 * INIT_TIME opcode: 0x74 ('t')
2531 * offset (8 bit): opcode
2532 * offset + 1 (16 bit): time
2534 * Sleep for "time" microseconds.
2537 unsigned time = ROM16(bios->data[offset + 1]);
2539 if (!iexec->execute)
2542 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X microseconds\n",
2548 msleep((time + 900) / 1000);
2554 init_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2557 * INIT_CONDITION opcode: 0x75 ('u')
2559 * offset (8 bit): opcode
2560 * offset + 1 (8 bit): condition number
2562 * Check condition "condition number" in the condition table.
2563 * If condition not met skip subsequent opcodes until condition is
2564 * inverted (INIT_NOT), or we hit INIT_RESUME
2567 uint8_t cond = bios->data[offset + 1];
2569 if (!iexec->execute)
2572 BIOSLOG(bios, "0x%04X: Condition: 0x%02X\n", offset, cond);
2574 if (bios_condition_met(bios, offset, cond))
2575 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset);
2577 BIOSLOG(bios, "0x%04X: Condition not fulfilled -- skipping following commands\n", offset);
2578 iexec->execute = false;
2585 init_io_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2588 * INIT_IO_CONDITION opcode: 0x76
2590 * offset (8 bit): opcode
2591 * offset + 1 (8 bit): condition number
2593 * Check condition "condition number" in the io condition table.
2594 * If condition not met skip subsequent opcodes until condition is
2595 * inverted (INIT_NOT), or we hit INIT_RESUME
2598 uint8_t cond = bios->data[offset + 1];
2600 if (!iexec->execute)
2603 BIOSLOG(bios, "0x%04X: IO condition: 0x%02X\n", offset, cond);
2605 if (io_condition_met(bios, offset, cond))
2606 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset);
2608 BIOSLOG(bios, "0x%04X: Condition not fulfilled -- skipping following commands\n", offset);
2609 iexec->execute = false;
2616 init_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2619 * INIT_INDEX_IO opcode: 0x78 ('x')
2621 * offset (8 bit): opcode
2622 * offset + 1 (16 bit): CRTC port
2623 * offset + 3 (8 bit): CRTC index
2624 * offset + 4 (8 bit): mask
2625 * offset + 5 (8 bit): data
2627 * Read value at index "CRTC index" on "CRTC port", AND with "mask",
2628 * OR with "data", write-back
2631 uint16_t crtcport = ROM16(bios->data[offset + 1]);
2632 uint8_t crtcindex = bios->data[offset + 3];
2633 uint8_t mask = bios->data[offset + 4];
2634 uint8_t data = bios->data[offset + 5];
2637 if (!iexec->execute)
2640 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
2642 offset, crtcport, crtcindex, mask, data);
2644 value = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) | data;
2645 bios_idxprt_wr(bios, crtcport, crtcindex, value);
2651 init_pll(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2654 * INIT_PLL opcode: 0x79 ('y')
2656 * offset (8 bit): opcode
2657 * offset + 1 (32 bit): register
2658 * offset + 5 (16 bit): freq
2660 * Set PLL register "register" to coefficients for frequency (10kHz)
2664 uint32_t reg = ROM32(bios->data[offset + 1]);
2665 uint16_t freq = ROM16(bios->data[offset + 5]);
2667 if (!iexec->execute)
2670 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Freq: %d0kHz\n", offset, reg, freq);
2672 setPLL(bios, reg, freq * 10);
2678 init_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2681 * INIT_ZM_REG opcode: 0x7A ('z')
2683 * offset (8 bit): opcode
2684 * offset + 1 (32 bit): register
2685 * offset + 5 (32 bit): value
2687 * Assign "value" to "register"
2690 uint32_t reg = ROM32(bios->data[offset + 1]);
2691 uint32_t value = ROM32(bios->data[offset + 5]);
2693 if (!iexec->execute)
2696 if (reg == 0x000200)
2699 bios_wr32(bios, reg, value);
2705 init_ram_restrict_pll(struct nvbios *bios, uint16_t offset,
2706 struct init_exec *iexec)
2709 * INIT_RAM_RESTRICT_PLL opcode: 0x87 ('')
2711 * offset (8 bit): opcode
2712 * offset + 1 (8 bit): PLL type
2713 * offset + 2 (32 bit): frequency 0
2715 * Uses the RAMCFG strap of PEXTDEV_BOOT as an index into the table at
2716 * ram_restrict_table_ptr. The value read from there is used to select
2717 * a frequency from the table starting at 'frequency 0' to be
2718 * programmed into the PLL corresponding to 'type'.
2720 * The PLL limits table on cards using this opcode has a mapping of
2721 * 'type' to the relevant registers.
2724 struct drm_device *dev = bios->dev;
2725 uint32_t strap = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) & 0x0000003c) >> 2;
2726 uint8_t index = bios->data[bios->ram_restrict_tbl_ptr + strap];
2727 uint8_t type = bios->data[offset + 1];
2728 uint32_t freq = ROM32(bios->data[offset + 2 + (index * 4)]);
2729 uint8_t *pll_limits = &bios->data[bios->pll_limit_tbl_ptr], *entry;
2730 int len = 2 + bios->ram_restrict_group_count * 4;
2733 if (!iexec->execute)
2736 if (!bios->pll_limit_tbl_ptr || (pll_limits[0] & 0xf0) != 0x30) {
2737 NV_ERROR(dev, "PLL limits table not version 3.x\n");
2738 return len; /* deliberate, allow default clocks to remain */
2741 entry = pll_limits + pll_limits[1];
2742 for (i = 0; i < pll_limits[3]; i++, entry += pll_limits[2]) {
2743 if (entry[0] == type) {
2744 uint32_t reg = ROM32(entry[3]);
2746 BIOSLOG(bios, "0x%04X: "
2747 "Type %02x Reg 0x%08x Freq %dKHz\n",
2748 offset, type, reg, freq);
2750 setPLL(bios, reg, freq);
2755 NV_ERROR(dev, "PLL type 0x%02x not found in PLL limits table", type);
2760 init_8c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2763 * INIT_8C opcode: 0x8C ('')
2773 init_8d(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2776 * INIT_8D opcode: 0x8D ('')
2786 init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2789 * INIT_GPIO opcode: 0x8E ('')
2791 * offset (8 bit): opcode
2793 * Loop over all entries in the DCB GPIO table, and initialise
2794 * each GPIO according to various values listed in each entry
2797 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
2798 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c };
2801 if (dev_priv->card_type != NV_50) {
2802 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n");
2806 if (!iexec->execute)
2809 for (i = 0; i < bios->dcb.gpio.entries; i++) {
2810 struct dcb_gpio_entry *gpio = &bios->dcb.gpio.entry[i];
2813 BIOSLOG(bios, "0x%04X: Entry: 0x%08X\n", offset, gpio->entry);
2815 BIOSLOG(bios, "0x%04X: set gpio 0x%02x, state %d\n",
2816 offset, gpio->tag, gpio->state_default);
2818 nv50_gpio_set(bios->dev, gpio->tag, gpio->state_default);
2820 /* The NVIDIA binary driver doesn't appear to actually do
2821 * any of this, my VBIOS does however.
2823 /* Not a clue, needs de-magicing */
2824 r = nv50_gpio_ctl[gpio->line >> 4];
2825 s = (gpio->line & 0x0f);
2826 v = bios_rd32(bios, r) & ~(0x00010001 << s);
2827 switch ((gpio->entry & 0x06000000) >> 25) {
2829 v |= (0x00000001 << s);
2832 v |= (0x00010000 << s);
2837 bios_wr32(bios, r, v);
2844 init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset,
2845 struct init_exec *iexec)
2848 * INIT_RAM_RESTRICT_ZM_REG_GROUP opcode: 0x8F ('')
2850 * offset (8 bit): opcode
2851 * offset + 1 (32 bit): reg
2852 * offset + 5 (8 bit): regincrement
2853 * offset + 6 (8 bit): count
2854 * offset + 7 (32 bit): value 1,1
2857 * Use the RAMCFG strap of PEXTDEV_BOOT as an index into the table at
2858 * ram_restrict_table_ptr. The value read from here is 'n', and
2859 * "value 1,n" gets written to "reg". This repeats "count" times and on
2860 * each iteration 'm', "reg" increases by "regincrement" and
2861 * "value m,n" is used. The extent of n is limited by a number read
2862 * from the 'M' BIT table, herein called "blocklen"
2865 uint32_t reg = ROM32(bios->data[offset + 1]);
2866 uint8_t regincrement = bios->data[offset + 5];
2867 uint8_t count = bios->data[offset + 6];
2868 uint32_t strap_ramcfg, data;
2869 /* previously set by 'M' BIT table */
2870 uint16_t blocklen = bios->ram_restrict_group_count * 4;
2871 int len = 7 + count * blocklen;
2876 if (!iexec->execute)
2881 "0x%04X: Zero block length - has the M table "
2882 "been parsed?\n", offset);
2886 strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf;
2887 index = bios->data[bios->ram_restrict_tbl_ptr + strap_ramcfg];
2889 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, RegIncrement: 0x%02X, "
2890 "Count: 0x%02X, StrapRamCfg: 0x%02X, Index: 0x%02X\n",
2891 offset, reg, regincrement, count, strap_ramcfg, index);
2893 for (i = 0; i < count; i++) {
2894 data = ROM32(bios->data[offset + 7 + index * 4 + blocklen * i]);
2896 bios_wr32(bios, reg, data);
2898 reg += regincrement;
2905 init_copy_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2908 * INIT_COPY_ZM_REG opcode: 0x90 ('')
2910 * offset (8 bit): opcode
2911 * offset + 1 (32 bit): src reg
2912 * offset + 5 (32 bit): dst reg
2914 * Put contents of "src reg" into "dst reg"
2917 uint32_t srcreg = ROM32(bios->data[offset + 1]);
2918 uint32_t dstreg = ROM32(bios->data[offset + 5]);
2920 if (!iexec->execute)
2923 bios_wr32(bios, dstreg, bios_rd32(bios, srcreg));
2929 init_zm_reg_group_addr_latched(struct nvbios *bios, uint16_t offset,
2930 struct init_exec *iexec)
2933 * INIT_ZM_REG_GROUP_ADDRESS_LATCHED opcode: 0x91 ('')
2935 * offset (8 bit): opcode
2936 * offset + 1 (32 bit): dst reg
2937 * offset + 5 (8 bit): count
2938 * offset + 6 (32 bit): data 1
2941 * For each of "count" values write "data n" to "dst reg"
2944 uint32_t reg = ROM32(bios->data[offset + 1]);
2945 uint8_t count = bios->data[offset + 5];
2946 int len = 6 + count * 4;
2949 if (!iexec->execute)
2952 for (i = 0; i < count; i++) {
2953 uint32_t data = ROM32(bios->data[offset + 6 + 4 * i]);
2954 bios_wr32(bios, reg, data);
2961 init_reserved(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2964 * INIT_RESERVED opcode: 0x92 ('')
2966 * offset (8 bit): opcode
2968 * Seemingly does nothing
2975 init_96(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2978 * INIT_96 opcode: 0x96 ('')
2980 * offset (8 bit): opcode
2981 * offset + 1 (32 bit): sreg
2982 * offset + 5 (8 bit): sshift
2983 * offset + 6 (8 bit): smask
2984 * offset + 7 (8 bit): index
2985 * offset + 8 (32 bit): reg
2986 * offset + 12 (32 bit): mask
2987 * offset + 16 (8 bit): shift
2991 uint16_t xlatptr = bios->init96_tbl_ptr + (bios->data[offset + 7] * 2);
2992 uint32_t reg = ROM32(bios->data[offset + 8]);
2993 uint32_t mask = ROM32(bios->data[offset + 12]);
2996 val = bios_rd32(bios, ROM32(bios->data[offset + 1]));
2997 if (bios->data[offset + 5] < 0x80)
2998 val >>= bios->data[offset + 5];
3000 val <<= (0x100 - bios->data[offset + 5]);
3001 val &= bios->data[offset + 6];
3003 val = bios->data[ROM16(bios->data[xlatptr]) + val];
3004 val <<= bios->data[offset + 16];
3006 if (!iexec->execute)
3009 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | val);
3014 init_97(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3017 * INIT_97 opcode: 0x97 ('')
3019 * offset (8 bit): opcode
3020 * offset + 1 (32 bit): register
3021 * offset + 5 (32 bit): mask
3022 * offset + 9 (32 bit): value
3024 * Adds "value" to "register" preserving the fields specified
3028 uint32_t reg = ROM32(bios->data[offset + 1]);
3029 uint32_t mask = ROM32(bios->data[offset + 5]);
3030 uint32_t add = ROM32(bios->data[offset + 9]);
3033 val = bios_rd32(bios, reg);
3034 val = (val & mask) | ((val + add) & ~mask);
3036 if (!iexec->execute)
3039 bios_wr32(bios, reg, val);
3044 init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3047 * INIT_AUXCH opcode: 0x98 ('')
3049 * offset (8 bit): opcode
3050 * offset + 1 (32 bit): address
3051 * offset + 5 (8 bit): count
3052 * offset + 6 (8 bit): mask 0
3053 * offset + 7 (8 bit): data 0
3058 struct drm_device *dev = bios->dev;
3059 struct nouveau_i2c_chan *auxch;
3060 uint32_t addr = ROM32(bios->data[offset + 1]);
3061 uint8_t count = bios->data[offset + 5];
3062 int len = 6 + count * 2;
3065 if (!bios->display.output) {
3066 NV_ERROR(dev, "INIT_AUXCH: no active output\n");
3070 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
3072 NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n",
3073 bios->display.output->i2c_index);
3077 if (!iexec->execute)
3081 for (i = 0; i < count; i++, offset += 2) {
3084 ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1);
3086 NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret);
3090 data &= bios->data[offset + 0];
3091 data |= bios->data[offset + 1];
3093 ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1);
3095 NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret);
3104 init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3107 * INIT_ZM_AUXCH opcode: 0x99 ('')
3109 * offset (8 bit): opcode
3110 * offset + 1 (32 bit): address
3111 * offset + 5 (8 bit): count
3112 * offset + 6 (8 bit): data 0
3117 struct drm_device *dev = bios->dev;
3118 struct nouveau_i2c_chan *auxch;
3119 uint32_t addr = ROM32(bios->data[offset + 1]);
3120 uint8_t count = bios->data[offset + 5];
3121 int len = 6 + count;
3124 if (!bios->display.output) {
3125 NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n");
3129 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
3131 NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n",
3132 bios->display.output->i2c_index);
3136 if (!iexec->execute)
3140 for (i = 0; i < count; i++, offset++) {
3141 ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1);
3143 NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret);
3151 static struct init_tbl_entry itbl_entry[] = {
3152 /* command name , id , length , offset , mult , command handler */
3153 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */
3154 { "INIT_IO_RESTRICT_PROG" , 0x32, init_io_restrict_prog },
3155 { "INIT_REPEAT" , 0x33, init_repeat },
3156 { "INIT_IO_RESTRICT_PLL" , 0x34, init_io_restrict_pll },
3157 { "INIT_END_REPEAT" , 0x36, init_end_repeat },
3158 { "INIT_COPY" , 0x37, init_copy },
3159 { "INIT_NOT" , 0x38, init_not },
3160 { "INIT_IO_FLAG_CONDITION" , 0x39, init_io_flag_condition },
3161 { "INIT_DP_CONDITION" , 0x3A, init_dp_condition },
3162 { "INIT_OP_3B" , 0x3B, init_op_3b },
3163 { "INIT_OP_3C" , 0x3C, init_op_3c },
3164 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, init_idx_addr_latched },
3165 { "INIT_IO_RESTRICT_PLL2" , 0x4A, init_io_restrict_pll2 },
3166 { "INIT_PLL2" , 0x4B, init_pll2 },
3167 { "INIT_I2C_BYTE" , 0x4C, init_i2c_byte },
3168 { "INIT_ZM_I2C_BYTE" , 0x4D, init_zm_i2c_byte },
3169 { "INIT_ZM_I2C" , 0x4E, init_zm_i2c },
3170 { "INIT_TMDS" , 0x4F, init_tmds },
3171 { "INIT_ZM_TMDS_GROUP" , 0x50, init_zm_tmds_group },
3172 { "INIT_CR_INDEX_ADDRESS_LATCHED" , 0x51, init_cr_idx_adr_latch },
3173 { "INIT_CR" , 0x52, init_cr },
3174 { "INIT_ZM_CR" , 0x53, init_zm_cr },
3175 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group },
3176 { "INIT_CONDITION_TIME" , 0x56, init_condition_time },
3177 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence },
3178 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */
3179 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct },
3180 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg },
3181 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io },
3182 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem },
3183 { "INIT_RESET" , 0x65, init_reset },
3184 { "INIT_CONFIGURE_MEM" , 0x66, init_configure_mem },
3185 { "INIT_CONFIGURE_CLK" , 0x67, init_configure_clk },
3186 { "INIT_CONFIGURE_PREINIT" , 0x68, init_configure_preinit },
3187 { "INIT_IO" , 0x69, init_io },
3188 { "INIT_SUB" , 0x6B, init_sub },
3189 { "INIT_RAM_CONDITION" , 0x6D, init_ram_condition },
3190 { "INIT_NV_REG" , 0x6E, init_nv_reg },
3191 { "INIT_MACRO" , 0x6F, init_macro },
3192 { "INIT_DONE" , 0x71, init_done },
3193 { "INIT_RESUME" , 0x72, init_resume },
3194 /* INIT_RAM_CONDITION2 (0x73, 9, 0, 0) removed due to no example of use */
3195 { "INIT_TIME" , 0x74, init_time },
3196 { "INIT_CONDITION" , 0x75, init_condition },
3197 { "INIT_IO_CONDITION" , 0x76, init_io_condition },
3198 { "INIT_INDEX_IO" , 0x78, init_index_io },
3199 { "INIT_PLL" , 0x79, init_pll },
3200 { "INIT_ZM_REG" , 0x7A, init_zm_reg },
3201 { "INIT_RAM_RESTRICT_PLL" , 0x87, init_ram_restrict_pll },
3202 { "INIT_8C" , 0x8C, init_8c },
3203 { "INIT_8D" , 0x8D, init_8d },
3204 { "INIT_GPIO" , 0x8E, init_gpio },
3205 { "INIT_RAM_RESTRICT_ZM_REG_GROUP" , 0x8F, init_ram_restrict_zm_reg_group },
3206 { "INIT_COPY_ZM_REG" , 0x90, init_copy_zm_reg },
3207 { "INIT_ZM_REG_GROUP_ADDRESS_LATCHED" , 0x91, init_zm_reg_group_addr_latched },
3208 { "INIT_RESERVED" , 0x92, init_reserved },
3209 { "INIT_96" , 0x96, init_96 },
3210 { "INIT_97" , 0x97, init_97 },
3211 { "INIT_AUXCH" , 0x98, init_auxch },
3212 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch },
3216 #define MAX_TABLE_OPS 1000
3219 parse_init_table(struct nvbios *bios, unsigned int offset,
3220 struct init_exec *iexec)
3223 * Parses all commands in an init table.
3225 * We start out executing all commands found in the init table. Some
3226 * opcodes may change the status of iexec->execute to SKIP, which will
3227 * cause the following opcodes to perform no operation until the value
3228 * is changed back to EXECUTE.
3231 int count = 0, i, ret;
3235 * Loop until INIT_DONE causes us to break out of the loop
3236 * (or until offset > bios length just in case... )
3237 * (and no more than MAX_TABLE_OPS iterations, just in case... )
3239 while ((offset < bios->length) && (count++ < MAX_TABLE_OPS)) {
3240 id = bios->data[offset];
3242 /* Find matching id in itbl_entry */
3243 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != id); i++)
3246 if (!itbl_entry[i].name) {
3248 "0x%04X: Init table command not found: "
3249 "0x%02X\n", offset, id);
3253 BIOSLOG(bios, "0x%04X: [ (0x%02X) - %s ]\n", offset,
3254 itbl_entry[i].id, itbl_entry[i].name);
3256 /* execute eventual command handler */
3257 ret = (*itbl_entry[i].handler)(bios, offset, iexec);
3259 NV_ERROR(bios->dev, "0x%04X: Failed parsing init "
3260 "table opcode: %s %d\n", offset,
3261 itbl_entry[i].name, ret);
3268 * Add the offset of the current command including all data
3269 * of that command. The offset will then be pointing on the
3275 if (offset >= bios->length)
3277 "Offset 0x%04X greater than known bios image length. "
3278 "Corrupt image?\n", offset);
3279 if (count >= MAX_TABLE_OPS)
3281 "More than %d opcodes to a table is unlikely, "
3282 "is the bios image corrupt?\n", MAX_TABLE_OPS);
3288 parse_init_tables(struct nvbios *bios)
3290 /* Loops and calls parse_init_table() for each present table. */
3294 struct init_exec iexec = {true, false};
3296 if (bios->old_style_init) {
3297 if (bios->init_script_tbls_ptr)
3298 parse_init_table(bios, bios->init_script_tbls_ptr, &iexec);
3299 if (bios->extra_init_script_tbl_ptr)
3300 parse_init_table(bios, bios->extra_init_script_tbl_ptr, &iexec);
3305 while ((table = ROM16(bios->data[bios->init_script_tbls_ptr + i]))) {
3307 "Parsing VBIOS init table %d at offset 0x%04X\n",
3309 BIOSLOG(bios, "0x%04X: ------ Executing following commands ------\n", table);
3311 parse_init_table(bios, table, &iexec);
3316 static uint16_t clkcmptable(struct nvbios *bios, uint16_t clktable, int pxclk)
3318 int compare_record_len, i = 0;
3319 uint16_t compareclk, scriptptr = 0;
3321 if (bios->major_version < 5) /* pre BIT */
3322 compare_record_len = 3;
3324 compare_record_len = 4;
3327 compareclk = ROM16(bios->data[clktable + compare_record_len * i]);
3328 if (pxclk >= compareclk * 10) {
3329 if (bios->major_version < 5) {
3330 uint8_t tmdssub = bios->data[clktable + 2 + compare_record_len * i];
3331 scriptptr = ROM16(bios->data[bios->init_script_tbls_ptr + tmdssub * 2]);
3333 scriptptr = ROM16(bios->data[clktable + 2 + compare_record_len * i]);
3337 } while (compareclk);
3343 run_digital_op_script(struct drm_device *dev, uint16_t scriptptr,
3344 struct dcb_entry *dcbent, int head, bool dl)
3346 struct drm_nouveau_private *dev_priv = dev->dev_private;
3347 struct nvbios *bios = &dev_priv->vbios;
3348 struct init_exec iexec = {true, false};
3350 NV_TRACE(dev, "0x%04X: Parsing digital output script table\n",
3352 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, NV_CIO_CRE_44,
3353 head ? NV_CIO_CRE_44_HEADB : NV_CIO_CRE_44_HEADA);
3354 /* note: if dcb entries have been merged, index may be misleading */
3355 NVWriteVgaCrtc5758(dev, head, 0, dcbent->index);
3356 parse_init_table(bios, scriptptr, &iexec);
3358 nv04_dfp_bind_head(dev, dcbent, head, dl);
3361 static int call_lvds_manufacturer_script(struct drm_device *dev, struct dcb_entry *dcbent, int head, enum LVDS_script script)
3363 struct drm_nouveau_private *dev_priv = dev->dev_private;
3364 struct nvbios *bios = &dev_priv->vbios;
3365 uint8_t sub = bios->data[bios->fp.xlated_entry + script] + (bios->fp.link_c_increment && dcbent->or & OUTPUT_C ? 1 : 0);
3366 uint16_t scriptofs = ROM16(bios->data[bios->init_script_tbls_ptr + sub * 2]);
3368 if (!bios->fp.xlated_entry || !sub || !scriptofs)
3371 run_digital_op_script(dev, scriptofs, dcbent, head, bios->fp.dual_link);
3373 if (script == LVDS_PANEL_OFF) {
3374 /* off-on delay in ms */
3375 msleep(ROM16(bios->data[bios->fp.xlated_entry + 7]));
3378 /* Powerbook specific quirks */
3379 if ((dev->pci_device & 0xffff) == 0x0179 ||
3380 (dev->pci_device & 0xffff) == 0x0189 ||
3381 (dev->pci_device & 0xffff) == 0x0329) {
3382 if (script == LVDS_RESET) {
3383 nv_write_tmds(dev, dcbent->or, 0, 0x02, 0x72);
3385 } else if (script == LVDS_PANEL_ON) {
3386 bios_wr32(bios, NV_PBUS_DEBUG_DUALHEAD_CTL,
3387 bios_rd32(bios, NV_PBUS_DEBUG_DUALHEAD_CTL)
3389 bios_wr32(bios, NV_PCRTC_GPIO_EXT,
3390 bios_rd32(bios, NV_PCRTC_GPIO_EXT) | 1);
3392 } else if (script == LVDS_PANEL_OFF) {
3393 bios_wr32(bios, NV_PBUS_DEBUG_DUALHEAD_CTL,
3394 bios_rd32(bios, NV_PBUS_DEBUG_DUALHEAD_CTL)
3396 bios_wr32(bios, NV_PCRTC_GPIO_EXT,
3397 bios_rd32(bios, NV_PCRTC_GPIO_EXT) & ~3);
3405 static int run_lvds_table(struct drm_device *dev, struct dcb_entry *dcbent, int head, enum LVDS_script script, int pxclk)
3408 * The BIT LVDS table's header has the information to setup the
3409 * necessary registers. Following the standard 4 byte header are:
3410 * A bitmask byte and a dual-link transition pxclk value for use in
3411 * selecting the init script when not using straps; 4 script pointers
3412 * for panel power, selected by output and on/off; and 8 table pointers
3413 * for panel init, the needed one determined by output, and bits in the
3414 * conf byte. These tables are similar to the TMDS tables, consisting
3415 * of a list of pxclks and script pointers.
3417 struct drm_nouveau_private *dev_priv = dev->dev_private;
3418 struct nvbios *bios = &dev_priv->vbios;
3419 unsigned int outputset = (dcbent->or == 4) ? 1 : 0;
3420 uint16_t scriptptr = 0, clktable;
3423 * For now we assume version 3.0 table - g80 support will need some
3430 case LVDS_BACKLIGHT_ON:
3432 scriptptr = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 7 + outputset * 2]);
3434 case LVDS_BACKLIGHT_OFF:
3435 case LVDS_PANEL_OFF:
3436 scriptptr = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 11 + outputset * 2]);
3439 clktable = bios->fp.lvdsmanufacturerpointer + 15;
3440 if (dcbent->or == 4)
3443 if (dcbent->lvdsconf.use_straps_for_mode) {
3444 if (bios->fp.dual_link)
3446 if (bios->fp.if_is_24bit)
3450 int cmpval_24bit = (dcbent->or == 4) ? 4 : 1;
3452 if (bios->fp.dual_link) {
3457 if (bios->fp.strapless_is_24bit & cmpval_24bit)
3461 clktable = ROM16(bios->data[clktable]);
3463 NV_ERROR(dev, "Pixel clock comparison table not found\n");
3466 scriptptr = clkcmptable(bios, clktable, pxclk);
3470 NV_ERROR(dev, "LVDS output init script not found\n");
3473 run_digital_op_script(dev, scriptptr, dcbent, head, bios->fp.dual_link);
3478 int call_lvds_script(struct drm_device *dev, struct dcb_entry *dcbent, int head, enum LVDS_script script, int pxclk)
3481 * LVDS operations are multiplexed in an effort to present a single API
3482 * which works with two vastly differing underlying structures.
3483 * This acts as the demux
3486 struct drm_nouveau_private *dev_priv = dev->dev_private;
3487 struct nvbios *bios = &dev_priv->vbios;
3488 uint8_t lvds_ver = bios->data[bios->fp.lvdsmanufacturerpointer];
3489 uint32_t sel_clk_binding, sel_clk;
3492 if (bios->fp.last_script_invoc == (script << 1 | head) || !lvds_ver ||
3493 (lvds_ver >= 0x30 && script == LVDS_INIT))
3496 if (!bios->fp.lvds_init_run) {
3497 bios->fp.lvds_init_run = true;
3498 call_lvds_script(dev, dcbent, head, LVDS_INIT, pxclk);
3501 if (script == LVDS_PANEL_ON && bios->fp.reset_after_pclk_change)
3502 call_lvds_script(dev, dcbent, head, LVDS_RESET, pxclk);
3503 if (script == LVDS_RESET && bios->fp.power_off_for_reset)
3504 call_lvds_script(dev, dcbent, head, LVDS_PANEL_OFF, pxclk);
3506 NV_TRACE(dev, "Calling LVDS script %d:\n", script);
3508 /* don't let script change pll->head binding */
3509 sel_clk_binding = bios_rd32(bios, NV_PRAMDAC_SEL_CLK) & 0x50000;
3511 if (lvds_ver < 0x30)
3512 ret = call_lvds_manufacturer_script(dev, dcbent, head, script);
3514 ret = run_lvds_table(dev, dcbent, head, script, pxclk);
3516 bios->fp.last_script_invoc = (script << 1 | head);
3518 sel_clk = NVReadRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK) & ~0x50000;
3519 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK, sel_clk | sel_clk_binding);
3520 /* some scripts set a value in NV_PBUS_POWERCTRL_2 and break video overlay */
3521 nvWriteMC(dev, NV_PBUS_POWERCTRL_2, 0);
3526 struct lvdstableheader {
3527 uint8_t lvds_ver, headerlen, recordlen;
3530 static int parse_lvds_manufacturer_table_header(struct drm_device *dev, struct nvbios *bios, struct lvdstableheader *lth)
3533 * BMP version (0xa) LVDS table has a simple header of version and
3534 * record length. The BIT LVDS table has the typical BIT table header:
3535 * version byte, header length byte, record length byte, and a byte for
3536 * the maximum number of records that can be held in the table.
3539 uint8_t lvds_ver, headerlen, recordlen;
3541 memset(lth, 0, sizeof(struct lvdstableheader));
3543 if (bios->fp.lvdsmanufacturerpointer == 0x0) {
3544 NV_ERROR(dev, "Pointer to LVDS manufacturer table invalid\n");
3548 lvds_ver = bios->data[bios->fp.lvdsmanufacturerpointer];
3551 case 0x0a: /* pre NV40 */
3553 recordlen = bios->data[bios->fp.lvdsmanufacturerpointer + 1];
3555 case 0x30: /* NV4x */
3556 headerlen = bios->data[bios->fp.lvdsmanufacturerpointer + 1];
3557 if (headerlen < 0x1f) {
3558 NV_ERROR(dev, "LVDS table header not understood\n");
3561 recordlen = bios->data[bios->fp.lvdsmanufacturerpointer + 2];
3563 case 0x40: /* G80/G90 */
3564 headerlen = bios->data[bios->fp.lvdsmanufacturerpointer + 1];
3565 if (headerlen < 0x7) {
3566 NV_ERROR(dev, "LVDS table header not understood\n");
3569 recordlen = bios->data[bios->fp.lvdsmanufacturerpointer + 2];
3573 "LVDS table revision %d.%d not currently supported\n",
3574 lvds_ver >> 4, lvds_ver & 0xf);
3578 lth->lvds_ver = lvds_ver;
3579 lth->headerlen = headerlen;
3580 lth->recordlen = recordlen;
3586 get_fp_strap(struct drm_device *dev, struct nvbios *bios)
3588 struct drm_nouveau_private *dev_priv = dev->dev_private;
3591 * The fp strap is normally dictated by the "User Strap" in
3592 * PEXTDEV_BOOT_0[20:16], but on BMP cards when bit 2 of the
3593 * Internal_Flags struct at 0x48 is set, the user strap gets overriden
3594 * by the PCI subsystem ID during POST, but not before the previous user
3595 * strap has been committed to CR58 for CR57=0xf on head A, which may be
3596 * read and used instead
3599 if (bios->major_version < 5 && bios->data[0x48] & 0x4)
3600 return NVReadVgaCrtc5758(dev, 0, 0xf) & 0xf;
3602 if (dev_priv->card_type >= NV_50)
3603 return (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 24) & 0xf;
3605 return (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 16) & 0xf;
3608 static int parse_fp_mode_table(struct drm_device *dev, struct nvbios *bios)
3611 uint8_t fptable_ver, headerlen = 0, recordlen, fpentries = 0xf, fpindex;
3612 int ret, ofs, fpstrapping;
3613 struct lvdstableheader lth;
3615 if (bios->fp.fptablepointer == 0x0) {
3616 /* Apple cards don't have the fp table; the laptops use DDC */
3617 /* The table is also missing on some x86 IGPs */
3619 NV_ERROR(dev, "Pointer to flat panel table invalid\n");
3621 bios->digital_min_front_porch = 0x4b;
3625 fptable = &bios->data[bios->fp.fptablepointer];
3626 fptable_ver = fptable[0];
3628 switch (fptable_ver) {
3630 * BMP version 0x5.0x11 BIOSen have version 1 like tables, but no
3631 * version field, and miss one of the spread spectrum/PWM bytes.
3632 * This could affect early GF2Go parts (not seen any appropriate ROMs
3633 * though). Here we assume that a version of 0x05 matches this case
3634 * (combining with a BMP version check would be better), as the
3635 * common case for the panel type field is 0x0005, and that is in
3636 * fact what we are reading the first byte of.
3638 case 0x05: /* some NV10, 11, 15, 16 */
3642 case 0x10: /* some NV15/16, and NV11+ */
3646 case 0x20: /* NV40+ */
3647 headerlen = fptable[1];
3648 recordlen = fptable[2];
3649 fpentries = fptable[3];
3651 * fptable[4] is the minimum
3652 * RAMDAC_FP_HCRTC -> RAMDAC_FP_HSYNC_START gap
3654 bios->digital_min_front_porch = fptable[4];
3659 "FP table revision %d.%d not currently supported\n",
3660 fptable_ver >> 4, fptable_ver & 0xf);
3664 if (!bios->is_mobile) /* !mobile only needs digital_min_front_porch */
3667 ret = parse_lvds_manufacturer_table_header(dev, bios, <h);
3671 if (lth.lvds_ver == 0x30 || lth.lvds_ver == 0x40) {
3672 bios->fp.fpxlatetableptr = bios->fp.lvdsmanufacturerpointer +
3674 bios->fp.xlatwidth = lth.recordlen;
3676 if (bios->fp.fpxlatetableptr == 0x0) {
3677 NV_ERROR(dev, "Pointer to flat panel xlat table invalid\n");
3681 fpstrapping = get_fp_strap(dev, bios);
3683 fpindex = bios->data[bios->fp.fpxlatetableptr +
3684 fpstrapping * bios->fp.xlatwidth];
3686 if (fpindex > fpentries) {
3687 NV_ERROR(dev, "Bad flat panel table index\n");
3691 /* nv4x cards need both a strap value and fpindex of 0xf to use DDC */
3692 if (lth.lvds_ver > 0x10)
3693 bios->fp_no_ddc = fpstrapping != 0xf || fpindex != 0xf;
3696 * If either the strap or xlated fpindex value are 0xf there is no
3697 * panel using a strap-derived bios mode present. this condition
3698 * includes, but is different from, the DDC panel indicator above
3700 if (fpstrapping == 0xf || fpindex == 0xf)
3703 bios->fp.mode_ptr = bios->fp.fptablepointer + headerlen +
3704 recordlen * fpindex + ofs;
3706 NV_TRACE(dev, "BIOS FP mode: %dx%d (%dkHz pixel clock)\n",
3707 ROM16(bios->data[bios->fp.mode_ptr + 11]) + 1,
3708 ROM16(bios->data[bios->fp.mode_ptr + 25]) + 1,
3709 ROM16(bios->data[bios->fp.mode_ptr + 7]) * 10);
3714 bool nouveau_bios_fp_mode(struct drm_device *dev, struct drm_display_mode *mode)
3716 struct drm_nouveau_private *dev_priv = dev->dev_private;
3717 struct nvbios *bios = &dev_priv->vbios;
3718 uint8_t *mode_entry = &bios->data[bios->fp.mode_ptr];
3720 if (!mode) /* just checking whether we can produce a mode */
3721 return bios->fp.mode_ptr;
3723 memset(mode, 0, sizeof(struct drm_display_mode));
3725 * For version 1.0 (version in byte 0):
3726 * bytes 1-2 are "panel type", including bits on whether Colour/mono,
3727 * single/dual link, and type (TFT etc.)
3728 * bytes 3-6 are bits per colour in RGBX
3730 mode->clock = ROM16(mode_entry[7]) * 10;
3731 /* bytes 9-10 is HActive */
3732 mode->hdisplay = ROM16(mode_entry[11]) + 1;
3734 * bytes 13-14 is HValid Start
3735 * bytes 15-16 is HValid End
3737 mode->hsync_start = ROM16(mode_entry[17]) + 1;
3738 mode->hsync_end = ROM16(mode_entry[19]) + 1;
3739 mode->htotal = ROM16(mode_entry[21]) + 1;
3740 /* bytes 23-24, 27-30 similarly, but vertical */
3741 mode->vdisplay = ROM16(mode_entry[25]) + 1;
3742 mode->vsync_start = ROM16(mode_entry[31]) + 1;
3743 mode->vsync_end = ROM16(mode_entry[33]) + 1;
3744 mode->vtotal = ROM16(mode_entry[35]) + 1;
3745 mode->flags |= (mode_entry[37] & 0x10) ?
3746 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
3747 mode->flags |= (mode_entry[37] & 0x1) ?
3748 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
3750 * bytes 38-39 relate to spread spectrum settings
3751 * bytes 40-43 are something to do with PWM
3754 mode->status = MODE_OK;
3755 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
3756 drm_mode_set_name(mode);
3757 return bios->fp.mode_ptr;
3760 int nouveau_bios_parse_lvds_table(struct drm_device *dev, int pxclk, bool *dl, bool *if_is_24bit)
3763 * The LVDS table header is (mostly) described in
3764 * parse_lvds_manufacturer_table_header(): the BIT header additionally
3765 * contains the dual-link transition pxclk (in 10s kHz), at byte 5 - if
3766 * straps are not being used for the panel, this specifies the frequency
3767 * at which modes should be set up in the dual link style.
3769 * Following the header, the BMP (ver 0xa) table has several records,
3770 * indexed by a separate xlat table, indexed in turn by the fp strap in
3771 * EXTDEV_BOOT. Each record had a config byte, followed by 6 script
3772 * numbers for use by INIT_SUB which controlled panel init and power,
3773 * and finally a dword of ms to sleep between power off and on
3776 * In the BIT versions, the table following the header serves as an
3777 * integrated config and xlat table: the records in the table are
3778 * indexed by the FP strap nibble in EXTDEV_BOOT, and each record has
3779 * two bytes - the first as a config byte, the second for indexing the
3780 * fp mode table pointed to by the BIT 'D' table
3782 * DDC is not used until after card init, so selecting the correct table
3783 * entry and setting the dual link flag for EDID equipped panels,
3784 * requiring tests against the native-mode pixel clock, cannot be done
3785 * until later, when this function should be called with non-zero pxclk
3787 struct drm_nouveau_private *dev_priv = dev->dev_private;
3788 struct nvbios *bios = &dev_priv->vbios;
3789 int fpstrapping = get_fp_strap(dev, bios), lvdsmanufacturerindex = 0;
3790 struct lvdstableheader lth;
3792 int ret, chip_version = bios->chip_version;
3794 ret = parse_lvds_manufacturer_table_header(dev, bios, <h);
3798 switch (lth.lvds_ver) {
3799 case 0x0a: /* pre NV40 */
3800 lvdsmanufacturerindex = bios->data[
3801 bios->fp.fpxlatemanufacturertableptr +
3804 /* we're done if this isn't the EDID panel case */
3808 if (chip_version < 0x25) {
3811 * It seems the old style lvds script pointer is reused
3812 * to select 18/24 bit colour depth for EDID panels.
3814 lvdsmanufacturerindex =
3815 (bios->legacy.lvds_single_a_script_ptr & 1) ?
3817 if (pxclk >= bios->fp.duallink_transition_clk)
3818 lvdsmanufacturerindex++;
3819 } else if (chip_version < 0x30) {
3820 /* nv28 behaviour (off-chip encoder)
3822 * nv28 does a complex dance of first using byte 121 of
3823 * the EDID to choose the lvdsmanufacturerindex, then
3824 * later attempting to match the EDID manufacturer and
3825 * product IDs in a table (signature 'pidt' (panel id
3826 * table?)), setting an lvdsmanufacturerindex of 0 and
3827 * an fp strap of the match index (or 0xf if none)
3829 lvdsmanufacturerindex = 0;
3831 /* nv31, nv34 behaviour */
3832 lvdsmanufacturerindex = 0;
3833 if (pxclk >= bios->fp.duallink_transition_clk)
3834 lvdsmanufacturerindex = 2;
3835 if (pxclk >= 140000)
3836 lvdsmanufacturerindex = 3;
3840 * nvidia set the high nibble of (cr57=f, cr58) to
3841 * lvdsmanufacturerindex in this case; we don't
3844 case 0x30: /* NV4x */
3845 case 0x40: /* G80/G90 */
3846 lvdsmanufacturerindex = fpstrapping;
3849 NV_ERROR(dev, "LVDS table revision not currently supported\n");
3853 lvdsofs = bios->fp.xlated_entry = bios->fp.lvdsmanufacturerpointer + lth.headerlen + lth.recordlen * lvdsmanufacturerindex;
3854 switch (lth.lvds_ver) {
3856 bios->fp.power_off_for_reset = bios->data[lvdsofs] & 1;
3857 bios->fp.reset_after_pclk_change = bios->data[lvdsofs] & 2;
3858 bios->fp.dual_link = bios->data[lvdsofs] & 4;
3859 bios->fp.link_c_increment = bios->data[lvdsofs] & 8;
3860 *if_is_24bit = bios->data[lvdsofs] & 16;
3865 * No sign of the "power off for reset" or "reset for panel
3866 * on" bits, but it's safer to assume we should
3868 bios->fp.power_off_for_reset = true;
3869 bios->fp.reset_after_pclk_change = true;
3872 * It's ok lvdsofs is wrong for nv4x edid case; dual_link is
3873 * over-written, and if_is_24bit isn't used
3875 bios->fp.dual_link = bios->data[lvdsofs] & 1;
3876 bios->fp.if_is_24bit = bios->data[lvdsofs] & 2;
3877 bios->fp.strapless_is_24bit = bios->data[bios->fp.lvdsmanufacturerpointer + 4];
3878 bios->fp.duallink_transition_clk = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 5]) * 10;
3882 /* Dell Latitude D620 reports a too-high value for the dual-link
3883 * transition freq, causing us to program the panel incorrectly.
3885 * It doesn't appear the VBIOS actually uses its transition freq
3886 * (90000kHz), instead it uses the "Number of LVDS channels" field
3887 * out of the panel ID structure (http://www.spwg.org/).
3889 * For the moment, a quirk will do :)
3891 if ((dev->pdev->device == 0x01d7) &&
3892 (dev->pdev->subsystem_vendor == 0x1028) &&
3893 (dev->pdev->subsystem_device == 0x01c2)) {
3894 bios->fp.duallink_transition_clk = 80000;
3897 /* set dual_link flag for EDID case */
3898 if (pxclk && (chip_version < 0x25 || chip_version > 0x28))
3899 bios->fp.dual_link = (pxclk >= bios->fp.duallink_transition_clk);
3901 *dl = bios->fp.dual_link;
3907 bios_output_config_match(struct drm_device *dev, struct dcb_entry *dcbent,
3908 uint16_t record, int record_len, int record_nr,
3911 struct drm_nouveau_private *dev_priv = dev->dev_private;
3912 struct nvbios *bios = &dev_priv->vbios;
3917 switch (dcbent->type) {
3927 for (i = 0; i < record_nr; i++, record += record_len) {
3928 table = ROM16(bios->data[record]);
3931 entry = ROM32(bios->data[table]);
3934 v = (entry & 0x00c00000) >> 22;
3935 if (!(v & dcbent->sorconf.link))
3939 v = (entry & 0x000f0000) >> 16;
3940 if (!(v & dcbent->or))
3943 v = (entry & 0x000000f0) >> 4;
3944 if (v != dcbent->location)
3947 v = (entry & 0x0000000f);
3948 if (v != dcbent->type)
3951 return &bios->data[table];
3958 nouveau_bios_dp_table(struct drm_device *dev, struct dcb_entry *dcbent,
3961 struct drm_nouveau_private *dev_priv = dev->dev_private;
3962 struct nvbios *bios = &dev_priv->vbios;
3965 if (!bios->display.dp_table_ptr) {
3966 NV_ERROR(dev, "No pointer to DisplayPort table\n");
3969 table = &bios->data[bios->display.dp_table_ptr];
3971 if (table[0] != 0x20 && table[0] != 0x21) {
3972 NV_ERROR(dev, "DisplayPort table version 0x%02x unknown\n",
3978 return bios_output_config_match(dev, dcbent,
3979 bios->display.dp_table_ptr + table[1],
3980 table[2], table[3], table[0] >= 0x21);
3984 nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent,
3985 uint32_t sub, int pxclk)
3988 * The display script table is located by the BIT 'U' table.
3990 * It contains an array of pointers to various tables describing
3991 * a particular output type. The first 32-bits of the output
3992 * tables contains similar information to a DCB entry, and is
3993 * used to decide whether that particular table is suitable for
3994 * the output you want to access.
3996 * The "record header length" field here seems to indicate the
3997 * offset of the first configuration entry in the output tables.
3998 * This is 10 on most cards I've seen, but 12 has been witnessed
3999 * on DP cards, and there's another script pointer within the
4002 * offset + 0 ( 8 bits): version
4003 * offset + 1 ( 8 bits): header length
4004 * offset + 2 ( 8 bits): record length
4005 * offset + 3 ( 8 bits): number of records
4006 * offset + 4 ( 8 bits): record header length
4007 * offset + 5 (16 bits): pointer to first output script table
4010 struct drm_nouveau_private *dev_priv = dev->dev_private;
4011 struct nvbios *bios = &dev_priv->vbios;
4012 uint8_t *table = &bios->data[bios->display.script_table_ptr];
4013 uint8_t *otable = NULL;
4017 if (!bios->display.script_table_ptr) {
4018 NV_ERROR(dev, "No pointer to output script table\n");
4023 * Nothing useful has been in any of the pre-2.0 tables I've seen,
4024 * so until they are, we really don't need to care.
4026 if (table[0] < 0x20)
4029 if (table[0] != 0x20 && table[0] != 0x21) {
4030 NV_ERROR(dev, "Output script table version 0x%02x unknown\n",
4036 * The output script tables describing a particular output type
4039 * offset + 0 (32 bits): output this table matches (hash of DCB)
4040 * offset + 4 ( 8 bits): unknown
4041 * offset + 5 ( 8 bits): number of configurations
4042 * offset + 6 (16 bits): pointer to some script
4043 * offset + 8 (16 bits): pointer to some script
4046 * offset + 10 : configuration 0
4049 * offset + 10 : pointer to some script
4050 * offset + 12 : configuration 0
4052 * Each config entry is as follows:
4054 * offset + 0 (16 bits): unknown, assumed to be a match value
4055 * offset + 2 (16 bits): pointer to script table (clock set?)
4056 * offset + 4 (16 bits): pointer to script table (reset?)
4058 * There doesn't appear to be a count value to say how many
4059 * entries exist in each script table, instead, a 0 value in
4060 * the first 16-bit word seems to indicate both the end of the
4061 * list and the default entry. The second 16-bit word in the
4062 * script tables is a pointer to the script to execute.
4065 NV_DEBUG_KMS(dev, "Searching for output entry for %d %d %d\n",
4066 dcbent->type, dcbent->location, dcbent->or);
4067 otable = bios_output_config_match(dev, dcbent, table[1] +
4068 bios->display.script_table_ptr,
4069 table[2], table[3], table[0] >= 0x21);
4071 NV_ERROR(dev, "Couldn't find matching output script table\n");
4075 if (pxclk < -2 || pxclk > 0) {
4076 /* Try to find matching script table entry */
4077 for (i = 0; i < otable[5]; i++) {
4078 if (ROM16(otable[table[4] + i*6]) == sub)
4082 if (i == otable[5]) {
4083 NV_ERROR(dev, "Table 0x%04x not found for %d/%d, "
4085 sub, dcbent->type, dcbent->or);
4091 script = ROM16(otable[6]);
4093 NV_DEBUG_KMS(dev, "output script 0 not found\n");
4097 NV_TRACE(dev, "0x%04X: parsing output script 0\n", script);
4098 nouveau_bios_run_init_table(dev, script, dcbent);
4101 script = ROM16(otable[8]);
4103 NV_DEBUG_KMS(dev, "output script 1 not found\n");
4107 NV_TRACE(dev, "0x%04X: parsing output script 1\n", script);
4108 nouveau_bios_run_init_table(dev, script, dcbent);
4112 script = ROM16(otable[10]);
4116 NV_DEBUG_KMS(dev, "output script 2 not found\n");
4120 NV_TRACE(dev, "0x%04X: parsing output script 2\n", script);
4121 nouveau_bios_run_init_table(dev, script, dcbent);
4124 script = ROM16(otable[table[4] + i*6 + 2]);
4126 script = clkcmptable(bios, script, pxclk);
4128 NV_ERROR(dev, "clock script 0 not found\n");
4132 NV_TRACE(dev, "0x%04X: parsing clock script 0\n", script);
4133 nouveau_bios_run_init_table(dev, script, dcbent);
4136 script = ROM16(otable[table[4] + i*6 + 4]);
4138 script = clkcmptable(bios, script, -pxclk);
4140 NV_DEBUG_KMS(dev, "clock script 1 not found\n");
4144 NV_TRACE(dev, "0x%04X: parsing clock script 1\n", script);
4145 nouveau_bios_run_init_table(dev, script, dcbent);
4152 int run_tmds_table(struct drm_device *dev, struct dcb_entry *dcbent, int head, int pxclk)
4155 * the pxclk parameter is in kHz
4157 * This runs the TMDS regs setting code found on BIT bios cards
4159 * For ffs(or) == 1 use the first table, for ffs(or) == 2 and
4160 * ffs(or) == 3, use the second.
4163 struct drm_nouveau_private *dev_priv = dev->dev_private;
4164 struct nvbios *bios = &dev_priv->vbios;
4165 int cv = bios->chip_version;
4166 uint16_t clktable = 0, scriptptr;
4167 uint32_t sel_clk_binding, sel_clk;
4169 /* pre-nv17 off-chip tmds uses scripts, post nv17 doesn't */
4170 if (cv >= 0x17 && cv != 0x1a && cv != 0x20 &&
4171 dcbent->location != DCB_LOC_ON_CHIP)
4174 switch (ffs(dcbent->or)) {
4176 clktable = bios->tmds.output0_script_ptr;
4180 clktable = bios->tmds.output1_script_ptr;
4185 NV_ERROR(dev, "Pixel clock comparison table not found\n");
4189 scriptptr = clkcmptable(bios, clktable, pxclk);
4192 NV_ERROR(dev, "TMDS output init script not found\n");
4196 /* don't let script change pll->head binding */
4197 sel_clk_binding = bios_rd32(bios, NV_PRAMDAC_SEL_CLK) & 0x50000;
4198 run_digital_op_script(dev, scriptptr, dcbent, head, pxclk >= 165000);
4199 sel_clk = NVReadRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK) & ~0x50000;
4200 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK, sel_clk | sel_clk_binding);
4205 int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims *pll_lim)
4210 * Version 0x10: NV30, NV31
4211 * One byte header (version), one record of 24 bytes
4212 * Version 0x11: NV36 - Not implemented
4213 * Seems to have same record style as 0x10, but 3 records rather than 1
4214 * Version 0x20: Found on Geforce 6 cards
4215 * Trivial 4 byte BIT header. 31 (0x1f) byte record length
4216 * Version 0x21: Found on Geforce 7, 8 and some Geforce 6 cards
4217 * 5 byte header, fifth byte of unknown purpose. 35 (0x23) byte record
4218 * length in general, some (integrated) have an extra configuration byte
4219 * Version 0x30: Found on Geforce 8, separates the register mapping
4220 * from the limits tables.
4223 struct drm_nouveau_private *dev_priv = dev->dev_private;
4224 struct nvbios *bios = &dev_priv->vbios;
4225 int cv = bios->chip_version, pllindex = 0;
4226 uint8_t pll_lim_ver = 0, headerlen = 0, recordlen = 0, entries = 0;
4227 uint32_t crystal_strap_mask, crystal_straps;
4229 if (!bios->pll_limit_tbl_ptr) {
4230 if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 ||
4232 NV_ERROR(dev, "Pointer to PLL limits table invalid\n");
4236 pll_lim_ver = bios->data[bios->pll_limit_tbl_ptr];
4238 crystal_strap_mask = 1 << 6;
4239 /* open coded dev->twoHeads test */
4240 if (cv > 0x10 && cv != 0x15 && cv != 0x1a && cv != 0x20)
4241 crystal_strap_mask |= 1 << 22;
4242 crystal_straps = nvReadEXTDEV(dev, NV_PEXTDEV_BOOT_0) &
4245 switch (pll_lim_ver) {
4247 * We use version 0 to indicate a pre limit table bios (single stage
4248 * pll) and load the hard coded limits instead.
4255 * Strictly v0x11 has 3 entries, but the last two don't seem
4267 headerlen = bios->data[bios->pll_limit_tbl_ptr + 1];
4268 recordlen = bios->data[bios->pll_limit_tbl_ptr + 2];
4269 entries = bios->data[bios->pll_limit_tbl_ptr + 3];
4272 NV_ERROR(dev, "PLL limits table revision 0x%X not currently "
4273 "supported\n", pll_lim_ver);
4277 /* initialize all members to zero */
4278 memset(pll_lim, 0, sizeof(struct pll_lims));
4280 if (pll_lim_ver == 0x10 || pll_lim_ver == 0x11) {
4281 uint8_t *pll_rec = &bios->data[bios->pll_limit_tbl_ptr + headerlen + recordlen * pllindex];
4283 pll_lim->vco1.minfreq = ROM32(pll_rec[0]);
4284 pll_lim->vco1.maxfreq = ROM32(pll_rec[4]);
4285 pll_lim->vco2.minfreq = ROM32(pll_rec[8]);
4286 pll_lim->vco2.maxfreq = ROM32(pll_rec[12]);
4287 pll_lim->vco1.min_inputfreq = ROM32(pll_rec[16]);
4288 pll_lim->vco2.min_inputfreq = ROM32(pll_rec[20]);
4289 pll_lim->vco1.max_inputfreq = pll_lim->vco2.max_inputfreq = INT_MAX;
4291 /* these values taken from nv30/31/36 */
4292 pll_lim->vco1.min_n = 0x1;
4294 pll_lim->vco1.min_n = 0x5;
4295 pll_lim->vco1.max_n = 0xff;
4296 pll_lim->vco1.min_m = 0x1;
4297 pll_lim->vco1.max_m = 0xd;
4298 pll_lim->vco2.min_n = 0x4;
4300 * On nv30, 31, 36 (i.e. all cards with two stage PLLs with this
4301 * table version (apart from nv35)), N2 is compared to
4302 * maxN2 (0x46) and 10 * maxM2 (0x4), so set maxN2 to 0x28 and
4305 pll_lim->vco2.max_n = 0x28;
4306 if (cv == 0x30 || cv == 0x35)
4307 /* only 5 bits available for N2 on nv30/35 */
4308 pll_lim->vco2.max_n = 0x1f;
4309 pll_lim->vco2.min_m = 0x1;
4310 pll_lim->vco2.max_m = 0x4;
4311 pll_lim->max_log2p = 0x7;
4312 pll_lim->max_usable_log2p = 0x6;
4313 } else if (pll_lim_ver == 0x20 || pll_lim_ver == 0x21) {
4314 uint16_t plloffs = bios->pll_limit_tbl_ptr + headerlen;
4315 uint32_t reg = 0; /* default match */
4320 * First entry is default match, if nothing better. warn if
4323 if (ROM32(bios->data[plloffs]))
4324 NV_WARN(dev, "Default PLL limit entry has non-zero "
4325 "register field\n");
4327 if (limit_match > MAX_PLL_TYPES)
4328 /* we've been passed a reg as the match */
4330 else /* limit match is a pll type */
4331 for (i = 1; i < entries && !reg; i++) {
4332 uint32_t cmpreg = ROM32(bios->data[plloffs + recordlen * i]);
4334 if (limit_match == NVPLL &&
4335 (cmpreg == NV_PRAMDAC_NVPLL_COEFF || cmpreg == 0x4000))
4337 if (limit_match == MPLL &&
4338 (cmpreg == NV_PRAMDAC_MPLL_COEFF || cmpreg == 0x4020))
4340 if (limit_match == VPLL1 &&
4341 (cmpreg == NV_PRAMDAC_VPLL_COEFF || cmpreg == 0x4010))
4343 if (limit_match == VPLL2 &&
4344 (cmpreg == NV_RAMDAC_VPLL2 || cmpreg == 0x4018))
4348 for (i = 1; i < entries; i++)
4349 if (ROM32(bios->data[plloffs + recordlen * i]) == reg) {
4354 pll_rec = &bios->data[plloffs + recordlen * pllindex];
4356 BIOSLOG(bios, "Loading PLL limits for reg 0x%08x\n",
4357 pllindex ? reg : 0);
4360 * Frequencies are stored in tables in MHz, kHz are more
4361 * useful, so we convert.
4364 /* What output frequencies can each VCO generate? */
4365 pll_lim->vco1.minfreq = ROM16(pll_rec[4]) * 1000;
4366 pll_lim->vco1.maxfreq = ROM16(pll_rec[6]) * 1000;
4367 pll_lim->vco2.minfreq = ROM16(pll_rec[8]) * 1000;
4368 pll_lim->vco2.maxfreq = ROM16(pll_rec[10]) * 1000;
4370 /* What input frequencies they accept (past the m-divider)? */
4371 pll_lim->vco1.min_inputfreq = ROM16(pll_rec[12]) * 1000;
4372 pll_lim->vco2.min_inputfreq = ROM16(pll_rec[14]) * 1000;
4373 pll_lim->vco1.max_inputfreq = ROM16(pll_rec[16]) * 1000;
4374 pll_lim->vco2.max_inputfreq = ROM16(pll_rec[18]) * 1000;
4376 /* What values are accepted as multiplier and divider? */
4377 pll_lim->vco1.min_n = pll_rec[20];
4378 pll_lim->vco1.max_n = pll_rec[21];
4379 pll_lim->vco1.min_m = pll_rec[22];
4380 pll_lim->vco1.max_m = pll_rec[23];
4381 pll_lim->vco2.min_n = pll_rec[24];
4382 pll_lim->vco2.max_n = pll_rec[25];
4383 pll_lim->vco2.min_m = pll_rec[26];
4384 pll_lim->vco2.max_m = pll_rec[27];
4386 pll_lim->max_usable_log2p = pll_lim->max_log2p = pll_rec[29];
4387 if (pll_lim->max_log2p > 0x7)
4388 /* pll decoding in nv_hw.c assumes never > 7 */
4389 NV_WARN(dev, "Max log2 P value greater than 7 (%d)\n",
4390 pll_lim->max_log2p);
4392 pll_lim->max_usable_log2p = 0x6;
4393 pll_lim->log2p_bias = pll_rec[30];
4395 if (recordlen > 0x22)
4396 pll_lim->refclk = ROM32(pll_rec[31]);
4398 if (recordlen > 0x23 && pll_rec[35])
4400 "Bits set in PLL configuration byte (%x)\n",
4403 /* C51 special not seen elsewhere */
4404 if (cv == 0x51 && !pll_lim->refclk) {
4405 uint32_t sel_clk = bios_rd32(bios, NV_PRAMDAC_SEL_CLK);
4407 if (((limit_match == NV_PRAMDAC_VPLL_COEFF || limit_match == VPLL1) && sel_clk & 0x20) ||
4408 ((limit_match == NV_RAMDAC_VPLL2 || limit_match == VPLL2) && sel_clk & 0x80)) {
4409 if (bios_idxprt_rd(bios, NV_CIO_CRX__COLOR, NV_CIO_CRE_CHIP_ID_INDEX) < 0xa3)
4410 pll_lim->refclk = 200000;
4412 pll_lim->refclk = 25000;
4415 } else if (pll_lim_ver == 0x30) { /* ver 0x30 */
4416 uint8_t *entry = &bios->data[bios->pll_limit_tbl_ptr + headerlen];
4417 uint8_t *record = NULL;
4420 BIOSLOG(bios, "Loading PLL limits for register 0x%08x\n",
4423 for (i = 0; i < entries; i++, entry += recordlen) {
4424 if (ROM32(entry[3]) == limit_match) {
4425 record = &bios->data[ROM16(entry[1])];
4431 NV_ERROR(dev, "Register 0x%08x not found in PLL "
4432 "limits table", limit_match);
4436 pll_lim->vco1.minfreq = ROM16(record[0]) * 1000;
4437 pll_lim->vco1.maxfreq = ROM16(record[2]) * 1000;
4438 pll_lim->vco2.minfreq = ROM16(record[4]) * 1000;
4439 pll_lim->vco2.maxfreq = ROM16(record[6]) * 1000;
4440 pll_lim->vco1.min_inputfreq = ROM16(record[8]) * 1000;
4441 pll_lim->vco2.min_inputfreq = ROM16(record[10]) * 1000;
4442 pll_lim->vco1.max_inputfreq = ROM16(record[12]) * 1000;
4443 pll_lim->vco2.max_inputfreq = ROM16(record[14]) * 1000;
4444 pll_lim->vco1.min_n = record[16];
4445 pll_lim->vco1.max_n = record[17];
4446 pll_lim->vco1.min_m = record[18];
4447 pll_lim->vco1.max_m = record[19];
4448 pll_lim->vco2.min_n = record[20];
4449 pll_lim->vco2.max_n = record[21];
4450 pll_lim->vco2.min_m = record[22];
4451 pll_lim->vco2.max_m = record[23];
4452 pll_lim->max_usable_log2p = pll_lim->max_log2p = record[25];
4453 pll_lim->log2p_bias = record[27];
4454 pll_lim->refclk = ROM32(record[28]);
4455 } else if (pll_lim_ver) { /* ver 0x40 */
4456 uint8_t *entry = &bios->data[bios->pll_limit_tbl_ptr + headerlen];
4457 uint8_t *record = NULL;
4460 BIOSLOG(bios, "Loading PLL limits for register 0x%08x\n",
4463 for (i = 0; i < entries; i++, entry += recordlen) {
4464 if (ROM32(entry[3]) == limit_match) {
4465 record = &bios->data[ROM16(entry[1])];
4471 NV_ERROR(dev, "Register 0x%08x not found in PLL "
4472 "limits table", limit_match);
4476 pll_lim->vco1.minfreq = ROM16(record[0]) * 1000;
4477 pll_lim->vco1.maxfreq = ROM16(record[2]) * 1000;
4478 pll_lim->vco1.min_inputfreq = ROM16(record[4]) * 1000;
4479 pll_lim->vco1.max_inputfreq = ROM16(record[6]) * 1000;
4480 pll_lim->vco1.min_m = record[8];
4481 pll_lim->vco1.max_m = record[9];
4482 pll_lim->vco1.min_n = record[10];
4483 pll_lim->vco1.max_n = record[11];
4484 pll_lim->min_p = record[12];
4485 pll_lim->max_p = record[13];
4486 /* where did this go to?? */
4487 if (limit_match == 0x00614100 || limit_match == 0x00614900)
4488 pll_lim->refclk = 27000;
4490 pll_lim->refclk = 100000;
4494 * By now any valid limit table ought to have set a max frequency for
4495 * vco1, so if it's zero it's either a pre limit table bios, or one
4496 * with an empty limit table (seen on nv18)
4498 if (!pll_lim->vco1.maxfreq) {
4499 pll_lim->vco1.minfreq = bios->fminvco;
4500 pll_lim->vco1.maxfreq = bios->fmaxvco;
4501 pll_lim->vco1.min_inputfreq = 0;
4502 pll_lim->vco1.max_inputfreq = INT_MAX;
4503 pll_lim->vco1.min_n = 0x1;
4504 pll_lim->vco1.max_n = 0xff;
4505 pll_lim->vco1.min_m = 0x1;
4506 if (crystal_straps == 0) {
4507 /* nv05 does this, nv11 doesn't, nv10 unknown */
4509 pll_lim->vco1.min_m = 0x7;
4510 pll_lim->vco1.max_m = 0xd;
4513 pll_lim->vco1.min_m = 0x8;
4514 pll_lim->vco1.max_m = 0xe;
4516 if (cv < 0x17 || cv == 0x1a || cv == 0x20)
4517 pll_lim->max_log2p = 4;
4519 pll_lim->max_log2p = 5;
4520 pll_lim->max_usable_log2p = pll_lim->max_log2p;
4523 if (!pll_lim->refclk)
4524 switch (crystal_straps) {
4526 pll_lim->refclk = 13500;
4529 pll_lim->refclk = 14318;
4532 pll_lim->refclk = 27000;
4534 case (1 << 22 | 1 << 6):
4535 pll_lim->refclk = 25000;
4539 NV_DEBUG(dev, "pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq);
4540 NV_DEBUG(dev, "pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq);
4541 NV_DEBUG(dev, "pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq);
4542 NV_DEBUG(dev, "pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq);
4543 NV_DEBUG(dev, "pll.vco1.min_n: %d\n", pll_lim->vco1.min_n);
4544 NV_DEBUG(dev, "pll.vco1.max_n: %d\n", pll_lim->vco1.max_n);
4545 NV_DEBUG(dev, "pll.vco1.min_m: %d\n", pll_lim->vco1.min_m);
4546 NV_DEBUG(dev, "pll.vco1.max_m: %d\n", pll_lim->vco1.max_m);
4547 if (pll_lim->vco2.maxfreq) {
4548 NV_DEBUG(dev, "pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq);
4549 NV_DEBUG(dev, "pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq);
4550 NV_DEBUG(dev, "pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq);
4551 NV_DEBUG(dev, "pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq);
4552 NV_DEBUG(dev, "pll.vco2.min_n: %d\n", pll_lim->vco2.min_n);
4553 NV_DEBUG(dev, "pll.vco2.max_n: %d\n", pll_lim->vco2.max_n);
4554 NV_DEBUG(dev, "pll.vco2.min_m: %d\n", pll_lim->vco2.min_m);
4555 NV_DEBUG(dev, "pll.vco2.max_m: %d\n", pll_lim->vco2.max_m);
4557 if (!pll_lim->max_p) {
4558 NV_DEBUG(dev, "pll.max_log2p: %d\n", pll_lim->max_log2p);
4559 NV_DEBUG(dev, "pll.log2p_bias: %d\n", pll_lim->log2p_bias);
4561 NV_DEBUG(dev, "pll.min_p: %d\n", pll_lim->min_p);
4562 NV_DEBUG(dev, "pll.max_p: %d\n", pll_lim->max_p);
4564 NV_DEBUG(dev, "pll.refclk: %d\n", pll_lim->refclk);
4569 static void parse_bios_version(struct drm_device *dev, struct nvbios *bios, uint16_t offset)
4572 * offset + 0 (8 bits): Micro version
4573 * offset + 1 (8 bits): Minor version
4574 * offset + 2 (8 bits): Chip version
4575 * offset + 3 (8 bits): Major version
4578 bios->major_version = bios->data[offset + 3];
4579 bios->chip_version = bios->data[offset + 2];
4580 NV_TRACE(dev, "Bios version %02x.%02x.%02x.%02x\n",
4581 bios->data[offset + 3], bios->data[offset + 2],
4582 bios->data[offset + 1], bios->data[offset]);
4585 static void parse_script_table_pointers(struct nvbios *bios, uint16_t offset)
4588 * Parses the init table segment for pointers used in script execution.
4590 * offset + 0 (16 bits): init script tables pointer
4591 * offset + 2 (16 bits): macro index table pointer
4592 * offset + 4 (16 bits): macro table pointer
4593 * offset + 6 (16 bits): condition table pointer
4594 * offset + 8 (16 bits): io condition table pointer
4595 * offset + 10 (16 bits): io flag condition table pointer
4596 * offset + 12 (16 bits): init function table pointer
4599 bios->init_script_tbls_ptr = ROM16(bios->data[offset]);
4600 bios->macro_index_tbl_ptr = ROM16(bios->data[offset + 2]);
4601 bios->macro_tbl_ptr = ROM16(bios->data[offset + 4]);
4602 bios->condition_tbl_ptr = ROM16(bios->data[offset + 6]);
4603 bios->io_condition_tbl_ptr = ROM16(bios->data[offset + 8]);
4604 bios->io_flag_condition_tbl_ptr = ROM16(bios->data[offset + 10]);
4605 bios->init_function_tbl_ptr = ROM16(bios->data[offset + 12]);
4608 static int parse_bit_A_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4611 * Parses the load detect values for g80 cards.
4613 * offset + 0 (16 bits): loadval table pointer
4616 uint16_t load_table_ptr;
4617 uint8_t version, headerlen, entrylen, num_entries;
4619 if (bitentry->length != 3) {
4620 NV_ERROR(dev, "Do not understand BIT A table\n");
4624 load_table_ptr = ROM16(bios->data[bitentry->offset]);
4626 if (load_table_ptr == 0x0) {
4627 NV_ERROR(dev, "Pointer to BIT loadval table invalid\n");
4631 version = bios->data[load_table_ptr];
4633 if (version != 0x10) {
4634 NV_ERROR(dev, "BIT loadval table version %d.%d not supported\n",
4635 version >> 4, version & 0xF);
4639 headerlen = bios->data[load_table_ptr + 1];
4640 entrylen = bios->data[load_table_ptr + 2];
4641 num_entries = bios->data[load_table_ptr + 3];
4643 if (headerlen != 4 || entrylen != 4 || num_entries != 2) {
4644 NV_ERROR(dev, "Do not understand BIT loadval table\n");
4648 /* First entry is normal dac, 2nd tv-out perhaps? */
4649 bios->dactestval = ROM32(bios->data[load_table_ptr + headerlen]) & 0x3ff;
4654 static int parse_bit_C_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4657 * offset + 8 (16 bits): PLL limits table pointer
4659 * There's more in here, but that's unknown.
4662 if (bitentry->length < 10) {
4663 NV_ERROR(dev, "Do not understand BIT C table\n");
4667 bios->pll_limit_tbl_ptr = ROM16(bios->data[bitentry->offset + 8]);
4672 static int parse_bit_display_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4675 * Parses the flat panel table segment that the bit entry points to.
4676 * Starting at bitentry->offset:
4678 * offset + 0 (16 bits): ??? table pointer - seems to have 18 byte
4679 * records beginning with a freq.
4680 * offset + 2 (16 bits): mode table pointer
4683 if (bitentry->length != 4) {
4684 NV_ERROR(dev, "Do not understand BIT display table\n");
4688 bios->fp.fptablepointer = ROM16(bios->data[bitentry->offset + 2]);
4693 static int parse_bit_init_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4696 * Parses the init table segment that the bit entry points to.
4698 * See parse_script_table_pointers for layout
4701 if (bitentry->length < 14) {
4702 NV_ERROR(dev, "Do not understand init table\n");
4706 parse_script_table_pointers(bios, bitentry->offset);
4708 if (bitentry->length >= 16)
4709 bios->some_script_ptr = ROM16(bios->data[bitentry->offset + 14]);
4710 if (bitentry->length >= 18)
4711 bios->init96_tbl_ptr = ROM16(bios->data[bitentry->offset + 16]);
4716 static int parse_bit_i_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4719 * BIT 'i' (info?) table
4721 * offset + 0 (32 bits): BIOS version dword (as in B table)
4722 * offset + 5 (8 bits): BIOS feature byte (same as for BMP?)
4723 * offset + 13 (16 bits): pointer to table containing DAC load
4724 * detection comparison values
4726 * There's other things in the table, purpose unknown
4729 uint16_t daccmpoffset;
4730 uint8_t dacver, dacheaderlen;
4732 if (bitentry->length < 6) {
4733 NV_ERROR(dev, "BIT i table too short for needed information\n");
4737 parse_bios_version(dev, bios, bitentry->offset);
4740 * bit 4 seems to indicate a mobile bios (doesn't suffer from BMP's
4741 * Quadro identity crisis), other bits possibly as for BMP feature byte
4743 bios->feature_byte = bios->data[bitentry->offset + 5];
4744 bios->is_mobile = bios->feature_byte & FEATURE_MOBILE;
4746 if (bitentry->length < 15) {
4747 NV_WARN(dev, "BIT i table not long enough for DAC load "
4748 "detection comparison table\n");
4752 daccmpoffset = ROM16(bios->data[bitentry->offset + 13]);
4754 /* doesn't exist on g80 */
4759 * The first value in the table, following the header, is the
4760 * comparison value, the second entry is a comparison value for
4761 * TV load detection.
4764 dacver = bios->data[daccmpoffset];
4765 dacheaderlen = bios->data[daccmpoffset + 1];
4767 if (dacver != 0x00 && dacver != 0x10) {
4768 NV_WARN(dev, "DAC load detection comparison table version "
4769 "%d.%d not known\n", dacver >> 4, dacver & 0xf);
4773 bios->dactestval = ROM32(bios->data[daccmpoffset + dacheaderlen]);
4774 bios->tvdactestval = ROM32(bios->data[daccmpoffset + dacheaderlen + 4]);
4779 static int parse_bit_lvds_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4782 * Parses the LVDS table segment that the bit entry points to.
4783 * Starting at bitentry->offset:
4785 * offset + 0 (16 bits): LVDS strap xlate table pointer
4788 if (bitentry->length != 2) {
4789 NV_ERROR(dev, "Do not understand BIT LVDS table\n");
4794 * No idea if it's still called the LVDS manufacturer table, but
4795 * the concept's close enough.
4797 bios->fp.lvdsmanufacturerpointer = ROM16(bios->data[bitentry->offset]);
4803 parse_bit_M_tbl_entry(struct drm_device *dev, struct nvbios *bios,
4804 struct bit_entry *bitentry)
4807 * offset + 2 (8 bits): number of options in an
4808 * INIT_RAM_RESTRICT_ZM_REG_GROUP opcode option set
4809 * offset + 3 (16 bits): pointer to strap xlate table for RAM
4810 * restrict option selection
4812 * There's a bunch of bits in this table other than the RAM restrict
4813 * stuff that we don't use - their use currently unknown
4817 * Older bios versions don't have a sufficiently long table for
4820 if (bitentry->length < 0x5)
4823 if (bitentry->id[1] < 2) {
4824 bios->ram_restrict_group_count = bios->data[bitentry->offset + 2];
4825 bios->ram_restrict_tbl_ptr = ROM16(bios->data[bitentry->offset + 3]);
4827 bios->ram_restrict_group_count = bios->data[bitentry->offset + 0];
4828 bios->ram_restrict_tbl_ptr = ROM16(bios->data[bitentry->offset + 1]);
4834 static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios, struct bit_entry *bitentry)
4837 * Parses the pointer to the TMDS table
4839 * Starting at bitentry->offset:
4841 * offset + 0 (16 bits): TMDS table pointer
4843 * The TMDS table is typically found just before the DCB table, with a
4844 * characteristic signature of 0x11,0x13 (1.1 being version, 0x13 being
4847 * At offset +7 is a pointer to a script, which I don't know how to
4849 * At offset +9 is a pointer to another script, likewise
4850 * Offset +11 has a pointer to a table where the first word is a pxclk
4851 * frequency and the second word a pointer to a script, which should be
4852 * run if the comparison pxclk frequency is less than the pxclk desired.
4853 * This repeats for decreasing comparison frequencies
4854 * Offset +13 has a pointer to a similar table
4855 * The selection of table (and possibly +7/+9 script) is dictated by
4856 * "or" from the DCB.
4859 uint16_t tmdstableptr, script1, script2;
4861 if (bitentry->length != 2) {
4862 NV_ERROR(dev, "Do not understand BIT TMDS table\n");
4866 tmdstableptr = ROM16(bios->data[bitentry->offset]);
4868 if (tmdstableptr == 0x0) {
4869 NV_ERROR(dev, "Pointer to TMDS table invalid\n");
4873 /* nv50+ has v2.0, but we don't parse it atm */
4874 if (bios->data[tmdstableptr] != 0x11) {
4876 "TMDS table revision %d.%d not currently supported\n",
4877 bios->data[tmdstableptr] >> 4, bios->data[tmdstableptr] & 0xf);
4882 * These two scripts are odd: they don't seem to get run even when
4883 * they are not stubbed.
4885 script1 = ROM16(bios->data[tmdstableptr + 7]);
4886 script2 = ROM16(bios->data[tmdstableptr + 9]);
4887 if (bios->data[script1] != 'q' || bios->data[script2] != 'q')
4888 NV_WARN(dev, "TMDS table script pointers not stubbed\n");
4890 bios->tmds.output0_script_ptr = ROM16(bios->data[tmdstableptr + 11]);
4891 bios->tmds.output1_script_ptr = ROM16(bios->data[tmdstableptr + 13]);
4897 parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
4898 struct bit_entry *bitentry)
4901 * Parses the pointer to the G80 output script tables
4903 * Starting at bitentry->offset:
4905 * offset + 0 (16 bits): output script table pointer
4908 uint16_t outputscripttableptr;
4910 if (bitentry->length != 3) {
4911 NV_ERROR(dev, "Do not understand BIT U table\n");
4915 outputscripttableptr = ROM16(bios->data[bitentry->offset]);
4916 bios->display.script_table_ptr = outputscripttableptr;
4921 parse_bit_displayport_tbl_entry(struct drm_device *dev, struct nvbios *bios,
4922 struct bit_entry *bitentry)
4924 bios->display.dp_table_ptr = ROM16(bios->data[bitentry->offset]);
4930 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
4933 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
4936 parse_bit_table(struct nvbios *bios, const uint16_t bitoffset,
4937 struct bit_table *table)
4939 struct drm_device *dev = bios->dev;
4940 uint8_t maxentries = bios->data[bitoffset + 4];
4942 struct bit_entry bitentry;
4944 for (i = 0, offset = bitoffset + 6; i < maxentries; i++, offset += 6) {
4945 bitentry.id[0] = bios->data[offset];
4947 if (bitentry.id[0] != table->id)
4950 bitentry.id[1] = bios->data[offset + 1];
4951 bitentry.length = ROM16(bios->data[offset + 2]);
4952 bitentry.offset = ROM16(bios->data[offset + 4]);
4954 return table->parse_fn(dev, bios, &bitentry);
4957 NV_INFO(dev, "BIT table '%c' not found\n", table->id);
4962 parse_bit_structure(struct nvbios *bios, const uint16_t bitoffset)
4967 * The only restriction on parsing order currently is having 'i' first
4968 * for use of bios->*_version or bios->feature_byte while parsing;
4969 * functions shouldn't be actually *doing* anything apart from pulling
4970 * data from the image into the bios struct, thus no interdependencies
4972 ret = parse_bit_table(bios, bitoffset, &BIT_TABLE('i', i));
4973 if (ret) /* info? */
4975 if (bios->major_version >= 0x60) /* g80+ */
4976 parse_bit_table(bios, bitoffset, &BIT_TABLE('A', A));
4977 ret = parse_bit_table(bios, bitoffset, &BIT_TABLE('C', C));
4980 parse_bit_table(bios, bitoffset, &BIT_TABLE('D', display));
4981 ret = parse_bit_table(bios, bitoffset, &BIT_TABLE('I', init));
4984 parse_bit_table(bios, bitoffset, &BIT_TABLE('M', M)); /* memory? */
4985 parse_bit_table(bios, bitoffset, &BIT_TABLE('L', lvds));
4986 parse_bit_table(bios, bitoffset, &BIT_TABLE('T', tmds));
4987 parse_bit_table(bios, bitoffset, &BIT_TABLE('U', U));
4988 parse_bit_table(bios, bitoffset, &BIT_TABLE('d', displayport));
4993 static int parse_bmp_structure(struct drm_device *dev, struct nvbios *bios, unsigned int offset)
4996 * Parses the BMP structure for useful things, but does not act on them
4998 * offset + 5: BMP major version
4999 * offset + 6: BMP minor version
5000 * offset + 9: BMP feature byte
5001 * offset + 10: BCD encoded BIOS version
5003 * offset + 18: init script table pointer (for bios versions < 5.10h)
5004 * offset + 20: extra init script table pointer (for bios
5007 * offset + 24: memory init table pointer (used on early bios versions)
5008 * offset + 26: SDR memory sequencing setup data table
5009 * offset + 28: DDR memory sequencing setup data table
5011 * offset + 54: index of I2C CRTC pair to use for CRT output
5012 * offset + 55: index of I2C CRTC pair to use for TV output
5013 * offset + 56: index of I2C CRTC pair to use for flat panel output
5014 * offset + 58: write CRTC index for I2C pair 0
5015 * offset + 59: read CRTC index for I2C pair 0
5016 * offset + 60: write CRTC index for I2C pair 1
5017 * offset + 61: read CRTC index for I2C pair 1
5019 * offset + 67: maximum internal PLL frequency (single stage PLL)
5020 * offset + 71: minimum internal PLL frequency (single stage PLL)
5022 * offset + 75: script table pointers, as described in
5023 * parse_script_table_pointers
5025 * offset + 89: TMDS single link output A table pointer
5026 * offset + 91: TMDS single link output B table pointer
5027 * offset + 95: LVDS single link output A table pointer
5028 * offset + 105: flat panel timings table pointer
5029 * offset + 107: flat panel strapping translation table pointer
5030 * offset + 117: LVDS manufacturer panel config table pointer
5031 * offset + 119: LVDS manufacturer strapping translation table pointer
5033 * offset + 142: PLL limits table pointer
5035 * offset + 156: minimum pixel clock for LVDS dual link
5038 uint8_t *bmp = &bios->data[offset], bmp_version_major, bmp_version_minor;
5040 uint16_t legacy_scripts_offset, legacy_i2c_offset;
5042 /* load needed defaults in case we can't parse this info */
5043 bios->dcb.i2c[0].write = NV_CIO_CRE_DDC_WR__INDEX;
5044 bios->dcb.i2c[0].read = NV_CIO_CRE_DDC_STATUS__INDEX;
5045 bios->dcb.i2c[1].write = NV_CIO_CRE_DDC0_WR__INDEX;
5046 bios->dcb.i2c[1].read = NV_CIO_CRE_DDC0_STATUS__INDEX;
5047 bios->digital_min_front_porch = 0x4b;
5048 bios->fmaxvco = 256000;
5049 bios->fminvco = 128000;
5050 bios->fp.duallink_transition_clk = 90000;
5052 bmp_version_major = bmp[5];
5053 bmp_version_minor = bmp[6];
5055 NV_TRACE(dev, "BMP version %d.%d\n",
5056 bmp_version_major, bmp_version_minor);
5059 * Make sure that 0x36 is blank and can't be mistaken for a DCB
5060 * pointer on early versions
5062 if (bmp_version_major < 5)
5063 *(uint16_t *)&bios->data[0x36] = 0;
5066 * Seems that the minor version was 1 for all major versions prior
5067 * to 5. Version 6 could theoretically exist, but I suspect BIT
5070 if ((bmp_version_major < 5 && bmp_version_minor != 1) || bmp_version_major > 5) {
5071 NV_ERROR(dev, "You have an unsupported BMP version. "
5072 "Please send in your bios\n");
5076 if (bmp_version_major == 0)
5077 /* nothing that's currently useful in this version */
5079 else if (bmp_version_major == 1)
5080 bmplength = 44; /* exact for 1.01 */
5081 else if (bmp_version_major == 2)
5082 bmplength = 48; /* exact for 2.01 */
5083 else if (bmp_version_major == 3)
5085 /* guessed - mem init tables added in this version */
5086 else if (bmp_version_major == 4 || bmp_version_minor < 0x1)
5087 /* don't know if 5.0 exists... */
5089 /* guessed - BMP I2C indices added in version 4*/
5090 else if (bmp_version_minor < 0x6)
5091 bmplength = 67; /* exact for 5.01 */
5092 else if (bmp_version_minor < 0x10)
5093 bmplength = 75; /* exact for 5.06 */
5094 else if (bmp_version_minor == 0x10)
5095 bmplength = 89; /* exact for 5.10h */
5096 else if (bmp_version_minor < 0x14)
5097 bmplength = 118; /* exact for 5.11h */
5098 else if (bmp_version_minor < 0x24)
5100 * Not sure of version where pll limits came in;
5101 * certainly exist by 0x24 though.
5103 /* length not exact: this is long enough to get lvds members */
5105 else if (bmp_version_minor < 0x27)
5107 * Length not exact: this is long enough to get pll limit
5113 * Length not exact: this is long enough to get dual link
5119 if (nv_cksum(bmp, 8)) {
5120 NV_ERROR(dev, "Bad BMP checksum\n");
5125 * Bit 4 seems to indicate either a mobile bios or a quadro card --
5126 * mobile behaviour consistent (nv11+), quadro only seen nv18gl-nv36gl
5127 * (not nv10gl), bit 5 that the flat panel tables are present, and
5130 bios->feature_byte = bmp[9];
5132 parse_bios_version(dev, bios, offset + 10);
5134 if (bmp_version_major < 5 || bmp_version_minor < 0x10)
5135 bios->old_style_init = true;
5136 legacy_scripts_offset = 18;
5137 if (bmp_version_major < 2)
5138 legacy_scripts_offset -= 4;
5139 bios->init_script_tbls_ptr = ROM16(bmp[legacy_scripts_offset]);
5140 bios->extra_init_script_tbl_ptr = ROM16(bmp[legacy_scripts_offset + 2]);
5142 if (bmp_version_major > 2) { /* appears in BMP 3 */
5143 bios->legacy.mem_init_tbl_ptr = ROM16(bmp[24]);
5144 bios->legacy.sdr_seq_tbl_ptr = ROM16(bmp[26]);
5145 bios->legacy.ddr_seq_tbl_ptr = ROM16(bmp[28]);
5148 legacy_i2c_offset = 0x48; /* BMP version 2 & 3 */
5150 legacy_i2c_offset = offset + 54;
5151 bios->legacy.i2c_indices.crt = bios->data[legacy_i2c_offset];
5152 bios->legacy.i2c_indices.tv = bios->data[legacy_i2c_offset + 1];
5153 bios->legacy.i2c_indices.panel = bios->data[legacy_i2c_offset + 2];
5154 bios->dcb.i2c[0].write = bios->data[legacy_i2c_offset + 4];
5155 bios->dcb.i2c[0].read = bios->data[legacy_i2c_offset + 5];
5156 bios->dcb.i2c[1].write = bios->data[legacy_i2c_offset + 6];
5157 bios->dcb.i2c[1].read = bios->data[legacy_i2c_offset + 7];
5159 if (bmplength > 74) {
5160 bios->fmaxvco = ROM32(bmp[67]);
5161 bios->fminvco = ROM32(bmp[71]);
5164 parse_script_table_pointers(bios, offset + 75);
5165 if (bmplength > 94) {
5166 bios->tmds.output0_script_ptr = ROM16(bmp[89]);
5167 bios->tmds.output1_script_ptr = ROM16(bmp[91]);
5169 * Never observed in use with lvds scripts, but is reused for
5170 * 18/24 bit panel interface default for EDID equipped panels
5171 * (if_is_24bit not set directly to avoid any oscillation).
5173 bios->legacy.lvds_single_a_script_ptr = ROM16(bmp[95]);
5175 if (bmplength > 108) {
5176 bios->fp.fptablepointer = ROM16(bmp[105]);
5177 bios->fp.fpxlatetableptr = ROM16(bmp[107]);
5178 bios->fp.xlatwidth = 1;
5180 if (bmplength > 120) {
5181 bios->fp.lvdsmanufacturerpointer = ROM16(bmp[117]);
5182 bios->fp.fpxlatemanufacturertableptr = ROM16(bmp[119]);
5184 if (bmplength > 143)
5185 bios->pll_limit_tbl_ptr = ROM16(bmp[142]);
5187 if (bmplength > 157)
5188 bios->fp.duallink_transition_clk = ROM16(bmp[156]) * 10;
5193 static uint16_t findstr(uint8_t *data, int n, const uint8_t *str, int len)
5197 for (i = 0; i <= (n - len); i++) {
5198 for (j = 0; j < len; j++)
5199 if (data[i + j] != str[j])
5208 static struct dcb_gpio_entry *
5209 new_gpio_entry(struct nvbios *bios)
5211 struct dcb_gpio_table *gpio = &bios->dcb.gpio;
5213 return &gpio->entry[gpio->entries++];
5216 struct dcb_gpio_entry *
5217 nouveau_bios_gpio_entry(struct drm_device *dev, enum dcb_gpio_tag tag)
5219 struct drm_nouveau_private *dev_priv = dev->dev_private;
5220 struct nvbios *bios = &dev_priv->vbios;
5223 for (i = 0; i < bios->dcb.gpio.entries; i++) {
5224 if (bios->dcb.gpio.entry[i].tag != tag)
5227 return &bios->dcb.gpio.entry[i];
5234 parse_dcb30_gpio_entry(struct nvbios *bios, uint16_t offset)
5236 struct dcb_gpio_entry *gpio;
5237 uint16_t ent = ROM16(bios->data[offset]);
5238 uint8_t line = ent & 0x1f,
5239 tag = ent >> 5 & 0x3f,
5240 flags = ent >> 11 & 0x1f;
5245 gpio = new_gpio_entry(bios);
5249 gpio->invert = flags != 4;
5254 parse_dcb40_gpio_entry(struct nvbios *bios, uint16_t offset)
5256 uint32_t entry = ROM32(bios->data[offset]);
5257 struct dcb_gpio_entry *gpio;
5259 if ((entry & 0x0000ff00) == 0x0000ff00)
5262 gpio = new_gpio_entry(bios);
5263 gpio->tag = (entry & 0x0000ff00) >> 8;
5264 gpio->line = (entry & 0x0000001f) >> 0;
5265 gpio->state_default = (entry & 0x01000000) >> 24;
5266 gpio->state[0] = (entry & 0x18000000) >> 27;
5267 gpio->state[1] = (entry & 0x60000000) >> 29;
5268 gpio->entry = entry;
5272 parse_dcb_gpio_table(struct nvbios *bios)
5274 struct drm_device *dev = bios->dev;
5275 uint16_t gpio_table_ptr = bios->dcb.gpio_table_ptr;
5276 uint8_t *gpio_table = &bios->data[gpio_table_ptr];
5277 int header_len = gpio_table[1],
5278 entries = gpio_table[2],
5279 entry_len = gpio_table[3];
5280 void (*parse_entry)(struct nvbios *, uint16_t) = NULL;
5283 if (bios->dcb.version >= 0x40) {
5284 if (gpio_table_ptr && entry_len != 4) {
5285 NV_WARN(dev, "Invalid DCB GPIO table entry length.\n");
5289 parse_entry = parse_dcb40_gpio_entry;
5291 } else if (bios->dcb.version >= 0x30) {
5292 if (gpio_table_ptr && entry_len != 2) {
5293 NV_WARN(dev, "Invalid DCB GPIO table entry length.\n");
5297 parse_entry = parse_dcb30_gpio_entry;
5299 } else if (bios->dcb.version >= 0x22) {
5301 * DCBs older than v3.0 don't really have a GPIO
5302 * table, instead they keep some GPIO info at fixed
5305 uint16_t dcbptr = ROM16(bios->data[0x36]);
5306 uint8_t *tvdac_gpio = &bios->data[dcbptr - 5];
5308 if (tvdac_gpio[0] & 1) {
5309 struct dcb_gpio_entry *gpio = new_gpio_entry(bios);
5311 gpio->tag = DCB_GPIO_TVDAC0;
5312 gpio->line = tvdac_gpio[1] >> 4;
5313 gpio->invert = tvdac_gpio[0] & 2;
5317 if (!gpio_table_ptr)
5320 if (entries > DCB_MAX_NUM_GPIO_ENTRIES) {
5321 NV_WARN(dev, "Too many entries in the DCB GPIO table.\n");
5322 entries = DCB_MAX_NUM_GPIO_ENTRIES;
5325 for (i = 0; i < entries; i++)
5326 parse_entry(bios, gpio_table_ptr + header_len + entry_len * i);
5329 struct dcb_connector_table_entry *
5330 nouveau_bios_connector_entry(struct drm_device *dev, int index)
5332 struct drm_nouveau_private *dev_priv = dev->dev_private;
5333 struct nvbios *bios = &dev_priv->vbios;
5334 struct dcb_connector_table_entry *cte;
5336 if (index >= bios->dcb.connector.entries)
5339 cte = &bios->dcb.connector.entry[index];
5340 if (cte->type == 0xff)
5346 static enum dcb_connector_type
5347 divine_connector_type(struct nvbios *bios, int index)
5349 struct dcb_table *dcb = &bios->dcb;
5350 unsigned encoders = 0, type = DCB_CONNECTOR_NONE;
5353 for (i = 0; i < dcb->entries; i++) {
5354 if (dcb->entry[i].connector == index)
5355 encoders |= (1 << dcb->entry[i].type);
5358 if (encoders & (1 << OUTPUT_DP)) {
5359 if (encoders & (1 << OUTPUT_TMDS))
5360 type = DCB_CONNECTOR_DP;
5362 type = DCB_CONNECTOR_eDP;
5364 if (encoders & (1 << OUTPUT_TMDS)) {
5365 if (encoders & (1 << OUTPUT_ANALOG))
5366 type = DCB_CONNECTOR_DVI_I;
5368 type = DCB_CONNECTOR_DVI_D;
5370 if (encoders & (1 << OUTPUT_ANALOG)) {
5371 type = DCB_CONNECTOR_VGA;
5373 if (encoders & (1 << OUTPUT_LVDS)) {
5374 type = DCB_CONNECTOR_LVDS;
5376 if (encoders & (1 << OUTPUT_TV)) {
5377 type = DCB_CONNECTOR_TV_0;
5384 apply_dcb_connector_quirks(struct nvbios *bios, int idx)
5386 struct dcb_connector_table_entry *cte = &bios->dcb.connector.entry[idx];
5387 struct drm_device *dev = bios->dev;
5389 /* Gigabyte NX85T */
5390 if ((dev->pdev->device == 0x0421) &&
5391 (dev->pdev->subsystem_vendor == 0x1458) &&
5392 (dev->pdev->subsystem_device == 0x344c)) {
5393 if (cte->type == DCB_CONNECTOR_HDMI_1)
5394 cte->type = DCB_CONNECTOR_DVI_I;
5399 parse_dcb_connector_table(struct nvbios *bios)
5401 struct drm_device *dev = bios->dev;
5402 struct dcb_connector_table *ct = &bios->dcb.connector;
5403 struct dcb_connector_table_entry *cte;
5404 uint8_t *conntab = &bios->data[bios->dcb.connector_table_ptr];
5408 if (!bios->dcb.connector_table_ptr) {
5409 NV_DEBUG_KMS(dev, "No DCB connector table present\n");
5413 NV_INFO(dev, "DCB connector table: VHER 0x%02x %d %d %d\n",
5414 conntab[0], conntab[1], conntab[2], conntab[3]);
5415 if ((conntab[0] != 0x30 && conntab[0] != 0x40) ||
5416 (conntab[3] != 2 && conntab[3] != 4)) {
5417 NV_ERROR(dev, " Unknown! Please report.\n");
5421 ct->entries = conntab[2];
5423 entry = conntab + conntab[1];
5424 cte = &ct->entry[0];
5425 for (i = 0; i < conntab[2]; i++, entry += conntab[3], cte++) {
5427 if (conntab[3] == 2)
5428 cte->entry = ROM16(entry[0]);
5430 cte->entry = ROM32(entry[0]);
5432 cte->type = (cte->entry & 0x000000ff) >> 0;
5433 cte->index2 = (cte->entry & 0x00000f00) >> 8;
5434 switch (cte->entry & 0x00033000) {
5436 cte->gpio_tag = 0x07;
5439 cte->gpio_tag = 0x08;
5442 cte->gpio_tag = 0x51;
5445 cte->gpio_tag = 0x52;
5448 cte->gpio_tag = 0xff;
5452 if (cte->type == 0xff)
5455 apply_dcb_connector_quirks(bios, i);
5457 NV_INFO(dev, " %d: 0x%08x: type 0x%02x idx %d tag 0x%02x\n",
5458 i, cte->entry, cte->type, cte->index, cte->gpio_tag);
5460 /* check for known types, fallback to guessing the type
5461 * from attached encoders if we hit an unknown.
5463 switch (cte->type) {
5464 case DCB_CONNECTOR_VGA:
5465 case DCB_CONNECTOR_TV_0:
5466 case DCB_CONNECTOR_TV_1:
5467 case DCB_CONNECTOR_TV_3:
5468 case DCB_CONNECTOR_DVI_I:
5469 case DCB_CONNECTOR_DVI_D:
5470 case DCB_CONNECTOR_LVDS:
5471 case DCB_CONNECTOR_DP:
5472 case DCB_CONNECTOR_eDP:
5473 case DCB_CONNECTOR_HDMI_0:
5474 case DCB_CONNECTOR_HDMI_1:
5477 cte->type = divine_connector_type(bios, cte->index);
5478 NV_WARN(dev, "unknown type, using 0x%02x\n", cte->type);
5482 if (nouveau_override_conntype) {
5483 int type = divine_connector_type(bios, cte->index);
5484 if (type != cte->type)
5485 NV_WARN(dev, " -> type 0x%02x\n", cte->type);
5491 static struct dcb_entry *new_dcb_entry(struct dcb_table *dcb)
5493 struct dcb_entry *entry = &dcb->entry[dcb->entries];
5495 memset(entry, 0, sizeof(struct dcb_entry));
5496 entry->index = dcb->entries++;
5501 static void fabricate_vga_output(struct dcb_table *dcb, int i2c, int heads)
5503 struct dcb_entry *entry = new_dcb_entry(dcb);
5506 entry->i2c_index = i2c;
5507 entry->heads = heads;
5508 entry->location = DCB_LOC_ON_CHIP;
5509 /* "or" mostly unused in early gen crt modesetting, 0 is fine */
5512 static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads)
5514 struct dcb_entry *entry = new_dcb_entry(dcb);
5517 entry->i2c_index = LEGACY_I2C_PANEL;
5518 entry->heads = twoHeads ? 3 : 1;
5519 entry->location = !DCB_LOC_ON_CHIP; /* ie OFF CHIP */
5520 entry->or = 1; /* means |0x10 gets set on CRE_LCD__INDEX */
5521 entry->duallink_possible = false; /* SiI164 and co. are single link */
5525 * For dvi-a either crtc probably works, but my card appears to only
5526 * support dvi-d. "nvidia" still attempts to program it for dvi-a,
5527 * doing the full fp output setup (program 0x6808.. fp dimension regs,
5528 * setting 0x680848 to 0x10000111 to enable, maybe setting 0x680880);
5529 * the monitor picks up the mode res ok and lights up, but no pixel
5530 * data appears, so the board manufacturer probably connected up the
5531 * sync lines, but missed the video traces / components
5533 * with this introduction, dvi-a left as an exercise for the reader.
5535 fabricate_vga_output(dcb, LEGACY_I2C_PANEL, entry->heads);
5539 static void fabricate_tv_output(struct dcb_table *dcb, bool twoHeads)
5541 struct dcb_entry *entry = new_dcb_entry(dcb);
5544 entry->i2c_index = LEGACY_I2C_TV;
5545 entry->heads = twoHeads ? 3 : 1;
5546 entry->location = !DCB_LOC_ON_CHIP; /* ie OFF CHIP */
5550 parse_dcb20_entry(struct drm_device *dev, struct dcb_table *dcb,
5551 uint32_t conn, uint32_t conf, struct dcb_entry *entry)
5553 entry->type = conn & 0xf;
5554 entry->i2c_index = (conn >> 4) & 0xf;
5555 entry->heads = (conn >> 8) & 0xf;
5556 if (dcb->version >= 0x40)
5557 entry->connector = (conn >> 12) & 0xf;
5558 entry->bus = (conn >> 16) & 0xf;
5559 entry->location = (conn >> 20) & 0x3;
5560 entry->or = (conn >> 24) & 0xf;
5562 switch (entry->type) {
5565 * Although the rest of a CRT conf dword is usually
5566 * zeros, mac biosen have stuff there so we must mask
5568 entry->crtconf.maxfreq = (dcb->version < 0x30) ?
5569 (conf & 0xffff) * 10 :
5570 (conf & 0xff) * 10000;
5576 entry->lvdsconf.use_straps_for_mode = true;
5577 if (dcb->version < 0x22) {
5580 * The laptop in bug 14567 lies and claims to not use
5581 * straps when it does, so assume all DCB 2.0 laptops
5582 * use straps, until a broken EDID using one is produced
5584 entry->lvdsconf.use_straps_for_mode = true;
5586 * Both 0x4 and 0x8 show up in v2.0 tables; assume they
5587 * mean the same thing (probably wrong, but might work)
5589 if (conf & 0x4 || conf & 0x8)
5590 entry->lvdsconf.use_power_scripts = true;
5594 entry->lvdsconf.use_power_scripts = true;
5598 * Until we even try to use these on G8x, it's
5599 * useless reporting unknown bits. They all are.
5601 if (dcb->version >= 0x40)
5604 NV_ERROR(dev, "Unknown LVDS configuration bits, "
5611 if (dcb->version >= 0x30)
5612 entry->tvconf.has_component_output = conf & (0x8 << 4);
5614 entry->tvconf.has_component_output = false;
5619 entry->dpconf.sor.link = (conf & 0x00000030) >> 4;
5620 entry->dpconf.link_bw = (conf & 0x00e00000) >> 21;
5621 switch ((conf & 0x0f000000) >> 24) {
5623 entry->dpconf.link_nr = 4;
5626 entry->dpconf.link_nr = 2;
5629 entry->dpconf.link_nr = 1;
5634 entry->tmdsconf.sor.link = (conf & 0x00000030) >> 4;
5637 /* weird g80 mobile type that "nv" treats as a terminator */
5644 if (dcb->version < 0x40) {
5645 /* Normal entries consist of a single bit, but dual link has
5646 * the next most significant bit set too
5648 entry->duallink_possible =
5649 ((1 << (ffs(entry->or) - 1)) * 3 == entry->or);
5651 entry->duallink_possible = (entry->sorconf.link == 3);
5654 /* unsure what DCB version introduces this, 3.0? */
5655 if (conf & 0x100000)
5656 entry->i2c_upper_default = true;
5662 parse_dcb15_entry(struct drm_device *dev, struct dcb_table *dcb,
5663 uint32_t conn, uint32_t conf, struct dcb_entry *entry)
5665 switch (conn & 0x0000000f) {
5667 entry->type = OUTPUT_ANALOG;
5670 entry->type = OUTPUT_TV;
5674 entry->type = OUTPUT_LVDS;
5677 switch ((conn & 0x000000f0) >> 4) {
5679 entry->type = OUTPUT_TMDS;
5682 entry->type = OUTPUT_LVDS;
5685 NV_ERROR(dev, "Unknown DCB subtype 4/%d\n",
5686 (conn & 0x000000f0) >> 4);
5691 NV_ERROR(dev, "Unknown DCB type %d\n", conn & 0x0000000f);
5695 entry->i2c_index = (conn & 0x0003c000) >> 14;
5696 entry->heads = ((conn & 0x001c0000) >> 18) + 1;
5697 entry->or = entry->heads; /* same as heads, hopefully safe enough */
5698 entry->location = (conn & 0x01e00000) >> 21;
5699 entry->bus = (conn & 0x0e000000) >> 25;
5700 entry->duallink_possible = false;
5702 switch (entry->type) {
5704 entry->crtconf.maxfreq = (conf & 0xffff) * 10;
5707 entry->tvconf.has_component_output = false;
5711 * Invent a DVI-A output, by copying the fields of the DVI-D
5712 * output; reported to work by math_b on an NV20(!).
5714 fabricate_vga_output(dcb, entry->i2c_index, entry->heads);
5717 if ((conn & 0x00003f00) != 0x10)
5718 entry->lvdsconf.use_straps_for_mode = true;
5719 entry->lvdsconf.use_power_scripts = true;
5728 static bool parse_dcb_entry(struct drm_device *dev, struct dcb_table *dcb,
5729 uint32_t conn, uint32_t conf)
5731 struct dcb_entry *entry = new_dcb_entry(dcb);
5734 if (dcb->version >= 0x20)
5735 ret = parse_dcb20_entry(dev, dcb, conn, conf, entry);
5737 ret = parse_dcb15_entry(dev, dcb, conn, conf, entry);
5741 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
5742 entry->i2c_index, &dcb->i2c[entry->i2c_index]);
5748 void merge_like_dcb_entries(struct drm_device *dev, struct dcb_table *dcb)
5751 * DCB v2.0 lists each output combination separately.
5752 * Here we merge compatible entries to have fewer outputs, with
5756 int i, newentries = 0;
5758 for (i = 0; i < dcb->entries; i++) {
5759 struct dcb_entry *ient = &dcb->entry[i];
5762 for (j = i + 1; j < dcb->entries; j++) {
5763 struct dcb_entry *jent = &dcb->entry[j];
5765 if (jent->type == 100) /* already merged entry */
5768 /* merge heads field when all other fields the same */
5769 if (jent->i2c_index == ient->i2c_index &&
5770 jent->type == ient->type &&
5771 jent->location == ient->location &&
5772 jent->or == ient->or) {
5773 NV_TRACE(dev, "Merging DCB entries %d and %d\n",
5775 ient->heads |= jent->heads;
5776 jent->type = 100; /* dummy value */
5781 /* Compact entries merged into others out of dcb */
5782 for (i = 0; i < dcb->entries; i++) {
5783 if (dcb->entry[i].type == 100)
5786 if (newentries != i) {
5787 dcb->entry[newentries] = dcb->entry[i];
5788 dcb->entry[newentries].index = newentries;
5793 dcb->entries = newentries;
5797 parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads)
5799 struct drm_nouveau_private *dev_priv = dev->dev_private;
5800 struct dcb_table *dcb = &bios->dcb;
5801 uint16_t dcbptr = 0, i2ctabptr = 0;
5803 uint8_t headerlen = 0x4, entries = DCB_MAX_NUM_ENTRIES;
5804 bool configblock = true;
5805 int recordlength = 8, confofs = 4;
5808 /* get the offset from 0x36 */
5809 if (dev_priv->card_type > NV_04) {
5810 dcbptr = ROM16(bios->data[0x36]);
5811 if (dcbptr == 0x0000)
5812 NV_WARN(dev, "No output data (DCB) found in BIOS\n");
5815 /* this situation likely means a really old card, pre DCB */
5816 if (dcbptr == 0x0) {
5817 NV_INFO(dev, "Assuming a CRT output exists\n");
5818 fabricate_vga_output(dcb, LEGACY_I2C_CRT, 1);
5820 if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >= 0)
5821 fabricate_tv_output(dcb, twoHeads);
5826 dcbtable = &bios->data[dcbptr];
5828 /* get DCB version */
5829 dcb->version = dcbtable[0];
5830 NV_TRACE(dev, "Found Display Configuration Block version %d.%d\n",
5831 dcb->version >> 4, dcb->version & 0xf);
5833 if (dcb->version >= 0x20) { /* NV17+ */
5836 if (dcb->version >= 0x30) { /* NV40+ */
5837 headerlen = dcbtable[1];
5838 entries = dcbtable[2];
5839 recordlength = dcbtable[3];
5840 i2ctabptr = ROM16(dcbtable[4]);
5841 sig = ROM32(dcbtable[6]);
5842 dcb->gpio_table_ptr = ROM16(dcbtable[10]);
5843 dcb->connector_table_ptr = ROM16(dcbtable[20]);
5845 i2ctabptr = ROM16(dcbtable[2]);
5846 sig = ROM32(dcbtable[4]);
5850 if (sig != 0x4edcbdcb) {
5851 NV_ERROR(dev, "Bad Display Configuration Block "
5852 "signature (%08X)\n", sig);
5855 } else if (dcb->version >= 0x15) { /* some NV11 and NV20 */
5856 char sig[8] = { 0 };
5858 strncpy(sig, (char *)&dcbtable[-7], 7);
5859 i2ctabptr = ROM16(dcbtable[2]);
5863 if (strcmp(sig, "DEV_REC")) {
5864 NV_ERROR(dev, "Bad Display Configuration Block "
5865 "signature (%s)\n", sig);
5870 * v1.4 (some NV15/16, NV11+) seems the same as v1.5, but always
5871 * has the same single (crt) entry, even when tv-out present, so
5872 * the conclusion is this version cannot really be used.
5873 * v1.2 tables (some NV6/10, and NV15+) normally have the same
5874 * 5 entries, which are not specific to the card and so no use.
5875 * v1.2 does have an I2C table that read_dcb_i2c_table can
5876 * handle, but cards exist (nv11 in #14821) with a bad i2c table
5877 * pointer, so use the indices parsed in parse_bmp_structure.
5878 * v1.1 (NV5+, maybe some NV4) is entirely unhelpful
5880 NV_TRACEWARN(dev, "No useful information in BIOS output table; "
5881 "adding all possible outputs\n");
5882 fabricate_vga_output(dcb, LEGACY_I2C_CRT, 1);
5885 * Attempt to detect TV before DVI because the test
5886 * for the former is more accurate and it rules the
5889 if (nv04_tv_identify(dev,
5890 bios->legacy.i2c_indices.tv) >= 0)
5891 fabricate_tv_output(dcb, twoHeads);
5893 else if (bios->tmds.output0_script_ptr ||
5894 bios->tmds.output1_script_ptr)
5895 fabricate_dvi_i_output(dcb, twoHeads);
5901 NV_WARN(dev, "No pointer to DCB I2C port table\n");
5903 dcb->i2c_table = &bios->data[i2ctabptr];
5904 if (dcb->version >= 0x30)
5905 dcb->i2c_default_indices = dcb->i2c_table[4];
5908 if (entries > DCB_MAX_NUM_ENTRIES)
5909 entries = DCB_MAX_NUM_ENTRIES;
5911 for (i = 0; i < entries; i++) {
5912 uint32_t connection, config = 0;
5914 connection = ROM32(dcbtable[headerlen + recordlength * i]);
5916 config = ROM32(dcbtable[headerlen + confofs + recordlength * i]);
5918 /* seen on an NV11 with DCB v1.5 */
5919 if (connection == 0x00000000)
5922 /* seen on an NV17 with DCB v2.0 */
5923 if (connection == 0xffffffff)
5926 if ((connection & 0x0000000f) == 0x0000000f)
5929 NV_TRACEWARN(dev, "Raw DCB entry %d: %08x %08x\n",
5930 dcb->entries, connection, config);
5932 if (!parse_dcb_entry(dev, dcb, connection, config))
5937 * apart for v2.1+ not being known for requiring merging, this
5938 * guarantees dcbent->index is the index of the entry in the rom image
5940 if (dcb->version < 0x21)
5941 merge_like_dcb_entries(dev, dcb);
5946 parse_dcb_gpio_table(bios);
5947 parse_dcb_connector_table(bios);
5952 fixup_legacy_connector(struct nvbios *bios)
5954 struct dcb_table *dcb = &bios->dcb;
5955 int i, i2c, i2c_conn[DCB_MAX_NUM_I2C_ENTRIES] = { };
5958 * DCB 3.0 also has the table in most cases, but there are some cards
5959 * where the table is filled with stub entries, and the DCB entriy
5960 * indices are all 0. We don't need the connector indices on pre-G80
5961 * chips (yet?) so limit the use to DCB 4.0 and above.
5963 if (dcb->version >= 0x40)
5966 dcb->connector.entries = 0;
5969 * No known connector info before v3.0, so make it up. the rule here
5970 * is: anything on the same i2c bus is considered to be on the same
5971 * connector. any output without an associated i2c bus is assigned
5972 * its own unique connector index.
5974 for (i = 0; i < dcb->entries; i++) {
5976 * Ignore the I2C index for on-chip TV-out, as there
5977 * are cards with bogus values (nv31m in bug 23212),
5978 * and it's otherwise useless.
5980 if (dcb->entry[i].type == OUTPUT_TV &&
5981 dcb->entry[i].location == DCB_LOC_ON_CHIP)
5982 dcb->entry[i].i2c_index = 0xf;
5983 i2c = dcb->entry[i].i2c_index;
5985 if (i2c_conn[i2c]) {
5986 dcb->entry[i].connector = i2c_conn[i2c] - 1;
5990 dcb->entry[i].connector = dcb->connector.entries++;
5992 i2c_conn[i2c] = dcb->connector.entries;
5995 /* Fake the connector table as well as just connector indices */
5996 for (i = 0; i < dcb->connector.entries; i++) {
5997 dcb->connector.entry[i].index = i;
5998 dcb->connector.entry[i].type = divine_connector_type(bios, i);
5999 dcb->connector.entry[i].gpio_tag = 0xff;
6004 fixup_legacy_i2c(struct nvbios *bios)
6006 struct dcb_table *dcb = &bios->dcb;
6009 for (i = 0; i < dcb->entries; i++) {
6010 if (dcb->entry[i].i2c_index == LEGACY_I2C_CRT)
6011 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.crt;
6012 if (dcb->entry[i].i2c_index == LEGACY_I2C_PANEL)
6013 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.panel;
6014 if (dcb->entry[i].i2c_index == LEGACY_I2C_TV)
6015 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.tv;
6019 static int load_nv17_hwsq_ucode_entry(struct drm_device *dev, struct nvbios *bios, uint16_t hwsq_offset, int entry)
6022 * The header following the "HWSQ" signature has the number of entries,
6023 * and the entry size
6025 * An entry consists of a dword to write to the sequencer control reg
6026 * (0x00001304), followed by the ucode bytes, written sequentially,
6027 * starting at reg 0x00001400
6030 uint8_t bytes_to_write;
6031 uint16_t hwsq_entry_offset;
6034 if (bios->data[hwsq_offset] <= entry) {
6035 NV_ERROR(dev, "Too few entries in HW sequencer table for "
6036 "requested entry\n");
6040 bytes_to_write = bios->data[hwsq_offset + 1];
6042 if (bytes_to_write != 36) {
6043 NV_ERROR(dev, "Unknown HW sequencer entry size\n");
6047 NV_TRACE(dev, "Loading NV17 power sequencing microcode\n");
6049 hwsq_entry_offset = hwsq_offset + 2 + entry * bytes_to_write;
6051 /* set sequencer control */
6052 bios_wr32(bios, 0x00001304, ROM32(bios->data[hwsq_entry_offset]));
6053 bytes_to_write -= 4;
6056 for (i = 0; i < bytes_to_write; i += 4)
6057 bios_wr32(bios, 0x00001400 + i, ROM32(bios->data[hwsq_entry_offset + i + 4]));
6059 /* twiddle NV_PBUS_DEBUG_4 */
6060 bios_wr32(bios, NV_PBUS_DEBUG_4, bios_rd32(bios, NV_PBUS_DEBUG_4) | 0x18);
6065 static int load_nv17_hw_sequencer_ucode(struct drm_device *dev,
6066 struct nvbios *bios)
6069 * BMP based cards, from NV17, need a microcode loading to correctly
6070 * control the GPIO etc for LVDS panels
6072 * BIT based cards seem to do this directly in the init scripts
6074 * The microcode entries are found by the "HWSQ" signature.
6077 const uint8_t hwsq_signature[] = { 'H', 'W', 'S', 'Q' };
6078 const int sz = sizeof(hwsq_signature);
6081 hwsq_offset = findstr(bios->data, bios->length, hwsq_signature, sz);
6085 /* always use entry 0? */
6086 return load_nv17_hwsq_ucode_entry(dev, bios, hwsq_offset + sz, 0);
6089 uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
6091 struct drm_nouveau_private *dev_priv = dev->dev_private;
6092 struct nvbios *bios = &dev_priv->vbios;
6093 const uint8_t edid_sig[] = {
6094 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
6095 uint16_t offset = 0;
6097 int searchlen = NV_PROM_SIZE;
6100 return bios->fp.edid;
6103 newoffset = findstr(&bios->data[offset], searchlen,
6107 offset += newoffset;
6108 if (!nv_cksum(&bios->data[offset], EDID1_LEN))
6111 searchlen -= offset;
6115 NV_TRACE(dev, "Found EDID in BIOS\n");
6117 return bios->fp.edid = &bios->data[offset];
6121 nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table,
6122 struct dcb_entry *dcbent)
6124 struct drm_nouveau_private *dev_priv = dev->dev_private;
6125 struct nvbios *bios = &dev_priv->vbios;
6126 struct init_exec iexec = { true, false };
6128 mutex_lock(&bios->lock);
6129 bios->display.output = dcbent;
6130 parse_init_table(bios, table, &iexec);
6131 bios->display.output = NULL;
6132 mutex_unlock(&bios->lock);
6135 static bool NVInitVBIOS(struct drm_device *dev)
6137 struct drm_nouveau_private *dev_priv = dev->dev_private;
6138 struct nvbios *bios = &dev_priv->vbios;
6140 memset(bios, 0, sizeof(struct nvbios));
6141 mutex_init(&bios->lock);
6144 if (!NVShadowVBIOS(dev, bios->data))
6147 bios->length = NV_PROM_SIZE;
6151 static int nouveau_parse_vbios_struct(struct drm_device *dev)
6153 struct drm_nouveau_private *dev_priv = dev->dev_private;
6154 struct nvbios *bios = &dev_priv->vbios;
6155 const uint8_t bit_signature[] = { 0xff, 0xb8, 'B', 'I', 'T' };
6156 const uint8_t bmp_signature[] = { 0xff, 0x7f, 'N', 'V', 0x0 };
6159 offset = findstr(bios->data, bios->length,
6160 bit_signature, sizeof(bit_signature));
6162 NV_TRACE(dev, "BIT BIOS found\n");
6163 return parse_bit_structure(bios, offset + 6);
6166 offset = findstr(bios->data, bios->length,
6167 bmp_signature, sizeof(bmp_signature));
6169 NV_TRACE(dev, "BMP BIOS found\n");
6170 return parse_bmp_structure(dev, bios, offset);
6173 NV_ERROR(dev, "No known BIOS signature found\n");
6178 nouveau_run_vbios_init(struct drm_device *dev)
6180 struct drm_nouveau_private *dev_priv = dev->dev_private;
6181 struct nvbios *bios = &dev_priv->vbios;
6184 NVLockVgaCrtcs(dev, false);
6185 if (nv_two_heads(dev))
6186 NVSetOwner(dev, bios->state.crtchead);
6188 if (bios->major_version < 5) /* BMP only */
6189 load_nv17_hw_sequencer_ucode(dev, bios);
6191 if (bios->execute) {
6192 bios->fp.last_script_invoc = 0;
6193 bios->fp.lvds_init_run = false;
6196 parse_init_tables(bios);
6199 * Runs some additional script seen on G8x VBIOSen. The VBIOS'
6200 * parser will run this right after the init tables, the binary
6201 * driver appears to run it at some point later.
6203 if (bios->some_script_ptr) {
6204 struct init_exec iexec = {true, false};
6206 NV_INFO(dev, "Parsing VBIOS init table at offset 0x%04X\n",
6207 bios->some_script_ptr);
6208 parse_init_table(bios, bios->some_script_ptr, &iexec);
6211 if (dev_priv->card_type >= NV_50) {
6212 for (i = 0; i < bios->dcb.entries; i++) {
6213 nouveau_bios_run_display_table(dev,
6214 &bios->dcb.entry[i],
6219 NVLockVgaCrtcs(dev, true);
6225 nouveau_bios_i2c_devices_takedown(struct drm_device *dev)
6227 struct drm_nouveau_private *dev_priv = dev->dev_private;
6228 struct nvbios *bios = &dev_priv->vbios;
6229 struct dcb_i2c_entry *entry;
6232 entry = &bios->dcb.i2c[0];
6233 for (i = 0; i < DCB_MAX_NUM_I2C_ENTRIES; i++, entry++)
6234 nouveau_i2c_fini(dev, entry);
6238 nouveau_bios_posted(struct drm_device *dev)
6240 struct drm_nouveau_private *dev_priv = dev->dev_private;
6244 if (dev_priv->chipset >= NV_50) {
6245 if (NVReadVgaCrtc(dev, 0, 0x00) == 0 &&
6246 NVReadVgaCrtc(dev, 0, 0x1a) == 0)
6251 was_locked = NVLockVgaCrtcs(dev, false);
6252 htotal = NVReadVgaCrtc(dev, 0, 0x06);
6253 htotal |= (NVReadVgaCrtc(dev, 0, 0x07) & 0x01) << 8;
6254 htotal |= (NVReadVgaCrtc(dev, 0, 0x07) & 0x20) << 4;
6255 htotal |= (NVReadVgaCrtc(dev, 0, 0x25) & 0x01) << 10;
6256 htotal |= (NVReadVgaCrtc(dev, 0, 0x41) & 0x01) << 11;
6257 NVLockVgaCrtcs(dev, was_locked);
6258 return (htotal != 0);
6262 nouveau_bios_init(struct drm_device *dev)
6264 struct drm_nouveau_private *dev_priv = dev->dev_private;
6265 struct nvbios *bios = &dev_priv->vbios;
6266 uint32_t saved_nv_pextdev_boot_0;
6270 if (!NVInitVBIOS(dev))
6273 ret = nouveau_parse_vbios_struct(dev);
6277 ret = parse_dcb_table(dev, bios, nv_two_heads(dev));
6281 fixup_legacy_i2c(bios);
6282 fixup_legacy_connector(bios);
6284 if (!bios->major_version) /* we don't run version 0 bios */
6287 /* these will need remembering across a suspend */
6288 saved_nv_pextdev_boot_0 = bios_rd32(bios, NV_PEXTDEV_BOOT_0);
6289 bios->state.saved_nv_pfb_cfg0 = bios_rd32(bios, NV_PFB_CFG0);
6291 /* init script execution disabled */
6292 bios->execute = false;
6294 /* ... unless card isn't POSTed already */
6295 if (!nouveau_bios_posted(dev)) {
6296 NV_INFO(dev, "Adaptor not initialised\n");
6297 if (dev_priv->card_type < NV_40) {
6298 NV_ERROR(dev, "Unable to POST this chipset\n");
6302 NV_INFO(dev, "Running VBIOS init tables\n");
6303 bios->execute = true;
6306 bios_wr32(bios, NV_PEXTDEV_BOOT_0, saved_nv_pextdev_boot_0);
6308 ret = nouveau_run_vbios_init(dev);
6312 /* feature_byte on BMP is poor, but init always sets CR4B */
6313 was_locked = NVLockVgaCrtcs(dev, false);
6314 if (bios->major_version < 5)
6315 bios->is_mobile = NVReadVgaCrtc(dev, 0, NV_CIO_CRE_4B) & 0x40;
6317 /* all BIT systems need p_f_m_t for digital_min_front_porch */
6318 if (bios->is_mobile || bios->major_version >= 5)
6319 ret = parse_fp_mode_table(dev, bios);
6320 NVLockVgaCrtcs(dev, was_locked);
6322 /* allow subsequent scripts to execute */
6323 bios->execute = true;
6329 nouveau_bios_takedown(struct drm_device *dev)
6331 nouveau_bios_i2c_devices_takedown(dev);