#include "util.h" // handle_155f
#include "config.h" // CONFIG_*
-// The Bus/Dev/Fn of the primary VGA device.
-int VGAbdf VAR16VISIBLE;
-// Coreboot board detected.
-int CBmainboard VAR16VISIBLE;
+#define VH_VIA 1
+#define VH_INTEL 2
+
+int VGAHookHandlerType VAR16VISIBLE;
static void
handle_155fXX(struct bregs *regs)
* Via hooks
****************************************************************/
+int ViaFBsize VAR16VISIBLE, ViaRamSpeed VAR16VISIBLE;
+
static void
via_155f01(struct bregs *regs)
{
dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
}
+static void
+via_155f18(struct bregs *regs)
+{
+ int fbsize = GET_GLOBAL(ViaFBsize), ramspeed = GET_GLOBAL(ViaRamSpeed);
+ if (fbsize < 0 || ramspeed < 0) {
+ set_code_invalid(regs, RET_EUNSUPPORTED);
+ return;
+ }
+ regs->eax = 0x5f;
+ regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
+ regs->ecx = 0x060;
+ set_success(regs);
+}
+
+static void
+via_155f19(struct bregs *regs)
+{
+ set_invalid_silent(regs);
+}
+
+static void
+via_155f(struct bregs *regs)
+{
+ switch (regs->al) {
+ case 0x01: via_155f01(regs); break;
+ case 0x02: via_155f02(regs); break;
+ case 0x18: via_155f18(regs); break;
+ case 0x19: via_155f19(regs); break;
+ default: handle_155fXX(regs); break;
+ }
+}
+
static int
-getFBSize(u16 bdf)
+getFBSize(struct pci_device *pci)
{
/* FB config */
- u8 reg = pci_config_readb(bdf, 0xa1);
+ u8 reg = pci_config_readb(pci->bdf, 0xa1);
/* GFX disabled ? */
if (!(reg & 0x80))
return -1;
- static u8 mem_power[] VAR16 = {0, 3, 4, 5, 6, 7, 8, 9};
- return GET_GLOBAL(mem_power[(reg >> 4) & 0x7]);
+ static u8 mem_power[] = {0, 3, 4, 5, 6, 7, 8, 9};
+ return mem_power[(reg >> 4) & 0x7];
}
static int
-getViaRamSpeed(u16 bdf)
+getViaRamSpeed(struct pci_device *pci)
{
- return (pci_config_readb(bdf, 0x90) & 0x07) + 3;
+ return (pci_config_readb(pci->bdf, 0x90) & 0x07) + 3;
}
static int
getAMDRamSpeed(void)
{
- int bdf = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
- if (bdf < 0)
+ struct pci_device *pci = pci_find_device(PCI_VENDOR_ID_AMD
+ , PCI_DEVICE_ID_AMD_K8_NB_MEMCTL);
+ if (!pci)
return -1;
/* mem clk 0 = DDR2 400 */
- return (pci_config_readb(bdf, 0x94) & 0x7) + 6;
+ return (pci_config_readb(pci->bdf, 0x94) & 0x7) + 6;
}
/* int 0x15 - 5f18
#define PCI_DEVICE_ID_VIA_VX855_MEMCTRL 0x3409
static void
-via_155f18(struct bregs *regs)
+via_setup(struct pci_device *pci)
{
- u32 ramspeed, fbsize;
+ VGAHookHandlerType = VH_VIA;
- int bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_3);
- if (bdf >= 0) {
- fbsize = getFBSize(bdf);
- ramspeed = getAMDRamSpeed();
- goto done;
+ struct pci_device *d = pci_find_device(PCI_VENDOR_ID_VIA
+ , PCI_DEVICE_ID_VIA_K8M890CE_3);
+ if (d) {
+ ViaFBsize = getFBSize(d);
+ ViaRamSpeed = getAMDRamSpeed();
+ return;
}
- bdf = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_MEMCTRL);
- if (bdf >= 0) {
- fbsize = getFBSize(bdf);
- ramspeed = getViaRamSpeed(bdf);
- goto done;
+ d = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_MEMCTRL);
+ if (d) {
+ ViaFBsize = getFBSize(d);
+ ViaRamSpeed = getViaRamSpeed(d);
+ return;
}
dprintf(1, "Warning: VGA memory size and speed is hardcoded\n");
- fbsize = 5; // 32M frame buffer
- ramspeed = 4; // MCLK = DDR266
+ ViaFBsize = 5; // 32M frame buffer
+ ViaRamSpeed = 4; // MCLK = DDR266
+}
-done:
- if (fbsize < 0 || ramspeed < 0) {
- set_code_invalid(regs, RET_EUNSUPPORTED);
- return;
- }
- regs->eax = 0x5f;
- regs->ebx = 0x500 | (ramspeed << 4) | fbsize;
- regs->ecx = 0x060;
+
+/****************************************************************
+ * Intel VGA hooks
+ ****************************************************************/
+
+u8 IntelDisplayType VAR16VISIBLE, IntelDisplayId VAR16VISIBLE;
+
+static void
+intel_155f35(struct bregs *regs)
+{
+ regs->ax = 0x005f;
+ regs->cl = GET_GLOBAL(IntelDisplayType);
set_success(regs);
}
static void
-via_155f19(struct bregs *regs)
+intel_155f40(struct bregs *regs)
{
- set_invalid_silent(regs);
+ regs->ax = 0x005f;
+ regs->cl = GET_GLOBAL(IntelDisplayId);
+ set_success(regs);
}
static void
-via_155f(struct bregs *regs)
+intel_155f(struct bregs *regs)
{
switch (regs->al) {
- case 0x01: via_155f01(regs); break;
- case 0x02: via_155f02(regs); break;
- case 0x18: via_155f18(regs); break;
- case 0x19: via_155f19(regs); break;
+ case 0x35: intel_155f35(regs); break;
+ case 0x40: intel_155f40(regs); break;
default: handle_155fXX(regs); break;
}
}
+#define BOOT_DISPLAY_DEFAULT (0)
+#define BOOT_DISPLAY_CRT (1 << 0)
+#define BOOT_DISPLAY_TV (1 << 1)
+#define BOOT_DISPLAY_EFP (1 << 2)
+#define BOOT_DISPLAY_LCD (1 << 3)
+#define BOOT_DISPLAY_CRT2 (1 << 4)
+#define BOOT_DISPLAY_TV2 (1 << 5)
+#define BOOT_DISPLAY_EFP2 (1 << 6)
+#define BOOT_DISPLAY_LCD2 (1 << 7)
+
+static void
+roda_setup(struct pci_device *pci)
+{
+ VGAHookHandlerType = VH_INTEL;
+ // IntelDisplayType = BOOT_DISPLAY_DEFAULT;
+ IntelDisplayType = BOOT_DISPLAY_LCD;
+ // IntelDisplayId = inb(0x60f) & 0x0f; // Correct according to Crete
+ IntelDisplayId = 3; // Correct according to empirical studies
+}
+
+static void
+kontron_setup(struct pci_device *pci)
+{
+ VGAHookHandlerType = VH_INTEL;
+ IntelDisplayType = BOOT_DISPLAY_CRT;
+ IntelDisplayId = 3;
+}
+
+static void
+getac_setup(struct pci_device *pci)
+{
+}
+
/****************************************************************
* Entry and setup
void
handle_155f(struct bregs *regs)
{
- if (! CONFIG_VGAHOOKS)
- goto fail;
-
- // XXX - Use this value later.
- //int cbmb = GET_GLOBAL(CBmainboard);
-
- int bdf = GET_GLOBAL(VGAbdf);
- if (bdf < 0)
- goto fail;
- u16 vendor = pci_config_readw(bdf, PCI_VENDOR_ID);
- if (vendor == PCI_VENDOR_ID_VIA) {
- via_155f(regs);
+ if (!CONFIG_VGAHOOKS) {
+ handle_155fXX(regs);
return;
}
-fail:
- handle_155fXX(regs);
+ int htype = GET_GLOBAL(VGAHookHandlerType);
+ switch (htype) {
+ case VH_VIA: via_155f(regs); break;
+ case VH_INTEL: intel_155f(regs); break;
+ default: handle_155fXX(regs); break;
+ }
}
// Setup
void
-vgahook_setup(const char *vendor, const char *part)
+vgahook_setup(struct pci_device *pci)
{
- if (! CONFIG_VGAHOOKS)
+ if (!CONFIG_VGAHOOKS || !CBvendor || !CBpart)
return;
- // XXX - add support later.
- CBmainboard = 0;
+
+ if (strcmp(CBvendor, "KONTRON") == 0 && strcmp(CBpart, "986LCD-M") == 0)
+ kontron_setup(pci);
+ else if (strcmp(CBvendor, "GETAC") == 0 && strcmp(CBpart, "P470") == 0)
+ getac_setup(pci);
+ else if (strcmp(CBvendor, "RODA") == 0 && strcmp(CBpart, "RK886EX") == 0)
+ roda_setup(pci);
+ else if (pci->vendor == PCI_VENDOR_ID_VIA)
+ via_setup(pci);
}