blob: c3adf401f42dbf59130091d2d7852d71eb5a4a6f [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +10004#include <arch/interrupt.h>
Felix Held38880d22023-08-12 00:30:36 +02005#include <arch/null_breakpoint.h>
Stefan Reinauer42dc7212009-10-24 00:47:07 +00006#include <arch/registers.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +10007#include <boot/coreboot_tables.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00008#include <console/console.h>
Stefan Reinauerc1efb902011-10-12 14:30:59 -07009#include <delay.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100010#include <device/pci.h>
11#include <device/pci_ids.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100012#include <pc80/i8259.h>
zbao741a0dd2015-06-25 16:58:53 -040013#include <pc80/i8254.h>
Arthur Heymans15c9c782021-11-25 09:39:02 +010014#include <stdint.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100015#include <string.h>
16#include <vbe.h>
Patrick Rudolph92106b12020-02-19 12:54:06 +010017#include <framebuffer_info.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100018
Patrick Georgi199b09c2012-11-22 12:46:12 +010019/* we use x86emu's register file representation */
20#include <x86emu/regs.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100021
22#include "x86.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010023
Subrata Banika2602152019-07-12 17:41:43 +053024typedef struct {
25 char signature[4];
26 u16 version;
27 u8 *oem_string_ptr;
28 u32 capabilities;
29 u32 video_mode_ptr;
30 u16 total_memory;
31 char reserved[236];
32} __packed vbe_info_block;
33
Aaron Durbina146d582013-02-08 16:56:51 -060034/* The following symbols cannot be used directly. They need to be fixed up
35 * to point to the correct address location after the code has been copied
36 * to REALMODE_BASE. Absolute symbols are not used because those symbols are
37 * relocated when a relocatable ramstage is enabled.
38 */
39extern unsigned char __realmode_call, __realmode_interrupt;
40extern unsigned char __realmode_buffer;
41
42#define PTR_TO_REAL_MODE(sym)\
43 (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code))
44
Patrick Georgi199b09c2012-11-22 12:46:12 +010045/* to have a common register file for interrupt handlers */
46X86EMU_sysEnv _X86EMU_env;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000047
Subrata Banikc76bfac2019-07-12 16:43:17 +053048unsigned int (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060049 u32 esi, u32 edi) asmlinkage;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000050
Subrata Banikc76bfac2019-07-12 16:43:17 +053051unsigned int (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx,
52 u32 edx, u32 esi, u32 edi) asmlinkage;
Aaron Durbina146d582013-02-08 16:56:51 -060053
54static void setup_realmode_code(void)
55{
56 memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size);
57
58 /* Ensure the global pointers are relocated properly. */
59 realmode_call = PTR_TO_REAL_MODE(__realmode_call);
60 realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt);
61
62 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
63 __realmode_code_size);
64}
Stefan Reinauer841af5e2010-05-11 15:39:20 +000065
Stefan Reinauer841af5e2010-05-11 15:39:20 +000066static void setup_rombios(void)
67{
68 const char date[] = "06/11/99";
69 memcpy((void *)0xffff5, &date, 8);
70
71 const char ident[] = "PCI_ISA";
72 memcpy((void *)0xfffd9, &ident, 7);
73
74 /* system model: IBM-AT */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 write8((void *)0xffffe, 0xfc);
Stefan Reinauer841af5e2010-05-11 15:39:20 +000076}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000077
Patrick Georgi199b09c2012-11-22 12:46:12 +010078static int (*intXX_handler[256])(void) = { NULL };
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000079
Patrick Georgi199b09c2012-11-22 12:46:12 +010080static int intXX_exception_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000081{
Patrick Georgi199b09c2012-11-22 12:46:12 +010082 /* compatibility shim */
83 struct eregs reg_info = {
84 .eax=X86_EAX,
85 .ecx=X86_ECX,
86 .edx=X86_EDX,
87 .ebx=X86_EBX,
88 .esp=X86_ESP,
89 .ebp=X86_EBP,
90 .esi=X86_ESI,
91 .edi=X86_EDI,
92 .vector=M.x86.intno,
93 .error_code=0, // FIXME: fill in
Patrick Georgi199b09c2012-11-22 12:46:12 +010094 .cs=X86_CS,
Arthur Heymans15c9c782021-11-25 09:39:02 +010095#if ENV_X86_64
96 .rip=X86_EIP,
97 .rflags=X86_EFLAGS
98#else
99 .eip=X86_EIP,
Patrick Georgi199b09c2012-11-22 12:46:12 +0100100 .eflags=X86_EFLAGS
Arthur Heymans15c9c782021-11-25 09:39:02 +0100101#endif
Patrick Georgi199b09c2012-11-22 12:46:12 +0100102 };
103 struct eregs *regs = &reg_info;
104
Stefan Reinauer14e22772010-04-27 06:56:47 +0000105 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Arthur Heymans15c9c782021-11-25 09:39:02 +0100106 (uint32_t)regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000107 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000108
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700109 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000110}
111
Patrick Georgi199b09c2012-11-22 12:46:12 +0100112static int intXX_unknown_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000113{
Myles Watsonf53eaa32010-09-09 14:42:58 +0000114 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100115 M.x86.intno, X86_EAX);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000116
117 return -1;
118}
119
Libra Lic1436932009-12-23 19:16:47 +0000120/* setup interrupt handlers for mainboard */
Aaron Durbin4d7a4c52013-04-23 10:25:34 -0500121void mainboard_interrupt_handlers(int intXX, int (*intXX_func)(void))
Libra Lic1436932009-12-23 19:16:47 +0000122{
123 intXX_handler[intXX] = intXX_func;
124}
125
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000126static void setup_interrupt_handlers(void)
127{
128 int i;
129
Stefan Reinauer14e22772010-04-27 06:56:47 +0000130 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000131 * but the CPU-generated exceptions ("hardware interrupts")
132 */
133 for (i = 0; i < 0x10; i++)
134 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000135
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000136 /* Mark all other intXX calls as unknown first */
137 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +0000138 {
139 /* If the mainboard_interrupt_handler isn't called first.
140 */
Elyes HAOUAS5ba154a2020-08-04 13:27:52 +0200141 if (!intXX_handler[i])
Libra Lic1436932009-12-23 19:16:47 +0000142 {
143 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700144 * needed to initialize the option roms. This is
145 * very slick, as it allows us to implement mainboard
146 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000147 */
148 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000149 case 0x10:
150 intXX_handler[0x10] = &int10_handler;
151 break;
Libra Lic1436932009-12-23 19:16:47 +0000152 case 0x12:
153 intXX_handler[0x12] = &int12_handler;
154 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000155 case 0x16:
156 intXX_handler[0x16] = &int16_handler;
157 break;
Libra Lic1436932009-12-23 19:16:47 +0000158 case 0x1a:
159 intXX_handler[0x1a] = &int1a_handler;
160 break;
161 default:
162 intXX_handler[i] = &intXX_unknown_handler;
163 break;
164 }
165 }
166 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000167}
168
169static void write_idt_stub(void *target, u8 intnum)
170{
171 unsigned char *codeptr;
172 codeptr = (unsigned char *) target;
Aaron Durbina146d582013-02-08 16:56:51 -0600173 memcpy(codeptr, &__idt_handler, __idt_handler_size);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000174 codeptr[3] = intnum; /* modify int# in the code stub. */
175}
176
177static void setup_realmode_idt(void)
178{
179 struct realmode_idt *idts = (struct realmode_idt *) 0;
180 int i;
181
Felix Held38880d22023-08-12 00:30:36 +0200182 /* It's expected that we write to the NULL page in the first two iterations of the
183 following loop, so temporarily disable the NULL breakpoint. */
184 null_breakpoint_disable();
185
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000186 /* Copy IDT stub code for each interrupt. This might seem wasteful
187 * but it is really simple
188 */
Felix Held38880d22023-08-12 00:30:36 +0200189 for (i = 0; i < 256; i++) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000190 idts[i].cs = 0;
Aaron Durbina146d582013-02-08 16:56:51 -0600191 idts[i].offset = 0x1000 + (i * __idt_handler_size);
Stefan Reinauer83fa1692015-06-18 22:01:07 -0700192 write_idt_stub((void *)((uintptr_t)idts[i].offset), i);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000193 }
194
Felix Held38880d22023-08-12 00:30:36 +0200195 null_breakpoint_init();
196
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000197 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000198 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000199 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000200
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000201 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000202 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000203 /* BIOS Int 11 Handler F000:F84D */
204 write_idt_stub((void *)0xff84d, 0x11);
205 /* BIOS Int 12 Handler F000:F841 */
206 write_idt_stub((void *)0xff841, 0x12);
207 /* BIOS Int 13 Handler F000:EC59 */
208 write_idt_stub((void *)0xfec59, 0x13);
209 /* BIOS Int 14 Handler F000:E739 */
210 write_idt_stub((void *)0xfe739, 0x14);
211 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000212 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000213 /* BIOS Int 16 Handler F000:E82E */
214 write_idt_stub((void *)0xfe82e, 0x16);
215 /* BIOS Int 17 Handler F000:EFD2 */
216 write_idt_stub((void *)0xfefd2, 0x17);
217 /* ROM BIOS Int 1A Handler F000:FE6E */
218 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000219}
220
Julius Wernercd49cce2019-03-05 16:53:33 -0800221#if CONFIG(FRAMEBUFFER_SET_VESA_MODE)
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +0200222static vbe_mode_info_t mode_info;
Gabe Blackfb8632a2012-09-30 04:47:48 -0700223static int mode_info_valid;
224
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +0200225const vbe_mode_info_t *vbe_mode_info(void)
226{
227 if (!mode_info_valid || !mode_info.vesa.phys_base_ptr)
228 return NULL;
229 return &mode_info;
230}
231
Subrata Banika2602152019-07-12 17:41:43 +0530232static int vbe_check_for_failure(int ah);
233
Martin Rothaeffa862021-01-20 12:07:31 -0700234static u8 vbe_get_ctrl_info(vbe_info_block *info)
Subrata Banika2602152019-07-12 17:41:43 +0530235{
236 char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
237 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
238 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
239 X86_EAX = realmode_interrupt(0x10, VESA_GET_INFO, 0x0000, 0x0000,
240 0x0000, buffer_seg, buffer_adr);
241 /* If the VBE function completed successfully, 0x0 is returned in AH */
Martin Rothaeffa862021-01-20 12:07:31 -0700242 if (X86_AH) {
Julius Wernere9665952022-01-21 17:06:20 -0800243 printk(BIOS_WARNING, "Error from VGA BIOS in %s\n", __func__);
Martin Rothaeffa862021-01-20 12:07:31 -0700244 return 1;
245 }
Subrata Banika2602152019-07-12 17:41:43 +0530246 memcpy(info, buffer, sizeof(vbe_info_block));
Martin Rothaeffa862021-01-20 12:07:31 -0700247 return 0;
Subrata Banika2602152019-07-12 17:41:43 +0530248}
249
250static void vbe_oprom_list_supported_mode(uint16_t *video_mode_ptr)
251{
252 uint16_t mode;
253 printk(BIOS_DEBUG, "Supported Video Mode list for OpRom:\n");
254 do {
255 mode = *video_mode_ptr++;
256 if (mode != 0xffff)
257 printk(BIOS_DEBUG, "%x\n", mode);
258 } while (mode != 0xffff);
259}
260
Martin Rothaeffa862021-01-20 12:07:31 -0700261static u8 vbe_oprom_supported_mode_list(void)
Subrata Banika2602152019-07-12 17:41:43 +0530262{
263 uint16_t segment, offset;
264 vbe_info_block info;
265
Martin Rothaeffa862021-01-20 12:07:31 -0700266 if (vbe_get_ctrl_info(&info))
267 return 1;
Subrata Banika2602152019-07-12 17:41:43 +0530268
269 offset = info.video_mode_ptr;
270 segment = info.video_mode_ptr >> 16;
271
272 vbe_oprom_list_supported_mode((uint16_t *)((segment << 4) + offset));
Martin Rothaeffa862021-01-20 12:07:31 -0700273 return 0;
Subrata Banika2602152019-07-12 17:41:43 +0530274}
Subrata Banikc76bfac2019-07-12 16:43:17 +0530275/*
276 * EAX register is used to indicate the completion status upon return from
277 * VBE function in real mode.
278 *
279 * If the VBE function completed successfully then 0x0 is returned in the AH
280 * register. Otherwise the AH register is set with the nature of the failure:
281 *
282 * AH == 0x00: Function call successful
283 * AH == 0x01: Function call failed
284 * AH == 0x02: Function is not supported in the current HW configuration
285 * AH == 0x03: Function call invalid in current video mode
286 *
287 * Return 0 on success else -1 for failure
288 */
289static int vbe_check_for_failure(int ah)
290{
291 int status;
292
293 switch (ah) {
294 case 0x0:
295 status = 0;
296 break;
297 case 1:
298 printk(BIOS_DEBUG, "VBE: Function call failed!\n");
299 status = -1;
300 break;
301 case 2:
302 printk(BIOS_DEBUG, "VBE: Function is not supported!\n");
303 status = -1;
304 break;
305 case 3:
306 default:
307 printk(BIOS_DEBUG, "VBE: Unsupported video mode %x!\n",
308 CONFIG_FRAMEBUFFER_VESA_MODE);
Martin Rothaeffa862021-01-20 12:07:31 -0700309 if (vbe_oprom_supported_mode_list())
310 printk(BIOS_WARNING, "VBE Warning: Could not get VBE mode list.\n");
Subrata Banikc76bfac2019-07-12 16:43:17 +0530311 status = -1;
312 break;
313 }
314
315 return status;
316}
Gabe Blackfb8632a2012-09-30 04:47:48 -0700317static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700318{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700319 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700320 mi->video_mode);
Aaron Durbina146d582013-02-08 16:56:51 -0600321 char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700322 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
323 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
Subrata Banikc76bfac2019-07-12 16:43:17 +0530324 X86_EAX = realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700325 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
Martin Rothaeffa862021-01-20 12:07:31 -0700326 if (vbe_check_for_failure(X86_AH)) {
327 printk(BIOS_WARNING, "VBE Warning: Error from VGA BIOS in %s\n", __func__);
328 return 1;
329 }
Zhuo-Hao Lee29445dc2014-12-24 11:13:34 +0800330 memcpy(mi->mode_info_block, buffer, sizeof(mi->mode_info_block));
Gabe Blackfb8632a2012-09-30 04:47:48 -0700331 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700332 return 0;
333}
334
Gabe Blackfb8632a2012-09-30 04:47:48 -0700335static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700336{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700337 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700338 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700339 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700340 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700341 mi->video_mode &= ~(1 << 15);
Subrata Banikc76bfac2019-07-12 16:43:17 +0530342 X86_EAX = realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700343 0x0000, 0x0000, 0x0000, 0x0000);
Martin Rothaeffa862021-01-20 12:07:31 -0700344 if (vbe_check_for_failure(X86_AH)) {
345 printk(BIOS_WARNING, "VBE Warning: Error from VGA BIOS in %s\n", __func__);
346 return 1;
347 }
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700348 return 0;
349}
350
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700351/* These two functions could probably even be generic between
352 * yabel and x86 native. TBD later.
353 */
354void vbe_set_graphics(void)
355{
356 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
Martin Rothaeffa862021-01-20 12:07:31 -0700357 if (vbe_get_mode_info(&mode_info)) {
358 printk(BIOS_WARNING, "VBE Warning: Could not get VBE graphics mode info.\n");
359 return;
360 }
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700361 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700362 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700363 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
364 le16_to_cpu(mode_info.vesa.x_resolution),
365 le16_to_cpu(mode_info.vesa.y_resolution),
366 mode_info.vesa.bits_per_pixel);
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +0200367
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700368 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
369 if (!framebuffer) {
370 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
371 "framebuffer\n");
372 return;
373 }
374
Martin Rothaeffa862021-01-20 12:07:31 -0700375 if (vbe_set_mode(&mode_info)) {
376 printk(BIOS_WARNING, "VBE Warning: Could not set VBE graphics mode.\n");
377 return;
378 }
Patrick Rudolph92106b12020-02-19 12:54:06 +0100379 const struct lb_framebuffer fb = {
380 .physical_address = mode_info.vesa.phys_base_ptr,
381 .x_resolution = le16_to_cpu(mode_info.vesa.x_resolution),
382 .y_resolution = le16_to_cpu(mode_info.vesa.y_resolution),
383 .bytes_per_line = le16_to_cpu(mode_info.vesa.bytes_per_scanline),
384 .bits_per_pixel = mode_info.vesa.bits_per_pixel,
385 .red_mask_pos = mode_info.vesa.red_mask_pos,
386 .red_mask_size = mode_info.vesa.red_mask_size,
387 .green_mask_pos = mode_info.vesa.green_mask_pos,
388 .green_mask_size = mode_info.vesa.green_mask_size,
389 .blue_mask_pos = mode_info.vesa.blue_mask_pos,
390 .blue_mask_size = mode_info.vesa.blue_mask_size,
391 .reserved_mask_pos = mode_info.vesa.reserved_mask_pos,
392 .reserved_mask_size = mode_info.vesa.reserved_mask_size,
393 .orientation = LB_FB_ORIENTATION_NORMAL,
394 };
395
396 fb_add_framebuffer_info_ex(&fb);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700397}
398
399void vbe_textmode_console(void)
400{
Martin Rothaeffa862021-01-20 12:07:31 -0700401 u8 retval = 1;
402 if (mode_info.vesa.phys_base_ptr) {
403 delay(2);
404 X86_EAX = realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
405 0x0000, 0x0000, 0x0000);
406 if (!vbe_check_for_failure(X86_AH))
407 retval = 0;
408 }
409
410 if (retval)
411 printk(BIOS_WARNING, "VBE Warning: Could not set VBE text mode.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700412}
413
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700414#endif
415
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000416void run_bios(struct device *dev, unsigned long addr)
417{
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200418 u32 num_dev = (dev->upstream->secondary << 8) | dev->path.pci.devfn;
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000419
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700420 /* Setting up required hardware.
421 * Removing this will cause random illegal instruction exceptions
422 * in some option roms.
423 */
424 setup_i8259();
zbao741a0dd2015-06-25 16:58:53 -0400425 setup_i8254();
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700426
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000427 /* Set up some legacy information in the F segment */
428 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000429
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000430 /* Set up C interrupt handlers */
431 setup_interrupt_handlers();
432
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000433 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000434 setup_realmode_idt();
435
Aaron Durbina146d582013-02-08 16:56:51 -0600436 /* Make sure the code is placed. */
437 setup_realmode_code();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000438
439 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000440 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
441 /* Option ROM entry point is at OPROM start + 3 */
442 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000443 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700444
Julius Wernercd49cce2019-03-05 16:53:33 -0800445#if CONFIG(FRAMEBUFFER_SET_VESA_MODE)
Stefan Reinauer22ae2b92013-02-08 08:48:20 -0800446 if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA)
447 vbe_set_graphics();
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700448#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000449}
450
Stefan Reinauer14e22772010-04-27 06:56:47 +0000451/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000452 * so there is no use in putting the prototype into a header file.
453 */
Stefan Reinauer399486e2012-12-06 13:54:29 -0800454int asmlinkage interrupt_handler(u32 intnumber,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000455 u32 gsfs, u32 dses,
456 u32 edi, u32 esi,
457 u32 ebp, u32 esp,
458 u32 ebx, u32 edx,
459 u32 ecx, u32 eax,
Uwe Hermann312673c2009-10-27 21:49:33 +0000460 u32 cs_ip, u16 stackflags);
461
Stefan Reinauer399486e2012-12-06 13:54:29 -0800462int asmlinkage interrupt_handler(u32 intnumber,
Uwe Hermann312673c2009-10-27 21:49:33 +0000463 u32 gsfs, u32 dses,
464 u32 edi, u32 esi,
465 u32 ebp, u32 esp,
466 u32 ebx, u32 edx,
467 u32 ecx, u32 eax,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000468 u32 cs_ip, u16 stackflags)
469{
470 u32 ip;
471 u32 cs;
472 u32 flags;
Patrick Georgi503af722012-11-22 10:48:18 +0100473 int ret = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000474
475 ip = cs_ip & 0xffff;
476 cs = cs_ip >> 16;
477 flags = stackflags;
478
Julius Wernercd49cce2019-03-05 16:53:33 -0800479#if CONFIG(REALMODE_DEBUG)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000480 printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber);
481 printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n",
482 eax, ebx, ecx, edx);
483 printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n",
484 ebp, esp, edi, esi);
485 printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n",
486 ip, cs, flags);
Myles Watson6c9bc012010-09-07 22:30:15 +0000487#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000488
Patrick Georgi199b09c2012-11-22 12:46:12 +0100489 // Fetch arguments from the stack and put them to a place
490 // suitable for the interrupt handlers
491 X86_EAX = eax;
492 X86_ECX = ecx;
493 X86_EDX = edx;
494 X86_EBX = ebx;
495 X86_ESP = esp;
496 X86_EBP = ebp;
497 X86_ESI = esi;
498 X86_EDI = edi;
499 M.x86.intno = intnumber;
500 /* TODO: error_code must be stored somewhere */
501 X86_EIP = ip;
502 X86_CS = cs;
503 X86_EFLAGS = flags;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000504
505 // Call the interrupt handler for this int#
Patrick Georgi199b09c2012-11-22 12:46:12 +0100506 ret = intXX_handler[intnumber]();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000507
508 // Put registers back on the stack. The assembler code
509 // will later pop them.
510 // What happens here is that we force (volatile!) changing
511 // the values of the parameters of this function. We do this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000512 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000513 // we leave this function. Don't say this is bollocks.
Patrick Georgi199b09c2012-11-22 12:46:12 +0100514 *(volatile u32 *)&eax = X86_EAX;
515 *(volatile u32 *)&ecx = X86_ECX;
516 *(volatile u32 *)&edx = X86_EDX;
517 *(volatile u32 *)&ebx = X86_EBX;
518 *(volatile u32 *)&esi = X86_ESI;
519 *(volatile u32 *)&edi = X86_EDI;
520 flags = X86_EFLAGS;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000521
Patrick Georgi503af722012-11-22 10:48:18 +0100522 /* Pass success or error back to our caller via the CARRY flag */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000523 if (ret) {
Patrick Georgi503af722012-11-22 10:48:18 +0100524 flags &= ~1; // no error: clear carry
525 }else{
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000526 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000527 flags |= 1; // error: set carry
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000528 }
529 *(volatile u16 *)&stackflags = flags;
530
Patrick Georgi503af722012-11-22 10:48:18 +0100531 /* The assembler code doesn't actually care for the return value,
532 * but keep it around so its expectations are met */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000533 return ret;
534}