| 1 |
|
| 2 |
|
| 3 |
#include <arch/null_breakpoint.h> |
| 4 |
#include <arch/stack_canary_breakpoint.h> |
| 5 |
#include <bootsplash.h> |
| 6 |
#include <cbfs.h> |
| 7 |
#include <cbmem.h> |
| 8 |
#include <commonlib/fsp.h> |
| 9 |
#include <cpu/x86/mtrr.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <console/console.h> |
| 12 |
#include <fsp/api.h> |
| 13 |
#include <fsp/util.h> |
| 14 |
#include <mrc_cache.h> |
| 15 |
#include <program_loading.h> |
| 16 |
#include <soc/intel/common/reset.h> |
| 17 |
#if CONFIG(SOC_AMD_COMMON) |
| 18 |
#include <amdblocks/vbt.h> |
| 19 |
#endif |
| 20 |
#if CONFIG(SOC_INTEL_COMMON) |
| 21 |
#include <soc/intel/common/vbt.h> |
| 22 |
#endif |
| 23 |
#include <stage_cache.h> |
| 24 |
#include <string.h> |
| 25 |
#include <timestamp.h> |
| 26 |
#include <types.h> |
| 27 |
#include <mode_switch.h> |
| 28 |
|
| 29 |
struct fsp_header fsps_hdr; |
| 30 |
|
| 31 |
|
| 32 |
void __weak platform_fsp_silicon_multi_phase_init_cb(uint32_t phase_index) |
| 33 |
{ |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
enum 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 |
|
| 46 |
static void fsps_return_value_handler(enum fsp_silicon_init_phases phases, |
| 47 |
efi_return_status_t status) |
| 48 |
{ |
| 49 |
uint8_t postcode; |
| 50 |
|
| 51 |
|
| 52 |
fsp_handle_reset(status); |
| 53 |
|
| 54 |
if (status == FSP_SUCCESS) |
| 55 |
return; |
| 56 |
|
| 57 |
|
| 58 |
if (CONFIG(RUN_FSP_GOP) && vbt_get()) |
| 59 |
postcode = POSTCODE_VIDEO_FAILURE; |
| 60 |
else |
| 61 |
postcode = POSTCODE_HW_INIT_FAILURE; |
| 62 |
|
| 63 |
switch (phases) { |
| 64 |
case FSP_SILICON_INIT_API: |
| 65 |
fsp_die_with_post_code(status, postcode, "FspSiliconInit error"); |
| 66 |
break; |
| 67 |
case FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API: |
| 68 |
fsp_printk(status, BIOS_SPEW, "FspMultiPhaseSiInit NumberOfPhases"); |
| 69 |
break; |
| 70 |
case FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API: |
| 71 |
fsp_printk(status, BIOS_SPEW, "FspMultiPhaseSiInit ExecutePhase"); |
| 72 |
break; |
| 73 |
default: |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
bool fsp_is_multi_phase_init_enabled(void) |
| 79 |
{ |
| 80 |
return CONFIG(FSPS_USE_MULTI_PHASE_INIT) && |
| 81 |
(fsps_hdr.fsp_multi_phase_si_init_entry_offset != 0); |
| 82 |
} |
| 83 |
|
| 84 |
static void fsp_fill_common_arch_params(FSPS_UPD *supd) |
| 85 |
{ |
| 86 |
#if (CONFIG(FSPS_HAS_ARCH_UPD) && !CONFIG(PLATFORM_USES_FSP2_4)) |
| 87 |
FSPS_ARCHx_UPD *s_arch_cfg = &supd->FspsArchUpd; |
| 88 |
s_arch_cfg->EnableMultiPhaseSiliconInit = fsp_is_multi_phase_init_enabled(); |
| 89 |
#endif |
| 90 |
} |
| 91 |
|
| 92 |
static void do_silicon_init(struct fsp_header *hdr) |
| 93 |
{ |
| 94 |
FSPS_UPD *upd, *supd; |
| 95 |
fsp_silicon_init_fn silicon_init; |
| 96 |
efi_return_status_t status; |
| 97 |
fsp_multi_phase_init_fn multi_phase_si_init; |
| 98 |
struct fsp_multi_phase_params multi_phase_params; |
| 99 |
struct fsp_multi_phase_get_number_of_phases_params multi_phase_get_number; |
| 100 |
int temp_mtrr_index = -1; |
| 101 |
|
| 102 |
supd = (FSPS_UPD *)(uintptr_t)(hdr->cfg_region_offset + hdr->image_base); |
| 103 |
|
| 104 |
fsp_verify_upd_header_signature(supd->FspUpdHeader.Signature, FSPS_UPD_SIGNATURE); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
if (!hdr->cfg_region_size || hdr->cfg_region_size < sizeof(FSPS_UPD)) |
| 113 |
die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY, |
| 114 |
"Invalid FSPS UPD region\n"); |
| 115 |
else if (hdr->cfg_region_size > sizeof(FSPS_UPD)) |
| 116 |
printk(BIOS_ERR, "FSP and coreboot are out of sync! FSPS UPD size > coreboot\n"); |
| 117 |
|
| 118 |
upd = xmalloc(hdr->cfg_region_size); |
| 119 |
|
| 120 |
memcpy(upd, supd, hdr->cfg_region_size); |
| 121 |
|
| 122 |
|
| 123 |
if (CONFIG(FSPS_HAS_ARCH_UPD)) |
| 124 |
fsp_fill_common_arch_params(upd); |
| 125 |
|
| 126 |
platform_fsp_silicon_init_params_cb(upd); |
| 127 |
|
| 128 |
if (CONFIG(BMP_LOGO) && CONFIG(USE_COREBOOT_FOR_BMP_RENDERING)) |
| 129 |
temp_mtrr_index = soc_mark_gfx_memory(); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
if (CONFIG(BMP_LOGO) && !CONFIG(USE_COREBOOT_FOR_BMP_RENDERING)) |
| 136 |
soc_load_logo_by_fsp(upd); |
| 137 |
|
| 138 |
|
| 139 |
silicon_init = (void *)(uintptr_t)(hdr->image_base + |
| 140 |
hdr->fsp_silicon_init_entry_offset); |
| 141 |
fsp_debug_before_silicon_init(silicon_init, supd, upd); |
| 142 |
|
| 143 |
timestamp_add_now(TS_FSP_SILICON_INIT_START); |
| 144 |
post_code(POSTCODE_FSP_SILICON_INIT); |
| 145 |
|
| 146 |
|
| 147 |
null_breakpoint_remove(); |
| 148 |
stack_canary_breakpoint_remove(); |
| 149 |
if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32)) |
| 150 |
status = protected_mode_call_1arg(silicon_init, (uintptr_t)upd); |
| 151 |
else |
| 152 |
status = silicon_init(upd); |
| 153 |
null_breakpoint_init(); |
| 154 |
stack_canary_breakpoint_init(); |
| 155 |
|
| 156 |
fsp_printk(status, BIOS_INFO, "FSPS"); |
| 157 |
|
| 158 |
timestamp_add_now(TS_FSP_SILICON_INIT_END); |
| 159 |
post_code(POSTCODE_FSP_SILICON_EXIT); |
| 160 |
|
| 161 |
fsp_debug_after_silicon_init(status); |
| 162 |
fsps_return_value_handler(FSP_SILICON_INIT_API, status); |
| 163 |
|
| 164 |
|
| 165 |
if (!CONFIG(PLATFORM_USES_FSP2_2) && CONFIG(BMP_LOGO)) { |
| 166 |
if (CONFIG(USE_COREBOOT_FOR_BMP_RENDERING)) |
| 167 |
soc_load_logo_by_coreboot(); |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
timestamp_add_now(TS_FIRMWARE_SPLASH_RENDERED); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
if (CONFIG(USE_INTEL_FSP_MP_INIT) && !fsp_is_multi_phase_init_enabled()) |
| 177 |
do_mpinit_after_fsp(); |
| 178 |
|
| 179 |
if (!CONFIG(PLATFORM_USES_FSP2_2)) |
| 180 |
return; |
| 181 |
|
| 182 |
|
| 183 |
if (!fsp_is_multi_phase_init_enabled()) |
| 184 |
return; |
| 185 |
|
| 186 |
|
| 187 |
multi_phase_si_init = (void *)(uintptr_t)(hdr->image_base + |
| 188 |
hdr->fsp_multi_phase_si_init_entry_offset); |
| 189 |
|
| 190 |
|
| 191 |
if (multi_phase_si_init == NULL) |
| 192 |
return; |
| 193 |
|
| 194 |
post_code(POSTCODE_FSP_MULTI_PHASE_SI_INIT_ENTRY); |
| 195 |
timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_START); |
| 196 |
|
| 197 |
multi_phase_params.multi_phase_action = GET_NUMBER_OF_PHASES; |
| 198 |
multi_phase_params.phase_index = 0; |
| 199 |
multi_phase_params.multi_phase_param_ptr = &multi_phase_get_number; |
| 200 |
status = multi_phase_si_init(&multi_phase_params); |
| 201 |
fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_GET_NUMBER_OF_PHASES_API, status); |
| 202 |
|
| 203 |
|
| 204 |
for (uint32_t i = 1; i <= multi_phase_get_number.number_of_phases; i++) { |
| 205 |
printk(BIOS_SPEW, "Executing Phase %u of FspMultiPhaseSiInit\n", i); |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
platform_fsp_silicon_multi_phase_init_cb(i); |
| 211 |
|
| 212 |
multi_phase_params.multi_phase_action = EXECUTE_PHASE; |
| 213 |
multi_phase_params.phase_index = i; |
| 214 |
multi_phase_params.multi_phase_param_ptr = NULL; |
| 215 |
status = multi_phase_si_init(&multi_phase_params); |
| 216 |
if (CONFIG(FSP_MULTIPHASE_SI_INIT_RETURN_BROKEN)) |
| 217 |
status = fsp_get_pch_reset_status(); |
| 218 |
fsps_return_value_handler(FSP_MULTI_PHASE_SI_INIT_EXECUTE_PHASE_API, status); |
| 219 |
} |
| 220 |
timestamp_add_now(TS_FSP_MULTI_PHASE_SI_INIT_END); |
| 221 |
post_code(POSTCODE_FSP_MULTI_PHASE_SI_INIT_EXIT); |
| 222 |
|
| 223 |
if (CONFIG(BMP_LOGO)) { |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
if (CONFIG(USE_COREBOOT_FOR_BMP_RENDERING)) |
| 231 |
soc_load_logo_by_coreboot(); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
timestamp_add_now(TS_FIRMWARE_SPLASH_RENDERED); |
| 237 |
|
| 238 |
|
| 239 |
if (temp_mtrr_index >= 0) |
| 240 |
clear_var_mtrr(temp_mtrr_index); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
if (CONFIG(USE_INTEL_FSP_MP_INIT)) |
| 245 |
do_mpinit_after_fsp(); |
| 246 |
} |
| 247 |
|
| 248 |
static void *fsps_allocator(void *arg_unused, size_t size, const union cbfs_mdata *mdata_unused) |
| 249 |
{ |
| 250 |
return cbmem_add(CBMEM_ID_REFCODE, size); |
| 251 |
} |
| 252 |
|
| 253 |
void fsps_load(void) |
| 254 |
{ |
| 255 |
const char *fsps_cbfs = soc_select_fsp_s_cbfs(); |
| 256 |
struct fsp_load_descriptor fspld = { |
| 257 |
.fsp_prog = PROG_INIT(PROG_REFCODE, fsps_cbfs), |
| 258 |
.alloc = fsps_allocator, |
| 259 |
}; |
| 260 |
struct prog *fsps = &fspld.fsp_prog; |
| 261 |
static int load_done; |
| 262 |
|
| 263 |
if (load_done) |
| 264 |
return; |
| 265 |
|
| 266 |
timestamp_add_now(TS_FSP_SILICON_INIT_LOAD); |
| 267 |
|
| 268 |
if (resume_from_stage_cache()) { |
| 269 |
printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n"); |
| 270 |
stage_cache_load_stage(STAGE_REFCODE, fsps); |
| 271 |
if (fsp_validate_component(&fsps_hdr, prog_start(fsps), prog_size(fsps))) |
| 272 |
die("On resume fsps header is invalid\n"); |
| 273 |
load_done = 1; |
| 274 |
return; |
| 275 |
} |
| 276 |
|
| 277 |
if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS) |
| 278 |
die("FSP-S failed to load\n"); |
| 279 |
|
| 280 |
stage_cache_add(STAGE_REFCODE, fsps); |
| 281 |
|
| 282 |
load_done = 1; |
| 283 |
} |
| 284 |
|
| 285 |
void preload_fsps(void) |
| 286 |
{ |
| 287 |
if (!CONFIG(CBFS_PRELOAD)) |
| 288 |
return; |
| 289 |
|
| 290 |
const char *fsps_cbfs = soc_select_fsp_s_cbfs(); |
| 291 |
printk(BIOS_DEBUG, "Preloading %s\n", fsps_cbfs); |
| 292 |
cbfs_preload(fsps_cbfs); |
| 293 |
} |
| 294 |
|
| 295 |
void fsp_silicon_init(void) |
| 296 |
{ |
| 297 |
fsps_load(); |
| 298 |
do_silicon_init(&fsps_hdr); |
| 299 |
|
| 300 |
if (platform_is_low_battery_shutdown_needed()) |
| 301 |
do_low_battery_poweroff(); |
| 302 |
|
| 303 |
if (CONFIG(CACHE_MRC_SETTINGS) && CONFIG(FSP_NVS_DATA_POST_SILICON_INIT)) |
| 304 |
save_memory_training_data(); |
| 305 |
|
| 306 |
if (CONFIG(DISPLAY_FSP_TIMESTAMPS)) |
| 307 |
fsp_display_timestamp(); |
| 308 |
} |
| 309 |
|
| 310 |
__weak void soc_load_logo_by_fsp(FSPS_UPD *supd) { } |