SPD improvements

This commit is contained in:
RichardG867
2020-03-27 12:11:00 -03:00
parent 80356a9b85
commit bc606a9911

View File

@@ -48,7 +48,6 @@ static uint8_t spd_read_byte_cmd(uint8_t addr, uint8_t cmd, void *priv);
static void spd_write_byte(uint8_t addr, uint8_t val, void *priv); static void spd_write_byte(uint8_t addr, uint8_t val, void *priv);
#define ENABLE_SPD_LOG 1
#ifdef ENABLE_SPD_LOG #ifdef ENABLE_SPD_LOG
int spd_do_log = ENABLE_SPD_LOG; int spd_do_log = ENABLE_SPD_LOG;
@@ -153,13 +152,13 @@ void
spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
{ {
uint8_t slot, slot_count, vslot, next_empty_vslot, i, split; uint8_t slot, slot_count, vslot, next_empty_vslot, i, split;
uint16_t min_size, total_size, vslots[SPD_MAX_SLOTS]; uint16_t min_module_size, total_size, vslots[SPD_MAX_SLOTS];
spd_sdram_t *sdram_data; spd_sdram_t *sdram_data;
/* determine the minimum module size for this RAM type */ /* determine the minimum module size for this RAM type */
switch (ram_type) { switch (ram_type) {
case SPD_TYPE_SDRAM: case SPD_TYPE_SDRAM:
min_size = SPD_MIN_SIZE_SDRAM; min_module_size = SPD_MIN_SIZE_SDRAM;
break; break;
default: default:
@@ -177,12 +176,16 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
} }
/* populate vslots with modules in power-of-2 capacities */ /* populate vslots with modules in power-of-2 capacities */
total_size = mem_size / 1024; total_size = (mem_size >> 10);
for (vslot = 0; vslot < slot_count && total_size; vslot++) { for (vslot = 0; vslot < slot_count && total_size; vslot++) {
/* populate slot */ /* populate slot */
vslots[vslot] = (1 << log2_ui16(MIN(total_size, max_module_size))); vslots[vslot] = (1 << log2_ui16(MIN(total_size, max_module_size)));
spd_log("SPD: assigning %d MB to vslot %d\n", vslots[vslot], vslot); if (total_size >= vslots[vslot]) {
total_size -= vslots[vslot]; spd_log("SPD: vslot %d = %d MB\n", vslot, vslots[vslot]);
total_size -= vslots[vslot];
} else {
break;
}
} }
if (total_size > 0) /* did we populate everything? */ if (total_size > 0) /* did we populate everything? */
@@ -194,7 +197,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
/* look for a module to split */ /* look for a module to split */
split = 0; split = 0;
for (vslot = 0; vslot < slot_count; vslot++) { for (vslot = 0; vslot < slot_count; vslot++) {
if (vslots[vslot] < (min_size * 2)) if (vslots[vslot] < (min_module_size << 1))
continue; /* no module here or module is too small to be split */ continue; /* no module here or module is too small to be split */
/* find next empty vslot */ /* find next empty vslot */
@@ -207,8 +210,8 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
break; /* no empty vslots left */ break; /* no empty vslots left */
/* split the module into its own vslot and the next empty vslot */ /* split the module into its own vslot and the next empty vslot */
spd_log("SPD: splitting vslot %d (%d MB) into %d and %d (%d MB each)\n", vslot, vslots[vslot], vslot, next_empty_vslot, vslots[vslot] >> 1); spd_log("SPD: splitting vslot %d (%d MB) into %d and %d (%d MB each)\n", vslot, vslots[vslot], vslot, next_empty_vslot, (vslots[vslot] >> 1));
vslots[vslot] = vslots[next_empty_vslot] = vslots[vslot] >> 1; vslots[vslot] = vslots[next_empty_vslot] = (vslots[vslot] >> 1);
split = 1; split = 1;
} }
@@ -219,14 +222,11 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
/* register SPD devices and populate their data according to the vslots */ /* register SPD devices and populate their data according to the vslots */
vslot = 0; vslot = 0;
for (slot = 0; slot < SPD_MAX_SLOTS; slot++) { for (slot = 0; slot < SPD_MAX_SLOTS && vslots[vslot]; slot++) {
if (!(slot_mask & (1 << slot))) if (!(slot_mask & (1 << slot)))
continue; /* slot disabled */ continue; /* slot disabled */
if (!vslots[vslot]) spd_log("SPD: registering slot %d = vslot %d = %d MB\n", slot, vslot, vslots[vslot]);
break; /* no slots left to fill */
spd_log("SPD: registering slot %d = %d MB\n", slot, vslots[vslot]);
spd_devices[slot] = (device_t *)malloc(sizeof(device_t)); spd_devices[slot] = (device_t *)malloc(sizeof(device_t));
memset(spd_devices[slot], 0, sizeof(device_t)); memset(spd_devices[slot], 0, sizeof(device_t));
@@ -266,7 +266,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
sdram_data->spd_rev = 0x12; sdram_data->spd_rev = 0x12;
sprintf(sdram_data->part_no, "86Box-SDR-%03dM", vslots[vslot]); sprintf(sdram_data->part_no, "86Box-SDR-%03dM", vslots[vslot]);
sdram_data->mfg_year = 0x20; sdram_data->mfg_year = 0x20;
sdram_data->mfg_week = 0x01; sdram_data->mfg_week = 0x13;
sdram_data->freq = 100; sdram_data->freq = 100;
sdram_data->features = 0xFF; sdram_data->features = 0xFF;