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_ids.h" // PCI_VENDOR_ID_VIA
11 #include "util.h" // handle_155f
12 #include "config.h" // CONFIG_*
15 handle_155f01(struct bregs *regs)
18 regs->cl = 2; // panel type = 2 = 1024 * 768
20 dprintf(1, "Warning: VGA panel type is hardcoded\n");
24 handle_155f02(struct bregs *regs)
28 regs->cx = 0x401; // PAL + crt only
29 regs->dx = 0; // TV Layout - default
31 dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
38 int bdf = pci_find_device(PCI_VENDOR_ID_VIA, 0x3336);
43 u8 reg = pci_config_readb(bdf, 0xa1);
49 static u8 mem_power[] VAR16 = {0, 3, 4, 5, 6, 7, 8, 9};
50 return GET_GLOBAL(mem_power[(reg >> 4) & 0x7]);
52 dprintf(1, "Warning: VGA memory size is hardcoded\n");
53 return 5; // 32M frame buffer
59 int bdf = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
63 /* mem clk 0 = DDR2 400 */
64 u8 reg = pci_config_readb(bdf, 0x94) & 0x7;
67 dprintf(1, "Warning: VGA memory clock speed is hardcoded\n");
68 return 4; // MCLK = DDR266
73 ECX = unknown/dont care
74 EBX[3..0] Frame Buffer Size 2^N MiB
75 EBX[7..4] Memory speed:
79 3: DDR 100Mhz (PC1600 or DDR200)
80 4: DDR 133Mhz (PC2100 or DDR266)
81 5: DDR 166Mhz (PC2700 or DDR333)
82 6: DDR 200Mhz (PC3200 or DDR400)
83 7: DDR2 133Mhz (DDR2 533)
84 8: DDR2 166Mhz (DDR2 667)
85 9: DDR2 200Mhz (DDR2 800)
86 A: DDR2 233Mhz (DDR2 1066)
88 EBX[?..8] Total memory size?
89 EAX = 0x5f for success
91 K8M890 BIOS wants only this call (Desktop NoTv)
95 handle_155f18(struct bregs *regs)
98 u32 ramspeed = getRamSpeed();
99 u32 fbsize = getFBSize();
100 regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
106 handle_155f19(struct bregs *regs)
108 set_fail_silent(regs);
112 handle_155fXX(struct bregs *regs)
114 set_code_fail(regs, RET_EUNSUPPORTED);
118 handle_155f(struct bregs *regs)
120 if (! CONFIG_VGAHOOKS) {
126 case 0x01: handle_155f01(regs); break;
127 case 0x02: handle_155f02(regs); break;
128 case 0x18: handle_155f18(regs); break;
129 case 0x19: handle_155f19(regs); break;
130 default: handle_155fXX(regs); break;