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