Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1 | /* This was originally for the e7500, modified for e7501 |
| 2 | * The primary differences are that 7501 apparently can |
| 3 | * support single channel RAM (i haven't tested), |
| 4 | * CAS1.5 is no longer supported, The ECC scrubber |
| 5 | * now supports a mode to zero RAM and init ECC in one step |
| 6 | * and the undocumented registers at 0x80 require new |
| 7 | * (undocumented) values determined by guesswork and |
| 8 | * comparison w/ OEM BIOS values. |
| 9 | * Steven James 02/06/2003 |
| 10 | */ |
| 11 | |
| 12 | /* converted to C 6/2004 yhlu */ |
| 13 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 14 | |
| 15 | #include <stdint.h> |
| 16 | #include <device/pci_def.h> |
| 17 | #include <arch/io.h> |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 18 | #include <arch/cpu.h> |
Alexandru Gagniuc | af4bd59 | 2014-01-12 15:42:58 -0600 | [diff] [blame] | 19 | #include <lib.h> |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <console/console.h> |
| 22 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 23 | #include <cpu/x86/mtrr.h> |
| 24 | #include <cpu/x86/cache.h> |
| 25 | #include <cpu/x86/msr.h> |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 26 | #include <assert.h> |
| 27 | #include <spd.h> |
| 28 | #include <sdram_mode.h> |
Kyösti Mälkki | dcb688e | 2013-09-04 01:11:16 +0300 | [diff] [blame] | 29 | #include <cbmem.h> |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 30 | |
| 31 | #include "raminit.h" |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 32 | #include "e7505.h" |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 33 | #include "debug.h" |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 34 | |
| 35 | /*----------------------------------------------------------------------------- |
| 36 | Definitions: |
| 37 | -----------------------------------------------------------------------------*/ |
| 38 | |
| 39 | // Uncomment this to enable run-time checking of DIMM parameters |
| 40 | // for dual-channel operation |
| 41 | // Unfortunately the code seems to chew up several K of space. |
| 42 | //#define VALIDATE_DIMM_COMPATIBILITY |
| 43 | |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 44 | #if IS_ENABLED(CONFIG_DEBUG_RAM_SETUP) |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 45 | #define RAM_DEBUG_MESSAGE(x) printk(BIOS_DEBUG, x) |
| 46 | #define RAM_DEBUG_HEX32(x) printk(BIOS_DEBUG, "%08x", x) |
| 47 | #define RAM_DEBUG_HEX8(x) printk(BIOS_DEBUG, "%02x", x) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 48 | #define DUMPNORTH() dump_pci_device(MCHDEV) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 49 | #else |
| 50 | #define RAM_DEBUG_MESSAGE(x) |
| 51 | #define RAM_DEBUG_HEX32(x) |
| 52 | #define RAM_DEBUG_HEX8(x) |
| 53 | #define DUMPNORTH() |
| 54 | #endif |
| 55 | |
| 56 | #define E7501_SDRAM_MODE (SDRAM_BURST_INTERLEAVED | SDRAM_BURST_4) |
| 57 | #define SPD_ERROR "Error reading SPD info\n" |
| 58 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 59 | #define MCHDEV PCI_DEV(0,0,0) |
| 60 | #define RASDEV PCI_DEV(0,0,1) |
| 61 | #define D060DEV PCI_DEV(0,6,0) |
| 62 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 63 | // NOTE: This used to be 0x100000. |
| 64 | // That doesn't work on systems where A20M# is asserted, because |
| 65 | // attempts to access 0x1000NN end up accessing 0x0000NN. |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 66 | #define RCOMP_MMIO ((u8 *)0x200000) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 67 | |
| 68 | struct dimm_size { |
| 69 | unsigned long side1; |
| 70 | unsigned long side2; |
| 71 | }; |
| 72 | |
| 73 | static const uint32_t refresh_frequency[] = { |
| 74 | /* Relative frequency (array value) of each E7501 Refresh Mode Select |
| 75 | * (RMS) value (array index) |
| 76 | * 0 == least frequent refresh (longest interval between refreshes) |
| 77 | * [0] disabled -> 0 |
| 78 | * [1] 15.6 usec -> 2 |
| 79 | * [2] 7.8 usec -> 3 |
| 80 | * [3] 64 usec -> 1 |
| 81 | * [4] reserved -> 0 |
| 82 | * [5] reserved -> 0 |
| 83 | * [6] reserved -> 0 |
| 84 | * [7] 64 clocks -> 4 |
| 85 | */ |
| 86 | 0, 2, 3, 1, 0, 0, 0, 4 |
| 87 | }; |
| 88 | |
| 89 | static const uint32_t refresh_rate_map[] = { |
| 90 | /* Map the JEDEC spd refresh rates (array index) to E7501 Refresh Mode |
| 91 | * Select values (array value) |
| 92 | * These are all the rates defined by JESD21-C Appendix D, Rev. 1.0 |
| 93 | * The E7501 supports only 15.6 us (1), 7.8 us (2), 64 us (3), and |
| 94 | * 64 clock (481 ns) (7) refresh. |
| 95 | * [0] == 15.625 us -> 15.6 us |
| 96 | * [1] == 3.9 us -> 481 ns |
| 97 | * [2] == 7.8 us -> 7.8 us |
| 98 | * [3] == 31.3 us -> 15.6 us |
| 99 | * [4] == 62.5 us -> 15.6 us |
| 100 | * [5] == 125 us -> 64 us |
| 101 | */ |
| 102 | 1, 7, 2, 1, 1, 3 |
| 103 | }; |
| 104 | |
| 105 | #define MAX_SPD_REFRESH_RATE ((sizeof(refresh_rate_map) / sizeof(uint32_t)) - 1) |
| 106 | |
Edward O'Callaghan | 08280cb | 2014-05-25 06:33:29 +1000 | [diff] [blame] | 107 | #ifdef VALIDATE_DIMM_COMPATIBILITY |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 108 | // SPD parameters that must match for dual-channel operation |
| 109 | static const uint8_t dual_channel_parameters[] = { |
| 110 | SPD_MEMORY_TYPE, |
| 111 | SPD_MODULE_VOLTAGE, |
| 112 | SPD_NUM_COLUMNS, |
| 113 | SPD_NUM_ROWS, |
| 114 | SPD_NUM_DIMM_BANKS, |
| 115 | SPD_PRIMARY_SDRAM_WIDTH, |
| 116 | SPD_NUM_BANKS_PER_SDRAM |
| 117 | }; |
Edward O'Callaghan | 08280cb | 2014-05-25 06:33:29 +1000 | [diff] [blame] | 118 | #endif /* VALIDATE_DIMM_COMPATIBILITY */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 119 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 120 | /* Comments here are remains of e7501 or even 855PM. |
| 121 | * They might be partially (in)correct for e7505. |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 122 | */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 123 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 124 | /* (DRAM Read Timing Control, if similar to 855PM?) |
| 125 | * 0x80 - 0x81 documented differently for e7505 |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 126 | * This register has something to do with CAS latencies, |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 127 | * possibly this is the real chipset control. |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 128 | * At 0x00 CAS latency 1.5 works. |
| 129 | * At 0x06 CAS latency 2.5 works. |
| 130 | * At 0x01 CAS latency 2.0 works. |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 131 | * |
| 132 | * This is still undocumented in e7501, but with different values |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 133 | * CAS 2.0 values taken from Intel BIOS settings, others are a guess |
| 134 | * and may be terribly wrong. Old values preserved as comments until I |
| 135 | * figure this out for sure. |
| 136 | * e7501 docs claim that CAS1.5 is unsupported, so it may or may not |
| 137 | * work at all. |
| 138 | * Steven James 02/06/2003 |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 139 | * |
| 140 | * NOTE: values now configured in configure_e7501_cas_latency() based |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 141 | * on SPD info and total number of DIMMs (per Intel) |
| 142 | */ |
| 143 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 144 | /* FDHC - Fixed DRAM Hole Control ??? |
| 145 | * 0x58 undocumented for e7505, memory hole in southbridge configuration? |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 146 | * [7:7] Hole_Enable |
| 147 | * 0 == No memory Hole |
| 148 | * 1 == Memory Hole from 15MB to 16MB |
| 149 | * [6:0] Reserved |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 150 | */ |
| 151 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 152 | /* Another Intel undocumented register |
| 153 | * 0x88 - 0x8B |
| 154 | * [31:31] Purpose unknown |
| 155 | * [26:26] Master DLL Reset? |
| 156 | * 0 == Normal operation? |
| 157 | * 1 == Reset? |
| 158 | * [07:07] Periodic memory recalibration? |
| 159 | * 0 == Disabled? |
| 160 | * 1 == Enabled? |
| 161 | * [04:04] Receive FIFO RE-Sync? |
| 162 | * 0 == Normal operation? |
| 163 | * 1 == Reset? |
| 164 | */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 165 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 166 | /* DDR RECOMP tables */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 167 | // Slew table for 2x drive? |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 168 | static const uint32_t slew_2x[] = { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 169 | 0x00000000, 0x76543210, 0xffffeca8, 0xffffffff, |
| 170 | 0x21000000, 0xa8765432, 0xffffffec, 0xffffffff, |
| 171 | }; |
| 172 | |
| 173 | // Pull Up / Pull Down offset table, if analogous to IXP2800? |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 174 | static const uint32_t pull_updown_offset_table[] = { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 175 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, |
| 176 | 0x88888888, 0x88888888, 0x88888888, 0x88888888, |
| 177 | }; |
| 178 | |
| 179 | /*----------------------------------------------------------------------------- |
| 180 | Delay functions: |
| 181 | -----------------------------------------------------------------------------*/ |
| 182 | |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 183 | /* Estimate that SLOW_DOWN_IO takes about 1 us */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 184 | #define SLOW_DOWN_IO inb(0x80) |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 185 | static void local_udelay(int i) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 186 | { |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 187 | while (i--) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 188 | SLOW_DOWN_IO; |
| 189 | } |
| 190 | } |
| 191 | |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 192 | /* delay for 200us */ |
| 193 | #define DO_DELAY local_udelay(200) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 194 | #define EXTRA_DELAY DO_DELAY |
| 195 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 196 | /*----------------------------------------------------------------------------- |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 197 | Handle (undocumented) control bits MCHTST and PCI_DEV(0,6,0) |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 198 | -----------------------------------------------------------------------------*/ |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 199 | typedef enum { |
| 200 | MCHTST_CMD_0, |
| 201 | D060_ENABLE, |
| 202 | D060_DISABLE, |
| 203 | RCOMP_BAR_ENABLE, |
| 204 | RCOMP_BAR_DISABLE, |
| 205 | } mchtst_cc; |
| 206 | |
| 207 | typedef enum { |
| 208 | D060_CMD_0, |
| 209 | D060_CMD_1, |
| 210 | } d060_cc; |
| 211 | |
| 212 | typedef enum { |
| 213 | RCOMP_HOLD, |
| 214 | RCOMP_RELEASE, |
| 215 | RCOMP_SMR_00, |
| 216 | RCOMP_SMR_01, |
| 217 | } rcomp_smr_cc; |
| 218 | |
| 219 | /** |
| 220 | * MCHTST - 0xF4 - 0xF7 -- Based on similarity to 855PM |
| 221 | * |
| 222 | * [31:31] Purpose unknown |
| 223 | * [30:30] Purpose unknown |
| 224 | * [29:23] Unknown - not used? |
| 225 | * [22:22] System Memory MMR Enable |
| 226 | * 0 == Disable: mem space and BAR at 0x14 are not accessible |
| 227 | * 1 == Enable: mem space and BAR at 0x14 are accessible |
| 228 | * [21:20] Purpose unknown |
| 229 | * [19:02] Unknown - not used? |
| 230 | * [01:01] D6EN (Device #6 enable) |
| 231 | * 0 == Disable |
| 232 | * 1 == Enable |
| 233 | * [00:00] Unknown - not used? |
| 234 | */ |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 235 | static void mchtest_control(mchtst_cc cmd) |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 236 | { |
| 237 | uint32_t dword = pci_read_config32(MCHDEV, MCHTST); |
| 238 | switch (cmd) { |
| 239 | case MCHTST_CMD_0: |
| 240 | dword &= ~(3 << 30); |
| 241 | break; |
| 242 | case RCOMP_BAR_ENABLE: |
| 243 | dword |= (1 << 22); |
| 244 | break; |
| 245 | case RCOMP_BAR_DISABLE: |
| 246 | dword &= ~(1 << 22); |
| 247 | break; |
| 248 | case D060_ENABLE: |
| 249 | dword |= (1 << 1); |
| 250 | break; |
| 251 | case D060_DISABLE: |
| 252 | dword &= ~(1 << 1); |
| 253 | break; |
| 254 | }; |
| 255 | pci_write_config32(MCHDEV, MCHTST, dword); |
| 256 | } |
| 257 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 258 | |
| 259 | /** |
| 260 | * |
| 261 | */ |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 262 | static void d060_control(d060_cc cmd) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 263 | { |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 264 | mchtest_control(D060_ENABLE); |
| 265 | uint32_t dword = pci_read_config32(D060DEV, 0xf0); |
| 266 | switch (cmd) { |
| 267 | case D060_CMD_0: |
| 268 | dword |= (1 << 2); |
| 269 | break; |
| 270 | case D060_CMD_1: |
| 271 | dword |= (3 << 27); |
| 272 | break; |
| 273 | } |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 274 | pci_write_config32(D060DEV, 0xf0, dword); |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 275 | mchtest_control(D060_DISABLE); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
| 279 | * |
| 280 | */ |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 281 | static void rcomp_smr_control(rcomp_smr_cc cmd) |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 282 | { |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 283 | uint32_t dword = read32(RCOMP_MMIO + SMRCTL); |
| 284 | switch (cmd) { |
| 285 | case RCOMP_HOLD: |
| 286 | dword |= (1 << 9); |
| 287 | break; |
| 288 | case RCOMP_RELEASE: |
| 289 | dword &= ~((1 << 9) | (3 << 0)); |
| 290 | dword |= (1 << 10) | (1 << 0); |
| 291 | break; |
| 292 | case RCOMP_SMR_00: |
| 293 | dword &= ~(1 << 8); |
| 294 | break; |
| 295 | case RCOMP_SMR_01: |
| 296 | dword |= (1 << 10) | (1 << 8); |
| 297 | break; |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 298 | } |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 299 | write32(RCOMP_MMIO + SMRCTL, dword); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /*----------------------------------------------------------------------------- |
| 303 | Serial presence detect (SPD) functions: |
| 304 | -----------------------------------------------------------------------------*/ |
| 305 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 306 | static void die_on_spd_error(int spd_return_value) |
| 307 | { |
| 308 | if (spd_return_value < 0) |
| 309 | die("Error reading SPD info\n"); |
| 310 | } |
| 311 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 312 | /** |
| 313 | * Calculate the page size for each physical bank of the DIMM: |
| 314 | * log2(page size) = (# columns) + log2(data width) |
| 315 | * |
| 316 | * NOTE: Page size is the total number of data bits in a row. |
| 317 | * |
| 318 | * @param dimm_socket_address SMBus address of DIMM socket to interrogate. |
| 319 | * @return log2(page size) for each side of the DIMM. |
| 320 | */ |
| 321 | static struct dimm_size sdram_spd_get_page_size(uint16_t dimm_socket_address) |
| 322 | { |
| 323 | uint16_t module_data_width; |
| 324 | int value; |
| 325 | struct dimm_size pgsz; |
| 326 | |
| 327 | pgsz.side1 = 0; |
| 328 | pgsz.side2 = 0; |
| 329 | |
| 330 | // Side 1 |
| 331 | value = spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS); |
| 332 | if (value < 0) |
| 333 | goto hw_err; |
| 334 | pgsz.side1 = value & 0xf; // # columns in bank 1 |
| 335 | |
| 336 | /* Get the module data width and convert it to a power of two */ |
| 337 | value = |
| 338 | spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_MSB); |
| 339 | if (value < 0) |
| 340 | goto hw_err; |
| 341 | module_data_width = (value & 0xff) << 8; |
| 342 | |
| 343 | value = |
| 344 | spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_LSB); |
| 345 | if (value < 0) |
| 346 | goto hw_err; |
| 347 | module_data_width |= (value & 0xff); |
| 348 | |
| 349 | pgsz.side1 += log2(module_data_width); |
| 350 | |
| 351 | /* side two */ |
| 352 | value = spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS); |
| 353 | if (value < 0) |
| 354 | goto hw_err; |
| 355 | if (value > 2) |
| 356 | die("Bad SPD value\n"); |
| 357 | if (value == 2) { |
| 358 | |
| 359 | pgsz.side2 = pgsz.side1; // Assume symmetric banks until we know differently |
| 360 | value = |
| 361 | spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS); |
| 362 | if (value < 0) |
| 363 | goto hw_err; |
| 364 | if ((value & 0xf0) != 0) { |
| 365 | // Asymmetric banks |
| 366 | pgsz.side2 -= value & 0xf; /* Subtract out columns on side 1 */ |
| 367 | pgsz.side2 += (value >> 4) & 0xf; /* Add in columns on side 2 */ |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return pgsz; |
| 372 | |
| 373 | hw_err: |
| 374 | die(SPD_ERROR); |
| 375 | return pgsz; // Never reached |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Read the width in bits of each DIMM side's DRAMs via SPD (i.e. 4, 8, 16). |
| 380 | * |
| 381 | * @param dimm_socket_address SMBus address of DIMM socket to interrogate. |
| 382 | * @return Width in bits of each DIMM side's DRAMs. |
| 383 | */ |
| 384 | static struct dimm_size sdram_spd_get_width(uint16_t dimm_socket_address) |
| 385 | { |
| 386 | int value; |
| 387 | struct dimm_size width; |
| 388 | |
| 389 | width.side1 = 0; |
| 390 | width.side2 = 0; |
| 391 | |
| 392 | value = |
| 393 | spd_read_byte(dimm_socket_address, SPD_PRIMARY_SDRAM_WIDTH); |
| 394 | die_on_spd_error(value); |
| 395 | |
| 396 | width.side1 = value & 0x7f; // Mask off bank 2 flag |
| 397 | |
| 398 | if (value & 0x80) { |
| 399 | width.side2 = width.side1 << 1; // Bank 2 exists and is double-width |
| 400 | } else { |
| 401 | // If bank 2 exists, it's the same width as bank 1 |
| 402 | value = |
| 403 | spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS); |
| 404 | die_on_spd_error(value); |
| 405 | |
| 406 | #ifdef ROMCC_IF_BUG_FIXED |
| 407 | if (value == 2) |
| 408 | width.side2 = width.side1; |
| 409 | #else |
| 410 | switch (value) { |
| 411 | case 2: |
| 412 | width.side2 = width.side1; |
| 413 | break; |
| 414 | |
| 415 | default: |
| 416 | break; |
| 417 | } |
| 418 | #endif |
| 419 | } |
| 420 | |
| 421 | return width; |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Calculate the log base 2 size in bits of both DIMM sides. |
| 426 | * |
| 427 | * log2(# bits) = (# columns) + log2(data width) + |
| 428 | * (# rows) + log2(banks per SDRAM) |
| 429 | * |
| 430 | * Note that it might be easier to use SPD byte 31 here, it has the DIMM size |
| 431 | * as a multiple of 4MB. The way we do it now we can size both sides of an |
| 432 | * asymmetric DIMM. |
| 433 | * |
| 434 | * @param dimm_socket_address SMBus address of DIMM socket to interrogate. |
| 435 | * @return log2(number of bits) for each side of the DIMM. |
| 436 | */ |
| 437 | static struct dimm_size spd_get_dimm_size(unsigned dimm_socket_address) |
| 438 | { |
| 439 | int value; |
| 440 | |
| 441 | // Start with log2(page size) |
| 442 | struct dimm_size sz = sdram_spd_get_page_size(dimm_socket_address); |
| 443 | |
| 444 | if (sz.side1 > 0) { |
| 445 | |
| 446 | value = spd_read_byte(dimm_socket_address, SPD_NUM_ROWS); |
| 447 | die_on_spd_error(value); |
| 448 | |
| 449 | sz.side1 += value & 0xf; |
| 450 | |
| 451 | if (sz.side2 > 0) { |
| 452 | |
| 453 | // Double-sided DIMM |
| 454 | if (value & 0xF0) |
| 455 | sz.side2 += value >> 4; // Asymmetric |
| 456 | else |
| 457 | sz.side2 += value; // Symmetric |
| 458 | } |
| 459 | |
| 460 | value = |
| 461 | spd_read_byte(dimm_socket_address, |
| 462 | SPD_NUM_BANKS_PER_SDRAM); |
| 463 | die_on_spd_error(value); |
| 464 | |
| 465 | value = log2(value); |
| 466 | sz.side1 += value; |
| 467 | if (sz.side2 > 0) |
| 468 | sz.side2 += value; |
| 469 | } |
| 470 | |
| 471 | return sz; |
| 472 | } |
| 473 | |
| 474 | #ifdef VALIDATE_DIMM_COMPATIBILITY |
| 475 | |
| 476 | /** |
| 477 | * Determine whether two DIMMs have the same value for an SPD parameter. |
| 478 | * |
| 479 | * @param spd_byte_number The SPD byte number to compare in both DIMMs. |
| 480 | * @param dimm0_address SMBus address of the 1st DIMM socket to interrogate. |
| 481 | * @param dimm1_address SMBus address of the 2nd DIMM socket to interrogate. |
| 482 | * @return 1 if both DIMM sockets report the same value for the specified |
| 483 | * SPD parameter, 0 if the values differed or an error occurred. |
| 484 | */ |
| 485 | static uint8_t are_spd_values_equal(uint8_t spd_byte_number, |
| 486 | uint16_t dimm0_address, |
| 487 | uint16_t dimm1_address) |
| 488 | { |
| 489 | uint8_t bEqual = 0; |
| 490 | int dimm0_value = spd_read_byte(dimm0_address, spd_byte_number); |
| 491 | int dimm1_value = spd_read_byte(dimm1_address, spd_byte_number); |
| 492 | |
| 493 | if ((dimm0_value >= 0) && (dimm1_value >= 0) |
| 494 | && (dimm0_value == dimm1_value)) |
| 495 | bEqual = 1; |
| 496 | |
| 497 | return bEqual; |
| 498 | } |
| 499 | #endif |
| 500 | |
| 501 | /** |
| 502 | * Scan for compatible DIMMs. |
| 503 | * |
| 504 | * The code in this module only supports dual-channel operation, so we test |
| 505 | * that compatible DIMMs are paired. |
| 506 | * |
| 507 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 508 | * addresses of DIMM slots on the mainboard. |
| 509 | * @return A bitmask indicating which of the possible sockets for each channel |
| 510 | * was found to contain a compatible DIMM. |
| 511 | * Bit 0 corresponds to the closest socket for channel 0 |
| 512 | * Bit 1 to the next socket for channel 0 |
| 513 | * ... |
| 514 | * Bit MAX_DIMM_SOCKETS_PER_CHANNEL-1 to the last socket for channel 0 |
| 515 | * Bit MAX_DIMM_SOCKETS_PER_CHANNEL is the closest socket for channel 1 |
| 516 | * ... |
| 517 | * Bit 2*MAX_DIMM_SOCKETS_PER_CHANNEL-1 is the last socket for channel 1 |
| 518 | */ |
| 519 | static uint8_t spd_get_supported_dimms(const struct mem_controller *ctrl) |
| 520 | { |
| 521 | int i; |
| 522 | uint8_t dimm_mask = 0; |
| 523 | |
| 524 | // Have to increase size of dimm_mask if this assertion is violated |
| 525 | ASSERT(MAX_DIMM_SOCKETS_PER_CHANNEL <= 4); |
| 526 | |
| 527 | // Find DIMMs we can support on channel 0. |
| 528 | // Then see if the corresponding channel 1 DIMM has the same parameters, |
| 529 | // since we only support dual-channel. |
| 530 | |
| 531 | for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 532 | |
| 533 | uint16_t channel0_dimm = ctrl->channel0[i]; |
| 534 | uint16_t channel1_dimm = ctrl->channel1[i]; |
| 535 | uint8_t bDualChannel = 1; |
| 536 | #ifdef VALIDATE_DIMM_COMPATIBILITY |
| 537 | struct dimm_size page_size; |
| 538 | struct dimm_size sdram_width; |
| 539 | #endif |
| 540 | int spd_value; |
| 541 | |
| 542 | if (channel0_dimm == 0) |
| 543 | continue; // No such socket on this mainboard |
| 544 | |
| 545 | if (spd_read_byte(channel0_dimm, SPD_MEMORY_TYPE) != |
| 546 | SPD_MEMORY_TYPE_SDRAM_DDR) |
| 547 | continue; |
| 548 | |
| 549 | #ifdef VALIDATE_DIMM_COMPATIBILITY |
| 550 | if (spd_read_byte(channel0_dimm, SPD_MODULE_VOLTAGE) != |
| 551 | SPD_VOLTAGE_SSTL2) |
| 552 | continue; // Unsupported voltage |
| 553 | |
| 554 | // E7501 does not support unregistered DIMMs |
| 555 | spd_value = |
| 556 | spd_read_byte(channel0_dimm, SPD_MODULE_ATTRIBUTES); |
| 557 | if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) |
| 558 | continue; |
| 559 | |
| 560 | // Must support burst = 4 for dual-channel operation on E7501 |
| 561 | // NOTE: for single-channel, burst = 8 is required |
| 562 | spd_value = |
| 563 | spd_read_byte(channel0_dimm, |
| 564 | SPD_SUPPORTED_BURST_LENGTHS); |
| 565 | if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0)) |
| 566 | continue; |
| 567 | |
| 568 | page_size = sdram_spd_get_page_size(channel0_dimm); |
| 569 | sdram_width = sdram_spd_get_width(channel0_dimm); |
| 570 | |
| 571 | // Validate DIMM page size |
| 572 | // The E7501 only supports page sizes of 4, 8, 16, or 32 KB per channel |
| 573 | // NOTE: 4 KB = 32 Kb = 2^15 |
| 574 | // 32 KB = 262 Kb = 2^18 |
| 575 | |
| 576 | if ((page_size.side1 < 15) || (page_size.side1 > 18)) |
| 577 | continue; |
| 578 | |
| 579 | // If DIMM is double-sided, verify side2 page size |
| 580 | if (page_size.side2 != 0) { |
| 581 | if ((page_size.side2 < 15) |
| 582 | || (page_size.side2 > 18)) |
| 583 | continue; |
| 584 | } |
| 585 | // Validate SDRAM width |
| 586 | // The E7501 only supports x4 and x8 devices |
| 587 | |
| 588 | if ((sdram_width.side1 != 4) && (sdram_width.side1 != 8)) |
| 589 | continue; |
| 590 | |
| 591 | // If DIMM is double-sided, verify side2 width |
| 592 | if (sdram_width.side2 != 0) { |
| 593 | if ((sdram_width.side2 != 4) |
| 594 | && (sdram_width.side2 != 8)) |
| 595 | continue; |
| 596 | } |
| 597 | #endif |
| 598 | // Channel 0 DIMM looks compatible. |
| 599 | // Now see if it is paired with the proper DIMM on channel 1. |
| 600 | |
| 601 | ASSERT(channel1_dimm != 0); // No such socket on this mainboard?? |
| 602 | |
| 603 | // NOTE: unpopulated DIMMs cause read to fail |
| 604 | spd_value = |
| 605 | spd_read_byte(channel1_dimm, SPD_MODULE_ATTRIBUTES); |
| 606 | if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) { |
| 607 | |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 608 | printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 609 | continue; |
| 610 | } |
| 611 | #ifdef VALIDATE_DIMM_COMPATIBILITY |
| 612 | spd_value = |
| 613 | spd_read_byte(channel1_dimm, |
| 614 | SPD_SUPPORTED_BURST_LENGTHS); |
| 615 | if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0)) |
| 616 | continue; |
| 617 | |
| 618 | int j; |
| 619 | for (j = 0; j < sizeof(dual_channel_parameters); ++j) { |
| 620 | if (!are_spd_values_equal |
| 621 | (dual_channel_parameters[j], channel0_dimm, |
| 622 | channel1_dimm)) { |
| 623 | |
| 624 | bDualChannel = 0; |
| 625 | break; |
| 626 | } |
| 627 | } |
Edward O'Callaghan | 08280cb | 2014-05-25 06:33:29 +1000 | [diff] [blame] | 628 | #endif /* VALIDATE_DIMM_COMPATIBILITY */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 629 | |
| 630 | // Code around ROMCC bug in optimization of "if" statements |
| 631 | #ifdef ROMCC_IF_BUG_FIXED |
| 632 | if (bDualChannel) { |
| 633 | // Made it through all the checks, this DIMM pair is usable |
| 634 | dimm_mask |= ((1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i))); |
| 635 | } else |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 636 | printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 637 | #else |
| 638 | switch (bDualChannel) { |
| 639 | case 0: |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 640 | printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | default: |
| 644 | // Made it through all the checks, this DIMM pair is usable |
| 645 | dimm_mask |= (1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i)); |
| 646 | break; |
| 647 | } |
| 648 | #endif |
| 649 | } |
| 650 | |
| 651 | return dimm_mask; |
| 652 | } |
| 653 | |
| 654 | /*----------------------------------------------------------------------------- |
| 655 | SDRAM configuration functions: |
| 656 | -----------------------------------------------------------------------------*/ |
| 657 | |
| 658 | /** |
| 659 | * Send the specified command to all DIMMs. |
| 660 | * |
| 661 | * @param command Specifies the command to be sent to the DIMMs. |
| 662 | * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the |
| 663 | * register value in JEDEC format. |
| 664 | */ |
| 665 | static void do_ram_command(uint8_t command, uint16_t jedec_mode_bits) |
| 666 | { |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 667 | uint8_t dimm_start_64M_multiple; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 668 | uintptr_t dimm_start_address; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 669 | uint32_t dram_controller_mode; |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 670 | uint8_t i; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 671 | |
| 672 | // Configure the RAM command |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 673 | dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 674 | dram_controller_mode &= 0xFFFFFF8F; |
| 675 | dram_controller_mode |= command; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 676 | pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 677 | |
| 678 | // RAM_COMMAND_NORMAL is an exception. |
| 679 | // It affects only the memory controller and does not need to be "sent" to the DIMMs. |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 680 | if (command == RAM_COMMAND_NORMAL) { |
| 681 | EXTRA_DELAY; |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 682 | return; |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 683 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 684 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 685 | // NOTE: for mode select commands, some of the location address bits are part of the command |
| 686 | // Map JEDEC mode bits to E7505 |
| 687 | if (command == RAM_COMMAND_MRS) { |
| 688 | // Host address lines [25:18] map to DIMM address lines [7:0] |
| 689 | // Host address lines [17:16] map to DIMM address lines [9:8] |
| 690 | // Host address lines [15:4] map to DIMM address lines [11:0] |
| 691 | dimm_start_address = (jedec_mode_bits & 0x00ff) << 18; |
| 692 | dimm_start_address |= (jedec_mode_bits & 0x0300) << 8; |
| 693 | dimm_start_address |= (jedec_mode_bits & 0x0fff) << 4; |
| 694 | } else if (command == RAM_COMMAND_EMRS) { |
| 695 | // Host address lines [15:4] map to DIMM address lines [11:0] |
| 696 | dimm_start_address = (jedec_mode_bits << 4); |
| 697 | } else { |
| 698 | ASSERT(jedec_mode_bits == 0); |
| 699 | dimm_start_address = 0; |
| 700 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 701 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 702 | // Send the command to all DIMMs by accessing a memory location within each |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 703 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 704 | dimm_start_64M_multiple = 0; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 705 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 706 | /* FIXME: Only address the number of rows present in the system? |
| 707 | * Seems like rows 4-7 overlap with 0-3. |
| 708 | */ |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 709 | for (i = 0; i < (MAX_NUM_CHANNELS * MAX_DIMM_SOCKETS_PER_CHANNEL); ++i) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 710 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 711 | uint8_t dimm_end_64M_multiple = pci_read_config8(MCHDEV, DRB_ROW_0 + i); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 712 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 713 | if (dimm_end_64M_multiple > dimm_start_64M_multiple) { |
| 714 | dimm_start_address &= 0x3ffffff; |
| 715 | dimm_start_address |= dimm_start_64M_multiple << 26; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 716 | read32((void *)dimm_start_address); |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 717 | // Set the start of the next DIMM |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 718 | dimm_start_64M_multiple = dimm_end_64M_multiple; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 721 | EXTRA_DELAY; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Set the mode register of all DIMMs. |
| 726 | * |
| 727 | * The proper CAS# latency setting is added to the mode bits specified |
| 728 | * by the caller. |
| 729 | * |
| 730 | * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the |
| 731 | * register value in JEDEC format. |
| 732 | */ |
| 733 | static void set_ram_mode(uint16_t jedec_mode_bits) |
| 734 | { |
| 735 | ASSERT(!(jedec_mode_bits & SDRAM_CAS_MASK)); |
| 736 | |
| 737 | uint32_t dram_cas_latency = |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 738 | pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 739 | |
| 740 | switch (dram_cas_latency) { |
| 741 | case DRT_CAS_2_5: |
| 742 | jedec_mode_bits |= SDRAM_CAS_2_5; |
| 743 | break; |
| 744 | |
| 745 | case DRT_CAS_2_0: |
| 746 | jedec_mode_bits |= SDRAM_CAS_2_0; |
| 747 | break; |
| 748 | |
| 749 | default: |
| 750 | BUG(); |
| 751 | break; |
| 752 | } |
| 753 | |
| 754 | do_ram_command(RAM_COMMAND_MRS, jedec_mode_bits); |
| 755 | } |
| 756 | |
| 757 | /*----------------------------------------------------------------------------- |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 758 | DIMM-independent configuration functions: |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 759 | -----------------------------------------------------------------------------*/ |
| 760 | |
| 761 | /** |
| 762 | * Configure the E7501's DRAM Row Boundary (DRB) registers for the memory |
| 763 | * present in the specified DIMM. |
| 764 | * |
| 765 | * @param dimm_log2_num_bits Specifies log2(number of bits) for each side of |
| 766 | * the DIMM. |
| 767 | * @param total_dram_64M_multiple Total DRAM in the system (as a multiple of |
| 768 | * 64 MB) for DIMMs < dimm_index. |
| 769 | * @param dimm_index Which DIMM pair is being processed |
| 770 | * (0..MAX_DIMM_SOCKETS_PER_CHANNEL). |
| 771 | * @return New multiple of 64 MB total DRAM in the system. |
| 772 | */ |
| 773 | static uint8_t configure_dimm_row_boundaries(struct dimm_size dimm_log2_num_bits, uint8_t total_dram_64M_multiple, unsigned dimm_index) |
| 774 | { |
| 775 | int i; |
| 776 | |
| 777 | ASSERT(dimm_index < MAX_DIMM_SOCKETS_PER_CHANNEL); |
| 778 | |
| 779 | // DIMM sides must be at least 32 MB |
| 780 | ASSERT(dimm_log2_num_bits.side1 >= 28); |
| 781 | ASSERT((dimm_log2_num_bits.side2 == 0) |
| 782 | || (dimm_log2_num_bits.side2 >= 28)); |
| 783 | |
| 784 | // In dual-channel mode, we are called only once for each pair of DIMMs. |
| 785 | // Each time we process twice the capacity of a single DIMM. |
| 786 | |
| 787 | // Convert single DIMM capacity to paired DIMM capacity |
| 788 | // (multiply by two ==> add 1 to log2) |
| 789 | dimm_log2_num_bits.side1++; |
| 790 | if (dimm_log2_num_bits.side2 > 0) |
| 791 | dimm_log2_num_bits.side2++; |
| 792 | |
| 793 | // Add the capacity of side 1 this DIMM pair (as a multiple of 64 MB) |
| 794 | // to the total capacity of the system |
| 795 | // NOTE: 64 MB == 512 Mb, and log2(512 Mb) == 29 |
| 796 | |
| 797 | total_dram_64M_multiple += (1 << (dimm_log2_num_bits.side1 - 29)); |
| 798 | |
| 799 | // Configure the boundary address for the row on side 1 |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 800 | pci_write_config8(MCHDEV, DRB_ROW_0 + (dimm_index << 1), |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 801 | total_dram_64M_multiple); |
| 802 | |
| 803 | // If the DIMMs are double-sided, add the capacity of side 2 this DIMM pair |
| 804 | // (as a multiple of 64 MB) to the total capacity of the system |
| 805 | if (dimm_log2_num_bits.side2 >= 29) |
| 806 | total_dram_64M_multiple += |
| 807 | (1 << (dimm_log2_num_bits.side2 - 29)); |
| 808 | |
| 809 | // Configure the boundary address for the row (if any) on side 2 |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 810 | pci_write_config8(MCHDEV, DRB_ROW_1 + (dimm_index << 1), |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 811 | total_dram_64M_multiple); |
| 812 | |
| 813 | // Update boundaries for rows subsequent to these. |
| 814 | // These settings will be overridden by a subsequent call if a populated physical slot exists |
| 815 | |
| 816 | for (i = dimm_index + 1; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 817 | pci_write_config8(MCHDEV, DRB_ROW_0 + (i << 1), |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 818 | total_dram_64M_multiple); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 819 | pci_write_config8(MCHDEV, DRB_ROW_1 + (i << 1), |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 820 | total_dram_64M_multiple); |
| 821 | } |
| 822 | |
| 823 | return total_dram_64M_multiple; |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Set the E7501's DRAM row boundary addresses & its Top Of Low Memory (TOLM). |
| 828 | * |
| 829 | * If necessary, set up a remap window so we don't waste DRAM that ordinarily |
| 830 | * would lie behind addresses reserved for memory-mapped I/O. |
| 831 | * |
| 832 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 833 | * addresses of DIMM slots on the mainboard. |
| 834 | * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms(). |
| 835 | */ |
| 836 | static void configure_e7501_ram_addresses(const struct mem_controller |
| 837 | *ctrl, uint8_t dimm_mask) |
| 838 | { |
| 839 | int i; |
| 840 | uint8_t total_dram_64M_multiple = 0; |
| 841 | |
| 842 | // Configure the E7501's DRAM row boundaries |
| 843 | // Start by zeroing out the temporary initial configuration |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 844 | pci_write_config32(MCHDEV, DRB_ROW_0, 0); |
| 845 | pci_write_config32(MCHDEV, DRB_ROW_4, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 846 | |
| 847 | for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 848 | |
| 849 | uint16_t dimm_socket_address = ctrl->channel0[i]; |
| 850 | struct dimm_size sz; |
| 851 | |
| 852 | if (!(dimm_mask & (1 << i))) |
| 853 | continue; // This DIMM not present |
| 854 | |
| 855 | sz = spd_get_dimm_size(dimm_socket_address); |
| 856 | |
| 857 | RAM_DEBUG_MESSAGE("dimm size ="); |
| 858 | RAM_DEBUG_HEX32((u32)sz.side1); |
| 859 | RAM_DEBUG_MESSAGE(" "); |
| 860 | RAM_DEBUG_HEX32((u32)sz.side2); |
| 861 | RAM_DEBUG_MESSAGE("\n"); |
| 862 | |
| 863 | if (sz.side1 == 0) |
| 864 | die("Bad SPD value\n"); |
| 865 | |
| 866 | total_dram_64M_multiple = |
| 867 | configure_dimm_row_boundaries(sz, total_dram_64M_multiple, i); |
| 868 | } |
| 869 | |
| 870 | // Configure the Top Of Low Memory (TOLM) in the E7501 |
| 871 | // This address must be a multiple of 128 MB that is less than 4 GB. |
| 872 | // NOTE: 16-bit wide TOLM register stores only the highest 5 bits of a 32-bit address |
| 873 | // in the highest 5 bits. |
| 874 | |
| 875 | // We set TOLM to the smaller of 0xC0000000 (3 GB) or the total DRAM in the system. |
| 876 | // This reserves addresses from 0xC0000000 - 0xFFFFFFFF for non-DRAM purposes |
| 877 | // such as flash and memory-mapped I/O. |
| 878 | |
| 879 | // If there is more than 3 GB of DRAM, we define a remap window which |
| 880 | // makes the DRAM "behind" the reserved region available above the top of physical |
| 881 | // memory. |
| 882 | |
| 883 | // NOTE: 0xC0000000 / (64 MB) == 0x30 |
| 884 | |
| 885 | if (total_dram_64M_multiple <= 0x30) { |
| 886 | |
| 887 | // <= 3 GB total RAM |
| 888 | |
| 889 | /* I should really adjust all of this in C after I have resources |
| 890 | * to all of the pci devices. |
| 891 | */ |
| 892 | |
| 893 | // Round up to 128MB granularity |
| 894 | // SJM: Is "missing" 64 MB of memory a potential issue? Should this round down? |
| 895 | |
| 896 | uint8_t total_dram_128M_multiple = |
| 897 | (total_dram_64M_multiple + 1) >> 1; |
| 898 | |
| 899 | // Convert to high 16 bits of address |
| 900 | uint16_t top_of_low_memory = |
| 901 | total_dram_128M_multiple << 11; |
| 902 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 903 | pci_write_config16(MCHDEV, TOLM, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 904 | top_of_low_memory); |
| 905 | |
| 906 | } else { |
| 907 | |
| 908 | // > 3 GB total RAM |
| 909 | |
| 910 | // Set defaults for > 4 GB DRAM, i.e. remap a 1 GB (= 0x10 * 64 MB) range of memory |
| 911 | uint16_t remap_base = total_dram_64M_multiple; // A[25:0] == 0 |
| 912 | uint16_t remap_limit = total_dram_64M_multiple + 0x10 - 1; // A[25:0] == 0xF |
| 913 | |
| 914 | // Put TOLM at 3 GB |
| 915 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 916 | pci_write_config16(MCHDEV, TOLM, 0xc000); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 917 | |
| 918 | // Define a remap window to make the RAM that would appear from 3 GB - 4 GB |
| 919 | // visible just beyond 4 GB or the end of physical memory, whichever is larger |
| 920 | // NOTE: 16-bit wide REMAP registers store only the highest 10 bits of a 36-bit address, |
| 921 | // (i.e. a multiple of 64 MB) in the lowest 10 bits. |
| 922 | // NOTE: 0x100000000 / (64 MB) == 0x40 |
| 923 | |
| 924 | if (total_dram_64M_multiple < 0x40) { |
| 925 | remap_base = 0x40; // 0x100000000 |
| 926 | remap_limit = |
| 927 | 0x40 + (total_dram_64M_multiple - 0x30) - 1; |
| 928 | } |
| 929 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 930 | pci_write_config16(MCHDEV, REMAPBASE, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 931 | remap_base); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 932 | pci_write_config16(MCHDEV, REMAPLIMIT, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 933 | remap_limit); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 938 | * Execute ECC full-speed scrub once and leave scrubber disabled. |
| 939 | * |
| 940 | * NOTE: All cache and stack is lost during ECC scrub loop. |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 941 | */ |
Stefan Reinauer | 1e0ddf6 | 2012-11-02 17:26:33 +0100 | [diff] [blame] | 942 | static inline void __attribute__((always_inline)) |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 943 | initialize_ecc(unsigned long ret_addr, unsigned long ret_addr2) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 944 | { |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 945 | uint16_t scrubbed = pci_read_config16(MCHDEV, MCHCFGNS) & 0x08; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 946 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 947 | if (!scrubbed) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 948 | RAM_DEBUG_MESSAGE("Initializing ECC state...\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 949 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 950 | /* ECC scrub flushes cache-lines and stack, need to |
| 951 | * store return address from romstage.c:main(). |
| 952 | */ |
| 953 | asm volatile( |
| 954 | "movd %0, %%xmm0;" |
| 955 | "movd (%0), %%xmm1;" |
| 956 | "movd %1, %%xmm2;" |
| 957 | "movd (%1), %%xmm3;" |
| 958 | :: "r" (ret_addr), "r" (ret_addr2) : |
| 959 | ); |
| 960 | |
| 961 | /* NOTE: All cache is lost during this loop. |
| 962 | * Make sure PCI access does not use stack. |
| 963 | */ |
| 964 | |
| 965 | pci_write_config16(MCHDEV, MCHCFGNS, 0x01); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 966 | do { |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 967 | scrubbed = pci_read_config16(MCHDEV, MCHCFGNS); |
| 968 | } while (! (scrubbed & 0x08)); |
| 969 | pci_write_config16(MCHDEV, MCHCFGNS, (scrubbed & ~0x07) | 0x04); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 970 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 971 | /* Some problem remains with XIP cache from ROM, so for |
| 972 | * now, I disable XIP and also invalidate cache (again) |
| 973 | * before the remaining small portion of romstage. |
| 974 | * |
| 975 | * Adding NOPs here has unexpected results, making |
| 976 | * the first do_printk()/vtxprintf() after ECC scrub |
| 977 | * fail midway. Sometimes vtxprintf() dumps strings |
| 978 | * completely but with every 4th (fourth) character as "/". |
| 979 | * |
| 980 | * An inlined dump to console of the same string, |
| 981 | * before vtxprintf() call, is successful. So the |
| 982 | * source string should be completely in cache already. |
| 983 | * |
| 984 | * I need to review this again with CPU microcode |
| 985 | * update applied pre-CAR. |
| 986 | */ |
| 987 | |
| 988 | /* Disable and invalidate all cache. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 989 | msr_t xip_mtrr = rdmsr(MTRR_PHYS_MASK(1)); |
| 990 | xip_mtrr.lo &= ~MTRR_PHYS_MASK_VALID; |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 991 | invd(); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 992 | wrmsr(MTRR_PHYS_MASK(1), xip_mtrr); |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 993 | invd(); |
| 994 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 995 | RAM_DEBUG_MESSAGE("ECC state initialized.\n"); |
| 996 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 997 | /* Recover IP for return from main. */ |
| 998 | asm volatile( |
| 999 | "movd %%xmm0, %%edi;" |
| 1000 | "movd %%xmm1, (%%edi);" |
| 1001 | "movd %%xmm2, %%edi;" |
| 1002 | "movd %%xmm3, (%%edi);" |
| 1003 | ::: "edi" |
| 1004 | ); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1005 | |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 1006 | #if IS_ENABLED(CONFIG_DEBUG_RAM_SETUP) |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1007 | unsigned int a1, a2; |
| 1008 | asm volatile("movd %%xmm2, %%eax;" : "=a" (a1) ::); |
| 1009 | asm volatile("movd %%xmm3, %%eax;" : "=a" (a2) ::); |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 1010 | printk(BIOS_DEBUG, "return EIP @ %x = %x\n", a1, a2); |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1011 | asm volatile("movd %%xmm0, %%eax;" : "=a" (a1) ::); |
| 1012 | asm volatile("movd %%xmm1, %%eax;" : "=a" (a2) ::); |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 1013 | printk(BIOS_DEBUG, "return EIP @ %x = %x\n", a1, a2); |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1014 | #endif |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1017 | /* Clear the ECC error bits. */ |
| 1018 | pci_write_config8(RASDEV, DRAM_FERR, 0x03); |
| 1019 | pci_write_config8(RASDEV, DRAM_NERR, 0x03); |
| 1020 | |
| 1021 | /* Clear DRAM Interface error bits. */ |
| 1022 | pci_write_config32(RASDEV, FERR_GLOBAL, 1 << 18); |
| 1023 | pci_write_config32(RASDEV, NERR_GLOBAL, 1 << 18); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * Program the DRAM Timing register (DRT) of the E7501 (except for CAS# |
| 1028 | * latency, which is assumed to have been programmed already), based on the |
| 1029 | * parameters of the various installed DIMMs. |
| 1030 | * |
| 1031 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1032 | * addresses of DIMM slots on the mainboard. |
| 1033 | * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms(). |
| 1034 | */ |
| 1035 | static void configure_e7501_dram_timing(const struct mem_controller *ctrl, |
| 1036 | uint8_t dimm_mask) |
| 1037 | { |
| 1038 | int i; |
| 1039 | uint32_t dram_timing; |
| 1040 | int value; |
| 1041 | uint8_t slowest_row_precharge = 0; |
| 1042 | uint8_t slowest_ras_cas_delay = 0; |
| 1043 | uint8_t slowest_active_to_precharge_delay = 0; |
| 1044 | uint32_t current_cas_latency = |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1045 | pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1046 | |
| 1047 | // CAS# latency must be programmed beforehand |
| 1048 | ASSERT((current_cas_latency == DRT_CAS_2_0) |
| 1049 | || (current_cas_latency == DRT_CAS_2_5)); |
| 1050 | |
| 1051 | // Each timing parameter is determined by the slowest DIMM |
| 1052 | |
| 1053 | for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 1054 | uint16_t dimm_socket_address; |
| 1055 | |
| 1056 | if (!(dimm_mask & (1 << i))) |
| 1057 | continue; // This DIMM not present |
| 1058 | |
| 1059 | if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 1060 | dimm_socket_address = ctrl->channel0[i]; |
| 1061 | else |
| 1062 | dimm_socket_address = |
| 1063 | ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 1064 | |
| 1065 | value = |
| 1066 | spd_read_byte(dimm_socket_address, |
| 1067 | SPD_MIN_ROW_PRECHARGE_TIME); |
| 1068 | if (value < 0) |
| 1069 | goto hw_err; |
| 1070 | if (value > slowest_row_precharge) |
| 1071 | slowest_row_precharge = value; |
| 1072 | |
| 1073 | value = |
| 1074 | spd_read_byte(dimm_socket_address, |
| 1075 | SPD_MIN_RAS_TO_CAS_DELAY); |
| 1076 | if (value < 0) |
| 1077 | goto hw_err; |
| 1078 | if (value > slowest_ras_cas_delay) |
| 1079 | slowest_ras_cas_delay = value; |
| 1080 | |
| 1081 | value = |
| 1082 | spd_read_byte(dimm_socket_address, |
| 1083 | SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY); |
| 1084 | if (value < 0) |
| 1085 | goto hw_err; |
| 1086 | if (value > slowest_active_to_precharge_delay) |
| 1087 | slowest_active_to_precharge_delay = value; |
| 1088 | } |
| 1089 | |
| 1090 | // NOTE for timing parameters: |
| 1091 | // At 133 MHz, 1 clock == 7.52 ns |
| 1092 | |
| 1093 | /* Read the initial state */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1094 | dram_timing = pci_read_config32(MCHDEV, DRT); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1095 | |
| 1096 | /* Trp */ |
| 1097 | |
| 1098 | // E7501 supports only 2 or 3 clocks for tRP |
| 1099 | if (slowest_row_precharge > ((22 << 2) | (2 << 0))) |
| 1100 | die("unsupported DIMM tRP"); // > 22.5 ns: 4 or more clocks |
| 1101 | else if (slowest_row_precharge > (15 << 2)) |
| 1102 | dram_timing &= ~(1 << 0); // > 15.0 ns: 3 clocks |
| 1103 | else |
| 1104 | dram_timing |= (1 << 0); // <= 15.0 ns: 2 clocks |
| 1105 | |
| 1106 | /* Trcd */ |
| 1107 | |
| 1108 | // E7501 supports only 2 or 3 clocks for tRCD |
| 1109 | // Use the same value for both read & write |
| 1110 | dram_timing &= ~((1 << 3) | (3 << 1)); |
| 1111 | if (slowest_ras_cas_delay > ((22 << 2) | (2 << 0))) |
| 1112 | die("unsupported DIMM tRCD"); // > 22.5 ns: 4 or more clocks |
| 1113 | else if (slowest_ras_cas_delay > (15 << 2)) |
| 1114 | dram_timing |= (2 << 1); // > 15.0 ns: 3 clocks |
| 1115 | else |
| 1116 | dram_timing |= ((1 << 3) | (3 << 1)); // <= 15.0 ns: 2 clocks |
| 1117 | |
| 1118 | /* Tras */ |
| 1119 | |
| 1120 | // E7501 supports only 5, 6, or 7 clocks for tRAS |
| 1121 | // 5 clocks ~= 37.6 ns, 6 clocks ~= 45.1 ns, 7 clocks ~= 52.6 ns |
| 1122 | dram_timing &= ~(3 << 9); |
| 1123 | |
| 1124 | if (slowest_active_to_precharge_delay > 52) |
| 1125 | die("unsupported DIMM tRAS"); // > 52 ns: 8 or more clocks |
| 1126 | else if (slowest_active_to_precharge_delay > 45) |
| 1127 | dram_timing |= (0 << 9); // 46-52 ns: 7 clocks |
| 1128 | else if (slowest_active_to_precharge_delay > 37) |
| 1129 | dram_timing |= (1 << 9); // 38-45 ns: 6 clocks |
| 1130 | else |
| 1131 | dram_timing |= (2 << 9); // < 38 ns: 5 clocks |
| 1132 | |
| 1133 | /* Trd */ |
| 1134 | |
Elyes HAOUAS | 0f92f63 | 2014-07-27 19:37:31 +0200 | [diff] [blame] | 1135 | /* Set to a 7 clock read delay. This is for 133MHz |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1136 | * with a CAS latency of 2.5 if 2.0 a 6 clock |
| 1137 | * delay is good */ |
| 1138 | |
| 1139 | dram_timing &= ~(7 << 24); // 7 clocks |
| 1140 | if (current_cas_latency == DRT_CAS_2_0) |
| 1141 | dram_timing |= (1 << 24); // 6 clocks |
| 1142 | |
| 1143 | /* |
| 1144 | * Back to Back Read-Write Turn Around |
| 1145 | */ |
| 1146 | /* Set to a 5 clock back to back read to write turn around. |
| 1147 | * 4 is a good delay if the CAS latency is 2.0 */ |
| 1148 | |
| 1149 | dram_timing &= ~(1 << 28); // 5 clocks |
| 1150 | if (current_cas_latency == DRT_CAS_2_0) |
| 1151 | dram_timing |= (1 << 28); // 4 clocks |
| 1152 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1153 | pci_write_config32(MCHDEV, DRT, dram_timing); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1154 | |
| 1155 | return; |
| 1156 | |
| 1157 | hw_err: |
| 1158 | die(SPD_ERROR); |
| 1159 | } |
| 1160 | |
| 1161 | /** |
| 1162 | * Determine the shortest CAS# latency that the E7501 and all DIMMs have in |
| 1163 | * common, and program the E7501 to use it. |
| 1164 | * |
| 1165 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1166 | * addresses of DIMM slots on the mainboard. |
| 1167 | * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms(). |
| 1168 | */ |
| 1169 | static void configure_e7501_cas_latency(const struct mem_controller *ctrl, |
| 1170 | uint8_t dimm_mask) |
| 1171 | { |
| 1172 | int i; |
| 1173 | int value; |
| 1174 | uint32_t dram_timing; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1175 | uint16_t dram_read_timing; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1176 | uint32_t dword; |
| 1177 | |
| 1178 | // CAS# latency bitmasks in SPD_ACCEPTABLE_CAS_LATENCIES format |
| 1179 | // NOTE: E7501 supports only 2.0 and 2.5 |
| 1180 | uint32_t system_compatible_cas_latencies = |
| 1181 | SPD_CAS_LATENCY_2_0 | SPD_CAS_LATENCY_2_5; |
| 1182 | uint32_t current_cas_latency; |
| 1183 | uint32_t dimm_compatible_cas_latencies; |
| 1184 | |
| 1185 | for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 1186 | |
| 1187 | uint16_t dimm_socket_address; |
| 1188 | |
| 1189 | if (!(dimm_mask & (1 << i))) |
| 1190 | continue; // This DIMM not usable |
| 1191 | |
| 1192 | if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 1193 | dimm_socket_address = ctrl->channel0[i]; |
| 1194 | else |
| 1195 | dimm_socket_address = |
| 1196 | ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 1197 | |
| 1198 | value = |
| 1199 | spd_read_byte(dimm_socket_address, |
| 1200 | SPD_ACCEPTABLE_CAS_LATENCIES); |
| 1201 | if (value < 0) |
| 1202 | goto hw_err; |
| 1203 | |
| 1204 | dimm_compatible_cas_latencies = value & 0x7f; // Start with all supported by DIMM |
| 1205 | current_cas_latency = 1 << log2(dimm_compatible_cas_latencies); // Max supported by DIMM |
| 1206 | |
| 1207 | // Can we support the highest CAS# latency? |
| 1208 | |
| 1209 | value = |
| 1210 | spd_read_byte(dimm_socket_address, |
| 1211 | SPD_MIN_CYCLE_TIME_AT_CAS_MAX); |
| 1212 | if (value < 0) |
| 1213 | goto hw_err; |
| 1214 | |
| 1215 | // NOTE: At 133 MHz, 1 clock == 7.52 ns |
| 1216 | if (value > 0x75) { |
| 1217 | // Our bus is too fast for this CAS# latency |
| 1218 | // Remove it from the bitmask of those supported by the DIMM that are compatible |
| 1219 | dimm_compatible_cas_latencies &= ~current_cas_latency; |
| 1220 | } |
| 1221 | // Can we support the next-highest CAS# latency (max - 0.5)? |
| 1222 | |
| 1223 | current_cas_latency >>= 1; |
| 1224 | if (current_cas_latency != 0) { |
| 1225 | value = |
| 1226 | spd_read_byte(dimm_socket_address, |
| 1227 | SPD_SDRAM_CYCLE_TIME_2ND); |
| 1228 | if (value < 0) |
| 1229 | goto hw_err; |
| 1230 | if (value > 0x75) |
| 1231 | dimm_compatible_cas_latencies &= |
| 1232 | ~current_cas_latency; |
| 1233 | } |
| 1234 | // Can we support the next-highest CAS# latency (max - 1.0)? |
| 1235 | current_cas_latency >>= 1; |
| 1236 | if (current_cas_latency != 0) { |
| 1237 | value = |
| 1238 | spd_read_byte(dimm_socket_address, |
| 1239 | SPD_SDRAM_CYCLE_TIME_3RD); |
| 1240 | if (value < 0) |
| 1241 | goto hw_err; |
| 1242 | if (value > 0x75) |
| 1243 | dimm_compatible_cas_latencies &= |
| 1244 | ~current_cas_latency; |
| 1245 | } |
| 1246 | // Restrict the system to CAS# latencies compatible with this DIMM |
| 1247 | system_compatible_cas_latencies &= |
| 1248 | dimm_compatible_cas_latencies; |
| 1249 | |
| 1250 | /* go to the next DIMM */ |
| 1251 | } |
| 1252 | |
| 1253 | /* After all of the arduous calculation setup with the fastest |
| 1254 | * cas latency I can use. |
| 1255 | */ |
| 1256 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1257 | dram_timing = pci_read_config32(MCHDEV, DRT); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1258 | dram_timing &= ~(DRT_CAS_MASK); |
| 1259 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1260 | dram_read_timing = |
| 1261 | pci_read_config16(MCHDEV, DRDCTL); |
| 1262 | dram_read_timing &= 0xF000; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1263 | |
| 1264 | if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_0) { |
| 1265 | dram_timing |= DRT_CAS_2_0; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1266 | dram_read_timing |= 0x0222; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1267 | } else if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_5) { |
| 1268 | |
| 1269 | uint32_t dram_row_attributes = |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1270 | pci_read_config32(MCHDEV, DRA); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1271 | |
| 1272 | dram_timing |= DRT_CAS_2_5; |
| 1273 | |
| 1274 | // At CAS# 2.5, DRAM Read Timing (if that's what it its) appears to need a slightly |
| 1275 | // different value if all DIMM slots are populated |
| 1276 | |
| 1277 | if ((dram_row_attributes & 0xff) |
| 1278 | && (dram_row_attributes & 0xff00) |
| 1279 | && (dram_row_attributes & 0xff0000) |
| 1280 | && (dram_row_attributes & 0xff000000)) { |
| 1281 | |
| 1282 | // All slots populated |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1283 | dram_read_timing |= 0x0882; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1284 | } else { |
| 1285 | // Some unpopulated slots |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1286 | dram_read_timing |= 0x0662; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } else |
| 1289 | die("No CAS# latencies compatible with all DIMMs!!\n"); |
| 1290 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1291 | pci_write_config32(MCHDEV, DRT, dram_timing); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1292 | |
| 1293 | /* set master DLL reset */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1294 | dword = pci_read_config32(MCHDEV, 0x88); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1295 | dword |= (1 << 26); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1296 | pci_write_config32(MCHDEV, 0x88, dword); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1297 | /* patch try register 88 is undocumented tnz */ |
| 1298 | dword &= 0x0ca17fff; |
| 1299 | dword |= 0xd14a5000; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1300 | pci_write_config32(MCHDEV, 0x88, dword); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1301 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1302 | pci_write_config16(MCHDEV, DRDCTL, |
| 1303 | dram_read_timing); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1304 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1305 | /* clear master DLL reset */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1306 | dword = pci_read_config32(MCHDEV, 0x88); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1307 | dword &= ~(1 << 26); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1308 | pci_write_config32(MCHDEV, 0x88, dword); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1309 | |
| 1310 | return; |
| 1311 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1312 | hw_err: |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1313 | die(SPD_ERROR); |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * Configure the refresh interval so that we refresh no more often than |
| 1318 | * required by the "most needy" DIMM. Also disable ECC if any of the DIMMs |
| 1319 | * don't support it. |
| 1320 | * |
| 1321 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1322 | * addresses of DIMM slots on the mainboard. |
| 1323 | * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms(). |
| 1324 | */ |
| 1325 | static void configure_e7501_dram_controller_mode(const struct |
| 1326 | mem_controller *ctrl, |
| 1327 | uint8_t dimm_mask) |
| 1328 | { |
| 1329 | int i; |
| 1330 | |
| 1331 | // Initial settings |
| 1332 | uint32_t controller_mode = |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1333 | pci_read_config32(MCHDEV, DRC); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1334 | uint32_t system_refresh_mode = (controller_mode >> 8) & 7; |
| 1335 | |
| 1336 | // Code below assumes that most aggressive settings are in |
| 1337 | // force when we are called, either via E7501 reset defaults |
| 1338 | // or by sdram_set_registers(): |
| 1339 | // - ECC enabled |
| 1340 | // - No refresh |
| 1341 | |
| 1342 | ASSERT((controller_mode & (3 << 20)) == (2 << 20)); // ECC |
| 1343 | ASSERT(!(controller_mode & (7 << 8))); // Refresh |
| 1344 | |
| 1345 | /* Walk through _all_ dimms and find the least-common denominator for: |
| 1346 | * - ECC support |
| 1347 | * - refresh rates |
| 1348 | */ |
| 1349 | |
| 1350 | for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 1351 | |
| 1352 | uint32_t dimm_refresh_mode; |
| 1353 | int value; |
| 1354 | uint16_t dimm_socket_address; |
| 1355 | |
| 1356 | if (!(dimm_mask & (1 << i))) { |
| 1357 | continue; // This DIMM not usable |
| 1358 | } |
| 1359 | |
| 1360 | if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 1361 | dimm_socket_address = ctrl->channel0[i]; |
| 1362 | else |
| 1363 | dimm_socket_address = |
| 1364 | ctrl->channel1[i - |
| 1365 | MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 1366 | |
| 1367 | // Disable ECC mode if any one of the DIMMs does not support ECC |
| 1368 | // SJM: Should we just die here? E7501 datasheet says non-ECC DIMMs aren't supported. |
| 1369 | |
| 1370 | value = |
| 1371 | spd_read_byte(dimm_socket_address, |
| 1372 | SPD_DIMM_CONFIG_TYPE); |
| 1373 | die_on_spd_error(value); |
| 1374 | if (value != ERROR_SCHEME_ECC) { |
| 1375 | controller_mode &= ~(3 << 20); |
| 1376 | } |
| 1377 | |
| 1378 | value = spd_read_byte(dimm_socket_address, SPD_REFRESH); |
| 1379 | die_on_spd_error(value); |
| 1380 | value &= 0x7f; // Mask off self-refresh bit |
| 1381 | if (value > MAX_SPD_REFRESH_RATE) { |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 1382 | printk(BIOS_ERR, "unsupported refresh rate\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1383 | continue; |
| 1384 | } |
| 1385 | // Get the appropriate E7501 refresh mode for this DIMM |
| 1386 | dimm_refresh_mode = refresh_rate_map[value]; |
| 1387 | if (dimm_refresh_mode > 7) { |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 1388 | printk(BIOS_ERR, "unsupported refresh rate\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1389 | continue; |
| 1390 | } |
| 1391 | // If this DIMM requires more frequent refresh than others, |
| 1392 | // update the system setting |
| 1393 | if (refresh_frequency[dimm_refresh_mode] > |
| 1394 | refresh_frequency[system_refresh_mode]) |
| 1395 | system_refresh_mode = dimm_refresh_mode; |
| 1396 | |
| 1397 | #ifdef SUSPICIOUS_LOOKING_CODE |
| 1398 | // SJM NOTE: This code doesn't look right. SPD values are an order of magnitude smaller |
| 1399 | // than the clock period of the memory controller. Also, no other northbridge |
| 1400 | // looks at SPD_CMD_SIGNAL_INPUT_HOLD_TIME. |
| 1401 | |
| 1402 | // Switch to 2 clocks for address/command if required by any one of the DIMMs |
| 1403 | // NOTE: At 133 MHz, 1 clock == 7.52 ns |
| 1404 | value = |
| 1405 | spd_read_byte(dimm_socket_address, |
| 1406 | SPD_CMD_SIGNAL_INPUT_HOLD_TIME); |
| 1407 | die_on_spd_error(value); |
| 1408 | if (value >= 0xa0) { /* At 133MHz this constant should be 0x75 */ |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 1409 | controller_mode &= ~(1 << 16); /* Use two clock cycles instead of one */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1410 | } |
| 1411 | #endif |
| 1412 | |
| 1413 | /* go to the next DIMM */ |
| 1414 | } |
| 1415 | |
| 1416 | controller_mode |= (system_refresh_mode << 8); |
| 1417 | |
| 1418 | // Configure the E7501 |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1419 | pci_write_config32(MCHDEV, DRC, controller_mode); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * Configure the E7501's DRAM Row Attributes (DRA) registers based on DIMM |
| 1424 | * parameters read via SPD. This tells the controller the width of the SDRAM |
| 1425 | * chips on each DIMM side (x4 or x8) and the page size of each DIMM side |
| 1426 | * (4, 8, 16, or 32 KB). |
| 1427 | * |
| 1428 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1429 | * addresses of DIMM slots on the mainboard. |
| 1430 | * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms(). |
| 1431 | */ |
| 1432 | static void configure_e7501_row_attributes(const struct mem_controller |
| 1433 | *ctrl, uint8_t dimm_mask) |
| 1434 | { |
| 1435 | int i; |
| 1436 | uint32_t row_attributes = 0; |
| 1437 | |
| 1438 | for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 1439 | |
| 1440 | uint16_t dimm_socket_address = ctrl->channel0[i]; |
| 1441 | struct dimm_size page_size; |
| 1442 | struct dimm_size sdram_width; |
| 1443 | |
| 1444 | if (!(dimm_mask & (1 << i))) |
| 1445 | continue; // This DIMM not usable |
| 1446 | |
| 1447 | // Get the relevant parameters via SPD |
| 1448 | page_size = sdram_spd_get_page_size(dimm_socket_address); |
| 1449 | sdram_width = sdram_spd_get_width(dimm_socket_address); |
| 1450 | |
| 1451 | // Update the DRAM Row Attributes. |
| 1452 | // Page size is encoded as log2(page size in bits) - log2(8 Kb) |
| 1453 | // NOTE: 8 Kb = 2^13 |
| 1454 | row_attributes |= (page_size.side1 - 13) << (i << 3); // Side 1 of each DIMM is an EVEN row |
| 1455 | |
| 1456 | if (sdram_width.side2 > 0) |
| 1457 | row_attributes |= (page_size.side2 - 13) << ((i << 3) + 4); // Side 2 is ODD |
| 1458 | |
| 1459 | // Set x4 flags if appropriate |
| 1460 | if (sdram_width.side1 == 4) { |
| 1461 | row_attributes |= 0x08 << (i << 3); |
| 1462 | } |
| 1463 | |
| 1464 | if (sdram_width.side2 == 4) { |
| 1465 | row_attributes |= 0x08 << ((i << 3) + 4); |
| 1466 | } |
| 1467 | |
| 1468 | /* go to the next DIMM */ |
| 1469 | } |
| 1470 | |
| 1471 | /* Write the new row attributes register */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1472 | pci_write_config32(MCHDEV, DRA, row_attributes); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | /* |
| 1476 | * Enable clock signals for populated DIMM sockets and disable them for |
| 1477 | * unpopulated sockets (to reduce EMI). |
| 1478 | * |
| 1479 | * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms(). |
| 1480 | */ |
| 1481 | static void enable_e7501_clocks(uint8_t dimm_mask) |
| 1482 | { |
| 1483 | int i; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1484 | uint8_t clock_disable = pci_read_config8(MCHDEV, CKDIS); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1485 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1486 | pci_write_config8(MCHDEV, 0x8e, 0xb0); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1487 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1488 | for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 1489 | |
| 1490 | uint8_t socket_mask = 1 << i; |
| 1491 | |
| 1492 | if (dimm_mask & socket_mask) |
| 1493 | clock_disable &= ~socket_mask; // DIMM present, enable clock |
| 1494 | else |
| 1495 | clock_disable |= socket_mask; // DIMM absent, disable clock |
| 1496 | } |
| 1497 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1498 | pci_write_config8(MCHDEV, CKDIS, clock_disable); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 1501 | /* DIMM-dependent configuration functions */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1502 | |
| 1503 | /** |
| 1504 | * DDR Receive FIFO RE-Sync (?) |
| 1505 | */ |
| 1506 | static void RAM_RESET_DDR_PTR(void) |
| 1507 | { |
| 1508 | uint8_t byte; |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1509 | byte = pci_read_config8(MCHDEV, 0x88); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1510 | byte |= (1 << 4); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1511 | pci_write_config8(MCHDEV, 0x88, byte); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1512 | |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1513 | byte = pci_read_config8(MCHDEV, 0x88); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1514 | byte &= ~(1 << 4); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1515 | pci_write_config8(MCHDEV, 0x88, byte); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /** |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1519 | * Copy 64 bytes from one location to another. |
| 1520 | * |
| 1521 | * @param src_addr TODO |
| 1522 | * @param dst_addr TODO |
| 1523 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1524 | static void write_8dwords(const uint32_t *src_addr, u8 *dst_addr) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1525 | { |
| 1526 | int i; |
| 1527 | for (i = 0; i < 8; i++) { |
| 1528 | write32(dst_addr, *src_addr); |
| 1529 | src_addr++; |
| 1530 | dst_addr += sizeof(uint32_t); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * Set the E7501's (undocumented) RCOMP registers. |
| 1536 | * |
| 1537 | * Per the 855PM datasheet and IXP2800 HW Initialization Reference Manual, |
| 1538 | * RCOMP registers appear to affect drive strength, pullup/pulldown offset, |
| 1539 | * and slew rate of various signal groups. |
| 1540 | * |
| 1541 | * Comments below are conjecture based on apparent similarity between the |
| 1542 | * E7501 and these two chips. |
| 1543 | */ |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1544 | static void rcomp_copy_registers(void) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1545 | { |
| 1546 | uint32_t dword; |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1547 | uint8_t strength_control; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1548 | |
| 1549 | RAM_DEBUG_MESSAGE("Setting RCOMP registers.\n"); |
| 1550 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1551 | /* Begin to write the RCOMP registers */ |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1552 | write8(RCOMP_MMIO + 0x2c, 0x0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1553 | |
| 1554 | // Set CMD and DQ/DQS strength to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1555 | strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0x88; |
| 1556 | strength_control |= 0x40; |
| 1557 | write8(RCOMP_MMIO + DQCMDSTR, strength_control); |
| 1558 | write_8dwords(slew_2x, RCOMP_MMIO + 0x80); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1559 | write16(RCOMP_MMIO + 0x42, 0); |
| 1560 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1561 | // Set CMD and DQ/DQS strength to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1562 | strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0xF8; |
| 1563 | strength_control |= 0x04; |
| 1564 | write8(RCOMP_MMIO + DQCMDSTR, strength_control); |
| 1565 | write_8dwords(slew_2x, RCOMP_MMIO + 0x60); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1566 | write16(RCOMP_MMIO + 0x40, 0); |
| 1567 | |
| 1568 | // Set RCVEnOut# strength to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1569 | strength_control = read8(RCOMP_MMIO + RCVENSTR) & 0xF8; |
| 1570 | strength_control |= 0x04; |
| 1571 | write8(RCOMP_MMIO + RCVENSTR, strength_control); |
| 1572 | write_8dwords(slew_2x, RCOMP_MMIO + 0x1c0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1573 | write16(RCOMP_MMIO + 0x50, 0); |
| 1574 | |
| 1575 | // Set CS# strength for x4 SDRAM to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1576 | strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x88; |
| 1577 | strength_control |= 0x04; |
| 1578 | write8(RCOMP_MMIO + CSBSTR, strength_control); |
| 1579 | write_8dwords(slew_2x, RCOMP_MMIO + 0x140); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1580 | write16(RCOMP_MMIO + 0x48, 0); |
| 1581 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1582 | // Set CS# strength for x4 SDRAM to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1583 | strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x8F; |
| 1584 | strength_control |= 0x40; |
| 1585 | write8(RCOMP_MMIO + CSBSTR, strength_control); |
| 1586 | write_8dwords(slew_2x, RCOMP_MMIO + 0x160); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1587 | write16(RCOMP_MMIO + 0x4a, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1588 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1589 | // Set CKE strength for x4 SDRAM to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1590 | strength_control = read8(RCOMP_MMIO + CKESTR) & 0x88; |
| 1591 | strength_control |= 0x04; |
| 1592 | write8(RCOMP_MMIO + CKESTR, strength_control); |
| 1593 | write_8dwords(slew_2x, RCOMP_MMIO + 0xa0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1594 | write16(RCOMP_MMIO + 0x44, 0); |
| 1595 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1596 | // Set CKE strength for x4 SDRAM to 2x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1597 | strength_control = read8(RCOMP_MMIO + CKESTR) & 0x8F; |
| 1598 | strength_control |= 0x40; |
| 1599 | write8(RCOMP_MMIO + CKESTR, strength_control); |
| 1600 | write_8dwords(slew_2x, RCOMP_MMIO + 0xc0); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1601 | write16(RCOMP_MMIO + 0x46, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1602 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1603 | // Set CK strength for x4 SDRAM to 1x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1604 | strength_control = read8(RCOMP_MMIO + CKSTR) & 0x88; |
| 1605 | strength_control |= 0x01; |
| 1606 | write8(RCOMP_MMIO + CKSTR, strength_control); |
| 1607 | write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x180); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1608 | write16(RCOMP_MMIO + 0x4c, 0); |
| 1609 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1610 | // Set CK strength for x4 SDRAM to 1x (?) |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1611 | strength_control = read8(RCOMP_MMIO + CKSTR) & 0x8F; |
| 1612 | strength_control |= 0x10; |
| 1613 | write8(RCOMP_MMIO + CKSTR, strength_control); |
| 1614 | write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x1a0); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1615 | write16(RCOMP_MMIO + 0x4e, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1616 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1617 | dword = read32(RCOMP_MMIO + 0x400); |
| 1618 | dword &= 0x7f7fffff; |
| 1619 | write32(RCOMP_MMIO + 0x400, dword); |
| 1620 | |
| 1621 | dword = read32(RCOMP_MMIO + 0x408); |
| 1622 | dword &= 0x7f7fffff; |
| 1623 | write32(RCOMP_MMIO + 0x408, dword); |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1624 | } |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1625 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1626 | static void ram_set_rcomp_regs(void) |
| 1627 | { |
| 1628 | /* Set the RCOMP MMIO base address */ |
| 1629 | mchtest_control(RCOMP_BAR_ENABLE); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1630 | pci_write_config32(MCHDEV, SMRBASE, (uintptr_t)RCOMP_MMIO); |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1631 | |
| 1632 | /* Block RCOMP updates while we configure the registers */ |
| 1633 | rcomp_smr_control(RCOMP_HOLD); |
| 1634 | rcomp_copy_registers(); |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1635 | d060_control(D060_CMD_0); |
| 1636 | mchtest_control(MCHTST_CMD_0); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1637 | |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1638 | uint8_t revision = pci_read_config8(MCHDEV, 0x08); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1639 | if (revision >= 3) { |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1640 | rcomp_smr_control(RCOMP_SMR_00); |
| 1641 | rcomp_smr_control(RCOMP_SMR_01); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1642 | } |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1643 | rcomp_smr_control(RCOMP_RELEASE); |
| 1644 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1645 | /* Wait 40 usec */ |
| 1646 | SLOW_DOWN_IO; |
| 1647 | |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1648 | /* Clear the RCOMP MMIO base address */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1649 | pci_write_config32(MCHDEV, SMRBASE, 0); |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1650 | mchtest_control(RCOMP_BAR_DISABLE); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | /*----------------------------------------------------------------------------- |
| 1654 | Public interface: |
| 1655 | -----------------------------------------------------------------------------*/ |
| 1656 | |
| 1657 | /** |
| 1658 | * Go through the JEDEC initialization sequence for all DIMMs, then enable |
| 1659 | * refresh and initialize ECC and memory to zero. Upon exit, SDRAM is up |
| 1660 | * and running. |
| 1661 | * |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1662 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1663 | * addresses of DIMM slots on the mainboard. |
| 1664 | */ |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1665 | static void sdram_enable(const struct mem_controller *ctrl) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1666 | { |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1667 | uint8_t dimm_mask = pci_read_config16(MCHDEV, SKPD); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1668 | uint32_t dram_controller_mode; |
| 1669 | |
| 1670 | if (dimm_mask == 0) |
| 1671 | return; |
| 1672 | |
| 1673 | /* 1 & 2 Power up and start clocks */ |
| 1674 | RAM_DEBUG_MESSAGE("Ram Enable 1\n"); |
| 1675 | RAM_DEBUG_MESSAGE("Ram Enable 2\n"); |
| 1676 | |
| 1677 | /* A 200us delay is needed */ |
| 1678 | DO_DELAY; EXTRA_DELAY; |
| 1679 | |
| 1680 | /* 3. Apply NOP */ |
| 1681 | RAM_DEBUG_MESSAGE("Ram Enable 3\n"); |
| 1682 | do_ram_command(RAM_COMMAND_NOP, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1683 | |
| 1684 | /* 4 Precharge all */ |
| 1685 | RAM_DEBUG_MESSAGE("Ram Enable 4\n"); |
| 1686 | do_ram_command(RAM_COMMAND_PRECHARGE, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1687 | /* wait until the all banks idle state... */ |
| 1688 | |
| 1689 | /* 5. Issue EMRS to enable DLL */ |
| 1690 | RAM_DEBUG_MESSAGE("Ram Enable 5\n"); |
| 1691 | do_ram_command(RAM_COMMAND_EMRS, |
| 1692 | SDRAM_EXTMODE_DLL_ENABLE | |
| 1693 | SDRAM_EXTMODE_DRIVE_NORMAL); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1694 | |
| 1695 | /* 6. Reset DLL */ |
| 1696 | RAM_DEBUG_MESSAGE("Ram Enable 6\n"); |
| 1697 | set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_DLL_RESET); |
| 1698 | EXTRA_DELAY; |
| 1699 | /* Ensure a 200us delay between the DLL reset in step 6 and the final |
| 1700 | * mode register set in step 9. |
| 1701 | * Infineon needs this before any other command is sent to the ram. |
| 1702 | */ |
| 1703 | DO_DELAY; EXTRA_DELAY; |
| 1704 | |
| 1705 | /* 7 Precharge all */ |
| 1706 | RAM_DEBUG_MESSAGE("Ram Enable 7\n"); |
| 1707 | do_ram_command(RAM_COMMAND_PRECHARGE, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1708 | |
| 1709 | /* 8 Now we need 2 AUTO REFRESH / CBR cycles to be performed */ |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1710 | /* And for good luck 6 more CBRs */ |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1711 | RAM_DEBUG_MESSAGE("Ram Enable 8\n"); |
| 1712 | int i; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 1713 | for (i = 0; i < 8; i++) |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1714 | do_ram_command(RAM_COMMAND_CBR, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1715 | |
| 1716 | /* 9 mode register set */ |
| 1717 | RAM_DEBUG_MESSAGE("Ram Enable 9\n"); |
| 1718 | set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_NORMAL); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1719 | |
| 1720 | /* 10 DDR Receive FIFO RE-Sync */ |
| 1721 | RAM_DEBUG_MESSAGE("Ram Enable 10\n"); |
| 1722 | RAM_RESET_DDR_PTR(); |
| 1723 | EXTRA_DELAY; |
| 1724 | |
| 1725 | /* 11 normal operation */ |
| 1726 | RAM_DEBUG_MESSAGE("Ram Enable 11\n"); |
| 1727 | do_ram_command(RAM_COMMAND_NORMAL, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1728 | |
| 1729 | // Reconfigure the row boundaries and Top of Low Memory |
| 1730 | // to match the true size of the DIMMs |
| 1731 | configure_e7501_ram_addresses(ctrl, dimm_mask); |
| 1732 | |
| 1733 | /* Finally enable refresh */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1734 | dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1735 | dram_controller_mode |= (1 << 29); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1736 | pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1737 | EXTRA_DELAY; |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1738 | } |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1739 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1740 | /** |
| 1741 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1742 | * addresses of DIMM slots on the mainboard. |
| 1743 | */ |
| 1744 | static void sdram_post_ecc(const struct mem_controller *ctrl) |
| 1745 | { |
| 1746 | /* Fast CS# Enable. */ |
| 1747 | uint32_t dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1748 | dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1749 | dram_controller_mode |= (1 << 17); |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1750 | pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * Configure SDRAM controller parameters that depend on characteristics of the |
| 1755 | * DIMMs installed in the system. These characteristics are read from the |
| 1756 | * DIMMs via the standard Serial Presence Detect (SPD) interface. |
| 1757 | * |
| 1758 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1759 | * addresses of DIMM slots on the mainboard. |
| 1760 | */ |
| 1761 | static void sdram_set_spd_registers(const struct mem_controller *ctrl) |
| 1762 | { |
| 1763 | uint8_t dimm_mask; |
| 1764 | |
| 1765 | RAM_DEBUG_MESSAGE("Reading SPD data...\n"); |
| 1766 | |
| 1767 | dimm_mask = spd_get_supported_dimms(ctrl); |
| 1768 | |
| 1769 | if (dimm_mask == 0) { |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 1770 | printk(BIOS_DEBUG, "No usable memory for this controller\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1771 | } else { |
| 1772 | enable_e7501_clocks(dimm_mask); |
| 1773 | |
| 1774 | RAM_DEBUG_MESSAGE("setting based on SPD data...\n"); |
| 1775 | |
| 1776 | configure_e7501_row_attributes(ctrl, dimm_mask); |
| 1777 | configure_e7501_dram_controller_mode(ctrl, dimm_mask); |
| 1778 | configure_e7501_cas_latency(ctrl, dimm_mask); |
| 1779 | RAM_RESET_DDR_PTR(); |
| 1780 | |
| 1781 | configure_e7501_dram_timing(ctrl, dimm_mask); |
| 1782 | DO_DELAY; |
| 1783 | RAM_DEBUG_MESSAGE("done\n"); |
| 1784 | } |
| 1785 | |
| 1786 | /* NOTE: configure_e7501_ram_addresses() is NOT called here. |
| 1787 | * We want to keep the default 64 MB/row mapping until sdram_enable() is called, |
| 1788 | * even though the default mapping is almost certainly incorrect. |
| 1789 | * The default mapping makes it easy to initialize all of the DIMMs |
| 1790 | * even if the total system memory is > 4 GB. |
| 1791 | * |
| 1792 | * Save the dimm_mask for when sdram_enable is called, so it can call |
| 1793 | * configure_e7501_ram_addresses() without having to regenerate the bitmask |
| 1794 | * of usable DIMMs. |
| 1795 | */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 1796 | pci_write_config16(MCHDEV, SKPD, dimm_mask); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | /** |
| 1800 | * Do basic RAM setup that does NOT depend on serial presence detect |
| 1801 | * information (i.e. independent of DIMM specifics). |
| 1802 | * |
| 1803 | * @param ctrl PCI addresses of memory controller functions, and SMBus |
| 1804 | * addresses of DIMM slots on the mainboard. |
| 1805 | */ |
| 1806 | static void sdram_set_registers(const struct mem_controller *ctrl) |
| 1807 | { |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1808 | uint32_t dword; |
| 1809 | uint16_t word; |
| 1810 | uint8_t byte; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1811 | |
| 1812 | ram_set_rcomp_regs(); |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1813 | |
| 1814 | /* Enable 0:0.1, 0:2.1 */ |
| 1815 | word = pci_read_config16(MCHDEV, DVNP); |
| 1816 | word &= ~0x05; |
| 1817 | pci_write_config16(MCHDEV, DVNP, word); |
| 1818 | |
| 1819 | /* Disable high-memory remap (power-on defaults, really) */ |
| 1820 | pci_write_config16(MCHDEV, REMAPBASE, 0x03ff); |
| 1821 | pci_write_config16(MCHDEV, REMAPLIMIT, 0x0); |
| 1822 | |
| 1823 | /* Disable legacy MMIO (0xC0000-0xEFFFF is DRAM) */ |
| 1824 | int i; |
| 1825 | pci_write_config8(MCHDEV, PAM_0, 0x30); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 1826 | for (i = 1; i <= 6; i++) |
Kyösti Mälkki | 77e4f7d | 2012-04-18 19:47:56 +0300 | [diff] [blame] | 1827 | pci_write_config8(MCHDEV, PAM_0 + i, 0x33); |
| 1828 | |
| 1829 | /* Conservatively say each row has 64MB of ram, we will fix this up later |
| 1830 | * Initial TOLM 8 rows 64MB each (1<<3 * 1<<26) >> 16 = 1<<13 |
| 1831 | * |
| 1832 | * FIXME: Hard-coded limit to first four rows to prevent overlap! |
| 1833 | */ |
| 1834 | pci_write_config32(MCHDEV, DRB_ROW_0, 0x04030201); |
| 1835 | pci_write_config32(MCHDEV, DRB_ROW_4, 0x04040404); |
| 1836 | //pci_write_config32(MCHDEV, DRB_ROW_4, 0x08070605); |
| 1837 | pci_write_config16(MCHDEV, TOLM, (1<<13)); |
| 1838 | |
| 1839 | /* DIMM clocks off */ |
| 1840 | pci_write_config8(MCHDEV, CKDIS, 0xff); |
| 1841 | |
| 1842 | /* reset row attributes */ |
| 1843 | pci_write_config32(MCHDEV, DRA, 0x0); |
| 1844 | |
| 1845 | // The only things we need to set here are DRAM idle timer, Back-to-Back Read Turnaround, and |
| 1846 | // Back-to-Back Write-Read Turnaround. All others are configured based on SPD. |
| 1847 | dword = pci_read_config32(MCHDEV, DRT); |
| 1848 | dword &= 0xC7F8FFFF; |
| 1849 | dword |= (0x28<<24)|(0x03<<16); |
| 1850 | pci_write_config32(MCHDEV, DRT, dword); |
| 1851 | |
| 1852 | dword = pci_read_config32(MCHDEV, DRC); |
| 1853 | dword &= 0xffcef8f7; |
| 1854 | dword |= 0x00210008; |
| 1855 | pci_write_config32(MCHDEV, DRC, dword); |
| 1856 | |
| 1857 | /* Undocumented */ |
| 1858 | pci_write_config8(MCHDEV, 0x88, 0x80); |
| 1859 | |
| 1860 | /* Undocumented. Set much later in vendor BIOS. */ |
| 1861 | byte = pci_read_config8(MCHDEV, 0xd9); |
| 1862 | byte &= ~0x60; |
| 1863 | pci_write_config8(MCHDEV, 0xd9, byte); |
| 1864 | |
| 1865 | #ifdef SUSPICIOUS_LOOKING_CODE |
| 1866 | /* This will access D2:F0:0x50, is this correct?? |
| 1867 | * Vendor BIOS reads Device ID before this is set. |
| 1868 | * Undocumented in the p64h2 PCI-X bridge datasheet. |
| 1869 | */ |
| 1870 | byte = pci_read_config8(PCI_DEV(0,2,0), 0x50); |
| 1871 | byte &= 0xcf; |
| 1872 | byte |= 0x30 |
| 1873 | pci_write_config8(PCI_DEV(0,2,0), 0x50, byte); |
| 1874 | #endif |
Kyösti Mälkki | 26c7b86 | 2012-04-12 22:46:23 +0300 | [diff] [blame] | 1875 | |
| 1876 | uint8_t revision = pci_read_config8(MCHDEV, 0x08); |
| 1877 | if (revision >= 3) |
| 1878 | d060_control(D060_CMD_1); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1879 | } |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 1880 | |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1881 | /** |
| 1882 | * |
| 1883 | * |
| 1884 | */ |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1885 | void e7505_mch_init(const struct mem_controller *memctrl) |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1886 | { |
| 1887 | RAM_DEBUG_MESSAGE("Northbridge prior to SDRAM init:\n"); |
| 1888 | DUMPNORTH(); |
| 1889 | |
| 1890 | sdram_set_registers(memctrl); |
| 1891 | sdram_set_spd_registers(memctrl); |
| 1892 | sdram_enable(memctrl); |
| 1893 | } |
| 1894 | |
Kyösti Mälkki | 70d92b9 | 2017-04-19 19:57:01 +0300 | [diff] [blame] | 1895 | uintptr_t restore_top_of_low_cacheable(void) |
Kyösti Mälkki | 41dd3db | 2012-07-03 11:36:44 +0300 | [diff] [blame] | 1896 | { |
| 1897 | u32 tolm = (pci_read_config16(MCHDEV, TOLM) & ~0x7ff) << 16; |
Kyösti Mälkki | 70d92b9 | 2017-04-19 19:57:01 +0300 | [diff] [blame] | 1898 | return tolm; |
Kyösti Mälkki | 41dd3db | 2012-07-03 11:36:44 +0300 | [diff] [blame] | 1899 | } |
| 1900 | |
Kyösti Mälkki | 97c064f | 2012-04-18 20:33:35 +0300 | [diff] [blame] | 1901 | /** |
| 1902 | * Scrub and reset error counts for ECC dimms. |
| 1903 | * |
| 1904 | * NOTE: this will invalidate cache and disable XIP cache for the |
| 1905 | * short remaining part of romstage. |
| 1906 | */ |
| 1907 | void e7505_mch_scrub_ecc(unsigned long ret_addr) |
| 1908 | { |
| 1909 | unsigned long ret_addr2 = (unsigned long)((unsigned long*)&ret_addr-1); |
| 1910 | if ((pci_read_config32(MCHDEV, DRC)>>20 & 3) == 2) |
| 1911 | initialize_ecc(ret_addr, ret_addr2); |
| 1912 | } |
| 1913 | |
| 1914 | void e7505_mch_done(const struct mem_controller *memctrl) |
| 1915 | { |
| 1916 | sdram_post_ecc(memctrl); |
| 1917 | |
| 1918 | RAM_DEBUG_MESSAGE("Northbridge following SDRAM init:\n"); |
| 1919 | DUMPNORTH(); |
| 1920 | } |
| 1921 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 1922 | int e7505_mch_is_ready(void) |
Kyösti Mälkki | 5c1ff92 | 2012-04-10 19:55:19 +0300 | [diff] [blame] | 1923 | { |
| 1924 | uint32_t dword = pci_read_config32(MCHDEV, DRC); |
| 1925 | return !!(dword & DRC_DONE); |
| 1926 | } |