blob: 53c962649a9bd843669f200a39002e18699d8fac [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
32int __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 */
40enum 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
46static 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 Leahy9671faa2016-07-24 18:18:52 -070080static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080081{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053082 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080083 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070084 uint32_t status;
Subrata Banik33d9c4a2020-05-26 18:26:54 +053085 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 Petrov42c4e882016-02-25 14:17:45 -080088
Patrick Rudolph31218a42020-11-30 15:50:06 +010089 supd = (FSPS_UPD *) (uintptr_t)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080090
Felix Held88995982021-01-28 22:43:52 +010091 fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE);
Andrey Petrov42c4e882016-02-25 14:17:45 -080092
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -060093 /* FSPS UPD and coreboot structure sizes should match. However, enforcing the exact
94 * match mandates simultaneous updates to coreboot and FSP repos. Allow coreboot
95 * to proceed if its UPD structure is smaller than FSP one to enable staggered UPD
96 * update process on both sides. The mismatch indicates a temporary build problem,
97 * don't leave it like this as FSP default settings can be bad choices for coreboot.
Marshall Dawson71dbcf12019-09-11 14:02:34 -060098 */
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -060099 if (!hdr->cfg_region_size || hdr->cfg_region_size < sizeof(FSPS_UPD))
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600100 die_with_post_code(POST_INVALID_VENDOR_BINARY,
101 "Invalid FSPS UPD region\n");
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600102 else if (hdr->cfg_region_size > sizeof(FSPS_UPD))
103 printk(BIOS_ERR, "FSP and coreboot are out of sync! FSPS UPD size > coreboot\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530104
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600105 upd = xmalloc(hdr->cfg_region_size);
106
107 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800108
109 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530110 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800111
Wim Vervoornd1371502019-12-17 14:10:16 +0100112 /* Populate logo related entries */
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200113 if (CONFIG(BMP_LOGO))
114 soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100115
Lee Leahy672df162016-07-24 18:21:13 -0700116 /* Call SiliconInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100117 silicon_init = (void *) (uintptr_t)(hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700118 hdr->silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530119 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -0700120
121 timestamp_add_now(TS_FSP_SILICON_INIT_START);
122 post_code(POST_FSP_SILICON_INIT);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100123
Patrick Rudolph31218a42020-11-30 15:50:06 +0100124 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +0100125 status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd);
126 else
127 status = silicon_init(upd);
128
129 printk(BIOS_ERR, "FSPS returned %x\n", status);
130
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700131 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +0530132 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700133
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200134 if (CONFIG(BMP_LOGO))
135 bmp_release_logo();
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100136
Lee Leahy672df162016-07-24 18:21:13 -0700137 fsp_debug_after_silicon_init(status);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530138 fsps_return_value_handler(FSP_SILICON_INIT_API, status);
Aaron Durbin35d42c72016-07-18 12:41:09 -0500139
Subrata Banik96b32f12020-07-31 12:09:11 +0530140 /* Reinitialize CPUs if FSP-S has done MP Init */
141 if (CONFIG(USE_INTEL_FSP_MP_INIT))
142 do_mpinit_after_fsp();
143
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530144 if (!CONFIG(PLATFORM_USES_FSP2_2))
145 return;
Marshall Dawson7a9e8942019-10-17 07:58:27 -0600146
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530147 /* Check if SoC user would like to call Multi Phase Init */
148 if (!soc_fsp_multi_phase_init_is_enable())
149 return;
150
151 /* Call MultiPhaseSiInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100152 multi_phase_si_init = (void *) (uintptr_t)(hdr->image_base +
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530153 hdr->multi_phase_si_init_entry_offset);
154
155 /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */
156 if (multi_phase_si_init == NULL)
157 return;
158
159 post_code(POST_FSP_MULTI_PHASE_SI_INIT_ENTRY);
160 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START);
161 /* Get NumberOfPhases Value */
162 multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES;
163 multi_phase_params.phase_index = 0;
164 multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number;
165 status = multi_phase_si_init(&multi_phase_params);
166 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status);
167
168 /* Execute Multi Phase Execution */
169 for (int i = 1; i <= multi_phase_get_number.number_of_phases; i++) {
170 printk(BIOS_SPEW, "Executing Phase %d of FspMultiPhaseSiInit\n", i);
171 /*
172 * Give SoC/mainboard a chance to perform any operation before
173 * Multi Phase Execution
174 */
175 platform_fsp_multi_phase_init_cb(i);
176
177 multi_phase_params.multi_phase_action = EXECUTE_PHASE;
178 multi_phase_params.phase_index = i;
179 multi_phase_params.multi_phase_param_ptr = NULL;
180 status = multi_phase_si_init(&multi_phase_params);
181 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700182 }
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530183 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END);
184 post_code(POST_FSP_MULTI_PHASE_SI_INIT_EXIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800185}
186
Julius Werner8205ce62021-03-10 17:25:01 -0800187static void *fsps_allocator(void *arg_unused, size_t size, const union cbfs_mdata *mdata_unused)
Aaron Durbina85febc2020-05-15 15:09:10 -0600188{
Julius Werner8205ce62021-03-10 17:25:01 -0800189 return cbmem_add(CBMEM_ID_REFCODE, size);
Aaron Durbina85febc2020-05-15 15:09:10 -0600190}
191
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200192void fsps_load(void)
Andrey Petrov42c4e882016-02-25 14:17:45 -0800193{
Aaron Durbina85febc2020-05-15 15:09:10 -0600194 struct fsp_load_descriptor fspld = {
195 .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS),
Julius Werner8205ce62021-03-10 17:25:01 -0800196 .alloc = fsps_allocator,
Aaron Durbina85febc2020-05-15 15:09:10 -0600197 };
198 struct prog *fsps = &fspld.fsp_prog;
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800199 static int load_done;
200
201 if (load_done)
202 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800203
Kyösti Mälkkie0165fb2021-01-09 13:30:57 +0200204 if (resume_from_stage_cache()) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800205 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
Aaron Durbina85febc2020-05-15 15:09:10 -0600206 stage_cache_load_stage(STAGE_REFCODE, fsps);
Julius Werner43c9d702021-04-12 17:00:16 -0700207 if (fsp_validate_component(&fsps_hdr, prog_start(fsps), prog_size(fsps)))
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800208 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800209 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800210 return;
211 }
212
Aaron Durbina85febc2020-05-15 15:09:10 -0600213 if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS)
214 die("FSP-S failed to load\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500215
Aaron Durbina85febc2020-05-15 15:09:10 -0600216 stage_cache_add(STAGE_REFCODE, fsps);
Aaron Durbin32ac0182016-07-18 00:35:42 -0500217
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800218 load_done = 1;
219}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500220
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200221void fsp_silicon_init(void)
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800222{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200223 fsps_load();
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800224 do_silicon_init(&fsps_hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800225}
Wim Vervoornd1371502019-12-17 14:10:16 +0100226
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200227__weak void soc_load_logo(FSPS_UPD *supd) { }