Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 3 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 4 | #include <console/console.h> |
Aaron Durbin | d4afa93 | 2016-04-19 17:25:59 -0500 | [diff] [blame] | 5 | #include <bootmem.h> |
Aaron Durbin | f46a9a0 | 2017-10-17 14:33:05 -0600 | [diff] [blame] | 6 | #include <bootstate.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 7 | #include <boot/tables.h> |
Stefan Reinauer | ca374d4 | 2008-01-18 16:16:45 +0000 | [diff] [blame] | 8 | #include <boot/coreboot_tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 9 | #include <arch/pirq_routing.h> |
| 10 | #include <arch/smp/mpspec.h> |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 11 | #include <arch/acpi.h> |
Elyes HAOUAS | e2d152c | 2019-06-21 07:06:50 +0200 | [diff] [blame] | 12 | #include <commonlib/helpers.h> |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 13 | #include <string.h> |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 14 | #include <cbmem.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 15 | #include <smbios.h> |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 16 | |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 17 | static unsigned long write_pirq_table(unsigned long rom_table_end) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 18 | { |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 19 | unsigned long high_table_pointer; |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 20 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 21 | #define MAX_PIRQ_TABLE_SIZE (4 * 1024) |
| 22 | post_code(0x9a); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 23 | |
| 24 | /* This table must be between 0x0f0000 and 0x100000 */ |
| 25 | rom_table_end = write_pirq_routing_table(rom_table_end); |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 26 | rom_table_end = ALIGN_UP(rom_table_end, 1024); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 27 | |
| 28 | /* And add a high table version for those payloads that |
| 29 | * want to live in the F segment |
| 30 | */ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 31 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, |
| 32 | MAX_PIRQ_TABLE_SIZE); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 33 | if (high_table_pointer) { |
| 34 | unsigned long new_high_table_pointer; |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 35 | new_high_table_pointer = |
| 36 | write_pirq_routing_table(high_table_pointer); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 37 | // FIXME make pirq table code intelligent enough to know how |
| 38 | // much space it's going to need. |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 39 | if (new_high_table_pointer > (high_table_pointer |
| 40 | + MAX_PIRQ_TABLE_SIZE)) |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 41 | printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n"); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 42 | printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n", |
| 43 | new_high_table_pointer - high_table_pointer); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 44 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 46 | return rom_table_end; |
| 47 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 48 | |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 49 | static unsigned long write_mptable(unsigned long rom_table_end) |
| 50 | { |
| 51 | unsigned long high_table_pointer; |
| 52 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 53 | #define MAX_MP_TABLE_SIZE (4 * 1024) |
| 54 | post_code(0x9b); |
| 55 | |
| 56 | /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */ |
| 57 | rom_table_end = write_smp_table(rom_table_end); |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 58 | rom_table_end = ALIGN_UP(rom_table_end, 1024); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 59 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 60 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, |
| 61 | MAX_MP_TABLE_SIZE); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 62 | if (high_table_pointer) { |
| 63 | unsigned long new_high_table_pointer; |
| 64 | new_high_table_pointer = write_smp_table(high_table_pointer); |
| 65 | // FIXME make mp table code intelligent enough to know how |
| 66 | // much space it's going to need. |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 67 | if (new_high_table_pointer > (high_table_pointer |
| 68 | + MAX_MP_TABLE_SIZE)) |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 69 | printk(BIOS_ERR, "ERROR: Increase MP table size.\n"); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 70 | |
| 71 | printk(BIOS_DEBUG, "MP table: %ld bytes.\n", |
| 72 | new_high_table_pointer - high_table_pointer); |
| 73 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 74 | |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 75 | return rom_table_end; |
| 76 | } |
| 77 | |
| 78 | static unsigned long write_acpi_table(unsigned long rom_table_end) |
| 79 | { |
| 80 | unsigned long high_table_pointer; |
Duncan Laurie | f02bf35 | 2020-03-17 18:32:54 -0700 | [diff] [blame^] | 81 | const size_t max_acpi_size = CONFIG_MAX_ACPI_TABLE_SIZE_KB * KiB; |
Kyösti Mälkki | ae98e83 | 2014-11-28 11:24:19 +0200 | [diff] [blame] | 82 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 83 | post_code(0x9c); |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame] | 84 | |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 85 | /* Write ACPI tables to F segment and high tables area */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 86 | |
| 87 | /* 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] | 88 | * completely dynamic. But right now we are setting fixed sizes. |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 89 | * It's probably still better than the old high_table_base code because |
| 90 | * now at least we know when we have an overflow in the area. |
| 91 | * |
| 92 | * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and |
| 93 | * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the |
| 94 | * coreboot table. This leaves us with 47KB for all of ACPI. Let's see |
| 95 | * how far we get. |
| 96 | */ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 97 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, |
Duncan Laurie | f02bf35 | 2020-03-17 18:32:54 -0700 | [diff] [blame^] | 98 | max_acpi_size); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 99 | if (high_table_pointer) { |
| 100 | unsigned long acpi_start = high_table_pointer; |
| 101 | unsigned long new_high_table_pointer; |
| 102 | |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 103 | rom_table_end = ALIGN_UP(rom_table_end, 16); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 104 | new_high_table_pointer = write_acpi_tables(high_table_pointer); |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 105 | if (new_high_table_pointer > (high_table_pointer |
Duncan Laurie | f02bf35 | 2020-03-17 18:32:54 -0700 | [diff] [blame^] | 106 | + max_acpi_size)) |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 107 | printk(BIOS_ERR, "ERROR: Increase ACPI size\n"); |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 108 | printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n", |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 109 | new_high_table_pointer - high_table_pointer); |
| 110 | |
| 111 | /* Now we need to create a low table copy of the RSDP. */ |
| 112 | |
| 113 | /* First we look for the high table RSDP */ |
| 114 | while (acpi_start < new_high_table_pointer) { |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 115 | if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, |
| 116 | RSDP_SIG, 8) == 0) |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 117 | break; |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 118 | acpi_start++; |
| 119 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 120 | |
| 121 | /* Now, if we found the RSDP, we take the RSDT and XSDT pointer |
| 122 | * from it in order to write the low RSDP |
| 123 | */ |
| 124 | if (acpi_start < new_high_table_pointer) { |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 125 | acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end, |
| 126 | *high_rsdp = (acpi_rsdp_t *)acpi_start; |
| 127 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 128 | /* Technically rsdp length varies but coreboot always |
| 129 | writes longest size available. */ |
| 130 | memcpy(low_rsdp, high_rsdp, sizeof(acpi_rsdp_t)); |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 131 | } else { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 132 | printk(BIOS_ERR, |
| 133 | "ERROR: Didn't find RSDP in high table.\n"); |
Patrick Georgi | bab4f92 | 2009-05-26 19:39:14 +0000 | [diff] [blame] | 134 | } |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 135 | rom_table_end = ALIGN_UP(rom_table_end + sizeof(acpi_rsdp_t), 16); |
Stefan Reinauer | f2152ec | 2009-05-26 14:07:44 +0000 | [diff] [blame] | 136 | } else { |
| 137 | rom_table_end = write_acpi_tables(rom_table_end); |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 138 | rom_table_end = ALIGN_UP(rom_table_end, 1024); |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 139 | } |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 140 | |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 141 | return rom_table_end; |
| 142 | } |
| 143 | |
| 144 | static unsigned long write_smbios_table(unsigned long rom_table_end) |
| 145 | { |
| 146 | unsigned long high_table_pointer; |
| 147 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 148 | #define MAX_SMBIOS_SIZE 2048 |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 149 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 150 | high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, |
| 151 | MAX_SMBIOS_SIZE); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 152 | if (high_table_pointer) { |
| 153 | unsigned long new_high_table_pointer; |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 154 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 155 | new_high_table_pointer = |
| 156 | smbios_write_tables(high_table_pointer); |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 157 | rom_table_end = ALIGN_UP(rom_table_end, 16); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 158 | memcpy((void *)rom_table_end, (void *)high_table_pointer, |
| 159 | sizeof(struct smbios_entry)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 160 | rom_table_end += sizeof(struct smbios_entry); |
| 161 | |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 162 | if (new_high_table_pointer > (high_table_pointer |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 163 | + MAX_SMBIOS_SIZE)) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 164 | printk(BIOS_ERR, "ERROR: Increase SMBIOS size\n"); |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 165 | printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n", |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 166 | new_high_table_pointer - high_table_pointer); |
| 167 | } else { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 168 | unsigned long new_rom_table_end; |
| 169 | |
| 170 | new_rom_table_end = smbios_write_tables(rom_table_end); |
| 171 | printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end |
| 172 | - rom_table_end); |
Felix Held | 0f6b51b | 2019-06-20 14:09:01 +0200 | [diff] [blame] | 173 | rom_table_end = ALIGN_UP(new_rom_table_end, 16); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 174 | } |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 175 | |
| 176 | return rom_table_end; |
| 177 | } |
| 178 | |
Aaron Durbin | a4db050 | 2016-04-19 21:38:18 -0500 | [diff] [blame] | 179 | /* Start forwarding table at 0x500, so we don't run into conflicts with the BDA |
| 180 | * in case our data structures grow beyond 0x400. Only GDT |
| 181 | * and the coreboot table use low_tables. |
| 182 | */ |
Aaron Durbin | f46a9a0 | 2017-10-17 14:33:05 -0600 | [diff] [blame] | 183 | #define FORWARDING_TABLE_ADDR ((uintptr_t)0x500) |
| 184 | static uintptr_t forwarding_table = FORWARDING_TABLE_ADDR; |
| 185 | |
Aaron Durbin | 5481c96 | 2016-04-19 20:37:51 -0500 | [diff] [blame] | 186 | void arch_write_tables(uintptr_t coreboot_table) |
Aaron Durbin | d4afa93 | 2016-04-19 17:25:59 -0500 | [diff] [blame] | 187 | { |
Aaron Durbin | a4db050 | 2016-04-19 21:38:18 -0500 | [diff] [blame] | 188 | size_t sz; |
Aaron Durbin | 5481c96 | 2016-04-19 20:37:51 -0500 | [diff] [blame] | 189 | unsigned long rom_table_end = 0xf0000; |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 190 | |
| 191 | /* This table must be between 0x0f0000 and 0x100000 */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 192 | if (CONFIG(GENERATE_PIRQ_TABLE)) |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 193 | rom_table_end = write_pirq_table(rom_table_end); |
| 194 | |
| 195 | /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 196 | if (CONFIG(GENERATE_MP_TABLE)) |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 197 | rom_table_end = write_mptable(rom_table_end); |
| 198 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 199 | if (CONFIG(HAVE_ACPI_TABLES)) |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 200 | rom_table_end = write_acpi_table(rom_table_end); |
| 201 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 202 | if (CONFIG(GENERATE_SMBIOS_TABLES)) |
Aaron Durbin | 86cbfa0 | 2016-04-19 15:53:56 -0500 | [diff] [blame] | 203 | rom_table_end = write_smbios_table(rom_table_end); |
Aaron Durbin | a4db050 | 2016-04-19 21:38:18 -0500 | [diff] [blame] | 204 | |
| 205 | sz = write_coreboot_forwarding_table(forwarding_table, coreboot_table); |
| 206 | |
| 207 | forwarding_table += sz; |
| 208 | /* Align up to page boundary for historical consistency. */ |
| 209 | forwarding_table = ALIGN_UP(forwarding_table, 4*KiB); |
Richard Spiegel | bb7424f | 2018-08-08 09:58:34 -0700 | [diff] [blame] | 210 | |
| 211 | /* Tell static analysis we know value is left unused. */ |
| 212 | (void)rom_table_end; |
Aaron Durbin | 5481c96 | 2016-04-19 20:37:51 -0500 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void bootmem_arch_add_ranges(void) |
| 216 | { |
Aaron Durbin | a4db050 | 2016-04-19 21:38:18 -0500 | [diff] [blame] | 217 | /* Memory from 0 through the forwarding_table is reserved. */ |
| 218 | const uintptr_t base = 0; |
Aaron Durbin | 5481c96 | 2016-04-19 20:37:51 -0500 | [diff] [blame] | 219 | |
Patrick Rudolph | 9ab9db0 | 2018-04-05 09:14:51 +0200 | [diff] [blame] | 220 | bootmem_add_range(base, forwarding_table - base, BM_MEM_TABLE); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 221 | } |