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