blob: 72f23449114d3a0e179a00d7f7d8544743de0d73 [file] [log] [blame]
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) .... others
5 * Copyright (C) 2008-2009 coresystems GmbH
6 *
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000020
21/* 2006.1 yhlu add mptable cross 0x467 processing */
22
Eric Biederman8ca8d762003-04-22 19:02:15 +000023#include <console/console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000024#include <cpu/cpu.h>
25#include <boot/tables.h>
Stefan Reinauerca374d42008-01-18 16:16:45 +000026#include <boot/coreboot_tables.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000027#include <arch/pirq_routing.h>
28#include <arch/smp/mpspec.h>
Stefan Reinauer688b3852004-01-28 16:56:14 +000029#include <arch/acpi.h>
Stefan Reinauer0dff6e32007-10-23 22:17:45 +000030#include <string.h>
Robert Millan81af3d42008-11-11 20:20:54 +000031#include <cpu/x86/multiboot.h>
Stefan Reinauerca374d42008-01-18 16:16:45 +000032#include "coreboot_table.h"
Eric Biederman8ca8d762003-04-22 19:02:15 +000033
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000034// Global Descriptor Table, defined in c_start.S
35extern uint8_t gdt;
36extern uint8_t gdt_end;
37
38/* i386 lgdt argument */
39struct gdtarg {
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000040 unsigned short limit;
41 unsigned int base;
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000042} __attribute__((packed));
43
44// Copy GDT to new location and reload it
45// 2003-07 by SONE Takeshi
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000046// Ported from Etherboot to coreboot 2005-08 by Steve Magnani
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000047void move_gdt(unsigned long newgdt)
48{
49 uint16_t num_gdt_bytes = &gdt_end - &gdt;
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000050 struct gdtarg gdtarg;
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000051
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000052 printk_debug("Moving GDT to %#lx...", newgdt);
53 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
54 gdtarg.base = newgdt;
55 gdtarg.limit = num_gdt_bytes - 1;
56 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
57 printk_debug("ok\n");
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000058}
59
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000060#if HAVE_HIGH_TABLES == 1
61uint64_t high_tables_base = 0;
62uint64_t high_tables_size;
63#endif
64
Eric Biedermanb78c1972004-10-14 20:54:17 +000065struct lb_memory *write_tables(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +000066{
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000067 unsigned long low_table_start, low_table_end, new_low_table_end;
Eric Biederman8ca8d762003-04-22 19:02:15 +000068 unsigned long rom_table_start, rom_table_end;
69
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000070#if HAVE_HIGH_TABLES == 1
71 /* Even if high tables are configured, all tables are copied both to the
72 * low and the high area, so payloads and OSes don't need to know about
73 * the high tables.
74 */
75 unsigned long high_table_start, high_table_end=0;
76
77 if (high_tables_base) {
Stefan Reinauerefab4ba2009-03-17 14:38:48 +000078 printk_debug("High Tables Base is %llx.\n", high_tables_base);
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000079 high_table_start = high_tables_base;
80 high_table_end = high_tables_base;
81 } else {
82 printk_debug("High Tables Base is not set.\n");
83 }
84#endif
85
Yinghai Lu47cb7c72007-04-06 20:27:40 +000086 rom_table_start = 0xf0000;
Eric Biederman8ca8d762003-04-22 19:02:15 +000087 rom_table_end = 0xf0000;
88 /* Start low addr at 16 bytes instead of 0 because of a buglet
89 * in the generic linux unzip code, as it tests for the a20 line.
90 */
91 low_table_start = 0;
92 low_table_end = 16;
93
94 post_code(0x9a);
Li-Ta Lo8e79fc32004-04-15 17:33:21 +000095
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000096#if HAVE_LOW_TABLES == 1
Eric Biederman8ca8d762003-04-22 19:02:15 +000097 /* This table must be betweeen 0xf0000 & 0x100000 */
Jason Schildt043b4092005-08-10 15:16:44 +000098 rom_table_end = write_pirq_routing_table(rom_table_end);
Eric Biederman8ca8d762003-04-22 19:02:15 +000099 rom_table_end = (rom_table_end + 1023) & ~1023;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000100#endif
101#if HAVE_HIGH_TABLES == 1
102 if (high_tables_base) {
103 high_table_end = write_pirq_routing_table(high_table_end);
104 high_table_end = (high_table_end + 1023) & ~1023;
105 }
106#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +0000107
Stefan Reinauera7648c22004-01-29 17:31:34 +0000108 /* Write ACPI tables */
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000109 /* write them in the rom area because DSDT can be large (8K on epia-m) which
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000110 * pushes coreboot table out of first 4K if set up in low table area
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000111 */
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000112#if HAVE_LOW_TABLES == 1
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000113 rom_table_end = write_acpi_tables(rom_table_end);
114 rom_table_end = (rom_table_end+1023) & ~1023;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000115#endif
116#if HAVE_HIGH_TABLES == 1
117 if (high_tables_base) {
118 high_table_end = write_acpi_tables(high_table_end);
119 high_table_end = (high_table_end+1023) & ~1023;
120 }
121#endif
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000122 /* copy the smp block to address 0 */
123 post_code(0x96);
124
Myles Watson47e42e52009-03-12 17:42:20 +0000125#if HAVE_MP_TABLE == 1
126
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000127 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000128#if HAVE_LOW_TABLES == 1
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000129 new_low_table_end = write_smp_table(low_table_end); // low_table_end is 0x10 at this point
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000130#endif
131#if HAVE_HIGH_TABLES == 1
132 if (high_tables_base) {
133 high_table_end = write_smp_table(high_table_end);
134 high_table_end = (high_table_end+1023) & ~1023;
135 }
136#endif
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000137
138 /* Don't write anything in the traditional x86 BIOS data segment,
139 * for example the linux kernel smp need to use 0x467 to pass reset vector
Roman Kononov96e30222008-07-23 23:22:59 +0000140 * or use 0x40e/0x413 for EBDA finding...
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000141 */
Roman Kononov96e30222008-07-23 23:22:59 +0000142 if(new_low_table_end>0x400){
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000143 unsigned mptable_size;
144 unsigned mpc_start;
145 low_table_end += SMP_FLOATING_TABLE_LEN; /* keep the mpf in 1k low, so kernel can find it */
146 mptable_size = new_low_table_end - low_table_end;
147 /* We can not put mptable low, we need to copy them to somewhere else*/
148 if((rom_table_end+mptable_size)<0x100000) {
149 /* We can copy mptable on rom_table */
150 mpc_start = rom_table_end;
151 rom_table_end += mptable_size;
152 rom_table_end = (rom_table_end+1023) & ~1023;
153 } else {
154 /* We can need to put mptable before rom_table */
155 mpc_start = rom_table_start - mptable_size;
156 mpc_start &= ~1023;
157 rom_table_start = mpc_start;
158 }
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000159 printk_debug("move mptable from 0x%0lx to 0x%0x, size 0x%0x\n", low_table_end, mpc_start, mptable_size);
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000160 memcpy((unsigned char *)mpc_start, (unsigned char *)low_table_end, mptable_size);
161 smp_write_floating_table_physaddr(low_table_end - SMP_FLOATING_TABLE_LEN, mpc_start);
162 memset((unsigned char *)low_table_end, '\0', mptable_size);
163 }
Myles Watson47e42e52009-03-12 17:42:20 +0000164#endif /* HAVE_MP_TABLE */
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000165
Eric Biederman8ca8d762003-04-22 19:02:15 +0000166 if (low_table_end < 0x500) {
167 low_table_end = 0x500;
168 }
Stefan Reinauer688b3852004-01-28 16:56:14 +0000169
Steven J. Magnanid94e1d62005-09-12 18:41:30 +0000170 // Relocate the GDT to reserved memory, so it won't get clobbered
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000171#if HAVE_HIGH_TABLES == 1
172 if (high_tables_base) {
173 move_gdt(high_table_end);
174 high_table_end += &gdt_end - &gdt;
175 high_table_end = (high_table_end+1023) & ~1023;
176 } else {
177#endif
178 move_gdt(low_table_end);
179 low_table_end += &gdt_end - &gdt;
180#if HAVE_HIGH_TABLES == 1
181 }
182#endif
Steven J. Magnanid94e1d62005-09-12 18:41:30 +0000183
Robert Millan81af3d42008-11-11 20:20:54 +0000184#if CONFIG_MULTIBOOT
185 /* The Multiboot information structure */
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000186 mbi = (struct multiboot_info *)rom_table_end;
Robert Millan81af3d42008-11-11 20:20:54 +0000187 rom_table_end = write_multiboot_info(
188 low_table_start, low_table_end,
189 rom_table_start, rom_table_end);
190#endif
191
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000192#if HAVE_HIGH_TABLES == 1
193 if (high_tables_base) {
194 write_coreboot_table(low_table_start, low_table_end,
195 high_table_start, high_table_end);
196 } else {
197 printk_err("ERROR: No high_tables_base.\n");
198 write_coreboot_table(low_table_start, low_table_end,
199 rom_table_start, rom_table_end);
200 }
201#else
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000202 /* The coreboot table must be in 0-4K or 960K-1M */
203 write_coreboot_table(low_table_start, low_table_end,
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000204 rom_table_start, rom_table_end);
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +0000205#endif
206
Eric Biederman8ca8d762003-04-22 19:02:15 +0000207 return get_lb_mem();
208}