blob: 3eee2da4e59b66ec63d544d43dafd73d6ca82895 [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
Lee Leahy0946ec32015-04-20 15:24:54 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Lee Leahy0946ec32015-04-20 15:24:54 -070014 */
15
Aaron Durbin932e09d2016-07-13 23:09:52 -050016#include <arch/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070017#include <cbmem.h>
18#include <console/console.h>
Lee Leahy94b856e2015-10-15 12:07:03 -070019#include <fsp/memmap.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 */
23#include <reset.h>
Pratik Prajapatib90b94d2015-09-11 13:51:38 -070024#include <soc/intel/common/mma.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070025#include <string.h>
26#include <timestamp.h>
haridhar07e9e6f2015-12-18 10:50:46 +053027#include <bootmode.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070028
29void raminit(struct romstage_params *params)
30{
31 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
32 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
33 FSP_INFO_HEADER *fsp_header;
34 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
35 FSP_MEMORY_INIT fsp_memory_init;
36 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
37 const EFI_GUID fsp_reserved_guid =
38 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
39 void *fsp_reserved_memory_area;
40 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
41 void *hob_list_ptr;
42 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
43 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
44 MEMORY_INIT_UPD memory_init_params;
45 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
46 u32 *mrc_hob;
47 u32 fsp_reserved_bytes;
48 MEMORY_INIT_UPD *original_params;
49 struct pei_data *pei_ptr;
50 EFI_STATUS status;
51 VPD_DATA_REGION *vpd_ptr;
52 UPD_DATA_REGION *upd_ptr;
53 int fsp_verification_failure = 0;
54#if IS_ENABLED(CONFIG_DISPLAY_HOBS)
55 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 */
68 post_code(0x34);
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));
83 pei_ptr = params->pei_data;
Aaron Durbin932e09d2016-07-13 23:09:52 -050084 if (pei_ptr->boot_mode == ACPI_S3) {
Lee Leahy0946ec32015-04-20 15:24:54 -070085 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
86 } else if (pei_ptr->saved_data != NULL) {
87 fsp_rt_common_buffer.BootMode =
88 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
89 } else {
90 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
91 }
92 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
93 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
94
95 /* Get any board specific changes */
96 fsp_memory_init_params.NvsBufferPtr = (void *)pei_ptr->saved_data;
97 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
98 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
99
100 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700101 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -0700102 mainboard_memory_init_params(params, &memory_init_params);
Pratik Prajapatib90b94d2015-09-11 13:51:38 -0700103
104 if (IS_ENABLED(CONFIG_MMA))
105 setup_mma(&memory_init_params);
106
Lee Leahy0946ec32015-04-20 15:24:54 -0700107 post_code(0x36);
108
109 /* Display the UPD data */
110 if (IS_ENABLED(CONFIG_DISPLAY_UPD_DATA))
111 soc_display_memory_init_params(original_params,
112 &memory_init_params);
113
114 /* Call FspMemoryInit to initialize RAM */
115 fsp_memory_init = (FSP_MEMORY_INIT)(fsp_header->ImageBase
116 + fsp_header->FspMemoryInitEntryOffset);
117 printk(BIOS_DEBUG, "Calling FspMemoryInit: 0x%p\n", fsp_memory_init);
118 printk(BIOS_SPEW, " 0x%p: NvsBufferPtr\n",
119 fsp_memory_init_params.NvsBufferPtr);
120 printk(BIOS_SPEW, " 0x%p: RtBufferPtr\n",
121 fsp_memory_init_params.RtBufferPtr);
122 printk(BIOS_SPEW, " 0x%p: HobListPtr\n",
123 fsp_memory_init_params.HobListPtr);
124
125 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Duncan Lauriefb509832015-11-22 14:53:57 -0800126 post_code(POST_FSP_MEMORY_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700127 status = fsp_memory_init(&fsp_memory_init_params);
128 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)
133 die("ERROR - FspMemoryInit failed to initialize memory!\n");
134
135 /* Locate the FSP reserved memory area */
136 fsp_reserved_bytes = 0;
137 fsp_memory = get_next_resource_hob(&fsp_reserved_guid, hob_list_ptr);
138 if (fsp_memory == NULL) {
139 fsp_verification_failure = 1;
140 printk(BIOS_DEBUG,
141 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
142 } else {
143 fsp_reserved_bytes = fsp_memory->ResourceLength;
144 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
145 (unsigned long int)fsp_reserved_bytes);
146 }
147
148 /* Display SMM area */
149#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
150 char *smm_base;
151 size_t smm_size;
152
153 smm_region((void **)&smm_base, &smm_size);
154 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
155 printk(BIOS_DEBUG, "0x%p: smm_base\n", smm_base);
156#endif
157
158 /* Migrate CAR data */
Lee Leahy0946ec32015-04-20 15:24:54 -0700159 printk(BIOS_DEBUG, "0x%p: cbmem_top\n", cbmem_top());
Aaron Durbin932e09d2016-07-13 23:09:52 -0500160 if (pei_ptr->boot_mode != ACPI_S3) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700161 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
162 fsp_reserved_bytes);
163 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
164 fsp_reserved_bytes)) {
165#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
166 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
167 /* Failed S3 resume, reset to come up cleanly */
168 hard_reset();
169#endif
170 }
171
172 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500173 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700174
175 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
176 cbmem_root = get_next_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
177 if (cbmem_root == NULL) {
178 fsp_verification_failure = 1;
179 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
180 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
181 fsp_rt_common_buffer.BootLoaderTolumSize);
182 }
183
184 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
185 memory_info_hob = get_next_guid_hob(&memory_info_hob_guid,
186 hob_list_ptr);
187 if (NULL == memory_info_hob) {
188 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
189 fsp_verification_failure = 1;
190 } else {
191 printk(BIOS_DEBUG,
192 "FSP_SMBIOS_MEMORY_INFO HOB: 0x%p\n",
193 memory_info_hob);
194 }
195
196#if IS_ENABLED(CONFIG_DISPLAY_HOBS)
197 if (hob_list_ptr == NULL)
198 die("ERROR - HOB pointer is NULL!\n");
199
200 /*
201 * Verify that FSP is generating the required HOBs:
202 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
203 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified above
204 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB verified below
205 * 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 */
209 if (NULL != cbmem_root) {
210 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);
219 if (NULL == hob_ptr.Raw) {
220 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
221 fsp_verification_failure =
222 (params->pei_data->saved_data == NULL) ? 1 : 0;
223 } else {
224 printk(BIOS_DEBUG,
225 "7.3: FSP_NON_VOLATILE_STORAGE_HOB: 0x%p\n",
226 hob_ptr.Raw);
227 }
228 if (fsp_memory != NULL) {
229 printk(BIOS_DEBUG,
230 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB: 0x%p\n",
231 fsp_memory);
232 data = fsp_memory->PhysicalStart;
233 printk(BIOS_DEBUG, " 0x%016lx: PhysicalStart\n", data);
234 data = fsp_memory->ResourceLength;
235 printk(BIOS_DEBUG, " 0x%016lx: ResourceLength\n", data);
236 }
237
238 /* Verify all the HOBs are present */
239 if (fsp_verification_failure)
240 printk(BIOS_DEBUG,
241 "ERROR - Missing one or more required FSP HOBs!\n");
242
243 /* Display the HOBs */
244 print_hob_type_structure(0, hob_list_ptr);
245#endif
246
247 /* Get the address of the CBMEM region for the FSP reserved memory */
248 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
249 printk(BIOS_DEBUG, "0x%p: fsp_reserved_memory_area\n",
250 fsp_reserved_memory_area);
251
252 /* Verify the order of CBMEM root and FSP memory */
253 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
254 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
255 fsp_verification_failure = 1;
256 printk(BIOS_DEBUG,
257 "ERROR - FSP reserved memory above CBMEM root!\n");
258 }
259
260 /* Verify that the FSP memory was properly reserved */
261 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
262 (fsp_memory->PhysicalStart !=
263 (unsigned int)fsp_reserved_memory_area))) {
264 fsp_verification_failure = 1;
265 printk(BIOS_DEBUG, "ERROR - Reserving FSP memory area!\n");
266#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
267 if (cbmem_root != NULL) {
268 size_t delta_bytes = (unsigned int)smm_base
269 - cbmem_root->PhysicalStart
270 - cbmem_root->ResourceLength;
271 printk(BIOS_DEBUG,
Lee Leahy0946ec32015-04-20 15:24:54 -0700272 "0x%08x: Chipset reserved bytes reported by FSP\n",
273 (unsigned int)delta_bytes);
274 die("Please verify the chipset reserved size\n");
275 }
276#endif
277 }
278
279 /* Verify the FSP 1.1 HOB interface */
280 if (fsp_verification_failure)
281 die("ERROR - Coreboot's requirements not met by FSP binary!\n");
282
283 /* Display the memory configuration */
284 report_memory_config();
285
286 /* Locate the memory configuration data to speed up the next reboot */
287 mrc_hob = get_next_guid_hob(&mrc_guid, hob_list_ptr);
288 if (mrc_hob == NULL)
289 printk(BIOS_DEBUG,
290 "Memory Configuration Data Hob not present\n");
haridhar07e9e6f2015-12-18 10:50:46 +0530291 else if (!recovery_mode_enabled()) {
292 /* Do not save MRC data in recovery path */
Lee Leahy0946ec32015-04-20 15:24:54 -0700293 pei_ptr->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
294 pei_ptr->data_to_save_size = ALIGN(
295 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
296 }
297}
298
299/* Initialize the UPD parameters for MemoryInit */
300__attribute__((weak)) void mainboard_memory_init_params(
301 struct romstage_params *params,
302 MEMORY_INIT_UPD *upd_ptr)
303{
304 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
305}
306
307/* Display the UPD parameters for MemoryInit */
308__attribute__((weak)) void soc_display_memory_init_params(
309 const MEMORY_INIT_UPD *old, MEMORY_INIT_UPD *new)
310{
311 printk(BIOS_SPEW, "UPD values for MemoryInit:\n");
312 hexdump32(BIOS_SPEW, new, sizeof(*new));
313}
314
315/* Initialize the UPD parameters for MemoryInit */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700316__attribute__((weak)) void soc_memory_init_params(
317 struct romstage_params *params,
318 MEMORY_INIT_UPD *upd)
Lee Leahy0946ec32015-04-20 15:24:54 -0700319{
320 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
321}