From 77ef99be22e69982a88bd77cafdb1a737fc2f185 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Thu, 11 Feb 2021 14:25:44 +0100 Subject: mb/google/slippy: Factor out SPD indexing The code to read the SPD file and index it is not variant-specific. Change-Id: Ifaedc39b683901b60abbb1d984f1d38c1ed364e2 Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/50542 Reviewed-by: Arthur Heymans Tested-by: build bot (Jenkins) --- src/mainboard/google/slippy/romstage.c | 29 ++++++++++++++++++- src/mainboard/google/slippy/variant.h | 4 +++ .../google/slippy/variants/falco/romstage.c | 27 ++---------------- .../google/slippy/variants/leon/romstage.c | 26 ++--------------- .../google/slippy/variants/peppy/romstage.c | 33 ++++------------------ .../google/slippy/variants/wolf/romstage.c | 27 ++---------------- 6 files changed, 43 insertions(+), 103 deletions(-) (limited to 'src/mainboard/google/slippy') diff --git a/src/mainboard/google/slippy/romstage.c b/src/mainboard/google/slippy/romstage.c index fb32b48e8e..89eaab986b 100644 --- a/src/mainboard/google/slippy/romstage.c +++ b/src/mainboard/google/slippy/romstage.c @@ -1,9 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include +#include +#include #include #include #include +#include +#include + #include "variant.h" void mainboard_config_rcba(void) @@ -46,3 +50,26 @@ void mb_get_spd_map(uint8_t spd_map[4]) spd_map[0] = 0xff; spd_map[2] = 0xff; } + +unsigned int fill_spd_for_index(uint8_t spd[], unsigned int spd_index) +{ + uint8_t *spd_file; + size_t spd_file_len; + + printk(BIOS_DEBUG, "SPD index %d\n", spd_index); + 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."); + + memcpy(spd, spd_file + (spd_index * SPD_LEN), SPD_LEN); + + return spd_index; +} diff --git a/src/mainboard/google/slippy/variant.h b/src/mainboard/google/slippy/variant.h index bfcf855848..f1aa6ab768 100644 --- a/src/mainboard/google/slippy/variant.h +++ b/src/mainboard/google/slippy/variant.h @@ -3,4 +3,8 @@ #ifndef VARIANT_H #define VARIANT_H +#include + +unsigned int fill_spd_for_index(uint8_t spd[], unsigned int index); + #endif diff --git a/src/mainboard/google/slippy/variants/falco/romstage.c b/src/mainboard/google/slippy/variants/falco/romstage.c index 8870faed2d..21a4ec62be 100644 --- a/src/mainboard/google/slippy/variants/falco/romstage.c +++ b/src/mainboard/google/slippy/variants/falco/romstage.c @@ -1,11 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include #include -#include -#include -#include -#include #include #include #include @@ -15,33 +10,15 @@ void copy_spd(struct pei_data *peid) { const int gpio_vector[] = {13, 9, 47, -1}; - int spd_index = get_gpios(gpio_vector); - char *spd_file; - size_t spd_file_len; - size_t spd_len = sizeof(peid->spd_data[0]); - printk(BIOS_DEBUG, "SPD index %d\n", spd_index); - 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."); - - memcpy(peid->spd_data[0], spd_file + (spd_index * spd_len), spd_len); + unsigned int spd_index = fill_spd_for_index(peid->spd_data[0], get_gpios(gpio_vector)); /* Index 0-2,6 are 4GB config with both CH0 and CH1 * Index 3-5,7 are 2GB config with CH0 only */ switch (spd_index) { case 0: case 1: case 2: case 6: - memcpy(peid->spd_data[1], - spd_file + (spd_index * spd_len), spd_len); + memcpy(peid->spd_data[1], peid->spd_data[0], SPD_LEN); break; case 3: case 4: case 5: case 7: peid->dimm_channel1_disabled = 3; diff --git a/src/mainboard/google/slippy/variants/leon/romstage.c b/src/mainboard/google/slippy/variants/leon/romstage.c index 49961d93df..938590b4f0 100644 --- a/src/mainboard/google/slippy/variants/leon/romstage.c +++ b/src/mainboard/google/slippy/variants/leon/romstage.c @@ -1,10 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include -#include -#include -#include -#include #include #include #include @@ -14,25 +10,8 @@ void copy_spd(struct pei_data *peid) { const int gpio_vector[] = {13, 9, 47, -1}; - int spd_index = get_gpios(gpio_vector); - char *spd_file; - size_t spd_file_len; - size_t spd_len = sizeof(peid->spd_data[0]); - printk(BIOS_DEBUG, "SPD index %d\n", spd_index); - 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."); - - memcpy(peid->spd_data[0], spd_file + (spd_index * spd_len), spd_len); + unsigned int spd_index = fill_spd_for_index(peid->spd_data[0], get_gpios(gpio_vector)); /* Limiting to a single dimm for 2GB configuration * Identified by bit 3 @@ -40,8 +19,7 @@ void copy_spd(struct pei_data *peid) if (spd_index & 0x4) peid->dimm_channel1_disabled = 3; else - memcpy(peid->spd_data[1], - spd_file + (spd_index * spd_len), spd_len); + memcpy(peid->spd_data[1], peid->spd_data[0], SPD_LEN); } const struct usb2_port_setting mainboard_usb2_ports[MAX_USB2_PORTS] = { diff --git a/src/mainboard/google/slippy/variants/peppy/romstage.c b/src/mainboard/google/slippy/variants/peppy/romstage.c index 8a3486a72c..02b47db97f 100644 --- a/src/mainboard/google/slippy/variants/peppy/romstage.c +++ b/src/mainboard/google/slippy/variants/peppy/romstage.c @@ -2,11 +2,7 @@ #include #include -#include -#include -#include -#include "ec/google/chromeec/ec.h" -#include +#include #include #include #include @@ -17,27 +13,10 @@ void copy_spd(struct pei_data *peid) { const int gpio_vector[] = {13, 9, 47, -1}; - int spd_index = get_gpios(gpio_vector); - char *spd_file; - size_t spd_file_len; - size_t spd_len = sizeof(peid->spd_data[0]); - uint32_t board_version = PEPPY_BOARD_VERSION_PROTO; - - printk(BIOS_DEBUG, "SPD index %d\n", spd_index); - spd_file = cbfs_map("spd.bin", &spd_file_len); - if (!spd_file) - die("SPD data not found."); - - if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) { - 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(peid->spd_data[0], spd_file + (spd_index * spd_len), spd_len); + unsigned int spd_index = fill_spd_for_index(peid->spd_data[0], get_gpios(gpio_vector)); + uint32_t board_version = PEPPY_BOARD_VERSION_PROTO; google_chromeec_get_board_version(&board_version); switch (board_version) { case PEPPY_BOARD_VERSION_PROTO: @@ -45,8 +24,7 @@ void copy_spd(struct pei_data *peid) if (spd_index == 0) peid->dimm_channel1_disabled = 3; else - memcpy(peid->spd_data[1], - spd_file + (spd_index * spd_len), spd_len); + memcpy(peid->spd_data[1], peid->spd_data[0], SPD_LEN); break; case PEPPY_BOARD_VERSION_EVT: @@ -56,8 +34,7 @@ void copy_spd(struct pei_data *peid) if (spd_index > 3) peid->dimm_channel1_disabled = 3; else - memcpy(peid->spd_data[1], - spd_file + (spd_index * spd_len), spd_len); + memcpy(peid->spd_data[1], peid->spd_data[0], SPD_LEN); break; } } diff --git a/src/mainboard/google/slippy/variants/wolf/romstage.c b/src/mainboard/google/slippy/variants/wolf/romstage.c index 9080f46c49..939d58403f 100644 --- a/src/mainboard/google/slippy/variants/wolf/romstage.c +++ b/src/mainboard/google/slippy/variants/wolf/romstage.c @@ -1,11 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include -#include -#include -#include -#include "ec/google/chromeec/ec.h" -#include #include #include #include @@ -15,33 +10,15 @@ void copy_spd(struct pei_data *peid) { const int gpio_vector[] = {13, 9, 47, -1}; - int spd_index = get_gpios(gpio_vector); - char *spd_file; - size_t spd_file_len; - size_t spd_len = sizeof(peid->spd_data[0]); - printk(BIOS_DEBUG, "SPD index %d\n", spd_index); - 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."); - - memcpy(peid->spd_data[0], spd_file + (spd_index * spd_len), spd_len); + unsigned int spd_index = fill_spd_for_index(peid->spd_data[0], get_gpios(gpio_vector)); /* Index 0-2, are 4GB config with both CH0 and CH1 * Index 3-5, are 2GB config with CH0 only */ switch (spd_index) { case 0: case 1: case 2: - memcpy(peid->spd_data[1], - spd_file + (spd_index * spd_len), spd_len); + memcpy(peid->spd_data[1], peid->spd_data[0], SPD_LEN); break; case 3: case 4: case 5: peid->dimm_channel1_disabled = 3; -- cgit v1.2.3