Quoting Uwe Hermann uwe@hermann-uwe.de:
/* First check if a DIMM is actually present. */
if (spd_read_byte(device, 2) == 0x4) {
print_debug("Found DIMM in slot ");
print_debug_hex8(i);
print_debug(", setting DRA...\r\n");
dra = 0x00;
/* columns */
col = spd_read_byte(device, 4);
/* data width */
width = spd_read_byte(device, 6);
/* calculate page size in bits */
value = ((1 << col) * width);
/* convert to Kilobytes */
dra = ((value / 8) >> 10);
/* # of banks of DIMM (single or double sided) */
value = spd_read_byte(device, 5);
if (value == 1) {
/* 2KB */
if (dra == 0x2) {
dra = 0xF0;
/* 4KB */
} else if (dra == 0x4) {
dra = 0xF1;
/* 8KB */
} else if (dra == 0x8) {
dra = 0xF2;
/* 16KB */
} else if (dra == 0x10) {
dra = 0xF3;
} else {
print_err("Page size not supported\r\n");
die("HALT\r\n");
}
} else if (value == 2) {
/* 2KB */
if (dra == 0x2) {
dra = 0x00;
/* 4KB */
} else if (dra == 0x4) {
dra = 0x11;
/* 8KB */
} else if (dra == 0x8) {
dra = 0x22;
/* 16KB */
} else if (dra == 0x10) {
dra = 0x33;
} else {
print_err("Page size not supported\r\n");
die("HALT\r\n");
}
This code can be made a lot shorter using a table and a loop, I think.
Uwe.
Uwe, I not really sure how I could use a table and a loop for this but would a switch be ok?
/* # of banks of DIMM (single or double sided) */ value = spd_read_byte(device, 5);
if (value == 1) { switch(dra) { /* 2KB */ case 2: dra = 0xF0; break; /* 4KB */ case 4: dra = 0xF1; break; /* 8KB */ case 8: dra = 0xF2; break; /* 16KB */ case 10: dra = 0xF3; break; default: print_err("Page size not supported\r\n"); die("HALT\r\n"); } } else if (value == 2) { switch(dra) { /* 2KB */ case 2: dra = 0x00; break; /* 4KB */ case 4: dra = 0x11; break; /* 8KB */ case 8: dra = 0x22; break; /* 16KB */ case 10: dra = 0x33; break; default: print_err("Page size not supported\r\n"); die("HALT\r\n"); } }else { print_err("# of banks of DIMM not supported\r\n"); die("HALT\r\n"); }
Thanks - Joe