1 // Hooks for via vgabios calls into main bios.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "bregs.h" // set_code_invalid
8 #include "biosvar.h" // GET_GLOBAL
9 #include "pci.h" // pci_find_device
10 #include "pci_regs.h" // PCI_VENDOR_ID
11 #include "pci_ids.h" // PCI_VENDOR_ID_VIA
12 #include "util.h" // handle_155f
13 #include "config.h" // CONFIG_*
15 // The Bus/Dev/Fn of the primary VGA device.
16 int VGAbdf VAR16VISIBLE = -1;
17 // Coreboot board detected.
18 int CBmainboard VAR16VISIBLE;
20 #define MAINBOARD_DEFAULT 0
21 #define KONTRON_986LCD_M 1
23 #define RODA_RK886EX 3
31 struct mainboards mainboard_list[] = {
32 { "KONTRON", "986LCD-M", KONTRON_986LCD_M },
33 { "GETAC", "P470", GETAC_P470 },
34 { "RODA", "RK886EX", RODA_RK886EX },
38 handle_155fXX(struct bregs *regs)
40 set_code_unimplemented(regs, RET_EUNSUPPORTED);
44 /****************************************************************
46 ****************************************************************/
49 via_155f01(struct bregs *regs)
52 regs->cl = 2; // panel type = 2 = 1024 * 768
54 dprintf(1, "Warning: VGA panel type is hardcoded\n");
58 via_155f02(struct bregs *regs)
62 regs->cx = 0x401; // PAL + crt only
63 regs->dx = 0; // TV Layout - default
65 dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
72 u8 reg = pci_config_readb(bdf, 0xa1);
78 static u8 mem_power[] VAR16 = {0, 3, 4, 5, 6, 7, 8, 9};
79 return GET_GLOBAL(mem_power[(reg >> 4) & 0x7]);
83 getViaRamSpeed(u16 bdf)
85 return (pci_config_readb(bdf, 0x90) & 0x07) + 3;
91 int bdf = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
95 /* mem clk 0 = DDR2 400 */
96 return (pci_config_readb(bdf, 0x94) & 0x7) + 6;
101 ECX = unknown/dont care
102 EBX[3..0] Frame Buffer Size 2^N MiB
103 EBX[7..4] Memory speed:
107 3: DDR 100Mhz (PC1600 or DDR200)
108 4: DDR 133Mhz (PC2100 or DDR266)
109 5: DDR 166Mhz (PC2700 or DDR333)
110 6: DDR 200Mhz (PC3200 or DDR400)
111 7: DDR2 133Mhz (DDR2 533)
112 8: DDR2 166Mhz (DDR2 667)
113 9: DDR2 200Mhz (DDR2 800)
114 A: DDR2 233Mhz (DDR2 1066)
115 B: and above: Unknown
116 EBX[?..8] Total memory size?
117 EAX = 0x5f for success
120 #define PCI_DEVICE_ID_VIA_K8M890CE_3 0x3336
121 #define PCI_DEVICE_ID_VIA_VX855_MEMCTRL 0x3409
124 via_155f18(struct bregs *regs)
126 int ramspeed, fbsize;
128 int bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_3);
130 fbsize = getFBSize(bdf);
131 ramspeed = getAMDRamSpeed();
134 bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_MEMCTRL);
136 fbsize = getFBSize(bdf);
137 ramspeed = getViaRamSpeed(bdf);
141 dprintf(1, "Warning: VGA memory size and speed is hardcoded\n");
142 fbsize = 5; // 32M frame buffer
143 ramspeed = 4; // MCLK = DDR266
146 if (fbsize < 0 || ramspeed < 0) {
147 set_code_invalid(regs, RET_EUNSUPPORTED);
151 regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
157 via_155f19(struct bregs *regs)
159 set_invalid_silent(regs);
163 via_155f(struct bregs *regs)
166 case 0x01: via_155f01(regs); break;
167 case 0x02: via_155f02(regs); break;
168 case 0x18: via_155f18(regs); break;
169 case 0x19: via_155f19(regs); break;
170 default: handle_155fXX(regs); break;
174 /****************************************************************
176 ****************************************************************/
177 #define BOOT_DISPLAY_DEFAULT (0)
178 #define BOOT_DISPLAY_CRT (1 << 0)
179 #define BOOT_DISPLAY_TV (1 << 1)
180 #define BOOT_DISPLAY_EFP (1 << 2)
181 #define BOOT_DISPLAY_LCD (1 << 3)
182 #define BOOT_DISPLAY_CRT2 (1 << 4)
183 #define BOOT_DISPLAY_TV2 (1 << 5)
184 #define BOOT_DISPLAY_EFP2 (1 << 6)
185 #define BOOT_DISPLAY_LCD2 (1 << 7)
188 roda_155f35(struct bregs *regs)
191 // regs->cl = BOOT_DISPLAY_DEFAULT;
192 regs->cl = BOOT_DISPLAY_LCD;
197 roda_155f40(struct bregs *regs)
200 //display_id = inb(0x60f) & 0x0f; // Correct according to Crete
201 display_id = 3; // Correct according to empirical studies
204 regs->cl = display_id;
209 roda_155f(struct bregs *regs)
211 dprintf(1, "Executing RODA specific interrupt %02x.\n", regs->al);
213 case 0x35: roda_155f35(regs); break;
214 case 0x40: roda_155f40(regs); break;
215 default: handle_155fXX(regs); break;
220 kontron_155f35(struct bregs *regs)
223 regs->cl = BOOT_DISPLAY_CRT;
228 kontron_155f40(struct bregs *regs)
234 regs->cl = display_id;
239 kontron_155f(struct bregs *regs)
241 dprintf(1, "Executing Kontron specific interrupt %02x.\n", regs->al);
243 case 0x35: kontron_155f35(regs); break;
244 case 0x40: kontron_155f40(regs); break;
245 default: handle_155fXX(regs); break;
250 getac_155f(struct bregs *regs)
252 dprintf(1, "Executing Getac specific interrupt %02x.\n", regs->al);
254 default: handle_155fXX(regs); break;
258 /****************************************************************
260 ****************************************************************/
262 // Main 16bit entry point
264 handle_155f(struct bregs *regs)
268 if (! CONFIG_VGAHOOKS)
271 cbmb = GET_GLOBAL(CBmainboard);
274 case KONTRON_986LCD_M:
283 case MAINBOARD_DEFAULT:
284 bdf = GET_GLOBAL(VGAbdf);
288 u16 vendor = pci_config_readw(bdf, PCI_VENDOR_ID);
289 if (vendor == PCI_VENDOR_ID_VIA) {
301 vgahook_setup(const char *vendor, const char *part)
305 if (! CONFIG_VGAHOOKS)
308 for (i=0; i<(sizeof(mainboard_list) / sizeof(mainboard_list[0])); i++) {
309 if (!strcmp(vendor, mainboard_list[i].vendor) &&
310 !strcmp(part, mainboard_list[i].device)) {
311 printf("Found mainboard %s %s\n", vendor, part);
312 CBmainboard = mainboard_list[i].type;