blob: 83d44b140fa32a6da3cb1a1527e0e96aeee28e6e [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
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +02003#include <bootsplash.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -08004#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -05005#include <cbmem.h>
6#include <commonlib/fsp.h>
Subrata Banik44ffb5d2018-05-24 10:51:29 +05307#include <commonlib/stdlib.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -08008#include <console/console.h>
9#include <fsp/api.h>
10#include <fsp/util.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050011#include <program_loading.h>
Keith Shortc58e3bd2019-05-10 11:14:31 -060012#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080013#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080014#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070015#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020016#include <types.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +010017#include <mode_switch.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080018
19struct fsp_header fsps_hdr;
20
Subrata Banik33d9c4a2020-05-26 18:26:54 +053021struct 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 */
27void __weak platform_fsp_multi_phase_init_cb(uint32_t phase_index)
28{
29 /* Leave for the SoC/Mainboard to implement if necessary. */
30}
31
Subrata Banik33d9c4a2020-05-26 18:26:54 +053032/* FSP Specification < 2.2 has only 1 stage like FspSiliconInit. FSP specification >= 2.2
33 * has multiple stages as below.
34 */
35enum fsp_silicon_init_phases {
36 FSP_SILICON_INIT_API,
37 FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API,
38 FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API
39};
40
41static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, uint32_t status)
42{
43 uint8_t postcode;
44
45 /* Handle any reset request returned by FSP-S APIs */
46 fsp_handle_reset(status);
47
48 if (status == FSP_SUCCESS)
49 return;
50 /* Handle all other errors returned by FSP-S APIs */
51 /* Assume video failure if attempted to initialize graphics */
52 if (CONFIG(RUN_FSP_GOP) && vbt_get())
53 postcode = POST_VIDEO_FAILURE;
54 else
55 postcode = POST_HW_INIT_FAILURE; /* else generic */
56
57 switch (phases) {
58 case FSP_SILICON_INIT_API:
59 die_with_post_code(postcode, "FspSiliconInit returned with error 0x%08x\n",
60 status);
61 break;
62 case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API:
63 printk(BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases returned 0x%08x\n",
64 status);
65 break;
66 case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API:
67 printk(BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase returned 0x%08x\n",
68 status);
69 break;
70 default:
71 break;
72 }
73}
74
Subrata Banik298b3592021-09-14 12:38:08 +053075bool fsp_is_multi_phase_init_enabled(void)
76{
77 return CONFIG(FSPS_USE_MULTI_PHASE_INIT) &&
78 (fsps_hdr.multi_phase_si_init_entry_offset != 0);
79}
80
81static void fsp_fill_common_arch_params(FSPS_UPD *supd)
82{
83#if CONFIG(FSPS_HAS_ARCH_UPD)
84 FSPS_ARCH_UPD *s_arch_cfg = &supd->FspsArchUpd;
85 s_arch_cfg->EnableMultiPhaseSiliconInit = fsp_is_multi_phase_init_enabled();
86#endif
87}
88
Lee Leahy9671faa2016-07-24 18:18:52 -070089static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080090{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053091 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080092 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070093 uint32_t status;
Subrata Banik33d9c4a2020-05-26 18:26:54 +053094 fsp_multi_phase_si_init_fn multi_phase_si_init;
95 struct fsp_multi_phase_params multi_phase_params;
96 struct fsp_multi_phase_get_number_of_phases_params multi_phase_get_number;
Andrey Petrov42c4e882016-02-25 14:17:45 -080097
Patrick Rudolph31218a42020-11-30 15:50:06 +010098 supd = (FSPS_UPD *) (uintptr_t)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080099
Felix Held88995982021-01-28 22:43:52 +0100100 fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800101
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600102 /* FSPS UPD and coreboot structure sizes should match. However, enforcing the exact
103 * match mandates simultaneous updates to coreboot and FSP repos. Allow coreboot
104 * to proceed if its UPD structure is smaller than FSP one to enable staggered UPD
105 * update process on both sides. The mismatch indicates a temporary build problem,
106 * don't leave it like this as FSP default settings can be bad choices for coreboot.
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600107 */
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600108 if (!hdr->cfg_region_size || hdr->cfg_region_size < sizeof(FSPS_UPD))
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600109 die_with_post_code(POST_INVALID_VENDOR_BINARY,
110 "Invalid FSPS UPD region\n");
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600111 else if (hdr->cfg_region_size > sizeof(FSPS_UPD))
112 printk(BIOS_ERR, "FSP and coreboot are out of sync! FSPS UPD size > coreboot\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530113
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600114 upd = xmalloc(hdr->cfg_region_size);
115
116 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800117
Subrata Banik298b3592021-09-14 12:38:08 +0530118 /* Fill common settings on behalf of chipset. */
119 if (CONFIG(FSPS_HAS_ARCH_UPD))
120 fsp_fill_common_arch_params(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800121 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530122 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800123
Wim Vervoornd1371502019-12-17 14:10:16 +0100124 /* Populate logo related entries */
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200125 if (CONFIG(BMP_LOGO))
126 soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100127
Lee Leahy672df162016-07-24 18:21:13 -0700128 /* Call SiliconInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100129 silicon_init = (void *) (uintptr_t)(hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700130 hdr->silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530131 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -0700132
133 timestamp_add_now(TS_FSP_SILICON_INIT_START);
134 post_code(POST_FSP_SILICON_INIT);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100135
Patrick Rudolph31218a42020-11-30 15:50:06 +0100136 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +0100137 status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd);
138 else
139 status = silicon_init(upd);
140
Raul E Rangel43e993b2021-06-29 13:09:55 -0600141 printk(BIOS_INFO, "FSPS returned %x\n", status);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100142
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700143 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +0530144 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700145
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200146 if (CONFIG(BMP_LOGO))
147 bmp_release_logo();
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100148
Lee Leahy672df162016-07-24 18:21:13 -0700149 fsp_debug_after_silicon_init(status);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530150 fsps_return_value_handler(FSP_SILICON_INIT_API, status);
Aaron Durbin35d42c72016-07-18 12:41:09 -0500151
Subrata Banik96b32f12020-07-31 12:09:11 +0530152 /* Reinitialize CPUs if FSP-S has done MP Init */
153 if (CONFIG(USE_INTEL_FSP_MP_INIT))
154 do_mpinit_after_fsp();
155
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530156 if (!CONFIG(PLATFORM_USES_FSP2_2))
157 return;
Marshall Dawson7a9e8942019-10-17 07:58:27 -0600158
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530159 /* Check if SoC user would like to call Multi Phase Init */
Subrata Banik298b3592021-09-14 12:38:08 +0530160 if (!fsp_is_multi_phase_init_enabled())
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530161 return;
162
163 /* Call MultiPhaseSiInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100164 multi_phase_si_init = (void *) (uintptr_t)(hdr->image_base +
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530165 hdr->multi_phase_si_init_entry_offset);
166
167 /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */
168 if (multi_phase_si_init == NULL)
169 return;
170
171 post_code(POST_FSP_MULTI_PHASE_SI_INIT_ENTRY);
172 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START);
173 /* Get NumberOfPhases Value */
174 multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES;
175 multi_phase_params.phase_index = 0;
176 multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number;
177 status = multi_phase_si_init(&multi_phase_params);
178 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status);
179
180 /* Execute Multi Phase Execution */
Angel Ponsfd63e112021-09-08 11:52:09 +0200181 for (uint32_t i = 1; i <= multi_phase_get_number.number_of_phases; i++) {
182 printk(BIOS_SPEW, "Executing Phase %u of FspMultiPhaseSiInit\n", i);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530183 /*
184 * Give SoC/mainboard a chance to perform any operation before
185 * Multi Phase Execution
186 */
187 platform_fsp_multi_phase_init_cb(i);
188
189 multi_phase_params.multi_phase_action = EXECUTE_PHASE;
190 multi_phase_params.phase_index = i;
191 multi_phase_params.multi_phase_param_ptr = NULL;
192 status = multi_phase_si_init(&multi_phase_params);
193 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700194 }
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530195 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END);
196 post_code(POST_FSP_MULTI_PHASE_SI_INIT_EXIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800197}
198
Julius Werner8205ce62021-03-10 17:25:01 -0800199static void *fsps_allocator(void *arg_unused, size_t size, const union cbfs_mdata *mdata_unused)
Aaron Durbina85febc2020-05-15 15:09:10 -0600200{
Julius Werner8205ce62021-03-10 17:25:01 -0800201 return cbmem_add(CBMEM_ID_REFCODE, size);
Aaron Durbina85febc2020-05-15 15:09:10 -0600202}
203
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200204void fsps_load(void)
Andrey Petrov42c4e882016-02-25 14:17:45 -0800205{
Aaron Durbina85febc2020-05-15 15:09:10 -0600206 struct fsp_load_descriptor fspld = {
207 .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS),
Julius Werner8205ce62021-03-10 17:25:01 -0800208 .alloc = fsps_allocator,
Aaron Durbina85febc2020-05-15 15:09:10 -0600209 };
210 struct prog *fsps = &fspld.fsp_prog;
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800211 static int load_done;
212
213 if (load_done)
214 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800215
Kyösti Mälkkie0165fb2021-01-09 13:30:57 +0200216 if (resume_from_stage_cache()) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800217 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
Aaron Durbina85febc2020-05-15 15:09:10 -0600218 stage_cache_load_stage(STAGE_REFCODE, fsps);
Julius Werner43c9d702021-04-12 17:00:16 -0700219 if (fsp_validate_component(&fsps_hdr, prog_start(fsps), prog_size(fsps)))
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800220 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800221 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800222 return;
223 }
224
Aaron Durbina85febc2020-05-15 15:09:10 -0600225 if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS)
226 die("FSP-S failed to load\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500227
Aaron Durbina85febc2020-05-15 15:09:10 -0600228 stage_cache_add(STAGE_REFCODE, fsps);
Aaron Durbin32ac0182016-07-18 00:35:42 -0500229
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800230 load_done = 1;
231}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500232
Raul E Rangel15928462021-11-05 10:29:24 -0600233void preload_fsps(void)
234{
235 if (!CONFIG(CBFS_PRELOAD))
236 return;
237
238 printk(BIOS_DEBUG, "Preloading %s\n", CONFIG_FSP_S_CBFS);
239 cbfs_preload(CONFIG_FSP_S_CBFS);
240}
241
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200242void fsp_silicon_init(void)
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800243{
Martin Roth146508d2021-04-30 16:45:08 -0600244 timestamp_add_now(TS_FSP_SILICON_INIT_LOAD);
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200245 fsps_load();
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800246 do_silicon_init(&fsps_hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800247}
Wim Vervoornd1371502019-12-17 14:10:16 +0100248
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200249__weak void soc_load_logo(FSPS_UPD *supd) { }