Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2009-2010 coresystems GmbH |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc.. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 21 | #include <arch/io.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 22 | #include <arch/interrupt.h> |
Stefan Reinauer | 42dc721 | 2009-10-24 00:47:07 +0000 | [diff] [blame] | 23 | #include <arch/registers.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 24 | #include <boot/coreboot_tables.h> |
Edward O'Callaghan | 7842eb2 | 2014-07-29 22:28:19 +1000 | [diff] [blame] | 25 | #include <cbfs.h> |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 26 | #include <console/console.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 27 | #include <cpu/amd/lxdef.h> |
| 28 | #include <cpu/amd/vr.h> |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 29 | #include <delay.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 30 | #include <device/pci.h> |
| 31 | #include <device/pci_ids.h> |
Patrick Georgi | 3e77eb6 | 2012-11-22 10:39:16 +0100 | [diff] [blame] | 32 | #include <lib/jpeg.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 33 | #include <pc80/i8259.h> |
zbao | 741a0dd | 2015-06-25 16:58:53 -0400 | [diff] [blame] | 34 | #include <pc80/i8254.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 35 | #include <string.h> |
| 36 | #include <vbe.h> |
| 37 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 38 | /* we use x86emu's register file representation */ |
| 39 | #include <x86emu/regs.h> |
Edward O'Callaghan | 91810dd | 2014-07-30 13:53:04 +1000 | [diff] [blame] | 40 | |
| 41 | #include "x86.h" |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 42 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 43 | /* The following symbols cannot be used directly. They need to be fixed up |
| 44 | * to point to the correct address location after the code has been copied |
| 45 | * to REALMODE_BASE. Absolute symbols are not used because those symbols are |
| 46 | * relocated when a relocatable ramstage is enabled. |
| 47 | */ |
| 48 | extern unsigned char __realmode_call, __realmode_interrupt; |
| 49 | extern unsigned char __realmode_buffer; |
| 50 | |
| 51 | #define PTR_TO_REAL_MODE(sym)\ |
| 52 | (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code)) |
| 53 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 54 | /* to have a common register file for interrupt handlers */ |
| 55 | X86EMU_sysEnv _X86EMU_env; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 56 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 57 | void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx, |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 58 | u32 esi, u32 edi) asmlinkage; |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 59 | |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 60 | void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx, |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 61 | u32 esi, u32 edi) asmlinkage; |
| 62 | |
| 63 | static void setup_realmode_code(void) |
| 64 | { |
| 65 | memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size); |
| 66 | |
| 67 | /* Ensure the global pointers are relocated properly. */ |
| 68 | realmode_call = PTR_TO_REAL_MODE(__realmode_call); |
| 69 | realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt); |
| 70 | |
| 71 | printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE, |
| 72 | __realmode_code_size); |
| 73 | } |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 74 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 75 | static void setup_rombios(void) |
| 76 | { |
| 77 | const char date[] = "06/11/99"; |
| 78 | memcpy((void *)0xffff5, &date, 8); |
| 79 | |
| 80 | const char ident[] = "PCI_ISA"; |
| 81 | memcpy((void *)0xfffd9, &ident, 7); |
| 82 | |
| 83 | /* system model: IBM-AT */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 84 | write8((void *)0xffffe, 0xfc); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 85 | } |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 86 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 87 | static int (*intXX_handler[256])(void) = { NULL }; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 88 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 89 | static int intXX_exception_handler(void) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 90 | { |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 91 | /* compatibility shim */ |
| 92 | struct eregs reg_info = { |
| 93 | .eax=X86_EAX, |
| 94 | .ecx=X86_ECX, |
| 95 | .edx=X86_EDX, |
| 96 | .ebx=X86_EBX, |
| 97 | .esp=X86_ESP, |
| 98 | .ebp=X86_EBP, |
| 99 | .esi=X86_ESI, |
| 100 | .edi=X86_EDI, |
| 101 | .vector=M.x86.intno, |
| 102 | .error_code=0, // FIXME: fill in |
| 103 | .eip=X86_EIP, |
| 104 | .cs=X86_CS, |
| 105 | .eflags=X86_EFLAGS |
| 106 | }; |
| 107 | struct eregs *regs = ®_info; |
| 108 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 109 | printk(BIOS_INFO, "Oops, exception %d while executing option rom\n", |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 110 | regs->vector); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 111 | x86_exception(regs); // Call coreboot exception handler |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 112 | |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 113 | return 0; // Never really returns |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 116 | static int intXX_unknown_handler(void) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 117 | { |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 118 | printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n", |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 119 | M.x86.intno, X86_EAX); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 120 | |
| 121 | return -1; |
| 122 | } |
| 123 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 124 | /* setup interrupt handlers for mainboard */ |
Aaron Durbin | 4d7a4c5 | 2013-04-23 10:25:34 -0500 | [diff] [blame] | 125 | void mainboard_interrupt_handlers(int intXX, int (*intXX_func)(void)) |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 126 | { |
| 127 | intXX_handler[intXX] = intXX_func; |
| 128 | } |
| 129 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 130 | static void setup_interrupt_handlers(void) |
| 131 | { |
| 132 | int i; |
| 133 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 134 | /* The first 16 intXX functions are not BIOS services, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 135 | * but the CPU-generated exceptions ("hardware interrupts") |
| 136 | */ |
| 137 | for (i = 0; i < 0x10; i++) |
| 138 | intXX_handler[i] = &intXX_exception_handler; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 139 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 140 | /* Mark all other intXX calls as unknown first */ |
| 141 | for (i = 0x10; i < 0x100; i++) |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 142 | { |
| 143 | /* If the mainboard_interrupt_handler isn't called first. |
| 144 | */ |
| 145 | if(!intXX_handler[i]) |
| 146 | { |
| 147 | /* Now set the default functions that are actually |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 148 | * needed to initialize the option roms. This is |
| 149 | * very slick, as it allows us to implement mainboard |
| 150 | * specific interrupt handlers, such as the int15. |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 151 | */ |
| 152 | switch (i) { |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 153 | case 0x10: |
| 154 | intXX_handler[0x10] = &int10_handler; |
| 155 | break; |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 156 | case 0x12: |
| 157 | intXX_handler[0x12] = &int12_handler; |
| 158 | break; |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 159 | case 0x16: |
| 160 | intXX_handler[0x16] = &int16_handler; |
| 161 | break; |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 162 | case 0x1a: |
| 163 | intXX_handler[0x1a] = &int1a_handler; |
| 164 | break; |
| 165 | default: |
| 166 | intXX_handler[i] = &intXX_unknown_handler; |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | } |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static void write_idt_stub(void *target, u8 intnum) |
| 174 | { |
| 175 | unsigned char *codeptr; |
| 176 | codeptr = (unsigned char *) target; |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 177 | memcpy(codeptr, &__idt_handler, __idt_handler_size); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 178 | codeptr[3] = intnum; /* modify int# in the code stub. */ |
| 179 | } |
| 180 | |
| 181 | static void setup_realmode_idt(void) |
| 182 | { |
| 183 | struct realmode_idt *idts = (struct realmode_idt *) 0; |
| 184 | int i; |
| 185 | |
| 186 | /* Copy IDT stub code for each interrupt. This might seem wasteful |
| 187 | * but it is really simple |
| 188 | */ |
| 189 | for (i = 0; i < 256; i++) { |
| 190 | idts[i].cs = 0; |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 191 | idts[i].offset = 0x1000 + (i * __idt_handler_size); |
Stefan Reinauer | 83fa169 | 2015-06-18 22:01:07 -0700 | [diff] [blame] | 192 | write_idt_stub((void *)((uintptr_t)idts[i].offset), i); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* Many option ROMs use the hard coded interrupt entry points in the |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 196 | * system bios. So install them at the known locations. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 197 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 198 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 199 | /* int42 is the relocated int10 */ |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 200 | write_idt_stub((void *)0xff065, 0x42); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 201 | /* BIOS Int 11 Handler F000:F84D */ |
| 202 | write_idt_stub((void *)0xff84d, 0x11); |
| 203 | /* BIOS Int 12 Handler F000:F841 */ |
| 204 | write_idt_stub((void *)0xff841, 0x12); |
| 205 | /* BIOS Int 13 Handler F000:EC59 */ |
| 206 | write_idt_stub((void *)0xfec59, 0x13); |
| 207 | /* BIOS Int 14 Handler F000:E739 */ |
| 208 | write_idt_stub((void *)0xfe739, 0x14); |
| 209 | /* BIOS Int 15 Handler F000:F859 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 210 | write_idt_stub((void *)0xff859, 0x15); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 211 | /* BIOS Int 16 Handler F000:E82E */ |
| 212 | write_idt_stub((void *)0xfe82e, 0x16); |
| 213 | /* BIOS Int 17 Handler F000:EFD2 */ |
| 214 | write_idt_stub((void *)0xfefd2, 0x17); |
| 215 | /* ROM BIOS Int 1A Handler F000:FE6E */ |
| 216 | write_idt_stub((void *)0xffe6e, 0x1a); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 219 | #if CONFIG_FRAMEBUFFER_SET_VESA_MODE |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 220 | vbe_mode_info_t mode_info; |
| 221 | static int mode_info_valid; |
| 222 | |
| 223 | int vbe_mode_info_valid(void) |
| 224 | { |
| 225 | return mode_info_valid; |
| 226 | } |
| 227 | |
| 228 | static u8 vbe_get_mode_info(vbe_mode_info_t * mi) |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 229 | { |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 230 | printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n", |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 231 | mi->video_mode); |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 232 | char *buffer = PTR_TO_REAL_MODE(__realmode_buffer); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 233 | u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00; |
| 234 | u16 buffer_adr = ((unsigned long)buffer) & 0xffff; |
| 235 | realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000, |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 236 | mi->video_mode, 0x0000, buffer_seg, buffer_adr); |
Zhuo-Hao Lee | 29445dc | 2014-12-24 11:13:34 +0800 | [diff] [blame] | 237 | memcpy(mi->mode_info_block, buffer, sizeof(mi->mode_info_block)); |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 238 | mode_info_valid = 1; |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 242 | static u8 vbe_set_mode(vbe_mode_info_t * mi) |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 243 | { |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 244 | printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 245 | // request linear framebuffer mode |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 246 | mi->video_mode |= (1 << 14); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 247 | // request clearing of framebuffer |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 248 | mi->video_mode &= ~(1 << 15); |
| 249 | realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode, |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 250 | 0x0000, 0x0000, 0x0000, 0x0000); |
| 251 | return 0; |
| 252 | } |
| 253 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 254 | /* These two functions could probably even be generic between |
| 255 | * yabel and x86 native. TBD later. |
| 256 | */ |
| 257 | void vbe_set_graphics(void) |
| 258 | { |
| 259 | mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE; |
| 260 | vbe_get_mode_info(&mode_info); |
| 261 | unsigned char *framebuffer = |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 262 | (unsigned char *)mode_info.vesa.phys_base_ptr; |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 263 | printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n", |
| 264 | le16_to_cpu(mode_info.vesa.x_resolution), |
| 265 | le16_to_cpu(mode_info.vesa.y_resolution), |
| 266 | mode_info.vesa.bits_per_pixel); |
| 267 | printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer); |
| 268 | if (!framebuffer) { |
| 269 | printk(BIOS_DEBUG, "VBE: Mode does not support linear " |
| 270 | "framebuffer\n"); |
| 271 | return; |
| 272 | } |
| 273 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 274 | vbe_set_mode(&mode_info); |
| 275 | #if CONFIG_BOOTSPLASH |
| 276 | struct jpeg_decdata *decdata; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 277 | unsigned char *jpeg = cbfs_boot_map_with_leak("bootsplash.jpg", |
| 278 | CBFS_TYPE_BOOTSPLASH, |
| 279 | NULL); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 280 | if (!jpeg) { |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 281 | printk(BIOS_DEBUG, "VBE: No bootsplash found.\n"); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 282 | return; |
| 283 | } |
Daniele Forsi | f9ce88e | 2014-07-26 11:32:16 +0200 | [diff] [blame] | 284 | decdata = malloc(sizeof(*decdata)); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 285 | int ret = 0; |
| 286 | ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata); |
| 287 | #endif |
| 288 | } |
| 289 | |
| 290 | void vbe_textmode_console(void) |
| 291 | { |
| 292 | delay(2); |
| 293 | realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000, |
| 294 | 0x0000, 0x0000, 0x0000); |
| 295 | } |
| 296 | |
| 297 | void fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 298 | { |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 299 | framebuffer->physical_address = mode_info.vesa.phys_base_ptr; |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 300 | |
| 301 | framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution); |
| 302 | framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution); |
| 303 | framebuffer->bytes_per_line = |
| 304 | le16_to_cpu(mode_info.vesa.bytes_per_scanline); |
| 305 | framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel; |
| 306 | |
| 307 | framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos; |
| 308 | framebuffer->red_mask_size = mode_info.vesa.red_mask_size; |
| 309 | |
| 310 | framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos; |
| 311 | framebuffer->green_mask_size = mode_info.vesa.green_mask_size; |
| 312 | |
| 313 | framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos; |
| 314 | framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size; |
| 315 | |
| 316 | framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos; |
| 317 | framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size; |
| 318 | } |
Vladimir Serbinenko | d737451 | 2015-10-10 13:50:30 +0200 | [diff] [blame^] | 319 | |
| 320 | #else |
| 321 | |
| 322 | int vbe_mode_info_valid(void) |
| 323 | { |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | void fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 328 | { |
| 329 | } |
| 330 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 331 | #endif |
| 332 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 333 | void run_bios(struct device *dev, unsigned long addr) |
| 334 | { |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 335 | u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn; |
| 336 | |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 337 | /* Setting up required hardware. |
| 338 | * Removing this will cause random illegal instruction exceptions |
| 339 | * in some option roms. |
| 340 | */ |
| 341 | setup_i8259(); |
zbao | 741a0dd | 2015-06-25 16:58:53 -0400 | [diff] [blame] | 342 | setup_i8254(); |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 343 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 344 | /* Set up some legacy information in the F segment */ |
| 345 | setup_rombios(); |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 346 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 347 | /* Set up C interrupt handlers */ |
| 348 | setup_interrupt_handlers(); |
| 349 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 350 | /* Set up real-mode IDT */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 351 | setup_realmode_idt(); |
| 352 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 353 | /* Make sure the code is placed. */ |
| 354 | setup_realmode_code(); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 355 | |
| 356 | printk(BIOS_DEBUG, "Calling Option ROM...\n"); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 357 | /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */ |
| 358 | /* Option ROM entry point is at OPROM start + 3 */ |
| 359 | realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 360 | printk(BIOS_DEBUG, "... Option ROM returned.\n"); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 361 | |
| 362 | #if CONFIG_FRAMEBUFFER_SET_VESA_MODE |
Stefan Reinauer | 22ae2b9 | 2013-02-08 08:48:20 -0800 | [diff] [blame] | 363 | if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA) |
| 364 | vbe_set_graphics(); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 365 | #endif |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Stefan Reinauer | d4814bd | 2011-04-21 20:45:45 +0000 | [diff] [blame] | 368 | #if CONFIG_GEODE_VSA |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 369 | |
| 370 | #define VSA2_BUFFER 0x60000 |
| 371 | #define VSA2_ENTRY_POINT 0x60020 |
| 372 | |
| 373 | // TODO move to a header file. |
| 374 | void do_vsmbios(void); |
| 375 | |
| 376 | /* VSA virtual register helper */ |
| 377 | static u32 VSA_vrRead(u16 classIndex) |
| 378 | { |
| 379 | u32 eax, ebx, ecx, edx; |
| 380 | asm volatile ( |
| 381 | "movw $0x0AC1C, %%dx\n" |
| 382 | "orl $0x0FC530000, %%eax\n" |
| 383 | "outl %%eax, %%dx\n" |
| 384 | "addb $2, %%dl\n" |
| 385 | "inw %%dx, %%ax\n" |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 386 | : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx) |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 387 | : "a"(classIndex) |
| 388 | ); |
| 389 | |
| 390 | return eax; |
| 391 | } |
| 392 | |
| 393 | void do_vsmbios(void) |
| 394 | { |
| 395 | printk(BIOS_DEBUG, "Preparing for VSA...\n"); |
| 396 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 397 | /* Set up C interrupt handlers */ |
| 398 | setup_interrupt_handlers(); |
| 399 | |
| 400 | /* Setting up realmode IDT */ |
| 401 | setup_realmode_idt(); |
| 402 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 403 | /* Make sure the code is placed. */ |
| 404 | setup_realmode_code(); |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 405 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 406 | if ((uintptr_t)cbfs_boot_load_stage_by_name("vsa") != |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 407 | VSA2_ENTRY_POINT) { |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 408 | printk(BIOS_ERR, "Failed to load VSA.\n"); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | unsigned char *buf = (unsigned char *)VSA2_BUFFER; |
| 413 | printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]); |
| 414 | printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n", |
| 415 | buf[0x20], buf[0x21], buf[0x22], buf[0x23]); |
| 416 | |
| 417 | /* Check for code to emit POST code at start of VSA. */ |
| 418 | if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) || |
| 419 | (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) { |
| 420 | printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n"); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | printk(BIOS_DEBUG, "Calling VSA module...\n"); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 425 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 426 | /* ECX gets SMM, EDX gets SYSMEM */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 427 | realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM, |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 428 | MSR_GLIU0_SYSMEM, 0x0, 0x0); |
| 429 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 430 | printk(BIOS_DEBUG, "... VSA module returned.\n"); |
| 431 | |
| 432 | /* Restart timer 1 */ |
| 433 | outb(0x56, 0x43); |
| 434 | outb(0x12, 0x41); |
| 435 | |
| 436 | /* Check that VSA is running OK */ |
| 437 | if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE) |
| 438 | printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n"); |
| 439 | else |
| 440 | printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n"); |
| 441 | } |
| 442 | #endif |
| 443 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 444 | /* interrupt_handler() is called from assembler code only, |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 445 | * so there is no use in putting the prototype into a header file. |
| 446 | */ |
Stefan Reinauer | 399486e | 2012-12-06 13:54:29 -0800 | [diff] [blame] | 447 | int asmlinkage interrupt_handler(u32 intnumber, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 448 | u32 gsfs, u32 dses, |
| 449 | u32 edi, u32 esi, |
| 450 | u32 ebp, u32 esp, |
| 451 | u32 ebx, u32 edx, |
| 452 | u32 ecx, u32 eax, |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 453 | u32 cs_ip, u16 stackflags); |
| 454 | |
Stefan Reinauer | 399486e | 2012-12-06 13:54:29 -0800 | [diff] [blame] | 455 | int asmlinkage interrupt_handler(u32 intnumber, |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 456 | u32 gsfs, u32 dses, |
| 457 | u32 edi, u32 esi, |
| 458 | u32 ebp, u32 esp, |
| 459 | u32 ebx, u32 edx, |
| 460 | u32 ecx, u32 eax, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 461 | u32 cs_ip, u16 stackflags) |
| 462 | { |
| 463 | u32 ip; |
| 464 | u32 cs; |
| 465 | u32 flags; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 466 | int ret = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 467 | |
| 468 | ip = cs_ip & 0xffff; |
| 469 | cs = cs_ip >> 16; |
| 470 | flags = stackflags; |
| 471 | |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 472 | #if CONFIG_REALMODE_DEBUG |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 473 | printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber); |
| 474 | printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n", |
| 475 | eax, ebx, ecx, edx); |
| 476 | printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n", |
| 477 | ebp, esp, edi, esi); |
| 478 | printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n", |
| 479 | ip, cs, flags); |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 480 | #endif |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 481 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 482 | // Fetch arguments from the stack and put them to a place |
| 483 | // suitable for the interrupt handlers |
| 484 | X86_EAX = eax; |
| 485 | X86_ECX = ecx; |
| 486 | X86_EDX = edx; |
| 487 | X86_EBX = ebx; |
| 488 | X86_ESP = esp; |
| 489 | X86_EBP = ebp; |
| 490 | X86_ESI = esi; |
| 491 | X86_EDI = edi; |
| 492 | M.x86.intno = intnumber; |
| 493 | /* TODO: error_code must be stored somewhere */ |
| 494 | X86_EIP = ip; |
| 495 | X86_CS = cs; |
| 496 | X86_EFLAGS = flags; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 497 | |
| 498 | // Call the interrupt handler for this int# |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 499 | ret = intXX_handler[intnumber](); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 500 | |
| 501 | // Put registers back on the stack. The assembler code |
| 502 | // will later pop them. |
| 503 | // What happens here is that we force (volatile!) changing |
| 504 | // the values of the parameters of this function. We do this |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 505 | // because we know that they stay alive on the stack after |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 506 | // we leave this function. Don't say this is bollocks. |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 507 | *(volatile u32 *)&eax = X86_EAX; |
| 508 | *(volatile u32 *)&ecx = X86_ECX; |
| 509 | *(volatile u32 *)&edx = X86_EDX; |
| 510 | *(volatile u32 *)&ebx = X86_EBX; |
| 511 | *(volatile u32 *)&esi = X86_ESI; |
| 512 | *(volatile u32 *)&edi = X86_EDI; |
| 513 | flags = X86_EFLAGS; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 514 | |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 515 | /* Pass success or error back to our caller via the CARRY flag */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 516 | if (ret) { |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 517 | flags &= ~1; // no error: clear carry |
| 518 | }else{ |
Stefan Reinauer | f75b19a | 2010-04-22 18:15:32 +0000 | [diff] [blame] | 519 | printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 520 | flags |= 1; // error: set carry |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 521 | } |
| 522 | *(volatile u16 *)&stackflags = flags; |
| 523 | |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 524 | /* The assembler code doesn't actually care for the return value, |
| 525 | * but keep it around so its expectations are met */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 526 | return ret; |
| 527 | } |