blob: 7464a722fa31b649e923832d3edd859aa7b7b620 [file] [log] [blame]
Martin Roth5474eb12018-05-26 19:22:33 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * converted to C 6/2004 yhlu
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Stefan Reinauerb15975b2011-10-21 12:57:59 -070016/* This was originally for the e7500, modified for e7501
17 * The primary differences are that 7501 apparently can
18 * support single channel RAM (i haven't tested),
19 * CAS1.5 is no longer supported, The ECC scrubber
20 * now supports a mode to zero RAM and init ECC in one step
21 * and the undocumented registers at 0x80 require new
22 * (undocumented) values determined by guesswork and
23 * comparison w/ OEM BIOS values.
24 * Steven James 02/06/2003
25 */
26
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030027#include <stdint.h>
28#include <device/pci_def.h>
29#include <arch/io.h>
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030030#include <arch/cpu.h>
Alexandru Gagniucaf4bd592014-01-12 15:42:58 -060031#include <lib.h>
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030032#include <stdlib.h>
Kyösti Mälkki717b6e32018-05-17 14:16:03 +030033#include <commonlib/helpers.h>
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030034#include <console/console.h>
Kyösti Mälkki97c064f2012-04-18 20:33:35 +030035#include <cpu/x86/mtrr.h>
36#include <cpu/x86/cache.h>
37#include <cpu/x86/msr.h>
Stefan Reinauerb15975b2011-10-21 12:57:59 -070038#include <assert.h>
39#include <spd.h>
40#include <sdram_mode.h>
Kyösti Mälkkidcb688e2013-09-04 01:11:16 +030041#include <cbmem.h>
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030042
43#include "raminit.h"
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020044#include "e7505.h"
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030045#include "debug.h"
Stefan Reinauerb15975b2011-10-21 12:57:59 -070046
47/*-----------------------------------------------------------------------------
48Definitions:
49-----------------------------------------------------------------------------*/
50
51// Uncomment this to enable run-time checking of DIMM parameters
52// for dual-channel operation
53// Unfortunately the code seems to chew up several K of space.
54//#define VALIDATE_DIMM_COMPATIBILITY
55
Martin Roth33232602017-06-24 14:48:50 -060056#if IS_ENABLED(CONFIG_DEBUG_RAM_SETUP)
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080057#define RAM_DEBUG_MESSAGE(x) printk(BIOS_DEBUG, x)
58#define RAM_DEBUG_HEX32(x) printk(BIOS_DEBUG, "%08x", x)
59#define RAM_DEBUG_HEX8(x) printk(BIOS_DEBUG, "%02x", x)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +030060#define DUMPNORTH() dump_pci_device(MCHDEV)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070061#else
62#define RAM_DEBUG_MESSAGE(x)
63#define RAM_DEBUG_HEX32(x)
64#define RAM_DEBUG_HEX8(x)
65#define DUMPNORTH()
66#endif
67
68#define E7501_SDRAM_MODE (SDRAM_BURST_INTERLEAVED | SDRAM_BURST_4)
69#define SPD_ERROR "Error reading SPD info\n"
70
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +030071#define MCHDEV PCI_DEV(0,0,0)
72#define RASDEV PCI_DEV(0,0,1)
73#define D060DEV PCI_DEV(0,6,0)
74
Stefan Reinauerb15975b2011-10-21 12:57:59 -070075// NOTE: This used to be 0x100000.
76// That doesn't work on systems where A20M# is asserted, because
77// attempts to access 0x1000NN end up accessing 0x0000NN.
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080078#define RCOMP_MMIO ((u8 *)0x200000)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070079
80struct dimm_size {
81 unsigned long side1;
82 unsigned long side2;
83};
84
85static const uint32_t refresh_frequency[] = {
86 /* Relative frequency (array value) of each E7501 Refresh Mode Select
87 * (RMS) value (array index)
88 * 0 == least frequent refresh (longest interval between refreshes)
89 * [0] disabled -> 0
90 * [1] 15.6 usec -> 2
91 * [2] 7.8 usec -> 3
92 * [3] 64 usec -> 1
93 * [4] reserved -> 0
94 * [5] reserved -> 0
95 * [6] reserved -> 0
96 * [7] 64 clocks -> 4
97 */
98 0, 2, 3, 1, 0, 0, 0, 4
99};
100
101static const uint32_t refresh_rate_map[] = {
102 /* Map the JEDEC spd refresh rates (array index) to E7501 Refresh Mode
103 * Select values (array value)
104 * These are all the rates defined by JESD21-C Appendix D, Rev. 1.0
105 * The E7501 supports only 15.6 us (1), 7.8 us (2), 64 us (3), and
106 * 64 clock (481 ns) (7) refresh.
107 * [0] == 15.625 us -> 15.6 us
108 * [1] == 3.9 us -> 481 ns
109 * [2] == 7.8 us -> 7.8 us
110 * [3] == 31.3 us -> 15.6 us
111 * [4] == 62.5 us -> 15.6 us
112 * [5] == 125 us -> 64 us
113 */
114 1, 7, 2, 1, 1, 3
115};
116
117#define MAX_SPD_REFRESH_RATE ((sizeof(refresh_rate_map) / sizeof(uint32_t)) - 1)
118
Edward O'Callaghan08280cb2014-05-25 06:33:29 +1000119#ifdef VALIDATE_DIMM_COMPATIBILITY
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700120// SPD parameters that must match for dual-channel operation
121static const uint8_t dual_channel_parameters[] = {
122 SPD_MEMORY_TYPE,
123 SPD_MODULE_VOLTAGE,
124 SPD_NUM_COLUMNS,
125 SPD_NUM_ROWS,
126 SPD_NUM_DIMM_BANKS,
127 SPD_PRIMARY_SDRAM_WIDTH,
128 SPD_NUM_BANKS_PER_SDRAM
129};
Edward O'Callaghan08280cb2014-05-25 06:33:29 +1000130#endif /* VALIDATE_DIMM_COMPATIBILITY */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700131
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300132 /* Comments here are remains of e7501 or even 855PM.
133 * They might be partially (in)correct for e7505.
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700134 */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700135
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300136 /* (DRAM Read Timing Control, if similar to 855PM?)
137 * 0x80 - 0x81 documented differently for e7505
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700138 * This register has something to do with CAS latencies,
Martin Roth128c1042016-11-18 09:29:03 -0700139 * possibly this is the real chipset control.
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700140 * At 0x00 CAS latency 1.5 works.
141 * At 0x06 CAS latency 2.5 works.
142 * At 0x01 CAS latency 2.0 works.
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300143 *
144 * This is still undocumented in e7501, but with different values
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700145 * CAS 2.0 values taken from Intel BIOS settings, others are a guess
146 * and may be terribly wrong. Old values preserved as comments until I
147 * figure this out for sure.
148 * e7501 docs claim that CAS1.5 is unsupported, so it may or may not
149 * work at all.
150 * Steven James 02/06/2003
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300151 *
152 * NOTE: values now configured in configure_e7501_cas_latency() based
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700153 * on SPD info and total number of DIMMs (per Intel)
154 */
155
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300156 /* FDHC - Fixed DRAM Hole Control ???
157 * 0x58 undocumented for e7505, memory hole in southbridge configuration?
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700158 * [7:7] Hole_Enable
159 * 0 == No memory Hole
160 * 1 == Memory Hole from 15MB to 16MB
161 * [6:0] Reserved
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700162 */
163
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700164 /* Another Intel undocumented register
165 * 0x88 - 0x8B
166 * [31:31] Purpose unknown
167 * [26:26] Master DLL Reset?
168 * 0 == Normal operation?
169 * 1 == Reset?
170 * [07:07] Periodic memory recalibration?
171 * 0 == Disabled?
172 * 1 == Enabled?
173 * [04:04] Receive FIFO RE-Sync?
174 * 0 == Normal operation?
175 * 1 == Reset?
176 */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700177
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300178/* DDR RECOMP tables */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700179// Slew table for 2x drive?
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300180static const uint32_t slew_2x[] = {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700181 0x00000000, 0x76543210, 0xffffeca8, 0xffffffff,
182 0x21000000, 0xa8765432, 0xffffffec, 0xffffffff,
183};
184
185// Pull Up / Pull Down offset table, if analogous to IXP2800?
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300186static const uint32_t pull_updown_offset_table[] = {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700187 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
188 0x88888888, 0x88888888, 0x88888888, 0x88888888,
189};
190
191/*-----------------------------------------------------------------------------
192Delay functions:
193-----------------------------------------------------------------------------*/
194
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300195/* Estimate that SLOW_DOWN_IO takes about 1 us */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700196#define SLOW_DOWN_IO inb(0x80)
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300197static void local_udelay(int i)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700198{
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300199 while (i--) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700200 SLOW_DOWN_IO;
201 }
202}
203
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300204/* delay for 200us */
205#define DO_DELAY local_udelay(200)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700206#define EXTRA_DELAY DO_DELAY
207
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200208/*-----------------------------------------------------------------------------
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300209Handle (undocumented) control bits MCHTST and PCI_DEV(0,6,0)
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200210-----------------------------------------------------------------------------*/
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300211typedef enum {
212 MCHTST_CMD_0,
213 D060_ENABLE,
214 D060_DISABLE,
215 RCOMP_BAR_ENABLE,
216 RCOMP_BAR_DISABLE,
217} mchtst_cc;
218
219typedef enum {
220 D060_CMD_0,
221 D060_CMD_1,
222} d060_cc;
223
224typedef enum {
225 RCOMP_HOLD,
226 RCOMP_RELEASE,
227 RCOMP_SMR_00,
228 RCOMP_SMR_01,
229} rcomp_smr_cc;
230
231/**
232 * MCHTST - 0xF4 - 0xF7 -- Based on similarity to 855PM
233 *
234 * [31:31] Purpose unknown
235 * [30:30] Purpose unknown
236 * [29:23] Unknown - not used?
237 * [22:22] System Memory MMR Enable
238 * 0 == Disable: mem space and BAR at 0x14 are not accessible
239 * 1 == Enable: mem space and BAR at 0x14 are accessible
240 * [21:20] Purpose unknown
241 * [19:02] Unknown - not used?
242 * [01:01] D6EN (Device #6 enable)
243 * 0 == Disable
244 * 1 == Enable
245 * [00:00] Unknown - not used?
246 */
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300247static void mchtest_control(mchtst_cc cmd)
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300248{
249 uint32_t dword = pci_read_config32(MCHDEV, MCHTST);
250 switch (cmd) {
251 case MCHTST_CMD_0:
252 dword &= ~(3 << 30);
253 break;
254 case RCOMP_BAR_ENABLE:
255 dword |= (1 << 22);
256 break;
257 case RCOMP_BAR_DISABLE:
258 dword &= ~(1 << 22);
259 break;
260 case D060_ENABLE:
261 dword |= (1 << 1);
262 break;
263 case D060_DISABLE:
264 dword &= ~(1 << 1);
265 break;
266 };
267 pci_write_config32(MCHDEV, MCHTST, dword);
268}
269
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200270
271/**
272 *
273 */
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300274static void d060_control(d060_cc cmd)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700275{
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300276 mchtest_control(D060_ENABLE);
277 uint32_t dword = pci_read_config32(D060DEV, 0xf0);
278 switch (cmd) {
279 case D060_CMD_0:
280 dword |= (1 << 2);
281 break;
282 case D060_CMD_1:
283 dword |= (3 << 27);
284 break;
285 }
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300286 pci_write_config32(D060DEV, 0xf0, dword);
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300287 mchtest_control(D060_DISABLE);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200288}
289
290/**
291 *
292 */
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300293static void rcomp_smr_control(rcomp_smr_cc cmd)
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200294{
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300295 uint32_t dword = read32(RCOMP_MMIO + SMRCTL);
296 switch (cmd) {
297 case RCOMP_HOLD:
298 dword |= (1 << 9);
299 break;
300 case RCOMP_RELEASE:
301 dword &= ~((1 << 9) | (3 << 0));
302 dword |= (1 << 10) | (1 << 0);
303 break;
304 case RCOMP_SMR_00:
305 dword &= ~(1 << 8);
306 break;
307 case RCOMP_SMR_01:
308 dword |= (1 << 10) | (1 << 8);
309 break;
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200310 }
Kyösti Mälkki26c7b862012-04-12 22:46:23 +0300311 write32(RCOMP_MMIO + SMRCTL, dword);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700312}
313
314/*-----------------------------------------------------------------------------
315Serial presence detect (SPD) functions:
316-----------------------------------------------------------------------------*/
317
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200318static void die_on_spd_error(int spd_return_value)
319{
320 if (spd_return_value < 0)
321 die("Error reading SPD info\n");
322}
323
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700324/**
325 * Calculate the page size for each physical bank of the DIMM:
326 * log2(page size) = (# columns) + log2(data width)
327 *
328 * NOTE: Page size is the total number of data bits in a row.
329 *
330 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
331 * @return log2(page size) for each side of the DIMM.
332 */
333static struct dimm_size sdram_spd_get_page_size(uint16_t dimm_socket_address)
334{
335 uint16_t module_data_width;
336 int value;
337 struct dimm_size pgsz;
338
339 pgsz.side1 = 0;
340 pgsz.side2 = 0;
341
342 // Side 1
343 value = spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS);
344 if (value < 0)
345 goto hw_err;
346 pgsz.side1 = value & 0xf; // # columns in bank 1
347
348 /* Get the module data width and convert it to a power of two */
349 value =
350 spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_MSB);
351 if (value < 0)
352 goto hw_err;
353 module_data_width = (value & 0xff) << 8;
354
355 value =
356 spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_LSB);
357 if (value < 0)
358 goto hw_err;
359 module_data_width |= (value & 0xff);
360
361 pgsz.side1 += log2(module_data_width);
362
363 /* side two */
364 value = spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS);
365 if (value < 0)
366 goto hw_err;
367 if (value > 2)
368 die("Bad SPD value\n");
369 if (value == 2) {
370
371 pgsz.side2 = pgsz.side1; // Assume symmetric banks until we know differently
372 value =
373 spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS);
374 if (value < 0)
375 goto hw_err;
376 if ((value & 0xf0) != 0) {
377 // Asymmetric banks
378 pgsz.side2 -= value & 0xf; /* Subtract out columns on side 1 */
379 pgsz.side2 += (value >> 4) & 0xf; /* Add in columns on side 2 */
380 }
381 }
382
383 return pgsz;
384
385 hw_err:
386 die(SPD_ERROR);
387 return pgsz; // Never reached
388}
389
390/**
391 * Read the width in bits of each DIMM side's DRAMs via SPD (i.e. 4, 8, 16).
392 *
393 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
394 * @return Width in bits of each DIMM side's DRAMs.
395 */
396static struct dimm_size sdram_spd_get_width(uint16_t dimm_socket_address)
397{
398 int value;
399 struct dimm_size width;
400
401 width.side1 = 0;
402 width.side2 = 0;
403
404 value =
405 spd_read_byte(dimm_socket_address, SPD_PRIMARY_SDRAM_WIDTH);
406 die_on_spd_error(value);
407
408 width.side1 = value & 0x7f; // Mask off bank 2 flag
409
410 if (value & 0x80) {
411 width.side2 = width.side1 << 1; // Bank 2 exists and is double-width
412 } else {
413 // If bank 2 exists, it's the same width as bank 1
414 value =
415 spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS);
416 die_on_spd_error(value);
417
418#ifdef ROMCC_IF_BUG_FIXED
419 if (value == 2)
420 width.side2 = width.side1;
421#else
422 switch (value) {
423 case 2:
424 width.side2 = width.side1;
425 break;
426
427 default:
428 break;
429 }
430#endif
431 }
432
433 return width;
434}
435
436/**
437 * Calculate the log base 2 size in bits of both DIMM sides.
438 *
439 * log2(# bits) = (# columns) + log2(data width) +
440 * (# rows) + log2(banks per SDRAM)
441 *
442 * Note that it might be easier to use SPD byte 31 here, it has the DIMM size
443 * as a multiple of 4MB. The way we do it now we can size both sides of an
444 * asymmetric DIMM.
445 *
446 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
447 * @return log2(number of bits) for each side of the DIMM.
448 */
449static struct dimm_size spd_get_dimm_size(unsigned dimm_socket_address)
450{
451 int value;
452
453 // Start with log2(page size)
454 struct dimm_size sz = sdram_spd_get_page_size(dimm_socket_address);
455
456 if (sz.side1 > 0) {
457
458 value = spd_read_byte(dimm_socket_address, SPD_NUM_ROWS);
459 die_on_spd_error(value);
460
461 sz.side1 += value & 0xf;
462
463 if (sz.side2 > 0) {
464
465 // Double-sided DIMM
466 if (value & 0xF0)
467 sz.side2 += value >> 4; // Asymmetric
468 else
469 sz.side2 += value; // Symmetric
470 }
471
472 value =
473 spd_read_byte(dimm_socket_address,
474 SPD_NUM_BANKS_PER_SDRAM);
475 die_on_spd_error(value);
476
477 value = log2(value);
478 sz.side1 += value;
479 if (sz.side2 > 0)
480 sz.side2 += value;
481 }
482
483 return sz;
484}
485
486#ifdef VALIDATE_DIMM_COMPATIBILITY
487
488/**
489 * Determine whether two DIMMs have the same value for an SPD parameter.
490 *
491 * @param spd_byte_number The SPD byte number to compare in both DIMMs.
492 * @param dimm0_address SMBus address of the 1st DIMM socket to interrogate.
493 * @param dimm1_address SMBus address of the 2nd DIMM socket to interrogate.
494 * @return 1 if both DIMM sockets report the same value for the specified
495 * SPD parameter, 0 if the values differed or an error occurred.
496 */
497static uint8_t are_spd_values_equal(uint8_t spd_byte_number,
498 uint16_t dimm0_address,
499 uint16_t dimm1_address)
500{
501 uint8_t bEqual = 0;
502 int dimm0_value = spd_read_byte(dimm0_address, spd_byte_number);
503 int dimm1_value = spd_read_byte(dimm1_address, spd_byte_number);
504
505 if ((dimm0_value >= 0) && (dimm1_value >= 0)
506 && (dimm0_value == dimm1_value))
507 bEqual = 1;
508
509 return bEqual;
510}
511#endif
512
513/**
514 * Scan for compatible DIMMs.
515 *
516 * The code in this module only supports dual-channel operation, so we test
517 * that compatible DIMMs are paired.
518 *
519 * @param ctrl PCI addresses of memory controller functions, and SMBus
520 * addresses of DIMM slots on the mainboard.
521 * @return A bitmask indicating which of the possible sockets for each channel
522 * was found to contain a compatible DIMM.
523 * Bit 0 corresponds to the closest socket for channel 0
524 * Bit 1 to the next socket for channel 0
525 * ...
526 * Bit MAX_DIMM_SOCKETS_PER_CHANNEL-1 to the last socket for channel 0
527 * Bit MAX_DIMM_SOCKETS_PER_CHANNEL is the closest socket for channel 1
528 * ...
529 * Bit 2*MAX_DIMM_SOCKETS_PER_CHANNEL-1 is the last socket for channel 1
530 */
531static uint8_t spd_get_supported_dimms(const struct mem_controller *ctrl)
532{
533 int i;
534 uint8_t dimm_mask = 0;
535
536 // Have to increase size of dimm_mask if this assertion is violated
537 ASSERT(MAX_DIMM_SOCKETS_PER_CHANNEL <= 4);
538
539 // Find DIMMs we can support on channel 0.
540 // Then see if the corresponding channel 1 DIMM has the same parameters,
541 // since we only support dual-channel.
542
543 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
544
545 uint16_t channel0_dimm = ctrl->channel0[i];
546 uint16_t channel1_dimm = ctrl->channel1[i];
547 uint8_t bDualChannel = 1;
548#ifdef VALIDATE_DIMM_COMPATIBILITY
549 struct dimm_size page_size;
550 struct dimm_size sdram_width;
551#endif
552 int spd_value;
553
554 if (channel0_dimm == 0)
555 continue; // No such socket on this mainboard
556
557 if (spd_read_byte(channel0_dimm, SPD_MEMORY_TYPE) !=
558 SPD_MEMORY_TYPE_SDRAM_DDR)
559 continue;
560
561#ifdef VALIDATE_DIMM_COMPATIBILITY
562 if (spd_read_byte(channel0_dimm, SPD_MODULE_VOLTAGE) !=
563 SPD_VOLTAGE_SSTL2)
564 continue; // Unsupported voltage
565
566 // E7501 does not support unregistered DIMMs
567 spd_value =
568 spd_read_byte(channel0_dimm, SPD_MODULE_ATTRIBUTES);
569 if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0))
570 continue;
571
572 // Must support burst = 4 for dual-channel operation on E7501
573 // NOTE: for single-channel, burst = 8 is required
574 spd_value =
575 spd_read_byte(channel0_dimm,
576 SPD_SUPPORTED_BURST_LENGTHS);
577 if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0))
578 continue;
579
580 page_size = sdram_spd_get_page_size(channel0_dimm);
581 sdram_width = sdram_spd_get_width(channel0_dimm);
582
583 // Validate DIMM page size
584 // The E7501 only supports page sizes of 4, 8, 16, or 32 KB per channel
585 // NOTE: 4 KB = 32 Kb = 2^15
586 // 32 KB = 262 Kb = 2^18
587
588 if ((page_size.side1 < 15) || (page_size.side1 > 18))
589 continue;
590
591 // If DIMM is double-sided, verify side2 page size
592 if (page_size.side2 != 0) {
593 if ((page_size.side2 < 15)
594 || (page_size.side2 > 18))
595 continue;
596 }
597 // Validate SDRAM width
598 // The E7501 only supports x4 and x8 devices
599
600 if ((sdram_width.side1 != 4) && (sdram_width.side1 != 8))
601 continue;
602
603 // If DIMM is double-sided, verify side2 width
604 if (sdram_width.side2 != 0) {
605 if ((sdram_width.side2 != 4)
606 && (sdram_width.side2 != 8))
607 continue;
608 }
609#endif
610 // Channel 0 DIMM looks compatible.
611 // Now see if it is paired with the proper DIMM on channel 1.
612
613 ASSERT(channel1_dimm != 0); // No such socket on this mainboard??
614
615 // NOTE: unpopulated DIMMs cause read to fail
616 spd_value =
617 spd_read_byte(channel1_dimm, SPD_MODULE_ATTRIBUTES);
618 if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) {
619
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800620 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700621 continue;
622 }
623#ifdef VALIDATE_DIMM_COMPATIBILITY
624 spd_value =
625 spd_read_byte(channel1_dimm,
626 SPD_SUPPORTED_BURST_LENGTHS);
627 if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0))
628 continue;
629
630 int j;
631 for (j = 0; j < sizeof(dual_channel_parameters); ++j) {
632 if (!are_spd_values_equal
633 (dual_channel_parameters[j], channel0_dimm,
634 channel1_dimm)) {
635
636 bDualChannel = 0;
637 break;
638 }
639 }
Edward O'Callaghan08280cb2014-05-25 06:33:29 +1000640#endif /* VALIDATE_DIMM_COMPATIBILITY */
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700641
642 // Code around ROMCC bug in optimization of "if" statements
643#ifdef ROMCC_IF_BUG_FIXED
644 if (bDualChannel) {
645 // Made it through all the checks, this DIMM pair is usable
646 dimm_mask |= ((1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i)));
647 } else
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800648 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700649#else
650 switch (bDualChannel) {
651 case 0:
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800652 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700653 break;
654
655 default:
656 // Made it through all the checks, this DIMM pair is usable
657 dimm_mask |= (1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i));
658 break;
659 }
660#endif
661 }
662
663 return dimm_mask;
664}
665
666/*-----------------------------------------------------------------------------
667SDRAM configuration functions:
668-----------------------------------------------------------------------------*/
669
670/**
671 * Send the specified command to all DIMMs.
672 *
673 * @param command Specifies the command to be sent to the DIMMs.
674 * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the
675 * register value in JEDEC format.
676 */
677static void do_ram_command(uint8_t command, uint16_t jedec_mode_bits)
678{
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200679 uint8_t dimm_start_64M_multiple;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800680 uintptr_t dimm_start_address;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700681 uint32_t dram_controller_mode;
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200682 uint8_t i;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700683
684 // Configure the RAM command
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300685 dram_controller_mode = pci_read_config32(MCHDEV, DRC);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700686 dram_controller_mode &= 0xFFFFFF8F;
687 dram_controller_mode |= command;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300688 pci_write_config32(MCHDEV, DRC, dram_controller_mode);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700689
690 // RAM_COMMAND_NORMAL is an exception.
691 // It affects only the memory controller and does not need to be "sent" to the DIMMs.
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300692 if (command == RAM_COMMAND_NORMAL) {
693 EXTRA_DELAY;
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200694 return;
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300695 }
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700696
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200697 // NOTE: for mode select commands, some of the location address bits are part of the command
698 // Map JEDEC mode bits to E7505
699 if (command == RAM_COMMAND_MRS) {
700 // Host address lines [25:18] map to DIMM address lines [7:0]
701 // Host address lines [17:16] map to DIMM address lines [9:8]
702 // Host address lines [15:4] map to DIMM address lines [11:0]
703 dimm_start_address = (jedec_mode_bits & 0x00ff) << 18;
704 dimm_start_address |= (jedec_mode_bits & 0x0300) << 8;
705 dimm_start_address |= (jedec_mode_bits & 0x0fff) << 4;
706 } else if (command == RAM_COMMAND_EMRS) {
707 // Host address lines [15:4] map to DIMM address lines [11:0]
708 dimm_start_address = (jedec_mode_bits << 4);
709 } else {
710 ASSERT(jedec_mode_bits == 0);
711 dimm_start_address = 0;
712 }
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700713
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200714 // Send the command to all DIMMs by accessing a memory location within each
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700715
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200716 dimm_start_64M_multiple = 0;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700717
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300718 /* FIXME: Only address the number of rows present in the system?
719 * Seems like rows 4-7 overlap with 0-3.
720 */
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200721 for (i = 0; i < (MAX_NUM_CHANNELS * MAX_DIMM_SOCKETS_PER_CHANNEL); ++i) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700722
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300723 uint8_t dimm_end_64M_multiple = pci_read_config8(MCHDEV, DRB_ROW_0 + i);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700724
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200725 if (dimm_end_64M_multiple > dimm_start_64M_multiple) {
726 dimm_start_address &= 0x3ffffff;
727 dimm_start_address |= dimm_start_64M_multiple << 26;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800728 read32((void *)dimm_start_address);
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +0300729 // Set the start of the next DIMM
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200730 dimm_start_64M_multiple = dimm_end_64M_multiple;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700731 }
732 }
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +0300733 EXTRA_DELAY;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700734}
735
736/**
737 * Set the mode register of all DIMMs.
738 *
739 * The proper CAS# latency setting is added to the mode bits specified
740 * by the caller.
741 *
742 * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the
743 * register value in JEDEC format.
744 */
745static void set_ram_mode(uint16_t jedec_mode_bits)
746{
747 ASSERT(!(jedec_mode_bits & SDRAM_CAS_MASK));
748
749 uint32_t dram_cas_latency =
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300750 pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700751
752 switch (dram_cas_latency) {
753 case DRT_CAS_2_5:
754 jedec_mode_bits |= SDRAM_CAS_2_5;
755 break;
756
757 case DRT_CAS_2_0:
758 jedec_mode_bits |= SDRAM_CAS_2_0;
759 break;
760
761 default:
762 BUG();
763 break;
764 }
765
766 do_ram_command(RAM_COMMAND_MRS, jedec_mode_bits);
767}
768
769/*-----------------------------------------------------------------------------
Martin Roth128c1042016-11-18 09:29:03 -0700770DIMM-independent configuration functions:
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700771-----------------------------------------------------------------------------*/
772
773/**
774 * Configure the E7501's DRAM Row Boundary (DRB) registers for the memory
775 * present in the specified DIMM.
776 *
777 * @param dimm_log2_num_bits Specifies log2(number of bits) for each side of
778 * the DIMM.
779 * @param total_dram_64M_multiple Total DRAM in the system (as a multiple of
780 * 64 MB) for DIMMs < dimm_index.
781 * @param dimm_index Which DIMM pair is being processed
782 * (0..MAX_DIMM_SOCKETS_PER_CHANNEL).
783 * @return New multiple of 64 MB total DRAM in the system.
784 */
785static uint8_t configure_dimm_row_boundaries(struct dimm_size dimm_log2_num_bits, uint8_t total_dram_64M_multiple, unsigned dimm_index)
786{
787 int i;
788
789 ASSERT(dimm_index < MAX_DIMM_SOCKETS_PER_CHANNEL);
790
791 // DIMM sides must be at least 32 MB
792 ASSERT(dimm_log2_num_bits.side1 >= 28);
793 ASSERT((dimm_log2_num_bits.side2 == 0)
794 || (dimm_log2_num_bits.side2 >= 28));
795
796 // In dual-channel mode, we are called only once for each pair of DIMMs.
797 // Each time we process twice the capacity of a single DIMM.
798
799 // Convert single DIMM capacity to paired DIMM capacity
800 // (multiply by two ==> add 1 to log2)
801 dimm_log2_num_bits.side1++;
802 if (dimm_log2_num_bits.side2 > 0)
803 dimm_log2_num_bits.side2++;
804
805 // Add the capacity of side 1 this DIMM pair (as a multiple of 64 MB)
806 // to the total capacity of the system
807 // NOTE: 64 MB == 512 Mb, and log2(512 Mb) == 29
808
809 total_dram_64M_multiple += (1 << (dimm_log2_num_bits.side1 - 29));
810
811 // Configure the boundary address for the row on side 1
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300812 pci_write_config8(MCHDEV, DRB_ROW_0 + (dimm_index << 1),
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700813 total_dram_64M_multiple);
814
815 // If the DIMMs are double-sided, add the capacity of side 2 this DIMM pair
816 // (as a multiple of 64 MB) to the total capacity of the system
817 if (dimm_log2_num_bits.side2 >= 29)
818 total_dram_64M_multiple +=
819 (1 << (dimm_log2_num_bits.side2 - 29));
820
821 // Configure the boundary address for the row (if any) on side 2
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300822 pci_write_config8(MCHDEV, DRB_ROW_1 + (dimm_index << 1),
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700823 total_dram_64M_multiple);
824
825 // Update boundaries for rows subsequent to these.
826 // These settings will be overridden by a subsequent call if a populated physical slot exists
827
828 for (i = dimm_index + 1; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300829 pci_write_config8(MCHDEV, DRB_ROW_0 + (i << 1),
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700830 total_dram_64M_multiple);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300831 pci_write_config8(MCHDEV, DRB_ROW_1 + (i << 1),
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700832 total_dram_64M_multiple);
833 }
834
835 return total_dram_64M_multiple;
836}
837
838/**
839 * Set the E7501's DRAM row boundary addresses & its Top Of Low Memory (TOLM).
840 *
841 * If necessary, set up a remap window so we don't waste DRAM that ordinarily
842 * would lie behind addresses reserved for memory-mapped I/O.
843 *
844 * @param ctrl PCI addresses of memory controller functions, and SMBus
845 * addresses of DIMM slots on the mainboard.
846 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
847 */
848static void configure_e7501_ram_addresses(const struct mem_controller
849 *ctrl, uint8_t dimm_mask)
850{
851 int i;
852 uint8_t total_dram_64M_multiple = 0;
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300853 uint64_t tolm, tom;
854 uint16_t reg;
855
856 /* Start with disabled remap range. */
857 uint16_t remapbase_r = 0x3ff;
858 uint16_t remaplimit_r = 0;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700859
860 // Configure the E7501's DRAM row boundaries
861 // Start by zeroing out the temporary initial configuration
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +0300862 pci_write_config32(MCHDEV, DRB_ROW_0, 0);
863 pci_write_config32(MCHDEV, DRB_ROW_4, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700864
865 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
866
867 uint16_t dimm_socket_address = ctrl->channel0[i];
868 struct dimm_size sz;
869
870 if (!(dimm_mask & (1 << i)))
871 continue; // This DIMM not present
872
873 sz = spd_get_dimm_size(dimm_socket_address);
874
875 RAM_DEBUG_MESSAGE("dimm size =");
876 RAM_DEBUG_HEX32((u32)sz.side1);
877 RAM_DEBUG_MESSAGE(" ");
878 RAM_DEBUG_HEX32((u32)sz.side2);
879 RAM_DEBUG_MESSAGE("\n");
880
881 if (sz.side1 == 0)
882 die("Bad SPD value\n");
883
884 total_dram_64M_multiple =
885 configure_dimm_row_boundaries(sz, total_dram_64M_multiple, i);
886 }
887
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300888 tom = total_dram_64M_multiple * 64ULL * MiB;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700889
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300890 /* Reserve MMIO space. */
891 tolm = 4ULL * GiB - 1 * GiB;
892 tolm = MIN(tolm, tom);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700893
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300894 /* The PCI memory hole overlaps memory setup the remap window. */
895 if (tolm < tom) {
896 uint64_t remapbase = MAX(tom, 4ULL * GiB);
897 uint64_t remaplimit = remapbase + (4ULL * GiB - tolm);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700898
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300899 remapbase_r = remapbase / (64 * MiB);
900 remaplimit_r = remaplimit / (64 * MiB);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700901
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300902 /* Limit register is inclusive. */
903 remaplimit_r -= 1;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700904 }
Kyösti Mälkki717b6e32018-05-17 14:16:03 +0300905
906 /* Write the RAM configuration registers,
907 preserving the reserved bits. */
908 reg = pci_read_config16(MCHDEV, TOLM) & 0x7ff;
909 reg |= (tolm / (128 * MiB)) << 11;
910 pci_write_config16(MCHDEV, TOLM, reg);
911
912 reg = pci_read_config16(MCHDEV, REMAPBASE) & 0xfc00;
913 reg |= remapbase_r;
914 pci_write_config16(MCHDEV, REMAPBASE, reg);
915
916 reg = pci_read_config16(MCHDEV, REMAPLIMIT) & 0xfc00;
917 reg |= remaplimit_r;
918 pci_write_config16(MCHDEV, REMAPLIMIT, reg);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700919}
920
921/**
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300922 * Execute ECC full-speed scrub once and leave scrubber disabled.
923 *
924 * NOTE: All cache and stack is lost during ECC scrub loop.
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700925 */
Stefan Reinauer1e0ddf62012-11-02 17:26:33 +0100926static inline void __attribute__((always_inline))
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300927 initialize_ecc(unsigned long ret_addr, unsigned long ret_addr2)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700928{
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300929 uint16_t scrubbed = pci_read_config16(MCHDEV, MCHCFGNS) & 0x08;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700930
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300931 if (!scrubbed) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700932 RAM_DEBUG_MESSAGE("Initializing ECC state...\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700933
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300934 /* ECC scrub flushes cache-lines and stack, need to
935 * store return address from romstage.c:main().
936 */
937 asm volatile(
938 "movd %0, %%xmm0;"
939 "movd (%0), %%xmm1;"
940 "movd %1, %%xmm2;"
941 "movd (%1), %%xmm3;"
942 :: "r" (ret_addr), "r" (ret_addr2) :
943 );
944
945 /* NOTE: All cache is lost during this loop.
946 * Make sure PCI access does not use stack.
947 */
948
949 pci_write_config16(MCHDEV, MCHCFGNS, 0x01);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700950 do {
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300951 scrubbed = pci_read_config16(MCHDEV, MCHCFGNS);
952 } while (! (scrubbed & 0x08));
953 pci_write_config16(MCHDEV, MCHCFGNS, (scrubbed & ~0x07) | 0x04);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700954
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300955 /* Some problem remains with XIP cache from ROM, so for
956 * now, I disable XIP and also invalidate cache (again)
957 * before the remaining small portion of romstage.
958 *
959 * Adding NOPs here has unexpected results, making
960 * the first do_printk()/vtxprintf() after ECC scrub
961 * fail midway. Sometimes vtxprintf() dumps strings
962 * completely but with every 4th (fourth) character as "/".
963 *
964 * An inlined dump to console of the same string,
965 * before vtxprintf() call, is successful. So the
966 * source string should be completely in cache already.
967 *
968 * I need to review this again with CPU microcode
969 * update applied pre-CAR.
970 */
971
972 /* Disable and invalidate all cache. */
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700973 msr_t xip_mtrr = rdmsr(MTRR_PHYS_MASK(1));
974 xip_mtrr.lo &= ~MTRR_PHYS_MASK_VALID;
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300975 invd();
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700976 wrmsr(MTRR_PHYS_MASK(1), xip_mtrr);
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300977 invd();
978
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700979 RAM_DEBUG_MESSAGE("ECC state initialized.\n");
980
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300981 /* Recover IP for return from main. */
982 asm volatile(
983 "movd %%xmm0, %%edi;"
984 "movd %%xmm1, (%%edi);"
985 "movd %%xmm2, %%edi;"
986 "movd %%xmm3, (%%edi);"
987 ::: "edi"
988 );
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700989
Martin Roth33232602017-06-24 14:48:50 -0600990#if IS_ENABLED(CONFIG_DEBUG_RAM_SETUP)
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300991 unsigned int a1, a2;
992 asm volatile("movd %%xmm2, %%eax;" : "=a" (a1) ::);
993 asm volatile("movd %%xmm3, %%eax;" : "=a" (a2) ::);
Martin Roth0cd338e2016-07-29 14:07:30 -0600994 printk(BIOS_DEBUG, "return EIP @ %x = %x\n", a1, a2);
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300995 asm volatile("movd %%xmm0, %%eax;" : "=a" (a1) ::);
996 asm volatile("movd %%xmm1, %%eax;" : "=a" (a2) ::);
Martin Roth0cd338e2016-07-29 14:07:30 -0600997 printk(BIOS_DEBUG, "return EIP @ %x = %x\n", a1, a2);
Kyösti Mälkki97c064f2012-04-18 20:33:35 +0300998#endif
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700999 }
1000
Kyösti Mälkki97c064f2012-04-18 20:33:35 +03001001 /* Clear the ECC error bits. */
1002 pci_write_config8(RASDEV, DRAM_FERR, 0x03);
1003 pci_write_config8(RASDEV, DRAM_NERR, 0x03);
1004
1005 /* Clear DRAM Interface error bits. */
1006 pci_write_config32(RASDEV, FERR_GLOBAL, 1 << 18);
1007 pci_write_config32(RASDEV, NERR_GLOBAL, 1 << 18);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001008}
1009
1010/**
1011 * Program the DRAM Timing register (DRT) of the E7501 (except for CAS#
1012 * latency, which is assumed to have been programmed already), based on the
1013 * parameters of the various installed DIMMs.
1014 *
1015 * @param ctrl PCI addresses of memory controller functions, and SMBus
1016 * addresses of DIMM slots on the mainboard.
1017 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
1018 */
1019static void configure_e7501_dram_timing(const struct mem_controller *ctrl,
1020 uint8_t dimm_mask)
1021{
1022 int i;
1023 uint32_t dram_timing;
1024 int value;
1025 uint8_t slowest_row_precharge = 0;
1026 uint8_t slowest_ras_cas_delay = 0;
1027 uint8_t slowest_active_to_precharge_delay = 0;
1028 uint32_t current_cas_latency =
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001029 pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001030
1031 // CAS# latency must be programmed beforehand
1032 ASSERT((current_cas_latency == DRT_CAS_2_0)
1033 || (current_cas_latency == DRT_CAS_2_5));
1034
1035 // Each timing parameter is determined by the slowest DIMM
1036
1037 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
1038 uint16_t dimm_socket_address;
1039
1040 if (!(dimm_mask & (1 << i)))
1041 continue; // This DIMM not present
1042
1043 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1044 dimm_socket_address = ctrl->channel0[i];
1045 else
1046 dimm_socket_address =
1047 ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL];
1048
1049 value =
1050 spd_read_byte(dimm_socket_address,
1051 SPD_MIN_ROW_PRECHARGE_TIME);
1052 if (value < 0)
1053 goto hw_err;
1054 if (value > slowest_row_precharge)
1055 slowest_row_precharge = value;
1056
1057 value =
1058 spd_read_byte(dimm_socket_address,
1059 SPD_MIN_RAS_TO_CAS_DELAY);
1060 if (value < 0)
1061 goto hw_err;
1062 if (value > slowest_ras_cas_delay)
1063 slowest_ras_cas_delay = value;
1064
1065 value =
1066 spd_read_byte(dimm_socket_address,
1067 SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
1068 if (value < 0)
1069 goto hw_err;
1070 if (value > slowest_active_to_precharge_delay)
1071 slowest_active_to_precharge_delay = value;
1072 }
1073
1074 // NOTE for timing parameters:
1075 // At 133 MHz, 1 clock == 7.52 ns
1076
1077 /* Read the initial state */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001078 dram_timing = pci_read_config32(MCHDEV, DRT);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001079
1080 /* Trp */
1081
1082 // E7501 supports only 2 or 3 clocks for tRP
1083 if (slowest_row_precharge > ((22 << 2) | (2 << 0)))
1084 die("unsupported DIMM tRP"); // > 22.5 ns: 4 or more clocks
1085 else if (slowest_row_precharge > (15 << 2))
1086 dram_timing &= ~(1 << 0); // > 15.0 ns: 3 clocks
1087 else
1088 dram_timing |= (1 << 0); // <= 15.0 ns: 2 clocks
1089
1090 /* Trcd */
1091
1092 // E7501 supports only 2 or 3 clocks for tRCD
1093 // Use the same value for both read & write
1094 dram_timing &= ~((1 << 3) | (3 << 1));
1095 if (slowest_ras_cas_delay > ((22 << 2) | (2 << 0)))
1096 die("unsupported DIMM tRCD"); // > 22.5 ns: 4 or more clocks
1097 else if (slowest_ras_cas_delay > (15 << 2))
1098 dram_timing |= (2 << 1); // > 15.0 ns: 3 clocks
1099 else
1100 dram_timing |= ((1 << 3) | (3 << 1)); // <= 15.0 ns: 2 clocks
1101
1102 /* Tras */
1103
1104 // E7501 supports only 5, 6, or 7 clocks for tRAS
1105 // 5 clocks ~= 37.6 ns, 6 clocks ~= 45.1 ns, 7 clocks ~= 52.6 ns
1106 dram_timing &= ~(3 << 9);
1107
1108 if (slowest_active_to_precharge_delay > 52)
1109 die("unsupported DIMM tRAS"); // > 52 ns: 8 or more clocks
1110 else if (slowest_active_to_precharge_delay > 45)
1111 dram_timing |= (0 << 9); // 46-52 ns: 7 clocks
1112 else if (slowest_active_to_precharge_delay > 37)
1113 dram_timing |= (1 << 9); // 38-45 ns: 6 clocks
1114 else
1115 dram_timing |= (2 << 9); // < 38 ns: 5 clocks
1116
1117 /* Trd */
1118
Elyes HAOUAS0f92f632014-07-27 19:37:31 +02001119 /* Set to a 7 clock read delay. This is for 133MHz
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001120 * with a CAS latency of 2.5 if 2.0 a 6 clock
1121 * delay is good */
1122
1123 dram_timing &= ~(7 << 24); // 7 clocks
1124 if (current_cas_latency == DRT_CAS_2_0)
1125 dram_timing |= (1 << 24); // 6 clocks
1126
1127 /*
1128 * Back to Back Read-Write Turn Around
1129 */
1130 /* Set to a 5 clock back to back read to write turn around.
1131 * 4 is a good delay if the CAS latency is 2.0 */
1132
1133 dram_timing &= ~(1 << 28); // 5 clocks
1134 if (current_cas_latency == DRT_CAS_2_0)
1135 dram_timing |= (1 << 28); // 4 clocks
1136
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001137 pci_write_config32(MCHDEV, DRT, dram_timing);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001138
1139 return;
1140
1141 hw_err:
1142 die(SPD_ERROR);
1143}
1144
1145/**
1146 * Determine the shortest CAS# latency that the E7501 and all DIMMs have in
1147 * common, and program the E7501 to use it.
1148 *
1149 * @param ctrl PCI addresses of memory controller functions, and SMBus
1150 * addresses of DIMM slots on the mainboard.
1151 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1152 */
1153static void configure_e7501_cas_latency(const struct mem_controller *ctrl,
1154 uint8_t dimm_mask)
1155{
1156 int i;
1157 int value;
1158 uint32_t dram_timing;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001159 uint16_t dram_read_timing;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001160 uint32_t dword;
1161
1162 // CAS# latency bitmasks in SPD_ACCEPTABLE_CAS_LATENCIES format
1163 // NOTE: E7501 supports only 2.0 and 2.5
1164 uint32_t system_compatible_cas_latencies =
1165 SPD_CAS_LATENCY_2_0 | SPD_CAS_LATENCY_2_5;
1166 uint32_t current_cas_latency;
1167 uint32_t dimm_compatible_cas_latencies;
1168
1169 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
1170
1171 uint16_t dimm_socket_address;
1172
1173 if (!(dimm_mask & (1 << i)))
1174 continue; // This DIMM not usable
1175
1176 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1177 dimm_socket_address = ctrl->channel0[i];
1178 else
1179 dimm_socket_address =
1180 ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL];
1181
1182 value =
1183 spd_read_byte(dimm_socket_address,
1184 SPD_ACCEPTABLE_CAS_LATENCIES);
1185 if (value < 0)
1186 goto hw_err;
1187
1188 dimm_compatible_cas_latencies = value & 0x7f; // Start with all supported by DIMM
1189 current_cas_latency = 1 << log2(dimm_compatible_cas_latencies); // Max supported by DIMM
1190
1191 // Can we support the highest CAS# latency?
1192
1193 value =
1194 spd_read_byte(dimm_socket_address,
1195 SPD_MIN_CYCLE_TIME_AT_CAS_MAX);
1196 if (value < 0)
1197 goto hw_err;
1198
1199 // NOTE: At 133 MHz, 1 clock == 7.52 ns
1200 if (value > 0x75) {
1201 // Our bus is too fast for this CAS# latency
1202 // Remove it from the bitmask of those supported by the DIMM that are compatible
1203 dimm_compatible_cas_latencies &= ~current_cas_latency;
1204 }
1205 // Can we support the next-highest CAS# latency (max - 0.5)?
1206
1207 current_cas_latency >>= 1;
1208 if (current_cas_latency != 0) {
1209 value =
1210 spd_read_byte(dimm_socket_address,
1211 SPD_SDRAM_CYCLE_TIME_2ND);
1212 if (value < 0)
1213 goto hw_err;
1214 if (value > 0x75)
1215 dimm_compatible_cas_latencies &=
1216 ~current_cas_latency;
1217 }
1218 // Can we support the next-highest CAS# latency (max - 1.0)?
1219 current_cas_latency >>= 1;
1220 if (current_cas_latency != 0) {
1221 value =
1222 spd_read_byte(dimm_socket_address,
1223 SPD_SDRAM_CYCLE_TIME_3RD);
1224 if (value < 0)
1225 goto hw_err;
1226 if (value > 0x75)
1227 dimm_compatible_cas_latencies &=
1228 ~current_cas_latency;
1229 }
1230 // Restrict the system to CAS# latencies compatible with this DIMM
1231 system_compatible_cas_latencies &=
1232 dimm_compatible_cas_latencies;
1233
1234 /* go to the next DIMM */
1235 }
1236
1237 /* After all of the arduous calculation setup with the fastest
1238 * cas latency I can use.
1239 */
1240
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001241 dram_timing = pci_read_config32(MCHDEV, DRT);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001242 dram_timing &= ~(DRT_CAS_MASK);
1243
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001244 dram_read_timing =
1245 pci_read_config16(MCHDEV, DRDCTL);
1246 dram_read_timing &= 0xF000;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001247
1248 if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_0) {
1249 dram_timing |= DRT_CAS_2_0;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001250 dram_read_timing |= 0x0222;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001251 } else if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_5) {
1252
1253 uint32_t dram_row_attributes =
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001254 pci_read_config32(MCHDEV, DRA);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001255
1256 dram_timing |= DRT_CAS_2_5;
1257
1258 // At CAS# 2.5, DRAM Read Timing (if that's what it its) appears to need a slightly
1259 // different value if all DIMM slots are populated
1260
1261 if ((dram_row_attributes & 0xff)
1262 && (dram_row_attributes & 0xff00)
1263 && (dram_row_attributes & 0xff0000)
1264 && (dram_row_attributes & 0xff000000)) {
1265
1266 // All slots populated
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001267 dram_read_timing |= 0x0882;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001268 } else {
1269 // Some unpopulated slots
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001270 dram_read_timing |= 0x0662;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001271 }
1272 } else
1273 die("No CAS# latencies compatible with all DIMMs!!\n");
1274
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001275 pci_write_config32(MCHDEV, DRT, dram_timing);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001276
1277 /* set master DLL reset */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001278 dword = pci_read_config32(MCHDEV, 0x88);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001279 dword |= (1 << 26);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001280 pci_write_config32(MCHDEV, 0x88, dword);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001281 /* patch try register 88 is undocumented tnz */
1282 dword &= 0x0ca17fff;
1283 dword |= 0xd14a5000;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001284 pci_write_config32(MCHDEV, 0x88, dword);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001285
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001286 pci_write_config16(MCHDEV, DRDCTL,
1287 dram_read_timing);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001288
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001289 /* clear master DLL reset */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001290 dword = pci_read_config32(MCHDEV, 0x88);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001291 dword &= ~(1 << 26);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001292 pci_write_config32(MCHDEV, 0x88, dword);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001293
1294 return;
1295
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001296hw_err:
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001297 die(SPD_ERROR);
1298}
1299
1300/**
1301 * Configure the refresh interval so that we refresh no more often than
1302 * required by the "most needy" DIMM. Also disable ECC if any of the DIMMs
1303 * don't support it.
1304 *
1305 * @param ctrl PCI addresses of memory controller functions, and SMBus
1306 * addresses of DIMM slots on the mainboard.
1307 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1308 */
1309static void configure_e7501_dram_controller_mode(const struct
1310 mem_controller *ctrl,
1311 uint8_t dimm_mask)
1312{
1313 int i;
1314
1315 // Initial settings
1316 uint32_t controller_mode =
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001317 pci_read_config32(MCHDEV, DRC);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001318 uint32_t system_refresh_mode = (controller_mode >> 8) & 7;
1319
1320 // Code below assumes that most aggressive settings are in
1321 // force when we are called, either via E7501 reset defaults
1322 // or by sdram_set_registers():
1323 // - ECC enabled
1324 // - No refresh
1325
1326 ASSERT((controller_mode & (3 << 20)) == (2 << 20)); // ECC
1327 ASSERT(!(controller_mode & (7 << 8))); // Refresh
1328
1329 /* Walk through _all_ dimms and find the least-common denominator for:
1330 * - ECC support
1331 * - refresh rates
1332 */
1333
1334 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
1335
1336 uint32_t dimm_refresh_mode;
1337 int value;
1338 uint16_t dimm_socket_address;
1339
1340 if (!(dimm_mask & (1 << i))) {
1341 continue; // This DIMM not usable
1342 }
1343
1344 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1345 dimm_socket_address = ctrl->channel0[i];
1346 else
1347 dimm_socket_address =
1348 ctrl->channel1[i -
1349 MAX_DIMM_SOCKETS_PER_CHANNEL];
1350
1351 // Disable ECC mode if any one of the DIMMs does not support ECC
1352 // SJM: Should we just die here? E7501 datasheet says non-ECC DIMMs aren't supported.
1353
1354 value =
1355 spd_read_byte(dimm_socket_address,
1356 SPD_DIMM_CONFIG_TYPE);
1357 die_on_spd_error(value);
1358 if (value != ERROR_SCHEME_ECC) {
1359 controller_mode &= ~(3 << 20);
1360 }
1361
1362 value = spd_read_byte(dimm_socket_address, SPD_REFRESH);
1363 die_on_spd_error(value);
1364 value &= 0x7f; // Mask off self-refresh bit
1365 if (value > MAX_SPD_REFRESH_RATE) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08001366 printk(BIOS_ERR, "unsupported refresh rate\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001367 continue;
1368 }
1369 // Get the appropriate E7501 refresh mode for this DIMM
1370 dimm_refresh_mode = refresh_rate_map[value];
1371 if (dimm_refresh_mode > 7) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08001372 printk(BIOS_ERR, "unsupported refresh rate\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001373 continue;
1374 }
1375 // If this DIMM requires more frequent refresh than others,
1376 // update the system setting
1377 if (refresh_frequency[dimm_refresh_mode] >
1378 refresh_frequency[system_refresh_mode])
1379 system_refresh_mode = dimm_refresh_mode;
1380
1381#ifdef SUSPICIOUS_LOOKING_CODE
1382// SJM NOTE: This code doesn't look right. SPD values are an order of magnitude smaller
1383// than the clock period of the memory controller. Also, no other northbridge
1384// looks at SPD_CMD_SIGNAL_INPUT_HOLD_TIME.
1385
1386 // Switch to 2 clocks for address/command if required by any one of the DIMMs
1387 // NOTE: At 133 MHz, 1 clock == 7.52 ns
1388 value =
1389 spd_read_byte(dimm_socket_address,
1390 SPD_CMD_SIGNAL_INPUT_HOLD_TIME);
1391 die_on_spd_error(value);
1392 if (value >= 0xa0) { /* At 133MHz this constant should be 0x75 */
Martin Roth128c1042016-11-18 09:29:03 -07001393 controller_mode &= ~(1 << 16); /* Use two clock cycles instead of one */
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001394 }
1395#endif
1396
1397 /* go to the next DIMM */
1398 }
1399
1400 controller_mode |= (system_refresh_mode << 8);
1401
1402 // Configure the E7501
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001403 pci_write_config32(MCHDEV, DRC, controller_mode);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001404}
1405
1406/**
1407 * Configure the E7501's DRAM Row Attributes (DRA) registers based on DIMM
1408 * parameters read via SPD. This tells the controller the width of the SDRAM
1409 * chips on each DIMM side (x4 or x8) and the page size of each DIMM side
1410 * (4, 8, 16, or 32 KB).
1411 *
1412 * @param ctrl PCI addresses of memory controller functions, and SMBus
1413 * addresses of DIMM slots on the mainboard.
1414 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1415 */
1416static void configure_e7501_row_attributes(const struct mem_controller
1417 *ctrl, uint8_t dimm_mask)
1418{
1419 int i;
1420 uint32_t row_attributes = 0;
1421
1422 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
1423
1424 uint16_t dimm_socket_address = ctrl->channel0[i];
1425 struct dimm_size page_size;
1426 struct dimm_size sdram_width;
1427
1428 if (!(dimm_mask & (1 << i)))
1429 continue; // This DIMM not usable
1430
1431 // Get the relevant parameters via SPD
1432 page_size = sdram_spd_get_page_size(dimm_socket_address);
1433 sdram_width = sdram_spd_get_width(dimm_socket_address);
1434
1435 // Update the DRAM Row Attributes.
1436 // Page size is encoded as log2(page size in bits) - log2(8 Kb)
1437 // NOTE: 8 Kb = 2^13
1438 row_attributes |= (page_size.side1 - 13) << (i << 3); // Side 1 of each DIMM is an EVEN row
1439
1440 if (sdram_width.side2 > 0)
1441 row_attributes |= (page_size.side2 - 13) << ((i << 3) + 4); // Side 2 is ODD
1442
1443 // Set x4 flags if appropriate
1444 if (sdram_width.side1 == 4) {
1445 row_attributes |= 0x08 << (i << 3);
1446 }
1447
1448 if (sdram_width.side2 == 4) {
1449 row_attributes |= 0x08 << ((i << 3) + 4);
1450 }
1451
1452 /* go to the next DIMM */
1453 }
1454
1455 /* Write the new row attributes register */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001456 pci_write_config32(MCHDEV, DRA, row_attributes);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001457}
1458
1459/*
1460 * Enable clock signals for populated DIMM sockets and disable them for
1461 * unpopulated sockets (to reduce EMI).
1462 *
1463 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
1464 */
1465static void enable_e7501_clocks(uint8_t dimm_mask)
1466{
1467 int i;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001468 uint8_t clock_disable = pci_read_config8(MCHDEV, CKDIS);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001469
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001470 pci_write_config8(MCHDEV, 0x8e, 0xb0);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001471
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001472 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
1473
1474 uint8_t socket_mask = 1 << i;
1475
1476 if (dimm_mask & socket_mask)
1477 clock_disable &= ~socket_mask; // DIMM present, enable clock
1478 else
1479 clock_disable |= socket_mask; // DIMM absent, disable clock
1480 }
1481
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001482 pci_write_config8(MCHDEV, CKDIS, clock_disable);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001483}
1484
Martin Roth128c1042016-11-18 09:29:03 -07001485/* DIMM-dependent configuration functions */
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001486
1487/**
1488 * DDR Receive FIFO RE-Sync (?)
1489 */
1490static void RAM_RESET_DDR_PTR(void)
1491{
1492 uint8_t byte;
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001493 byte = pci_read_config8(MCHDEV, 0x88);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001494 byte |= (1 << 4);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001495 pci_write_config8(MCHDEV, 0x88, byte);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001496
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001497 byte = pci_read_config8(MCHDEV, 0x88);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001498 byte &= ~(1 << 4);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001499 pci_write_config8(MCHDEV, 0x88, byte);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001500}
1501
1502/**
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001503 * Copy 64 bytes from one location to another.
1504 *
1505 * @param src_addr TODO
1506 * @param dst_addr TODO
1507 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -08001508static void write_8dwords(const uint32_t *src_addr, u8 *dst_addr)
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001509{
1510 int i;
1511 for (i = 0; i < 8; i++) {
1512 write32(dst_addr, *src_addr);
1513 src_addr++;
1514 dst_addr += sizeof(uint32_t);
1515 }
1516}
1517
1518/**
1519 * Set the E7501's (undocumented) RCOMP registers.
1520 *
1521 * Per the 855PM datasheet and IXP2800 HW Initialization Reference Manual,
1522 * RCOMP registers appear to affect drive strength, pullup/pulldown offset,
1523 * and slew rate of various signal groups.
1524 *
1525 * Comments below are conjecture based on apparent similarity between the
1526 * E7501 and these two chips.
1527 */
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001528static void rcomp_copy_registers(void)
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001529{
1530 uint32_t dword;
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001531 uint8_t strength_control;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001532
1533 RAM_DEBUG_MESSAGE("Setting RCOMP registers.\n");
1534
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001535 /* Begin to write the RCOMP registers */
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001536 write8(RCOMP_MMIO + 0x2c, 0x0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001537
1538 // Set CMD and DQ/DQS strength to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001539 strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0x88;
1540 strength_control |= 0x40;
1541 write8(RCOMP_MMIO + DQCMDSTR, strength_control);
1542 write_8dwords(slew_2x, RCOMP_MMIO + 0x80);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001543 write16(RCOMP_MMIO + 0x42, 0);
1544
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001545 // Set CMD and DQ/DQS strength to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001546 strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0xF8;
1547 strength_control |= 0x04;
1548 write8(RCOMP_MMIO + DQCMDSTR, strength_control);
1549 write_8dwords(slew_2x, RCOMP_MMIO + 0x60);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001550 write16(RCOMP_MMIO + 0x40, 0);
1551
1552 // Set RCVEnOut# strength to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001553 strength_control = read8(RCOMP_MMIO + RCVENSTR) & 0xF8;
1554 strength_control |= 0x04;
1555 write8(RCOMP_MMIO + RCVENSTR, strength_control);
1556 write_8dwords(slew_2x, RCOMP_MMIO + 0x1c0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001557 write16(RCOMP_MMIO + 0x50, 0);
1558
1559 // Set CS# strength for x4 SDRAM to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001560 strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x88;
1561 strength_control |= 0x04;
1562 write8(RCOMP_MMIO + CSBSTR, strength_control);
1563 write_8dwords(slew_2x, RCOMP_MMIO + 0x140);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001564 write16(RCOMP_MMIO + 0x48, 0);
1565
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001566 // Set CS# strength for x4 SDRAM to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001567 strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x8F;
1568 strength_control |= 0x40;
1569 write8(RCOMP_MMIO + CSBSTR, strength_control);
1570 write_8dwords(slew_2x, RCOMP_MMIO + 0x160);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001571 write16(RCOMP_MMIO + 0x4a, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001572
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001573 // Set CKE strength for x4 SDRAM to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001574 strength_control = read8(RCOMP_MMIO + CKESTR) & 0x88;
1575 strength_control |= 0x04;
1576 write8(RCOMP_MMIO + CKESTR, strength_control);
1577 write_8dwords(slew_2x, RCOMP_MMIO + 0xa0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001578 write16(RCOMP_MMIO + 0x44, 0);
1579
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001580 // Set CKE strength for x4 SDRAM to 2x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001581 strength_control = read8(RCOMP_MMIO + CKESTR) & 0x8F;
1582 strength_control |= 0x40;
1583 write8(RCOMP_MMIO + CKESTR, strength_control);
1584 write_8dwords(slew_2x, RCOMP_MMIO + 0xc0);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001585 write16(RCOMP_MMIO + 0x46, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001586
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001587 // Set CK strength for x4 SDRAM to 1x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001588 strength_control = read8(RCOMP_MMIO + CKSTR) & 0x88;
1589 strength_control |= 0x01;
1590 write8(RCOMP_MMIO + CKSTR, strength_control);
1591 write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x180);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001592 write16(RCOMP_MMIO + 0x4c, 0);
1593
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001594 // Set CK strength for x4 SDRAM to 1x (?)
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001595 strength_control = read8(RCOMP_MMIO + CKSTR) & 0x8F;
1596 strength_control |= 0x10;
1597 write8(RCOMP_MMIO + CKSTR, strength_control);
1598 write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x1a0);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001599 write16(RCOMP_MMIO + 0x4e, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001600
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001601 dword = read32(RCOMP_MMIO + 0x400);
1602 dword &= 0x7f7fffff;
1603 write32(RCOMP_MMIO + 0x400, dword);
1604
1605 dword = read32(RCOMP_MMIO + 0x408);
1606 dword &= 0x7f7fffff;
1607 write32(RCOMP_MMIO + 0x408, dword);
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001608}
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001609
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001610static void ram_set_rcomp_regs(void)
1611{
1612 /* Set the RCOMP MMIO base address */
1613 mchtest_control(RCOMP_BAR_ENABLE);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -08001614 pci_write_config32(MCHDEV, SMRBASE, (uintptr_t)RCOMP_MMIO);
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001615
1616 /* Block RCOMP updates while we configure the registers */
1617 rcomp_smr_control(RCOMP_HOLD);
1618 rcomp_copy_registers();
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001619 d060_control(D060_CMD_0);
1620 mchtest_control(MCHTST_CMD_0);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001621
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001622 uint8_t revision = pci_read_config8(MCHDEV, 0x08);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001623 if (revision >= 3) {
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001624 rcomp_smr_control(RCOMP_SMR_00);
1625 rcomp_smr_control(RCOMP_SMR_01);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001626 }
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001627 rcomp_smr_control(RCOMP_RELEASE);
1628
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001629 /* Wait 40 usec */
1630 SLOW_DOWN_IO;
1631
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001632 /* Clear the RCOMP MMIO base address */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001633 pci_write_config32(MCHDEV, SMRBASE, 0);
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001634 mchtest_control(RCOMP_BAR_DISABLE);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001635}
1636
1637/*-----------------------------------------------------------------------------
1638Public interface:
1639-----------------------------------------------------------------------------*/
1640
1641/**
1642 * Go through the JEDEC initialization sequence for all DIMMs, then enable
1643 * refresh and initialize ECC and memory to zero. Upon exit, SDRAM is up
1644 * and running.
1645 *
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001646 * @param ctrl PCI addresses of memory controller functions, and SMBus
1647 * addresses of DIMM slots on the mainboard.
1648 */
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001649static void sdram_enable(const struct mem_controller *ctrl)
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001650{
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001651 uint8_t dimm_mask = pci_read_config16(MCHDEV, SKPD);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001652 uint32_t dram_controller_mode;
1653
1654 if (dimm_mask == 0)
1655 return;
1656
1657 /* 1 & 2 Power up and start clocks */
1658 RAM_DEBUG_MESSAGE("Ram Enable 1\n");
1659 RAM_DEBUG_MESSAGE("Ram Enable 2\n");
1660
1661 /* A 200us delay is needed */
1662 DO_DELAY; EXTRA_DELAY;
1663
1664 /* 3. Apply NOP */
1665 RAM_DEBUG_MESSAGE("Ram Enable 3\n");
1666 do_ram_command(RAM_COMMAND_NOP, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001667
1668 /* 4 Precharge all */
1669 RAM_DEBUG_MESSAGE("Ram Enable 4\n");
1670 do_ram_command(RAM_COMMAND_PRECHARGE, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001671 /* wait until the all banks idle state... */
1672
1673 /* 5. Issue EMRS to enable DLL */
1674 RAM_DEBUG_MESSAGE("Ram Enable 5\n");
1675 do_ram_command(RAM_COMMAND_EMRS,
1676 SDRAM_EXTMODE_DLL_ENABLE |
1677 SDRAM_EXTMODE_DRIVE_NORMAL);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001678
1679 /* 6. Reset DLL */
1680 RAM_DEBUG_MESSAGE("Ram Enable 6\n");
1681 set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_DLL_RESET);
1682 EXTRA_DELAY;
1683 /* Ensure a 200us delay between the DLL reset in step 6 and the final
1684 * mode register set in step 9.
1685 * Infineon needs this before any other command is sent to the ram.
1686 */
1687 DO_DELAY; EXTRA_DELAY;
1688
1689 /* 7 Precharge all */
1690 RAM_DEBUG_MESSAGE("Ram Enable 7\n");
1691 do_ram_command(RAM_COMMAND_PRECHARGE, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001692
1693 /* 8 Now we need 2 AUTO REFRESH / CBR cycles to be performed */
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001694 /* And for good luck 6 more CBRs */
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001695 RAM_DEBUG_MESSAGE("Ram Enable 8\n");
1696 int i;
Elyes HAOUAS93095522016-09-17 21:05:10 +02001697 for (i = 0; i < 8; i++)
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001698 do_ram_command(RAM_COMMAND_CBR, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001699
1700 /* 9 mode register set */
1701 RAM_DEBUG_MESSAGE("Ram Enable 9\n");
1702 set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_NORMAL);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001703
1704 /* 10 DDR Receive FIFO RE-Sync */
1705 RAM_DEBUG_MESSAGE("Ram Enable 10\n");
1706 RAM_RESET_DDR_PTR();
1707 EXTRA_DELAY;
1708
1709 /* 11 normal operation */
1710 RAM_DEBUG_MESSAGE("Ram Enable 11\n");
1711 do_ram_command(RAM_COMMAND_NORMAL, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001712
1713 // Reconfigure the row boundaries and Top of Low Memory
1714 // to match the true size of the DIMMs
1715 configure_e7501_ram_addresses(ctrl, dimm_mask);
1716
1717 /* Finally enable refresh */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001718 dram_controller_mode = pci_read_config32(MCHDEV, DRC);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001719 dram_controller_mode |= (1 << 29);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001720 pci_write_config32(MCHDEV, DRC, dram_controller_mode);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001721 EXTRA_DELAY;
Kyösti Mälkki97c064f2012-04-18 20:33:35 +03001722}
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001723
Kyösti Mälkki97c064f2012-04-18 20:33:35 +03001724/**
1725 * @param ctrl PCI addresses of memory controller functions, and SMBus
1726 * addresses of DIMM slots on the mainboard.
1727 */
1728static void sdram_post_ecc(const struct mem_controller *ctrl)
1729{
1730 /* Fast CS# Enable. */
1731 uint32_t dram_controller_mode = pci_read_config32(MCHDEV, DRC);
1732 dram_controller_mode = pci_read_config32(MCHDEV, DRC);
1733 dram_controller_mode |= (1 << 17);
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001734 pci_write_config32(MCHDEV, DRC, dram_controller_mode);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001735}
1736
1737/**
1738 * Configure SDRAM controller parameters that depend on characteristics of the
1739 * DIMMs installed in the system. These characteristics are read from the
1740 * DIMMs via the standard Serial Presence Detect (SPD) interface.
1741 *
1742 * @param ctrl PCI addresses of memory controller functions, and SMBus
1743 * addresses of DIMM slots on the mainboard.
1744 */
1745static void sdram_set_spd_registers(const struct mem_controller *ctrl)
1746{
1747 uint8_t dimm_mask;
1748
1749 RAM_DEBUG_MESSAGE("Reading SPD data...\n");
1750
1751 dimm_mask = spd_get_supported_dimms(ctrl);
1752
1753 if (dimm_mask == 0) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08001754 printk(BIOS_DEBUG, "No usable memory for this controller\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001755 } else {
1756 enable_e7501_clocks(dimm_mask);
1757
1758 RAM_DEBUG_MESSAGE("setting based on SPD data...\n");
1759
1760 configure_e7501_row_attributes(ctrl, dimm_mask);
1761 configure_e7501_dram_controller_mode(ctrl, dimm_mask);
1762 configure_e7501_cas_latency(ctrl, dimm_mask);
1763 RAM_RESET_DDR_PTR();
1764
1765 configure_e7501_dram_timing(ctrl, dimm_mask);
1766 DO_DELAY;
1767 RAM_DEBUG_MESSAGE("done\n");
1768 }
1769
1770 /* NOTE: configure_e7501_ram_addresses() is NOT called here.
1771 * We want to keep the default 64 MB/row mapping until sdram_enable() is called,
1772 * even though the default mapping is almost certainly incorrect.
1773 * The default mapping makes it easy to initialize all of the DIMMs
1774 * even if the total system memory is > 4 GB.
1775 *
1776 * Save the dimm_mask for when sdram_enable is called, so it can call
1777 * configure_e7501_ram_addresses() without having to regenerate the bitmask
1778 * of usable DIMMs.
1779 */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +03001780 pci_write_config16(MCHDEV, SKPD, dimm_mask);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001781}
1782
1783/**
1784 * Do basic RAM setup that does NOT depend on serial presence detect
1785 * information (i.e. independent of DIMM specifics).
1786 *
1787 * @param ctrl PCI addresses of memory controller functions, and SMBus
1788 * addresses of DIMM slots on the mainboard.
1789 */
1790static void sdram_set_registers(const struct mem_controller *ctrl)
1791{
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001792 uint32_t dword;
1793 uint16_t word;
1794 uint8_t byte;
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001795
1796 ram_set_rcomp_regs();
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001797
1798 /* Enable 0:0.1, 0:2.1 */
1799 word = pci_read_config16(MCHDEV, DVNP);
1800 word &= ~0x05;
1801 pci_write_config16(MCHDEV, DVNP, word);
1802
1803 /* Disable high-memory remap (power-on defaults, really) */
1804 pci_write_config16(MCHDEV, REMAPBASE, 0x03ff);
1805 pci_write_config16(MCHDEV, REMAPLIMIT, 0x0);
1806
1807 /* Disable legacy MMIO (0xC0000-0xEFFFF is DRAM) */
1808 int i;
1809 pci_write_config8(MCHDEV, PAM_0, 0x30);
Elyes HAOUAS93095522016-09-17 21:05:10 +02001810 for (i = 1; i <= 6; i++)
Kyösti Mälkki77e4f7d2012-04-18 19:47:56 +03001811 pci_write_config8(MCHDEV, PAM_0 + i, 0x33);
1812
1813 /* Conservatively say each row has 64MB of ram, we will fix this up later
1814 * Initial TOLM 8 rows 64MB each (1<<3 * 1<<26) >> 16 = 1<<13
1815 *
1816 * FIXME: Hard-coded limit to first four rows to prevent overlap!
1817 */
1818 pci_write_config32(MCHDEV, DRB_ROW_0, 0x04030201);
1819 pci_write_config32(MCHDEV, DRB_ROW_4, 0x04040404);
1820 //pci_write_config32(MCHDEV, DRB_ROW_4, 0x08070605);
1821 pci_write_config16(MCHDEV, TOLM, (1<<13));
1822
1823 /* DIMM clocks off */
1824 pci_write_config8(MCHDEV, CKDIS, 0xff);
1825
1826 /* reset row attributes */
1827 pci_write_config32(MCHDEV, DRA, 0x0);
1828
1829 // The only things we need to set here are DRAM idle timer, Back-to-Back Read Turnaround, and
1830 // Back-to-Back Write-Read Turnaround. All others are configured based on SPD.
1831 dword = pci_read_config32(MCHDEV, DRT);
1832 dword &= 0xC7F8FFFF;
1833 dword |= (0x28<<24)|(0x03<<16);
1834 pci_write_config32(MCHDEV, DRT, dword);
1835
1836 dword = pci_read_config32(MCHDEV, DRC);
1837 dword &= 0xffcef8f7;
1838 dword |= 0x00210008;
1839 pci_write_config32(MCHDEV, DRC, dword);
1840
1841 /* Undocumented */
1842 pci_write_config8(MCHDEV, 0x88, 0x80);
1843
1844 /* Undocumented. Set much later in vendor BIOS. */
1845 byte = pci_read_config8(MCHDEV, 0xd9);
1846 byte &= ~0x60;
1847 pci_write_config8(MCHDEV, 0xd9, byte);
1848
1849#ifdef SUSPICIOUS_LOOKING_CODE
1850 /* This will access D2:F0:0x50, is this correct??
1851 * Vendor BIOS reads Device ID before this is set.
1852 * Undocumented in the p64h2 PCI-X bridge datasheet.
1853 */
1854 byte = pci_read_config8(PCI_DEV(0,2,0), 0x50);
1855 byte &= 0xcf;
1856 byte |= 0x30
1857 pci_write_config8(PCI_DEV(0,2,0), 0x50, byte);
1858#endif
Kyösti Mälkki26c7b862012-04-12 22:46:23 +03001859
1860 uint8_t revision = pci_read_config8(MCHDEV, 0x08);
1861 if (revision >= 3)
1862 d060_control(D060_CMD_1);
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001863}
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02001864
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001865/**
1866 *
1867 *
1868 */
Kyösti Mälkki97c064f2012-04-18 20:33:35 +03001869void e7505_mch_init(const struct mem_controller *memctrl)
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001870{
1871 RAM_DEBUG_MESSAGE("Northbridge prior to SDRAM init:\n");
1872 DUMPNORTH();
1873
1874 sdram_set_registers(memctrl);
1875 sdram_set_spd_registers(memctrl);
1876 sdram_enable(memctrl);
1877}
1878
Kyösti Mälkki97c064f2012-04-18 20:33:35 +03001879/**
1880 * Scrub and reset error counts for ECC dimms.
1881 *
1882 * NOTE: this will invalidate cache and disable XIP cache for the
1883 * short remaining part of romstage.
1884 */
1885void e7505_mch_scrub_ecc(unsigned long ret_addr)
1886{
1887 unsigned long ret_addr2 = (unsigned long)((unsigned long*)&ret_addr-1);
1888 if ((pci_read_config32(MCHDEV, DRC)>>20 & 3) == 2)
1889 initialize_ecc(ret_addr, ret_addr2);
1890}
1891
1892void e7505_mch_done(const struct mem_controller *memctrl)
1893{
1894 sdram_post_ecc(memctrl);
1895
1896 RAM_DEBUG_MESSAGE("Northbridge following SDRAM init:\n");
1897 DUMPNORTH();
1898}
1899
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +03001900int e7505_mch_is_ready(void)
Kyösti Mälkki5c1ff922012-04-10 19:55:19 +03001901{
1902 uint32_t dword = pci_read_config32(MCHDEV, DRC);
1903 return !!(dword & DRC_DONE);
1904}