Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3 | #include <console/console.h> |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 4 | #include <commonlib/helpers.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 5 | #include <string.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 6 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 7 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame] | 9 | #include <device/smbus_host.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 10 | #include <cpu/x86/msr.h> |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 11 | #include <cpu/x86/cache.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 12 | #include <cbmem.h> |
Elyes HAOUAS | d45f338 | 2019-04-28 18:04:35 +0200 | [diff] [blame] | 13 | #include <cf9_reset.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 14 | #include <ip_checksum.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 15 | #include <option.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 16 | #include <device/pci_def.h> |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 17 | #include <device/device.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 18 | #include <halt.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 19 | #include <spd.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 20 | #include <timestamp.h> |
| 21 | #include <cpu/x86/mtrr.h> |
| 22 | #include <cpu/intel/speedstep.h> |
| 23 | #include <cpu/intel/turbo.h> |
Arthur Heymans | dc71e25 | 2018-01-29 10:14:48 +0100 | [diff] [blame] | 24 | #include <mrc_cache.h> |
Elyes HAOUAS | 21b71ce6 | 2018-06-16 18:43:52 +0200 | [diff] [blame] | 25 | #include <southbridge/intel/ibexpeak/me.h> |
Arthur Heymans | 2878c0b | 2019-10-14 18:42:00 +0200 | [diff] [blame] | 26 | #include <southbridge/intel/common/pmbase.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 27 | #include <delay.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 28 | #include <types.h> |
| 29 | |
| 30 | #include "chip.h" |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 31 | #include "ironlake.h" |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 32 | #include "raminit.h" |
Angel Pons | 18a55cd | 2019-08-14 20:46:00 +0200 | [diff] [blame] | 33 | #include "raminit_tables.h" |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 34 | |
| 35 | #define NORTHBRIDGE PCI_DEV(0, 0, 0) |
| 36 | #define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0) |
| 37 | #define GMA PCI_DEV (0, 0x2, 0x0) |
| 38 | #define HECIDEV PCI_DEV(0, 0x16, 0) |
| 39 | #define HECIBAR 0x10 |
| 40 | |
| 41 | #define FOR_ALL_RANKS \ |
| 42 | for (channel = 0; channel < NUM_CHANNELS; channel++) \ |
| 43 | for (slot = 0; slot < NUM_SLOTS; slot++) \ |
| 44 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 45 | |
| 46 | #define FOR_POPULATED_RANKS \ |
| 47 | for (channel = 0; channel < NUM_CHANNELS; channel++) \ |
| 48 | for (slot = 0; slot < NUM_SLOTS; slot++) \ |
| 49 | for (rank = 0; rank < NUM_RANKS; rank++) \ |
| 50 | if (info->populated_ranks[channel][slot][rank]) |
| 51 | |
| 52 | #define FOR_POPULATED_RANKS_BACKWARDS \ |
| 53 | for (channel = NUM_CHANNELS - 1; channel >= 0; channel--) \ |
| 54 | for (slot = 0; slot < NUM_SLOTS; slot++) \ |
| 55 | for (rank = 0; rank < NUM_RANKS; rank++) \ |
| 56 | if (info->populated_ranks[channel][slot][rank]) |
| 57 | |
| 58 | /* [REG_178][CHANNEL][2 * SLOT + RANK][LANE] */ |
| 59 | typedef struct { |
| 60 | u8 smallest; |
| 61 | u8 largest; |
| 62 | } timing_bounds_t[2][2][2][9]; |
| 63 | |
Arthur Heymans | dc71e25 | 2018-01-29 10:14:48 +0100 | [diff] [blame] | 64 | #define MRC_CACHE_VERSION 1 |
| 65 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 66 | struct ram_training { |
| 67 | /* [TM][CHANNEL][SLOT][RANK][LANE] */ |
| 68 | u16 lane_timings[4][2][2][2][9]; |
| 69 | u16 reg_178; |
| 70 | u16 reg_10b; |
| 71 | |
| 72 | u8 reg178_center; |
| 73 | u8 reg178_smallest; |
| 74 | u8 reg178_largest; |
| 75 | timing_bounds_t timing_bounds[2]; |
| 76 | u16 timing_offset[2][2][2][9]; |
| 77 | u16 timing2_offset[2][2][2][9]; |
| 78 | u16 timing2_bounds[2][2][2][9][2]; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 79 | u8 reg274265[2][3]; /* [CHANNEL][REGISTER] */ |
| 80 | u8 reg2ca9_bit0; |
| 81 | u32 reg_6dc; |
| 82 | u32 reg_6e8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 85 | #include <lib.h> /* Prototypes */ |
| 86 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 87 | typedef struct _u128 { |
| 88 | u64 lo; |
| 89 | u64 hi; |
| 90 | } u128; |
| 91 | |
| 92 | static void read128(u32 addr, u64 * out) |
| 93 | { |
| 94 | u128 ret; |
| 95 | u128 stor; |
| 96 | asm volatile ("movdqu %%xmm0, %0\n" |
| 97 | "movdqa (%2), %%xmm0\n" |
| 98 | "movdqu %%xmm0, %1\n" |
| 99 | "movdqu %0, %%xmm0":"+m" (stor), "=m"(ret):"r"(addr)); |
| 100 | out[0] = ret.lo; |
| 101 | out[1] = ret.hi; |
| 102 | } |
| 103 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 104 | /* OK */ |
| 105 | static void write_1d0(u32 val, u16 addr, int bits, int flag) |
| 106 | { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 107 | MCHBAR32(0x1d0) = 0; |
| 108 | while (MCHBAR32(0x1d0) & 0x800000) |
| 109 | ; |
| 110 | MCHBAR32(0x1d4) = |
| 111 | (val & ((1 << bits) - 1)) | (2 << bits) | (flag << bits); |
| 112 | MCHBAR32(0x1d0) = 0x40000000 | addr; |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 113 | while (MCHBAR32(0x1d0) & 0x800000) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 114 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* OK */ |
| 118 | static u16 read_1d0(u16 addr, int split) |
| 119 | { |
| 120 | u32 val; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 121 | MCHBAR32(0x1d0) = 0; |
| 122 | while (MCHBAR32(0x1d0) & 0x800000) |
| 123 | ; |
| 124 | MCHBAR32(0x1d0) = |
| 125 | 0x80000000 | (((MCHBAR8(0x246) >> 2) & 3) + 0x361 - addr); |
| 126 | while (MCHBAR32(0x1d0) & 0x800000) |
| 127 | ; |
| 128 | val = MCHBAR32(0x1d8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 129 | write_1d0(0, 0x33d, 0, 0); |
| 130 | write_1d0(0, 0x33d, 0, 0); |
| 131 | val &= ((1 << split) - 1); |
| 132 | // printk (BIOS_ERR, "R1D0C [%x] => %x\n", addr, val); |
| 133 | return val; |
| 134 | } |
| 135 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 136 | static void write32p(uintptr_t addr, uint32_t val) |
| 137 | { |
| 138 | write32((void *)addr, val); |
| 139 | } |
| 140 | |
| 141 | static uint32_t read32p(uintptr_t addr) |
| 142 | { |
| 143 | return read32((void *)addr); |
| 144 | } |
| 145 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 146 | static void sfence(void) |
| 147 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 148 | asm volatile ("sfence"); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static inline u16 get_lane_offset(int slot, int rank, int lane) |
| 152 | { |
| 153 | return 0x124 * lane + ((lane & 4) ? 0x23e : 0) + 11 * rank + 22 * slot - |
| 154 | 0x452 * (lane == 8); |
| 155 | } |
| 156 | |
| 157 | static inline u16 get_timing_register_addr(int lane, int tm, int slot, int rank) |
| 158 | { |
| 159 | const u16 offs[] = { 0x1d, 0xa8, 0xe6, 0x5c }; |
| 160 | return get_lane_offset(slot, rank, lane) + offs[(tm + 3) % 4]; |
| 161 | } |
| 162 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 163 | static u32 gav_real(int line, u32 in) |
| 164 | { |
| 165 | // printk (BIOS_DEBUG, "%d: GAV: %x\n", line, in); |
| 166 | return in; |
| 167 | } |
| 168 | |
| 169 | #define gav(x) gav_real (__LINE__, (x)) |
Felix Held | 29a9c07 | 2018-07-29 01:34:45 +0200 | [diff] [blame] | 170 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 171 | struct raminfo { |
| 172 | u16 clock_speed_index; /* clock_speed (REAL, not DDR) / 133.(3) - 3 */ |
| 173 | u16 fsb_frequency; /* in 1.(1)/2 MHz. */ |
| 174 | u8 is_x16_module[2][2]; /* [CHANNEL][SLOT] */ |
| 175 | u8 density[2][2]; /* [CHANNEL][SLOT] */ |
| 176 | u8 populated_ranks[2][2][2]; /* [CHANNEL][SLOT][RANK] */ |
| 177 | int rank_start[2][2][2]; |
| 178 | u8 cas_latency; |
| 179 | u8 board_lane_delay[9]; |
| 180 | u8 use_ecc; |
| 181 | u8 revision; |
| 182 | u8 max_supported_clock_speed_index; |
| 183 | u8 uma_enabled; |
| 184 | u8 spd[2][2][151]; /* [CHANNEL][SLOT][BYTE] */ |
| 185 | u8 silicon_revision; |
| 186 | u8 populated_ranks_mask[2]; |
| 187 | u8 max_slots_used_in_channel; |
| 188 | u8 mode4030[2]; |
| 189 | u16 avg4044[2]; |
| 190 | u16 max4048[2]; |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 191 | unsigned int total_memory_mb; |
| 192 | unsigned int interleaved_part_mb; |
| 193 | unsigned int non_interleaved_part_mb; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 194 | |
| 195 | u32 heci_bar; |
| 196 | u64 heci_uma_addr; |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 197 | unsigned int memory_reserved_for_heci_mb; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 198 | |
| 199 | struct ram_training training; |
| 200 | u32 last_500_command[2]; |
| 201 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 202 | u32 delay46_ps[2]; |
| 203 | u32 delay54_ps[2]; |
| 204 | u8 revision_flag_1; |
| 205 | u8 some_delay_1_cycle_floor; |
| 206 | u8 some_delay_2_halfcycles_ceil; |
| 207 | u8 some_delay_3_ps_rounded; |
| 208 | |
| 209 | const struct ram_training *cached_training; |
| 210 | }; |
| 211 | |
Matthias Gazzari | dfa5125 | 2018-05-19 00:44:20 +0200 | [diff] [blame] | 212 | /* Global allocation of timings_car */ |
Arthur Heymans | 33ab29f | 2018-12-29 13:34:30 +0100 | [diff] [blame] | 213 | timing_bounds_t timings_car[64]; |
Matthias Gazzari | dfa5125 | 2018-05-19 00:44:20 +0200 | [diff] [blame] | 214 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 215 | static void |
| 216 | write_500(struct raminfo *info, int channel, u32 val, u16 addr, int bits, |
| 217 | int flag); |
| 218 | |
| 219 | /* OK */ |
| 220 | static u16 |
| 221 | read_500(struct raminfo *info, int channel, u16 addr, int split) |
| 222 | { |
| 223 | u32 val; |
| 224 | info->last_500_command[channel] = 0x80000000; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 225 | MCHBAR32(0x500 + (channel << 10)) = 0; |
| 226 | while (MCHBAR32(0x500 + (channel << 10)) & 0x800000) |
| 227 | ; |
| 228 | MCHBAR32(0x500 + (channel << 10)) = |
| 229 | 0x80000000 | (((MCHBAR8(0x246 + (channel << 10)) >> 2) & 3) |
| 230 | + 0xb88 - addr); |
| 231 | while (MCHBAR32(0x500 + (channel << 10)) & 0x800000) |
| 232 | ; |
| 233 | val = MCHBAR32(0x508 + (channel << 10)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 234 | return val & ((1 << split) - 1); |
| 235 | } |
| 236 | |
| 237 | /* OK */ |
| 238 | static void |
| 239 | write_500(struct raminfo *info, int channel, u32 val, u16 addr, int bits, |
| 240 | int flag) |
| 241 | { |
| 242 | if (info->last_500_command[channel] == 0x80000000) { |
| 243 | info->last_500_command[channel] = 0x40000000; |
| 244 | write_500(info, channel, 0, 0xb61, 0, 0); |
| 245 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 246 | MCHBAR32(0x500 + (channel << 10)) = 0; |
| 247 | while (MCHBAR32(0x500 + (channel << 10)) & 0x800000) |
| 248 | ; |
| 249 | MCHBAR32(0x504 + (channel << 10)) = |
| 250 | (val & ((1 << bits) - 1)) | (2 << bits) | (flag << bits); |
| 251 | MCHBAR32(0x500 + (channel << 10)) = 0x40000000 | addr; |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 252 | while (MCHBAR32(0x500 + (channel << 10)) & 0x800000) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 253 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static int rw_test(int rank) |
| 257 | { |
| 258 | const u32 mask = 0xf00fc33c; |
| 259 | int ok = 0xff; |
| 260 | int i; |
| 261 | for (i = 0; i < 64; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 262 | write32p((rank << 28) | (i << 2), 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 263 | sfence(); |
| 264 | for (i = 0; i < 64; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 265 | gav(read32p((rank << 28) | (i << 2))); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 266 | sfence(); |
| 267 | for (i = 0; i < 32; i++) { |
| 268 | u32 pat = (((mask >> i) & 1) ? 0xffffffff : 0); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 269 | write32p((rank << 28) | (i << 3), pat); |
| 270 | write32p((rank << 28) | (i << 3) | 4, pat); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 271 | } |
| 272 | sfence(); |
| 273 | for (i = 0; i < 32; i++) { |
| 274 | u8 pat = (((mask >> i) & 1) ? 0xff : 0); |
| 275 | int j; |
| 276 | u32 val; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 277 | gav(val = read32p((rank << 28) | (i << 3))); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 278 | for (j = 0; j < 4; j++) |
| 279 | if (((val >> (j * 8)) & 0xff) != pat) |
| 280 | ok &= ~(1 << j); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 281 | gav(val = read32p((rank << 28) | (i << 3) | 4)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 282 | for (j = 0; j < 4; j++) |
| 283 | if (((val >> (j * 8)) & 0xff) != pat) |
| 284 | ok &= ~(16 << j); |
| 285 | } |
| 286 | sfence(); |
| 287 | for (i = 0; i < 64; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 288 | write32p((rank << 28) | (i << 2), 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 289 | sfence(); |
| 290 | for (i = 0; i < 64; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 291 | gav(read32p((rank << 28) | (i << 2))); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 292 | |
| 293 | return ok; |
| 294 | } |
| 295 | |
| 296 | static void |
| 297 | program_timings(struct raminfo *info, u16 base, int channel, int slot, int rank) |
| 298 | { |
| 299 | int lane; |
| 300 | for (lane = 0; lane < 8; lane++) { |
| 301 | write_500(info, channel, |
| 302 | base + |
| 303 | info->training. |
| 304 | lane_timings[2][channel][slot][rank][lane], |
| 305 | get_timing_register_addr(lane, 2, slot, rank), 9, 0); |
| 306 | write_500(info, channel, |
| 307 | base + |
| 308 | info->training. |
| 309 | lane_timings[3][channel][slot][rank][lane], |
| 310 | get_timing_register_addr(lane, 3, slot, rank), 9, 0); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | static void write_26c(int channel, u16 si) |
| 315 | { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 316 | MCHBAR32(0x26c + (channel << 10)) = 0x03243f35; |
| 317 | MCHBAR32(0x268 + (channel << 10)) = 0xcfc00000 | (si << 9); |
| 318 | MCHBAR16(0x2b9 + (channel << 10)) = si; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static u32 get_580(int channel, u8 addr) |
| 322 | { |
| 323 | u32 ret; |
| 324 | gav(read_1d0(0x142, 3)); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 325 | MCHBAR8(0x5ff) = 0x0; |
| 326 | MCHBAR8(0x5ff) = 0x80; |
| 327 | MCHBAR32(0x580 + (channel << 10)) = 0x8493c012 | addr; |
| 328 | MCHBAR8_OR(0x580 + (channel << 10), 1); |
| 329 | while (!((ret = MCHBAR32(0x580 + (channel << 10))) & 0x10000)) |
| 330 | ; |
| 331 | MCHBAR8_AND(0x580 + (channel << 10), ~1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 332 | return ret; |
| 333 | } |
| 334 | |
| 335 | const int cached_config = 0; |
| 336 | |
| 337 | #define NUM_CHANNELS 2 |
| 338 | #define NUM_SLOTS 2 |
| 339 | #define NUM_RANKS 2 |
| 340 | #define RANK_SHIFT 28 |
| 341 | #define CHANNEL_SHIFT 10 |
| 342 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 343 | static void seq9(struct raminfo *info, int channel, int slot, int rank) |
| 344 | { |
| 345 | int i, lane; |
| 346 | |
| 347 | for (i = 0; i < 2; i++) |
| 348 | for (lane = 0; lane < 8; lane++) |
| 349 | write_500(info, channel, |
| 350 | info->training.lane_timings[i + |
| 351 | 1][channel][slot] |
| 352 | [rank][lane], get_timing_register_addr(lane, |
| 353 | i + 1, |
| 354 | slot, |
| 355 | rank), |
| 356 | 9, 0); |
| 357 | |
| 358 | write_1d0(1, 0x103, 6, 1); |
| 359 | for (lane = 0; lane < 8; lane++) |
| 360 | write_500(info, channel, |
| 361 | info->training. |
| 362 | lane_timings[0][channel][slot][rank][lane], |
| 363 | get_timing_register_addr(lane, 0, slot, rank), 9, 0); |
| 364 | |
| 365 | for (i = 0; i < 2; i++) { |
| 366 | for (lane = 0; lane < 8; lane++) |
| 367 | write_500(info, channel, |
| 368 | info->training.lane_timings[i + |
| 369 | 1][channel][slot] |
| 370 | [rank][lane], get_timing_register_addr(lane, |
| 371 | i + 1, |
| 372 | slot, |
| 373 | rank), |
| 374 | 9, 0); |
| 375 | gav(get_580(channel, ((i + 1) << 2) | (rank << 5))); |
| 376 | } |
| 377 | |
| 378 | gav(read_1d0(0x142, 3)); // = 0x10408118 |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 379 | MCHBAR8(0x5ff) = 0x0; |
| 380 | MCHBAR8(0x5ff) = 0x80; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 381 | write_1d0(0x2, 0x142, 3, 1); |
| 382 | for (lane = 0; lane < 8; lane++) { |
| 383 | // printk (BIOS_ERR, "before: %x\n", info->training.lane_timings[2][channel][slot][rank][lane]); |
| 384 | info->training.lane_timings[2][channel][slot][rank][lane] = |
| 385 | read_500(info, channel, |
| 386 | get_timing_register_addr(lane, 2, slot, rank), 9); |
| 387 | //printk (BIOS_ERR, "after: %x\n", info->training.lane_timings[2][channel][slot][rank][lane]); |
| 388 | info->training.lane_timings[3][channel][slot][rank][lane] = |
| 389 | info->training.lane_timings[2][channel][slot][rank][lane] + |
| 390 | 0x20; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | static int count_ranks_in_channel(struct raminfo *info, int channel) |
| 395 | { |
| 396 | int slot, rank; |
| 397 | int res = 0; |
| 398 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 399 | for (rank = 0; rank < NUM_SLOTS; rank++) |
| 400 | res += info->populated_ranks[channel][slot][rank]; |
| 401 | return res; |
| 402 | } |
| 403 | |
| 404 | static void |
| 405 | config_rank(struct raminfo *info, int s3resume, int channel, int slot, int rank) |
| 406 | { |
| 407 | int add; |
| 408 | |
| 409 | write_1d0(0, 0x178, 7, 1); |
| 410 | seq9(info, channel, slot, rank); |
| 411 | program_timings(info, 0x80, channel, slot, rank); |
| 412 | |
| 413 | if (channel == 0) |
| 414 | add = count_ranks_in_channel(info, 1); |
| 415 | else |
| 416 | add = 0; |
| 417 | if (!s3resume) |
| 418 | gav(rw_test(rank + add)); |
| 419 | program_timings(info, 0x00, channel, slot, rank); |
| 420 | if (!s3resume) |
| 421 | gav(rw_test(rank + add)); |
| 422 | if (!s3resume) |
| 423 | gav(rw_test(rank + add)); |
| 424 | write_1d0(0, 0x142, 3, 1); |
| 425 | write_1d0(0, 0x103, 6, 1); |
| 426 | |
| 427 | gav(get_580(channel, 0xc | (rank << 5))); |
| 428 | gav(read_1d0(0x142, 3)); |
| 429 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 430 | MCHBAR8(0x5ff) = 0x0; |
| 431 | MCHBAR8(0x5ff) = 0x80; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void set_4cf(struct raminfo *info, int channel, u8 val) |
| 435 | { |
| 436 | gav(read_500(info, channel, 0x4cf, 4)); // = 0xc2300cf9 |
| 437 | write_500(info, channel, val, 0x4cf, 4, 1); |
| 438 | gav(read_500(info, channel, 0x659, 4)); // = 0x80300839 |
| 439 | write_500(info, channel, val, 0x659, 4, 1); |
| 440 | gav(read_500(info, channel, 0x697, 4)); // = 0x80300839 |
| 441 | write_500(info, channel, val, 0x697, 4, 1); |
| 442 | } |
| 443 | |
| 444 | static void set_334(int zero) |
| 445 | { |
| 446 | int j, k, channel; |
| 447 | const u32 val3[] = { 0x2a2b2a2b, 0x26272627, 0x2e2f2e2f, 0x2a2b }; |
| 448 | u32 vd8[2][16]; |
| 449 | |
| 450 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 451 | for (j = 0; j < 4; j++) { |
| 452 | u32 a = (j == 1) ? 0x29292929 : 0x31313131; |
| 453 | u32 lmask = (j == 3) ? 0xffff : 0xffffffff; |
| 454 | u16 c; |
| 455 | if ((j == 0 || j == 3) && zero) |
| 456 | c = 0; |
| 457 | else if (j == 3) |
| 458 | c = 0x5f; |
| 459 | else |
| 460 | c = 0x5f5f; |
| 461 | |
| 462 | for (k = 0; k < 2; k++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 463 | MCHBAR32(0x138 + 8 * k) = |
| 464 | (channel << 26) | (j << 24); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 465 | gav(vd8[1][(channel << 3) | (j << 1) | k] = |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 466 | MCHBAR32(0x138 + 8 * k)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 467 | gav(vd8[0][(channel << 3) | (j << 1) | k] = |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 468 | MCHBAR32(0x13c + 8 * k)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 471 | MCHBAR32(0x334 + (channel << 10) + (j * 0x44)) = |
| 472 | zero ? 0 : val3[j]; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 473 | MCHBAR32(0x32c + (channel << 10) + (j * 0x44)) = |
| 474 | zero ? 0 : (0x18191819 & lmask); |
| 475 | MCHBAR16(0x34a + (channel << 10) + (j * 0x44)) = c; |
| 476 | MCHBAR32(0x33c + (channel << 10) + (j * 0x44)) = |
| 477 | zero ? 0 : (a & lmask); |
| 478 | MCHBAR32(0x344 + (channel << 10) + (j * 0x44)) = |
| 479 | zero ? 0 : (a & lmask); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 483 | MCHBAR32_OR(0x130, 1); |
| 484 | while (MCHBAR8(0x130) & 1) |
| 485 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void rmw_1d0(u16 addr, u32 and, u32 or, int split, int flag) |
| 489 | { |
| 490 | u32 v; |
| 491 | v = read_1d0(addr, split); |
| 492 | write_1d0((v & and) | or, addr, split, flag); |
| 493 | } |
| 494 | |
| 495 | static int find_highest_bit_set(u16 val) |
| 496 | { |
| 497 | int i; |
| 498 | for (i = 15; i >= 0; i--) |
| 499 | if (val & (1 << i)) |
| 500 | return i; |
| 501 | return -1; |
| 502 | } |
| 503 | |
| 504 | static int find_lowest_bit_set32(u32 val) |
| 505 | { |
| 506 | int i; |
| 507 | for (i = 0; i < 32; i++) |
| 508 | if (val & (1 << i)) |
| 509 | return i; |
| 510 | return -1; |
| 511 | } |
| 512 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 513 | enum { |
| 514 | DEVICE_TYPE = 2, |
| 515 | MODULE_TYPE = 3, |
| 516 | DENSITY = 4, |
| 517 | RANKS_AND_DQ = 7, |
| 518 | MEMORY_BUS_WIDTH = 8, |
| 519 | TIMEBASE_DIVIDEND = 10, |
| 520 | TIMEBASE_DIVISOR = 11, |
| 521 | CYCLETIME = 12, |
| 522 | |
| 523 | CAS_LATENCIES_LSB = 14, |
| 524 | CAS_LATENCIES_MSB = 15, |
| 525 | CAS_LATENCY_TIME = 16, |
| 526 | THERMAL_AND_REFRESH = 31, |
| 527 | REFERENCE_RAW_CARD_USED = 62, |
| 528 | RANK1_ADDRESS_MAPPING = 63 |
| 529 | }; |
| 530 | |
| 531 | static void calculate_timings(struct raminfo *info) |
| 532 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 533 | unsigned int cycletime; |
| 534 | unsigned int cas_latency_time; |
| 535 | unsigned int supported_cas_latencies; |
| 536 | unsigned int channel, slot; |
| 537 | unsigned int clock_speed_index; |
| 538 | unsigned int min_cas_latency; |
| 539 | unsigned int cas_latency; |
| 540 | unsigned int max_clock_index; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 541 | |
| 542 | /* Find common CAS latency */ |
| 543 | supported_cas_latencies = 0x3fe; |
| 544 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 545 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 546 | if (info->populated_ranks[channel][slot][0]) |
| 547 | supported_cas_latencies &= |
| 548 | 2 * |
| 549 | (info-> |
| 550 | spd[channel][slot][CAS_LATENCIES_LSB] | |
| 551 | (info-> |
| 552 | spd[channel][slot][CAS_LATENCIES_MSB] << |
| 553 | 8)); |
| 554 | |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 555 | max_clock_index = MIN(3, info->max_supported_clock_speed_index); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 556 | |
| 557 | cycletime = min_cycletime[max_clock_index]; |
| 558 | cas_latency_time = min_cas_latency_time[max_clock_index]; |
| 559 | |
| 560 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 561 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 562 | if (info->populated_ranks[channel][slot][0]) { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 563 | unsigned int timebase; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 564 | timebase = |
| 565 | 1000 * |
| 566 | info-> |
| 567 | spd[channel][slot][TIMEBASE_DIVIDEND] / |
| 568 | info->spd[channel][slot][TIMEBASE_DIVISOR]; |
| 569 | cycletime = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 570 | MAX(cycletime, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 571 | timebase * |
| 572 | info->spd[channel][slot][CYCLETIME]); |
| 573 | cas_latency_time = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 574 | MAX(cas_latency_time, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 575 | timebase * |
| 576 | info-> |
| 577 | spd[channel][slot][CAS_LATENCY_TIME]); |
| 578 | } |
Jacob Garber | 3c19382 | 2019-06-10 18:23:32 -0600 | [diff] [blame] | 579 | if (cycletime > min_cycletime[0]) |
| 580 | die("RAM init: Decoded SPD DRAM freq is slower than the controller minimum!"); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 581 | for (clock_speed_index = 0; clock_speed_index < 3; clock_speed_index++) { |
| 582 | if (cycletime == min_cycletime[clock_speed_index]) |
| 583 | break; |
| 584 | if (cycletime > min_cycletime[clock_speed_index]) { |
| 585 | clock_speed_index--; |
| 586 | cycletime = min_cycletime[clock_speed_index]; |
| 587 | break; |
| 588 | } |
| 589 | } |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 590 | min_cas_latency = DIV_ROUND_UP(cas_latency_time, cycletime); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 591 | cas_latency = 0; |
| 592 | while (supported_cas_latencies) { |
| 593 | cas_latency = find_highest_bit_set(supported_cas_latencies) + 3; |
| 594 | if (cas_latency <= min_cas_latency) |
| 595 | break; |
| 596 | supported_cas_latencies &= |
| 597 | ~(1 << find_highest_bit_set(supported_cas_latencies)); |
| 598 | } |
| 599 | |
| 600 | if (cas_latency != min_cas_latency && clock_speed_index) |
| 601 | clock_speed_index--; |
| 602 | |
| 603 | if (cas_latency * min_cycletime[clock_speed_index] > 20000) |
| 604 | die("Couldn't configure DRAM"); |
| 605 | info->clock_speed_index = clock_speed_index; |
| 606 | info->cas_latency = cas_latency; |
| 607 | } |
| 608 | |
| 609 | static void program_base_timings(struct raminfo *info) |
| 610 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 611 | unsigned int channel; |
| 612 | unsigned int slot, rank, lane; |
| 613 | unsigned int extended_silicon_revision; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 614 | int i; |
| 615 | |
| 616 | extended_silicon_revision = info->silicon_revision; |
| 617 | if (info->silicon_revision == 0) |
| 618 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 619 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 620 | if ((info-> |
| 621 | spd[channel][slot][MODULE_TYPE] & 0xF) == |
| 622 | 3) |
| 623 | extended_silicon_revision = 4; |
| 624 | |
| 625 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 626 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 627 | for (rank = 0; rank < NUM_SLOTS; rank++) { |
| 628 | int card_timing_2; |
| 629 | if (!info->populated_ranks[channel][slot][rank]) |
| 630 | continue; |
| 631 | |
| 632 | for (lane = 0; lane < 9; lane++) { |
| 633 | int tm_reg; |
| 634 | int card_timing; |
| 635 | |
| 636 | card_timing = 0; |
| 637 | if ((info-> |
| 638 | spd[channel][slot][MODULE_TYPE] & |
| 639 | 0xF) == 3) { |
| 640 | int reference_card; |
| 641 | reference_card = |
| 642 | info-> |
| 643 | spd[channel][slot] |
| 644 | [REFERENCE_RAW_CARD_USED] & |
| 645 | 0x1f; |
| 646 | if (reference_card == 3) |
| 647 | card_timing = |
| 648 | u16_ffd1188[0][lane] |
| 649 | [info-> |
| 650 | clock_speed_index]; |
| 651 | if (reference_card == 5) |
| 652 | card_timing = |
| 653 | u16_ffd1188[1][lane] |
| 654 | [info-> |
| 655 | clock_speed_index]; |
| 656 | } |
| 657 | |
| 658 | info->training. |
| 659 | lane_timings[0][channel][slot][rank] |
| 660 | [lane] = |
| 661 | u8_FFFD1218[info-> |
| 662 | clock_speed_index]; |
| 663 | info->training. |
| 664 | lane_timings[1][channel][slot][rank] |
| 665 | [lane] = 256; |
| 666 | |
| 667 | for (tm_reg = 2; tm_reg < 4; tm_reg++) |
| 668 | info->training. |
| 669 | lane_timings[tm_reg] |
| 670 | [channel][slot][rank][lane] |
| 671 | = |
| 672 | u8_FFFD1240[channel] |
| 673 | [extended_silicon_revision] |
| 674 | [lane][2 * slot + |
| 675 | rank][info-> |
| 676 | clock_speed_index] |
| 677 | + info->max4048[channel] |
| 678 | + |
| 679 | u8_FFFD0C78[channel] |
| 680 | [extended_silicon_revision] |
| 681 | [info-> |
| 682 | mode4030[channel]][slot] |
| 683 | [rank][info-> |
| 684 | clock_speed_index] |
| 685 | + card_timing; |
| 686 | for (tm_reg = 0; tm_reg < 4; tm_reg++) |
| 687 | write_500(info, channel, |
| 688 | info->training. |
| 689 | lane_timings[tm_reg] |
| 690 | [channel][slot][rank] |
| 691 | [lane], |
| 692 | get_timing_register_addr |
| 693 | (lane, tm_reg, slot, |
| 694 | rank), 9, 0); |
| 695 | } |
| 696 | |
| 697 | card_timing_2 = 0; |
| 698 | if (!(extended_silicon_revision != 4 |
| 699 | || (info-> |
| 700 | populated_ranks_mask[channel] & 5) == |
| 701 | 5)) { |
| 702 | if ((info-> |
| 703 | spd[channel][slot] |
| 704 | [REFERENCE_RAW_CARD_USED] & 0x1F) |
| 705 | == 3) |
| 706 | card_timing_2 = |
| 707 | u16_FFFE0EB8[0][info-> |
| 708 | clock_speed_index]; |
| 709 | if ((info-> |
| 710 | spd[channel][slot] |
| 711 | [REFERENCE_RAW_CARD_USED] & 0x1F) |
| 712 | == 5) |
| 713 | card_timing_2 = |
| 714 | u16_FFFE0EB8[1][info-> |
| 715 | clock_speed_index]; |
| 716 | } |
| 717 | |
| 718 | for (i = 0; i < 3; i++) |
| 719 | write_500(info, channel, |
| 720 | (card_timing_2 + |
| 721 | info->max4048[channel] |
| 722 | + |
| 723 | u8_FFFD0EF8[channel] |
| 724 | [extended_silicon_revision] |
| 725 | [info-> |
| 726 | mode4030[channel]][info-> |
| 727 | clock_speed_index]), |
| 728 | u16_fffd0c50[i][slot][rank], |
| 729 | 8, 1); |
| 730 | write_500(info, channel, |
| 731 | (info->max4048[channel] + |
| 732 | u8_FFFD0C78[channel] |
| 733 | [extended_silicon_revision][info-> |
| 734 | mode4030 |
| 735 | [channel]] |
| 736 | [slot][rank][info-> |
| 737 | clock_speed_index]), |
| 738 | u16_fffd0c70[slot][rank], 7, 1); |
| 739 | } |
| 740 | if (!info->populated_ranks_mask[channel]) |
| 741 | continue; |
| 742 | for (i = 0; i < 3; i++) |
| 743 | write_500(info, channel, |
| 744 | (info->max4048[channel] + |
| 745 | info->avg4044[channel] |
| 746 | + |
| 747 | u8_FFFD17E0[channel] |
| 748 | [extended_silicon_revision][info-> |
| 749 | mode4030 |
| 750 | [channel]][info-> |
| 751 | clock_speed_index]), |
| 752 | u16_fffd0c68[i], 8, 1); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | static unsigned int fsbcycle_ps(struct raminfo *info) |
| 757 | { |
| 758 | return 900000 / info->fsb_frequency; |
| 759 | } |
| 760 | |
| 761 | /* The time of DDR transfer in ps. */ |
| 762 | static unsigned int halfcycle_ps(struct raminfo *info) |
| 763 | { |
| 764 | return 3750 / (info->clock_speed_index + 3); |
| 765 | } |
| 766 | |
| 767 | /* The time of clock cycle in ps. */ |
| 768 | static unsigned int cycle_ps(struct raminfo *info) |
| 769 | { |
| 770 | return 2 * halfcycle_ps(info); |
| 771 | } |
| 772 | |
| 773 | /* Frequency in 1.(1)=10/9 MHz units. */ |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 774 | static unsigned int frequency_11(struct raminfo *info) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 775 | { |
| 776 | return (info->clock_speed_index + 3) * 120; |
| 777 | } |
| 778 | |
| 779 | /* Frequency in 0.1 MHz units. */ |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 780 | static unsigned int frequency_01(struct raminfo *info) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 781 | { |
| 782 | return 100 * frequency_11(info) / 9; |
| 783 | } |
| 784 | |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 785 | static unsigned int ps_to_halfcycles(struct raminfo *info, unsigned int ps) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 786 | { |
| 787 | return (frequency_11(info) * 2) * ps / 900000; |
| 788 | } |
| 789 | |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 790 | static unsigned int ns_to_cycles(struct raminfo *info, unsigned int ns) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 791 | { |
| 792 | return (frequency_11(info)) * ns / 900; |
| 793 | } |
| 794 | |
| 795 | static void compute_derived_timings(struct raminfo *info) |
| 796 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 797 | unsigned int channel, slot, rank; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 798 | int extended_silicon_revision; |
| 799 | int some_delay_1_ps; |
| 800 | int some_delay_2_ps; |
| 801 | int some_delay_2_halfcycles_ceil; |
| 802 | int some_delay_2_halfcycles_floor; |
| 803 | int some_delay_3_ps; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 804 | int some_delay_3_ps_rounded; |
| 805 | int some_delay_1_cycle_ceil; |
| 806 | int some_delay_1_cycle_floor; |
| 807 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 808 | some_delay_3_ps_rounded = 0; |
| 809 | extended_silicon_revision = info->silicon_revision; |
| 810 | if (!info->silicon_revision) |
| 811 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 812 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 813 | if ((info-> |
| 814 | spd[channel][slot][MODULE_TYPE] & 0xF) == |
| 815 | 3) |
| 816 | extended_silicon_revision = 4; |
| 817 | if (info->board_lane_delay[7] < 5) |
| 818 | info->board_lane_delay[7] = 5; |
| 819 | info->revision_flag_1 = 2; |
| 820 | if (info->silicon_revision == 2 || info->silicon_revision == 3) |
| 821 | info->revision_flag_1 = 0; |
| 822 | if (info->revision < 16) |
| 823 | info->revision_flag_1 = 0; |
| 824 | |
| 825 | if (info->revision < 8) |
| 826 | info->revision_flag_1 = 0; |
| 827 | if (info->revision >= 8 && (info->silicon_revision == 0 |
| 828 | || info->silicon_revision == 1)) |
| 829 | some_delay_2_ps = 735; |
| 830 | else |
| 831 | some_delay_2_ps = 750; |
| 832 | |
| 833 | if (info->revision >= 0x10 && (info->silicon_revision == 0 |
| 834 | || info->silicon_revision == 1)) |
| 835 | some_delay_1_ps = 3929; |
| 836 | else |
| 837 | some_delay_1_ps = 3490; |
| 838 | |
| 839 | some_delay_1_cycle_floor = some_delay_1_ps / cycle_ps(info); |
| 840 | some_delay_1_cycle_ceil = some_delay_1_ps / cycle_ps(info); |
| 841 | if (some_delay_1_ps % cycle_ps(info)) |
| 842 | some_delay_1_cycle_ceil++; |
| 843 | else |
| 844 | some_delay_1_cycle_floor--; |
| 845 | info->some_delay_1_cycle_floor = some_delay_1_cycle_floor; |
| 846 | if (info->revision_flag_1) |
| 847 | some_delay_2_ps = halfcycle_ps(info) >> 6; |
| 848 | some_delay_2_ps += |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 849 | MAX(some_delay_1_ps - 30, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 850 | 2 * halfcycle_ps(info) * (some_delay_1_cycle_ceil - 1) + 1000) + |
| 851 | 375; |
| 852 | some_delay_3_ps = |
| 853 | halfcycle_ps(info) - some_delay_2_ps % halfcycle_ps(info); |
| 854 | if (info->revision_flag_1) { |
Elyes HAOUAS | 6f7c955 | 2019-10-18 20:20:03 +0200 | [diff] [blame] | 855 | if (some_delay_3_ps >= 150) { |
| 856 | const int some_delay_3_halfcycles = |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 857 | (some_delay_3_ps << 6) / halfcycle_ps(info); |
Elyes HAOUAS | 6f7c955 | 2019-10-18 20:20:03 +0200 | [diff] [blame] | 858 | some_delay_3_ps_rounded = |
| 859 | halfcycle_ps(info) * some_delay_3_halfcycles >> 6; |
| 860 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 861 | } |
| 862 | some_delay_2_halfcycles_ceil = |
| 863 | (some_delay_2_ps + halfcycle_ps(info) - 1) / halfcycle_ps(info) - |
| 864 | 2 * (some_delay_1_cycle_ceil - 1); |
| 865 | if (info->revision_flag_1 && some_delay_3_ps < 150) |
| 866 | some_delay_2_halfcycles_ceil++; |
| 867 | some_delay_2_halfcycles_floor = some_delay_2_halfcycles_ceil; |
| 868 | if (info->revision < 0x10) |
| 869 | some_delay_2_halfcycles_floor = |
| 870 | some_delay_2_halfcycles_ceil - 1; |
| 871 | if (!info->revision_flag_1) |
| 872 | some_delay_2_halfcycles_floor++; |
| 873 | info->some_delay_2_halfcycles_ceil = some_delay_2_halfcycles_ceil; |
| 874 | info->some_delay_3_ps_rounded = some_delay_3_ps_rounded; |
| 875 | if ((info->populated_ranks[0][0][0] && info->populated_ranks[0][1][0]) |
| 876 | || (info->populated_ranks[1][0][0] |
| 877 | && info->populated_ranks[1][1][0])) |
| 878 | info->max_slots_used_in_channel = 2; |
| 879 | else |
| 880 | info->max_slots_used_in_channel = 1; |
| 881 | for (channel = 0; channel < 2; channel++) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 882 | MCHBAR32(0x244 + (channel << 10)) = |
| 883 | ((info->revision < 8) ? 1 : 0x200) | |
| 884 | ((2 - info->max_slots_used_in_channel) << 17) | |
| 885 | (channel << 21) | |
| 886 | (info->some_delay_1_cycle_floor << 18) | 0x9510; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 887 | if (info->max_slots_used_in_channel == 1) { |
| 888 | info->mode4030[0] = (count_ranks_in_channel(info, 0) == 2); |
| 889 | info->mode4030[1] = (count_ranks_in_channel(info, 1) == 2); |
| 890 | } else { |
| 891 | info->mode4030[0] = ((count_ranks_in_channel(info, 0) == 1) || (count_ranks_in_channel(info, 0) == 2)) ? 2 : 3; /* 2 if 1 or 2 ranks */ |
| 892 | info->mode4030[1] = ((count_ranks_in_channel(info, 1) == 1) |
| 893 | || (count_ranks_in_channel(info, 1) == |
| 894 | 2)) ? 2 : 3; |
| 895 | } |
| 896 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 897 | int max_of_unk; |
| 898 | int min_of_unk_2; |
| 899 | |
| 900 | int i, count; |
| 901 | int sum; |
| 902 | |
| 903 | if (!info->populated_ranks_mask[channel]) |
| 904 | continue; |
| 905 | |
| 906 | max_of_unk = 0; |
| 907 | min_of_unk_2 = 32767; |
| 908 | |
| 909 | sum = 0; |
| 910 | count = 0; |
| 911 | for (i = 0; i < 3; i++) { |
| 912 | int unk1; |
| 913 | if (info->revision < 8) |
| 914 | unk1 = |
| 915 | u8_FFFD1891[0][channel][info-> |
| 916 | clock_speed_index] |
| 917 | [i]; |
| 918 | else if (! |
| 919 | (info->revision >= 0x10 |
| 920 | || info->revision_flag_1)) |
| 921 | unk1 = |
| 922 | u8_FFFD1891[1][channel][info-> |
| 923 | clock_speed_index] |
| 924 | [i]; |
| 925 | else |
| 926 | unk1 = 0; |
| 927 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 928 | for (rank = 0; rank < NUM_RANKS; rank++) { |
| 929 | int a = 0; |
| 930 | int b = 0; |
| 931 | |
| 932 | if (!info-> |
| 933 | populated_ranks[channel][slot] |
| 934 | [rank]) |
| 935 | continue; |
| 936 | if (extended_silicon_revision == 4 |
| 937 | && (info-> |
| 938 | populated_ranks_mask[channel] & |
| 939 | 5) != 5) { |
| 940 | if ((info-> |
| 941 | spd[channel][slot] |
| 942 | [REFERENCE_RAW_CARD_USED] & |
| 943 | 0x1F) == 3) { |
| 944 | a = u16_ffd1178[0] |
| 945 | [info-> |
| 946 | clock_speed_index]; |
| 947 | b = u16_fe0eb8[0][info-> |
| 948 | clock_speed_index]; |
| 949 | } else |
| 950 | if ((info-> |
| 951 | spd[channel][slot] |
| 952 | [REFERENCE_RAW_CARD_USED] |
| 953 | & 0x1F) == 5) { |
| 954 | a = u16_ffd1178[1] |
| 955 | [info-> |
| 956 | clock_speed_index]; |
| 957 | b = u16_fe0eb8[1][info-> |
| 958 | clock_speed_index]; |
| 959 | } |
| 960 | } |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 961 | min_of_unk_2 = MIN(min_of_unk_2, a); |
| 962 | min_of_unk_2 = MIN(min_of_unk_2, b); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 963 | if (rank == 0) { |
| 964 | sum += a; |
| 965 | count++; |
| 966 | } |
| 967 | { |
| 968 | int t; |
| 969 | t = b + |
| 970 | u8_FFFD0EF8[channel] |
| 971 | [extended_silicon_revision] |
| 972 | [info-> |
| 973 | mode4030[channel]][info-> |
| 974 | clock_speed_index]; |
| 975 | if (unk1 >= t) |
| 976 | max_of_unk = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 977 | MAX(max_of_unk, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 978 | unk1 - t); |
| 979 | } |
| 980 | } |
| 981 | { |
| 982 | int t = |
| 983 | u8_FFFD17E0[channel] |
| 984 | [extended_silicon_revision][info-> |
| 985 | mode4030 |
| 986 | [channel]] |
| 987 | [info->clock_speed_index] + min_of_unk_2; |
| 988 | if (unk1 >= t) |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 989 | max_of_unk = MAX(max_of_unk, unk1 - t); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Jacob Garber | 64fb4a3 | 2019-06-10 17:29:18 -0600 | [diff] [blame] | 993 | if (count == 0) |
| 994 | die("No memory ranks found for channel %u\n", channel); |
| 995 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 996 | info->avg4044[channel] = sum / count; |
| 997 | info->max4048[channel] = max_of_unk; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | static void jedec_read(struct raminfo *info, |
| 1002 | int channel, int slot, int rank, |
| 1003 | int total_rank, u8 addr3, unsigned int value) |
| 1004 | { |
| 1005 | /* Handle mirrored mapping. */ |
| 1006 | if ((rank & 1) && (info->spd[channel][slot][RANK1_ADDRESS_MAPPING] & 1)) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1007 | addr3 = (addr3 & 0xCF) | ((addr3 & 0x10) << 1) | |
| 1008 | ((addr3 >> 1) & 0x10); |
| 1009 | MCHBAR8(0x271) = addr3 | (MCHBAR8(0x271) & 0xC1); |
| 1010 | MCHBAR8(0x671) = addr3 | (MCHBAR8(0x671) & 0xC1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1011 | |
| 1012 | /* Handle mirrored mapping. */ |
| 1013 | if ((rank & 1) && (info->spd[channel][slot][RANK1_ADDRESS_MAPPING] & 1)) |
| 1014 | value = |
| 1015 | (value & ~0x1f8) | ((value >> 1) & 0xa8) | ((value & 0xa8) |
| 1016 | << 1); |
| 1017 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1018 | read32p((value << 3) | (total_rank << 28)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1019 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1020 | MCHBAR8(0x271) = (MCHBAR8(0x271) & 0xC3) | 2; |
| 1021 | MCHBAR8(0x671) = (MCHBAR8(0x671) & 0xC3) | 2; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1022 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1023 | read32p(total_rank << 28); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | enum { |
| 1027 | MR1_RZQ12 = 512, |
| 1028 | MR1_RZQ2 = 64, |
| 1029 | MR1_RZQ4 = 4, |
| 1030 | MR1_ODS34OHM = 2 |
| 1031 | }; |
| 1032 | |
| 1033 | enum { |
| 1034 | MR0_BT_INTERLEAVED = 8, |
| 1035 | MR0_DLL_RESET_ON = 256 |
| 1036 | }; |
| 1037 | |
| 1038 | enum { |
| 1039 | MR2_RTT_WR_DISABLED = 0, |
| 1040 | MR2_RZQ2 = 1 << 10 |
| 1041 | }; |
| 1042 | |
| 1043 | static void jedec_init(struct raminfo *info) |
| 1044 | { |
| 1045 | int write_recovery; |
| 1046 | int channel, slot, rank; |
| 1047 | int total_rank; |
| 1048 | int dll_on; |
| 1049 | int self_refresh_temperature; |
| 1050 | int auto_self_refresh; |
| 1051 | |
| 1052 | auto_self_refresh = 1; |
| 1053 | self_refresh_temperature = 1; |
| 1054 | if (info->board_lane_delay[3] <= 10) { |
| 1055 | if (info->board_lane_delay[3] <= 8) |
| 1056 | write_recovery = info->board_lane_delay[3] - 4; |
| 1057 | else |
| 1058 | write_recovery = 5; |
| 1059 | } else { |
| 1060 | write_recovery = 6; |
| 1061 | } |
| 1062 | FOR_POPULATED_RANKS { |
| 1063 | auto_self_refresh &= |
| 1064 | (info->spd[channel][slot][THERMAL_AND_REFRESH] >> 2) & 1; |
| 1065 | self_refresh_temperature &= |
| 1066 | info->spd[channel][slot][THERMAL_AND_REFRESH] & 1; |
| 1067 | } |
| 1068 | if (auto_self_refresh == 1) |
| 1069 | self_refresh_temperature = 0; |
| 1070 | |
| 1071 | dll_on = ((info->silicon_revision != 2 && info->silicon_revision != 3) |
| 1072 | || (info->populated_ranks[0][0][0] |
| 1073 | && info->populated_ranks[0][1][0]) |
| 1074 | || (info->populated_ranks[1][0][0] |
| 1075 | && info->populated_ranks[1][1][0])); |
| 1076 | |
| 1077 | total_rank = 0; |
| 1078 | |
| 1079 | for (channel = NUM_CHANNELS - 1; channel >= 0; channel--) { |
| 1080 | int rtt, rtt_wr = MR2_RTT_WR_DISABLED; |
| 1081 | int rzq_reg58e; |
| 1082 | |
| 1083 | if (info->silicon_revision == 2 || info->silicon_revision == 3) { |
| 1084 | rzq_reg58e = 64; |
| 1085 | rtt = MR1_RZQ2; |
| 1086 | if (info->clock_speed_index != 0) { |
| 1087 | rzq_reg58e = 4; |
| 1088 | if (info->populated_ranks_mask[channel] == 3) |
| 1089 | rtt = MR1_RZQ4; |
| 1090 | } |
| 1091 | } else { |
| 1092 | if ((info->populated_ranks_mask[channel] & 5) == 5) { |
| 1093 | rtt = MR1_RZQ12; |
| 1094 | rzq_reg58e = 64; |
| 1095 | rtt_wr = MR2_RZQ2; |
| 1096 | } else { |
| 1097 | rzq_reg58e = 4; |
| 1098 | rtt = MR1_RZQ4; |
| 1099 | } |
| 1100 | } |
| 1101 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1102 | MCHBAR16(0x588 + (channel << 10)) = 0x0; |
| 1103 | MCHBAR16(0x58a + (channel << 10)) = 0x4; |
| 1104 | MCHBAR16(0x58c + (channel << 10)) = rtt | MR1_ODS34OHM; |
| 1105 | MCHBAR16(0x58e + (channel << 10)) = rzq_reg58e | 0x82; |
| 1106 | MCHBAR16(0x590 + (channel << 10)) = 0x1282; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1107 | |
| 1108 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 1109 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 1110 | if (info->populated_ranks[channel][slot][rank]) { |
| 1111 | jedec_read(info, channel, slot, rank, |
| 1112 | total_rank, 0x28, |
| 1113 | rtt_wr | (info-> |
| 1114 | clock_speed_index |
| 1115 | << 3) |
| 1116 | | (auto_self_refresh << 6) | |
| 1117 | (self_refresh_temperature << |
| 1118 | 7)); |
| 1119 | jedec_read(info, channel, slot, rank, |
| 1120 | total_rank, 0x38, 0); |
| 1121 | jedec_read(info, channel, slot, rank, |
| 1122 | total_rank, 0x18, |
| 1123 | rtt | MR1_ODS34OHM); |
| 1124 | jedec_read(info, channel, slot, rank, |
| 1125 | total_rank, 6, |
| 1126 | (dll_on << 12) | |
| 1127 | (write_recovery << 9) |
| 1128 | | ((info->cas_latency - 4) << |
| 1129 | 4) | MR0_BT_INTERLEAVED | |
| 1130 | MR0_DLL_RESET_ON); |
| 1131 | total_rank++; |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | static void program_modules_memory_map(struct raminfo *info, int pre_jedec) |
| 1137 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 1138 | unsigned int channel, slot, rank; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1139 | unsigned int total_mb[2] = { 0, 0 }; /* total memory per channel in MB */ |
| 1140 | unsigned int channel_0_non_interleaved; |
| 1141 | |
| 1142 | FOR_ALL_RANKS { |
| 1143 | if (info->populated_ranks[channel][slot][rank]) { |
| 1144 | total_mb[channel] += |
| 1145 | pre_jedec ? 256 : (256 << info-> |
| 1146 | density[channel][slot] >> info-> |
| 1147 | is_x16_module[channel][slot]); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1148 | MCHBAR8(0x208 + rank + 2 * slot + (channel << 10)) = |
| 1149 | (pre_jedec ? (1 | ((1 + 1) << 1)) : |
| 1150 | (info->is_x16_module[channel][slot] | |
| 1151 | ((info->density[channel][slot] + 1) << 1))) | |
| 1152 | 0x80; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1153 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1154 | MCHBAR16(0x200 + (channel << 10) + 4 * slot + 2 * rank) = |
| 1155 | total_mb[channel] >> 6; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | info->total_memory_mb = total_mb[0] + total_mb[1]; |
| 1159 | |
| 1160 | info->interleaved_part_mb = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1161 | pre_jedec ? 0 : 2 * MIN(total_mb[0], total_mb[1]); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1162 | info->non_interleaved_part_mb = |
| 1163 | total_mb[0] + total_mb[1] - info->interleaved_part_mb; |
| 1164 | channel_0_non_interleaved = total_mb[0] - info->interleaved_part_mb / 2; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1165 | MCHBAR32(0x100) = channel_0_non_interleaved | |
| 1166 | (info->non_interleaved_part_mb << 16); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1167 | if (!pre_jedec) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1168 | MCHBAR16(0x104) = info->interleaved_part_mb; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static void program_board_delay(struct raminfo *info) |
| 1172 | { |
| 1173 | int cas_latency_shift; |
| 1174 | int some_delay_ns; |
| 1175 | int some_delay_3_half_cycles; |
| 1176 | |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 1177 | unsigned int channel, i; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1178 | int high_multiplier; |
| 1179 | int lane_3_delay; |
| 1180 | int cas_latency_derived; |
| 1181 | |
| 1182 | high_multiplier = 0; |
| 1183 | some_delay_ns = 200; |
| 1184 | some_delay_3_half_cycles = 4; |
| 1185 | cas_latency_shift = info->silicon_revision == 0 |
| 1186 | || info->silicon_revision == 1 ? 1 : 0; |
| 1187 | if (info->revision < 8) { |
| 1188 | some_delay_ns = 600; |
| 1189 | cas_latency_shift = 0; |
| 1190 | } |
| 1191 | { |
| 1192 | int speed_bit; |
| 1193 | speed_bit = |
| 1194 | ((info->clock_speed_index > 1 |
| 1195 | || (info->silicon_revision != 2 |
| 1196 | && info->silicon_revision != 3))) ^ (info->revision >= |
| 1197 | 0x10); |
| 1198 | write_500(info, 0, speed_bit | ((!info->use_ecc) << 1), 0x60e, |
| 1199 | 3, 1); |
| 1200 | write_500(info, 1, speed_bit | ((!info->use_ecc) << 1), 0x60e, |
| 1201 | 3, 1); |
| 1202 | if (info->revision >= 0x10 && info->clock_speed_index <= 1 |
| 1203 | && (info->silicon_revision == 2 |
| 1204 | || info->silicon_revision == 3)) |
| 1205 | rmw_1d0(0x116, 5, 2, 4, 1); |
| 1206 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1207 | MCHBAR32(0x120) = (1 << (info->max_slots_used_in_channel + 28)) | |
| 1208 | 0x188e7f9f; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1209 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1210 | MCHBAR8(0x124) = info->board_lane_delay[4] + |
| 1211 | ((frequency_01(info) + 999) / 1000); |
| 1212 | MCHBAR16(0x125) = 0x1360; |
| 1213 | MCHBAR8(0x127) = 0x40; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1214 | if (info->fsb_frequency < frequency_11(info) / 2) { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 1215 | unsigned int some_delay_2_half_cycles; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1216 | high_multiplier = 1; |
| 1217 | some_delay_2_half_cycles = ps_to_halfcycles(info, |
| 1218 | ((3 * |
| 1219 | fsbcycle_ps(info)) |
| 1220 | >> 1) + |
| 1221 | (halfcycle_ps(info) |
| 1222 | * |
| 1223 | reg178_min[info-> |
| 1224 | clock_speed_index] |
| 1225 | >> 6) |
| 1226 | + |
| 1227 | 4 * |
| 1228 | halfcycle_ps(info) |
| 1229 | + 2230); |
| 1230 | some_delay_3_half_cycles = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1231 | MIN((some_delay_2_half_cycles + |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1232 | (frequency_11(info) * 2) * (28 - |
| 1233 | some_delay_2_half_cycles) / |
| 1234 | (frequency_11(info) * 2 - |
| 1235 | 4 * (info->fsb_frequency))) >> 3, 7); |
| 1236 | } |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1237 | if (MCHBAR8(0x2ca9) & 1) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1238 | some_delay_3_half_cycles = 3; |
| 1239 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1240 | MCHBAR32_OR(0x220 + (channel << 10), 0x18001117); |
| 1241 | MCHBAR32(0x224 + (channel << 10)) = |
| 1242 | (info->max_slots_used_in_channel - 1) | |
| 1243 | ((info->cas_latency - 5 - info->clock_speed_index) |
| 1244 | << 21) | ((info->max_slots_used_in_channel + |
| 1245 | info->cas_latency - cas_latency_shift - 4) << 16) | |
| 1246 | ((info->cas_latency - cas_latency_shift - 4) << 26) | |
| 1247 | ((info->cas_latency - info->clock_speed_index + |
| 1248 | info->max_slots_used_in_channel - 6) << 8); |
| 1249 | MCHBAR32(0x228 + (channel << 10)) = |
| 1250 | info->max_slots_used_in_channel; |
| 1251 | MCHBAR8(0x239 + (channel << 10)) = 32; |
| 1252 | MCHBAR32(0x248 + (channel << 10)) = (high_multiplier << 24) | |
| 1253 | (some_delay_3_half_cycles << 25) | 0x840000; |
| 1254 | MCHBAR32(0x278 + (channel << 10)) = 0xc362042; |
| 1255 | MCHBAR32(0x27c + (channel << 10)) = 0x8b000062; |
| 1256 | MCHBAR32(0x24c + (channel << 10)) = |
| 1257 | ((!!info->clock_speed_index) << 17) | |
| 1258 | (((2 + info->clock_speed_index - |
| 1259 | (!!info->clock_speed_index))) << 12) | 0x10200; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1260 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1261 | MCHBAR8(0x267 + (channel << 10)) = 0x4; |
| 1262 | MCHBAR16(0x272 + (channel << 10)) = 0x155; |
| 1263 | MCHBAR32_AND_OR(0x2bc + (channel << 10), 0xFF000000, 0x707070); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1264 | |
| 1265 | write_500(info, channel, |
| 1266 | ((!info->populated_ranks[channel][1][1]) |
| 1267 | | (!info->populated_ranks[channel][1][0] << 1) |
| 1268 | | (!info->populated_ranks[channel][0][1] << 2) |
| 1269 | | (!info->populated_ranks[channel][0][0] << 3)), |
| 1270 | 0x4c9, 4, 1); |
| 1271 | } |
| 1272 | |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1273 | MCHBAR8(0x2c4) = ((1 + (info->clock_speed_index != 0)) << 6) | 0xC; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1274 | { |
| 1275 | u8 freq_divisor = 2; |
| 1276 | if (info->fsb_frequency == frequency_11(info)) |
| 1277 | freq_divisor = 3; |
| 1278 | else if (2 * info->fsb_frequency < 3 * (frequency_11(info) / 2)) |
| 1279 | freq_divisor = 1; |
| 1280 | else |
| 1281 | freq_divisor = 2; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1282 | MCHBAR32(0x2c0) = (freq_divisor << 11) | 0x6009c400; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | if (info->board_lane_delay[3] <= 10) { |
| 1286 | if (info->board_lane_delay[3] <= 8) |
| 1287 | lane_3_delay = info->board_lane_delay[3]; |
| 1288 | else |
| 1289 | lane_3_delay = 10; |
| 1290 | } else { |
| 1291 | lane_3_delay = 12; |
| 1292 | } |
| 1293 | cas_latency_derived = info->cas_latency - info->clock_speed_index + 2; |
| 1294 | if (info->clock_speed_index > 1) |
| 1295 | cas_latency_derived++; |
| 1296 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1297 | MCHBAR32(0x240 + (channel << 10)) = |
| 1298 | ((info->clock_speed_index == 0) * 0x11000) | |
| 1299 | 0x1002100 | ((2 + info->clock_speed_index) << 4) | |
| 1300 | (info->cas_latency - 3); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1301 | write_500(info, channel, (info->clock_speed_index << 1) | 1, |
| 1302 | 0x609, 6, 1); |
| 1303 | write_500(info, channel, |
| 1304 | info->clock_speed_index + 2 * info->cas_latency - 7, |
| 1305 | 0x601, 6, 1); |
| 1306 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1307 | MCHBAR32(0x250 + (channel << 10)) = |
| 1308 | ((lane_3_delay + info->clock_speed_index + 9) << 6) | |
| 1309 | (info->board_lane_delay[7] << 2) | |
| 1310 | (info->board_lane_delay[4] << 16) | |
| 1311 | (info->board_lane_delay[1] << 25) | |
| 1312 | (info->board_lane_delay[1] << 29) | 1; |
| 1313 | MCHBAR32(0x254 + (channel << 10)) = |
| 1314 | (info->board_lane_delay[1] >> 3) | |
| 1315 | ((info->board_lane_delay[8] + 4 * info->use_ecc) << 6) | |
| 1316 | 0x80 | (info->board_lane_delay[6] << 1) | |
| 1317 | (info->board_lane_delay[2] << 28) | |
| 1318 | (cas_latency_derived << 16) | 0x4700000; |
| 1319 | MCHBAR32(0x258 + (channel << 10)) = |
| 1320 | ((info->board_lane_delay[5] + info->clock_speed_index + |
| 1321 | 9) << 12) | ((info->clock_speed_index - |
| 1322 | info->cas_latency + 12) << 8) | |
| 1323 | (info->board_lane_delay[2] << 17) | |
| 1324 | (info->board_lane_delay[4] << 24) | 0x47; |
| 1325 | MCHBAR32(0x25c + (channel << 10)) = |
| 1326 | (info->board_lane_delay[1] << 1) | |
| 1327 | (info->board_lane_delay[0] << 8) | 0x1da50000; |
| 1328 | MCHBAR8(0x264 + (channel << 10)) = 0xff; |
| 1329 | MCHBAR8(0x5f8 + (channel << 10)) = |
| 1330 | (cas_latency_shift << 3) | info->use_ecc; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | program_modules_memory_map(info, 1); |
| 1334 | |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1335 | MCHBAR16(0x610) = (MIN(ns_to_cycles(info, some_delay_ns) / 2, 127) << 9) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1336 | | (MCHBAR16(0x610) & 0x1C3) | 0x3C; |
| 1337 | MCHBAR16_OR(0x612, 0x100); |
| 1338 | MCHBAR16_OR(0x214, 0x3E00); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1339 | for (i = 0; i < 8; i++) { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1340 | pci_write_config32(PCI_DEV (QUICKPATH_BUS, 0, 1), 0x80 + 4 * i, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1341 | (info->total_memory_mb - 64) | !i | 2); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1342 | pci_write_config32(PCI_DEV (QUICKPATH_BUS, 0, 1), 0xc0 + 4 * i, 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1346 | #define DEFAULT_PCI_MMIO_SIZE 2048 |
| 1347 | #define HOST_BRIDGE PCI_DEVFN(0, 0) |
| 1348 | |
| 1349 | static unsigned int get_mmio_size(void) |
| 1350 | { |
| 1351 | const struct device *dev; |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 1352 | const struct northbridge_intel_ironlake_config *cfg = NULL; |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1353 | |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 1354 | dev = pcidev_path_on_root(HOST_BRIDGE); |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1355 | if (dev) |
| 1356 | cfg = dev->chip_info; |
| 1357 | |
| 1358 | /* If this is zero, it just means devicetree.cb didn't set it */ |
| 1359 | if (!cfg || cfg->pci_mmio_size == 0) |
| 1360 | return DEFAULT_PCI_MMIO_SIZE; |
| 1361 | else |
| 1362 | return cfg->pci_mmio_size; |
| 1363 | } |
| 1364 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1365 | #define BETTER_MEMORY_MAP 0 |
| 1366 | |
| 1367 | static void program_total_memory_map(struct raminfo *info) |
| 1368 | { |
| 1369 | unsigned int TOM, TOLUD, TOUUD; |
| 1370 | unsigned int quickpath_reserved; |
| 1371 | unsigned int REMAPbase; |
| 1372 | unsigned int uma_base_igd; |
| 1373 | unsigned int uma_base_gtt; |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1374 | unsigned int mmio_size; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1375 | int memory_remap; |
| 1376 | unsigned int memory_map[8]; |
| 1377 | int i; |
| 1378 | unsigned int current_limit; |
| 1379 | unsigned int tseg_base; |
| 1380 | int uma_size_igd = 0, uma_size_gtt = 0; |
| 1381 | |
| 1382 | memset(memory_map, 0, sizeof(memory_map)); |
| 1383 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1384 | if (info->uma_enabled) { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1385 | u16 t = pci_read_config16(NORTHBRIDGE, D0F0_GGC); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1386 | gav(t); |
| 1387 | const int uma_sizes_gtt[16] = |
| 1388 | { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 }; |
| 1389 | /* Igd memory */ |
| 1390 | const int uma_sizes_igd[16] = { |
| 1391 | 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, |
| 1392 | 256, 512 |
| 1393 | }; |
| 1394 | |
| 1395 | uma_size_igd = uma_sizes_igd[(t >> 4) & 0xF]; |
| 1396 | uma_size_gtt = uma_sizes_gtt[(t >> 8) & 0xF]; |
| 1397 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1398 | |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1399 | mmio_size = get_mmio_size(); |
| 1400 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1401 | TOM = info->total_memory_mb; |
| 1402 | if (TOM == 4096) |
| 1403 | TOM = 4032; |
| 1404 | TOUUD = ALIGN_DOWN(TOM - info->memory_reserved_for_heci_mb, 64); |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1405 | TOLUD = ALIGN_DOWN(MIN(4096 - mmio_size + ALIGN_UP(uma_size_igd + uma_size_gtt, 64) |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 1406 | , TOUUD), 64); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1407 | memory_remap = 0; |
| 1408 | if (TOUUD - TOLUD > 64) { |
| 1409 | memory_remap = 1; |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1410 | REMAPbase = MAX(4096, TOUUD); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1411 | TOUUD = TOUUD - TOLUD + 4096; |
| 1412 | } |
| 1413 | if (TOUUD > 4096) |
| 1414 | memory_map[2] = TOUUD | 1; |
| 1415 | quickpath_reserved = 0; |
| 1416 | |
Jacob Garber | 975a7e3 | 2019-06-10 16:32:47 -0600 | [diff] [blame] | 1417 | u32 t = pci_read_config32(PCI_DEV(QUICKPATH_BUS, 0, 1), 0x68); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1418 | |
Jacob Garber | 975a7e3 | 2019-06-10 16:32:47 -0600 | [diff] [blame] | 1419 | gav(t); |
| 1420 | |
| 1421 | if (t & 0x800) { |
| 1422 | u32 shift = t >> 20; |
| 1423 | if (shift == 0) |
| 1424 | die("Quickpath value is 0\n"); |
| 1425 | quickpath_reserved = (u32)1 << find_lowest_bit_set32(shift); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1426 | } |
Jacob Garber | 975a7e3 | 2019-06-10 16:32:47 -0600 | [diff] [blame] | 1427 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1428 | if (memory_remap) |
| 1429 | TOUUD -= quickpath_reserved; |
| 1430 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1431 | uma_base_igd = TOLUD - uma_size_igd; |
| 1432 | uma_base_gtt = uma_base_igd - uma_size_gtt; |
| 1433 | tseg_base = ALIGN_DOWN(uma_base_gtt, 64) - (CONFIG_SMM_TSEG_SIZE >> 20); |
| 1434 | if (!memory_remap) |
| 1435 | tseg_base -= quickpath_reserved; |
| 1436 | tseg_base = ALIGN_DOWN(tseg_base, 8); |
| 1437 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1438 | pci_write_config16(NORTHBRIDGE, D0F0_TOLUD, TOLUD << 4); |
| 1439 | pci_write_config16(NORTHBRIDGE, D0F0_TOM, TOM >> 6); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1440 | if (memory_remap) { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1441 | pci_write_config16(NORTHBRIDGE, D0F0_REMAPBASE, REMAPbase >> 6); |
| 1442 | pci_write_config16(NORTHBRIDGE, D0F0_REMAPLIMIT, (TOUUD - 64) >> 6); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1443 | } |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1444 | pci_write_config16(NORTHBRIDGE, D0F0_TOUUD, TOUUD); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1445 | |
| 1446 | if (info->uma_enabled) { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1447 | pci_write_config32(NORTHBRIDGE, D0F0_IGD_BASE, uma_base_igd << 20); |
| 1448 | pci_write_config32(NORTHBRIDGE, D0F0_GTT_BASE, uma_base_gtt << 20); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1449 | } |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1450 | pci_write_config32(NORTHBRIDGE, TSEG, tseg_base << 20); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1451 | |
| 1452 | current_limit = 0; |
| 1453 | memory_map[0] = ALIGN_DOWN(uma_base_gtt, 64) | 1; |
| 1454 | memory_map[1] = 4096; |
| 1455 | for (i = 0; i < ARRAY_SIZE(memory_map); i++) { |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 1456 | current_limit = MAX(current_limit, memory_map[i] & ~1); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1457 | pci_write_config32(PCI_DEV(QUICKPATH_BUS, 0, 1), 4 * i + 0x80, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1458 | (memory_map[i] & 1) | ALIGN_DOWN(current_limit - |
| 1459 | 1, 64) | 2); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1460 | pci_write_config32(PCI_DEV(QUICKPATH_BUS, 0, 1), 4 * i + 0xc0, 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | static void collect_system_info(struct raminfo *info) |
| 1465 | { |
| 1466 | u32 capid0[3]; |
| 1467 | int i; |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 1468 | unsigned int channel; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1469 | |
| 1470 | /* Wait for some bit, maybe TXT clear. */ |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1471 | while (!(read8((u8 *)0xfed40000) & (1 << 7))) |
| 1472 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1473 | |
| 1474 | if (!info->heci_bar) |
| 1475 | gav(info->heci_bar = |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1476 | pci_read_config32(HECIDEV, HECIBAR) & 0xFFFFFFF8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1477 | if (!info->memory_reserved_for_heci_mb) { |
| 1478 | /* Wait for ME to be ready */ |
| 1479 | intel_early_me_init(); |
| 1480 | info->memory_reserved_for_heci_mb = intel_early_me_uma_size(); |
| 1481 | } |
| 1482 | |
| 1483 | for (i = 0; i < 3; i++) |
| 1484 | gav(capid0[i] = |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1485 | pci_read_config32(NORTHBRIDGE, D0F0_CAPID0 | (i << 2))); |
| 1486 | gav(info->revision = pci_read_config8(NORTHBRIDGE, PCI_REVISION_ID)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1487 | info->max_supported_clock_speed_index = (~capid0[1] & 7); |
| 1488 | |
| 1489 | if ((capid0[1] >> 11) & 1) |
| 1490 | info->uma_enabled = 0; |
| 1491 | else |
| 1492 | gav(info->uma_enabled = |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1493 | pci_read_config8(NORTHBRIDGE, D0F0_DEVEN) & 8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1494 | /* Unrecognised: [0000:fffd3d2d] 37f81.37f82 ! CPUID: eax: 00000001; ecx: 00000e00 => 00020655.00010800.029ae3ff.bfebfbff */ |
| 1495 | info->silicon_revision = 0; |
| 1496 | |
| 1497 | if (capid0[2] & 2) { |
| 1498 | info->silicon_revision = 0; |
| 1499 | info->max_supported_clock_speed_index = 2; |
| 1500 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 1501 | if (info->populated_ranks[channel][0][0] |
| 1502 | && (info->spd[channel][0][MODULE_TYPE] & 0xf) == |
| 1503 | 3) { |
| 1504 | info->silicon_revision = 2; |
| 1505 | info->max_supported_clock_speed_index = 1; |
| 1506 | } |
| 1507 | } else { |
| 1508 | switch (((capid0[2] >> 18) & 1) + 2 * ((capid0[1] >> 3) & 1)) { |
| 1509 | case 1: |
| 1510 | case 2: |
| 1511 | info->silicon_revision = 3; |
| 1512 | break; |
| 1513 | case 3: |
| 1514 | info->silicon_revision = 0; |
| 1515 | break; |
| 1516 | case 0: |
| 1517 | info->silicon_revision = 2; |
| 1518 | break; |
| 1519 | } |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1520 | switch (pci_read_config16(NORTHBRIDGE, PCI_DEVICE_ID)) { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1521 | case 0x40: |
| 1522 | info->silicon_revision = 0; |
| 1523 | break; |
| 1524 | case 0x48: |
| 1525 | info->silicon_revision = 1; |
| 1526 | break; |
| 1527 | } |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | static void write_training_data(struct raminfo *info) |
| 1532 | { |
| 1533 | int tm, channel, slot, rank, lane; |
| 1534 | if (info->revision < 8) |
| 1535 | return; |
| 1536 | |
| 1537 | for (tm = 0; tm < 4; tm++) |
| 1538 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 1539 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 1540 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 1541 | for (lane = 0; lane < 9; lane++) |
| 1542 | write_500(info, channel, |
| 1543 | info-> |
| 1544 | cached_training-> |
| 1545 | lane_timings[tm] |
| 1546 | [channel][slot][rank] |
| 1547 | [lane], |
| 1548 | get_timing_register_addr |
| 1549 | (lane, tm, slot, |
| 1550 | rank), 9, 0); |
| 1551 | write_1d0(info->cached_training->reg_178, 0x178, 7, 1); |
| 1552 | write_1d0(info->cached_training->reg_10b, 0x10b, 6, 1); |
| 1553 | } |
| 1554 | |
| 1555 | static void dump_timings(struct raminfo *info) |
| 1556 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1557 | int channel, slot, rank, lane, i; |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1558 | printk(RAM_SPEW, "Timings:\n"); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1559 | FOR_POPULATED_RANKS { |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1560 | printk(RAM_SPEW, "channel %d, slot %d, rank %d\n", channel, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1561 | slot, rank); |
| 1562 | for (lane = 0; lane < 9; lane++) { |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1563 | printk(RAM_SPEW, "lane %d: ", lane); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1564 | for (i = 0; i < 4; i++) { |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1565 | printk(RAM_SPEW, "%x (%x) ", |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1566 | read_500(info, channel, |
| 1567 | get_timing_register_addr |
| 1568 | (lane, i, slot, rank), |
| 1569 | 9), |
| 1570 | info->training. |
| 1571 | lane_timings[i][channel][slot][rank] |
| 1572 | [lane]); |
| 1573 | } |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1574 | printk(RAM_SPEW, "\n"); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1575 | } |
| 1576 | } |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1577 | printk(RAM_SPEW, "[178] = %x (%x)\n", read_1d0(0x178, 7), |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1578 | info->training.reg_178); |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 1579 | printk(RAM_SPEW, "[10b] = %x (%x)\n", read_1d0(0x10b, 6), |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1580 | info->training.reg_10b); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1583 | /* Read timings and other registers that need to be restored verbatim and |
| 1584 | put them to CBMEM. |
| 1585 | */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1586 | static void save_timings(struct raminfo *info) |
| 1587 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1588 | struct ram_training train; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1589 | int channel, slot, rank, lane, i; |
| 1590 | |
| 1591 | train = info->training; |
| 1592 | FOR_POPULATED_RANKS for (lane = 0; lane < 9; lane++) |
| 1593 | for (i = 0; i < 4; i++) |
| 1594 | train.lane_timings[i][channel][slot][rank][lane] = |
| 1595 | read_500(info, channel, |
| 1596 | get_timing_register_addr(lane, i, slot, |
| 1597 | rank), 9); |
| 1598 | train.reg_178 = read_1d0(0x178, 7); |
| 1599 | train.reg_10b = read_1d0(0x10b, 6); |
| 1600 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1601 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 1602 | u32 reg32; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1603 | reg32 = MCHBAR32((channel << 10) + 0x274); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1604 | train.reg274265[channel][0] = reg32 >> 16; |
| 1605 | train.reg274265[channel][1] = reg32 & 0xffff; |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1606 | train.reg274265[channel][2] = |
| 1607 | MCHBAR16((channel << 10) + 0x265) >> 8; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1608 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1609 | train.reg2ca9_bit0 = MCHBAR8(0x2ca9) & 1; |
| 1610 | train.reg_6dc = MCHBAR32(0x6dc); |
| 1611 | train.reg_6e8 = MCHBAR32(0x6e8); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1612 | |
Arthur Heymans | b328209 | 2019-04-14 17:53:28 +0200 | [diff] [blame] | 1613 | printk(RAM_SPEW, "[6dc] = %x\n", train.reg_6dc); |
| 1614 | printk(RAM_SPEW, "[6e8] = %x\n", train.reg_6e8); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 1615 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1616 | /* Save the MRC S3 restore data to cbmem */ |
Arthur Heymans | dc71e25 | 2018-01-29 10:14:48 +0100 | [diff] [blame] | 1617 | mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, |
| 1618 | &train, sizeof(train)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1621 | static const struct ram_training *get_cached_training(void) |
| 1622 | { |
Arthur Heymans | dc71e25 | 2018-01-29 10:14:48 +0100 | [diff] [blame] | 1623 | struct region_device rdev; |
| 1624 | if (mrc_cache_get_current(MRC_TRAINING_DATA, MRC_CACHE_VERSION, |
| 1625 | &rdev)) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1626 | return 0; |
Arthur Heymans | dc71e25 | 2018-01-29 10:14:48 +0100 | [diff] [blame] | 1627 | return (void *)rdev_mmap_full(&rdev); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1628 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1629 | |
| 1630 | /* FIXME: add timeout. */ |
| 1631 | static void wait_heci_ready(void) |
| 1632 | { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1633 | while (!(read32(DEFAULT_HECIBAR + 0xc) & 8)) // = 0x8000000c |
| 1634 | ; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1635 | write32((DEFAULT_HECIBAR + 0x4), |
| 1636 | (read32(DEFAULT_HECIBAR + 0x4) & ~0x10) | 0xc); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | /* FIXME: add timeout. */ |
| 1640 | static void wait_heci_cb_avail(int len) |
| 1641 | { |
| 1642 | union { |
| 1643 | struct mei_csr csr; |
| 1644 | u32 raw; |
| 1645 | } csr; |
| 1646 | |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1647 | while (!(read32(DEFAULT_HECIBAR + 0xc) & 8)) |
| 1648 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1649 | |
| 1650 | do |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1651 | csr.raw = read32(DEFAULT_HECIBAR + 0x4); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1652 | while (len > |
| 1653 | csr.csr.buffer_depth - (csr.csr.buffer_write_ptr - |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1654 | csr.csr.buffer_read_ptr)) |
| 1655 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
Elyes HAOUAS | fd051dc | 2018-07-08 12:39:34 +0200 | [diff] [blame] | 1658 | static void send_heci_packet(struct mei_header *head, u32 *payload) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1659 | { |
| 1660 | int len = (head->length + 3) / 4; |
| 1661 | int i; |
| 1662 | |
| 1663 | wait_heci_cb_avail(len + 1); |
| 1664 | |
| 1665 | /* FIXME: handle leftovers correctly. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1666 | write32(DEFAULT_HECIBAR + 0, *(u32 *) head); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1667 | for (i = 0; i < len - 1; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1668 | write32(DEFAULT_HECIBAR + 0, payload[i]); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1669 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1670 | write32(DEFAULT_HECIBAR + 0, payload[i] & ((1 << (8 * len)) - 1)); |
| 1671 | write32(DEFAULT_HECIBAR + 0x4, read32(DEFAULT_HECIBAR + 0x4) | 0x4); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | static void |
Elyes HAOUAS | fd051dc | 2018-07-08 12:39:34 +0200 | [diff] [blame] | 1675 | send_heci_message(u8 *msg, int len, u8 hostaddress, u8 clientaddress) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1676 | { |
| 1677 | struct mei_header head; |
| 1678 | int maxlen; |
| 1679 | |
| 1680 | wait_heci_ready(); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1681 | maxlen = (read32(DEFAULT_HECIBAR + 0x4) >> 24) * 4 - 4; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1682 | |
| 1683 | while (len) { |
| 1684 | int cur = len; |
| 1685 | if (cur > maxlen) { |
| 1686 | cur = maxlen; |
| 1687 | head.is_complete = 0; |
| 1688 | } else |
| 1689 | head.is_complete = 1; |
| 1690 | head.length = cur; |
| 1691 | head.reserved = 0; |
| 1692 | head.client_address = clientaddress; |
| 1693 | head.host_address = hostaddress; |
| 1694 | send_heci_packet(&head, (u32 *) msg); |
| 1695 | len -= cur; |
| 1696 | msg += cur; |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | /* FIXME: Add timeout. */ |
| 1701 | static int |
Elyes HAOUAS | fd051dc | 2018-07-08 12:39:34 +0200 | [diff] [blame] | 1702 | recv_heci_packet(struct raminfo *info, struct mei_header *head, u32 *packet, |
| 1703 | u32 *packet_size) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1704 | { |
| 1705 | union { |
| 1706 | struct mei_csr csr; |
| 1707 | u32 raw; |
| 1708 | } csr; |
| 1709 | int i = 0; |
| 1710 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1711 | write32(DEFAULT_HECIBAR + 0x4, read32(DEFAULT_HECIBAR + 0x4) | 2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1712 | do { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1713 | csr.raw = read32(DEFAULT_HECIBAR + 0xc); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1714 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1715 | while (csr.csr.buffer_write_ptr == csr.csr.buffer_read_ptr) |
| 1716 | ; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1717 | *(u32 *) head = read32(DEFAULT_HECIBAR + 0x8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1718 | if (!head->length) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1719 | write32(DEFAULT_HECIBAR + 0x4, |
| 1720 | read32(DEFAULT_HECIBAR + 0x4) | 2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1721 | *packet_size = 0; |
| 1722 | return 0; |
| 1723 | } |
| 1724 | if (head->length + 4 > 4 * csr.csr.buffer_depth |
| 1725 | || head->length > *packet_size) { |
| 1726 | *packet_size = 0; |
| 1727 | return -1; |
| 1728 | } |
| 1729 | |
| 1730 | do |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1731 | csr.raw = read32(DEFAULT_HECIBAR + 0xc); |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 1732 | while (((head->length + 3) >> 2) > |
| 1733 | (csr.csr.buffer_write_ptr - csr.csr.buffer_read_ptr)) |
| 1734 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1735 | |
| 1736 | for (i = 0; i < (head->length + 3) >> 2; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1737 | packet[i++] = read32(DEFAULT_HECIBAR + 0x8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1738 | *packet_size = head->length; |
| 1739 | if (!csr.csr.ready) |
| 1740 | *packet_size = 0; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1741 | write32(DEFAULT_HECIBAR + 0x4, read32(DEFAULT_HECIBAR + 0x4) | 4); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1742 | return 0; |
| 1743 | } |
| 1744 | |
| 1745 | /* FIXME: Add timeout. */ |
| 1746 | static int |
Elyes HAOUAS | fd051dc | 2018-07-08 12:39:34 +0200 | [diff] [blame] | 1747 | recv_heci_message(struct raminfo *info, u32 *message, u32 *message_size) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1748 | { |
| 1749 | struct mei_header head; |
| 1750 | int current_position; |
| 1751 | |
| 1752 | current_position = 0; |
| 1753 | while (1) { |
| 1754 | u32 current_size; |
| 1755 | current_size = *message_size - current_position; |
| 1756 | if (recv_heci_packet |
| 1757 | (info, &head, message + (current_position >> 2), |
| 1758 | ¤t_size) == -1) |
| 1759 | break; |
| 1760 | if (!current_size) |
| 1761 | break; |
| 1762 | current_position += current_size; |
| 1763 | if (head.is_complete) { |
| 1764 | *message_size = current_position; |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | if (current_position >= *message_size) |
| 1769 | break; |
| 1770 | } |
| 1771 | *message_size = 0; |
| 1772 | return -1; |
| 1773 | } |
| 1774 | |
| 1775 | static void send_heci_uma_message(struct raminfo *info) |
| 1776 | { |
| 1777 | struct uma_reply { |
| 1778 | u8 group_id; |
| 1779 | u8 command; |
| 1780 | u8 reserved; |
| 1781 | u8 result; |
| 1782 | u8 field2; |
| 1783 | u8 unk3[0x48 - 4 - 1]; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 1784 | } __packed reply; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1785 | struct uma_message { |
| 1786 | u8 group_id; |
| 1787 | u8 cmd; |
| 1788 | u8 reserved; |
| 1789 | u8 result; |
| 1790 | u32 c2; |
| 1791 | u64 heci_uma_addr; |
| 1792 | u32 memory_reserved_for_heci_mb; |
| 1793 | u16 c3; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 1794 | } __packed msg = { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1795 | 0, MKHI_SET_UMA, 0, 0, |
| 1796 | 0x82, |
| 1797 | info->heci_uma_addr, info->memory_reserved_for_heci_mb, 0}; |
| 1798 | u32 reply_size; |
| 1799 | |
| 1800 | send_heci_message((u8 *) & msg, sizeof(msg), 0, 7); |
| 1801 | |
| 1802 | reply_size = sizeof(reply); |
| 1803 | if (recv_heci_message(info, (u32 *) & reply, &reply_size) == -1) |
| 1804 | return; |
| 1805 | |
| 1806 | if (reply.command != (MKHI_SET_UMA | (1 << 7))) |
| 1807 | die("HECI init failed\n"); |
| 1808 | } |
| 1809 | |
| 1810 | static void setup_heci_uma(struct raminfo *info) |
| 1811 | { |
| 1812 | u32 reg44; |
| 1813 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1814 | reg44 = pci_read_config32(HECIDEV, 0x44); // = 0x80010020 |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1815 | info->memory_reserved_for_heci_mb = 0; |
| 1816 | info->heci_uma_addr = 0; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1817 | if (!((reg44 & 0x10000) && !(pci_read_config32(HECIDEV, 0x40) & 0x20))) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1818 | return; |
| 1819 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1820 | info->heci_bar = pci_read_config32(HECIDEV, 0x10) & 0xFFFFFFF0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1821 | info->memory_reserved_for_heci_mb = reg44 & 0x3f; |
| 1822 | info->heci_uma_addr = |
| 1823 | ((u64) |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1824 | ((((u64) pci_read_config16(NORTHBRIDGE, D0F0_TOM)) << 6) - |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1825 | info->memory_reserved_for_heci_mb)) << 20; |
| 1826 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1827 | pci_read_config32(NORTHBRIDGE, DMIBAR); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1828 | if (info->memory_reserved_for_heci_mb) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1829 | write32(DEFAULT_DMIBAR + 0x14, |
| 1830 | read32(DEFAULT_DMIBAR + 0x14) & ~0x80); |
| 1831 | write32(DEFAULT_RCBA + 0x14, |
| 1832 | read32(DEFAULT_RCBA + 0x14) & ~0x80); |
| 1833 | write32(DEFAULT_DMIBAR + 0x20, |
| 1834 | read32(DEFAULT_DMIBAR + 0x20) & ~0x80); |
| 1835 | write32(DEFAULT_RCBA + 0x20, |
| 1836 | read32(DEFAULT_RCBA + 0x20) & ~0x80); |
| 1837 | write32(DEFAULT_DMIBAR + 0x2c, |
| 1838 | read32(DEFAULT_DMIBAR + 0x2c) & ~0x80); |
| 1839 | write32(DEFAULT_RCBA + 0x30, |
| 1840 | read32(DEFAULT_RCBA + 0x30) & ~0x80); |
| 1841 | write32(DEFAULT_DMIBAR + 0x38, |
| 1842 | read32(DEFAULT_DMIBAR + 0x38) & ~0x80); |
| 1843 | write32(DEFAULT_RCBA + 0x40, |
| 1844 | read32(DEFAULT_RCBA + 0x40) & ~0x80); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1845 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1846 | write32(DEFAULT_RCBA + 0x40, 0x87000080); // OK |
| 1847 | write32(DEFAULT_DMIBAR + 0x38, 0x87000080); // OK |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1848 | while ((read16(DEFAULT_RCBA + 0x46) & 2) && |
| 1849 | read16(DEFAULT_DMIBAR + 0x3e) & 2) |
| 1850 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1851 | } |
| 1852 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 1853 | MCHBAR32(0x24) = 0x10000 + info->memory_reserved_for_heci_mb; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1854 | |
| 1855 | send_heci_uma_message(info); |
| 1856 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1857 | pci_write_config32(HECIDEV, 0x10, 0x0); |
| 1858 | pci_write_config8(HECIDEV, 0x4, 0x0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1859 | |
| 1860 | } |
| 1861 | |
| 1862 | static int have_match_ranks(struct raminfo *info, int channel, int ranks) |
| 1863 | { |
| 1864 | int ranks_in_channel; |
| 1865 | ranks_in_channel = info->populated_ranks[channel][0][0] |
| 1866 | + info->populated_ranks[channel][0][1] |
| 1867 | + info->populated_ranks[channel][1][0] |
| 1868 | + info->populated_ranks[channel][1][1]; |
| 1869 | |
| 1870 | /* empty channel */ |
| 1871 | if (ranks_in_channel == 0) |
| 1872 | return 1; |
| 1873 | |
| 1874 | if (ranks_in_channel != ranks) |
| 1875 | return 0; |
| 1876 | /* single slot */ |
| 1877 | if (info->populated_ranks[channel][0][0] != |
| 1878 | info->populated_ranks[channel][1][0]) |
| 1879 | return 1; |
| 1880 | if (info->populated_ranks[channel][0][1] != |
| 1881 | info->populated_ranks[channel][1][1]) |
| 1882 | return 1; |
| 1883 | if (info->is_x16_module[channel][0] != info->is_x16_module[channel][1]) |
| 1884 | return 0; |
| 1885 | if (info->density[channel][0] != info->density[channel][1]) |
| 1886 | return 0; |
| 1887 | return 1; |
| 1888 | } |
| 1889 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1890 | static void read_4090(struct raminfo *info) |
| 1891 | { |
| 1892 | int i, channel, slot, rank, lane; |
| 1893 | for (i = 0; i < 2; i++) |
| 1894 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 1895 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 1896 | for (lane = 0; lane < 9; lane++) |
| 1897 | info->training. |
| 1898 | lane_timings[0][i][slot][rank][lane] |
| 1899 | = 32; |
| 1900 | |
| 1901 | for (i = 1; i < 4; i++) |
| 1902 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 1903 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 1904 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 1905 | for (lane = 0; lane < 9; lane++) { |
| 1906 | info->training. |
| 1907 | lane_timings[i][channel] |
| 1908 | [slot][rank][lane] = |
| 1909 | read_500(info, channel, |
| 1910 | get_timing_register_addr |
| 1911 | (lane, i, slot, |
| 1912 | rank), 9) |
| 1913 | + (i == 1) * 11; // !!!! |
| 1914 | } |
| 1915 | |
| 1916 | } |
| 1917 | |
| 1918 | static u32 get_etalon2(int flip, u32 addr) |
| 1919 | { |
| 1920 | const u16 invmask[] = { |
| 1921 | 0xaaaa, 0x6db6, 0x4924, 0xeeee, 0xcccc, 0x8888, 0x7bde, 0x739c, |
| 1922 | 0x6318, 0x4210, 0xefbe, 0xcf3c, 0x8e38, 0x0c30, 0x0820 |
| 1923 | }; |
| 1924 | u32 ret; |
| 1925 | u32 comp4 = addr / 480; |
| 1926 | addr %= 480; |
| 1927 | u32 comp1 = addr & 0xf; |
| 1928 | u32 comp2 = (addr >> 4) & 1; |
| 1929 | u32 comp3 = addr >> 5; |
| 1930 | |
| 1931 | if (comp4) |
| 1932 | ret = 0x1010101 << (comp4 - 1); |
| 1933 | else |
| 1934 | ret = 0; |
| 1935 | if (flip ^ (((invmask[comp3] >> comp1) ^ comp2) & 1)) |
| 1936 | ret = ~ret; |
| 1937 | |
| 1938 | return ret; |
| 1939 | } |
| 1940 | |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 1941 | static void disable_cache_region(void) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1942 | { |
| 1943 | msr_t msr = {.lo = 0, .hi = 0 }; |
| 1944 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 1945 | wrmsr(MTRR_PHYS_BASE(3), msr); |
| 1946 | wrmsr(MTRR_PHYS_MASK(3), msr); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1947 | } |
| 1948 | |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 1949 | static void enable_cache_region(unsigned int base, unsigned int size) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1950 | { |
| 1951 | msr_t msr; |
| 1952 | msr.lo = base | MTRR_TYPE_WRPROT; |
| 1953 | msr.hi = 0; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 1954 | wrmsr(MTRR_PHYS_BASE(3), msr); |
| 1955 | msr.lo = ((~(ALIGN_DOWN(size + 4096, 4096) - 1) | MTRR_DEF_TYPE_EN) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1956 | & 0xffffffff); |
| 1957 | msr.hi = 0x0000000f; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 1958 | wrmsr(MTRR_PHYS_MASK(3), msr); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | static void flush_cache(u32 start, u32 size) |
| 1962 | { |
| 1963 | u32 end; |
| 1964 | u32 addr; |
| 1965 | |
| 1966 | end = start + (ALIGN_DOWN(size + 4096, 4096)); |
| 1967 | for (addr = start; addr < end; addr += 64) |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 1968 | clflush((void *)addr); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static void clear_errors(void) |
| 1972 | { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 1973 | pci_write_config8(NORTHBRIDGE, 0xc0, 0x01); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | static void write_testing(struct raminfo *info, int totalrank, int flip) |
| 1977 | { |
| 1978 | int nwrites = 0; |
| 1979 | /* in 8-byte units. */ |
| 1980 | u32 offset; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1981 | u8 *base; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1982 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1983 | base = (u8 *)(totalrank << 28); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1984 | for (offset = 0; offset < 9 * 480; offset += 2) { |
| 1985 | write32(base + offset * 8, get_etalon2(flip, offset)); |
| 1986 | write32(base + offset * 8 + 4, get_etalon2(flip, offset)); |
| 1987 | write32(base + offset * 8 + 8, get_etalon2(flip, offset + 1)); |
| 1988 | write32(base + offset * 8 + 12, get_etalon2(flip, offset + 1)); |
| 1989 | nwrites += 4; |
| 1990 | if (nwrites >= 320) { |
| 1991 | clear_errors(); |
| 1992 | nwrites = 0; |
| 1993 | } |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | static u8 check_testing(struct raminfo *info, u8 total_rank, int flip) |
| 1998 | { |
| 1999 | u8 failmask = 0; |
| 2000 | int i; |
| 2001 | int comp1, comp2, comp3; |
| 2002 | u32 failxor[2] = { 0, 0 }; |
| 2003 | |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 2004 | enable_cache_region((total_rank << 28), 1728 * 5 * 4); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2005 | |
| 2006 | for (comp3 = 0; comp3 < 9 && failmask != 0xff; comp3++) { |
| 2007 | for (comp1 = 0; comp1 < 4; comp1++) |
| 2008 | for (comp2 = 0; comp2 < 60; comp2++) { |
| 2009 | u32 re[4]; |
| 2010 | u32 curroffset = |
| 2011 | comp3 * 8 * 60 + 2 * comp1 + 8 * comp2; |
| 2012 | read128((total_rank << 28) | (curroffset << 3), |
| 2013 | (u64 *) re); |
| 2014 | failxor[0] |= |
| 2015 | get_etalon2(flip, curroffset) ^ re[0]; |
| 2016 | failxor[1] |= |
| 2017 | get_etalon2(flip, curroffset) ^ re[1]; |
| 2018 | failxor[0] |= |
| 2019 | get_etalon2(flip, curroffset | 1) ^ re[2]; |
| 2020 | failxor[1] |= |
| 2021 | get_etalon2(flip, curroffset | 1) ^ re[3]; |
| 2022 | } |
| 2023 | for (i = 0; i < 8; i++) |
| 2024 | if ((0xff << (8 * (i % 4))) & failxor[i / 4]) |
| 2025 | failmask |= 1 << i; |
| 2026 | } |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 2027 | disable_cache_region(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2028 | flush_cache((total_rank << 28), 1728 * 5 * 4); |
| 2029 | return failmask; |
| 2030 | } |
| 2031 | |
| 2032 | const u32 seed1[0x18] = { |
| 2033 | 0x3a9d5ab5, 0x576cb65b, 0x555773b6, 0x2ab772ee, |
| 2034 | 0x555556ee, 0x3a9d5ab5, 0x576cb65b, 0x555773b6, |
| 2035 | 0x2ab772ee, 0x555556ee, 0x5155a555, 0x5155a555, |
| 2036 | 0x5155a555, 0x5155a555, 0x3a9d5ab5, 0x576cb65b, |
| 2037 | 0x555773b6, 0x2ab772ee, 0x555556ee, 0x55d6b4a5, |
| 2038 | 0x366d6b3a, 0x2ae5ddbb, 0x3b9ddbb7, 0x55d6b4a5, |
| 2039 | }; |
| 2040 | |
| 2041 | static u32 get_seed2(int a, int b) |
| 2042 | { |
| 2043 | const u32 seed2[5] = { |
| 2044 | 0x55555555, 0x33333333, 0x2e555a55, 0x55555555, |
| 2045 | 0x5b6db6db, |
| 2046 | }; |
| 2047 | u32 r; |
| 2048 | r = seed2[(a + (a >= 10)) / 5]; |
| 2049 | return b ? ~r : r; |
| 2050 | } |
| 2051 | |
| 2052 | static int make_shift(int comp2, int comp5, int x) |
| 2053 | { |
| 2054 | const u8 seed3[32] = { |
| 2055 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2056 | 0x00, 0x00, 0x38, 0x1c, 0x3c, 0x18, 0x38, 0x38, |
| 2057 | 0x38, 0x38, 0x38, 0x38, 0x0f, 0x0f, 0x0f, 0x0f, |
| 2058 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, |
| 2059 | }; |
| 2060 | |
| 2061 | return (comp2 - ((seed3[comp5] >> (x & 7)) & 1)) & 0x1f; |
| 2062 | } |
| 2063 | |
| 2064 | static u32 get_etalon(int flip, u32 addr) |
| 2065 | { |
| 2066 | u32 mask_byte = 0; |
| 2067 | int comp1 = (addr >> 1) & 1; |
| 2068 | int comp2 = (addr >> 3) & 0x1f; |
| 2069 | int comp3 = (addr >> 8) & 0xf; |
| 2070 | int comp4 = (addr >> 12) & 0xf; |
| 2071 | int comp5 = (addr >> 16) & 0x1f; |
| 2072 | u32 mask_bit = ~(0x10001 << comp3); |
| 2073 | u32 part1; |
| 2074 | u32 part2; |
| 2075 | int byte; |
| 2076 | |
| 2077 | part2 = |
| 2078 | ((seed1[comp5] >> |
| 2079 | make_shift(comp2, comp5, |
| 2080 | (comp3 >> 3) | (comp1 << 2) | 2)) & 1) ^ flip; |
| 2081 | part1 = |
| 2082 | ((seed1[comp5] >> |
| 2083 | make_shift(comp2, comp5, |
| 2084 | (comp3 >> 3) | (comp1 << 2) | 0)) & 1) ^ flip; |
| 2085 | |
| 2086 | for (byte = 0; byte < 4; byte++) |
| 2087 | if ((get_seed2(comp5, comp4) >> |
| 2088 | make_shift(comp2, comp5, (byte | (comp1 << 2)))) & 1) |
| 2089 | mask_byte |= 0xff << (8 * byte); |
| 2090 | |
| 2091 | return (mask_bit & mask_byte) | (part1 << comp3) | (part2 << |
| 2092 | (comp3 + 16)); |
| 2093 | } |
| 2094 | |
| 2095 | static void |
| 2096 | write_testing_type2(struct raminfo *info, u8 totalrank, u8 region, u8 block, |
| 2097 | char flip) |
| 2098 | { |
| 2099 | int i; |
| 2100 | for (i = 0; i < 2048; i++) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 2101 | write32p((totalrank << 28) | (region << 25) | (block << 16) | |
| 2102 | (i << 2), get_etalon(flip, (block << 16) | (i << 2))); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | static u8 |
| 2106 | check_testing_type2(struct raminfo *info, u8 totalrank, u8 region, u8 block, |
| 2107 | char flip) |
| 2108 | { |
| 2109 | u8 failmask = 0; |
| 2110 | u32 failxor[2]; |
| 2111 | int i; |
| 2112 | int comp1, comp2, comp3; |
| 2113 | |
| 2114 | failxor[0] = 0; |
| 2115 | failxor[1] = 0; |
| 2116 | |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 2117 | enable_cache_region(totalrank << 28, 134217728); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2118 | for (comp3 = 0; comp3 < 2 && failmask != 0xff; comp3++) { |
| 2119 | for (comp1 = 0; comp1 < 16; comp1++) |
| 2120 | for (comp2 = 0; comp2 < 64; comp2++) { |
| 2121 | u32 addr = |
| 2122 | (totalrank << 28) | (region << 25) | (block |
| 2123 | << 16) |
| 2124 | | (comp3 << 12) | (comp2 << 6) | (comp1 << |
| 2125 | 2); |
| 2126 | failxor[comp1 & 1] |= |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 2127 | read32p(addr) ^ get_etalon(flip, addr); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2128 | } |
| 2129 | for (i = 0; i < 8; i++) |
| 2130 | if ((0xff << (8 * (i % 4))) & failxor[i / 4]) |
| 2131 | failmask |= 1 << i; |
| 2132 | } |
Arthur Heymans | e7dd380 | 2019-11-25 12:09:33 +0100 | [diff] [blame] | 2133 | disable_cache_region(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2134 | flush_cache((totalrank << 28) | (region << 25) | (block << 16), 16384); |
| 2135 | return failmask; |
| 2136 | } |
| 2137 | |
| 2138 | static int check_bounded(unsigned short *vals, u16 bound) |
| 2139 | { |
| 2140 | int i; |
| 2141 | |
| 2142 | for (i = 0; i < 8; i++) |
| 2143 | if (vals[i] < bound) |
| 2144 | return 0; |
| 2145 | return 1; |
| 2146 | } |
| 2147 | |
| 2148 | enum state { |
| 2149 | BEFORE_USABLE = 0, AT_USABLE = 1, AT_MARGIN = 2, COMPLETE = 3 |
| 2150 | }; |
| 2151 | |
| 2152 | static int validate_state(enum state *in) |
| 2153 | { |
| 2154 | int i; |
| 2155 | for (i = 0; i < 8; i++) |
| 2156 | if (in[i] != COMPLETE) |
| 2157 | return 0; |
| 2158 | return 1; |
| 2159 | } |
| 2160 | |
| 2161 | static void |
Elyes HAOUAS | fd051dc | 2018-07-08 12:39:34 +0200 | [diff] [blame] | 2162 | do_fsm(enum state *state, u16 *counter, |
| 2163 | u8 fail_mask, int margin, int uplimit, |
| 2164 | u8 *res_low, u8 *res_high, u8 val) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2165 | { |
| 2166 | int lane; |
| 2167 | |
| 2168 | for (lane = 0; lane < 8; lane++) { |
| 2169 | int is_fail = (fail_mask >> lane) & 1; |
| 2170 | switch (state[lane]) { |
| 2171 | case BEFORE_USABLE: |
| 2172 | if (!is_fail) { |
| 2173 | counter[lane] = 1; |
| 2174 | state[lane] = AT_USABLE; |
| 2175 | break; |
| 2176 | } |
| 2177 | counter[lane] = 0; |
| 2178 | state[lane] = BEFORE_USABLE; |
| 2179 | break; |
| 2180 | case AT_USABLE: |
| 2181 | if (!is_fail) { |
| 2182 | ++counter[lane]; |
| 2183 | if (counter[lane] >= margin) { |
| 2184 | state[lane] = AT_MARGIN; |
| 2185 | res_low[lane] = val - margin + 1; |
| 2186 | break; |
| 2187 | } |
| 2188 | state[lane] = 1; |
| 2189 | break; |
| 2190 | } |
| 2191 | counter[lane] = 0; |
| 2192 | state[lane] = BEFORE_USABLE; |
| 2193 | break; |
| 2194 | case AT_MARGIN: |
| 2195 | if (is_fail) { |
| 2196 | state[lane] = COMPLETE; |
| 2197 | res_high[lane] = val - 1; |
| 2198 | } else { |
| 2199 | counter[lane]++; |
| 2200 | state[lane] = AT_MARGIN; |
| 2201 | if (val == uplimit) { |
| 2202 | state[lane] = COMPLETE; |
| 2203 | res_high[lane] = uplimit; |
| 2204 | } |
| 2205 | } |
| 2206 | break; |
| 2207 | case COMPLETE: |
| 2208 | break; |
| 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | static void |
| 2214 | train_ram_at_178(struct raminfo *info, u8 channel, int slot, int rank, |
| 2215 | u8 total_rank, u8 reg_178, int first_run, int niter, |
| 2216 | timing_bounds_t * timings) |
| 2217 | { |
| 2218 | int lane; |
| 2219 | enum state state[8]; |
| 2220 | u16 count[8]; |
| 2221 | u8 lower_usable[8]; |
| 2222 | u8 upper_usable[8]; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2223 | unsigned short num_successfully_checked[8]; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2224 | u8 reg1b3; |
Elyes HAOUAS | 019a253 | 2019-05-25 11:13:43 +0200 | [diff] [blame] | 2225 | int i; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2226 | |
Elyes HAOUAS | 019a253 | 2019-05-25 11:13:43 +0200 | [diff] [blame] | 2227 | for (i = 0; i < 8; i++) |
| 2228 | state[i] = BEFORE_USABLE; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2229 | |
| 2230 | if (!first_run) { |
| 2231 | int is_all_ok = 1; |
| 2232 | for (lane = 0; lane < 8; lane++) |
| 2233 | if (timings[reg_178][channel][slot][rank][lane]. |
| 2234 | smallest == |
| 2235 | timings[reg_178][channel][slot][rank][lane]. |
| 2236 | largest) { |
| 2237 | timings[reg_178][channel][slot][rank][lane]. |
| 2238 | smallest = 0; |
| 2239 | timings[reg_178][channel][slot][rank][lane]. |
| 2240 | largest = 0; |
| 2241 | is_all_ok = 0; |
| 2242 | } |
| 2243 | if (is_all_ok) { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2244 | for (i = 0; i < 8; i++) |
| 2245 | state[i] = COMPLETE; |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | for (reg1b3 = 0; reg1b3 < 0x30 && !validate_state(state); reg1b3++) { |
| 2250 | u8 failmask = 0; |
| 2251 | write_1d0(reg1b3 ^ 32, 0x1b3, 6, 1); |
| 2252 | write_1d0(reg1b3 ^ 32, 0x1a3, 6, 1); |
| 2253 | failmask = check_testing(info, total_rank, 0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2254 | MCHBAR32_OR(0xfb0, 0x00030000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2255 | do_fsm(state, count, failmask, 5, 47, lower_usable, |
| 2256 | upper_usable, reg1b3); |
| 2257 | } |
| 2258 | |
| 2259 | if (reg1b3) { |
| 2260 | write_1d0(0, 0x1b3, 6, 1); |
| 2261 | write_1d0(0, 0x1a3, 6, 1); |
| 2262 | for (lane = 0; lane < 8; lane++) { |
| 2263 | if (state[lane] == COMPLETE) { |
| 2264 | timings[reg_178][channel][slot][rank][lane]. |
| 2265 | smallest = |
| 2266 | lower_usable[lane] + |
| 2267 | (info->training. |
| 2268 | lane_timings[0][channel][slot][rank][lane] |
| 2269 | & 0x3F) - 32; |
| 2270 | timings[reg_178][channel][slot][rank][lane]. |
| 2271 | largest = |
| 2272 | upper_usable[lane] + |
| 2273 | (info->training. |
| 2274 | lane_timings[0][channel][slot][rank][lane] |
| 2275 | & 0x3F) - 32; |
| 2276 | } |
| 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | if (!first_run) { |
| 2281 | for (lane = 0; lane < 8; lane++) |
| 2282 | if (state[lane] == COMPLETE) { |
| 2283 | write_500(info, channel, |
| 2284 | timings[reg_178][channel][slot][rank] |
| 2285 | [lane].smallest, |
| 2286 | get_timing_register_addr(lane, 0, |
| 2287 | slot, rank), |
| 2288 | 9, 1); |
| 2289 | write_500(info, channel, |
| 2290 | timings[reg_178][channel][slot][rank] |
| 2291 | [lane].smallest + |
| 2292 | info->training. |
| 2293 | lane_timings[1][channel][slot][rank] |
| 2294 | [lane] |
| 2295 | - |
| 2296 | info->training. |
| 2297 | lane_timings[0][channel][slot][rank] |
| 2298 | [lane], get_timing_register_addr(lane, |
| 2299 | 1, |
| 2300 | slot, |
| 2301 | rank), |
| 2302 | 9, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2303 | num_successfully_checked[lane] = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2304 | } else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2305 | num_successfully_checked[lane] = -1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2306 | |
| 2307 | do { |
| 2308 | u8 failmask = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2309 | for (i = 0; i < niter; i++) { |
| 2310 | if (failmask == 0xFF) |
| 2311 | break; |
| 2312 | failmask |= |
| 2313 | check_testing_type2(info, total_rank, 2, i, |
| 2314 | 0); |
| 2315 | failmask |= |
| 2316 | check_testing_type2(info, total_rank, 3, i, |
| 2317 | 1); |
| 2318 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2319 | MCHBAR32_OR(0xfb0, 0x00030000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2320 | for (lane = 0; lane < 8; lane++) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2321 | if (num_successfully_checked[lane] != 0xffff) { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2322 | if ((1 << lane) & failmask) { |
| 2323 | if (timings[reg_178][channel] |
| 2324 | [slot][rank][lane]. |
| 2325 | largest <= |
| 2326 | timings[reg_178][channel] |
| 2327 | [slot][rank][lane].smallest) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2328 | num_successfully_checked |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2329 | [lane] = -1; |
| 2330 | else { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2331 | num_successfully_checked |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2332 | [lane] = 0; |
| 2333 | timings[reg_178] |
| 2334 | [channel][slot] |
| 2335 | [rank][lane]. |
| 2336 | smallest++; |
| 2337 | write_500(info, channel, |
| 2338 | timings |
| 2339 | [reg_178] |
| 2340 | [channel] |
| 2341 | [slot][rank] |
| 2342 | [lane]. |
| 2343 | smallest, |
| 2344 | get_timing_register_addr |
| 2345 | (lane, 0, |
| 2346 | slot, rank), |
| 2347 | 9, 1); |
| 2348 | write_500(info, channel, |
| 2349 | timings |
| 2350 | [reg_178] |
| 2351 | [channel] |
| 2352 | [slot][rank] |
| 2353 | [lane]. |
| 2354 | smallest + |
| 2355 | info-> |
| 2356 | training. |
| 2357 | lane_timings |
| 2358 | [1][channel] |
| 2359 | [slot][rank] |
| 2360 | [lane] |
| 2361 | - |
| 2362 | info-> |
| 2363 | training. |
| 2364 | lane_timings |
| 2365 | [0][channel] |
| 2366 | [slot][rank] |
| 2367 | [lane], |
| 2368 | get_timing_register_addr |
| 2369 | (lane, 1, |
| 2370 | slot, rank), |
| 2371 | 9, 1); |
| 2372 | } |
| 2373 | } else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2374 | num_successfully_checked[lane] |
| 2375 | ++; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2376 | } |
| 2377 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2378 | while (!check_bounded(num_successfully_checked, 2)) |
| 2379 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2380 | |
| 2381 | for (lane = 0; lane < 8; lane++) |
| 2382 | if (state[lane] == COMPLETE) { |
| 2383 | write_500(info, channel, |
| 2384 | timings[reg_178][channel][slot][rank] |
| 2385 | [lane].largest, |
| 2386 | get_timing_register_addr(lane, 0, |
| 2387 | slot, rank), |
| 2388 | 9, 1); |
| 2389 | write_500(info, channel, |
| 2390 | timings[reg_178][channel][slot][rank] |
| 2391 | [lane].largest + |
| 2392 | info->training. |
| 2393 | lane_timings[1][channel][slot][rank] |
| 2394 | [lane] |
| 2395 | - |
| 2396 | info->training. |
| 2397 | lane_timings[0][channel][slot][rank] |
| 2398 | [lane], get_timing_register_addr(lane, |
| 2399 | 1, |
| 2400 | slot, |
| 2401 | rank), |
| 2402 | 9, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2403 | num_successfully_checked[lane] = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2404 | } else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2405 | num_successfully_checked[lane] = -1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2406 | |
| 2407 | do { |
| 2408 | int failmask = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2409 | for (i = 0; i < niter; i++) { |
| 2410 | if (failmask == 0xFF) |
| 2411 | break; |
| 2412 | failmask |= |
| 2413 | check_testing_type2(info, total_rank, 2, i, |
| 2414 | 0); |
| 2415 | failmask |= |
| 2416 | check_testing_type2(info, total_rank, 3, i, |
| 2417 | 1); |
| 2418 | } |
| 2419 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2420 | MCHBAR32_OR(0xfb0, 0x00030000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2421 | for (lane = 0; lane < 8; lane++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2422 | if (num_successfully_checked[lane] != 0xffff) { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2423 | if ((1 << lane) & failmask) { |
| 2424 | if (timings[reg_178][channel] |
| 2425 | [slot][rank][lane]. |
| 2426 | largest <= |
| 2427 | timings[reg_178][channel] |
| 2428 | [slot][rank][lane]. |
| 2429 | smallest) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2430 | num_successfully_checked |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2431 | [lane] = -1; |
| 2432 | } else { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2433 | num_successfully_checked |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2434 | [lane] = 0; |
| 2435 | timings[reg_178] |
| 2436 | [channel][slot] |
| 2437 | [rank][lane]. |
| 2438 | largest--; |
| 2439 | write_500(info, channel, |
| 2440 | timings |
| 2441 | [reg_178] |
| 2442 | [channel] |
| 2443 | [slot][rank] |
| 2444 | [lane]. |
| 2445 | largest, |
| 2446 | get_timing_register_addr |
| 2447 | (lane, 0, |
| 2448 | slot, rank), |
| 2449 | 9, 1); |
| 2450 | write_500(info, channel, |
| 2451 | timings |
| 2452 | [reg_178] |
| 2453 | [channel] |
| 2454 | [slot][rank] |
| 2455 | [lane]. |
| 2456 | largest + |
| 2457 | info-> |
| 2458 | training. |
| 2459 | lane_timings |
| 2460 | [1][channel] |
| 2461 | [slot][rank] |
| 2462 | [lane] |
| 2463 | - |
| 2464 | info-> |
| 2465 | training. |
| 2466 | lane_timings |
| 2467 | [0][channel] |
| 2468 | [slot][rank] |
| 2469 | [lane], |
| 2470 | get_timing_register_addr |
| 2471 | (lane, 1, |
| 2472 | slot, rank), |
| 2473 | 9, 1); |
| 2474 | } |
| 2475 | } else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2476 | num_successfully_checked[lane] |
| 2477 | ++; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2481 | while (!check_bounded(num_successfully_checked, 3)) |
| 2482 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2483 | |
| 2484 | for (lane = 0; lane < 8; lane++) { |
| 2485 | write_500(info, channel, |
| 2486 | info->training. |
| 2487 | lane_timings[0][channel][slot][rank][lane], |
| 2488 | get_timing_register_addr(lane, 0, slot, rank), |
| 2489 | 9, 1); |
| 2490 | write_500(info, channel, |
| 2491 | info->training. |
| 2492 | lane_timings[1][channel][slot][rank][lane], |
| 2493 | get_timing_register_addr(lane, 1, slot, rank), |
| 2494 | 9, 1); |
| 2495 | if (timings[reg_178][channel][slot][rank][lane]. |
| 2496 | largest <= |
| 2497 | timings[reg_178][channel][slot][rank][lane]. |
| 2498 | smallest) { |
| 2499 | timings[reg_178][channel][slot][rank][lane]. |
| 2500 | largest = 0; |
| 2501 | timings[reg_178][channel][slot][rank][lane]. |
| 2502 | smallest = 0; |
| 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | static void set_10b(struct raminfo *info, u8 val) |
| 2509 | { |
| 2510 | int channel; |
| 2511 | int slot, rank; |
| 2512 | int lane; |
| 2513 | |
| 2514 | if (read_1d0(0x10b, 6) == val) |
| 2515 | return; |
| 2516 | |
| 2517 | write_1d0(val, 0x10b, 6, 1); |
| 2518 | |
| 2519 | FOR_POPULATED_RANKS_BACKWARDS for (lane = 0; lane < 9; lane++) { |
| 2520 | u16 reg_500; |
| 2521 | reg_500 = read_500(info, channel, |
| 2522 | get_timing_register_addr(lane, 0, slot, |
| 2523 | rank), 9); |
| 2524 | if (val == 1) { |
| 2525 | if (lut16[info->clock_speed_index] <= reg_500) |
| 2526 | reg_500 -= lut16[info->clock_speed_index]; |
| 2527 | else |
| 2528 | reg_500 = 0; |
| 2529 | } else { |
| 2530 | reg_500 += lut16[info->clock_speed_index]; |
| 2531 | } |
| 2532 | write_500(info, channel, reg_500, |
| 2533 | get_timing_register_addr(lane, 0, slot, rank), 9, 1); |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | static void set_ecc(int onoff) |
| 2538 | { |
| 2539 | int channel; |
| 2540 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 2541 | u8 t; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2542 | t = MCHBAR8((channel << 10) + 0x5f8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2543 | if (onoff) |
| 2544 | t |= 1; |
| 2545 | else |
| 2546 | t &= ~1; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2547 | MCHBAR8((channel << 10) + 0x5f8) = t; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | static void set_178(u8 val) |
| 2552 | { |
| 2553 | if (val >= 31) |
| 2554 | val = val - 31; |
| 2555 | else |
| 2556 | val = 63 - val; |
| 2557 | |
| 2558 | write_1d0(2 * val, 0x178, 7, 1); |
| 2559 | } |
| 2560 | |
| 2561 | static void |
| 2562 | write_500_timings_type(struct raminfo *info, int channel, int slot, int rank, |
| 2563 | int type) |
| 2564 | { |
| 2565 | int lane; |
| 2566 | |
| 2567 | for (lane = 0; lane < 8; lane++) |
| 2568 | write_500(info, channel, |
| 2569 | info->training. |
| 2570 | lane_timings[type][channel][slot][rank][lane], |
| 2571 | get_timing_register_addr(lane, type, slot, rank), 9, |
| 2572 | 0); |
| 2573 | } |
| 2574 | |
| 2575 | static void |
| 2576 | try_timing_offsets(struct raminfo *info, int channel, |
| 2577 | int slot, int rank, int totalrank) |
| 2578 | { |
| 2579 | u16 count[8]; |
| 2580 | enum state state[8]; |
| 2581 | u8 lower_usable[8], upper_usable[8]; |
| 2582 | int lane; |
| 2583 | int i; |
| 2584 | int flip = 1; |
| 2585 | int timing_offset; |
| 2586 | |
| 2587 | for (i = 0; i < 8; i++) |
| 2588 | state[i] = BEFORE_USABLE; |
| 2589 | |
| 2590 | memset(count, 0, sizeof(count)); |
| 2591 | |
| 2592 | for (lane = 0; lane < 8; lane++) |
| 2593 | write_500(info, channel, |
| 2594 | info->training. |
| 2595 | lane_timings[2][channel][slot][rank][lane] + 32, |
| 2596 | get_timing_register_addr(lane, 3, slot, rank), 9, 1); |
| 2597 | |
| 2598 | for (timing_offset = 0; !validate_state(state) && timing_offset < 64; |
| 2599 | timing_offset++) { |
| 2600 | u8 failmask; |
| 2601 | write_1d0(timing_offset ^ 32, 0x1bb, 6, 1); |
| 2602 | failmask = 0; |
| 2603 | for (i = 0; i < 2 && failmask != 0xff; i++) { |
| 2604 | flip = !flip; |
| 2605 | write_testing(info, totalrank, flip); |
| 2606 | failmask |= check_testing(info, totalrank, flip); |
| 2607 | } |
| 2608 | do_fsm(state, count, failmask, 10, 63, lower_usable, |
| 2609 | upper_usable, timing_offset); |
| 2610 | } |
| 2611 | write_1d0(0, 0x1bb, 6, 1); |
| 2612 | dump_timings(info); |
| 2613 | if (!validate_state(state)) |
| 2614 | die("Couldn't discover DRAM timings (1)\n"); |
| 2615 | |
| 2616 | for (lane = 0; lane < 8; lane++) { |
| 2617 | u8 bias = 0; |
| 2618 | |
| 2619 | if (info->silicon_revision) { |
| 2620 | int usable_length; |
| 2621 | |
| 2622 | usable_length = upper_usable[lane] - lower_usable[lane]; |
| 2623 | if (usable_length >= 20) { |
| 2624 | bias = usable_length / 2 - 10; |
| 2625 | if (bias >= 2) |
| 2626 | bias = 2; |
| 2627 | } |
| 2628 | } |
| 2629 | write_500(info, channel, |
| 2630 | info->training. |
| 2631 | lane_timings[2][channel][slot][rank][lane] + |
| 2632 | (upper_usable[lane] + lower_usable[lane]) / 2 - bias, |
| 2633 | get_timing_register_addr(lane, 3, slot, rank), 9, 1); |
| 2634 | info->training.timing2_bounds[channel][slot][rank][lane][0] = |
| 2635 | info->training.lane_timings[2][channel][slot][rank][lane] + |
| 2636 | lower_usable[lane]; |
| 2637 | info->training.timing2_bounds[channel][slot][rank][lane][1] = |
| 2638 | info->training.lane_timings[2][channel][slot][rank][lane] + |
| 2639 | upper_usable[lane]; |
| 2640 | info->training.timing2_offset[channel][slot][rank][lane] = |
| 2641 | info->training.lane_timings[2][channel][slot][rank][lane]; |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | static u8 |
| 2646 | choose_training(struct raminfo *info, int channel, int slot, int rank, |
| 2647 | int lane, timing_bounds_t * timings, u8 center_178) |
| 2648 | { |
| 2649 | u16 central_weight; |
| 2650 | u16 side_weight; |
| 2651 | unsigned int sum = 0, count = 0; |
| 2652 | u8 span; |
| 2653 | u8 lower_margin, upper_margin; |
| 2654 | u8 reg_178; |
| 2655 | u8 result; |
| 2656 | |
| 2657 | span = 12; |
| 2658 | central_weight = 20; |
| 2659 | side_weight = 20; |
| 2660 | if (info->silicon_revision == 1 && channel == 1) { |
| 2661 | central_weight = 5; |
| 2662 | side_weight = 20; |
| 2663 | if ((info-> |
| 2664 | populated_ranks_mask[1] ^ (info-> |
| 2665 | populated_ranks_mask[1] >> 2)) & |
| 2666 | 1) |
| 2667 | span = 18; |
| 2668 | } |
| 2669 | if ((info->populated_ranks_mask[0] & 5) == 5) { |
| 2670 | central_weight = 20; |
| 2671 | side_weight = 20; |
| 2672 | } |
| 2673 | if (info->clock_speed_index >= 2 |
| 2674 | && (info->populated_ranks_mask[0] & 5) == 5 && slot == 1) { |
| 2675 | if (info->silicon_revision == 1) { |
| 2676 | switch (channel) { |
| 2677 | case 0: |
| 2678 | if (lane == 1) { |
| 2679 | central_weight = 10; |
| 2680 | side_weight = 20; |
| 2681 | } |
| 2682 | break; |
| 2683 | case 1: |
| 2684 | if (lane == 6) { |
| 2685 | side_weight = 5; |
| 2686 | central_weight = 20; |
| 2687 | } |
| 2688 | break; |
| 2689 | } |
| 2690 | } |
| 2691 | if (info->silicon_revision == 0 && channel == 0 && lane == 0) { |
| 2692 | side_weight = 5; |
| 2693 | central_weight = 20; |
| 2694 | } |
| 2695 | } |
| 2696 | for (reg_178 = center_178 - span; reg_178 <= center_178 + span; |
| 2697 | reg_178 += span) { |
| 2698 | u8 smallest; |
| 2699 | u8 largest; |
| 2700 | largest = timings[reg_178][channel][slot][rank][lane].largest; |
| 2701 | smallest = timings[reg_178][channel][slot][rank][lane].smallest; |
| 2702 | if (largest - smallest + 1 >= 5) { |
| 2703 | unsigned int weight; |
| 2704 | if (reg_178 == center_178) |
| 2705 | weight = central_weight; |
| 2706 | else |
| 2707 | weight = side_weight; |
| 2708 | sum += weight * (largest + smallest); |
| 2709 | count += weight; |
| 2710 | } |
| 2711 | } |
| 2712 | dump_timings(info); |
| 2713 | if (count == 0) |
| 2714 | die("Couldn't discover DRAM timings (2)\n"); |
| 2715 | result = sum / (2 * count); |
| 2716 | lower_margin = |
| 2717 | result - timings[center_178][channel][slot][rank][lane].smallest; |
| 2718 | upper_margin = |
| 2719 | timings[center_178][channel][slot][rank][lane].largest - result; |
| 2720 | if (upper_margin < 10 && lower_margin > 10) |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 2721 | result -= MIN(lower_margin - 10, 10 - upper_margin); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2722 | if (upper_margin > 10 && lower_margin < 10) |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 2723 | result += MIN(upper_margin - 10, 10 - lower_margin); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2724 | return result; |
| 2725 | } |
| 2726 | |
| 2727 | #define STANDARD_MIN_MARGIN 5 |
| 2728 | |
| 2729 | static u8 choose_reg178(struct raminfo *info, timing_bounds_t * timings) |
| 2730 | { |
| 2731 | u16 margin[64]; |
| 2732 | int lane, rank, slot, channel; |
| 2733 | u8 reg178; |
| 2734 | int count = 0, sum = 0; |
| 2735 | |
| 2736 | for (reg178 = reg178_min[info->clock_speed_index]; |
| 2737 | reg178 < reg178_max[info->clock_speed_index]; |
| 2738 | reg178 += reg178_step[info->clock_speed_index]) { |
| 2739 | margin[reg178] = -1; |
| 2740 | FOR_POPULATED_RANKS_BACKWARDS for (lane = 0; lane < 8; lane++) { |
| 2741 | int curmargin = |
| 2742 | timings[reg178][channel][slot][rank][lane].largest - |
| 2743 | timings[reg178][channel][slot][rank][lane]. |
| 2744 | smallest + 1; |
| 2745 | if (curmargin < margin[reg178]) |
| 2746 | margin[reg178] = curmargin; |
| 2747 | } |
| 2748 | if (margin[reg178] >= STANDARD_MIN_MARGIN) { |
| 2749 | u16 weight; |
| 2750 | weight = margin[reg178] - STANDARD_MIN_MARGIN; |
| 2751 | sum += weight * reg178; |
| 2752 | count += weight; |
| 2753 | } |
| 2754 | } |
| 2755 | dump_timings(info); |
| 2756 | if (count == 0) |
| 2757 | die("Couldn't discover DRAM timings (3)\n"); |
| 2758 | |
| 2759 | u8 threshold; |
| 2760 | |
| 2761 | for (threshold = 30; threshold >= 5; threshold--) { |
| 2762 | int usable_length = 0; |
| 2763 | int smallest_fount = 0; |
| 2764 | for (reg178 = reg178_min[info->clock_speed_index]; |
| 2765 | reg178 < reg178_max[info->clock_speed_index]; |
| 2766 | reg178 += reg178_step[info->clock_speed_index]) |
| 2767 | if (margin[reg178] >= threshold) { |
| 2768 | usable_length += |
| 2769 | reg178_step[info->clock_speed_index]; |
| 2770 | info->training.reg178_largest = |
| 2771 | reg178 - |
| 2772 | 2 * reg178_step[info->clock_speed_index]; |
| 2773 | |
| 2774 | if (!smallest_fount) { |
| 2775 | smallest_fount = 1; |
| 2776 | info->training.reg178_smallest = |
| 2777 | reg178 + |
| 2778 | reg178_step[info-> |
| 2779 | clock_speed_index]; |
| 2780 | } |
| 2781 | } |
| 2782 | if (usable_length >= 0x21) |
| 2783 | break; |
| 2784 | } |
| 2785 | |
| 2786 | return sum / count; |
| 2787 | } |
| 2788 | |
| 2789 | static int check_cached_sanity(struct raminfo *info) |
| 2790 | { |
| 2791 | int lane; |
| 2792 | int slot, rank; |
| 2793 | int channel; |
| 2794 | |
| 2795 | if (!info->cached_training) |
| 2796 | return 0; |
| 2797 | |
| 2798 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 2799 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 2800 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 2801 | for (lane = 0; lane < 8 + info->use_ecc; lane++) { |
| 2802 | u16 cached_value, estimation_value; |
| 2803 | cached_value = |
| 2804 | info->cached_training-> |
| 2805 | lane_timings[1][channel][slot][rank] |
| 2806 | [lane]; |
| 2807 | if (cached_value >= 0x18 |
| 2808 | && cached_value <= 0x1E7) { |
| 2809 | estimation_value = |
| 2810 | info->training. |
| 2811 | lane_timings[1][channel] |
| 2812 | [slot][rank][lane]; |
| 2813 | if (estimation_value < |
| 2814 | cached_value - 24) |
| 2815 | return 0; |
| 2816 | if (estimation_value > |
| 2817 | cached_value + 24) |
| 2818 | return 0; |
| 2819 | } |
| 2820 | } |
| 2821 | return 1; |
| 2822 | } |
| 2823 | |
| 2824 | static int try_cached_training(struct raminfo *info) |
| 2825 | { |
| 2826 | u8 saved_243[2]; |
| 2827 | u8 tm; |
| 2828 | |
| 2829 | int channel, slot, rank, lane; |
| 2830 | int flip = 1; |
| 2831 | int i, j; |
| 2832 | |
| 2833 | if (!check_cached_sanity(info)) |
| 2834 | return 0; |
| 2835 | |
| 2836 | info->training.reg178_center = info->cached_training->reg178_center; |
| 2837 | info->training.reg178_smallest = info->cached_training->reg178_smallest; |
| 2838 | info->training.reg178_largest = info->cached_training->reg178_largest; |
| 2839 | memcpy(&info->training.timing_bounds, |
| 2840 | &info->cached_training->timing_bounds, |
| 2841 | sizeof(info->training.timing_bounds)); |
| 2842 | memcpy(&info->training.timing_offset, |
| 2843 | &info->cached_training->timing_offset, |
| 2844 | sizeof(info->training.timing_offset)); |
| 2845 | |
| 2846 | write_1d0(2, 0x142, 3, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2847 | saved_243[0] = MCHBAR8(0x243); |
| 2848 | saved_243[1] = MCHBAR8(0x643); |
| 2849 | MCHBAR8(0x243) = saved_243[0] | 2; |
| 2850 | MCHBAR8(0x643) = saved_243[1] | 2; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2851 | set_ecc(0); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 2852 | pci_write_config16(NORTHBRIDGE, 0xc8, 3); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2853 | if (read_1d0(0x10b, 6) & 1) |
| 2854 | set_10b(info, 0); |
| 2855 | for (tm = 0; tm < 2; tm++) { |
| 2856 | int totalrank; |
| 2857 | |
| 2858 | set_178(tm ? info->cached_training->reg178_largest : info-> |
| 2859 | cached_training->reg178_smallest); |
| 2860 | |
| 2861 | totalrank = 0; |
| 2862 | /* Check timing ranges. With i == 0 we check smallest one and with |
| 2863 | i == 1 the largest bound. With j == 0 we check that on the bound |
| 2864 | it still works whereas with j == 1 we check that just outside of |
| 2865 | bound we fail. |
| 2866 | */ |
| 2867 | FOR_POPULATED_RANKS_BACKWARDS { |
| 2868 | for (i = 0; i < 2; i++) { |
| 2869 | for (lane = 0; lane < 8; lane++) { |
| 2870 | write_500(info, channel, |
| 2871 | info->cached_training-> |
| 2872 | timing2_bounds[channel][slot] |
| 2873 | [rank][lane][i], |
| 2874 | get_timing_register_addr(lane, |
| 2875 | 3, |
| 2876 | slot, |
| 2877 | rank), |
| 2878 | 9, 1); |
| 2879 | |
| 2880 | if (!i) |
| 2881 | write_500(info, channel, |
| 2882 | info-> |
| 2883 | cached_training-> |
| 2884 | timing2_offset |
| 2885 | [channel][slot][rank] |
| 2886 | [lane], |
| 2887 | get_timing_register_addr |
| 2888 | (lane, 2, slot, rank), |
| 2889 | 9, 1); |
| 2890 | write_500(info, channel, |
| 2891 | i ? info->cached_training-> |
| 2892 | timing_bounds[tm][channel] |
| 2893 | [slot][rank][lane]. |
| 2894 | largest : info-> |
| 2895 | cached_training-> |
| 2896 | timing_bounds[tm][channel] |
| 2897 | [slot][rank][lane].smallest, |
| 2898 | get_timing_register_addr(lane, |
| 2899 | 0, |
| 2900 | slot, |
| 2901 | rank), |
| 2902 | 9, 1); |
| 2903 | write_500(info, channel, |
| 2904 | info->cached_training-> |
| 2905 | timing_offset[channel][slot] |
| 2906 | [rank][lane] + |
| 2907 | (i ? info->cached_training-> |
| 2908 | timing_bounds[tm][channel] |
| 2909 | [slot][rank][lane]. |
| 2910 | largest : info-> |
| 2911 | cached_training-> |
| 2912 | timing_bounds[tm][channel] |
| 2913 | [slot][rank][lane]. |
| 2914 | smallest) - 64, |
| 2915 | get_timing_register_addr(lane, |
| 2916 | 1, |
| 2917 | slot, |
| 2918 | rank), |
| 2919 | 9, 1); |
| 2920 | } |
| 2921 | for (j = 0; j < 2; j++) { |
| 2922 | u8 failmask; |
| 2923 | u8 expected_failmask; |
| 2924 | char reg1b3; |
| 2925 | |
| 2926 | reg1b3 = (j == 1) + 4; |
| 2927 | reg1b3 = |
| 2928 | j == i ? reg1b3 : (-reg1b3) & 0x3f; |
| 2929 | write_1d0(reg1b3, 0x1bb, 6, 1); |
| 2930 | write_1d0(reg1b3, 0x1b3, 6, 1); |
| 2931 | write_1d0(reg1b3, 0x1a3, 6, 1); |
| 2932 | |
| 2933 | flip = !flip; |
| 2934 | write_testing(info, totalrank, flip); |
| 2935 | failmask = |
| 2936 | check_testing(info, totalrank, |
| 2937 | flip); |
| 2938 | expected_failmask = |
| 2939 | j == 0 ? 0x00 : 0xff; |
| 2940 | if (failmask != expected_failmask) |
| 2941 | goto fail; |
| 2942 | } |
| 2943 | } |
| 2944 | totalrank++; |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | set_178(info->cached_training->reg178_center); |
| 2949 | if (info->use_ecc) |
| 2950 | set_ecc(1); |
| 2951 | write_training_data(info); |
| 2952 | write_1d0(0, 322, 3, 1); |
| 2953 | info->training = *info->cached_training; |
| 2954 | |
| 2955 | write_1d0(0, 0x1bb, 6, 1); |
| 2956 | write_1d0(0, 0x1b3, 6, 1); |
| 2957 | write_1d0(0, 0x1a3, 6, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2958 | MCHBAR8(0x243) = saved_243[0]; |
| 2959 | MCHBAR8(0x643) = saved_243[1]; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2960 | |
| 2961 | return 1; |
| 2962 | |
| 2963 | fail: |
| 2964 | FOR_POPULATED_RANKS { |
| 2965 | write_500_timings_type(info, channel, slot, rank, 1); |
| 2966 | write_500_timings_type(info, channel, slot, rank, 2); |
| 2967 | write_500_timings_type(info, channel, slot, rank, 3); |
| 2968 | } |
| 2969 | |
| 2970 | write_1d0(0, 0x1bb, 6, 1); |
| 2971 | write_1d0(0, 0x1b3, 6, 1); |
| 2972 | write_1d0(0, 0x1a3, 6, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2973 | MCHBAR8(0x243) = saved_243[0]; |
| 2974 | MCHBAR8(0x643) = saved_243[1]; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2975 | |
| 2976 | return 0; |
| 2977 | } |
| 2978 | |
| 2979 | static void do_ram_training(struct raminfo *info) |
| 2980 | { |
| 2981 | u8 saved_243[2]; |
| 2982 | int totalrank = 0; |
| 2983 | u8 reg_178; |
| 2984 | int niter; |
| 2985 | |
Matthias Gazzari | dfa5125 | 2018-05-19 00:44:20 +0200 | [diff] [blame] | 2986 | timing_bounds_t *timings = timings_car; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2987 | int lane, rank, slot, channel; |
| 2988 | u8 reg178_center; |
| 2989 | |
| 2990 | write_1d0(2, 0x142, 3, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 2991 | saved_243[0] = MCHBAR8(0x243); |
| 2992 | saved_243[1] = MCHBAR8(0x643); |
| 2993 | MCHBAR8(0x243) = saved_243[0] | 2; |
| 2994 | MCHBAR8(0x643) = saved_243[1] | 2; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2995 | switch (info->clock_speed_index) { |
| 2996 | case 0: |
| 2997 | niter = 5; |
| 2998 | break; |
| 2999 | case 1: |
| 3000 | niter = 10; |
| 3001 | break; |
| 3002 | default: |
| 3003 | niter = 19; |
| 3004 | break; |
| 3005 | } |
| 3006 | set_ecc(0); |
| 3007 | |
| 3008 | FOR_POPULATED_RANKS_BACKWARDS { |
| 3009 | int i; |
| 3010 | |
| 3011 | write_500_timings_type(info, channel, slot, rank, 0); |
| 3012 | |
| 3013 | write_testing(info, totalrank, 0); |
| 3014 | for (i = 0; i < niter; i++) { |
| 3015 | write_testing_type2(info, totalrank, 2, i, 0); |
| 3016 | write_testing_type2(info, totalrank, 3, i, 1); |
| 3017 | } |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3018 | pci_write_config8(NORTHBRIDGE, 0xc0, 0x01); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3019 | totalrank++; |
| 3020 | } |
| 3021 | |
| 3022 | if (reg178_min[info->clock_speed_index] < |
| 3023 | reg178_max[info->clock_speed_index]) |
| 3024 | memset(timings[reg178_min[info->clock_speed_index]], 0, |
| 3025 | sizeof(timings[0]) * |
| 3026 | (reg178_max[info->clock_speed_index] - |
| 3027 | reg178_min[info->clock_speed_index])); |
| 3028 | for (reg_178 = reg178_min[info->clock_speed_index]; |
| 3029 | reg_178 < reg178_max[info->clock_speed_index]; |
| 3030 | reg_178 += reg178_step[info->clock_speed_index]) { |
| 3031 | totalrank = 0; |
| 3032 | set_178(reg_178); |
| 3033 | for (channel = NUM_CHANNELS - 1; channel >= 0; channel--) |
| 3034 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 3035 | for (rank = 0; rank < NUM_RANKS; rank++) { |
| 3036 | memset(&timings[reg_178][channel][slot] |
| 3037 | [rank][0].smallest, 0, 16); |
| 3038 | if (info-> |
| 3039 | populated_ranks[channel][slot] |
| 3040 | [rank]) { |
| 3041 | train_ram_at_178(info, channel, |
| 3042 | slot, rank, |
| 3043 | totalrank, |
| 3044 | reg_178, 1, |
| 3045 | niter, |
| 3046 | timings); |
| 3047 | totalrank++; |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | reg178_center = choose_reg178(info, timings); |
| 3053 | |
| 3054 | FOR_POPULATED_RANKS_BACKWARDS for (lane = 0; lane < 8; lane++) { |
| 3055 | info->training.timing_bounds[0][channel][slot][rank][lane]. |
| 3056 | smallest = |
| 3057 | timings[info->training. |
| 3058 | reg178_smallest][channel][slot][rank][lane]. |
| 3059 | smallest; |
| 3060 | info->training.timing_bounds[0][channel][slot][rank][lane]. |
| 3061 | largest = |
| 3062 | timings[info->training. |
| 3063 | reg178_smallest][channel][slot][rank][lane].largest; |
| 3064 | info->training.timing_bounds[1][channel][slot][rank][lane]. |
| 3065 | smallest = |
| 3066 | timings[info->training. |
| 3067 | reg178_largest][channel][slot][rank][lane].smallest; |
| 3068 | info->training.timing_bounds[1][channel][slot][rank][lane]. |
| 3069 | largest = |
| 3070 | timings[info->training. |
| 3071 | reg178_largest][channel][slot][rank][lane].largest; |
| 3072 | info->training.timing_offset[channel][slot][rank][lane] = |
| 3073 | info->training.lane_timings[1][channel][slot][rank][lane] |
| 3074 | - |
| 3075 | info->training.lane_timings[0][channel][slot][rank][lane] + |
| 3076 | 64; |
| 3077 | } |
| 3078 | |
| 3079 | if (info->silicon_revision == 1 |
| 3080 | && (info-> |
| 3081 | populated_ranks_mask[1] ^ (info-> |
| 3082 | populated_ranks_mask[1] >> 2)) & 1) { |
| 3083 | int ranks_after_channel1; |
| 3084 | |
| 3085 | totalrank = 0; |
| 3086 | for (reg_178 = reg178_center - 18; |
| 3087 | reg_178 <= reg178_center + 18; reg_178 += 18) { |
| 3088 | totalrank = 0; |
| 3089 | set_178(reg_178); |
| 3090 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 3091 | for (rank = 0; rank < NUM_RANKS; rank++) { |
| 3092 | if (info-> |
| 3093 | populated_ranks[1][slot][rank]) { |
| 3094 | train_ram_at_178(info, 1, slot, |
| 3095 | rank, |
| 3096 | totalrank, |
| 3097 | reg_178, 0, |
| 3098 | niter, |
| 3099 | timings); |
| 3100 | totalrank++; |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | ranks_after_channel1 = totalrank; |
| 3105 | |
| 3106 | for (reg_178 = reg178_center - 12; |
| 3107 | reg_178 <= reg178_center + 12; reg_178 += 12) { |
| 3108 | totalrank = ranks_after_channel1; |
| 3109 | set_178(reg_178); |
| 3110 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 3111 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 3112 | if (info-> |
| 3113 | populated_ranks[0][slot][rank]) { |
| 3114 | train_ram_at_178(info, 0, slot, |
| 3115 | rank, |
| 3116 | totalrank, |
| 3117 | reg_178, 0, |
| 3118 | niter, |
| 3119 | timings); |
| 3120 | totalrank++; |
| 3121 | } |
| 3122 | |
| 3123 | } |
| 3124 | } else { |
| 3125 | for (reg_178 = reg178_center - 12; |
| 3126 | reg_178 <= reg178_center + 12; reg_178 += 12) { |
| 3127 | totalrank = 0; |
| 3128 | set_178(reg_178); |
| 3129 | FOR_POPULATED_RANKS_BACKWARDS { |
| 3130 | train_ram_at_178(info, channel, slot, rank, |
| 3131 | totalrank, reg_178, 0, niter, |
| 3132 | timings); |
| 3133 | totalrank++; |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | set_178(reg178_center); |
| 3139 | FOR_POPULATED_RANKS_BACKWARDS for (lane = 0; lane < 8; lane++) { |
| 3140 | u16 tm0; |
| 3141 | |
| 3142 | tm0 = |
| 3143 | choose_training(info, channel, slot, rank, lane, timings, |
| 3144 | reg178_center); |
| 3145 | write_500(info, channel, tm0, |
| 3146 | get_timing_register_addr(lane, 0, slot, rank), 9, 1); |
| 3147 | write_500(info, channel, |
| 3148 | tm0 + |
| 3149 | info->training. |
| 3150 | lane_timings[1][channel][slot][rank][lane] - |
| 3151 | info->training. |
| 3152 | lane_timings[0][channel][slot][rank][lane], |
| 3153 | get_timing_register_addr(lane, 1, slot, rank), 9, 1); |
| 3154 | } |
| 3155 | |
| 3156 | totalrank = 0; |
| 3157 | FOR_POPULATED_RANKS_BACKWARDS { |
| 3158 | try_timing_offsets(info, channel, slot, rank, totalrank); |
| 3159 | totalrank++; |
| 3160 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3161 | MCHBAR8(0x243) = saved_243[0]; |
| 3162 | MCHBAR8(0x643) = saved_243[1]; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3163 | write_1d0(0, 0x142, 3, 1); |
| 3164 | info->training.reg178_center = reg178_center; |
| 3165 | } |
| 3166 | |
| 3167 | static void ram_training(struct raminfo *info) |
| 3168 | { |
| 3169 | u16 saved_fc4; |
| 3170 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3171 | saved_fc4 = MCHBAR16(0xfc4); |
| 3172 | MCHBAR16(0xfc4) = 0xffff; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3173 | |
| 3174 | if (info->revision >= 8) |
| 3175 | read_4090(info); |
| 3176 | |
| 3177 | if (!try_cached_training(info)) |
| 3178 | do_ram_training(info); |
| 3179 | if ((info->silicon_revision == 2 || info->silicon_revision == 3) |
| 3180 | && info->clock_speed_index < 2) |
| 3181 | set_10b(info, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3182 | MCHBAR16(0xfc4) = saved_fc4; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3183 | } |
| 3184 | |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 3185 | static unsigned int gcd(unsigned int a, unsigned int b) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3186 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 3187 | unsigned int t; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3188 | if (a > b) { |
| 3189 | t = a; |
| 3190 | a = b; |
| 3191 | b = t; |
| 3192 | } |
| 3193 | /* invariant a < b. */ |
| 3194 | while (a) { |
| 3195 | t = b % a; |
| 3196 | b = a; |
| 3197 | a = t; |
| 3198 | } |
| 3199 | return b; |
| 3200 | } |
| 3201 | |
| 3202 | static inline int div_roundup(int a, int b) |
| 3203 | { |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 3204 | return DIV_ROUND_UP(a, b); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3205 | } |
| 3206 | |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 3207 | static unsigned int lcm(unsigned int a, unsigned int b) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3208 | { |
| 3209 | return (a * b) / gcd(a, b); |
| 3210 | } |
| 3211 | |
| 3212 | struct stru1 { |
| 3213 | u8 freqs_reversed; |
| 3214 | u8 freq_diff_reduced; |
| 3215 | u8 freq_min_reduced; |
| 3216 | u8 divisor_f4_to_fmax; |
| 3217 | u8 divisor_f3_to_fmax; |
| 3218 | u8 freq4_to_max_remainder; |
| 3219 | u8 freq3_to_2_remainder; |
| 3220 | u8 freq3_to_2_remaindera; |
| 3221 | u8 freq4_to_2_remainder; |
| 3222 | int divisor_f3_to_f1, divisor_f4_to_f2; |
| 3223 | int common_time_unit_ps; |
| 3224 | int freq_max_reduced; |
| 3225 | }; |
| 3226 | |
| 3227 | static void |
| 3228 | compute_frequence_ratios(struct raminfo *info, u16 freq1, u16 freq2, |
| 3229 | int num_cycles_2, int num_cycles_1, int round_it, |
| 3230 | int add_freqs, struct stru1 *result) |
| 3231 | { |
| 3232 | int g; |
| 3233 | int common_time_unit_ps; |
| 3234 | int freq1_reduced, freq2_reduced; |
| 3235 | int freq_min_reduced; |
| 3236 | int freq_max_reduced; |
| 3237 | int freq3, freq4; |
| 3238 | |
| 3239 | g = gcd(freq1, freq2); |
| 3240 | freq1_reduced = freq1 / g; |
| 3241 | freq2_reduced = freq2 / g; |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 3242 | freq_min_reduced = MIN(freq1_reduced, freq2_reduced); |
| 3243 | freq_max_reduced = MAX(freq1_reduced, freq2_reduced); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3244 | |
| 3245 | common_time_unit_ps = div_roundup(900000, lcm(freq1, freq2)); |
| 3246 | freq3 = div_roundup(num_cycles_2, common_time_unit_ps) - 1; |
| 3247 | freq4 = div_roundup(num_cycles_1, common_time_unit_ps) - 1; |
| 3248 | if (add_freqs) { |
| 3249 | freq3 += freq2_reduced; |
| 3250 | freq4 += freq1_reduced; |
| 3251 | } |
| 3252 | |
| 3253 | if (round_it) { |
| 3254 | result->freq3_to_2_remainder = 0; |
| 3255 | result->freq3_to_2_remaindera = 0; |
| 3256 | result->freq4_to_max_remainder = 0; |
| 3257 | result->divisor_f4_to_f2 = 0; |
| 3258 | result->divisor_f3_to_f1 = 0; |
| 3259 | } else { |
| 3260 | if (freq2_reduced < freq1_reduced) { |
| 3261 | result->freq3_to_2_remainder = |
| 3262 | result->freq3_to_2_remaindera = |
| 3263 | freq3 % freq1_reduced - freq1_reduced + 1; |
| 3264 | result->freq4_to_max_remainder = |
| 3265 | -(freq4 % freq1_reduced); |
| 3266 | result->divisor_f3_to_f1 = freq3 / freq1_reduced; |
| 3267 | result->divisor_f4_to_f2 = |
| 3268 | (freq4 - |
| 3269 | (freq1_reduced - freq2_reduced)) / freq2_reduced; |
| 3270 | result->freq4_to_2_remainder = |
| 3271 | -(char)((freq1_reduced - freq2_reduced) + |
| 3272 | ((u8) freq4 - |
| 3273 | (freq1_reduced - |
| 3274 | freq2_reduced)) % (u8) freq2_reduced); |
| 3275 | } else { |
| 3276 | if (freq2_reduced > freq1_reduced) { |
| 3277 | result->freq4_to_max_remainder = |
| 3278 | (freq4 % freq2_reduced) - freq2_reduced + 1; |
| 3279 | result->freq4_to_2_remainder = |
| 3280 | freq4 % freq_max_reduced - |
| 3281 | freq_max_reduced + 1; |
| 3282 | } else { |
| 3283 | result->freq4_to_max_remainder = |
| 3284 | -(freq4 % freq2_reduced); |
| 3285 | result->freq4_to_2_remainder = |
| 3286 | -(char)(freq4 % freq_max_reduced); |
| 3287 | } |
| 3288 | result->divisor_f4_to_f2 = freq4 / freq2_reduced; |
| 3289 | result->divisor_f3_to_f1 = |
| 3290 | (freq3 - |
| 3291 | (freq2_reduced - freq1_reduced)) / freq1_reduced; |
| 3292 | result->freq3_to_2_remainder = -(freq3 % freq2_reduced); |
| 3293 | result->freq3_to_2_remaindera = |
| 3294 | -(char)((freq_max_reduced - freq_min_reduced) + |
| 3295 | (freq3 - |
| 3296 | (freq_max_reduced - |
| 3297 | freq_min_reduced)) % freq1_reduced); |
| 3298 | } |
| 3299 | } |
| 3300 | result->divisor_f3_to_fmax = freq3 / freq_max_reduced; |
| 3301 | result->divisor_f4_to_fmax = freq4 / freq_max_reduced; |
| 3302 | if (round_it) { |
| 3303 | if (freq2_reduced > freq1_reduced) { |
| 3304 | if (freq3 % freq_max_reduced) |
| 3305 | result->divisor_f3_to_fmax++; |
| 3306 | } |
| 3307 | if (freq2_reduced < freq1_reduced) { |
| 3308 | if (freq4 % freq_max_reduced) |
| 3309 | result->divisor_f4_to_fmax++; |
| 3310 | } |
| 3311 | } |
| 3312 | result->freqs_reversed = (freq2_reduced < freq1_reduced); |
| 3313 | result->freq_diff_reduced = freq_max_reduced - freq_min_reduced; |
| 3314 | result->freq_min_reduced = freq_min_reduced; |
| 3315 | result->common_time_unit_ps = common_time_unit_ps; |
| 3316 | result->freq_max_reduced = freq_max_reduced; |
| 3317 | } |
| 3318 | |
| 3319 | static void |
| 3320 | set_2d5x_reg(struct raminfo *info, u16 reg, u16 freq1, u16 freq2, |
| 3321 | int num_cycles_2, int num_cycles_1, int num_cycles_3, |
| 3322 | int num_cycles_4, int reverse) |
| 3323 | { |
| 3324 | struct stru1 vv; |
| 3325 | char multiplier; |
| 3326 | |
| 3327 | compute_frequence_ratios(info, freq1, freq2, num_cycles_2, num_cycles_1, |
| 3328 | 0, 1, &vv); |
| 3329 | |
| 3330 | multiplier = |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 3331 | div_roundup(MAX |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3332 | (div_roundup(num_cycles_2, vv.common_time_unit_ps) + |
| 3333 | div_roundup(num_cycles_3, vv.common_time_unit_ps), |
| 3334 | div_roundup(num_cycles_1, |
| 3335 | vv.common_time_unit_ps) + |
| 3336 | div_roundup(num_cycles_4, vv.common_time_unit_ps)) |
| 3337 | + vv.freq_min_reduced - 1, vv.freq_max_reduced) - 1; |
| 3338 | |
| 3339 | u32 y = |
| 3340 | (u8) ((vv.freq_max_reduced - vv.freq_min_reduced) + |
| 3341 | vv.freq_max_reduced * multiplier) |
| 3342 | | (vv. |
| 3343 | freqs_reversed << 8) | ((u8) (vv.freq_min_reduced * |
| 3344 | multiplier) << 16) | ((u8) (vv. |
| 3345 | freq_min_reduced |
| 3346 | * |
| 3347 | multiplier) |
| 3348 | << 24); |
| 3349 | u32 x = |
| 3350 | vv.freq3_to_2_remaindera | (vv.freq4_to_2_remainder << 8) | (vv. |
| 3351 | divisor_f3_to_f1 |
| 3352 | << 16) |
| 3353 | | (vv.divisor_f4_to_f2 << 20) | (vv.freq_min_reduced << 24); |
| 3354 | if (reverse) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3355 | MCHBAR32(reg) = y; |
| 3356 | MCHBAR32(reg + 4) = x; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3357 | } else { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3358 | MCHBAR32(reg + 4) = y; |
| 3359 | MCHBAR32(reg) = x; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | static void |
| 3364 | set_6d_reg(struct raminfo *info, u16 reg, u16 freq1, u16 freq2, |
| 3365 | int num_cycles_1, int num_cycles_2, int num_cycles_3, |
| 3366 | int num_cycles_4) |
| 3367 | { |
| 3368 | struct stru1 ratios1; |
| 3369 | struct stru1 ratios2; |
| 3370 | |
| 3371 | compute_frequence_ratios(info, freq1, freq2, num_cycles_1, num_cycles_2, |
| 3372 | 0, 1, &ratios2); |
| 3373 | compute_frequence_ratios(info, freq1, freq2, num_cycles_3, num_cycles_4, |
| 3374 | 0, 1, &ratios1); |
Arthur Heymans | b328209 | 2019-04-14 17:53:28 +0200 | [diff] [blame] | 3375 | printk(RAM_SPEW, "[%x] <= %x\n", reg, |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3376 | ratios1.freq4_to_max_remainder | (ratios2. |
| 3377 | freq4_to_max_remainder |
| 3378 | << 8) |
| 3379 | | (ratios1.divisor_f4_to_fmax << 16) | (ratios2. |
| 3380 | divisor_f4_to_fmax |
| 3381 | << 20)); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3382 | MCHBAR32(reg) = ratios1.freq4_to_max_remainder | |
| 3383 | (ratios2.freq4_to_max_remainder << 8) | |
| 3384 | (ratios1.divisor_f4_to_fmax << 16) | |
| 3385 | (ratios2.divisor_f4_to_fmax << 20); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | static void |
| 3389 | set_2dx8_reg(struct raminfo *info, u16 reg, u8 mode, u16 freq1, u16 freq2, |
| 3390 | int num_cycles_2, int num_cycles_1, int round_it, int add_freqs) |
| 3391 | { |
| 3392 | struct stru1 ratios; |
| 3393 | |
| 3394 | compute_frequence_ratios(info, freq1, freq2, num_cycles_2, num_cycles_1, |
| 3395 | round_it, add_freqs, &ratios); |
| 3396 | switch (mode) { |
| 3397 | case 0: |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3398 | MCHBAR32(reg + 4) = ratios.freq_diff_reduced | |
| 3399 | (ratios.freqs_reversed << 8); |
| 3400 | MCHBAR32(reg) = ratios.freq3_to_2_remainder | |
| 3401 | (ratios.freq4_to_max_remainder << 8) | |
| 3402 | (ratios.divisor_f3_to_fmax << 16) | |
| 3403 | (ratios.divisor_f4_to_fmax << 20) | |
| 3404 | (ratios.freq_min_reduced << 24); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3405 | break; |
| 3406 | |
| 3407 | case 1: |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3408 | MCHBAR32(reg) = ratios.freq3_to_2_remainder | |
| 3409 | (ratios.divisor_f3_to_fmax << 16); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3410 | break; |
| 3411 | |
| 3412 | case 2: |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3413 | MCHBAR32(reg) = ratios.freq3_to_2_remainder | |
| 3414 | (ratios.freq4_to_max_remainder << 8) | |
| 3415 | (ratios.divisor_f3_to_fmax << 16) | |
| 3416 | (ratios.divisor_f4_to_fmax << 20); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3417 | break; |
| 3418 | |
| 3419 | case 4: |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3420 | MCHBAR32(reg) = (ratios.divisor_f3_to_fmax << 4) | |
| 3421 | (ratios.divisor_f4_to_fmax << 8) | |
| 3422 | (ratios.freqs_reversed << 12) | |
| 3423 | (ratios.freq_min_reduced << 16) | |
| 3424 | (ratios.freq_diff_reduced << 24); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3425 | break; |
| 3426 | } |
| 3427 | } |
| 3428 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3429 | static void set_2dxx_series(struct raminfo *info, int s3resume) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3430 | { |
| 3431 | set_2dx8_reg(info, 0x2d00, 0, 0x78, frequency_11(info) / 2, 1359, 1005, |
| 3432 | 0, 1); |
| 3433 | set_2dx8_reg(info, 0x2d08, 0, 0x78, 0x78, 3273, 5033, 1, 1); |
| 3434 | set_2dx8_reg(info, 0x2d10, 0, 0x78, info->fsb_frequency, 1475, 1131, 0, |
| 3435 | 1); |
| 3436 | set_2dx8_reg(info, 0x2d18, 0, 2 * info->fsb_frequency, |
| 3437 | frequency_11(info), 1231, 1524, 0, 1); |
| 3438 | set_2dx8_reg(info, 0x2d20, 0, 2 * info->fsb_frequency, |
| 3439 | frequency_11(info) / 2, 1278, 2008, 0, 1); |
| 3440 | set_2dx8_reg(info, 0x2d28, 0, info->fsb_frequency, frequency_11(info), |
| 3441 | 1167, 1539, 0, 1); |
| 3442 | set_2dx8_reg(info, 0x2d30, 0, info->fsb_frequency, |
| 3443 | frequency_11(info) / 2, 1403, 1318, 0, 1); |
| 3444 | set_2dx8_reg(info, 0x2d38, 0, info->fsb_frequency, 0x78, 3460, 5363, 1, |
| 3445 | 1); |
| 3446 | set_2dx8_reg(info, 0x2d40, 0, info->fsb_frequency, 0x3c, 2792, 5178, 1, |
| 3447 | 1); |
| 3448 | set_2dx8_reg(info, 0x2d48, 0, 2 * info->fsb_frequency, 0x78, 2738, 4610, |
| 3449 | 1, 1); |
| 3450 | set_2dx8_reg(info, 0x2d50, 0, info->fsb_frequency, 0x78, 2819, 5932, 1, |
| 3451 | 1); |
| 3452 | set_2dx8_reg(info, 0x6d4, 1, info->fsb_frequency, |
| 3453 | frequency_11(info) / 2, 4000, 0, 0, 0); |
| 3454 | set_2dx8_reg(info, 0x6d8, 2, info->fsb_frequency, |
| 3455 | frequency_11(info) / 2, 4000, 4000, 0, 0); |
| 3456 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3457 | if (s3resume) { |
Arthur Heymans | b328209 | 2019-04-14 17:53:28 +0200 | [diff] [blame] | 3458 | printk(RAM_SPEW, "[6dc] <= %x\n", |
| 3459 | info->cached_training->reg_6dc); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3460 | MCHBAR32(0x6dc) = info->cached_training->reg_6dc; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3461 | } else |
| 3462 | set_6d_reg(info, 0x6dc, 2 * info->fsb_frequency, frequency_11(info), 0, |
| 3463 | info->delay46_ps[0], 0, |
| 3464 | info->delay54_ps[0]); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3465 | set_2dx8_reg(info, 0x6e0, 1, 2 * info->fsb_frequency, |
| 3466 | frequency_11(info), 2500, 0, 0, 0); |
| 3467 | set_2dx8_reg(info, 0x6e4, 1, 2 * info->fsb_frequency, |
| 3468 | frequency_11(info) / 2, 3500, 0, 0, 0); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3469 | if (s3resume) { |
Arthur Heymans | b328209 | 2019-04-14 17:53:28 +0200 | [diff] [blame] | 3470 | printk(RAM_SPEW, "[6e8] <= %x\n", |
| 3471 | info->cached_training->reg_6e8); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3472 | MCHBAR32(0x6e8) = info->cached_training->reg_6e8; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3473 | } else |
| 3474 | set_6d_reg(info, 0x6e8, 2 * info->fsb_frequency, frequency_11(info), 0, |
| 3475 | info->delay46_ps[1], 0, |
| 3476 | info->delay54_ps[1]); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3477 | set_2d5x_reg(info, 0x2d58, 0x78, 0x78, 864, 1195, 762, 786, 0); |
| 3478 | set_2d5x_reg(info, 0x2d60, 0x195, info->fsb_frequency, 1352, 725, 455, |
| 3479 | 470, 0); |
| 3480 | set_2d5x_reg(info, 0x2d68, 0x195, 0x3c, 2707, 5632, 3277, 2207, 0); |
| 3481 | set_2d5x_reg(info, 0x2d70, 0x195, frequency_11(info) / 2, 1276, 758, |
| 3482 | 454, 459, 0); |
| 3483 | set_2d5x_reg(info, 0x2d78, 0x195, 0x78, 1021, 799, 510, 513, 0); |
| 3484 | set_2d5x_reg(info, 0x2d80, info->fsb_frequency, 0xe1, 0, 2862, 2579, |
| 3485 | 2588, 0); |
| 3486 | set_2d5x_reg(info, 0x2d88, info->fsb_frequency, 0xe1, 0, 2690, 2405, |
| 3487 | 2405, 0); |
| 3488 | set_2d5x_reg(info, 0x2da0, 0x78, 0xe1, 0, 2560, 2264, 2251, 0); |
| 3489 | set_2d5x_reg(info, 0x2da8, 0x195, frequency_11(info), 1060, 775, 484, |
| 3490 | 480, 0); |
| 3491 | set_2d5x_reg(info, 0x2db0, 0x195, 0x78, 4183, 6023, 2217, 2048, 0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3492 | MCHBAR32(0x2dbc) = ((frequency_11(info) / 2) - 1) | 0xe00000; |
| 3493 | MCHBAR32(0x2db8) = ((info->fsb_frequency - 1) << 16) | 0x77; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | static u16 get_max_timing(struct raminfo *info, int channel) |
| 3497 | { |
| 3498 | int slot, rank, lane; |
| 3499 | u16 ret = 0; |
| 3500 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3501 | if ((MCHBAR8(0x2ca8) >> 2) < 1) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3502 | return 384; |
| 3503 | |
| 3504 | if (info->revision < 8) |
| 3505 | return 256; |
| 3506 | |
| 3507 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 3508 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 3509 | if (info->populated_ranks[channel][slot][rank]) |
| 3510 | for (lane = 0; lane < 8 + info->use_ecc; lane++) |
Elyes HAOUAS | ba9b504 | 2019-12-19 07:47:52 +0100 | [diff] [blame] | 3511 | ret = MAX(ret, read_500(info, channel, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3512 | get_timing_register_addr |
| 3513 | (lane, 0, slot, |
| 3514 | rank), 9)); |
| 3515 | return ret; |
| 3516 | } |
| 3517 | |
| 3518 | static void set_274265(struct raminfo *info) |
| 3519 | { |
| 3520 | int delay_a_ps, delay_b_ps, delay_c_ps, delay_d_ps; |
| 3521 | int delay_e_ps, delay_e_cycles, delay_f_cycles; |
| 3522 | int delay_e_over_cycle_ps; |
| 3523 | int cycletime_ps; |
| 3524 | int channel; |
| 3525 | |
| 3526 | delay_a_ps = 4 * halfcycle_ps(info) + 6 * fsbcycle_ps(info); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3527 | info->training.reg2ca9_bit0 = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3528 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 3529 | cycletime_ps = |
| 3530 | 900000 / lcm(2 * info->fsb_frequency, frequency_11(info)); |
| 3531 | delay_d_ps = |
| 3532 | (halfcycle_ps(info) * get_max_timing(info, channel) >> 6) |
| 3533 | - info->some_delay_3_ps_rounded + 200; |
| 3534 | if (! |
| 3535 | ((info->silicon_revision == 0 |
| 3536 | || info->silicon_revision == 1) |
| 3537 | && (info->revision >= 8))) |
| 3538 | delay_d_ps += halfcycle_ps(info) * 2; |
| 3539 | delay_d_ps += |
| 3540 | halfcycle_ps(info) * (!info->revision_flag_1 + |
| 3541 | info->some_delay_2_halfcycles_ceil + |
| 3542 | 2 * info->some_delay_1_cycle_floor + |
| 3543 | info->clock_speed_index + |
| 3544 | 2 * info->cas_latency - 7 + 11); |
| 3545 | delay_d_ps += info->revision >= 8 ? 2758 : 4428; |
| 3546 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3547 | MCHBAR32_AND_OR(0x140, 0xfaffffff, 0x2000000); |
| 3548 | MCHBAR32_AND_OR(0x138, 0xfaffffff, 0x2000000); |
| 3549 | if ((MCHBAR8(0x144) & 0x1f) > 0x13) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3550 | delay_d_ps += 650; |
| 3551 | delay_c_ps = delay_d_ps + 1800; |
| 3552 | if (delay_c_ps <= delay_a_ps) |
| 3553 | delay_e_ps = 0; |
| 3554 | else |
| 3555 | delay_e_ps = |
| 3556 | cycletime_ps * div_roundup(delay_c_ps - delay_a_ps, |
| 3557 | cycletime_ps); |
| 3558 | |
| 3559 | delay_e_over_cycle_ps = delay_e_ps % (2 * halfcycle_ps(info)); |
| 3560 | delay_e_cycles = delay_e_ps / (2 * halfcycle_ps(info)); |
| 3561 | delay_f_cycles = |
| 3562 | div_roundup(2500 - delay_e_over_cycle_ps, |
| 3563 | 2 * halfcycle_ps(info)); |
| 3564 | if (delay_f_cycles > delay_e_cycles) { |
| 3565 | info->delay46_ps[channel] = delay_e_ps; |
| 3566 | delay_e_cycles = 0; |
| 3567 | } else { |
| 3568 | info->delay46_ps[channel] = |
| 3569 | delay_e_over_cycle_ps + |
| 3570 | 2 * halfcycle_ps(info) * delay_f_cycles; |
| 3571 | delay_e_cycles -= delay_f_cycles; |
| 3572 | } |
| 3573 | |
| 3574 | if (info->delay46_ps[channel] < 2500) { |
| 3575 | info->delay46_ps[channel] = 2500; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3576 | info->training.reg2ca9_bit0 = 1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3577 | } |
| 3578 | delay_b_ps = halfcycle_ps(info) + delay_c_ps; |
| 3579 | if (delay_b_ps <= delay_a_ps) |
| 3580 | delay_b_ps = 0; |
| 3581 | else |
| 3582 | delay_b_ps -= delay_a_ps; |
| 3583 | info->delay54_ps[channel] = |
| 3584 | cycletime_ps * div_roundup(delay_b_ps, |
| 3585 | cycletime_ps) - |
| 3586 | 2 * halfcycle_ps(info) * delay_e_cycles; |
| 3587 | if (info->delay54_ps[channel] < 2500) |
| 3588 | info->delay54_ps[channel] = 2500; |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3589 | info->training.reg274265[channel][0] = delay_e_cycles; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3590 | if (delay_d_ps + 7 * halfcycle_ps(info) <= |
| 3591 | 24 * halfcycle_ps(info)) |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3592 | info->training.reg274265[channel][1] = 0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3593 | else |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3594 | info->training.reg274265[channel][1] = |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3595 | div_roundup(delay_d_ps + 7 * halfcycle_ps(info), |
| 3596 | 4 * halfcycle_ps(info)) - 6; |
| 3597 | MCHBAR32((channel << 10) + 0x274) = |
| 3598 | info->training.reg274265[channel][1] | |
| 3599 | (info->training.reg274265[channel][0] << 16); |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3600 | info->training.reg274265[channel][2] = |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3601 | div_roundup(delay_c_ps + 3 * fsbcycle_ps(info), |
| 3602 | 4 * halfcycle_ps(info)) + 1; |
| 3603 | MCHBAR16((channel << 10) + 0x265) = |
| 3604 | info->training.reg274265[channel][2] << 8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3605 | } |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3606 | if (info->training.reg2ca9_bit0) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3607 | MCHBAR8_OR(0x2ca9, 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3608 | else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3609 | MCHBAR8_AND(0x2ca9, ~1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | static void restore_274265(struct raminfo *info) |
| 3613 | { |
| 3614 | int channel; |
| 3615 | |
| 3616 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 3617 | MCHBAR32((channel << 10) + 0x274) = |
| 3618 | (info->cached_training->reg274265[channel][0] << 16) | |
| 3619 | info->cached_training->reg274265[channel][1]; |
| 3620 | MCHBAR16((channel << 10) + 0x265) = |
| 3621 | info->cached_training->reg274265[channel][2] << 8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3622 | } |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3623 | if (info->cached_training->reg2ca9_bit0) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3624 | MCHBAR8_OR(0x2ca9, 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3625 | else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3626 | MCHBAR8_AND(0x2ca9, ~1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3627 | } |
| 3628 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3629 | static void dmi_setup(void) |
| 3630 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 3631 | gav(read8(DEFAULT_DMIBAR + 0x254)); |
| 3632 | write8(DEFAULT_DMIBAR + 0x254, 0x1); |
| 3633 | write16(DEFAULT_DMIBAR + 0x1b8, 0x18f2); |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 3634 | MCHBAR16_AND_OR(0x48, 0, 0x2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3635 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 3636 | write32(DEFAULT_DMIBAR + 0xd68, read32(DEFAULT_DMIBAR + 0xd68) | 0x08000000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3637 | |
| 3638 | outl((gav(inl(DEFAULT_GPIOBASE | 0x38)) & ~0x140000) | 0x400000, |
| 3639 | DEFAULT_GPIOBASE | 0x38); |
| 3640 | gav(inb(DEFAULT_GPIOBASE | 0xe)); // = 0xfdcaff6e |
| 3641 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3642 | |
Vladimir Serbinenko | 9817a37 | 2014-02-19 22:07:12 +0100 | [diff] [blame] | 3643 | void chipset_init(const int s3resume) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3644 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3645 | u8 x2ca8; |
Vladimir Serbinenko | 55391c4 | 2014-08-03 14:51:00 +0200 | [diff] [blame] | 3646 | u16 ggc; |
| 3647 | u8 gfxsize; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3648 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3649 | x2ca8 = MCHBAR8(0x2ca8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3650 | if ((x2ca8 & 1) || (x2ca8 == 8 && !s3resume)) { |
| 3651 | printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n"); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3652 | MCHBAR8(0x2ca8) = 0; |
Elyes HAOUAS | d45f338 | 2019-04-28 18:04:35 +0200 | [diff] [blame] | 3653 | system_reset(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3654 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3655 | |
| 3656 | dmi_setup(); |
| 3657 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3658 | MCHBAR16(0x1170) = 0xa880; |
| 3659 | MCHBAR8(0x11c1) = 0x1; |
| 3660 | MCHBAR16(0x1170) = 0xb880; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 3661 | MCHBAR8_AND_OR(0x1210, 0, 0x84); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3662 | |
Vladimir Serbinenko | 55391c4 | 2014-08-03 14:51:00 +0200 | [diff] [blame] | 3663 | if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) { |
| 3664 | /* 0 for 32MB */ |
| 3665 | gfxsize = 0; |
| 3666 | } |
| 3667 | |
| 3668 | ggc = 0xb00 | ((gfxsize + 5) << 4); |
| 3669 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3670 | pci_write_config16(NORTHBRIDGE, D0F0_GGC, ggc | 2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3671 | |
| 3672 | u16 deven; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3673 | deven = pci_read_config16(NORTHBRIDGE, D0F0_DEVEN); // = 0x3 |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3674 | |
| 3675 | if (deven & 8) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3676 | MCHBAR8(0x2c30) = 0x20; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3677 | pci_read_config8(NORTHBRIDGE, 0x8); // = 0x18 |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3678 | MCHBAR16_OR(0x2c30, 0x200); |
| 3679 | MCHBAR16(0x2c32) = 0x434; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 3680 | MCHBAR32_AND_OR(0x2c44, 0, 0x1053687); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3681 | pci_read_config8(GMA, 0x62); // = 0x2 |
| 3682 | pci_write_config8(GMA, 0x62, 0x2); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 3683 | read8(DEFAULT_RCBA + 0x2318); |
| 3684 | write8(DEFAULT_RCBA + 0x2318, 0x47); |
| 3685 | read8(DEFAULT_RCBA + 0x2320); |
| 3686 | write8(DEFAULT_RCBA + 0x2320, 0xfc); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3687 | } |
| 3688 | |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 3689 | MCHBAR32_AND_OR(0x30, 0, 0x40); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3690 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3691 | pci_write_config16(NORTHBRIDGE, D0F0_GGC, ggc); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 3692 | gav(read32(DEFAULT_RCBA + 0x3428)); |
| 3693 | write32(DEFAULT_RCBA + 0x3428, 0x1d); |
Vladimir Serbinenko | 9817a37 | 2014-02-19 22:07:12 +0100 | [diff] [blame] | 3694 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3695 | |
Vladimir Serbinenko | 9817a37 | 2014-02-19 22:07:12 +0100 | [diff] [blame] | 3696 | void raminit(const int s3resume, const u8 *spd_addrmap) |
| 3697 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 3698 | unsigned int channel, slot, lane, rank; |
Vladimir Serbinenko | 9817a37 | 2014-02-19 22:07:12 +0100 | [diff] [blame] | 3699 | int i; |
| 3700 | struct raminfo info; |
| 3701 | u8 x2ca8; |
| 3702 | u16 deven; |
Vladimir Serbinenko | b16f092 | 2014-06-07 16:27:27 +0200 | [diff] [blame] | 3703 | int cbmem_wasnot_inited; |
Vladimir Serbinenko | 9817a37 | 2014-02-19 22:07:12 +0100 | [diff] [blame] | 3704 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3705 | x2ca8 = MCHBAR8(0x2ca8); |
Arthur Heymans | b572c9d | 2019-10-14 18:18:46 +0200 | [diff] [blame] | 3706 | |
| 3707 | printk(RAM_DEBUG, "Scratchpad MCHBAR8(0x2ca8): 0x%04x\n", x2ca8); |
| 3708 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3709 | deven = pci_read_config16(NORTHBRIDGE, D0F0_DEVEN); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3710 | |
| 3711 | memset(&info, 0x5a, sizeof(info)); |
| 3712 | |
| 3713 | info.last_500_command[0] = 0; |
| 3714 | info.last_500_command[1] = 0; |
| 3715 | |
| 3716 | info.fsb_frequency = 135 * 2; |
| 3717 | info.board_lane_delay[0] = 0x14; |
| 3718 | info.board_lane_delay[1] = 0x07; |
| 3719 | info.board_lane_delay[2] = 0x07; |
| 3720 | info.board_lane_delay[3] = 0x08; |
| 3721 | info.board_lane_delay[4] = 0x56; |
| 3722 | info.board_lane_delay[5] = 0x04; |
| 3723 | info.board_lane_delay[6] = 0x04; |
| 3724 | info.board_lane_delay[7] = 0x05; |
| 3725 | info.board_lane_delay[8] = 0x10; |
| 3726 | |
| 3727 | info.training.reg_178 = 0; |
| 3728 | info.training.reg_10b = 0; |
| 3729 | |
| 3730 | info.heci_bar = 0; |
| 3731 | info.memory_reserved_for_heci_mb = 0; |
| 3732 | |
| 3733 | /* before SPD */ |
| 3734 | timestamp_add_now(101); |
| 3735 | |
Felix Held | 29a9c07 | 2018-07-29 01:34:45 +0200 | [diff] [blame] | 3736 | if (!s3resume || 1) { // possible error |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3737 | pci_read_config8(SOUTHBRIDGE, GEN_PMCON_2); // = 0x80 |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3738 | |
| 3739 | collect_system_info(&info); |
| 3740 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3741 | memset(&info.populated_ranks, 0, sizeof(info.populated_ranks)); |
| 3742 | |
| 3743 | info.use_ecc = 1; |
| 3744 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
Vladimir Serbinenko | 2ab8ec7 | 2014-02-20 14:34:56 +0100 | [diff] [blame] | 3745 | for (slot = 0; slot < NUM_SLOTS; slot++) { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3746 | int v; |
| 3747 | int try; |
| 3748 | int addr; |
| 3749 | const u8 useful_addresses[] = { |
| 3750 | DEVICE_TYPE, |
| 3751 | MODULE_TYPE, |
| 3752 | DENSITY, |
| 3753 | RANKS_AND_DQ, |
| 3754 | MEMORY_BUS_WIDTH, |
| 3755 | TIMEBASE_DIVIDEND, |
| 3756 | TIMEBASE_DIVISOR, |
| 3757 | CYCLETIME, |
| 3758 | CAS_LATENCIES_LSB, |
| 3759 | CAS_LATENCIES_MSB, |
| 3760 | CAS_LATENCY_TIME, |
| 3761 | 0x11, 0x12, 0x13, 0x14, 0x15, |
| 3762 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, |
| 3763 | 0x1c, 0x1d, |
| 3764 | THERMAL_AND_REFRESH, |
| 3765 | 0x20, |
| 3766 | REFERENCE_RAW_CARD_USED, |
| 3767 | RANK1_ADDRESS_MAPPING, |
| 3768 | 0x75, 0x76, 0x77, 0x78, |
| 3769 | 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, |
| 3770 | 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, |
| 3771 | 0x85, 0x86, 0x87, 0x88, |
| 3772 | 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, |
| 3773 | 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, |
| 3774 | 0x95 |
| 3775 | }; |
Vladimir Serbinenko | 902626c | 2014-02-16 17:22:26 +0100 | [diff] [blame] | 3776 | if (!spd_addrmap[2 * channel + slot]) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3777 | continue; |
| 3778 | for (try = 0; try < 5; try++) { |
Vladimir Serbinenko | 902626c | 2014-02-16 17:22:26 +0100 | [diff] [blame] | 3779 | v = smbus_read_byte(spd_addrmap[2 * channel + slot], |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3780 | DEVICE_TYPE); |
| 3781 | if (v >= 0) |
| 3782 | break; |
| 3783 | } |
| 3784 | if (v < 0) |
| 3785 | continue; |
| 3786 | for (addr = 0; |
| 3787 | addr < |
| 3788 | sizeof(useful_addresses) / |
| 3789 | sizeof(useful_addresses[0]); addr++) |
| 3790 | gav(info. |
| 3791 | spd[channel][0][useful_addresses |
| 3792 | [addr]] = |
Vladimir Serbinenko | 902626c | 2014-02-16 17:22:26 +0100 | [diff] [blame] | 3793 | smbus_read_byte(spd_addrmap[2 * channel + slot], |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3794 | useful_addresses |
| 3795 | [addr])); |
| 3796 | if (info.spd[channel][0][DEVICE_TYPE] != 11) |
| 3797 | die("Only DDR3 is supported"); |
| 3798 | |
| 3799 | v = info.spd[channel][0][RANKS_AND_DQ]; |
| 3800 | info.populated_ranks[channel][0][0] = 1; |
| 3801 | info.populated_ranks[channel][0][1] = |
| 3802 | ((v >> 3) & 7); |
| 3803 | if (((v >> 3) & 7) > 1) |
| 3804 | die("At most 2 ranks are supported"); |
| 3805 | if ((v & 7) == 0 || (v & 7) > 2) |
| 3806 | die("Only x8 and x16 modules are supported"); |
| 3807 | if ((info. |
| 3808 | spd[channel][slot][MODULE_TYPE] & 0xF) != 2 |
| 3809 | && (info. |
| 3810 | spd[channel][slot][MODULE_TYPE] & 0xF) |
| 3811 | != 3) |
| 3812 | die("Registered memory is not supported"); |
| 3813 | info.is_x16_module[channel][0] = (v & 7) - 1; |
| 3814 | info.density[channel][slot] = |
| 3815 | info.spd[channel][slot][DENSITY] & 0xF; |
| 3816 | if (! |
| 3817 | (info. |
| 3818 | spd[channel][slot][MEMORY_BUS_WIDTH] & |
| 3819 | 0x18)) |
| 3820 | info.use_ecc = 0; |
| 3821 | } |
| 3822 | |
| 3823 | gav(0x55); |
| 3824 | |
| 3825 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 3826 | int v = 0; |
| 3827 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 3828 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 3829 | v |= info. |
| 3830 | populated_ranks[channel][slot][rank] |
| 3831 | << (2 * slot + rank); |
| 3832 | info.populated_ranks_mask[channel] = v; |
| 3833 | } |
| 3834 | |
| 3835 | gav(0x55); |
| 3836 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3837 | gav(pci_read_config32(NORTHBRIDGE, D0F0_CAPID0 + 4)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | /* after SPD */ |
| 3841 | timestamp_add_now(102); |
| 3842 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3843 | MCHBAR8_AND(0x2ca8, 0xfc); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3844 | |
| 3845 | collect_system_info(&info); |
| 3846 | calculate_timings(&info); |
| 3847 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3848 | if (!s3resume) { |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3849 | u8 reg8 = pci_read_config8(SOUTHBRIDGE, GEN_PMCON_2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3850 | if (x2ca8 == 0 && (reg8 & 0x80)) { |
| 3851 | /* Don't enable S4-assertion stretch. Makes trouble on roda/rk9. |
| 3852 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4); |
| 3853 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8 | 0x08); |
| 3854 | */ |
| 3855 | |
| 3856 | /* Clear bit7. */ |
| 3857 | |
| 3858 | pci_write_config8(SOUTHBRIDGE, GEN_PMCON_2, |
| 3859 | (reg8 & ~(1 << 7))); |
| 3860 | |
| 3861 | printk(BIOS_INFO, |
| 3862 | "Interrupted RAM init, reset required.\n"); |
Elyes HAOUAS | d45f338 | 2019-04-28 18:04:35 +0200 | [diff] [blame] | 3863 | system_reset(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3864 | } |
| 3865 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3866 | |
| 3867 | if (!s3resume && x2ca8 == 0) |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3868 | pci_write_config8(SOUTHBRIDGE, GEN_PMCON_2, |
| 3869 | pci_read_config8(SOUTHBRIDGE, GEN_PMCON_2) | 0x80); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3870 | |
| 3871 | compute_derived_timings(&info); |
| 3872 | |
| 3873 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3874 | gav(MCHBAR8(0x164)); |
| 3875 | MCHBAR8(0x164) = 0x26; |
| 3876 | MCHBAR16(0x2c20) = 0x10; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3879 | MCHBAR32_OR(0x18b4, 0x210000); |
| 3880 | MCHBAR32_OR(0x1890, 0x2000000); |
| 3881 | MCHBAR32_OR(0x18b4, 0x8000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3882 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3883 | gav(pci_read_config32(PCI_DEV(0xff, 2, 1), 0x50)); // !!!! |
| 3884 | pci_write_config8(PCI_DEV(0xff, 2, 1), 0x54, 0x12); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3885 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3886 | gav(MCHBAR16(0x2c10)); |
| 3887 | MCHBAR16(0x2c10) = 0x412; |
| 3888 | gav(MCHBAR16(0x2c10)); |
| 3889 | MCHBAR16_OR(0x2c12, 0x100); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3890 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3891 | gav(MCHBAR8(0x2ca8)); // !!!! |
| 3892 | MCHBAR32_AND_OR(0x1804, 0xfffffffc, 0x8400080); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3893 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3894 | pci_read_config32(PCI_DEV(0xff, 2, 1), 0x6c); // !!!! |
| 3895 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0x6c, 0x40a0a0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3896 | gav(MCHBAR32(0x1c04)); // !!!! |
| 3897 | gav(MCHBAR32(0x1804)); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3898 | |
| 3899 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3900 | MCHBAR8_OR(0x2ca8, 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3903 | MCHBAR32(0x18d8) = 0x120000; |
| 3904 | MCHBAR32(0x18dc) = 0x30a484a; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3905 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xe0, 0x0); |
| 3906 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xf4, 0x9444a); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3907 | MCHBAR32(0x18d8) = 0x40000; |
| 3908 | MCHBAR32(0x18dc) = 0xb000000; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3909 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xe0, 0x60000); |
| 3910 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xf4, 0x0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3911 | MCHBAR32(0x18d8) = 0x180000; |
| 3912 | MCHBAR32(0x18dc) = 0xc0000142; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3913 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xe0, 0x20000); |
| 3914 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xf4, 0x142); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3915 | MCHBAR32(0x18d8) = 0x1e0000; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3916 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3917 | gav(MCHBAR32(0x18dc)); // !!!! |
| 3918 | MCHBAR32(0x18dc) = 0x3; |
| 3919 | gav(MCHBAR32(0x18dc)); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3920 | |
| 3921 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3922 | MCHBAR8_OR(0x2ca8, 1); // guess |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3923 | } |
| 3924 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3925 | MCHBAR32(0x188c) = 0x20bc09; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3926 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0xd0, 0x40b0c09); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3927 | MCHBAR32(0x1a10) = 0x4200010e; |
| 3928 | MCHBAR32_OR(0x18b8, 0x200); |
| 3929 | gav(MCHBAR32(0x1918)); // !!!! |
| 3930 | MCHBAR32(0x1918) = 0x332; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3931 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3932 | gav(MCHBAR32(0x18b8)); // !!!! |
| 3933 | MCHBAR32(0x18b8) = 0xe00; |
| 3934 | gav(MCHBAR32(0x182c)); // !!!! |
| 3935 | MCHBAR32(0x182c) = 0x10202; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3936 | gav(pci_read_config32(PCI_DEV(0xff, 2, 1), 0x94)); // !!!! |
| 3937 | pci_write_config32(PCI_DEV(0xff, 2, 1), 0x94, 0x10202); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3938 | MCHBAR32_AND(0x1a1c, 0x8fffffff); |
| 3939 | MCHBAR32_OR(0x1a70, 0x100000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3940 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3941 | MCHBAR32_AND(0x18b4, 0xffff7fff); |
| 3942 | gav(MCHBAR32(0x1a68)); // !!!! |
| 3943 | MCHBAR32(0x1a68) = 0x343800; |
| 3944 | gav(MCHBAR32(0x1e68)); // !!!! |
| 3945 | gav(MCHBAR32(0x1a68)); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3946 | |
| 3947 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3948 | MCHBAR8_OR(0x2ca8, 1); // guess |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3949 | } |
| 3950 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 3951 | pci_read_config32(PCI_DEV(0xff, 2, 0), 0x048); // !!!! |
| 3952 | pci_write_config32(PCI_DEV(0xff, 2, 0), 0x048, 0x140000); |
| 3953 | pci_read_config32(PCI_DEV(0xff, 2, 0), 0x058); // !!!! |
| 3954 | pci_write_config32(PCI_DEV(0xff, 2, 0), 0x058, 0x64555); |
| 3955 | pci_read_config32(PCI_DEV(0xff, 2, 0), 0x058); // !!!! |
| 3956 | pci_read_config32(PCI_DEV (0xff, 0, 0), 0xd0); // !!!! |
| 3957 | pci_write_config32(PCI_DEV (0xff, 0, 0), 0xd0, 0x180); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3958 | gav(MCHBAR32(0x1af0)); // !!!! |
| 3959 | gav(MCHBAR32(0x1af0)); // !!!! |
| 3960 | MCHBAR32(0x1af0) = 0x1f020003; |
| 3961 | gav(MCHBAR32(0x1af0)); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3962 | |
Edward O'Callaghan | 42b716f | 2014-06-26 21:38:52 +1000 | [diff] [blame] | 3963 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3964 | MCHBAR8_OR(0x2ca8, 1); // guess |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 3967 | gav(MCHBAR32(0x1890)); // !!!! |
| 3968 | MCHBAR32(0x1890) = 0x80102; |
| 3969 | gav(MCHBAR32(0x18b4)); // !!!! |
| 3970 | MCHBAR32(0x18b4) = 0x216000; |
| 3971 | MCHBAR32(0x18a4) = 0x22222222; |
| 3972 | MCHBAR32(0x18a8) = 0x22222222; |
| 3973 | MCHBAR32(0x18ac) = 0x22222; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3974 | |
| 3975 | udelay(1000); |
| 3976 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3977 | info.cached_training = get_cached_training(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3978 | |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3979 | if (x2ca8 == 0) { |
| 3980 | int j; |
| 3981 | if (s3resume && info.cached_training) { |
| 3982 | restore_274265(&info); |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 3983 | printk(RAM_SPEW, "reg2ca9_bit0 = %x\n", |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3984 | info.cached_training->reg2ca9_bit0); |
| 3985 | for (i = 0; i < 2; i++) |
| 3986 | for (j = 0; j < 3; j++) |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 3987 | printk(RAM_SPEW, "reg274265[%d][%d] = %x\n", |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3988 | i, j, info.cached_training->reg274265[i][j]); |
| 3989 | } else { |
| 3990 | set_274265(&info); |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 3991 | printk(RAM_SPEW, "reg2ca9_bit0 = %x\n", |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3992 | info.training.reg2ca9_bit0); |
| 3993 | for (i = 0; i < 2; i++) |
| 3994 | for (j = 0; j < 3; j++) |
Arthur Heymans | c892db6 | 2019-10-14 19:05:14 +0200 | [diff] [blame] | 3995 | printk(RAM_SPEW, "reg274265[%d][%d] = %x\n", |
Vladimir Serbinenko | f7a42de | 2014-01-09 11:10:04 +0100 | [diff] [blame] | 3996 | i, j, info.training.reg274265[i][j]); |
| 3997 | } |
| 3998 | |
| 3999 | set_2dxx_series(&info, s3resume); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4000 | |
| 4001 | if (!(deven & 8)) { |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4002 | MCHBAR32_AND_OR(0x2cb0, 0, 0x40); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | udelay(1000); |
| 4006 | |
| 4007 | if (deven & 8) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4008 | MCHBAR32_OR(0xff8, 0x1800); |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4009 | MCHBAR32_AND(0x2cb0, 0x00); |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4010 | pci_read_config8(PCI_DEV (0, 0x2, 0x0), 0x4c); |
| 4011 | pci_read_config8(PCI_DEV (0, 0x2, 0x0), 0x4c); |
| 4012 | pci_read_config8(PCI_DEV (0, 0x2, 0x0), 0x4e); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4013 | |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4014 | MCHBAR8(0x1150); |
| 4015 | MCHBAR8(0x1151); |
| 4016 | MCHBAR8(0x1022); |
| 4017 | MCHBAR8(0x16d0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4018 | MCHBAR32(0x1300) = 0x60606060; |
| 4019 | MCHBAR32(0x1304) = 0x60606060; |
| 4020 | MCHBAR32(0x1308) = 0x78797a7b; |
| 4021 | MCHBAR32(0x130c) = 0x7c7d7e7f; |
| 4022 | MCHBAR32(0x1310) = 0x60606060; |
| 4023 | MCHBAR32(0x1314) = 0x60606060; |
| 4024 | MCHBAR32(0x1318) = 0x60606060; |
| 4025 | MCHBAR32(0x131c) = 0x60606060; |
| 4026 | MCHBAR32(0x1320) = 0x50515253; |
| 4027 | MCHBAR32(0x1324) = 0x54555657; |
| 4028 | MCHBAR32(0x1328) = 0x58595a5b; |
| 4029 | MCHBAR32(0x132c) = 0x5c5d5e5f; |
| 4030 | MCHBAR32(0x1330) = 0x40414243; |
| 4031 | MCHBAR32(0x1334) = 0x44454647; |
| 4032 | MCHBAR32(0x1338) = 0x48494a4b; |
| 4033 | MCHBAR32(0x133c) = 0x4c4d4e4f; |
| 4034 | MCHBAR32(0x1340) = 0x30313233; |
| 4035 | MCHBAR32(0x1344) = 0x34353637; |
| 4036 | MCHBAR32(0x1348) = 0x38393a3b; |
| 4037 | MCHBAR32(0x134c) = 0x3c3d3e3f; |
| 4038 | MCHBAR32(0x1350) = 0x20212223; |
| 4039 | MCHBAR32(0x1354) = 0x24252627; |
| 4040 | MCHBAR32(0x1358) = 0x28292a2b; |
| 4041 | MCHBAR32(0x135c) = 0x2c2d2e2f; |
| 4042 | MCHBAR32(0x1360) = 0x10111213; |
| 4043 | MCHBAR32(0x1364) = 0x14151617; |
| 4044 | MCHBAR32(0x1368) = 0x18191a1b; |
| 4045 | MCHBAR32(0x136c) = 0x1c1d1e1f; |
| 4046 | MCHBAR32(0x1370) = 0x10203; |
| 4047 | MCHBAR32(0x1374) = 0x4050607; |
| 4048 | MCHBAR32(0x1378) = 0x8090a0b; |
| 4049 | MCHBAR32(0x137c) = 0xc0d0e0f; |
| 4050 | MCHBAR8(0x11cc) = 0x4e; |
| 4051 | MCHBAR32(0x1110) = 0x73970404; |
| 4052 | MCHBAR32(0x1114) = 0x72960404; |
| 4053 | MCHBAR32(0x1118) = 0x6f950404; |
| 4054 | MCHBAR32(0x111c) = 0x6d940404; |
| 4055 | MCHBAR32(0x1120) = 0x6a930404; |
| 4056 | MCHBAR32(0x1124) = 0x68a41404; |
| 4057 | MCHBAR32(0x1128) = 0x66a21404; |
| 4058 | MCHBAR32(0x112c) = 0x63a01404; |
| 4059 | MCHBAR32(0x1130) = 0x609e1404; |
| 4060 | MCHBAR32(0x1134) = 0x5f9c1404; |
| 4061 | MCHBAR32(0x1138) = 0x5c961404; |
| 4062 | MCHBAR32(0x113c) = 0x58a02404; |
| 4063 | MCHBAR32(0x1140) = 0x54942404; |
| 4064 | MCHBAR32(0x1190) = 0x900080a; |
| 4065 | MCHBAR16(0x11c0) = 0xc40b; |
| 4066 | MCHBAR16(0x11c2) = 0x303; |
| 4067 | MCHBAR16(0x11c4) = 0x301; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4068 | MCHBAR32_AND_OR(0x1190, 0, 0x8900080a); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4069 | MCHBAR32(0x11b8) = 0x70c3000; |
| 4070 | MCHBAR8(0x11ec) = 0xa; |
| 4071 | MCHBAR16(0x1100) = 0x800; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4072 | MCHBAR32_AND_OR(0x11bc, 0, 0x1e84800); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4073 | MCHBAR16(0x11ca) = 0xfa; |
| 4074 | MCHBAR32(0x11e4) = 0x4e20; |
| 4075 | MCHBAR8(0x11bc) = 0xf; |
| 4076 | MCHBAR16(0x11da) = 0x19; |
| 4077 | MCHBAR16(0x11ba) = 0x470c; |
| 4078 | MCHBAR32(0x1680) = 0xe6ffe4ff; |
| 4079 | MCHBAR32(0x1684) = 0xdeffdaff; |
| 4080 | MCHBAR32(0x1688) = 0xd4ffd0ff; |
| 4081 | MCHBAR32(0x168c) = 0xccffc6ff; |
| 4082 | MCHBAR32(0x1690) = 0xc0ffbeff; |
| 4083 | MCHBAR32(0x1694) = 0xb8ffb0ff; |
| 4084 | MCHBAR32(0x1698) = 0xa8ff0000; |
| 4085 | MCHBAR32(0x169c) = 0xc00; |
| 4086 | MCHBAR32(0x1290) = 0x5000000; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4087 | } |
| 4088 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4089 | MCHBAR32(0x124c) = 0x15040d00; |
| 4090 | MCHBAR32(0x1250) = 0x7f0000; |
| 4091 | MCHBAR32(0x1254) = 0x1e220004; |
| 4092 | MCHBAR32(0x1258) = 0x4000004; |
| 4093 | MCHBAR32(0x1278) = 0x0; |
| 4094 | MCHBAR32(0x125c) = 0x0; |
| 4095 | MCHBAR32(0x1260) = 0x0; |
| 4096 | MCHBAR32(0x1264) = 0x0; |
| 4097 | MCHBAR32(0x1268) = 0x0; |
| 4098 | MCHBAR32(0x126c) = 0x0; |
| 4099 | MCHBAR32(0x1270) = 0x0; |
| 4100 | MCHBAR32(0x1274) = 0x0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | if ((deven & 8) && x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4104 | MCHBAR16(0x1214) = 0x320; |
| 4105 | MCHBAR32(0x1600) = 0x40000000; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4106 | MCHBAR32_AND_OR(0x11f4, 0, 0x10000000); |
| 4107 | MCHBAR16_AND_OR(0x1230, 0, 0x8000); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4108 | MCHBAR32(0x1400) = 0x13040020; |
| 4109 | MCHBAR32(0x1404) = 0xe090120; |
| 4110 | MCHBAR32(0x1408) = 0x5120220; |
| 4111 | MCHBAR32(0x140c) = 0x5120330; |
| 4112 | MCHBAR32(0x1410) = 0xe090220; |
| 4113 | MCHBAR32(0x1414) = 0x1010001; |
| 4114 | MCHBAR32(0x1418) = 0x1110000; |
| 4115 | MCHBAR32(0x141c) = 0x9020020; |
| 4116 | MCHBAR32(0x1420) = 0xd090220; |
| 4117 | MCHBAR32(0x1424) = 0x2090220; |
| 4118 | MCHBAR32(0x1428) = 0x2090330; |
| 4119 | MCHBAR32(0x142c) = 0xd090220; |
| 4120 | MCHBAR32(0x1430) = 0x1010001; |
| 4121 | MCHBAR32(0x1434) = 0x1110000; |
| 4122 | MCHBAR32(0x1438) = 0x11040020; |
| 4123 | MCHBAR32(0x143c) = 0x4030220; |
| 4124 | MCHBAR32(0x1440) = 0x1060220; |
| 4125 | MCHBAR32(0x1444) = 0x1060330; |
| 4126 | MCHBAR32(0x1448) = 0x4030220; |
| 4127 | MCHBAR32(0x144c) = 0x1010001; |
| 4128 | MCHBAR32(0x1450) = 0x1110000; |
| 4129 | MCHBAR32(0x1454) = 0x4010020; |
| 4130 | MCHBAR32(0x1458) = 0xb090220; |
| 4131 | MCHBAR32(0x145c) = 0x1090220; |
| 4132 | MCHBAR32(0x1460) = 0x1090330; |
| 4133 | MCHBAR32(0x1464) = 0xb090220; |
| 4134 | MCHBAR32(0x1468) = 0x1010001; |
| 4135 | MCHBAR32(0x146c) = 0x1110000; |
| 4136 | MCHBAR32(0x1470) = 0xf040020; |
| 4137 | MCHBAR32(0x1474) = 0xa090220; |
| 4138 | MCHBAR32(0x1478) = 0x1120220; |
| 4139 | MCHBAR32(0x147c) = 0x1120330; |
| 4140 | MCHBAR32(0x1480) = 0xa090220; |
| 4141 | MCHBAR32(0x1484) = 0x1010001; |
| 4142 | MCHBAR32(0x1488) = 0x1110000; |
| 4143 | MCHBAR32(0x148c) = 0x7020020; |
| 4144 | MCHBAR32(0x1490) = 0x1010220; |
| 4145 | MCHBAR32(0x1494) = 0x10210; |
| 4146 | MCHBAR32(0x1498) = 0x10320; |
| 4147 | MCHBAR32(0x149c) = 0x1010220; |
| 4148 | MCHBAR32(0x14a0) = 0x1010001; |
| 4149 | MCHBAR32(0x14a4) = 0x1110000; |
| 4150 | MCHBAR32(0x14a8) = 0xd040020; |
| 4151 | MCHBAR32(0x14ac) = 0x8090220; |
| 4152 | MCHBAR32(0x14b0) = 0x1111310; |
| 4153 | MCHBAR32(0x14b4) = 0x1111420; |
| 4154 | MCHBAR32(0x14b8) = 0x8090220; |
| 4155 | MCHBAR32(0x14bc) = 0x1010001; |
| 4156 | MCHBAR32(0x14c0) = 0x1110000; |
| 4157 | MCHBAR32(0x14c4) = 0x3010020; |
| 4158 | MCHBAR32(0x14c8) = 0x7090220; |
| 4159 | MCHBAR32(0x14cc) = 0x1081310; |
| 4160 | MCHBAR32(0x14d0) = 0x1081420; |
| 4161 | MCHBAR32(0x14d4) = 0x7090220; |
| 4162 | MCHBAR32(0x14d8) = 0x1010001; |
| 4163 | MCHBAR32(0x14dc) = 0x1110000; |
| 4164 | MCHBAR32(0x14e0) = 0xb040020; |
| 4165 | MCHBAR32(0x14e4) = 0x2030220; |
| 4166 | MCHBAR32(0x14e8) = 0x1051310; |
| 4167 | MCHBAR32(0x14ec) = 0x1051420; |
| 4168 | MCHBAR32(0x14f0) = 0x2030220; |
| 4169 | MCHBAR32(0x14f4) = 0x1010001; |
| 4170 | MCHBAR32(0x14f8) = 0x1110000; |
| 4171 | MCHBAR32(0x14fc) = 0x5020020; |
| 4172 | MCHBAR32(0x1500) = 0x5090220; |
| 4173 | MCHBAR32(0x1504) = 0x2071310; |
| 4174 | MCHBAR32(0x1508) = 0x2071420; |
| 4175 | MCHBAR32(0x150c) = 0x5090220; |
| 4176 | MCHBAR32(0x1510) = 0x1010001; |
| 4177 | MCHBAR32(0x1514) = 0x1110000; |
| 4178 | MCHBAR32(0x1518) = 0x7040120; |
| 4179 | MCHBAR32(0x151c) = 0x2090220; |
| 4180 | MCHBAR32(0x1520) = 0x70b1210; |
| 4181 | MCHBAR32(0x1524) = 0x70b1310; |
| 4182 | MCHBAR32(0x1528) = 0x2090220; |
| 4183 | MCHBAR32(0x152c) = 0x1010001; |
| 4184 | MCHBAR32(0x1530) = 0x1110000; |
| 4185 | MCHBAR32(0x1534) = 0x1010110; |
| 4186 | MCHBAR32(0x1538) = 0x1081310; |
| 4187 | MCHBAR32(0x153c) = 0x5041200; |
| 4188 | MCHBAR32(0x1540) = 0x5041310; |
| 4189 | MCHBAR32(0x1544) = 0x1081310; |
| 4190 | MCHBAR32(0x1548) = 0x1010001; |
| 4191 | MCHBAR32(0x154c) = 0x1110000; |
| 4192 | MCHBAR32(0x1550) = 0x1040120; |
| 4193 | MCHBAR32(0x1554) = 0x4051210; |
| 4194 | MCHBAR32(0x1558) = 0xd051200; |
| 4195 | MCHBAR32(0x155c) = 0xd051200; |
| 4196 | MCHBAR32(0x1560) = 0x4051210; |
| 4197 | MCHBAR32(0x1564) = 0x1010001; |
| 4198 | MCHBAR32(0x1568) = 0x1110000; |
| 4199 | MCHBAR16(0x1222) = 0x220a; |
| 4200 | MCHBAR16(0x123c) = 0x1fc0; |
| 4201 | MCHBAR16(0x1220) = 0x1388; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4202 | } |
| 4203 | |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4204 | MCHBAR32_AND_OR(0x2c80, 0, 0x1053688); // !!!! |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4205 | MCHBAR32(0x1c04); // !!!! |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4206 | MCHBAR32(0x1804) = 0x406080; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4207 | |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4208 | MCHBAR8(0x2ca8); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4209 | |
| 4210 | if (x2ca8 == 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4211 | MCHBAR8_AND(0x2ca8, ~3); |
| 4212 | MCHBAR8(0x2ca8) = MCHBAR8(0x2ca8) + 4; // "+" or "|"? |
Arthur Heymans | b572c9d | 2019-10-14 18:18:46 +0200 | [diff] [blame] | 4213 | /* This issues a CPU reset without resetting the platform */ |
| 4214 | printk(BIOS_DEBUG, "Issuing a CPU reset\n"); |
Arthur Heymans | 2878c0b | 2019-10-14 18:42:00 +0200 | [diff] [blame] | 4215 | /* Write back the S3 state to PM1_CNT to let the reset CPU |
| 4216 | know it also needs to take the s3 path. */ |
| 4217 | if (s3resume) |
| 4218 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) |
| 4219 | | (SLP_TYP_S3 << 10)); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4220 | MCHBAR32_OR(0x1af0, 0x10); |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 4221 | halt(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4222 | } |
| 4223 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4224 | MCHBAR8(0x2ca8) = MCHBAR8(0x2ca8); |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4225 | MCHBAR32_AND_OR(0x2c80, 0, 0x53688); // !!!! |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4226 | pci_write_config32(PCI_DEV (0xff, 0, 0), 0x60, 0x20220); |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4227 | MCHBAR16(0x2c20); // !!!! |
| 4228 | MCHBAR16(0x2c10); // !!!! |
| 4229 | MCHBAR16(0x2c00); // !!!! |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4230 | MCHBAR16(0x2c00) = 0x8c0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4231 | udelay(1000); |
| 4232 | write_1d0(0, 0x33d, 0, 0); |
| 4233 | write_500(&info, 0, 0, 0xb61, 0, 0); |
| 4234 | write_500(&info, 1, 0, 0xb61, 0, 0); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4235 | MCHBAR32(0x1a30) = 0x0; |
| 4236 | MCHBAR32(0x1a34) = 0x0; |
| 4237 | MCHBAR16(0x614) = 0xb5b | (info.populated_ranks[1][0][0] * 0x404) | |
| 4238 | (info.populated_ranks[0][0][0] * 0xa0); |
| 4239 | MCHBAR16(0x616) = 0x26a; |
| 4240 | MCHBAR32(0x134) = 0x856000; |
| 4241 | MCHBAR32(0x160) = 0x5ffffff; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4242 | MCHBAR32_AND_OR(0x114, 0, 0xc2024440); // !!!! |
| 4243 | MCHBAR32_AND_OR(0x118, 0, 0x4); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4244 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4245 | MCHBAR32(0x260 + (channel << 10)) = 0x30809ff | |
| 4246 | ((info.populated_ranks_mask[channel] & 3) << 20); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4247 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4248 | MCHBAR16(0x31c + (channel << 10)) = 0x101; |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4249 | MCHBAR16(0x360 + (channel << 10)) = 0x909; |
| 4250 | MCHBAR16(0x3a4 + (channel << 10)) = 0x101; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4251 | MCHBAR16(0x3e8 + (channel << 10)) = 0x101; |
| 4252 | MCHBAR32(0x320 + (channel << 10)) = 0x29002900; |
| 4253 | MCHBAR32(0x324 + (channel << 10)) = 0x0; |
| 4254 | MCHBAR32(0x368 + (channel << 10)) = 0x32003200; |
| 4255 | MCHBAR16(0x352 + (channel << 10)) = 0x505; |
| 4256 | MCHBAR16(0x354 + (channel << 10)) = 0x3c3c; |
| 4257 | MCHBAR16(0x356 + (channel << 10)) = 0x1040; |
| 4258 | MCHBAR16(0x39a + (channel << 10)) = 0x73e4; |
| 4259 | MCHBAR16(0x3de + (channel << 10)) = 0x77ed; |
| 4260 | MCHBAR16(0x422 + (channel << 10)) = 0x1040; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | write_1d0(0x4, 0x151, 4, 1); |
| 4264 | write_1d0(0, 0x142, 3, 1); |
| 4265 | rdmsr(0x1ac); // !!!! |
| 4266 | write_500(&info, 1, 1, 0x6b3, 4, 1); |
| 4267 | write_500(&info, 1, 1, 0x6cf, 4, 1); |
| 4268 | |
| 4269 | rmw_1d0(0x21c, 0x38, 0, 6, 1); |
| 4270 | |
| 4271 | write_1d0(((!info.populated_ranks[1][0][0]) << 1) | ((!info. |
| 4272 | populated_ranks[0] |
| 4273 | [0][0]) << 0), |
| 4274 | 0x1d1, 3, 1); |
| 4275 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4276 | MCHBAR16(0x38e + (channel << 10)) = 0x5f5f; |
| 4277 | MCHBAR16(0x3d2 + (channel << 10)) = 0x5f5f; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | set_334(0); |
| 4281 | |
| 4282 | program_base_timings(&info); |
| 4283 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4284 | MCHBAR8_OR(0x5ff, 0x80); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4285 | |
| 4286 | write_1d0(0x2, 0x1d5, 2, 1); |
| 4287 | write_1d0(0x20, 0x166, 7, 1); |
| 4288 | write_1d0(0x0, 0xeb, 3, 1); |
| 4289 | write_1d0(0x0, 0xf3, 6, 1); |
| 4290 | |
| 4291 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4292 | for (lane = 0; lane < 9; lane++) { |
| 4293 | u16 addr = 0x125 + get_lane_offset(0, 0, lane); |
| 4294 | u8 a; |
| 4295 | a = read_500(&info, channel, addr, 6); // = 0x20040080 //!!!! |
| 4296 | write_500(&info, channel, a, addr, 6, 1); |
| 4297 | } |
| 4298 | |
| 4299 | udelay(1000); |
| 4300 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4301 | if (s3resume) { |
| 4302 | if (info.cached_training == NULL) { |
| 4303 | u32 reg32; |
| 4304 | printk(BIOS_ERR, |
| 4305 | "Couldn't find training data. Rebooting\n"); |
| 4306 | reg32 = inl(DEFAULT_PMBASE + 0x04); |
| 4307 | outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04); |
Elyes HAOUAS | d45f338 | 2019-04-28 18:04:35 +0200 | [diff] [blame] | 4308 | full_reset(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4309 | } |
| 4310 | int tm; |
| 4311 | info.training = *info.cached_training; |
| 4312 | for (tm = 0; tm < 4; tm++) |
| 4313 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4314 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 4315 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 4316 | for (lane = 0; lane < 9; lane++) |
| 4317 | write_500(&info, |
| 4318 | channel, |
| 4319 | info.training. |
| 4320 | lane_timings |
| 4321 | [tm][channel] |
| 4322 | [slot][rank] |
| 4323 | [lane], |
| 4324 | get_timing_register_addr |
| 4325 | (lane, tm, |
| 4326 | slot, rank), |
| 4327 | 9, 0); |
| 4328 | write_1d0(info.cached_training->reg_178, 0x178, 7, 1); |
| 4329 | write_1d0(info.cached_training->reg_10b, 0x10b, 6, 1); |
| 4330 | } |
| 4331 | |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4332 | MCHBAR32_AND_OR(0x1f4, 0, 0x20000); // !!!! |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4333 | MCHBAR32(0x1f0) = 0x1d000200; |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4334 | MCHBAR8_AND_OR(0x1f0, 0, 0x1); // !!!! |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4335 | MCHBAR8(0x1f0); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4336 | |
| 4337 | program_board_delay(&info); |
| 4338 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4339 | MCHBAR8(0x5ff) = 0x0; |
| 4340 | MCHBAR8(0x5ff) = 0x80; |
| 4341 | MCHBAR8(0x5f4) = 0x1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4342 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4343 | MCHBAR32_AND(0x130, 0xfffffffd); // | 2 when ? |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4344 | while (MCHBAR32(0x130) & 1) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4345 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4346 | gav(read_1d0(0x14b, 7)); // = 0x81023100 |
| 4347 | write_1d0(0x30, 0x14b, 7, 1); |
| 4348 | read_1d0(0xd6, 6); // = 0xfa008080 // !!!! |
| 4349 | write_1d0(7, 0xd6, 6, 1); |
| 4350 | read_1d0(0x328, 6); // = 0xfa018080 // !!!! |
| 4351 | write_1d0(7, 0x328, 6, 1); |
| 4352 | |
| 4353 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4354 | set_4cf(&info, channel, |
| 4355 | info.populated_ranks[channel][0][0] ? 8 : 0); |
| 4356 | |
| 4357 | read_1d0(0x116, 4); // = 0x4040432 // !!!! |
| 4358 | write_1d0(2, 0x116, 4, 1); |
| 4359 | read_1d0(0xae, 6); // = 0xe8088080 // !!!! |
| 4360 | write_1d0(0, 0xae, 6, 1); |
| 4361 | read_1d0(0x300, 4); // = 0x48088080 // !!!! |
| 4362 | write_1d0(0, 0x300, 6, 1); |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4363 | MCHBAR16_AND_OR(0x356, 0, 0x1040); // !!!! |
| 4364 | MCHBAR16_AND_OR(0x756, 0, 0x1040); // !!!! |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4365 | MCHBAR32_AND(0x140, ~0x07000000); |
| 4366 | MCHBAR32_AND(0x138, ~0x07000000); |
| 4367 | MCHBAR32(0x130) = 0x31111301; |
Vladimir Serbinenko | 25fc532 | 2014-12-07 13:05:44 +0100 | [diff] [blame] | 4368 | /* Wait until REG130b0 is 1. */ |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4369 | while (MCHBAR32(0x130) & 1) |
Vladimir Serbinenko | 25fc532 | 2014-12-07 13:05:44 +0100 | [diff] [blame] | 4370 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4371 | |
| 4372 | { |
| 4373 | u32 t; |
| 4374 | u8 val_a1; |
| 4375 | val_a1 = read_1d0(0xa1, 6); // = 0x1cf4040 // !!!! |
| 4376 | t = read_1d0(0x2f3, 6); // = 0x10a4040 // !!!! |
| 4377 | rmw_1d0(0x320, 0x07, |
| 4378 | (t & 4) | ((t & 8) >> 2) | ((t & 0x10) >> 4), 6, 1); |
| 4379 | rmw_1d0(0x14b, 0x78, |
| 4380 | ((((val_a1 >> 2) & 4) | (val_a1 & 8)) >> 2) | (val_a1 & |
| 4381 | 4), 7, |
| 4382 | 1); |
| 4383 | rmw_1d0(0xce, 0x38, |
| 4384 | ((((val_a1 >> 2) & 4) | (val_a1 & 8)) >> 2) | (val_a1 & |
| 4385 | 4), 6, |
| 4386 | 1); |
| 4387 | } |
| 4388 | |
| 4389 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4390 | set_4cf(&info, channel, |
| 4391 | info.populated_ranks[channel][0][0] ? 9 : 1); |
| 4392 | |
| 4393 | rmw_1d0(0x116, 0xe, 1, 4, 1); // = 0x4040432 // !!!! |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4394 | MCHBAR32(0x144); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4395 | write_1d0(2, 0xae, 6, 1); |
| 4396 | write_1d0(2, 0x300, 6, 1); |
| 4397 | write_1d0(2, 0x121, 3, 1); |
| 4398 | read_1d0(0xd6, 6); // = 0xfa00c0c7 // !!!! |
| 4399 | write_1d0(4, 0xd6, 6, 1); |
| 4400 | read_1d0(0x328, 6); // = 0xfa00c0c7 // !!!! |
| 4401 | write_1d0(4, 0x328, 6, 1); |
| 4402 | |
| 4403 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4404 | set_4cf(&info, channel, |
| 4405 | info.populated_ranks[channel][0][0] ? 9 : 0); |
| 4406 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4407 | MCHBAR32(0x130) = 0x11111301 | (info.populated_ranks[1][0][0] << 30) | |
| 4408 | (info.populated_ranks[0][0][0] << 29); |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4409 | while (MCHBAR8(0x130) & 1) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4410 | ; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4411 | read_1d0(0xa1, 6); // = 0x1cf4054 // !!!! |
| 4412 | read_1d0(0x2f3, 6); // = 0x10a4054 // !!!! |
| 4413 | read_1d0(0x21c, 6); // = 0xafa00c0 // !!!! |
| 4414 | write_1d0(0, 0x21c, 6, 1); |
| 4415 | read_1d0(0x14b, 7); // = 0x810231b0 // !!!! |
| 4416 | write_1d0(0x35, 0x14b, 7, 1); |
| 4417 | |
| 4418 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4419 | set_4cf(&info, channel, |
| 4420 | info.populated_ranks[channel][0][0] ? 0xb : 0x2); |
| 4421 | |
| 4422 | set_334(1); |
| 4423 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4424 | MCHBAR8(0x1e8) = 0x4; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4425 | |
| 4426 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
| 4427 | write_500(&info, channel, |
| 4428 | 0x3 & ~(info.populated_ranks_mask[channel]), 0x6b7, 2, |
| 4429 | 1); |
| 4430 | write_500(&info, channel, 0x3, 0x69b, 2, 1); |
| 4431 | } |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4432 | MCHBAR32_AND_OR(0x2d0, 0xff2c01ff, 0x200000); |
| 4433 | MCHBAR16(0x6c0) = 0x14a0; |
| 4434 | MCHBAR32_AND_OR(0x6d0, 0xff0080ff, 0x8000); |
| 4435 | MCHBAR16(0x232) = 0x8; |
| 4436 | /* 0x40004 or 0 depending on ? */ |
| 4437 | MCHBAR32_AND_OR(0x234, 0xfffbfffb, 0x40004); |
| 4438 | MCHBAR32_AND_OR(0x34, 0xfffffffd, 5); |
| 4439 | MCHBAR32(0x128) = 0x2150d05; |
| 4440 | MCHBAR8(0x12c) = 0x1f; |
| 4441 | MCHBAR8(0x12d) = 0x56; |
| 4442 | MCHBAR8(0x12e) = 0x31; |
| 4443 | MCHBAR8(0x12f) = 0x0; |
| 4444 | MCHBAR8(0x271) = 0x2; |
| 4445 | MCHBAR8(0x671) = 0x2; |
| 4446 | MCHBAR8(0x1e8) = 0x4; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4447 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4448 | MCHBAR32(0x294 + (channel << 10)) = |
| 4449 | (info.populated_ranks_mask[channel] & 3) << 16; |
| 4450 | MCHBAR32_AND_OR(0x134, 0xfc01ffff, 0x10000); |
| 4451 | MCHBAR32_AND_OR(0x134, 0xfc85ffff, 0x850000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4452 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4453 | MCHBAR32_AND_OR(0x260 + (channel << 10), ~0xf00000, 0x8000000 | |
| 4454 | ((info.populated_ranks_mask[channel] & 3) << 20)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4455 | |
| 4456 | if (!s3resume) |
| 4457 | jedec_init(&info); |
| 4458 | |
| 4459 | int totalrank = 0; |
| 4460 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4461 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 4462 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 4463 | if (info.populated_ranks[channel][slot][rank]) { |
| 4464 | jedec_read(&info, channel, slot, rank, |
| 4465 | totalrank, 0xa, 0x400); |
| 4466 | totalrank++; |
| 4467 | } |
| 4468 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4469 | MCHBAR8(0x12c) = 0x9f; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4470 | |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4471 | MCHBAR8_AND_OR(0x271, 0, 0xe); // 2 // !!!! |
| 4472 | MCHBAR8_AND_OR(0x671, 0, 0xe); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4473 | |
| 4474 | if (!s3resume) { |
| 4475 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4476 | MCHBAR32(0x294 + (channel << 10)) = |
| 4477 | (info.populated_ranks_mask[channel] & 3) << 16; |
| 4478 | MCHBAR16(0x298 + (channel << 10)) = |
| 4479 | info.populated_ranks[channel][0][0] | |
| 4480 | (info.populated_ranks[channel][0][1] << 5); |
| 4481 | MCHBAR32(0x29c + (channel << 10)) = 0x77a; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4482 | } |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4483 | MCHBAR32_AND_OR(0x2c0, 0, 0x6009cc00); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4484 | |
| 4485 | { |
| 4486 | u8 a, b; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4487 | a = MCHBAR8(0x243); |
| 4488 | b = MCHBAR8(0x643); |
| 4489 | MCHBAR8(0x243) = a | 2; |
| 4490 | MCHBAR8(0x643) = b | 2; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | write_1d0(7, 0x19b, 3, 1); |
| 4494 | write_1d0(7, 0x1c0, 3, 1); |
| 4495 | write_1d0(4, 0x1c6, 4, 1); |
| 4496 | write_1d0(4, 0x1cc, 4, 1); |
| 4497 | read_1d0(0x151, 4); // = 0x408c6d74 // !!!! |
| 4498 | write_1d0(4, 0x151, 4, 1); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4499 | MCHBAR32(0x584) = 0xfffff; |
| 4500 | MCHBAR32(0x984) = 0xfffff; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4501 | |
| 4502 | for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 4503 | for (slot = 0; slot < NUM_SLOTS; slot++) |
| 4504 | for (rank = 0; rank < NUM_RANKS; rank++) |
| 4505 | if (info. |
| 4506 | populated_ranks[channel][slot] |
| 4507 | [rank]) |
| 4508 | config_rank(&info, s3resume, |
| 4509 | channel, slot, |
| 4510 | rank); |
| 4511 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4512 | MCHBAR8(0x243) = 0x1; |
| 4513 | MCHBAR8(0x643) = 0x1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | /* was == 1 but is common */ |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4517 | pci_write_config16(NORTHBRIDGE, 0xc8, 3); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4518 | write_26c(0, 0x820); |
| 4519 | write_26c(1, 0x820); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4520 | MCHBAR32_OR(0x130, 2); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4521 | /* end */ |
| 4522 | |
| 4523 | if (s3resume) { |
| 4524 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4525 | MCHBAR32(0x294 + (channel << 10)) = |
| 4526 | (info.populated_ranks_mask[channel] & 3) << 16; |
| 4527 | MCHBAR16(0x298 + (channel << 10)) = |
| 4528 | info.populated_ranks[channel][0][0] | |
| 4529 | (info.populated_ranks[channel][0][1] << 5); |
| 4530 | MCHBAR32(0x29c + (channel << 10)) = 0x77a; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4531 | } |
Felix Held | f83d80b | 2018-07-29 05:30:30 +0200 | [diff] [blame] | 4532 | MCHBAR32_AND_OR(0x2c0, 0, 0x6009cc00); // !!!! |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4533 | } |
| 4534 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4535 | MCHBAR32_AND(0xfa4, ~0x01000002); |
| 4536 | MCHBAR32(0xfb0) = 0x2000e019; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4537 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4538 | /* Before training. */ |
| 4539 | timestamp_add_now(103); |
| 4540 | |
| 4541 | if (!s3resume) |
| 4542 | ram_training(&info); |
| 4543 | |
| 4544 | /* After training. */ |
Paul Menzel | 9e817bf | 2015-05-28 07:32:48 +0200 | [diff] [blame] | 4545 | timestamp_add_now(104); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4546 | |
| 4547 | dump_timings(&info); |
| 4548 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4549 | program_modules_memory_map(&info, 0); |
| 4550 | program_total_memory_map(&info); |
| 4551 | |
| 4552 | if (info.non_interleaved_part_mb != 0 && info.interleaved_part_mb != 0) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4553 | MCHBAR8(0x111) = 0x20 | (0 << 2) | (1 << 6) | (0 << 7); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4554 | else if (have_match_ranks(&info, 0, 4) && have_match_ranks(&info, 1, 4)) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4555 | MCHBAR8(0x111) = 0x20 | (3 << 2) | (0 << 6) | (1 << 7); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4556 | else if (have_match_ranks(&info, 0, 2) && have_match_ranks(&info, 1, 2)) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4557 | MCHBAR8(0x111) = 0x20 | (3 << 2) | (0 << 6) | (0 << 7); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4558 | else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4559 | MCHBAR8(0x111) = 0x20 | (3 << 2) | (1 << 6) | (0 << 7); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4560 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4561 | MCHBAR32_AND(0xfac, ~0x80000000); |
| 4562 | MCHBAR32(0xfb4) = 0x4800; |
| 4563 | MCHBAR32(0xfb8) = (info.revision < 8) ? 0x20 : 0x0; |
| 4564 | MCHBAR32(0xe94) = 0x7ffff; |
| 4565 | MCHBAR32(0xfc0) = 0x80002040; |
| 4566 | MCHBAR32(0xfc4) = 0x701246; |
| 4567 | MCHBAR8_AND(0xfc8, ~0x70); |
| 4568 | MCHBAR32_OR(0xe5c, 0x1000000); |
| 4569 | MCHBAR32_AND_OR(0x1a70, ~0x00100000, 0x00200000); |
| 4570 | MCHBAR32(0x50) = 0x700b0; |
| 4571 | MCHBAR32(0x3c) = 0x10; |
| 4572 | MCHBAR8(0x1aa8) = (MCHBAR8(0x1aa8) & ~0x35) | 0xa; |
| 4573 | MCHBAR8_OR(0xff4, 0x2); |
| 4574 | MCHBAR32_AND_OR(0xff8, ~0xe008, 0x1020); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4575 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4576 | MCHBAR32(0xd00) = IOMMU_BASE2 | 1; |
| 4577 | MCHBAR32(0xd40) = IOMMU_BASE1 | 1; |
| 4578 | MCHBAR32(0xdc0) = IOMMU_BASE4 | 1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4579 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 4580 | write32p(IOMMU_BASE1 | 0xffc, 0x80000000); |
| 4581 | write32p(IOMMU_BASE2 | 0xffc, 0xc0000000); |
| 4582 | write32p(IOMMU_BASE4 | 0xffc, 0x80000000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4583 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4584 | { |
| 4585 | u32 eax; |
| 4586 | |
| 4587 | eax = info.fsb_frequency / 9; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4588 | MCHBAR32_AND_OR(0xfcc, 0xfffc0000, |
| 4589 | (eax * 0x280) | (eax * 0x5000) | eax | 0x40000); |
| 4590 | MCHBAR32(0x20) = 0x33001; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4594 | MCHBAR32_AND(0x220 + (channel << 10), ~0x7770); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4595 | if (info.max_slots_used_in_channel == 1) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4596 | MCHBAR16_OR(0x237 + (channel << 10), 0x0201); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4597 | else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4598 | MCHBAR16_AND(0x237 + (channel << 10), ~0x0201); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4599 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4600 | MCHBAR8_OR(0x241 + (channel << 10), 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4601 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4602 | if (info.clock_speed_index <= 1 && (info.silicon_revision == 2 |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4603 | || info.silicon_revision == 3)) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4604 | MCHBAR32_OR(0x248 + (channel << 10), 0x00102000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4605 | else |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4606 | MCHBAR32_AND(0x248 + (channel << 10), ~0x00102000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4607 | } |
| 4608 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4609 | MCHBAR32_OR(0x115, 0x1000000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4610 | |
| 4611 | { |
| 4612 | u8 al; |
| 4613 | al = 0xd; |
| 4614 | if (!(info.silicon_revision == 0 || info.silicon_revision == 1)) |
| 4615 | al += 2; |
| 4616 | al |= ((1 << (info.max_slots_used_in_channel - 1)) - 1) << 4; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4617 | MCHBAR32(0x210) = (al << 16) | 0x20; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | for (channel = 0; channel < NUM_CHANNELS; channel++) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4621 | MCHBAR32(0x288 + (channel << 10)) = 0x70605040; |
| 4622 | MCHBAR32(0x28c + (channel << 10)) = 0xfffec080; |
| 4623 | MCHBAR32(0x290 + (channel << 10)) = 0x282091c | |
| 4624 | ((info.max_slots_used_in_channel - 1) << 0x16); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4625 | } |
| 4626 | u32 reg1c; |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4627 | pci_read_config32(NORTHBRIDGE, 0x40); // = DEFAULT_EPBAR | 0x001 // OK |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 4628 | reg1c = read32p(DEFAULT_EPBAR | 0x01c); // = 0x8001 // OK |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4629 | pci_read_config32(NORTHBRIDGE, 0x40); // = DEFAULT_EPBAR | 0x001 // OK |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 4630 | write32p(DEFAULT_EPBAR | 0x01c, reg1c); // OK |
Elyes HAOUAS | 97642c2 | 2019-05-22 20:53:25 +0200 | [diff] [blame] | 4631 | MCHBAR8(0xe08); // = 0x0 |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4632 | pci_read_config32(NORTHBRIDGE, 0xe4); // = 0x316126 |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4633 | MCHBAR8_OR(0x1210, 2); |
| 4634 | MCHBAR32(0x1200) = 0x8800440; |
| 4635 | MCHBAR32(0x1204) = 0x53ff0453; |
| 4636 | MCHBAR32(0x1208) = 0x19002043; |
| 4637 | MCHBAR16(0x1214) = 0x320; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4638 | |
| 4639 | if (info.revision == 0x10 || info.revision == 0x11) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4640 | MCHBAR16(0x1214) = 0x220; |
| 4641 | MCHBAR8_OR(0x1210, 0x40); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4644 | MCHBAR8_OR(0x1214, 0x4); |
| 4645 | MCHBAR8(0x120c) = 0x1; |
| 4646 | MCHBAR8(0x1218) = 0x3; |
| 4647 | MCHBAR8(0x121a) = 0x3; |
| 4648 | MCHBAR8(0x121c) = 0x3; |
| 4649 | MCHBAR16(0xc14) = 0x0; |
| 4650 | MCHBAR16(0xc20) = 0x0; |
| 4651 | MCHBAR32(0x1c) = 0x0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4652 | |
| 4653 | /* revision dependent here. */ |
| 4654 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4655 | MCHBAR16_OR(0x1230, 0x1f07); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4656 | |
| 4657 | if (info.uma_enabled) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4658 | MCHBAR32_OR(0x11f4, 0x10000000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4659 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4660 | MCHBAR16_OR(0x1230, 0x8000); |
| 4661 | MCHBAR8_OR(0x1214, 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4662 | |
| 4663 | u8 bl, ebpb; |
| 4664 | u16 reg_1020; |
| 4665 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4666 | reg_1020 = MCHBAR32(0x1020); // = 0x6c733c // OK |
| 4667 | MCHBAR8(0x1070) = 0x1; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4668 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4669 | MCHBAR32(0x1000) = 0x100; |
| 4670 | MCHBAR8(0x1007) = 0x0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4671 | |
| 4672 | if (reg_1020 != 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4673 | MCHBAR16(0x1018) = 0x0; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4674 | bl = reg_1020 >> 8; |
| 4675 | ebpb = reg_1020 & 0xff; |
| 4676 | } else { |
| 4677 | ebpb = 0; |
| 4678 | bl = 8; |
| 4679 | } |
| 4680 | |
| 4681 | rdmsr(0x1a2); |
| 4682 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4683 | MCHBAR32(0x1014) = 0xffffffff; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4684 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4685 | MCHBAR32(0x1010) = ((((ebpb + 0x7d) << 7) / bl) & 0xff) * (!!reg_1020); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4686 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4687 | MCHBAR8(0x101c) = 0xb8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4688 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4689 | MCHBAR8(0x123e) = (MCHBAR8(0x123e) & 0xf) | 0x60; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4690 | if (reg_1020 != 0) { |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4691 | MCHBAR32_AND_OR(0x123c, ~0x00900000, 0x600000); |
| 4692 | MCHBAR8(0x101c) = 0xb8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | setup_heci_uma(&info); |
| 4696 | |
| 4697 | if (info.uma_enabled) { |
| 4698 | u16 ax; |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4699 | MCHBAR32_OR(0x11b0, 0x4000); |
| 4700 | MCHBAR32_OR(0x11b4, 0x4000); |
| 4701 | MCHBAR16_OR(0x1190, 0x4000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4702 | |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4703 | ax = MCHBAR16(0x1190) & 0xf00; // = 0x480a // OK |
| 4704 | MCHBAR16(0x1170) = ax | (MCHBAR16(0x1170) & 0x107f) | 0x4080; |
| 4705 | MCHBAR16_OR(0x1170, 0x1000); |
| 4706 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4707 | udelay(1000); |
Felix Held | 29a9c07 | 2018-07-29 01:34:45 +0200 | [diff] [blame] | 4708 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4709 | u16 ecx; |
Felix Held | 22ca8cb | 2018-07-29 05:09:44 +0200 | [diff] [blame] | 4710 | for (ecx = 0xffff; ecx && (MCHBAR16(0x1170) & 0x1000); ecx--) |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4711 | ; |
| 4712 | MCHBAR16_AND(0x1190, ~0x4000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4713 | } |
| 4714 | |
Kyösti Mälkki | d45114f | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 4715 | pci_write_config8(SOUTHBRIDGE, GEN_PMCON_2, |
| 4716 | pci_read_config8(SOUTHBRIDGE, GEN_PMCON_2) & ~0x80); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4717 | udelay(10000); |
Felix Held | 04be2dd | 2018-07-29 04:53:22 +0200 | [diff] [blame] | 4718 | MCHBAR16(0x2ca8) = 0x8; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4719 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4720 | udelay(1000); |
| 4721 | dump_timings(&info); |
Vladimir Serbinenko | b16f092 | 2014-06-07 16:27:27 +0200 | [diff] [blame] | 4722 | cbmem_wasnot_inited = cbmem_recovery(s3resume); |
| 4723 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4724 | if (!s3resume) |
| 4725 | save_timings(&info); |
Vladimir Serbinenko | b16f092 | 2014-06-07 16:27:27 +0200 | [diff] [blame] | 4726 | if (s3resume && cbmem_wasnot_inited) { |
| 4727 | u32 reg32; |
| 4728 | printk(BIOS_ERR, "Failed S3 resume.\n"); |
| 4729 | ram_check(0x100000, 0x200000); |
| 4730 | |
| 4731 | /* Clear SLP_TYPE. */ |
| 4732 | reg32 = inl(DEFAULT_PMBASE + 0x04); |
| 4733 | outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04); |
| 4734 | |
| 4735 | /* Failed S3 resume, reset to come up cleanly */ |
Elyes HAOUAS | d45f338 | 2019-04-28 18:04:35 +0200 | [diff] [blame] | 4736 | full_reset(); |
Vladimir Serbinenko | b16f092 | 2014-06-07 16:27:27 +0200 | [diff] [blame] | 4737 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4738 | } |