| 1 |
|
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <delay.h> |
| 6 |
#include <northbridge/intel/haswell/haswell.h> |
| 7 |
#include <types.h> |
| 8 |
|
| 9 |
#include "raminit_native.h" |
| 10 |
|
| 11 |
#define DDR3_RTTNOM(a, b, c) (((a) << 9) | ((b) << 6) | ((c) << 2)) |
| 12 |
|
| 13 |
uint16_t encode_ddr3_rttnom(const uint32_t rttnom) |
| 14 |
{ |
| 15 |
switch (rttnom) { |
| 16 |
case 0: return DDR3_RTTNOM(0, 0, 0); |
| 17 |
case 20: return DDR3_RTTNOM(1, 0, 0); |
| 18 |
case 30: return DDR3_RTTNOM(1, 0, 1); |
| 19 |
case 40: return DDR3_RTTNOM(0, 1, 1); |
| 20 |
case 60: return DDR3_RTTNOM(0, 0, 1); |
| 21 |
case 120: return DDR3_RTTNOM(0, 1, 0); |
| 22 |
} |
| 23 |
printk(BIOS_ERR, "%s: Invalid rtt_nom value %u\n", __func__, rttnom); |
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
static const uint8_t jedec_wr_t[12] = { 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0 }; |
| 28 |
|
| 29 |
static void ddr3_program_mr0(struct sysinfo *ctrl, const uint8_t dll_reset) |
| 30 |
{ |
| 31 |
assert(ctrl->tWR >= 5 && ctrl->tWR <= 16); |
| 32 |
assert(ctrl->tAA >= 4); |
| 33 |
const uint8_t jedec_cas = ctrl->tAA - 4; |
| 34 |
const union { |
| 35 |
struct __packed { |
| 36 |
uint16_t burst_length : 2; |
| 37 |
uint16_t cas_latency_msb : 1; |
| 38 |
uint16_t read_burst_type : 1; |
| 39 |
uint16_t cas_latency_low : 3; |
| 40 |
uint16_t test_mode : 1; |
| 41 |
uint16_t dll_reset : 1; |
| 42 |
uint16_t write_recovery : 3; |
| 43 |
uint16_t precharge_pd_dll : 1; |
| 44 |
uint16_t : 3; |
| 45 |
}; |
| 46 |
uint16_t raw; |
| 47 |
} mr0reg = { |
| 48 |
.burst_length = 0, |
| 49 |
.cas_latency_msb = !!(jedec_cas & BIT(3)), |
| 50 |
.read_burst_type = 0, |
| 51 |
.cas_latency_low = jedec_cas & 0x7, |
| 52 |
.dll_reset = 1, |
| 53 |
.write_recovery = jedec_wr_t[ctrl->tWR - 5], |
| 54 |
.precharge_pd_dll = 0, |
| 55 |
}; |
| 56 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 57 |
if (!does_ch_exist(ctrl, channel)) |
| 58 |
continue; |
| 59 |
|
| 60 |
for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) { |
| 61 |
if (!rank_in_ch(ctrl, slot + slot, channel)) |
| 62 |
continue; |
| 63 |
|
| 64 |
if (!ctrl->restore_mrs) |
| 65 |
ctrl->mr0[channel][slot] = mr0reg.raw; |
| 66 |
} |
| 67 |
reut_issue_mrs_all(ctrl, channel, 0, ctrl->mr0[channel]); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
void ddr3_program_mr1(struct sysinfo *ctrl, const uint8_t wl_mode, const uint8_t q_off) |
| 72 |
{ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
union { |
| 81 |
struct __packed { |
| 82 |
uint16_t dll_disable : 1; |
| 83 |
uint16_t od_impedance_ctl : 1; |
| 84 |
uint16_t odt_rtt_nom_low : 1; |
| 85 |
uint16_t additive_latency : 2; |
| 86 |
uint16_t : 1; |
| 87 |
uint16_t odt_rtt_nom_mid : 1; |
| 88 |
uint16_t write_level_mode : 1; |
| 89 |
uint16_t : 1; |
| 90 |
uint16_t odt_rtt_nom_high : 1; |
| 91 |
uint16_t : 1; |
| 92 |
uint16_t t_dqs : 1; |
| 93 |
uint16_t q_off : 1; |
| 94 |
uint16_t : 3; |
| 95 |
}; |
| 96 |
uint16_t raw; |
| 97 |
} mr1reg = { |
| 98 |
.dll_disable = 0, |
| 99 |
.od_impedance_ctl = 1, |
| 100 |
.additive_latency = 0, |
| 101 |
.write_level_mode = wl_mode, |
| 102 |
.t_dqs = 0, |
| 103 |
.q_off = q_off, |
| 104 |
}; |
| 105 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 106 |
if (!does_ch_exist(ctrl, channel)) |
| 107 |
continue; |
| 108 |
|
| 109 |
mr1reg.raw &= ~RTTNOM_MASK; |
| 110 |
mr1reg.raw |= encode_ddr3_rttnom(ctrl->dpc[channel] == 2 ? 60 : 0); |
| 111 |
for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) { |
| 112 |
if (!rank_in_ch(ctrl, slot + slot, channel)) |
| 113 |
continue; |
| 114 |
|
| 115 |
if (!ctrl->restore_mrs) |
| 116 |
ctrl->mr1[channel][slot] = mr1reg.raw; |
| 117 |
} |
| 118 |
reut_issue_mrs_all(ctrl, channel, 1, ctrl->mr1[channel]); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
enum { |
| 123 |
RTT_WR_OFF = 0, |
| 124 |
RTT_WR_60 = 1, |
| 125 |
RTT_WR_120 = 2, |
| 126 |
}; |
| 127 |
|
| 128 |
static void ddr3_program_mr2(struct sysinfo *ctrl) |
| 129 |
{ |
| 130 |
assert(ctrl->tCWL >= 5); |
| 131 |
const bool dimm_srt = ctrl->flags.ext_temp_refresh && !ctrl->flags.asr; |
| 132 |
|
| 133 |
const union { |
| 134 |
struct __packed { |
| 135 |
uint16_t partial_array_sr : 3; |
| 136 |
uint16_t cas_write_latency : 3; |
| 137 |
uint16_t auto_self_refresh : 1; |
| 138 |
uint16_t self_refresh_temp : 1; |
| 139 |
uint16_t : 1; |
| 140 |
uint16_t odt_rtt_wr : 2; |
| 141 |
uint16_t : 5; |
| 142 |
}; |
| 143 |
uint16_t raw; |
| 144 |
} mr2reg = { |
| 145 |
.partial_array_sr = 0, |
| 146 |
.cas_write_latency = ctrl->tCWL - 5, |
| 147 |
.auto_self_refresh = ctrl->flags.asr, |
| 148 |
.self_refresh_temp = dimm_srt, |
| 149 |
.odt_rtt_wr = is_hsw_ult() ? RTT_WR_120 : RTT_WR_60, |
| 150 |
}; |
| 151 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 152 |
if (!does_ch_exist(ctrl, channel)) |
| 153 |
continue; |
| 154 |
|
| 155 |
for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) { |
| 156 |
if (!rank_in_ch(ctrl, slot + slot, channel)) |
| 157 |
continue; |
| 158 |
|
| 159 |
if (!ctrl->restore_mrs) |
| 160 |
ctrl->mr2[channel][slot] = mr2reg.raw; |
| 161 |
} |
| 162 |
|
| 163 |
if (!ctrl->restore_mrs) { |
| 164 |
union tc_mr2_shadow_reg tc_mr2_shadow = { |
| 165 |
.raw = mr2reg.raw & 0x073f, |
| 166 |
}; |
| 167 |
for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) { |
| 168 |
if (!rank_in_ch(ctrl, slot + slot, channel)) |
| 169 |
continue; |
| 170 |
|
| 171 |
if (dimm_srt) |
| 172 |
tc_mr2_shadow.srt_available |= BIT(slot); |
| 173 |
|
| 174 |
if (ctrl->rank_mirrored[channel] & BIT(slot + slot + 1)) |
| 175 |
tc_mr2_shadow.addr_bit_swizzle |= BIT(slot); |
| 176 |
} |
| 177 |
mchbar_write32(TC_MR2_SHADOW_ch(channel), tc_mr2_shadow.raw); |
| 178 |
} |
| 179 |
reut_issue_mrs_all(ctrl, channel, 2, ctrl->mr2[channel]); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
static void ddr3_program_mr3(struct sysinfo *ctrl, const uint8_t mpr_mode) |
| 184 |
{ |
| 185 |
const union { |
| 186 |
struct __packed { |
| 187 |
uint16_t mpr_loc : 2; |
| 188 |
uint16_t mpr_mode : 1; |
| 189 |
uint16_t : 13; |
| 190 |
}; |
| 191 |
uint16_t raw; |
| 192 |
} mr3reg = { |
| 193 |
.mpr_loc = 0, |
| 194 |
.mpr_mode = mpr_mode, |
| 195 |
}; |
| 196 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 197 |
if (!does_ch_exist(ctrl, channel)) |
| 198 |
continue; |
| 199 |
|
| 200 |
for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) { |
| 201 |
if (!rank_in_ch(ctrl, slot + slot, channel)) |
| 202 |
continue; |
| 203 |
|
| 204 |
if (!ctrl->restore_mrs) |
| 205 |
ctrl->mr3[channel][slot] = mr3reg.raw; |
| 206 |
} |
| 207 |
reut_issue_mrs_all(ctrl, channel, 3, ctrl->mr3[channel]); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
enum raminit_status ddr3_jedec_init(struct sysinfo *ctrl) |
| 212 |
{ |
| 213 |
ddr3_program_mr2(ctrl); |
| 214 |
ddr3_program_mr3(ctrl, 0); |
| 215 |
ddr3_program_mr1(ctrl, 0, 0); |
| 216 |
ddr3_program_mr0(ctrl, 1); |
| 217 |
return reut_issue_zq(ctrl, ctrl->chanmap, ZQ_INIT); |
| 218 |
} |
| 219 |
|
| 220 |
enum raminit_status exit_selfrefresh(struct sysinfo *ctrl) |
| 221 |
{ |
| 222 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 223 |
if (!does_ch_exist(ctrl, channel)) |
| 224 |
continue; |
| 225 |
|
| 226 |
|
| 227 |
union ddr_data_control_0_reg data_control_0 = { |
| 228 |
.raw = mchbar_read32(DQ_CONTROL_0(channel, 0)), |
| 229 |
}; |
| 230 |
data_control_0.read_rf_rd = 1; |
| 231 |
for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) { |
| 232 |
if (!rank_in_ch(ctrl, rank, channel)) |
| 233 |
continue; |
| 234 |
|
| 235 |
data_control_0.read_rf_rank = rank; |
| 236 |
mchbar_write32(DDR_DATA_ch_CONTROL_0(channel), data_control_0.raw); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
udelay(6); |
| 242 |
|
| 243 |
|
| 244 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 245 |
const union reut_misc_cke_ctrl_reg reut_misc_cke_ctrl = { |
| 246 |
.cke_on = ctrl->rankmap[channel], |
| 247 |
}; |
| 248 |
mchbar_write32(REUT_ch_MISC_CKE_CTRL(channel), reut_misc_cke_ctrl.raw); |
| 249 |
} |
| 250 |
mchbar_write32(REUT_MISC_ODT_CTRL, 0); |
| 251 |
|
| 252 |
const enum raminit_status status = reut_issue_zq(ctrl, ctrl->chanmap, ZQ_LONG); |
| 253 |
if (status) { |
| 254 |
|
| 255 |
printk(BIOS_ERR, "ZQ Long failed during S3 resume or warm reset flow\n"); |
| 256 |
} |
| 257 |
return RAMINIT_STATUS_SUCCESS; |
| 258 |
} |