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