Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 3 | #include <assert.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 4 | #include <cbfs.h> |
| 5 | #include <cbmem.h> |
Patrick Rudolph | 45022ae | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 6 | #include <cf9_reset.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <device/pci_def.h> |
Matt DeVillier | 9aaf59a | 2018-05-27 21:51:49 -0500 | [diff] [blame] | 9 | #include <memory_info.h> |
Aaron Durbin | decd062 | 2017-12-15 12:26:40 -0700 | [diff] [blame] | 10 | #include <mrc_cache.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 11 | #include <string.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 12 | #include <soc/iomap.h> |
| 13 | #include <soc/pei_data.h> |
| 14 | #include <soc/pei_wrapper.h> |
| 15 | #include <soc/pm.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 16 | #include <soc/romstage.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 17 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 18 | |
Angel Pons | d0d528a | 2021-01-20 23:09:16 +0100 | [diff] [blame] | 19 | void save_mrc_data(struct pei_data *pei_data) |
| 20 | { |
| 21 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save, |
| 22 | pei_data->data_to_save_size); |
| 23 | |
| 24 | if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0) |
| 25 | mrc_cache_stash_data(MRC_TRAINING_DATA, 0, |
| 26 | pei_data->data_to_save, |
| 27 | pei_data->data_to_save_size); |
| 28 | } |
| 29 | |
Angel Pons | 29a52c8 | 2020-10-13 23:32:55 +0200 | [diff] [blame] | 30 | static const char *const ecc_decoder[] = { |
| 31 | "inactive", |
| 32 | "active on IO", |
| 33 | "disabled on IO", |
| 34 | "active", |
| 35 | }; |
| 36 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 37 | /* |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 38 | * Dump in the log memory controller configuration as read from the memory |
| 39 | * controller registers. |
| 40 | */ |
| 41 | static void report_memory_config(void) |
| 42 | { |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 43 | int i; |
| 44 | |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame] | 45 | const u32 addr_decoder_common = mchbar_read32(MAD_CHNL); |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 46 | |
| 47 | printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n", |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame] | 48 | (mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100); |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 49 | |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 50 | printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n", |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 51 | (addr_decoder_common >> 0) & 3, |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 52 | (addr_decoder_common >> 2) & 3, |
| 53 | (addr_decoder_common >> 4) & 3); |
| 54 | |
Angel Pons | 162a737 | 2020-10-13 23:37:07 +0200 | [diff] [blame] | 55 | for (i = 0; i < NUM_CHANNELS; i++) { |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame] | 56 | const u32 ch_conf = mchbar_read32(MAD_DIMM(i)); |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 57 | |
| 58 | printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf); |
Angel Pons | 29a52c8 | 2020-10-13 23:32:55 +0200 | [diff] [blame] | 59 | printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]); |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 60 | printk(BIOS_DEBUG, " enhanced interleave mode %s\n", |
| 61 | ((ch_conf >> 22) & 1) ? "on" : "off"); |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 62 | |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 63 | printk(BIOS_DEBUG, " rank interleave %s\n", |
| 64 | ((ch_conf >> 21) & 1) ? "on" : "off"); |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 65 | |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 66 | printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n", |
| 67 | ((ch_conf >> 0) & 0xff) * 256, |
| 68 | ((ch_conf >> 19) & 1) ? "x16" : "x8 or x32", |
| 69 | ((ch_conf >> 17) & 1) ? "dual" : "single", |
| 70 | ((ch_conf >> 16) & 1) ? "" : ", selected"); |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 71 | |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 72 | printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n", |
| 73 | ((ch_conf >> 8) & 0xff) * 256, |
Angel Pons | 973c9d4 | 2020-10-13 23:28:23 +0200 | [diff] [blame] | 74 | ((ch_conf >> 20) & 1) ? "x16" : "x8 or x32", |
Angel Pons | 239c966 | 2020-10-13 21:34:53 +0200 | [diff] [blame] | 75 | ((ch_conf >> 18) & 1) ? "dual" : "single", |
| 76 | ((ch_conf >> 16) & 1) ? ", selected" : ""); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /* |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 81 | * Find PEI executable in coreboot filesystem and execute it. |
| 82 | */ |
Angel Pons | d0d528a | 2021-01-20 23:09:16 +0100 | [diff] [blame] | 83 | void sdram_initialize(struct pei_data *pei_data) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 84 | { |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 85 | size_t mrc_size; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 86 | pei_wrapper_entry_t entry; |
| 87 | int ret; |
| 88 | |
| 89 | broadwell_fill_pei_data(pei_data); |
| 90 | |
Shelley Chen | 6615c6e | 2020-10-27 15:58:31 -0700 | [diff] [blame] | 91 | /* Assume boot device is memory mapped. */ |
| 92 | assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 93 | |
Shelley Chen | 6615c6e | 2020-10-27 15:58:31 -0700 | [diff] [blame] | 94 | pei_data->saved_data = |
| 95 | mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, 0, |
| 96 | &mrc_size); |
| 97 | if (pei_data->saved_data) { |
| 98 | /* MRC cache found */ |
| 99 | pei_data->saved_data_size = mrc_size; |
| 100 | } else if (pei_data->boot_mode == ACPI_S3) { |
| 101 | /* Waking from S3 and no cache. */ |
| 102 | printk(BIOS_DEBUG, |
| 103 | "No MRC cache found in S3 resume path.\n"); |
| 104 | post_code(POST_RESUME_FAILURE); |
| 105 | system_reset(); |
| 106 | } else { |
| 107 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 110 | /* |
| 111 | * Do not use saved pei data. Can be set by mainboard romstage |
| 112 | * to force a full train of memory on every boot. |
| 113 | */ |
| 114 | if (pei_data->disable_saved_data) { |
| 115 | printk(BIOS_DEBUG, "Disabling PEI saved data by request\n"); |
| 116 | pei_data->saved_data = NULL; |
| 117 | pei_data->saved_data_size = 0; |
| 118 | } |
| 119 | |
Arthur Heymans | 4d56a06 | 2018-12-22 16:11:52 +0100 | [diff] [blame] | 120 | /* We don't care about leaking the mapping */ |
Julius Werner | 9d0cc2a | 2020-01-22 18:00:18 -0800 | [diff] [blame] | 121 | entry = cbfs_ro_map("mrc.bin", NULL); |
| 122 | if (entry == NULL) |
| 123 | die("mrc.bin not found!"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 124 | |
| 125 | printk(BIOS_DEBUG, "Starting Memory Reference Code\n"); |
| 126 | |
| 127 | ret = entry(pei_data); |
| 128 | if (ret < 0) |
| 129 | die("pei_data version mismatch\n"); |
| 130 | |
| 131 | /* Print the MRC version after executing the UEFI PEI stage. */ |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame] | 132 | u32 version = mchbar_read32(MRC_REVISION); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 133 | printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n", |
Angel Pons | 430f1c5 | 2020-10-13 23:01:48 +0200 | [diff] [blame] | 134 | (version >> 24) & 0xff, (version >> 16) & 0xff, |
| 135 | (version >> 8) & 0xff, (version >> 0) & 0xff); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 136 | |
| 137 | report_memory_config(); |
Angel Pons | d0d528a | 2021-01-20 23:09:16 +0100 | [diff] [blame] | 138 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 139 | |
Angel Pons | d0d528a | 2021-01-20 23:09:16 +0100 | [diff] [blame] | 140 | void setup_sdram_meminfo(struct pei_data *pei_data) |
| 141 | { |
| 142 | struct memory_info *mem_info; |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame] | 143 | |
| 144 | printk(BIOS_DEBUG, "create cbmem for dimm information\n"); |
| 145 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info)); |
John Zhao | 317cbd6 | 2019-05-31 10:44:46 -0700 | [diff] [blame] | 146 | |
| 147 | if (!mem_info) { |
| 148 | printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n"); |
| 149 | return; |
| 150 | } |
| 151 | |
Matt DeVillier | 9aaf59a | 2018-05-27 21:51:49 -0500 | [diff] [blame] | 152 | memset(mem_info, 0, sizeof(*mem_info)); |
| 153 | /* Translate pei_memory_info struct data into memory_info struct */ |
| 154 | mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt; |
| 155 | for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) { |
| 156 | struct dimm_info *dimm = &mem_info->dimm[i]; |
| 157 | const struct pei_dimm_info *pei_dimm = |
| 158 | &pei_data->meminfo.dimm[i]; |
| 159 | dimm->dimm_size = pei_dimm->dimm_size; |
| 160 | dimm->ddr_type = pei_dimm->ddr_type; |
| 161 | dimm->ddr_frequency = pei_dimm->ddr_frequency; |
| 162 | dimm->rank_per_dimm = pei_dimm->rank_per_dimm; |
| 163 | dimm->channel_num = pei_dimm->channel_num; |
| 164 | dimm->dimm_num = pei_dimm->dimm_num; |
| 165 | dimm->bank_locator = pei_dimm->bank_locator; |
| 166 | memcpy(&dimm->serial, &pei_dimm->serial, |
| 167 | MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial))); |
| 168 | memcpy(&dimm->module_part_number, |
| 169 | &pei_dimm->module_part_number, |
| 170 | MIN(sizeof(dimm->module_part_number), |
| 171 | sizeof(pei_dimm->module_part_number))); |
| 172 | dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0'; |
| 173 | dimm->mod_id = pei_dimm->mod_id; |
| 174 | dimm->mod_type = pei_dimm->mod_type; |
| 175 | dimm->bus_width = pei_dimm->bus_width; |
| 176 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 177 | } |