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