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_*
18 int VGAHookHandlerType VAR16VISIBLE;
21 handle_155fXX(struct bregs *regs)
23 set_code_unimplemented(regs, RET_EUNSUPPORTED);
27 /****************************************************************
29 ****************************************************************/
31 int ViaFBsize VAR16VISIBLE, ViaRamSpeed VAR16VISIBLE;
34 via_155f01(struct bregs *regs)
37 regs->cl = 2; // panel type = 2 = 1024 * 768
39 dprintf(1, "Warning: VGA panel type is hardcoded\n");
43 via_155f02(struct bregs *regs)
47 regs->cx = 0x401; // PAL + crt only
48 regs->dx = 0; // TV Layout - default
50 dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
54 via_155f18(struct bregs *regs)
56 int fbsize = GET_GLOBAL(ViaFBsize), ramspeed = GET_GLOBAL(ViaRamSpeed);
57 if (fbsize < 0 || ramspeed < 0) {
58 set_code_invalid(regs, RET_EUNSUPPORTED);
62 regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
68 via_155f19(struct bregs *regs)
70 set_invalid_silent(regs);
74 via_155f(struct bregs *regs)
77 case 0x01: via_155f01(regs); break;
78 case 0x02: via_155f02(regs); break;
79 case 0x18: via_155f18(regs); break;
80 case 0x19: via_155f19(regs); break;
81 default: handle_155fXX(regs); break;
86 getFBSize(struct pci_device *pci)
89 u8 reg = pci_config_readb(pci->bdf, 0xa1);
95 static u8 mem_power[] = {0, 3, 4, 5, 6, 7, 8, 9};
96 return mem_power[(reg >> 4) & 0x7];
100 getViaRamSpeed(struct pci_device *pci)
102 return (pci_config_readb(pci->bdf, 0x90) & 0x07) + 3;
108 struct pci_device *pci = pci_find_device(PCI_VENDOR_ID_AMD
109 , PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
113 /* mem clk 0 = DDR2 400 */
114 return (pci_config_readb(pci->bdf, 0x94) & 0x7) + 6;
119 ECX = unknown/dont care
120 EBX[3..0] Frame Buffer Size 2^N MiB
121 EBX[7..4] Memory speed:
125 3: DDR 100Mhz (PC1600 or DDR200)
126 4: DDR 133Mhz (PC2100 or DDR266)
127 5: DDR 166Mhz (PC2700 or DDR333)
128 6: DDR 200Mhz (PC3200 or DDR400)
129 7: DDR2 133Mhz (DDR2 533)
130 8: DDR2 166Mhz (DDR2 667)
131 9: DDR2 200Mhz (DDR2 800)
132 A: DDR2 233Mhz (DDR2 1066)
133 B: and above: Unknown
134 EBX[?..8] Total memory size?
135 EAX = 0x5f for success
138 #define PCI_DEVICE_ID_VIA_K8M890CE_3 0x3336
139 #define PCI_DEVICE_ID_VIA_VX855_MEMCTRL 0x3409
142 via_setup(struct pci_device *pci)
144 VGAHookHandlerType = VH_VIA;
146 struct pci_device *d = pci_find_device(PCI_VENDOR_ID_VIA
147 , PCI_DEVICE_ID_VIA_K8M890CE_3);
149 ViaFBsize = getFBSize(d);
150 ViaRamSpeed = getAMDRamSpeed();
153 d = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_MEMCTRL);
155 ViaFBsize = getFBSize(d);
156 ViaRamSpeed = getViaRamSpeed(d);
160 dprintf(1, "Warning: VGA memory size and speed is hardcoded\n");
161 ViaFBsize = 5; // 32M frame buffer
162 ViaRamSpeed = 4; // MCLK = DDR266
166 /****************************************************************
168 ****************************************************************/
170 u8 IntelDisplayType VAR16VISIBLE, IntelDisplayId VAR16VISIBLE;
173 intel_155f35(struct bregs *regs)
176 regs->cl = GET_GLOBAL(IntelDisplayType);
181 intel_155f40(struct bregs *regs)
184 regs->cl = GET_GLOBAL(IntelDisplayId);
189 intel_155f(struct bregs *regs)
192 case 0x35: intel_155f35(regs); break;
193 case 0x40: intel_155f40(regs); break;
194 default: handle_155fXX(regs); break;
198 #define BOOT_DISPLAY_DEFAULT (0)
199 #define BOOT_DISPLAY_CRT (1 << 0)
200 #define BOOT_DISPLAY_TV (1 << 1)
201 #define BOOT_DISPLAY_EFP (1 << 2)
202 #define BOOT_DISPLAY_LCD (1 << 3)
203 #define BOOT_DISPLAY_CRT2 (1 << 4)
204 #define BOOT_DISPLAY_TV2 (1 << 5)
205 #define BOOT_DISPLAY_EFP2 (1 << 6)
206 #define BOOT_DISPLAY_LCD2 (1 << 7)
209 roda_setup(struct pci_device *pci)
211 VGAHookHandlerType = VH_INTEL;
212 // IntelDisplayType = BOOT_DISPLAY_DEFAULT;
213 IntelDisplayType = BOOT_DISPLAY_LCD;
214 // IntelDisplayId = inb(0x60f) & 0x0f; // Correct according to Crete
215 IntelDisplayId = 3; // Correct according to empirical studies
219 kontron_setup(struct pci_device *pci)
221 VGAHookHandlerType = VH_INTEL;
222 IntelDisplayType = BOOT_DISPLAY_CRT;
227 getac_setup(struct pci_device *pci)
232 /****************************************************************
234 ****************************************************************/
236 // Main 16bit entry point
238 handle_155f(struct bregs *regs)
240 if (!CONFIG_VGAHOOKS) {
245 int htype = GET_GLOBAL(VGAHookHandlerType);
247 case VH_VIA: via_155f(regs); break;
248 case VH_INTEL: intel_155f(regs); break;
249 default: handle_155fXX(regs); break;
255 vgahook_setup(struct pci_device *pci)
257 if (!CONFIG_VGAHOOKS || !CBvendor || !CBpart)
260 if (strcmp(CBvendor, "KONTRON") == 0 && strcmp(CBpart, "986LCD-M") == 0)
262 else if (strcmp(CBvendor, "GETAC") == 0 && strcmp(CBpart, "P470") == 0)
264 else if (strcmp(CBvendor, "RODA") == 0 && strcmp(CBpart, "RK886EX") == 0)
266 else if (pci->vendor == PCI_VENDOR_ID_VIA)