blob: a631fcae607c20f911c0a94899e08adc3ecbcf8d [file] [log] [blame]
Lee Leahy0946ec32015-04-20 15:24:54 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahyb092c9e2016-01-01 18:09:50 -08004 * Copyright (C) 2014-2016 Intel Corporation
Frans Hendriks8f95edc2018-11-06 12:04:34 +01005 * Copyright (C) 2018 Eltan B.V.
Lee Leahy0946ec32015-04-20 15:24:54 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy0946ec32015-04-20 15:24:54 -070015 */
16
Aaron Durbin932e09d2016-07-13 23:09:52 -050017#include <arch/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070018#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +020019#include <cf9_reset.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070020#include <console/console.h>
Lee Leahy94b856e2015-10-15 12:07:03 -070021#include <fsp/memmap.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080022#include <fsp/romstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050023#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070024#include <lib.h> /* hexdump */
Lee Leahy0946ec32015-04-20 15:24:54 -070025#include <string.h>
26#include <timestamp.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020027#include <security/vboot/vboot_common.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070028
29void raminit(struct romstage_params *params)
30{
Nico Huber16895c52019-05-04 16:29:17 +020031 const bool s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070032 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
33 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
34 FSP_INFO_HEADER *fsp_header;
35 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
36 FSP_MEMORY_INIT fsp_memory_init;
37 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
38 const EFI_GUID fsp_reserved_guid =
39 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
40 void *fsp_reserved_memory_area;
41 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
42 void *hob_list_ptr;
43 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
44 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
45 MEMORY_INIT_UPD memory_init_params;
46 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
47 u32 *mrc_hob;
48 u32 fsp_reserved_bytes;
49 MEMORY_INIT_UPD *original_params;
Lee Leahy0946ec32015-04-20 15:24:54 -070050 EFI_STATUS status;
51 VPD_DATA_REGION *vpd_ptr;
52 UPD_DATA_REGION *upd_ptr;
53 int fsp_verification_failure = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -080054#if CONFIG(DISPLAY_HOBS)
Lee Leahy0946ec32015-04-20 15:24:54 -070055 unsigned long int data;
56 EFI_PEI_HOB_POINTERS hob_ptr;
57#endif
58
59 /*
60 * Find and copy the UPD region to the stack so the platform can modify
61 * the settings if needed. Modifications to the UPD buffer are done in
62 * the platform callback code. The platform callback code is also
63 * responsible for assigning the UpdDataRngPtr to this buffer if any
64 * updates are made. The default state is to leave the UpdDataRngPtr
65 * set to NULL. This indicates that the FSP code will use the UPD
66 * region in the FSP binary.
67 */
Furquan Shaikh585210a2018-10-16 11:54:37 -070068 post_code(POST_MEM_PREINIT_PREP_START);
Aaron Durbine6af4be2015-09-24 12:26:31 -050069 fsp_header = params->chipset_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070070 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
71 fsp_header->ImageBase);
72 printk(BIOS_DEBUG, "VPD Data: 0x%p\n", vpd_ptr);
73 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
74 fsp_header->ImageBase);
75 printk(BIOS_DEBUG, "UPD Data: 0x%p\n", upd_ptr);
76 original_params = (void *)((u8 *)upd_ptr +
77 upd_ptr->MemoryInitUpdOffset);
78 memcpy(&memory_init_params, original_params,
79 sizeof(memory_init_params));
80
81 /* Zero fill RT Buffer data and start populating fields. */
82 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
Nico Huber16895c52019-05-04 16:29:17 +020083 if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070084 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
Nico Huber66318aa2019-05-04 16:59:20 +020085 } else if (params->saved_data != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -070086 fsp_rt_common_buffer.BootMode =
87 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
88 } else {
89 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
90 }
91 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
92 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
93
94 /* Get any board specific changes */
Nico Huber66318aa2019-05-04 16:59:20 +020095 fsp_memory_init_params.NvsBufferPtr = (void *)params->saved_data;
Lee Leahy0946ec32015-04-20 15:24:54 -070096 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
97 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
98
99 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700100 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -0700101 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -0700102
Julius Wernercd49cce2019-03-05 16:53:33 -0800103 if (CONFIG(MMA))
Pratik Prajapatib90b94d2015-09-11 13:51:38 -0700104 setup_mma(&memory_init_params);
105
Furquan Shaikh585210a2018-10-16 11:54:37 -0700106 post_code(POST_MEM_PREINIT_PREP_END);
Lee Leahy0946ec32015-04-20 15:24:54 -0700107
108 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -0800109 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -0700110 soc_display_memory_init_params(original_params,
111 &memory_init_params);
112
113 /* Call FspMemoryInit to initialize RAM */
114 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
115 + fsp_header->FspMemoryInitEntryOffset);
116 printk(BIOS_DEBUG, "Calling FspMemoryInit: 0x%p\n", fsp_memory_init);
117 printk(BIOS_SPEW, " 0x%p: NvsBufferPtr\n",
118 fsp_memory_init_params.NvsBufferPtr);
119 printk(BIOS_SPEW, " 0x%p: RtBufferPtr\n",
120 fsp_memory_init_params.RtBufferPtr);
121 printk(BIOS_SPEW, " 0x%p: HobListPtr\n",
122 fsp_memory_init_params.HobListPtr);
123
124 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Duncan Lauriefb509832015-11-22 14:53:57 -0800125 post_code(POST_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700126 status = fsp_memory_init(&fsp_memory_init_params);
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200127 mainboard_after_memory_init();
Lee Leahy0946ec32015-04-20 15:24:54 -0700128 post_code(0x37);
129 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
130
131 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
132 if (status != EFI_SUCCESS)
Keith Short24302632019-05-16 14:08:31 -0600133 die_with_post_code(POST_RAM_FAILURE,
134 "ERROR - FspMemoryInit failed to initialize memory!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700135
136 /* Locate the FSP reserved memory area */
137 fsp_reserved_bytes = 0;
138 fsp_memory = get_next_resource_hob(&fsp_reserved_guid, hob_list_ptr);
139 if (fsp_memory == NULL) {
140 fsp_verification_failure = 1;
141 printk(BIOS_DEBUG,
142 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
143 } else {
144 fsp_reserved_bytes = fsp_memory->ResourceLength;
145 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
146 (unsigned long int)fsp_reserved_bytes);
147 }
148
149 /* Display SMM area */
Julius Wernercd49cce2019-03-05 16:53:33 -0800150#if CONFIG(HAVE_SMI_HANDLER)
Lee Leahy0946ec32015-04-20 15:24:54 -0700151 char *smm_base;
152 size_t smm_size;
153
154 smm_region((void **)&smm_base, &smm_size);
155 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
156 printk(BIOS_DEBUG, "0x%p: smm_base\n", smm_base);
157#endif
158
159 /* Migrate CAR data */
Lee Leahy0946ec32015-04-20 15:24:54 -0700160 printk(BIOS_DEBUG, "0x%p: cbmem_top\n", cbmem_top());
Nico Huber16895c52019-05-04 16:29:17 +0200161 if (!s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700162 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
163 fsp_reserved_bytes);
164 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
165 fsp_reserved_bytes)) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800166#if CONFIG(HAVE_ACPI_RESUME)
Lee Leahy0946ec32015-04-20 15:24:54 -0700167 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
168 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolphf677d172018-10-01 19:17:11 +0200169 /* FIXME: A "system" reset is likely enough: */
170 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700171#endif
172 }
173
174 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500175 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700176
177 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
178 cbmem_root = get_next_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
179 if (cbmem_root == NULL) {
180 fsp_verification_failure = 1;
181 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
182 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
183 fsp_rt_common_buffer.BootLoaderTolumSize);
184 }
185
186 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
187 memory_info_hob = get_next_guid_hob(&memory_info_hob_guid,
188 hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700189 if (memory_info_hob == NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700190 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
191 fsp_verification_failure = 1;
192 } else {
193 printk(BIOS_DEBUG,
194 "FSP_SMBIOS_MEMORY_INFO HOB: 0x%p\n",
195 memory_info_hob);
196 }
197
Julius Wernercd49cce2019-03-05 16:53:33 -0800198#if CONFIG(DISPLAY_HOBS)
Lee Leahy0946ec32015-04-20 15:24:54 -0700199 /*
200 * Verify that FSP is generating the required HOBs:
201 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
202 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100203 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB only produced when
204 * new NVS data is generated, verified below
Lee Leahy0946ec32015-04-20 15:24:54 -0700205 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
206 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
207 * FSP_SMBIOS_MEMORY_INFO HOB verified above
208 */
Lee Leahy216712a2017-03-17 11:23:32 -0700209 if (cbmem_root != NULL) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700210 printk(BIOS_DEBUG,
211 "7.4: FSP_BOOTLOADER_TOLUM_HOB: 0x%p\n",
212 cbmem_root);
213 data = cbmem_root->PhysicalStart;
214 printk(BIOS_DEBUG, " 0x%016lx: PhysicalStart\n", data);
215 data = cbmem_root->ResourceLength;
216 printk(BIOS_DEBUG, " 0x%016lx: ResourceLength\n", data);
217 }
218 hob_ptr.Raw = get_next_guid_hob(&mrc_guid, hob_list_ptr);
Lee Leahy216712a2017-03-17 11:23:32 -0700219 if (hob_ptr.Raw == NULL) {
Nico Huber66318aa2019-05-04 16:59:20 +0200220 if (params->saved_data == NULL) {
Frans Hendriks8f95edc2018-11-06 12:04:34 +0100221 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
222 fsp_verification_failure = 1;
223 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700224 } else {
225 printk(BIOS_DEBUG,
226 "7.3: FSP_NON_VOLATILE_STORAGE_HOB: 0x%p\n",
227 hob_ptr.Raw);
228 }
229 if (fsp_memory != NULL) {
230 printk(BIOS_DEBUG,
231 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB: 0x%p\n",
232 fsp_memory);
233 data = fsp_memory->PhysicalStart;
234 printk(BIOS_DEBUG, " 0x%016lx: PhysicalStart\n", data);
235 data = fsp_memory->ResourceLength;
236 printk(BIOS_DEBUG, " 0x%016lx: ResourceLength\n", data);
237 }
238
239 /* Verify all the HOBs are present */
240 if (fsp_verification_failure)
241 printk(BIOS_DEBUG,
242 "ERROR - Missing one or more required FSP HOBs!\n");
243
244 /* Display the HOBs */
Keith Shortbb41aba2019-05-16 14:07:43 -0600245 if (hob_list_ptr != NULL)
246 print_hob_type_structure(0, hob_list_ptr);
247 else
248 printk(BIOS_ERR, "ERROR - HOB pointer is NULL!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700249#endif
250
251 /* Get the address of the CBMEM region for the FSP reserved memory */
252 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
253 printk(BIOS_DEBUG, "0x%p: fsp_reserved_memory_area\n",
254 fsp_reserved_memory_area);
255
256 /* Verify the order of CBMEM root and FSP memory */
257 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
258 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
259 fsp_verification_failure = 1;
260 printk(BIOS_DEBUG,
261 "ERROR - FSP reserved memory above CBMEM root!\n");
262 }
263
264 /* Verify that the FSP memory was properly reserved */
265 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
266 (fsp_memory->PhysicalStart !=
267 (unsigned int)fsp_reserved_memory_area))) {
268 fsp_verification_failure = 1;
269 printk(BIOS_DEBUG, "ERROR - Reserving FSP memory area!\n");
Julius Wernercd49cce2019-03-05 16:53:33 -0800270#if CONFIG(HAVE_SMI_HANDLER)
Lee Leahy0946ec32015-04-20 15:24:54 -0700271 if (cbmem_root != NULL) {
272 size_t delta_bytes = (unsigned int)smm_base
273 - cbmem_root->PhysicalStart
274 - cbmem_root->ResourceLength;
275 printk(BIOS_DEBUG,
Lee Leahy0946ec32015-04-20 15:24:54 -0700276 "0x%08x: Chipset reserved bytes reported by FSP\n",
277 (unsigned int)delta_bytes);
Keith Shortbb41aba2019-05-16 14:07:43 -0600278 die_with_post_code(POST_INVALID_VENDOR_BINARY,
279 "Please verify the chipset reserved size\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700280 }
281#endif
282 }
283
284 /* Verify the FSP 1.1 HOB interface */
285 if (fsp_verification_failure)
Keith Shortbb41aba2019-05-16 14:07:43 -0600286 die_with_post_code(POST_INVALID_VENDOR_BINARY,
287 "ERROR - coreboot's requirements not met by FSP binary!\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700288
289 /* Display the memory configuration */
290 report_memory_config();
291
292 /* Locate the memory configuration data to speed up the next reboot */
293 mrc_hob = get_next_guid_hob(&mrc_guid, hob_list_ptr);
294 if (mrc_hob == NULL)
295 printk(BIOS_DEBUG,
296 "Memory Configuration Data Hob not present\n");
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700297 else if (!vboot_recovery_mode_enabled()) {
haridhar07e9e6f2015-12-18 10:50:46 +0530298 /* Do not save MRC data in recovery path */
Nico Huber66318aa2019-05-04 16:59:20 +0200299 params->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
Felix Held51ff9e82019-06-20 14:49:16 +0200300 params->data_to_save_size = ALIGN_UP(
Lee Leahy0946ec32015-04-20 15:24:54 -0700301 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
302 }
303}
304
305/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600306__weak void mainboard_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700307 struct romstage_params *params,
308 MEMORY_INIT_UPD *upd_ptr)
309{
310 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
311}
312
313/* Display the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600314__weak void soc_display_memory_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700315 const MEMORY_INIT_UPD *old, MEMORY_INIT_UPD *new)
316{
317 printk(BIOS_SPEW, "UPD values for MemoryInit:\n");
318 hexdump32(BIOS_SPEW, new, sizeof(*new));
319}
320
321/* Initialize the UPD parameters for MemoryInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600322__weak void soc_memory_init_params(
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700323 struct romstage_params *params,
324 MEMORY_INIT_UPD *upd)
Lee Leahy0946ec32015-04-20 15:24:54 -0700325{
326 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
327}
Frans Hendriks1385b7d2019-04-05 13:42:14 +0200328
329/* Initialize the SoC after MemoryInit */
330__weak void mainboard_after_memory_init(void)
331{
332 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
333}