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