smbus: refactor SPD SKU (part number) handling

Replace SPD SKU reading code repeated multiple times across
all the parse_spd_* functions with a dedicated read_sku function.

Convert spd_infos.sku from len+data into classic NULL-terminated C-string.
Takes the same space, but simplifies handling. Also, use char instead of
uint8_t so no conversion is needed when printing.

Change the way how the end of part number is handled. Stop on the first
non-ASCII character and then trim all trailing spaces. This allows SKUs
with two (or more) spaces inside the name to be handled properly.

Finally, fix incorrect / inconsistent part number length handling, with
the following end result:
 - parse_spd_sdram: 18 [73-90] (no change)
 - parse_spd_rdram: 18 [73-90] (no change)
 - parse_spd_ddr:   18 [73-90] (no change)
 - parse_spd_ddr2:  18 [73-90] (no change)
 - parse_spd_ddr3:  20+1=21 -> 18 [128-145]
 - parse_spd_ddr4:  20+1=21 -> 20 [329-348]
 - parse_spd_ddr5:  29+1=30 -> 30 [521-550] (technicaly no change)

Before:
      text       data        bss      total filename
     13143       3795         18      16956 build32/system/smbus.o
     11735       4359         18      16112 build64/system/smbus.o

     81705      51133      13088     145926 build32/memtest_shared
     79686      58109     294432     432227 build64/memtest_shared

After:
      text       data        bss      total filename
     10784       3887         18      14689 build32/system/smbus.o
     10486       4399         18      14903 build64/system/smbus.o

     79353      51101      13088     143542 build32/memtest_shared
     78438      58077     294432     430947 build64/memtest_shared

gcc-11.3.0.
This commit is contained in:
01e3
2022-08-26 21:21:20 -07:00
committed by Sam Demeulemeester
parent 0f8981412c
commit 43b0f64ddb
2 changed files with 44 additions and 109 deletions

View File

@@ -93,6 +93,8 @@
#define DDR5_ROUNDING_FACTOR 30
#define ROUNDING_FACTOR 0.9f
#define SPD_SKU_LEN 32
struct pci_smbus_controller {
unsigned vendor;
unsigned device;
@@ -105,8 +107,7 @@ typedef struct spd_infos {
uint16_t jedec_code;
uint32_t module_size;
char *type;
uint8_t sku[32];
uint8_t sku_len;
char sku[SPD_SKU_LEN + 1];
uint8_t XMP;
uint16_t freq;
bool hasECC;