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