blob: f99c87a3c7369027605fca9c997e1de11db11eec [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>
Lee Leahy0946ec32015-04-20 15:24:54 -070018#include <arch/io.h>
19#include <arch/cbfs.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070020#include <arch/early_variables.h>
Duncan Laurie91da91f2015-09-04 13:47:34 -070021#include <boardid.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070022#include <console/console.h>
23#include <cbmem.h>
robbie zhang13a2e942016-02-10 11:40:11 -080024#include <cpu/intel/microcode.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070025#include <cpu/x86/mtrr.h>
26#include <ec/google/chromeec/ec.h>
27#include <ec/google/chromeec/ec_commands.h>
28#include <elog.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080029#include <fsp/romstage.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070030#include <reset.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030031#include <program_loading.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070032#include <romstage_handoff.h>
Lee Leahy0be6d932015-06-26 11:15:42 -070033#include <smbios.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070034#include <soc/intel/common/mrc_cache.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070035#include <stage_cache.h>
36#include <timestamp.h>
37#include <tpm.h>
38#include <vendorcode/google/chromeos/chromeos.h>
39
Aaron Durbine6af4be2015-09-24 12:26:31 -050040asmlinkage void *romstage_main(FSP_INFO_HEADER *fih)
Lee Leahy0946ec32015-04-20 15:24:54 -070041{
42 void *top_of_stack;
43 struct pei_data pei_data;
44 struct romstage_params params = {
Lee Leahy0946ec32015-04-20 15:24:54 -070045 .pei_data = &pei_data,
Aaron Durbine6af4be2015-09-24 12:26:31 -050046 .chipset_context = fih,
Lee Leahy0946ec32015-04-20 15:24:54 -070047 };
48
49 post_code(0x30);
50
Lee Leahy0946ec32015-04-20 15:24:54 -070051 timestamp_add_now(TS_START_ROMSTAGE);
52
robbie zhang13a2e942016-02-10 11:40:11 -080053 /* Load microcode before ram init */
54 if (IS_ENABLED(CONFIG_SUPPORT_CPU_UCODE_IN_CBFS))
55 intel_update_microcode_from_cbfs();
56
Lee Leahy0946ec32015-04-20 15:24:54 -070057 memset(&pei_data, 0, sizeof(pei_data));
58
Lee Leahy0946ec32015-04-20 15:24:54 -070059 /* Display parameters */
Lee Leahy0946ec32015-04-20 15:24:54 -070060 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
61 CONFIG_MMCONF_BASE_ADDRESS);
Aaron Durbin929b6022015-12-09 16:00:18 -060062 printk(BIOS_INFO, "Using FSP 1.1\n");
Lee Leahy0946ec32015-04-20 15:24:54 -070063
64 /* Display FSP banner */
Aaron Durbine6af4be2015-09-24 12:26:31 -050065 print_fsp_info(fih);
Lee Leahy0946ec32015-04-20 15:24:54 -070066
Aaron Durbin929b6022015-12-09 16:00:18 -060067 /* Stash FSP version. */
68 params.fsp_version = fsp_version(fih);
69
Lee Leahy0946ec32015-04-20 15:24:54 -070070 /* Get power state */
71 params.power_state = fill_power_state();
72
Duncan Laurie91da91f2015-09-04 13:47:34 -070073 /*
74 * Read and print board version. Done after SOC romstage
75 * in case PCH needs to be configured to talk to the EC.
76 */
77 if (IS_ENABLED(CONFIG_BOARD_ID_AUTO))
78 printk(BIOS_INFO, "MLB: board version %d\n", board_id());
79
Lee Leahy0946ec32015-04-20 15:24:54 -070080 /* Call into mainboard. */
81 mainboard_romstage_entry(&params);
82 soc_after_ram_init(&params);
83 post_code(0x38);
84
85 top_of_stack = setup_stack_and_mtrrs();
86
Lee Leahy3e5bc1f2015-06-24 11:17:54 -070087 printk(BIOS_DEBUG, "Calling FspTempRamExit API\n");
88 timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_START);
Lee Leahy0946ec32015-04-20 15:24:54 -070089 return top_of_stack;
90}
91
Aaron Durbine6af4be2015-09-24 12:26:31 -050092void *cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
93{
94 return romstage_main(fih);
95}
96
Lee Leahy0946ec32015-04-20 15:24:54 -070097/* Entry from the mainboard. */
98void romstage_common(struct romstage_params *params)
99{
100 const struct mrc_saved_data *cache;
101 struct romstage_handoff *handoff;
102 struct pei_data *pei_data;
103
104 post_code(0x32);
105
106 timestamp_add_now(TS_BEFORE_INITRAM);
107
108 pei_data = params->pei_data;
109 pei_data->boot_mode = params->power_state->prev_sleep_state;
110
111#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
112 if (params->power_state->prev_sleep_state != SLEEP_STATE_S3)
113 boot_count_increment();
114#endif
115
116 /* Perform remaining SOC initialization */
117 soc_pre_ram_init(params);
118 post_code(0x33);
119
120 /* Check recovery and MRC cache */
121 params->pei_data->saved_data_size = 0;
122 params->pei_data->saved_data = NULL;
123 if (!params->pei_data->disable_saved_data) {
124 if (recovery_mode_enabled()) {
125 /* Recovery mode does not use MRC cache */
126 printk(BIOS_DEBUG,
127 "Recovery mode: not using MRC cache.\n");
Lee Leahya6089692016-01-05 16:34:58 -0800128 } else if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)
129 && (!mrc_cache_get_current_with_version(&cache,
130 params->fsp_version))) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700131 /* MRC cache found */
132 params->pei_data->saved_data_size = cache->size;
133 params->pei_data->saved_data = &cache->data[0];
134 } else if (params->pei_data->boot_mode == SLEEP_STATE_S3) {
135 /* Waking from S3 and no cache. */
136 printk(BIOS_DEBUG,
137 "No MRC cache found in S3 resume path.\n");
138 post_code(POST_RESUME_FAILURE);
139 hard_reset();
140 } else {
141 printk(BIOS_DEBUG, "No MRC cache found.\n");
142 mainboard_check_ec_image(params);
143 }
144 }
145
146 /* Initialize RAM */
147 raminit(params);
148 timestamp_add_now(TS_AFTER_INITRAM);
149
150 /* Save MRC output */
Lee Leahya6089692016-01-05 16:34:58 -0800151 if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)) {
152 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n",
153 pei_data->data_to_save, pei_data->data_to_save_size);
154 if ((params->pei_data->boot_mode != SLEEP_STATE_S3)
155 && (params->pei_data->data_to_save_size != 0)
156 && (params->pei_data->data_to_save != NULL))
157 mrc_cache_stash_data_with_version(
158 params->pei_data->data_to_save,
159 params->pei_data->data_to_save_size,
160 params->fsp_version);
Lee Leahy0946ec32015-04-20 15:24:54 -0700161 }
162
163 /* Save DIMM information */
164 mainboard_save_dimm_info(params);
165
166 /* Create romstage handof information */
167 handoff = romstage_handoff_find_or_add();
168 if (handoff != NULL)
169 handoff->s3_resume = (params->power_state->prev_sleep_state ==
170 SLEEP_STATE_S3);
171 else {
172 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
173 hard_reset();
174 }
175
Duncan Lauriefe4983e2016-03-14 09:29:09 -0700176 /*
177 * Initialize the TPM, unless the TPM was already initialized
178 * in verstage and used to verify romstage.
179 */
180 if (IS_ENABLED(CONFIG_LPC_TPM) &&
181 !IS_ENABLED(CONFIG_RESUME_PATH_SAME_AS_BOOT) &&
182 !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK))
183 init_tpm(params->power_state->prev_sleep_state ==
184 SLEEP_STATE_S3);
Lee Leahy0946ec32015-04-20 15:24:54 -0700185}
186
Aaron Durbine6af4be2015-09-24 12:26:31 -0500187void after_cache_as_ram_stage(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700188{
Lee Leahy0946ec32015-04-20 15:24:54 -0700189 /* Load the ramstage. */
Kyösti Mälkki65e8f642016-06-27 11:27:56 +0300190 run_ramstage();
Lee Leahy0946ec32015-04-20 15:24:54 -0700191 die("ERROR - Failed to load ramstage!");
192}
193
194/* Initialize the power state */
195__attribute__((weak)) struct chipset_power_state *fill_power_state(void)
196{
Lee Leahy0946ec32015-04-20 15:24:54 -0700197 return NULL;
198}
199
200__attribute__((weak)) void mainboard_check_ec_image(
201 struct romstage_params *params)
202{
Lee Leahy0946ec32015-04-20 15:24:54 -0700203#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
204 struct pei_data *pei_data;
205
206 pei_data = params->pei_data;
207 if (params->pei_data->boot_mode == SLEEP_STATE_S0) {
208 /* Ensure EC is running RO firmware. */
209 google_chromeec_check_ec_image(EC_IMAGE_RO);
210 }
211#endif
212}
213
Lee Leahy0946ec32015-04-20 15:24:54 -0700214/* Board initialization before and after RAM is enabled */
215__attribute__((weak)) void mainboard_romstage_entry(
216 struct romstage_params *params)
217{
Lee Leahy0946ec32015-04-20 15:24:54 -0700218 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{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700359}
360
Lee Leahy0946ec32015-04-20 15:24:54 -0700361/* Get the memory configuration data */
Lee Leahyd52f2582016-05-31 18:12:53 -0700362__attribute__((weak)) int mrc_cache_get_current_with_version(
363 const struct mrc_saved_data **cache, uint32_t version)
Lee Leahy0946ec32015-04-20 15:24:54 -0700364{
Lee Leahy0946ec32015-04-20 15:24:54 -0700365 return -1;
366}
367
368/* Save the memory configuration data */
Lee Leahyd52f2582016-05-31 18:12:53 -0700369__attribute__((weak)) int mrc_cache_stash_data_with_version(const void *data,
370 size_t size, uint32_t version)
Lee Leahy0946ec32015-04-20 15:24:54 -0700371{
Lee Leahy0946ec32015-04-20 15:24:54 -0700372 return -1;
373}
374
375/* Transition RAM from off or self-refresh to active */
376__attribute__((weak)) void raminit(struct romstage_params *params)
377{
Lee Leahy0946ec32015-04-20 15:24:54 -0700378 post_code(0x34);
379 die("ERROR - No RAM initialization specified!\n");
380}
381
382void ramstage_cache_invalid(void)
383{
384 if (IS_ENABLED(CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE))
385 /* Perform cold reset on invalid ramstage cache. */
386 hard_reset();
387}
388
389/* Display the memory configuration */
390__attribute__((weak)) void report_memory_config(void)
391{
Lee Leahy0946ec32015-04-20 15:24:54 -0700392}
393
Lee Leahy0946ec32015-04-20 15:24:54 -0700394/* Choose top of stack and setup MTRRs */
395__attribute__((weak)) void *setup_stack_and_mtrrs(void)
396{
Lee Leahy0946ec32015-04-20 15:24:54 -0700397 die("ERROR - Must specify top of stack!\n");
398 return NULL;
399}
400
Lee Leahy0946ec32015-04-20 15:24:54 -0700401/* SOC initialization after RAM is enabled */
402__attribute__((weak)) void soc_after_ram_init(struct romstage_params *params)
403{
Lee Leahy0946ec32015-04-20 15:24:54 -0700404}
405
Lee Leahy0946ec32015-04-20 15:24:54 -0700406/* SOC initialization before RAM is enabled */
407__attribute__((weak)) void soc_pre_ram_init(struct romstage_params *params)
408{
Lee Leahy0946ec32015-04-20 15:24:54 -0700409}