Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 2 | |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 3 | #include <arch/null_breakpoint.h> |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 4 | #include <arch/symbols.h> |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 5 | #include <assert.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 6 | #include <cbfs.h> |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 7 | #include <cbmem.h> |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 8 | #include <cf9_reset.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 9 | #include <console/console.h> |
Furquan Shaikh | 5aea588 | 2016-07-30 18:10:05 -0700 | [diff] [blame] | 10 | #include <elog.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 11 | #include <fsp/api.h> |
| 12 | #include <fsp/util.h> |
| 13 | #include <memrange.h> |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 14 | #include <mode_switch.h> |
Aaron Durbin | decd062 | 2017-12-15 12:26:40 -0700 | [diff] [blame] | 15 | #include <mrc_cache.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 16 | #include <program_loading.h> |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 17 | #include <romstage_handoff.h> |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 18 | #include <security/tpm/tspi.h> |
| 19 | #include <security/vboot/antirollback.h> |
| 20 | #include <security/vboot/vboot_common.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 21 | #include <string.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 22 | #include <symbols.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 23 | #include <timestamp.h> |
Elyes HAOUAS | bd1683d | 2019-05-15 21:05:37 +0200 | [diff] [blame] | 24 | #include <types.h> |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 25 | #include <vb2_api.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 26 | |
Subrata Banik | 30a0114 | 2023-03-22 00:35:42 +0530 | [diff] [blame^] | 27 | #if CONFIG(SOC_INTEL_COMMON_BASECODE_RAMTOP) |
| 28 | #include <intelbasecode/ramtop.h> |
Subrata Banik | dbfbfaf | 2023-02-28 07:01:26 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 31 | static uint8_t temp_ram[CONFIG_FSP_TEMP_RAM_SIZE] __aligned(sizeof(uint64_t)); |
| 32 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 33 | static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version) |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 34 | { |
| 35 | struct range_entry fsp_mem; |
Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 36 | uint32_t *fsp_version_cbmem; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 37 | |
Michael Niewöhner | bc1dbb3 | 2019-10-24 22:58:25 +0200 | [diff] [blame] | 38 | fsp_find_reserved_memory(&fsp_mem); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 39 | |
| 40 | /* initialize cbmem by adding FSP reserved memory first thing */ |
| 41 | if (!s3wake) { |
| 42 | cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY, |
| 43 | range_entry_size(&fsp_mem)); |
| 44 | } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY, |
| 45 | range_entry_size(&fsp_mem))) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 46 | if (CONFIG(HAVE_ACPI_RESUME)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 47 | printk(BIOS_ERR, "Failed to recover CBMEM in S3 resume.\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 48 | /* Failed S3 resume, reset to come up cleanly */ |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 49 | /* FIXME: A "system" reset is likely enough: */ |
| 50 | full_reset(); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
| 54 | /* make sure FSP memory is reserved in cbmem */ |
| 55 | if (range_entry_base(&fsp_mem) != |
| 56 | (uintptr_t)cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY)) |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 57 | die("Failed to accommodate FSP reserved memory request!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 58 | |
Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 59 | /* ramstage uses the FSP-M version when updating the MRC cache */ |
| 60 | if (CONFIG(CACHE_MRC_SETTINGS) && !s3wake) { |
| 61 | fsp_version_cbmem = cbmem_add(CBMEM_ID_FSPM_VERSION, |
| 62 | sizeof(fsp_version)); |
| 63 | if (!fsp_version_cbmem) |
| 64 | printk(BIOS_ERR, "Failed to add FSP-M version to cbmem.\n"); |
| 65 | *fsp_version_cbmem = fsp_version; |
| 66 | } |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 67 | |
| 68 | /* Create romstage handof information */ |
Aaron Durbin | 77e1399 | 2016-11-29 17:43:04 -0600 | [diff] [blame] | 69 | romstage_handoff_init(s3wake); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Aamir Bohra | 69cd62c | 2018-01-08 11:01:34 +0530 | [diff] [blame] | 72 | static void fsp_fill_mrc_cache(FSPM_ARCH_UPD *arch_upd, uint32_t fsp_version) |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 73 | { |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 74 | void *data; |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 75 | size_t mrc_size; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 76 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 77 | arch_upd->NvsBufferPtr = 0; |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 78 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 79 | if (!CONFIG(CACHE_MRC_SETTINGS)) |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 80 | return; |
| 81 | |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 82 | /* Assume boot device is memory mapped. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 83 | assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 84 | |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 85 | data = mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, fsp_version, |
| 86 | &mrc_size); |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 87 | if (data == NULL) |
| 88 | return; |
| 89 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 90 | /* MRC cache found */ |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 91 | arch_upd->NvsBufferPtr = (uintptr_t)data; |
Aamir Bohra | 69cd62c | 2018-01-08 11:01:34 +0530 | [diff] [blame] | 92 | |
Subrata Banik | 0593708 | 2023-03-06 08:18:24 +0000 | [diff] [blame] | 93 | printk(BIOS_SPEW, "MRC cache found, size %zu bytes\n", mrc_size); |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 96 | static enum cb_err check_region_overlap(const struct memranges *ranges, |
| 97 | const char *description, |
| 98 | uintptr_t begin, uintptr_t end) |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 99 | { |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 100 | const struct range_entry *r; |
| 101 | |
| 102 | memranges_each_entry(r, ranges) { |
| 103 | if (end <= range_entry_base(r)) |
| 104 | continue; |
| 105 | if (begin >= range_entry_end(r)) |
| 106 | continue; |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 107 | printk(BIOS_CRIT, "'%s' overlaps currently running program: " |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 108 | "[%p, %p)\n", description, (void *)begin, (void *)end); |
| 109 | return CB_ERR; |
| 110 | } |
| 111 | |
| 112 | return CB_SUCCESS; |
| 113 | } |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 114 | |
Aamir Bohra | 6d569e0c | 2018-08-27 13:36:15 +0530 | [diff] [blame] | 115 | static enum cb_err setup_fsp_stack_frame(FSPM_ARCH_UPD *arch_upd, |
| 116 | const struct memranges *memmap) |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 117 | { |
| 118 | uintptr_t stack_begin; |
| 119 | uintptr_t stack_end; |
| 120 | |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 121 | /* |
Aamir Bohra | 6d569e0c | 2018-08-27 13:36:15 +0530 | [diff] [blame] | 122 | * FSPM_UPD passed here is populated with default values |
| 123 | * provided by the blob itself. We let FSPM use top of CAR |
| 124 | * region of the size it requests. |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 125 | */ |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 126 | stack_end = (uintptr_t)_car_region_end; |
| 127 | stack_begin = stack_end - arch_upd->StackSize; |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 128 | if (check_region_overlap(memmap, "FSPM stack", stack_begin, |
| 129 | stack_end) != CB_SUCCESS) |
| 130 | return CB_ERR; |
| 131 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 132 | arch_upd->StackBase = stack_begin; |
Aamir Bohra | 6d569e0c | 2018-08-27 13:36:15 +0530 | [diff] [blame] | 133 | return CB_SUCCESS; |
| 134 | } |
| 135 | |
| 136 | static enum cb_err fsp_fill_common_arch_params(FSPM_ARCH_UPD *arch_upd, |
| 137 | bool s3wake, uint32_t fsp_version, |
| 138 | const struct memranges *memmap) |
| 139 | { |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 140 | /* |
| 141 | * FSP 2.1 version would use same stack as coreboot instead of |
| 142 | * setting up separate stack frame. FSP 2.1 would not relocate stack |
| 143 | * top and does not reinitialize stack pointer. The parameters passed |
| 144 | * as StackBase and StackSize are actually for temporary RAM and HOBs |
| 145 | * and are not related to FSP stack at all. |
Felix Held | 414d7e4 | 2020-08-11 22:54:06 +0200 | [diff] [blame] | 146 | * Non-CAR FSP 2.0 platforms pass a DRAM location for the FSP stack. |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 147 | */ |
Felix Held | 414d7e4 | 2020-08-11 22:54:06 +0200 | [diff] [blame] | 148 | if (CONFIG(FSP_USES_CB_STACK) || !ENV_CACHE_AS_RAM) { |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 149 | arch_upd->StackBase = (uintptr_t)temp_ram; |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 150 | arch_upd->StackSize = sizeof(temp_ram); |
| 151 | } else if (setup_fsp_stack_frame(arch_upd, memmap)) { |
Aamir Bohra | 6d569e0c | 2018-08-27 13:36:15 +0530 | [diff] [blame] | 152 | return CB_ERR; |
Kyösti Mälkki | c987150 | 2019-09-03 07:03:39 +0300 | [diff] [blame] | 153 | } |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 154 | |
Aamir Bohra | 69cd62c | 2018-01-08 11:01:34 +0530 | [diff] [blame] | 155 | fsp_fill_mrc_cache(arch_upd, fsp_version); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 156 | |
Aamir Bohra | 69cd62c | 2018-01-08 11:01:34 +0530 | [diff] [blame] | 157 | /* Configure bootmode */ |
| 158 | if (s3wake) { |
Aamir Bohra | 69cd62c | 2018-01-08 11:01:34 +0530 | [diff] [blame] | 159 | arch_upd->BootMode = FSP_BOOT_ON_S3_RESUME; |
| 160 | } else { |
| 161 | if (arch_upd->NvsBufferPtr) |
| 162 | arch_upd->BootMode = |
| 163 | FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES; |
| 164 | else |
| 165 | arch_upd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION; |
| 166 | } |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 167 | |
Marshall Dawson | 22d66ef | 2019-08-30 14:52:37 -0600 | [diff] [blame] | 168 | printk(BIOS_SPEW, "bootmode is set to: %d\n", arch_upd->BootMode); |
Aamir Bohra | 276c06a | 2017-12-26 17:54:45 +0530 | [diff] [blame] | 169 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 170 | return CB_SUCCESS; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 173 | __weak |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 174 | uint8_t fsp_memory_mainboard_version(void) |
| 175 | { |
| 176 | return 0; |
| 177 | } |
| 178 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 179 | __weak |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 180 | uint8_t fsp_memory_soc_version(void) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Allow SoC and/or mainboard to bump the revision of the FSP setting |
| 187 | * number. The FSP spec uses the low 8 bits as the build number. Take over |
| 188 | * bits 3:0 for the SoC setting and bits 7:4 for the mainboard. That way |
| 189 | * a tweak in the settings will bump the version used to track the cached |
| 190 | * setting which triggers retraining when the FSP version hasn't changed, but |
| 191 | * the SoC or mainboard settings have. |
| 192 | */ |
| 193 | static uint32_t fsp_memory_settings_version(const struct fsp_header *hdr) |
| 194 | { |
| 195 | /* Use the full FSP version by default. */ |
Julian Schroeder | 8a576f6 | 2021-11-02 16:32:28 -0500 | [diff] [blame] | 196 | uint32_t ver = hdr->image_revision; |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 197 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 198 | if (!CONFIG(FSP_PLATFORM_MEMORY_SETTINGS_VERSIONS)) |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 199 | return ver; |
| 200 | |
| 201 | ver &= ~0xff; |
| 202 | ver |= (0xf & fsp_memory_mainboard_version()) << 4; |
| 203 | ver |= (0xf & fsp_memory_soc_version()) << 0; |
| 204 | |
| 205 | return ver; |
| 206 | } |
| 207 | |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 208 | struct fspm_context { |
| 209 | struct fsp_header header; |
| 210 | struct memranges memmap; |
| 211 | }; |
| 212 | |
| 213 | static void do_fsp_memory_init(const struct fspm_context *context, bool s3wake) |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 214 | { |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 215 | uint32_t status; |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 216 | fsp_memory_init_fn fsp_raminit; |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 217 | FSPM_UPD fspm_upd, *upd; |
| 218 | FSPM_ARCH_UPD *arch_upd; |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 219 | uint32_t fsp_version; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 220 | const struct fsp_header *hdr = &context->header; |
| 221 | const struct memranges *memmap = &context->memmap; |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 222 | |
Furquan Shaikh | 585210a | 2018-10-16 11:54:37 -0700 | [diff] [blame] | 223 | post_code(POST_MEM_PREINIT_PREP_START); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 224 | |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 225 | fsp_version = fsp_memory_settings_version(hdr); |
| 226 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 227 | upd = (FSPM_UPD *)(uintptr_t)(hdr->cfg_region_offset + hdr->image_base); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 228 | |
Felix Held | a095595 | 2021-02-02 21:30:25 +0100 | [diff] [blame] | 229 | /* |
| 230 | * Verify UPD region size. We don't have malloc before ramstage, so we |
| 231 | * use a static buffer for the FSP-M UPDs which is sizeof(FSPM_UPD) |
| 232 | * bytes long, since that is the value known at compile time. If |
| 233 | * hdr->cfg_region_size is bigger than that, not all UPD defaults will |
| 234 | * be copied, so it'll contain random data at the end, so we just call |
| 235 | * die() in that case. If hdr->cfg_region_size is smaller than that, |
| 236 | * there's a mismatch between the FSP and the header, but since it will |
| 237 | * copy the full UPD defaults to the buffer, we try to continue and |
| 238 | * hope that there was no incompatible change in the UPDs. |
| 239 | */ |
| 240 | if (hdr->cfg_region_size > sizeof(FSPM_UPD)) |
| 241 | die("FSP-M UPD size is larger than FSPM_UPD struct size.\n"); |
| 242 | if (hdr->cfg_region_size < sizeof(FSPM_UPD)) |
| 243 | printk(BIOS_ERR, "FSP-M UPD size is smaller than FSPM_UPD struct size. " |
| 244 | "Check if the FSP binary matches the FSP headers.\n"); |
| 245 | |
Felix Held | 8899598 | 2021-01-28 22:43:52 +0100 | [diff] [blame] | 246 | fsp_verify_upd_header_signature(upd->FspUpdHeader.Signature, FSPM_UPD_SIGNATURE); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 247 | |
| 248 | /* Copy the default values from the UPD area */ |
| 249 | memcpy(&fspm_upd, upd, sizeof(fspm_upd)); |
| 250 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 251 | arch_upd = &fspm_upd.FspmArchUpd; |
| 252 | |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 253 | /* Reserve enough memory under TOLUD to save CBMEM header */ |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 254 | arch_upd->BootLoaderTolumSize = cbmem_overhead_size(); |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 255 | |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 256 | /* Fill common settings on behalf of chipset. */ |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 257 | if (fsp_fill_common_arch_params(arch_upd, s3wake, fsp_version, |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 258 | memmap) != CB_SUCCESS) |
Keith Short | bb41aba | 2019-05-16 14:07:43 -0600 | [diff] [blame] | 259 | die_with_post_code(POST_INVALID_VENDOR_BINARY, |
| 260 | "FSPM_ARCH_UPD not found!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 261 | |
Subrata Banik | 30a0114 | 2023-03-22 00:35:42 +0530 | [diff] [blame^] | 262 | /* Early caching of RAMTOP region if valid mrc cache data is found */ |
| 263 | #if (CONFIG(SOC_INTEL_COMMON_BASECODE_RAMTOP)) |
Subrata Banik | dbfbfaf | 2023-02-28 07:01:26 +0000 | [diff] [blame] | 264 | if (arch_upd->NvsBufferPtr) |
Subrata Banik | 30a0114 | 2023-03-22 00:35:42 +0530 | [diff] [blame^] | 265 | early_ramtop_enable_cache_range(); |
Subrata Banik | dbfbfaf | 2023-02-28 07:01:26 +0000 | [diff] [blame] | 266 | #endif |
| 267 | |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 268 | /* Give SoC and mainboard a chance to update the UPD */ |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 269 | platform_fsp_memory_init_params_cb(&fspm_upd, fsp_version); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 270 | |
Furquan Shaikh | dbce8ba | 2020-06-05 19:17:00 -0700 | [diff] [blame] | 271 | /* |
| 272 | * For S3 resume case, if valid mrc cache data is not found or |
| 273 | * RECOVERY_MRC_CACHE hash verification fails, the S3 data |
| 274 | * pointer would be null and S3 resume fails with fsp-m |
| 275 | * returning error. Invoking a reset here saves time. |
| 276 | */ |
| 277 | if (s3wake && !arch_upd->NvsBufferPtr) |
| 278 | /* FIXME: A "system" reset is likely enough: */ |
| 279 | full_reset(); |
| 280 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 281 | if (CONFIG(MMA)) |
Pratik Prajapati | ffc934d | 2016-11-18 14:36:34 -0800 | [diff] [blame] | 282 | setup_mma(&fspm_upd.FspmConfig); |
| 283 | |
Furquan Shaikh | 585210a | 2018-10-16 11:54:37 -0700 | [diff] [blame] | 284 | post_code(POST_MEM_PREINIT_PREP_END); |
| 285 | |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 286 | /* Call FspMemoryInit */ |
Julian Schroeder | 8a576f6 | 2021-11-02 16:32:28 -0500 | [diff] [blame] | 287 | fsp_raminit = (void *)(uintptr_t)(hdr->image_base + hdr->fsp_memory_init_entry_offset); |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 288 | fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 289 | |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 290 | /* FSP disables the interrupt handler so remove debug exceptions temporarily */ |
| 291 | null_breakpoint_disable(); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 292 | post_code(POST_FSP_MEMORY_INIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 293 | timestamp_add_now(TS_FSP_MEMORY_INIT_START); |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 294 | if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32)) |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 295 | status = protected_mode_call_2arg(fsp_raminit, |
| 296 | (uintptr_t)&fspm_upd, |
| 297 | (uintptr_t)fsp_get_hob_list_ptr()); |
| 298 | else |
| 299 | status = fsp_raminit(&fspm_upd, fsp_get_hob_list_ptr()); |
Arthur Heymans | fdf6d12 | 2022-05-17 13:07:30 +0200 | [diff] [blame] | 300 | null_breakpoint_init(); |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 301 | |
Subrata Banik | 0755ab9 | 2017-07-12 15:31:06 +0530 | [diff] [blame] | 302 | post_code(POST_FSP_MEMORY_EXIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 303 | timestamp_add_now(TS_FSP_MEMORY_INIT_END); |
| 304 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 305 | /* Handle any errors returned by FspMemoryInit */ |
Aaron Durbin | f41f2aa | 2016-07-18 12:03:58 -0500 | [diff] [blame] | 306 | fsp_handle_reset(status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 307 | if (status != FSP_SUCCESS) { |
Keith Short | 2430263 | 2019-05-16 14:08:31 -0600 | [diff] [blame] | 308 | die_with_post_code(POST_RAM_FAILURE, |
Angel Pons | 2b1f8d4 | 2022-01-01 17:20:00 +0100 | [diff] [blame] | 309 | "FspMemoryInit returned with error 0x%08x!\n", status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 310 | } |
Aaron Durbin | f41f2aa | 2016-07-18 12:03:58 -0500 | [diff] [blame] | 311 | |
Aaron Durbin | a3cecb2 | 2017-04-25 21:58:10 -0500 | [diff] [blame] | 312 | do_fsp_post_memory_init(s3wake, fsp_version); |
Matthew Garrett | 78b58a4 | 2018-07-28 16:53:16 -0700 | [diff] [blame] | 313 | |
| 314 | /* |
| 315 | * fsp_debug_after_memory_init() checks whether the end of the tolum |
| 316 | * region is the same as the top of cbmem, so must be called here |
| 317 | * after cbmem has been initialised in do_fsp_post_memory_init(). |
| 318 | */ |
| 319 | fsp_debug_after_memory_init(status); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 322 | static void *fspm_allocator(void *arg, size_t size, const union cbfs_mdata *unused) |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 323 | { |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 324 | const struct fsp_load_descriptor *fspld = arg; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 325 | struct fspm_context *context = fspld->arg; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 326 | struct memranges *memmap = &context->memmap; |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 327 | |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 328 | /* Non XIP FSP-M uses FSP-M address */ |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 329 | uintptr_t fspm_begin = (uintptr_t)CONFIG_FSP_M_ADDR; |
| 330 | uintptr_t fspm_end = fspm_begin + size; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 331 | |
| 332 | if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) != CB_SUCCESS) |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 333 | return NULL; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 334 | |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 335 | return (void *)fspm_begin; |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Raul E Rangel | 1592846 | 2021-11-05 10:29:24 -0600 | [diff] [blame] | 338 | void preload_fspm(void) |
| 339 | { |
| 340 | if (!CONFIG(CBFS_PRELOAD)) |
| 341 | return; |
| 342 | |
| 343 | printk(BIOS_DEBUG, "Preloading %s\n", CONFIG_FSP_M_CBFS); |
| 344 | cbfs_preload(CONFIG_FSP_M_CBFS); |
| 345 | } |
| 346 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 347 | void fsp_memory_init(bool s3wake) |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 348 | { |
Marshall Dawson | e3aa424 | 2019-10-16 21:53:21 -0600 | [diff] [blame] | 349 | struct range_entry prog_ranges[2]; |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 350 | struct fspm_context context; |
| 351 | struct fsp_load_descriptor fspld = { |
| 352 | .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_M_CBFS), |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 353 | .arg = &context, |
| 354 | }; |
| 355 | struct fsp_header *hdr = &context.header; |
| 356 | struct memranges *memmap = &context.memmap; |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 357 | |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 358 | /* For FSP-M XIP we leave alloc NULL to get a direct mapping to flash. */ |
| 359 | if (!CONFIG(FSP_M_XIP)) |
| 360 | fspld.alloc = fspm_allocator; |
| 361 | |
Kyösti Mälkki | 7f50afb | 2019-09-11 17:12:26 +0300 | [diff] [blame] | 362 | elog_boot_notify(s3wake); |
Furquan Shaikh | 5aea588 | 2016-07-30 18:10:05 -0700 | [diff] [blame] | 363 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 364 | /* Build up memory map of romstage address space including CAR. */ |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 365 | memranges_init_empty(memmap, &prog_ranges[0], ARRAY_SIZE(prog_ranges)); |
Marshall Dawson | e3aa424 | 2019-10-16 21:53:21 -0600 | [diff] [blame] | 366 | if (ENV_CACHE_AS_RAM) |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 367 | memranges_insert(memmap, (uintptr_t)_car_region_start, |
Marshall Dawson | e3aa424 | 2019-10-16 21:53:21 -0600 | [diff] [blame] | 368 | _car_unallocated_start - _car_region_start, 0); |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 369 | memranges_insert(memmap, (uintptr_t)_program, REGION_SIZE(program), 0); |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 370 | |
Martin Roth | 146508d | 2021-04-30 16:45:08 -0600 | [diff] [blame] | 371 | timestamp_add_now(TS_FSP_MEMORY_INIT_LOAD); |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 372 | if (fsp_load_component(&fspld, hdr) != CB_SUCCESS) |
| 373 | die("FSPM not available or failed to load!\n"); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 374 | |
Julius Werner | 8205ce6 | 2021-03-10 17:25:01 -0800 | [diff] [blame] | 375 | if (CONFIG(FSP_M_XIP) && (uintptr_t)prog_start(&fspld.fsp_prog) != hdr->image_base) |
| 376 | die("FSPM XIP base does not match: %p vs %p\n", |
| 377 | (void *)(uintptr_t)hdr->image_base, prog_start(&fspld.fsp_prog)); |
| 378 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 379 | timestamp_add_now(TS_INITRAM_START); |
Kyösti Mälkki | 216db61 | 2019-09-11 09:57:14 +0300 | [diff] [blame] | 380 | |
Aaron Durbin | ecbfa99 | 2020-05-15 17:01:58 -0600 | [diff] [blame] | 381 | do_fsp_memory_init(&context, s3wake); |
Kyösti Mälkki | 0889e93 | 2019-08-18 07:40:43 +0300 | [diff] [blame] | 382 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 383 | timestamp_add_now(TS_INITRAM_END); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 384 | } |