blob: 2aec5db7cd0427cf4edb14597be7afc3fa155886 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy0946ec32015-04-20 15:24:54 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07004#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02005#include <cf9_reset.h>
Elyes HAOUAS2195f7a2019-06-21 07:20:12 +02006#include <commonlib/helpers.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07007#include <console/console.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03008#include <cpu/x86/smm.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -08009#include <fsp/romstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050010#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070011#include <string.h>
12#include <timestamp.h>
13
14void raminit(struct romstage_params *params)
15{
Nico Huber16895c52019-05-04 16:29:17 +020016 const bool s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070017 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
18 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
19 FSP_INFO_HEADER *fsp_header;
20 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
21 FSP_MEMORY_INIT fsp_memory_init;
22 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
23 const EFI_GUID fsp_reserved_guid =
24 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
25 void *fsp_reserved_memory_area;
26 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
27 void *hob_list_ptr;
28 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
29 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
30 MEMORY_INIT_UPD memory_init_params;
31 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
32 u32 *mrc_hob;
33 u32 fsp_reserved_bytes;
34 MEMORY_INIT_UPD *original_params;
Lee Leahy0946ec32015-04-20 15:24:54 -070035 EFI_STATUS status;
36 VPD_DATA_REGION *vpd_ptr;
37 UPD_DATA_REGION *upd_ptr;
38 int fsp_verification_failure = 0;
Lee Leahy0946ec32015-04-20 15:24:54 -070039 EFI_PEI_HOB_POINTERS hob_ptr;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030040 uintptr_t smm_base;
Kyösti Mälkkib4905622019-07-12 08:02:35 +030041 size_t smm_size;
Lee Leahy0946ec32015-04-20 15:24:54 -070042
43 /*
44 * Find and copy the UPD region to the stack so the platform can modify
45 * the settings if needed. Modifications to the UPD buffer are done in
46 * the platform callback code. The platform callback code is also
47 * responsible for assigning the UpdDataRngPtr to this buffer if any
48 * updates are made. The default state is to leave the UpdDataRngPtr
49 * set to NULL. This indicates that the FSP code will use the UPD
50 * region in the FSP binary.
51 */
lilacious40cb3fe2023-06-21 23:24:14 +020052 post_code(POSTCODE_MEM_PREINIT_PREP_START);
Aaron Durbine6af4be2015-09-24 12:26:31 -050053 fsp_header = params->chipset_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070054 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
55 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080056 printk(BIOS_DEBUG, "VPD Data: %p\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070057 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
58 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080059 printk(BIOS_DEBUG, "UPD Data: %p\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070060 original_params = (void *)((u8 *)upd_ptr +
61 upd_ptr->MemoryInitUpdOffset);
62 memcpy(&memory_init_params, original_params,
63 sizeof(memory_init_params));
64
65 /* Zero fill RT Buffer data and start populating fields. */
66 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
Nico Huber16895c52019-05-04 16:29:17 +020067 if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070068 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
Nico Huber66318aa2019-05-04 16:59:20 +020069 } else if (params->saved_data != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -070070 fsp_rt_common_buffer.BootMode =
71 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
72 } else {
73 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
74 }
75 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
76 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
77
78 /* Get any board specific changes */
Nico Huber66318aa2019-05-04 16:59:20 +020079 fsp_memory_init_params.NvsBufferPtr = (void *)params->saved_data;
Lee Leahy0946ec32015-04-20 15:24:54 -070080 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
81 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
82
83 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -070084 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070085 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070086
Julius Wernercd49cce2019-03-05 16:53:33 -080087 if (CONFIG(MMA))
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070088 setup_mma(&memory_init_params);
89
lilacious40cb3fe2023-06-21 23:24:14 +020090 post_code(POSTCODE_MEM_PREINIT_PREP_END);
Lee Leahy0946ec32015-04-20 15:24:54 -070091
92 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -080093 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -070094 soc_display_memory_init_params(original_params,
95 &memory_init_params);
96
97 /* Call FspMemoryInit to initialize RAM */
98 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
99 + fsp_header->FspMemoryInitEntryOffset);
Julius Werner540a9802019-12-09 13:03:29 -0800100 printk(BIOS_DEBUG, "Calling FspMemoryInit: %p\n", fsp_memory_init);
101 printk(BIOS_SPEW, " %p: NvsBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700102 fsp_memory_init_params.NvsBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800103 printk(BIOS_SPEW, " %p: RtBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700104 fsp_memory_init_params.RtBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800105 printk(BIOS_SPEW, " %p: HobListPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700106 fsp_memory_init_params.HobListPtr);
107
108 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
lilacious40cb3fe2023-06-21 23:24:14 +0200109 post_code(POSTCODE_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700110 status = fsp_memory_init(&fsp_memory_init_params);
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200111 mainboard_after_memory_init();
Lee Leahy0946ec32015-04-20 15:24:54 -0700112 post_code(0x37);
113 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
114
115 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
116 if (status != EFI_SUCCESS)
lilacious40cb3fe2023-06-21 23:24:14 +0200117 die_with_post_code(POSTCODE_RAM_FAILURE,
Keith Short24302632019-05-16 14:08:31 -0600118 "ERROR - FspMemoryInit failed to initialize memory!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700119
120 /* Locate the FSP reserved memory area */
121 fsp_reserved_bytes = 0;
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200122 fsp_memory = get_resource_hob(&fsp_reserved_guid, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700123 if (fsp_memory == NULL) {
124 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200125 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700126 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
127 } else {
128 fsp_reserved_bytes = fsp_memory->ResourceLength;
129 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
130 (unsigned long int)fsp_reserved_bytes);
131 }
132
133 /* Display SMM area */
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300134 if (CONFIG(HAVE_SMI_HANDLER)) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300135 smm_region(&smm_base, &smm_size);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300136 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300137 printk(BIOS_DEBUG, "0x%08x: smm_base\n", (unsigned int)smm_base);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300138 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700139
140 /* Migrate CAR data */
Julius Werner540a9802019-12-09 13:03:29 -0800141 printk(BIOS_DEBUG, "%p: cbmem_top\n", cbmem_top());
Nico Huber16895c52019-05-04 16:29:17 +0200142 if (!s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700143 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
144 fsp_reserved_bytes);
145 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
146 fsp_reserved_bytes)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700147 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
148 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolphf677d172018-10-01 19:17:11 +0200149 /* FIXME: A "system" reset is likely enough: */
150 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700151 }
152
153 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500154 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700155
156 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200157 cbmem_root = get_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700158 if (cbmem_root == NULL) {
159 fsp_verification_failure = 1;
160 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
161 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
162 fsp_rt_common_buffer.BootLoaderTolumSize);
163 }
164
165 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200166 memory_info_hob = get_guid_hob(&memory_info_hob_guid,
Lee Leahy0946ec32015-04-20 15:24:54 -0700167 hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700168 if (memory_info_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700169 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
170 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700171 }
172
Frans Hendriks509f4692019-06-28 14:11:41 +0200173 if (hob_list_ptr == NULL)
lilacious40cb3fe2023-06-21 23:24:14 +0200174 die_with_post_code(POSTCODE_RAM_FAILURE,
Frans Hendriks509f4692019-06-28 14:11:41 +0200175 "ERROR - HOB pointer is NULL!\n");
176
Lee Leahy0946ec32015-04-20 15:24:54 -0700177 /*
178 * Verify that FSP is generating the required HOBs:
179 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
180 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100181 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB only produced when
Frans Hendriks509f4692019-06-28 14:11:41 +0200182 * new NVS data is generated, verified below
Lee Leahy0946ec32015-04-20 15:24:54 -0700183 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
184 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
185 * FSP_SMBIOS_MEMORY_INFO HOB verified above
186 */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200187 hob_ptr.Raw = get_guid_hob(&mrc_guid, hob_list_ptr);
Frans Hendriks509f4692019-06-28 14:11:41 +0200188 if ((hob_ptr.Raw == NULL) && (params->saved_data == NULL)) {
189 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
190 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700191 }
192
193 /* Verify all the HOBs are present */
194 if (fsp_verification_failure)
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100195 printk(BIOS_ERR, "Missing one or more required FSP HOBs!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700196
197 /* Display the HOBs */
Frans Hendriks509f4692019-06-28 14:11:41 +0200198 if (CONFIG(DISPLAY_HOBS))
Keith Shortbb41aba2019-05-16 14:07:43 -0600199 print_hob_type_structure(0, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700200
201 /* Get the address of the CBMEM region for the FSP reserved memory */
202 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
Julius Werner540a9802019-12-09 13:03:29 -0800203 printk(BIOS_DEBUG, "%p: fsp_reserved_memory_area\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700204 fsp_reserved_memory_area);
205
206 /* Verify the order of CBMEM root and FSP memory */
207 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
208 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
209 fsp_verification_failure = 1;
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100210 printk(BIOS_ERR, "FSP reserved memory above CBMEM root!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700211 }
212
213 /* Verify that the FSP memory was properly reserved */
214 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
215 (fsp_memory->PhysicalStart !=
216 (unsigned int)fsp_reserved_memory_area))) {
217 fsp_verification_failure = 1;
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100218 printk(BIOS_ERR, "Reserving FSP memory area!\n");
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300219
220 if (CONFIG(HAVE_SMI_HANDLER) && cbmem_root != NULL) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300221 size_t delta_bytes = smm_base
Lee Leahy0946ec32015-04-20 15:24:54 -0700222 - cbmem_root->PhysicalStart
223 - cbmem_root->ResourceLength;
Frans Hendriks509f4692019-06-28 14:11:41 +0200224 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700225 "0x%08x: Chipset reserved bytes reported by FSP\n",
226 (unsigned int)delta_bytes);
lilacious40cb3fe2023-06-21 23:24:14 +0200227 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600228 "Please verify the chipset reserved size\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700229 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700230 }
231
232 /* Verify the FSP 1.1 HOB interface */
233 if (fsp_verification_failure)
lilacious40cb3fe2023-06-21 23:24:14 +0200234 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600235 "ERROR - coreboot's requirements not met by FSP binary!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700236
Lee Leahy0946ec32015-04-20 15:24:54 -0700237 /* Locate the memory configuration data to speed up the next reboot */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200238 mrc_hob = get_guid_hob(&mrc_guid, hob_list_ptr);
Julius Werner29fbfcc2020-03-02 15:54:43 -0800239 if (mrc_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700240 printk(BIOS_DEBUG,
Martin Roth74f18772023-09-03 21:38:29 -0600241 "Memory Configuration Data HOB not present\n");
Julius Werner29fbfcc2020-03-02 15:54:43 -0800242 } else {
Nico Huber66318aa2019-05-04 16:59:20 +0200243 params->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
Felix Held51ff9e82019-06-20 14:49:16 +0200244 params->data_to_save_size = ALIGN_UP(
Lee Leahy0946ec32015-04-20 15:24:54 -0700245 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
246 }
247}
248
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200249/* Initialize the SoC after MemoryInit */
250__weak void mainboard_after_memory_init(void)
251{
252 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
253}