blob: a090a1fce546fa3a20bce9da80268acf5cc5da4e [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahy0946ec32015-04-20 15:24:54 -07003
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07005#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02006#include <cf9_reset.h>
Elyes HAOUAS2195f7a2019-06-21 07:20:12 +02007#include <commonlib/helpers.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07008#include <console/console.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03009#include <cpu/x86/smm.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080010#include <fsp/romstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050011#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070012#include <lib.h> /* hexdump */
Lee Leahy0946ec32015-04-20 15:24:54 -070013#include <string.h>
14#include <timestamp.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020015#include <security/vboot/vboot_common.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070016
17void raminit(struct romstage_params *params)
18{
Nico Huber16895c52019-05-04 16:29:17 +020019 const bool s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070020 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
21 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
22 FSP_INFO_HEADER *fsp_header;
23 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
24 FSP_MEMORY_INIT fsp_memory_init;
25 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
26 const EFI_GUID fsp_reserved_guid =
27 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
28 void *fsp_reserved_memory_area;
29 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
30 void *hob_list_ptr;
31 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
32 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
33 MEMORY_INIT_UPD memory_init_params;
34 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
35 u32 *mrc_hob;
36 u32 fsp_reserved_bytes;
37 MEMORY_INIT_UPD *original_params;
Lee Leahy0946ec32015-04-20 15:24:54 -070038 EFI_STATUS status;
39 VPD_DATA_REGION *vpd_ptr;
40 UPD_DATA_REGION *upd_ptr;
41 int fsp_verification_failure = 0;
Lee Leahy0946ec32015-04-20 15:24:54 -070042 EFI_PEI_HOB_POINTERS hob_ptr;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030043 uintptr_t smm_base;
Kyösti Mälkkib4905622019-07-12 08:02:35 +030044 size_t smm_size;
Lee Leahy0946ec32015-04-20 15:24:54 -070045
46 /*
47 * Find and copy the UPD region to the stack so the platform can modify
48 * the settings if needed. Modifications to the UPD buffer are done in
49 * the platform callback code. The platform callback code is also
50 * responsible for assigning the UpdDataRngPtr to this buffer if any
51 * updates are made. The default state is to leave the UpdDataRngPtr
52 * set to NULL. This indicates that the FSP code will use the UPD
53 * region in the FSP binary.
54 */
Furquan Shaikh585210a2018-10-16 11:54:37 -070055 post_code(POST_MEM_PREINIT_PREP_START);
Aaron Durbine6af4be2015-09-24 12:26:31 -050056 fsp_header = params->chipset_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070057 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
58 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080059 printk(BIOS_DEBUG, "VPD Data: %p\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070060 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
61 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080062 printk(BIOS_DEBUG, "UPD Data: %p\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070063 original_params = (void *)((u8 *)upd_ptr +
64 upd_ptr->MemoryInitUpdOffset);
65 memcpy(&memory_init_params, original_params,
66 sizeof(memory_init_params));
67
68 /* Zero fill RT Buffer data and start populating fields. */
69 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
Nico Huber16895c52019-05-04 16:29:17 +020070 if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070071 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
Nico Huber66318aa2019-05-04 16:59:20 +020072 } else if (params->saved_data != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -070073 fsp_rt_common_buffer.BootMode =
74 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
75 } else {
76 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
77 }
78 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
79 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
80
81 /* Get any board specific changes */
Nico Huber66318aa2019-05-04 16:59:20 +020082 fsp_memory_init_params.NvsBufferPtr = (void *)params->saved_data;
Lee Leahy0946ec32015-04-20 15:24:54 -070083 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
84 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
85
86 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -070087 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070088 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070089
Julius Wernercd49cce2019-03-05 16:53:33 -080090 if (CONFIG(MMA))
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070091 setup_mma(&memory_init_params);
92
Furquan Shaikh585210a2018-10-16 11:54:37 -070093 post_code(POST_MEM_PREINIT_PREP_END);
Lee Leahy0946ec32015-04-20 15:24:54 -070094
95 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -080096 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -070097 soc_display_memory_init_params(original_params,
98 &memory_init_params);
99
100 /* Call FspMemoryInit to initialize RAM */
101 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
102 + fsp_header->FspMemoryInitEntryOffset);
Julius Werner540a9802019-12-09 13:03:29 -0800103 printk(BIOS_DEBUG, "Calling FspMemoryInit: %p\n", fsp_memory_init);
104 printk(BIOS_SPEW, " %p: NvsBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700105 fsp_memory_init_params.NvsBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800106 printk(BIOS_SPEW, " %p: RtBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700107 fsp_memory_init_params.RtBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800108 printk(BIOS_SPEW, " %p: HobListPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700109 fsp_memory_init_params.HobListPtr);
110
111 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Duncan Lauriefb509832015-11-22 14:53:57 -0800112 post_code(POST_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700113 status = fsp_memory_init(&fsp_memory_init_params);
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200114 mainboard_after_memory_init();
Lee Leahy0946ec32015-04-20 15:24:54 -0700115 post_code(0x37);
116 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
117
118 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
119 if (status != EFI_SUCCESS)
Keith Short24302632019-05-16 14:08:31 -0600120 die_with_post_code(POST_RAM_FAILURE,
121 "ERROR - FspMemoryInit failed to initialize memory!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700122
123 /* Locate the FSP reserved memory area */
124 fsp_reserved_bytes = 0;
125 fsp_memory = get_next_resource_hob(&fsp_reserved_guid, hob_list_ptr);
126 if (fsp_memory == NULL) {
127 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200128 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700129 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
130 } else {
131 fsp_reserved_bytes = fsp_memory->ResourceLength;
132 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
133 (unsigned long int)fsp_reserved_bytes);
134 }
135
136 /* Display SMM area */
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300137 if (CONFIG(HAVE_SMI_HANDLER)) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300138 smm_region(&smm_base, &smm_size);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300139 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300140 printk(BIOS_DEBUG, "0x%08x: smm_base\n", (unsigned int)smm_base);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300141 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700142
143 /* Migrate CAR data */
Julius Werner540a9802019-12-09 13:03:29 -0800144 printk(BIOS_DEBUG, "%p: cbmem_top\n", cbmem_top());
Nico Huber16895c52019-05-04 16:29:17 +0200145 if (!s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700146 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
147 fsp_reserved_bytes);
148 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
149 fsp_reserved_bytes)) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800150#if CONFIG(HAVE_ACPI_RESUME)
Lee Leahy0946ec32015-04-20 15:24:54 -0700151 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
152 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolphf677d172018-10-01 19:17:11 +0200153 /* FIXME: A "system" reset is likely enough: */
154 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700155#endif
156 }
157
158 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500159 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700160
161 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
162 cbmem_root = get_next_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
163 if (cbmem_root == NULL) {
164 fsp_verification_failure = 1;
165 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
166 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
167 fsp_rt_common_buffer.BootLoaderTolumSize);
168 }
169
170 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
171 memory_info_hob = get_next_guid_hob(&memory_info_hob_guid,
172 hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700173 if (memory_info_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700174 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
175 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700176 }
177
Frans Hendriks509f4692019-06-28 14:11:41 +0200178 if (hob_list_ptr == NULL)
179 die_with_post_code(POST_RAM_FAILURE,
180 "ERROR - HOB pointer is NULL!\n");
181
Lee Leahy0946ec32015-04-20 15:24:54 -0700182 /*
183 * Verify that FSP is generating the required HOBs:
184 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
185 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100186 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB only produced when
Frans Hendriks509f4692019-06-28 14:11:41 +0200187 * new NVS data is generated, verified below
Lee Leahy0946ec32015-04-20 15:24:54 -0700188 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
189 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
190 * FSP_SMBIOS_MEMORY_INFO HOB verified above
191 */
Lee Leahy0946ec32015-04-20 15:24:54 -0700192 hob_ptr.Raw = get_next_guid_hob(&mrc_guid, hob_list_ptr);
Frans Hendriks509f4692019-06-28 14:11:41 +0200193 if ((hob_ptr.Raw == NULL) && (params->saved_data == NULL)) {
194 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
195 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700196 }
197
198 /* Verify all the HOBs are present */
199 if (fsp_verification_failure)
Frans Hendriks509f4692019-06-28 14:11:41 +0200200 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700201 "ERROR - Missing one or more required FSP HOBs!\n");
202
203 /* Display the HOBs */
Frans Hendriks509f4692019-06-28 14:11:41 +0200204 if (CONFIG(DISPLAY_HOBS))
Keith Shortbb41aba2019-05-16 14:07:43 -0600205 print_hob_type_structure(0, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700206
207 /* Get the address of the CBMEM region for the FSP reserved memory */
208 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
Julius Werner540a9802019-12-09 13:03:29 -0800209 printk(BIOS_DEBUG, "%p: fsp_reserved_memory_area\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700210 fsp_reserved_memory_area);
211
212 /* Verify the order of CBMEM root and FSP memory */
213 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
214 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
215 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200216 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700217 "ERROR - FSP reserved memory above CBMEM root!\n");
218 }
219
220 /* Verify that the FSP memory was properly reserved */
221 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
222 (fsp_memory->PhysicalStart !=
223 (unsigned int)fsp_reserved_memory_area))) {
224 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200225 printk(BIOS_ERR, "ERROR - Reserving FSP memory area!\n");
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300226
227 if (CONFIG(HAVE_SMI_HANDLER) && cbmem_root != NULL) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300228 size_t delta_bytes = smm_base
Lee Leahy0946ec32015-04-20 15:24:54 -0700229 - cbmem_root->PhysicalStart
230 - cbmem_root->ResourceLength;
Frans Hendriks509f4692019-06-28 14:11:41 +0200231 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700232 "0x%08x: Chipset reserved bytes reported by FSP\n",
233 (unsigned int)delta_bytes);
Keith Shortbb41aba2019-05-16 14:07:43 -0600234 die_with_post_code(POST_INVALID_VENDOR_BINARY,
235 "Please verify the chipset reserved size\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700236 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700237 }
238
239 /* Verify the FSP 1.1 HOB interface */
240 if (fsp_verification_failure)
Keith Shortbb41aba2019-05-16 14:07:43 -0600241 die_with_post_code(POST_INVALID_VENDOR_BINARY,
242 "ERROR - coreboot's requirements not met by FSP binary!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700243
244 /* Display the memory configuration */
245 report_memory_config();
246
247 /* Locate the memory configuration data to speed up the next reboot */
248 mrc_hob = get_next_guid_hob(&mrc_guid, hob_list_ptr);
Matt DeVillier41833122019-08-02 20:16:36 -0500249 if (mrc_hob == NULL)
Lee Leahy0946ec32015-04-20 15:24:54 -0700250 printk(BIOS_DEBUG,
251 "Memory Configuration Data Hob not present\n");
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700252 else if (!vboot_recovery_mode_enabled()) {
haridhar07e9e6f2015-12-18 10:50:46 +0530253 /* Do not save MRC data in recovery path */
Nico Huber66318aa2019-05-04 16:59:20 +0200254 params->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
Felix Held51ff9e82019-06-20 14:49:16 +0200255 params->data_to_save_size = ALIGN_UP(
Lee Leahy0946ec32015-04-20 15:24:54 -0700256 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
257 }
258}
259
260/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600261__weak void mainboard_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700262 struct romstage_params *params,
263 MEMORY_INIT_UPD *upd_ptr)
264{
265 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
266}
267
268/* Display the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600269__weak void soc_display_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700270 const MEMORY_INIT_UPD *old, MEMORY_INIT_UPD *new)
271{
272 printk(BIOS_SPEW, "UPD values for MemoryInit:\n");
273 hexdump32(BIOS_SPEW, new, sizeof(*new));
274}
275
276/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600277__weak void soc_memory_init_params(
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700278 struct romstage_params *params,
279 MEMORY_INIT_UPD *upd)
Lee Leahy0946ec32015-04-20 15:24:54 -0700280{
281 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
282}
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200283
284/* Initialize the SoC after MemoryInit */
285__weak void mainboard_after_memory_init(void)
286{
287 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
288}