blob: b8f54f3039146f42841c7445cc127a56c29541c0 [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>
zbao741a0dd2015-06-25 16:58:53 -040034#include <pc80/i8254.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100035#include <string.h>
36#include <vbe.h>
37
Patrick Georgi199b09c2012-11-22 12:46:12 +010038/* we use x86emu's register file representation */
39#include <x86emu/regs.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100040
41#include "x86.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010042
Aaron Durbina146d582013-02-08 16:56:51 -060043/* The following symbols cannot be used directly. They need to be fixed up
44 * to point to the correct address location after the code has been copied
45 * to REALMODE_BASE. Absolute symbols are not used because those symbols are
46 * relocated when a relocatable ramstage is enabled.
47 */
48extern unsigned char __realmode_call, __realmode_interrupt;
49extern unsigned char __realmode_buffer;
50
51#define PTR_TO_REAL_MODE(sym)\
52 (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code))
53
Patrick Georgi199b09c2012-11-22 12:46:12 +010054/* to have a common register file for interrupt handlers */
55X86EMU_sysEnv _X86EMU_env;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000056
Stefan Reinauer841af5e2010-05-11 15:39:20 +000057void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060058 u32 esi, u32 edi) asmlinkage;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000059
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070060void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060061 u32 esi, u32 edi) asmlinkage;
62
63static void setup_realmode_code(void)
64{
65 memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size);
66
67 /* Ensure the global pointers are relocated properly. */
68 realmode_call = PTR_TO_REAL_MODE(__realmode_call);
69 realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt);
70
71 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
72 __realmode_code_size);
73}
Stefan Reinauer841af5e2010-05-11 15:39:20 +000074
Stefan Reinauer841af5e2010-05-11 15:39:20 +000075static void setup_rombios(void)
76{
77 const char date[] = "06/11/99";
78 memcpy((void *)0xffff5, &date, 8);
79
80 const char ident[] = "PCI_ISA";
81 memcpy((void *)0xfffd9, &ident, 7);
82
83 /* system model: IBM-AT */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080084 write8((void *)0xffffe, 0xfc);
Stefan Reinauer841af5e2010-05-11 15:39:20 +000085}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000086
Patrick Georgi199b09c2012-11-22 12:46:12 +010087static int (*intXX_handler[256])(void) = { NULL };
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000088
Patrick Georgi199b09c2012-11-22 12:46:12 +010089static int intXX_exception_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000090{
Patrick Georgi199b09c2012-11-22 12:46:12 +010091 /* compatibility shim */
92 struct eregs reg_info = {
93 .eax=X86_EAX,
94 .ecx=X86_ECX,
95 .edx=X86_EDX,
96 .ebx=X86_EBX,
97 .esp=X86_ESP,
98 .ebp=X86_EBP,
99 .esi=X86_ESI,
100 .edi=X86_EDI,
101 .vector=M.x86.intno,
102 .error_code=0, // FIXME: fill in
103 .eip=X86_EIP,
104 .cs=X86_CS,
105 .eflags=X86_EFLAGS
106 };
107 struct eregs *regs = &reg_info;
108
Stefan Reinauer14e22772010-04-27 06:56:47 +0000109 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000110 regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000111 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000112
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700113 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000114}
115
Patrick Georgi199b09c2012-11-22 12:46:12 +0100116static int intXX_unknown_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000117{
Myles Watsonf53eaa32010-09-09 14:42:58 +0000118 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100119 M.x86.intno, X86_EAX);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000120
121 return -1;
122}
123
Libra Lic1436932009-12-23 19:16:47 +0000124/* setup interrupt handlers for mainboard */
Aaron Durbin4d7a4c52013-04-23 10:25:34 -0500125void mainboard_interrupt_handlers(int intXX, int (*intXX_func)(void))
Libra Lic1436932009-12-23 19:16:47 +0000126{
127 intXX_handler[intXX] = intXX_func;
128}
129
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000130static void setup_interrupt_handlers(void)
131{
132 int i;
133
Stefan Reinauer14e22772010-04-27 06:56:47 +0000134 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000135 * but the CPU-generated exceptions ("hardware interrupts")
136 */
137 for (i = 0; i < 0x10; i++)
138 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000139
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000140 /* Mark all other intXX calls as unknown first */
141 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +0000142 {
143 /* If the mainboard_interrupt_handler isn't called first.
144 */
145 if(!intXX_handler[i])
146 {
147 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700148 * needed to initialize the option roms. This is
149 * very slick, as it allows us to implement mainboard
150 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000151 */
152 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000153 case 0x10:
154 intXX_handler[0x10] = &int10_handler;
155 break;
Libra Lic1436932009-12-23 19:16:47 +0000156 case 0x12:
157 intXX_handler[0x12] = &int12_handler;
158 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000159 case 0x16:
160 intXX_handler[0x16] = &int16_handler;
161 break;
Libra Lic1436932009-12-23 19:16:47 +0000162 case 0x1a:
163 intXX_handler[0x1a] = &int1a_handler;
164 break;
165 default:
166 intXX_handler[i] = &intXX_unknown_handler;
167 break;
168 }
169 }
170 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000171}
172
173static void write_idt_stub(void *target, u8 intnum)
174{
175 unsigned char *codeptr;
176 codeptr = (unsigned char *) target;
Aaron Durbina146d582013-02-08 16:56:51 -0600177 memcpy(codeptr, &__idt_handler, __idt_handler_size);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000178 codeptr[3] = intnum; /* modify int# in the code stub. */
179}
180
181static void setup_realmode_idt(void)
182{
183 struct realmode_idt *idts = (struct realmode_idt *) 0;
184 int i;
185
186 /* Copy IDT stub code for each interrupt. This might seem wasteful
187 * but it is really simple
188 */
189 for (i = 0; i < 256; i++) {
190 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
195 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000196 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000197 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000198
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000199 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000200 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000201 /* BIOS Int 11 Handler F000:F84D */
202 write_idt_stub((void *)0xff84d, 0x11);
203 /* BIOS Int 12 Handler F000:F841 */
204 write_idt_stub((void *)0xff841, 0x12);
205 /* BIOS Int 13 Handler F000:EC59 */
206 write_idt_stub((void *)0xfec59, 0x13);
207 /* BIOS Int 14 Handler F000:E739 */
208 write_idt_stub((void *)0xfe739, 0x14);
209 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000210 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000211 /* BIOS Int 16 Handler F000:E82E */
212 write_idt_stub((void *)0xfe82e, 0x16);
213 /* BIOS Int 17 Handler F000:EFD2 */
214 write_idt_stub((void *)0xfefd2, 0x17);
215 /* ROM BIOS Int 1A Handler F000:FE6E */
216 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000217}
218
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700219#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Gabe Blackfb8632a2012-09-30 04:47:48 -0700220vbe_mode_info_t mode_info;
221static int mode_info_valid;
222
223int vbe_mode_info_valid(void)
224{
225 return mode_info_valid;
226}
227
228static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700229{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700230 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700231 mi->video_mode);
Aaron Durbina146d582013-02-08 16:56:51 -0600232 char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700233 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
234 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
235 realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700236 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
Zhuo-Hao Lee29445dc2014-12-24 11:13:34 +0800237 memcpy(mi->mode_info_block, buffer, sizeof(mi->mode_info_block));
Gabe Blackfb8632a2012-09-30 04:47:48 -0700238 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700239 return 0;
240}
241
Gabe Blackfb8632a2012-09-30 04:47:48 -0700242static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700243{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700244 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700245 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700246 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700247 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700248 mi->video_mode &= ~(1 << 15);
249 realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700250 0x0000, 0x0000, 0x0000, 0x0000);
251 return 0;
252}
253
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700254/* These two functions could probably even be generic between
255 * yabel and x86 native. TBD later.
256 */
257void vbe_set_graphics(void)
258{
259 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
260 vbe_get_mode_info(&mode_info);
261 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700262 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700263 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
264 le16_to_cpu(mode_info.vesa.x_resolution),
265 le16_to_cpu(mode_info.vesa.y_resolution),
266 mode_info.vesa.bits_per_pixel);
267 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
268 if (!framebuffer) {
269 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
270 "framebuffer\n");
271 return;
272 }
273
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700274 vbe_set_mode(&mode_info);
275#if CONFIG_BOOTSPLASH
276 struct jpeg_decdata *decdata;
Aaron Durbin899d13d2015-05-15 23:39:23 -0500277 unsigned char *jpeg = cbfs_boot_map_with_leak("bootsplash.jpg",
278 CBFS_TYPE_BOOTSPLASH,
279 NULL);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700280 if (!jpeg) {
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700281 printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700282 return;
283 }
Daniele Forsif9ce88e2014-07-26 11:32:16 +0200284 decdata = malloc(sizeof(*decdata));
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700285 int ret = 0;
286 ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
287#endif
288}
289
290void vbe_textmode_console(void)
291{
292 delay(2);
293 realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
294 0x0000, 0x0000, 0x0000);
295}
296
297void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
298{
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700299 framebuffer->physical_address = mode_info.vesa.phys_base_ptr;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700300
301 framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution);
302 framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution);
303 framebuffer->bytes_per_line =
304 le16_to_cpu(mode_info.vesa.bytes_per_scanline);
305 framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel;
306
307 framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos;
308 framebuffer->red_mask_size = mode_info.vesa.red_mask_size;
309
310 framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos;
311 framebuffer->green_mask_size = mode_info.vesa.green_mask_size;
312
313 framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos;
314 framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size;
315
316 framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos;
317 framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size;
318}
Vladimir Serbinenkod7374512015-10-10 13:50:30 +0200319
320#else
321
322int vbe_mode_info_valid(void)
323{
324 return 0;
325}
326
327void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
328{
329}
330
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700331#endif
332
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000333void run_bios(struct device *dev, unsigned long addr)
334{
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000335 u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn;
336
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700337 /* Setting up required hardware.
338 * Removing this will cause random illegal instruction exceptions
339 * in some option roms.
340 */
341 setup_i8259();
zbao741a0dd2015-06-25 16:58:53 -0400342 setup_i8254();
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700343
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000344 /* Set up some legacy information in the F segment */
345 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000346
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000347 /* Set up C interrupt handlers */
348 setup_interrupt_handlers();
349
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000350 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000351 setup_realmode_idt();
352
Aaron Durbina146d582013-02-08 16:56:51 -0600353 /* Make sure the code is placed. */
354 setup_realmode_code();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000355
356 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000357 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
358 /* Option ROM entry point is at OPROM start + 3 */
359 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000360 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700361
362#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Stefan Reinauer22ae2b92013-02-08 08:48:20 -0800363 if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA)
364 vbe_set_graphics();
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700365#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000366}
367
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000368#if CONFIG_GEODE_VSA
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000369
370#define VSA2_BUFFER 0x60000
371#define VSA2_ENTRY_POINT 0x60020
372
373// TODO move to a header file.
374void do_vsmbios(void);
375
376/* VSA virtual register helper */
377static u32 VSA_vrRead(u16 classIndex)
378{
379 u32 eax, ebx, ecx, edx;
380 asm volatile (
381 "movw $0x0AC1C, %%dx\n"
382 "orl $0x0FC530000, %%eax\n"
383 "outl %%eax, %%dx\n"
384 "addb $2, %%dl\n"
385 "inw %%dx, %%ax\n"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000386 : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000387 : "a"(classIndex)
388 );
389
390 return eax;
391}
392
393void do_vsmbios(void)
394{
395 printk(BIOS_DEBUG, "Preparing for VSA...\n");
396
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000397 /* Set up C interrupt handlers */
398 setup_interrupt_handlers();
399
400 /* Setting up realmode IDT */
401 setup_realmode_idt();
402
Aaron Durbina146d582013-02-08 16:56:51 -0600403 /* Make sure the code is placed. */
404 setup_realmode_code();
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000405
Aaron Durbin899d13d2015-05-15 23:39:23 -0500406 if ((uintptr_t)cbfs_boot_load_stage_by_name("vsa") !=
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800407 VSA2_ENTRY_POINT) {
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000408 printk(BIOS_ERR, "Failed to load VSA.\n");
409 return;
410 }
411
412 unsigned char *buf = (unsigned char *)VSA2_BUFFER;
413 printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]);
414 printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n",
415 buf[0x20], buf[0x21], buf[0x22], buf[0x23]);
416
417 /* Check for code to emit POST code at start of VSA. */
418 if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) ||
419 (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) {
420 printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n");
421 return;
422 }
423
424 printk(BIOS_DEBUG, "Calling VSA module...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000425
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000426 /* ECX gets SMM, EDX gets SYSMEM */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700427 realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM,
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000428 MSR_GLIU0_SYSMEM, 0x0, 0x0);
429
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000430 printk(BIOS_DEBUG, "... VSA module returned.\n");
431
432 /* Restart timer 1 */
433 outb(0x56, 0x43);
434 outb(0x12, 0x41);
435
436 /* Check that VSA is running OK */
437 if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE)
438 printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n");
439 else
440 printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n");
441}
442#endif
443
Stefan Reinauer14e22772010-04-27 06:56:47 +0000444/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000445 * so there is no use in putting the prototype into a header file.
446 */
Stefan Reinauer399486e2012-12-06 13:54:29 -0800447int asmlinkage interrupt_handler(u32 intnumber,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000448 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 Hermann312673c2009-10-27 21:49:33 +0000453 u32 cs_ip, u16 stackflags);
454
Stefan Reinauer399486e2012-12-06 13:54:29 -0800455int asmlinkage interrupt_handler(u32 intnumber,
Uwe Hermann312673c2009-10-27 21:49:33 +0000456 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 Reinauer38cd29e2009-08-11 21:28:25 +0000461 u32 cs_ip, u16 stackflags)
462{
463 u32 ip;
464 u32 cs;
465 u32 flags;
Patrick Georgi503af722012-11-22 10:48:18 +0100466 int ret = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000467
468 ip = cs_ip & 0xffff;
469 cs = cs_ip >> 16;
470 flags = stackflags;
471
Myles Watson6c9bc012010-09-07 22:30:15 +0000472#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000473 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 Watson6c9bc012010-09-07 22:30:15 +0000480#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000481
Patrick Georgi199b09c2012-11-22 12:46:12 +0100482 // 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 Reinauer38cd29e2009-08-11 21:28:25 +0000497
498 // Call the interrupt handler for this int#
Patrick Georgi199b09c2012-11-22 12:46:12 +0100499 ret = intXX_handler[intnumber]();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000500
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 Reinauer14e22772010-04-27 06:56:47 +0000505 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000506 // we leave this function. Don't say this is bollocks.
Patrick Georgi199b09c2012-11-22 12:46:12 +0100507 *(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 Reinauer38cd29e2009-08-11 21:28:25 +0000514
Patrick Georgi503af722012-11-22 10:48:18 +0100515 /* Pass success or error back to our caller via the CARRY flag */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000516 if (ret) {
Patrick Georgi503af722012-11-22 10:48:18 +0100517 flags &= ~1; // no error: clear carry
518 }else{
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000519 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000520 flags |= 1; // error: set carry
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000521 }
522 *(volatile u16 *)&stackflags = flags;
523
Patrick Georgi503af722012-11-22 10:48:18 +0100524 /* The assembler code doesn't actually care for the return value,
525 * but keep it around so its expectations are met */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000526 return ret;
527}