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