blob: 97379b2231ee5cbbca359fc50ca8d17c02ff630e [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>
Aaron Durbin932e09d2016-07-13 23:09:52 -050018#include <arch/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070019#include <arch/io.h>
20#include <arch/cbfs.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070021#include <arch/early_variables.h>
Duncan Laurie91da91f2015-09-04 13:47:34 -070022#include <boardid.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070023#include <console/console.h>
24#include <cbmem.h>
robbie zhang13a2e942016-02-10 11:40:11 -080025#include <cpu/intel/microcode.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070026#include <cpu/x86/mtrr.h>
27#include <ec/google/chromeec/ec.h>
28#include <ec/google/chromeec/ec_commands.h>
29#include <elog.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080030#include <fsp/romstage.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070031#include <reset.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030032#include <program_loading.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070033#include <romstage_handoff.h>
Lee Leahy0be6d932015-06-26 11:15:42 -070034#include <smbios.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070035#include <soc/intel/common/mrc_cache.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070036#include <stage_cache.h>
37#include <timestamp.h>
38#include <tpm.h>
39#include <vendorcode/google/chromeos/chromeos.h>
40
Aaron Durbine6af4be2015-09-24 12:26:31 -050041asmlinkage void *romstage_main(FSP_INFO_HEADER *fih)
Lee Leahy0946ec32015-04-20 15:24:54 -070042{
43 void *top_of_stack;
44 struct pei_data pei_data;
45 struct romstage_params params = {
Lee Leahy0946ec32015-04-20 15:24:54 -070046 .pei_data = &pei_data,
Aaron Durbine6af4be2015-09-24 12:26:31 -050047 .chipset_context = fih,
Lee Leahy0946ec32015-04-20 15:24:54 -070048 };
49
50 post_code(0x30);
51
Lee Leahy0946ec32015-04-20 15:24:54 -070052 timestamp_add_now(TS_START_ROMSTAGE);
53
Elyes HAOUAS77537312016-07-30 15:37:26 +020054 /* Load microcode before RAM init */
robbie zhang13a2e942016-02-10 11:40:11 -080055 if (IS_ENABLED(CONFIG_SUPPORT_CPU_UCODE_IN_CBFS))
56 intel_update_microcode_from_cbfs();
57
Lee Leahy0946ec32015-04-20 15:24:54 -070058 memset(&pei_data, 0, sizeof(pei_data));
59
Lee Leahy0946ec32015-04-20 15:24:54 -070060 /* Display parameters */
Lee Leahy0946ec32015-04-20 15:24:54 -070061 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
62 CONFIG_MMCONF_BASE_ADDRESS);
Aaron Durbin929b6022015-12-09 16:00:18 -060063 printk(BIOS_INFO, "Using FSP 1.1\n");
Lee Leahy0946ec32015-04-20 15:24:54 -070064
65 /* Display FSP banner */
Aaron Durbine6af4be2015-09-24 12:26:31 -050066 print_fsp_info(fih);
Lee Leahy0946ec32015-04-20 15:24:54 -070067
Aaron Durbin929b6022015-12-09 16:00:18 -060068 /* Stash FSP version. */
69 params.fsp_version = fsp_version(fih);
70
Lee Leahy0946ec32015-04-20 15:24:54 -070071 /* Get power state */
72 params.power_state = fill_power_state();
73
Duncan Laurie91da91f2015-09-04 13:47:34 -070074 /*
75 * Read and print board version. Done after SOC romstage
76 * in case PCH needs to be configured to talk to the EC.
77 */
78 if (IS_ENABLED(CONFIG_BOARD_ID_AUTO))
79 printk(BIOS_INFO, "MLB: board version %d\n", board_id());
80
Lee Leahy0946ec32015-04-20 15:24:54 -070081 /* Call into mainboard. */
82 mainboard_romstage_entry(&params);
83 soc_after_ram_init(&params);
84 post_code(0x38);
85
86 top_of_stack = setup_stack_and_mtrrs();
87
Lee Leahy3e5bc1f2015-06-24 11:17:54 -070088 printk(BIOS_DEBUG, "Calling FspTempRamExit API\n");
89 timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_START);
Lee Leahy0946ec32015-04-20 15:24:54 -070090 return top_of_stack;
91}
92
Aaron Durbine6af4be2015-09-24 12:26:31 -050093void *cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
94{
95 return romstage_main(fih);
96}
97
Lee Leahy0946ec32015-04-20 15:24:54 -070098/* Entry from the mainboard. */
99void romstage_common(struct romstage_params *params)
100{
101 const struct mrc_saved_data *cache;
102 struct romstage_handoff *handoff;
103 struct pei_data *pei_data;
104
105 post_code(0x32);
106
107 timestamp_add_now(TS_BEFORE_INITRAM);
108
109 pei_data = params->pei_data;
110 pei_data->boot_mode = params->power_state->prev_sleep_state;
111
112#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
Aaron Durbin932e09d2016-07-13 23:09:52 -0500113 if (params->power_state->prev_sleep_state != ACPI_S3)
Lee Leahy0946ec32015-04-20 15:24:54 -0700114 boot_count_increment();
115#endif
116
117 /* Perform remaining SOC initialization */
118 soc_pre_ram_init(params);
119 post_code(0x33);
120
121 /* Check recovery and MRC cache */
122 params->pei_data->saved_data_size = 0;
123 params->pei_data->saved_data = NULL;
124 if (!params->pei_data->disable_saved_data) {
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700125 if (vboot_recovery_mode_enabled()) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700126 /* Recovery mode does not use MRC cache */
127 printk(BIOS_DEBUG,
128 "Recovery mode: not using MRC cache.\n");
Lee Leahya6089692016-01-05 16:34:58 -0800129 } else if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)
130 && (!mrc_cache_get_current_with_version(&cache,
131 params->fsp_version))) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700132 /* MRC cache found */
133 params->pei_data->saved_data_size = cache->size;
134 params->pei_data->saved_data = &cache->data[0];
Aaron Durbin932e09d2016-07-13 23:09:52 -0500135 } else if (params->pei_data->boot_mode == ACPI_S3) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700136 /* Waking from S3 and no cache. */
137 printk(BIOS_DEBUG,
138 "No MRC cache found in S3 resume path.\n");
139 post_code(POST_RESUME_FAILURE);
140 hard_reset();
141 } else {
142 printk(BIOS_DEBUG, "No MRC cache found.\n");
143 mainboard_check_ec_image(params);
144 }
145 }
146
147 /* Initialize RAM */
148 raminit(params);
149 timestamp_add_now(TS_AFTER_INITRAM);
150
151 /* Save MRC output */
Lee Leahya6089692016-01-05 16:34:58 -0800152 if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)) {
153 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n",
154 pei_data->data_to_save, pei_data->data_to_save_size);
Aaron Durbin932e09d2016-07-13 23:09:52 -0500155 if ((params->pei_data->boot_mode != ACPI_S3)
Lee Leahya6089692016-01-05 16:34:58 -0800156 && (params->pei_data->data_to_save_size != 0)
157 && (params->pei_data->data_to_save != NULL))
158 mrc_cache_stash_data_with_version(
159 params->pei_data->data_to_save,
160 params->pei_data->data_to_save_size,
161 params->fsp_version);
Lee Leahy0946ec32015-04-20 15:24:54 -0700162 }
163
164 /* Save DIMM information */
165 mainboard_save_dimm_info(params);
166
167 /* Create romstage handof information */
168 handoff = romstage_handoff_find_or_add();
169 if (handoff != NULL)
170 handoff->s3_resume = (params->power_state->prev_sleep_state ==
Aaron Durbin932e09d2016-07-13 23:09:52 -0500171 ACPI_S3);
Lee Leahy0946ec32015-04-20 15:24:54 -0700172 else {
173 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
174 hard_reset();
175 }
176
Duncan Lauriefe4983e2016-03-14 09:29:09 -0700177 /*
178 * Initialize the TPM, unless the TPM was already initialized
179 * in verstage and used to verify romstage.
180 */
181 if (IS_ENABLED(CONFIG_LPC_TPM) &&
182 !IS_ENABLED(CONFIG_RESUME_PATH_SAME_AS_BOOT) &&
183 !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK))
184 init_tpm(params->power_state->prev_sleep_state ==
Aaron Durbin932e09d2016-07-13 23:09:52 -0500185 ACPI_S3);
Lee Leahy0946ec32015-04-20 15:24:54 -0700186}
187
Aaron Durbine6af4be2015-09-24 12:26:31 -0500188void after_cache_as_ram_stage(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700189{
Lee Leahy0946ec32015-04-20 15:24:54 -0700190 /* Load the ramstage. */
Kyösti Mälkki65e8f642016-06-27 11:27:56 +0300191 run_ramstage();
Lee Leahy0946ec32015-04-20 15:24:54 -0700192 die("ERROR - Failed to load ramstage!");
193}
194
195/* Initialize the power state */
196__attribute__((weak)) struct chipset_power_state *fill_power_state(void)
197{
Lee Leahy0946ec32015-04-20 15:24:54 -0700198 return NULL;
199}
200
201__attribute__((weak)) void mainboard_check_ec_image(
202 struct romstage_params *params)
203{
Lee Leahy0946ec32015-04-20 15:24:54 -0700204#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
205 struct pei_data *pei_data;
206
207 pei_data = params->pei_data;
Aaron Durbin932e09d2016-07-13 23:09:52 -0500208 if (params->pei_data->boot_mode == ACPI_S0) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700209 /* Ensure EC is running RO firmware. */
210 google_chromeec_check_ec_image(EC_IMAGE_RO);
211 }
212#endif
213}
214
Lee Leahy0946ec32015-04-20 15:24:54 -0700215/* Board initialization before and after RAM is enabled */
216__attribute__((weak)) void mainboard_romstage_entry(
217 struct romstage_params *params)
218{
Lee Leahy0946ec32015-04-20 15:24:54 -0700219 post_code(0x31);
220
221 /* Initliaze memory */
222 romstage_common(params);
223}
224
225/* Save the DIMM information for SMBIOS table 17 */
Lee Leahy0946ec32015-04-20 15:24:54 -0700226__attribute__((weak)) void mainboard_save_dimm_info(
227 struct romstage_params *params)
228{
229 int channel;
230 CHANNEL_INFO *channel_info;
231 int dimm;
232 DIMM_INFO *dimm_info;
233 int dimm_max;
234 void *hob_list_ptr;
235 EFI_HOB_GUID_TYPE *hob_ptr;
236 int index;
237 struct memory_info *mem_info;
238 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
239 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
240
241 /* Locate the memory info HOB, presence validated by raminit */
242 hob_list_ptr = fsp_get_hob_list();
243 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
244 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
245
246 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
247 if (IS_ENABLED(CONFIG_DISPLAY_HOBS)) {
248 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
249 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
250 memory_info_hob->Revision);
251 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
252 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700253 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700254 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700255 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
256 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700257 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
258 memory_info_hob->ErrorCorrectionType);
259 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
260 memory_info_hob->ChannelCount);
261 for (channel = 0; channel < memory_info_hob->ChannelCount;
262 channel++) {
263 channel_info = &memory_info_hob->ChannelInfo[channel];
264 printk(BIOS_DEBUG, " Channel %d\n", channel);
265 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
266 channel_info->ChannelId);
267 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
268 channel_info->DimmCount);
269 for (dimm = 0; dimm < channel_info->DimmCount;
270 dimm++) {
271 dimm_info = &channel_info->DimmInfo[dimm];
272 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
273 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
274 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700275 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700276 dimm_info->SizeInMb);
277 }
278 }
279 }
280
281 /*
282 * Allocate CBMEM area for DIMM information used to populate SMBIOS
283 * table 17
284 */
285 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
286 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: 0x%p\n", mem_info);
287 if (mem_info == NULL)
288 return;
289 memset(mem_info, 0, sizeof(*mem_info));
290
291 /* Describe the first N DIMMs in the system */
292 index = 0;
293 dimm_max = ARRAY_SIZE(mem_info->dimm);
294 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
295 if (index >= dimm_max)
296 break;
297 channel_info = &memory_info_hob->ChannelInfo[channel];
298 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
299 if (index >= dimm_max)
300 break;
301 dimm_info = &channel_info->DimmInfo[dimm];
302
303 /* Populate the DIMM information */
304 if (dimm_info->SizeInMb) {
305 mem_info->dimm[index].dimm_size =
306 dimm_info->SizeInMb;
307 mem_info->dimm[index].ddr_type =
308 memory_info_hob->MemoryType;
309 mem_info->dimm[index].ddr_frequency =
310 memory_info_hob->MemoryFrequencyInMHz;
311 mem_info->dimm[index].channel_num =
312 channel_info->ChannelId;
313 mem_info->dimm[index].dimm_num =
314 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700315 switch (memory_info_hob->DataWidth) {
316 default:
317 case 8:
318 mem_info->dimm[index].bus_width =
319 MEMORY_BUS_WIDTH_8;
320 break;
321
322 case 16:
323 mem_info->dimm[index].bus_width =
324 MEMORY_BUS_WIDTH_16;
325 break;
326
327 case 32:
328 mem_info->dimm[index].bus_width =
329 MEMORY_BUS_WIDTH_32;
330 break;
331
332 case 64:
333 mem_info->dimm[index].bus_width =
334 MEMORY_BUS_WIDTH_64;
335 break;
336
337 case 128:
338 mem_info->dimm[index].bus_width =
339 MEMORY_BUS_WIDTH_128;
340 break;
341 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700342
343 /* Add any mainboard specific information */
344 mainboard_add_dimm_info(params, mem_info,
345 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700346 index++;
347 }
348 }
349 }
350 mem_info->dimm_cnt = index;
351 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
352}
Lee Leahy0946ec32015-04-20 15:24:54 -0700353
Duncan Laurie46a2c772015-07-20 16:48:55 -0700354/* Add any mainboard specific information */
355__attribute__((weak)) void mainboard_add_dimm_info(
356 struct romstage_params *params,
357 struct memory_info *mem_info,
358 int channel, int dimm, int index)
359{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700360}
361
Lee Leahy0946ec32015-04-20 15:24:54 -0700362/* Get the memory configuration data */
Lee Leahyd52f2582016-05-31 18:12:53 -0700363__attribute__((weak)) int mrc_cache_get_current_with_version(
364 const struct mrc_saved_data **cache, uint32_t version)
Lee Leahy0946ec32015-04-20 15:24:54 -0700365{
Lee Leahy0946ec32015-04-20 15:24:54 -0700366 return -1;
367}
368
369/* Save the memory configuration data */
Lee Leahyd52f2582016-05-31 18:12:53 -0700370__attribute__((weak)) int mrc_cache_stash_data_with_version(const void *data,
371 size_t size, uint32_t version)
Lee Leahy0946ec32015-04-20 15:24:54 -0700372{
Lee Leahy0946ec32015-04-20 15:24:54 -0700373 return -1;
374}
375
376/* Transition RAM from off or self-refresh to active */
377__attribute__((weak)) void raminit(struct romstage_params *params)
378{
Lee Leahy0946ec32015-04-20 15:24:54 -0700379 post_code(0x34);
380 die("ERROR - No RAM initialization specified!\n");
381}
382
Lee Leahy0946ec32015-04-20 15:24:54 -0700383/* Display the memory configuration */
384__attribute__((weak)) void report_memory_config(void)
385{
Lee Leahy0946ec32015-04-20 15:24:54 -0700386}
387
Lee Leahy0946ec32015-04-20 15:24:54 -0700388/* Choose top of stack and setup MTRRs */
389__attribute__((weak)) void *setup_stack_and_mtrrs(void)
390{
Lee Leahy0946ec32015-04-20 15:24:54 -0700391 die("ERROR - Must specify top of stack!\n");
392 return NULL;
393}
394
Lee Leahy0946ec32015-04-20 15:24:54 -0700395/* SOC initialization after RAM is enabled */
396__attribute__((weak)) void soc_after_ram_init(struct romstage_params *params)
397{
Lee Leahy0946ec32015-04-20 15:24:54 -0700398}
399
Lee Leahy0946ec32015-04-20 15:24:54 -0700400/* SOC initialization before RAM is enabled */
401__attribute__((weak)) void soc_pre_ram_init(struct romstage_params *params)
402{
Lee Leahy0946ec32015-04-20 15:24:54 -0700403}