blob: 208ebb5a58c32b2c31562729f390c3916e26cc5e [file] [log] [blame]
Lee Leahy0946ec32015-04-20 15:24:54 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy0946ec32015-04-20 15:24:54 -07004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Lee Leahy0946ec32015-04-20 15:24:54 -070012 */
13
Aaron Durbin932e09d2016-07-13 23:09:52 -050014#include <arch/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070015#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +020016#include <cf9_reset.h>
Elyes HAOUAS2195f7a2019-06-21 07:20:12 +020017#include <commonlib/helpers.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070018#include <console/console.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030019#include <cpu/x86/smm.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080020#include <fsp/romstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050021#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070022#include <lib.h> /* hexdump */
Lee Leahy0946ec32015-04-20 15:24:54 -070023#include <string.h>
24#include <timestamp.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020025#include <security/vboot/vboot_common.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070026
27void raminit(struct romstage_params *params)
28{
Nico Huber16895c52019-05-04 16:29:17 +020029 const bool s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070030 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
31 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
32 FSP_INFO_HEADER *fsp_header;
33 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
34 FSP_MEMORY_INIT fsp_memory_init;
35 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
36 const EFI_GUID fsp_reserved_guid =
37 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
38 void *fsp_reserved_memory_area;
39 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
40 void *hob_list_ptr;
41 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
42 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
43 MEMORY_INIT_UPD memory_init_params;
44 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
45 u32 *mrc_hob;
46 u32 fsp_reserved_bytes;
47 MEMORY_INIT_UPD *original_params;
Lee Leahy0946ec32015-04-20 15:24:54 -070048 EFI_STATUS status;
49 VPD_DATA_REGION *vpd_ptr;
50 UPD_DATA_REGION *upd_ptr;
51 int fsp_verification_failure = 0;
Lee Leahy0946ec32015-04-20 15:24:54 -070052 EFI_PEI_HOB_POINTERS hob_ptr;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030053 uintptr_t smm_base;
Kyösti Mälkkib4905622019-07-12 08:02:35 +030054 size_t smm_size;
Lee Leahy0946ec32015-04-20 15:24:54 -070055
56 /*
57 * Find and copy the UPD region to the stack so the platform can modify
58 * the settings if needed. Modifications to the UPD buffer are done in
59 * the platform callback code. The platform callback code is also
60 * responsible for assigning the UpdDataRngPtr to this buffer if any
61 * updates are made. The default state is to leave the UpdDataRngPtr
62 * set to NULL. This indicates that the FSP code will use the UPD
63 * region in the FSP binary.
64 */
Furquan Shaikh585210a2018-10-16 11:54:37 -070065 post_code(POST_MEM_PREINIT_PREP_START);
Aaron Durbine6af4be2015-09-24 12:26:31 -050066 fsp_header = params->chipset_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070067 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
68 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080069 printk(BIOS_DEBUG, "VPD Data: %p\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070070 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
71 fsp_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080072 printk(BIOS_DEBUG, "UPD Data: %p\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070073 original_params = (void *)((u8 *)upd_ptr +
74 upd_ptr->MemoryInitUpdOffset);
75 memcpy(&memory_init_params, original_params,
76 sizeof(memory_init_params));
77
78 /* Zero fill RT Buffer data and start populating fields. */
79 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
Nico Huber16895c52019-05-04 16:29:17 +020080 if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070081 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
Nico Huber66318aa2019-05-04 16:59:20 +020082 } else if (params->saved_data != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -070083 fsp_rt_common_buffer.BootMode =
84 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
85 } else {
86 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
87 }
88 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
89 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
90
91 /* Get any board specific changes */
Nico Huber66318aa2019-05-04 16:59:20 +020092 fsp_memory_init_params.NvsBufferPtr = (void *)params->saved_data;
Lee Leahy0946ec32015-04-20 15:24:54 -070093 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
94 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
95
96 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -070097 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070098 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070099
Julius Wernercd49cce2019-03-05 16:53:33 -0800100 if (CONFIG(MMA))
Pratik Prajapatib90b94d2015-09-11 13:51:38 -0700101 setup_mma(&memory_init_params);
102
Furquan Shaikh585210a2018-10-16 11:54:37 -0700103 post_code(POST_MEM_PREINIT_PREP_END);
Lee Leahy0946ec32015-04-20 15:24:54 -0700104
105 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -0800106 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -0700107 soc_display_memory_init_params(original_params,
108 &memory_init_params);
109
110 /* Call FspMemoryInit to initialize RAM */
111 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
112 + fsp_header->FspMemoryInitEntryOffset);
Julius Werner540a9802019-12-09 13:03:29 -0800113 printk(BIOS_DEBUG, "Calling FspMemoryInit: %p\n", fsp_memory_init);
114 printk(BIOS_SPEW, " %p: NvsBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700115 fsp_memory_init_params.NvsBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800116 printk(BIOS_SPEW, " %p: RtBufferPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700117 fsp_memory_init_params.RtBufferPtr);
Julius Werner540a9802019-12-09 13:03:29 -0800118 printk(BIOS_SPEW, " %p: HobListPtr\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700119 fsp_memory_init_params.HobListPtr);
120
121 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Duncan Lauriefb509832015-11-22 14:53:57 -0800122 post_code(POST_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700123 status = fsp_memory_init(&fsp_memory_init_params);
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200124 mainboard_after_memory_init();
Lee Leahy0946ec32015-04-20 15:24:54 -0700125 post_code(0x37);
126 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
127
128 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
129 if (status != EFI_SUCCESS)
Keith Short24302632019-05-16 14:08:31 -0600130 die_with_post_code(POST_RAM_FAILURE,
131 "ERROR - FspMemoryInit failed to initialize memory!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700132
133 /* Locate the FSP reserved memory area */
134 fsp_reserved_bytes = 0;
135 fsp_memory = get_next_resource_hob(&fsp_reserved_guid, hob_list_ptr);
136 if (fsp_memory == NULL) {
137 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200138 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700139 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
140 } else {
141 fsp_reserved_bytes = fsp_memory->ResourceLength;
142 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
143 (unsigned long int)fsp_reserved_bytes);
144 }
145
146 /* Display SMM area */
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300147 if (CONFIG(HAVE_SMI_HANDLER)) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300148 smm_region(&smm_base, &smm_size);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300149 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300150 printk(BIOS_DEBUG, "0x%08x: smm_base\n", (unsigned int)smm_base);
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300151 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700152
153 /* Migrate CAR data */
Julius Werner540a9802019-12-09 13:03:29 -0800154 printk(BIOS_DEBUG, "%p: cbmem_top\n", cbmem_top());
Nico Huber16895c52019-05-04 16:29:17 +0200155 if (!s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700156 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
157 fsp_reserved_bytes);
158 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
159 fsp_reserved_bytes)) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800160#if CONFIG(HAVE_ACPI_RESUME)
Lee Leahy0946ec32015-04-20 15:24:54 -0700161 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
162 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolphf677d172018-10-01 19:17:11 +0200163 /* FIXME: A "system" reset is likely enough: */
164 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700165#endif
166 }
167
168 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500169 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700170
171 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
172 cbmem_root = get_next_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
173 if (cbmem_root == NULL) {
174 fsp_verification_failure = 1;
175 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
176 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
177 fsp_rt_common_buffer.BootLoaderTolumSize);
178 }
179
180 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
181 memory_info_hob = get_next_guid_hob(&memory_info_hob_guid,
182 hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700183 if (memory_info_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700184 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
185 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700186 }
187
Frans Hendriks509f4692019-06-28 14:11:41 +0200188 if (hob_list_ptr == NULL)
189 die_with_post_code(POST_RAM_FAILURE,
190 "ERROR - HOB pointer is NULL!\n");
191
Lee Leahy0946ec32015-04-20 15:24:54 -0700192 /*
193 * Verify that FSP is generating the required HOBs:
194 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
195 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100196 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB only produced when
Frans Hendriks509f4692019-06-28 14:11:41 +0200197 * new NVS data is generated, verified below
Lee Leahy0946ec32015-04-20 15:24:54 -0700198 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
199 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
200 * FSP_SMBIOS_MEMORY_INFO HOB verified above
201 */
Lee Leahy0946ec32015-04-20 15:24:54 -0700202 hob_ptr.Raw = get_next_guid_hob(&mrc_guid, hob_list_ptr);
Frans Hendriks509f4692019-06-28 14:11:41 +0200203 if ((hob_ptr.Raw == NULL) && (params->saved_data == NULL)) {
204 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
205 fsp_verification_failure = 1;
Lee Leahy0946ec32015-04-20 15:24:54 -0700206 }
207
208 /* Verify all the HOBs are present */
209 if (fsp_verification_failure)
Frans Hendriks509f4692019-06-28 14:11:41 +0200210 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700211 "ERROR - Missing one or more required FSP HOBs!\n");
212
213 /* Display the HOBs */
Frans Hendriks509f4692019-06-28 14:11:41 +0200214 if (CONFIG(DISPLAY_HOBS))
Keith Shortbb41aba2019-05-16 14:07:43 -0600215 print_hob_type_structure(0, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700216
217 /* Get the address of the CBMEM region for the FSP reserved memory */
218 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
Julius Werner540a9802019-12-09 13:03:29 -0800219 printk(BIOS_DEBUG, "%p: fsp_reserved_memory_area\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700220 fsp_reserved_memory_area);
221
222 /* Verify the order of CBMEM root and FSP memory */
223 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
224 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
225 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200226 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700227 "ERROR - FSP reserved memory above CBMEM root!\n");
228 }
229
230 /* Verify that the FSP memory was properly reserved */
231 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
232 (fsp_memory->PhysicalStart !=
233 (unsigned int)fsp_reserved_memory_area))) {
234 fsp_verification_failure = 1;
Frans Hendriks509f4692019-06-28 14:11:41 +0200235 printk(BIOS_ERR, "ERROR - Reserving FSP memory area!\n");
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300236
237 if (CONFIG(HAVE_SMI_HANDLER) && cbmem_root != NULL) {
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300238 size_t delta_bytes = smm_base
Lee Leahy0946ec32015-04-20 15:24:54 -0700239 - cbmem_root->PhysicalStart
240 - cbmem_root->ResourceLength;
Frans Hendriks509f4692019-06-28 14:11:41 +0200241 printk(BIOS_ERR,
Lee Leahy0946ec32015-04-20 15:24:54 -0700242 "0x%08x: Chipset reserved bytes reported by FSP\n",
243 (unsigned int)delta_bytes);
Keith Shortbb41aba2019-05-16 14:07:43 -0600244 die_with_post_code(POST_INVALID_VENDOR_BINARY,
245 "Please verify the chipset reserved size\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700246 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700247 }
248
249 /* Verify the FSP 1.1 HOB interface */
250 if (fsp_verification_failure)
Keith Shortbb41aba2019-05-16 14:07:43 -0600251 die_with_post_code(POST_INVALID_VENDOR_BINARY,
252 "ERROR - coreboot's requirements not met by FSP binary!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700253
254 /* Display the memory configuration */
255 report_memory_config();
256
257 /* Locate the memory configuration data to speed up the next reboot */
258 mrc_hob = get_next_guid_hob(&mrc_guid, hob_list_ptr);
Matt DeVillier41833122019-08-02 20:16:36 -0500259 if (mrc_hob == NULL)
Lee Leahy0946ec32015-04-20 15:24:54 -0700260 printk(BIOS_DEBUG,
261 "Memory Configuration Data Hob not present\n");
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700262 else if (!vboot_recovery_mode_enabled()) {
haridhar07e9e6f2015-12-18 10:50:46 +0530263 /* Do not save MRC data in recovery path */
Nico Huber66318aa2019-05-04 16:59:20 +0200264 params->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
Felix Held51ff9e82019-06-20 14:49:16 +0200265 params->data_to_save_size = ALIGN_UP(
Lee Leahy0946ec32015-04-20 15:24:54 -0700266 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
267 }
268}
269
270/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600271__weak void mainboard_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700272 struct romstage_params *params,
273 MEMORY_INIT_UPD *upd_ptr)
274{
275 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
276}
277
278/* Display the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600279__weak void soc_display_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700280 const MEMORY_INIT_UPD *old, MEMORY_INIT_UPD *new)
281{
282 printk(BIOS_SPEW, "UPD values for MemoryInit:\n");
283 hexdump32(BIOS_SPEW, new, sizeof(*new));
284}
285
286/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600287__weak void soc_memory_init_params(
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700288 struct romstage_params *params,
289 MEMORY_INIT_UPD *upd)
Lee Leahy0946ec32015-04-20 15:24:54 -0700290{
291 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
292}
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200293
294/* Initialize the SoC after MemoryInit */
295__weak void mainboard_after_memory_init(void)
296{
297 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
298}