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