| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include <bdk.h> |
| 40 |
#include "dram-internal.h" |
| 41 |
|
| 42 |
#include <bdk-minimal.h> |
| 43 |
#include <libbdk-arch/bdk-warn.h> |
| 44 |
#include <libbdk-hal/bdk-config.h> |
| 45 |
#include <libbdk-hal/bdk-twsi.h> |
| 46 |
#include <assert.h> |
| 47 |
#include <ctype.h> |
| 48 |
#include <stdlib.h> |
| 49 |
#include <string.h> |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static uint8_t spd_bufs[4 * 256]; |
| 64 |
int read_entire_spd(bdk_node_t node, dram_config_t *cfg, int lmc, int dimm) |
| 65 |
{ |
| 66 |
|
| 67 |
assert(dimm < 4); |
| 68 |
|
| 69 |
|
| 70 |
if (cfg->config[lmc].dimm_config_table[dimm].spd_ptr) |
| 71 |
return 0; |
| 72 |
if (!cfg->config[lmc].dimm_config_table[dimm].spd_addr) |
| 73 |
return -1; |
| 74 |
|
| 75 |
|
| 76 |
int spd_addr = cfg->config[lmc].dimm_config_table[dimm].spd_addr; |
| 77 |
int bus = spd_addr >> 12; |
| 78 |
int address = spd_addr & 0x7f; |
| 79 |
|
| 80 |
|
| 81 |
int64_t dev_type = bdk_twsix_read_ia(node, bus, address, DDR4_SPD_KEY_BYTE_DEVICE_TYPE, 1, 1); |
| 82 |
if (dev_type < 0) |
| 83 |
return -1; |
| 84 |
|
| 85 |
|
| 86 |
int spd_size = 256; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
assert(spd_size == 256); |
| 94 |
uint8_t *spd_buf = &spd_bufs[dimm * 256]; |
| 95 |
uint32_t *ptr = (uint32_t *)spd_buf; |
| 96 |
|
| 97 |
for (int bank = 0; bank < (spd_size >> 8); bank++) |
| 98 |
{ |
| 99 |
|
| 100 |
if (bank) |
| 101 |
bdk_twsix_write_ia(node, bus, 0x36 | bank, 0, 2, 1, 0); |
| 102 |
int bank_size = 256; |
| 103 |
for (int i = 0; i < bank_size; i += 4) |
| 104 |
{ |
| 105 |
int64_t data = bdk_twsix_read_ia(node, bus, address, i, 4, 1); |
| 106 |
if (data < 0) |
| 107 |
{ |
| 108 |
bdk_error("Failed to read SPD data at 0x%x\n", i + (bank << 8)); |
| 109 |
|
| 110 |
if (bank) |
| 111 |
bdk_twsix_write_ia(node, bus, 0x36 | 0, 0, 2, 1, 0); |
| 112 |
return -1; |
| 113 |
} |
| 114 |
else |
| 115 |
*ptr++ = bdk_be32_to_cpu(data); |
| 116 |
} |
| 117 |
|
| 118 |
if (bank) |
| 119 |
bdk_twsix_write_ia(node, bus, 0x36 | 0, 0, 2, 1, 0); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
cfg->config[lmc].dimm_config_table[dimm].spd_ptr = (void*)spd_buf; |
| 127 |
|
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
int read_spd(bdk_node_t node, const dimm_config_t *dimm_config, int spd_field) |
| 135 |
{ |
| 136 |
|
| 137 |
if (dimm_config->spd_ptr) |
| 138 |
return dimm_config->spd_ptr[spd_field]; |
| 139 |
else if (dimm_config->spd_addr) |
| 140 |
{ |
| 141 |
int data; |
| 142 |
int bus = dimm_config->spd_addr >> 12; |
| 143 |
int address = dimm_config->spd_addr & 0x7f; |
| 144 |
|
| 145 |
|
| 146 |
int bank = (spd_field >> 8) & 1; |
| 147 |
if (bank) { |
| 148 |
bdk_twsix_write_ia(node, bus, 0x36 | bank, 0, 2, 1, 0); |
| 149 |
spd_field %= 256; |
| 150 |
} |
| 151 |
|
| 152 |
data = bdk_twsix_read_ia(node, bus, address, spd_field, 1, 1); |
| 153 |
|
| 154 |
|
| 155 |
if (bank) { |
| 156 |
bdk_twsix_write_ia(node, bus, 0x36 | 0, 0, 2, 1, 0); |
| 157 |
} |
| 158 |
|
| 159 |
return data; |
| 160 |
} |
| 161 |
else |
| 162 |
return -1; |
| 163 |
} |
| 164 |
|
| 165 |
static uint16_t ddr3_crc16(uint8_t *ptr, int count) |
| 166 |
{ |
| 167 |
|
| 168 |
int crc, i; |
| 169 |
crc = 0; |
| 170 |
while (--count >= 0) |
| 171 |
{ |
| 172 |
crc = crc ^ (int)*ptr++ << 8; |
| 173 |
for (i = 0; i < 8; ++i) |
| 174 |
if (crc & 0x8000) |
| 175 |
crc = crc << 1 ^ 0x1021; |
| 176 |
else |
| 177 |
crc = crc << 1; |
| 178 |
} |
| 179 |
return crc & 0xFFFF; |
| 180 |
} |
| 181 |
|
| 182 |
static int validate_spd_checksum_ddr3(bdk_node_t node, int twsi_addr, int silent) |
| 183 |
{ |
| 184 |
uint8_t spd_data[128]; |
| 185 |
int crc_bytes = 126; |
| 186 |
uint16_t crc_comp; |
| 187 |
int i; |
| 188 |
int rv; |
| 189 |
int ret = 1; |
| 190 |
for (i = 0; i < 128; i++) |
| 191 |
{ |
| 192 |
rv = bdk_twsix_read_ia(node, twsi_addr >> 12, twsi_addr & 0x7f, i, 1, 1); |
| 193 |
if (rv < 0) |
| 194 |
return 0; |
| 195 |
spd_data[i] = (uint8_t)rv; |
| 196 |
} |
| 197 |
|
| 198 |
if (spd_data[0] & 0x80) |
| 199 |
crc_bytes = 117; |
| 200 |
|
| 201 |
crc_comp = ddr3_crc16(spd_data, crc_bytes); |
| 202 |
|
| 203 |
if (spd_data[DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE] != (crc_comp & 0xff) || |
| 204 |
spd_data[DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE] != (crc_comp >> 8)) |
| 205 |
{ |
| 206 |
if (!silent) { |
| 207 |
printf("DDR3 SPD CRC error, spd addr: 0x%x, calculated crc: 0x%04x, read crc: 0x%02x%02x\n", |
| 208 |
twsi_addr, crc_comp, |
| 209 |
spd_data[DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE], |
| 210 |
spd_data[DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE]); |
| 211 |
} |
| 212 |
ret = 0; |
| 213 |
} |
| 214 |
return ret; |
| 215 |
} |
| 216 |
|
| 217 |
static int validate_spd_checksum(bdk_node_t node, int twsi_addr, int silent) |
| 218 |
{ |
| 219 |
int rv; |
| 220 |
|
| 221 |
debug_print("Validating DIMM at address 0x%x\n", twsi_addr); |
| 222 |
|
| 223 |
if (!twsi_addr) return 1; |
| 224 |
|
| 225 |
|
| 226 |
rv = bdk_twsix_read_ia(node, twsi_addr >> 12, twsi_addr & 0x7f, 2, 1, 1); |
| 227 |
|
| 228 |
if (rv >= 0xB && rv <= 0xC) |
| 229 |
return validate_spd_checksum_ddr3(node, twsi_addr, silent); |
| 230 |
|
| 231 |
if (!silent) |
| 232 |
printf("Unrecognized DIMM type: 0x%x at spd address: 0x%x\n", |
| 233 |
rv, twsi_addr); |
| 234 |
|
| 235 |
return 0; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
int validate_dimm(bdk_node_t node, const dimm_config_t *dimm_config) |
| 240 |
{ |
| 241 |
int spd_addr; |
| 242 |
|
| 243 |
spd_addr = dimm_config->spd_addr; |
| 244 |
|
| 245 |
debug_print("Validating dimm spd addr: 0x%02x spd ptr: %x\n", |
| 246 |
spd_addr, dimm_config->spd_ptr); |
| 247 |
|
| 248 |
|
| 249 |
if (!spd_addr && !dimm_config->spd_ptr) |
| 250 |
return -1; |
| 251 |
|
| 252 |
{ |
| 253 |
int val0, val1; |
| 254 |
int ddr_type = get_ddr_type(node, dimm_config); |
| 255 |
|
| 256 |
switch (ddr_type) |
| 257 |
{ |
| 258 |
case DDR3_DRAM: |
| 259 |
case DDR4_DRAM: |
| 260 |
|
| 261 |
debug_print("Validating DDR%d DIMM\n", ((dimm_type >> 2) & 3) + 1); |
| 262 |
|
| 263 |
#define DENSITY_BANKS DDR4_SPD_DENSITY_BANKS // same for DDR3 and DDR4 |
| 264 |
#define ROW_COL_BITS DDR4_SPD_ADDRESSING_ROW_COL_BITS // same for DDR3 and DDR4 |
| 265 |
|
| 266 |
val0 = read_spd(node, dimm_config, DENSITY_BANKS); |
| 267 |
val1 = read_spd(node, dimm_config, ROW_COL_BITS); |
| 268 |
if (val0 < 0 && val1 < 0) { |
| 269 |
debug_print("Error reading SPD for DIMM\n"); |
| 270 |
return 0; |
| 271 |
} |
| 272 |
if (val0 == 0xff && val1 == 0xff) { |
| 273 |
ddr_print("Blank or unreadable SPD for DIMM\n"); |
| 274 |
return 0; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
validate_spd_checksum(node, spd_addr, 0); |
| 279 |
break; |
| 280 |
|
| 281 |
case 0x00: |
| 282 |
return 0; |
| 283 |
|
| 284 |
default: |
| 285 |
debug_print("Unknown DIMM type 0x%x for DIMM @ 0x%x\n", |
| 286 |
dimm_type, dimm_config->spd_addr); |
| 287 |
return 0; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
return 1; |
| 292 |
} |
| 293 |
|
| 294 |
int get_dimm_part_number(char *buffer, bdk_node_t node, |
| 295 |
const dimm_config_t *dimm_config, |
| 296 |
int ddr_type) |
| 297 |
{ |
| 298 |
int i; |
| 299 |
int c; |
| 300 |
int skipping = 1; |
| 301 |
int strlen = 0; |
| 302 |
|
| 303 |
#define PART_LIMIT(t) (((t) == DDR4_DRAM) ? 19 : 18) |
| 304 |
#define PART_NUMBER(t) (((t) == DDR4_DRAM) ? DDR4_SPD_MODULE_PART_NUMBER : DDR3_SPD_MODULE_PART_NUMBER) |
| 305 |
|
| 306 |
int limit = PART_LIMIT(ddr_type); |
| 307 |
int offset = PART_NUMBER(ddr_type); |
| 308 |
|
| 309 |
for (i = 0; i < limit; ++i) { |
| 310 |
|
| 311 |
c = (read_spd(node, dimm_config, offset+i) & 0xff); |
| 312 |
if (c == 0) |
| 313 |
break; |
| 314 |
|
| 315 |
|
| 316 |
if (skipping) { |
| 317 |
if (isspace(c)) |
| 318 |
continue; |
| 319 |
else |
| 320 |
skipping = 0; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
buffer[strlen] = c; |
| 325 |
++strlen; |
| 326 |
} |
| 327 |
|
| 328 |
if (strlen > 0) { |
| 329 |
i = strlen - 1; |
| 330 |
while (i >= 0 && isspace((int)buffer[i])) { |
| 331 |
--i; |
| 332 |
--strlen; |
| 333 |
} |
| 334 |
} |
| 335 |
buffer[strlen] = 0; |
| 336 |
|
| 337 |
return strlen; |
| 338 |
} |
| 339 |
|
| 340 |
uint32_t get_dimm_serial_number(bdk_node_t node, const dimm_config_t *dimm_config, int ddr_type) |
| 341 |
{ |
| 342 |
uint32_t serial_number = 0; |
| 343 |
int offset; |
| 344 |
|
| 345 |
#define SERIAL_NUMBER(t) (((t) == DDR4_DRAM) ? DDR4_SPD_MODULE_SERIAL_NUMBER : DDR3_SPD_MODULE_SERIAL_NUMBER) |
| 346 |
|
| 347 |
offset = SERIAL_NUMBER(ddr_type); |
| 348 |
|
| 349 |
for (int i = 0, j = 24; i < 4; ++i, j -= 8) { |
| 350 |
serial_number |= ((read_spd(node, dimm_config, offset + i) & 0xff) << j); |
| 351 |
} |
| 352 |
|
| 353 |
return serial_number; |
| 354 |
} |
| 355 |
|
| 356 |
static uint32_t get_dimm_checksum(bdk_node_t node, const dimm_config_t *dimm_config, int ddr_type) |
| 357 |
{ |
| 358 |
uint32_t spd_chksum; |
| 359 |
|
| 360 |
#define LOWER_NIBBLE(t) (((t) == DDR4_DRAM) ? DDR4_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE : DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE) |
| 361 |
#define UPPER_NIBBLE(t) (((t) == DDR4_DRAM) ? DDR4_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE : DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE) |
| 362 |
|
| 363 |
spd_chksum = 0xff & read_spd(node, dimm_config, LOWER_NIBBLE(ddr_type)); |
| 364 |
spd_chksum |= ((0xff & read_spd(node, dimm_config, UPPER_NIBBLE(ddr_type))) << 8); |
| 365 |
|
| 366 |
return spd_chksum; |
| 367 |
} |
| 368 |
|
| 369 |
static |
| 370 |
void report_common_dimm(bdk_node_t node, const dimm_config_t *dimm_config, int dimm, |
| 371 |
const char **dimm_types, int ddr_type, const char *volt_str, |
| 372 |
int ddr_interface_num, int num_ranks, int dram_width, int dimm_size_mb) |
| 373 |
{ |
| 374 |
int spd_ecc; |
| 375 |
unsigned spd_module_type; |
| 376 |
uint32_t serial_number; |
| 377 |
char part_number[21]; |
| 378 |
const char *sn_str; |
| 379 |
|
| 380 |
spd_module_type = get_dimm_module_type(node, dimm_config, ddr_type); |
| 381 |
spd_ecc = get_dimm_ecc(node, dimm_config, ddr_type); |
| 382 |
|
| 383 |
(void) get_dimm_part_number(part_number, node, dimm_config, ddr_type); |
| 384 |
|
| 385 |
serial_number = get_dimm_serial_number(node, dimm_config, ddr_type); |
| 386 |
if ((serial_number != 0) && (serial_number != 0xffffffff)) { |
| 387 |
sn_str = "s/n"; |
| 388 |
} else { |
| 389 |
serial_number = get_dimm_checksum(node, dimm_config, ddr_type); |
| 390 |
sn_str = "chksum"; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
printf("N%d.LMC%d.DIMM%d: %d MB, DDR%d %s %dRx%d %s, p/n: %s, %s: %u, %s\n", |
| 395 |
node, ddr_interface_num, dimm, dimm_size_mb, ddr_type, |
| 396 |
dimm_types[spd_module_type], num_ranks, dram_width, |
| 397 |
(spd_ecc ? "ECC" : "non-ECC"), part_number, |
| 398 |
sn_str, serial_number, volt_str); |
| 399 |
} |
| 400 |
|
| 401 |
const char *ddr3_dimm_types[16] = { |
| 402 |
"Undefined", |
| 403 |
"RDIMM", |
| 404 |
"UDIMM", |
| 405 |
"SO-DIMM", |
| 406 |
"Micro-DIMM", |
| 407 |
"Mini-RDIMM", |
| 408 |
"Mini-UDIMM", |
| 409 |
"Mini-CDIMM", |
| 410 |
"72b-SO-UDIMM", |
| 411 |
"72b-SO-RDIMM", |
| 412 |
"72b-SO-CDIMM", |
| 413 |
"LRDIMM", |
| 414 |
"16b-SO-DIMM", |
| 415 |
"32b-SO-DIMM", |
| 416 |
"Reserved", |
| 417 |
"Reserved" |
| 418 |
}; |
| 419 |
|
| 420 |
static |
| 421 |
void report_ddr3_dimm(bdk_node_t node, const dimm_config_t *dimm_config, |
| 422 |
int dimm, int ddr_interface_num, int num_ranks, |
| 423 |
int dram_width, int dimm_size_mb) |
| 424 |
{ |
| 425 |
int spd_voltage; |
| 426 |
const char *volt_str = "unknown voltage"; |
| 427 |
|
| 428 |
spd_voltage = read_spd(node, dimm_config, DDR3_SPD_NOMINAL_VOLTAGE); |
| 429 |
if ((spd_voltage == 0) || (spd_voltage & 3)) |
| 430 |
volt_str = "1.5V"; |
| 431 |
if (spd_voltage & 2) |
| 432 |
volt_str = "1.35V"; |
| 433 |
if (spd_voltage & 4) |
| 434 |
volt_str = "1.2xV"; |
| 435 |
|
| 436 |
report_common_dimm(node, dimm_config, dimm, ddr3_dimm_types, |
| 437 |
DDR3_DRAM, volt_str, ddr_interface_num, |
| 438 |
num_ranks, dram_width, dimm_size_mb); |
| 439 |
} |
| 440 |
|
| 441 |
const char *ddr4_dimm_types[16] = { |
| 442 |
"Extended", |
| 443 |
"RDIMM", |
| 444 |
"UDIMM", |
| 445 |
"SO-DIMM", |
| 446 |
"LRDIMM", |
| 447 |
"Mini-RDIMM", |
| 448 |
"Mini-UDIMM", |
| 449 |
"Reserved", |
| 450 |
"72b-SO-RDIMM", |
| 451 |
"72b-SO-UDIMM", |
| 452 |
"Reserved", |
| 453 |
"Reserved", |
| 454 |
"16b-SO-DIMM", |
| 455 |
"32b-SO-DIMM", |
| 456 |
"Reserved", |
| 457 |
"Reserved" |
| 458 |
}; |
| 459 |
|
| 460 |
static |
| 461 |
void report_ddr4_dimm(bdk_node_t node, const dimm_config_t *dimm_config, |
| 462 |
int dimm, int ddr_interface_num, int num_ranks, |
| 463 |
int dram_width, int dimm_size_mb) |
| 464 |
{ |
| 465 |
int spd_voltage; |
| 466 |
const char *volt_str = "unknown voltage"; |
| 467 |
|
| 468 |
spd_voltage = read_spd(node, dimm_config, DDR4_SPD_MODULE_NOMINAL_VOLTAGE); |
| 469 |
if ((spd_voltage == 0x01) || (spd_voltage & 0x02)) |
| 470 |
volt_str = "1.2V"; |
| 471 |
if ((spd_voltage == 0x04) || (spd_voltage & 0x08)) |
| 472 |
volt_str = "TBD1 V"; |
| 473 |
if ((spd_voltage == 0x10) || (spd_voltage & 0x20)) |
| 474 |
volt_str = "TBD2 V"; |
| 475 |
|
| 476 |
report_common_dimm(node, dimm_config, dimm, ddr4_dimm_types, |
| 477 |
DDR4_DRAM, volt_str, ddr_interface_num, |
| 478 |
num_ranks, dram_width, dimm_size_mb); |
| 479 |
} |
| 480 |
|
| 481 |
void report_dimm(bdk_node_t node, const dimm_config_t *dimm_config, |
| 482 |
int dimm, int ddr_interface_num, int num_ranks, |
| 483 |
int dram_width, int dimm_size_mb) |
| 484 |
{ |
| 485 |
int ddr_type; |
| 486 |
|
| 487 |
|
| 488 |
ddr_type = get_ddr_type(node, dimm_config); |
| 489 |
|
| 490 |
if (ddr_type == DDR4_DRAM) |
| 491 |
report_ddr4_dimm(node, dimm_config, dimm, ddr_interface_num, |
| 492 |
num_ranks, dram_width, dimm_size_mb); |
| 493 |
else |
| 494 |
report_ddr3_dimm(node, dimm_config, dimm, ddr_interface_num, |
| 495 |
num_ranks, dram_width, dimm_size_mb); |
| 496 |
} |
| 497 |
|
| 498 |
static int |
| 499 |
get_ddr4_spd_speed(bdk_node_t node, const dimm_config_t *dimm_config) |
| 500 |
{ |
| 501 |
int spdMTB = 125; |
| 502 |
int spdFTB = 1; |
| 503 |
|
| 504 |
int tCKAVGmin |
| 505 |
= spdMTB * read_spd(node, dimm_config, DDR4_SPD_MINIMUM_CYCLE_TIME_TCKAVGMIN) |
| 506 |
+ spdFTB * (signed char) read_spd(node, dimm_config, DDR4_SPD_MIN_CYCLE_TIME_FINE_TCKAVGMIN); |
| 507 |
|
| 508 |
return pretty_psecs_to_mts(tCKAVGmin); |
| 509 |
} |
| 510 |
|
| 511 |
static int |
| 512 |
get_ddr3_spd_speed(bdk_node_t node, const dimm_config_t *dimm_config) |
| 513 |
{ |
| 514 |
int spd_mtb_dividend = 0xff & read_spd(node, dimm_config, DDR3_SPD_MEDIUM_TIMEBASE_DIVIDEND); |
| 515 |
int spd_mtb_divisor = 0xff & read_spd(node, dimm_config, DDR3_SPD_MEDIUM_TIMEBASE_DIVISOR); |
| 516 |
int spd_tck_min = 0xff & read_spd(node, dimm_config, DDR3_SPD_MINIMUM_CYCLE_TIME_TCKMIN); |
| 517 |
|
| 518 |
short ftb_Dividend = read_spd(node, dimm_config, DDR3_SPD_FINE_TIMEBASE_DIVIDEND_DIVISOR) >> 4; |
| 519 |
short ftb_Divisor = read_spd(node, dimm_config, DDR3_SPD_FINE_TIMEBASE_DIVIDEND_DIVISOR) & 0xf; |
| 520 |
|
| 521 |
ftb_Divisor = (ftb_Divisor == 0) ? 1 : ftb_Divisor; |
| 522 |
|
| 523 |
int mtb_psec = spd_mtb_dividend * 1000 / spd_mtb_divisor; |
| 524 |
int tCKmin = mtb_psec * spd_tck_min; |
| 525 |
tCKmin += ftb_Dividend * |
| 526 |
(signed char) read_spd(node, dimm_config, DDR3_SPD_MINIMUM_CYCLE_TIME_FINE_TCKMIN) |
| 527 |
/ ftb_Divisor; |
| 528 |
|
| 529 |
return pretty_psecs_to_mts(tCKmin); |
| 530 |
} |
| 531 |
|
| 532 |
static int |
| 533 |
speed_bin_down(int speed) |
| 534 |
{ |
| 535 |
if (speed == 2133) |
| 536 |
return 1866; |
| 537 |
else if (speed == 1866) |
| 538 |
return 1600; |
| 539 |
else |
| 540 |
return speed; |
| 541 |
} |
| 542 |
|
| 543 |
int |
| 544 |
dram_get_default_spd_speed(bdk_node_t node, const ddr_configuration_t *ddr_config) |
| 545 |
{ |
| 546 |
int lmc, dimm; |
| 547 |
int speed, ret_speed = 0; |
| 548 |
int ddr_type = get_ddr_type(node, &ddr_config[0].dimm_config_table[0]); |
| 549 |
int dimm_speed[8], dimm_count = 0; |
| 550 |
int dimms_per_lmc = 0; |
| 551 |
|
| 552 |
memset (dimm_speed, 0, sizeof(dimm_speed)); |
| 553 |
|
| 554 |
for (lmc = 0; lmc < 4; lmc++) { |
| 555 |
for (dimm = 0; dimm < DDR_CFG_T_MAX_DIMMS; dimm++) { |
| 556 |
const dimm_config_t *dimm_config = &ddr_config[lmc].dimm_config_table[dimm]; |
| 557 |
if (dimm_config->spd_addr || dimm_config->spd_ptr) |
| 558 |
{ |
| 559 |
speed = (ddr_type == DDR4_DRAM) |
| 560 |
? get_ddr4_spd_speed(node, dimm_config) |
| 561 |
: get_ddr3_spd_speed(node, dimm_config); |
| 562 |
printf("N%d.LMC%d.DIMM%d: SPD speed %d\n", node, lmc, dimm, speed); |
| 563 |
dimm_speed[dimm_count] = speed; |
| 564 |
dimm_count++; |
| 565 |
if (lmc == 0) |
| 566 |
dimms_per_lmc++; |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
speed = dimm_speed[0]; |
| 573 |
for (dimm = 1; dimm < dimm_count; dimm++) { |
| 574 |
if (dimm_speed[dimm] != speed) { |
| 575 |
ret_speed = -1; |
| 576 |
goto finish_up; |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
if (speed >= 2400) |
| 582 |
speed = 2133; |
| 583 |
|
| 584 |
|
| 585 |
if (dimms_per_lmc > 1) |
| 586 |
speed = speed_bin_down(speed); |
| 587 |
|
| 588 |
|
| 589 |
bdk_config_set_int(speed, BDK_CONFIG_DDR_SPEED, node); |
| 590 |
|
| 591 |
|
| 592 |
if (speed == 2133) |
| 593 |
speed = 2100; |
| 594 |
else if (speed == 1866) |
| 595 |
speed = 1880; |
| 596 |
|
| 597 |
|
| 598 |
ret_speed = mts_to_hertz(speed); |
| 599 |
|
| 600 |
finish_up: |
| 601 |
printf("N%d: Returning default SPD speed %d\n", node, ret_speed); |
| 602 |
return ret_speed; |
| 603 |
} |