blob: dd35b0f228b71252c17724459e6c232389231d53 [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>
Elyes HAOUAS3b3d0852021-02-01 10:09:40 +010011#include <lib.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070012#include <string.h>
13#include <timestamp.h>
14
15void raminit(struct romstage_params *params)
16{
Nico Huber16895c52019-05-04 16:29:17 +020017 const bool s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070018 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
19 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
20 FSP_INFO_HEADER *fsp_header;
21 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
22 FSP_MEMORY_INIT fsp_memory_init;
23 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
24 const EFI_GUID fsp_reserved_guid =
25 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
26 void *fsp_reserved_memory_area;
27 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
28 void *hob_list_ptr;
29 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
30 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
31 MEMORY_INIT_UPD memory_init_params;
32 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
33 u32 *mrc_hob;
34 u32 fsp_reserved_bytes;
35 MEMORY_INIT_UPD *original_params;
Lee Leahy0946ec32015-04-20 15:24:54 -070036 EFI_STATUS status;
37 VPD_DATA_REGION *vpd_ptr;
38 UPD_DATA_REGION *upd_ptr;
39 int fsp_verification_failure = 0;
Lee Leahy0946ec32015-04-20 15:24:54 -070040 EFI_PEI_HOB_POINTERS hob_ptr;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030041 uintptr_t smm_base;
Kyösti Mälkkib4905622019-07-12 08:02:35 +030042 size_t smm_size;
Lee Leahy0946ec32015-04-20 15:24:54 -070043
44 /*
45 * Find and copy the UPD region to the stack so the platform can modify
46 * the settings if needed. Modifications to the UPD buffer are done in
47 * the platform callback code. The platform callback code is also
48 * responsible for assigning the UpdDataRngPtr to this buffer if any
49 * updates are made. The default state is to leave the UpdDataRngPtr
50 * set to NULL. This indicates that the FSP code will use the UPD
51 * region in the FSP binary.
52 */
lilacious40cb3fe2023-06-21 23:24:14 +020053 post_code(POSTCODE_MEM_PREINIT_PREP_START);
Aaron Durbine6af4be2015-09-24 12:26:31 -050054 fsp_header = params->chipset_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070055 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
56 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080057 printk(BIOS_DEBUG, "VPD Data: %p\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070058 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
59 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080060 printk(BIOS_DEBUG, "UPD Data: %p\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070061 original_params = (void *)((u8 *)upd_ptr +
62 upd_ptr->MemoryInitUpdOffset);
63 memcpy(&memory_init_params, original_params,
64 sizeof(memory_init_params));
65
66 /* Zero fill RT Buffer data and start populating fields. */
67 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
Nico Huber16895c52019-05-04 16:29:17 +020068 if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070069 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
Nico Huber66318aa2019-05-04 16:59:20 +020070 } else if (params->saved_data != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -070071 fsp_rt_common_buffer.BootMode =
72 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
73 } else {
74 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
75 }
76 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
77 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
78
79 /* Get any board specific changes */
Nico Huber66318aa2019-05-04 16:59:20 +020080 fsp_memory_init_params.NvsBufferPtr = (void *)params->saved_data;
Lee Leahy0946ec32015-04-20 15:24:54 -070081 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
82 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
83
84 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -070085 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070086 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070087
Julius Wernercd49cce2019-03-05 16:53:33 -080088 if (CONFIG(MMA))
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070089 setup_mma(&memory_init_params);
90
lilacious40cb3fe2023-06-21 23:24:14 +020091 post_code(POSTCODE_MEM_PREINIT_PREP_END);
Lee Leahy0946ec32015-04-20 15:24:54 -070092
93 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -080094 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -070095 soc_display_memory_init_params(original_params,
96 &memory_init_params);
97
98 /* Call FspMemoryInit to initialize RAM */
99 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
100 + fsp_header->FspMemoryInitEntryOffset);
Julius Werner540a9802019-12-09 13:03:29 -0800101 printk(BIOS_DEBUG, "Calling FspMemoryInit: %p\n", fsp_memory_init);
102 printk(BIOS_SPEW, " %p: NvsBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700103 fsp_memory_init_params.NvsBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800104 printk(BIOS_SPEW, " %p: RtBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700105 fsp_memory_init_params.RtBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800106 printk(BIOS_SPEW, " %p: HobListPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700107 fsp_memory_init_params.HobListPtr);
108
109 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
lilacious40cb3fe2023-06-21 23:24:14 +0200110 post_code(POSTCODE_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700111 status = fsp_memory_init(&fsp_memory_init_params);
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200112 mainboard_after_memory_init();
Lee Leahy0946ec32015-04-20 15:24:54 -0700113 post_code(0x37);
114 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
115
116 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
117 if (status != EFI_SUCCESS)
lilacious40cb3fe2023-06-21 23:24:14 +0200118 die_with_post_code(POSTCODE_RAM_FAILURE,
Keith Short24302632019-05-16 14:08:31 -0600119 "ERROR - FspMemoryInit failed to initialize memory!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700120
121 /* Locate the FSP reserved memory area */
122 fsp_reserved_bytes = 0;
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200123 fsp_memory = get_resource_hob(&fsp_reserved_guid, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700124 if (fsp_memory == NULL) {
125 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200126 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700127 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
128 } else {
129 fsp_reserved_bytes = fsp_memory->ResourceLength;
130 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
131 (unsigned long int)fsp_reserved_bytes);
132 }
133
134 /* Display SMM area */
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300135 if (CONFIG(HAVE_SMI_HANDLER)) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300136 smm_region(&smm_base, &smm_size);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300137 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300138 printk(BIOS_DEBUG, "0x%08x: smm_base\n", (unsigned int)smm_base);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300139 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700140
141 /* Migrate CAR data */
Julius Werner540a9802019-12-09 13:03:29 -0800142 printk(BIOS_DEBUG, "%p: cbmem_top\n", cbmem_top());
Nico Huber16895c52019-05-04 16:29:17 +0200143 if (!s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700144 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
145 fsp_reserved_bytes);
146 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
147 fsp_reserved_bytes)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700148 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
149 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolphf677d172018-10-01 19:17:11 +0200150 /* FIXME: A "system" reset is likely enough: */
151 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700152 }
153
154 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500155 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700156
157 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200158 cbmem_root = get_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700159 if (cbmem_root == NULL) {
160 fsp_verification_failure = 1;
161 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
162 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
163 fsp_rt_common_buffer.BootLoaderTolumSize);
164 }
165
166 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200167 memory_info_hob = get_guid_hob(&memory_info_hob_guid,
Lee Leahy0946ec32015-04-20 15:24:54 -0700168 hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700169 if (memory_info_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700170 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
171 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700172 }
173
Frans Hendriks509f4692019-06-28 14:11:41 +0200174 if (hob_list_ptr == NULL)
lilacious40cb3fe2023-06-21 23:24:14 +0200175 die_with_post_code(POSTCODE_RAM_FAILURE,
Frans Hendriks509f4692019-06-28 14:11:41 +0200176 "ERROR - HOB pointer is NULL!\n");
177
Lee Leahy0946ec32015-04-20 15:24:54 -0700178 /*
179 * Verify that FSP is generating the required HOBs:
180 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
181 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100182 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB only produced when
Frans Hendriks509f4692019-06-28 14:11:41 +0200183 * new NVS data is generated, verified below
Lee Leahy0946ec32015-04-20 15:24:54 -0700184 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
185 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
186 * FSP_SMBIOS_MEMORY_INFO HOB verified above
187 */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200188 hob_ptr.Raw = get_guid_hob(&mrc_guid, hob_list_ptr);
Frans Hendriks509f4692019-06-28 14:11:41 +0200189 if ((hob_ptr.Raw == NULL) && (params->saved_data == NULL)) {
190 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
191 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700192 }
193
194 /* Verify all the HOBs are present */
195 if (fsp_verification_failure)
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100196 printk(BIOS_ERR, "Missing one or more required FSP HOBs!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700197
198 /* Display the HOBs */
Frans Hendriks509f4692019-06-28 14:11:41 +0200199 if (CONFIG(DISPLAY_HOBS))
Keith Shortbb41aba2019-05-16 14:07:43 -0600200 print_hob_type_structure(0, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700201
202 /* Get the address of the CBMEM region for the FSP reserved memory */
203 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
Julius Werner540a9802019-12-09 13:03:29 -0800204 printk(BIOS_DEBUG, "%p: fsp_reserved_memory_area\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700205 fsp_reserved_memory_area);
206
207 /* Verify the order of CBMEM root and FSP memory */
208 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
209 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
210 fsp_verification_failure = 1;
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100211 printk(BIOS_ERR, "FSP reserved memory above CBMEM root!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700212 }
213
214 /* Verify that the FSP memory was properly reserved */
215 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
216 (fsp_memory->PhysicalStart !=
217 (unsigned int)fsp_reserved_memory_area))) {
218 fsp_verification_failure = 1;
Elyes HAOUAS22ad8f22022-02-04 19:44:16 +0100219 printk(BIOS_ERR, "Reserving FSP memory area!\n");
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300220
221 if (CONFIG(HAVE_SMI_HANDLER) && cbmem_root != NULL) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300222 size_t delta_bytes = smm_base
Lee Leahy0946ec32015-04-20 15:24:54 -0700223 - cbmem_root->PhysicalStart
224 - cbmem_root->ResourceLength;
Frans Hendriks509f4692019-06-28 14:11:41 +0200225 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700226 "0x%08x: Chipset reserved bytes reported by FSP\n",
227 (unsigned int)delta_bytes);
lilacious40cb3fe2023-06-21 23:24:14 +0200228 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600229 "Please verify the chipset reserved size\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700230 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700231 }
232
233 /* Verify the FSP 1.1 HOB interface */
234 if (fsp_verification_failure)
lilacious40cb3fe2023-06-21 23:24:14 +0200235 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600236 "ERROR - coreboot's requirements not met by FSP binary!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700237
Lee Leahy0946ec32015-04-20 15:24:54 -0700238 /* Locate the memory configuration data to speed up the next reboot */
Arthur Heymansca74d7e2022-03-30 14:41:16 +0200239 mrc_hob = get_guid_hob(&mrc_guid, hob_list_ptr);
Julius Werner29fbfcc2020-03-02 15:54:43 -0800240 if (mrc_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700241 printk(BIOS_DEBUG,
242 "Memory Configuration Data Hob not present\n");
Julius Werner29fbfcc2020-03-02 15:54:43 -0800243 } else {
Nico Huber66318aa2019-05-04 16:59:20 +0200244 params->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
Felix Held51ff9e82019-06-20 14:49:16 +0200245 params->data_to_save_size = ALIGN_UP(
Lee Leahy0946ec32015-04-20 15:24:54 -0700246 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
247 }
248}
249
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200250/* Initialize the SoC after MemoryInit */
251__weak void mainboard_after_memory_init(void)
252{
253 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
254}