blob: accb70ba9182698c8686597c08cc1afbb3b8f333 [file] [log] [blame]
Andrey Petrov465fc132016-02-25 14:16:33 -08001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy47bd2d92016-07-24 18:12:16 -07004 * Copyright (C) 2015-2016 Intel Corp.
Andrey Petrov465fc132016-02-25 14:16:33 -08005 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
6 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
Stefan Reinauer6a001132017-07-13 02:20:27 +020014#include <compiler.h>
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010015#include <security/vboot/antirollback.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080016#include <arch/io.h>
17#include <arch/cpu.h>
Aaron Durbinb4302502016-07-17 17:04:37 -050018#include <arch/symbols.h>
Aaron Durbin31be2c92016-12-03 22:08:20 -060019#include <assert.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050020#include <cbfs.h>
Aaron Durbin27928682016-07-15 22:32:28 -050021#include <cbmem.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080022#include <console/console.h>
Furquan Shaikh5aea5882016-07-30 18:10:05 -070023#include <elog.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080024#include <fsp/api.h>
25#include <fsp/util.h>
26#include <memrange.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070027#include <mrc_cache.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050028#include <program_loading.h>
Aaron Durbinb4302502016-07-17 17:04:37 -050029#include <reset.h>
30#include <romstage_handoff.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080031#include <string.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050032#include <symbols.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080033#include <timestamp.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020034#include <security/vboot/vboot_common.h>
Philipp Deppenwiese80961af2018-02-27 22:14:34 +010035#include <security/tpm/tspi.h>
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080036#include <vb2_api.h>
Philipp Deppenwiese80961af2018-02-27 22:14:34 +010037#include <fsp/memory_init.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080038
Aaron Durbinf0ec8242016-07-18 11:24:36 -050039static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -050040{
Aaron Durbinb4302502016-07-17 17:04:37 -050041 size_t mrc_data_size;
42 const void *mrc_data;
Aaron Durbinf0ec8242016-07-18 11:24:36 -050043
44 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS) || s3wake)
45 return;
46
47 mrc_data = fsp_find_nv_storage_data(&mrc_data_size);
48 if (!mrc_data) {
49 printk(BIOS_ERR, "Couldn't find memory training data HOB.\n");
50 return;
51 }
52
53 /*
54 * Save MRC Data to CBMEM. By always saving the data this forces
55 * a retrain after a trip through Chrome OS recovery path. The
56 * code which saves the data to flash doesn't write if the latest
57 * training data matches this one.
58 */
Aaron Durbin31be2c92016-12-03 22:08:20 -060059 if (mrc_cache_stash_data(MRC_TRAINING_DATA, fsp_version, mrc_data,
60 mrc_data_size) < 0)
61 printk(BIOS_ERR, "Failed to stash MRC data\n");
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080062
Philipp Deppenwiese80961af2018-02-27 22:14:34 +010063 if (IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH))
64 mrc_cache_update_hash(mrc_data, mrc_data_size);
Aaron Durbinf0ec8242016-07-18 11:24:36 -050065}
66
Lee Leahy9671faa2016-07-24 18:18:52 -070067static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version)
Aaron Durbinf0ec8242016-07-18 11:24:36 -050068{
69 struct range_entry fsp_mem;
Aaron Durbinb4302502016-07-17 17:04:37 -050070
Lee Leahy52d0c682016-08-01 15:47:42 -070071 if (fsp_find_reserved_memory(&fsp_mem))
72 die("Failed to find FSP_RESERVED_MEMORY_RESOURCE_HOB!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -050073
74 /* initialize cbmem by adding FSP reserved memory first thing */
75 if (!s3wake) {
76 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
77 range_entry_size(&fsp_mem));
78 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
79 range_entry_size(&fsp_mem))) {
80 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070081 printk(BIOS_ERR,
Lee Leahyac3b0a62016-07-27 07:40:25 -070082 "Failed to recover CBMEM in S3 resume.\n");
Aaron Durbinb4302502016-07-17 17:04:37 -050083 /* Failed S3 resume, reset to come up cleanly */
84 hard_reset();
85 }
86 }
87
88 /* make sure FSP memory is reserved in cbmem */
89 if (range_entry_base(&fsp_mem) !=
90 (uintptr_t)cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY))
Lee Leahy9671faa2016-07-24 18:18:52 -070091 die("Failed to accommodate FSP reserved memory request!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -050092
Aaron Durbinf0ec8242016-07-18 11:24:36 -050093 save_memory_training_data(s3wake, fsp_version);
Aaron Durbinb4302502016-07-17 17:04:37 -050094
95 /* Create romstage handof information */
Aaron Durbin77e13992016-11-29 17:43:04 -060096 romstage_handoff_init(s3wake);
Youness Alaoui676887d2018-02-07 11:49:35 -050097
98 /*
99 * Initialize the TPM, unless the TPM was already initialized
100 * in verstage and used to verify romstage.
101 */
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +0100102 if ((IS_ENABLED(CONFIG_TPM1) || IS_ENABLED(CONFIG_TPM2)) &&
Youness Alaoui676887d2018-02-07 11:49:35 -0500103 !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK))
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +0100104 tpm_setup(s3wake);
Aaron Durbinb4302502016-07-17 17:04:37 -0500105}
106
Aamir Bohra69cd62c2018-01-08 11:01:34 +0530107static void fsp_fill_mrc_cache(FSPM_ARCH_UPD *arch_upd, uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -0500108{
Aaron Durbin31be2c92016-12-03 22:08:20 -0600109 struct region_device rdev;
110 void *data;
Aaron Durbinb4302502016-07-17 17:04:37 -0500111
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500112 arch_upd->NvsBufferPtr = NULL;
113
114 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS))
115 return;
116
Aaron Durbin31be2c92016-12-03 22:08:20 -0600117 /*
118 * In recovery mode, force retraining:
119 * 1. Recovery cache is not supported, or
120 * 2. Memory retrain switch is set.
121 */
122 if (vboot_recovery_mode_enabled()) {
123 if (!IS_ENABLED(CONFIG_HAS_RECOVERY_MRC_CACHE))
124 return;
125 if (vboot_recovery_mode_memory_retrain())
126 return;
127 }
Aaron Durbin98ea6362016-07-18 11:31:53 -0500128
Aaron Durbin31be2c92016-12-03 22:08:20 -0600129 if (mrc_cache_get_current(MRC_TRAINING_DATA, fsp_version, &rdev) < 0)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500130 return;
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500131
Aaron Durbin31be2c92016-12-03 22:08:20 -0600132 /* Assume boot device is memory mapped. */
133 assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED));
134 data = rdev_mmap_full(&rdev);
135
136 if (data == NULL)
137 return;
138
Philipp Deppenwiese80961af2018-02-27 22:14:34 +0100139 if (IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH) &&
140 !mrc_cache_verify_hash(data, region_device_sz(&rdev)))
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800141 return;
142
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500143 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600144 arch_upd->NvsBufferPtr = data;
Aamir Bohra69cd62c2018-01-08 11:01:34 +0530145
146 printk(BIOS_SPEW, "MRC cache found, size %zx\n",
147 region_device_sz(&rdev));
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500148}
149
Aaron Durbin02e504c2016-07-18 11:53:10 -0500150static enum cb_err check_region_overlap(const struct memranges *ranges,
151 const char *description,
152 uintptr_t begin, uintptr_t end)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500153{
Aaron Durbin02e504c2016-07-18 11:53:10 -0500154 const struct range_entry *r;
155
156 memranges_each_entry(r, ranges) {
157 if (end <= range_entry_base(r))
158 continue;
159 if (begin >= range_entry_end(r))
160 continue;
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700161 printk(BIOS_CRIT, "'%s' overlaps currently running program: "
Aaron Durbin02e504c2016-07-18 11:53:10 -0500162 "[%p, %p)\n", description, (void *)begin, (void *)end);
163 return CB_ERR;
164 }
165
166 return CB_SUCCESS;
167}
Aamir Bohra6d569e0c2018-08-27 13:36:15 +0530168static enum cb_err setup_fsp_stack_frame(FSPM_ARCH_UPD *arch_upd,
169 const struct memranges *memmap)
Aaron Durbin02e504c2016-07-18 11:53:10 -0500170{
171 uintptr_t stack_begin;
172 uintptr_t stack_end;
173
Aaron Durbinb4302502016-07-17 17:04:37 -0500174 /*
Aamir Bohra6d569e0c2018-08-27 13:36:15 +0530175 * FSP 2.1 version would use same stack as coreboot instead of
176 * setting up seprate stack frame. FSP 2.1 would not relocate stack
177 * top and does not reinitialize stack pointer.
178 */
179 if (IS_ENABLED(CONFIG_FSP_USES_CB_STACK)) {
180 arch_upd->StackBase = (void *)_car_stack_end;
181 arch_upd->StackSize = CONFIG_DCACHE_BSP_STACK_SIZE;
182 return CB_SUCCESS;
183 }
184
185 /*
186 * FSPM_UPD passed here is populated with default values
187 * provided by the blob itself. We let FSPM use top of CAR
188 * region of the size it requests.
Aaron Durbinb4302502016-07-17 17:04:37 -0500189 */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500190 stack_end = (uintptr_t)_car_region_end;
191 stack_begin = stack_end - arch_upd->StackSize;
Aaron Durbin02e504c2016-07-18 11:53:10 -0500192 if (check_region_overlap(memmap, "FSPM stack", stack_begin,
193 stack_end) != CB_SUCCESS)
194 return CB_ERR;
195
196 arch_upd->StackBase = (void *)stack_begin;
Aamir Bohra6d569e0c2018-08-27 13:36:15 +0530197 return CB_SUCCESS;
198}
199
200static enum cb_err fsp_fill_common_arch_params(FSPM_ARCH_UPD *arch_upd,
201 bool s3wake, uint32_t fsp_version,
202 const struct memranges *memmap)
203{
204 if (setup_fsp_stack_frame(arch_upd, memmap))
205 return CB_ERR;
Aaron Durbinb4302502016-07-17 17:04:37 -0500206
Aamir Bohra69cd62c2018-01-08 11:01:34 +0530207 fsp_fill_mrc_cache(arch_upd, fsp_version);
Aaron Durbinb4302502016-07-17 17:04:37 -0500208
Aamir Bohra69cd62c2018-01-08 11:01:34 +0530209 /* Configure bootmode */
210 if (s3wake) {
211 /*
212 * For S3 resume case, if valid mrc cache data is not found or
213 * RECOVERY_MRC_CACHE hash verification fails, the S3 data
214 * pointer would be null and S3 resume fails with fsp-m
215 * returning error. Invoking a reset here saves time.
216 */
217 if (!arch_upd->NvsBufferPtr)
218 hard_reset();
219 arch_upd->BootMode = FSP_BOOT_ON_S3_RESUME;
220 } else {
221 if (arch_upd->NvsBufferPtr)
222 arch_upd->BootMode =
223 FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
224 else
225 arch_upd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION;
226 }
Aaron Durbin02e504c2016-07-18 11:53:10 -0500227
Aamir Bohra69cd62c2018-01-08 11:01:34 +0530228 printk(BIOS_SPEW, "bootmode is set to :%d\n", arch_upd->BootMode);
Aamir Bohra276c06a2017-12-26 17:54:45 +0530229
Aaron Durbin02e504c2016-07-18 11:53:10 -0500230 return CB_SUCCESS;
Aaron Durbinb4302502016-07-17 17:04:37 -0500231}
232
Aaron Durbin64031672018-04-21 14:45:32 -0600233__weak
Aaron Durbina3cecb22017-04-25 21:58:10 -0500234uint8_t fsp_memory_mainboard_version(void)
235{
236 return 0;
237}
238
Aaron Durbin64031672018-04-21 14:45:32 -0600239__weak
Aaron Durbina3cecb22017-04-25 21:58:10 -0500240uint8_t fsp_memory_soc_version(void)
241{
242 return 0;
243}
244
245/*
246 * Allow SoC and/or mainboard to bump the revision of the FSP setting
247 * number. The FSP spec uses the low 8 bits as the build number. Take over
248 * bits 3:0 for the SoC setting and bits 7:4 for the mainboard. That way
249 * a tweak in the settings will bump the version used to track the cached
250 * setting which triggers retraining when the FSP version hasn't changed, but
251 * the SoC or mainboard settings have.
252 */
253static uint32_t fsp_memory_settings_version(const struct fsp_header *hdr)
254{
255 /* Use the full FSP version by default. */
256 uint32_t ver = hdr->fsp_revision;
257
258 if (!IS_ENABLED(CONFIG_FSP_PLATFORM_MEMORY_SETTINGS_VERSIONS))
259 return ver;
260
261 ver &= ~0xff;
262 ver |= (0xf & fsp_memory_mainboard_version()) << 4;
263 ver |= (0xf & fsp_memory_soc_version()) << 0;
264
265 return ver;
266}
267
Lee Leahy9671faa2016-07-24 18:18:52 -0700268static void do_fsp_memory_init(struct fsp_header *hdr, bool s3wake,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500269 const struct memranges *memmap)
Andrey Petrov465fc132016-02-25 14:16:33 -0800270{
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700271 uint32_t status;
Andrey Petrov465fc132016-02-25 14:16:33 -0800272 fsp_memory_init_fn fsp_raminit;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700273 FSPM_UPD fspm_upd, *upd;
274 FSPM_ARCH_UPD *arch_upd;
Aaron Durbina3cecb22017-04-25 21:58:10 -0500275 uint32_t fsp_version;
Andrey Petrov465fc132016-02-25 14:16:33 -0800276
277 post_code(0x34);
278
Aaron Durbina3cecb22017-04-25 21:58:10 -0500279 fsp_version = fsp_memory_settings_version(hdr);
280
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700281 upd = (FSPM_UPD *)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov465fc132016-02-25 14:16:33 -0800282
Lee Leahye686ee82017-03-10 08:45:30 -0800283 if (upd->FspUpdHeader.Signature != FSPM_UPD_SIGNATURE)
Lee Leahy9671faa2016-07-24 18:18:52 -0700284 die("Invalid FSPM signature!\n");
Andrey Petrov465fc132016-02-25 14:16:33 -0800285
286 /* Copy the default values from the UPD area */
287 memcpy(&fspm_upd, upd, sizeof(fspm_upd));
288
Aaron Durbin02e504c2016-07-18 11:53:10 -0500289 arch_upd = &fspm_upd.FspmArchUpd;
290
Aaron Durbin27928682016-07-15 22:32:28 -0500291 /* Reserve enough memory under TOLUD to save CBMEM header */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500292 arch_upd->BootLoaderTolumSize = cbmem_overhead_size();
Aaron Durbin27928682016-07-15 22:32:28 -0500293
Aaron Durbinb4302502016-07-17 17:04:37 -0500294 /* Fill common settings on behalf of chipset. */
Aaron Durbina3cecb22017-04-25 21:58:10 -0500295 if (fsp_fill_common_arch_params(arch_upd, s3wake, fsp_version,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500296 memmap) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700297 die("FSPM_ARCH_UPD not found!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500298
Andrey Petrov465fc132016-02-25 14:16:33 -0800299 /* Give SoC and mainboard a chance to update the UPD */
Aaron Durbina3cecb22017-04-25 21:58:10 -0500300 platform_fsp_memory_init_params_cb(&fspm_upd, fsp_version);
Andrey Petrov465fc132016-02-25 14:16:33 -0800301
Pratik Prajapatiffc934d2016-11-18 14:36:34 -0800302 if (IS_ENABLED(CONFIG_MMA))
303 setup_mma(&fspm_upd.FspmConfig);
304
Andrey Petrov465fc132016-02-25 14:16:33 -0800305 /* Call FspMemoryInit */
306 fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700307 fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd);
Andrey Petrov465fc132016-02-25 14:16:33 -0800308
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -0700309 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800310 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700311 status = fsp_raminit(&fspm_upd, fsp_get_hob_list_ptr());
Subrata Banik0755ab92017-07-12 15:31:06 +0530312 post_code(POST_FSP_MEMORY_EXIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800313 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
314
Lee Leahyac3b0a62016-07-27 07:40:25 -0700315 fsp_debug_after_memory_init(status);
Andrey Petrov465fc132016-02-25 14:16:33 -0800316
Lee Leahy9671faa2016-07-24 18:18:52 -0700317 /* Handle any errors returned by FspMemoryInit */
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500318 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700319 if (status != FSP_SUCCESS) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700320 printk(BIOS_CRIT, "FspMemoryInit returned 0x%08x\n", status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700321 die("FspMemoryInit returned an error!\n");
322 }
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500323
Aaron Durbina3cecb22017-04-25 21:58:10 -0500324 do_fsp_post_memory_init(s3wake, fsp_version);
Andrey Petrov465fc132016-02-25 14:16:33 -0800325}
326
Aaron Durbind04639b2016-07-17 23:23:59 -0500327/* Load the binary into the memory specified by the info header. */
328static enum cb_err load_fspm_mem(struct fsp_header *hdr,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500329 const struct region_device *rdev,
330 const struct memranges *memmap)
Aaron Durbind04639b2016-07-17 23:23:59 -0500331{
Aaron Durbind04639b2016-07-17 23:23:59 -0500332 uintptr_t fspm_begin;
333 uintptr_t fspm_end;
334
335 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
336 return CB_ERR;
337
338 fspm_begin = hdr->image_base;
339 fspm_end = fspm_begin + hdr->image_size;
340
Aaron Durbin02e504c2016-07-18 11:53:10 -0500341 if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) !=
342 CB_SUCCESS)
Aaron Durbind04639b2016-07-17 23:23:59 -0500343 return CB_ERR;
Aaron Durbind04639b2016-07-17 23:23:59 -0500344
345 /* Load binary into memory at provided address. */
346 if (rdev_readat(rdev, (void *)fspm_begin, 0, fspm_end - fspm_begin) < 0)
347 return CB_ERR;
348
349 return CB_SUCCESS;
350}
351
352/* Handle the case when FSPM is running XIP. */
353static enum cb_err load_fspm_xip(struct fsp_header *hdr,
354 const struct region_device *rdev)
355{
356 void *base;
357
358 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
359 return CB_ERR;
360
361 base = rdev_mmap_full(rdev);
362 if ((uintptr_t)base != hdr->image_base) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700363 printk(BIOS_CRIT, "FSPM XIP base does not match: %p vs %p\n",
Aaron Durbind04639b2016-07-17 23:23:59 -0500364 (void *)(uintptr_t)hdr->image_base, base);
365 return CB_ERR;
366 }
367
368 /*
369 * Since the component is XIP it's already in the address space. Thus,
370 * there's no need to rdev_munmap().
371 */
372 return CB_SUCCESS;
373}
374
Lee Leahy9671faa2016-07-24 18:18:52 -0700375void fsp_memory_init(bool s3wake)
Andrey Petrov465fc132016-02-25 14:16:33 -0800376{
377 struct fsp_header hdr;
Aaron Durbind04639b2016-07-17 23:23:59 -0500378 enum cb_err status;
379 struct cbfsf file_desc;
380 struct region_device file_data;
381 const char *name = CONFIG_FSP_M_CBFS;
Aaron Durbin02e504c2016-07-18 11:53:10 -0500382 struct memranges memmap;
383 struct range_entry freeranges[2];
Andrey Petrov465fc132016-02-25 14:16:33 -0800384
Furquan Shaikh5aea5882016-07-30 18:10:05 -0700385 if (IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) && !s3wake)
386 boot_count_increment();
387
Aaron Durbind04639b2016-07-17 23:23:59 -0500388 if (cbfs_boot_locate(&file_desc, name, NULL)) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700389 printk(BIOS_CRIT, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -0700390 die("FSPM not available!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500391 }
392
393 cbfs_file_data(&file_data, &file_desc);
394
Aaron Durbin02e504c2016-07-18 11:53:10 -0500395 /* Build up memory map of romstage address space including CAR. */
396 memranges_init_empty(&memmap, &freeranges[0], ARRAY_SIZE(freeranges));
397 memranges_insert(&memmap, (uintptr_t)_car_region_start,
398 _car_relocatable_data_end - _car_region_start, 0);
399 memranges_insert(&memmap, (uintptr_t)_program, _program_size, 0);
400
Lee Leahy27cd96a2016-07-21 11:16:39 -0700401 if (!IS_ENABLED(CONFIG_FSP_M_XIP))
Aaron Durbin02e504c2016-07-18 11:53:10 -0500402 status = load_fspm_mem(&hdr, &file_data, &memmap);
Aaron Durbind04639b2016-07-17 23:23:59 -0500403 else
404 status = load_fspm_xip(&hdr, &file_data);
405
Lee Leahye686ee82017-03-10 08:45:30 -0800406 if (status != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700407 die("Loading FSPM failed!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500408
409 /* Signal that FSP component has been loaded. */
410 prog_segment_loaded(hdr.image_base, hdr.image_size, SEG_FINAL);
Andrey Petrov465fc132016-02-25 14:16:33 -0800411
Lee Leahy9671faa2016-07-24 18:18:52 -0700412 do_fsp_memory_init(&hdr, s3wake, &memmap);
Andrey Petrov465fc132016-02-25 14:16:33 -0800413}