Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
Kyösti Mälkki | 931c1dc | 2014-06-30 09:40:19 +0300 | [diff] [blame] | 18 | #include <stdlib.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 19 | #include <arch/cpu.h> |
| 20 | #include <arch/io.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 21 | #include <device/pci_def.h> |
| 22 | #include <device/pnp_def.h> |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 23 | #include <device/device.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 24 | #include <spd.h> |
| 25 | #include <console/console.h> |
| 26 | #include <lib.h> |
Arthur Heymans | 10141c3 | 2016-10-27 00:31:41 +0200 | [diff] [blame] | 27 | #include <delay.h> |
Arthur Heymans | 049347f | 2017-05-12 11:54:08 +0200 | [diff] [blame] | 28 | #include <timestamp.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 29 | #include "gm45.h" |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 30 | #include "chip.h" |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 31 | |
| 32 | static const gmch_gfx_t gmch_gfx_types[][5] = { |
| 33 | /* MAX_667MHz MAX_533MHz MAX_400MHz MAX_333MHz MAX_800MHz */ |
| 34 | { GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN }, |
| 35 | { GMCH_GM47, GMCH_GM45, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_GM49 }, |
| 36 | { GMCH_GE45, GMCH_GE45, GMCH_GE45, GMCH_GE45, GMCH_GE45 }, |
| 37 | { GMCH_UNKNOWN, GMCH_GL43, GMCH_GL40, GMCH_UNKNOWN, GMCH_UNKNOWN }, |
| 38 | { GMCH_UNKNOWN, GMCH_GS45, GMCH_GS40, GMCH_UNKNOWN, GMCH_UNKNOWN }, |
| 39 | { GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN }, |
| 40 | { GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN, GMCH_UNKNOWN }, |
| 41 | { GMCH_PM45, GMCH_PM45, GMCH_PM45, GMCH_PM45, GMCH_PM45 }, |
| 42 | }; |
| 43 | |
| 44 | void get_gmch_info(sysinfo_t *sysinfo) |
| 45 | { |
| 46 | sysinfo->stepping = pci_read_config8(PCI_DEV(0, 0, 0), PCI_CLASS_REVISION); |
| 47 | if ((sysinfo->stepping > STEPPING_B3) && |
| 48 | (sysinfo->stepping != STEPPING_CONVERSION_A1)) |
| 49 | die("Unknown stepping.\n"); |
| 50 | if (sysinfo->stepping <= STEPPING_B3) |
| 51 | printk(BIOS_DEBUG, "Stepping %c%d\n", 'A' + sysinfo->stepping / 4, sysinfo->stepping % 4); |
| 52 | else |
| 53 | printk(BIOS_DEBUG, "Conversion stepping A1\n"); |
| 54 | |
| 55 | const u32 eax = cpuid_ext(0x04, 0).eax; |
| 56 | sysinfo->cores = ((eax >> 26) & 0x3f) + 1; |
| 57 | printk(BIOS_SPEW, "%d CPU cores\n", sysinfo->cores); |
| 58 | |
| 59 | u32 capid = pci_read_config16(PCI_DEV(0, 0, 0), D0F0_CAPID0+8); |
| 60 | if (!(capid & (1<<(79-64)))) { |
| 61 | printk(BIOS_SPEW, "iTPM enabled\n"); |
| 62 | } |
| 63 | |
| 64 | capid = pci_read_config32(PCI_DEV(0, 0, 0), D0F0_CAPID0+4); |
| 65 | if (!(capid & (1<<(57-32)))) { |
| 66 | printk(BIOS_SPEW, "ME enabled\n"); |
| 67 | } |
| 68 | |
| 69 | if (!(capid & (1<<(56-32)))) { |
| 70 | printk(BIOS_SPEW, "AMT enabled\n"); |
| 71 | } |
| 72 | |
| 73 | sysinfo->max_ddr2_mhz = (capid & (1<<(53-32)))?667:800; |
| 74 | printk(BIOS_SPEW, "capable of DDR2 of %d MHz or lower\n", sysinfo->max_ddr2_mhz); |
| 75 | |
| 76 | if (!(capid & (1<<(48-32)))) { |
| 77 | printk(BIOS_SPEW, "VT-d enabled\n"); |
| 78 | } |
| 79 | |
| 80 | const u32 gfx_variant = (capid>>(42-32)) & 0x7; |
| 81 | const u32 render_freq = ((capid>>(50-32) & 0x1) << 2) | ((capid>>(35-32)) & 0x3); |
| 82 | if (render_freq <= 4) |
| 83 | sysinfo->gfx_type = gmch_gfx_types[gfx_variant][render_freq]; |
| 84 | else |
| 85 | sysinfo->gfx_type = GMCH_UNKNOWN; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 86 | switch (sysinfo->gfx_type) { |
| 87 | case GMCH_GM45: |
| 88 | printk(BIOS_SPEW, "GMCH: GM45\n"); |
| 89 | break; |
| 90 | case GMCH_GM47: |
| 91 | printk(BIOS_SPEW, "GMCH: GM47\n"); |
| 92 | break; |
| 93 | case GMCH_GM49: |
| 94 | printk(BIOS_SPEW, "GMCH: GM49\n"); |
| 95 | break; |
| 96 | case GMCH_GE45: |
| 97 | printk(BIOS_SPEW, "GMCH: GE45\n"); |
| 98 | break; |
| 99 | case GMCH_GL40: |
| 100 | printk(BIOS_SPEW, "GMCH: GL40\n"); |
| 101 | break; |
| 102 | case GMCH_GL43: |
| 103 | printk(BIOS_SPEW, "GMCH: GL43\n"); |
| 104 | break; |
| 105 | case GMCH_GS40: |
| 106 | printk(BIOS_SPEW, "GMCH: GS40\n"); |
| 107 | break; |
| 108 | case GMCH_GS45: |
Nico Huber | 5aaeb27 | 2015-12-30 00:17:27 +0100 | [diff] [blame] | 109 | printk(BIOS_SPEW, "GMCH: GS45, using %s-power mode\n", |
| 110 | sysinfo->gs45_low_power_mode ? "low" : "high"); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 111 | break; |
| 112 | case GMCH_PM45: |
| 113 | printk(BIOS_SPEW, "GMCH: PM45\n"); |
| 114 | break; |
| 115 | case GMCH_UNKNOWN: |
| 116 | printk(BIOS_SPEW, "unknown GMCH\n"); |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | sysinfo->txt_enabled = !(capid & (1 << (37-32))); |
| 121 | if (sysinfo->txt_enabled) { |
| 122 | printk(BIOS_SPEW, "TXT enabled\n"); |
| 123 | } |
| 124 | |
| 125 | switch (render_freq) { |
| 126 | case 4: |
| 127 | sysinfo->max_render_mhz = 800; |
| 128 | break; |
| 129 | case 0: |
| 130 | sysinfo->max_render_mhz = 667; |
| 131 | break; |
| 132 | case 1: |
| 133 | sysinfo->max_render_mhz = 533; |
| 134 | break; |
| 135 | case 2: |
| 136 | sysinfo->max_render_mhz = 400; |
| 137 | break; |
| 138 | case 3: |
| 139 | sysinfo->max_render_mhz = 333; |
| 140 | break; |
| 141 | default: |
| 142 | printk(BIOS_SPEW, "Unknown render frequency\n"); |
| 143 | sysinfo->max_render_mhz = 0; |
| 144 | break; |
| 145 | } |
| 146 | if (sysinfo->max_render_mhz != 0) { |
| 147 | printk(BIOS_SPEW, "Render frequency: %d MHz\n", sysinfo->max_render_mhz); |
| 148 | } |
| 149 | |
| 150 | if (!(capid & (1<<(33-32)))) { |
| 151 | printk(BIOS_SPEW, "IGD enabled\n"); |
| 152 | } |
| 153 | |
| 154 | if (!(capid & (1<<(32-32)))) { |
| 155 | printk(BIOS_SPEW, "PCIe-to-GMCH enabled\n"); |
| 156 | } |
| 157 | |
| 158 | capid = pci_read_config32(PCI_DEV(0, 0, 0), D0F0_CAPID0); |
| 159 | |
| 160 | u32 ddr_cap = capid>>30 & 0x3; |
| 161 | switch (ddr_cap) { |
| 162 | case 0: |
| 163 | sysinfo->max_ddr3_mt = 1067; |
| 164 | break; |
| 165 | case 1: |
| 166 | sysinfo->max_ddr3_mt = 800; |
| 167 | break; |
| 168 | case 2: |
| 169 | case 3: |
| 170 | printk(BIOS_SPEW, "GMCH not DDR3 capable\n"); |
| 171 | sysinfo->max_ddr3_mt = 0; |
| 172 | break; |
| 173 | } |
| 174 | if (sysinfo->max_ddr3_mt != 0) { |
| 175 | printk(BIOS_SPEW, "GMCH supports DDR3 with %d MT or less\n", sysinfo->max_ddr3_mt); |
| 176 | } |
| 177 | |
| 178 | const unsigned max_fsb = (capid >> 28) & 0x3; |
| 179 | switch (max_fsb) { |
| 180 | case 1: |
| 181 | sysinfo->max_fsb_mhz = 1067; |
| 182 | break; |
| 183 | case 2: |
| 184 | sysinfo->max_fsb_mhz = 800; |
| 185 | break; |
| 186 | case 3: |
| 187 | sysinfo->max_fsb_mhz = 667; |
| 188 | break; |
| 189 | default: |
| 190 | die("unknown FSB capability\n"); |
| 191 | break; |
| 192 | } |
| 193 | if (sysinfo->max_fsb_mhz != 0) { |
| 194 | printk(BIOS_SPEW, "GMCH supports FSB with up to %d MHz\n", sysinfo->max_fsb_mhz); |
| 195 | } |
| 196 | sysinfo->max_fsb = max_fsb - 1; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Detect if the system went through an interrupted RAM init or is incon- |
| 201 | * sistent. If so, initiate a cold reboot. Otherwise mark the system to be |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 202 | * in RAM init, so this function would detect it on an erroneous reboot. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 203 | */ |
| 204 | void enter_raminit_or_reset(void) |
| 205 | { |
| 206 | /* Interrupted RAM init or inconsistent system? */ |
| 207 | u8 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa2); |
| 208 | |
| 209 | if (reg8 & (1 << 2)) { /* S4-assertion-width violation */ |
| 210 | /* Ignore S4-assertion-width violation like original BIOS. */ |
| 211 | printk(BIOS_WARNING, |
| 212 | "WARNING: Ignoring S4-assertion-width violation.\n"); |
| 213 | /* Bit2 is R/WC, so it will clear itself below. */ |
| 214 | } |
| 215 | |
| 216 | if (reg8 & (1 << 7)) { /* interrupted RAM init */ |
| 217 | /* Don't enable S4-assertion stretch. Makes trouble on roda/rk9. |
| 218 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4); |
| 219 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8 | 0x08); |
| 220 | */ |
| 221 | |
| 222 | /* Clear bit7. */ |
| 223 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8 & ~(1 << 7)); |
| 224 | |
| 225 | printk(BIOS_INFO, "Interrupted RAM init, reset required.\n"); |
| 226 | gm45_early_reset(); |
| 227 | } |
| 228 | /* Mark system to be in RAM init. */ |
| 229 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8 | (1 << 7)); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /* For a detected DIMM, test the value of an SPD byte to |
| 234 | match the expected value after masking some bits. */ |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 235 | static int test_dimm(sysinfo_t *const sysinfo, |
| 236 | int dimm, int addr, int bitmask, int expected) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 237 | { |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 238 | return (smbus_read_byte(sysinfo->spd_map[dimm], addr) & bitmask) == expected; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* This function dies if dimm is unsuitable for the chipset. */ |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 242 | static void verify_ddr3_dimm(sysinfo_t *const sysinfo, int dimm) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 243 | { |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 244 | if (!test_dimm(sysinfo, dimm, 3, 15, 3)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 245 | die("Chipset only supports SO-DIMM\n"); |
| 246 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 247 | if (!test_dimm(sysinfo, dimm, 8, 0x18, 0)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 248 | die("Chipset doesn't support ECC RAM\n"); |
| 249 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 250 | if (!test_dimm(sysinfo, dimm, 7, 0x38, 0) && |
| 251 | !test_dimm(sysinfo, dimm, 7, 0x38, 8)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 252 | die("Chipset wants single or double sided DIMMs\n"); |
| 253 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 254 | if (!test_dimm(sysinfo, dimm, 7, 7, 1) && |
| 255 | !test_dimm(sysinfo, dimm, 7, 7, 2)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 256 | die("Chipset requires x8 or x16 width\n"); |
| 257 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 258 | if (!test_dimm(sysinfo, dimm, 4, 0x0f, 0) && |
| 259 | !test_dimm(sysinfo, dimm, 4, 0x0f, 1) && |
| 260 | !test_dimm(sysinfo, dimm, 4, 0x0f, 2) && |
| 261 | !test_dimm(sysinfo, dimm, 4, 0x0f, 3)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 262 | die("Chipset requires 256Mb, 512Mb, 1Gb or 2Gb chips."); |
| 263 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 264 | if (!test_dimm(sysinfo, dimm, 4, 0x70, 0)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 265 | die("Chipset requires 8 banks on DDR3\n"); |
| 266 | |
| 267 | /* How to check if burst length is 8? |
| 268 | Other values are not supported, are they even possible? */ |
| 269 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 270 | if (!test_dimm(sysinfo, dimm, 10, 0xff, 1)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 271 | die("Code assumes 1/8ns MTB\n"); |
| 272 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 273 | if (!test_dimm(sysinfo, dimm, 11, 0xff, 8)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 274 | die("Code assumes 1/8ns MTB\n"); |
| 275 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 276 | if (!test_dimm(sysinfo, dimm, 62, 0x9f, 0) && |
| 277 | !test_dimm(sysinfo, dimm, 62, 0x9f, 1) && |
| 278 | !test_dimm(sysinfo, dimm, 62, 0x9f, 2) && |
| 279 | !test_dimm(sysinfo, dimm, 62, 0x9f, 3) && |
| 280 | !test_dimm(sysinfo, dimm, 62, 0x9f, 5)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 281 | die("Only raw card types A, B, C, D and F are supported.\n"); |
| 282 | } |
| 283 | |
| 284 | /* For every detected DIMM, test if it's suitable for the chipset. */ |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 285 | static void verify_ddr3(sysinfo_t *const sysinfo, int mask) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 286 | { |
| 287 | int cur = 0; |
| 288 | while (mask) { |
| 289 | if (mask & 1) { |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 290 | verify_ddr3_dimm(sysinfo, cur); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 291 | } |
| 292 | mask >>= 1; |
| 293 | cur++; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | |
| 298 | typedef struct { |
| 299 | int dimm_mask; |
| 300 | struct { |
| 301 | unsigned int rows; |
| 302 | unsigned int cols; |
| 303 | unsigned int chip_capacity; |
| 304 | unsigned int banks; |
| 305 | unsigned int ranks; |
| 306 | unsigned int cas_latencies; |
| 307 | unsigned int tAAmin; |
| 308 | unsigned int tCKmin; |
| 309 | unsigned int width; |
| 310 | unsigned int tRAS; |
| 311 | unsigned int tRP; |
| 312 | unsigned int tRCD; |
| 313 | unsigned int tWR; |
| 314 | unsigned int page_size; |
| 315 | unsigned int raw_card; |
| 316 | } channel[2]; |
| 317 | } spdinfo_t; |
| 318 | /* |
| 319 | * This function collects RAM characteristics from SPD, assuming that RAM |
| 320 | * is generally within chipset's requirements, since verify_ddr3() passed. |
| 321 | */ |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 322 | static void collect_ddr3(sysinfo_t *const sysinfo, spdinfo_t *const config) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 323 | { |
| 324 | int mask = config->dimm_mask; |
| 325 | int cur = 0; |
| 326 | while (mask != 0) { |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 327 | /* FIXME: support several dimms on same channel. */ |
| 328 | if ((mask & 1) && sysinfo->spd_map[2 * cur]) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 329 | int tmp; |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 330 | const int smb_addr = sysinfo->spd_map[2 * cur]; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 331 | |
| 332 | config->channel[cur].rows = ((smbus_read_byte(smb_addr, 5) >> 3) & 7) + 12; |
| 333 | config->channel[cur].cols = (smbus_read_byte(smb_addr, 5) & 7) + 9; |
| 334 | |
| 335 | config->channel[cur].chip_capacity = smbus_read_byte(smb_addr, 4) & 0xf; |
| 336 | |
| 337 | config->channel[cur].banks = 8; /* GM45 only accepts this for DDR3. |
| 338 | verify_ddr3() fails for other values. */ |
| 339 | config->channel[cur].ranks = ((smbus_read_byte(smb_addr, 7) >> 3) & 7) + 1; |
| 340 | |
| 341 | config->channel[cur].cas_latencies = |
| 342 | ((smbus_read_byte(smb_addr, 15) << 8) | smbus_read_byte(smb_addr, 14)) |
| 343 | << 4; /* so bit x is CAS x */ |
| 344 | config->channel[cur].tAAmin = smbus_read_byte(smb_addr, 16); /* in MTB */ |
| 345 | config->channel[cur].tCKmin = smbus_read_byte(smb_addr, 12); /* in MTB */ |
| 346 | |
| 347 | config->channel[cur].width = smbus_read_byte(smb_addr, 7) & 7; |
| 348 | config->channel[cur].page_size = config->channel[cur].width * |
| 349 | (1 << config->channel[cur].cols); /* in Bytes */ |
| 350 | |
| 351 | tmp = smbus_read_byte(smb_addr, 21); |
| 352 | config->channel[cur].tRAS = smbus_read_byte(smb_addr, 22) | ((tmp & 0xf) << 8); |
| 353 | config->channel[cur].tRP = smbus_read_byte(smb_addr, 20); |
| 354 | config->channel[cur].tRCD = smbus_read_byte(smb_addr, 18); |
| 355 | config->channel[cur].tWR = smbus_read_byte(smb_addr, 17); |
| 356 | |
| 357 | config->channel[cur].raw_card = smbus_read_byte(smb_addr, 62) & 0x1f; |
| 358 | } |
| 359 | cur++; |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 360 | mask >>= 2; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Edward O'Callaghan | 7116ac8 | 2014-07-08 01:53:24 +1000 | [diff] [blame] | 364 | #define ROUNDUP_DIV(val, by) CEIL_DIV(val, by) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 365 | #define ROUNDUP_DIV_THIS(val, by) val = ROUNDUP_DIV(val, by) |
| 366 | static fsb_clock_t read_fsb_clock(void) |
| 367 | { |
| 368 | switch (MCHBAR32(CLKCFG_MCHBAR) & CLKCFG_FSBCLK_MASK) { |
| 369 | case 6: |
| 370 | return FSB_CLOCK_1067MHz; |
| 371 | case 2: |
| 372 | return FSB_CLOCK_800MHz; |
| 373 | case 3: |
| 374 | return FSB_CLOCK_667MHz; |
| 375 | default: |
| 376 | die("Unsupported FSB clock.\n"); |
| 377 | } |
| 378 | } |
| 379 | static mem_clock_t clock_index(const unsigned int clock) |
| 380 | { |
| 381 | switch (clock) { |
| 382 | case 533: return MEM_CLOCK_533MHz; |
| 383 | case 400: return MEM_CLOCK_400MHz; |
| 384 | case 333: return MEM_CLOCK_333MHz; |
| 385 | default: die("Unknown clock value.\n"); |
| 386 | } |
| 387 | return -1; /* Won't be reached. */ |
| 388 | } |
| 389 | static void normalize_clock(unsigned int *const clock) |
| 390 | { |
| 391 | if (*clock >= 533) |
| 392 | *clock = 533; |
| 393 | else if (*clock >= 400) |
| 394 | *clock = 400; |
| 395 | else if (*clock >= 333) |
| 396 | *clock = 333; |
| 397 | else |
| 398 | *clock = 0; |
| 399 | } |
| 400 | static void lower_clock(unsigned int *const clock) |
| 401 | { |
| 402 | --*clock; |
| 403 | normalize_clock(clock); |
| 404 | } |
| 405 | static unsigned int find_common_clock_cas(sysinfo_t *const sysinfo, |
| 406 | const spdinfo_t *const spdinfo) |
| 407 | { |
| 408 | /* various constraints must be fulfilled: |
| 409 | CAS * tCK < 20ns == 160MTB |
| 410 | tCK_max >= tCK >= tCK_min |
| 411 | CAS >= roundup(tAA_min/tCK) |
| 412 | CAS supported |
| 413 | Clock(MHz) = 1000 / tCK(ns) |
| 414 | Clock(MHz) = 8000 / tCK(MTB) |
| 415 | AND BTW: Clock(MT) = 2000 / tCK(ns) - intel uses MTs but calls them MHz |
| 416 | */ |
| 417 | int i; |
| 418 | |
| 419 | /* Calculate common cas_latencies mask, tCKmin and tAAmin. */ |
| 420 | unsigned int cas_latencies = (unsigned int)-1; |
| 421 | unsigned int tCKmin = 0, tAAmin = 0; |
| 422 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, i) { |
| 423 | cas_latencies &= spdinfo->channel[i].cas_latencies; |
| 424 | if (spdinfo->channel[i].tCKmin > tCKmin) |
| 425 | tCKmin = spdinfo->channel[i].tCKmin; |
| 426 | if (spdinfo->channel[i].tAAmin > tAAmin) |
| 427 | tAAmin = spdinfo->channel[i].tAAmin; |
| 428 | } |
| 429 | |
| 430 | /* Get actual value of fsb clock. */ |
| 431 | sysinfo->selected_timings.fsb_clock = read_fsb_clock(); |
| 432 | unsigned int fsb_mhz = 0; |
| 433 | switch (sysinfo->selected_timings.fsb_clock) { |
| 434 | case FSB_CLOCK_1067MHz: fsb_mhz = 1067; break; |
| 435 | case FSB_CLOCK_800MHz: fsb_mhz = 800; break; |
| 436 | case FSB_CLOCK_667MHz: fsb_mhz = 667; break; |
| 437 | } |
| 438 | |
| 439 | unsigned int clock = 8000 / tCKmin; |
| 440 | if ((clock > sysinfo->max_ddr3_mt / 2) || (clock > fsb_mhz / 2)) { |
| 441 | int new_clock = min(sysinfo->max_ddr3_mt / 2, fsb_mhz / 2); |
| 442 | printk(BIOS_SPEW, "DIMMs support %d MHz, but chipset only runs at up to %d. Limiting...\n", |
| 443 | clock, new_clock); |
| 444 | clock = new_clock; |
| 445 | } |
| 446 | normalize_clock(&clock); |
| 447 | |
| 448 | /* Find compatible clock / CAS pair. */ |
| 449 | unsigned int tCKproposed; |
| 450 | unsigned int CAS; |
| 451 | while (1) { |
| 452 | if (!clock) |
| 453 | die("Couldn't find compatible clock / CAS settings.\n"); |
| 454 | tCKproposed = 8000 / clock; |
| 455 | CAS = ROUNDUP_DIV(tAAmin, tCKproposed); |
| 456 | printk(BIOS_SPEW, "Trying CAS %u, tCK %u.\n", CAS, tCKproposed); |
| 457 | for (; CAS <= DDR3_MAX_CAS; ++CAS) |
| 458 | if (cas_latencies & (1 << CAS)) |
| 459 | break; |
| 460 | if ((CAS <= DDR3_MAX_CAS) && (CAS * tCKproposed < 160)) { |
| 461 | /* Found good CAS. */ |
| 462 | printk(BIOS_SPEW, "Found compatible clock / CAS pair: %u / %u.\n", clock, CAS); |
| 463 | break; |
| 464 | } |
| 465 | lower_clock(&clock); |
| 466 | } |
| 467 | sysinfo->selected_timings.CAS = CAS; |
| 468 | sysinfo->selected_timings.mem_clock = clock_index(clock); |
| 469 | |
| 470 | return tCKproposed; |
| 471 | } |
| 472 | |
| 473 | static void calculate_derived_timings(sysinfo_t *const sysinfo, |
| 474 | const unsigned int tCLK, |
| 475 | const spdinfo_t *const spdinfo) |
| 476 | { |
| 477 | int i; |
| 478 | |
| 479 | /* Calculate common tRASmin, tRPmin, tRCDmin and tWRmin. */ |
| 480 | unsigned int tRASmin = 0, tRPmin = 0, tRCDmin = 0, tWRmin = 0; |
| 481 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, i) { |
| 482 | if (spdinfo->channel[i].tRAS > tRASmin) |
| 483 | tRASmin = spdinfo->channel[i].tRAS; |
| 484 | if (spdinfo->channel[i].tRP > tRPmin) |
| 485 | tRPmin = spdinfo->channel[i].tRP; |
| 486 | if (spdinfo->channel[i].tRCD > tRCDmin) |
| 487 | tRCDmin = spdinfo->channel[i].tRCD; |
| 488 | if (spdinfo->channel[i].tWR > tWRmin) |
| 489 | tWRmin = spdinfo->channel[i].tWR; |
| 490 | } |
| 491 | ROUNDUP_DIV_THIS(tRASmin, tCLK); |
| 492 | ROUNDUP_DIV_THIS(tRPmin, tCLK); |
| 493 | ROUNDUP_DIV_THIS(tRCDmin, tCLK); |
| 494 | ROUNDUP_DIV_THIS(tWRmin, tCLK); |
| 495 | |
| 496 | /* Lookup tRFC and calculate common tRFCmin. */ |
| 497 | const unsigned int tRFC_from_clock_and_cap[][4] = { |
| 498 | /* CAP_256M CAP_512M CAP_1G CAP_2G */ |
| 499 | /* 533MHz */ { 40, 56, 68, 104 }, |
| 500 | /* 400MHz */ { 30, 42, 51, 78 }, |
| 501 | /* 333MHz */ { 25, 35, 43, 65 }, |
| 502 | }; |
| 503 | unsigned int tRFCmin = 0; |
| 504 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, i) { |
| 505 | const unsigned int tRFC = tRFC_from_clock_and_cap |
| 506 | [sysinfo->selected_timings.mem_clock][spdinfo->channel[i].chip_capacity]; |
| 507 | if (tRFC > tRFCmin) |
| 508 | tRFCmin = tRFC; |
| 509 | } |
| 510 | |
| 511 | /* Calculate common tRD from CAS and FSB and DRAM clocks. */ |
| 512 | unsigned int tRDmin = sysinfo->selected_timings.CAS; |
| 513 | switch (sysinfo->selected_timings.fsb_clock) { |
| 514 | case FSB_CLOCK_667MHz: |
| 515 | tRDmin += 1; |
| 516 | break; |
| 517 | case FSB_CLOCK_800MHz: |
| 518 | tRDmin += 2; |
| 519 | break; |
| 520 | case FSB_CLOCK_1067MHz: |
| 521 | tRDmin += 3; |
| 522 | if (sysinfo->selected_timings.mem_clock == MEM_CLOCK_1067MT) |
| 523 | tRDmin += 1; |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | /* Calculate common tRRDmin. */ |
| 528 | unsigned int tRRDmin = 0; |
| 529 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, i) { |
| 530 | unsigned int tRRD = 2 + (spdinfo->channel[i].page_size / 1024); |
| 531 | if (sysinfo->selected_timings.mem_clock == MEM_CLOCK_1067MT) |
| 532 | tRRD += (spdinfo->channel[i].page_size / 1024); |
| 533 | if (tRRD > tRRDmin) |
| 534 | tRRDmin = tRRD; |
| 535 | } |
| 536 | |
| 537 | /* Lookup and calculate common tFAWmin. */ |
| 538 | unsigned int tFAW_from_pagesize_and_clock[][3] = { |
| 539 | /* 533MHz 400MHz 333MHz */ |
| 540 | /* 1K */ { 20, 15, 13 }, |
| 541 | /* 2K */ { 27, 20, 17 }, |
| 542 | }; |
| 543 | unsigned int tFAWmin = 0; |
| 544 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, i) { |
| 545 | const unsigned int tFAW = tFAW_from_pagesize_and_clock |
| 546 | [spdinfo->channel[i].page_size / 1024 - 1] |
| 547 | [sysinfo->selected_timings.mem_clock]; |
| 548 | if (tFAW > tFAWmin) |
| 549 | tFAWmin = tFAW; |
| 550 | } |
| 551 | |
| 552 | /* Refresh rate is fixed. */ |
| 553 | unsigned int tWL; |
| 554 | if (sysinfo->selected_timings.mem_clock == MEM_CLOCK_1067MT) { |
| 555 | tWL = 6; |
| 556 | } else { |
| 557 | tWL = 5; |
| 558 | } |
| 559 | |
| 560 | printk(BIOS_SPEW, "Timing values:\n" |
| 561 | " tCLK: %3u\n" |
| 562 | " tRAS: %3u\n" |
| 563 | " tRP: %3u\n" |
| 564 | " tRCD: %3u\n" |
| 565 | " tRFC: %3u\n" |
| 566 | " tWR: %3u\n" |
| 567 | " tRD: %3u\n" |
| 568 | " tRRD: %3u\n" |
| 569 | " tFAW: %3u\n" |
| 570 | " tWL: %3u\n", |
| 571 | tCLK, tRASmin, tRPmin, tRCDmin, tRFCmin, tWRmin, tRDmin, tRRDmin, tFAWmin, tWL); |
| 572 | |
| 573 | sysinfo->selected_timings.tRAS = tRASmin; |
| 574 | sysinfo->selected_timings.tRP = tRPmin; |
| 575 | sysinfo->selected_timings.tRCD = tRCDmin; |
| 576 | sysinfo->selected_timings.tRFC = tRFCmin; |
| 577 | sysinfo->selected_timings.tWR = tWRmin; |
| 578 | sysinfo->selected_timings.tRD = tRDmin; |
| 579 | sysinfo->selected_timings.tRRD = tRRDmin; |
| 580 | sysinfo->selected_timings.tFAW = tFAWmin; |
| 581 | sysinfo->selected_timings.tWL = tWL; |
| 582 | } |
| 583 | |
| 584 | static void collect_dimm_config(sysinfo_t *const sysinfo) |
| 585 | { |
| 586 | int i; |
| 587 | spdinfo_t spdinfo; |
| 588 | |
| 589 | spdinfo.dimm_mask = 0; |
| 590 | sysinfo->spd_type = 0; |
| 591 | |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 592 | for (i = 0; i < 4; i++) |
| 593 | if (sysinfo->spd_map[i]) { |
| 594 | const u8 spd = smbus_read_byte(sysinfo->spd_map[i], 2); |
| 595 | printk (BIOS_DEBUG, "%x:%x:%x\n", |
| 596 | i, sysinfo->spd_map[i], |
| 597 | spd); |
| 598 | if ((spd == 7) || (spd == 8) || (spd == 0xb)) { |
| 599 | spdinfo.dimm_mask |= 1 << i; |
| 600 | if (sysinfo->spd_type && sysinfo->spd_type != spd) { |
| 601 | die("Multiple types of DIMM installed in the system, don't do that!\n"); |
| 602 | } |
| 603 | sysinfo->spd_type = spd; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 604 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 605 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 606 | if (spdinfo.dimm_mask == 0) { |
| 607 | die("Could not find any DIMM.\n"); |
| 608 | } |
| 609 | |
| 610 | /* Normalize spd_type to 1, 2, 3. */ |
| 611 | sysinfo->spd_type = (sysinfo->spd_type & 1) | ((sysinfo->spd_type & 8) >> 2); |
| 612 | printk(BIOS_SPEW, "DDR mask %x, DDR %d\n", spdinfo.dimm_mask, sysinfo->spd_type); |
| 613 | |
| 614 | if (sysinfo->spd_type == DDR2) { |
| 615 | die("DDR2 not supported at this time.\n"); |
| 616 | } else if (sysinfo->spd_type == DDR3) { |
Vladimir Serbinenko | c4d8948 | 2014-06-05 09:14:48 +0200 | [diff] [blame] | 617 | verify_ddr3(sysinfo, spdinfo.dimm_mask); |
| 618 | collect_ddr3(sysinfo, &spdinfo); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 619 | } else { |
| 620 | die("Will never support DDR1.\n"); |
| 621 | } |
| 622 | |
| 623 | for (i = 0; i < 2; i++) { |
| 624 | if ((spdinfo.dimm_mask >> (i*2)) & 1) { |
| 625 | printk(BIOS_SPEW, "Bank %d populated:\n" |
| 626 | " Raw card type: %4c\n" |
| 627 | " Row addr bits: %4u\n" |
| 628 | " Col addr bits: %4u\n" |
| 629 | " byte width: %4u\n" |
| 630 | " page size: %4u\n" |
| 631 | " banks: %4u\n" |
| 632 | " ranks: %4u\n" |
| 633 | " tAAmin: %3u\n" |
| 634 | " tCKmin: %3u\n" |
| 635 | " Max clock: %3u MHz\n" |
| 636 | " CAS: 0x%04x\n", |
| 637 | i, spdinfo.channel[i].raw_card + 'A', |
| 638 | spdinfo.channel[i].rows, spdinfo.channel[i].cols, |
| 639 | spdinfo.channel[i].width, spdinfo.channel[i].page_size, |
| 640 | spdinfo.channel[i].banks, spdinfo.channel[i].ranks, |
| 641 | spdinfo.channel[i].tAAmin, spdinfo.channel[i].tCKmin, |
| 642 | 8000 / spdinfo.channel[i].tCKmin, spdinfo.channel[i].cas_latencies); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | FOR_EACH_CHANNEL(i) { |
| 647 | sysinfo->dimms[i].card_type = |
| 648 | (spdinfo.dimm_mask & (1 << (i * 2))) ? spdinfo.channel[i].raw_card + 0xa : 0; |
| 649 | } |
| 650 | |
| 651 | /* Find common memory clock and CAS. */ |
| 652 | const unsigned int tCLK = find_common_clock_cas(sysinfo, &spdinfo); |
| 653 | |
| 654 | /* Calculate other timings from clock and CAS. */ |
| 655 | calculate_derived_timings(sysinfo, tCLK, &spdinfo); |
| 656 | |
| 657 | /* Initialize DIMM infos. */ |
| 658 | /* Always prefer interleaved over async channel mode. */ |
| 659 | FOR_EACH_CHANNEL(i) { |
| 660 | IF_CHANNEL_POPULATED(sysinfo->dimms, i) { |
| 661 | sysinfo->dimms[i].banks = spdinfo.channel[i].banks; |
| 662 | sysinfo->dimms[i].ranks = spdinfo.channel[i].ranks; |
| 663 | |
| 664 | /* .width is 1 for x8 or 2 for x16, bus width is 8 bytes. */ |
| 665 | const unsigned int chips_per_rank = 8 / spdinfo.channel[i].width; |
| 666 | |
| 667 | sysinfo->dimms[i].chip_width = spdinfo.channel[i].width; |
| 668 | sysinfo->dimms[i].chip_capacity = spdinfo.channel[i].chip_capacity; |
| 669 | sysinfo->dimms[i].page_size = spdinfo.channel[i].page_size * chips_per_rank; |
| 670 | sysinfo->dimms[i].rank_capacity_mb = |
| 671 | /* offset of chip_capacity is 8 (256M), therefore, add 8 |
| 672 | chip_capacity is in Mbit, we want MByte, therefore, subtract 3 */ |
| 673 | (1 << (spdinfo.channel[i].chip_capacity + 8 - 3)) * chips_per_rank; |
| 674 | } |
| 675 | } |
| 676 | if (CHANNEL_IS_POPULATED(sysinfo->dimms, 0) && |
| 677 | CHANNEL_IS_POPULATED(sysinfo->dimms, 1)) |
| 678 | sysinfo->selected_timings.channel_mode = CHANNEL_MODE_DUAL_INTERLEAVED; |
| 679 | else |
| 680 | sysinfo->selected_timings.channel_mode = CHANNEL_MODE_SINGLE; |
| 681 | } |
| 682 | |
| 683 | static void reset_on_bad_warmboot(void) |
| 684 | { |
| 685 | /* Check self refresh channel status. */ |
| 686 | const u32 reg = MCHBAR32(PMSTS_MCHBAR); |
| 687 | /* Clear status bits. R/WC */ |
| 688 | MCHBAR32(PMSTS_MCHBAR) = reg; |
| 689 | if ((reg & PMSTS_WARM_RESET) && !(reg & PMSTS_BOTH_SELFREFRESH)) { |
| 690 | printk(BIOS_INFO, "DRAM was not in self refresh " |
| 691 | "during warm boot, reset required.\n"); |
| 692 | gm45_early_reset(); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | static void set_system_memory_frequency(const timings_t *const timings) |
| 697 | { |
| 698 | MCHBAR16(CLKCFG_MCHBAR + 0x60) &= ~(1 << 15); |
| 699 | MCHBAR16(CLKCFG_MCHBAR + 0x48) &= ~(1 << 15); |
| 700 | |
| 701 | /* Calculate wanted frequency setting. */ |
| 702 | const int want_freq = 6 - timings->mem_clock; |
| 703 | |
| 704 | /* Read current memory frequency. */ |
| 705 | const u32 clkcfg = MCHBAR32(CLKCFG_MCHBAR); |
| 706 | int cur_freq = (clkcfg & CLKCFG_MEMCLK_MASK) >> CLKCFG_MEMCLK_SHIFT; |
| 707 | if (0 == cur_freq) { |
| 708 | /* Try memory frequency from scratchpad. */ |
| 709 | printk(BIOS_DEBUG, "Reading current memory frequency from scratchpad.\n"); |
| 710 | cur_freq = (MCHBAR16(SSKPD_MCHBAR) & SSKPD_CLK_MASK) >> SSKPD_CLK_SHIFT; |
| 711 | } |
| 712 | |
| 713 | if (cur_freq != want_freq) { |
| 714 | printk(BIOS_DEBUG, "Changing memory frequency: old %x, new %x.\n", cur_freq, want_freq); |
| 715 | /* When writing new frequency setting, reset, then set update bit. */ |
| 716 | MCHBAR32(CLKCFG_MCHBAR) = (MCHBAR32(CLKCFG_MCHBAR) & ~(CLKCFG_UPDATE | CLKCFG_MEMCLK_MASK)) | |
| 717 | (want_freq << CLKCFG_MEMCLK_SHIFT); |
| 718 | MCHBAR32(CLKCFG_MCHBAR) = (MCHBAR32(CLKCFG_MCHBAR) & ~CLKCFG_MEMCLK_MASK) | |
| 719 | (want_freq << CLKCFG_MEMCLK_SHIFT) | CLKCFG_UPDATE; |
| 720 | /* Reset update bit. */ |
| 721 | MCHBAR32(CLKCFG_MCHBAR) &= ~CLKCFG_UPDATE; |
| 722 | } |
| 723 | |
| 724 | if ((timings->fsb_clock == FSB_CLOCK_1067MHz) && (timings->mem_clock == MEM_CLOCK_667MT)) { |
| 725 | MCHBAR32(CLKCFG_MCHBAR + 0x16) = 0x000030f0; |
| 726 | MCHBAR32(CLKCFG_MCHBAR + 0x64) = 0x000050c1; |
| 727 | |
| 728 | MCHBAR32(CLKCFG_MCHBAR) = (MCHBAR32(CLKCFG_MCHBAR) & ~(1 << 12)) | (1 << 17); |
| 729 | MCHBAR32(CLKCFG_MCHBAR) |= (1 << 17) | (1 << 12); |
| 730 | MCHBAR32(CLKCFG_MCHBAR) &= ~(1 << 12); |
| 731 | |
| 732 | MCHBAR32(CLKCFG_MCHBAR + 0x04) = 0x9bad1f1f; |
| 733 | MCHBAR8(CLKCFG_MCHBAR + 0x08) = 0xf4; |
| 734 | MCHBAR8(CLKCFG_MCHBAR + 0x0a) = 0x43; |
| 735 | MCHBAR8(CLKCFG_MCHBAR + 0x0c) = 0x10; |
| 736 | MCHBAR8(CLKCFG_MCHBAR + 0x0d) = 0x80; |
| 737 | MCHBAR32(CLKCFG_MCHBAR + 0x50) = 0x0b0e151b; |
| 738 | MCHBAR8(CLKCFG_MCHBAR + 0x54) = 0xb4; |
| 739 | MCHBAR8(CLKCFG_MCHBAR + 0x55) = 0x10; |
| 740 | MCHBAR8(CLKCFG_MCHBAR + 0x56) = 0x08; |
| 741 | |
| 742 | MCHBAR32(CLKCFG_MCHBAR) |= (1 << 10); |
| 743 | MCHBAR32(CLKCFG_MCHBAR) |= (1 << 11); |
| 744 | MCHBAR32(CLKCFG_MCHBAR) &= ~(1 << 10); |
| 745 | MCHBAR32(CLKCFG_MCHBAR) &= ~(1 << 11); |
| 746 | } |
| 747 | |
| 748 | MCHBAR32(CLKCFG_MCHBAR + 0x48) |= 0x3f << 24; |
| 749 | } |
| 750 | |
| 751 | int raminit_read_vco_index(void) |
| 752 | { |
Nico Huber | d85a71a | 2016-11-27 14:43:12 +0100 | [diff] [blame] | 753 | switch (MCHBAR8(HPLLVCO_MCHBAR) & 0x7) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 754 | case VCO_2666: |
| 755 | return 0; |
| 756 | case VCO_3200: |
| 757 | return 1; |
| 758 | case VCO_4000: |
| 759 | return 2; |
| 760 | case VCO_5333: |
| 761 | return 3; |
| 762 | default: |
| 763 | die("Unknown VCO frequency.\n"); |
| 764 | return 0; |
| 765 | } |
| 766 | } |
| 767 | static void set_igd_memory_frequencies(const sysinfo_t *const sysinfo) |
| 768 | { |
| 769 | const int gfx_idx = ((sysinfo->gfx_type == GMCH_GS45) && |
| 770 | !sysinfo->gs45_low_power_mode) |
| 771 | ? (GMCH_GS45 + 1) : sysinfo->gfx_type; |
| 772 | |
| 773 | /* Render and sampler frequency values seem to be some kind of factor. */ |
| 774 | const u16 render_freq_from_vco_and_gfxtype[][10] = { |
| 775 | /* GM45 GM47 GM49 GE45 GL40 GL43 GS40 GS45 (perf) */ |
| 776 | /* VCO 2666 */ { 0xd, 0xd, 0xe, 0xd, 0xb, 0xd, 0xb, 0xa, 0xd }, |
| 777 | /* VCO 3200 */ { 0xd, 0xe, 0xf, 0xd, 0xb, 0xd, 0xb, 0x9, 0xd }, |
| 778 | /* VCO 4000 */ { 0xc, 0xd, 0xf, 0xc, 0xa, 0xc, 0xa, 0x9, 0xc }, |
| 779 | /* VCO 5333 */ { 0xb, 0xc, 0xe, 0xb, 0x9, 0xb, 0x9, 0x8, 0xb }, |
| 780 | }; |
| 781 | const u16 sampler_freq_from_vco_and_gfxtype[][10] = { |
| 782 | /* GM45 GM47 GM49 GE45 GL40 GL43 GS40 GS45 (perf) */ |
| 783 | /* VCO 2666 */ { 0xc, 0xc, 0xd, 0xc, 0x9, 0xc, 0x9, 0x8, 0xc }, |
| 784 | /* VCO 3200 */ { 0xc, 0xd, 0xe, 0xc, 0x9, 0xc, 0x9, 0x8, 0xc }, |
| 785 | /* VCO 4000 */ { 0xa, 0xc, 0xd, 0xa, 0x8, 0xa, 0x8, 0x8, 0xa }, |
| 786 | /* VCO 5333 */ { 0xa, 0xa, 0xc, 0xa, 0x7, 0xa, 0x7, 0x6, 0xa }, |
| 787 | }; |
| 788 | const u16 display_clock_select_from_gfxtype[] = { |
| 789 | /* GM45 GM47 GM49 GE45 GL40 GL43 GS40 GS45 (perf) */ |
| 790 | 1, 1, 1, 1, 1, 1, 1, 0, 1 |
| 791 | }; |
| 792 | |
| 793 | if (pci_read_config16(GCFGC_PCIDEV, 0) != 0x8086) { |
| 794 | printk(BIOS_DEBUG, "Skipping IGD memory frequency setting.\n"); |
| 795 | return; |
| 796 | } |
| 797 | |
| 798 | MCHBAR16(0x119e) = 0xa800; |
| 799 | MCHBAR16(0x11c0) = (MCHBAR16(0x11c0) & ~0xff00) | (0x01 << 8); |
| 800 | MCHBAR16(0x119e) = 0xb800; |
| 801 | MCHBAR8(0x0f10) |= 1 << 7; |
| 802 | |
| 803 | /* Read VCO. */ |
| 804 | const int vco_idx = raminit_read_vco_index(); |
| 805 | printk(BIOS_DEBUG, "Setting IGD memory frequencies for VCO #%d.\n", vco_idx); |
| 806 | |
| 807 | const u32 freqcfg = |
| 808 | ((render_freq_from_vco_and_gfxtype[vco_idx][gfx_idx] |
| 809 | << GCFGC_CR_SHIFT) & GCFGC_CR_MASK) | |
| 810 | ((sampler_freq_from_vco_and_gfxtype[vco_idx][gfx_idx] |
| 811 | << GCFGC_CS_SHIFT) & GCFGC_CS_MASK); |
| 812 | |
| 813 | /* Set frequencies, clear update bit. */ |
| 814 | u32 gcfgc = pci_read_config16(GCFGC_PCIDEV, GCFGC_OFFSET); |
| 815 | gcfgc &= ~(GCFGC_CS_MASK | GCFGC_UPDATE | GCFGC_CR_MASK); |
| 816 | gcfgc |= freqcfg; |
| 817 | pci_write_config16(GCFGC_PCIDEV, GCFGC_OFFSET, gcfgc); |
| 818 | |
| 819 | /* Set frequencies, set update bit. */ |
| 820 | gcfgc = pci_read_config16(GCFGC_PCIDEV, GCFGC_OFFSET); |
| 821 | gcfgc &= ~(GCFGC_CS_MASK | GCFGC_CR_MASK); |
| 822 | gcfgc |= freqcfg | GCFGC_UPDATE; |
| 823 | pci_write_config16(GCFGC_PCIDEV, GCFGC_OFFSET, gcfgc); |
| 824 | |
| 825 | /* Clear update bit. */ |
| 826 | pci_write_config16(GCFGC_PCIDEV, GCFGC_OFFSET, |
| 827 | pci_read_config16(GCFGC_PCIDEV, GCFGC_OFFSET) & ~GCFGC_UPDATE); |
| 828 | |
| 829 | /* Set display clock select bit. */ |
| 830 | pci_write_config16(GCFGC_PCIDEV, GCFGC_OFFSET, |
| 831 | (pci_read_config16(GCFGC_PCIDEV, GCFGC_OFFSET) & ~GCFGC_CD_MASK) | |
| 832 | (display_clock_select_from_gfxtype[gfx_idx] << GCFGC_CD_SHIFT)); |
| 833 | } |
| 834 | |
| 835 | static void configure_dram_control_mode(const timings_t *const timings, const dimminfo_t *const dimms) |
| 836 | { |
| 837 | int ch, r; |
| 838 | |
| 839 | FOR_EACH_CHANNEL(ch) { |
| 840 | unsigned int mchbar = CxDRC0_MCHBAR(ch); |
| 841 | u32 cxdrc = MCHBAR32(mchbar); |
| 842 | cxdrc &= ~CxDRC0_RANKEN_MASK; |
| 843 | FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) |
| 844 | cxdrc |= CxDRC0_RANKEN(r); |
| 845 | cxdrc = (cxdrc & ~CxDRC0_RMS_MASK) | |
| 846 | /* Always 7.8us for DDR3: */ |
| 847 | CxDRC0_RMS_78US; |
| 848 | MCHBAR32(mchbar) = cxdrc; |
| 849 | |
| 850 | mchbar = CxDRC1_MCHBAR(ch); |
| 851 | cxdrc = MCHBAR32(mchbar); |
| 852 | cxdrc |= CxDRC1_NOTPOP_MASK; |
| 853 | FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) |
| 854 | cxdrc &= ~CxDRC1_NOTPOP(r); |
| 855 | cxdrc |= CxDRC1_MUSTWR; |
| 856 | MCHBAR32(mchbar) = cxdrc; |
| 857 | |
| 858 | mchbar = CxDRC2_MCHBAR(ch); |
| 859 | cxdrc = MCHBAR32(mchbar); |
| 860 | cxdrc |= CxDRC2_NOTPOP_MASK; |
| 861 | FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) |
| 862 | cxdrc &= ~CxDRC2_NOTPOP(r); |
| 863 | cxdrc |= CxDRC2_MUSTWR; |
| 864 | if (timings->mem_clock == MEM_CLOCK_1067MT) |
| 865 | cxdrc |= CxDRC2_CLK1067MT; |
| 866 | MCHBAR32(mchbar) = cxdrc; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | static void rcomp_initialization(const stepping_t stepping, const int sff) |
| 871 | { |
Elyes HAOUAS | 3d45000 | 2018-08-09 18:55:58 +0200 | [diff] [blame] | 872 | /* Program RCOMP codes. */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 873 | if (sff) |
| 874 | die("SFF platform unsupported in RCOMP initialization.\n"); |
| 875 | /* Values are for DDR3. */ |
| 876 | MCHBAR8(0x6ac) &= ~0x0f; |
| 877 | MCHBAR8(0x6b0) = 0x55; |
| 878 | MCHBAR8(0x6ec) &= ~0x0f; |
| 879 | MCHBAR8(0x6f0) = 0x66; |
| 880 | MCHBAR8(0x72c) &= ~0x0f; |
| 881 | MCHBAR8(0x730) = 0x66; |
| 882 | MCHBAR8(0x76c) &= ~0x0f; |
| 883 | MCHBAR8(0x770) = 0x66; |
| 884 | MCHBAR8(0x7ac) &= ~0x0f; |
| 885 | MCHBAR8(0x7b0) = 0x66; |
| 886 | MCHBAR8(0x7ec) &= ~0x0f; |
| 887 | MCHBAR8(0x7f0) = 0x66; |
| 888 | MCHBAR8(0x86c) &= ~0x0f; |
| 889 | MCHBAR8(0x870) = 0x55; |
| 890 | MCHBAR8(0x8ac) &= ~0x0f; |
| 891 | MCHBAR8(0x8b0) = 0x66; |
| 892 | /* ODT multiplier bits. */ |
| 893 | MCHBAR32(0x04d0) = (MCHBAR32(0x04d0) & ~((7 << 3) | (7 << 0))) | (2 << 3) | (2 << 0); |
| 894 | |
| 895 | /* Perform RCOMP calibration for DDR3. */ |
| 896 | raminit_rcomp_calibration(stepping); |
| 897 | |
| 898 | /* Run initial RCOMP. */ |
| 899 | MCHBAR32(0x418) |= 1 << 17; |
| 900 | MCHBAR32(0x40c) &= ~(1 << 23); |
| 901 | MCHBAR32(0x41c) &= ~((1 << 7) | (1 << 3)); |
| 902 | MCHBAR32(0x400) |= 1; |
| 903 | while (MCHBAR32(0x400) & 1) {} |
| 904 | |
| 905 | /* Run second RCOMP. */ |
| 906 | MCHBAR32(0x40c) |= 1 << 19; |
| 907 | MCHBAR32(0x400) |= 1; |
| 908 | while (MCHBAR32(0x400) & 1) {} |
| 909 | |
| 910 | /* Cleanup and start periodic RCOMP. */ |
| 911 | MCHBAR32(0x40c) &= ~(1 << 19); |
| 912 | MCHBAR32(0x40c) |= 1 << 23; |
| 913 | MCHBAR32(0x418) &= ~(1 << 17); |
| 914 | MCHBAR32(0x41c) |= (1 << 7) | (1 << 3); |
| 915 | MCHBAR32(0x400) |= (1 << 1); |
| 916 | } |
| 917 | |
| 918 | static void dram_powerup(const int resume) |
| 919 | { |
Arthur Heymans | 10141c3 | 2016-10-27 00:31:41 +0200 | [diff] [blame] | 920 | udelay(200); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 921 | MCHBAR32(CLKCFG_MCHBAR) = (MCHBAR32(CLKCFG_MCHBAR) & ~(1 << 3)) | (3 << 21); |
| 922 | if (!resume) { |
| 923 | MCHBAR32(0x1434) |= (1 << 10); |
Arthur Heymans | 10141c3 | 2016-10-27 00:31:41 +0200 | [diff] [blame] | 924 | udelay(1); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 925 | } |
| 926 | MCHBAR32(0x1434) |= (1 << 6); |
| 927 | if (!resume) { |
Arthur Heymans | 10141c3 | 2016-10-27 00:31:41 +0200 | [diff] [blame] | 928 | udelay(1); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 929 | MCHBAR32(0x1434) |= (1 << 9); |
| 930 | MCHBAR32(0x1434) &= ~(1 << 10); |
| 931 | udelay(500); |
| 932 | } |
| 933 | } |
| 934 | static void dram_program_timings(const timings_t *const timings) |
| 935 | { |
| 936 | /* Values are for DDR3. */ |
| 937 | const int burst_length = 8; |
| 938 | const int tWTR = 4, tRTP = 1; |
| 939 | int i; |
| 940 | |
| 941 | FOR_EACH_CHANNEL(i) { |
| 942 | u32 reg = MCHBAR32(CxDRT0_MCHBAR(i)); |
| 943 | const int btb_wtp = timings->tWL + burst_length/2 + timings->tWR; |
| 944 | const int btb_wtr = timings->tWL + burst_length/2 + tWTR; |
| 945 | reg = (reg & ~(CxDRT0_BtB_WtP_MASK | CxDRT0_BtB_WtR_MASK)) | |
| 946 | ((btb_wtp << CxDRT0_BtB_WtP_SHIFT) & CxDRT0_BtB_WtP_MASK) | |
| 947 | ((btb_wtr << CxDRT0_BtB_WtR_SHIFT) & CxDRT0_BtB_WtR_MASK); |
| 948 | if (timings->mem_clock != MEM_CLOCK_1067MT) { |
| 949 | reg = (reg & ~(0x7 << 15)) | ((9 - timings->CAS) << 15); |
| 950 | reg = (reg & ~(0xf << 10)) | ((timings->CAS - 3) << 10); |
| 951 | } else { |
| 952 | reg = (reg & ~(0x7 << 15)) | ((10 - timings->CAS) << 15); |
| 953 | reg = (reg & ~(0xf << 10)) | ((timings->CAS - 4) << 10); |
| 954 | } |
| 955 | reg = (reg & ~(0x7 << 5)) | (3 << 5); |
| 956 | reg = (reg & ~(0x7 << 0)) | (1 << 0); |
| 957 | MCHBAR32(CxDRT0_MCHBAR(i)) = reg; |
| 958 | |
| 959 | reg = MCHBAR32(CxDRT1_MCHBAR(i)); |
| 960 | reg = (reg & ~(0x03 << 28)) | ((tRTP & 0x03) << 28); |
| 961 | reg = (reg & ~(0x1f << 21)) | ((timings->tRAS & 0x1f) << 21); |
| 962 | reg = (reg & ~(0x07 << 10)) | (((timings->tRRD - 2) & 0x07) << 10); |
| 963 | reg = (reg & ~(0x07 << 5)) | (((timings->tRCD - 2) & 0x07) << 5); |
| 964 | reg = (reg & ~(0x07 << 0)) | (((timings->tRP - 2) & 0x07) << 0); |
| 965 | MCHBAR32(CxDRT1_MCHBAR(i)) = reg; |
| 966 | |
| 967 | reg = MCHBAR32(CxDRT2_MCHBAR(i)); |
| 968 | reg = (reg & ~(0x1f << 17)) | ((timings->tFAW & 0x1f) << 17); |
| 969 | if (timings->mem_clock != MEM_CLOCK_1067MT) { |
| 970 | reg = (reg & ~(0x7 << 12)) | (0x2 << 12); |
| 971 | reg = (reg & ~(0xf << 6)) | (0x9 << 6); |
| 972 | } else { |
| 973 | reg = (reg & ~(0x7 << 12)) | (0x3 << 12); |
| 974 | reg = (reg & ~(0xf << 6)) | (0xc << 6); |
| 975 | } |
| 976 | reg = (reg & ~(0x1f << 0)) | (0x13 << 0); |
| 977 | MCHBAR32(CxDRT2_MCHBAR(i)) = reg; |
| 978 | |
| 979 | reg = MCHBAR32(CxDRT3_MCHBAR(i)); |
| 980 | reg |= 0x3 << 28; |
| 981 | reg = (reg & ~(0x03 << 26)); |
| 982 | reg = (reg & ~(0x07 << 23)) | (((timings->CAS - 3) & 0x07) << 23); |
| 983 | reg = (reg & ~(0xff << 13)) | ((timings->tRFC & 0xff) << 13); |
| 984 | reg = (reg & ~(0x07 << 0)) | (((timings->tWL - 2) & 0x07) << 0); |
| 985 | MCHBAR32(CxDRT3_MCHBAR(i)) = reg; |
| 986 | |
| 987 | reg = MCHBAR32(CxDRT4_MCHBAR(i)); |
| 988 | static const u8 timings_by_clock[4][3] = { |
| 989 | /* 333MHz 400MHz 533MHz |
| 990 | 667MT 800MT 1067MT */ |
| 991 | { 0x07, 0x0a, 0x0d }, |
| 992 | { 0x3a, 0x46, 0x5d }, |
| 993 | { 0x0c, 0x0e, 0x18 }, |
| 994 | { 0x21, 0x28, 0x35 }, |
| 995 | }; |
| 996 | const int clk_idx = 2 - timings->mem_clock; |
| 997 | reg = (reg & ~(0x01f << 27)) | (timings_by_clock[0][clk_idx] << 27); |
| 998 | reg = (reg & ~(0x3ff << 17)) | (timings_by_clock[1][clk_idx] << 17); |
| 999 | reg = (reg & ~(0x03f << 10)) | (timings_by_clock[2][clk_idx] << 10); |
| 1000 | reg = (reg & ~(0x1ff << 0)) | (timings_by_clock[3][clk_idx] << 0); |
| 1001 | MCHBAR32(CxDRT4_MCHBAR(i)) = reg; |
| 1002 | |
| 1003 | reg = MCHBAR32(CxDRT5_MCHBAR(i)); |
| 1004 | if (timings->mem_clock == MEM_CLOCK_1067MT) |
| 1005 | reg = (reg & ~(0xf << 28)) | (0x8 << 28); |
| 1006 | reg = (reg & ~(0x00f << 22)) | ((burst_length/2 + timings->CAS + 2) << 22); |
| 1007 | reg = (reg & ~(0x3ff << 12)) | (0x190 << 12); |
| 1008 | reg = (reg & ~(0x00f << 4)) | ((timings->CAS - 2) << 4); |
| 1009 | reg = (reg & ~(0x003 << 2)) | (0x001 << 2); |
| 1010 | reg = (reg & ~(0x003 << 0)); |
| 1011 | MCHBAR32(CxDRT5_MCHBAR(i)) = reg; |
| 1012 | |
| 1013 | reg = MCHBAR32(CxDRT6_MCHBAR(i)); |
| 1014 | reg = (reg & ~(0xffff << 16)) | (0x066a << 16); /* always 7.8us refresh rate for DDR3 */ |
| 1015 | reg |= (1 << 2); |
| 1016 | MCHBAR32(CxDRT6_MCHBAR(i)) = reg; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | static void dram_program_banks(const dimminfo_t *const dimms) |
| 1021 | { |
| 1022 | int ch, r; |
| 1023 | |
| 1024 | FOR_EACH_CHANNEL(ch) { |
| 1025 | const int tRPALL = dimms[ch].banks == 8; |
| 1026 | |
| 1027 | u32 reg = MCHBAR32(CxDRT1_MCHBAR(ch)) & ~(0x01 << 15); |
| 1028 | IF_CHANNEL_POPULATED(dimms, ch) |
| 1029 | reg |= tRPALL << 15; |
| 1030 | MCHBAR32(CxDRT1_MCHBAR(ch)) = reg; |
| 1031 | |
| 1032 | reg = MCHBAR32(CxDRA_MCHBAR(ch)) & ~CxDRA_BANKS_MASK; |
| 1033 | FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) { |
| 1034 | reg |= CxDRA_BANKS(r, dimms[ch].banks); |
| 1035 | } |
| 1036 | MCHBAR32(CxDRA_MCHBAR(ch)) = reg; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | static void odt_setup(const timings_t *const timings, const int sff) |
| 1041 | { |
| 1042 | /* Values are for DDR3. */ |
| 1043 | int ch; |
| 1044 | |
| 1045 | FOR_EACH_CHANNEL(ch) { |
| 1046 | u32 reg = MCHBAR32(CxODT_HIGH(ch)); |
| 1047 | if (sff && (timings->mem_clock != MEM_CLOCK_1067MT)) |
| 1048 | reg &= ~(0x3 << (61 - 32)); |
| 1049 | else |
| 1050 | reg |= 0x3 << (61 - 32); |
| 1051 | reg = (reg & ~(0x3 << (52 - 32))) | (0x2 << (52 - 32)); |
| 1052 | reg = (reg & ~(0x7 << (48 - 32))) | ((timings->CAS - 3) << (48 - 32)); |
| 1053 | reg = (reg & ~(0xf << (44 - 32))) | (0x7 << (44 - 32)); |
| 1054 | if (timings->mem_clock != MEM_CLOCK_1067MT) { |
| 1055 | reg = (reg & ~(0xf << (40 - 32))) | ((12 - timings->CAS) << (40 - 32)); |
| 1056 | reg = (reg & ~(0xf << (36 - 32))) | (( 2 + timings->CAS) << (36 - 32)); |
| 1057 | } else { |
| 1058 | reg = (reg & ~(0xf << (40 - 32))) | ((13 - timings->CAS) << (40 - 32)); |
| 1059 | reg = (reg & ~(0xf << (36 - 32))) | (( 1 + timings->CAS) << (36 - 32)); |
| 1060 | } |
| 1061 | reg = (reg & ~(0xf << (32 - 32))) | (0x7 << (32 - 32)); |
| 1062 | MCHBAR32(CxODT_HIGH(ch)) = reg; |
| 1063 | |
| 1064 | reg = MCHBAR32(CxODT_LOW(ch)); |
| 1065 | reg = (reg & ~(0x7 << 28)) | (0x2 << 28); |
| 1066 | reg = (reg & ~(0x3 << 22)) | (0x2 << 22); |
| 1067 | reg = (reg & ~(0x7 << 12)) | (0x2 << 12); |
| 1068 | reg = (reg & ~(0x7 << 4)) | (0x2 << 4); |
| 1069 | switch (timings->mem_clock) { |
| 1070 | case MEM_CLOCK_667MT: |
| 1071 | reg = (reg & ~0x7); |
| 1072 | break; |
| 1073 | case MEM_CLOCK_800MT: |
| 1074 | reg = (reg & ~0x7) | 0x2; |
| 1075 | break; |
| 1076 | case MEM_CLOCK_1067MT: |
| 1077 | reg = (reg & ~0x7) | 0x5; |
| 1078 | break; |
| 1079 | } |
| 1080 | MCHBAR32(CxODT_LOW(ch)) = reg; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | static void misc_settings(const timings_t *const timings, |
| 1085 | const stepping_t stepping) |
| 1086 | { |
| 1087 | MCHBAR32(0x1260) = (MCHBAR32(0x1260) & ~((1 << 24) | 0x1f)) | timings->tRD; |
| 1088 | MCHBAR32(0x1360) = (MCHBAR32(0x1360) & ~((1 << 24) | 0x1f)) | timings->tRD; |
| 1089 | |
| 1090 | MCHBAR8(0x1268) = (MCHBAR8(0x1268) & ~(0xf)) | timings->tWL; |
| 1091 | MCHBAR8(0x1368) = (MCHBAR8(0x1368) & ~(0xf)) | timings->tWL; |
| 1092 | MCHBAR8(0x12a0) = (MCHBAR8(0x12a0) & ~(0xf)) | 0xa; |
| 1093 | MCHBAR8(0x13a0) = (MCHBAR8(0x13a0) & ~(0xf)) | 0xa; |
| 1094 | |
| 1095 | MCHBAR32(0x218) = (MCHBAR32(0x218) & ~((7 << 29) | (7 << 25) | (3 << 22) | (3 << 10))) | |
| 1096 | (4 << 29) | (3 << 25) | (0 << 22) | (1 << 10); |
| 1097 | MCHBAR32(0x220) = (MCHBAR32(0x220) & ~(7 << 16)) | (1 << 21) | (1 << 16); |
| 1098 | MCHBAR32(0x224) = (MCHBAR32(0x224) & ~(7 << 8)) | (3 << 8); |
| 1099 | if (stepping >= STEPPING_B1) |
| 1100 | MCHBAR8(0x234) |= (1 << 3); |
| 1101 | } |
| 1102 | |
| 1103 | static void clock_crossing_setup(const fsb_clock_t fsb, |
| 1104 | const mem_clock_t ddr3clock, |
| 1105 | const dimminfo_t *const dimms) |
| 1106 | { |
| 1107 | int ch; |
| 1108 | |
| 1109 | static const u32 values_from_fsb_and_mem[][3][4] = { |
| 1110 | /* FSB 1067MHz */{ |
| 1111 | /* DDR3-1067 */ { 0x00000000, 0x00000000, 0x00180006, 0x00810060 }, |
| 1112 | /* DDR3-800 */ { 0x00000000, 0x00000000, 0x0000001c, 0x000300e0 }, |
| 1113 | /* DDR3-667 */ { 0x00000000, 0x00001c00, 0x03c00038, 0x0007e000 }, |
| 1114 | }, |
| 1115 | /* FSB 800MHz */{ |
| 1116 | /* DDR3-1067 */ { 0, 0, 0, 0 }, |
| 1117 | /* DDR3-800 */ { 0x00000000, 0x00000000, 0x0030000c, 0x000300c0 }, |
| 1118 | /* DDR3-667 */ { 0x00000000, 0x00000380, 0x0060001c, 0x00030c00 }, |
| 1119 | }, |
| 1120 | /* FSB 667MHz */{ |
| 1121 | /* DDR3-1067 */ { 0, 0, 0, 0 }, |
| 1122 | /* DDR3-800 */ { 0, 0, 0, 0 }, |
| 1123 | /* DDR3-667 */ { 0x00000000, 0x00000000, 0x0030000c, 0x000300c0 }, |
| 1124 | }, |
| 1125 | }; |
| 1126 | |
| 1127 | const u32 *data = values_from_fsb_and_mem[fsb][ddr3clock]; |
| 1128 | MCHBAR32(0x0208) = data[3]; |
| 1129 | MCHBAR32(0x020c) = data[2]; |
| 1130 | if (((fsb == FSB_CLOCK_1067MHz) || (fsb == FSB_CLOCK_800MHz)) && (ddr3clock == MEM_CLOCK_667MT)) |
| 1131 | MCHBAR32(0x0210) = data[1]; |
| 1132 | |
| 1133 | static const u32 from_fsb_and_mem[][3] = { |
| 1134 | /* DDR3-1067 DDR3-800 DDR3-667 */ |
| 1135 | /* FSB 1067MHz */{ 0x40100401, 0x10040220, 0x08040110, }, |
| 1136 | /* FSB 800MHz */{ 0x00000000, 0x40100401, 0x00080201, }, |
| 1137 | /* FSB 667MHz */{ 0x00000000, 0x00000000, 0x40100401, }, |
| 1138 | }; |
| 1139 | FOR_EACH_CHANNEL(ch) { |
| 1140 | const unsigned int mchbar = 0x1258 + (ch * 0x0100); |
| 1141 | if ((fsb == FSB_CLOCK_1067MHz) && (ddr3clock == MEM_CLOCK_800MT) && CHANNEL_IS_CARDF(dimms, ch)) |
| 1142 | MCHBAR32(mchbar) = 0x08040120; |
| 1143 | else |
| 1144 | MCHBAR32(mchbar) = from_fsb_and_mem[fsb][ddr3clock]; |
| 1145 | MCHBAR32(mchbar + 4) = 0x00000000; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | /* Program egress VC1 timings. */ |
| 1150 | static void vc1_program_timings(const fsb_clock_t fsb) |
| 1151 | { |
| 1152 | const u32 timings_by_fsb[][2] = { |
| 1153 | /* FSB 1067MHz */ { 0x1a, 0x01380138 }, |
| 1154 | /* FSB 800MHz */ { 0x14, 0x00f000f0 }, |
| 1155 | /* FSB 667MHz */ { 0x10, 0x00c000c0 }, |
| 1156 | }; |
| 1157 | EPBAR8(0x2c) = timings_by_fsb[fsb][0]; |
| 1158 | EPBAR32(0x38) = timings_by_fsb[fsb][1]; |
| 1159 | EPBAR32(0x3c) = timings_by_fsb[fsb][1]; |
| 1160 | } |
| 1161 | |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1162 | #define DEFAULT_PCI_MMIO_SIZE 2048 |
| 1163 | #define HOST_BRIDGE PCI_DEVFN(0, 0) |
| 1164 | |
| 1165 | static unsigned int get_mmio_size(void) |
| 1166 | { |
| 1167 | const struct device *dev; |
| 1168 | const struct northbridge_intel_gm45_config *cfg = NULL; |
| 1169 | |
| 1170 | dev = dev_find_slot(0, HOST_BRIDGE); |
| 1171 | if (dev) |
| 1172 | cfg = dev->chip_info; |
| 1173 | |
| 1174 | /* If this is zero, it just means devicetree.cb didn't set it */ |
| 1175 | if (!cfg || cfg->pci_mmio_size == 0) |
| 1176 | return DEFAULT_PCI_MMIO_SIZE; |
| 1177 | else |
| 1178 | return cfg->pci_mmio_size; |
| 1179 | } |
| 1180 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1181 | /* @prejedec if not zero, set rank size to 128MB and page size to 4KB. */ |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1182 | static void program_memory_map(const dimminfo_t *const dimms, const channel_mode_t mode, const int prejedec, u16 ggc) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1183 | { |
| 1184 | int ch, r; |
| 1185 | |
| 1186 | /* Program rank boundaries (CxDRBy). */ |
| 1187 | unsigned int base = 0; /* start of next rank in MB */ |
| 1188 | unsigned int total_mb[2] = { 0, 0 }; /* total memory per channel in MB */ |
| 1189 | FOR_EACH_CHANNEL(ch) { |
| 1190 | if (mode == CHANNEL_MODE_DUAL_INTERLEAVED) |
| 1191 | /* In interleaved mode, start every channel from 0. */ |
| 1192 | base = 0; |
| 1193 | for (r = 0; r < RANKS_PER_CHANNEL; r += 2) { |
| 1194 | /* Fixed capacity for pre-jedec config. */ |
| 1195 | const unsigned int rank_capacity_mb = |
| 1196 | prejedec ? 128 : dimms[ch].rank_capacity_mb; |
| 1197 | u32 reg = 0; |
| 1198 | |
| 1199 | /* Program bounds in CxDRBy. */ |
| 1200 | IF_RANK_POPULATED(dimms, ch, r) { |
| 1201 | base += rank_capacity_mb; |
| 1202 | total_mb[ch] += rank_capacity_mb; |
| 1203 | } |
| 1204 | reg |= CxDRBy_BOUND_MB(r, base); |
| 1205 | IF_RANK_POPULATED(dimms, ch, r+1) { |
| 1206 | base += rank_capacity_mb; |
| 1207 | total_mb[ch] += rank_capacity_mb; |
| 1208 | } |
| 1209 | reg |= CxDRBy_BOUND_MB(r+1, base); |
| 1210 | |
| 1211 | MCHBAR32(CxDRBy_MCHBAR(ch, r)) = reg; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | /* Program page size (CxDRA). */ |
| 1216 | FOR_EACH_CHANNEL(ch) { |
| 1217 | u32 reg = MCHBAR32(CxDRA_MCHBAR(ch)) & ~CxDRA_PAGESIZE_MASK; |
| 1218 | FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) { |
| 1219 | /* Fixed page size for pre-jedec config. */ |
| 1220 | const unsigned int page_size = /* dimm page size in bytes */ |
| 1221 | prejedec ? 4096 : dimms[ch].page_size; |
| 1222 | reg |= CxDRA_PAGESIZE(r, log2(page_size)); |
| 1223 | /* deferred to f5_27: reg |= CxDRA_BANKS(r, dimms[ch].banks); */ |
| 1224 | } |
| 1225 | MCHBAR32(CxDRA_MCHBAR(ch)) = reg; |
| 1226 | } |
| 1227 | |
| 1228 | /* Calculate memory mapping, all values in MB. */ |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1229 | |
| 1230 | u32 uma_sizem = 0; |
| 1231 | if (!prejedec) { |
| 1232 | if (!(ggc & 2)) { |
| 1233 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 1234 | |
| 1235 | /* Graphics memory */ |
| 1236 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
| 1237 | printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10); |
| 1238 | |
| 1239 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 1240 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
| 1241 | printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10); |
| 1242 | |
| 1243 | uma_sizem = (gms_sizek + gsm_sizek) >> 10; |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1244 | } |
Arthur Heymans | d522db0 | 2018-08-06 15:50:54 +0200 | [diff] [blame] | 1245 | /* TSEG 2M, This amount can easily be covered by SMRR MTRR's, |
| 1246 | which requires to have TSEG_BASE aligned to TSEG_SIZE. */ |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 1247 | u8 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), D0F0_ESMRAMC); |
| 1248 | reg8 &= ~0x7; |
Arthur Heymans | d522db0 | 2018-08-06 15:50:54 +0200 | [diff] [blame] | 1249 | reg8 |= (1 << 1) | (1 << 0); /* 2M and TSEG_Enable */ |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 1250 | pci_write_config8(PCI_DEV(0, 0, 0), D0F0_ESMRAMC, reg8); |
Arthur Heymans | d522db0 | 2018-08-06 15:50:54 +0200 | [diff] [blame] | 1251 | uma_sizem += 2; |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1252 | } |
| 1253 | |
Patrick Rudolph | 266a1f7 | 2016-06-09 18:13:34 +0200 | [diff] [blame] | 1254 | const unsigned int mmio_size = get_mmio_size(); |
| 1255 | const unsigned int MMIOstart = 4096 - mmio_size + uma_sizem; |
Vladimir Serbinenko | 9907be4 | 2014-08-12 21:51:28 +0200 | [diff] [blame] | 1256 | const int me_active = pci_read_config8(PCI_DEV(0, 3, 0), PCI_CLASS_REVISION) != 0xff; |
| 1257 | const unsigned int ME_SIZE = prejedec || !me_active ? 0 : 32; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1258 | const unsigned int usedMEsize = (total_mb[0] != total_mb[1]) ? ME_SIZE : 2 * ME_SIZE; |
| 1259 | const unsigned int claimCapable = |
| 1260 | !(pci_read_config32(PCI_DEV(0, 0, 0), D0F0_CAPID0 + 4) & (1 << (47 - 32))); |
| 1261 | |
| 1262 | const unsigned int TOM = total_mb[0] + total_mb[1]; |
| 1263 | unsigned int TOMminusME = TOM - usedMEsize; |
| 1264 | unsigned int TOLUD = (TOMminusME < MMIOstart) ? TOMminusME : MMIOstart; |
| 1265 | unsigned int TOUUD = TOMminusME; |
| 1266 | unsigned int REMAPbase = 0xffff, REMAPlimit = 0; |
| 1267 | |
| 1268 | if (claimCapable && (TOMminusME >= (MMIOstart + 64))) { |
| 1269 | /* 64MB alignment: We'll lose some MBs here, if ME is on. */ |
| 1270 | TOMminusME &= ~(64 - 1); |
| 1271 | /* 64MB alignment: Loss will be reclaimed. */ |
| 1272 | TOLUD &= ~(64 - 1); |
| 1273 | if (TOMminusME > 4096) { |
| 1274 | REMAPbase = TOMminusME; |
| 1275 | REMAPlimit = REMAPbase + (4096 - TOLUD); |
| 1276 | } else { |
| 1277 | REMAPbase = 4096; |
| 1278 | REMAPlimit = REMAPbase + (TOMminusME - TOLUD); |
| 1279 | } |
| 1280 | TOUUD = REMAPlimit; |
| 1281 | /* REMAPlimit is an inclusive bound, all others exclusive. */ |
| 1282 | REMAPlimit -= 64; |
| 1283 | } |
| 1284 | |
| 1285 | pci_write_config16(PCI_DEV(0, 0, 0), D0F0_TOM, (TOM >> 7) & 0x1ff); |
| 1286 | pci_write_config16(PCI_DEV(0, 0, 0), D0F0_TOLUD, TOLUD << 4); |
| 1287 | pci_write_config16(PCI_DEV(0, 0, 0), D0F0_TOUUD, TOUUD); |
| 1288 | pci_write_config16(PCI_DEV(0, 0, 0), D0F0_REMAPBASE, (REMAPbase >> 6) & 0x03ff); |
| 1289 | pci_write_config16(PCI_DEV(0, 0, 0), D0F0_REMAPLIMIT, (REMAPlimit >> 6) & 0x03ff); |
| 1290 | |
| 1291 | /* Program channel mode. */ |
| 1292 | switch (mode) { |
| 1293 | case CHANNEL_MODE_SINGLE: |
| 1294 | printk(BIOS_DEBUG, "Memory configured in single-channel mode.\n"); |
| 1295 | MCHBAR32(DCC_MCHBAR) &= ~DCC_INTERLEAVED; |
| 1296 | break; |
| 1297 | case CHANNEL_MODE_DUAL_ASYNC: |
| 1298 | printk(BIOS_DEBUG, "Memory configured in dual-channel assymetric mode.\n"); |
| 1299 | MCHBAR32(DCC_MCHBAR) &= ~DCC_INTERLEAVED; |
| 1300 | break; |
| 1301 | case CHANNEL_MODE_DUAL_INTERLEAVED: |
| 1302 | printk(BIOS_DEBUG, "Memory configured in dual-channel interleaved mode.\n"); |
| 1303 | MCHBAR32(DCC_MCHBAR) &= ~(DCC_NO_CHANXOR | (1 << 9)); |
| 1304 | MCHBAR32(DCC_MCHBAR) |= DCC_INTERLEAVED; |
| 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | printk(BIOS_SPEW, "Memory map:\n" |
| 1309 | "TOM = %5uMB\n" |
| 1310 | "TOLUD = %5uMB\n" |
| 1311 | "TOUUD = %5uMB\n" |
| 1312 | "REMAP:\t base = %5uMB\n" |
Vladimir Serbinenko | 9907be4 | 2014-08-12 21:51:28 +0200 | [diff] [blame] | 1313 | "\t limit = %5uMB\n" |
| 1314 | "usedMEsize: %dMB\n", |
| 1315 | TOM, TOLUD, TOUUD, REMAPbase, REMAPlimit, usedMEsize); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1316 | } |
| 1317 | static void prejedec_memory_map(const dimminfo_t *const dimms, channel_mode_t mode) |
| 1318 | { |
| 1319 | /* Never use dual-interleaved mode in pre-jedec config. */ |
| 1320 | if (CHANNEL_MODE_DUAL_INTERLEAVED == mode) |
| 1321 | mode = CHANNEL_MODE_DUAL_ASYNC; |
| 1322 | |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1323 | program_memory_map(dimms, mode, 1, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1324 | MCHBAR32(DCC_MCHBAR) |= DCC_NO_CHANXOR; |
| 1325 | } |
| 1326 | |
| 1327 | static void ddr3_select_clock_mux(const mem_clock_t ddr3clock, |
| 1328 | const dimminfo_t *const dimms, |
| 1329 | const stepping_t stepping) |
| 1330 | { |
| 1331 | const int clk1067 = (ddr3clock == MEM_CLOCK_1067MT); |
| 1332 | const int cardF[] = { CHANNEL_IS_CARDF(dimms, 0), CHANNEL_IS_CARDF(dimms, 1) }; |
| 1333 | |
| 1334 | int ch; |
| 1335 | |
| 1336 | if (stepping < STEPPING_B1) |
| 1337 | die("Stepping <B1 unsupported in clock-multiplexer selection.\n"); |
| 1338 | |
| 1339 | FOR_EACH_POPULATED_CHANNEL(dimms, ch) { |
| 1340 | int mixed = 0; |
| 1341 | if ((1 == ch) && (!CHANNEL_IS_POPULATED(dimms, 0) || (cardF[0] != cardF[1]))) |
| 1342 | mixed = 4 << 11; |
| 1343 | const unsigned int b = 0x14b0 + (ch * 0x0100); |
| 1344 | MCHBAR32(b+0x1c) = (MCHBAR32(b+0x1c) & ~(7 << 11)) | |
| 1345 | ((( cardF[ch])?1:0) << 11) | mixed; |
| 1346 | MCHBAR32(b+0x18) = (MCHBAR32(b+0x18) & ~(7 << 11)) | mixed; |
| 1347 | MCHBAR32(b+0x14) = (MCHBAR32(b+0x14) & ~(7 << 11)) | |
| 1348 | (((!clk1067 && !cardF[ch])?0:1) << 11) | mixed; |
| 1349 | MCHBAR32(b+0x10) = (MCHBAR32(b+0x10) & ~(7 << 11)) | |
| 1350 | ((( clk1067 && !cardF[ch])?1:0) << 11) | mixed; |
| 1351 | MCHBAR32(b+0x0c) = (MCHBAR32(b+0x0c) & ~(7 << 11)) | |
| 1352 | ((( cardF[ch])?3:2) << 11) | mixed; |
| 1353 | MCHBAR32(b+0x08) = (MCHBAR32(b+0x08) & ~(7 << 11)) | |
| 1354 | (2 << 11) | mixed; |
| 1355 | MCHBAR32(b+0x04) = (MCHBAR32(b+0x04) & ~(7 << 11)) | |
| 1356 | (((!clk1067 && !cardF[ch])?2:3) << 11) | mixed; |
| 1357 | MCHBAR32(b+0x00) = (MCHBAR32(b+0x00) & ~(7 << 11)) | |
| 1358 | ((( clk1067 && !cardF[ch])?3:2) << 11) | mixed; |
| 1359 | } |
| 1360 | } |
| 1361 | static void ddr3_write_io_init(const mem_clock_t ddr3clock, |
| 1362 | const dimminfo_t *const dimms, |
| 1363 | const stepping_t stepping, |
| 1364 | const int sff) |
| 1365 | { |
| 1366 | const int a1step = stepping >= STEPPING_CONVERSION_A1; |
| 1367 | const int cardF[] = { CHANNEL_IS_CARDF(dimms, 0), CHANNEL_IS_CARDF(dimms, 1) }; |
| 1368 | |
| 1369 | int ch; |
| 1370 | |
| 1371 | if (stepping < STEPPING_B1) |
| 1372 | die("Stepping <B1 unsupported in write i/o initialization.\n"); |
| 1373 | if (sff) |
| 1374 | die("SFF platform unsupported in write i/o initialization.\n"); |
| 1375 | |
| 1376 | static const u32 ddr3_667_800_by_stepping_ddr3_and_card[][2][2][4] = { |
| 1377 | { /* Stepping B3 and below */ |
| 1378 | { /* 667 MHz */ |
| 1379 | { 0xa3255008, 0x26888209, 0x26288208, 0x6188040f }, |
| 1380 | { 0x7524240b, 0xa5255608, 0x232b8508, 0x5528040f }, |
| 1381 | }, |
| 1382 | { /* 800 MHz */ |
| 1383 | { 0xa6255308, 0x26888209, 0x212b7508, 0x6188040f }, |
| 1384 | { 0x7524240b, 0xa6255708, 0x132b7508, 0x5528040f }, |
| 1385 | }, |
| 1386 | }, |
| 1387 | { /* Conversion stepping A1 and above */ |
| 1388 | { /* 667 MHz */ |
| 1389 | { 0xc5257208, 0x26888209, 0x26288208, 0x6188040f }, |
| 1390 | { 0x7524240b, 0xc5257608, 0x232b8508, 0x5528040f }, |
| 1391 | }, |
| 1392 | { /* 800 MHz */ |
| 1393 | { 0xb6256308, 0x26888209, 0x212b7508, 0x6188040f }, |
| 1394 | { 0x7524240b, 0xb6256708, 0x132b7508, 0x5528040f }, |
| 1395 | } |
| 1396 | }}; |
| 1397 | |
| 1398 | static const u32 ddr3_1067_by_channel_and_card[][2][4] = { |
| 1399 | { /* Channel A */ |
| 1400 | { 0xb2254708, 0x002b7408, 0x132b8008, 0x7228060f }, |
| 1401 | { 0xb0255008, 0xa4254108, 0x4528b409, 0x9428230f }, |
| 1402 | }, |
| 1403 | { /* Channel B */ |
| 1404 | { 0xa4254208, 0x022b6108, 0x132b8208, 0x9228210f }, |
| 1405 | { 0x6024140b, 0x92244408, 0x252ba409, 0x9328360c }, |
| 1406 | }, |
| 1407 | }; |
| 1408 | |
| 1409 | FOR_EACH_POPULATED_CHANNEL(dimms, ch) { |
| 1410 | if ((1 == ch) && CHANNEL_IS_POPULATED(dimms, 0) && (cardF[0] == cardF[1])) |
| 1411 | /* Only write if second channel population differs. */ |
| 1412 | continue; |
| 1413 | const u32 *const data = (ddr3clock != MEM_CLOCK_1067MT) |
| 1414 | ? ddr3_667_800_by_stepping_ddr3_and_card[a1step][2 - ddr3clock][cardF[ch]] |
| 1415 | : ddr3_1067_by_channel_and_card[ch][cardF[ch]]; |
| 1416 | MCHBAR32(CxWRTy_MCHBAR(ch, 0)) = data[0]; |
| 1417 | MCHBAR32(CxWRTy_MCHBAR(ch, 1)) = data[1]; |
| 1418 | MCHBAR32(CxWRTy_MCHBAR(ch, 2)) = data[2]; |
| 1419 | MCHBAR32(CxWRTy_MCHBAR(ch, 3)) = data[3]; |
| 1420 | } |
| 1421 | |
| 1422 | MCHBAR32(0x1490) = 0x00e70067; |
| 1423 | MCHBAR32(0x1494) = 0x000d8000; |
| 1424 | MCHBAR32(0x1590) = 0x00e70067; |
| 1425 | MCHBAR32(0x1594) = 0x000d8000; |
| 1426 | } |
| 1427 | static void ddr3_read_io_init(const mem_clock_t ddr3clock, |
| 1428 | const dimminfo_t *const dimms, |
| 1429 | const int sff) |
| 1430 | { |
| 1431 | int ch; |
| 1432 | |
| 1433 | FOR_EACH_POPULATED_CHANNEL(dimms, ch) { |
| 1434 | u32 addr, tmp; |
| 1435 | const unsigned int base = 0x14b0 + (ch * 0x0100); |
| 1436 | for (addr = base + 0x1c; addr >= base; addr -= 4) { |
| 1437 | tmp = MCHBAR32(addr); |
| 1438 | tmp &= ~((3 << 25) | (1 << 8) | (7 << 16) | (0xf << 20) | (1 << 27)); |
| 1439 | tmp |= (1 << 27); |
| 1440 | switch (ddr3clock) { |
| 1441 | case MEM_CLOCK_667MT: |
| 1442 | tmp |= (1 << 16) | (4 << 20); |
| 1443 | break; |
| 1444 | case MEM_CLOCK_800MT: |
| 1445 | tmp |= (2 << 16) | (3 << 20); |
| 1446 | break; |
| 1447 | case MEM_CLOCK_1067MT: |
| 1448 | if (!sff) |
| 1449 | tmp |= (2 << 16) | (1 << 20); |
| 1450 | else |
| 1451 | tmp |= (2 << 16) | (2 << 20); |
| 1452 | break; |
| 1453 | default: |
| 1454 | die("Wrong clock"); |
| 1455 | } |
| 1456 | MCHBAR32(addr) = tmp; |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | static void memory_io_init(const mem_clock_t ddr3clock, |
| 1462 | const dimminfo_t *const dimms, |
| 1463 | const stepping_t stepping, |
| 1464 | const int sff) |
| 1465 | { |
| 1466 | u32 tmp; |
| 1467 | |
| 1468 | if (stepping < STEPPING_B1) |
| 1469 | die("Stepping <B1 unsupported in " |
| 1470 | "system-memory i/o initialization.\n"); |
| 1471 | |
| 1472 | tmp = MCHBAR32(0x1400); |
| 1473 | tmp &= ~(3<<13); |
| 1474 | tmp |= (1<<9) | (1<<13); |
| 1475 | MCHBAR32(0x1400) = tmp; |
| 1476 | |
| 1477 | tmp = MCHBAR32(0x140c); |
| 1478 | tmp &= ~(0xff | (1<<11) | (1<<12) | |
| 1479 | (1<<16) | (1<<18) | (1<<27) | (0xf<<28)); |
| 1480 | tmp |= (1<<7) | (1<<11) | (1<<16); |
| 1481 | switch (ddr3clock) { |
| 1482 | case MEM_CLOCK_667MT: |
| 1483 | tmp |= 9 << 28; |
| 1484 | break; |
| 1485 | case MEM_CLOCK_800MT: |
| 1486 | tmp |= 7 << 28; |
| 1487 | break; |
| 1488 | case MEM_CLOCK_1067MT: |
| 1489 | tmp |= 8 << 28; |
| 1490 | break; |
| 1491 | } |
| 1492 | MCHBAR32(0x140c) = tmp; |
| 1493 | |
| 1494 | MCHBAR32(0x1440) &= ~1; |
| 1495 | |
| 1496 | tmp = MCHBAR32(0x1414); |
| 1497 | tmp &= ~((1<<20) | (7<<11) | (0xf << 24) | (0xf << 16)); |
| 1498 | tmp |= (3<<11); |
| 1499 | switch (ddr3clock) { |
| 1500 | case MEM_CLOCK_667MT: |
| 1501 | tmp |= (2 << 24) | (10 << 16); |
| 1502 | break; |
| 1503 | case MEM_CLOCK_800MT: |
| 1504 | tmp |= (3 << 24) | (7 << 16); |
| 1505 | break; |
| 1506 | case MEM_CLOCK_1067MT: |
| 1507 | tmp |= (4 << 24) | (4 << 16); |
| 1508 | break; |
| 1509 | } |
| 1510 | MCHBAR32(0x1414) = tmp; |
| 1511 | |
| 1512 | MCHBAR32(0x1418) &= ~((1<<3) | (1<<11) | (1<<19) | (1<<27)); |
| 1513 | |
| 1514 | MCHBAR32(0x141c) &= ~((1<<3) | (1<<11) | (1<<19) | (1<<27)); |
| 1515 | |
| 1516 | MCHBAR32(0x1428) |= 1<<14; |
| 1517 | |
| 1518 | tmp = MCHBAR32(0x142c); |
| 1519 | tmp &= ~((0xf << 8) | (0x7 << 20) | 0xf | (0xf << 24)); |
| 1520 | tmp |= (0x3 << 20) | (5 << 24); |
| 1521 | switch (ddr3clock) { |
| 1522 | case MEM_CLOCK_667MT: |
| 1523 | tmp |= (2 << 8) | 0xc; |
| 1524 | break; |
| 1525 | case MEM_CLOCK_800MT: |
| 1526 | tmp |= (3 << 8) | 0xa; |
| 1527 | break; |
| 1528 | case MEM_CLOCK_1067MT: |
| 1529 | tmp |= (4 << 8) | 0x7; |
| 1530 | break; |
| 1531 | } |
| 1532 | MCHBAR32(0x142c) = tmp; |
| 1533 | |
| 1534 | tmp = MCHBAR32(0x400); |
| 1535 | tmp &= ~((3 << 4) | (3 << 16) | (3 << 30)); |
| 1536 | tmp |= (2 << 4) | (2 << 16); |
| 1537 | MCHBAR32(0x400) = tmp; |
| 1538 | |
| 1539 | MCHBAR32(0x404) &= ~(0xf << 20); |
| 1540 | |
| 1541 | MCHBAR32(0x40c) &= ~(1 << 6); |
| 1542 | |
| 1543 | tmp = MCHBAR32(0x410); |
| 1544 | tmp &= ~(7 << 28); |
| 1545 | tmp |= 2 << 28; |
| 1546 | MCHBAR32(0x410) = tmp; |
| 1547 | |
| 1548 | tmp = MCHBAR32(0x41c); |
| 1549 | tmp &= ~0x77; |
| 1550 | tmp |= 0x11; |
| 1551 | MCHBAR32(0x41c) = tmp; |
| 1552 | |
| 1553 | ddr3_select_clock_mux(ddr3clock, dimms, stepping); |
| 1554 | |
| 1555 | ddr3_write_io_init(ddr3clock, dimms, stepping, sff); |
| 1556 | |
| 1557 | ddr3_read_io_init(ddr3clock, dimms, sff); |
| 1558 | } |
| 1559 | |
| 1560 | static void jedec_init(const timings_t *const timings, |
| 1561 | const dimminfo_t *const dimms) |
| 1562 | { |
| 1563 | if ((timings->tWR < 5) || (timings->tWR > 12)) |
| 1564 | die("tWR value unsupported in Jedec initialization.\n"); |
| 1565 | |
| 1566 | /* Pre-jedec settings */ |
| 1567 | MCHBAR32(0x40) |= (1 << 1); |
| 1568 | MCHBAR32(0x230) |= (3 << 1); |
| 1569 | MCHBAR32(0x238) |= (3 << 24); |
| 1570 | MCHBAR32(0x23c) |= (3 << 24); |
| 1571 | |
| 1572 | /* Normal write pointer operation */ |
| 1573 | MCHBAR32(0x14f0) |= (1 << 9); |
| 1574 | MCHBAR32(0x15f0) |= (1 << 9); |
| 1575 | |
| 1576 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_CMD_MASK) | DCC_CMD_NOP; |
| 1577 | |
| 1578 | u8 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 1579 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 & ~(1 << 2)); |
| 1580 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 1581 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 | (1 << 2)); |
| 1582 | udelay(2); |
| 1583 | |
| 1584 | /* 5 6 7 8 9 10 11 12 */ |
| 1585 | static const u8 wr_lut[] = { 1, 2, 3, 4, 5, 5, 6, 6 }; |
| 1586 | |
| 1587 | const int WL = ((timings->tWL - 5) & 7) << 6; |
| 1588 | const int ODT_120OHMS = (1 << 9); |
| 1589 | const int ODS_34OHMS = (1 << 4); |
| 1590 | const int WR = (wr_lut[timings->tWR - 5] & 7) << 12; |
| 1591 | const int DLL1 = 1 << 11; |
| 1592 | const int CAS = ((timings->CAS - 4) & 7) << 7; |
| 1593 | const int INTERLEAVED = 1 << 6;/* This is READ Burst Type == interleaved. */ |
| 1594 | |
| 1595 | int ch, r; |
| 1596 | FOR_EACH_POPULATED_RANK(dimms, ch, r) { |
| 1597 | /* We won't do this in dual-interleaved mode, |
| 1598 | so don't care about the offset. */ |
| 1599 | const u32 rankaddr = raminit_get_rank_addr(ch, r); |
Nico Huber | 0624f92 | 2017-04-15 15:57:28 +0200 | [diff] [blame] | 1600 | printk(BIOS_DEBUG, "JEDEC init @0x%08x\n", rankaddr); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1601 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_SET_EREG_MASK) | DCC_SET_EREGx(2); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1602 | read32((u32 *)(rankaddr | WL)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1603 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_SET_EREG_MASK) | DCC_SET_EREGx(3); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1604 | read32((u32 *)rankaddr); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1605 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_SET_EREG_MASK) | DCC_SET_EREGx(1); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1606 | read32((u32 *)(rankaddr | ODT_120OHMS | ODS_34OHMS)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1607 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_CMD_MASK) | DCC_SET_MREG; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1608 | read32((u32 *)(rankaddr | WR | DLL1 | CAS | INTERLEAVED)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1609 | MCHBAR32(DCC_MCHBAR) = (MCHBAR32(DCC_MCHBAR) & ~DCC_CMD_MASK) | DCC_SET_MREG; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1610 | read32((u32 *)(rankaddr | WR | CAS | INTERLEAVED)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | static void ddr3_calibrate_zq(void) { |
| 1615 | udelay(2); |
| 1616 | |
| 1617 | u32 tmp = MCHBAR32(DCC_MCHBAR); |
| 1618 | tmp &= ~(7 << 16); |
| 1619 | tmp |= (5 << 16); /* ZQ calibration mode */ |
| 1620 | MCHBAR32(DCC_MCHBAR) = tmp; |
| 1621 | |
| 1622 | MCHBAR32(CxDRT6_MCHBAR(0)) |= (1 << 3); |
| 1623 | MCHBAR32(CxDRT6_MCHBAR(1)) |= (1 << 3); |
| 1624 | |
| 1625 | udelay(1); |
| 1626 | |
| 1627 | MCHBAR32(CxDRT6_MCHBAR(0)) &= ~(1 << 3); |
| 1628 | MCHBAR32(CxDRT6_MCHBAR(1)) &= ~(1 << 3); |
| 1629 | |
| 1630 | MCHBAR32(DCC_MCHBAR) |= (7 << 16); /* Normal operation */ |
| 1631 | } |
| 1632 | |
| 1633 | static void post_jedec_sequence(const int cores) { |
| 1634 | const int quadcore = cores == 4; |
| 1635 | |
| 1636 | MCHBAR32(0x0040) &= ~(1 << 1); |
| 1637 | MCHBAR32(0x0230) &= ~(3 << 1); |
| 1638 | MCHBAR32(0x0230) |= 1 << 15; |
| 1639 | MCHBAR32(0x0230) &= ~(1 << 19); |
| 1640 | MCHBAR32(0x1250) = 0x6c4; |
| 1641 | MCHBAR32(0x1350) = 0x6c4; |
| 1642 | MCHBAR32(0x1254) = 0x871a066d; |
| 1643 | MCHBAR32(0x1354) = 0x871a066d; |
| 1644 | MCHBAR32(0x0238) |= 1 << 26; |
| 1645 | MCHBAR32(0x0238) &= ~(3 << 24); |
| 1646 | MCHBAR32(0x0238) |= 1 << 23; |
| 1647 | MCHBAR32(0x0238) = (MCHBAR32(0x238) & ~(7 << 20)) | (3 << 20); |
| 1648 | MCHBAR32(0x0238) = (MCHBAR32(0x238) & ~(7 << 17)) | (6 << 17); |
| 1649 | MCHBAR32(0x0238) = (MCHBAR32(0x238) & ~(7 << 14)) | (6 << 14); |
| 1650 | MCHBAR32(0x0238) = (MCHBAR32(0x238) & ~(7 << 11)) | (6 << 11); |
| 1651 | MCHBAR32(0x0238) = (MCHBAR32(0x238) & ~(7 << 8)) | (6 << 8); |
| 1652 | MCHBAR32(0x023c) &= ~(3 << 24); |
| 1653 | MCHBAR32(0x023c) &= ~(1 << 23); |
| 1654 | MCHBAR32(0x023c) = (MCHBAR32(0x23c) & ~(7 << 20)) | (3 << 20); |
| 1655 | MCHBAR32(0x023c) = (MCHBAR32(0x23c) & ~(7 << 17)) | (6 << 17); |
| 1656 | MCHBAR32(0x023c) = (MCHBAR32(0x23c) & ~(7 << 14)) | (6 << 14); |
| 1657 | MCHBAR32(0x023c) = (MCHBAR32(0x23c) & ~(7 << 11)) | (6 << 11); |
| 1658 | MCHBAR32(0x023c) = (MCHBAR32(0x23c) & ~(7 << 8)) | (6 << 8); |
| 1659 | |
| 1660 | if (quadcore) { |
| 1661 | MCHBAR32(0xb14) |= (0xbfbf << 16); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | static void dram_optimizations(const timings_t *const timings, |
| 1666 | const dimminfo_t *const dimms) |
| 1667 | { |
| 1668 | int ch; |
| 1669 | |
| 1670 | FOR_EACH_POPULATED_CHANNEL(dimms, ch) { |
| 1671 | const unsigned int mchbar = CxDRC1_MCHBAR(ch); |
| 1672 | u32 cxdrc1 = MCHBAR32(mchbar); |
| 1673 | cxdrc1 &= ~CxDRC1_SSDS_MASK; |
| 1674 | if (dimms[ch].ranks == 1) |
| 1675 | cxdrc1 |= CxDRC1_SS; |
| 1676 | else |
| 1677 | cxdrc1 |= CxDRC1_DS; |
| 1678 | MCHBAR32(mchbar) = cxdrc1; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | u32 raminit_get_rank_addr(unsigned int channel, unsigned int rank) |
| 1683 | { |
| 1684 | if (!channel && !rank) |
| 1685 | return 0; /* Address of first rank */ |
| 1686 | |
| 1687 | /* Read the bound of the previous rank. */ |
| 1688 | if (rank > 0) { |
| 1689 | rank--; |
| 1690 | } else { |
| 1691 | rank = 3; /* Highest rank per channel */ |
| 1692 | channel--; |
| 1693 | } |
| 1694 | const u32 reg = MCHBAR32(CxDRBy_MCHBAR(channel, rank)); |
| 1695 | /* Bound is in 32MB. */ |
| 1696 | return ((reg & CxDRBy_BOUND_MASK(rank)) >> CxDRBy_BOUND_SHIFT(rank)) << 25; |
| 1697 | } |
| 1698 | |
| 1699 | void raminit_reset_readwrite_pointers(void) { |
| 1700 | MCHBAR32(0x1234) |= (1 << 6); |
| 1701 | MCHBAR32(0x1234) &= ~(1 << 6); |
| 1702 | MCHBAR32(0x1334) |= (1 << 6); |
| 1703 | MCHBAR32(0x1334) &= ~(1 << 6); |
| 1704 | MCHBAR32(0x14f0) &= ~(1 << 9); |
| 1705 | MCHBAR32(0x14f0) |= (1 << 9); |
| 1706 | MCHBAR32(0x14f0) |= (1 << 10); |
| 1707 | MCHBAR32(0x15f0) &= ~(1 << 9); |
| 1708 | MCHBAR32(0x15f0) |= (1 << 9); |
| 1709 | MCHBAR32(0x15f0) |= (1 << 10); |
| 1710 | } |
| 1711 | |
| 1712 | void raminit(sysinfo_t *const sysinfo, const int s3resume) |
| 1713 | { |
| 1714 | const dimminfo_t *const dimms = sysinfo->dimms; |
| 1715 | const timings_t *const timings = &sysinfo->selected_timings; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1716 | |
| 1717 | int ch; |
| 1718 | u8 reg8; |
| 1719 | |
Arthur Heymans | 049347f | 2017-05-12 11:54:08 +0200 | [diff] [blame] | 1720 | timestamp_add_now(TS_BEFORE_INITRAM); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1721 | |
| 1722 | /* Wait for some bit, maybe TXT clear. */ |
| 1723 | if (sysinfo->txt_enabled) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 1724 | while (!(read8((u8 *)0xfed40000) & (1 << 7))) {} |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | /* Enable SMBUS. */ |
| 1728 | enable_smbus(); |
| 1729 | |
| 1730 | /* Collect information about DIMMs and find common settings. */ |
| 1731 | collect_dimm_config(sysinfo); |
| 1732 | |
| 1733 | /* Check for bad warm boot. */ |
| 1734 | reset_on_bad_warmboot(); |
| 1735 | |
| 1736 | |
| 1737 | /***** From now on, program according to collected infos: *****/ |
| 1738 | |
| 1739 | /* Program DRAM type. */ |
| 1740 | switch (sysinfo->spd_type) { |
| 1741 | case DDR2: |
| 1742 | MCHBAR8(0x1434) |= (1 << 7); |
| 1743 | break; |
| 1744 | case DDR3: |
| 1745 | MCHBAR8(0x1434) |= (3 << 0); |
| 1746 | break; |
| 1747 | } |
| 1748 | |
| 1749 | /* Program system memory frequency. */ |
| 1750 | set_system_memory_frequency(timings); |
| 1751 | /* Program IGD memory frequency. */ |
| 1752 | set_igd_memory_frequencies(sysinfo); |
| 1753 | |
| 1754 | /* Configure DRAM control mode for populated channels. */ |
| 1755 | configure_dram_control_mode(timings, dimms); |
| 1756 | |
| 1757 | /* Initialize RCOMP. */ |
Nico Huber | 5aaeb27 | 2015-12-30 00:17:27 +0100 | [diff] [blame] | 1758 | rcomp_initialization(sysinfo->stepping, sysinfo->sff); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1759 | |
| 1760 | /* Power-up DRAM. */ |
| 1761 | dram_powerup(s3resume); |
| 1762 | /* Program DRAM timings. */ |
| 1763 | dram_program_timings(timings); |
| 1764 | /* Program number of banks. */ |
| 1765 | dram_program_banks(dimms); |
| 1766 | /* Enable DRAM clock pairs for populated DIMMs. */ |
| 1767 | FOR_EACH_POPULATED_CHANNEL(dimms, ch) |
| 1768 | MCHBAR32(CxDCLKDIS_MCHBAR(ch)) |= CxDCLKDIS_ENABLE; |
| 1769 | |
| 1770 | /* Enable On-Die Termination. */ |
Nico Huber | 5aaeb27 | 2015-12-30 00:17:27 +0100 | [diff] [blame] | 1771 | odt_setup(timings, sysinfo->sff); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1772 | /* Miscellaneous settings. */ |
| 1773 | misc_settings(timings, sysinfo->stepping); |
| 1774 | /* Program clock crossing registers. */ |
| 1775 | clock_crossing_setup(timings->fsb_clock, timings->mem_clock, dimms); |
| 1776 | /* Program egress VC1 timings. */ |
| 1777 | vc1_program_timings(timings->fsb_clock); |
| 1778 | /* Perform system-memory i/o initialization. */ |
Nico Huber | 5aaeb27 | 2015-12-30 00:17:27 +0100 | [diff] [blame] | 1779 | memory_io_init(timings->mem_clock, dimms, |
| 1780 | sysinfo->stepping, sysinfo->sff); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1781 | |
| 1782 | /* Initialize memory map with dummy values of 128MB per rank with a |
| 1783 | page size of 4KB. This makes the JEDEC initialization code easier. */ |
| 1784 | prejedec_memory_map(dimms, timings->channel_mode); |
| 1785 | if (!s3resume) |
| 1786 | /* Perform JEDEC initialization of DIMMS. */ |
| 1787 | jedec_init(timings, dimms); |
| 1788 | /* Some programming steps after JEDEC initialization. */ |
| 1789 | post_jedec_sequence(sysinfo->cores); |
| 1790 | |
| 1791 | /* Announce normal operation, initialization completed. */ |
| 1792 | MCHBAR32(DCC_MCHBAR) |= (0x7 << 16) | (0x1 << 19); |
| 1793 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 1794 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 | (1 << 2)); |
| 1795 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 1796 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 & ~(1 << 2)); |
| 1797 | |
| 1798 | |
| 1799 | /* Take a breath (the reader). */ |
| 1800 | |
| 1801 | |
| 1802 | /* Perform ZQ calibration for DDR3. */ |
| 1803 | ddr3_calibrate_zq(); |
| 1804 | |
| 1805 | /* Perform receive-enable calibration. */ |
| 1806 | raminit_receive_enable_calibration(timings, dimms); |
| 1807 | /* Lend clock values from receive-enable calibration. */ |
Jonathan Neuschäfer | 2f828eb | 2018-02-12 12:00:44 +0100 | [diff] [blame] | 1808 | MCHBAR32(CxDRT5_MCHBAR(0)) = |
| 1809 | (MCHBAR32(CxDRT5_MCHBAR(0)) & ~(0xf0)) | |
| 1810 | ((((MCHBAR32(CxDRT3_MCHBAR(0)) >> 7) - 1) & 0xf) << 4); |
| 1811 | MCHBAR32(CxDRT5_MCHBAR(1)) = |
| 1812 | (MCHBAR32(CxDRT5_MCHBAR(1)) & ~(0xf0)) | |
| 1813 | ((((MCHBAR32(CxDRT3_MCHBAR(1)) >> 7) - 1) & 0xf) << 4); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1814 | |
| 1815 | /* Perform read/write training for high clock rate. */ |
| 1816 | if (timings->mem_clock == MEM_CLOCK_1067MT) { |
| 1817 | raminit_read_training(dimms, s3resume); |
| 1818 | raminit_write_training(timings->mem_clock, dimms, s3resume); |
| 1819 | } |
| 1820 | |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1821 | igd_compute_ggc(sysinfo); |
| 1822 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1823 | /* Program final memory map (with real values). */ |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1824 | program_memory_map(dimms, timings->channel_mode, 0, sysinfo->ggc); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1825 | |
| 1826 | /* Some last optimizations. */ |
| 1827 | dram_optimizations(timings, dimms); |
| 1828 | |
Elyes HAOUAS | 3d45000 | 2018-08-09 18:55:58 +0200 | [diff] [blame] | 1829 | /* Mark raminit being finished. :-) */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1830 | u8 tmp8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa2) & ~(1 << 7); |
| 1831 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, tmp8); |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 1832 | |
| 1833 | raminit_thermal(sysinfo); |
| 1834 | init_igd(sysinfo); |
Arthur Heymans | 049347f | 2017-05-12 11:54:08 +0200 | [diff] [blame] | 1835 | |
| 1836 | timestamp_add_now(TS_AFTER_INITRAM); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1837 | } |