blob: e6dec251be96a4fc5d42e321ac77d682b0aa72b4 [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>
Aaron Durbin31be2c92016-12-03 22:08:20 -060022#include <assert.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>
Aaron Durbinafe8aee2016-11-29 21:37:42 -060037#include <string.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070038#include <timestamp.h>
39#include <tpm.h>
40#include <vendorcode/google/chromeos/chromeos.h>
41
Aaron Durbine6af4be2015-09-24 12:26:31 -050042asmlinkage void *romstage_main(FSP_INFO_HEADER *fih)
Lee Leahy0946ec32015-04-20 15:24:54 -070043{
44 void *top_of_stack;
45 struct pei_data pei_data;
46 struct romstage_params params = {
Lee Leahy0946ec32015-04-20 15:24:54 -070047 .pei_data = &pei_data,
Aaron Durbine6af4be2015-09-24 12:26:31 -050048 .chipset_context = fih,
Lee Leahy0946ec32015-04-20 15:24:54 -070049 };
50
51 post_code(0x30);
52
Lee Leahy0946ec32015-04-20 15:24:54 -070053 timestamp_add_now(TS_START_ROMSTAGE);
54
Elyes HAOUAS77537312016-07-30 15:37:26 +020055 /* Load microcode before RAM init */
robbie zhang13a2e942016-02-10 11:40:11 -080056 if (IS_ENABLED(CONFIG_SUPPORT_CPU_UCODE_IN_CBFS))
57 intel_update_microcode_from_cbfs();
58
Lee Leahy0946ec32015-04-20 15:24:54 -070059 memset(&pei_data, 0, sizeof(pei_data));
60
Lee Leahy0946ec32015-04-20 15:24:54 -070061 /* Display parameters */
Lee Leahyc253a922017-03-13 17:36:39 -070062 if (!IS_ENABLED(CONFIG_NO_MMCONF_SUPPORT))
63 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
Lee Leahy0946ec32015-04-20 15:24:54 -070076 /* Call into mainboard. */
77 mainboard_romstage_entry(&params);
78 soc_after_ram_init(&params);
79 post_code(0x38);
80
81 top_of_stack = setup_stack_and_mtrrs();
82
Lee Leahy3e5bc1f2015-06-24 11:17:54 -070083 printk(BIOS_DEBUG, "Calling FspTempRamExit API\n");
84 timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_START);
Lee Leahy0946ec32015-04-20 15:24:54 -070085 return top_of_stack;
86}
87
Aaron Durbine6af4be2015-09-24 12:26:31 -050088void *cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
89{
90 return romstage_main(fih);
91}
92
Lee Leahy0946ec32015-04-20 15:24:54 -070093/* Entry from the mainboard. */
94void romstage_common(struct romstage_params *params)
95{
Subrata Banik0beac812017-07-12 15:13:53 +053096 bool s3wake;
Aaron Durbin31be2c92016-12-03 22:08:20 -060097 struct region_device rdev;
Lee Leahy0946ec32015-04-20 15:24:54 -070098 struct pei_data *pei_data;
99
100 post_code(0x32);
101
102 timestamp_add_now(TS_BEFORE_INITRAM);
103
104 pei_data = params->pei_data;
105 pei_data->boot_mode = params->power_state->prev_sleep_state;
Subrata Banik0beac812017-07-12 15:13:53 +0530106 s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -0700107
Subrata Banik0beac812017-07-12 15:13:53 +0530108 if (IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) && !s3wake)
Lee Leahy0946ec32015-04-20 15:24:54 -0700109 boot_count_increment();
Lee Leahy0946ec32015-04-20 15:24:54 -0700110
111 /* Perform remaining SOC initialization */
112 soc_pre_ram_init(params);
113 post_code(0x33);
114
115 /* Check recovery and MRC cache */
116 params->pei_data->saved_data_size = 0;
117 params->pei_data->saved_data = NULL;
118 if (!params->pei_data->disable_saved_data) {
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700119 if (vboot_recovery_mode_enabled()) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700120 /* Recovery mode does not use MRC cache */
121 printk(BIOS_DEBUG,
122 "Recovery mode: not using MRC cache.\n");
Lee Leahya6089692016-01-05 16:34:58 -0800123 } else if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600124 && (!mrc_cache_get_current(MRC_TRAINING_DATA,
125 params->fsp_version,
126 &rdev))) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700127 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600128 params->pei_data->saved_data_size =
129 region_device_sz(&rdev);
130 params->pei_data->saved_data = rdev_mmap_full(&rdev);
131 /* Assum boot device is memory mapped. */
132 assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED));
Aaron Durbin932e09d2016-07-13 23:09:52 -0500133 } else if (params->pei_data->boot_mode == ACPI_S3) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700134 /* Waking from S3 and no cache. */
135 printk(BIOS_DEBUG,
136 "No MRC cache found in S3 resume path.\n");
137 post_code(POST_RESUME_FAILURE);
138 hard_reset();
139 } else {
140 printk(BIOS_DEBUG, "No MRC cache found.\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700141 }
142 }
143
144 /* Initialize RAM */
145 raminit(params);
146 timestamp_add_now(TS_AFTER_INITRAM);
147
148 /* Save MRC output */
Lee Leahya6089692016-01-05 16:34:58 -0800149 if (IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)) {
150 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n",
151 pei_data->data_to_save, pei_data->data_to_save_size);
Aaron Durbin932e09d2016-07-13 23:09:52 -0500152 if ((params->pei_data->boot_mode != ACPI_S3)
Lee Leahya6089692016-01-05 16:34:58 -0800153 && (params->pei_data->data_to_save_size != 0)
154 && (params->pei_data->data_to_save != NULL))
Lee Leahy216712a2017-03-17 11:23:32 -0700155 mrc_cache_stash_data(MRC_TRAINING_DATA,
156 params->fsp_version,
157 params->pei_data->data_to_save,
158 params->pei_data->data_to_save_size);
Lee Leahy0946ec32015-04-20 15:24:54 -0700159 }
160
161 /* Save DIMM information */
Subrata Banik0beac812017-07-12 15:13:53 +0530162 if (!s3wake)
163 mainboard_save_dimm_info(params);
Lee Leahy0946ec32015-04-20 15:24:54 -0700164
165 /* Create romstage handof information */
Aaron Durbin77e13992016-11-29 17:43:04 -0600166 if (romstage_handoff_init(
167 params->power_state->prev_sleep_state == ACPI_S3) < 0)
Lee Leahy0946ec32015-04-20 15:24:54 -0700168 hard_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700169
Duncan Lauriefe4983e2016-03-14 09:29:09 -0700170 /*
171 * Initialize the TPM, unless the TPM was already initialized
172 * in verstage and used to verify romstage.
173 */
174 if (IS_ENABLED(CONFIG_LPC_TPM) &&
175 !IS_ENABLED(CONFIG_RESUME_PATH_SAME_AS_BOOT) &&
176 !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK))
177 init_tpm(params->power_state->prev_sleep_state ==
Aaron Durbin932e09d2016-07-13 23:09:52 -0500178 ACPI_S3);
Lee Leahy0946ec32015-04-20 15:24:54 -0700179}
180
Aaron Durbine6af4be2015-09-24 12:26:31 -0500181void after_cache_as_ram_stage(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700182{
Lee Leahy0946ec32015-04-20 15:24:54 -0700183 /* Load the ramstage. */
Kyösti Mälkki65e8f642016-06-27 11:27:56 +0300184 run_ramstage();
Lee Leahy0946ec32015-04-20 15:24:54 -0700185 die("ERROR - Failed to load ramstage!");
186}
187
188/* Initialize the power state */
189__attribute__((weak)) struct chipset_power_state *fill_power_state(void)
190{
Lee Leahy0946ec32015-04-20 15:24:54 -0700191 return NULL;
192}
193
Lee Leahy0946ec32015-04-20 15:24:54 -0700194/* Board initialization before and after RAM is enabled */
195__attribute__((weak)) void mainboard_romstage_entry(
196 struct romstage_params *params)
197{
Lee Leahy0946ec32015-04-20 15:24:54 -0700198 post_code(0x31);
199
200 /* Initliaze memory */
201 romstage_common(params);
202}
203
204/* Save the DIMM information for SMBIOS table 17 */
Lee Leahy0946ec32015-04-20 15:24:54 -0700205__attribute__((weak)) void mainboard_save_dimm_info(
206 struct romstage_params *params)
207{
208 int channel;
209 CHANNEL_INFO *channel_info;
210 int dimm;
211 DIMM_INFO *dimm_info;
212 int dimm_max;
213 void *hob_list_ptr;
214 EFI_HOB_GUID_TYPE *hob_ptr;
215 int index;
216 struct memory_info *mem_info;
217 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
218 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
219
220 /* Locate the memory info HOB, presence validated by raminit */
221 hob_list_ptr = fsp_get_hob_list();
222 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
223 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
224
225 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
226 if (IS_ENABLED(CONFIG_DISPLAY_HOBS)) {
227 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
228 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
229 memory_info_hob->Revision);
230 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
231 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700232 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700233 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700234 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
235 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700236 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
237 memory_info_hob->ErrorCorrectionType);
238 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
239 memory_info_hob->ChannelCount);
240 for (channel = 0; channel < memory_info_hob->ChannelCount;
241 channel++) {
242 channel_info = &memory_info_hob->ChannelInfo[channel];
243 printk(BIOS_DEBUG, " Channel %d\n", channel);
244 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
245 channel_info->ChannelId);
246 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
247 channel_info->DimmCount);
248 for (dimm = 0; dimm < channel_info->DimmCount;
249 dimm++) {
250 dimm_info = &channel_info->DimmInfo[dimm];
251 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
252 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
253 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700254 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700255 dimm_info->SizeInMb);
256 }
257 }
258 }
259
260 /*
261 * Allocate CBMEM area for DIMM information used to populate SMBIOS
262 * table 17
263 */
264 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
265 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: 0x%p\n", mem_info);
266 if (mem_info == NULL)
267 return;
268 memset(mem_info, 0, sizeof(*mem_info));
269
270 /* Describe the first N DIMMs in the system */
271 index = 0;
272 dimm_max = ARRAY_SIZE(mem_info->dimm);
273 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
274 if (index >= dimm_max)
275 break;
276 channel_info = &memory_info_hob->ChannelInfo[channel];
277 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
278 if (index >= dimm_max)
279 break;
280 dimm_info = &channel_info->DimmInfo[dimm];
281
282 /* Populate the DIMM information */
283 if (dimm_info->SizeInMb) {
284 mem_info->dimm[index].dimm_size =
285 dimm_info->SizeInMb;
286 mem_info->dimm[index].ddr_type =
287 memory_info_hob->MemoryType;
288 mem_info->dimm[index].ddr_frequency =
289 memory_info_hob->MemoryFrequencyInMHz;
290 mem_info->dimm[index].channel_num =
291 channel_info->ChannelId;
292 mem_info->dimm[index].dimm_num =
293 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700294 switch (memory_info_hob->DataWidth) {
295 default:
296 case 8:
297 mem_info->dimm[index].bus_width =
298 MEMORY_BUS_WIDTH_8;
299 break;
300
301 case 16:
302 mem_info->dimm[index].bus_width =
303 MEMORY_BUS_WIDTH_16;
304 break;
305
306 case 32:
307 mem_info->dimm[index].bus_width =
308 MEMORY_BUS_WIDTH_32;
309 break;
310
311 case 64:
312 mem_info->dimm[index].bus_width =
313 MEMORY_BUS_WIDTH_64;
314 break;
315
316 case 128:
317 mem_info->dimm[index].bus_width =
318 MEMORY_BUS_WIDTH_128;
319 break;
320 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700321
322 /* Add any mainboard specific information */
323 mainboard_add_dimm_info(params, mem_info,
324 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700325 index++;
326 }
327 }
328 }
329 mem_info->dimm_cnt = index;
330 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
331}
Lee Leahy0946ec32015-04-20 15:24:54 -0700332
Duncan Laurie46a2c772015-07-20 16:48:55 -0700333/* Add any mainboard specific information */
334__attribute__((weak)) void mainboard_add_dimm_info(
335 struct romstage_params *params,
336 struct memory_info *mem_info,
337 int channel, int dimm, int index)
338{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700339}
340
Lee Leahy0946ec32015-04-20 15:24:54 -0700341/* Get the memory configuration data */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600342__attribute__((weak)) int mrc_cache_get_current(int type, uint32_t version,
343 struct region_device *rdev)
Lee Leahy0946ec32015-04-20 15:24:54 -0700344{
Lee Leahy0946ec32015-04-20 15:24:54 -0700345 return -1;
346}
347
348/* Save the memory configuration data */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600349__attribute__((weak)) int mrc_cache_stash_data(int type, uint32_t version,
350 const void *data, size_t size)
Lee Leahy0946ec32015-04-20 15:24:54 -0700351{
Lee Leahy0946ec32015-04-20 15:24:54 -0700352 return -1;
353}
354
355/* Transition RAM from off or self-refresh to active */
356__attribute__((weak)) void raminit(struct romstage_params *params)
357{
Lee Leahy0946ec32015-04-20 15:24:54 -0700358 post_code(0x34);
359 die("ERROR - No RAM initialization specified!\n");
360}
361
Lee Leahy0946ec32015-04-20 15:24:54 -0700362/* Display the memory configuration */
363__attribute__((weak)) void report_memory_config(void)
364{
Lee Leahy0946ec32015-04-20 15:24:54 -0700365}
366
Lee Leahy0946ec32015-04-20 15:24:54 -0700367/* Choose top of stack and setup MTRRs */
368__attribute__((weak)) void *setup_stack_and_mtrrs(void)
369{
Lee Leahy0946ec32015-04-20 15:24:54 -0700370 die("ERROR - Must specify top of stack!\n");
371 return NULL;
372}
373
Lee Leahy0946ec32015-04-20 15:24:54 -0700374/* SOC initialization after RAM is enabled */
375__attribute__((weak)) void soc_after_ram_init(struct romstage_params *params)
376{
Lee Leahy0946ec32015-04-20 15:24:54 -0700377}
378
Lee Leahy0946ec32015-04-20 15:24:54 -0700379/* SOC initialization before RAM is enabled */
380__attribute__((weak)) void soc_pre_ram_init(struct romstage_params *params)
381{
Lee Leahy0946ec32015-04-20 15:24:54 -0700382}