blob: b17927ab0992951db08344895880d021699ccc6f [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 Google Inc.
Lee Leahya6089692016-01-05 16:34:58 -08005 * Copyright (C) 2015-2016 Intel Corporation.
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
17#include <stddef.h>
18#include <stdint.h>
19#include <arch/cpu.h>
20#include <arch/io.h>
21#include <arch/cbfs.h>
22#include <arch/stages.h>
23#include <arch/early_variables.h>
Duncan Laurie91da91f2015-09-04 13:47:34 -070024#include <boardid.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070025#include <console/console.h>
26#include <cbmem.h>
27#include <cpu/x86/mtrr.h>
28#include <ec/google/chromeec/ec.h>
29#include <ec/google/chromeec/ec_commands.h>
30#include <elog.h>
Aaron Durbine1ecfc92015-09-16 15:18:04 -050031#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070032#include <memory_info.h>
33#include <reset.h>
34#include <romstage_handoff.h>
Lee Leahy0be6d932015-06-26 11:15:42 -070035#include <smbios.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070036#include <soc/intel/common/mrc_cache.h>
37#include <soc/intel/common/util.h>
38#include <soc/pei_wrapper.h>
39#include <soc/pm.h>
40#include <soc/romstage.h>
41#include <soc/spi.h>
42#include <stage_cache.h>
43#include <timestamp.h>
44#include <tpm.h>
45#include <vendorcode/google/chromeos/chromeos.h>
46
Aaron Durbine6af4be2015-09-24 12:26:31 -050047asmlinkage void *romstage_main(FSP_INFO_HEADER *fih)
Lee Leahy0946ec32015-04-20 15:24:54 -070048{
49 void *top_of_stack;
50 struct pei_data pei_data;
51 struct romstage_params params = {
Lee Leahy0946ec32015-04-20 15:24:54 -070052 .pei_data = &pei_data,
Aaron Durbine6af4be2015-09-24 12:26:31 -050053 .chipset_context = fih,
Lee Leahy0946ec32015-04-20 15:24:54 -070054 };
55
56 post_code(0x30);
57
Lee Leahy0946ec32015-04-20 15:24:54 -070058 timestamp_add_now(TS_START_ROMSTAGE);
59
60 memset(&pei_data, 0, sizeof(pei_data));
61
Lee Leahy0946ec32015-04-20 15:24:54 -070062 /* Display parameters */
Lee Leahy0946ec32015-04-20 15:24:54 -070063 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
64 CONFIG_MMCONF_BASE_ADDRESS);
Aaron Durbin929b6022015-12-09 16:00:18 -060065 printk(BIOS_INFO, "Using FSP 1.1\n");
Lee Leahy0946ec32015-04-20 15:24:54 -070066
67 /* Display FSP banner */
Aaron Durbine6af4be2015-09-24 12:26:31 -050068 print_fsp_info(fih);
Lee Leahy0946ec32015-04-20 15:24:54 -070069
Aaron Durbin929b6022015-12-09 16:00:18 -060070 /* Stash FSP version. */
71 params.fsp_version = fsp_version(fih);
72
Lee Leahy0946ec32015-04-20 15:24:54 -070073 /* Get power state */
74 params.power_state = fill_power_state();
75
Duncan Laurie91da91f2015-09-04 13:47:34 -070076 /*
77 * Read and print board version. Done after SOC romstage
78 * in case PCH needs to be configured to talk to the EC.
79 */
80 if (IS_ENABLED(CONFIG_BOARD_ID_AUTO))
81 printk(BIOS_INFO, "MLB: board version %d\n", board_id());
82
Lee Leahy0946ec32015-04-20 15:24:54 -070083 /* Call into mainboard. */
84 mainboard_romstage_entry(&params);
85 soc_after_ram_init(&params);
86 post_code(0x38);
87
88 top_of_stack = setup_stack_and_mtrrs();
89
Lee Leahy3e5bc1f2015-06-24 11:17:54 -070090 printk(BIOS_DEBUG, "Calling FspTempRamExit API\n");
91 timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_START);
Lee Leahy0946ec32015-04-20 15:24:54 -070092 return top_of_stack;
93}
94
Aaron Durbine6af4be2015-09-24 12:26:31 -050095void *cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
96{
97 return romstage_main(fih);
98}
99
Lee Leahy0946ec32015-04-20 15:24:54 -0700100/* Entry from the mainboard. */
101void romstage_common(struct romstage_params *params)
102{
103 const struct mrc_saved_data *cache;
104 struct romstage_handoff *handoff;
105 struct pei_data *pei_data;
106
107 post_code(0x32);
108
109 timestamp_add_now(TS_BEFORE_INITRAM);
110
111 pei_data = params->pei_data;
112 pei_data->boot_mode = params->power_state->prev_sleep_state;
113
114#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
115 if (params->power_state->prev_sleep_state != SLEEP_STATE_S3)
116 boot_count_increment();
117#endif
118
119 /* Perform remaining SOC initialization */
120 soc_pre_ram_init(params);
121 post_code(0x33);
122
123 /* Check recovery and MRC cache */
124 params->pei_data->saved_data_size = 0;
125 params->pei_data->saved_data = NULL;
126 if (!params->pei_data->disable_saved_data) {
127 if (recovery_mode_enabled()) {
128 /* Recovery mode does not use MRC cache */
129 printk(BIOS_DEBUG,
130 "Recovery mode: not using MRC cache.\n");
Lee Leahya6089692016-01-05 16:34:58 -0800131 } else if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)
132 && (!mrc_cache_get_current_with_version(&cache,
133 params->fsp_version))) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700134 /* MRC cache found */
135 params->pei_data->saved_data_size = cache->size;
136 params->pei_data->saved_data = &cache->data[0];
137 } else if (params->pei_data->boot_mode == SLEEP_STATE_S3) {
138 /* Waking from S3 and no cache. */
139 printk(BIOS_DEBUG,
140 "No MRC cache found in S3 resume path.\n");
141 post_code(POST_RESUME_FAILURE);
142 hard_reset();
143 } else {
144 printk(BIOS_DEBUG, "No MRC cache found.\n");
145 mainboard_check_ec_image(params);
146 }
147 }
148
149 /* Initialize RAM */
150 raminit(params);
151 timestamp_add_now(TS_AFTER_INITRAM);
152
153 /* Save MRC output */
Lee Leahya6089692016-01-05 16:34:58 -0800154 if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)) {
155 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n",
156 pei_data->data_to_save, pei_data->data_to_save_size);
157 if ((params->pei_data->boot_mode != SLEEP_STATE_S3)
158 && (params->pei_data->data_to_save_size != 0)
159 && (params->pei_data->data_to_save != NULL))
160 mrc_cache_stash_data_with_version(
161 params->pei_data->data_to_save,
162 params->pei_data->data_to_save_size,
163 params->fsp_version);
Lee Leahy0946ec32015-04-20 15:24:54 -0700164 }
165
166 /* Save DIMM information */
167 mainboard_save_dimm_info(params);
168
169 /* Create romstage handof information */
170 handoff = romstage_handoff_find_or_add();
171 if (handoff != NULL)
172 handoff->s3_resume = (params->power_state->prev_sleep_state ==
173 SLEEP_STATE_S3);
174 else {
175 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
176 hard_reset();
177 }
178
179 if (IS_ENABLED(CONFIG_LPC_TPM))
180 init_tpm(params->power_state->prev_sleep_state == SLEEP_STATE_S3);
181}
182
Aaron Durbine6af4be2015-09-24 12:26:31 -0500183void after_cache_as_ram_stage(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700184{
Lee Leahy0946ec32015-04-20 15:24:54 -0700185 /* Load the ramstage. */
186 copy_and_run();
187 die("ERROR - Failed to load ramstage!");
188}
189
190/* Initialize the power state */
191__attribute__((weak)) struct chipset_power_state *fill_power_state(void)
192{
193 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
194 return NULL;
195}
196
197__attribute__((weak)) void mainboard_check_ec_image(
198 struct romstage_params *params)
199{
200 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
201#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
202 struct pei_data *pei_data;
203
204 pei_data = params->pei_data;
205 if (params->pei_data->boot_mode == SLEEP_STATE_S0) {
206 /* Ensure EC is running RO firmware. */
207 google_chromeec_check_ec_image(EC_IMAGE_RO);
208 }
209#endif
210}
211
Lee Leahy0946ec32015-04-20 15:24:54 -0700212/* Board initialization before and after RAM is enabled */
213__attribute__((weak)) void mainboard_romstage_entry(
214 struct romstage_params *params)
215{
216 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
217
218 post_code(0x31);
219
220 /* Initliaze memory */
221 romstage_common(params);
222}
223
224/* Save the DIMM information for SMBIOS table 17 */
Lee Leahy0946ec32015-04-20 15:24:54 -0700225__attribute__((weak)) void mainboard_save_dimm_info(
226 struct romstage_params *params)
227{
228 int channel;
229 CHANNEL_INFO *channel_info;
230 int dimm;
231 DIMM_INFO *dimm_info;
232 int dimm_max;
233 void *hob_list_ptr;
234 EFI_HOB_GUID_TYPE *hob_ptr;
235 int index;
236 struct memory_info *mem_info;
237 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
238 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
239
240 /* Locate the memory info HOB, presence validated by raminit */
241 hob_list_ptr = fsp_get_hob_list();
242 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
243 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
244
245 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
246 if (IS_ENABLED(CONFIG_DISPLAY_HOBS)) {
247 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
248 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
249 memory_info_hob->Revision);
250 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
251 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700252 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700253 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700254 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
255 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700256 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
257 memory_info_hob->ErrorCorrectionType);
258 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
259 memory_info_hob->ChannelCount);
260 for (channel = 0; channel < memory_info_hob->ChannelCount;
261 channel++) {
262 channel_info = &memory_info_hob->ChannelInfo[channel];
263 printk(BIOS_DEBUG, " Channel %d\n", channel);
264 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
265 channel_info->ChannelId);
266 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
267 channel_info->DimmCount);
268 for (dimm = 0; dimm < channel_info->DimmCount;
269 dimm++) {
270 dimm_info = &channel_info->DimmInfo[dimm];
271 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
272 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
273 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700274 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700275 dimm_info->SizeInMb);
276 }
277 }
278 }
279
280 /*
281 * Allocate CBMEM area for DIMM information used to populate SMBIOS
282 * table 17
283 */
284 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
285 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: 0x%p\n", mem_info);
286 if (mem_info == NULL)
287 return;
288 memset(mem_info, 0, sizeof(*mem_info));
289
290 /* Describe the first N DIMMs in the system */
291 index = 0;
292 dimm_max = ARRAY_SIZE(mem_info->dimm);
293 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
294 if (index >= dimm_max)
295 break;
296 channel_info = &memory_info_hob->ChannelInfo[channel];
297 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
298 if (index >= dimm_max)
299 break;
300 dimm_info = &channel_info->DimmInfo[dimm];
301
302 /* Populate the DIMM information */
303 if (dimm_info->SizeInMb) {
304 mem_info->dimm[index].dimm_size =
305 dimm_info->SizeInMb;
306 mem_info->dimm[index].ddr_type =
307 memory_info_hob->MemoryType;
308 mem_info->dimm[index].ddr_frequency =
309 memory_info_hob->MemoryFrequencyInMHz;
310 mem_info->dimm[index].channel_num =
311 channel_info->ChannelId;
312 mem_info->dimm[index].dimm_num =
313 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700314 switch (memory_info_hob->DataWidth) {
315 default:
316 case 8:
317 mem_info->dimm[index].bus_width =
318 MEMORY_BUS_WIDTH_8;
319 break;
320
321 case 16:
322 mem_info->dimm[index].bus_width =
323 MEMORY_BUS_WIDTH_16;
324 break;
325
326 case 32:
327 mem_info->dimm[index].bus_width =
328 MEMORY_BUS_WIDTH_32;
329 break;
330
331 case 64:
332 mem_info->dimm[index].bus_width =
333 MEMORY_BUS_WIDTH_64;
334 break;
335
336 case 128:
337 mem_info->dimm[index].bus_width =
338 MEMORY_BUS_WIDTH_128;
339 break;
340 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700341
342 /* Add any mainboard specific information */
343 mainboard_add_dimm_info(params, mem_info,
344 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700345 index++;
346 }
347 }
348 }
349 mem_info->dimm_cnt = index;
350 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
351}
Lee Leahy0946ec32015-04-20 15:24:54 -0700352
Duncan Laurie46a2c772015-07-20 16:48:55 -0700353/* Add any mainboard specific information */
354__attribute__((weak)) void mainboard_add_dimm_info(
355 struct romstage_params *params,
356 struct memory_info *mem_info,
357 int channel, int dimm, int index)
358{
359 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
360}
361
Lee Leahy0946ec32015-04-20 15:24:54 -0700362/* Get the memory configuration data */
363__attribute__((weak)) int mrc_cache_get_current(
364 const struct mrc_saved_data **cache)
365{
366 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
367 return -1;
368}
369
370/* Save the memory configuration data */
371__attribute__((weak)) int mrc_cache_stash_data(void *data, size_t size)
372{
373 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
374 return -1;
375}
376
377/* Transition RAM from off or self-refresh to active */
378__attribute__((weak)) void raminit(struct romstage_params *params)
379{
380 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
381 post_code(0x34);
382 die("ERROR - No RAM initialization specified!\n");
383}
384
385void ramstage_cache_invalid(void)
386{
387 if (IS_ENABLED(CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE))
388 /* Perform cold reset on invalid ramstage cache. */
389 hard_reset();
390}
391
392/* Display the memory configuration */
393__attribute__((weak)) void report_memory_config(void)
394{
395 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
396}
397
Lee Leahy0946ec32015-04-20 15:24:54 -0700398/* Choose top of stack and setup MTRRs */
399__attribute__((weak)) void *setup_stack_and_mtrrs(void)
400{
401 printk(BIOS_ERR, "WEAK: %s/%s called\n", __FILE__, __func__);
402 die("ERROR - Must specify top of stack!\n");
403 return NULL;
404}
405
Lee Leahy0946ec32015-04-20 15:24:54 -0700406/* SOC initialization after RAM is enabled */
407__attribute__((weak)) void soc_after_ram_init(struct romstage_params *params)
408{
409 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
410}
411
Lee Leahy0946ec32015-04-20 15:24:54 -0700412/* SOC initialization before RAM is enabled */
413__attribute__((weak)) void soc_pre_ram_init(struct romstage_params *params)
414{
415 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
416}