Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003 Eric Biederman |
| 5 | * Copyright (C) 2005 Steve Magnani |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008-2009 coresystems GmbH |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 20 | */ |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 21 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 22 | #include <console/console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 23 | #include <cpu/cpu.h> |
| 24 | #include <boot/tables.h> |
Stefan Reinauer | ca374d4 | 2008-01-18 16:16:45 +0000 | [diff] [blame] | 25 | #include <boot/coreboot_tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | #include <arch/pirq_routing.h> |
| 27 | #include <arch/smp/mpspec.h> |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 28 | #include <arch/acpi.h> |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 29 | #include <string.h> |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 30 | #include <cbmem.h> |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 31 | #include <lib.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 32 | #include <smbios.h> |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 33 | |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 34 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 35 | void cbmem_arch_init(void) |
| 36 | { |
| 37 | /* defined in gdt.c */ |
| 38 | move_gdt(); |
| 39 | } |
| 40 | |
Aaron Durbin | 3f7ad7b | 2014-02-18 19:36:05 -0600 | [diff] [blame] | 41 | void write_tables(void) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 42 | { |
Stefan Reinauer | df77f34 | 2009-04-06 14:00:53 +0000 | [diff] [blame] | 43 | unsigned long low_table_start, low_table_end; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 44 | unsigned long rom_table_start, rom_table_end; |
| 45 | |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 46 | /* Even if high tables are configured, some tables are copied both to |
| 47 | * the low and the high area, so payloads and OSes don't need to know |
| 48 | * about the high tables. |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 49 | */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 50 | unsigned long high_table_pointer; |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 51 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 52 | rom_table_start = 0xf0000; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 53 | rom_table_end = 0xf0000; |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 54 | |
| 55 | /* Start low addr at 0x500, so we don't run into conflicts with the BDA |
Vladimir Serbinenko | 2657e84 | 2014-01-06 20:40:27 +0100 | [diff] [blame] | 56 | * in case our data structures grow beyond 0x400. Only GDT |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 57 | * and the coreboot table use low_tables. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 58 | */ |
| 59 | low_table_start = 0; |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 60 | low_table_end = 0x500; |
| 61 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 62 | #if CONFIG_GENERATE_PIRQ_TABLE |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 63 | #define MAX_PIRQ_TABLE_SIZE (4 * 1024) |
| 64 | post_code(0x9a); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 65 | |
| 66 | /* This table must be between 0x0f0000 and 0x100000 */ |
| 67 | rom_table_end = write_pirq_routing_table(rom_table_end); |
| 68 | rom_table_end = ALIGN(rom_table_end, 1024); |
| 69 | |
| 70 | /* And add a high table version for those payloads that |
| 71 | * want to live in the F segment |
| 72 | */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 73 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, MAX_PIRQ_TABLE_SIZE); |
| 74 | if (high_table_pointer) { |
| 75 | unsigned long new_high_table_pointer; |
| 76 | new_high_table_pointer = write_pirq_routing_table(high_table_pointer); |
| 77 | // FIXME make pirq table code intelligent enough to know how |
| 78 | // much space it's going to need. |
| 79 | if (new_high_table_pointer > (high_table_pointer + MAX_PIRQ_TABLE_SIZE)) { |
| 80 | printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n"); |
| 81 | } |
| 82 | printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n", |
| 83 | new_high_table_pointer - high_table_pointer); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 84 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 85 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 88 | #if CONFIG_GENERATE_MP_TABLE |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 89 | #define MAX_MP_TABLE_SIZE (4 * 1024) |
| 90 | post_code(0x9b); |
| 91 | |
| 92 | /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */ |
| 93 | rom_table_end = write_smp_table(rom_table_end); |
| 94 | rom_table_end = ALIGN(rom_table_end, 1024); |
| 95 | |
| 96 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, MAX_MP_TABLE_SIZE); |
| 97 | if (high_table_pointer) { |
| 98 | unsigned long new_high_table_pointer; |
| 99 | new_high_table_pointer = write_smp_table(high_table_pointer); |
| 100 | // FIXME make mp table code intelligent enough to know how |
| 101 | // much space it's going to need. |
| 102 | if (new_high_table_pointer > (high_table_pointer + MAX_MP_TABLE_SIZE)) { |
| 103 | printk(BIOS_ERR, "ERROR: Increase MP table size.\n"); |
| 104 | } |
| 105 | |
| 106 | printk(BIOS_DEBUG, "MP table: %ld bytes.\n", |
| 107 | new_high_table_pointer - high_table_pointer); |
| 108 | } |
| 109 | #endif /* CONFIG_GENERATE_MP_TABLE */ |
| 110 | |
Vladimir Serbinenko | 822bc65 | 2014-01-03 15:55:40 +0100 | [diff] [blame^] | 111 | #if CONFIG_HAVE_ACPI_TABLES |
Stefan Reinauer | 802c910 | 2014-08-28 23:03:15 +0200 | [diff] [blame] | 112 | #if CONFIG_DYNAMIC_CBMEM |
| 113 | #define MAX_ACPI_SIZE (144 * 1024) |
| 114 | #else |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 115 | #define MAX_ACPI_SIZE (45 * 1024) |
Stefan Reinauer | 802c910 | 2014-08-28 23:03:15 +0200 | [diff] [blame] | 116 | #endif |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 117 | post_code(0x9c); |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame] | 118 | |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 119 | /* Write ACPI tables to F segment and high tables area */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 120 | |
| 121 | /* Ok, this is a bit hacky still, because some day we want to have this |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 122 | * completely dynamic. But right now we are setting fixed sizes. |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 123 | * It's probably still better than the old high_table_base code because |
| 124 | * now at least we know when we have an overflow in the area. |
| 125 | * |
| 126 | * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and |
| 127 | * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the |
| 128 | * coreboot table. This leaves us with 47KB for all of ACPI. Let's see |
| 129 | * how far we get. |
| 130 | */ |
| 131 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, MAX_ACPI_SIZE); |
| 132 | if (high_table_pointer) { |
| 133 | unsigned long acpi_start = high_table_pointer; |
| 134 | unsigned long new_high_table_pointer; |
| 135 | |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 136 | rom_table_end = ALIGN(rom_table_end, 16); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 137 | new_high_table_pointer = write_acpi_tables(high_table_pointer); |
| 138 | if (new_high_table_pointer > ( high_table_pointer + MAX_ACPI_SIZE)) { |
| 139 | printk(BIOS_ERR, "ERROR: Increase ACPI size\n"); |
| 140 | } |
| 141 | printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n", |
| 142 | new_high_table_pointer - high_table_pointer); |
| 143 | |
| 144 | /* Now we need to create a low table copy of the RSDP. */ |
| 145 | |
| 146 | /* First we look for the high table RSDP */ |
| 147 | while (acpi_start < new_high_table_pointer) { |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 148 | if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) { |
| 149 | break; |
| 150 | } |
| 151 | acpi_start++; |
| 152 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 153 | |
| 154 | /* Now, if we found the RSDP, we take the RSDT and XSDT pointer |
| 155 | * from it in order to write the low RSDP |
| 156 | */ |
| 157 | if (acpi_start < new_high_table_pointer) { |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 158 | acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end, |
| 159 | *high_rsdp = (acpi_rsdp_t *)acpi_start; |
| 160 | |
| 161 | acpi_write_rsdp(low_rsdp, |
| 162 | (acpi_rsdt_t *)(high_rsdp->rsdt_address), |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 163 | (acpi_xsdt_t *)((unsigned long)high_rsdp->xsdt_address)); |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 164 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 165 | printk(BIOS_ERR, "ERROR: Didn't find RSDP in high table.\n"); |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 166 | } |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 167 | rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 168 | } else { |
| 169 | rom_table_end = write_acpi_tables(rom_table_end); |
| 170 | rom_table_end = ALIGN(rom_table_end, 1024); |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 171 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 172 | |
Patrick Georgi | 8f047de | 2009-05-13 14:39:59 +0000 | [diff] [blame] | 173 | #endif |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 174 | #define MAX_SMBIOS_SIZE 2048 |
| 175 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 176 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, MAX_SMBIOS_SIZE); |
| 177 | if (high_table_pointer) { |
| 178 | unsigned long new_high_table_pointer; |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 179 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 180 | new_high_table_pointer = smbios_write_tables(high_table_pointer); |
| 181 | rom_table_end = ALIGN(rom_table_end, 16); |
| 182 | memcpy((void *)rom_table_end, (void *)high_table_pointer, sizeof(struct smbios_entry)); |
| 183 | rom_table_end += sizeof(struct smbios_entry); |
| 184 | |
| 185 | if (new_high_table_pointer > ( high_table_pointer + MAX_SMBIOS_SIZE)) { |
| 186 | printk(BIOS_ERR, "ERROR: Increase SMBIOS size\n"); |
| 187 | } |
| 188 | printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n", |
| 189 | new_high_table_pointer - high_table_pointer); |
| 190 | } else { |
| 191 | unsigned long new_rom_table_end = smbios_write_tables(rom_table_end); |
| 192 | printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end - rom_table_end); |
| 193 | rom_table_end = ALIGN(new_rom_table_end, 16); |
| 194 | } |
| 195 | #endif |
Robert Millan | 81af3d4 | 2008-11-11 20:20:54 +0000 | [diff] [blame] | 196 | |
Aaron Durbin | 5a767fd | 2013-03-23 00:12:19 -0500 | [diff] [blame] | 197 | post_code(0x9e); |
| 198 | |
Aaron Durbin | 5a767fd | 2013-03-23 00:12:19 -0500 | [diff] [blame] | 199 | /* Let's prepare the ACPI S3 Resume area now already, so we can rely on |
| 200 | * it begin there during reboot time. We don't need the pointer, nor |
| 201 | * the result right now. If it fails, ACPI resume will be disabled. |
| 202 | */ |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 203 | if (HIGH_MEMORY_SAVE && acpi_s3_resume_allowed()) |
| 204 | cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE); |
| 205 | |
| 206 | if (HIGH_MEMORY_SCRATCH && acpi_s3_resume_allowed()) |
| 207 | cbmem_add(CBMEM_ID_RESUME_SCRATCH, HIGH_MEMORY_SCRATCH); |
Aaron Durbin | 5a767fd | 2013-03-23 00:12:19 -0500 | [diff] [blame] | 208 | |
Stefan Reinauer | 294edb2 | 2011-08-14 13:52:03 -0700 | [diff] [blame] | 209 | #define MAX_COREBOOT_TABLE_SIZE (32 * 1024) |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 210 | post_code(0x9d); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 211 | |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 212 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_CBTABLE, MAX_COREBOOT_TABLE_SIZE); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 213 | |
| 214 | if (high_table_pointer) { |
| 215 | unsigned long new_high_table_pointer; |
| 216 | |
Kyösti Mälkki | 1ae305e | 2013-09-04 13:05:01 +0300 | [diff] [blame] | 217 | /* FIXME: The high_table_base parameter is not reference when tables are high, |
| 218 | * or high_table_pointer >1 MB. |
| 219 | */ |
| 220 | #if CONFIG_DYNAMIC_CBMEM |
| 221 | u64 fixme_high_tables_base = 0; |
| 222 | #else |
Kyösti Mälkki | e1ea802 | 2013-09-04 14:11:08 +0300 | [diff] [blame] | 223 | u64 fixme_high_tables_base = (u32)get_cbmem_toc(); |
Kyösti Mälkki | 1ae305e | 2013-09-04 13:05:01 +0300 | [diff] [blame] | 224 | #endif |
| 225 | |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 226 | /* Also put a forwarder entry into 0-4K */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 227 | new_high_table_pointer = write_coreboot_table(low_table_start, low_table_end, |
Kyösti Mälkki | 1ae305e | 2013-09-04 13:05:01 +0300 | [diff] [blame] | 228 | fixme_high_tables_base, high_table_pointer); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 229 | |
| 230 | if (new_high_table_pointer > (high_table_pointer + |
| 231 | MAX_COREBOOT_TABLE_SIZE)) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 232 | printk(BIOS_ERR, "%s: coreboot table didn't fit (%lx)\n", |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 233 | __func__, new_high_table_pointer - |
| 234 | high_table_pointer); |
| 235 | |
| 236 | printk(BIOS_DEBUG, "coreboot table: %ld bytes.\n", |
| 237 | new_high_table_pointer - high_table_pointer); |
Stefan Reinauer | efab4ba | 2009-03-17 14:38:48 +0000 | [diff] [blame] | 238 | } else { |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 239 | /* The coreboot table must be in 0-4K or 960K-1M */ |
Juhana Helovuo | 6b56e43 | 2010-09-13 14:47:22 +0000 | [diff] [blame] | 240 | rom_table_end = write_coreboot_table( |
| 241 | low_table_start, low_table_end, |
| 242 | rom_table_start, rom_table_end); |
Stefan Reinauer | efab4ba | 2009-03-17 14:38:48 +0000 | [diff] [blame] | 243 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 244 | |
Stefan Reinauer | 3e4e303 | 2013-03-20 14:08:04 -0700 | [diff] [blame] | 245 | /* Print CBMEM sections */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 246 | cbmem_list(); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 247 | } |