mb/asus/p8z77-m: Drop GPIO by I/O
[coreboot2.git] / src / arch / x86 / tables.c
blobe47f1bce97d9ebf93c425ecfde87d1c6707dafcd
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <bootmem.h>
5 #include <boot/tables.h>
6 #include <boot/coreboot_tables.h>
7 #include <arch/pirq_routing.h>
8 #include <arch/smp/mpspec.h>
9 #include <acpi/acpi.h>
10 #include <commonlib/helpers.h>
11 #include <string.h>
12 #include <cbmem.h>
13 #include <smbios.h>
15 static unsigned long write_pirq_table(unsigned long rom_table_end)
17 unsigned long high_table_pointer;
19 #define MAX_PIRQ_TABLE_SIZE (4 * 1024)
20 post_code(POSTCODE_X86_WRITE_PIRQ_TABLE);
22 /* This table must be between 0x0f0000 and 0x100000 */
23 rom_table_end = write_pirq_routing_table(rom_table_end);
24 rom_table_end = ALIGN_UP(rom_table_end, 1024);
26 /* And add a high table version for those payloads that
27 * want to live in the F segment
29 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ,
30 MAX_PIRQ_TABLE_SIZE);
31 if (high_table_pointer) {
32 unsigned long new_high_table_pointer;
33 new_high_table_pointer =
34 write_pirq_routing_table(high_table_pointer);
35 // FIXME make pirq table code intelligent enough to know how
36 // much space it's going to need.
37 if (new_high_table_pointer > (high_table_pointer
38 + MAX_PIRQ_TABLE_SIZE))
39 printk(BIOS_ERR, "Increase PIRQ size.\n");
40 printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n",
41 new_high_table_pointer - high_table_pointer);
44 return rom_table_end;
47 static unsigned long write_mptable(unsigned long rom_table_end)
49 unsigned long high_table_pointer;
51 #define MAX_MP_TABLE_SIZE (4 * 1024)
52 post_code(POSTCODE_X86_WRITE_MPTABLE);
54 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
55 rom_table_end = write_smp_table(rom_table_end);
56 rom_table_end = ALIGN_UP(rom_table_end, 1024);
58 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE,
59 MAX_MP_TABLE_SIZE);
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.
65 if (new_high_table_pointer > (high_table_pointer
66 + MAX_MP_TABLE_SIZE))
67 printk(BIOS_ERR, "Increase MP table size.\n");
69 printk(BIOS_DEBUG, "MP table: %ld bytes.\n",
70 new_high_table_pointer - high_table_pointer);
73 return rom_table_end;
76 static unsigned long write_acpi_table(unsigned long rom_table_end)
78 unsigned long high_table_pointer;
79 const size_t max_acpi_size = CONFIG_MAX_ACPI_TABLE_SIZE_KB * KiB;
81 post_code(POSTCODE_X86_WRITE_ACPITABLE);
83 /* Write ACPI tables to F segment and high tables area */
85 /* Ok, this is a bit hacky still, because some day we want to have this
86 * completely dynamic. But right now we are setting fixed sizes.
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.
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.
95 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI,
96 max_acpi_size);
97 if (high_table_pointer) {
98 unsigned long acpi_start = high_table_pointer;
99 unsigned long new_high_table_pointer;
101 rom_table_end = ALIGN_UP(rom_table_end, 16);
102 new_high_table_pointer = write_acpi_tables(high_table_pointer);
103 if (new_high_table_pointer > (high_table_pointer
104 + max_acpi_size)) {
105 printk(BIOS_CRIT, "ACPI tables overflowed and corrupted CBMEM!\n");
106 printk(BIOS_ERR, "Increase config MAX_ACPI_TABLE_SIZE_KB!\n");
108 printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n",
109 new_high_table_pointer - high_table_pointer);
111 /* Now we need to create a low table copy of the RSDP. */
113 /* First we look for the high table RSDP */
114 while (acpi_start < new_high_table_pointer) {
115 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature,
116 RSDP_SIG, 8) == 0)
117 break;
118 acpi_start++;
121 /* Now, if we found the RSDP, we take the RSDT and XSDT pointer
122 * from it in order to write the low RSDP
124 if (acpi_start < new_high_table_pointer) {
125 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
126 *high_rsdp = (acpi_rsdp_t *)acpi_start;
128 /* Technically rsdp length varies but coreboot always
129 writes longest size available. */
130 memcpy(low_rsdp, high_rsdp, sizeof(acpi_rsdp_t));
131 } else {
132 printk(BIOS_ERR, "Didn't find RSDP in high table.\n");
134 rom_table_end = ALIGN_UP(rom_table_end + sizeof(acpi_rsdp_t), 16);
135 } else {
136 rom_table_end = write_acpi_tables(rom_table_end);
137 rom_table_end = ALIGN_UP(rom_table_end, 1024);
140 return rom_table_end;
143 static unsigned long write_smbios_table(unsigned long rom_table_end)
145 unsigned long high_table_pointer;
147 #define MAX_SMBIOS_SIZE (32 * KiB)
149 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS,
150 MAX_SMBIOS_SIZE);
151 if (high_table_pointer) {
152 unsigned long new_high_table_pointer;
155 * Clear the entire region to ensure the unused space doesn't
156 * contain garbage from a previous boot, like stale table
157 * signatures that could be found by the OS.
159 memset((void *)high_table_pointer, 0, MAX_SMBIOS_SIZE);
161 new_high_table_pointer =
162 smbios_write_tables(high_table_pointer);
163 rom_table_end = ALIGN_UP(rom_table_end, 16);
164 memcpy((void *)rom_table_end, (void *)high_table_pointer,
165 sizeof(struct smbios_entry));
166 rom_table_end += sizeof(struct smbios_entry);
168 if (new_high_table_pointer > (high_table_pointer
169 + MAX_SMBIOS_SIZE))
170 printk(BIOS_ERR, "Increase SMBIOS size\n");
171 printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n",
172 new_high_table_pointer - high_table_pointer);
173 } else {
174 unsigned long new_rom_table_end;
176 new_rom_table_end = smbios_write_tables(rom_table_end);
177 printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end
178 - rom_table_end);
179 rom_table_end = ALIGN_UP(new_rom_table_end, 16);
182 return rom_table_end;
185 /* Start forwarding table at 0x500, so we don't run into conflicts with the BDA
186 * in case our data structures grow beyond 0x400. Only GDT
187 * and the coreboot table use low_tables.
189 #define FORWARDING_TABLE_ADDR ((uintptr_t)0x500)
190 static uintptr_t forwarding_table = FORWARDING_TABLE_ADDR;
192 void arch_write_tables(uintptr_t coreboot_table)
194 size_t sz;
195 unsigned long rom_table_end;
197 if (CONFIG(SHADOW_ROM_TABLE_TO_EBDA))
198 rom_table_end = CONFIG_DEFAULT_EBDA_SEGMENT << 4;
199 else
200 rom_table_end = 0xf0000;
202 /* This table must be between 0x0f0000 and 0x100000 */
203 if (CONFIG(GENERATE_PIRQ_TABLE))
204 rom_table_end = write_pirq_table(rom_table_end);
206 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
207 if (CONFIG(GENERATE_MP_TABLE))
208 rom_table_end = write_mptable(rom_table_end);
210 if (CONFIG(HAVE_ACPI_TABLES))
211 rom_table_end = write_acpi_table(rom_table_end);
213 if (CONFIG(GENERATE_SMBIOS_TABLES))
214 rom_table_end = write_smbios_table(rom_table_end);
216 sz = write_coreboot_forwarding_table(forwarding_table, coreboot_table);
218 forwarding_table += sz;
219 /* Align up to page boundary for historical consistency. */
220 forwarding_table = ALIGN_UP(forwarding_table, 4*KiB);
222 /* Tell static analysis we know value is left unused. */
223 (void)rom_table_end;
226 void bootmem_arch_add_ranges(void)
228 /* Memory from 0 through the forwarding_table is reserved. */
229 const uintptr_t base = 0;
231 bootmem_add_range(base, forwarding_table - base, BM_MEM_TABLE);
233 /* Reserve Extend BIOS Data Area (EBDA) region explicitly */
234 bootmem_add_range((uintptr_t)CONFIG_DEFAULT_EBDA_SEGMENT << 4,
235 CONFIG_DEFAULT_EBDA_SIZE, BM_MEM_TABLE);