| 1 |
|
| 2 |
|
| 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> |
| 14 |
|
| 15 |
static unsigned long write_pirq_table(unsigned long rom_table_end) |
| 16 |
{ |
| 17 |
unsigned long high_table_pointer; |
| 18 |
|
| 19 |
#define MAX_PIRQ_TABLE_SIZE (4 * 1024) |
| 20 |
post_code(POSTCODE_X86_WRITE_PIRQ_TABLE); |
| 21 |
|
| 22 |
|
| 23 |
rom_table_end = write_pirq_routing_table(rom_table_end); |
| 24 |
rom_table_end = ALIGN_UP(rom_table_end, 1024); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 36 |
|
| 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); |
| 42 |
} |
| 43 |
|
| 44 |
return rom_table_end; |
| 45 |
} |
| 46 |
|
| 47 |
static unsigned long write_mptable(unsigned long rom_table_end) |
| 48 |
{ |
| 49 |
unsigned long high_table_pointer; |
| 50 |
|
| 51 |
#define MAX_MP_TABLE_SIZE (4 * 1024) |
| 52 |
post_code(POSTCODE_X86_WRITE_MPTABLE); |
| 53 |
|
| 54 |
|
| 55 |
rom_table_end = write_smp_table(rom_table_end); |
| 56 |
rom_table_end = ALIGN_UP(rom_table_end, 1024); |
| 57 |
|
| 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 |
|
| 64 |
|
| 65 |
if (new_high_table_pointer > (high_table_pointer |
| 66 |
+ MAX_MP_TABLE_SIZE)) |
| 67 |
printk(BIOS_ERR, "Increase MP table size.\n"); |
| 68 |
|
| 69 |
printk(BIOS_DEBUG, "MP table: %ld bytes.\n", |
| 70 |
new_high_table_pointer - high_table_pointer); |
| 71 |
} |
| 72 |
|
| 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; |
| 79 |
const size_t max_acpi_size = CONFIG_MAX_ACPI_TABLE_SIZE_KB * KiB; |
| 80 |
|
| 81 |
post_code(POSTCODE_X86_WRITE_ACPITABLE); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 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; |
| 100 |
|
| 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"); |
| 107 |
} |
| 108 |
printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n", |
| 109 |
new_high_table_pointer - high_table_pointer); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 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++; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 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; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
memcpy(low_rsdp, high_rsdp, sizeof(acpi_rsdp_t)); |
| 131 |
} else { |
| 132 |
printk(BIOS_ERR, "Didn't find RSDP in high table.\n"); |
| 133 |
} |
| 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); |
| 138 |
} |
| 139 |
|
| 140 |
return rom_table_end; |
| 141 |
} |
| 142 |
|
| 143 |
static unsigned long write_smbios_table(unsigned long rom_table_end) |
| 144 |
{ |
| 145 |
unsigned long high_table_pointer; |
| 146 |
|
| 147 |
#define MAX_SMBIOS_SIZE (32 * KiB) |
| 148 |
|
| 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; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
memset((void *)high_table_pointer, 0, MAX_SMBIOS_SIZE); |
| 160 |
|
| 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); |
| 167 |
|
| 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; |
| 175 |
|
| 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); |
| 180 |
} |
| 181 |
|
| 182 |
return rom_table_end; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
#define FORWARDING_TABLE_ADDR ((uintptr_t)0x500) |
| 190 |
static uintptr_t forwarding_table = FORWARDING_TABLE_ADDR; |
| 191 |
|
| 192 |
void arch_write_tables(uintptr_t coreboot_table) |
| 193 |
{ |
| 194 |
size_t sz; |
| 195 |
unsigned long rom_table_end; |
| 196 |
|
| 197 |
if (CONFIG(SHADOW_ROM_TABLE_TO_EBDA)) |
| 198 |
rom_table_end = CONFIG_DEFAULT_EBDA_SEGMENT << 4; |
| 199 |
else |
| 200 |
rom_table_end = 0xf0000; |
| 201 |
|
| 202 |
|
| 203 |
if (CONFIG(GENERATE_PIRQ_TABLE)) |
| 204 |
rom_table_end = write_pirq_table(rom_table_end); |
| 205 |
|
| 206 |
|
| 207 |
if (CONFIG(GENERATE_MP_TABLE)) |
| 208 |
rom_table_end = write_mptable(rom_table_end); |
| 209 |
|
| 210 |
if (CONFIG(HAVE_ACPI_TABLES)) |
| 211 |
rom_table_end = write_acpi_table(rom_table_end); |
| 212 |
|
| 213 |
if (CONFIG(GENERATE_SMBIOS_TABLES)) |
| 214 |
rom_table_end = write_smbios_table(rom_table_end); |
| 215 |
|
| 216 |
sz = write_coreboot_forwarding_table(forwarding_table, coreboot_table); |
| 217 |
|
| 218 |
forwarding_table += sz; |
| 219 |
|
| 220 |
forwarding_table = ALIGN_UP(forwarding_table, 4*KiB); |
| 221 |
|
| 222 |
|
| 223 |
(void)rom_table_end; |
| 224 |
} |
| 225 |
|
| 226 |
void bootmem_arch_add_ranges(void) |
| 227 |
{ |
| 228 |
|
| 229 |
const uintptr_t base = 0; |
| 230 |
|
| 231 |
bootmem_add_range(base, forwarding_table - base, BM_MEM_TABLE); |
| 232 |
|
| 233 |
|
| 234 |
bootmem_add_range((uintptr_t)CONFIG_DEFAULT_EBDA_SEGMENT << 4, |
| 235 |
CONFIG_DEFAULT_EBDA_SIZE, BM_MEM_TABLE); |
| 236 |
} |