blob: a4ffbda4cc52670e7bec3d2f50ff2d100fd25223 [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
Andrey Petrov42c4e882016-02-25 14:17:45 -08003#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -05004#include <cbmem.h>
5#include <commonlib/fsp.h>
Subrata Banik44ffb5d2018-05-24 10:51:29 +05306#include <commonlib/stdlib.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -08007#include <console/console.h>
8#include <fsp/api.h>
9#include <fsp/util.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050010#include <program_loading.h>
Keith Shortc58e3bd2019-05-10 11:14:31 -060011#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080012#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080013#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070014#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020015#include <types.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +010016#include <mode_switch.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080017
18struct fsp_header fsps_hdr;
19
Subrata Banik33d9c4a2020-05-26 18:26:54 +053020struct fsp_multi_phase_get_number_of_phases_params {
21 uint32_t number_of_phases;
22 uint32_t phases_executed;
23};
24
25/* Callbacks for SoC/Mainboard specific overrides */
26void __weak platform_fsp_multi_phase_init_cb(uint32_t phase_index)
27{
28 /* Leave for the SoC/Mainboard to implement if necessary. */
29}
30
31int __weak soc_fsp_multi_phase_init_is_enable(void)
32{
33 return 1;
34}
35
36/* FSP Specification < 2.2 has only 1 stage like FspSiliconInit. FSP specification >= 2.2
37 * has multiple stages as below.
38 */
39enum fsp_silicon_init_phases {
40 FSP_SILICON_INIT_API,
41 FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API,
42 FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API
43};
44
45static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, uint32_t status)
46{
47 uint8_t postcode;
48
49 /* Handle any reset request returned by FSP-S APIs */
50 fsp_handle_reset(status);
51
52 if (status == FSP_SUCCESS)
53 return;
54 /* Handle all other errors returned by FSP-S APIs */
55 /* Assume video failure if attempted to initialize graphics */
56 if (CONFIG(RUN_FSP_GOP) && vbt_get())
57 postcode = POST_VIDEO_FAILURE;
58 else
59 postcode = POST_HW_INIT_FAILURE; /* else generic */
60
61 switch (phases) {
62 case FSP_SILICON_INIT_API:
63 die_with_post_code(postcode, "FspSiliconInit returned with error 0x%08x\n",
64 status);
65 break;
66 case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API:
67 printk(BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases returned 0x%08x\n",
68 status);
69 break;
70 case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API:
71 printk(BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase returned 0x%08x\n",
72 status);
73 break;
74 default:
75 break;
76 }
77}
78
Lee Leahy9671faa2016-07-24 18:18:52 -070079static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080080{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053081 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080082 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070083 uint32_t status;
Wim Vervoornd1371502019-12-17 14:10:16 +010084 const struct cbmem_entry *logo_entry = NULL;
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
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070089 supd = (FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080090
Lee Leahye686ee82017-03-10 08:45:30 -080091 if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE)
Keith Shortbb41aba2019-05-16 14:07:43 -060092 die_with_post_code(POST_INVALID_VENDOR_BINARY,
93 "Invalid FSPS signature\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080094
Marshall Dawson71dbcf12019-09-11 14:02:34 -060095 /* Disallow invalid config regions. Default settings are likely bad
96 * choices for coreboot, and different sized UPD from what the region
97 * allows is potentially a build problem.
98 */
99 if (!hdr->cfg_region_size || hdr->cfg_region_size != sizeof(FSPS_UPD))
100 die_with_post_code(POST_INVALID_VENDOR_BINARY,
101 "Invalid FSPS UPD region\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530102
Marshall Dawson71dbcf12019-09-11 14:02:34 -0600103 upd = xmalloc(hdr->cfg_region_size);
104
105 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800106
107 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530108 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800109
Wim Vervoornd1371502019-12-17 14:10:16 +0100110 /* Populate logo related entries */
111 if (CONFIG(FSP2_0_DISPLAY_LOGO))
112 logo_entry = soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100113
Lee Leahy672df162016-07-24 18:21:13 -0700114 /* Call SiliconInit */
Andrey Petrov42c4e882016-02-25 14:17:45 -0800115 silicon_init = (void *) (hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700116 hdr->silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +0530117 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -0700118
119 timestamp_add_now(TS_FSP_SILICON_INIT_START);
120 post_code(POST_FSP_SILICON_INIT);
Patrick Rudolph40beb362020-12-01 10:08:38 +0100121
122 if (ENV_X86_64)
123 status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd);
124 else
125 status = silicon_init(upd);
126
127 printk(BIOS_ERR, "FSPS returned %x\n", status);
128
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700129 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +0530130 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -0700131
Wim Vervoornd1371502019-12-17 14:10:16 +0100132 if (logo_entry)
Wim Vervoorncbc878d22019-11-28 14:45:12 +0100133 cbmem_entry_remove(logo_entry);
134
Lee Leahy672df162016-07-24 18:21:13 -0700135 fsp_debug_after_silicon_init(status);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530136 fsps_return_value_handler(FSP_SILICON_INIT_API, status);
Aaron Durbin35d42c72016-07-18 12:41:09 -0500137
Subrata Banik96b32f12020-07-31 12:09:11 +0530138 /* Reinitialize CPUs if FSP-S has done MP Init */
139 if (CONFIG(USE_INTEL_FSP_MP_INIT))
140 do_mpinit_after_fsp();
141
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530142 if (!CONFIG(PLATFORM_USES_FSP2_2))
143 return;
Marshall Dawson7a9e8942019-10-17 07:58:27 -0600144
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530145 /* Check if SoC user would like to call Multi Phase Init */
146 if (!soc_fsp_multi_phase_init_is_enable())
147 return;
148
149 /* Call MultiPhaseSiInit */
150 multi_phase_si_init = (void *) (hdr->image_base +
151 hdr->multi_phase_si_init_entry_offset);
152
153 /* Implementing multi_phase_si_init() is optional as per FSP 2.2 spec */
154 if (multi_phase_si_init == NULL)
155 return;
156
157 post_code(POST_FSP_MULTI_PHASE_SI_INIT_ENTRY);
158 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START);
159 /* Get NumberOfPhases Value */
160 multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES;
161 multi_phase_params.phase_index = 0;
162 multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number;
163 status = multi_phase_si_init(&multi_phase_params);
164 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status);
165
166 /* Execute Multi Phase Execution */
167 for (int i = 1; i <= multi_phase_get_number.number_of_phases; i++) {
168 printk(BIOS_SPEW, "Executing Phase %d of FspMultiPhaseSiInit\n", i);
169 /*
170 * Give SoC/mainboard a chance to perform any operation before
171 * Multi Phase Execution
172 */
173 platform_fsp_multi_phase_init_cb(i);
174
175 multi_phase_params.multi_phase_action = EXECUTE_PHASE;
176 multi_phase_params.phase_index = i;
177 multi_phase_params.multi_phase_param_ptr = NULL;
178 status = multi_phase_si_init(&multi_phase_params);
179 fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700180 }
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530181 timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END);
182 post_code(POST_FSP_MULTI_PHASE_SI_INIT_EXIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800183}
184
Aaron Durbina85febc2020-05-15 15:09:10 -0600185static int fsps_get_dest(const struct fsp_load_descriptor *fspld, void **dest,
186 size_t size, const struct region_device *source)
187{
188 *dest = cbmem_add(CBMEM_ID_REFCODE, size);
189
190 if (*dest == NULL)
191 return -1;
192
193 return 0;
194}
195
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800196void fsps_load(bool s3wake)
Andrey Petrov42c4e882016-02-25 14:17:45 -0800197{
Aaron Durbina85febc2020-05-15 15:09:10 -0600198 struct fsp_load_descriptor fspld = {
199 .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS),
200 .get_destination = fsps_get_dest,
201 };
202 struct prog *fsps = &fspld.fsp_prog;
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800203 static int load_done;
204
205 if (load_done)
206 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800207
Julius Wernercd49cce2019-03-05 16:53:33 -0800208 if (s3wake && !CONFIG(NO_STAGE_CACHE)) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800209 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
Aaron Durbina85febc2020-05-15 15:09:10 -0600210 stage_cache_load_stage(STAGE_REFCODE, fsps);
211 if (fsp_validate_component(&fsps_hdr, prog_rdev(fsps)) != CB_SUCCESS)
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800212 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800213 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800214 return;
215 }
216
Aaron Durbina85febc2020-05-15 15:09:10 -0600217 if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS)
218 die("FSP-S failed to load\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500219
Aaron Durbina85febc2020-05-15 15:09:10 -0600220 stage_cache_add(STAGE_REFCODE, fsps);
Aaron Durbin32ac0182016-07-18 00:35:42 -0500221
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800222 load_done = 1;
223}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500224
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800225void fsp_silicon_init(bool s3wake)
226{
227 fsps_load(s3wake);
228 do_silicon_init(&fsps_hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800229}
Wim Vervoornd1371502019-12-17 14:10:16 +0100230
231/* Load bmp and set FSP parameters, fsp_load_logo can be used */
232__weak const struct cbmem_entry *soc_load_logo(FSPS_UPD *supd)
233{
234 return NULL;
235}