Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 2 | |
Kyösti Mälkki | 4949a3d | 2021-01-09 20:38:43 +0200 | [diff] [blame] | 3 | #include <bootsplash.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 4 | #include <cbfs.h> |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 5 | #include <cbmem.h> |
| 6 | #include <commonlib/fsp.h> |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 7 | #include <commonlib/stdlib.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 8 | #include <console/console.h> |
| 9 | #include <fsp/api.h> |
| 10 | #include <fsp/util.h> |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 11 | #include <program_loading.h> |
Keith Short | c58e3bd | 2019-05-10 11:14:31 -0600 | [diff] [blame] | 12 | #include <soc/intel/common/vbt.h> |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 13 | #include <stage_cache.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 14 | #include <string.h> |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 15 | #include <timestamp.h> |
Elyes HAOUAS | bd1683d | 2019-05-15 21:05:37 +0200 | [diff] [blame] | 16 | #include <types.h> |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 17 | #include <mode_switch.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 18 | |
| 19 | struct fsp_header fsps_hdr; |
| 20 | |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 21 | struct fsp_multi_phase_get_number_of_phases_params { |
| 22 | uint32_t number_of_phases; |
| 23 | uint32_t phases_executed; |
| 24 | }; |
| 25 | |
| 26 | /* Callbacks for SoC/Mainboard specific overrides */ |
| 27 | void __weak platform_fsp_multi_phase_init_cb(uint32_t phase_index) |
| 28 | { |
| 29 | /* Leave for the SoC/Mainboard to implement if necessary. */ |
| 30 | } |
| 31 | |
| 32 | int __weak soc_fsp_multi_phase_init_is_enable(void) |
| 33 | { |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | /* FSP Specification < 2.2 has only 1 stage like FspSiliconInit. FSP specification >= 2.2 |
| 38 | * has multiple stages as below. |
| 39 | */ |
| 40 | enum fsp_silicon_init_phases { |
| 41 | FSP_SILICON_INIT_API, |
| 42 | FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, |
| 43 | FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API |
| 44 | }; |
| 45 | |
| 46 | static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, uint32_t status) |
| 47 | { |
| 48 | uint8_t postcode; |
| 49 | |
| 50 | /* Handle any reset request returned by FSP-S APIs */ |
| 51 | fsp_handle_reset(status); |
| 52 | |
| 53 | if (status == FSP_SUCCESS) |
| 54 | return; |
| 55 | /* Handle all other errors returned by FSP-S APIs */ |
| 56 | /* Assume video failure if attempted to initialize graphics */ |
| 57 | if (CONFIG(RUN_FSP_GOP) && vbt_get()) |
| 58 | postcode = POST_VIDEO_FAILURE; |
| 59 | else |
| 60 | postcode = POST_HW_INIT_FAILURE; /* else generic */ |
| 61 | |
| 62 | switch (phases) { |
| 63 | case FSP_SILICON_INIT_API: |
| 64 | die_with_post_code(postcode, "FspSiliconInit returned with error 0x%08x\n", |
| 65 | status); |
| 66 | break; |
| 67 | case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API: |
| 68 | printk(BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases returned 0x%08x\n", |
| 69 | status); |
| 70 | break; |
| 71 | case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API: |
| 72 | printk(BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase returned 0x%08x\n", |
| 73 | status); |
| 74 | break; |
| 75 | default: |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 80 | static void do_silicon_init(struct fsp_header *hdr) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 81 | { |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 82 | FSPS_UPD *upd, *supd; |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 83 | fsp_silicon_init_fn silicon_init; |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 84 | uint32_t status; |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 85 | fsp_multi_phase_si_init_fn multi_phase_si_init; |
| 86 | struct fsp_multi_phase_params multi_phase_params; |
| 87 | struct fsp_multi_phase_get_number_of_phases_params multi_phase_get_number; |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 88 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 89 | supd = (FSPS_UPD *) (uintptr_t)(hdr->cfg_region_offset + hdr->image_base); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 90 | |
Felix Held | 8899598 | 2021-01-28 22:43:52 +0100 | [diff] [blame] | 91 | fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 92 | |
Marshall Dawson | 71dbcf1 | 2019-09-11 14:02:34 -0600 | [diff] [blame] | 93 | /* Disallow invalid config regions. Default settings are likely bad |
| 94 | * choices for coreboot, and different sized UPD from what the region |
| 95 | * allows is potentially a build problem. |
| 96 | */ |
| 97 | if (!hdr->cfg_region_size || hdr->cfg_region_size != sizeof(FSPS_UPD)) |
| 98 | die_with_post_code(POST_INVALID_VENDOR_BINARY, |
| 99 | "Invalid FSPS UPD region\n"); |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 100 | |
Marshall Dawson | 71dbcf1 | 2019-09-11 14:02:34 -0600 | [diff] [blame] | 101 | upd = xmalloc(hdr->cfg_region_size); |
| 102 | |
| 103 | memcpy(upd, supd, hdr->cfg_region_size); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 104 | |
| 105 | /* Give SoC/mainboard a chance to populate entries */ |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 106 | platform_fsp_silicon_init_params_cb(upd); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 107 | |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 108 | /* Populate logo related entries */ |
Kyösti Mälkki | 4949a3d | 2021-01-09 20:38:43 +0200 | [diff] [blame] | 109 | if (CONFIG(BMP_LOGO)) |
| 110 | soc_load_logo(upd); |
Wim Vervoorn | cbc878d2 | 2019-11-28 14:45:12 +0100 | [diff] [blame] | 111 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 112 | /* Call SiliconInit */ |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 113 | silicon_init = (void *) (uintptr_t)(hdr->image_base + |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 114 | hdr->silicon_init_entry_offset); |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 115 | fsp_debug_before_silicon_init(silicon_init, supd, upd); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 116 | |
| 117 | timestamp_add_now(TS_FSP_SILICON_INIT_START); |
| 118 | post_code(POST_FSP_SILICON_INIT); |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 119 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 120 | if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32)) |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 121 | status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd); |
| 122 | else |
| 123 | status = silicon_init(upd); |
| 124 | |
| 125 | printk(BIOS_ERR, "FSPS returned %x\n", status); |
| 126 | |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 127 | timestamp_add_now(TS_FSP_SILICON_INIT_END); |
Subrata Banik | 0755ab9 | 2017-07-12 15:31:06 +0530 | [diff] [blame] | 128 | post_code(POST_FSP_SILICON_EXIT); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 129 | |
Kyösti Mälkki | 4949a3d | 2021-01-09 20:38:43 +0200 | [diff] [blame] | 130 | if (CONFIG(BMP_LOGO)) |
| 131 | bmp_release_logo(); |
Wim Vervoorn | cbc878d2 | 2019-11-28 14:45:12 +0100 | [diff] [blame] | 132 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 133 | fsp_debug_after_silicon_init(status); |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 134 | fsps_return_value_handler(FSP_SILICON_INIT_API, status); |
Aaron Durbin | 35d42c7 | 2016-07-18 12:41:09 -0500 | [diff] [blame] | 135 | |
Subrata Banik | 96b32f1 | 2020-07-31 12:09:11 +0530 | [diff] [blame] | 136 | /* Reinitialize CPUs if FSP-S has done MP Init */ |
| 137 | if (CONFIG(USE_INTEL_FSP_MP_INIT)) |
| 138 | do_mpinit_after_fsp(); |
| 139 | |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 140 | if (!CONFIG(PLATFORM_USES_FSP2_2)) |
| 141 | return; |
Marshall Dawson | 7a9e894 | 2019-10-17 07:58:27 -0600 | [diff] [blame] | 142 | |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 143 | /* Check if SoC user would like to call Multi Phase Init */ |
| 144 | if (!soc_fsp_multi_phase_init_is_enable()) |
| 145 | return; |
| 146 | |
| 147 | /* Call MultiPhaseSiInit */ |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 148 | multi_phase_si_init = (void *) (uintptr_t)(hdr->image_base + |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 149 | hdr->multi_phase_si_init_entry_offset); |
| 150 | |
| 151 | /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */ |
| 152 | if (multi_phase_si_init == NULL) |
| 153 | return; |
| 154 | |
| 155 | post_code(POST_FSP_MULTI_PHASE_SI_INIT_ENTRY); |
| 156 | timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START); |
| 157 | /* Get NumberOfPhases Value */ |
| 158 | multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES; |
| 159 | multi_phase_params.phase_index = 0; |
| 160 | multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number; |
| 161 | status = multi_phase_si_init(&multi_phase_params); |
| 162 | fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status); |
| 163 | |
| 164 | /* Execute Multi Phase Execution */ |
| 165 | for (int i = 1; i <= multi_phase_get_number.number_of_phases; i++) { |
| 166 | printk(BIOS_SPEW, "Executing Phase %d of FspMultiPhaseSiInit\n", i); |
| 167 | /* |
| 168 | * Give SoC/mainboard a chance to perform any operation before |
| 169 | * Multi Phase Execution |
| 170 | */ |
| 171 | platform_fsp_multi_phase_init_cb(i); |
| 172 | |
| 173 | multi_phase_params.multi_phase_action = EXECUTE_PHASE; |
| 174 | multi_phase_params.phase_index = i; |
| 175 | multi_phase_params.multi_phase_param_ptr = NULL; |
| 176 | status = multi_phase_si_init(&multi_phase_params); |
| 177 | fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 178 | } |
Subrata Banik | 33d9c4a | 2020-05-26 18:26:54 +0530 | [diff] [blame] | 179 | timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END); |
| 180 | post_code(POST_FSP_MULTI_PHASE_SI_INIT_EXIT); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame] | 183 | static int fsps_get_dest(const struct fsp_load_descriptor *fspld, void **dest, |
| 184 | size_t size, const struct region_device *source) |
| 185 | { |
| 186 | *dest = cbmem_add(CBMEM_ID_REFCODE, size); |
| 187 | |
| 188 | if (*dest == NULL) |
| 189 | return -1; |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 194 | void fsps_load(void) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 195 | { |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame] | 196 | struct fsp_load_descriptor fspld = { |
| 197 | .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS), |
| 198 | .get_destination = fsps_get_dest, |
| 199 | }; |
| 200 | struct prog *fsps = &fspld.fsp_prog; |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 201 | static int load_done; |
| 202 | |
| 203 | if (load_done) |
| 204 | return; |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 205 | |
Kyösti Mälkki | e0165fb | 2021-01-09 13:30:57 +0200 | [diff] [blame] | 206 | if (resume_from_stage_cache()) { |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n"); |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame] | 208 | stage_cache_load_stage(STAGE_REFCODE, fsps); |
| 209 | if (fsp_validate_component(&fsps_hdr, prog_rdev(fsps)) != CB_SUCCESS) |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 210 | die("On resume fsps header is invalid\n"); |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 211 | load_done = 1; |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame] | 215 | if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS) |
| 216 | die("FSP-S failed to load\n"); |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 217 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame] | 218 | stage_cache_add(STAGE_REFCODE, fsps); |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 219 | |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 220 | load_done = 1; |
| 221 | } |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 222 | |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 223 | void fsp_silicon_init(void) |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 224 | { |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 225 | fsps_load(); |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 226 | do_silicon_init(&fsps_hdr); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 227 | } |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 228 | |
Kyösti Mälkki | 4949a3d | 2021-01-09 20:38:43 +0200 | [diff] [blame] | 229 | __weak void soc_load_logo(FSPS_UPD *supd) { } |