mb/google/auron: Factor out SPD indexing
The code to read the SPD file and index it is not variant-specific. Change-Id: Iaee0a77934a45c65bf32dd0dba23cec654abc0b9 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/49773 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Reviewed-by: Michael Niewöhner <foss@mniewoehner.de>
This commit is contained in:
parent
e23b0abe30
commit
292a764141
|
@ -19,7 +19,7 @@
|
|||
#define SPD_PART_OFF 128
|
||||
#define SPD_PART_LEN 18
|
||||
|
||||
void mainboard_print_spd_info(uint8_t spd[])
|
||||
static void mainboard_print_spd_info(uint8_t spd[])
|
||||
{
|
||||
const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
|
||||
const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 };
|
||||
|
@ -68,3 +68,28 @@ void mainboard_print_spd_info(uint8_t spd[])
|
|||
capmb / 8 * busw / devw * ranks);
|
||||
}
|
||||
}
|
||||
|
||||
void fill_spd_for_index(uint8_t spd[], unsigned int spd_index)
|
||||
{
|
||||
size_t spd_file_len;
|
||||
uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
memcpy(spd, spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (spd[0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(spd);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ void variant_romstage_entry(struct romstage_params *rp);
|
|||
void lan_init(void);
|
||||
|
||||
void mainboard_fill_spd_data(struct pei_data *pei_data);
|
||||
void mainboard_print_spd_info(uint8_t spd[]);
|
||||
void fill_spd_for_index(uint8_t spd[], unsigned int index);
|
||||
|
||||
#define SPD_LEN 256
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
};
|
||||
int spd_gpio[3];
|
||||
int spd_index;
|
||||
size_t spd_file_len;
|
||||
char *spd_file;
|
||||
|
||||
spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
|
||||
spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
|
||||
|
@ -41,31 +39,12 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
spd_bits[1], spd_gpio[1],
|
||||
spd_bits[0], spd_gpio[0]);
|
||||
|
||||
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
fill_spd_for_index(pei_data->spd_data[0][0], spd_index);
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
|
||||
memcpy(pei_data->spd_data[0][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
/* Index 0-2 are 4GB config with both CH0 and CH1.
|
||||
* Index 4-6 are 2GB config with CH0 only. */
|
||||
if (spd_index > 3)
|
||||
pei_data->dimm_channel1_disabled = 3;
|
||||
else
|
||||
memcpy(pei_data->spd_data[1][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (pei_data->spd_data[0][0][0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(pei_data->spd_data[0][0]);
|
||||
memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
};
|
||||
int spd_gpio[3];
|
||||
int spd_index;
|
||||
size_t spd_file_len;
|
||||
char *spd_file;
|
||||
|
||||
spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
|
||||
spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
|
||||
|
@ -41,31 +39,12 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
spd_bits[1], spd_gpio[1],
|
||||
spd_bits[0], spd_gpio[0]);
|
||||
|
||||
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
fill_spd_for_index(pei_data->spd_data[0][0], spd_index);
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
|
||||
memcpy(pei_data->spd_data[0][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
/* Index 0-2 are 4GB config with both CH0 and CH1.
|
||||
* Index 4-6 are 2GB config with CH0 only. */
|
||||
if (spd_index > 3)
|
||||
pei_data->dimm_channel1_disabled = 3;
|
||||
else
|
||||
memcpy(pei_data->spd_data[1][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (pei_data->spd_data[0][0][0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(pei_data->spd_data[0][0]);
|
||||
memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
};
|
||||
int spd_gpio[3];
|
||||
int spd_index;
|
||||
size_t spd_file_len;
|
||||
char *spd_file;
|
||||
|
||||
spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
|
||||
spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
|
||||
|
@ -41,31 +39,12 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
spd_bits[1], spd_gpio[1],
|
||||
spd_bits[0], spd_gpio[0]);
|
||||
|
||||
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
fill_spd_for_index(pei_data->spd_data[0][0], spd_index);
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
|
||||
memcpy(pei_data->spd_data[0][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
/* Index 0-2 are 4GB config with both CH0 and CH1.
|
||||
* Index 4-6 are 2GB config with CH0 only. */
|
||||
if (spd_index > 3)
|
||||
pei_data->dimm_channel1_disabled = 3;
|
||||
else
|
||||
memcpy(pei_data->spd_data[1][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (pei_data->spd_data[0][0][0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(pei_data->spd_data[0][0]);
|
||||
memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,6 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
};
|
||||
int spd_gpio[4];
|
||||
int spd_index;
|
||||
size_t spd_file_len;
|
||||
char *spd_file;
|
||||
|
||||
spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
|
||||
spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
|
||||
|
@ -46,32 +44,12 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
spd_bits[1], spd_gpio[1],
|
||||
spd_bits[0], spd_gpio[0]);
|
||||
|
||||
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
|
||||
/* CH0 */
|
||||
memcpy(pei_data->spd_data[0][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
fill_spd_for_index(pei_data->spd_data[0][0], spd_index);
|
||||
|
||||
/* CH1 not used in 2GB configurations */
|
||||
if (!((spd_index == 0b0000) || (spd_index == 0b0011) ||
|
||||
(spd_index == 0b1010))) {
|
||||
memcpy(pei_data->spd_data[1][0],
|
||||
spd_file + (spd_index * SPD_LEN), SPD_LEN);
|
||||
memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
|
||||
}
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (pei_data->spd_data[0][0][0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(pei_data->spd_data[0][0]);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,6 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
};
|
||||
int spd_gpio[4];
|
||||
int spd_index;
|
||||
size_t spd_file_len;
|
||||
char *spd_file;
|
||||
|
||||
spd_gpio[0] = get_gpio(spd_bits[0]);
|
||||
spd_gpio[1] = get_gpio(spd_bits[1]);
|
||||
|
@ -44,26 +42,8 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
|
|||
spd_bits[3], spd_gpio[3], spd_bits[2], spd_gpio[2],
|
||||
spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]);
|
||||
|
||||
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
||||
if (!spd_file)
|
||||
die("SPD data not found.");
|
||||
|
||||
if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
|
||||
printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
|
||||
spd_index = 0;
|
||||
}
|
||||
|
||||
if (spd_file_len < SPD_LEN)
|
||||
die("Missing SPD data.");
|
||||
fill_spd_for_index(pei_data->spd_data[0][0], spd_index);
|
||||
|
||||
/* Assume same memory in both channels */
|
||||
spd_index *= SPD_LEN;
|
||||
memcpy(pei_data->spd_data[0][0], spd_file + spd_index, SPD_LEN);
|
||||
memcpy(pei_data->spd_data[1][0], spd_file + spd_index, SPD_LEN);
|
||||
|
||||
/* Make sure a valid SPD was found */
|
||||
if (pei_data->spd_data[0][0][0] == 0)
|
||||
die("Invalid SPD data.");
|
||||
|
||||
mainboard_print_spd_info(pei_data->spd_data[0][0]);
|
||||
memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue