Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 4 | #include <commonlib/region.h> |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 5 | #include <cf9_reset.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 6 | #include <string.h> |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 7 | #include <cbfs.h> |
Subrata Banik | 53b08c3 | 2018-12-10 14:11:35 +0530 | [diff] [blame] | 8 | #include <arch/cpu.h> |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/dram/ddr3.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 11 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 13 | #include <device/smbus_host.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 14 | #include <cbmem.h> |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 15 | #include <timestamp.h> |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 16 | #include <mrc_cache.h> |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 17 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | da9302a | 2019-03-24 17:01:41 +0100 | [diff] [blame] | 18 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 19 | #include <cpu/x86/msr.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 20 | #include <types.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 21 | |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 22 | #include "raminit.h" |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 23 | #include "raminit_native.h" |
| 24 | #include "raminit_common.h" |
| 25 | #include "sandybridge.h" |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 26 | #include "chip.h" |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 27 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 28 | /* FIXME: no support for 3-channel chipsets */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 29 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 30 | static void wait_txt_clear(void) |
| 31 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 32 | struct cpuid_result cp = cpuid_ext(1, 0); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 33 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 34 | /* Check if TXT is supported */ |
| 35 | if (!(cp.ecx & (1 << 6))) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 36 | return; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 37 | |
| 38 | /* Some TXT public bit */ |
Elyes Haouas | 4b7d405 | 2022-12-03 13:24:03 +0100 | [diff] [blame] | 39 | if (!(read32p(0xfed30010) & 1)) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 40 | return; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 41 | |
| 42 | /* Wait for TXT clear */ |
Elyes Haouas | 4b7d405 | 2022-12-03 13:24:03 +0100 | [diff] [blame] | 43 | while (!(read8p(0xfed40000) & (1 << 7))) |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 44 | ; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 47 | /* Disable a channel in ramctr_timing */ |
| 48 | static void disable_channel(ramctr_timing *ctrl, int channel) |
| 49 | { |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 50 | ctrl->rankmap[channel] = 0; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 51 | |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 52 | memset(&ctrl->rank_mirror[channel][0], 0, sizeof(ctrl->rank_mirror[0])); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 53 | |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 54 | ctrl->channel_size_mb[channel] = 0; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 55 | ctrl->cmd_stretch[channel] = 0; |
| 56 | ctrl->mad_dimm[channel] = 0; |
| 57 | memset(&ctrl->timings[channel][0], 0, sizeof(ctrl->timings[0])); |
Patrick Rudolph | 74163d6 | 2016-11-17 20:02:43 +0100 | [diff] [blame] | 58 | memset(&ctrl->info.dimm[channel][0], 0, sizeof(ctrl->info.dimm[0])); |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Angel Pons | 6724ba4 | 2021-01-31 15:06:59 +0100 | [diff] [blame] | 61 | static uint8_t nb_get_ecc_type(const uint32_t capid0_a) |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 62 | { |
Angel Pons | 6724ba4 | 2021-01-31 15:06:59 +0100 | [diff] [blame] | 63 | return capid0_a & CAPID_ECCDIS ? MEMORY_ARRAY_ECC_NONE : MEMORY_ARRAY_ECC_SINGLE_BIT; |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static uint16_t nb_slots_per_channel(const uint32_t capid0_a) |
| 67 | { |
| 68 | return !(capid0_a & CAPID_DDPCD) + 1; |
| 69 | } |
| 70 | |
| 71 | static uint16_t nb_number_of_channels(const uint32_t capid0_a) |
| 72 | { |
| 73 | return !(capid0_a & CAPID_PDCD) + 1; |
| 74 | } |
| 75 | |
| 76 | static uint32_t nb_max_chan_capacity_mib(const uint32_t capid0_a) |
| 77 | { |
| 78 | uint32_t ddrsz; |
| 79 | |
| 80 | /* Values from documentation, which assume two DIMMs per channel */ |
| 81 | switch (CAPID_DDRSZ(capid0_a)) { |
| 82 | case 1: |
| 83 | ddrsz = 8192; |
| 84 | break; |
| 85 | case 2: |
| 86 | ddrsz = 2048; |
| 87 | break; |
| 88 | case 3: |
| 89 | ddrsz = 512; |
| 90 | break; |
| 91 | default: |
| 92 | ddrsz = 16384; |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | /* Account for the maximum number of DIMMs per channel */ |
| 97 | return (ddrsz / 2) * nb_slots_per_channel(capid0_a); |
| 98 | } |
| 99 | |
| 100 | /* Fill cbmem with information for SMBIOS type 16 and type 17 */ |
| 101 | static void setup_sdram_meminfo(ramctr_timing *ctrl) |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 102 | { |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 103 | int channel, slot; |
Patrick Rudolph | 24efe73 | 2018-08-19 11:06:06 +0200 | [diff] [blame] | 104 | const u16 ddr_freq = (1000 << 8) / ctrl->tCK; |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 105 | |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 106 | FOR_ALL_CHANNELS for (slot = 0; slot < NUM_SLOTS; slot++) { |
Patrick Rudolph | 24efe73 | 2018-08-19 11:06:06 +0200 | [diff] [blame] | 107 | enum cb_err ret = spd_add_smbios17(channel, slot, ddr_freq, |
| 108 | &ctrl->info.dimm[channel][slot]); |
| 109 | if (ret != CB_SUCCESS) |
| 110 | printk(BIOS_ERR, "RAMINIT: Failed to add SMBIOS17\n"); |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 111 | } |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 112 | |
| 113 | /* The 'spd_add_smbios17' function allocates this CBMEM area */ |
| 114 | struct memory_info *m = cbmem_find(CBMEM_ID_MEMINFO); |
Elyes Haouas | 5e6b0f0 | 2022-09-13 09:55:49 +0200 | [diff] [blame] | 115 | if (!m) |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 116 | return; |
| 117 | |
| 118 | const uint32_t capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A); |
| 119 | |
| 120 | const uint16_t channels = nb_number_of_channels(capid0_a); |
| 121 | |
Angel Pons | 6724ba4 | 2021-01-31 15:06:59 +0100 | [diff] [blame] | 122 | m->ecc_type = nb_get_ecc_type(capid0_a); |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 123 | m->max_capacity_mib = channels * nb_max_chan_capacity_mib(capid0_a); |
| 124 | m->number_of_devices = channels * nb_slots_per_channel(capid0_a); |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 127 | /* Return CRC16 match for all SPDs */ |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 128 | static int verify_crc16_spds_ddr3(spd_raw_data *spd, ramctr_timing *ctrl) |
| 129 | { |
| 130 | int channel, slot, spd_slot; |
| 131 | int match = 1; |
| 132 | |
| 133 | FOR_ALL_CHANNELS { |
| 134 | for (slot = 0; slot < NUM_SLOTS; slot++) { |
| 135 | spd_slot = 2 * channel + slot; |
| 136 | match &= ctrl->spd_crc[channel][slot] == |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 137 | spd_ddr3_calc_unique_crc(spd[spd_slot], sizeof(spd_raw_data)); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | return match; |
| 141 | } |
| 142 | |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 143 | void read_spd(spd_raw_data * spd, u8 addr, bool id_only) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 144 | { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 145 | int j; |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 146 | if (id_only) { |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 147 | for (j = SPD_DIMM_MOD_ID1; j < 128; j++) |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame] | 148 | (*spd)[j] = smbus_read_byte(addr, j); |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 149 | } else { |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 150 | for (j = 0; j < SPD_SIZE_MAX_DDR3; j++) |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame] | 151 | (*spd)[j] = smbus_read_byte(addr, j); |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 152 | } |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Keith Hui | 1e9601c | 2023-07-15 12:08:51 -0400 | [diff] [blame] | 155 | /* Temporary stub */ |
| 156 | __weak void mb_get_spd_map(struct spd_info *spdi) {} |
| 157 | |
| 158 | __weak void mainboard_get_spd(spd_raw_data *spd, bool id_only) |
| 159 | { |
| 160 | const struct northbridge_intel_sandybridge_config *cfg = config_of_soc(); |
| 161 | unsigned int i; |
| 162 | |
| 163 | if (CONFIG(HAVE_SPD_IN_CBFS)) { |
| 164 | struct spd_info spdi = {0}; |
| 165 | |
| 166 | mb_get_spd_map(&spdi); |
| 167 | |
| 168 | size_t spd_file_len; |
| 169 | uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len); |
| 170 | |
| 171 | printk(BIOS_DEBUG, "SPD index %d\n", spdi.spd_index); |
| 172 | |
| 173 | /* SPD file sanity check */ |
| 174 | if (!spd_file) |
| 175 | die("SPD data %s!", "not found"); |
| 176 | |
| 177 | if (spd_file_len < ((spdi.spd_index + 1) * SPD_SIZE_MAX_DDR3)) |
| 178 | die("SPD data %s!", "incomplete"); |
| 179 | |
| 180 | /* |
| 181 | * Copy SPD data specified by spd_info.spd_index to all slots marked as |
| 182 | * SPD_MEMORY_DOWN. |
| 183 | * |
| 184 | * Read SPD data from slots with a real SMBus address. |
| 185 | */ |
| 186 | for (i = 0; i < ARRAY_SIZE(spdi.addresses); i++) { |
| 187 | if (spdi.addresses[i] == SPD_MEMORY_DOWN) |
| 188 | memcpy(&spd[i], spd_file + (spdi.spd_index * SPD_SIZE_MAX_DDR3), SPD_SIZE_MAX_DDR3); |
| 189 | else if (spdi.addresses[i] != 0) |
| 190 | read_spd(&spd[i], spdi.addresses[i], id_only); |
| 191 | } |
| 192 | } else { |
| 193 | for (i = 0; i < ARRAY_SIZE(cfg->spd_addresses); i++) { |
| 194 | if (cfg->spd_addresses[i] != 0) |
| 195 | read_spd(&spd[i], cfg->spd_addresses[i], id_only); |
| 196 | } |
| 197 | } /* CONFIG(HAVE_SPD_IN_CBFS) */ |
| 198 | } |
| 199 | |
Patrick Rudolph | 735ecce | 2016-03-26 10:42:27 +0100 | [diff] [blame] | 200 | static void dram_find_spds_ddr3(spd_raw_data *spd, ramctr_timing *ctrl) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 201 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 202 | int dimms = 0, ch_dimms; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 203 | int channel, slot, spd_slot; |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 204 | bool can_use_ecc = ctrl->ecc_supported; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 205 | |
Elyes Haouas | 9d450b2 | 2023-09-10 10:30:29 +0200 | [diff] [blame] | 206 | memset(ctrl->rankmap, 0, sizeof(ctrl->rankmap)); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 207 | |
| 208 | ctrl->extended_temperature_range = 1; |
| 209 | ctrl->auto_self_refresh = 1; |
| 210 | |
| 211 | FOR_ALL_CHANNELS { |
| 212 | ctrl->channel_size_mb[channel] = 0; |
| 213 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 214 | ch_dimms = 0; |
| 215 | /* Count dimms on channel */ |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 216 | for (slot = 0; slot < NUM_SLOTS; slot++) { |
| 217 | spd_slot = 2 * channel + slot; |
Patrick Rudolph | 5a06185 | 2017-09-22 15:19:26 +0200 | [diff] [blame] | 218 | |
Angel Pons | 035096c | 2020-09-17 22:31:19 +0200 | [diff] [blame] | 219 | if (spd[spd_slot][SPD_MEMORY_TYPE] == SPD_MEMORY_TYPE_SDRAM_DDR3) |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 220 | ch_dimms++; |
Patrick Rudolph | bd1fdc6 | 2016-01-26 08:45:21 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | for (slot = 0; slot < NUM_SLOTS; slot++) { |
| 224 | spd_slot = 2 * channel + slot; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 225 | printk(BIOS_DEBUG, "SPD probe channel%d, slot%d\n", channel, slot); |
Patrick Rudolph | 5a06185 | 2017-09-22 15:19:26 +0200 | [diff] [blame] | 226 | |
Angel Pons | afb3d7e | 2021-03-28 13:43:13 +0200 | [diff] [blame] | 227 | struct dimm_attr_ddr3_st *const dimm = &ctrl->info.dimm[channel][slot]; |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 228 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 229 | /* Search for XMP profile */ |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 230 | spd_xmp_decode_ddr3(dimm, spd[spd_slot], |
Patrick Rudolph | bd1fdc6 | 2016-01-26 08:45:21 +0100 | [diff] [blame] | 231 | DDR3_XMP_PROFILE_1); |
| 232 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 233 | if (dimm->dram_type != SPD_MEMORY_TYPE_SDRAM_DDR3) { |
Patrick Rudolph | bd1fdc6 | 2016-01-26 08:45:21 +0100 | [diff] [blame] | 234 | printram("No valid XMP profile found.\n"); |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 235 | spd_decode_ddr3(dimm, spd[spd_slot]); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 236 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 237 | } else if (ch_dimms > dimm->dimms_per_channel) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 238 | printram( |
| 239 | "XMP profile supports %u DIMMs, but %u DIMMs are installed.\n", |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 240 | dimm->dimms_per_channel, ch_dimms); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 241 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 242 | if (CONFIG(NATIVE_RAMINIT_IGNORE_XMP_MAX_DIMMS)) |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 243 | printk(BIOS_WARNING, |
| 244 | "XMP maximum DIMMs will be ignored.\n"); |
Vagiz Trakhanov | 771be48 | 2017-10-02 10:02:35 +0000 | [diff] [blame] | 245 | else |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 246 | spd_decode_ddr3(dimm, spd[spd_slot]); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 247 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 248 | } else if (dimm->voltage != 1500) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 249 | /* TODO: Support DDR3 voltages other than 1500mV */ |
Patrick Rudolph | bd1fdc6 | 2016-01-26 08:45:21 +0100 | [diff] [blame] | 250 | printram("XMP profile's requested %u mV is unsupported.\n", |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 251 | dimm->voltage); |
Angel Pons | 3170e9c | 2020-12-12 16:22:18 +0100 | [diff] [blame] | 252 | |
| 253 | if (CONFIG(NATIVE_RAMINIT_IGNORE_XMP_REQUESTED_VOLTAGE)) |
| 254 | printk(BIOS_WARNING, |
| 255 | "XMP requested voltage will be ignored.\n"); |
| 256 | else |
| 257 | spd_decode_ddr3(dimm, spd[spd_slot]); |
Patrick Rudolph | bd1fdc6 | 2016-01-26 08:45:21 +0100 | [diff] [blame] | 258 | } |
| 259 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 260 | /* Fill in CRC16 for MRC cache */ |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 261 | ctrl->spd_crc[channel][slot] = |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 262 | spd_ddr3_calc_unique_crc(spd[spd_slot], sizeof(spd_raw_data)); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 263 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 264 | if (dimm->dram_type != SPD_MEMORY_TYPE_SDRAM_DDR3) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 265 | /* Mark DIMM as invalid */ |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 266 | dimm->ranks = 0; |
| 267 | dimm->size_mb = 0; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 268 | continue; |
| 269 | } |
| 270 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 271 | dram_print_spd_ddr3(dimm); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 272 | dimms++; |
| 273 | ctrl->rank_mirror[channel][slot * 2] = 0; |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 274 | ctrl->rank_mirror[channel][slot * 2 + 1] = dimm->flags.pins_mirrored; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 275 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 276 | ctrl->channel_size_mb[channel] += dimm->size_mb; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 277 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 278 | if (!dimm->flags.is_ecc) |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 279 | can_use_ecc = false; |
| 280 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 281 | ctrl->auto_self_refresh &= dimm->flags.asr; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 282 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 283 | ctrl->extended_temperature_range &= dimm->flags.ext_temp_refresh; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 284 | |
Angel Pons | 323c0ae | 2020-12-12 16:57:37 +0100 | [diff] [blame] | 285 | ctrl->rankmap[channel] |= ((1 << dimm->ranks) - 1) << (2 * slot); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 286 | |
| 287 | printk(BIOS_DEBUG, "channel[%d] rankmap = 0x%x\n", channel, |
| 288 | ctrl->rankmap[channel]); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 289 | } |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 290 | |
Angel Pons | d4d3ba0 | 2020-12-12 17:45:14 +0100 | [diff] [blame] | 291 | const u8 rc_0 = ctrl->info.dimm[channel][0].reference_card; |
| 292 | const u8 rc_1 = ctrl->info.dimm[channel][1].reference_card; |
| 293 | |
| 294 | if (ch_dimms == NUM_SLOTS && rc_0 < 6 && rc_1 < 6) { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 295 | const int ref_card_offset_table[6][6] = { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 296 | { 0, 0, 0, 0, 2, 2 }, |
| 297 | { 0, 0, 0, 0, 2, 2 }, |
| 298 | { 0, 0, 0, 0, 2, 2 }, |
| 299 | { 0, 0, 0, 0, 1, 1 }, |
| 300 | { 2, 2, 2, 1, 0, 0 }, |
| 301 | { 2, 2, 2, 1, 0, 0 }, |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 302 | }; |
Angel Pons | d4d3ba0 | 2020-12-12 17:45:14 +0100 | [diff] [blame] | 303 | ctrl->ref_card_offset[channel] = ref_card_offset_table[rc_0][rc_1]; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 304 | } else { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 305 | ctrl->ref_card_offset[channel] = 0; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 306 | } |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 309 | if (ctrl->ecc_forced || CONFIG(RAMINIT_ENABLE_ECC)) |
| 310 | ctrl->ecc_enabled = can_use_ecc; |
| 311 | if (ctrl->ecc_forced && !ctrl->ecc_enabled) |
| 312 | die("ECC mode forced but non-ECC DIMM installed!"); |
| 313 | printk(BIOS_DEBUG, "ECC is %s\n", ctrl->ecc_enabled ? "enabled" : "disabled"); |
| 314 | |
| 315 | ctrl->lanes = ctrl->ecc_enabled ? 9 : 8; |
| 316 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 317 | if (!dimms) |
| 318 | die("No DIMMs were found"); |
| 319 | } |
| 320 | |
Patrick Rudolph | bb9c90a | 2016-05-29 17:05:06 +0200 | [diff] [blame] | 321 | static void save_timings(ramctr_timing *ctrl) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 322 | { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 323 | /* Save the MRC S3 restore data to cbmem */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 324 | mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, ctrl, sizeof(*ctrl)); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Angel Pons | fc93024 | 2020-03-24 11:12:09 +0100 | [diff] [blame] | 327 | static void reinit_ctrl(ramctr_timing *ctrl, const u32 cpuid) |
Patrick Rudolph | 05d4bf7e | 2017-10-28 16:36:09 +0200 | [diff] [blame] | 328 | { |
| 329 | /* Reset internal state */ |
| 330 | memset(ctrl, 0, sizeof(*ctrl)); |
Patrick Rudolph | 05d4bf7e | 2017-10-28 16:36:09 +0200 | [diff] [blame] | 331 | |
| 332 | /* Get architecture */ |
| 333 | ctrl->cpu = cpuid; |
| 334 | |
| 335 | /* Get ECC support and mode */ |
| 336 | ctrl->ecc_forced = get_host_ecc_forced(); |
| 337 | ctrl->ecc_supported = ctrl->ecc_forced || get_host_ecc_cap(); |
| 338 | printk(BIOS_DEBUG, "ECC supported: %s ECC forced: %s\n", |
| 339 | ctrl->ecc_supported ? "yes" : "no", |
| 340 | ctrl->ecc_forced ? "yes" : "no"); |
| 341 | } |
| 342 | |
Angel Pons | fc93024 | 2020-03-24 11:12:09 +0100 | [diff] [blame] | 343 | static void init_dram_ddr3(int s3resume, const u32 cpuid) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 344 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 345 | int me_uma_size, cbmem_was_inited, fast_boot, err; |
Patrick Rudolph | 735ecce | 2016-03-26 10:42:27 +0100 | [diff] [blame] | 346 | ramctr_timing ctrl; |
Kyösti Mälkki | 4cb44e5 | 2016-11-18 19:11:24 +0200 | [diff] [blame] | 347 | spd_raw_data spds[4]; |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 348 | size_t mrc_size; |
Angel Pons | a6a6418 | 2020-03-21 18:06:03 +0100 | [diff] [blame] | 349 | ramctr_timing *ctrl_cached = NULL; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 350 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 351 | timestamp_add_now(TS_INITRAM_START); |
Kyösti Mälkki | b33c6fb | 2021-02-17 20:43:04 +0200 | [diff] [blame] | 352 | |
Angel Pons | 66780a0 | 2021-03-26 13:33:22 +0100 | [diff] [blame] | 353 | mchbar_setbits32(SAPMCTL, 1 << 0); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 354 | |
| 355 | /* Wait for ME to be ready */ |
| 356 | intel_early_me_init(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 357 | me_uma_size = intel_early_me_uma_size(); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 358 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 359 | printk(BIOS_DEBUG, "Starting native Platform init\n"); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 360 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 361 | wait_txt_clear(); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 362 | |
Angel Pons | 5db1b15 | 2020-12-13 16:37:53 +0100 | [diff] [blame] | 363 | wrmsr(0x2e6, (msr_t) { .lo = 0, .hi = 0 }); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 364 | |
Angel Pons | 66780a0 | 2021-03-26 13:33:22 +0100 | [diff] [blame] | 365 | const u32 sskpd = mchbar_read32(SSKPD); // !!! = 0x00000000 |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 366 | if ((pci_read_config16(SOUTHBRIDGE, 0xa2) & 0xa0) == 0x20 && sskpd && !s3resume) { |
Angel Pons | 66780a0 | 2021-03-26 13:33:22 +0100 | [diff] [blame] | 367 | mchbar_write32(SSKPD, 0); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 368 | /* Need reset */ |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 369 | system_reset(); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 370 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 371 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 372 | early_pch_init_native(); |
Patrick Rudolph | 6aca7e6 | 2019-03-26 18:22:36 +0100 | [diff] [blame] | 373 | early_init_dmi(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 374 | early_thermal_init(); |
| 375 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 376 | /* Try to find timings in MRC cache */ |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 377 | ctrl_cached = mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, |
| 378 | MRC_CACHE_VERSION, |
| 379 | &mrc_size); |
| 380 | if (mrc_size < sizeof(ctrl)) |
| 381 | ctrl_cached = NULL; |
Angel Pons | a6a6418 | 2020-03-21 18:06:03 +0100 | [diff] [blame] | 382 | |
| 383 | /* Before reusing training data, assert that the CPU has not been replaced */ |
| 384 | if (ctrl_cached && cpuid != ctrl_cached->cpu) { |
| 385 | |
| 386 | /* It is not really worrying on a cold boot, but fatal when resuming from S3 */ |
| 387 | printk(s3resume ? BIOS_ALERT : BIOS_NOTICE, |
| 388 | "CPUID %x differs from stored CPUID %x, CPU was replaced!\n", |
| 389 | cpuid, ctrl_cached->cpu); |
| 390 | |
| 391 | /* Invalidate the stored data, it likely does not apply to the current CPU */ |
| 392 | ctrl_cached = NULL; |
| 393 | } |
| 394 | |
| 395 | if (s3resume && !ctrl_cached) { |
| 396 | /* S3 resume is impossible, reset to come up cleanly */ |
| 397 | system_reset(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 400 | /* Verify MRC cache for fast boot */ |
Kyösti Mälkki | 38cb822 | 2016-11-18 19:25:52 +0200 | [diff] [blame] | 401 | if (!s3resume && ctrl_cached) { |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 402 | /* Load SPD unique information data. */ |
| 403 | memset(spds, 0, sizeof(spds)); |
| 404 | mainboard_get_spd(spds, 1); |
| 405 | |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 406 | /* check SPD CRC16 to make sure the DIMMs haven't been replaced */ |
| 407 | fast_boot = verify_crc16_spds_ddr3(spds, ctrl_cached); |
| 408 | if (!fast_boot) |
| 409 | printk(BIOS_DEBUG, "Stored timings CRC16 mismatch.\n"); |
Kyösti Mälkki | 38cb822 | 2016-11-18 19:25:52 +0200 | [diff] [blame] | 410 | } else { |
| 411 | fast_boot = s3resume; |
| 412 | } |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 413 | |
| 414 | if (fast_boot) { |
| 415 | printk(BIOS_DEBUG, "Trying stored timings.\n"); |
| 416 | memcpy(&ctrl, ctrl_cached, sizeof(ctrl)); |
| 417 | |
Patrick Rudolph | 588ccaa | 2016-04-20 18:00:27 +0200 | [diff] [blame] | 418 | err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 419 | if (err) { |
Patrick Rudolph | 588ccaa | 2016-04-20 18:00:27 +0200 | [diff] [blame] | 420 | if (s3resume) { |
| 421 | /* Failed S3 resume, reset to come up cleanly */ |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 422 | system_reset(); |
Patrick Rudolph | 588ccaa | 2016-04-20 18:00:27 +0200 | [diff] [blame] | 423 | } |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 424 | /* No need to erase bad MRC cache here, it gets overwritten on a |
| 425 | successful boot */ |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 426 | printk(BIOS_ERR, "Stored timings are invalid !\n"); |
| 427 | fast_boot = 0; |
| 428 | } |
| 429 | } |
| 430 | if (!fast_boot) { |
Patrick Rudolph | e74ad21 | 2016-11-16 18:06:50 +0100 | [diff] [blame] | 431 | /* Reset internal state */ |
Angel Pons | fc93024 | 2020-03-24 11:12:09 +0100 | [diff] [blame] | 432 | reinit_ctrl(&ctrl, cpuid); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 433 | |
Patrick Rudolph | 05d4bf7e | 2017-10-28 16:36:09 +0200 | [diff] [blame] | 434 | printk(BIOS_INFO, "ECC RAM %s.\n", ctrl.ecc_forced ? "required" : |
| 435 | ctrl.ecc_supported ? "supported" : "unsupported"); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 436 | |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 437 | /* Get DDR3 SPD data */ |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 438 | memset(spds, 0, sizeof(spds)); |
| 439 | mainboard_get_spd(spds, 0); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 440 | dram_find_spds_ddr3(spds, &ctrl); |
| 441 | |
Patrick Rudolph | 588ccaa | 2016-04-20 18:00:27 +0200 | [diff] [blame] | 442 | err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 443 | } |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 444 | |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 445 | if (err) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 446 | /* Fallback: disable failing channel */ |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 447 | printk(BIOS_ERR, "RAM training failed, trying fallback.\n"); |
| 448 | printram("Disable failing channel.\n"); |
| 449 | |
Patrick Rudolph | e74ad21 | 2016-11-16 18:06:50 +0100 | [diff] [blame] | 450 | /* Reset internal state */ |
Angel Pons | fc93024 | 2020-03-24 11:12:09 +0100 | [diff] [blame] | 451 | reinit_ctrl(&ctrl, cpuid); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 452 | |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 453 | /* Reset DDR3 frequency */ |
| 454 | dram_find_spds_ddr3(spds, &ctrl); |
| 455 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 456 | /* Disable failing channel */ |
Patrick Rudolph | 2ccb74b | 2016-03-26 12:16:29 +0100 | [diff] [blame] | 457 | disable_channel(&ctrl, GET_ERR_CHANNEL(err)); |
| 458 | |
| 459 | err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size); |
| 460 | } |
| 461 | |
Patrick Rudolph | 31d1959 | 2016-03-26 12:22:34 +0100 | [diff] [blame] | 462 | if (err) |
| 463 | die("raminit failed"); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 464 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 465 | /* FIXME: should be hardware revision-dependent. The register only exists on IVB. */ |
Angel Pons | 66780a0 | 2021-03-26 13:33:22 +0100 | [diff] [blame] | 466 | mchbar_write32(CHANNEL_HASH, 0x00a030ce); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 467 | |
| 468 | set_scrambling_seed(&ctrl); |
| 469 | |
Patrick Rudolph | d058131 | 2020-05-01 18:31:48 +0200 | [diff] [blame] | 470 | if (!s3resume && ctrl.ecc_enabled) |
| 471 | channel_scrub(&ctrl); |
| 472 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 473 | set_normal_operation(&ctrl); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 474 | |
| 475 | final_registers(&ctrl); |
| 476 | |
Patrick Rudolph | d058131 | 2020-05-01 18:31:48 +0200 | [diff] [blame] | 477 | /* can't do this earlier because it needs to be done in normal operation */ |
| 478 | if (CONFIG(DEBUG_RAM_SETUP) && !s3resume && ctrl.ecc_enabled) { |
| 479 | uint32_t i, tseg = pci_read_config32(HOST_BRIDGE, TSEGMB); |
| 480 | |
| 481 | printk(BIOS_INFO, "RAMINIT: ECC scrub test on first channel up to 0x%x\n", |
| 482 | tseg); |
| 483 | |
| 484 | /* |
| 485 | * This test helps to debug the ECC scrubbing. |
| 486 | * It likely tests every channel/rank, as rank interleave and enhanced |
| 487 | * interleave are enabled, but there's no guarantee for it. |
| 488 | */ |
| 489 | |
| 490 | /* Skip first MB to avoid special case for A-seg and test up to TSEG */ |
| 491 | for (i = 1; i < tseg >> 20; i++) { |
| 492 | for (int j = 0; j < 1 * MiB; j += 4096) { |
| 493 | uintptr_t addr = i * MiB + j; |
| 494 | if (read32((u32 *)addr) == 0) |
| 495 | continue; |
| 496 | |
| 497 | printk(BIOS_ERR, "RAMINIT: ECC scrub: DRAM not cleared at" |
| 498 | " addr 0x%lx\n", addr); |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | printk(BIOS_INFO, "RAMINIT: ECC scrub test done.\n"); |
| 503 | } |
| 504 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 505 | /* Zone config */ |
| 506 | dram_zones(&ctrl, 0); |
| 507 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 508 | intel_early_me_init_done(ME_INIT_STATUS_SUCCESS); |
| 509 | intel_early_me_status(); |
| 510 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 511 | report_memory_config(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 512 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 513 | timestamp_add_now(TS_INITRAM_END); |
Kyösti Mälkki | b33c6fb | 2021-02-17 20:43:04 +0200 | [diff] [blame] | 514 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 515 | cbmem_was_inited = !cbmem_recovery(s3resume); |
Patrick Rudolph | 56abd4d | 2016-03-13 11:07:45 +0100 | [diff] [blame] | 516 | if (!fast_boot) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 517 | save_timings(&ctrl); |
| 518 | if (s3resume && !cbmem_was_inited) { |
| 519 | /* Failed S3 resume, reset to come up cleanly */ |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 520 | system_reset(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 521 | } |
Patrick Rudolph | b97009e | 2016-02-28 15:24:04 +0100 | [diff] [blame] | 522 | |
Nico Huber | 9ce5974 | 2018-09-13 10:52:44 +0200 | [diff] [blame] | 523 | if (!s3resume) |
Patrick Rudolph | 42609d8 | 2020-07-27 16:23:36 +0200 | [diff] [blame] | 524 | setup_sdram_meminfo(&ctrl); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 525 | } |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 526 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 527 | void perform_raminit(int s3resume) |
| 528 | { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 529 | post_code(0x3a); |
Angel Pons | fc93024 | 2020-03-24 11:12:09 +0100 | [diff] [blame] | 530 | init_dram_ddr3(s3resume, cpu_get_cpuid()); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 531 | } |