2 * This file is part of the coreboot project.
4 * Copyright (C) .... others
5 * Copyright (C) 2008-2009 coresystems GmbH
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.
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.
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
21 /* 2006.1 yhlu add mptable cross 0x467 processing */
23 #include <console/console.h>
25 #include <boot/tables.h>
26 #include <boot/coreboot_tables.h>
27 #include <arch/pirq_routing.h>
28 #include <arch/smp/mpspec.h>
29 #include <arch/acpi.h>
31 #include <cpu/x86/multiboot.h>
32 #include "coreboot_table.h"
34 // Global Descriptor Table, defined in c_start.S
36 extern uint8_t gdt_end;
38 /* i386 lgdt argument */
42 } __attribute__((packed));
44 // Copy GDT to new location and reload it
45 // 2003-07 by SONE Takeshi
46 // Ported from Etherboot to coreboot 2005-08 by Steve Magnani
47 void move_gdt(unsigned long newgdt)
49 uint16_t num_gdt_bytes = &gdt_end - &gdt;
52 printk_debug("Moving GDT to %#lx...", newgdt);
53 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
55 gdtarg.limit = num_gdt_bytes - 1;
56 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
60 #if HAVE_HIGH_TABLES == 1
61 uint64_t high_tables_base = 0;
62 uint64_t high_tables_size;
65 struct lb_memory *write_tables(void)
67 unsigned long low_table_start, low_table_end;
68 unsigned long rom_table_start, rom_table_end;
69 #if HAVE_MP_TABLE == 1
70 unsigned long new_low_table_end;
73 #if HAVE_HIGH_TABLES == 1
74 /* Even if high tables are configured, all tables are copied both to the
75 * low and the high area, so payloads and OSes don't need to know about
78 unsigned long high_table_start=0, high_table_end=0;
80 if (high_tables_base) {
81 printk_debug("High Tables Base is %llx.\n", high_tables_base);
82 high_table_start = high_tables_base;
83 high_table_end = high_tables_base;
85 printk_debug("High Tables Base is not set.\n");
89 rom_table_start = 0xf0000;
90 rom_table_end = 0xf0000;
91 /* Start low addr at 16 bytes instead of 0 because of a buglet
92 * in the generic linux unzip code, as it tests for the a20 line.
99 #if HAVE_LOW_TABLES == 1
100 /* This table must be betweeen 0xf0000 & 0x100000 */
101 rom_table_end = write_pirq_routing_table(rom_table_end);
102 rom_table_end = (rom_table_end + 1023) & ~1023;
104 #if HAVE_HIGH_TABLES == 1
105 if (high_tables_base) {
106 high_table_end = write_pirq_routing_table(high_table_end);
107 high_table_end = (high_table_end + 1023) & ~1023;
111 /* Write ACPI tables */
112 /* write them in the rom area because DSDT can be large (8K on epia-m) which
113 * pushes coreboot table out of first 4K if set up in low table area
115 #if HAVE_LOW_TABLES == 1
116 rom_table_end = write_acpi_tables(rom_table_end);
117 rom_table_end = (rom_table_end+1023) & ~1023;
119 #if HAVE_HIGH_TABLES == 1
120 if (high_tables_base) {
121 high_table_end = write_acpi_tables(high_table_end);
122 high_table_end = (high_table_end+1023) & ~1023;
125 /* copy the smp block to address 0 */
128 #if HAVE_MP_TABLE == 1
130 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
131 #if HAVE_LOW_TABLES == 1
132 new_low_table_end = write_smp_table(low_table_end); // low_table_end is 0x10 at this point
134 #if HAVE_HIGH_TABLES == 1
135 if (high_tables_base) {
136 high_table_end = write_smp_table(high_table_end);
137 high_table_end = (high_table_end+1023) & ~1023;
141 /* Don't write anything in the traditional x86 BIOS data segment,
142 * for example the linux kernel smp need to use 0x467 to pass reset vector
143 * or use 0x40e/0x413 for EBDA finding...
145 if(new_low_table_end>0x400){
146 unsigned mptable_size;
148 low_table_end += SMP_FLOATING_TABLE_LEN; /* keep the mpf in 1k low, so kernel can find it */
149 mptable_size = new_low_table_end - low_table_end;
150 /* We can not put mptable low, we need to copy them to somewhere else*/
151 if((rom_table_end+mptable_size)<0x100000) {
152 /* We can copy mptable on rom_table */
153 mpc_start = rom_table_end;
154 rom_table_end += mptable_size;
155 rom_table_end = (rom_table_end+1023) & ~1023;
157 /* We can need to put mptable before rom_table */
158 mpc_start = rom_table_start - mptable_size;
160 rom_table_start = mpc_start;
162 printk_debug("move mptable from 0x%0lx to 0x%0x, size 0x%0x\n", low_table_end, mpc_start, mptable_size);
163 memcpy((unsigned char *)mpc_start, (unsigned char *)low_table_end, mptable_size);
164 smp_write_floating_table_physaddr(low_table_end - SMP_FLOATING_TABLE_LEN, mpc_start);
165 memset((unsigned char *)low_table_end, '\0', mptable_size);
167 #endif /* HAVE_MP_TABLE */
169 if (low_table_end < 0x500) {
170 low_table_end = 0x500;
173 // Relocate the GDT to reserved memory, so it won't get clobbered
174 #if HAVE_HIGH_TABLES == 1
175 if (high_tables_base) {
176 move_gdt(high_table_end);
177 high_table_end += &gdt_end - &gdt;
178 high_table_end = (high_table_end+1023) & ~1023;
181 move_gdt(low_table_end);
182 low_table_end += &gdt_end - &gdt;
183 #if HAVE_HIGH_TABLES == 1
188 /* The Multiboot information structure */
189 mbi = (struct multiboot_info *)rom_table_end;
190 rom_table_end = write_multiboot_info(
191 low_table_start, low_table_end,
192 rom_table_start, rom_table_end);
195 #if HAVE_HIGH_TABLES == 1
196 if (high_tables_base) {
197 write_coreboot_table(low_table_start, low_table_end,
198 high_table_start, high_table_end);
200 printk_err("ERROR: No high_tables_base.\n");
201 write_coreboot_table(low_table_start, low_table_end,
202 rom_table_start, rom_table_end);
205 /* The coreboot table must be in 0-4K or 960K-1M */
206 write_coreboot_table(low_table_start, low_table_end,
207 rom_table_start, rom_table_end);