blob: 5a59c502a9cfa698155e10d7607839e865946dcc [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;
Shelley Chenad9cd682020-07-23 16:10:52 -070026 size_t mrc_size;
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");
Shelley Chenad9cd682020-07-23 16:10:52 -070048 } else {
Elyes HAOUAS18958382018-08-07 12:23:16 +020049 /* Assume boot device is memory mapped. */
Julius Wernercd49cce2019-03-05 16:53:33 -080050 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Shelley Chenad9cd682020-07-23 16:10:52 -070051
52 params->saved_data = NULL;
53 if (CONFIG(CACHE_MRC_SETTINGS))
54 params->saved_data =
55 mrc_cache_current_mmap_leak(MRC_TRAINING_DATA,
56 params->fsp_version,
57 &mrc_size);
58 if (params->saved_data) {
59 /* MRC cache found */
60 params->saved_data_size = mrc_size;
61
62 } else if (s3wake) {
63 /* Waking from S3 and no cache. */
64 printk(BIOS_DEBUG,
65 "No MRC cache "
66 "found in S3 resume path.\n");
67 post_code(POST_RESUME_FAILURE);
68 /* FIXME: A "system" reset is likely enough: */
69 full_reset();
70 } else {
71 printk(BIOS_DEBUG, "No MRC cache found.\n");
72 }
Lee Leahy0946ec32015-04-20 15:24:54 -070073 }
74 }
75
76 /* Initialize RAM */
77 raminit(params);
78 timestamp_add_now(TS_AFTER_INITRAM);
79
80 /* Save MRC output */
Julius Wernercd49cce2019-03-05 16:53:33 -080081 if (CONFIG(CACHE_MRC_SETTINGS)) {
Nico Huber66318aa2019-05-04 16:59:20 +020082 printk(BIOS_DEBUG, "MRC data at %p %zu bytes\n",
83 params->data_to_save, params->data_to_save_size);
Nico Huber16895c52019-05-04 16:29:17 +020084 if (!s3wake
Nico Huber66318aa2019-05-04 16:59:20 +020085 && (params->data_to_save_size != 0)
86 && (params->data_to_save != NULL))
Lee Leahy216712a2017-03-17 11:23:32 -070087 mrc_cache_stash_data(MRC_TRAINING_DATA,
88 params->fsp_version,
Nico Huber66318aa2019-05-04 16:59:20 +020089 params->data_to_save,
90 params->data_to_save_size);
Lee Leahy0946ec32015-04-20 15:24:54 -070091 }
92
93 /* Save DIMM information */
Subrata Banik0beac812017-07-12 15:13:53 +053094 if (!s3wake)
95 mainboard_save_dimm_info(params);
Lee Leahy0946ec32015-04-20 15:24:54 -070096
97 /* Create romstage handof information */
Aaron Durbin77e13992016-11-29 17:43:04 -060098 if (romstage_handoff_init(
99 params->power_state->prev_sleep_state == ACPI_S3) < 0)
Patrick Rudolphf677d172018-10-01 19:17:11 +0200100 /* FIXME: A "system" reset is likely enough: */
101 full_reset();
Lee Leahy0946ec32015-04-20 15:24:54 -0700102}
103
Arthur Heymans73ac1212019-05-23 14:41:19 +0200104void cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
105{
106 struct romstage_params params = {
107 .chipset_context = fih,
108 };
109
110 post_code(0x30);
111
112 timestamp_add_now(TS_START_ROMSTAGE);
113
114 /* Load microcode before RAM init */
115 if (CONFIG(SUPPORT_CPU_UCODE_IN_CBFS))
116 intel_update_microcode_from_cbfs();
117
118 /* Display parameters */
119 if (!CONFIG(NO_MMCONF_SUPPORT))
120 printk(BIOS_SPEW, "CONFIG_MMCONF_BASE_ADDRESS: 0x%08x\n",
121 CONFIG_MMCONF_BASE_ADDRESS);
122 printk(BIOS_INFO, "Using FSP 1.1\n");
123
124 /* Display FSP banner */
125 print_fsp_info(fih);
126
127 /* Stash FSP version. */
128 params.fsp_version = fsp_version(fih);
129
130 /* Get power state */
131 params.power_state = fill_power_state();
132
133 /* Board initialization before and after RAM is enabled */
134 mainboard_pre_raminit(&params);
135
136 post_code(0x31);
137
138 /* Initialize memory */
139 raminit_common(&params);
140
141 soc_after_ram_init(&params);
142 post_code(0x38);
143}
144
Lee Leahy0946ec32015-04-20 15:24:54 -0700145/* Initialize the power state */
Aaron Durbin64031672018-04-21 14:45:32 -0600146__weak struct chipset_power_state *fill_power_state(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700147{
Lee Leahy0946ec32015-04-20 15:24:54 -0700148 return NULL;
149}
150
Lee Leahy0946ec32015-04-20 15:24:54 -0700151/* Board initialization before and after RAM is enabled */
Arthur Heymans73ac1212019-05-23 14:41:19 +0200152__weak void mainboard_pre_raminit(struct romstage_params *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700153{
Lee Leahy0946ec32015-04-20 15:24:54 -0700154}
155
156/* Save the DIMM information for SMBIOS table 17 */
Aaron Durbin64031672018-04-21 14:45:32 -0600157__weak void mainboard_save_dimm_info(
Lee Leahy0946ec32015-04-20 15:24:54 -0700158 struct romstage_params *params)
159{
160 int channel;
161 CHANNEL_INFO *channel_info;
162 int dimm;
163 DIMM_INFO *dimm_info;
164 int dimm_max;
165 void *hob_list_ptr;
166 EFI_HOB_GUID_TYPE *hob_ptr;
167 int index;
168 struct memory_info *mem_info;
169 FSP_SMBIOS_MEMORY_INFO *memory_info_hob;
170 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
171
172 /* Locate the memory info HOB, presence validated by raminit */
173 hob_list_ptr = fsp_get_hob_list();
174 hob_ptr = get_next_guid_hob(&memory_info_hob_guid, hob_list_ptr);
175 memory_info_hob = (FSP_SMBIOS_MEMORY_INFO *)(hob_ptr + 1);
176
177 /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */
Julius Wernercd49cce2019-03-05 16:53:33 -0800178 if (CONFIG(DISPLAY_HOBS)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700179 printk(BIOS_DEBUG, "FSP_SMBIOS_MEMORY_INFO HOB\n");
180 printk(BIOS_DEBUG, " 0x%02x: Revision\n",
181 memory_info_hob->Revision);
182 printk(BIOS_DEBUG, " 0x%02x: MemoryType\n",
183 memory_info_hob->MemoryType);
Lee Leahy0be6d932015-06-26 11:15:42 -0700184 printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700185 memory_info_hob->MemoryFrequencyInMHz);
Lee Leahy0be6d932015-06-26 11:15:42 -0700186 printk(BIOS_DEBUG, " %d: DataWidth in bits\n",
187 memory_info_hob->DataWidth);
Lee Leahy0946ec32015-04-20 15:24:54 -0700188 printk(BIOS_DEBUG, " 0x%02x: ErrorCorrectionType\n",
189 memory_info_hob->ErrorCorrectionType);
190 printk(BIOS_DEBUG, " 0x%02x: ChannelCount\n",
191 memory_info_hob->ChannelCount);
192 for (channel = 0; channel < memory_info_hob->ChannelCount;
193 channel++) {
194 channel_info = &memory_info_hob->ChannelInfo[channel];
195 printk(BIOS_DEBUG, " Channel %d\n", channel);
196 printk(BIOS_DEBUG, " 0x%02x: ChannelId\n",
197 channel_info->ChannelId);
198 printk(BIOS_DEBUG, " 0x%02x: DimmCount\n",
199 channel_info->DimmCount);
200 for (dimm = 0; dimm < channel_info->DimmCount;
201 dimm++) {
202 dimm_info = &channel_info->DimmInfo[dimm];
203 printk(BIOS_DEBUG, " DIMM %d\n", dimm);
204 printk(BIOS_DEBUG, " 0x%02x: DimmId\n",
205 dimm_info->DimmId);
Lee Leahy0be6d932015-06-26 11:15:42 -0700206 printk(BIOS_DEBUG, " %d: SizeInMb\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700207 dimm_info->SizeInMb);
208 }
209 }
210 }
211
212 /*
213 * Allocate CBMEM area for DIMM information used to populate SMBIOS
214 * table 17
215 */
216 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
Julius Werner540a9802019-12-09 13:03:29 -0800217 printk(BIOS_DEBUG, "CBMEM entry for DIMM info: %p\n", mem_info);
Lee Leahy0946ec32015-04-20 15:24:54 -0700218 if (mem_info == NULL)
219 return;
220 memset(mem_info, 0, sizeof(*mem_info));
221
222 /* Describe the first N DIMMs in the system */
223 index = 0;
224 dimm_max = ARRAY_SIZE(mem_info->dimm);
225 for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) {
226 if (index >= dimm_max)
227 break;
228 channel_info = &memory_info_hob->ChannelInfo[channel];
229 for (dimm = 0; dimm < channel_info->DimmCount; dimm++) {
230 if (index >= dimm_max)
231 break;
232 dimm_info = &channel_info->DimmInfo[dimm];
233
234 /* Populate the DIMM information */
235 if (dimm_info->SizeInMb) {
236 mem_info->dimm[index].dimm_size =
237 dimm_info->SizeInMb;
238 mem_info->dimm[index].ddr_type =
239 memory_info_hob->MemoryType;
240 mem_info->dimm[index].ddr_frequency =
241 memory_info_hob->MemoryFrequencyInMHz;
242 mem_info->dimm[index].channel_num =
243 channel_info->ChannelId;
244 mem_info->dimm[index].dimm_num =
245 dimm_info->DimmId;
Lee Leahy0be6d932015-06-26 11:15:42 -0700246 switch (memory_info_hob->DataWidth) {
247 default:
248 case 8:
249 mem_info->dimm[index].bus_width =
250 MEMORY_BUS_WIDTH_8;
251 break;
252
253 case 16:
254 mem_info->dimm[index].bus_width =
255 MEMORY_BUS_WIDTH_16;
256 break;
257
258 case 32:
259 mem_info->dimm[index].bus_width =
260 MEMORY_BUS_WIDTH_32;
261 break;
262
263 case 64:
264 mem_info->dimm[index].bus_width =
265 MEMORY_BUS_WIDTH_64;
266 break;
267
268 case 128:
269 mem_info->dimm[index].bus_width =
270 MEMORY_BUS_WIDTH_128;
271 break;
272 }
Duncan Laurie46a2c772015-07-20 16:48:55 -0700273
274 /* Add any mainboard specific information */
275 mainboard_add_dimm_info(params, mem_info,
276 channel, dimm, index);
Lee Leahy0946ec32015-04-20 15:24:54 -0700277 index++;
278 }
279 }
280 }
281 mem_info->dimm_cnt = index;
282 printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt);
283}
Lee Leahy0946ec32015-04-20 15:24:54 -0700284
Duncan Laurie46a2c772015-07-20 16:48:55 -0700285/* Add any mainboard specific information */
Aaron Durbin64031672018-04-21 14:45:32 -0600286__weak void mainboard_add_dimm_info(
Duncan Laurie46a2c772015-07-20 16:48:55 -0700287 struct romstage_params *params,
288 struct memory_info *mem_info,
289 int channel, int dimm, int index)
290{
Duncan Laurie46a2c772015-07-20 16:48:55 -0700291}
292
Lee Leahy0946ec32015-04-20 15:24:54 -0700293/* 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}