2 * This file is part of the coreboot project.
4 * Copyright (C) 2003 Eric Biederman
5 * Copyright (C) 2005 Steve Magnani
6 * Copyright (C) 2008-2009 coresystems GmbH
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 /* 2006.1 yhlu add mptable cross 0x467 processing */
24 #include <console/console.h>
26 #include <boot/tables.h>
27 #include <boot/coreboot_tables.h>
28 #include <arch/pirq_routing.h>
29 #include <arch/smp/mpspec.h>
30 #include <arch/acpi.h>
32 #include <cpu/x86/multiboot.h>
33 #include "coreboot_table.h"
35 // Global Descriptor Table, defined in c_start.S
37 extern uint8_t gdt_end;
39 /* i386 lgdt argument */
43 } __attribute__((packed));
45 // Copy GDT to new location and reload it
46 void move_gdt(unsigned long newgdt)
48 uint16_t num_gdt_bytes = &gdt_end - &gdt;
51 printk_debug("Moving GDT to %#lx...", newgdt);
52 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
54 gdtarg.limit = num_gdt_bytes - 1;
55 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
59 uint64_t high_tables_base = 0;
60 uint64_t high_tables_size;
62 struct lb_memory *write_tables(void)
64 unsigned long low_table_start, low_table_end;
65 unsigned long rom_table_start, rom_table_end;
67 /* Even if high tables are configured, some tables are copied both to
68 * the low and the high area, so payloads and OSes don't need to know
69 * about the high tables.
71 unsigned long high_table_end=0;
73 if (high_tables_base) {
74 printk_debug("High Tables Base is %llx.\n", high_tables_base);
75 high_table_end = high_tables_base;
77 printk_err("ERROR: High Tables Base is not set.\n");
80 rom_table_start = 0xf0000;
81 rom_table_end = 0xf0000;
83 /* Start low addr at 0x500, so we don't run into conflicts with the BDA
84 * in case our data structures grow beyound 0x400. Only multiboot, GDT
85 * and the coreboot table use low_tables.
88 low_table_end = 0x500;
92 /* This table must be between 0x0f0000 and 0x100000 */
93 rom_table_end = write_pirq_routing_table(rom_table_end);
94 rom_table_end = ALIGN(rom_table_end, 1024);
96 /* And add a high table version for those payloads that
97 * want to live in the F segment
99 if (high_tables_base) {
100 high_table_end = write_pirq_routing_table(high_table_end);
101 high_table_end = ALIGN(high_table_end, 1024);
106 /* Write ACPI tables to F segment and high tables area */
107 #if CONFIG_HAVE_ACPI_TABLES == 1
108 if (high_tables_base) {
109 unsigned long acpi_start = high_table_end;
110 rom_table_end = ALIGN(rom_table_end, 16);
111 high_table_end = write_acpi_tables(high_table_end);
112 while (acpi_start < high_table_end) {
113 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) {
118 if (acpi_start != high_table_end) {
119 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
120 *high_rsdp = (acpi_rsdp_t *)acpi_start;
122 acpi_write_rsdp(low_rsdp,
123 (acpi_rsdt_t *)(high_rsdp->rsdt_address),
124 (acpi_xsdt_t *)(high_rsdp->xsdt_address));
126 printk_err("ERROR: Didn't find RSDP in high table.\n");
128 high_table_end = ALIGN(high_table_end, 1024);
129 rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16);
131 rom_table_end = write_acpi_tables(rom_table_end);
132 rom_table_end = ALIGN(rom_table_end, 1024);
137 #if CONFIG_HAVE_MP_TABLE == 1
138 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
139 rom_table_end = write_smp_table(rom_table_end);
140 rom_table_end = ALIGN(rom_table_end, 1024);
142 /* ... and a copy in the high tables */
143 if (high_tables_base) {
144 high_table_end = write_smp_table(high_table_end);
145 high_table_end = ALIGN(high_table_end, 1024);
147 #endif /* CONFIG_HAVE_MP_TABLE */
151 // Relocate the GDT to reserved memory, so it won't get clobbered
152 if (high_tables_base) {
153 move_gdt(high_table_end);
154 high_table_end += &gdt_end - &gdt;
155 high_table_end = ALIGN(high_table_end, 1024);
157 move_gdt(low_table_end);
158 low_table_end += &gdt_end - &gdt;
164 /* The Multiboot information structure */
165 rom_table_end = write_multiboot_info(
166 low_table_start, low_table_end,
167 rom_table_start, rom_table_end);
172 if (high_tables_base) {
173 /* Also put a forwarder entry into 0-4K */
174 write_coreboot_table(low_table_start, low_table_end,
175 high_tables_base, high_table_end);
176 if (high_table_end > high_tables_base + high_tables_size)
177 printk_err("%s: High tables didn't fit in %llx (%llx)\n",
178 __func__, high_tables_size, high_table_end -
181 /* The coreboot table must be in 0-4K or 960K-1M */
182 write_coreboot_table(low_table_start, low_table_end,
183 rom_table_start, rom_table_end);