tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / arch / x86 / tables.c
blobd8d558ddd6a98f9b6a5d64a029bec805da701442
1 /*
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.
18 #include <console/console.h>
19 #include <cpu/cpu.h>
20 #include <boot/tables.h>
21 #include <boot/coreboot_tables.h>
22 #include <arch/pirq_routing.h>
23 #include <arch/smp/mpspec.h>
24 #include <arch/acpi.h>
25 #include <string.h>
26 #include <cbmem.h>
27 #include <smbios.h>
29 void write_tables(void)
31 unsigned long low_table_start, low_table_end;
32 unsigned long rom_table_start, rom_table_end;
34 /* Even if high tables are configured, some tables are copied both to
35 * the low and the high area, so payloads and OSes don't need to know
36 * about the high tables.
38 unsigned long high_table_pointer;
40 rom_table_start = 0xf0000;
41 rom_table_end = 0xf0000;
43 /* Start low addr at 0x500, so we don't run into conflicts with the BDA
44 * in case our data structures grow beyond 0x400. Only GDT
45 * and the coreboot table use low_tables.
47 low_table_start = 0;
48 low_table_end = 0x500;
50 #if CONFIG_GENERATE_PIRQ_TABLE
51 #define MAX_PIRQ_TABLE_SIZE (4 * 1024)
52 post_code(0x9a);
54 /* This table must be between 0x0f0000 and 0x100000 */
55 rom_table_end = write_pirq_routing_table(rom_table_end);
56 rom_table_end = ALIGN(rom_table_end, 1024);
58 /* And add a high table version for those payloads that
59 * want to live in the F segment
61 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, MAX_PIRQ_TABLE_SIZE);
62 if (high_table_pointer) {
63 unsigned long new_high_table_pointer;
64 new_high_table_pointer = write_pirq_routing_table(high_table_pointer);
65 // FIXME make pirq table code intelligent enough to know how
66 // much space it's going to need.
67 if (new_high_table_pointer > (high_table_pointer + MAX_PIRQ_TABLE_SIZE)) {
68 printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n");
70 printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n",
71 new_high_table_pointer - high_table_pointer);
74 #endif
76 #if CONFIG_GENERATE_MP_TABLE
77 #define MAX_MP_TABLE_SIZE (4 * 1024)
78 post_code(0x9b);
80 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
81 rom_table_end = write_smp_table(rom_table_end);
82 rom_table_end = ALIGN(rom_table_end, 1024);
84 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, MAX_MP_TABLE_SIZE);
85 if (high_table_pointer) {
86 unsigned long new_high_table_pointer;
87 new_high_table_pointer = write_smp_table(high_table_pointer);
88 // FIXME make mp table code intelligent enough to know how
89 // much space it's going to need.
90 if (new_high_table_pointer > (high_table_pointer + MAX_MP_TABLE_SIZE)) {
91 printk(BIOS_ERR, "ERROR: Increase MP table size.\n");
94 printk(BIOS_DEBUG, "MP table: %ld bytes.\n",
95 new_high_table_pointer - high_table_pointer);
97 #endif /* CONFIG_GENERATE_MP_TABLE */
99 #if CONFIG_HAVE_ACPI_TABLES
100 #define MAX_ACPI_SIZE (144 * 1024)
102 post_code(0x9c);
104 /* Write ACPI tables to F segment and high tables area */
106 /* Ok, this is a bit hacky still, because some day we want to have this
107 * completely dynamic. But right now we are setting fixed sizes.
108 * It's probably still better than the old high_table_base code because
109 * now at least we know when we have an overflow in the area.
111 * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and
112 * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the
113 * coreboot table. This leaves us with 47KB for all of ACPI. Let's see
114 * how far we get.
116 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, MAX_ACPI_SIZE);
117 if (high_table_pointer) {
118 unsigned long acpi_start = high_table_pointer;
119 unsigned long new_high_table_pointer;
121 rom_table_end = ALIGN(rom_table_end, 16);
122 new_high_table_pointer = write_acpi_tables(high_table_pointer);
123 if (new_high_table_pointer > ( high_table_pointer + MAX_ACPI_SIZE)) {
124 printk(BIOS_ERR, "ERROR: Increase ACPI size\n");
126 printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n",
127 new_high_table_pointer - high_table_pointer);
129 /* Now we need to create a low table copy of the RSDP. */
131 /* First we look for the high table RSDP */
132 while (acpi_start < new_high_table_pointer) {
133 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) {
134 break;
136 acpi_start++;
139 /* Now, if we found the RSDP, we take the RSDT and XSDT pointer
140 * from it in order to write the low RSDP
142 if (acpi_start < new_high_table_pointer) {
143 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
144 *high_rsdp = (acpi_rsdp_t *)acpi_start;
146 /* Technically rsdp length varies but coreboot always
147 writes longest size available. */
148 memcpy(low_rsdp, high_rsdp, sizeof(acpi_rsdp_t));
149 } else {
150 printk(BIOS_ERR, "ERROR: Didn't find RSDP in high table.\n");
152 rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16);
153 } else {
154 rom_table_end = write_acpi_tables(rom_table_end);
155 rom_table_end = ALIGN(rom_table_end, 1024);
158 #endif
159 #define MAX_SMBIOS_SIZE 2048
160 #if CONFIG_GENERATE_SMBIOS_TABLES
161 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, MAX_SMBIOS_SIZE);
162 if (high_table_pointer) {
163 unsigned long new_high_table_pointer;
165 new_high_table_pointer = smbios_write_tables(high_table_pointer);
166 rom_table_end = ALIGN(rom_table_end, 16);
167 memcpy((void *)rom_table_end, (void *)high_table_pointer, sizeof(struct smbios_entry));
168 rom_table_end += sizeof(struct smbios_entry);
170 if (new_high_table_pointer > ( high_table_pointer + MAX_SMBIOS_SIZE)) {
171 printk(BIOS_ERR, "ERROR: Increase SMBIOS size\n");
173 printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n",
174 new_high_table_pointer - high_table_pointer);
175 } else {
176 unsigned long new_rom_table_end = smbios_write_tables(rom_table_end);
177 printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end - rom_table_end);
178 rom_table_end = ALIGN(new_rom_table_end, 16);
180 #endif
182 post_code(0x9e);
184 #define MAX_COREBOOT_TABLE_SIZE (32 * 1024)
185 post_code(0x9d);
187 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_CBTABLE, MAX_COREBOOT_TABLE_SIZE);
189 if (high_table_pointer) {
190 unsigned long new_high_table_pointer;
192 /* FIXME: The high_table_base parameter is not reference when tables are high,
193 * or high_table_pointer >1 MB.
195 u64 fixme_high_tables_base = 0;
197 /* Also put a forwarder entry into 0-4K */
198 new_high_table_pointer = write_coreboot_table(low_table_start, low_table_end,
199 fixme_high_tables_base, high_table_pointer);
201 if (new_high_table_pointer > (high_table_pointer +
202 MAX_COREBOOT_TABLE_SIZE))
203 printk(BIOS_ERR, "%s: coreboot table didn't fit (%lx)\n",
204 __func__, new_high_table_pointer -
205 high_table_pointer);
207 printk(BIOS_DEBUG, "coreboot table: %ld bytes.\n",
208 new_high_table_pointer - high_table_pointer);
209 } else {
210 /* The coreboot table must be in 0-4K or 960K-1M */
211 write_coreboot_table(low_table_start, low_table_end,
212 rom_table_start, rom_table_end);
215 /* Print CBMEM sections */
216 cbmem_list();