Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 2 | |
| 3 | #include <stddef.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 5 | #include <assert.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <cbmem.h> |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 8 | #include <cf9_reset.h> |
robbie zhang | 13a2e94 | 2016-02-10 11:40:11 -0800 | [diff] [blame] | 9 | #include <cpu/intel/microcode.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 10 | #include <ec/google/chromeec/ec.h> |
| 11 | #include <ec/google/chromeec/ec_commands.h> |
| 12 | #include <elog.h> |
Lee Leahy | b092c9e | 2016-01-01 18:09:50 -0800 | [diff] [blame] | 13 | #include <fsp/romstage.h> |
Aaron Durbin | decd062 | 2017-12-15 12:26:40 -0700 | [diff] [blame] | 14 | #include <mrc_cache.h> |
Kyösti Mälkki | 65e8f64 | 2016-06-27 11:27:56 +0300 | [diff] [blame] | 15 | #include <program_loading.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 16 | #include <romstage_handoff.h> |
Lee Leahy | 0be6d93 | 2015-06-26 11:15:42 -0700 | [diff] [blame] | 17 | #include <smbios.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 18 | #include <stage_cache.h> |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 19 | #include <string.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 20 | #include <timestamp.h> |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 21 | #include <vendorcode/google/chromeos/chromeos.h> |
| 22 | |
Arthur Heymans | 73ac121 | 2019-05-23 14:41:19 +0200 | [diff] [blame] | 23 | static void raminit_common(struct romstage_params *params) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 24 | { |
Subrata Banik | 0beac81 | 2017-07-12 15:13:53 +0530 | [diff] [blame] | 25 | bool s3wake; |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 26 | size_t mrc_size; |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 27 | |
| 28 | post_code(0x32); |
| 29 | |
| 30 | timestamp_add_now(TS_BEFORE_INITRAM); |
| 31 | |
Subrata Banik | 0beac81 | 2017-07-12 15:13:53 +0530 | [diff] [blame] | 32 | s3wake = params->power_state->prev_sleep_state == ACPI_S3; |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 33 | |
Kyösti Mälkki | 7f50afb | 2019-09-11 17:12:26 +0300 | [diff] [blame] | 34 | elog_boot_notify(s3wake); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 35 | |
| 36 | /* Perform remaining SOC initialization */ |
| 37 | soc_pre_ram_init(params); |
| 38 | post_code(0x33); |
| 39 | |
| 40 | /* Check recovery and MRC cache */ |
Nico Huber | 66318aa | 2019-05-04 16:59:20 +0200 | [diff] [blame] | 41 | params->saved_data_size = 0; |
| 42 | params->saved_data = NULL; |
| 43 | if (!params->disable_saved_data) { |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 44 | if (vboot_recovery_mode_enabled()) { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 45 | /* Recovery mode does not use MRC cache */ |
| 46 | printk(BIOS_DEBUG, |
| 47 | "Recovery mode: not using MRC cache.\n"); |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 48 | } else { |
Elyes HAOUAS | 1895838 | 2018-08-07 12:23:16 +0200 | [diff] [blame] | 49 | /* Assume boot device is memory mapped. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 50 | assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 51 | |
| 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 Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | /* Initialize RAM */ |
| 77 | raminit(params); |
| 78 | timestamp_add_now(TS_AFTER_INITRAM); |
| 79 | |
| 80 | /* Save MRC output */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 81 | if (CONFIG(CACHE_MRC_SETTINGS)) { |
Nico Huber | 66318aa | 2019-05-04 16:59:20 +0200 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "MRC data at %p %zu bytes\n", |
| 83 | params->data_to_save, params->data_to_save_size); |
Nico Huber | 16895c5 | 2019-05-04 16:29:17 +0200 | [diff] [blame] | 84 | if (!s3wake |
Nico Huber | 66318aa | 2019-05-04 16:59:20 +0200 | [diff] [blame] | 85 | && (params->data_to_save_size != 0) |
| 86 | && (params->data_to_save != NULL)) |
Lee Leahy | 216712a | 2017-03-17 11:23:32 -0700 | [diff] [blame] | 87 | mrc_cache_stash_data(MRC_TRAINING_DATA, |
| 88 | params->fsp_version, |
Nico Huber | 66318aa | 2019-05-04 16:59:20 +0200 | [diff] [blame] | 89 | params->data_to_save, |
| 90 | params->data_to_save_size); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* Save DIMM information */ |
Subrata Banik | 0beac81 | 2017-07-12 15:13:53 +0530 | [diff] [blame] | 94 | if (!s3wake) |
| 95 | mainboard_save_dimm_info(params); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 96 | |
| 97 | /* Create romstage handof information */ |
Aaron Durbin | 77e1399 | 2016-11-29 17:43:04 -0600 | [diff] [blame] | 98 | if (romstage_handoff_init( |
| 99 | params->power_state->prev_sleep_state == ACPI_S3) < 0) |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 100 | /* FIXME: A "system" reset is likely enough: */ |
| 101 | full_reset(); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Arthur Heymans | 73ac121 | 2019-05-23 14:41:19 +0200 | [diff] [blame] | 104 | void 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(¶ms); |
| 135 | |
| 136 | post_code(0x31); |
| 137 | |
| 138 | /* Initialize memory */ |
| 139 | raminit_common(¶ms); |
| 140 | |
| 141 | soc_after_ram_init(¶ms); |
| 142 | post_code(0x38); |
| 143 | } |
| 144 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 145 | /* Initialize the power state */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 146 | __weak struct chipset_power_state *fill_power_state(void) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 147 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 148 | return NULL; |
| 149 | } |
| 150 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 151 | /* Board initialization before and after RAM is enabled */ |
Arthur Heymans | 73ac121 | 2019-05-23 14:41:19 +0200 | [diff] [blame] | 152 | __weak void mainboard_pre_raminit(struct romstage_params *params) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 153 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* Save the DIMM information for SMBIOS table 17 */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 157 | __weak void mainboard_save_dimm_info( |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 158 | 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 178 | if (CONFIG(DISPLAY_HOBS)) { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 179 | 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 Leahy | 0be6d93 | 2015-06-26 11:15:42 -0700 | [diff] [blame] | 184 | printk(BIOS_DEBUG, " %d: MemoryFrequencyInMHz\n", |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 185 | memory_info_hob->MemoryFrequencyInMHz); |
Lee Leahy | 0be6d93 | 2015-06-26 11:15:42 -0700 | [diff] [blame] | 186 | printk(BIOS_DEBUG, " %d: DataWidth in bits\n", |
| 187 | memory_info_hob->DataWidth); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 188 | 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 Leahy | 0be6d93 | 2015-06-26 11:15:42 -0700 | [diff] [blame] | 206 | printk(BIOS_DEBUG, " %d: SizeInMb\n", |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 207 | 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 Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 217 | printk(BIOS_DEBUG, "CBMEM entry for DIMM info: %p\n", mem_info); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 218 | 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 Leahy | 0be6d93 | 2015-06-26 11:15:42 -0700 | [diff] [blame] | 246 | 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 Laurie | 46a2c77 | 2015-07-20 16:48:55 -0700 | [diff] [blame] | 273 | |
| 274 | /* Add any mainboard specific information */ |
| 275 | mainboard_add_dimm_info(params, mem_info, |
| 276 | channel, dimm, index); |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 277 | index++; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | mem_info->dimm_cnt = index; |
| 282 | printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt); |
| 283 | } |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 284 | |
Duncan Laurie | 46a2c77 | 2015-07-20 16:48:55 -0700 | [diff] [blame] | 285 | /* Add any mainboard specific information */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 286 | __weak void mainboard_add_dimm_info( |
Duncan Laurie | 46a2c77 | 2015-07-20 16:48:55 -0700 | [diff] [blame] | 287 | struct romstage_params *params, |
| 288 | struct memory_info *mem_info, |
| 289 | int channel, int dimm, int index) |
| 290 | { |
Duncan Laurie | 46a2c77 | 2015-07-20 16:48:55 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 293 | /* Save the memory configuration data */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 294 | __weak int mrc_cache_stash_data(int type, uint32_t version, |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 295 | const void *data, size_t size) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 296 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 297 | return -1; |
| 298 | } |
| 299 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 300 | /* Display the memory configuration */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 301 | __weak void report_memory_config(void) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 302 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 305 | /* SOC initialization after RAM is enabled */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 306 | __weak void soc_after_ram_init(struct romstage_params *params) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 307 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 310 | /* SOC initialization before RAM is enabled */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 311 | __weak void soc_pre_ram_init(struct romstage_params *params) |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 312 | { |
Lee Leahy | 0946ec3 | 2015-04-20 15:24:54 -0700 | [diff] [blame] | 313 | } |