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_fail
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;
17 // Coreboot board detected.
18 int CBmainboard VAR16VISIBLE;
21 handle_155fXX(struct bregs *regs)
23 set_code_fail(regs, RET_EUNSUPPORTED);
27 /****************************************************************
29 ****************************************************************/
32 via_155f01(struct bregs *regs)
35 regs->cl = 2; // panel type = 2 = 1024 * 768
37 dprintf(1, "Warning: VGA panel type is hardcoded\n");
41 via_155f02(struct bregs *regs)
45 regs->cx = 0x401; // PAL + crt only
46 regs->dx = 0; // TV Layout - default
48 dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
55 u8 reg = pci_config_readb(bdf, 0xa1);
61 static u8 mem_power[] VAR16 = {0, 3, 4, 5, 6, 7, 8, 9};
62 return GET_GLOBAL(mem_power[(reg >> 4) & 0x7]);
66 getViaRamSpeed(u16 bdf)
68 return (pci_config_readb(bdf, 0x90) & 0x07) + 3;
74 int bdf = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
78 /* mem clk 0 = DDR2 400 */
79 return (pci_config_readb(bdf, 0x94) & 0x7) + 6;
84 ECX = unknown/dont care
85 EBX[3..0] Frame Buffer Size 2^N MiB
86 EBX[7..4] Memory speed:
90 3: DDR 100Mhz (PC1600 or DDR200)
91 4: DDR 133Mhz (PC2100 or DDR266)
92 5: DDR 166Mhz (PC2700 or DDR333)
93 6: DDR 200Mhz (PC3200 or DDR400)
94 7: DDR2 133Mhz (DDR2 533)
95 8: DDR2 166Mhz (DDR2 667)
96 9: DDR2 200Mhz (DDR2 800)
97 A: DDR2 233Mhz (DDR2 1066)
99 EBX[?..8] Total memory size?
100 EAX = 0x5f for success
103 #define PCI_DEVICE_ID_VIA_K8M890CE_3 0x3336
104 #define PCI_DEVICE_ID_VIA_VX855_MEMCTRL 0x3409
107 via_155f18(struct bregs *regs)
109 u32 ramspeed, fbsize;
111 int bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_3);
113 fbsize = getFBSize(bdf);
114 ramspeed = getAMDRamSpeed();
117 bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_MEMCTRL);
119 fbsize = getFBSize(bdf);
120 ramspeed = getViaRamSpeed(bdf);
124 dprintf(1, "Warning: VGA memory size and speed is hardcoded\n");
125 fbsize = 5; // 32M frame buffer
126 ramspeed = 4; // MCLK = DDR266
129 if (fbsize < 0 || ramspeed < 0) {
130 set_code_fail(regs, RET_EUNSUPPORTED);
134 regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
140 via_155f19(struct bregs *regs)
142 set_fail_silent(regs);
146 via_155f(struct bregs *regs)
149 case 0x01: via_155f01(regs); break;
150 case 0x02: via_155f02(regs); break;
151 case 0x18: via_155f18(regs); break;
152 case 0x19: via_155f19(regs); break;
153 default: handle_155fXX(regs); break;
158 /****************************************************************
160 ****************************************************************/
162 // Main 16bit entry point
164 handle_155f(struct bregs *regs)
166 if (! CONFIG_VGAHOOKS)
169 // XXX - Use this value later.
170 //int cbmb = GET_GLOBAL(CBmainboard);
172 int bdf = GET_GLOBAL(VGAbdf);
175 u16 vendor = pci_config_readw(bdf, PCI_VENDOR_ID);
176 if (vendor == PCI_VENDOR_ID_VIA) {
187 vgahook_setup(const char *vendor, const char *part)
189 if (! CONFIG_VGAHOOKS)
191 // XXX - add support later.