1 #include <core/engine.h>
2 #include <core/device.h>
4 #include <subdev/bios.h>
5 #include <subdev/bios/bmp.h>
6 #include <subdev/bios/bit.h>
7 #include <subdev/bios/conn.h>
8 #include <subdev/bios/dcb.h>
9 #include <subdev/bios/dp.h>
10 #include <subdev/bios/gpio.h>
11 #include <subdev/bios/init.h>
12 #include <subdev/devinit.h>
13 #include <subdev/i2c.h>
14 #include <subdev/vga.h>
15 #include <subdev/gpio.h>
17 #define bioslog(lvl, fmt, args...) do { \
18 nv_printk(init->bios, lvl, "0x%04x[%c]: "fmt, init->offset, \
19 init_exec(init) ? '0' + (init->nested - 1) : ' ', ##args); \
21 #define cont(fmt, args...) do { \
22 if (nv_subdev(init->bios)->debug >= NV_DBG_TRACE) \
23 printk(fmt, ##args); \
25 #define trace(fmt, args...) bioslog(TRACE, fmt, ##args)
26 #define warn(fmt, args...) bioslog(WARN, fmt, ##args)
27 #define error(fmt, args...) bioslog(ERROR, fmt, ##args)
29 /******************************************************************************
30 * init parser control flow helpers
31 *****************************************************************************/
34 init_exec(struct nvbios_init *init)
36 return (init->execute == 1) || ((init->execute & 5) == 5);
40 init_exec_set(struct nvbios_init *init, bool exec)
42 if (exec) init->execute &= 0xfd;
43 else init->execute |= 0x02;
47 init_exec_inv(struct nvbios_init *init)
49 init->execute ^= 0x02;
53 init_exec_force(struct nvbios_init *init, bool exec)
55 if (exec) init->execute |= 0x04;
56 else init->execute &= 0xfb;
59 /******************************************************************************
60 * init parser wrappers for normal register/i2c/whatever accessors
61 *****************************************************************************/
64 init_or(struct nvbios_init *init)
66 if (init_exec(init)) {
68 return ffs(init->outp->or) - 1;
69 error("script needs OR!!\n");
75 init_link(struct nvbios_init *init)
77 if (init_exec(init)) {
79 return !(init->outp->sorconf.link & 1);
80 error("script needs OR link\n");
86 init_crtc(struct nvbios_init *init)
88 if (init_exec(init)) {
91 error("script needs crtc\n");
97 init_conn(struct nvbios_init *init)
99 struct nouveau_bios *bios = init->bios;
103 if (init_exec(init)) {
105 conn = init->outp->connector;
106 conn = dcb_conn(bios, conn, &ver, &len);
108 return nv_ro08(bios, conn);
111 error("script needs connector type\n");
118 init_nvreg(struct nvbios_init *init, u32 reg)
120 /* C51 (at least) sometimes has the lower bits set which the VBIOS
121 * interprets to mean that access needs to go through certain IO
122 * ports instead. The NVIDIA binary driver has been seen to access
123 * these through the NV register address, so lets assume we can
128 /* GF8+ display scripts need register addresses mangled a bit to
129 * select a specific CRTC/OR
131 if (nv_device(init->bios)->card_type >= NV_50) {
132 if (reg & 0x80000000) {
133 reg += init_crtc(init) * 0x800;
137 if (reg & 0x40000000) {
138 reg += init_or(init) * 0x800;
140 if (reg & 0x20000000) {
141 reg += init_link(init) * 0x80;
147 if (reg & ~0x00fffffc)
148 warn("unknown bits in register 0x%08x\n", reg);
153 init_rd32(struct nvbios_init *init, u32 reg)
155 reg = init_nvreg(init, reg);
157 return nv_rd32(init->subdev, reg);
162 init_wr32(struct nvbios_init *init, u32 reg, u32 val)
164 reg = init_nvreg(init, reg);
166 nv_wr32(init->subdev, reg, val);
170 init_mask(struct nvbios_init *init, u32 reg, u32 mask, u32 val)
172 reg = init_nvreg(init, reg);
173 if (init_exec(init)) {
174 u32 tmp = nv_rd32(init->subdev, reg);
175 nv_wr32(init->subdev, reg, (tmp & ~mask) | val);
182 init_rdport(struct nvbios_init *init, u16 port)
185 return nv_rdport(init->subdev, init->crtc, port);
190 init_wrport(struct nvbios_init *init, u16 port, u8 value)
193 nv_wrport(init->subdev, init->crtc, port, value);
197 init_rdvgai(struct nvbios_init *init, u16 port, u8 index)
199 struct nouveau_subdev *subdev = init->subdev;
200 if (init_exec(init)) {
201 int head = init->crtc < 0 ? 0 : init->crtc;
202 return nv_rdvgai(subdev, head, port, index);
208 init_wrvgai(struct nvbios_init *init, u16 port, u8 index, u8 value)
210 /* force head 0 for updates to cr44, it only exists on first head */
211 if (nv_device(init->subdev)->card_type < NV_50) {
212 if (port == 0x03d4 && index == 0x44)
216 if (init_exec(init)) {
217 int head = init->crtc < 0 ? 0 : init->crtc;
218 nv_wrvgai(init->subdev, head, port, index, value);
221 /* select head 1 if cr44 write selected it */
222 if (nv_device(init->subdev)->card_type < NV_50) {
223 if (port == 0x03d4 && index == 0x44 && value == 3)
228 static struct nouveau_i2c_port *
229 init_i2c(struct nvbios_init *init, int index)
231 struct nouveau_i2c *i2c = nouveau_i2c(init->bios);
234 index = NV_I2C_DEFAULT(0);
235 if (init->outp && init->outp->i2c_upper_default)
236 index = NV_I2C_DEFAULT(1);
241 error("script needs output for i2c\n");
245 if (index == -2 && init->outp->location) {
246 index = NV_I2C_TYPE_EXTAUX(init->outp->extdev);
247 return i2c->find_type(i2c, index);
250 index = init->outp->i2c_index;
253 return i2c->find(i2c, index);
257 init_rdi2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg)
259 struct nouveau_i2c_port *port = init_i2c(init, index);
260 if (port && init_exec(init))
261 return nv_rdi2cr(port, addr, reg);
266 init_wri2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg, u8 val)
268 struct nouveau_i2c_port *port = init_i2c(init, index);
269 if (port && init_exec(init))
270 return nv_wri2cr(port, addr, reg, val);
275 init_rdauxr(struct nvbios_init *init, u32 addr)
277 struct nouveau_i2c_port *port = init_i2c(init, -2);
280 if (port && init_exec(init)) {
281 int ret = nv_rdaux(port, addr, &data, 1);
291 init_wrauxr(struct nvbios_init *init, u32 addr, u8 data)
293 struct nouveau_i2c_port *port = init_i2c(init, -2);
294 if (port && init_exec(init))
295 return nv_wraux(port, addr, &data, 1);
300 init_prog_pll(struct nvbios_init *init, u32 id, u32 freq)
302 struct nouveau_devinit *devinit = nouveau_devinit(init->bios);
303 if (devinit->pll_set && init_exec(init)) {
304 int ret = devinit->pll_set(devinit, id, freq);
306 warn("failed to prog pll 0x%08x to %dkHz\n", id, freq);
310 /******************************************************************************
311 * parsing of bios structures that are required to execute init tables
312 *****************************************************************************/
315 init_table(struct nouveau_bios *bios, u16 *len)
317 struct bit_entry bit_I;
319 if (!bit_entry(bios, 'I', &bit_I)) {
324 if (bmp_version(bios) >= 0x0510) {
326 return bios->bmp_offset + 75;
333 init_table_(struct nvbios_init *init, u16 offset, const char *name)
335 struct nouveau_bios *bios = init->bios;
336 u16 len, data = init_table(bios, &len);
338 if (len >= offset + 2) {
339 data = nv_ro16(bios, data + offset);
343 warn("%s pointer invalid\n", name);
347 warn("init data too short for %s pointer", name);
351 warn("init data not found\n");
355 #define init_script_table(b) init_table_((b), 0x00, "script table")
356 #define init_macro_index_table(b) init_table_((b), 0x02, "macro index table")
357 #define init_macro_table(b) init_table_((b), 0x04, "macro table")
358 #define init_condition_table(b) init_table_((b), 0x06, "condition table")
359 #define init_io_condition_table(b) init_table_((b), 0x08, "io condition table")
360 #define init_io_flag_condition_table(b) init_table_((b), 0x0a, "io flag conditon table")
361 #define init_function_table(b) init_table_((b), 0x0c, "function table")
362 #define init_xlat_table(b) init_table_((b), 0x10, "xlat table");
365 init_script(struct nouveau_bios *bios, int index)
367 struct nvbios_init init = { .bios = bios };
370 if (bmp_version(bios) && bmp_version(bios) < 0x0510) {
374 data = bios->bmp_offset + (bios->version.major < 2 ? 14 : 18);
375 return nv_ro16(bios, data + (index * 2));
378 data = init_script_table(&init);
380 return nv_ro16(bios, data + (index * 2));
386 init_unknown_script(struct nouveau_bios *bios)
388 u16 len, data = init_table(bios, &len);
389 if (data && len >= 16)
390 return nv_ro16(bios, data + 14);
395 init_ram_restrict_table(struct nvbios_init *init)
397 struct nouveau_bios *bios = init->bios;
398 struct bit_entry bit_M;
401 if (!bit_entry(bios, 'M', &bit_M)) {
402 if (bit_M.version == 1 && bit_M.length >= 5)
403 data = nv_ro16(bios, bit_M.offset + 3);
404 if (bit_M.version == 2 && bit_M.length >= 3)
405 data = nv_ro16(bios, bit_M.offset + 1);
409 warn("ram restrict table not found\n");
414 init_ram_restrict_group_count(struct nvbios_init *init)
416 struct nouveau_bios *bios = init->bios;
417 struct bit_entry bit_M;
419 if (!bit_entry(bios, 'M', &bit_M)) {
420 if (bit_M.version == 1 && bit_M.length >= 5)
421 return nv_ro08(bios, bit_M.offset + 2);
422 if (bit_M.version == 2 && bit_M.length >= 3)
423 return nv_ro08(bios, bit_M.offset + 0);
430 init_ram_restrict_strap(struct nvbios_init *init)
432 /* This appears to be the behaviour of the VBIOS parser, and *is*
433 * important to cache the NV_PEXTDEV_BOOT0 on later chipsets to
434 * avoid fucking up the memory controller (somehow) by reading it
435 * on every INIT_RAM_RESTRICT_ZM_GROUP opcode.
437 * Preserving the non-caching behaviour on earlier chipsets just
438 * in case *not* re-reading the strap causes similar breakage.
440 if (!init->ramcfg || init->bios->version.major < 0x70)
441 init->ramcfg = init_rd32(init, 0x101000);
442 return (init->ramcfg & 0x00000003c) >> 2;
446 init_ram_restrict(struct nvbios_init *init)
448 u8 strap = init_ram_restrict_strap(init);
449 u16 table = init_ram_restrict_table(init);
451 return nv_ro08(init->bios, table + strap);
456 init_xlat_(struct nvbios_init *init, u8 index, u8 offset)
458 struct nouveau_bios *bios = init->bios;
459 u16 table = init_xlat_table(init);
461 u16 data = nv_ro16(bios, table + (index * 2));
463 return nv_ro08(bios, data + offset);
464 warn("xlat table pointer %d invalid\n", index);
469 /******************************************************************************
470 * utility functions used by various init opcode handlers
471 *****************************************************************************/
474 init_condition_met(struct nvbios_init *init, u8 cond)
476 struct nouveau_bios *bios = init->bios;
477 u16 table = init_condition_table(init);
479 u32 reg = nv_ro32(bios, table + (cond * 12) + 0);
480 u32 msk = nv_ro32(bios, table + (cond * 12) + 4);
481 u32 val = nv_ro32(bios, table + (cond * 12) + 8);
482 trace("\t[0x%02x] (R[0x%06x] & 0x%08x) == 0x%08x\n",
483 cond, reg, msk, val);
484 return (init_rd32(init, reg) & msk) == val;
490 init_io_condition_met(struct nvbios_init *init, u8 cond)
492 struct nouveau_bios *bios = init->bios;
493 u16 table = init_io_condition_table(init);
495 u16 port = nv_ro16(bios, table + (cond * 5) + 0);
496 u8 index = nv_ro08(bios, table + (cond * 5) + 2);
497 u8 mask = nv_ro08(bios, table + (cond * 5) + 3);
498 u8 value = nv_ro08(bios, table + (cond * 5) + 4);
499 trace("\t[0x%02x] (0x%04x[0x%02x] & 0x%02x) == 0x%02x\n",
500 cond, port, index, mask, value);
501 return (init_rdvgai(init, port, index) & mask) == value;
507 init_io_flag_condition_met(struct nvbios_init *init, u8 cond)
509 struct nouveau_bios *bios = init->bios;
510 u16 table = init_io_flag_condition_table(init);
512 u16 port = nv_ro16(bios, table + (cond * 9) + 0);
513 u8 index = nv_ro08(bios, table + (cond * 9) + 2);
514 u8 mask = nv_ro08(bios, table + (cond * 9) + 3);
515 u8 shift = nv_ro08(bios, table + (cond * 9) + 4);
516 u16 data = nv_ro16(bios, table + (cond * 9) + 5);
517 u8 dmask = nv_ro08(bios, table + (cond * 9) + 7);
518 u8 value = nv_ro08(bios, table + (cond * 9) + 8);
519 u8 ioval = (init_rdvgai(init, port, index) & mask) >> shift;
520 return (nv_ro08(bios, data + ioval) & dmask) == value;
526 init_shift(u32 data, u8 shift)
529 return data >> shift;
530 return data << (0x100 - shift);
534 init_tmds_reg(struct nvbios_init *init, u8 tmds)
536 /* For mlv < 0x80, it is an index into a table of TMDS base addresses.
537 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by
538 * CR58 for CR57 = 0 to index a table of offsets to the basic
540 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by
541 * CR58 for CR57 = 0 to index a table of offsets to the basic
542 * 0x6808b0 address, and then flip the offset by 8.
545 const int pramdac_offset[13] = {
546 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 };
547 const u32 pramdac_table[4] = {
548 0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8 };
552 u32 dacoffset = pramdac_offset[init->outp->or];
555 return 0x6808b0 + dacoffset;
559 error("tmds opcodes need dcb\n");
561 if (tmds < ARRAY_SIZE(pramdac_table))
562 return pramdac_table[tmds];
564 error("tmds selector 0x%02x unknown\n", tmds);
570 /******************************************************************************
571 * init opcode handlers
572 *****************************************************************************/
575 * init_reserved - stub for various unknown/unused single-byte opcodes
579 init_reserved(struct nvbios_init *init)
581 u8 opcode = nv_ro08(init->bios, init->offset);
593 trace("RESERVED 0x%02x\t", opcode);
594 for (i = 1; i < length; i++)
595 cont(" 0x%02x", nv_ro08(init->bios, init->offset + i));
597 init->offset += length;
601 * INIT_DONE - opcode 0x71
605 init_done(struct nvbios_init *init)
608 init->offset = 0x0000;
612 * INIT_IO_RESTRICT_PROG - opcode 0x32
616 init_io_restrict_prog(struct nvbios_init *init)
618 struct nouveau_bios *bios = init->bios;
619 u16 port = nv_ro16(bios, init->offset + 1);
620 u8 index = nv_ro08(bios, init->offset + 3);
621 u8 mask = nv_ro08(bios, init->offset + 4);
622 u8 shift = nv_ro08(bios, init->offset + 5);
623 u8 count = nv_ro08(bios, init->offset + 6);
624 u32 reg = nv_ro32(bios, init->offset + 7);
627 trace("IO_RESTRICT_PROG\tR[0x%06x] = "
628 "((0x%04x[0x%02x] & 0x%02x) >> %d) [{\n",
629 reg, port, index, mask, shift);
632 conf = (init_rdvgai(init, port, index) & mask) >> shift;
633 for (i = 0; i < count; i++) {
634 u32 data = nv_ro32(bios, init->offset);
637 trace("\t0x%08x *\n", data);
638 init_wr32(init, reg, data);
640 trace("\t0x%08x\n", data);
649 * INIT_REPEAT - opcode 0x33
653 init_repeat(struct nvbios_init *init)
655 struct nouveau_bios *bios = init->bios;
656 u8 count = nv_ro08(bios, init->offset + 1);
657 u16 repeat = init->repeat;
659 trace("REPEAT\t0x%02x\n", count);
662 init->repeat = init->offset;
663 init->repend = init->offset;
665 init->offset = init->repeat;
668 trace("REPEAT\t0x%02x\n", count);
670 init->offset = init->repend;
671 init->repeat = repeat;
675 * INIT_IO_RESTRICT_PLL - opcode 0x34
679 init_io_restrict_pll(struct nvbios_init *init)
681 struct nouveau_bios *bios = init->bios;
682 u16 port = nv_ro16(bios, init->offset + 1);
683 u8 index = nv_ro08(bios, init->offset + 3);
684 u8 mask = nv_ro08(bios, init->offset + 4);
685 u8 shift = nv_ro08(bios, init->offset + 5);
686 s8 iofc = nv_ro08(bios, init->offset + 6);
687 u8 count = nv_ro08(bios, init->offset + 7);
688 u32 reg = nv_ro32(bios, init->offset + 8);
691 trace("IO_RESTRICT_PLL\tR[0x%06x] =PLL= "
692 "((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) IOFCOND 0x%02x [{\n",
693 reg, port, index, mask, shift, iofc);
696 conf = (init_rdvgai(init, port, index) & mask) >> shift;
697 for (i = 0; i < count; i++) {
698 u32 freq = nv_ro16(bios, init->offset) * 10;
701 trace("\t%dkHz *\n", freq);
702 if (iofc > 0 && init_io_flag_condition_met(init, iofc))
704 init_prog_pll(init, reg, freq);
706 trace("\t%dkHz\n", freq);
715 * INIT_END_REPEAT - opcode 0x36
719 init_end_repeat(struct nvbios_init *init)
721 trace("END_REPEAT\n");
725 init->repend = init->offset;
731 * INIT_COPY - opcode 0x37
735 init_copy(struct nvbios_init *init)
737 struct nouveau_bios *bios = init->bios;
738 u32 reg = nv_ro32(bios, init->offset + 1);
739 u8 shift = nv_ro08(bios, init->offset + 5);
740 u8 smask = nv_ro08(bios, init->offset + 6);
741 u16 port = nv_ro16(bios, init->offset + 7);
742 u8 index = nv_ro08(bios, init->offset + 9);
743 u8 mask = nv_ro08(bios, init->offset + 10);
746 trace("COPY\t0x%04x[0x%02x] &= 0x%02x |= "
747 "((R[0x%06x] %s 0x%02x) & 0x%02x)\n",
748 port, index, mask, reg, (shift & 0x80) ? "<<" : ">>",
749 (shift & 0x80) ? (0x100 - shift) : shift, smask);
752 data = init_rdvgai(init, port, index) & mask;
753 data |= init_shift(init_rd32(init, reg), shift) & smask;
754 init_wrvgai(init, port, index, data);
758 * INIT_NOT - opcode 0x38
762 init_not(struct nvbios_init *init)
770 * INIT_IO_FLAG_CONDITION - opcode 0x39
774 init_io_flag_condition(struct nvbios_init *init)
776 struct nouveau_bios *bios = init->bios;
777 u8 cond = nv_ro08(bios, init->offset + 1);
779 trace("IO_FLAG_CONDITION\t0x%02x\n", cond);
782 if (!init_io_flag_condition_met(init, cond))
783 init_exec_set(init, false);
787 * INIT_DP_CONDITION - opcode 0x3a
791 init_dp_condition(struct nvbios_init *init)
793 struct nouveau_bios *bios = init->bios;
794 struct nvbios_dpout info;
795 u8 cond = nv_ro08(bios, init->offset + 1);
796 u8 unkn = nv_ro08(bios, init->offset + 2);
797 u8 ver, hdr, cnt, len;
800 trace("DP_CONDITION\t0x%02x 0x%02x\n", cond, unkn);
805 if (init_conn(init) != DCB_CONNECTOR_eDP)
806 init_exec_set(init, false);
811 (data = nvbios_dpout_match(bios, DCB_OUTPUT_DP,
812 (init->outp->or << 0) |
813 (init->outp->sorconf.link << 6),
814 &ver, &hdr, &cnt, &len, &info)))
816 if (!(info.flags & cond))
817 init_exec_set(init, false);
822 warn("script needs dp output table data\n");
825 if (!(init_rdauxr(init, 0x0d) & 1))
826 init_exec_set(init, false);
829 warn("unknown dp condition 0x%02x\n", cond);
835 * INIT_IO_MASK_OR - opcode 0x3b
839 init_io_mask_or(struct nvbios_init *init)
841 struct nouveau_bios *bios = init->bios;
842 u8 index = nv_ro08(bios, init->offset + 1);
843 u8 or = init_or(init);
846 trace("IO_MASK_OR\t0x03d4[0x%02x] &= ~(1 << 0x%02x)\n", index, or);
849 data = init_rdvgai(init, 0x03d4, index);
850 init_wrvgai(init, 0x03d4, index, data &= ~(1 << or));
854 * INIT_IO_OR - opcode 0x3c
858 init_io_or(struct nvbios_init *init)
860 struct nouveau_bios *bios = init->bios;
861 u8 index = nv_ro08(bios, init->offset + 1);
862 u8 or = init_or(init);
865 trace("IO_OR\t0x03d4[0x%02x] |= (1 << 0x%02x)\n", index, or);
868 data = init_rdvgai(init, 0x03d4, index);
869 init_wrvgai(init, 0x03d4, index, data | (1 << or));
873 * INIT_INDEX_ADDRESS_LATCHED - opcode 0x49
877 init_idx_addr_latched(struct nvbios_init *init)
879 struct nouveau_bios *bios = init->bios;
880 u32 creg = nv_ro32(bios, init->offset + 1);
881 u32 dreg = nv_ro32(bios, init->offset + 5);
882 u32 mask = nv_ro32(bios, init->offset + 9);
883 u32 data = nv_ro32(bios, init->offset + 13);
884 u8 count = nv_ro08(bios, init->offset + 17);
886 trace("INDEX_ADDRESS_LATCHED\t"
887 "R[0x%06x] : R[0x%06x]\n\tCTRL &= 0x%08x |= 0x%08x\n",
888 creg, dreg, mask, data);
892 u8 iaddr = nv_ro08(bios, init->offset + 0);
893 u8 idata = nv_ro08(bios, init->offset + 1);
895 trace("\t[0x%02x] = 0x%02x\n", iaddr, idata);
898 init_wr32(init, dreg, idata);
899 init_mask(init, creg, ~mask, data | iaddr);
904 * INIT_IO_RESTRICT_PLL2 - opcode 0x4a
908 init_io_restrict_pll2(struct nvbios_init *init)
910 struct nouveau_bios *bios = init->bios;
911 u16 port = nv_ro16(bios, init->offset + 1);
912 u8 index = nv_ro08(bios, init->offset + 3);
913 u8 mask = nv_ro08(bios, init->offset + 4);
914 u8 shift = nv_ro08(bios, init->offset + 5);
915 u8 count = nv_ro08(bios, init->offset + 6);
916 u32 reg = nv_ro32(bios, init->offset + 7);
919 trace("IO_RESTRICT_PLL2\t"
920 "R[0x%06x] =PLL= ((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) [{\n",
921 reg, port, index, mask, shift);
924 conf = (init_rdvgai(init, port, index) & mask) >> shift;
925 for (i = 0; i < count; i++) {
926 u32 freq = nv_ro32(bios, init->offset);
928 trace("\t%dkHz *\n", freq);
929 init_prog_pll(init, reg, freq);
931 trace("\t%dkHz\n", freq);
939 * INIT_PLL2 - opcode 0x4b
943 init_pll2(struct nvbios_init *init)
945 struct nouveau_bios *bios = init->bios;
946 u32 reg = nv_ro32(bios, init->offset + 1);
947 u32 freq = nv_ro32(bios, init->offset + 5);
949 trace("PLL2\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
952 init_prog_pll(init, reg, freq);
956 * INIT_I2C_BYTE - opcode 0x4c
960 init_i2c_byte(struct nvbios_init *init)
962 struct nouveau_bios *bios = init->bios;
963 u8 index = nv_ro08(bios, init->offset + 1);
964 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
965 u8 count = nv_ro08(bios, init->offset + 3);
967 trace("I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
971 u8 reg = nv_ro08(bios, init->offset + 0);
972 u8 mask = nv_ro08(bios, init->offset + 1);
973 u8 data = nv_ro08(bios, init->offset + 2);
976 trace("\t[0x%02x] &= 0x%02x |= 0x%02x\n", reg, mask, data);
979 val = init_rdi2cr(init, index, addr, reg);
982 init_wri2cr(init, index, addr, reg, (val & mask) | data);
987 * INIT_ZM_I2C_BYTE - opcode 0x4d
991 init_zm_i2c_byte(struct nvbios_init *init)
993 struct nouveau_bios *bios = init->bios;
994 u8 index = nv_ro08(bios, init->offset + 1);
995 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
996 u8 count = nv_ro08(bios, init->offset + 3);
998 trace("ZM_I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
1002 u8 reg = nv_ro08(bios, init->offset + 0);
1003 u8 data = nv_ro08(bios, init->offset + 1);
1005 trace("\t[0x%02x] = 0x%02x\n", reg, data);
1008 init_wri2cr(init, index, addr, reg, data);
1014 * INIT_ZM_I2C - opcode 0x4e
1018 init_zm_i2c(struct nvbios_init *init)
1020 struct nouveau_bios *bios = init->bios;
1021 u8 index = nv_ro08(bios, init->offset + 1);
1022 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
1023 u8 count = nv_ro08(bios, init->offset + 3);
1026 trace("ZM_I2C\tI2C[0x%02x][0x%02x]\n", index, addr);
1029 for (i = 0; i < count; i++) {
1030 data[i] = nv_ro08(bios, init->offset);
1031 trace("\t0x%02x\n", data[i]);
1035 if (init_exec(init)) {
1036 struct nouveau_i2c_port *port = init_i2c(init, index);
1037 struct i2c_msg msg = {
1038 .addr = addr, .flags = 0, .len = count, .buf = data,
1042 if (port && (ret = i2c_transfer(&port->adapter, &msg, 1)) != 1)
1043 warn("i2c wr failed, %d\n", ret);
1048 * INIT_TMDS - opcode 0x4f
1052 init_tmds(struct nvbios_init *init)
1054 struct nouveau_bios *bios = init->bios;
1055 u8 tmds = nv_ro08(bios, init->offset + 1);
1056 u8 addr = nv_ro08(bios, init->offset + 2);
1057 u8 mask = nv_ro08(bios, init->offset + 3);
1058 u8 data = nv_ro08(bios, init->offset + 4);
1059 u32 reg = init_tmds_reg(init, tmds);
1061 trace("TMDS\tT[0x%02x][0x%02x] &= 0x%02x |= 0x%02x\n",
1062 tmds, addr, mask, data);
1068 init_wr32(init, reg + 0, addr | 0x00010000);
1069 init_wr32(init, reg + 4, data | (init_rd32(init, reg + 4) & mask));
1070 init_wr32(init, reg + 0, addr);
1074 * INIT_ZM_TMDS_GROUP - opcode 0x50
1078 init_zm_tmds_group(struct nvbios_init *init)
1080 struct nouveau_bios *bios = init->bios;
1081 u8 tmds = nv_ro08(bios, init->offset + 1);
1082 u8 count = nv_ro08(bios, init->offset + 2);
1083 u32 reg = init_tmds_reg(init, tmds);
1085 trace("TMDS_ZM_GROUP\tT[0x%02x]\n", tmds);
1089 u8 addr = nv_ro08(bios, init->offset + 0);
1090 u8 data = nv_ro08(bios, init->offset + 1);
1092 trace("\t[0x%02x] = 0x%02x\n", addr, data);
1095 init_wr32(init, reg + 4, data);
1096 init_wr32(init, reg + 0, addr);
1101 * INIT_CR_INDEX_ADDRESS_LATCHED - opcode 0x51
1105 init_cr_idx_adr_latch(struct nvbios_init *init)
1107 struct nouveau_bios *bios = init->bios;
1108 u8 addr0 = nv_ro08(bios, init->offset + 1);
1109 u8 addr1 = nv_ro08(bios, init->offset + 2);
1110 u8 base = nv_ro08(bios, init->offset + 3);
1111 u8 count = nv_ro08(bios, init->offset + 4);
1114 trace("CR_INDEX_ADDR C[%02x] C[%02x]\n", addr0, addr1);
1117 save0 = init_rdvgai(init, 0x03d4, addr0);
1119 u8 data = nv_ro08(bios, init->offset);
1121 trace("\t\t[0x%02x] = 0x%02x\n", base, data);
1124 init_wrvgai(init, 0x03d4, addr0, base++);
1125 init_wrvgai(init, 0x03d4, addr1, data);
1127 init_wrvgai(init, 0x03d4, addr0, save0);
1131 * INIT_CR - opcode 0x52
1135 init_cr(struct nvbios_init *init)
1137 struct nouveau_bios *bios = init->bios;
1138 u8 addr = nv_ro08(bios, init->offset + 1);
1139 u8 mask = nv_ro08(bios, init->offset + 2);
1140 u8 data = nv_ro08(bios, init->offset + 3);
1143 trace("CR\t\tC[0x%02x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1146 val = init_rdvgai(init, 0x03d4, addr) & mask;
1147 init_wrvgai(init, 0x03d4, addr, val | data);
1151 * INIT_ZM_CR - opcode 0x53
1155 init_zm_cr(struct nvbios_init *init)
1157 struct nouveau_bios *bios = init->bios;
1158 u8 addr = nv_ro08(bios, init->offset + 1);
1159 u8 data = nv_ro08(bios, init->offset + 2);
1161 trace("ZM_CR\tC[0x%02x] = 0x%02x\n", addr, data);
1164 init_wrvgai(init, 0x03d4, addr, data);
1168 * INIT_ZM_CR_GROUP - opcode 0x54
1172 init_zm_cr_group(struct nvbios_init *init)
1174 struct nouveau_bios *bios = init->bios;
1175 u8 count = nv_ro08(bios, init->offset + 1);
1177 trace("ZM_CR_GROUP\n");
1181 u8 addr = nv_ro08(bios, init->offset + 0);
1182 u8 data = nv_ro08(bios, init->offset + 1);
1184 trace("\t\tC[0x%02x] = 0x%02x\n", addr, data);
1187 init_wrvgai(init, 0x03d4, addr, data);
1192 * INIT_CONDITION_TIME - opcode 0x56
1196 init_condition_time(struct nvbios_init *init)
1198 struct nouveau_bios *bios = init->bios;
1199 u8 cond = nv_ro08(bios, init->offset + 1);
1200 u8 retry = nv_ro08(bios, init->offset + 2);
1201 u8 wait = min((u16)retry * 50, 100);
1203 trace("CONDITION_TIME\t0x%02x 0x%02x\n", cond, retry);
1206 if (!init_exec(init))
1210 if (init_condition_met(init, cond))
1215 init_exec_set(init, false);
1219 * INIT_LTIME - opcode 0x57
1223 init_ltime(struct nvbios_init *init)
1225 struct nouveau_bios *bios = init->bios;
1226 u16 msec = nv_ro16(bios, init->offset + 1);
1228 trace("LTIME\t0x%04x\n", msec);
1231 if (init_exec(init))
1236 * INIT_ZM_REG_SEQUENCE - opcode 0x58
1240 init_zm_reg_sequence(struct nvbios_init *init)
1242 struct nouveau_bios *bios = init->bios;
1243 u32 base = nv_ro32(bios, init->offset + 1);
1244 u8 count = nv_ro08(bios, init->offset + 5);
1246 trace("ZM_REG_SEQUENCE\t0x%02x\n", count);
1250 u32 data = nv_ro32(bios, init->offset);
1252 trace("\t\tR[0x%06x] = 0x%08x\n", base, data);
1255 init_wr32(init, base, data);
1261 * INIT_SUB_DIRECT - opcode 0x5b
1265 init_sub_direct(struct nvbios_init *init)
1267 struct nouveau_bios *bios = init->bios;
1268 u16 addr = nv_ro16(bios, init->offset + 1);
1271 trace("SUB_DIRECT\t0x%04x\n", addr);
1273 if (init_exec(init)) {
1274 save = init->offset;
1275 init->offset = addr;
1276 if (nvbios_exec(init)) {
1277 error("error parsing sub-table\n");
1280 init->offset = save;
1287 * INIT_JUMP - opcode 0x5c
1291 init_jump(struct nvbios_init *init)
1293 struct nouveau_bios *bios = init->bios;
1294 u16 offset = nv_ro16(bios, init->offset + 1);
1296 trace("JUMP\t0x%04x\n", offset);
1297 init->offset = offset;
1301 * INIT_I2C_IF - opcode 0x5e
1305 init_i2c_if(struct nvbios_init *init)
1307 struct nouveau_bios *bios = init->bios;
1308 u8 index = nv_ro08(bios, init->offset + 1);
1309 u8 addr = nv_ro08(bios, init->offset + 2);
1310 u8 reg = nv_ro08(bios, init->offset + 3);
1311 u8 mask = nv_ro08(bios, init->offset + 4);
1312 u8 data = nv_ro08(bios, init->offset + 5);
1315 trace("I2C_IF\tI2C[0x%02x][0x%02x][0x%02x] & 0x%02x == 0x%02x\n",
1316 index, addr, reg, mask, data);
1318 init_exec_force(init, true);
1320 value = init_rdi2cr(init, index, addr, reg);
1321 if ((value & mask) != data)
1322 init_exec_set(init, false);
1324 init_exec_force(init, false);
1328 * INIT_COPY_NV_REG - opcode 0x5f
1332 init_copy_nv_reg(struct nvbios_init *init)
1334 struct nouveau_bios *bios = init->bios;
1335 u32 sreg = nv_ro32(bios, init->offset + 1);
1336 u8 shift = nv_ro08(bios, init->offset + 5);
1337 u32 smask = nv_ro32(bios, init->offset + 6);
1338 u32 sxor = nv_ro32(bios, init->offset + 10);
1339 u32 dreg = nv_ro32(bios, init->offset + 14);
1340 u32 dmask = nv_ro32(bios, init->offset + 18);
1343 trace("COPY_NV_REG\tR[0x%06x] &= 0x%08x |= "
1344 "((R[0x%06x] %s 0x%02x) & 0x%08x ^ 0x%08x)\n",
1345 dreg, dmask, sreg, (shift & 0x80) ? "<<" : ">>",
1346 (shift & 0x80) ? (0x100 - shift) : shift, smask, sxor);
1349 data = init_shift(init_rd32(init, sreg), shift);
1350 init_mask(init, dreg, ~dmask, (data & smask) ^ sxor);
1354 * INIT_ZM_INDEX_IO - opcode 0x62
1358 init_zm_index_io(struct nvbios_init *init)
1360 struct nouveau_bios *bios = init->bios;
1361 u16 port = nv_ro16(bios, init->offset + 1);
1362 u8 index = nv_ro08(bios, init->offset + 3);
1363 u8 data = nv_ro08(bios, init->offset + 4);
1365 trace("ZM_INDEX_IO\tI[0x%04x][0x%02x] = 0x%02x\n", port, index, data);
1368 init_wrvgai(init, port, index, data);
1372 * INIT_COMPUTE_MEM - opcode 0x63
1376 init_compute_mem(struct nvbios_init *init)
1378 struct nouveau_devinit *devinit = nouveau_devinit(init->bios);
1380 trace("COMPUTE_MEM\n");
1383 init_exec_force(init, true);
1384 if (init_exec(init) && devinit->meminit)
1385 devinit->meminit(devinit);
1386 init_exec_force(init, false);
1390 * INIT_RESET - opcode 0x65
1394 init_reset(struct nvbios_init *init)
1396 struct nouveau_bios *bios = init->bios;
1397 u32 reg = nv_ro32(bios, init->offset + 1);
1398 u32 data1 = nv_ro32(bios, init->offset + 5);
1399 u32 data2 = nv_ro32(bios, init->offset + 9);
1402 trace("RESET\tR[0x%08x] = 0x%08x, 0x%08x", reg, data1, data2);
1404 init_exec_force(init, true);
1406 savepci19 = init_mask(init, 0x00184c, 0x00000f00, 0x00000000);
1407 init_wr32(init, reg, data1);
1409 init_wr32(init, reg, data2);
1410 init_wr32(init, 0x00184c, savepci19);
1411 init_mask(init, 0x001850, 0x00000001, 0x00000000);
1413 init_exec_force(init, false);
1417 * INIT_CONFIGURE_MEM - opcode 0x66
1421 init_configure_mem_clk(struct nvbios_init *init)
1423 u16 mdata = bmp_mem_init_table(init->bios);
1425 mdata += (init_rdvgai(init, 0x03d4, 0x3c) >> 4) * 66;
1430 init_configure_mem(struct nvbios_init *init)
1432 struct nouveau_bios *bios = init->bios;
1436 trace("CONFIGURE_MEM\n");
1439 if (bios->version.major > 2) {
1443 init_exec_force(init, true);
1445 mdata = init_configure_mem_clk(init);
1446 sdata = bmp_sdr_seq_table(bios);
1447 if (nv_ro08(bios, mdata) & 0x01)
1448 sdata = bmp_ddr_seq_table(bios);
1449 mdata += 6; /* skip to data */
1451 data = init_rdvgai(init, 0x03c4, 0x01);
1452 init_wrvgai(init, 0x03c4, 0x01, data | 0x20);
1454 for (; (addr = nv_ro32(bios, sdata)) != 0xffffffff; sdata += 4) {
1456 case 0x10021c: /* CKE_NORMAL */
1457 case 0x1002d0: /* CMD_REFRESH */
1458 case 0x1002d4: /* CMD_PRECHARGE */
1462 data = nv_ro32(bios, mdata);
1464 if (data == 0xffffffff)
1469 init_wr32(init, addr, data);
1472 init_exec_force(init, false);
1476 * INIT_CONFIGURE_CLK - opcode 0x67
1480 init_configure_clk(struct nvbios_init *init)
1482 struct nouveau_bios *bios = init->bios;
1485 trace("CONFIGURE_CLK\n");
1488 if (bios->version.major > 2) {
1492 init_exec_force(init, true);
1494 mdata = init_configure_mem_clk(init);
1497 clock = nv_ro16(bios, mdata + 4) * 10;
1498 init_prog_pll(init, 0x680500, clock);
1501 clock = nv_ro16(bios, mdata + 2) * 10;
1502 if (nv_ro08(bios, mdata) & 0x01)
1504 init_prog_pll(init, 0x680504, clock);
1506 init_exec_force(init, false);
1510 * INIT_CONFIGURE_PREINIT - opcode 0x68
1514 init_configure_preinit(struct nvbios_init *init)
1516 struct nouveau_bios *bios = init->bios;
1519 trace("CONFIGURE_PREINIT\n");
1522 if (bios->version.major > 2) {
1526 init_exec_force(init, true);
1528 strap = init_rd32(init, 0x101000);
1529 strap = ((strap << 2) & 0xf0) | ((strap & 0x40) >> 6);
1530 init_wrvgai(init, 0x03d4, 0x3c, strap);
1532 init_exec_force(init, false);
1536 * INIT_IO - opcode 0x69
1540 init_io(struct nvbios_init *init)
1542 struct nouveau_bios *bios = init->bios;
1543 u16 port = nv_ro16(bios, init->offset + 1);
1544 u8 mask = nv_ro16(bios, init->offset + 3);
1545 u8 data = nv_ro16(bios, init->offset + 4);
1548 trace("IO\t\tI[0x%04x] &= 0x%02x |= 0x%02x\n", port, mask, data);
1551 /* ummm.. yes.. should really figure out wtf this is and why it's
1552 * needed some day.. it's almost certainly wrong, but, it also
1553 * somehow makes things work...
1555 if (nv_device(init->bios)->card_type >= NV_50 &&
1556 port == 0x03c3 && data == 0x01) {
1557 init_mask(init, 0x614100, 0xf0800000, 0x00800000);
1558 init_mask(init, 0x00e18c, 0x00020000, 0x00020000);
1559 init_mask(init, 0x614900, 0xf0800000, 0x00800000);
1560 init_mask(init, 0x000200, 0x40000000, 0x00000000);
1562 init_mask(init, 0x00e18c, 0x00020000, 0x00000000);
1563 init_mask(init, 0x000200, 0x40000000, 0x40000000);
1564 init_wr32(init, 0x614100, 0x00800018);
1565 init_wr32(init, 0x614900, 0x00800018);
1567 init_wr32(init, 0x614100, 0x10000018);
1568 init_wr32(init, 0x614900, 0x10000018);
1571 value = init_rdport(init, port) & mask;
1572 init_wrport(init, port, data | value);
1576 * INIT_SUB - opcode 0x6b
1580 init_sub(struct nvbios_init *init)
1582 struct nouveau_bios *bios = init->bios;
1583 u8 index = nv_ro08(bios, init->offset + 1);
1586 trace("SUB\t0x%02x\n", index);
1588 addr = init_script(bios, index);
1589 if (addr && init_exec(init)) {
1590 save = init->offset;
1591 init->offset = addr;
1592 if (nvbios_exec(init)) {
1593 error("error parsing sub-table\n");
1596 init->offset = save;
1603 * INIT_RAM_CONDITION - opcode 0x6d
1607 init_ram_condition(struct nvbios_init *init)
1609 struct nouveau_bios *bios = init->bios;
1610 u8 mask = nv_ro08(bios, init->offset + 1);
1611 u8 value = nv_ro08(bios, init->offset + 2);
1613 trace("RAM_CONDITION\t"
1614 "(R[0x100000] & 0x%02x) == 0x%02x\n", mask, value);
1617 if ((init_rd32(init, 0x100000) & mask) != value)
1618 init_exec_set(init, false);
1622 * INIT_NV_REG - opcode 0x6e
1626 init_nv_reg(struct nvbios_init *init)
1628 struct nouveau_bios *bios = init->bios;
1629 u32 reg = nv_ro32(bios, init->offset + 1);
1630 u32 mask = nv_ro32(bios, init->offset + 5);
1631 u32 data = nv_ro32(bios, init->offset + 9);
1633 trace("NV_REG\tR[0x%06x] &= 0x%08x |= 0x%08x\n", reg, mask, data);
1636 init_mask(init, reg, ~mask, data);
1640 * INIT_MACRO - opcode 0x6f
1644 init_macro(struct nvbios_init *init)
1646 struct nouveau_bios *bios = init->bios;
1647 u8 macro = nv_ro08(bios, init->offset + 1);
1650 trace("MACRO\t0x%02x\n", macro);
1652 table = init_macro_table(init);
1654 u32 addr = nv_ro32(bios, table + (macro * 8) + 0);
1655 u32 data = nv_ro32(bios, table + (macro * 8) + 4);
1656 trace("\t\tR[0x%06x] = 0x%08x\n", addr, data);
1657 init_wr32(init, addr, data);
1664 * INIT_RESUME - opcode 0x72
1668 init_resume(struct nvbios_init *init)
1672 init_exec_set(init, true);
1676 * INIT_TIME - opcode 0x74
1680 init_time(struct nvbios_init *init)
1682 struct nouveau_bios *bios = init->bios;
1683 u16 usec = nv_ro16(bios, init->offset + 1);
1685 trace("TIME\t0x%04x\n", usec);
1688 if (init_exec(init)) {
1692 mdelay((usec + 900) / 1000);
1697 * INIT_CONDITION - opcode 0x75
1701 init_condition(struct nvbios_init *init)
1703 struct nouveau_bios *bios = init->bios;
1704 u8 cond = nv_ro08(bios, init->offset + 1);
1706 trace("CONDITION\t0x%02x\n", cond);
1709 if (!init_condition_met(init, cond))
1710 init_exec_set(init, false);
1714 * INIT_IO_CONDITION - opcode 0x76
1718 init_io_condition(struct nvbios_init *init)
1720 struct nouveau_bios *bios = init->bios;
1721 u8 cond = nv_ro08(bios, init->offset + 1);
1723 trace("IO_CONDITION\t0x%02x\n", cond);
1726 if (!init_io_condition_met(init, cond))
1727 init_exec_set(init, false);
1731 * INIT_INDEX_IO - opcode 0x78
1735 init_index_io(struct nvbios_init *init)
1737 struct nouveau_bios *bios = init->bios;
1738 u16 port = nv_ro16(bios, init->offset + 1);
1739 u8 index = nv_ro16(bios, init->offset + 3);
1740 u8 mask = nv_ro08(bios, init->offset + 4);
1741 u8 data = nv_ro08(bios, init->offset + 5);
1744 trace("INDEX_IO\tI[0x%04x][0x%02x] &= 0x%02x |= 0x%02x\n",
1745 port, index, mask, data);
1748 value = init_rdvgai(init, port, index) & mask;
1749 init_wrvgai(init, port, index, data | value);
1753 * INIT_PLL - opcode 0x79
1757 init_pll(struct nvbios_init *init)
1759 struct nouveau_bios *bios = init->bios;
1760 u32 reg = nv_ro32(bios, init->offset + 1);
1761 u32 freq = nv_ro16(bios, init->offset + 5) * 10;
1763 trace("PLL\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
1766 init_prog_pll(init, reg, freq);
1770 * INIT_ZM_REG - opcode 0x7a
1774 init_zm_reg(struct nvbios_init *init)
1776 struct nouveau_bios *bios = init->bios;
1777 u32 addr = nv_ro32(bios, init->offset + 1);
1778 u32 data = nv_ro32(bios, init->offset + 5);
1780 trace("ZM_REG\tR[0x%06x] = 0x%08x\n", addr, data);
1783 if (addr == 0x000200)
1786 init_wr32(init, addr, data);
1790 * INIT_RAM_RESTRICT_PLL - opcde 0x87
1794 init_ram_restrict_pll(struct nvbios_init *init)
1796 struct nouveau_bios *bios = init->bios;
1797 u8 type = nv_ro08(bios, init->offset + 1);
1798 u8 count = init_ram_restrict_group_count(init);
1799 u8 strap = init_ram_restrict(init);
1802 trace("RAM_RESTRICT_PLL\t0x%02x\n", type);
1805 for (cconf = 0; cconf < count; cconf++) {
1806 u32 freq = nv_ro32(bios, init->offset);
1808 if (cconf == strap) {
1809 trace("%dkHz *\n", freq);
1810 init_prog_pll(init, type, freq);
1812 trace("%dkHz\n", freq);
1820 * INIT_GPIO - opcode 0x8e
1824 init_gpio(struct nvbios_init *init)
1826 struct nouveau_gpio *gpio = nouveau_gpio(init->bios);
1831 if (init_exec(init) && gpio && gpio->reset)
1832 gpio->reset(gpio, DCB_GPIO_UNUSED);
1836 * INIT_RAM_RESTRICT_ZM_GROUP - opcode 0x8f
1840 init_ram_restrict_zm_reg_group(struct nvbios_init *init)
1842 struct nouveau_bios *bios = init->bios;
1843 u32 addr = nv_ro32(bios, init->offset + 1);
1844 u8 incr = nv_ro08(bios, init->offset + 5);
1845 u8 num = nv_ro08(bios, init->offset + 6);
1846 u8 count = init_ram_restrict_group_count(init);
1847 u8 index = init_ram_restrict(init);
1850 trace("RAM_RESTRICT_ZM_REG_GROUP\t"
1851 "R[0x%08x] 0x%02x 0x%02x\n", addr, incr, num);
1854 for (i = 0; i < num; i++) {
1855 trace("\tR[0x%06x] = {\n", addr);
1856 for (j = 0; j < count; j++) {
1857 u32 data = nv_ro32(bios, init->offset);
1860 trace("\t\t0x%08x *\n", data);
1861 init_wr32(init, addr, data);
1863 trace("\t\t0x%08x\n", data);
1874 * INIT_COPY_ZM_REG - opcode 0x90
1878 init_copy_zm_reg(struct nvbios_init *init)
1880 struct nouveau_bios *bios = init->bios;
1881 u32 sreg = nv_ro32(bios, init->offset + 1);
1882 u32 dreg = nv_ro32(bios, init->offset + 5);
1884 trace("COPY_ZM_REG\tR[0x%06x] = R[0x%06x]\n", dreg, sreg);
1887 init_wr32(init, dreg, init_rd32(init, sreg));
1891 * INIT_ZM_REG_GROUP - opcode 0x91
1895 init_zm_reg_group(struct nvbios_init *init)
1897 struct nouveau_bios *bios = init->bios;
1898 u32 addr = nv_ro32(bios, init->offset + 1);
1899 u8 count = nv_ro08(bios, init->offset + 5);
1901 trace("ZM_REG_GROUP\tR[0x%06x] =\n", addr);
1905 u32 data = nv_ro32(bios, init->offset);
1906 trace("\t0x%08x\n", data);
1907 init_wr32(init, addr, data);
1913 * INIT_XLAT - opcode 0x96
1917 init_xlat(struct nvbios_init *init)
1919 struct nouveau_bios *bios = init->bios;
1920 u32 saddr = nv_ro32(bios, init->offset + 1);
1921 u8 sshift = nv_ro08(bios, init->offset + 5);
1922 u8 smask = nv_ro08(bios, init->offset + 6);
1923 u8 index = nv_ro08(bios, init->offset + 7);
1924 u32 daddr = nv_ro32(bios, init->offset + 8);
1925 u32 dmask = nv_ro32(bios, init->offset + 12);
1926 u8 shift = nv_ro08(bios, init->offset + 16);
1929 trace("INIT_XLAT\tR[0x%06x] &= 0x%08x |= "
1930 "(X%02x((R[0x%06x] %s 0x%02x) & 0x%02x) << 0x%02x)\n",
1931 daddr, dmask, index, saddr, (sshift & 0x80) ? "<<" : ">>",
1932 (sshift & 0x80) ? (0x100 - sshift) : sshift, smask, shift);
1935 data = init_shift(init_rd32(init, saddr), sshift) & smask;
1936 data = init_xlat_(init, index, data) << shift;
1937 init_mask(init, daddr, ~dmask, data);
1941 * INIT_ZM_MASK_ADD - opcode 0x97
1945 init_zm_mask_add(struct nvbios_init *init)
1947 struct nouveau_bios *bios = init->bios;
1948 u32 addr = nv_ro32(bios, init->offset + 1);
1949 u32 mask = nv_ro32(bios, init->offset + 5);
1950 u32 add = nv_ro32(bios, init->offset + 9);
1953 trace("ZM_MASK_ADD\tR[0x%06x] &= 0x%08x += 0x%08x\n", addr, mask, add);
1956 data = init_rd32(init, addr);
1957 data = (data & mask) | ((data + add) & ~mask);
1958 init_wr32(init, addr, data);
1962 * INIT_AUXCH - opcode 0x98
1966 init_auxch(struct nvbios_init *init)
1968 struct nouveau_bios *bios = init->bios;
1969 u32 addr = nv_ro32(bios, init->offset + 1);
1970 u8 count = nv_ro08(bios, init->offset + 5);
1972 trace("AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
1976 u8 mask = nv_ro08(bios, init->offset + 0);
1977 u8 data = nv_ro08(bios, init->offset + 1);
1978 trace("\tAUX[0x%08x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1979 mask = init_rdauxr(init, addr) & mask;
1980 init_wrauxr(init, addr, mask | data);
1986 * INIT_AUXCH - opcode 0x99
1990 init_zm_auxch(struct nvbios_init *init)
1992 struct nouveau_bios *bios = init->bios;
1993 u32 addr = nv_ro32(bios, init->offset + 1);
1994 u8 count = nv_ro08(bios, init->offset + 5);
1996 trace("ZM_AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
2000 u8 data = nv_ro08(bios, init->offset + 0);
2001 trace("\tAUX[0x%08x] = 0x%02x\n", addr, data);
2002 init_wrauxr(init, addr, data);
2008 * INIT_I2C_LONG_IF - opcode 0x9a
2012 init_i2c_long_if(struct nvbios_init *init)
2014 struct nouveau_bios *bios = init->bios;
2015 u8 index = nv_ro08(bios, init->offset + 1);
2016 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
2017 u8 reglo = nv_ro08(bios, init->offset + 3);
2018 u8 reghi = nv_ro08(bios, init->offset + 4);
2019 u8 mask = nv_ro08(bios, init->offset + 5);
2020 u8 data = nv_ro08(bios, init->offset + 6);
2021 struct nouveau_i2c_port *port;
2023 trace("I2C_LONG_IF\t"
2024 "I2C[0x%02x][0x%02x][0x%02x%02x] & 0x%02x == 0x%02x\n",
2025 index, addr, reglo, reghi, mask, data);
2028 port = init_i2c(init, index);
2030 u8 i[2] = { reghi, reglo };
2032 struct i2c_msg msg[] = {
2033 { .addr = addr, .flags = 0, .len = 2, .buf = i },
2034 { .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = o }
2038 ret = i2c_transfer(&port->adapter, msg, 2);
2039 if (ret == 2 && ((o[0] & mask) == data))
2043 init_exec_set(init, false);
2047 * INIT_GPIO_NE - opcode 0xa9
2051 init_gpio_ne(struct nvbios_init *init)
2053 struct nouveau_bios *bios = init->bios;
2054 struct nouveau_gpio *gpio = nouveau_gpio(bios);
2055 struct dcb_gpio_func func;
2056 u8 count = nv_ro08(bios, init->offset + 1);
2057 u8 idx = 0, ver, len;
2063 for (i = init->offset; i < init->offset + count; i++)
2064 cont("0x%02x ", nv_ro08(bios, i));
2067 while ((data = dcb_gpio_parse(bios, 0, idx++, &ver, &len, &func))) {
2068 if (func.func != DCB_GPIO_UNUSED) {
2069 for (i = init->offset; i < init->offset + count; i++) {
2070 if (func.func == nv_ro08(bios, i))
2074 trace("\tFUNC[0x%02x]", func.func);
2075 if (i == (init->offset + count)) {
2077 if (init_exec(init) && gpio && gpio->reset)
2078 gpio->reset(gpio, func.func);
2084 init->offset += count;
2087 static struct nvbios_init_opcode {
2088 void (*exec)(struct nvbios_init *);
2090 [0x32] = { init_io_restrict_prog },
2091 [0x33] = { init_repeat },
2092 [0x34] = { init_io_restrict_pll },
2093 [0x36] = { init_end_repeat },
2094 [0x37] = { init_copy },
2095 [0x38] = { init_not },
2096 [0x39] = { init_io_flag_condition },
2097 [0x3a] = { init_dp_condition },
2098 [0x3b] = { init_io_mask_or },
2099 [0x3c] = { init_io_or },
2100 [0x49] = { init_idx_addr_latched },
2101 [0x4a] = { init_io_restrict_pll2 },
2102 [0x4b] = { init_pll2 },
2103 [0x4c] = { init_i2c_byte },
2104 [0x4d] = { init_zm_i2c_byte },
2105 [0x4e] = { init_zm_i2c },
2106 [0x4f] = { init_tmds },
2107 [0x50] = { init_zm_tmds_group },
2108 [0x51] = { init_cr_idx_adr_latch },
2109 [0x52] = { init_cr },
2110 [0x53] = { init_zm_cr },
2111 [0x54] = { init_zm_cr_group },
2112 [0x56] = { init_condition_time },
2113 [0x57] = { init_ltime },
2114 [0x58] = { init_zm_reg_sequence },
2115 [0x5b] = { init_sub_direct },
2116 [0x5c] = { init_jump },
2117 [0x5e] = { init_i2c_if },
2118 [0x5f] = { init_copy_nv_reg },
2119 [0x62] = { init_zm_index_io },
2120 [0x63] = { init_compute_mem },
2121 [0x65] = { init_reset },
2122 [0x66] = { init_configure_mem },
2123 [0x67] = { init_configure_clk },
2124 [0x68] = { init_configure_preinit },
2125 [0x69] = { init_io },
2126 [0x6b] = { init_sub },
2127 [0x6d] = { init_ram_condition },
2128 [0x6e] = { init_nv_reg },
2129 [0x6f] = { init_macro },
2130 [0x71] = { init_done },
2131 [0x72] = { init_resume },
2132 [0x74] = { init_time },
2133 [0x75] = { init_condition },
2134 [0x76] = { init_io_condition },
2135 [0x78] = { init_index_io },
2136 [0x79] = { init_pll },
2137 [0x7a] = { init_zm_reg },
2138 [0x87] = { init_ram_restrict_pll },
2139 [0x8c] = { init_reserved },
2140 [0x8d] = { init_reserved },
2141 [0x8e] = { init_gpio },
2142 [0x8f] = { init_ram_restrict_zm_reg_group },
2143 [0x90] = { init_copy_zm_reg },
2144 [0x91] = { init_zm_reg_group },
2145 [0x92] = { init_reserved },
2146 [0x96] = { init_xlat },
2147 [0x97] = { init_zm_mask_add },
2148 [0x98] = { init_auxch },
2149 [0x99] = { init_zm_auxch },
2150 [0x9a] = { init_i2c_long_if },
2151 [0xa9] = { init_gpio_ne },
2152 [0xaa] = { init_reserved },
2155 #define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
2158 nvbios_exec(struct nvbios_init *init)
2161 while (init->offset) {
2162 u8 opcode = nv_ro08(init->bios, init->offset);
2163 if (opcode >= init_opcode_nr || !init_opcode[opcode].exec) {
2164 error("unknown opcode 0x%02x\n", opcode);
2168 init_opcode[opcode].exec(init);
2175 nvbios_init(struct nouveau_subdev *subdev, bool execute)
2177 struct nouveau_bios *bios = nouveau_bios(subdev);
2183 nv_info(bios, "running init tables\n");
2184 while (!ret && (data = (init_script(bios, ++i)))) {
2185 struct nvbios_init init = {
2191 .execute = execute ? 1 : 0,
2194 ret = nvbios_exec(&init);
2197 /* the vbios parser will run this right after the normal init
2198 * tables, whereas the binary driver appears to run it later.
2200 if (!ret && (data = init_unknown_script(bios))) {
2201 struct nvbios_init init = {
2207 .execute = execute ? 1 : 0,
2210 ret = nvbios_exec(&init);