blob: 46df1c869715d2849d1836f9d59623af640aeb40 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy0946ec32015-04-20 15:24:54 -07002
3#include <stddef.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Aaron Durbin31be2c92016-12-03 22:08:20 -06005#include <assert.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07006#include <console/console.h>
7#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02008#include <cf9_reset.h>
robbie zhang13a2e942016-02-10 11:40:11 -08009#include <cpu/intel/microcode.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070010#include <ec/google/chromeec/ec.h>
11#include <ec/google/chromeec/ec_commands.h>
12#include <elog.h>
Lee Leahyb092c9e2016-01-01 18:09:50 -080013#include <fsp/romstage.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070014#include <mrc_cache.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030015#include <program_loading.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070016#include <romstage_handoff.h>
Lee Leahy0be6d932015-06-26 11:15:42 -070017#include <smbios.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070018#include <stage_cache.h>
Aaron Durbinafe8aee2016-11-29 21:37:42 -060019#include <string.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070020#include <timestamp.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070021#include <vendorcode/google/chromeos/chromeos.h>
22
Arthur Heymans73ac1212019-05-23 14:41:19 +020023static void raminit_common(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -070024{
Subrata Banik0beac812017-07-12 15:13:53 +053025 bool s3wake;
Aaron Durbin31be2c92016-12-03 22:08:20 -060026 struct region_device rdev;
Lee Leahy0946ec32015-04-20 15:24:54 -070027
28 post_code(0x32);
29
30 timestamp_add_now(TS_BEFORE_INITRAM);
31
Subrata Banik0beac812017-07-12 15:13:53 +053032 s3wake = params->power_state->prev_sleep_state == ACPI_S3;
Lee Leahy0946ec32015-04-20 15:24:54 -070033
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +030034 elog_boot_notify(s3wake);
Lee Leahy0946ec32015-04-20 15:24:54 -070035
36 /* Perform remaining SOC initialization */
37 soc_pre_ram_init(params);
38 post_code(0x33);
39
40 /* Check recovery and MRC cache */
Nico Huber66318aa2019-05-04 16:59:20 +020041 params->saved_data_size = 0;
42 params->saved_data = NULL;
43 if (!params->disable_saved_data) {
Furquan Shaikh0325dc62016-07-25 13:02:36 -070044 if (vboot_recovery_mode_enabled()) {
Lee Leahy0946ec32015-04-20 15:24:54 -070045 /* Recovery mode does not use MRC cache */
46 printk(BIOS_DEBUG,
47 "Recovery mode: not using MRC cache.\n");
Julius Wernercd49cce2019-03-05 16:53:33 -080048 } else if (CONFIG(CACHE_MRC_SETTINGS)
Aaron Durbin31be2c92016-12-03 22:08:20 -060049 && (!mrc_cache_get_current(MRC_TRAINING_DATA,
50 params->fsp_version,
51 &rdev))) {
Lee Leahy0946ec32015-04-20 15:24:54 -070052 /* MRC cache found */
Nico Huber66318aa2019-05-04 16:59:20 +020053 params->saved_data_size = region_device_sz(&rdev);
54 params->saved_data = rdev_mmap_full(&rdev);
Elyes HAOUAS18958382018-08-07 12:23:16 +020055 /* Assume boot device is memory mapped. */
Julius Wernercd49cce2019-03-05 16:53:33 -080056 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Nico Huber16895c52019-05-04 16:29:17 +020057 } else if (s3wake) {
Lee Leahy0946ec32015-04-20 15:24:54 -070058 /* Waking from S3 and no cache. */
59 printk(BIOS_DEBUG,
60 "No MRC cache found in S3 resume path.\n");
61 post_code(POST_RESUME_FAILURE);
Patrick Rudolphf677d172018-10-01 19:17:11 +020062 /* FIXME: A "system" reset is likely enough: */
63 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -070064 } else {
65 printk(BIOS_DEBUG, "No MRC cache found.\n");
Lee Leahy0946ec32015-04-20 15:24:54 -070066 }
67 }
68
69 /* Initialize RAM */
70 raminit(params);
71 timestamp_add_now(TS_AFTER_INITRAM);
72
73 /* Save MRC output */
Julius Wernercd49cce2019-03-05 16:53:33 -080074 if (CONFIG(CACHE_MRC_SETTINGS)) {
Nico Huber66318aa2019-05-04 16:59:20 +020075 printk(BIOS_DEBUG, "MRC data at %p %zu bytes\n",
76 params->data_to_save, params->data_to_save_size);
Nico Huber16895c52019-05-04 16:29:17 +020077 if (!s3wake
Nico Huber66318aa2019-05-04 16:59:20 +020078 && (params->data_to_save_size != 0)
79 && (params->data_to_save != NULL))
Lee Leahy216712a2017-03-17 11:23:32 -070080 mrc_cache_stash_data(MRC_TRAINING_DATA,
81 params->fsp_version,
Nico Huber66318aa2019-05-04 16:59:20 +020082 params->data_to_save,
83 params->data_to_save_size);
Lee Leahy0946ec32015-04-20 15:24:54 -070084 }
85
86 /* Save DIMM information */
Subrata Banik0beac812017-07-12 15:13:53 +053087 if (!s3wake)
88 mainboard_save_dimm_info(params);
Lee Leahy0946ec32015-04-20 15:24:54 -070089
90 /* Create romstage handof information */
Aaron Durbin77e13992016-11-29 17:43:04 -060091 if (romstage_handoff_init(
92 params->power_state->prev_sleep_state == ACPI_S3) < 0)
Patrick Rudolphf677d172018-10-01 19:17:11 +020093 /* FIXME: A "system" reset is likely enough: */
94 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -070095}
96
Arthur Heymans73ac1212019-05-23 14:41:19 +020097void cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
98{
99 struct romstage_params params = {
100 .chipset_context = fih,
101 };
102
103 post_code(0x30);
104
105 timestamp_add_now(TS_START_ROMSTAGE);
106
107 /* Load microcode before RAM init */
108 if (CONFIG(SUPPORT_CPU_UCODE_IN_CBFS))
109 intel_update_microcode_from_cbfs();
110
111 /* Display parameters */
112 if (!CONFIG(NO_MMCONF_SUPPORT))
113 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
114 CONFIG_MMCONF_BASE_ADDRESS);
115 printk(BIOS_INFO, "Using FSP 1.1\n");
116
117 /* Display FSP banner */
118 print_fsp_info(fih);
119
120 /* Stash FSP version. */
121 params.fsp_version = fsp_version(fih);
122
123 /* Get power state */
124 params.power_state = fill_power_state();
125
126 /* Board initialization before and after RAM is enabled */
127 mainboard_pre_raminit(&params);
128
129 post_code(0x31);
130
131 /* Initialize memory */
132 raminit_common(&params);
133
134 soc_after_ram_init(&params);
135 post_code(0x38);
136}
137
Lee Leahy0946ec32015-04-20 15:24:54 -0700138/* Initialize the power state */
Aaron Durbin64031672018-04-21 14:45:32 -0600139__weak struct chipset_power_state *fill_power_state(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700140{
Lee Leahy0946ec32015-04-20 15:24:54 -0700141 return NULL;
142}
143
Lee Leahy0946ec32015-04-20 15:24:54 -0700144/* Board initialization before and after RAM is enabled */
Arthur Heymans73ac1212019-05-23 14:41:19 +0200145__weak void mainboard_pre_raminit(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700146{
Lee Leahy0946ec32015-04-20 15:24:54 -0700147}
148
149/* Save the DIMM information for SMBIOS table 17 */
Aaron Durbin64031672018-04-21 14:45:32 -0600150__weak void mainboard_save_dimm_info(
Lee Leahy0946ec32015-04-20 15:24:54 -0700151 struct romstage_params *params)
152{
153 int channel;
154 CHANNEL_INFO *channel_info;
155 int dimm;
156 DIMM_INFO *dimm_info;
157 int dimm_max;
158 void *hob_list_ptr;
159 EFI_HOB_GUID_TYPE *hob_ptr;
160 int index;
161 struct memory_info *mem_info;
162 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
163 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
164
165 /* Locate the memory info HOB, presence validated by raminit */
166 hob_list_ptr = fsp_get_hob_list();
167 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
168 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
169
170 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
Julius Wernercd49cce2019-03-05 16:53:33 -0800171 if (CONFIG(DISPLAY_HOBS)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700172 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
173 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
174 memory_info_hob->Revision);
175 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
176 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700177 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700178 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700179 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
180 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700181 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
182 memory_info_hob->ErrorCorrectionType);
183 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
184 memory_info_hob->ChannelCount);
185 for (channel = 0; channel < memory_info_hob->ChannelCount;
186 channel++) {
187 channel_info = &memory_info_hob->ChannelInfo[channel];
188 printk(BIOS_DEBUG, " Channel %d\n", channel);
189 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
190 channel_info->ChannelId);
191 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
192 channel_info->DimmCount);
193 for (dimm = 0; dimm < channel_info->DimmCount;
194 dimm++) {
195 dimm_info = &channel_info->DimmInfo[dimm];
196 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
197 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
198 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700199 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700200 dimm_info->SizeInMb);
201 }
202 }
203 }
204
205 /*
206 * Allocate CBMEM area for DIMM information used to populate SMBIOS
207 * table 17
208 */
209 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
Julius Werner540a9802019-12-09 13:03:29 -0800210 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: %p\n", mem_info);
Lee Leahy0946ec32015-04-20 15:24:54 -0700211 if (mem_info == NULL)
212 return;
213 memset(mem_info, 0, sizeof(*mem_info));
214
215 /* Describe the first N DIMMs in the system */
216 index = 0;
217 dimm_max = ARRAY_SIZE(mem_info->dimm);
218 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
219 if (index >= dimm_max)
220 break;
221 channel_info = &memory_info_hob->ChannelInfo[channel];
222 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
223 if (index >= dimm_max)
224 break;
225 dimm_info = &channel_info->DimmInfo[dimm];
226
227 /* Populate the DIMM information */
228 if (dimm_info->SizeInMb) {
229 mem_info->dimm[index].dimm_size =
230 dimm_info->SizeInMb;
231 mem_info->dimm[index].ddr_type =
232 memory_info_hob->MemoryType;
233 mem_info->dimm[index].ddr_frequency =
234 memory_info_hob->MemoryFrequencyInMHz;
235 mem_info->dimm[index].channel_num =
236 channel_info->ChannelId;
237 mem_info->dimm[index].dimm_num =
238 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700239 switch (memory_info_hob->DataWidth) {
240 default:
241 case 8:
242 mem_info->dimm[index].bus_width =
243 MEMORY_BUS_WIDTH_8;
244 break;
245
246 case 16:
247 mem_info->dimm[index].bus_width =
248 MEMORY_BUS_WIDTH_16;
249 break;
250
251 case 32:
252 mem_info->dimm[index].bus_width =
253 MEMORY_BUS_WIDTH_32;
254 break;
255
256 case 64:
257 mem_info->dimm[index].bus_width =
258 MEMORY_BUS_WIDTH_64;
259 break;
260
261 case 128:
262 mem_info->dimm[index].bus_width =
263 MEMORY_BUS_WIDTH_128;
264 break;
265 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700266
267 /* Add any mainboard specific information */
268 mainboard_add_dimm_info(params, mem_info,
269 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700270 index++;
271 }
272 }
273 }
274 mem_info->dimm_cnt = index;
275 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
276}
Lee Leahy0946ec32015-04-20 15:24:54 -0700277
Duncan Laurie46a2c772015-07-20 16:48:55 -0700278/* Add any mainboard specific information */
Aaron Durbin64031672018-04-21 14:45:32 -0600279__weak void mainboard_add_dimm_info(
Duncan Laurie46a2c772015-07-20 16:48:55 -0700280 struct romstage_params *params,
281 struct memory_info *mem_info,
282 int channel, int dimm, int index)
283{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700284}
285
Lee Leahy0946ec32015-04-20 15:24:54 -0700286/* Get the memory configuration data */
Aaron Durbin64031672018-04-21 14:45:32 -0600287__weak int mrc_cache_get_current(int type, uint32_t version,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600288 struct region_device *rdev)
Lee Leahy0946ec32015-04-20 15:24:54 -0700289{
Lee Leahy0946ec32015-04-20 15:24:54 -0700290 return -1;
291}
292
293/* Save the memory configuration data */
Aaron Durbin64031672018-04-21 14:45:32 -0600294__weak int mrc_cache_stash_data(int type, uint32_t version,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600295 const void *data, size_t size)
Lee Leahy0946ec32015-04-20 15:24:54 -0700296{
Lee Leahy0946ec32015-04-20 15:24:54 -0700297 return -1;
298}
299
Lee Leahy0946ec32015-04-20 15:24:54 -0700300/* Display the memory configuration */
Aaron Durbin64031672018-04-21 14:45:32 -0600301__weak void report_memory_config(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700302{
Lee Leahy0946ec32015-04-20 15:24:54 -0700303}
304
Lee Leahy0946ec32015-04-20 15:24:54 -0700305/* SOC initialization after RAM is enabled */
Aaron Durbin64031672018-04-21 14:45:32 -0600306__weak void soc_after_ram_init(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700307{
Lee Leahy0946ec32015-04-20 15:24:54 -0700308}
309
Lee Leahy0946ec32015-04-20 15:24:54 -0700310/* SOC initialization before RAM is enabled */
Aaron Durbin64031672018-04-21 14:45:32 -0600311__weak void soc_pre_ram_init(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700312{
Lee Leahy0946ec32015-04-20 15:24:54 -0700313}