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/bios/ramcfg.h>
13 #include <subdev/devinit.h>
14 #include <subdev/i2c.h>
15 #include <subdev/vga.h>
16 #include <subdev/gpio.h>
18 #define bioslog(lvl, fmt, args...) do { \
19 nv_printk(init->bios, lvl, "0x%04x[%c]: "fmt, init->offset, \
20 init_exec(init) ? '0' + (init->nested - 1) : ' ', ##args); \
22 #define cont(fmt, args...) do { \
23 if (nv_subdev(init->bios)->debug >= NV_DBG_TRACE) \
24 printk(fmt, ##args); \
26 #define trace(fmt, args...) bioslog(TRACE, fmt, ##args)
27 #define warn(fmt, args...) bioslog(WARN, fmt, ##args)
28 #define error(fmt, args...) bioslog(ERROR, fmt, ##args)
30 /******************************************************************************
31 * init parser control flow helpers
32 *****************************************************************************/
35 init_exec(struct nvbios_init *init)
37 return (init->execute == 1) || ((init->execute & 5) == 5);
41 init_exec_set(struct nvbios_init *init, bool exec)
43 if (exec) init->execute &= 0xfd;
44 else init->execute |= 0x02;
48 init_exec_inv(struct nvbios_init *init)
50 init->execute ^= 0x02;
54 init_exec_force(struct nvbios_init *init, bool exec)
56 if (exec) init->execute |= 0x04;
57 else init->execute &= 0xfb;
60 /******************************************************************************
61 * init parser wrappers for normal register/i2c/whatever accessors
62 *****************************************************************************/
65 init_or(struct nvbios_init *init)
67 if (init_exec(init)) {
69 return ffs(init->outp->or) - 1;
70 error("script needs OR!!\n");
76 init_link(struct nvbios_init *init)
78 if (init_exec(init)) {
80 return !(init->outp->sorconf.link & 1);
81 error("script needs OR link\n");
87 init_crtc(struct nvbios_init *init)
89 if (init_exec(init)) {
92 error("script needs crtc\n");
98 init_conn(struct nvbios_init *init)
100 struct nouveau_bios *bios = init->bios;
104 if (init_exec(init)) {
106 conn = init->outp->connector;
107 conn = dcb_conn(bios, conn, &ver, &len);
109 return nv_ro08(bios, conn);
112 error("script needs connector type\n");
119 init_nvreg(struct nvbios_init *init, u32 reg)
121 /* C51 (at least) sometimes has the lower bits set which the VBIOS
122 * interprets to mean that access needs to go through certain IO
123 * ports instead. The NVIDIA binary driver has been seen to access
124 * these through the NV register address, so lets assume we can
129 /* GF8+ display scripts need register addresses mangled a bit to
130 * select a specific CRTC/OR
132 if (nv_device(init->bios)->card_type >= NV_50) {
133 if (reg & 0x80000000) {
134 reg += init_crtc(init) * 0x800;
138 if (reg & 0x40000000) {
139 reg += init_or(init) * 0x800;
141 if (reg & 0x20000000) {
142 reg += init_link(init) * 0x80;
148 if (reg & ~0x00fffffc)
149 warn("unknown bits in register 0x%08x\n", reg);
154 init_rd32(struct nvbios_init *init, u32 reg)
156 reg = init_nvreg(init, reg);
158 return nv_rd32(init->subdev, reg);
163 init_wr32(struct nvbios_init *init, u32 reg, u32 val)
165 reg = init_nvreg(init, reg);
167 nv_wr32(init->subdev, reg, val);
171 init_mask(struct nvbios_init *init, u32 reg, u32 mask, u32 val)
173 reg = init_nvreg(init, reg);
174 if (init_exec(init)) {
175 u32 tmp = nv_rd32(init->subdev, reg);
176 nv_wr32(init->subdev, reg, (tmp & ~mask) | val);
183 init_rdport(struct nvbios_init *init, u16 port)
186 return nv_rdport(init->subdev, init->crtc, port);
191 init_wrport(struct nvbios_init *init, u16 port, u8 value)
194 nv_wrport(init->subdev, init->crtc, port, value);
198 init_rdvgai(struct nvbios_init *init, u16 port, u8 index)
200 struct nouveau_subdev *subdev = init->subdev;
201 if (init_exec(init)) {
202 int head = init->crtc < 0 ? 0 : init->crtc;
203 return nv_rdvgai(subdev, head, port, index);
209 init_wrvgai(struct nvbios_init *init, u16 port, u8 index, u8 value)
211 /* force head 0 for updates to cr44, it only exists on first head */
212 if (nv_device(init->subdev)->card_type < NV_50) {
213 if (port == 0x03d4 && index == 0x44)
217 if (init_exec(init)) {
218 int head = init->crtc < 0 ? 0 : init->crtc;
219 nv_wrvgai(init->subdev, head, port, index, value);
222 /* select head 1 if cr44 write selected it */
223 if (nv_device(init->subdev)->card_type < NV_50) {
224 if (port == 0x03d4 && index == 0x44 && value == 3)
229 static struct nouveau_i2c_port *
230 init_i2c(struct nvbios_init *init, int index)
232 struct nouveau_i2c *i2c = nouveau_i2c(init->bios);
235 index = NV_I2C_DEFAULT(0);
236 if (init->outp && init->outp->i2c_upper_default)
237 index = NV_I2C_DEFAULT(1);
242 error("script needs output for i2c\n");
246 if (index == -2 && init->outp->location) {
247 index = NV_I2C_TYPE_EXTAUX(init->outp->extdev);
248 return i2c->find_type(i2c, index);
251 index = init->outp->i2c_index;
254 return i2c->find(i2c, index);
258 init_rdi2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg)
260 struct nouveau_i2c_port *port = init_i2c(init, index);
261 if (port && init_exec(init))
262 return nv_rdi2cr(port, addr, reg);
267 init_wri2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg, u8 val)
269 struct nouveau_i2c_port *port = init_i2c(init, index);
270 if (port && init_exec(init))
271 return nv_wri2cr(port, addr, reg, val);
276 init_rdauxr(struct nvbios_init *init, u32 addr)
278 struct nouveau_i2c_port *port = init_i2c(init, -2);
281 if (port && init_exec(init)) {
282 int ret = nv_rdaux(port, addr, &data, 1);
292 init_wrauxr(struct nvbios_init *init, u32 addr, u8 data)
294 struct nouveau_i2c_port *port = init_i2c(init, -2);
295 if (port && init_exec(init))
296 return nv_wraux(port, addr, &data, 1);
301 init_prog_pll(struct nvbios_init *init, u32 id, u32 freq)
303 struct nouveau_devinit *devinit = nouveau_devinit(init->bios);
304 if (devinit->pll_set && init_exec(init)) {
305 int ret = devinit->pll_set(devinit, id, freq);
307 warn("failed to prog pll 0x%08x to %dkHz\n", id, freq);
311 /******************************************************************************
312 * parsing of bios structures that are required to execute init tables
313 *****************************************************************************/
316 init_table(struct nouveau_bios *bios, u16 *len)
318 struct bit_entry bit_I;
320 if (!bit_entry(bios, 'I', &bit_I)) {
325 if (bmp_version(bios) >= 0x0510) {
327 return bios->bmp_offset + 75;
334 init_table_(struct nvbios_init *init, u16 offset, const char *name)
336 struct nouveau_bios *bios = init->bios;
337 u16 len, data = init_table(bios, &len);
339 if (len >= offset + 2) {
340 data = nv_ro16(bios, data + offset);
344 warn("%s pointer invalid\n", name);
348 warn("init data too short for %s pointer", name);
352 warn("init data not found\n");
356 #define init_script_table(b) init_table_((b), 0x00, "script table")
357 #define init_macro_index_table(b) init_table_((b), 0x02, "macro index table")
358 #define init_macro_table(b) init_table_((b), 0x04, "macro table")
359 #define init_condition_table(b) init_table_((b), 0x06, "condition table")
360 #define init_io_condition_table(b) init_table_((b), 0x08, "io condition table")
361 #define init_io_flag_condition_table(b) init_table_((b), 0x0a, "io flag conditon table")
362 #define init_function_table(b) init_table_((b), 0x0c, "function table")
363 #define init_xlat_table(b) init_table_((b), 0x10, "xlat table");
366 init_script(struct nouveau_bios *bios, int index)
368 struct nvbios_init init = { .bios = bios };
369 u16 bmp_ver = bmp_version(bios), data;
371 if (bmp_ver && bmp_ver < 0x0510) {
372 if (index > 1 || bmp_ver < 0x0100)
375 data = bios->bmp_offset + (bmp_ver < 0x0200 ? 14 : 18);
376 return nv_ro16(bios, data + (index * 2));
379 data = init_script_table(&init);
381 return nv_ro16(bios, data + (index * 2));
387 init_unknown_script(struct nouveau_bios *bios)
389 u16 len, data = init_table(bios, &len);
390 if (data && len >= 16)
391 return nv_ro16(bios, data + 14);
396 init_ram_restrict_group_count(struct nvbios_init *init)
398 return nvbios_ramcfg_count(init->bios);
402 init_ram_restrict(struct nvbios_init *init)
404 /* This appears to be the behaviour of the VBIOS parser, and *is*
405 * important to cache the NV_PEXTDEV_BOOT0 on later chipsets to
406 * avoid fucking up the memory controller (somehow) by reading it
407 * on every INIT_RAM_RESTRICT_ZM_GROUP opcode.
409 * Preserving the non-caching behaviour on earlier chipsets just
410 * in case *not* re-reading the strap causes similar breakage.
412 if (!init->ramcfg || init->bios->version.major < 0x70)
413 init->ramcfg = 0x80000000 | nvbios_ramcfg_index(init->bios);
414 return (init->ramcfg & 0x7fffffff);
418 init_xlat_(struct nvbios_init *init, u8 index, u8 offset)
420 struct nouveau_bios *bios = init->bios;
421 u16 table = init_xlat_table(init);
423 u16 data = nv_ro16(bios, table + (index * 2));
425 return nv_ro08(bios, data + offset);
426 warn("xlat table pointer %d invalid\n", index);
431 /******************************************************************************
432 * utility functions used by various init opcode handlers
433 *****************************************************************************/
436 init_condition_met(struct nvbios_init *init, u8 cond)
438 struct nouveau_bios *bios = init->bios;
439 u16 table = init_condition_table(init);
441 u32 reg = nv_ro32(bios, table + (cond * 12) + 0);
442 u32 msk = nv_ro32(bios, table + (cond * 12) + 4);
443 u32 val = nv_ro32(bios, table + (cond * 12) + 8);
444 trace("\t[0x%02x] (R[0x%06x] & 0x%08x) == 0x%08x\n",
445 cond, reg, msk, val);
446 return (init_rd32(init, reg) & msk) == val;
452 init_io_condition_met(struct nvbios_init *init, u8 cond)
454 struct nouveau_bios *bios = init->bios;
455 u16 table = init_io_condition_table(init);
457 u16 port = nv_ro16(bios, table + (cond * 5) + 0);
458 u8 index = nv_ro08(bios, table + (cond * 5) + 2);
459 u8 mask = nv_ro08(bios, table + (cond * 5) + 3);
460 u8 value = nv_ro08(bios, table + (cond * 5) + 4);
461 trace("\t[0x%02x] (0x%04x[0x%02x] & 0x%02x) == 0x%02x\n",
462 cond, port, index, mask, value);
463 return (init_rdvgai(init, port, index) & mask) == value;
469 init_io_flag_condition_met(struct nvbios_init *init, u8 cond)
471 struct nouveau_bios *bios = init->bios;
472 u16 table = init_io_flag_condition_table(init);
474 u16 port = nv_ro16(bios, table + (cond * 9) + 0);
475 u8 index = nv_ro08(bios, table + (cond * 9) + 2);
476 u8 mask = nv_ro08(bios, table + (cond * 9) + 3);
477 u8 shift = nv_ro08(bios, table + (cond * 9) + 4);
478 u16 data = nv_ro16(bios, table + (cond * 9) + 5);
479 u8 dmask = nv_ro08(bios, table + (cond * 9) + 7);
480 u8 value = nv_ro08(bios, table + (cond * 9) + 8);
481 u8 ioval = (init_rdvgai(init, port, index) & mask) >> shift;
482 return (nv_ro08(bios, data + ioval) & dmask) == value;
488 init_shift(u32 data, u8 shift)
491 return data >> shift;
492 return data << (0x100 - shift);
496 init_tmds_reg(struct nvbios_init *init, u8 tmds)
498 /* For mlv < 0x80, it is an index into a table of TMDS base addresses.
499 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by
500 * CR58 for CR57 = 0 to index a table of offsets to the basic
502 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by
503 * CR58 for CR57 = 0 to index a table of offsets to the basic
504 * 0x6808b0 address, and then flip the offset by 8.
507 const int pramdac_offset[13] = {
508 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 };
509 const u32 pramdac_table[4] = {
510 0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8 };
514 u32 dacoffset = pramdac_offset[init->outp->or];
517 return 0x6808b0 + dacoffset;
521 error("tmds opcodes need dcb\n");
523 if (tmds < ARRAY_SIZE(pramdac_table))
524 return pramdac_table[tmds];
526 error("tmds selector 0x%02x unknown\n", tmds);
532 /******************************************************************************
533 * init opcode handlers
534 *****************************************************************************/
537 * init_reserved - stub for various unknown/unused single-byte opcodes
541 init_reserved(struct nvbios_init *init)
543 u8 opcode = nv_ro08(init->bios, init->offset);
555 trace("RESERVED 0x%02x\t", opcode);
556 for (i = 1; i < length; i++)
557 cont(" 0x%02x", nv_ro08(init->bios, init->offset + i));
559 init->offset += length;
563 * INIT_DONE - opcode 0x71
567 init_done(struct nvbios_init *init)
570 init->offset = 0x0000;
574 * INIT_IO_RESTRICT_PROG - opcode 0x32
578 init_io_restrict_prog(struct nvbios_init *init)
580 struct nouveau_bios *bios = init->bios;
581 u16 port = nv_ro16(bios, init->offset + 1);
582 u8 index = nv_ro08(bios, init->offset + 3);
583 u8 mask = nv_ro08(bios, init->offset + 4);
584 u8 shift = nv_ro08(bios, init->offset + 5);
585 u8 count = nv_ro08(bios, init->offset + 6);
586 u32 reg = nv_ro32(bios, init->offset + 7);
589 trace("IO_RESTRICT_PROG\tR[0x%06x] = "
590 "((0x%04x[0x%02x] & 0x%02x) >> %d) [{\n",
591 reg, port, index, mask, shift);
594 conf = (init_rdvgai(init, port, index) & mask) >> shift;
595 for (i = 0; i < count; i++) {
596 u32 data = nv_ro32(bios, init->offset);
599 trace("\t0x%08x *\n", data);
600 init_wr32(init, reg, data);
602 trace("\t0x%08x\n", data);
611 * INIT_REPEAT - opcode 0x33
615 init_repeat(struct nvbios_init *init)
617 struct nouveau_bios *bios = init->bios;
618 u8 count = nv_ro08(bios, init->offset + 1);
619 u16 repeat = init->repeat;
621 trace("REPEAT\t0x%02x\n", count);
624 init->repeat = init->offset;
625 init->repend = init->offset;
627 init->offset = init->repeat;
630 trace("REPEAT\t0x%02x\n", count);
632 init->offset = init->repend;
633 init->repeat = repeat;
637 * INIT_IO_RESTRICT_PLL - opcode 0x34
641 init_io_restrict_pll(struct nvbios_init *init)
643 struct nouveau_bios *bios = init->bios;
644 u16 port = nv_ro16(bios, init->offset + 1);
645 u8 index = nv_ro08(bios, init->offset + 3);
646 u8 mask = nv_ro08(bios, init->offset + 4);
647 u8 shift = nv_ro08(bios, init->offset + 5);
648 s8 iofc = nv_ro08(bios, init->offset + 6);
649 u8 count = nv_ro08(bios, init->offset + 7);
650 u32 reg = nv_ro32(bios, init->offset + 8);
653 trace("IO_RESTRICT_PLL\tR[0x%06x] =PLL= "
654 "((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) IOFCOND 0x%02x [{\n",
655 reg, port, index, mask, shift, iofc);
658 conf = (init_rdvgai(init, port, index) & mask) >> shift;
659 for (i = 0; i < count; i++) {
660 u32 freq = nv_ro16(bios, init->offset) * 10;
663 trace("\t%dkHz *\n", freq);
664 if (iofc > 0 && init_io_flag_condition_met(init, iofc))
666 init_prog_pll(init, reg, freq);
668 trace("\t%dkHz\n", freq);
677 * INIT_END_REPEAT - opcode 0x36
681 init_end_repeat(struct nvbios_init *init)
683 trace("END_REPEAT\n");
687 init->repend = init->offset;
693 * INIT_COPY - opcode 0x37
697 init_copy(struct nvbios_init *init)
699 struct nouveau_bios *bios = init->bios;
700 u32 reg = nv_ro32(bios, init->offset + 1);
701 u8 shift = nv_ro08(bios, init->offset + 5);
702 u8 smask = nv_ro08(bios, init->offset + 6);
703 u16 port = nv_ro16(bios, init->offset + 7);
704 u8 index = nv_ro08(bios, init->offset + 9);
705 u8 mask = nv_ro08(bios, init->offset + 10);
708 trace("COPY\t0x%04x[0x%02x] &= 0x%02x |= "
709 "((R[0x%06x] %s 0x%02x) & 0x%02x)\n",
710 port, index, mask, reg, (shift & 0x80) ? "<<" : ">>",
711 (shift & 0x80) ? (0x100 - shift) : shift, smask);
714 data = init_rdvgai(init, port, index) & mask;
715 data |= init_shift(init_rd32(init, reg), shift) & smask;
716 init_wrvgai(init, port, index, data);
720 * INIT_NOT - opcode 0x38
724 init_not(struct nvbios_init *init)
732 * INIT_IO_FLAG_CONDITION - opcode 0x39
736 init_io_flag_condition(struct nvbios_init *init)
738 struct nouveau_bios *bios = init->bios;
739 u8 cond = nv_ro08(bios, init->offset + 1);
741 trace("IO_FLAG_CONDITION\t0x%02x\n", cond);
744 if (!init_io_flag_condition_met(init, cond))
745 init_exec_set(init, false);
749 * INIT_DP_CONDITION - opcode 0x3a
753 init_dp_condition(struct nvbios_init *init)
755 struct nouveau_bios *bios = init->bios;
756 struct nvbios_dpout info;
757 u8 cond = nv_ro08(bios, init->offset + 1);
758 u8 unkn = nv_ro08(bios, init->offset + 2);
759 u8 ver, hdr, cnt, len;
762 trace("DP_CONDITION\t0x%02x 0x%02x\n", cond, unkn);
767 if (init_conn(init) != DCB_CONNECTOR_eDP)
768 init_exec_set(init, false);
773 (data = nvbios_dpout_match(bios, DCB_OUTPUT_DP,
774 (init->outp->or << 0) |
775 (init->outp->sorconf.link << 6),
776 &ver, &hdr, &cnt, &len, &info)))
778 if (!(info.flags & cond))
779 init_exec_set(init, false);
784 warn("script needs dp output table data\n");
787 if (!(init_rdauxr(init, 0x0d) & 1))
788 init_exec_set(init, false);
791 warn("unknown dp condition 0x%02x\n", cond);
797 * INIT_IO_MASK_OR - opcode 0x3b
801 init_io_mask_or(struct nvbios_init *init)
803 struct nouveau_bios *bios = init->bios;
804 u8 index = nv_ro08(bios, init->offset + 1);
805 u8 or = init_or(init);
808 trace("IO_MASK_OR\t0x03d4[0x%02x] &= ~(1 << 0x%02x)\n", index, or);
811 data = init_rdvgai(init, 0x03d4, index);
812 init_wrvgai(init, 0x03d4, index, data &= ~(1 << or));
816 * INIT_IO_OR - opcode 0x3c
820 init_io_or(struct nvbios_init *init)
822 struct nouveau_bios *bios = init->bios;
823 u8 index = nv_ro08(bios, init->offset + 1);
824 u8 or = init_or(init);
827 trace("IO_OR\t0x03d4[0x%02x] |= (1 << 0x%02x)\n", index, or);
830 data = init_rdvgai(init, 0x03d4, index);
831 init_wrvgai(init, 0x03d4, index, data | (1 << or));
835 * INIT_INDEX_ADDRESS_LATCHED - opcode 0x49
839 init_idx_addr_latched(struct nvbios_init *init)
841 struct nouveau_bios *bios = init->bios;
842 u32 creg = nv_ro32(bios, init->offset + 1);
843 u32 dreg = nv_ro32(bios, init->offset + 5);
844 u32 mask = nv_ro32(bios, init->offset + 9);
845 u32 data = nv_ro32(bios, init->offset + 13);
846 u8 count = nv_ro08(bios, init->offset + 17);
848 trace("INDEX_ADDRESS_LATCHED\tR[0x%06x] : R[0x%06x]\n", creg, dreg);
849 trace("\tCTRL &= 0x%08x |= 0x%08x\n", mask, data);
853 u8 iaddr = nv_ro08(bios, init->offset + 0);
854 u8 idata = nv_ro08(bios, init->offset + 1);
856 trace("\t[0x%02x] = 0x%02x\n", iaddr, idata);
859 init_wr32(init, dreg, idata);
860 init_mask(init, creg, ~mask, data | iaddr);
865 * INIT_IO_RESTRICT_PLL2 - opcode 0x4a
869 init_io_restrict_pll2(struct nvbios_init *init)
871 struct nouveau_bios *bios = init->bios;
872 u16 port = nv_ro16(bios, init->offset + 1);
873 u8 index = nv_ro08(bios, init->offset + 3);
874 u8 mask = nv_ro08(bios, init->offset + 4);
875 u8 shift = nv_ro08(bios, init->offset + 5);
876 u8 count = nv_ro08(bios, init->offset + 6);
877 u32 reg = nv_ro32(bios, init->offset + 7);
880 trace("IO_RESTRICT_PLL2\t"
881 "R[0x%06x] =PLL= ((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) [{\n",
882 reg, port, index, mask, shift);
885 conf = (init_rdvgai(init, port, index) & mask) >> shift;
886 for (i = 0; i < count; i++) {
887 u32 freq = nv_ro32(bios, init->offset);
889 trace("\t%dkHz *\n", freq);
890 init_prog_pll(init, reg, freq);
892 trace("\t%dkHz\n", freq);
900 * INIT_PLL2 - opcode 0x4b
904 init_pll2(struct nvbios_init *init)
906 struct nouveau_bios *bios = init->bios;
907 u32 reg = nv_ro32(bios, init->offset + 1);
908 u32 freq = nv_ro32(bios, init->offset + 5);
910 trace("PLL2\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
913 init_prog_pll(init, reg, freq);
917 * INIT_I2C_BYTE - opcode 0x4c
921 init_i2c_byte(struct nvbios_init *init)
923 struct nouveau_bios *bios = init->bios;
924 u8 index = nv_ro08(bios, init->offset + 1);
925 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
926 u8 count = nv_ro08(bios, init->offset + 3);
928 trace("I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
932 u8 reg = nv_ro08(bios, init->offset + 0);
933 u8 mask = nv_ro08(bios, init->offset + 1);
934 u8 data = nv_ro08(bios, init->offset + 2);
937 trace("\t[0x%02x] &= 0x%02x |= 0x%02x\n", reg, mask, data);
940 val = init_rdi2cr(init, index, addr, reg);
943 init_wri2cr(init, index, addr, reg, (val & mask) | data);
948 * INIT_ZM_I2C_BYTE - opcode 0x4d
952 init_zm_i2c_byte(struct nvbios_init *init)
954 struct nouveau_bios *bios = init->bios;
955 u8 index = nv_ro08(bios, init->offset + 1);
956 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
957 u8 count = nv_ro08(bios, init->offset + 3);
959 trace("ZM_I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index, addr);
963 u8 reg = nv_ro08(bios, init->offset + 0);
964 u8 data = nv_ro08(bios, init->offset + 1);
966 trace("\t[0x%02x] = 0x%02x\n", reg, data);
969 init_wri2cr(init, index, addr, reg, data);
975 * INIT_ZM_I2C - opcode 0x4e
979 init_zm_i2c(struct nvbios_init *init)
981 struct nouveau_bios *bios = init->bios;
982 u8 index = nv_ro08(bios, init->offset + 1);
983 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
984 u8 count = nv_ro08(bios, init->offset + 3);
987 trace("ZM_I2C\tI2C[0x%02x][0x%02x]\n", index, addr);
990 for (i = 0; i < count; i++) {
991 data[i] = nv_ro08(bios, init->offset);
992 trace("\t0x%02x\n", data[i]);
996 if (init_exec(init)) {
997 struct nouveau_i2c_port *port = init_i2c(init, index);
998 struct i2c_msg msg = {
999 .addr = addr, .flags = 0, .len = count, .buf = data,
1003 if (port && (ret = i2c_transfer(&port->adapter, &msg, 1)) != 1)
1004 warn("i2c wr failed, %d\n", ret);
1009 * INIT_TMDS - opcode 0x4f
1013 init_tmds(struct nvbios_init *init)
1015 struct nouveau_bios *bios = init->bios;
1016 u8 tmds = nv_ro08(bios, init->offset + 1);
1017 u8 addr = nv_ro08(bios, init->offset + 2);
1018 u8 mask = nv_ro08(bios, init->offset + 3);
1019 u8 data = nv_ro08(bios, init->offset + 4);
1020 u32 reg = init_tmds_reg(init, tmds);
1022 trace("TMDS\tT[0x%02x][0x%02x] &= 0x%02x |= 0x%02x\n",
1023 tmds, addr, mask, data);
1029 init_wr32(init, reg + 0, addr | 0x00010000);
1030 init_wr32(init, reg + 4, data | (init_rd32(init, reg + 4) & mask));
1031 init_wr32(init, reg + 0, addr);
1035 * INIT_ZM_TMDS_GROUP - opcode 0x50
1039 init_zm_tmds_group(struct nvbios_init *init)
1041 struct nouveau_bios *bios = init->bios;
1042 u8 tmds = nv_ro08(bios, init->offset + 1);
1043 u8 count = nv_ro08(bios, init->offset + 2);
1044 u32 reg = init_tmds_reg(init, tmds);
1046 trace("TMDS_ZM_GROUP\tT[0x%02x]\n", tmds);
1050 u8 addr = nv_ro08(bios, init->offset + 0);
1051 u8 data = nv_ro08(bios, init->offset + 1);
1053 trace("\t[0x%02x] = 0x%02x\n", addr, data);
1056 init_wr32(init, reg + 4, data);
1057 init_wr32(init, reg + 0, addr);
1062 * INIT_CR_INDEX_ADDRESS_LATCHED - opcode 0x51
1066 init_cr_idx_adr_latch(struct nvbios_init *init)
1068 struct nouveau_bios *bios = init->bios;
1069 u8 addr0 = nv_ro08(bios, init->offset + 1);
1070 u8 addr1 = nv_ro08(bios, init->offset + 2);
1071 u8 base = nv_ro08(bios, init->offset + 3);
1072 u8 count = nv_ro08(bios, init->offset + 4);
1075 trace("CR_INDEX_ADDR C[%02x] C[%02x]\n", addr0, addr1);
1078 save0 = init_rdvgai(init, 0x03d4, addr0);
1080 u8 data = nv_ro08(bios, init->offset);
1082 trace("\t\t[0x%02x] = 0x%02x\n", base, data);
1085 init_wrvgai(init, 0x03d4, addr0, base++);
1086 init_wrvgai(init, 0x03d4, addr1, data);
1088 init_wrvgai(init, 0x03d4, addr0, save0);
1092 * INIT_CR - opcode 0x52
1096 init_cr(struct nvbios_init *init)
1098 struct nouveau_bios *bios = init->bios;
1099 u8 addr = nv_ro08(bios, init->offset + 1);
1100 u8 mask = nv_ro08(bios, init->offset + 2);
1101 u8 data = nv_ro08(bios, init->offset + 3);
1104 trace("CR\t\tC[0x%02x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1107 val = init_rdvgai(init, 0x03d4, addr) & mask;
1108 init_wrvgai(init, 0x03d4, addr, val | data);
1112 * INIT_ZM_CR - opcode 0x53
1116 init_zm_cr(struct nvbios_init *init)
1118 struct nouveau_bios *bios = init->bios;
1119 u8 addr = nv_ro08(bios, init->offset + 1);
1120 u8 data = nv_ro08(bios, init->offset + 2);
1122 trace("ZM_CR\tC[0x%02x] = 0x%02x\n", addr, data);
1125 init_wrvgai(init, 0x03d4, addr, data);
1129 * INIT_ZM_CR_GROUP - opcode 0x54
1133 init_zm_cr_group(struct nvbios_init *init)
1135 struct nouveau_bios *bios = init->bios;
1136 u8 count = nv_ro08(bios, init->offset + 1);
1138 trace("ZM_CR_GROUP\n");
1142 u8 addr = nv_ro08(bios, init->offset + 0);
1143 u8 data = nv_ro08(bios, init->offset + 1);
1145 trace("\t\tC[0x%02x] = 0x%02x\n", addr, data);
1148 init_wrvgai(init, 0x03d4, addr, data);
1153 * INIT_CONDITION_TIME - opcode 0x56
1157 init_condition_time(struct nvbios_init *init)
1159 struct nouveau_bios *bios = init->bios;
1160 u8 cond = nv_ro08(bios, init->offset + 1);
1161 u8 retry = nv_ro08(bios, init->offset + 2);
1162 u8 wait = min((u16)retry * 50, 100);
1164 trace("CONDITION_TIME\t0x%02x 0x%02x\n", cond, retry);
1167 if (!init_exec(init))
1171 if (init_condition_met(init, cond))
1176 init_exec_set(init, false);
1180 * INIT_LTIME - opcode 0x57
1184 init_ltime(struct nvbios_init *init)
1186 struct nouveau_bios *bios = init->bios;
1187 u16 msec = nv_ro16(bios, init->offset + 1);
1189 trace("LTIME\t0x%04x\n", msec);
1192 if (init_exec(init))
1197 * INIT_ZM_REG_SEQUENCE - opcode 0x58
1201 init_zm_reg_sequence(struct nvbios_init *init)
1203 struct nouveau_bios *bios = init->bios;
1204 u32 base = nv_ro32(bios, init->offset + 1);
1205 u8 count = nv_ro08(bios, init->offset + 5);
1207 trace("ZM_REG_SEQUENCE\t0x%02x\n", count);
1211 u32 data = nv_ro32(bios, init->offset);
1213 trace("\t\tR[0x%06x] = 0x%08x\n", base, data);
1216 init_wr32(init, base, data);
1222 * INIT_SUB_DIRECT - opcode 0x5b
1226 init_sub_direct(struct nvbios_init *init)
1228 struct nouveau_bios *bios = init->bios;
1229 u16 addr = nv_ro16(bios, init->offset + 1);
1232 trace("SUB_DIRECT\t0x%04x\n", addr);
1234 if (init_exec(init)) {
1235 save = init->offset;
1236 init->offset = addr;
1237 if (nvbios_exec(init)) {
1238 error("error parsing sub-table\n");
1241 init->offset = save;
1248 * INIT_JUMP - opcode 0x5c
1252 init_jump(struct nvbios_init *init)
1254 struct nouveau_bios *bios = init->bios;
1255 u16 offset = nv_ro16(bios, init->offset + 1);
1257 trace("JUMP\t0x%04x\n", offset);
1259 if (init_exec(init))
1260 init->offset = offset;
1266 * INIT_I2C_IF - opcode 0x5e
1270 init_i2c_if(struct nvbios_init *init)
1272 struct nouveau_bios *bios = init->bios;
1273 u8 index = nv_ro08(bios, init->offset + 1);
1274 u8 addr = nv_ro08(bios, init->offset + 2);
1275 u8 reg = nv_ro08(bios, init->offset + 3);
1276 u8 mask = nv_ro08(bios, init->offset + 4);
1277 u8 data = nv_ro08(bios, init->offset + 5);
1280 trace("I2C_IF\tI2C[0x%02x][0x%02x][0x%02x] & 0x%02x == 0x%02x\n",
1281 index, addr, reg, mask, data);
1283 init_exec_force(init, true);
1285 value = init_rdi2cr(init, index, addr, reg);
1286 if ((value & mask) != data)
1287 init_exec_set(init, false);
1289 init_exec_force(init, false);
1293 * INIT_COPY_NV_REG - opcode 0x5f
1297 init_copy_nv_reg(struct nvbios_init *init)
1299 struct nouveau_bios *bios = init->bios;
1300 u32 sreg = nv_ro32(bios, init->offset + 1);
1301 u8 shift = nv_ro08(bios, init->offset + 5);
1302 u32 smask = nv_ro32(bios, init->offset + 6);
1303 u32 sxor = nv_ro32(bios, init->offset + 10);
1304 u32 dreg = nv_ro32(bios, init->offset + 14);
1305 u32 dmask = nv_ro32(bios, init->offset + 18);
1308 trace("COPY_NV_REG\tR[0x%06x] &= 0x%08x |= "
1309 "((R[0x%06x] %s 0x%02x) & 0x%08x ^ 0x%08x)\n",
1310 dreg, dmask, sreg, (shift & 0x80) ? "<<" : ">>",
1311 (shift & 0x80) ? (0x100 - shift) : shift, smask, sxor);
1314 data = init_shift(init_rd32(init, sreg), shift);
1315 init_mask(init, dreg, ~dmask, (data & smask) ^ sxor);
1319 * INIT_ZM_INDEX_IO - opcode 0x62
1323 init_zm_index_io(struct nvbios_init *init)
1325 struct nouveau_bios *bios = init->bios;
1326 u16 port = nv_ro16(bios, init->offset + 1);
1327 u8 index = nv_ro08(bios, init->offset + 3);
1328 u8 data = nv_ro08(bios, init->offset + 4);
1330 trace("ZM_INDEX_IO\tI[0x%04x][0x%02x] = 0x%02x\n", port, index, data);
1333 init_wrvgai(init, port, index, data);
1337 * INIT_COMPUTE_MEM - opcode 0x63
1341 init_compute_mem(struct nvbios_init *init)
1343 struct nouveau_devinit *devinit = nouveau_devinit(init->bios);
1345 trace("COMPUTE_MEM\n");
1348 init_exec_force(init, true);
1349 if (init_exec(init) && devinit->meminit)
1350 devinit->meminit(devinit);
1351 init_exec_force(init, false);
1355 * INIT_RESET - opcode 0x65
1359 init_reset(struct nvbios_init *init)
1361 struct nouveau_bios *bios = init->bios;
1362 u32 reg = nv_ro32(bios, init->offset + 1);
1363 u32 data1 = nv_ro32(bios, init->offset + 5);
1364 u32 data2 = nv_ro32(bios, init->offset + 9);
1367 trace("RESET\tR[0x%08x] = 0x%08x, 0x%08x", reg, data1, data2);
1369 init_exec_force(init, true);
1371 savepci19 = init_mask(init, 0x00184c, 0x00000f00, 0x00000000);
1372 init_wr32(init, reg, data1);
1374 init_wr32(init, reg, data2);
1375 init_wr32(init, 0x00184c, savepci19);
1376 init_mask(init, 0x001850, 0x00000001, 0x00000000);
1378 init_exec_force(init, false);
1382 * INIT_CONFIGURE_MEM - opcode 0x66
1386 init_configure_mem_clk(struct nvbios_init *init)
1388 u16 mdata = bmp_mem_init_table(init->bios);
1390 mdata += (init_rdvgai(init, 0x03d4, 0x3c) >> 4) * 66;
1395 init_configure_mem(struct nvbios_init *init)
1397 struct nouveau_bios *bios = init->bios;
1401 trace("CONFIGURE_MEM\n");
1404 if (bios->version.major > 2) {
1408 init_exec_force(init, true);
1410 mdata = init_configure_mem_clk(init);
1411 sdata = bmp_sdr_seq_table(bios);
1412 if (nv_ro08(bios, mdata) & 0x01)
1413 sdata = bmp_ddr_seq_table(bios);
1414 mdata += 6; /* skip to data */
1416 data = init_rdvgai(init, 0x03c4, 0x01);
1417 init_wrvgai(init, 0x03c4, 0x01, data | 0x20);
1419 for (; (addr = nv_ro32(bios, sdata)) != 0xffffffff; sdata += 4) {
1421 case 0x10021c: /* CKE_NORMAL */
1422 case 0x1002d0: /* CMD_REFRESH */
1423 case 0x1002d4: /* CMD_PRECHARGE */
1427 data = nv_ro32(bios, mdata);
1429 if (data == 0xffffffff)
1434 init_wr32(init, addr, data);
1437 init_exec_force(init, false);
1441 * INIT_CONFIGURE_CLK - opcode 0x67
1445 init_configure_clk(struct nvbios_init *init)
1447 struct nouveau_bios *bios = init->bios;
1450 trace("CONFIGURE_CLK\n");
1453 if (bios->version.major > 2) {
1457 init_exec_force(init, true);
1459 mdata = init_configure_mem_clk(init);
1462 clock = nv_ro16(bios, mdata + 4) * 10;
1463 init_prog_pll(init, 0x680500, clock);
1466 clock = nv_ro16(bios, mdata + 2) * 10;
1467 if (nv_ro08(bios, mdata) & 0x01)
1469 init_prog_pll(init, 0x680504, clock);
1471 init_exec_force(init, false);
1475 * INIT_CONFIGURE_PREINIT - opcode 0x68
1479 init_configure_preinit(struct nvbios_init *init)
1481 struct nouveau_bios *bios = init->bios;
1484 trace("CONFIGURE_PREINIT\n");
1487 if (bios->version.major > 2) {
1491 init_exec_force(init, true);
1493 strap = init_rd32(init, 0x101000);
1494 strap = ((strap << 2) & 0xf0) | ((strap & 0x40) >> 6);
1495 init_wrvgai(init, 0x03d4, 0x3c, strap);
1497 init_exec_force(init, false);
1501 * INIT_IO - opcode 0x69
1505 init_io(struct nvbios_init *init)
1507 struct nouveau_bios *bios = init->bios;
1508 u16 port = nv_ro16(bios, init->offset + 1);
1509 u8 mask = nv_ro16(bios, init->offset + 3);
1510 u8 data = nv_ro16(bios, init->offset + 4);
1513 trace("IO\t\tI[0x%04x] &= 0x%02x |= 0x%02x\n", port, mask, data);
1516 /* ummm.. yes.. should really figure out wtf this is and why it's
1517 * needed some day.. it's almost certainly wrong, but, it also
1518 * somehow makes things work...
1520 if (nv_device(init->bios)->card_type >= NV_50 &&
1521 port == 0x03c3 && data == 0x01) {
1522 init_mask(init, 0x614100, 0xf0800000, 0x00800000);
1523 init_mask(init, 0x00e18c, 0x00020000, 0x00020000);
1524 init_mask(init, 0x614900, 0xf0800000, 0x00800000);
1525 init_mask(init, 0x000200, 0x40000000, 0x00000000);
1527 init_mask(init, 0x00e18c, 0x00020000, 0x00000000);
1528 init_mask(init, 0x000200, 0x40000000, 0x40000000);
1529 init_wr32(init, 0x614100, 0x00800018);
1530 init_wr32(init, 0x614900, 0x00800018);
1532 init_wr32(init, 0x614100, 0x10000018);
1533 init_wr32(init, 0x614900, 0x10000018);
1536 value = init_rdport(init, port) & mask;
1537 init_wrport(init, port, data | value);
1541 * INIT_SUB - opcode 0x6b
1545 init_sub(struct nvbios_init *init)
1547 struct nouveau_bios *bios = init->bios;
1548 u8 index = nv_ro08(bios, init->offset + 1);
1551 trace("SUB\t0x%02x\n", index);
1553 addr = init_script(bios, index);
1554 if (addr && init_exec(init)) {
1555 save = init->offset;
1556 init->offset = addr;
1557 if (nvbios_exec(init)) {
1558 error("error parsing sub-table\n");
1561 init->offset = save;
1568 * INIT_RAM_CONDITION - opcode 0x6d
1572 init_ram_condition(struct nvbios_init *init)
1574 struct nouveau_bios *bios = init->bios;
1575 u8 mask = nv_ro08(bios, init->offset + 1);
1576 u8 value = nv_ro08(bios, init->offset + 2);
1578 trace("RAM_CONDITION\t"
1579 "(R[0x100000] & 0x%02x) == 0x%02x\n", mask, value);
1582 if ((init_rd32(init, 0x100000) & mask) != value)
1583 init_exec_set(init, false);
1587 * INIT_NV_REG - opcode 0x6e
1591 init_nv_reg(struct nvbios_init *init)
1593 struct nouveau_bios *bios = init->bios;
1594 u32 reg = nv_ro32(bios, init->offset + 1);
1595 u32 mask = nv_ro32(bios, init->offset + 5);
1596 u32 data = nv_ro32(bios, init->offset + 9);
1598 trace("NV_REG\tR[0x%06x] &= 0x%08x |= 0x%08x\n", reg, mask, data);
1601 init_mask(init, reg, ~mask, data);
1605 * INIT_MACRO - opcode 0x6f
1609 init_macro(struct nvbios_init *init)
1611 struct nouveau_bios *bios = init->bios;
1612 u8 macro = nv_ro08(bios, init->offset + 1);
1615 trace("MACRO\t0x%02x\n", macro);
1617 table = init_macro_table(init);
1619 u32 addr = nv_ro32(bios, table + (macro * 8) + 0);
1620 u32 data = nv_ro32(bios, table + (macro * 8) + 4);
1621 trace("\t\tR[0x%06x] = 0x%08x\n", addr, data);
1622 init_wr32(init, addr, data);
1629 * INIT_RESUME - opcode 0x72
1633 init_resume(struct nvbios_init *init)
1637 init_exec_set(init, true);
1641 * INIT_TIME - opcode 0x74
1645 init_time(struct nvbios_init *init)
1647 struct nouveau_bios *bios = init->bios;
1648 u16 usec = nv_ro16(bios, init->offset + 1);
1650 trace("TIME\t0x%04x\n", usec);
1653 if (init_exec(init)) {
1657 mdelay((usec + 900) / 1000);
1662 * INIT_CONDITION - opcode 0x75
1666 init_condition(struct nvbios_init *init)
1668 struct nouveau_bios *bios = init->bios;
1669 u8 cond = nv_ro08(bios, init->offset + 1);
1671 trace("CONDITION\t0x%02x\n", cond);
1674 if (!init_condition_met(init, cond))
1675 init_exec_set(init, false);
1679 * INIT_IO_CONDITION - opcode 0x76
1683 init_io_condition(struct nvbios_init *init)
1685 struct nouveau_bios *bios = init->bios;
1686 u8 cond = nv_ro08(bios, init->offset + 1);
1688 trace("IO_CONDITION\t0x%02x\n", cond);
1691 if (!init_io_condition_met(init, cond))
1692 init_exec_set(init, false);
1696 * INIT_INDEX_IO - opcode 0x78
1700 init_index_io(struct nvbios_init *init)
1702 struct nouveau_bios *bios = init->bios;
1703 u16 port = nv_ro16(bios, init->offset + 1);
1704 u8 index = nv_ro16(bios, init->offset + 3);
1705 u8 mask = nv_ro08(bios, init->offset + 4);
1706 u8 data = nv_ro08(bios, init->offset + 5);
1709 trace("INDEX_IO\tI[0x%04x][0x%02x] &= 0x%02x |= 0x%02x\n",
1710 port, index, mask, data);
1713 value = init_rdvgai(init, port, index) & mask;
1714 init_wrvgai(init, port, index, data | value);
1718 * INIT_PLL - opcode 0x79
1722 init_pll(struct nvbios_init *init)
1724 struct nouveau_bios *bios = init->bios;
1725 u32 reg = nv_ro32(bios, init->offset + 1);
1726 u32 freq = nv_ro16(bios, init->offset + 5) * 10;
1728 trace("PLL\tR[0x%06x] =PLL= %dkHz\n", reg, freq);
1731 init_prog_pll(init, reg, freq);
1735 * INIT_ZM_REG - opcode 0x7a
1739 init_zm_reg(struct nvbios_init *init)
1741 struct nouveau_bios *bios = init->bios;
1742 u32 addr = nv_ro32(bios, init->offset + 1);
1743 u32 data = nv_ro32(bios, init->offset + 5);
1745 trace("ZM_REG\tR[0x%06x] = 0x%08x\n", addr, data);
1748 if (addr == 0x000200)
1751 init_wr32(init, addr, data);
1755 * INIT_RAM_RESTRICT_PLL - opcde 0x87
1759 init_ram_restrict_pll(struct nvbios_init *init)
1761 struct nouveau_bios *bios = init->bios;
1762 u8 type = nv_ro08(bios, init->offset + 1);
1763 u8 count = init_ram_restrict_group_count(init);
1764 u8 strap = init_ram_restrict(init);
1767 trace("RAM_RESTRICT_PLL\t0x%02x\n", type);
1770 for (cconf = 0; cconf < count; cconf++) {
1771 u32 freq = nv_ro32(bios, init->offset);
1773 if (cconf == strap) {
1774 trace("%dkHz *\n", freq);
1775 init_prog_pll(init, type, freq);
1777 trace("%dkHz\n", freq);
1785 * INIT_GPIO - opcode 0x8e
1789 init_gpio(struct nvbios_init *init)
1791 struct nouveau_gpio *gpio = nouveau_gpio(init->bios);
1796 if (init_exec(init) && gpio && gpio->reset)
1797 gpio->reset(gpio, DCB_GPIO_UNUSED);
1801 * INIT_RAM_RESTRICT_ZM_GROUP - opcode 0x8f
1805 init_ram_restrict_zm_reg_group(struct nvbios_init *init)
1807 struct nouveau_bios *bios = init->bios;
1808 u32 addr = nv_ro32(bios, init->offset + 1);
1809 u8 incr = nv_ro08(bios, init->offset + 5);
1810 u8 num = nv_ro08(bios, init->offset + 6);
1811 u8 count = init_ram_restrict_group_count(init);
1812 u8 index = init_ram_restrict(init);
1815 trace("RAM_RESTRICT_ZM_REG_GROUP\t"
1816 "R[0x%08x] 0x%02x 0x%02x\n", addr, incr, num);
1819 for (i = 0; i < num; i++) {
1820 trace("\tR[0x%06x] = {\n", addr);
1821 for (j = 0; j < count; j++) {
1822 u32 data = nv_ro32(bios, init->offset);
1825 trace("\t\t0x%08x *\n", data);
1826 init_wr32(init, addr, data);
1828 trace("\t\t0x%08x\n", data);
1839 * INIT_COPY_ZM_REG - opcode 0x90
1843 init_copy_zm_reg(struct nvbios_init *init)
1845 struct nouveau_bios *bios = init->bios;
1846 u32 sreg = nv_ro32(bios, init->offset + 1);
1847 u32 dreg = nv_ro32(bios, init->offset + 5);
1849 trace("COPY_ZM_REG\tR[0x%06x] = R[0x%06x]\n", dreg, sreg);
1852 init_wr32(init, dreg, init_rd32(init, sreg));
1856 * INIT_ZM_REG_GROUP - opcode 0x91
1860 init_zm_reg_group(struct nvbios_init *init)
1862 struct nouveau_bios *bios = init->bios;
1863 u32 addr = nv_ro32(bios, init->offset + 1);
1864 u8 count = nv_ro08(bios, init->offset + 5);
1866 trace("ZM_REG_GROUP\tR[0x%06x] =\n", addr);
1870 u32 data = nv_ro32(bios, init->offset);
1871 trace("\t0x%08x\n", data);
1872 init_wr32(init, addr, data);
1878 * INIT_XLAT - opcode 0x96
1882 init_xlat(struct nvbios_init *init)
1884 struct nouveau_bios *bios = init->bios;
1885 u32 saddr = nv_ro32(bios, init->offset + 1);
1886 u8 sshift = nv_ro08(bios, init->offset + 5);
1887 u8 smask = nv_ro08(bios, init->offset + 6);
1888 u8 index = nv_ro08(bios, init->offset + 7);
1889 u32 daddr = nv_ro32(bios, init->offset + 8);
1890 u32 dmask = nv_ro32(bios, init->offset + 12);
1891 u8 shift = nv_ro08(bios, init->offset + 16);
1894 trace("INIT_XLAT\tR[0x%06x] &= 0x%08x |= "
1895 "(X%02x((R[0x%06x] %s 0x%02x) & 0x%02x) << 0x%02x)\n",
1896 daddr, dmask, index, saddr, (sshift & 0x80) ? "<<" : ">>",
1897 (sshift & 0x80) ? (0x100 - sshift) : sshift, smask, shift);
1900 data = init_shift(init_rd32(init, saddr), sshift) & smask;
1901 data = init_xlat_(init, index, data) << shift;
1902 init_mask(init, daddr, ~dmask, data);
1906 * INIT_ZM_MASK_ADD - opcode 0x97
1910 init_zm_mask_add(struct nvbios_init *init)
1912 struct nouveau_bios *bios = init->bios;
1913 u32 addr = nv_ro32(bios, init->offset + 1);
1914 u32 mask = nv_ro32(bios, init->offset + 5);
1915 u32 add = nv_ro32(bios, init->offset + 9);
1918 trace("ZM_MASK_ADD\tR[0x%06x] &= 0x%08x += 0x%08x\n", addr, mask, add);
1921 data = init_rd32(init, addr);
1922 data = (data & mask) | ((data + add) & ~mask);
1923 init_wr32(init, addr, data);
1927 * INIT_AUXCH - opcode 0x98
1931 init_auxch(struct nvbios_init *init)
1933 struct nouveau_bios *bios = init->bios;
1934 u32 addr = nv_ro32(bios, init->offset + 1);
1935 u8 count = nv_ro08(bios, init->offset + 5);
1937 trace("AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
1941 u8 mask = nv_ro08(bios, init->offset + 0);
1942 u8 data = nv_ro08(bios, init->offset + 1);
1943 trace("\tAUX[0x%08x] &= 0x%02x |= 0x%02x\n", addr, mask, data);
1944 mask = init_rdauxr(init, addr) & mask;
1945 init_wrauxr(init, addr, mask | data);
1951 * INIT_AUXCH - opcode 0x99
1955 init_zm_auxch(struct nvbios_init *init)
1957 struct nouveau_bios *bios = init->bios;
1958 u32 addr = nv_ro32(bios, init->offset + 1);
1959 u8 count = nv_ro08(bios, init->offset + 5);
1961 trace("ZM_AUXCH\tAUX[0x%08x] 0x%02x\n", addr, count);
1965 u8 data = nv_ro08(bios, init->offset + 0);
1966 trace("\tAUX[0x%08x] = 0x%02x\n", addr, data);
1967 init_wrauxr(init, addr, data);
1973 * INIT_I2C_LONG_IF - opcode 0x9a
1977 init_i2c_long_if(struct nvbios_init *init)
1979 struct nouveau_bios *bios = init->bios;
1980 u8 index = nv_ro08(bios, init->offset + 1);
1981 u8 addr = nv_ro08(bios, init->offset + 2) >> 1;
1982 u8 reglo = nv_ro08(bios, init->offset + 3);
1983 u8 reghi = nv_ro08(bios, init->offset + 4);
1984 u8 mask = nv_ro08(bios, init->offset + 5);
1985 u8 data = nv_ro08(bios, init->offset + 6);
1986 struct nouveau_i2c_port *port;
1988 trace("I2C_LONG_IF\t"
1989 "I2C[0x%02x][0x%02x][0x%02x%02x] & 0x%02x == 0x%02x\n",
1990 index, addr, reglo, reghi, mask, data);
1993 port = init_i2c(init, index);
1995 u8 i[2] = { reghi, reglo };
1997 struct i2c_msg msg[] = {
1998 { .addr = addr, .flags = 0, .len = 2, .buf = i },
1999 { .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = o }
2003 ret = i2c_transfer(&port->adapter, msg, 2);
2004 if (ret == 2 && ((o[0] & mask) == data))
2008 init_exec_set(init, false);
2012 * INIT_GPIO_NE - opcode 0xa9
2016 init_gpio_ne(struct nvbios_init *init)
2018 struct nouveau_bios *bios = init->bios;
2019 struct nouveau_gpio *gpio = nouveau_gpio(bios);
2020 struct dcb_gpio_func func;
2021 u8 count = nv_ro08(bios, init->offset + 1);
2022 u8 idx = 0, ver, len;
2028 for (i = init->offset; i < init->offset + count; i++)
2029 cont("0x%02x ", nv_ro08(bios, i));
2032 while ((data = dcb_gpio_parse(bios, 0, idx++, &ver, &len, &func))) {
2033 if (func.func != DCB_GPIO_UNUSED) {
2034 for (i = init->offset; i < init->offset + count; i++) {
2035 if (func.func == nv_ro08(bios, i))
2039 trace("\tFUNC[0x%02x]", func.func);
2040 if (i == (init->offset + count)) {
2042 if (init_exec(init) && gpio && gpio->reset)
2043 gpio->reset(gpio, func.func);
2049 init->offset += count;
2052 static struct nvbios_init_opcode {
2053 void (*exec)(struct nvbios_init *);
2055 [0x32] = { init_io_restrict_prog },
2056 [0x33] = { init_repeat },
2057 [0x34] = { init_io_restrict_pll },
2058 [0x36] = { init_end_repeat },
2059 [0x37] = { init_copy },
2060 [0x38] = { init_not },
2061 [0x39] = { init_io_flag_condition },
2062 [0x3a] = { init_dp_condition },
2063 [0x3b] = { init_io_mask_or },
2064 [0x3c] = { init_io_or },
2065 [0x49] = { init_idx_addr_latched },
2066 [0x4a] = { init_io_restrict_pll2 },
2067 [0x4b] = { init_pll2 },
2068 [0x4c] = { init_i2c_byte },
2069 [0x4d] = { init_zm_i2c_byte },
2070 [0x4e] = { init_zm_i2c },
2071 [0x4f] = { init_tmds },
2072 [0x50] = { init_zm_tmds_group },
2073 [0x51] = { init_cr_idx_adr_latch },
2074 [0x52] = { init_cr },
2075 [0x53] = { init_zm_cr },
2076 [0x54] = { init_zm_cr_group },
2077 [0x56] = { init_condition_time },
2078 [0x57] = { init_ltime },
2079 [0x58] = { init_zm_reg_sequence },
2080 [0x5b] = { init_sub_direct },
2081 [0x5c] = { init_jump },
2082 [0x5e] = { init_i2c_if },
2083 [0x5f] = { init_copy_nv_reg },
2084 [0x62] = { init_zm_index_io },
2085 [0x63] = { init_compute_mem },
2086 [0x65] = { init_reset },
2087 [0x66] = { init_configure_mem },
2088 [0x67] = { init_configure_clk },
2089 [0x68] = { init_configure_preinit },
2090 [0x69] = { init_io },
2091 [0x6b] = { init_sub },
2092 [0x6d] = { init_ram_condition },
2093 [0x6e] = { init_nv_reg },
2094 [0x6f] = { init_macro },
2095 [0x71] = { init_done },
2096 [0x72] = { init_resume },
2097 [0x74] = { init_time },
2098 [0x75] = { init_condition },
2099 [0x76] = { init_io_condition },
2100 [0x78] = { init_index_io },
2101 [0x79] = { init_pll },
2102 [0x7a] = { init_zm_reg },
2103 [0x87] = { init_ram_restrict_pll },
2104 [0x8c] = { init_reserved },
2105 [0x8d] = { init_reserved },
2106 [0x8e] = { init_gpio },
2107 [0x8f] = { init_ram_restrict_zm_reg_group },
2108 [0x90] = { init_copy_zm_reg },
2109 [0x91] = { init_zm_reg_group },
2110 [0x92] = { init_reserved },
2111 [0x96] = { init_xlat },
2112 [0x97] = { init_zm_mask_add },
2113 [0x98] = { init_auxch },
2114 [0x99] = { init_zm_auxch },
2115 [0x9a] = { init_i2c_long_if },
2116 [0xa9] = { init_gpio_ne },
2117 [0xaa] = { init_reserved },
2120 #define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
2123 nvbios_exec(struct nvbios_init *init)
2126 while (init->offset) {
2127 u8 opcode = nv_ro08(init->bios, init->offset);
2128 if (opcode >= init_opcode_nr || !init_opcode[opcode].exec) {
2129 error("unknown opcode 0x%02x\n", opcode);
2133 init_opcode[opcode].exec(init);
2140 nvbios_init(struct nouveau_subdev *subdev, bool execute)
2142 struct nouveau_bios *bios = nouveau_bios(subdev);
2148 nv_info(bios, "running init tables\n");
2149 while (!ret && (data = (init_script(bios, ++i)))) {
2150 struct nvbios_init init = {
2156 .execute = execute ? 1 : 0,
2159 ret = nvbios_exec(&init);
2162 /* the vbios parser will run this right after the normal init
2163 * tables, whereas the binary driver appears to run it later.
2165 if (!ret && (data = init_unknown_script(bios))) {
2166 struct nvbios_init init = {
2172 .execute = execute ? 1 : 0,
2175 ret = nvbios_exec(&init);