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