| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include <stdint.h> |
| 15 |
#include <device/pci_def.h> |
| 16 |
#include <arch/io.h> |
| 17 |
#include <device/mmio.h> |
| 18 |
#include <device/pci_ops.h> |
| 19 |
#include <device/smbus_host.h> |
| 20 |
#include <lib.h> |
| 21 |
#include <commonlib/helpers.h> |
| 22 |
#include <console/console.h> |
| 23 |
#include <assert.h> |
| 24 |
#include <spd.h> |
| 25 |
#include <sdram_mode.h> |
| 26 |
#include <timestamp.h> |
| 27 |
|
| 28 |
#include "raminit.h" |
| 29 |
#include "e7505.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#if CONFIG(DEBUG_RAM_SETUP) |
| 36 |
#define RAM_DEBUG_MESSAGE(x) printk(BIOS_DEBUG, x) |
| 37 |
#define RAM_DEBUG_HEX32(x) printk(BIOS_DEBUG, "%08x", x) |
| 38 |
#define RAM_DEBUG_HEX8(x) printk(BIOS_DEBUG, "%02x", x) |
| 39 |
#else |
| 40 |
#define RAM_DEBUG_MESSAGE(x) |
| 41 |
#define RAM_DEBUG_HEX32(x) |
| 42 |
#define RAM_DEBUG_HEX8(x) |
| 43 |
#endif |
| 44 |
|
| 45 |
#define E7501_SDRAM_MODE (SDRAM_BURST_INTERLEAVED | SDRAM_BURST_4) |
| 46 |
#define SPD_ERROR "Error reading SPD info\n" |
| 47 |
|
| 48 |
#define MCHDEV PCI_DEV(0, 0, 0) |
| 49 |
#define RASDEV PCI_DEV(0, 0, 1) |
| 50 |
#define AGPDEV PCI_DEV(0, 1, 0) |
| 51 |
#define D060DEV PCI_DEV(0, 6, 0) |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#define RCOMP_MMIO ((u8 *)0x200000) |
| 57 |
|
| 58 |
struct dimm_size { |
| 59 |
unsigned long side1; |
| 60 |
unsigned long side2; |
| 61 |
}; |
| 62 |
|
| 63 |
static const uint32_t refresh_frequency[] = { |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
0, 2, 3, 1, 0, 0, 0, 4 |
| 77 |
}; |
| 78 |
|
| 79 |
static const uint32_t refresh_rate_map[] = { |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
1, 7, 2, 1, 1, 3 |
| 93 |
}; |
| 94 |
|
| 95 |
#define MAX_SPD_REFRESH_RATE (ARRAY_SIZE(refresh_rate_map) - 1) |
| 96 |
|
| 97 |
|
| 98 |
static const uint8_t dual_channel_parameters[] = { |
| 99 |
SPD_MEMORY_TYPE, |
| 100 |
SPD_MODULE_VOLTAGE, |
| 101 |
SPD_NUM_COLUMNS, |
| 102 |
SPD_NUM_ROWS, |
| 103 |
SPD_NUM_DIMM_BANKS, |
| 104 |
SPD_PRIMARY_SDRAM_WIDTH, |
| 105 |
SPD_NUM_BANKS_PER_SDRAM |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
static const uint32_t slew_2x[] = { |
| 157 |
0x00000000, 0x76543210, 0xffffeca8, 0xffffffff, |
| 158 |
0x21000000, 0xa8765432, 0xffffffec, 0xffffffff, |
| 159 |
}; |
| 160 |
|
| 161 |
|
| 162 |
static const uint32_t pull_updown_offset_table[] = { |
| 163 |
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, |
| 164 |
0x88888888, 0x88888888, 0x88888888, 0x88888888, |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
#define SLOW_DOWN_IO inb(0x80) |
| 173 |
static void local_udelay(int i) |
| 174 |
{ |
| 175 |
while (i--) { |
| 176 |
SLOW_DOWN_IO; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
#define DO_DELAY local_udelay(200) |
| 182 |
#define EXTRA_DELAY DO_DELAY |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
typedef enum { |
| 188 |
MCHTST_CMD_0, |
| 189 |
D060_ENABLE, |
| 190 |
D060_DISABLE, |
| 191 |
RCOMP_BAR_ENABLE, |
| 192 |
RCOMP_BAR_DISABLE, |
| 193 |
} mchtst_cc; |
| 194 |
|
| 195 |
typedef enum { |
| 196 |
D060_CMD_0, |
| 197 |
D060_CMD_1, |
| 198 |
} d060_cc; |
| 199 |
|
| 200 |
typedef enum { |
| 201 |
RCOMP_HOLD, |
| 202 |
RCOMP_RELEASE, |
| 203 |
RCOMP_SMR_00, |
| 204 |
RCOMP_SMR_01, |
| 205 |
} rcomp_smr_cc; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
static void mchtest_control(mchtst_cc cmd) |
| 224 |
{ |
| 225 |
uint32_t dword = pci_read_config32(MCHDEV, MCHTST); |
| 226 |
switch (cmd) { |
| 227 |
case MCHTST_CMD_0: |
| 228 |
dword &= ~(3 << 30); |
| 229 |
break; |
| 230 |
case RCOMP_BAR_ENABLE: |
| 231 |
dword |= (1 << 22); |
| 232 |
break; |
| 233 |
case RCOMP_BAR_DISABLE: |
| 234 |
dword &= ~(1 << 22); |
| 235 |
break; |
| 236 |
case D060_ENABLE: |
| 237 |
dword |= (1 << 1); |
| 238 |
break; |
| 239 |
case D060_DISABLE: |
| 240 |
dword &= ~(1 << 1); |
| 241 |
break; |
| 242 |
}; |
| 243 |
pci_write_config32(MCHDEV, MCHTST, dword); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
static void d060_control(d060_cc cmd) |
| 250 |
{ |
| 251 |
mchtest_control(D060_ENABLE); |
| 252 |
uint32_t dword = pci_read_config32(D060DEV, 0xf0); |
| 253 |
switch (cmd) { |
| 254 |
case D060_CMD_0: |
| 255 |
dword |= (1 << 2); |
| 256 |
break; |
| 257 |
case D060_CMD_1: |
| 258 |
dword |= (3 << 27); |
| 259 |
break; |
| 260 |
} |
| 261 |
pci_write_config32(D060DEV, 0xf0, dword); |
| 262 |
mchtest_control(D060_DISABLE); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
static void rcomp_smr_control(rcomp_smr_cc cmd) |
| 269 |
{ |
| 270 |
uint32_t dword = read32(RCOMP_MMIO + SMRCTL); |
| 271 |
switch (cmd) { |
| 272 |
case RCOMP_HOLD: |
| 273 |
dword |= (1 << 9); |
| 274 |
break; |
| 275 |
case RCOMP_RELEASE: |
| 276 |
dword &= ~((1 << 9) | (3 << 0)); |
| 277 |
dword |= (1 << 10) | (1 << 0); |
| 278 |
break; |
| 279 |
case RCOMP_SMR_00: |
| 280 |
dword &= ~(1 << 8); |
| 281 |
break; |
| 282 |
case RCOMP_SMR_01: |
| 283 |
dword |= (1 << 10) | (1 << 8); |
| 284 |
break; |
| 285 |
} |
| 286 |
write32(RCOMP_MMIO + SMRCTL, dword); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
static void die_on_spd_error(int spd_return_value) |
| 294 |
{ |
| 295 |
if (spd_return_value < 0) |
| 296 |
die("Error reading SPD info\n"); |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
static struct dimm_size sdram_spd_get_page_size(uint16_t dimm_socket_address) |
| 309 |
{ |
| 310 |
uint16_t module_data_width; |
| 311 |
int value; |
| 312 |
struct dimm_size pgsz; |
| 313 |
|
| 314 |
pgsz.side1 = 0; |
| 315 |
pgsz.side2 = 0; |
| 316 |
|
| 317 |
|
| 318 |
value = smbus_read_byte(dimm_socket_address, SPD_NUM_COLUMNS); |
| 319 |
if (value < 0) |
| 320 |
goto hw_err; |
| 321 |
pgsz.side1 = value & 0xf; |
| 322 |
|
| 323 |
|
| 324 |
value = smbus_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_MSB); |
| 325 |
if (value < 0) |
| 326 |
goto hw_err; |
| 327 |
module_data_width = (value & 0xff) << 8; |
| 328 |
|
| 329 |
value = smbus_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_LSB); |
| 330 |
if (value < 0) |
| 331 |
goto hw_err; |
| 332 |
module_data_width |= (value & 0xff); |
| 333 |
|
| 334 |
pgsz.side1 += log2(module_data_width); |
| 335 |
|
| 336 |
|
| 337 |
value = smbus_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS); |
| 338 |
if (value < 0) |
| 339 |
goto hw_err; |
| 340 |
if (value > 2) |
| 341 |
die("Bad SPD value\n"); |
| 342 |
if (value == 2) { |
| 343 |
pgsz.side2 = pgsz.side1; |
| 344 |
value = smbus_read_byte(dimm_socket_address, SPD_NUM_COLUMNS); |
| 345 |
if (value < 0) |
| 346 |
goto hw_err; |
| 347 |
if ((value & 0xf0) != 0) { |
| 348 |
|
| 349 |
pgsz.side2 -= value & 0xf; |
| 350 |
pgsz.side2 += (value >> 4) & 0xf; |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
return pgsz; |
| 355 |
|
| 356 |
hw_err: |
| 357 |
die(SPD_ERROR); |
| 358 |
return pgsz; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
static struct dimm_size sdram_spd_get_width(uint16_t dimm_socket_address) |
| 368 |
{ |
| 369 |
int value; |
| 370 |
struct dimm_size width; |
| 371 |
|
| 372 |
width.side1 = 0; |
| 373 |
width.side2 = 0; |
| 374 |
|
| 375 |
value = smbus_read_byte(dimm_socket_address, SPD_PRIMARY_SDRAM_WIDTH); |
| 376 |
die_on_spd_error(value); |
| 377 |
|
| 378 |
width.side1 = value & 0x7f; |
| 379 |
|
| 380 |
if (value & 0x80) { |
| 381 |
width.side2 = width.side1 << 1; |
| 382 |
} else { |
| 383 |
|
| 384 |
value = smbus_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS); |
| 385 |
die_on_spd_error(value); |
| 386 |
|
| 387 |
if (value == 2) |
| 388 |
width.side2 = width.side1; |
| 389 |
} |
| 390 |
|
| 391 |
return width; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
static struct dimm_size spd_get_dimm_size(unsigned int dimm_socket_address) |
| 408 |
{ |
| 409 |
int value; |
| 410 |
|
| 411 |
|
| 412 |
struct dimm_size sz = sdram_spd_get_page_size(dimm_socket_address); |
| 413 |
|
| 414 |
if (sz.side1 > 0) { |
| 415 |
value = smbus_read_byte(dimm_socket_address, SPD_NUM_ROWS); |
| 416 |
die_on_spd_error(value); |
| 417 |
|
| 418 |
sz.side1 += value & 0xf; |
| 419 |
|
| 420 |
if (sz.side2 > 0) { |
| 421 |
|
| 422 |
if (value & 0xF0) |
| 423 |
sz.side2 += value >> 4; |
| 424 |
else |
| 425 |
sz.side2 += value; |
| 426 |
} |
| 427 |
|
| 428 |
value = smbus_read_byte(dimm_socket_address, |
| 429 |
SPD_NUM_BANKS_PER_SDRAM); |
| 430 |
die_on_spd_error(value); |
| 431 |
|
| 432 |
value = log2(value); |
| 433 |
sz.side1 += value; |
| 434 |
if (sz.side2 > 0) |
| 435 |
sz.side2 += value; |
| 436 |
} |
| 437 |
|
| 438 |
return sz; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
static uint8_t are_spd_values_equal(uint8_t spd_byte_number, |
| 451 |
uint16_t dimm0_address, |
| 452 |
uint16_t dimm1_address) |
| 453 |
{ |
| 454 |
uint8_t bEqual = 0; |
| 455 |
int dimm0_value = smbus_read_byte(dimm0_address, spd_byte_number); |
| 456 |
int dimm1_value = smbus_read_byte(dimm1_address, spd_byte_number); |
| 457 |
|
| 458 |
if ((dimm0_value >= 0) && (dimm1_value >= 0) |
| 459 |
&& (dimm0_value == dimm1_value)) |
| 460 |
bEqual = 1; |
| 461 |
|
| 462 |
return bEqual; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
static uint8_t spd_get_supported_dimms(const struct mem_controller *ctrl) |
| 484 |
{ |
| 485 |
int i; |
| 486 |
uint8_t dimm_mask = 0; |
| 487 |
|
| 488 |
|
| 489 |
ASSERT(MAX_DIMM_SOCKETS_PER_CHANNEL <= 4); |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 496 |
uint16_t channel0_dimm = ctrl->channel0[i]; |
| 497 |
uint16_t channel1_dimm = ctrl->channel1[i]; |
| 498 |
uint8_t bDualChannel = 1; |
| 499 |
struct dimm_size page_size; |
| 500 |
struct dimm_size sdram_width; |
| 501 |
int spd_value; |
| 502 |
|
| 503 |
if (channel0_dimm == 0) |
| 504 |
continue; |
| 505 |
|
| 506 |
if (smbus_read_byte(channel0_dimm, SPD_MEMORY_TYPE) != |
| 507 |
SPD_MEMORY_TYPE_SDRAM_DDR) |
| 508 |
continue; |
| 509 |
|
| 510 |
if (smbus_read_byte(channel0_dimm, SPD_MODULE_VOLTAGE) != |
| 511 |
SPD_VOLTAGE_SSTL2) |
| 512 |
continue; |
| 513 |
|
| 514 |
|
| 515 |
spd_value = smbus_read_byte(channel0_dimm, SPD_MODULE_ATTRIBUTES); |
| 516 |
if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) |
| 517 |
continue; |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
spd_value = smbus_read_byte(channel0_dimm, |
| 522 |
SPD_SUPPORTED_BURST_LENGTHS); |
| 523 |
if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0)) |
| 524 |
continue; |
| 525 |
|
| 526 |
page_size = sdram_spd_get_page_size(channel0_dimm); |
| 527 |
sdram_width = sdram_spd_get_width(channel0_dimm); |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
if ((page_size.side1 < 15) || (page_size.side1 > 18)) |
| 535 |
continue; |
| 536 |
|
| 537 |
|
| 538 |
if (page_size.side2 != 0) { |
| 539 |
if ((page_size.side2 < 15) |
| 540 |
|| (page_size.side2 > 18)) |
| 541 |
continue; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
if ((sdram_width.side1 != 4) && (sdram_width.side1 != 8)) |
| 547 |
continue; |
| 548 |
|
| 549 |
|
| 550 |
if (sdram_width.side2 != 0) { |
| 551 |
if ((sdram_width.side2 != 4) |
| 552 |
&& (sdram_width.side2 != 8)) |
| 553 |
continue; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
ASSERT(channel1_dimm != 0); |
| 560 |
|
| 561 |
|
| 562 |
spd_value = smbus_read_byte(channel1_dimm, SPD_MODULE_ATTRIBUTES); |
| 563 |
if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) { |
| 564 |
printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n"); |
| 565 |
continue; |
| 566 |
} |
| 567 |
|
| 568 |
spd_value = smbus_read_byte(channel1_dimm, |
| 569 |
SPD_SUPPORTED_BURST_LENGTHS); |
| 570 |
if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0)) |
| 571 |
continue; |
| 572 |
|
| 573 |
int j; |
| 574 |
for (j = 0; j < sizeof(dual_channel_parameters); ++j) { |
| 575 |
if (!are_spd_values_equal |
| 576 |
(dual_channel_parameters[j], channel0_dimm, |
| 577 |
channel1_dimm)) { |
| 578 |
bDualChannel = 0; |
| 579 |
break; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
if (bDualChannel) { |
| 584 |
|
| 585 |
dimm_mask |= 1 << i; |
| 586 |
dimm_mask |= 1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i); |
| 587 |
} else |
| 588 |
printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n"); |
| 589 |
} |
| 590 |
|
| 591 |
return dimm_mask; |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
static void do_ram_command(uint8_t command, uint16_t jedec_mode_bits) |
| 606 |
{ |
| 607 |
uint8_t dimm_start_64M_multiple; |
| 608 |
uintptr_t dimm_start_address; |
| 609 |
uint32_t dram_controller_mode; |
| 610 |
uint8_t i; |
| 611 |
|
| 612 |
|
| 613 |
dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 614 |
dram_controller_mode &= 0xFFFFFF8F; |
| 615 |
dram_controller_mode |= command; |
| 616 |
pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
if (command == RAM_COMMAND_NORMAL) { |
| 621 |
EXTRA_DELAY; |
| 622 |
return; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
if (command == RAM_COMMAND_MRS) { |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
dimm_start_address = (jedec_mode_bits & 0x00ff) << 18; |
| 632 |
dimm_start_address |= (jedec_mode_bits & 0x0300) << 8; |
| 633 |
dimm_start_address |= (jedec_mode_bits & 0x0fff) << 4; |
| 634 |
} else if (command == RAM_COMMAND_EMRS) { |
| 635 |
|
| 636 |
dimm_start_address = (jedec_mode_bits << 4); |
| 637 |
} else { |
| 638 |
ASSERT(jedec_mode_bits == 0); |
| 639 |
dimm_start_address = 0; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
dimm_start_64M_multiple = 0; |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
for (i = 0; i < (MAX_NUM_CHANNELS * MAX_DIMM_SOCKETS_PER_CHANNEL); ++i) { |
| 650 |
uint8_t dimm_end_64M_multiple = pci_read_config8(MCHDEV, DRB_ROW_0 + i); |
| 651 |
|
| 652 |
if (dimm_end_64M_multiple > dimm_start_64M_multiple) { |
| 653 |
dimm_start_address &= 0x3ffffff; |
| 654 |
dimm_start_address |= dimm_start_64M_multiple << 26; |
| 655 |
read32p(dimm_start_address); |
| 656 |
|
| 657 |
dimm_start_64M_multiple = dimm_end_64M_multiple; |
| 658 |
} |
| 659 |
} |
| 660 |
EXTRA_DELAY; |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
static void set_ram_mode(uint16_t jedec_mode_bits) |
| 673 |
{ |
| 674 |
ASSERT(!(jedec_mode_bits & SDRAM_CAS_MASK)); |
| 675 |
|
| 676 |
uint32_t dram_cas_latency = |
| 677 |
pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK; |
| 678 |
|
| 679 |
switch (dram_cas_latency) { |
| 680 |
case DRT_CAS_2_5: |
| 681 |
jedec_mode_bits |= SDRAM_CAS_2_5; |
| 682 |
break; |
| 683 |
|
| 684 |
case DRT_CAS_2_0: |
| 685 |
jedec_mode_bits |= SDRAM_CAS_2_0; |
| 686 |
break; |
| 687 |
|
| 688 |
default: |
| 689 |
BUG(); |
| 690 |
break; |
| 691 |
} |
| 692 |
|
| 693 |
do_ram_command(RAM_COMMAND_MRS, jedec_mode_bits); |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
static uint8_t configure_dimm_row_boundaries(struct dimm_size dimm_log2_num_bits, uint8_t total_dram_64M_multiple, unsigned int dimm_index) |
| 713 |
{ |
| 714 |
int i; |
| 715 |
|
| 716 |
ASSERT(dimm_index < MAX_DIMM_SOCKETS_PER_CHANNEL); |
| 717 |
|
| 718 |
|
| 719 |
ASSERT(dimm_log2_num_bits.side1 >= 28); |
| 720 |
ASSERT((dimm_log2_num_bits.side2 == 0) |
| 721 |
|| (dimm_log2_num_bits.side2 >= 28)); |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
dimm_log2_num_bits.side1++; |
| 729 |
if (dimm_log2_num_bits.side2 > 0) |
| 730 |
dimm_log2_num_bits.side2++; |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
total_dram_64M_multiple += (1 << (dimm_log2_num_bits.side1 - 29)); |
| 737 |
|
| 738 |
|
| 739 |
pci_write_config8(MCHDEV, DRB_ROW_0 + (dimm_index << 1), |
| 740 |
total_dram_64M_multiple); |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
if (dimm_log2_num_bits.side2 >= 29) |
| 745 |
total_dram_64M_multiple += |
| 746 |
(1 << (dimm_log2_num_bits.side2 - 29)); |
| 747 |
|
| 748 |
|
| 749 |
pci_write_config8(MCHDEV, DRB_ROW_1 + (dimm_index << 1), |
| 750 |
total_dram_64M_multiple); |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
for (i = dimm_index + 1; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 756 |
pci_write_config8(MCHDEV, DRB_ROW_0 + (i << 1), |
| 757 |
total_dram_64M_multiple); |
| 758 |
pci_write_config8(MCHDEV, DRB_ROW_1 + (i << 1), |
| 759 |
total_dram_64M_multiple); |
| 760 |
} |
| 761 |
|
| 762 |
return total_dram_64M_multiple; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
static void configure_e7501_ram_addresses(const struct mem_controller |
| 776 |
*ctrl, uint8_t dimm_mask) |
| 777 |
{ |
| 778 |
int i; |
| 779 |
uint8_t total_dram_64M_multiple = 0; |
| 780 |
uint64_t tolm, tom; |
| 781 |
uint16_t reg; |
| 782 |
|
| 783 |
|
| 784 |
const int agp_slot_disabled = 1; |
| 785 |
|
| 786 |
|
| 787 |
uint16_t remapbase_r = 0x3ff; |
| 788 |
uint16_t remaplimit_r = 0; |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
pci_write_config32(MCHDEV, DRB_ROW_0, 0); |
| 793 |
pci_write_config32(MCHDEV, DRB_ROW_4, 0); |
| 794 |
|
| 795 |
for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 796 |
uint16_t dimm_socket_address = ctrl->channel0[i]; |
| 797 |
struct dimm_size sz; |
| 798 |
|
| 799 |
if (!(dimm_mask & (1 << i))) |
| 800 |
continue; |
| 801 |
|
| 802 |
sz = spd_get_dimm_size(dimm_socket_address); |
| 803 |
|
| 804 |
RAM_DEBUG_MESSAGE("dimm size ="); |
| 805 |
RAM_DEBUG_HEX32((u32)sz.side1); |
| 806 |
RAM_DEBUG_MESSAGE(" "); |
| 807 |
RAM_DEBUG_HEX32((u32)sz.side2); |
| 808 |
RAM_DEBUG_MESSAGE("\n"); |
| 809 |
|
| 810 |
if (sz.side1 == 0) |
| 811 |
die("Bad SPD value\n"); |
| 812 |
|
| 813 |
total_dram_64M_multiple = |
| 814 |
configure_dimm_row_boundaries(sz, total_dram_64M_multiple, i); |
| 815 |
} |
| 816 |
|
| 817 |
tom = total_dram_64M_multiple * 64ULL * MiB; |
| 818 |
|
| 819 |
|
| 820 |
tolm = 4ULL * GiB - 512 * MiB; |
| 821 |
if (agp_slot_disabled) { |
| 822 |
|
| 823 |
pci_write_config8(MCHDEV, APSIZE, 0x3F); |
| 824 |
pci_write_config16(AGPDEV, APSIZE1, 0x3F); |
| 825 |
} else { |
| 826 |
|
| 827 |
tolm -= 512 * MiB; |
| 828 |
} |
| 829 |
tolm = MIN(tolm, tom); |
| 830 |
|
| 831 |
|
| 832 |
if (tolm < tom) { |
| 833 |
uint64_t remapbase = MAX(tom, 4ULL * GiB); |
| 834 |
uint64_t remaplimit = remapbase + (4ULL * GiB - tolm); |
| 835 |
|
| 836 |
remapbase_r = remapbase / (64 * MiB); |
| 837 |
remaplimit_r = remaplimit / (64 * MiB); |
| 838 |
|
| 839 |
|
| 840 |
remaplimit_r -= 1; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
reg = pci_read_config16(MCHDEV, TOLM) & 0x7ff; |
| 846 |
reg |= (tolm / (128 * MiB)) << 11; |
| 847 |
pci_write_config16(MCHDEV, TOLM, reg); |
| 848 |
|
| 849 |
reg = pci_read_config16(MCHDEV, REMAPBASE) & 0xfc00; |
| 850 |
reg |= remapbase_r; |
| 851 |
pci_write_config16(MCHDEV, REMAPBASE, reg); |
| 852 |
|
| 853 |
reg = pci_read_config16(MCHDEV, REMAPLIMIT) & 0xfc00; |
| 854 |
reg |= remaplimit_r; |
| 855 |
pci_write_config16(MCHDEV, REMAPLIMIT, reg); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
static void configure_e7501_dram_timing(const struct mem_controller *ctrl, |
| 868 |
uint8_t dimm_mask) |
| 869 |
{ |
| 870 |
int i; |
| 871 |
uint32_t dram_timing; |
| 872 |
int value; |
| 873 |
uint8_t slowest_row_precharge = 0; |
| 874 |
uint8_t slowest_ras_cas_delay = 0; |
| 875 |
uint8_t slowest_active_to_precharge_delay = 0; |
| 876 |
uint32_t current_cas_latency = |
| 877 |
pci_read_config32(MCHDEV, DRT) & DRT_CAS_MASK; |
| 878 |
|
| 879 |
|
| 880 |
ASSERT((current_cas_latency == DRT_CAS_2_0) |
| 881 |
|| (current_cas_latency == DRT_CAS_2_5)); |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 886 |
uint16_t dimm_socket_address; |
| 887 |
|
| 888 |
if (!(dimm_mask & (1 << i))) |
| 889 |
continue; |
| 890 |
|
| 891 |
if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 892 |
dimm_socket_address = ctrl->channel0[i]; |
| 893 |
else |
| 894 |
dimm_socket_address = |
| 895 |
ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 896 |
|
| 897 |
value = smbus_read_byte(dimm_socket_address, |
| 898 |
SPD_MIN_ROW_PRECHARGE_TIME); |
| 899 |
if (value < 0) |
| 900 |
goto hw_err; |
| 901 |
if (value > slowest_row_precharge) |
| 902 |
slowest_row_precharge = value; |
| 903 |
|
| 904 |
value = smbus_read_byte(dimm_socket_address, |
| 905 |
SPD_MIN_RAS_TO_CAS_DELAY); |
| 906 |
if (value < 0) |
| 907 |
goto hw_err; |
| 908 |
if (value > slowest_ras_cas_delay) |
| 909 |
slowest_ras_cas_delay = value; |
| 910 |
|
| 911 |
value = smbus_read_byte(dimm_socket_address, |
| 912 |
SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY); |
| 913 |
if (value < 0) |
| 914 |
goto hw_err; |
| 915 |
if (value > slowest_active_to_precharge_delay) |
| 916 |
slowest_active_to_precharge_delay = value; |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
dram_timing = pci_read_config32(MCHDEV, DRT); |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
if (slowest_row_precharge > ((22 << 2) | (2 << 0))) |
| 929 |
die("unsupported DIMM tRP"); |
| 930 |
else if (slowest_row_precharge > (15 << 2)) |
| 931 |
dram_timing &= ~(1 << 0); |
| 932 |
else |
| 933 |
dram_timing |= (1 << 0); |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
dram_timing &= ~((1 << 3) | (3 << 1)); |
| 940 |
if (slowest_ras_cas_delay > ((22 << 2) | (2 << 0))) |
| 941 |
die("unsupported DIMM tRCD"); |
| 942 |
else if (slowest_ras_cas_delay > (15 << 2)) |
| 943 |
dram_timing |= (2 << 1); |
| 944 |
else |
| 945 |
dram_timing |= ((1 << 3) | (3 << 1)); |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
dram_timing &= ~(3 << 9); |
| 952 |
|
| 953 |
if (slowest_active_to_precharge_delay > 52) |
| 954 |
die("unsupported DIMM tRAS"); |
| 955 |
else if (slowest_active_to_precharge_delay > 45) |
| 956 |
dram_timing |= (0 << 9); |
| 957 |
else if (slowest_active_to_precharge_delay > 37) |
| 958 |
dram_timing |= (1 << 9); |
| 959 |
else |
| 960 |
dram_timing |= (2 << 9); |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
dram_timing &= ~(7 << 24); |
| 969 |
if (current_cas_latency == DRT_CAS_2_0) |
| 970 |
dram_timing |= (1 << 24); |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
dram_timing &= ~(1 << 28); |
| 979 |
if (current_cas_latency == DRT_CAS_2_0) |
| 980 |
dram_timing |= (1 << 28); |
| 981 |
|
| 982 |
pci_write_config32(MCHDEV, DRT, dram_timing); |
| 983 |
|
| 984 |
return; |
| 985 |
|
| 986 |
hw_err: |
| 987 |
die(SPD_ERROR); |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
static void configure_e7501_cas_latency(const struct mem_controller *ctrl, |
| 999 |
uint8_t dimm_mask) |
| 1000 |
{ |
| 1001 |
int i; |
| 1002 |
int value; |
| 1003 |
uint32_t dram_timing; |
| 1004 |
uint16_t dram_read_timing; |
| 1005 |
uint32_t dword; |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
uint32_t system_compatible_cas_latencies = |
| 1010 |
SPD_CAS_LATENCY_2_0 | SPD_CAS_LATENCY_2_5; |
| 1011 |
uint32_t current_cas_latency; |
| 1012 |
uint32_t dimm_compatible_cas_latencies; |
| 1013 |
|
| 1014 |
for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 1015 |
uint16_t dimm_socket_address; |
| 1016 |
|
| 1017 |
if (!(dimm_mask & (1 << i))) |
| 1018 |
continue; |
| 1019 |
|
| 1020 |
if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 1021 |
dimm_socket_address = ctrl->channel0[i]; |
| 1022 |
else |
| 1023 |
dimm_socket_address = |
| 1024 |
ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 1025 |
|
| 1026 |
value = smbus_read_byte(dimm_socket_address, |
| 1027 |
SPD_ACCEPTABLE_CAS_LATENCIES); |
| 1028 |
if (value < 0) |
| 1029 |
goto hw_err; |
| 1030 |
|
| 1031 |
dimm_compatible_cas_latencies = value & 0x7f; |
| 1032 |
current_cas_latency = 1 << log2(dimm_compatible_cas_latencies); |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
value = smbus_read_byte(dimm_socket_address, |
| 1037 |
SPD_MIN_CYCLE_TIME_AT_CAS_MAX); |
| 1038 |
if (value < 0) |
| 1039 |
goto hw_err; |
| 1040 |
|
| 1041 |
|
| 1042 |
if (value > 0x75) { |
| 1043 |
|
| 1044 |
|
| 1045 |
dimm_compatible_cas_latencies &= ~current_cas_latency; |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
current_cas_latency >>= 1; |
| 1050 |
if (current_cas_latency != 0) { |
| 1051 |
value = smbus_read_byte(dimm_socket_address, |
| 1052 |
SPD_SDRAM_CYCLE_TIME_2ND); |
| 1053 |
if (value < 0) |
| 1054 |
goto hw_err; |
| 1055 |
if (value > 0x75) |
| 1056 |
dimm_compatible_cas_latencies &= |
| 1057 |
~current_cas_latency; |
| 1058 |
} |
| 1059 |
|
| 1060 |
current_cas_latency >>= 1; |
| 1061 |
if (current_cas_latency != 0) { |
| 1062 |
value = smbus_read_byte(dimm_socket_address, |
| 1063 |
SPD_SDRAM_CYCLE_TIME_3RD); |
| 1064 |
if (value < 0) |
| 1065 |
goto hw_err; |
| 1066 |
if (value > 0x75) |
| 1067 |
dimm_compatible_cas_latencies &= |
| 1068 |
~current_cas_latency; |
| 1069 |
} |
| 1070 |
|
| 1071 |
system_compatible_cas_latencies &= |
| 1072 |
dimm_compatible_cas_latencies; |
| 1073 |
|
| 1074 |
|
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
dram_timing = pci_read_config32(MCHDEV, DRT); |
| 1082 |
dram_timing &= ~(DRT_CAS_MASK); |
| 1083 |
|
| 1084 |
dram_read_timing = |
| 1085 |
pci_read_config16(MCHDEV, DRDCTL); |
| 1086 |
dram_read_timing &= 0xF000; |
| 1087 |
|
| 1088 |
if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_0) { |
| 1089 |
dram_timing |= DRT_CAS_2_0; |
| 1090 |
dram_read_timing |= 0x0222; |
| 1091 |
} else if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_5) { |
| 1092 |
uint32_t dram_row_attributes = |
| 1093 |
pci_read_config32(MCHDEV, DRA); |
| 1094 |
|
| 1095 |
dram_timing |= DRT_CAS_2_5; |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
if ((dram_row_attributes & 0xff) |
| 1101 |
&& (dram_row_attributes & 0xff00) |
| 1102 |
&& (dram_row_attributes & 0xff0000) |
| 1103 |
&& (dram_row_attributes & 0xff000000)) { |
| 1104 |
|
| 1105 |
dram_read_timing |= 0x0882; |
| 1106 |
} else { |
| 1107 |
|
| 1108 |
dram_read_timing |= 0x0662; |
| 1109 |
} |
| 1110 |
} else |
| 1111 |
die("No CAS# latencies compatible with all DIMMs!!\n"); |
| 1112 |
|
| 1113 |
pci_write_config32(MCHDEV, DRT, dram_timing); |
| 1114 |
|
| 1115 |
|
| 1116 |
dword = pci_read_config32(MCHDEV, 0x88); |
| 1117 |
dword |= (1 << 26); |
| 1118 |
pci_write_config32(MCHDEV, 0x88, dword); |
| 1119 |
|
| 1120 |
dword &= 0x0ca17fff; |
| 1121 |
dword |= 0xd14a5000; |
| 1122 |
pci_write_config32(MCHDEV, 0x88, dword); |
| 1123 |
|
| 1124 |
pci_write_config16(MCHDEV, DRDCTL, |
| 1125 |
dram_read_timing); |
| 1126 |
|
| 1127 |
|
| 1128 |
dword = pci_read_config32(MCHDEV, 0x88); |
| 1129 |
dword &= ~(1 << 26); |
| 1130 |
pci_write_config32(MCHDEV, 0x88, dword); |
| 1131 |
|
| 1132 |
return; |
| 1133 |
|
| 1134 |
hw_err: |
| 1135 |
die(SPD_ERROR); |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
static void configure_e7501_dram_controller_mode(const struct mem_controller *ctrl, |
| 1148 |
uint8_t dimm_mask) |
| 1149 |
{ |
| 1150 |
int i; |
| 1151 |
|
| 1152 |
|
| 1153 |
uint32_t controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1154 |
uint32_t system_refresh_mode = (controller_mode >> 8) & 7; |
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
ASSERT((controller_mode & (3 << 20)) == (2 << 20)); |
| 1163 |
ASSERT(!(controller_mode & (7 << 8))); |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
for (i = 0; i < MAX_DIMM_SOCKETS; i++) { |
| 1171 |
uint32_t dimm_refresh_mode; |
| 1172 |
int value; |
| 1173 |
uint16_t dimm_socket_address; |
| 1174 |
|
| 1175 |
if (!(dimm_mask & (1 << i))) { |
| 1176 |
continue; |
| 1177 |
} |
| 1178 |
|
| 1179 |
if (i < MAX_DIMM_SOCKETS_PER_CHANNEL) |
| 1180 |
dimm_socket_address = ctrl->channel0[i]; |
| 1181 |
else |
| 1182 |
dimm_socket_address = |
| 1183 |
ctrl->channel1[i - |
| 1184 |
MAX_DIMM_SOCKETS_PER_CHANNEL]; |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
value = smbus_read_byte(dimm_socket_address, |
| 1190 |
SPD_DIMM_CONFIG_TYPE); |
| 1191 |
die_on_spd_error(value); |
| 1192 |
if (value != ERROR_SCHEME_ECC) { |
| 1193 |
controller_mode &= ~(3 << 20); |
| 1194 |
} |
| 1195 |
|
| 1196 |
value = smbus_read_byte(dimm_socket_address, SPD_REFRESH); |
| 1197 |
die_on_spd_error(value); |
| 1198 |
value &= 0x7f; |
| 1199 |
if (value > MAX_SPD_REFRESH_RATE) { |
| 1200 |
printk(BIOS_ERR, "unsupported refresh rate\n"); |
| 1201 |
continue; |
| 1202 |
} |
| 1203 |
|
| 1204 |
dimm_refresh_mode = refresh_rate_map[value]; |
| 1205 |
if (dimm_refresh_mode > 7) { |
| 1206 |
printk(BIOS_ERR, "unsupported refresh rate\n"); |
| 1207 |
continue; |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
if (refresh_frequency[dimm_refresh_mode] > |
| 1212 |
refresh_frequency[system_refresh_mode]) |
| 1213 |
system_refresh_mode = dimm_refresh_mode; |
| 1214 |
|
| 1215 |
|
| 1216 |
} |
| 1217 |
|
| 1218 |
controller_mode |= (system_refresh_mode << 8); |
| 1219 |
|
| 1220 |
|
| 1221 |
pci_write_config32(MCHDEV, DRC, controller_mode); |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
static void configure_e7501_row_attributes(const struct mem_controller |
| 1235 |
*ctrl, uint8_t dimm_mask) |
| 1236 |
{ |
| 1237 |
int i; |
| 1238 |
uint32_t row_attributes = 0; |
| 1239 |
|
| 1240 |
for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 1241 |
uint16_t dimm_socket_address = ctrl->channel0[i]; |
| 1242 |
struct dimm_size page_size; |
| 1243 |
struct dimm_size sdram_width; |
| 1244 |
|
| 1245 |
if (!(dimm_mask & (1 << i))) |
| 1246 |
continue; |
| 1247 |
|
| 1248 |
|
| 1249 |
page_size = sdram_spd_get_page_size(dimm_socket_address); |
| 1250 |
sdram_width = sdram_spd_get_width(dimm_socket_address); |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
row_attributes |= (page_size.side1 - 13) << (i << 3); |
| 1256 |
|
| 1257 |
if (sdram_width.side2 > 0) |
| 1258 |
row_attributes |= (page_size.side2 - 13) << ((i << 3) + 4); |
| 1259 |
|
| 1260 |
|
| 1261 |
if (sdram_width.side1 == 4) { |
| 1262 |
row_attributes |= 0x08 << (i << 3); |
| 1263 |
} |
| 1264 |
|
| 1265 |
if (sdram_width.side2 == 4) { |
| 1266 |
row_attributes |= 0x08 << ((i << 3) + 4); |
| 1267 |
} |
| 1268 |
|
| 1269 |
|
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
pci_write_config32(MCHDEV, DRA, row_attributes); |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
static void enable_e7501_clocks(uint8_t dimm_mask) |
| 1283 |
{ |
| 1284 |
int i; |
| 1285 |
uint8_t clock_disable = pci_read_config8(MCHDEV, CKDIS); |
| 1286 |
|
| 1287 |
pci_write_config8(MCHDEV, 0x8e, 0xb0); |
| 1288 |
|
| 1289 |
for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) { |
| 1290 |
uint8_t socket_mask = 1 << i; |
| 1291 |
|
| 1292 |
if (dimm_mask & socket_mask) |
| 1293 |
clock_disable &= ~socket_mask; |
| 1294 |
else |
| 1295 |
clock_disable |= socket_mask; |
| 1296 |
} |
| 1297 |
|
| 1298 |
pci_write_config8(MCHDEV, CKDIS, clock_disable); |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
static void RAM_RESET_DDR_PTR(void) |
| 1307 |
{ |
| 1308 |
uint8_t byte; |
| 1309 |
byte = pci_read_config8(MCHDEV, 0x88); |
| 1310 |
byte |= (1 << 4); |
| 1311 |
pci_write_config8(MCHDEV, 0x88, byte); |
| 1312 |
|
| 1313 |
byte = pci_read_config8(MCHDEV, 0x88); |
| 1314 |
byte &= ~(1 << 4); |
| 1315 |
pci_write_config8(MCHDEV, 0x88, byte); |
| 1316 |
} |
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
static void write_8dwords(const uint32_t *src_addr, u8 *dst_addr) |
| 1325 |
{ |
| 1326 |
int i; |
| 1327 |
for (i = 0; i < 8; i++) { |
| 1328 |
write32(dst_addr, *src_addr); |
| 1329 |
src_addr++; |
| 1330 |
dst_addr += sizeof(uint32_t); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
static void rcomp_copy_registers(void) |
| 1345 |
{ |
| 1346 |
uint32_t dword; |
| 1347 |
uint8_t strength_control; |
| 1348 |
|
| 1349 |
RAM_DEBUG_MESSAGE("Setting RCOMP registers.\n"); |
| 1350 |
|
| 1351 |
|
| 1352 |
write8(RCOMP_MMIO + 0x2c, 0x0); |
| 1353 |
|
| 1354 |
|
| 1355 |
strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0x88; |
| 1356 |
strength_control |= 0x40; |
| 1357 |
write8(RCOMP_MMIO + DQCMDSTR, strength_control); |
| 1358 |
write_8dwords(slew_2x, RCOMP_MMIO + 0x80); |
| 1359 |
write16(RCOMP_MMIO + 0x42, 0); |
| 1360 |
|
| 1361 |
|
| 1362 |
strength_control = read8(RCOMP_MMIO + DQCMDSTR) & 0xF8; |
| 1363 |
strength_control |= 0x04; |
| 1364 |
write8(RCOMP_MMIO + DQCMDSTR, strength_control); |
| 1365 |
write_8dwords(slew_2x, RCOMP_MMIO + 0x60); |
| 1366 |
write16(RCOMP_MMIO + 0x40, 0); |
| 1367 |
|
| 1368 |
|
| 1369 |
strength_control = read8(RCOMP_MMIO + RCVENSTR) & 0xF8; |
| 1370 |
strength_control |= 0x04; |
| 1371 |
write8(RCOMP_MMIO + RCVENSTR, strength_control); |
| 1372 |
write_8dwords(slew_2x, RCOMP_MMIO + 0x1c0); |
| 1373 |
write16(RCOMP_MMIO + 0x50, 0); |
| 1374 |
|
| 1375 |
|
| 1376 |
strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x88; |
| 1377 |
strength_control |= 0x04; |
| 1378 |
write8(RCOMP_MMIO + CSBSTR, strength_control); |
| 1379 |
write_8dwords(slew_2x, RCOMP_MMIO + 0x140); |
| 1380 |
write16(RCOMP_MMIO + 0x48, 0); |
| 1381 |
|
| 1382 |
|
| 1383 |
strength_control = read8(RCOMP_MMIO + CSBSTR) & 0x8F; |
| 1384 |
strength_control |= 0x40; |
| 1385 |
write8(RCOMP_MMIO + CSBSTR, strength_control); |
| 1386 |
write_8dwords(slew_2x, RCOMP_MMIO + 0x160); |
| 1387 |
write16(RCOMP_MMIO + 0x4a, 0); |
| 1388 |
|
| 1389 |
|
| 1390 |
strength_control = read8(RCOMP_MMIO + CKESTR) & 0x88; |
| 1391 |
strength_control |= 0x04; |
| 1392 |
write8(RCOMP_MMIO + CKESTR, strength_control); |
| 1393 |
write_8dwords(slew_2x, RCOMP_MMIO + 0xa0); |
| 1394 |
write16(RCOMP_MMIO + 0x44, 0); |
| 1395 |
|
| 1396 |
|
| 1397 |
strength_control = read8(RCOMP_MMIO + CKESTR) & 0x8F; |
| 1398 |
strength_control |= 0x40; |
| 1399 |
write8(RCOMP_MMIO + CKESTR, strength_control); |
| 1400 |
write_8dwords(slew_2x, RCOMP_MMIO + 0xc0); |
| 1401 |
write16(RCOMP_MMIO + 0x46, 0); |
| 1402 |
|
| 1403 |
|
| 1404 |
strength_control = read8(RCOMP_MMIO + CKSTR) & 0x88; |
| 1405 |
strength_control |= 0x01; |
| 1406 |
write8(RCOMP_MMIO + CKSTR, strength_control); |
| 1407 |
write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x180); |
| 1408 |
write16(RCOMP_MMIO + 0x4c, 0); |
| 1409 |
|
| 1410 |
|
| 1411 |
strength_control = read8(RCOMP_MMIO + CKSTR) & 0x8F; |
| 1412 |
strength_control |= 0x10; |
| 1413 |
write8(RCOMP_MMIO + CKSTR, strength_control); |
| 1414 |
write_8dwords(pull_updown_offset_table, RCOMP_MMIO + 0x1a0); |
| 1415 |
write16(RCOMP_MMIO + 0x4e, 0); |
| 1416 |
|
| 1417 |
dword = read32(RCOMP_MMIO + 0x400); |
| 1418 |
dword &= 0x7f7fffff; |
| 1419 |
write32(RCOMP_MMIO + 0x400, dword); |
| 1420 |
|
| 1421 |
dword = read32(RCOMP_MMIO + 0x408); |
| 1422 |
dword &= 0x7f7fffff; |
| 1423 |
write32(RCOMP_MMIO + 0x408, dword); |
| 1424 |
} |
| 1425 |
|
| 1426 |
static void ram_set_rcomp_regs(void) |
| 1427 |
{ |
| 1428 |
|
| 1429 |
mchtest_control(RCOMP_BAR_ENABLE); |
| 1430 |
pci_write_config32(MCHDEV, SMRBASE, (uintptr_t)RCOMP_MMIO); |
| 1431 |
|
| 1432 |
|
| 1433 |
rcomp_smr_control(RCOMP_HOLD); |
| 1434 |
rcomp_copy_registers(); |
| 1435 |
d060_control(D060_CMD_0); |
| 1436 |
mchtest_control(MCHTST_CMD_0); |
| 1437 |
|
| 1438 |
uint8_t revision = pci_read_config8(MCHDEV, 0x08); |
| 1439 |
if (revision >= 3) { |
| 1440 |
rcomp_smr_control(RCOMP_SMR_00); |
| 1441 |
rcomp_smr_control(RCOMP_SMR_01); |
| 1442 |
} |
| 1443 |
rcomp_smr_control(RCOMP_RELEASE); |
| 1444 |
|
| 1445 |
|
| 1446 |
SLOW_DOWN_IO; |
| 1447 |
|
| 1448 |
|
| 1449 |
pci_write_config32(MCHDEV, SMRBASE, 0); |
| 1450 |
mchtest_control(RCOMP_BAR_DISABLE); |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
static void sdram_enable(const struct mem_controller *ctrl) |
| 1466 |
{ |
| 1467 |
uint8_t dimm_mask = pci_read_config16(MCHDEV, SKPD); |
| 1468 |
uint32_t dram_controller_mode; |
| 1469 |
|
| 1470 |
if (dimm_mask == 0) |
| 1471 |
return; |
| 1472 |
|
| 1473 |
|
| 1474 |
RAM_DEBUG_MESSAGE("Ram Enable 1\n"); |
| 1475 |
RAM_DEBUG_MESSAGE("Ram Enable 2\n"); |
| 1476 |
|
| 1477 |
|
| 1478 |
DO_DELAY; EXTRA_DELAY; |
| 1479 |
|
| 1480 |
|
| 1481 |
RAM_DEBUG_MESSAGE("Ram Enable 3\n"); |
| 1482 |
do_ram_command(RAM_COMMAND_NOP, 0); |
| 1483 |
|
| 1484 |
|
| 1485 |
RAM_DEBUG_MESSAGE("Ram Enable 4\n"); |
| 1486 |
do_ram_command(RAM_COMMAND_PRECHARGE, 0); |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
RAM_DEBUG_MESSAGE("Ram Enable 5\n"); |
| 1491 |
do_ram_command(RAM_COMMAND_EMRS, |
| 1492 |
SDRAM_EXTMODE_DLL_ENABLE | |
| 1493 |
SDRAM_EXTMODE_DRIVE_NORMAL); |
| 1494 |
|
| 1495 |
|
| 1496 |
RAM_DEBUG_MESSAGE("Ram Enable 6\n"); |
| 1497 |
set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_DLL_RESET); |
| 1498 |
EXTRA_DELAY; |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
DO_DELAY; EXTRA_DELAY; |
| 1504 |
|
| 1505 |
|
| 1506 |
RAM_DEBUG_MESSAGE("Ram Enable 7\n"); |
| 1507 |
do_ram_command(RAM_COMMAND_PRECHARGE, 0); |
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
RAM_DEBUG_MESSAGE("Ram Enable 8\n"); |
| 1512 |
int i; |
| 1513 |
for (i = 0; i < 8; i++) |
| 1514 |
do_ram_command(RAM_COMMAND_CBR, 0); |
| 1515 |
|
| 1516 |
|
| 1517 |
RAM_DEBUG_MESSAGE("Ram Enable 9\n"); |
| 1518 |
set_ram_mode(E7501_SDRAM_MODE | SDRAM_MODE_NORMAL); |
| 1519 |
|
| 1520 |
|
| 1521 |
RAM_DEBUG_MESSAGE("Ram Enable 10\n"); |
| 1522 |
RAM_RESET_DDR_PTR(); |
| 1523 |
EXTRA_DELAY; |
| 1524 |
|
| 1525 |
|
| 1526 |
RAM_DEBUG_MESSAGE("Ram Enable 11\n"); |
| 1527 |
do_ram_command(RAM_COMMAND_NORMAL, 0); |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
configure_e7501_ram_addresses(ctrl, dimm_mask); |
| 1532 |
|
| 1533 |
|
| 1534 |
dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1535 |
dram_controller_mode |= (1 << 29); |
| 1536 |
pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
| 1537 |
EXTRA_DELAY; |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
static void sdram_post_ecc(const struct mem_controller *ctrl) |
| 1545 |
{ |
| 1546 |
|
| 1547 |
uint32_t dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1548 |
dram_controller_mode = pci_read_config32(MCHDEV, DRC); |
| 1549 |
dram_controller_mode |= (1 << 17); |
| 1550 |
pci_write_config32(MCHDEV, DRC, dram_controller_mode); |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
static void sdram_set_spd_registers(const struct mem_controller *ctrl) |
| 1562 |
{ |
| 1563 |
uint8_t dimm_mask; |
| 1564 |
|
| 1565 |
RAM_DEBUG_MESSAGE("Reading SPD data...\n"); |
| 1566 |
|
| 1567 |
dimm_mask = spd_get_supported_dimms(ctrl); |
| 1568 |
|
| 1569 |
if (dimm_mask == 0) { |
| 1570 |
printk(BIOS_DEBUG, "No usable memory for this controller\n"); |
| 1571 |
} else { |
| 1572 |
enable_e7501_clocks(dimm_mask); |
| 1573 |
|
| 1574 |
RAM_DEBUG_MESSAGE("setting based on SPD data...\n"); |
| 1575 |
|
| 1576 |
configure_e7501_row_attributes(ctrl, dimm_mask); |
| 1577 |
configure_e7501_dram_controller_mode(ctrl, dimm_mask); |
| 1578 |
configure_e7501_cas_latency(ctrl, dimm_mask); |
| 1579 |
RAM_RESET_DDR_PTR(); |
| 1580 |
|
| 1581 |
configure_e7501_dram_timing(ctrl, dimm_mask); |
| 1582 |
DO_DELAY; |
| 1583 |
RAM_DEBUG_MESSAGE("done\n"); |
| 1584 |
} |
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
pci_write_config16(MCHDEV, SKPD, dimm_mask); |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
static void sdram_set_registers(const struct mem_controller *ctrl) |
| 1607 |
{ |
| 1608 |
uint32_t dword; |
| 1609 |
uint16_t word; |
| 1610 |
uint8_t byte; |
| 1611 |
|
| 1612 |
ram_set_rcomp_regs(); |
| 1613 |
|
| 1614 |
|
| 1615 |
word = pci_read_config16(MCHDEV, DVNP); |
| 1616 |
word &= ~0x05; |
| 1617 |
pci_write_config16(MCHDEV, DVNP, word); |
| 1618 |
|
| 1619 |
|
| 1620 |
pci_write_config16(MCHDEV, REMAPBASE, 0x03ff); |
| 1621 |
pci_write_config16(MCHDEV, REMAPLIMIT, 0x0); |
| 1622 |
|
| 1623 |
|
| 1624 |
int i; |
| 1625 |
pci_write_config8(MCHDEV, PAM_0, 0x30); |
| 1626 |
for (i = 1; i <= 6; i++) |
| 1627 |
pci_write_config8(MCHDEV, PAM_0 + i, 0x33); |
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
pci_write_config32(MCHDEV, DRB_ROW_0, 0x04030201); |
| 1635 |
pci_write_config32(MCHDEV, DRB_ROW_4, 0x04040404); |
| 1636 |
|
| 1637 |
pci_write_config16(MCHDEV, TOLM, (1<<13)); |
| 1638 |
|
| 1639 |
|
| 1640 |
pci_write_config8(MCHDEV, CKDIS, 0xff); |
| 1641 |
|
| 1642 |
|
| 1643 |
pci_write_config32(MCHDEV, DRA, 0x0); |
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
dword = pci_read_config32(MCHDEV, DRT); |
| 1648 |
dword &= 0xC7F8FFFF; |
| 1649 |
dword |= (0x28<<24)|(0x03<<16); |
| 1650 |
pci_write_config32(MCHDEV, DRT, dword); |
| 1651 |
|
| 1652 |
dword = pci_read_config32(MCHDEV, DRC); |
| 1653 |
dword &= 0xffcef8f7; |
| 1654 |
dword |= 0x00210008; |
| 1655 |
pci_write_config32(MCHDEV, DRC, dword); |
| 1656 |
|
| 1657 |
|
| 1658 |
pci_write_config8(MCHDEV, 0x88, 0x80); |
| 1659 |
|
| 1660 |
|
| 1661 |
byte = pci_read_config8(MCHDEV, 0xd9); |
| 1662 |
byte &= ~0x60; |
| 1663 |
pci_write_config8(MCHDEV, 0xd9, byte); |
| 1664 |
|
| 1665 |
uint8_t revision = pci_read_config8(MCHDEV, 0x08); |
| 1666 |
if (revision >= 3) |
| 1667 |
d060_control(D060_CMD_1); |
| 1668 |
} |
| 1669 |
|
| 1670 |
static int e7505_mch_is_ready(void) |
| 1671 |
{ |
| 1672 |
uint32_t dword = pci_read_config32(MCHDEV, DRC); |
| 1673 |
return !!(dword & DRC_DONE); |
| 1674 |
} |
| 1675 |
|
| 1676 |
#define HOST_BRIDGE PCI_DEV(0, 0, 0) |
| 1677 |
|
| 1678 |
void sdram_initialize(void) |
| 1679 |
{ |
| 1680 |
static const struct mem_controller memctrl[] = { |
| 1681 |
{ |
| 1682 |
.d0 = PCI_DEV(0, 0, 0), |
| 1683 |
.d0f1 = PCI_DEV(0, 0, 1), |
| 1684 |
.channel0 = { 0x50, 0x52, 0, 0 }, |
| 1685 |
.channel1 = { 0x51, 0x53, 0, 0 }, |
| 1686 |
}, |
| 1687 |
}; |
| 1688 |
|
| 1689 |
|
| 1690 |
if (!e7505_mch_is_ready()) { |
| 1691 |
|
| 1692 |
timestamp_add_now(TS_INITRAM_START); |
| 1693 |
|
| 1694 |
sdram_set_registers(memctrl); |
| 1695 |
sdram_set_spd_registers(memctrl); |
| 1696 |
sdram_enable(memctrl); |
| 1697 |
|
| 1698 |
|
| 1699 |
sdram_post_ecc(memctrl); |
| 1700 |
|
| 1701 |
timestamp_add_now(TS_INITRAM_END); |
| 1702 |
} |
| 1703 |
|
| 1704 |
|
| 1705 |
if (CONFIG(SMM_TSEG)) |
| 1706 |
pci_write_config8(HOST_BRIDGE, ESMRAMC, TSEG_SZ_1M | T_EN); |
| 1707 |
|
| 1708 |
printk(BIOS_DEBUG, "SDRAM is up.\n"); |
| 1709 |
} |