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