blob: 87f77a2be6fc8bd61c5dd89a6fb6b563af13ce72 [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>
Keith Shortc58e3bd2019-05-10 11:14:31 -060013#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080014#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080015#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070016#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020017#include <types.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +010018#include <mode_switch.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080019
20struct fsp_header fsps_hdr;
21
Subrata Banik33d9c4a2020-05-26 18:26:54 +053022struct fsp_multi_phase_get_number_of_phases_params {
23 uint32_t number_of_phases;
24 uint32_t phases_executed;
25};
26
27/* Callbacks for SoC/Mainboard specific overrides */
28void __weak platform_fsp_multi_phase_init_cb(uint32_t phase_index)
29{
30 /* Leave for the SoC/Mainboard to implement if necessary. */
31}
32
Subrata Banik33d9c4a2020-05-26 18:26:54 +053033/* FSP Specification < 2.2 has only 1 stage like FspSiliconInit. FSP specification >= 2.2
34 * has multiple stages as below.
35 */
36enum fsp_silicon_init_phases {
37 FSP_SILICON_INIT_API,
38 FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API,
39 FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API
40};
41
42static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, uint32_t status)
43{
44 uint8_t postcode;
45
46 /* Handle any reset request returned by FSP-S APIs */
47 fsp_handle_reset(status);
48
49 if (status == FSP_SUCCESS)
50 return;
51 /* Handle all other errors returned by FSP-S APIs */
52 /* Assume video failure if attempted to initialize graphics */
53 if (CONFIG(RUN_FSP_GOP) && vbt_get())
54 postcode = POST_VIDEO_FAILURE;
55 else
56 postcode = POST_HW_INIT_FAILURE; /* else generic */
57
58 switch (phases) {
59 case FSP_SILICON_INIT_API:
60 die_with_post_code(postcode, "FspSiliconInit returned with error 0x%08x\n",
61 status);
62 break;
63 case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API:
64 printk(BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases returned 0x%08x\n",
65 status);
66 break;
67 case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API:
68 printk(BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase returned 0x%08x\n",
69 status);
70 break;
71 default:
72 break;
73 }
74}
75
Subrata Banik298b3592021-09-14 12:38:08 +053076bool fsp_is_multi_phase_init_enabled(void)
77{
78 return CONFIG(FSPS_USE_MULTI_PHASE_INIT) &&
Julian Schroeder8a576f62021-11-02 16:32:28 -050079 (fsps_hdr.fsp_multi_phase_si_init_entry_offset != 0);
Subrata Banik298b3592021-09-14 12:38:08 +053080}
81
82static void fsp_fill_common_arch_params(FSPS_UPD *supd)
83{
84#if CONFIG(FSPS_HAS_ARCH_UPD)
85 FSPS_ARCH_UPD *s_arch_cfg = &supd->FspsArchUpd;
86 s_arch_cfg->EnableMultiPhaseSiliconInit = fsp_is_multi_phase_init_enabled();
87#endif
88}
89
Lee Leahy9671faa2016-07-24 18:18:52 -070090static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080091{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053092 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080093 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070094 uint32_t status;
Subrata Banik33d9c4a2020-05-26 18:26:54 +053095 fsp_multi_phase_si_init_fn multi_phase_si_init;
96 struct fsp_multi_phase_params multi_phase_params;
97 struct fsp_multi_phase_get_number_of_phases_params multi_phase_get_number;
Andrey Petrov42c4e882016-02-25 14:17:45 -080098
Patrick Rudolph31218a42020-11-30 15:50:06 +010099 supd = (FSPS_UPD *) (uintptr_t)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800100
Felix Held88995982021-01-28 22:43:52 +0100101 fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800102
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600103 /* FSPS UPD and coreboot structure sizes should match. However, enforcing the exact
104 * match mandates simultaneous updates to coreboot and FSP repos. Allow coreboot
105 * to proceed if its UPD structure is smaller than FSP one to enable staggered UPD
106 * update process on both sides. The mismatch indicates a temporary build problem,
107 * don't leave it like this as FSP default settings can be bad choices for coreboot.
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600108 */
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600109 if (!hdr->cfg_region_size || hdr->cfg_region_size < sizeof(FSPS_UPD))
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600110 die_with_post_code(POST_INVALID_VENDOR_BINARY,
111 "Invalid FSPS UPD region\n");
Nikolai Vyssotski175e4c52021-02-11 18:25:43 -0600112 else if (hdr->cfg_region_size > sizeof(FSPS_UPD))
113 printk(BIOS_ERR, "FSP and coreboot are out of sync! FSPS UPD size > coreboot\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530114
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600115 upd = xmalloc(hdr->cfg_region_size);
116
117 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800118
Subrata Banik298b3592021-09-14 12:38:08 +0530119 /* Fill common settings on behalf of chipset. */
120 if (CONFIG(FSPS_HAS_ARCH_UPD))
121 fsp_fill_common_arch_params(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800122 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530123 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800124
Wim Vervoornd1371502019-12-17 14:10:16 +0100125 /* Populate logo related entries */
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200126 if (CONFIG(BMP_LOGO))
127 soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100128
Lee Leahy672df162016-07-24 18:21:13 -0700129 /* Call SiliconInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100130 silicon_init = (void *) (uintptr_t)(hdr->image_base +
Julian Schroeder8a576f62021-11-02 16:32:28 -0500131 hdr->fsp_silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530132 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -0700133
134 timestamp_add_now(TS_FSP_SILICON_INIT_START);
135 post_code(POST_FSP_SILICON_INIT);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100136
Arthur Heymansfdf6d122022-05-17 13:07:30 +0200137 /* FSP disables the interrupt handler so remove debug exceptions temporarily */
138 null_breakpoint_disable();
Patrick Rudolph31218a42020-11-30 15:50:06 +0100139 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +0100140 status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd);
141 else
142 status = silicon_init(upd);
Arthur Heymansfdf6d122022-05-17 13:07:30 +0200143 null_breakpoint_init();
Patrick Rudolph40beb362020-12-01 10:08:38 +0100144
Raul E Rangel43e993b2021-06-29 13:09:55 -0600145 printk(BIOS_INFO, "FSPS returned %x\n", status);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100146
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700147 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +0530148 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700149
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200150 if (CONFIG(BMP_LOGO))
151 bmp_release_logo();
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100152
Lee Leahy672df162016-07-24 18:21:13 -0700153 fsp_debug_after_silicon_init(status);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530154 fsps_return_value_handler(FSP_SILICON_INIT_API, status);
Aaron Durbin35d42c72016-07-18 12:41:09 -0500155
Subrata Banik96b32f12020-07-31 12:09:11 +0530156 /* Reinitialize CPUs if FSP-S has done MP Init */
157 if (CONFIG(USE_INTEL_FSP_MP_INIT))
158 do_mpinit_after_fsp();
159
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530160 if (!CONFIG(PLATFORM_USES_FSP2_2))
161 return;
Marshall Dawson7a9e8942019-10-17 07:58:27 -0600162
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530163 /* Check if SoC user would like to call Multi Phase Init */
Subrata Banik298b3592021-09-14 12:38:08 +0530164 if (!fsp_is_multi_phase_init_enabled())
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530165 return;
166
167 /* Call MultiPhaseSiInit */
Patrick Rudolph31218a42020-11-30 15:50:06 +0100168 multi_phase_si_init = (void *) (uintptr_t)(hdr->image_base +
Julian Schroeder8a576f62021-11-02 16:32:28 -0500169 hdr->fsp_multi_phase_si_init_entry_offset);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530170
171 /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */
172 if (multi_phase_si_init == NULL)
173 return;
174
175 post_code(POST_FSP_MULTI_PHASE_SI_INIT_ENTRY);
176 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START);
177 /* Get NumberOfPhases Value */
178 multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES;
179 multi_phase_params.phase_index = 0;
180 multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number;
181 status = multi_phase_si_init(&multi_phase_params);
182 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status);
183
184 /* Execute Multi Phase Execution */
Angel Ponsfd63e112021-09-08 11:52:09 +0200185 for (uint32_t i = 1; i <= multi_phase_get_number.number_of_phases; i++) {
186 printk(BIOS_SPEW, "Executing Phase %u of FspMultiPhaseSiInit\n", i);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530187 /*
188 * Give SoC/mainboard a chance to perform any operation before
189 * Multi Phase Execution
190 */
191 platform_fsp_multi_phase_init_cb(i);
192
193 multi_phase_params.multi_phase_action = EXECUTE_PHASE;
194 multi_phase_params.phase_index = i;
195 multi_phase_params.multi_phase_param_ptr = NULL;
196 status = multi_phase_si_init(&multi_phase_params);
197 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700198 }
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530199 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END);
200 post_code(POST_FSP_MULTI_PHASE_SI_INIT_EXIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800201}
202
Julius Werner8205ce62021-03-10 17:25:01 -0800203static void *fsps_allocator(void *arg_unused, size_t size, const union cbfs_mdata *mdata_unused)
Aaron Durbina85febc2020-05-15 15:09:10 -0600204{
Julius Werner8205ce62021-03-10 17:25:01 -0800205 return cbmem_add(CBMEM_ID_REFCODE, size);
Aaron Durbina85febc2020-05-15 15:09:10 -0600206}
207
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200208void fsps_load(void)
Andrey Petrov42c4e882016-02-25 14:17:45 -0800209{
Aaron Durbina85febc2020-05-15 15:09:10 -0600210 struct fsp_load_descriptor fspld = {
211 .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS),
Julius Werner8205ce62021-03-10 17:25:01 -0800212 .alloc = fsps_allocator,
Aaron Durbina85febc2020-05-15 15:09:10 -0600213 };
214 struct prog *fsps = &fspld.fsp_prog;
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800215 static int load_done;
216
217 if (load_done)
218 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800219
Reka Norman8baa3712022-09-05 15:33:39 +1000220 timestamp_add_now(TS_FSP_SILICON_INIT_LOAD);
221
Kyösti Mälkkie0165fb2021-01-09 13:30:57 +0200222 if (resume_from_stage_cache()) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800223 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
Aaron Durbina85febc2020-05-15 15:09:10 -0600224 stage_cache_load_stage(STAGE_REFCODE, fsps);
Julius Werner43c9d702021-04-12 17:00:16 -0700225 if (fsp_validate_component(&fsps_hdr, prog_start(fsps), prog_size(fsps)))
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800226 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800227 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800228 return;
229 }
230
Aaron Durbina85febc2020-05-15 15:09:10 -0600231 if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS)
232 die("FSP-S failed to load\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500233
Aaron Durbina85febc2020-05-15 15:09:10 -0600234 stage_cache_add(STAGE_REFCODE, fsps);
Aaron Durbin32ac0182016-07-18 00:35:42 -0500235
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800236 load_done = 1;
237}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500238
Raul E Rangel15928462021-11-05 10:29:24 -0600239void preload_fsps(void)
240{
241 if (!CONFIG(CBFS_PRELOAD))
242 return;
243
244 printk(BIOS_DEBUG, "Preloading %s\n", CONFIG_FSP_S_CBFS);
245 cbfs_preload(CONFIG_FSP_S_CBFS);
246}
247
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200248void fsp_silicon_init(void)
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800249{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200250 fsps_load();
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800251 do_silicon_init(&fsps_hdr);
Subrata Banik6de1d9f2022-03-20 19:50:38 +0530252
253 if (CONFIG(DISPLAY_FSP_TIMESTAMPS))
254 fsp_display_timestamp();
Andrey Petrov42c4e882016-02-25 14:17:45 -0800255}
Wim Vervoornd1371502019-12-17 14:10:16 +0100256
Kyösti Mälkki4949a3d2021-01-09 20:38:43 +0200257__weak void soc_load_logo(FSPS_UPD *supd) { }