blob: 72a30c51e33f2163c619753a70c8ffb8a9f73918 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrov42c4e882016-02-25 14:17:45 -08002
Arthur Heymansfdf6d122022-05-17 13:07:30 +02003#include <arch/null_breakpoint.h>
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +02004#include <bootsplash.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -08005#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -05006#include <cbmem.h>
7#include <commonlib/fsp.h>
Subrata Banik44ffb5d2018-05-24 10:51:29 +05308#include <commonlib/stdlib.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -08009#include <console/console.h>
10#include <fsp/api.h>
11#include <fsp/util.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050012#include <program_loading.h>
Subrata Banik25d10022023-04-26 16:32:29 +053013#include <soc/intel/common/reset.h>
Keith Shortc58e3bd2019-05-10 11:14:31 -060014#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080015#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080016#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070017#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020018#include <types.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +010019#include <mode_switch.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080020
21struct fsp_header fsps_hdr;
22
Subrata Banik33d9c4a2020-05-26 18:26:54 +053023struct fsp_multi_phase_get_number_of_phases_params {
24 uint32_t number_of_phases;
25 uint32_t phases_executed;
26};
27
28/* Callbacks for SoC/Mainboard specific overrides */
29void __weak platform_fsp_multi_phase_init_cb(uint32_t phase_index)
30{
31 /* Leave for the SoC/Mainboard to implement if necessary. */
32}
33
Subrata Banik33d9c4a2020-05-26 18:26:54 +053034/* FSP Specification < 2.2 has only 1 stage like FspSiliconInit. FSP specification >= 2.2
35 * has multiple stages as below.
36 */
37enum fsp_silicon_init_phases {
38 FSP_SILICON_INIT_API,
39 FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API,
40 FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API
41};
42
43static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, uint32_t status)
44{
45 uint8_t postcode;
46
47 /* Handle any reset request returned by FSP-S APIs */
48 fsp_handle_reset(status);
49
50 if (status == FSP_SUCCESS)
51 return;
52 /* Handle all other errors returned by FSP-S APIs */
53 /* Assume video failure if attempted to initialize graphics */
54 if (CONFIG(RUN_FSP_GOP) && vbt_get())
lilacious40cb3fe2023-06-21 23:24:14 +020055 postcode = POSTCODE_VIDEO_FAILURE;
Subrata Banik33d9c4a2020-05-26 18:26:54 +053056 else
lilacious40cb3fe2023-06-21 23:24:14 +020057 postcode = POSTCODE_HW_INIT_FAILURE; /* else generic */
Subrata Banik33d9c4a2020-05-26 18:26:54 +053058
59 switch (phases) {
60 case FSP_SILICON_INIT_API:
61 die_with_post_code(postcode, "FspSiliconInit returned with error 0x%08x\n",
62 status);
63 break;
64 case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API:
65 printk(BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases returned 0x%08x\n",
66 status);
67 break;
68 case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API:
69 printk(BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase returned 0x%08x\n",
70 status);
71 break;
72 default:
73 break;
74 }
75}
76
Subrata Banik298b3592021-09-14 12:38:08 +053077bool fsp_is_multi_phase_init_enabled(void)
78{
79 return CONFIG(FSPS_USE_MULTI_PHASE_INIT) &&
Julian Schroeder8a576f62021-11-02 16:32:28 -050080 (fsps_hdr.fsp_multi_phase_si_init_entry_offset != 0);
Subrata Banik298b3592021-09-14 12:38:08 +053081}
82
83static void fsp_fill_common_arch_params(FSPS_UPD *supd)
84{
85#if CONFIG(FSPS_HAS_ARCH_UPD)
86 FSPS_ARCH_UPD *s_arch_cfg = &supd->FspsArchUpd;
87 s_arch_cfg->EnableMultiPhaseSiliconInit = fsp_is_multi_phase_init_enabled();
88#endif
89}
90
Lee Leahy9671faa2016-07-24 18:18:52 -070091static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080092{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053093 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080094 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070095 uint32_t status;
Subrata Banik33d9c4a2020-05-26 18:26:54 +053096 fsp_multi_phase_si_init_fn multi_phase_si_init;
97 struct fsp_multi_phase_params multi_phase_params;
98 struct fsp_multi_phase_get_number_of_phases_params multi_phase_get_number;
Andrey Petrov42c4e882016-02-25 14:17:45 -080099
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100100 supd = (FSPS_UPD *)(uintptr_t)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800101
Felix Held88995982021-01-28 22:43:52 +0100102 fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800103
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600104 /* FSPS UPD and coreboot structure sizes should match. However, enforcing the exact
105 * match mandates simultaneous updates to coreboot and FSP repos. Allow coreboot
106 * to proceed if its UPD structure is smaller than FSP one to enable staggered UPD
107 * update process on both sides. The mismatch indicates a temporary build problem,
108 * don't leave it like this as FSP default settings can be bad choices for coreboot.
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600109 */
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600110 if (!hdr->cfg_region_size || hdr->cfg_region_size < sizeof(FSPS_UPD))
lilacious40cb3fe2023-06-21 23:24:14 +0200111 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600112 "Invalid FSPS UPD region\n");
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600113 else if (hdr->cfg_region_size > sizeof(FSPS_UPD))
114 printk(BIOS_ERR, "FSP and coreboot are out of sync! FSPS UPD size > coreboot\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530115
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600116 upd = xmalloc(hdr->cfg_region_size);
117
118 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800119
Subrata Banik298b3592021-09-14 12:38:08 +0530120 /* Fill common settings on behalf of chipset. */
121 if (CONFIG(FSPS_HAS_ARCH_UPD))
122 fsp_fill_common_arch_params(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800123 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530124 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800125
Wim Vervoornd1371502019-12-17 14:10:16 +0100126 /* Populate logo related entries */
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200127 if (CONFIG(BMP_LOGO))
128 soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100129
Lee Leahy672df162016-07-24 18:21:13 -0700130 /* Call SiliconInit */
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100131 silicon_init = (void *)(uintptr_t)(hdr->image_base +
Julian Schroeder8a576f62021-11-02 16:32:28 -0500132 hdr->fsp_silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530133 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -0700134
135 timestamp_add_now(TS_FSP_SILICON_INIT_START);
lilacious40cb3fe2023-06-21 23:24:14 +0200136 post_code(POSTCODE_FSP_SILICON_INIT);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100137
Arthur Heymansfdf6d122022-05-17 13:07:30 +0200138 /* FSP disables the interrupt handler so remove debug exceptions temporarily */
139 null_breakpoint_disable();
Patrick Rudolph31218a42020-11-30 15:50:06 +0100140 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +0100141 status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd);
142 else
143 status = silicon_init(upd);
Arthur Heymansfdf6d122022-05-17 13:07:30 +0200144 null_breakpoint_init();
Patrick Rudolph40beb362020-12-01 10:08:38 +0100145
Raul E Rangel43e993b2021-06-29 13:09:55 -0600146 printk(BIOS_INFO, "FSPS returned %x\n", status);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100147
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700148 timestamp_add_now(TS_FSP_SILICON_INIT_END);
lilacious40cb3fe2023-06-21 23:24:14 +0200149 post_code(POSTCODE_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700150
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200151 if (CONFIG(BMP_LOGO))
152 bmp_release_logo();
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100153
Lee Leahy672df162016-07-24 18:21:13 -0700154 fsp_debug_after_silicon_init(status);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530155 fsps_return_value_handler(FSP_SILICON_INIT_API, status);
Aaron Durbin35d42c72016-07-18 12:41:09 -0500156
Subrata Banik96b32f12020-07-31 12:09:11 +0530157 /* Reinitialize CPUs if FSP-S has done MP Init */
158 if (CONFIG(USE_INTEL_FSP_MP_INIT))
159 do_mpinit_after_fsp();
160
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530161 if (!CONFIG(PLATFORM_USES_FSP2_2))
162 return;
Marshall Dawson7a9e8942019-10-17 07:58:27 -0600163
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530164 /* Check if SoC user would like to call Multi Phase Init */
Subrata Banik298b3592021-09-14 12:38:08 +0530165 if (!fsp_is_multi_phase_init_enabled())
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530166 return;
167
168 /* Call MultiPhaseSiInit */
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100169 multi_phase_si_init = (void *)(uintptr_t)(hdr->image_base +
Julian Schroeder8a576f62021-11-02 16:32:28 -0500170 hdr->fsp_multi_phase_si_init_entry_offset);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530171
172 /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */
173 if (multi_phase_si_init == NULL)
174 return;
175
lilacious40cb3fe2023-06-21 23:24:14 +0200176 post_code(POSTCODE_FSP_MULTI_PHASE_SI_INIT_ENTRY);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530177 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START);
178 /* Get NumberOfPhases Value */
179 multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES;
180 multi_phase_params.phase_index = 0;
181 multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number;
182 status = multi_phase_si_init(&multi_phase_params);
183 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status);
184
185 /* Execute Multi Phase Execution */
Angel Ponsfd63e112021-09-08 11:52:09 +0200186 for (uint32_t i = 1; i <= multi_phase_get_number.number_of_phases; i++) {
187 printk(BIOS_SPEW, "Executing Phase %u of FspMultiPhaseSiInit\n", i);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530188 /*
189 * Give SoC/mainboard a chance to perform any operation before
190 * Multi Phase Execution
191 */
192 platform_fsp_multi_phase_init_cb(i);
193
194 multi_phase_params.multi_phase_action = EXECUTE_PHASE;
195 multi_phase_params.phase_index = i;
196 multi_phase_params.multi_phase_param_ptr = NULL;
197 status = multi_phase_si_init(&multi_phase_params);
Subrata Banik25d10022023-04-26 16:32:29 +0530198 if (CONFIG(FSP_MULTIPHASE_SI_INIT_RETURN_BROKEN))
199 status = fsp_get_pch_reset_status();
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530200 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700201 }
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530202 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END);
lilacious40cb3fe2023-06-21 23:24:14 +0200203 post_code(POSTCODE_FSP_MULTI_PHASE_SI_INIT_EXIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800204}
205
Julius Werner8205ce62021-03-10 17:25:01 -0800206static void *fsps_allocator(void *arg_unused, size_t size, const union cbfs_mdata *mdata_unused)
Aaron Durbina85febc2020-05-15 15:09:10 -0600207{
Julius Werner8205ce62021-03-10 17:25:01 -0800208 return cbmem_add(CBMEM_ID_REFCODE, size);
Aaron Durbina85febc2020-05-15 15:09:10 -0600209}
210
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200211void fsps_load(void)
Andrey Petrov42c4e882016-02-25 14:17:45 -0800212{
Aaron Durbina85febc2020-05-15 15:09:10 -0600213 struct fsp_load_descriptor fspld = {
214 .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS),
Julius Werner8205ce62021-03-10 17:25:01 -0800215 .alloc = fsps_allocator,
Aaron Durbina85febc2020-05-15 15:09:10 -0600216 };
217 struct prog *fsps = &fspld.fsp_prog;
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800218 static int load_done;
219
220 if (load_done)
221 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800222
Reka Norman8baa3712022-09-05 15:33:39 +1000223 timestamp_add_now(TS_FSP_SILICON_INIT_LOAD);
224
Kyösti Mälkkie0165fb2021-01-09 13:30:57 +0200225 if (resume_from_stage_cache()) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800226 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
Aaron Durbina85febc2020-05-15 15:09:10 -0600227 stage_cache_load_stage(STAGE_REFCODE, fsps);
Julius Werner43c9d702021-04-12 17:00:16 -0700228 if (fsp_validate_component(&fsps_hdr, prog_start(fsps), prog_size(fsps)))
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800229 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800230 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800231 return;
232 }
233
Aaron Durbina85febc2020-05-15 15:09:10 -0600234 if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS)
235 die("FSP-S failed to load\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500236
Aaron Durbina85febc2020-05-15 15:09:10 -0600237 stage_cache_add(STAGE_REFCODE, fsps);
Aaron Durbin32ac0182016-07-18 00:35:42 -0500238
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800239 load_done = 1;
240}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500241
Raul E Rangel15928462021-11-05 10:29:24 -0600242void preload_fsps(void)
243{
244 if (!CONFIG(CBFS_PRELOAD))
245 return;
246
247 printk(BIOS_DEBUG, "Preloading %s\n", CONFIG_FSP_S_CBFS);
248 cbfs_preload(CONFIG_FSP_S_CBFS);
249}
250
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200251void fsp_silicon_init(void)
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800252{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200253 fsps_load();
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800254 do_silicon_init(&fsps_hdr);
Subrata Banik6de1d9f2022-03-20 19:50:38 +0530255
256 if (CONFIG(DISPLAY_FSP_TIMESTAMPS))
257 fsp_display_timestamp();
Andrey Petrov42c4e882016-02-25 14:17:45 -0800258}
Wim Vervoornd1371502019-12-17 14:10:16 +0100259
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200260__weak void soc_load_logo(FSPS_UPD *supd) { }