Reorganize struct spd_infos for better alignment (#2), fix left shifts of count > width of type, fix whitespace, improve comments.

This commit is contained in:
Lionel Debroux 2022-03-21 08:00:50 +01:00
parent c2d033b4b4
commit caa07482a0
2 changed files with 52 additions and 52 deletions

View File

@ -287,7 +287,7 @@ static spd_info parse_spd_ddr5(uint8_t smb_idx, uint8_t slot_idx)
// Die per package
if ((sbyte >> 5) > 1 && (sbyte >> 5) <= 5) {
cur_rank *= 1 << (((sbyte >> 5) & 7) - 1);
cur_rank *= 1U << (((sbyte >> 5) & 7) - 1);
}
sbyte = get_spd(smb_idx, slot_idx, 235);
@ -299,11 +299,11 @@ static spd_info parse_spd_ddr5(uint8_t smb_idx, uint8_t slot_idx)
}
// Primary Bus Width per Channel
cur_rank *= 1 << ((sbyte & 3) + 3);
cur_rank *= 1U << ((sbyte & 3) + 3);
// I/O Width
sbyte = get_spd(smb_idx, slot_idx, (sbyte_adr * 4) + 2);
cur_rank /= 1 << (((sbyte >> 5) & 3) + 2);
cur_rank /= 1U << (((sbyte >> 5) & 3) + 2);
// Add current rank to total package size
spdi.module_size += cur_rank;
@ -445,12 +445,12 @@ static spd_info parse_spd_ddr4(uint8_t smb_idx, uint8_t slot_idx)
spdi.sku_len = 0;
// Compute module size in MB with shifts
spdi.module_size = 1 << (
((get_spd(smb_idx, slot_idx, 4) & 0xF) + 5) +
((get_spd(smb_idx, slot_idx, 13) & 0x7) + 3) -
((get_spd(smb_idx, slot_idx, 12) & 0x7) + 2) +
((get_spd(smb_idx, slot_idx, 12) >> 3) & 0x7) +
((get_spd(smb_idx, slot_idx, 6) >> 4) & 0x7)
spdi.module_size = 1U << (
((get_spd(smb_idx, slot_idx, 4) & 0xF) + 5) + // Total SDRAM capacity: (256 Mbits << byte4[3:0] with an oddity for values >= 8) / 1 KB
((get_spd(smb_idx, slot_idx, 13) & 0x7) + 3) - // Primary Bus Width: 8 << byte13[2:0]
((get_spd(smb_idx, slot_idx, 12) & 0x7) + 2) + // SDRAM Device Width: 4 << byte12[2:0]
((get_spd(smb_idx, slot_idx, 12) >> 3) & 0x7) + // Number of Ranks: byte12[5:3]
((get_spd(smb_idx, slot_idx, 6) >> 4) & 0x7) // Die count - 1: byte6[6:4]
);
spdi.hasECC = (((get_spd(smb_idx, slot_idx, 13) >> 3) & 1) == 1);
@ -544,7 +544,7 @@ static spd_info parse_spd_ddr4(uint8_t smb_idx, uint8_t slot_idx)
}
// Module manufacturer
spdi.jedec_code = (get_spd(smb_idx, slot_idx, 320) & 0x1F) << 8;
spdi.jedec_code = ((uint16_t)(get_spd(smb_idx, slot_idx, 320) & 0x1F)) << 8;
spdi.jedec_code |= get_spd(smb_idx, slot_idx, 321) & 0x7F;
// Module SKU
@ -583,11 +583,11 @@ static spd_info parse_spd_ddr3(uint8_t smb_idx, uint8_t slot_idx)
spdi.XMP = 0;
// Compute module size in MB with shifts
spdi.module_size = 1 << (
((get_spd(smb_idx, slot_idx, 4) & 0xF) + 5) +
((get_spd(smb_idx, slot_idx, 8) & 0x7) + 3) -
((get_spd(smb_idx, slot_idx, 7) & 0x7) + 2) +
((get_spd(smb_idx, slot_idx, 7) >> 3) & 0x7)
spdi.module_size = 1U << (
((get_spd(smb_idx, slot_idx, 4) & 0xF) + 5) + // Total SDRAM capacity: (256 Mbits << byte4[3:0]) / 1 KB
((get_spd(smb_idx, slot_idx, 8) & 0x7) + 3) - // Primary Bus Width: 8 << byte8[2:0]
((get_spd(smb_idx, slot_idx, 7) & 0x7) + 2) + // SDRAM Device Width: 4 << byte7[2:0]
((get_spd(smb_idx, slot_idx, 7) >> 3) & 0x7) // Number of Ranks: byte7[5:3]
);
spdi.hasECC = (((get_spd(smb_idx, slot_idx, 8) >> 3) & 1) == 1);
@ -694,7 +694,7 @@ static spd_info parse_spd_ddr3(uint8_t smb_idx, uint8_t slot_idx)
}
// Module manufacturer
spdi.jedec_code= (get_spd(smb_idx, slot_idx, 117) & 0x1F) << 8;
spdi.jedec_code = ((uint16_t)(get_spd(smb_idx, slot_idx, 117) & 0x1F)) << 8;
spdi.jedec_code |= get_spd(smb_idx, slot_idx, 118) & 0x7F;
// Module SKU
@ -767,7 +767,7 @@ static spd_info parse_spd_ddr2(uint8_t smb_idx, uint8_t slot_idx)
float tckns, tns;
uint8_t tbyte;
// Module EPP Detection (we only support Full profiles
// Module EPP Detection (we only support Full profiles)
uint8_t epp_offset = 0;
if (get_spd(smb_idx, slot_idx, 99) == 0x6D && get_spd(smb_idx, slot_idx, 102) == 0xB1) {
epp_offset = (get_spd(smb_idx, slot_idx, 103) & 0x3) * 12;
@ -823,7 +823,7 @@ static spd_info parse_spd_ddr2(uint8_t smb_idx, uint8_t slot_idx)
spdi.tRAS = (uint16_t)(tns/tckns);
// Row Cycle Time
tns = 0;
spdi.tRC = 0;
} else {
// Module Timings (JEDEC)
// CAS# Latency
@ -850,7 +850,7 @@ static spd_info parse_spd_ddr2(uint8_t smb_idx, uint8_t slot_idx)
spdi.tRAS = (uint16_t)(tns/tckns);
// Row Cycle Time
tns = 0;
spdi.tRC = 0;
}
// Module manufacturer
@ -861,7 +861,7 @@ static spd_info parse_spd_ddr2(uint8_t smb_idx, uint8_t slot_idx)
}
}
spdi.jedec_code = (contcode - 64) << 8;
spdi.jedec_code = ((uint16_t)(contcode - 64)) << 8;
spdi.jedec_code |= get_spd(smb_idx, slot_idx, contcode) & 0x7F;
// Module SKU
@ -1065,7 +1065,7 @@ static spd_info parse_spd_rdram(uint8_t smb_idx, uint8_t slot_idx)
}
}
spdi.jedec_code = (contcode - 64) << 8;
spdi.jedec_code = ((uint16_t)(contcode - 64)) << 8;
spdi.jedec_code |= get_spd(smb_idx, slot_idx, contcode) & 0x7F;
// Module SKU

View File

@ -61,13 +61,14 @@ struct pci_smbus_controller{
typedef struct spd_infos {
bool isValid;
uint32_t module_size;
uint8_t slot_num;
uint16_t jedec_code;
uint32_t module_size;
char *type;
char sku[32];
uint8_t sku_len;
uint16_t freq;
uint8_t XMP;
uint16_t freq;
bool hasECC;
uint8_t fab_year;
uint8_t fab_week;
@ -76,7 +77,6 @@ typedef struct spd_infos {
uint16_t tRP;
uint16_t tRAS;
uint16_t tRC;
char *type;
} spd_info;
typedef struct ram_infos {