1 #include <core/engine.h>
2 #include <core/device.h>
4 #include <subdev/bios.h>
5 #include <subdev/bios/conn.h>
6 #include <subdev/bios/bmp.h>
7 #include <subdev/bios/bit.h>
8 #include <subdev/bios/dcb.h>
9 #include <subdev/bios/dp.h>
10 #include <subdev/bios/init.h>
11 #include <subdev/devinit.h>
12 #include <subdev/clock.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)
67 return ffs(init->outp->or) - 1;
68 error("script needs OR!!\n");
73 init_link(struct nvbios_init *init)
76 return !(init->outp->sorconf.link & 1);
77 error("script needs OR link\n");
82 init_crtc(struct nvbios_init *init)
86 error("script needs crtc\n");
91 init_conn(struct nvbios_init *init)
93 struct nouveau_bios *bios = init->bios;
97 u16 conn = dcb_conn(bios, init->outp->connector, &ver, &len);
99 return nv_ro08(bios, conn);
102 error("script needs connector type\n");
107 init_nvreg(struct nvbios_init *init, u32 reg)
109 /* C51 (at least) sometimes has the lower bits set which the VBIOS
110 * interprets to mean that access needs to go through certain IO
111 * ports instead. The NVIDIA binary driver has been seen to access
112 * these through the NV register address, so lets assume we can
117 /* GF8+ display scripts need register addresses mangled a bit to
118 * select a specific CRTC/OR
120 if (nv_device(init->bios)->card_type >= NV_50) {
121 if (reg & 0x80000000) {
122 reg += init_crtc(init) * 0x800;
126 if (reg & 0x40000000) {
127 reg += init_or(init) * 0x800;
129 if (reg & 0x20000000) {
130 reg += init_link(init) * 0x80;
136 if (reg & ~0x00fffffc)
137 warn("unknown bits in register 0x%08x\n", reg);
142 init_rd32(struct nvbios_init *init, u32 reg)
144 reg = init_nvreg(init, reg);
146 return nv_rd32(init->subdev, reg);
151 init_wr32(struct nvbios_init *init, u32 reg, u32 val)
153 reg = init_nvreg(init, reg);
155 nv_wr32(init->subdev, reg, val);
159 init_mask(struct nvbios_init *init, u32 reg, u32 mask, u32 val)
161 reg = init_nvreg(init, reg);
162 if (init_exec(init)) {
163 u32 tmp = nv_rd32(init->subdev, reg);
164 nv_wr32(init->subdev, reg, (tmp & ~mask) | val);
171 init_rdport(struct nvbios_init *init, u16 port)
174 return nv_rdport(init->subdev, init->crtc, port);
179 init_wrport(struct nvbios_init *init, u16 port, u8 value)
182 nv_wrport(init->subdev, init->crtc, port, value);
186 init_rdvgai(struct nvbios_init *init, u16 port, u8 index)
188 struct nouveau_subdev *subdev = init->subdev;
189 if (init_exec(init)) {
190 int head = init->crtc < 0 ? 0 : init->crtc;
191 return nv_rdvgai(subdev, head, port, index);
197 init_wrvgai(struct nvbios_init *init, u16 port, u8 index, u8 value)
199 /* force head 0 for updates to cr44, it only exists on first head */
200 if (nv_device(init->subdev)->card_type < NV_50) {
201 if (port == 0x03d4 && index == 0x44)
205 if (init_exec(init)) {
206 int head = init->crtc < 0 ? 0 : init->crtc;
207 nv_wrvgai(init->subdev, head, port, index, value);
210 /* select head 1 if cr44 write selected it */
211 if (nv_device(init->subdev)->card_type < NV_50) {
212 if (port == 0x03d4 && index == 0x44 && value == 3)
217 static struct nouveau_i2c_port *
218 init_i2c(struct nvbios_init *init, int index)
220 struct nouveau_i2c *i2c = nouveau_i2c(init->bios);
223 index = NV_I2C_DEFAULT(0);
224 if (init->outp && init->outp->i2c_upper_default)
225 index = NV_I2C_DEFAULT(1);
229 error("script needs output for i2c\n");
233 index = init->outp->i2c_index;
236 return i2c->find(i2c, index);
240 init_rdi2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg)
242 struct nouveau_i2c_port *port = init_i2c(init, index);
243 if (port && init_exec(init))
244 return nv_rdi2cr(port, addr, reg);
249 init_wri2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg, u8 val)
251 struct nouveau_i2c_port *port = init_i2c(init, index);
252 if (port && init_exec(init))
253 return nv_wri2cr(port, addr, reg, val);
258 init_rdauxr(struct nvbios_init *init, u32 addr)
260 struct nouveau_i2c_port *port = init_i2c(init, -1);
263 if (port && init_exec(init)) {
264 int ret = nv_rdaux(port, addr, &data, 1);
274 init_wrauxr(struct nvbios_init *init, u32 addr, u8 data)
276 struct nouveau_i2c_port *port = init_i2c(init, -1);
277 if (port && init_exec(init))
278 return nv_wraux(port, addr, &data, 1);
283 init_prog_pll(struct nvbios_init *init, u32 id, u32 freq)
285 struct nouveau_clock *clk = nouveau_clock(init->bios);
286 if (clk && clk->pll_set && init_exec(init)) {
287 int ret = clk->pll_set(clk, id, freq);
289 warn("failed to prog pll 0x%08x to %dkHz\n", id, freq);
293 /******************************************************************************
294 * parsing of bios structures that are required to execute init tables
295 *****************************************************************************/
298 init_table(struct nouveau_bios *bios, u16 *len)
300 struct bit_entry bit_I;
302 if (!bit_entry(bios, 'I', &bit_I)) {
307 if (bmp_version(bios) >= 0x0510) {
309 return bios->bmp_offset + 75;
316 init_table_(struct nvbios_init *init, u16 offset, const char *name)
318 struct nouveau_bios *bios = init->bios;
319 u16 len, data = init_table(bios, &len);
321 if (len >= offset + 2) {
322 data = nv_ro16(bios, data + offset);
326 warn("%s pointer invalid\n", name);
330 warn("init data too short for %s pointer", name);
334 warn("init data not found\n");
338 #define init_script_table(b) init_table_((b), 0x00, "script table")
339 #define init_macro_index_table(b) init_table_((b), 0x02, "macro index table")
340 #define init_macro_table(b) init_table_((b), 0x04, "macro table")
341 #define init_condition_table(b) init_table_((b), 0x06, "condition table")
342 #define init_io_condition_table(b) init_table_((b), 0x08, "io condition table")
343 #define init_io_flag_condition_table(b) init_table_((b), 0x0a, "io flag conditon table")
344 #define init_function_table(b) init_table_((b), 0x0c, "function table")
345 #define init_xlat_table(b) init_table_((b), 0x10, "xlat table");
348 init_script(struct nouveau_bios *bios, int index)
350 struct nvbios_init init = { .bios = bios };
353 if (bmp_version(bios) && bmp_version(bios) < 0x0510) {
357 data = bios->bmp_offset + (bios->version.major < 2 ? 14 : 18);
358 return nv_ro16(bios, data + (index * 2));
361 data = init_script_table(&init);
363 return nv_ro16(bios, data + (index * 2));
369 init_unknown_script(struct nouveau_bios *bios)
371 u16 len, data = init_table(bios, &len);
372 if (data && len >= 16)
373 return nv_ro16(bios, data + 14);
378 init_ram_restrict_table(struct nvbios_init *init)
380 struct nouveau_bios *bios = init->bios;
381 struct bit_entry bit_M;
384 if (!bit_entry(bios, 'M', &bit_M)) {
385 if (bit_M.version == 1 && bit_M.length >= 5)
386 data = nv_ro16(bios, bit_M.offset + 3);
387 if (bit_M.version == 2 && bit_M.length >= 3)
388 data = nv_ro16(bios, bit_M.offset + 1);
392 warn("ram restrict table not found\n");
397 init_ram_restrict_group_count(struct nvbios_init *init)
399 struct nouveau_bios *bios = init->bios;
400 struct bit_entry bit_M;
402 if (!bit_entry(bios, 'M', &bit_M)) {
403 if (bit_M.version == 1 && bit_M.length >= 5)
404 return nv_ro08(bios, bit_M.offset + 2);
405 if (bit_M.version == 2 && bit_M.length >= 3)
406 return nv_ro08(bios, bit_M.offset + 0);
413 init_ram_restrict(struct nvbios_init *init)
415 u32 strap = (init_rd32(init, 0x101000) & 0x0000003c) >> 2;
416 u16 table = init_ram_restrict_table(init);
418 return nv_ro08(init->bios, table + strap);
423 init_xlat_(struct nvbios_init *init, u8 index, u8 offset)
425 struct nouveau_bios *bios = init->bios;
426 u16 table = init_xlat_table(init);
428 u16 data = nv_ro16(bios, table + (index * 2));
430 return nv_ro08(bios, data + offset);
431 warn("xlat table pointer %d invalid\n", index);
436 /******************************************************************************
437 * utility functions used by various init opcode handlers
438 *****************************************************************************/
441 init_condition_met(struct nvbios_init *init, u8 cond)
443 struct nouveau_bios *bios = init->bios;
444 u16 table = init_condition_table(init);
446 u32 reg = nv_ro32(bios, table + (cond * 12) + 0);
447 u32 msk = nv_ro32(bios, table + (cond * 12) + 4);
448 u32 val = nv_ro32(bios, table + (cond * 12) + 8);
449 trace("\t[0x%02x] (R[0x%06x] & 0x%08x) == 0x%08x\n",
450 cond, reg, msk, val);
451 return (init_rd32(init, reg) & msk) == val;
457 init_io_condition_met(struct nvbios_init *init, u8 cond)
459 struct nouveau_bios *bios = init->bios;
460 u16 table = init_io_condition_table(init);
462 u16 port = nv_ro16(bios, table + (cond * 5) + 0);
463 u8 index = nv_ro08(bios, table + (cond * 5) + 2);
464 u8 mask = nv_ro08(bios, table + (cond * 5) + 3);
465 u8 value = nv_ro08(bios, table + (cond * 5) + 4);
466 trace("\t[0x%02x] (0x%04x[0x%02x] & 0x%02x) == 0x%02x\n",
467 cond, port, index, mask, value);
468 return (init_rdvgai(init, port, index) & mask) == value;
474 init_io_flag_condition_met(struct nvbios_init *init, u8 cond)
476 struct nouveau_bios *bios = init->bios;
477 u16 table = init_io_flag_condition_table(init);
479 u16 port = nv_ro16(bios, table + (cond * 9) + 0);
480 u8 index = nv_ro08(bios, table + (cond * 9) + 2);
481 u8 mask = nv_ro08(bios, table + (cond * 9) + 3);
482 u8 shift = nv_ro08(bios, table + (cond * 9) + 4);
483 u16 data = nv_ro16(bios, table + (cond * 9) + 5);
484 u8 dmask = nv_ro08(bios, table + (cond * 9) + 7);
485 u8 value = nv_ro08(bios, table + (cond * 9) + 8);
486 u8 ioval = (init_rdvgai(init, port, index) & mask) >> shift;
487 return (nv_ro08(bios, data + ioval) & dmask) == value;
493 init_shift(u32 data, u8 shift)
496 return data >> shift;
497 return data << (0x100 - shift);
501 init_tmds_reg(struct nvbios_init *init, u8 tmds)
503 /* For mlv < 0x80, it is an index into a table of TMDS base addresses.
504 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by
505 * CR58 for CR57 = 0 to index a table of offsets to the basic
507 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by
508 * CR58 for CR57 = 0 to index a table of offsets to the basic
509 * 0x6808b0 address, and then flip the offset by 8.
512 const int pramdac_offset[13] = {
513 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 };
514 const u32 pramdac_table[4] = {
515 0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8 };
519 u32 dacoffset = pramdac_offset[init->outp->or];
522 return 0x6808b0 + dacoffset;
525 error("tmds opcodes need dcb\n");
527 if (tmds < ARRAY_SIZE(pramdac_table))
528 return pramdac_table[tmds];
530 error("tmds selector 0x%02x unknown\n", tmds);
536 /******************************************************************************
537 * init opcode handlers
538 *****************************************************************************/
541 * init_reserved - stub for various unknown/unused single-byte opcodes
545 init_reserved(struct nvbios_init *init)
547 u8 opcode = nv_ro08(init->bios, init->offset);
548 trace("RESERVED\t0x%02x\n", opcode);
553 * INIT_DONE - opcode 0x71
557 init_done(struct nvbios_init *init)
560 init->offset = 0x0000;
564 * INIT_IO_RESTRICT_PROG - opcode 0x32
568 init_io_restrict_prog(struct nvbios_init *init)
570 struct nouveau_bios *bios = init->bios;
571 u16 port = nv_ro16(bios, init->offset + 1);
572 u8 index = nv_ro08(bios, init->offset + 3);
573 u8 mask = nv_ro08(bios, init->offset + 4);
574 u8 shift = nv_ro08(bios, init->offset + 5);
575 u8 count = nv_ro08(bios, init->offset + 6);
576 u32 reg = nv_ro32(bios, init->offset + 7);
579 trace("IO_RESTRICT_PROG\tR[0x%06x] = "
580 "((0x%04x[0x%02x] & 0x%02x) >> %d) [{\n",
581 reg, port, index, mask, shift);
584 conf = (init_rdvgai(init, port, index) & mask) >> shift;
585 for (i = 0; i < count; i++) {
586 u32 data = nv_ro32(bios, init->offset);
589 trace("\t0x%08x *\n", data);
590 init_wr32(init, reg, data);
592 trace("\t0x%08x\n", data);
601 * INIT_REPEAT - opcode 0x33
605 init_repeat(struct nvbios_init *init)
607 struct nouveau_bios *bios = init->bios;
608 u8 count = nv_ro08(bios, init->offset + 1);
609 u16 repeat = init->repeat;
611 trace("REPEAT\t0x%02x\n", count);
614 init->repeat = init->offset;
615 init->repend = init->offset;
617 init->offset = init->repeat;
620 trace("REPEAT\t0x%02x\n", count);
622 init->offset = init->repend;
623 init->repeat = repeat;
627 * INIT_IO_RESTRICT_PLL - opcode 0x34
631 init_io_restrict_pll(struct nvbios_init *init)
633 struct nouveau_bios *bios = init->bios;
634 u16 port = nv_ro16(bios, init->offset + 1);
635 u8 index = nv_ro08(bios, init->offset + 3);
636 u8 mask = nv_ro08(bios, init->offset + 4);
637 u8 shift = nv_ro08(bios, init->offset + 5);
638 s8 iofc = nv_ro08(bios, init->offset + 6);
639 u8 count = nv_ro08(bios, init->offset + 7);
640 u32 reg = nv_ro32(bios, init->offset + 8);
643 trace("IO_RESTRICT_PLL\tR[0x%06x] =PLL= "
644 "((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) IOFCOND 0x%02x [{\n",
645 reg, port, index, mask, shift, iofc);
648 conf = (init_rdvgai(init, port, index) & mask) >> shift;
649 for (i = 0; i < count; i++) {
650 u32 freq = nv_ro16(bios, init->offset) * 10;
653 trace("\t%dkHz *\n", freq);
654 if (iofc > 0 && init_io_flag_condition_met(init, iofc))
656 init_prog_pll(init, reg, freq);
658 trace("\t%dkHz\n", freq);
667 * INIT_END_REPEAT - opcode 0x36
671 init_end_repeat(struct nvbios_init *init)
673 trace("END_REPEAT\n");
677 init->repend = init->offset;
683 * INIT_COPY - opcode 0x37
687 init_copy(struct nvbios_init *init)
689 struct nouveau_bios *bios = init->bios;
690 u32 reg = nv_ro32(bios, init->offset + 1);
691 u8 shift = nv_ro08(bios, init->offset + 5);
692 u8 smask = nv_ro08(bios, init->offset + 6);
693 u16 port = nv_ro16(bios, init->offset + 7);
694 u8 index = nv_ro08(bios, init->offset + 9);
695 u8 mask = nv_ro08(bios, init->offset + 10);
698 trace("COPY\t0x%04x[0x%02x] &= 0x%02x |= "
699 "((R[0x%06x] %s 0x%02x) & 0x%02x)\n",
700 port, index, mask, reg, (shift & 0x80) ? "<<" : ">>",
701 (shift & 0x80) ? (0x100 - shift) : shift, smask);
704 data = init_rdvgai(init, port, index) & mask;
705 data |= init_shift(init_rd32(init, reg), shift) & smask;
706 init_wrvgai(init, port, index, data);
710 * INIT_NOT - opcode 0x38
714 init_not(struct nvbios_init *init)
722 * INIT_IO_FLAG_CONDITION - opcode 0x39
726 init_io_flag_condition(struct nvbios_init *init)
728 struct nouveau_bios *bios = init->bios;
729 u8 cond = nv_ro08(bios, init->offset + 1);
731 trace("IO_FLAG_CONDITION\t0x%02x\n", cond);
734 if (!init_io_flag_condition_met(init, cond))
735 init_exec_set(init, false);
739 * INIT_DP_CONDITION - opcode 0x3a
743 init_dp_condition(struct nvbios_init *init)
745 struct nouveau_bios *bios = init->bios;
746 u8 cond = nv_ro08(bios, init->offset + 1);
747 u8 unkn = nv_ro08(bios, init->offset + 2);
751 trace("DP_CONDITION\t0x%02x 0x%02x\n", cond, unkn);
756 if (init_conn(init) != DCB_CONNECTOR_eDP)
757 init_exec_set(init, false);
762 (data = dp_outp_match(bios, init->outp, &ver, &len))) {
763 if (ver <= 0x40 && !(nv_ro08(bios, data + 5) & cond))
764 init_exec_set(init, false);
765 if (ver == 0x40 && !(nv_ro08(bios, data + 4) & cond))
766 init_exec_set(init, false);
770 warn("script needs dp output table data\n");
773 if (!(init_rdauxr(init, 0x0d) & 1))
774 init_exec_set(init, false);
777 warn("unknown dp condition 0x%02x\n", cond);
783 * INIT_IO_MASK_OR - opcode 0x3b
787 init_io_mask_or(struct nvbios_init *init)
789 struct nouveau_bios *bios = init->bios;
790 u8 index = nv_ro08(bios, init->offset + 1);
791 u8 or = init_or(init);
794 trace("IO_MASK_OR\t0x03d4[0x%02x] &= ~(1 << 0x%02x)", index, or);
797 data = init_rdvgai(init, 0x03d4, index);
798 init_wrvgai(init, 0x03d4, index, data &= ~(1 << or));
802 * INIT_IO_OR - opcode 0x3c
806 init_io_or(struct nvbios_init *init)
808 struct nouveau_bios *bios = init->bios;
809 u8 index = nv_ro08(bios, init->offset + 1);
810 u8 or = init_or(init);
813 trace("IO_OR\t0x03d4[0x%02x] |= (1 << 0x%02x)", index, or);
816 data = init_rdvgai(init, 0x03d4, index);
817 init_wrvgai(init, 0x03d4, index, data | (1 << or));
821 * INIT_INDEX_ADDRESS_LATCHED - opcode 0x49
825 init_idx_addr_latched(struct nvbios_init *init)
827 struct nouveau_bios *bios = init->bios;
828 u32 creg = nv_ro32(bios, init->offset + 1);
829 u32 dreg = nv_ro32(bios, init->offset + 5);
830 u32 mask = nv_ro32(bios, init->offset + 9);
831 u32 data = nv_ro32(bios, init->offset + 13);
832 u8 count = nv_ro08(bios, init->offset + 17);
834 trace("INDEX_ADDRESS_LATCHED\t"
835 "R[0x%06x] : R[0x%06x]\n\tCTRL &= 0x%08x |= 0x%08x\n",
836 creg, dreg, mask, data);
840 u8 iaddr = nv_ro08(bios, init->offset + 0);
841 u8 idata = nv_ro08(bios, init->offset + 1);
843 trace("\t[0x%02x] = 0x%02x\n", iaddr, idata);
846 init_wr32(init, dreg, idata);
847 init_mask(init, creg, ~mask, data | idata);
852 * INIT_IO_RESTRICT_PLL2 - opcode 0x4a
856 init_io_restrict_pll2(struct nvbios_init *init)
858 struct nouveau_bios *bios = init->bios;
859 u16 port = nv_ro16(bios, init->offset + 1);
860 u8 index = nv_ro08(bios, init->offset + 3);
861 u8 mask = nv_ro08(bios, init->offset + 4);
862 u8 shift = nv_ro08(bios, init->offset + 5);
863 u8 count = nv_ro08(bios, init->offset + 6);
864 u32 reg = nv_ro32(bios, init->offset + 7);
867 trace("IO_RESTRICT_PLL2\t"
868 "R[0x%06x] =PLL= ((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) [{\n",
869 reg, port, index, mask, shift);
872 conf = (init_rdvgai(init, port, index) & mask) >> shift;
873 for (i = 0; i < count; i++) {
874 u32 freq = nv_ro32(bios, init->offset);
876 trace("\t%dkHz *\n", freq);
877 init_prog_pll(init, reg, freq);
879 trace("\t%dkHz\n", freq);
887 * INIT_PLL2 - opcode 0x4b
891 init_pll2(struct nvbios_init *init)
893 struct nouveau_bios *bios = init->bios;
894 u32 reg = nv_ro32(bios, init->offset + 1);
895 u32 freq = nv_ro32(bios, init->offset + 5);
897 trace("PLL2\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
900 init_prog_pll(init, reg, freq);
904 * INIT_I2C_BYTE - opcode 0x4c
908 init_i2c_byte(struct nvbios_init *init)
910 struct nouveau_bios *bios = init->bios;
911 u8 index = nv_ro08(bios, init->offset + 1);
912 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
913 u8 count = nv_ro08(bios, init->offset + 3);
915 trace("I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
919 u8 reg = nv_ro08(bios, init->offset + 0);
920 u8 mask = nv_ro08(bios, init->offset + 1);
921 u8 data = nv_ro08(bios, init->offset + 2);
924 trace("\t[0x%02x] &= 0x%02x |= 0x%02x\n", reg, mask, data);
927 val = init_rdi2cr(init, index, addr, reg);
930 init_wri2cr(init, index, addr, reg, (val & mask) | data);
935 * INIT_ZM_I2C_BYTE - opcode 0x4d
939 init_zm_i2c_byte(struct nvbios_init *init)
941 struct nouveau_bios *bios = init->bios;
942 u8 index = nv_ro08(bios, init->offset + 1);
943 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
944 u8 count = nv_ro08(bios, init->offset + 3);
946 trace("ZM_I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
950 u8 reg = nv_ro08(bios, init->offset + 0);
951 u8 data = nv_ro08(bios, init->offset + 1);
953 trace("\t[0x%02x] = 0x%02x\n", reg, data);
956 init_wri2cr(init, index, addr, reg, data);
962 * INIT_ZM_I2C - opcode 0x4e
966 init_zm_i2c(struct nvbios_init *init)
968 struct nouveau_bios *bios = init->bios;
969 u8 index = nv_ro08(bios, init->offset + 1);
970 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
971 u8 count = nv_ro08(bios, init->offset + 3);
974 trace("ZM_I2C\tI2C[0x%02x][0x%02x]\n", index, addr);
977 for (i = 0; i < count; i++) {
978 data[i] = nv_ro08(bios, init->offset);
979 trace("\t0x%02x\n", data[i]);
983 if (init_exec(init)) {
984 struct nouveau_i2c_port *port = init_i2c(init, index);
985 struct i2c_msg msg = {
986 .addr = addr, .flags = 0, .len = count, .buf = data,
990 if (port && (ret = i2c_transfer(&port->adapter, &msg, 1)) != 1)
991 warn("i2c wr failed, %d\n", ret);
996 * INIT_TMDS - opcode 0x4f
1000 init_tmds(struct nvbios_init *init)
1002 struct nouveau_bios *bios = init->bios;
1003 u8 tmds = nv_ro08(bios, init->offset + 1);
1004 u8 addr = nv_ro08(bios, init->offset + 2);
1005 u8 mask = nv_ro08(bios, init->offset + 3);
1006 u8 data = nv_ro08(bios, init->offset + 4);
1007 u32 reg = init_tmds_reg(init, tmds);
1009 trace("TMDS\tT[0x%02x][0x%02x] &= 0x%02x |= 0x%02x\n",
1010 tmds, addr, mask, data);
1016 init_wr32(init, reg + 0, addr | 0x00010000);
1017 init_wr32(init, reg + 4, data | (init_rd32(init, reg + 4) & mask));
1018 init_wr32(init, reg + 0, addr);
1022 * INIT_ZM_TMDS_GROUP - opcode 0x50
1026 init_zm_tmds_group(struct nvbios_init *init)
1028 struct nouveau_bios *bios = init->bios;
1029 u8 tmds = nv_ro08(bios, init->offset + 1);
1030 u8 count = nv_ro08(bios, init->offset + 2);
1031 u32 reg = init_tmds_reg(init, tmds);
1033 trace("TMDS_ZM_GROUP\tT[0x%02x]\n", tmds);
1037 u8 addr = nv_ro08(bios, init->offset + 0);
1038 u8 data = nv_ro08(bios, init->offset + 1);
1040 trace("\t[0x%02x] = 0x%02x\n", addr, data);
1043 init_wr32(init, reg + 4, data);
1044 init_wr32(init, reg + 0, addr);
1049 * INIT_CR_INDEX_ADDRESS_LATCHED - opcode 0x51
1053 init_cr_idx_adr_latch(struct nvbios_init *init)
1055 struct nouveau_bios *bios = init->bios;
1056 u8 addr0 = nv_ro08(bios, init->offset + 1);
1057 u8 addr1 = nv_ro08(bios, init->offset + 2);
1058 u8 base = nv_ro08(bios, init->offset + 3);
1059 u8 count = nv_ro08(bios, init->offset + 4);
1062 trace("CR_INDEX_ADDR C[%02x] C[%02x]\n", addr0, addr1);
1065 save0 = init_rdvgai(init, 0x03d4, addr0);
1067 u8 data = nv_ro08(bios, init->offset);
1069 trace("\t\t[0x%02x] = 0x%02x\n", base, data);
1072 init_wrvgai(init, 0x03d4, addr0, base++);
1073 init_wrvgai(init, 0x03d4, addr1, data);
1075 init_wrvgai(init, 0x03d4, addr0, save0);
1079 * INIT_CR - opcode 0x52
1083 init_cr(struct nvbios_init *init)
1085 struct nouveau_bios *bios = init->bios;
1086 u8 addr = nv_ro08(bios, init->offset + 1);
1087 u8 mask = nv_ro08(bios, init->offset + 2);
1088 u8 data = nv_ro08(bios, init->offset + 3);
1091 trace("CR\t\tC[0x%02x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1094 val = init_rdvgai(init, 0x03d4, addr) & mask;
1095 init_wrvgai(init, 0x03d4, addr, val | data);
1099 * INIT_ZM_CR - opcode 0x53
1103 init_zm_cr(struct nvbios_init *init)
1105 struct nouveau_bios *bios = init->bios;
1106 u8 addr = nv_ro08(bios, init->offset + 1);
1107 u8 data = nv_ro08(bios, init->offset + 2);
1109 trace("ZM_CR\tC[0x%02x] = 0x%02x\n", addr, data);
1112 init_wrvgai(init, 0x03d4, addr, data);
1116 * INIT_ZM_CR_GROUP - opcode 0x54
1120 init_zm_cr_group(struct nvbios_init *init)
1122 struct nouveau_bios *bios = init->bios;
1123 u8 count = nv_ro08(bios, init->offset + 1);
1125 trace("ZM_CR_GROUP\n");
1129 u8 addr = nv_ro08(bios, init->offset + 0);
1130 u8 data = nv_ro08(bios, init->offset + 1);
1132 trace("\t\tC[0x%02x] = 0x%02x\n", addr, data);
1135 init_wrvgai(init, 0x03d4, addr, data);
1140 * INIT_CONDITION_TIME - opcode 0x56
1144 init_condition_time(struct nvbios_init *init)
1146 struct nouveau_bios *bios = init->bios;
1147 u8 cond = nv_ro08(bios, init->offset + 1);
1148 u8 retry = nv_ro08(bios, init->offset + 2);
1149 u8 wait = min((u16)retry * 50, 100);
1151 trace("CONDITION_TIME\t0x%02x 0x%02x\n", cond, retry);
1154 if (!init_exec(init))
1158 if (init_condition_met(init, cond))
1163 init_exec_set(init, false);
1167 * INIT_LTIME - opcode 0x57
1171 init_ltime(struct nvbios_init *init)
1173 struct nouveau_bios *bios = init->bios;
1174 u16 msec = nv_ro16(bios, init->offset + 1);
1176 trace("LTIME\t0x%04x\n", msec);
1179 if (init_exec(init))
1184 * INIT_ZM_REG_SEQUENCE - opcode 0x58
1188 init_zm_reg_sequence(struct nvbios_init *init)
1190 struct nouveau_bios *bios = init->bios;
1191 u32 base = nv_ro32(bios, init->offset + 1);
1192 u8 count = nv_ro08(bios, init->offset + 5);
1194 trace("ZM_REG_SEQUENCE\t0x%02x\n", count);
1198 u32 data = nv_ro32(bios, init->offset);
1200 trace("\t\tR[0x%06x] = 0x%08x\n", base, data);
1203 init_wr32(init, base, data);
1209 * INIT_SUB_DIRECT - opcode 0x5b
1213 init_sub_direct(struct nvbios_init *init)
1215 struct nouveau_bios *bios = init->bios;
1216 u16 addr = nv_ro16(bios, init->offset + 1);
1219 trace("SUB_DIRECT\t0x%04x\n", addr);
1221 if (init_exec(init)) {
1222 save = init->offset;
1223 init->offset = addr;
1224 if (nvbios_exec(init)) {
1225 error("error parsing sub-table\n");
1228 init->offset = save;
1235 * INIT_JUMP - opcode 0x5c
1239 init_jump(struct nvbios_init *init)
1241 struct nouveau_bios *bios = init->bios;
1242 u16 offset = nv_ro16(bios, init->offset + 1);
1244 trace("JUMP\t0x%04x\n", offset);
1245 init->offset = offset;
1249 * INIT_I2C_IF - opcode 0x5e
1253 init_i2c_if(struct nvbios_init *init)
1255 struct nouveau_bios *bios = init->bios;
1256 u8 index = nv_ro08(bios, init->offset + 1);
1257 u8 addr = nv_ro08(bios, init->offset + 2);
1258 u8 reg = nv_ro08(bios, init->offset + 3);
1259 u8 mask = nv_ro08(bios, init->offset + 4);
1260 u8 data = nv_ro08(bios, init->offset + 5);
1263 trace("I2C_IF\tI2C[0x%02x][0x%02x][0x%02x] & 0x%02x == 0x%02x\n",
1264 index, addr, reg, mask, data);
1266 init_exec_force(init, true);
1268 value = init_rdi2cr(init, index, addr, reg);
1269 if ((value & mask) != data)
1270 init_exec_set(init, false);
1272 init_exec_force(init, false);
1276 * INIT_COPY_NV_REG - opcode 0x5f
1280 init_copy_nv_reg(struct nvbios_init *init)
1282 struct nouveau_bios *bios = init->bios;
1283 u32 sreg = nv_ro32(bios, init->offset + 1);
1284 u8 shift = nv_ro08(bios, init->offset + 5);
1285 u32 smask = nv_ro32(bios, init->offset + 6);
1286 u32 sxor = nv_ro32(bios, init->offset + 10);
1287 u32 dreg = nv_ro32(bios, init->offset + 14);
1288 u32 dmask = nv_ro32(bios, init->offset + 18);
1291 trace("COPY_NV_REG\tR[0x%06x] &= 0x%08x |= "
1292 "((R[0x%06x] %s 0x%02x) & 0x%08x ^ 0x%08x)\n",
1293 dreg, dmask, sreg, (shift & 0x80) ? "<<" : ">>",
1294 (shift & 0x80) ? (0x100 - shift) : shift, smask, sxor);
1297 data = init_shift(init_rd32(init, sreg), shift);
1298 init_mask(init, dreg, ~dmask, (data & smask) ^ sxor);
1302 * INIT_ZM_INDEX_IO - opcode 0x62
1306 init_zm_index_io(struct nvbios_init *init)
1308 struct nouveau_bios *bios = init->bios;
1309 u16 port = nv_ro16(bios, init->offset + 1);
1310 u8 index = nv_ro08(bios, init->offset + 3);
1311 u8 data = nv_ro08(bios, init->offset + 4);
1313 trace("ZM_INDEX_IO\tI[0x%04x][0x%02x] = 0x%02x\n", port, index, data);
1316 init_wrvgai(init, port, index, data);
1320 * INIT_COMPUTE_MEM - opcode 0x63
1324 init_compute_mem(struct nvbios_init *init)
1326 struct nouveau_devinit *devinit = nouveau_devinit(init->bios);
1328 trace("COMPUTE_MEM\n");
1331 init_exec_force(init, true);
1332 if (init_exec(init) && devinit->meminit)
1333 devinit->meminit(devinit);
1334 init_exec_force(init, false);
1338 * INIT_RESET - opcode 0x65
1342 init_reset(struct nvbios_init *init)
1344 struct nouveau_bios *bios = init->bios;
1345 u32 reg = nv_ro32(bios, init->offset + 1);
1346 u32 data1 = nv_ro32(bios, init->offset + 5);
1347 u32 data2 = nv_ro32(bios, init->offset + 9);
1350 trace("RESET\tR[0x%08x] = 0x%08x, 0x%08x", reg, data1, data2);
1352 init_exec_force(init, true);
1354 savepci19 = init_mask(init, 0x00184c, 0x00000f00, 0x00000000);
1355 init_wr32(init, reg, data1);
1357 init_wr32(init, reg, data2);
1358 init_wr32(init, 0x00184c, savepci19);
1359 init_mask(init, 0x001850, 0x00000001, 0x00000000);
1361 init_exec_force(init, false);
1365 * INIT_CONFIGURE_MEM - opcode 0x66
1369 init_configure_mem_clk(struct nvbios_init *init)
1371 u16 mdata = bmp_mem_init_table(init->bios);
1373 mdata += (init_rdvgai(init, 0x03d4, 0x3c) >> 4) * 66;
1378 init_configure_mem(struct nvbios_init *init)
1380 struct nouveau_bios *bios = init->bios;
1384 trace("CONFIGURE_MEM\n");
1387 if (bios->version.major > 2) {
1391 init_exec_force(init, true);
1393 mdata = init_configure_mem_clk(init);
1394 sdata = bmp_sdr_seq_table(bios);
1395 if (nv_ro08(bios, mdata) & 0x01)
1396 sdata = bmp_ddr_seq_table(bios);
1397 mdata += 6; /* skip to data */
1399 data = init_rdvgai(init, 0x03c4, 0x01);
1400 init_wrvgai(init, 0x03c4, 0x01, data | 0x20);
1402 while ((addr = nv_ro32(bios, sdata)) != 0xffffffff) {
1404 case 0x10021c: /* CKE_NORMAL */
1405 case 0x1002d0: /* CMD_REFRESH */
1406 case 0x1002d4: /* CMD_PRECHARGE */
1410 data = nv_ro32(bios, mdata);
1412 if (data == 0xffffffff)
1417 init_wr32(init, addr, data);
1420 init_exec_force(init, false);
1424 * INIT_CONFIGURE_CLK - opcode 0x67
1428 init_configure_clk(struct nvbios_init *init)
1430 struct nouveau_bios *bios = init->bios;
1433 trace("CONFIGURE_CLK\n");
1436 if (bios->version.major > 2) {
1440 init_exec_force(init, true);
1442 mdata = init_configure_mem_clk(init);
1445 clock = nv_ro16(bios, mdata + 4) * 10;
1446 init_prog_pll(init, 0x680500, clock);
1449 clock = nv_ro16(bios, mdata + 2) * 10;
1450 if (nv_ro08(bios, mdata) & 0x01)
1452 init_prog_pll(init, 0x680504, clock);
1454 init_exec_force(init, false);
1458 * INIT_CONFIGURE_PREINIT - opcode 0x68
1462 init_configure_preinit(struct nvbios_init *init)
1464 struct nouveau_bios *bios = init->bios;
1467 trace("CONFIGURE_PREINIT\n");
1470 if (bios->version.major > 2) {
1474 init_exec_force(init, true);
1476 strap = init_rd32(init, 0x101000);
1477 strap = ((strap << 2) & 0xf0) | ((strap & 0x40) >> 6);
1478 init_wrvgai(init, 0x03d4, 0x3c, strap);
1480 init_exec_force(init, false);
1484 * INIT_IO - opcode 0x69
1488 init_io(struct nvbios_init *init)
1490 struct nouveau_bios *bios = init->bios;
1491 u16 port = nv_ro16(bios, init->offset + 1);
1492 u8 mask = nv_ro16(bios, init->offset + 3);
1493 u8 data = nv_ro16(bios, init->offset + 4);
1496 trace("IO\t\tI[0x%04x] &= 0x%02x |= 0x%02x\n", port, mask, data);
1499 /* ummm.. yes.. should really figure out wtf this is and why it's
1500 * needed some day.. it's almost certainly wrong, but, it also
1501 * somehow makes things work...
1503 if (nv_device(init->bios)->card_type >= NV_50 &&
1504 port == 0x03c3 && data == 0x01) {
1505 init_mask(init, 0x614100, 0xf0800000, 0x00800000);
1506 init_mask(init, 0x00e18c, 0x00020000, 0x00020000);
1507 init_mask(init, 0x614900, 0xf0800000, 0x00800000);
1508 init_mask(init, 0x000200, 0x40000000, 0x00000000);
1510 init_mask(init, 0x00e18c, 0x00020000, 0x00000000);
1511 init_mask(init, 0x000200, 0x40000000, 0x40000000);
1512 init_wr32(init, 0x614100, 0x00800018);
1513 init_wr32(init, 0x614900, 0x00800018);
1515 init_wr32(init, 0x614100, 0x10000018);
1516 init_wr32(init, 0x614900, 0x10000018);
1520 value = init_rdport(init, port) & mask;
1521 init_wrport(init, port, data | value);
1525 * INIT_SUB - opcode 0x6b
1529 init_sub(struct nvbios_init *init)
1531 struct nouveau_bios *bios = init->bios;
1532 u8 index = nv_ro08(bios, init->offset + 1);
1535 trace("SUB\t0x%02x\n", index);
1537 addr = init_script(bios, index);
1538 if (addr && init_exec(init)) {
1539 save = init->offset;
1540 init->offset = addr;
1541 if (nvbios_exec(init)) {
1542 error("error parsing sub-table\n");
1545 init->offset = save;
1552 * INIT_RAM_CONDITION - opcode 0x6d
1556 init_ram_condition(struct nvbios_init *init)
1558 struct nouveau_bios *bios = init->bios;
1559 u8 mask = nv_ro08(bios, init->offset + 1);
1560 u8 value = nv_ro08(bios, init->offset + 2);
1562 trace("RAM_CONDITION\t"
1563 "(R[0x100000] & 0x%02x) == 0x%02x\n", mask, value);
1566 if ((init_rd32(init, 0x100000) & mask) != value)
1567 init_exec_set(init, false);
1571 * INIT_NV_REG - opcode 0x6e
1575 init_nv_reg(struct nvbios_init *init)
1577 struct nouveau_bios *bios = init->bios;
1578 u32 reg = nv_ro32(bios, init->offset + 1);
1579 u32 mask = nv_ro32(bios, init->offset + 5);
1580 u32 data = nv_ro32(bios, init->offset + 9);
1582 trace("NV_REG\tR[0x%06x] &= 0x%08x |= 0x%08x\n", reg, mask, data);
1585 init_mask(init, reg, ~mask, data);
1589 * INIT_MACRO - opcode 0x6f
1593 init_macro(struct nvbios_init *init)
1595 struct nouveau_bios *bios = init->bios;
1596 u8 macro = nv_ro08(bios, init->offset + 1);
1599 trace("MACRO\t0x%02x\n", macro);
1601 table = init_macro_table(init);
1603 u32 addr = nv_ro32(bios, table + (macro * 8) + 0);
1604 u32 data = nv_ro32(bios, table + (macro * 8) + 4);
1605 trace("\t\tR[0x%06x] = 0x%08x\n", addr, data);
1606 init_wr32(init, addr, data);
1613 * INIT_RESUME - opcode 0x72
1617 init_resume(struct nvbios_init *init)
1621 init_exec_set(init, true);
1625 * INIT_TIME - opcode 0x74
1629 init_time(struct nvbios_init *init)
1631 struct nouveau_bios *bios = init->bios;
1632 u16 usec = nv_ro16(bios, init->offset + 1);
1634 trace("TIME\t0x%04x\n", usec);
1637 if (init_exec(init)) {
1641 mdelay((usec + 900) / 1000);
1646 * INIT_CONDITION - opcode 0x75
1650 init_condition(struct nvbios_init *init)
1652 struct nouveau_bios *bios = init->bios;
1653 u8 cond = nv_ro08(bios, init->offset + 1);
1655 trace("CONDITION\t0x%02x\n", cond);
1658 if (!init_condition_met(init, cond))
1659 init_exec_set(init, false);
1663 * INIT_IO_CONDITION - opcode 0x76
1667 init_io_condition(struct nvbios_init *init)
1669 struct nouveau_bios *bios = init->bios;
1670 u8 cond = nv_ro08(bios, init->offset + 1);
1672 trace("IO_CONDITION\t0x%02x\n", cond);
1675 if (!init_io_condition_met(init, cond))
1676 init_exec_set(init, false);
1680 * INIT_INDEX_IO - opcode 0x78
1684 init_index_io(struct nvbios_init *init)
1686 struct nouveau_bios *bios = init->bios;
1687 u16 port = nv_ro16(bios, init->offset + 1);
1688 u8 index = nv_ro16(bios, init->offset + 3);
1689 u8 mask = nv_ro08(bios, init->offset + 4);
1690 u8 data = nv_ro08(bios, init->offset + 5);
1693 trace("INDEX_IO\tI[0x%04x][0x%02x] &= 0x%02x |= 0x%02x\n",
1694 port, index, mask, data);
1697 value = init_rdvgai(init, port, index) & mask;
1698 init_wrvgai(init, port, index, data | value);
1702 * INIT_PLL - opcode 0x79
1706 init_pll(struct nvbios_init *init)
1708 struct nouveau_bios *bios = init->bios;
1709 u32 reg = nv_ro32(bios, init->offset + 1);
1710 u32 freq = nv_ro16(bios, init->offset + 5) * 10;
1712 trace("PLL\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
1715 init_prog_pll(init, reg, freq);
1719 * INIT_ZM_REG - opcode 0x7a
1723 init_zm_reg(struct nvbios_init *init)
1725 struct nouveau_bios *bios = init->bios;
1726 u32 addr = nv_ro32(bios, init->offset + 1);
1727 u32 data = nv_ro32(bios, init->offset + 5);
1729 trace("ZM_REG\tR[0x%06x] = 0x%08x\n", addr, data);
1732 if (addr == 0x000200)
1735 init_wr32(init, addr, data);
1739 * INIT_RAM_RESTRICT_PLL - opcde 0x87
1743 init_ram_restrict_pll(struct nvbios_init *init)
1745 struct nouveau_bios *bios = init->bios;
1746 u8 type = nv_ro08(bios, init->offset + 1);
1747 u8 count = init_ram_restrict_group_count(init);
1748 u8 strap = init_ram_restrict(init);
1751 trace("RAM_RESTRICT_PLL\t0x%02x\n", type);
1754 for (cconf = 0; cconf < count; cconf++) {
1755 u32 freq = nv_ro32(bios, init->offset);
1757 if (cconf == strap) {
1758 trace("%dkHz *\n", freq);
1759 init_prog_pll(init, type, freq);
1761 trace("%dkHz\n", freq);
1769 * INIT_GPIO - opcode 0x8e
1773 init_gpio(struct nvbios_init *init)
1775 struct nouveau_gpio *gpio = nouveau_gpio(init->bios);
1780 if (init_exec(init) && gpio && gpio->reset)
1785 * INIT_RAM_RESTRICT_ZM_GROUP - opcode 0x8f
1789 init_ram_restrict_zm_reg_group(struct nvbios_init *init)
1791 struct nouveau_bios *bios = init->bios;
1792 u32 addr = nv_ro32(bios, init->offset + 1);
1793 u8 incr = nv_ro08(bios, init->offset + 5);
1794 u8 num = nv_ro08(bios, init->offset + 6);
1795 u8 count = init_ram_restrict_group_count(init);
1796 u8 index = init_ram_restrict(init);
1799 trace("RAM_RESTRICT_ZM_REG_GROUP\t"
1800 "R[%08x] 0x%02x 0x%02x\n", addr, incr, num);
1803 for (i = 0; i < num; i++) {
1804 trace("\tR[0x%06x] = {\n", addr);
1805 for (j = 0; j < count; j++) {
1806 u32 data = nv_ro32(bios, init->offset);
1809 trace("\t\t0x%08x *\n", data);
1810 init_wr32(init, addr, data);
1812 trace("\t\t0x%08x\n", data);
1823 * INIT_COPY_ZM_REG - opcode 0x90
1827 init_copy_zm_reg(struct nvbios_init *init)
1829 struct nouveau_bios *bios = init->bios;
1830 u32 sreg = nv_ro32(bios, init->offset + 1);
1831 u32 dreg = nv_ro32(bios, init->offset + 5);
1833 trace("COPY_ZM_REG\tR[0x%06x] = R[0x%06x]\n", sreg, dreg);
1836 init_wr32(init, dreg, init_rd32(init, sreg));
1840 * INIT_ZM_REG_GROUP - opcode 0x91
1844 init_zm_reg_group(struct nvbios_init *init)
1846 struct nouveau_bios *bios = init->bios;
1847 u32 addr = nv_ro32(bios, init->offset + 1);
1848 u8 count = nv_ro08(bios, init->offset + 5);
1850 trace("ZM_REG_GROUP\tR[0x%06x] =\n");
1854 u32 data = nv_ro32(bios, init->offset);
1855 trace("\t0x%08x\n", data);
1856 init_wr32(init, addr, data);
1862 * INIT_XLAT - opcode 0x96
1866 init_xlat(struct nvbios_init *init)
1868 struct nouveau_bios *bios = init->bios;
1869 u32 saddr = nv_ro32(bios, init->offset + 1);
1870 u8 sshift = nv_ro08(bios, init->offset + 5);
1871 u8 smask = nv_ro08(bios, init->offset + 6);
1872 u8 index = nv_ro08(bios, init->offset + 7);
1873 u32 daddr = nv_ro32(bios, init->offset + 8);
1874 u32 dmask = nv_ro32(bios, init->offset + 12);
1875 u8 shift = nv_ro08(bios, init->offset + 16);
1878 trace("INIT_XLAT\tR[0x%06x] &= 0x%08x |= "
1879 "(X%02x((R[0x%06x] %s 0x%02x) & 0x%02x) << 0x%02x)\n",
1880 daddr, dmask, index, saddr, (sshift & 0x80) ? "<<" : ">>",
1881 (sshift & 0x80) ? (0x100 - sshift) : sshift, smask, shift);
1884 data = init_shift(init_rd32(init, saddr), sshift) & smask;
1885 data = init_xlat_(init, index, data) << shift;
1886 init_mask(init, daddr, ~dmask, data);
1890 * INIT_ZM_MASK_ADD - opcode 0x97
1894 init_zm_mask_add(struct nvbios_init *init)
1896 struct nouveau_bios *bios = init->bios;
1897 u32 addr = nv_ro32(bios, init->offset + 1);
1898 u32 mask = nv_ro32(bios, init->offset + 5);
1899 u32 add = nv_ro32(bios, init->offset + 9);
1902 trace("ZM_MASK_ADD\tR[0x%06x] &= 0x%08x += 0x%08x\n", addr, mask, add);
1905 data = init_rd32(init, addr) & mask;
1906 data |= ((data + add) & ~mask);
1907 init_wr32(init, addr, data);
1911 * INIT_AUXCH - opcode 0x98
1915 init_auxch(struct nvbios_init *init)
1917 struct nouveau_bios *bios = init->bios;
1918 u32 addr = nv_ro32(bios, init->offset + 1);
1919 u8 count = nv_ro08(bios, init->offset + 5);
1921 trace("AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
1925 u8 mask = nv_ro08(bios, init->offset + 0);
1926 u8 data = nv_ro08(bios, init->offset + 1);
1927 trace("\tAUX[0x%08x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1928 mask = init_rdauxr(init, addr) & mask;
1929 init_wrauxr(init, addr, mask | data);
1935 * INIT_AUXCH - opcode 0x99
1939 init_zm_auxch(struct nvbios_init *init)
1941 struct nouveau_bios *bios = init->bios;
1942 u32 addr = nv_ro32(bios, init->offset + 1);
1943 u8 count = nv_ro08(bios, init->offset + 5);
1945 trace("ZM_AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
1949 u8 data = nv_ro08(bios, init->offset + 0);
1950 trace("\tAUX[0x%08x] = 0x%02x\n", addr, data);
1951 init_wrauxr(init, addr, data);
1957 * INIT_I2C_LONG_IF - opcode 0x9a
1961 init_i2c_long_if(struct nvbios_init *init)
1963 struct nouveau_bios *bios = init->bios;
1964 u8 index = nv_ro08(bios, init->offset + 1);
1965 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
1966 u8 reglo = nv_ro08(bios, init->offset + 3);
1967 u8 reghi = nv_ro08(bios, init->offset + 4);
1968 u8 mask = nv_ro08(bios, init->offset + 5);
1969 u8 data = nv_ro08(bios, init->offset + 6);
1970 struct nouveau_i2c_port *port;
1972 trace("I2C_LONG_IF\t"
1973 "I2C[0x%02x][0x%02x][0x%02x%02x] & 0x%02x == 0x%02x\n",
1974 index, addr, reglo, reghi, mask, data);
1977 port = init_i2c(init, index);
1979 u8 i[2] = { reghi, reglo };
1981 struct i2c_msg msg[] = {
1982 { .addr = addr, .flags = 0, .len = 2, .buf = i },
1983 { .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = o }
1987 ret = i2c_transfer(&port->adapter, msg, 2);
1988 if (ret == 2 && ((o[0] & mask) == data))
1992 init_exec_set(init, false);
1995 static struct nvbios_init_opcode {
1996 void (*exec)(struct nvbios_init *);
1998 [0x32] = { init_io_restrict_prog },
1999 [0x33] = { init_repeat },
2000 [0x34] = { init_io_restrict_pll },
2001 [0x36] = { init_end_repeat },
2002 [0x37] = { init_copy },
2003 [0x38] = { init_not },
2004 [0x39] = { init_io_flag_condition },
2005 [0x3a] = { init_dp_condition },
2006 [0x3b] = { init_io_mask_or },
2007 [0x3c] = { init_io_or },
2008 [0x49] = { init_idx_addr_latched },
2009 [0x4a] = { init_io_restrict_pll2 },
2010 [0x4b] = { init_pll2 },
2011 [0x4c] = { init_i2c_byte },
2012 [0x4d] = { init_zm_i2c_byte },
2013 [0x4e] = { init_zm_i2c },
2014 [0x4f] = { init_tmds },
2015 [0x50] = { init_zm_tmds_group },
2016 [0x51] = { init_cr_idx_adr_latch },
2017 [0x52] = { init_cr },
2018 [0x53] = { init_zm_cr },
2019 [0x54] = { init_zm_cr_group },
2020 [0x56] = { init_condition_time },
2021 [0x57] = { init_ltime },
2022 [0x58] = { init_zm_reg_sequence },
2023 [0x5b] = { init_sub_direct },
2024 [0x5c] = { init_jump },
2025 [0x5e] = { init_i2c_if },
2026 [0x5f] = { init_copy_nv_reg },
2027 [0x62] = { init_zm_index_io },
2028 [0x63] = { init_compute_mem },
2029 [0x65] = { init_reset },
2030 [0x66] = { init_configure_mem },
2031 [0x67] = { init_configure_clk },
2032 [0x68] = { init_configure_preinit },
2033 [0x69] = { init_io },
2034 [0x6b] = { init_sub },
2035 [0x6d] = { init_ram_condition },
2036 [0x6e] = { init_nv_reg },
2037 [0x6f] = { init_macro },
2038 [0x71] = { init_done },
2039 [0x72] = { init_resume },
2040 [0x74] = { init_time },
2041 [0x75] = { init_condition },
2042 [0x76] = { init_io_condition },
2043 [0x78] = { init_index_io },
2044 [0x79] = { init_pll },
2045 [0x7a] = { init_zm_reg },
2046 [0x87] = { init_ram_restrict_pll },
2047 [0x8c] = { init_reserved },
2048 [0x8d] = { init_reserved },
2049 [0x8e] = { init_gpio },
2050 [0x8f] = { init_ram_restrict_zm_reg_group },
2051 [0x90] = { init_copy_zm_reg },
2052 [0x91] = { init_zm_reg_group },
2053 [0x92] = { init_reserved },
2054 [0x96] = { init_xlat },
2055 [0x97] = { init_zm_mask_add },
2056 [0x98] = { init_auxch },
2057 [0x99] = { init_zm_auxch },
2058 [0x9a] = { init_i2c_long_if },
2061 #define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
2064 nvbios_exec(struct nvbios_init *init)
2067 while (init->offset) {
2068 u8 opcode = nv_ro08(init->bios, init->offset);
2069 if (opcode >= init_opcode_nr || !init_opcode[opcode].exec) {
2070 error("unknown opcode 0x%02x\n", opcode);
2074 init_opcode[opcode].exec(init);
2081 nvbios_init(struct nouveau_subdev *subdev, bool execute)
2083 struct nouveau_bios *bios = nouveau_bios(subdev);
2089 nv_info(bios, "running init tables\n");
2090 while (!ret && (data = (init_script(bios, ++i)))) {
2091 struct nvbios_init init = {
2097 .execute = execute ? 1 : 0,
2100 ret = nvbios_exec(&init);
2103 /* the vbios parser will run this right after the normal init
2104 * tables, whereas the binary driver appears to run it later.
2106 if (!ret && (data = init_unknown_script(bios))) {
2107 struct nvbios_init init = {
2113 .execute = execute ? 1 : 0,
2116 ret = nvbios_exec(&init);