blob: 932d5c36e87576017c1bafbe1fd9839a9043b2d8 [file] [log] [blame]
Lee Leahy0946ec32015-04-20 15:24:54 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014-2015 Intel Corporation
5 *
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Lee Leahy40c05432015-05-27 17:25:47 -070017 * Foundation, Inc.
Lee Leahy0946ec32015-04-20 15:24:54 -070018 */
19
20#include <cbmem.h>
21#include <console/console.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050022#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070023#include <lib.h> /* hexdump */
24#include <reset.h>
25#include <soc/intel/common/memmap.h>
26#include <soc/pei_data.h>
27#include <soc/romstage.h>
28#include <string.h>
29#include <timestamp.h>
30
31void raminit(struct romstage_params *params)
32{
33 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
34 EFI_HOB_RESOURCE_DESCRIPTOR *cbmem_root;
35 FSP_INFO_HEADER *fsp_header;
36 EFI_HOB_RESOURCE_DESCRIPTOR *fsp_memory;
37 FSP_MEMORY_INIT fsp_memory_init;
38 FSP_MEMORY_INIT_PARAMS fsp_memory_init_params;
39 const EFI_GUID fsp_reserved_guid =
40 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
41 void *fsp_reserved_memory_area;
42 FSP_INIT_RT_COMMON_BUFFER fsp_rt_common_buffer;
43 void *hob_list_ptr;
44 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
45 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
46 MEMORY_INIT_UPD memory_init_params;
47 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
48 u32 *mrc_hob;
49 u32 fsp_reserved_bytes;
50 MEMORY_INIT_UPD *original_params;
51 struct pei_data *pei_ptr;
52 EFI_STATUS status;
53 VPD_DATA_REGION *vpd_ptr;
54 UPD_DATA_REGION *upd_ptr;
55 int fsp_verification_failure = 0;
56#if IS_ENABLED(CONFIG_DISPLAY_HOBS)
57 unsigned long int data;
58 EFI_PEI_HOB_POINTERS hob_ptr;
59#endif
Aaron Durbine1ecfc92015-09-16 15:18:04 -050060 struct fsp_car_context *fsp_car_context;
Lee Leahy0946ec32015-04-20 15:24:54 -070061
62 /*
63 * Find and copy the UPD region to the stack so the platform can modify
64 * the settings if needed. Modifications to the UPD buffer are done in
65 * the platform callback code. The platform callback code is also
66 * responsible for assigning the UpdDataRngPtr to this buffer if any
67 * updates are made. The default state is to leave the UpdDataRngPtr
68 * set to NULL. This indicates that the FSP code will use the UPD
69 * region in the FSP binary.
70 */
71 post_code(0x34);
Aaron Durbine1ecfc92015-09-16 15:18:04 -050072 fsp_car_context = params->chipset_context;
73 fsp_header = fsp_car_context->fih;
Lee Leahy0946ec32015-04-20 15:24:54 -070074 vpd_ptr = (VPD_DATA_REGION *)(fsp_header->CfgRegionOffset +
75 fsp_header->ImageBase);
76 printk(BIOS_DEBUG, "VPD Data: 0x%p\n", vpd_ptr);
77 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
78 fsp_header->ImageBase);
79 printk(BIOS_DEBUG, "UPD Data: 0x%p\n", upd_ptr);
80 original_params = (void *)((u8 *)upd_ptr +
81 upd_ptr->MemoryInitUpdOffset);
82 memcpy(&memory_init_params, original_params,
83 sizeof(memory_init_params));
84
85 /* Zero fill RT Buffer data and start populating fields. */
86 memset(&fsp_rt_common_buffer, 0, sizeof(fsp_rt_common_buffer));
87 pei_ptr = params->pei_data;
88 if (pei_ptr->boot_mode == SLEEP_STATE_S3) {
89 fsp_rt_common_buffer.BootMode = BOOT_ON_S3_RESUME;
90 } else if (pei_ptr->saved_data != NULL) {
91 fsp_rt_common_buffer.BootMode =
92 BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
93 } else {
94 fsp_rt_common_buffer.BootMode = BOOT_WITH_FULL_CONFIGURATION;
95 }
96 fsp_rt_common_buffer.UpdDataRgnPtr = &memory_init_params;
97 fsp_rt_common_buffer.BootLoaderTolumSize = cbmem_overhead_size();
98
99 /* Get any board specific changes */
100 fsp_memory_init_params.NvsBufferPtr = (void *)pei_ptr->saved_data;
101 fsp_memory_init_params.RtBufferPtr = &fsp_rt_common_buffer;
102 fsp_memory_init_params.HobListPtr = &hob_list_ptr;
103
104 /* Update the UPD data */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700105 soc_memory_init_params(params, &memory_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -0700106 mainboard_memory_init_params(params, &memory_init_params);
107 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);
126 status = fsp_memory_init(&fsp_memory_init_params);
127 post_code(0x37);
128 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
129
130 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
131 if (status != EFI_SUCCESS)
132 die("ERROR - FspMemoryInit failed to initialize memory!\n");
133
134 /* Locate the FSP reserved memory area */
135 fsp_reserved_bytes = 0;
136 fsp_memory = get_next_resource_hob(&fsp_reserved_guid, hob_list_ptr);
137 if (fsp_memory == NULL) {
138 fsp_verification_failure = 1;
139 printk(BIOS_DEBUG,
140 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
141 } else {
142 fsp_reserved_bytes = fsp_memory->ResourceLength;
143 printk(BIOS_DEBUG, "Reserving 0x%016lx bytes for FSP\n",
144 (unsigned long int)fsp_reserved_bytes);
145 }
146
147 /* Display SMM area */
148#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
149 char *smm_base;
150 size_t smm_size;
151
152 smm_region((void **)&smm_base, &smm_size);
153 printk(BIOS_DEBUG, "0x%08x: smm_size\n", (unsigned int)smm_size);
154 printk(BIOS_DEBUG, "0x%p: smm_base\n", smm_base);
155#endif
156
157 /* Migrate CAR data */
Lee Leahy0946ec32015-04-20 15:24:54 -0700158 printk(BIOS_DEBUG, "0x%p: cbmem_top\n", cbmem_top());
159 if (pei_ptr->boot_mode != SLEEP_STATE_S3) {
160 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
161 fsp_reserved_bytes);
162 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
163 fsp_reserved_bytes)) {
164#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
165 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
166 /* Failed S3 resume, reset to come up cleanly */
167 hard_reset();
168#endif
169 }
170
171 /* Save the FSP runtime parameters. */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500172 fsp_set_runtime(fsp_header, hob_list_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -0700173
174 /* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
175 cbmem_root = get_next_resource_hob(&bootldr_tolum_guid, hob_list_ptr);
176 if (cbmem_root == NULL) {
177 fsp_verification_failure = 1;
178 printk(BIOS_ERR, "7.4: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
179 printk(BIOS_ERR, "BootLoaderTolumSize: 0x%08x bytes\n",
180 fsp_rt_common_buffer.BootLoaderTolumSize);
181 }
182
183 /* Locate the FSP_SMBIOS_MEMORY_INFO HOB */
184 memory_info_hob = get_next_guid_hob(&memory_info_hob_guid,
185 hob_list_ptr);
186 if (NULL == memory_info_hob) {
187 printk(BIOS_ERR, "FSP_SMBIOS_MEMORY_INFO HOB missing!\n");
188 fsp_verification_failure = 1;
189 } else {
190 printk(BIOS_DEBUG,
191 "FSP_SMBIOS_MEMORY_INFO HOB: 0x%p\n",
192 memory_info_hob);
193 }
194
195#if IS_ENABLED(CONFIG_DISPLAY_HOBS)
196 if (hob_list_ptr == NULL)
197 die("ERROR - HOB pointer is NULL!\n");
198
199 /*
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
203 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB verified below
204 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified above
205 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB produced by SiliconInit
206 * FSP_SMBIOS_MEMORY_INFO HOB verified above
207 */
208 if (NULL != cbmem_root) {
209 printk(BIOS_DEBUG,
210 "7.4: FSP_BOOTLOADER_TOLUM_HOB: 0x%p\n",
211 cbmem_root);
212 data = cbmem_root->PhysicalStart;
213 printk(BIOS_DEBUG, " 0x%016lx: PhysicalStart\n", data);
214 data = cbmem_root->ResourceLength;
215 printk(BIOS_DEBUG, " 0x%016lx: ResourceLength\n", data);
216 }
217 hob_ptr.Raw = get_next_guid_hob(&mrc_guid, hob_list_ptr);
218 if (NULL == hob_ptr.Raw) {
219 printk(BIOS_ERR, "7.3: FSP_NON_VOLATILE_STORAGE_HOB missing!\n");
220 fsp_verification_failure =
221 (params->pei_data->saved_data == NULL) ? 1 : 0;
222 } else {
223 printk(BIOS_DEBUG,
224 "7.3: FSP_NON_VOLATILE_STORAGE_HOB: 0x%p\n",
225 hob_ptr.Raw);
226 }
227 if (fsp_memory != NULL) {
228 printk(BIOS_DEBUG,
229 "7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB: 0x%p\n",
230 fsp_memory);
231 data = fsp_memory->PhysicalStart;
232 printk(BIOS_DEBUG, " 0x%016lx: PhysicalStart\n", data);
233 data = fsp_memory->ResourceLength;
234 printk(BIOS_DEBUG, " 0x%016lx: ResourceLength\n", data);
235 }
236
237 /* Verify all the HOBs are present */
238 if (fsp_verification_failure)
239 printk(BIOS_DEBUG,
240 "ERROR - Missing one or more required FSP HOBs!\n");
241
242 /* Display the HOBs */
243 print_hob_type_structure(0, hob_list_ptr);
244#endif
245
246 /* Get the address of the CBMEM region for the FSP reserved memory */
247 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
248 printk(BIOS_DEBUG, "0x%p: fsp_reserved_memory_area\n",
249 fsp_reserved_memory_area);
250
251 /* Verify the order of CBMEM root and FSP memory */
252 if ((fsp_memory != NULL) && (cbmem_root != NULL) &&
253 (cbmem_root->PhysicalStart <= fsp_memory->PhysicalStart)) {
254 fsp_verification_failure = 1;
255 printk(BIOS_DEBUG,
256 "ERROR - FSP reserved memory above CBMEM root!\n");
257 }
258
259 /* Verify that the FSP memory was properly reserved */
260 if ((fsp_memory != NULL) && ((fsp_reserved_memory_area == NULL) ||
261 (fsp_memory->PhysicalStart !=
262 (unsigned int)fsp_reserved_memory_area))) {
263 fsp_verification_failure = 1;
264 printk(BIOS_DEBUG, "ERROR - Reserving FSP memory area!\n");
265#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
266 if (cbmem_root != NULL) {
267 size_t delta_bytes = (unsigned int)smm_base
268 - cbmem_root->PhysicalStart
269 - cbmem_root->ResourceLength;
270 printk(BIOS_DEBUG,
Lee Leahy0946ec32015-04-20 15:24:54 -0700271 "0x%08x: Chipset reserved bytes reported by FSP\n",
272 (unsigned int)delta_bytes);
273 die("Please verify the chipset reserved size\n");
274 }
275#endif
276 }
277
278 /* Verify the FSP 1.1 HOB interface */
279 if (fsp_verification_failure)
280 die("ERROR - Coreboot's requirements not met by FSP binary!\n");
281
282 /* Display the memory configuration */
283 report_memory_config();
284
285 /* Locate the memory configuration data to speed up the next reboot */
286 mrc_hob = get_next_guid_hob(&mrc_guid, hob_list_ptr);
287 if (mrc_hob == NULL)
288 printk(BIOS_DEBUG,
289 "Memory Configuration Data Hob not present\n");
290 else {
291 pei_ptr->data_to_save = GET_GUID_HOB_DATA(mrc_hob);
292 pei_ptr->data_to_save_size = ALIGN(
293 ((u32)GET_HOB_LENGTH(mrc_hob)), 16);
294 }
295}
296
297/* Initialize the UPD parameters for MemoryInit */
298__attribute__((weak)) void mainboard_memory_init_params(
299 struct romstage_params *params,
300 MEMORY_INIT_UPD *upd_ptr)
301{
302 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
303}
304
305/* Display the UPD parameters for MemoryInit */
306__attribute__((weak)) void soc_display_memory_init_params(
307 const MEMORY_INIT_UPD *old, MEMORY_INIT_UPD *new)
308{
309 printk(BIOS_SPEW, "UPD values for MemoryInit:\n");
310 hexdump32(BIOS_SPEW, new, sizeof(*new));
311}
312
313/* Initialize the UPD parameters for MemoryInit */
Duncan Laurie9dcd4f02015-08-17 18:09:14 -0700314__attribute__((weak)) void soc_memory_init_params(
315 struct romstage_params *params,
316 MEMORY_INIT_UPD *upd)
Lee Leahy0946ec32015-04-20 15:24:54 -0700317{
318 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
319}