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