blob: 485d1a4e42612caa602ff0d158aae065e162a15f [file] [log] [blame]
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer9839cbd2010-04-21 20:06:10 +00004 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Copyright (C) 2009-2010 coresystems GmbH
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00006 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc..
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000019 */
20
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000021#include <arch/io.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100022#include <arch/interrupt.h>
Stefan Reinauer42dc7212009-10-24 00:47:07 +000023#include <arch/registers.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100024#include <boot/coreboot_tables.h>
Edward O'Callaghan7842eb22014-07-29 22:28:19 +100025#include <cbfs.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000026#include <console/console.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100027#include <cpu/amd/lxdef.h>
28#include <cpu/amd/vr.h>
Stefan Reinauerc1efb902011-10-12 14:30:59 -070029#include <delay.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100030#include <device/pci.h>
31#include <device/pci_ids.h>
Patrick Georgi3e77eb62012-11-22 10:39:16 +010032#include <lib/jpeg.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100033#include <pc80/i8259.h>
34#include <string.h>
35#include <vbe.h>
36
Patrick Georgi199b09c2012-11-22 12:46:12 +010037/* we use x86emu's register file representation */
38#include <x86emu/regs.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100039
40#include "x86.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010041
Aaron Durbina146d582013-02-08 16:56:51 -060042/* The following symbols cannot be used directly. They need to be fixed up
43 * to point to the correct address location after the code has been copied
44 * to REALMODE_BASE. Absolute symbols are not used because those symbols are
45 * relocated when a relocatable ramstage is enabled.
46 */
47extern unsigned char __realmode_call, __realmode_interrupt;
48extern unsigned char __realmode_buffer;
49
50#define PTR_TO_REAL_MODE(sym)\
51 (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code))
52
Patrick Georgi199b09c2012-11-22 12:46:12 +010053/* to have a common register file for interrupt handlers */
54X86EMU_sysEnv _X86EMU_env;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000055
Stefan Reinauer841af5e2010-05-11 15:39:20 +000056void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060057 u32 esi, u32 edi) asmlinkage;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000058
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070059void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060060 u32 esi, u32 edi) asmlinkage;
61
62static void setup_realmode_code(void)
63{
64 memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size);
65
66 /* Ensure the global pointers are relocated properly. */
67 realmode_call = PTR_TO_REAL_MODE(__realmode_call);
68 realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt);
69
70 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
71 __realmode_code_size);
72}
Stefan Reinauer841af5e2010-05-11 15:39:20 +000073
Stefan Reinauer841af5e2010-05-11 15:39:20 +000074static void setup_rombios(void)
75{
76 const char date[] = "06/11/99";
77 memcpy((void *)0xffff5, &date, 8);
78
79 const char ident[] = "PCI_ISA";
80 memcpy((void *)0xfffd9, &ident, 7);
81
82 /* system model: IBM-AT */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080083 write8((void *)0xffffe, 0xfc);
Stefan Reinauer841af5e2010-05-11 15:39:20 +000084}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000085
Patrick Georgi199b09c2012-11-22 12:46:12 +010086static int (*intXX_handler[256])(void) = { NULL };
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000087
Patrick Georgi199b09c2012-11-22 12:46:12 +010088static int intXX_exception_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000089{
Patrick Georgi199b09c2012-11-22 12:46:12 +010090 /* compatibility shim */
91 struct eregs reg_info = {
92 .eax=X86_EAX,
93 .ecx=X86_ECX,
94 .edx=X86_EDX,
95 .ebx=X86_EBX,
96 .esp=X86_ESP,
97 .ebp=X86_EBP,
98 .esi=X86_ESI,
99 .edi=X86_EDI,
100 .vector=M.x86.intno,
101 .error_code=0, // FIXME: fill in
102 .eip=X86_EIP,
103 .cs=X86_CS,
104 .eflags=X86_EFLAGS
105 };
106 struct eregs *regs = &reg_info;
107
Stefan Reinauer14e22772010-04-27 06:56:47 +0000108 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000109 regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000110 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000111
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700112 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000113}
114
Patrick Georgi199b09c2012-11-22 12:46:12 +0100115static int intXX_unknown_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000116{
Myles Watsonf53eaa32010-09-09 14:42:58 +0000117 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100118 M.x86.intno, X86_EAX);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000119
120 return -1;
121}
122
Libra Lic1436932009-12-23 19:16:47 +0000123/* setup interrupt handlers for mainboard */
Aaron Durbin4d7a4c52013-04-23 10:25:34 -0500124void mainboard_interrupt_handlers(int intXX, int (*intXX_func)(void))
Libra Lic1436932009-12-23 19:16:47 +0000125{
126 intXX_handler[intXX] = intXX_func;
127}
128
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000129static void setup_interrupt_handlers(void)
130{
131 int i;
132
Stefan Reinauer14e22772010-04-27 06:56:47 +0000133 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000134 * but the CPU-generated exceptions ("hardware interrupts")
135 */
136 for (i = 0; i < 0x10; i++)
137 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000138
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000139 /* Mark all other intXX calls as unknown first */
140 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +0000141 {
142 /* If the mainboard_interrupt_handler isn't called first.
143 */
144 if(!intXX_handler[i])
145 {
146 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700147 * needed to initialize the option roms. This is
148 * very slick, as it allows us to implement mainboard
149 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000150 */
151 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000152 case 0x10:
153 intXX_handler[0x10] = &int10_handler;
154 break;
Libra Lic1436932009-12-23 19:16:47 +0000155 case 0x12:
156 intXX_handler[0x12] = &int12_handler;
157 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000158 case 0x16:
159 intXX_handler[0x16] = &int16_handler;
160 break;
Libra Lic1436932009-12-23 19:16:47 +0000161 case 0x1a:
162 intXX_handler[0x1a] = &int1a_handler;
163 break;
164 default:
165 intXX_handler[i] = &intXX_unknown_handler;
166 break;
167 }
168 }
169 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000170}
171
172static void write_idt_stub(void *target, u8 intnum)
173{
174 unsigned char *codeptr;
175 codeptr = (unsigned char *) target;
Aaron Durbina146d582013-02-08 16:56:51 -0600176 memcpy(codeptr, &__idt_handler, __idt_handler_size);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000177 codeptr[3] = intnum; /* modify int# in the code stub. */
178}
179
180static void setup_realmode_idt(void)
181{
182 struct realmode_idt *idts = (struct realmode_idt *) 0;
183 int i;
184
185 /* Copy IDT stub code for each interrupt. This might seem wasteful
186 * but it is really simple
187 */
188 for (i = 0; i < 256; i++) {
189 idts[i].cs = 0;
Aaron Durbina146d582013-02-08 16:56:51 -0600190 idts[i].offset = 0x1000 + (i * __idt_handler_size);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000191 write_idt_stub((void *)((u32 )idts[i].offset), i);
192 }
193
194 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000195 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000196 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000197
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000198 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000199 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000200 /* BIOS Int 11 Handler F000:F84D */
201 write_idt_stub((void *)0xff84d, 0x11);
202 /* BIOS Int 12 Handler F000:F841 */
203 write_idt_stub((void *)0xff841, 0x12);
204 /* BIOS Int 13 Handler F000:EC59 */
205 write_idt_stub((void *)0xfec59, 0x13);
206 /* BIOS Int 14 Handler F000:E739 */
207 write_idt_stub((void *)0xfe739, 0x14);
208 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000209 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000210 /* BIOS Int 16 Handler F000:E82E */
211 write_idt_stub((void *)0xfe82e, 0x16);
212 /* BIOS Int 17 Handler F000:EFD2 */
213 write_idt_stub((void *)0xfefd2, 0x17);
214 /* ROM BIOS Int 1A Handler F000:FE6E */
215 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000216}
217
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700218#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Gabe Blackfb8632a2012-09-30 04:47:48 -0700219vbe_mode_info_t mode_info;
220static int mode_info_valid;
221
222int vbe_mode_info_valid(void)
223{
224 return mode_info_valid;
225}
226
227static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700228{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700229 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700230 mi->video_mode);
Aaron Durbina146d582013-02-08 16:56:51 -0600231 char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700232 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
233 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
234 realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700235 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
Zhuo-Hao Lee29445dc2014-12-24 11:13:34 +0800236 memcpy(mi->mode_info_block, buffer, sizeof(mi->mode_info_block));
Gabe Blackfb8632a2012-09-30 04:47:48 -0700237 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700238 return 0;
239}
240
Gabe Blackfb8632a2012-09-30 04:47:48 -0700241static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700242{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700243 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700244 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700245 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700246 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700247 mi->video_mode &= ~(1 << 15);
248 realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700249 0x0000, 0x0000, 0x0000, 0x0000);
250 return 0;
251}
252
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700253/* These two functions could probably even be generic between
254 * yabel and x86 native. TBD later.
255 */
256void vbe_set_graphics(void)
257{
258 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
259 vbe_get_mode_info(&mode_info);
260 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700261 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700262 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
263 le16_to_cpu(mode_info.vesa.x_resolution),
264 le16_to_cpu(mode_info.vesa.y_resolution),
265 mode_info.vesa.bits_per_pixel);
266 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
267 if (!framebuffer) {
268 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
269 "framebuffer\n");
270 return;
271 }
272
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700273 vbe_set_mode(&mode_info);
274#if CONFIG_BOOTSPLASH
275 struct jpeg_decdata *decdata;
Aaron Durbin899d13d2015-05-15 23:39:23 -0500276 unsigned char *jpeg = cbfs_boot_map_with_leak("bootsplash.jpg",
277 CBFS_TYPE_BOOTSPLASH,
278 NULL);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700279 if (!jpeg) {
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700280 printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700281 return;
282 }
Daniele Forsif9ce88e2014-07-26 11:32:16 +0200283 decdata = malloc(sizeof(*decdata));
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700284 int ret = 0;
285 ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
286#endif
287}
288
289void vbe_textmode_console(void)
290{
291 delay(2);
292 realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
293 0x0000, 0x0000, 0x0000);
294}
295
296void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
297{
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700298 framebuffer->physical_address = mode_info.vesa.phys_base_ptr;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700299
300 framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution);
301 framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution);
302 framebuffer->bytes_per_line =
303 le16_to_cpu(mode_info.vesa.bytes_per_scanline);
304 framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel;
305
306 framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos;
307 framebuffer->red_mask_size = mode_info.vesa.red_mask_size;
308
309 framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos;
310 framebuffer->green_mask_size = mode_info.vesa.green_mask_size;
311
312 framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos;
313 framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size;
314
315 framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos;
316 framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size;
317}
318#endif
319
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000320void run_bios(struct device *dev, unsigned long addr)
321{
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000322 u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn;
323
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700324 /* Setting up required hardware.
325 * Removing this will cause random illegal instruction exceptions
326 * in some option roms.
327 */
328 setup_i8259();
329
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000330 /* Set up some legacy information in the F segment */
331 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000332
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000333 /* Set up C interrupt handlers */
334 setup_interrupt_handlers();
335
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000336 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000337 setup_realmode_idt();
338
Aaron Durbina146d582013-02-08 16:56:51 -0600339 /* Make sure the code is placed. */
340 setup_realmode_code();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000341
342 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000343 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
344 /* Option ROM entry point is at OPROM start + 3 */
345 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000346 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700347
348#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Stefan Reinauer22ae2b92013-02-08 08:48:20 -0800349 if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA)
350 vbe_set_graphics();
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700351#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000352}
353
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000354#if CONFIG_GEODE_VSA
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000355
356#define VSA2_BUFFER 0x60000
357#define VSA2_ENTRY_POINT 0x60020
358
359// TODO move to a header file.
360void do_vsmbios(void);
361
362/* VSA virtual register helper */
363static u32 VSA_vrRead(u16 classIndex)
364{
365 u32 eax, ebx, ecx, edx;
366 asm volatile (
367 "movw $0x0AC1C, %%dx\n"
368 "orl $0x0FC530000, %%eax\n"
369 "outl %%eax, %%dx\n"
370 "addb $2, %%dl\n"
371 "inw %%dx, %%ax\n"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000372 : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000373 : "a"(classIndex)
374 );
375
376 return eax;
377}
378
379void do_vsmbios(void)
380{
381 printk(BIOS_DEBUG, "Preparing for VSA...\n");
382
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000383 /* Set up C interrupt handlers */
384 setup_interrupt_handlers();
385
386 /* Setting up realmode IDT */
387 setup_realmode_idt();
388
Aaron Durbina146d582013-02-08 16:56:51 -0600389 /* Make sure the code is placed. */
390 setup_realmode_code();
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000391
Aaron Durbin899d13d2015-05-15 23:39:23 -0500392 if ((uintptr_t)cbfs_boot_load_stage_by_name("vsa") !=
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800393 VSA2_ENTRY_POINT) {
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000394 printk(BIOS_ERR, "Failed to load VSA.\n");
395 return;
396 }
397
398 unsigned char *buf = (unsigned char *)VSA2_BUFFER;
399 printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]);
400 printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n",
401 buf[0x20], buf[0x21], buf[0x22], buf[0x23]);
402
403 /* Check for code to emit POST code at start of VSA. */
404 if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) ||
405 (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) {
406 printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n");
407 return;
408 }
409
410 printk(BIOS_DEBUG, "Calling VSA module...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000411
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000412 /* ECX gets SMM, EDX gets SYSMEM */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700413 realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM,
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000414 MSR_GLIU0_SYSMEM, 0x0, 0x0);
415
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000416 printk(BIOS_DEBUG, "... VSA module returned.\n");
417
418 /* Restart timer 1 */
419 outb(0x56, 0x43);
420 outb(0x12, 0x41);
421
422 /* Check that VSA is running OK */
423 if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE)
424 printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n");
425 else
426 printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n");
427}
428#endif
429
Stefan Reinauer14e22772010-04-27 06:56:47 +0000430/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000431 * so there is no use in putting the prototype into a header file.
432 */
Stefan Reinauer399486e2012-12-06 13:54:29 -0800433int asmlinkage interrupt_handler(u32 intnumber,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000434 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 Hermann312673c2009-10-27 21:49:33 +0000439 u32 cs_ip, u16 stackflags);
440
Stefan Reinauer399486e2012-12-06 13:54:29 -0800441int asmlinkage interrupt_handler(u32 intnumber,
Uwe Hermann312673c2009-10-27 21:49:33 +0000442 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 Reinauer38cd29e2009-08-11 21:28:25 +0000447 u32 cs_ip, u16 stackflags)
448{
449 u32 ip;
450 u32 cs;
451 u32 flags;
Patrick Georgi503af722012-11-22 10:48:18 +0100452 int ret = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000453
454 ip = cs_ip & 0xffff;
455 cs = cs_ip >> 16;
456 flags = stackflags;
457
Myles Watson6c9bc012010-09-07 22:30:15 +0000458#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000459 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 Watson6c9bc012010-09-07 22:30:15 +0000466#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000467
Patrick Georgi199b09c2012-11-22 12:46:12 +0100468 // 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 Reinauer38cd29e2009-08-11 21:28:25 +0000483
484 // Call the interrupt handler for this int#
Patrick Georgi199b09c2012-11-22 12:46:12 +0100485 ret = intXX_handler[intnumber]();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000486
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 Reinauer14e22772010-04-27 06:56:47 +0000491 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000492 // we leave this function. Don't say this is bollocks.
Patrick Georgi199b09c2012-11-22 12:46:12 +0100493 *(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 Reinauer38cd29e2009-08-11 21:28:25 +0000500
Patrick Georgi503af722012-11-22 10:48:18 +0100501 /* Pass success or error back to our caller via the CARRY flag */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000502 if (ret) {
Patrick Georgi503af722012-11-22 10:48:18 +0100503 flags &= ~1; // no error: clear carry
504 }else{
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000505 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000506 flags |= 1; // error: set carry
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000507 }
508 *(volatile u16 *)&stackflags = flags;
509
Patrick Georgi503af722012-11-22 10:48:18 +0100510 /* The assembler code doesn't actually care for the return value,
511 * but keep it around so its expectations are met */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000512 return ret;
513}