blob: d86d3ab484296d36e0b90f52d24b0880977948c1 [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.
Frans Hendriks44d2c852018-12-03 10:40:06 +01006 * Copyright (C) 2018 Eltan B.V.
Lee Leahy0946ec32015-04-20 15:24:54 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Lee Leahy0946ec32015-04-20 15:24:54 -070016 */
17
18#include <stddef.h>
Aaron Durbin932e09d2016-07-13 23:09:52 -050019#include <arch/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070020#include <arch/cbfs.h>
Aaron Durbin31be2c92016-12-03 22:08:20 -060021#include <assert.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070022#include <console/console.h>
23#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +020024#include <cf9_reset.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>
Aaron Durbindecd0622017-12-15 12:26:40 -070031#include <mrc_cache.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 <stage_cache.h>
Aaron Durbinafe8aee2016-11-29 21:37:42 -060036#include <string.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070037#include <timestamp.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070038#include <vendorcode/google/chromeos/chromeos.h>
39
Arthur Heymans73ac1212019-05-23 14:41:19 +020040static void raminit_common(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -070041{
Subrata Banik0beac812017-07-12 15:13:53 +053042 bool s3wake;
Aaron Durbin31be2c92016-12-03 22:08:20 -060043 struct region_device rdev;
Lee Leahy0946ec32015-04-20 15:24:54 -070044
45 post_code(0x32);
46
47 timestamp_add_now(TS_BEFORE_INITRAM);
48
Subrata Banik0beac812017-07-12 15:13:53 +053049 s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070050
Julius Wernercd49cce2019-03-05 16:53:33 -080051 if (CONFIG(ELOG_BOOT_COUNT) && !s3wake)
Lee Leahy0946ec32015-04-20 15:24:54 -070052 boot_count_increment();
Lee Leahy0946ec32015-04-20 15:24:54 -070053
54 /* Perform remaining SOC initialization */
55 soc_pre_ram_init(params);
56 post_code(0x33);
57
58 /* Check recovery and MRC cache */
Nico Huber66318aa2019-05-04 16:59:20 +020059 params->saved_data_size = 0;
60 params->saved_data = NULL;
61 if (!params->disable_saved_data) {
Furquan Shaikh0325dc62016-07-25 13:02:36 -070062 if (vboot_recovery_mode_enabled()) {
Lee Leahy0946ec32015-04-20 15:24:54 -070063 /* Recovery mode does not use MRC cache */
64 printk(BIOS_DEBUG,
65 "Recovery mode: not using MRC cache.\n");
Julius Wernercd49cce2019-03-05 16:53:33 -080066 } else if (CONFIG(CACHE_MRC_SETTINGS)
Aaron Durbin31be2c92016-12-03 22:08:20 -060067 && (!mrc_cache_get_current(MRC_TRAINING_DATA,
68 params->fsp_version,
69 &rdev))) {
Lee Leahy0946ec32015-04-20 15:24:54 -070070 /* MRC cache found */
Nico Huber66318aa2019-05-04 16:59:20 +020071 params->saved_data_size = region_device_sz(&rdev);
72 params->saved_data = rdev_mmap_full(&rdev);
Elyes HAOUAS18958382018-08-07 12:23:16 +020073 /* Assume boot device is memory mapped. */
Julius Wernercd49cce2019-03-05 16:53:33 -080074 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Nico Huber16895c52019-05-04 16:29:17 +020075 } else if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070076 /* Waking from S3 and no cache. */
77 printk(BIOS_DEBUG,
78 "No MRC cache found in S3 resume path.\n");
79 post_code(POST_RESUME_FAILURE);
Patrick Rudolphf677d172018-10-01 19:17:11 +020080 /* FIXME: A "system" reset is likely enough: */
81 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -070082 } else {
83 printk(BIOS_DEBUG, "No MRC cache found.\n");
Lee Leahy0946ec32015-04-20 15:24:54 -070084 }
85 }
86
87 /* Initialize RAM */
88 raminit(params);
89 timestamp_add_now(TS_AFTER_INITRAM);
90
91 /* Save MRC output */
Julius Wernercd49cce2019-03-05 16:53:33 -080092 if (CONFIG(CACHE_MRC_SETTINGS)) {
Nico Huber66318aa2019-05-04 16:59:20 +020093 printk(BIOS_DEBUG, "MRC data at %p %zu bytes\n",
94 params->data_to_save, params->data_to_save_size);
Nico Huber16895c52019-05-04 16:29:17 +020095 if (!s3wake
Nico Huber66318aa2019-05-04 16:59:20 +020096 && (params->data_to_save_size != 0)
97 && (params->data_to_save != NULL))
Lee Leahy216712a2017-03-17 11:23:32 -070098 mrc_cache_stash_data(MRC_TRAINING_DATA,
99 params->fsp_version,
Nico Huber66318aa2019-05-04 16:59:20 +0200100 params->data_to_save,
101 params->data_to_save_size);
Lee Leahy0946ec32015-04-20 15:24:54 -0700102 }
103
104 /* Save DIMM information */
Subrata Banik0beac812017-07-12 15:13:53 +0530105 if (!s3wake)
106 mainboard_save_dimm_info(params);
Lee Leahy0946ec32015-04-20 15:24:54 -0700107
108 /* Create romstage handof information */
Aaron Durbin77e13992016-11-29 17:43:04 -0600109 if (romstage_handoff_init(
110 params->power_state->prev_sleep_state == ACPI_S3) < 0)
Patrick Rudolphf677d172018-10-01 19:17:11 +0200111 /* FIXME: A "system" reset is likely enough: */
112 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700113}
114
Arthur Heymans73ac1212019-05-23 14:41:19 +0200115void cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
116{
117 struct romstage_params params = {
118 .chipset_context = fih,
119 };
120
121 post_code(0x30);
122
123 timestamp_add_now(TS_START_ROMSTAGE);
124
125 /* Load microcode before RAM init */
126 if (CONFIG(SUPPORT_CPU_UCODE_IN_CBFS))
127 intel_update_microcode_from_cbfs();
128
129 /* Display parameters */
130 if (!CONFIG(NO_MMCONF_SUPPORT))
131 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
132 CONFIG_MMCONF_BASE_ADDRESS);
133 printk(BIOS_INFO, "Using FSP 1.1\n");
134
135 /* Display FSP banner */
136 print_fsp_info(fih);
137
138 /* Stash FSP version. */
139 params.fsp_version = fsp_version(fih);
140
141 /* Get power state */
142 params.power_state = fill_power_state();
143
144 /* Board initialization before and after RAM is enabled */
145 mainboard_pre_raminit(&params);
146
147 post_code(0x31);
148
149 /* Initialize memory */
150 raminit_common(&params);
151
152 soc_after_ram_init(&params);
153 post_code(0x38);
154}
155
Lee Leahy0946ec32015-04-20 15:24:54 -0700156/* Initialize the power state */
Aaron Durbin64031672018-04-21 14:45:32 -0600157__weak struct chipset_power_state *fill_power_state(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700158{
Lee Leahy0946ec32015-04-20 15:24:54 -0700159 return NULL;
160}
161
Lee Leahy0946ec32015-04-20 15:24:54 -0700162/* Board initialization before and after RAM is enabled */
Arthur Heymans73ac1212019-05-23 14:41:19 +0200163__weak void mainboard_pre_raminit(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700164{
Lee Leahy0946ec32015-04-20 15:24:54 -0700165}
166
167/* Save the DIMM information for SMBIOS table 17 */
Aaron Durbin64031672018-04-21 14:45:32 -0600168__weak void mainboard_save_dimm_info(
Lee Leahy0946ec32015-04-20 15:24:54 -0700169 struct romstage_params *params)
170{
171 int channel;
172 CHANNEL_INFO *channel_info;
173 int dimm;
174 DIMM_INFO *dimm_info;
175 int dimm_max;
176 void *hob_list_ptr;
177 EFI_HOB_GUID_TYPE *hob_ptr;
178 int index;
179 struct memory_info *mem_info;
180 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
181 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
182
183 /* Locate the memory info HOB, presence validated by raminit */
184 hob_list_ptr = fsp_get_hob_list();
185 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
186 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
187
188 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
Julius Wernercd49cce2019-03-05 16:53:33 -0800189 if (CONFIG(DISPLAY_HOBS)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700190 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
191 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
192 memory_info_hob->Revision);
193 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
194 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700195 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700196 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700197 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
198 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700199 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
200 memory_info_hob->ErrorCorrectionType);
201 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
202 memory_info_hob->ChannelCount);
203 for (channel = 0; channel < memory_info_hob->ChannelCount;
204 channel++) {
205 channel_info = &memory_info_hob->ChannelInfo[channel];
206 printk(BIOS_DEBUG, " Channel %d\n", channel);
207 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
208 channel_info->ChannelId);
209 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
210 channel_info->DimmCount);
211 for (dimm = 0; dimm < channel_info->DimmCount;
212 dimm++) {
213 dimm_info = &channel_info->DimmInfo[dimm];
214 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
215 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
216 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700217 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700218 dimm_info->SizeInMb);
219 }
220 }
221 }
222
223 /*
224 * Allocate CBMEM area for DIMM information used to populate SMBIOS
225 * table 17
226 */
227 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
228 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: 0x%p\n", mem_info);
229 if (mem_info == NULL)
230 return;
231 memset(mem_info, 0, sizeof(*mem_info));
232
233 /* Describe the first N DIMMs in the system */
234 index = 0;
235 dimm_max = ARRAY_SIZE(mem_info->dimm);
236 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
237 if (index >= dimm_max)
238 break;
239 channel_info = &memory_info_hob->ChannelInfo[channel];
240 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
241 if (index >= dimm_max)
242 break;
243 dimm_info = &channel_info->DimmInfo[dimm];
244
245 /* Populate the DIMM information */
246 if (dimm_info->SizeInMb) {
247 mem_info->dimm[index].dimm_size =
248 dimm_info->SizeInMb;
249 mem_info->dimm[index].ddr_type =
250 memory_info_hob->MemoryType;
251 mem_info->dimm[index].ddr_frequency =
252 memory_info_hob->MemoryFrequencyInMHz;
253 mem_info->dimm[index].channel_num =
254 channel_info->ChannelId;
255 mem_info->dimm[index].dimm_num =
256 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700257 switch (memory_info_hob->DataWidth) {
258 default:
259 case 8:
260 mem_info->dimm[index].bus_width =
261 MEMORY_BUS_WIDTH_8;
262 break;
263
264 case 16:
265 mem_info->dimm[index].bus_width =
266 MEMORY_BUS_WIDTH_16;
267 break;
268
269 case 32:
270 mem_info->dimm[index].bus_width =
271 MEMORY_BUS_WIDTH_32;
272 break;
273
274 case 64:
275 mem_info->dimm[index].bus_width =
276 MEMORY_BUS_WIDTH_64;
277 break;
278
279 case 128:
280 mem_info->dimm[index].bus_width =
281 MEMORY_BUS_WIDTH_128;
282 break;
283 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700284
285 /* Add any mainboard specific information */
286 mainboard_add_dimm_info(params, mem_info,
287 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700288 index++;
289 }
290 }
291 }
292 mem_info->dimm_cnt = index;
293 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
294}
Lee Leahy0946ec32015-04-20 15:24:54 -0700295
Duncan Laurie46a2c772015-07-20 16:48:55 -0700296/* Add any mainboard specific information */
Aaron Durbin64031672018-04-21 14:45:32 -0600297__weak void mainboard_add_dimm_info(
Duncan Laurie46a2c772015-07-20 16:48:55 -0700298 struct romstage_params *params,
299 struct memory_info *mem_info,
300 int channel, int dimm, int index)
301{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700302}
303
Lee Leahy0946ec32015-04-20 15:24:54 -0700304/* Get the memory configuration data */
Aaron Durbin64031672018-04-21 14:45:32 -0600305__weak int mrc_cache_get_current(int type, uint32_t version,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600306 struct region_device *rdev)
Lee Leahy0946ec32015-04-20 15:24:54 -0700307{
Lee Leahy0946ec32015-04-20 15:24:54 -0700308 return -1;
309}
310
311/* Save the memory configuration data */
Aaron Durbin64031672018-04-21 14:45:32 -0600312__weak int mrc_cache_stash_data(int type, uint32_t version,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600313 const void *data, size_t size)
Lee Leahy0946ec32015-04-20 15:24:54 -0700314{
Lee Leahy0946ec32015-04-20 15:24:54 -0700315 return -1;
316}
317
Lee Leahy0946ec32015-04-20 15:24:54 -0700318/* Display the memory configuration */
Aaron Durbin64031672018-04-21 14:45:32 -0600319__weak void report_memory_config(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700320{
Lee Leahy0946ec32015-04-20 15:24:54 -0700321}
322
Lee Leahy0946ec32015-04-20 15:24:54 -0700323/* SOC initialization after RAM is enabled */
Aaron Durbin64031672018-04-21 14:45:32 -0600324__weak void soc_after_ram_init(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700325{
Lee Leahy0946ec32015-04-20 15:24:54 -0700326}
327
Lee Leahy0946ec32015-04-20 15:24:54 -0700328/* SOC initialization before RAM is enabled */
Aaron Durbin64031672018-04-21 14:45:32 -0600329__weak void soc_pre_ram_init(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700330{
Lee Leahy0946ec32015-04-20 15:24:54 -0700331}