blob: b096a11bf2bb211585c191c06b5ac0eac142b591 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauer00636b02012-04-04 00:08:51 +02003
4#include <console/console.h>
Arthur Heymans7539b8c2017-12-24 10:42:57 +01005#include <commonlib/region.h>
Kyösti Mälkki5687fc92013-11-28 18:11:49 +02006#include <bootmode.h>
Elyes HAOUASc0567292019-04-28 17:57:47 +02007#include <cf9_reset.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02008#include <string.h>
Subrata Banik53b08c32018-12-10 14:11:35 +05309#include <arch/cpu.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020010#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020012#include <device/smbus_host.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020013#include <cbmem.h>
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010014#include <timestamp.h>
Arthur Heymans7539b8c2017-12-24 10:42:57 +010015#include <mrc_cache.h>
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010016#include <southbridge/intel/bd82x6x/me.h>
Patrick Rudolphda9302a2019-03-24 17:01:41 +010017#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010018#include <cpu/x86/msr.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020019#include <types.h>
Elyes HAOUASbf0970e2019-03-21 11:10:03 +010020
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010021#include "raminit_native.h"
22#include "raminit_common.h"
23#include "sandybridge.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020024
Angel Pons7c49cb82020-03-16 23:17:32 +010025/* FIXME: no ECC support */
26/* FIXME: no support for 3-channel chipsets */
Stefan Reinauer00636b02012-04-04 00:08:51 +020027
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070028static void wait_txt_clear(void)
29{
Angel Pons7c49cb82020-03-16 23:17:32 +010030 struct cpuid_result cp = cpuid_ext(1, 0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070031
Angel Pons7c49cb82020-03-16 23:17:32 +010032 /* Check if TXT is supported */
33 if (!(cp.ecx & (1 << 6)))
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070034 return;
Angel Pons7c49cb82020-03-16 23:17:32 +010035
36 /* Some TXT public bit */
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070037 if (!(read32((void *)0xfed30010) & 1))
38 return;
Angel Pons7c49cb82020-03-16 23:17:32 +010039
40 /* Wait for TXT clear */
41 while (!(read8((void *)0xfed40000) & (1 << 7)))
42 ;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070043}
44
Angel Pons7c49cb82020-03-16 23:17:32 +010045/* Disable a channel in ramctr_timing */
46static void disable_channel(ramctr_timing *ctrl, int channel)
47{
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +010048 ctrl->rankmap[channel] = 0;
Angel Pons7c49cb82020-03-16 23:17:32 +010049
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +010050 memset(&ctrl->rank_mirror[channel][0], 0, sizeof(ctrl->rank_mirror[0]));
Angel Pons7c49cb82020-03-16 23:17:32 +010051
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +010052 ctrl->channel_size_mb[channel] = 0;
Angel Pons7c49cb82020-03-16 23:17:32 +010053 ctrl->cmd_stretch[channel] = 0;
54 ctrl->mad_dimm[channel] = 0;
55 memset(&ctrl->timings[channel][0], 0, sizeof(ctrl->timings[0]));
Patrick Rudolph74163d62016-11-17 20:02:43 +010056 memset(&ctrl->info.dimm[channel][0], 0, sizeof(ctrl->info.dimm[0]));
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +010057}
58
Angel Pons7c49cb82020-03-16 23:17:32 +010059/* Fill cbmem with information for SMBIOS type 17 */
Patrick Rudolph735ecce2016-03-26 10:42:27 +010060static void fill_smbios17(ramctr_timing *ctrl)
Patrick Rudolphb97009e2016-02-28 15:24:04 +010061{
Patrick Rudolphb97009e2016-02-28 15:24:04 +010062 int channel, slot;
Patrick Rudolph24efe732018-08-19 11:06:06 +020063 const u16 ddr_freq = (1000 << 8) / ctrl->tCK;
Patrick Rudolphb97009e2016-02-28 15:24:04 +010064
Elyes HAOUAS12df9502016-08-23 21:29:48 +020065 FOR_ALL_CHANNELS for (slot = 0; slot < NUM_SLOTS; slot++) {
Patrick Rudolph24efe732018-08-19 11:06:06 +020066 enum cb_err ret = spd_add_smbios17(channel, slot, ddr_freq,
67 &ctrl->info.dimm[channel][slot]);
68 if (ret != CB_SUCCESS)
69 printk(BIOS_ERR, "RAMINIT: Failed to add SMBIOS17\n");
Patrick Rudolphb97009e2016-02-28 15:24:04 +010070 }
71}
72
Angel Pons7c49cb82020-03-16 23:17:32 +010073/* Return CRC16 match for all SPDs */
Patrick Rudolph56abd4d2016-03-13 11:07:45 +010074static int verify_crc16_spds_ddr3(spd_raw_data *spd, ramctr_timing *ctrl)
75{
76 int channel, slot, spd_slot;
77 int match = 1;
78
79 FOR_ALL_CHANNELS {
80 for (slot = 0; slot < NUM_SLOTS; slot++) {
81 spd_slot = 2 * channel + slot;
82 match &= ctrl->spd_crc[channel][slot] ==
Angel Pons7c49cb82020-03-16 23:17:32 +010083 spd_ddr3_calc_unique_crc(spd[spd_slot], sizeof(spd_raw_data));
Patrick Rudolph56abd4d2016-03-13 11:07:45 +010084 }
85 }
86 return match;
87}
88
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +020089void read_spd(spd_raw_data * spd, u8 addr, bool id_only)
Stefan Reinauer00636b02012-04-04 00:08:51 +020090{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070091 int j;
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +020092 if (id_only) {
93 for (j = 117; j < 128; j++)
94 (*spd)[j] = do_smbus_read_byte(SMBUS_IO_BASE, addr, j);
95 } else {
96 for (j = 0; j < 256; j++)
97 (*spd)[j] = do_smbus_read_byte(SMBUS_IO_BASE, addr, j);
98 }
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070099}
100
Patrick Rudolph735ecce2016-03-26 10:42:27 +0100101static void dram_find_spds_ddr3(spd_raw_data *spd, ramctr_timing *ctrl)
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700102{
Angel Pons7c49cb82020-03-16 23:17:32 +0100103 int dimms = 0, ch_dimms;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700104 int channel, slot, spd_slot;
Patrick Rudolph735ecce2016-03-26 10:42:27 +0100105 dimm_info *dimm = &ctrl->info;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700106
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200107 memset (ctrl->rankmap, 0, sizeof(ctrl->rankmap));
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700108
109 ctrl->extended_temperature_range = 1;
110 ctrl->auto_self_refresh = 1;
111
112 FOR_ALL_CHANNELS {
113 ctrl->channel_size_mb[channel] = 0;
114
Angel Pons7c49cb82020-03-16 23:17:32 +0100115 ch_dimms = 0;
116 /* Count dimms on channel */
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700117 for (slot = 0; slot < NUM_SLOTS; slot++) {
118 spd_slot = 2 * channel + slot;
Angel Pons7c49cb82020-03-16 23:17:32 +0100119 printk(BIOS_DEBUG, "SPD probe channel%d, slot%d\n", channel, slot);
Patrick Rudolph5a061852017-09-22 15:19:26 +0200120
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700121 spd_decode_ddr3(&dimm->dimm[channel][slot], spd[spd_slot]);
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100122 if (dimm->dimm[channel][slot].dram_type == SPD_MEMORY_TYPE_SDRAM_DDR3)
Angel Pons7c49cb82020-03-16 23:17:32 +0100123 ch_dimms++;
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100124 }
125
126 for (slot = 0; slot < NUM_SLOTS; slot++) {
127 spd_slot = 2 * channel + slot;
Angel Pons7c49cb82020-03-16 23:17:32 +0100128 printk(BIOS_DEBUG, "SPD probe channel%d, slot%d\n", channel, slot);
Patrick Rudolph5a061852017-09-22 15:19:26 +0200129
Angel Pons7c49cb82020-03-16 23:17:32 +0100130 /* Search for XMP profile */
131 spd_xmp_decode_ddr3(&dimm->dimm[channel][slot], spd[spd_slot],
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100132 DDR3_XMP_PROFILE_1);
133
134 if (dimm->dimm[channel][slot].dram_type != SPD_MEMORY_TYPE_SDRAM_DDR3) {
135 printram("No valid XMP profile found.\n");
136 spd_decode_ddr3(&dimm->dimm[channel][slot], spd[spd_slot]);
Angel Pons7c49cb82020-03-16 23:17:32 +0100137
138 } else if (ch_dimms > dimm->dimm[channel][slot].dimms_per_channel) {
139 printram(
140 "XMP profile supports %u DIMMs, but %u DIMMs are installed.\n",
141 dimm->dimm[channel][slot].dimms_per_channel, ch_dimms);
142
Julius Wernercd49cce2019-03-05 16:53:33 -0800143 if (CONFIG(NATIVE_RAMINIT_IGNORE_XMP_MAX_DIMMS))
Angel Pons7c49cb82020-03-16 23:17:32 +0100144 printk(BIOS_WARNING,
145 "XMP maximum DIMMs will be ignored.\n");
Vagiz Trakhanov771be482017-10-02 10:02:35 +0000146 else
Angel Pons7c49cb82020-03-16 23:17:32 +0100147 spd_decode_ddr3(&dimm->dimm[channel][slot],
148 spd[spd_slot]);
149
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100150 } else if (dimm->dimm[channel][slot].voltage != 1500) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100151 /* TODO: Support DDR3 voltages other than 1500mV */
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100152 printram("XMP profile's requested %u mV is unsupported.\n",
153 dimm->dimm[channel][slot].voltage);
154 spd_decode_ddr3(&dimm->dimm[channel][slot], spd[spd_slot]);
155 }
156
Angel Pons7c49cb82020-03-16 23:17:32 +0100157 /* Fill in CRC16 for MRC cache */
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100158 ctrl->spd_crc[channel][slot] =
Angel Pons7c49cb82020-03-16 23:17:32 +0100159 spd_ddr3_calc_unique_crc(spd[spd_slot], sizeof(spd_raw_data));
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100160
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700161 if (dimm->dimm[channel][slot].dram_type != SPD_MEMORY_TYPE_SDRAM_DDR3) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100162 /* Mark DIMM as invalid */
163 dimm->dimm[channel][slot].ranks = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700164 dimm->dimm[channel][slot].size_mb = 0;
165 continue;
166 }
167
168 dram_print_spd_ddr3(&dimm->dimm[channel][slot]);
169 dimms++;
170 ctrl->rank_mirror[channel][slot * 2] = 0;
Angel Pons7c49cb82020-03-16 23:17:32 +0100171 ctrl->rank_mirror[channel][slot * 2 + 1] =
172 dimm->dimm[channel][slot].flags.pins_mirrored;
173
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700174 ctrl->channel_size_mb[channel] += dimm->dimm[channel][slot].size_mb;
175
176 ctrl->auto_self_refresh &= dimm->dimm[channel][slot].flags.asr;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700177
Angel Pons7c49cb82020-03-16 23:17:32 +0100178 ctrl->extended_temperature_range &=
179 dimm->dimm[channel][slot].flags.ext_temp_refresh;
180
181 ctrl->rankmap[channel] |=
182 ((1 << dimm->dimm[channel][slot].ranks) - 1) << (2 * slot);
183
184 printk(BIOS_DEBUG, "channel[%d] rankmap = 0x%x\n", channel,
185 ctrl->rankmap[channel]);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700186 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100187 if ((ctrl->rankmap[channel] & 0x03) && (ctrl->rankmap[channel] & 0x0c)
188 && dimm->dimm[channel][0].reference_card <= 5
189 && dimm->dimm[channel][1].reference_card <= 5) {
190
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700191 const int ref_card_offset_table[6][6] = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100192 { 0, 0, 0, 0, 2, 2 },
193 { 0, 0, 0, 0, 2, 2 },
194 { 0, 0, 0, 0, 2, 2 },
195 { 0, 0, 0, 0, 1, 1 },
196 { 2, 2, 2, 1, 0, 0 },
197 { 2, 2, 2, 1, 0, 0 },
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700198 };
Angel Pons7c49cb82020-03-16 23:17:32 +0100199 ctrl->ref_card_offset[channel] = ref_card_offset_table
200 [dimm->dimm[channel][0].reference_card]
201 [dimm->dimm[channel][1].reference_card];
202 } else {
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700203 ctrl->ref_card_offset[channel] = 0;
Angel Pons7c49cb82020-03-16 23:17:32 +0100204 }
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700205 }
206
207 if (!dimms)
208 die("No DIMMs were found");
209}
210
Patrick Rudolphbb9c90a2016-05-29 17:05:06 +0200211static void save_timings(ramctr_timing *ctrl)
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700212{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700213 /* Save the MRC S3 restore data to cbmem */
Angel Pons7c49cb82020-03-16 23:17:32 +0100214 mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, ctrl, sizeof(*ctrl));
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700215}
216
Angel Pons80037f72020-03-21 13:12:37 +0100217static void init_dram_ddr3(int min_tck, int s3resume, const u32 cpuid)
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700218{
Angel Pons7c49cb82020-03-16 23:17:32 +0100219 int me_uma_size, cbmem_was_inited, fast_boot, err;
Patrick Rudolph735ecce2016-03-26 10:42:27 +0100220 ramctr_timing ctrl;
Kyösti Mälkki4cb44e52016-11-18 19:11:24 +0200221 spd_raw_data spds[4];
Arthur Heymans7539b8c2017-12-24 10:42:57 +0100222 struct region_device rdev;
Angel Ponsa6a64182020-03-21 18:06:03 +0100223 ramctr_timing *ctrl_cached = NULL;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700224
Angel Pons88521882020-01-05 20:21:20 +0100225 MCHBAR32(SAPMCTL) |= 1;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200226
227 /* Wait for ME to be ready */
228 intel_early_me_init();
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700229 me_uma_size = intel_early_me_uma_size();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200230
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700231 printk(BIOS_DEBUG, "Starting native Platform init\n");
Stefan Reinauer00636b02012-04-04 00:08:51 +0200232
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700233 wait_txt_clear();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200234
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700235 wrmsr(0x000002e6, (msr_t) { .lo = 0, .hi = 0 });
Stefan Reinauer00636b02012-04-04 00:08:51 +0200236
Angel Pons7c49cb82020-03-16 23:17:32 +0100237 const u32 sskpd = MCHBAR32(SSKPD); // !!! = 0x00000000
238 if ((pci_read_config16(SOUTHBRIDGE, 0xa2) & 0xa0) == 0x20 && sskpd && !s3resume) {
239 MCHBAR32(SSKPD) = 0;
240 /* Need reset */
Elyes HAOUASc0567292019-04-28 17:57:47 +0200241 system_reset();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200242 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200243
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700244 early_pch_init_native();
Patrick Rudolph6aca7e62019-03-26 18:22:36 +0100245 early_init_dmi();
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700246 early_thermal_init();
247
Angel Pons7c49cb82020-03-16 23:17:32 +0100248 /* Try to find timings in MRC cache */
249 err = mrc_cache_get_current(MRC_TRAINING_DATA, MRC_CACHE_VERSION, &rdev);
Angel Ponsa6a64182020-03-21 18:06:03 +0100250
251 if (!err && !(region_device_sz(&rdev) < sizeof(ctrl)))
Arthur Heymans7539b8c2017-12-24 10:42:57 +0100252 ctrl_cached = rdev_mmap_full(&rdev);
Angel Ponsa6a64182020-03-21 18:06:03 +0100253
254 /* Before reusing training data, assert that the CPU has not been replaced */
255 if (ctrl_cached && cpuid != ctrl_cached->cpu) {
256
257 /* It is not really worrying on a cold boot, but fatal when resuming from S3 */
258 printk(s3resume ? BIOS_ALERT : BIOS_NOTICE,
259 "CPUID %x differs from stored CPUID %x, CPU was replaced!\n",
260 cpuid, ctrl_cached->cpu);
261
262 /* Invalidate the stored data, it likely does not apply to the current CPU */
263 ctrl_cached = NULL;
264 }
265
266 if (s3resume && !ctrl_cached) {
267 /* S3 resume is impossible, reset to come up cleanly */
268 system_reset();
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700269 }
270
Angel Pons7c49cb82020-03-16 23:17:32 +0100271 /* Verify MRC cache for fast boot */
Kyösti Mälkki38cb8222016-11-18 19:25:52 +0200272 if (!s3resume && ctrl_cached) {
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +0200273 /* Load SPD unique information data. */
274 memset(spds, 0, sizeof(spds));
275 mainboard_get_spd(spds, 1);
276
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100277 /* check SPD CRC16 to make sure the DIMMs haven't been replaced */
278 fast_boot = verify_crc16_spds_ddr3(spds, ctrl_cached);
279 if (!fast_boot)
280 printk(BIOS_DEBUG, "Stored timings CRC16 mismatch.\n");
Kyösti Mälkki38cb8222016-11-18 19:25:52 +0200281 } else {
282 fast_boot = s3resume;
283 }
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100284
285 if (fast_boot) {
286 printk(BIOS_DEBUG, "Trying stored timings.\n");
287 memcpy(&ctrl, ctrl_cached, sizeof(ctrl));
288
Patrick Rudolph588ccaa2016-04-20 18:00:27 +0200289 err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size);
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100290 if (err) {
Patrick Rudolph588ccaa2016-04-20 18:00:27 +0200291 if (s3resume) {
292 /* Failed S3 resume, reset to come up cleanly */
Elyes HAOUASc0567292019-04-28 17:57:47 +0200293 system_reset();
Patrick Rudolph588ccaa2016-04-20 18:00:27 +0200294 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100295 /* No need to erase bad MRC cache here, it gets overwritten on a
296 successful boot */
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100297 printk(BIOS_ERR, "Stored timings are invalid !\n");
298 fast_boot = 0;
299 }
300 }
301 if (!fast_boot) {
Patrick Rudolphe74ad212016-11-16 18:06:50 +0100302 /* Reset internal state */
303 memset(&ctrl, 0, sizeof(ctrl));
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100304 ctrl.tCK = min_tck;
305
Patrick Rudolph305035c2016-11-11 18:38:50 +0100306 /* Get architecture */
Angel Pons80037f72020-03-21 13:12:37 +0100307 ctrl.cpu = cpuid;
Patrick Rudolph305035c2016-11-11 18:38:50 +0100308
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100309 /* Get DDR3 SPD data */
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +0200310 memset(spds, 0, sizeof(spds));
311 mainboard_get_spd(spds, 0);
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100312 dram_find_spds_ddr3(spds, &ctrl);
313
Patrick Rudolph588ccaa2016-04-20 18:00:27 +0200314 err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size);
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100315 }
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +0100316
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +0100317 if (err) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100318 /* Fallback: disable failing channel */
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +0100319 printk(BIOS_ERR, "RAM training failed, trying fallback.\n");
320 printram("Disable failing channel.\n");
321
Patrick Rudolphe74ad212016-11-16 18:06:50 +0100322 /* Reset internal state */
323 memset(&ctrl, 0, sizeof(ctrl));
Patrick Rudolphe74ad212016-11-16 18:06:50 +0100324 ctrl.tCK = min_tck;
325
Patrick Rudolph305035c2016-11-11 18:38:50 +0100326 /* Get architecture */
Angel Pons80037f72020-03-21 13:12:37 +0100327 ctrl.cpu = cpuid;
Patrick Rudolph305035c2016-11-11 18:38:50 +0100328
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +0100329 /* Reset DDR3 frequency */
330 dram_find_spds_ddr3(spds, &ctrl);
331
Angel Pons7c49cb82020-03-16 23:17:32 +0100332 /* Disable failing channel */
Patrick Rudolph2ccb74b2016-03-26 12:16:29 +0100333 disable_channel(&ctrl, GET_ERR_CHANNEL(err));
334
335 err = try_init_dram_ddr3(&ctrl, fast_boot, s3resume, me_uma_size);
336 }
337
Patrick Rudolph31d19592016-03-26 12:22:34 +0100338 if (err)
339 die("raminit failed");
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700340
Angel Pons88521882020-01-05 20:21:20 +0100341 /* FIXME: should be hardware revision-dependent. The register only exists on IVB. */
342 MCHBAR32(CHANNEL_HASH) = 0x00a030ce;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700343
344 set_scrambling_seed(&ctrl);
345
Angel Pons88521882020-01-05 20:21:20 +0100346 set_normal_operation(&ctrl);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700347
348 final_registers(&ctrl);
349
350 /* Zone config */
351 dram_zones(&ctrl, 0);
352
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700353 intel_early_me_status();
354 intel_early_me_init_done(ME_INIT_STATUS_SUCCESS);
355 intel_early_me_status();
356
Stefan Reinauer00636b02012-04-04 00:08:51 +0200357 report_memory_config();
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700358
359 cbmem_was_inited = !cbmem_recovery(s3resume);
Patrick Rudolph56abd4d2016-03-13 11:07:45 +0100360 if (!fast_boot)
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700361 save_timings(&ctrl);
362 if (s3resume && !cbmem_was_inited) {
363 /* Failed S3 resume, reset to come up cleanly */
Elyes HAOUASc0567292019-04-28 17:57:47 +0200364 system_reset();
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700365 }
Patrick Rudolphb97009e2016-02-28 15:24:04 +0100366
Nico Huber9ce59742018-09-13 10:52:44 +0200367 if (!s3resume)
368 fill_smbios17(&ctrl);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200369}
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100370
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100371void perform_raminit(int s3resume)
372{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100373 post_code(0x3a);
374
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100375 timestamp_add_now(TS_BEFORE_INITRAM);
376
Angel Pons80037f72020-03-21 13:12:37 +0100377 init_dram_ddr3(get_mem_min_tck(), s3resume, cpu_get_cpuid());
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100378}