romstage_handoff: remove code duplication

The same pattern was being used throughout the code base
for initializing the romstage handoff structure. Provide
a helper function to initialize the structure with the S3
resume state then utilize it at all the existing call sites.

Change-Id: I1e9d588ab6b9ace67757387dbb5963ae31ceb252
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/17646
Tested-by: build bot (Jenkins)
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
Aaron Durbin 2016-11-29 17:43:04 -06:00
parent c1d72942f4
commit 77e13997d3
9 changed files with 35 additions and 60 deletions

View File

@ -129,14 +129,7 @@ void post_cache_as_ram(void)
prepare_romstage_ramstack(s3resume);
if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)) {
struct romstage_handoff *handoff;
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = s3resume;
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
}
romstage_handoff_init(s3resume);
/* from here don't store more data in CAR */
if (family >= 0x1f && family <= 0x3f) {

View File

@ -172,7 +172,6 @@ void romstage_common(const struct romstage_params *params)
{
int boot_mode;
int wake_from_s3;
struct romstage_handoff *handoff;
timestamp_init(get_initial_timestamp());
timestamp_add_now(TS_START_ROMSTAGE);
@ -245,11 +244,7 @@ void romstage_common(const struct romstage_params *params)
#endif
}
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = wake_from_s3;
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
romstage_handoff_init(wake_from_s3);
post_code(0x3f);
if (IS_ENABLED(CONFIG_LPC_TPM)) {

View File

@ -99,7 +99,6 @@ void *cache_as_ram_stage_main(FSP_INFO_HEADER *fih)
void romstage_common(struct romstage_params *params)
{
const struct mrc_saved_data *cache;
struct romstage_handoff *handoff;
struct pei_data *pei_data;
post_code(0x32);
@ -165,14 +164,9 @@ void romstage_common(struct romstage_params *params)
mainboard_save_dimm_info(params);
/* Create romstage handof information */
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = (params->power_state->prev_sleep_state ==
ACPI_S3);
else {
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
if (romstage_handoff_init(
params->power_state->prev_sleep_state == ACPI_S3) < 0)
hard_reset();
}
/*
* Initialize the TPM, unless the TPM was already initialized

View File

@ -117,7 +117,6 @@ static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version)
{
struct range_entry fsp_mem;
struct romstage_handoff *handoff;
if (fsp_find_reserved_memory(&fsp_mem))
die("Failed to find FSP_RESERVED_MEMORY_RESOURCE_HOB!\n");
@ -144,11 +143,7 @@ static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version)
save_memory_training_data(s3wake, fsp_version);
/* Create romstage handof information */
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = s3wake;
else
printk(BIOS_SPEW, "Romstage handoff structure not added!\n");
romstage_handoff_init(s3wake);
}
static const char *mrc_cache_get_region_name(void)

View File

@ -18,6 +18,8 @@
#include <stdint.h>
#include <string.h>
#include <cbmem.h>
#include <console/console.h>
#include <rules.h>
/* It is the chipset's responsibility for maintaining the integrity of this
* structure in CBMEM. For instance, if chipset code adds this structure
@ -48,13 +50,32 @@ static inline struct romstage_handoff *romstage_handoff_find_or_add(void)
* found so it can be initialized to 0. */
handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
if (handoff == NULL) {
if (handoff)
return handoff;
handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff));
if (handoff != NULL)
memset(handoff, 0, sizeof(*handoff));
}
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
return handoff;
}
/* Returns 0 if initialized. Else < 0 if handoff structure not added. */
static inline int romstage_handoff_init(int is_s3_resume)
{
struct romstage_handoff *handoff;
handoff = romstage_handoff_find_or_add();
if (handoff == NULL)
return -1;
handoff->s3_resume = is_s3_resume;
return 0;
}
#endif /* ROMSTAGE_HANDOFF_H */

View File

@ -227,13 +227,7 @@ void sandybridge_early_initialization(int chipset_type)
void northbridge_romstage_finalize(int s3resume)
{
struct romstage_handoff *handoff;
MCHBAR16(SSKPD) = 0xCAFE;
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = s3resume;
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
romstage_handoff_init(s3resume);
}

View File

@ -210,7 +210,6 @@ static int chipset_prev_sleep_state(struct chipset_power_state *ps)
/* Entry from the mainboard. */
void romstage_common(struct romstage_params *params)
{
struct romstage_handoff *handoff;
struct chipset_power_state *ps;
int prev_sleep_state;
@ -232,11 +231,7 @@ void romstage_common(struct romstage_params *params)
timestamp_add_now(TS_AFTER_INITRAM);
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = (prev_sleep_state == ACPI_S3);
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
romstage_handoff_init(prev_sleep_state == ACPI_S3);
if (IS_ENABLED(CONFIG_LPC_TPM)) {
init_tpm(prev_sleep_state == ACPI_S3);

View File

@ -89,8 +89,6 @@ void * asmlinkage romstage_main(unsigned long bist,
/* Entry from the mainboard. */
void romstage_common(struct romstage_params *params)
{
struct romstage_handoff *handoff;
post_code(0x32);
timestamp_add_now(TS_BEFORE_INITRAM);
@ -114,12 +112,7 @@ void romstage_common(struct romstage_params *params)
timestamp_add_now(TS_AFTER_INITRAM);
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = (params->power_state->prev_sleep_state ==
ACPI_S3);
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
romstage_handoff_init(params->power_state->prev_sleep_state == ACPI_S3);
#if CONFIG_LPC_TPM
init_tpm(params->power_state->prev_sleep_state == ACPI_S3);

View File

@ -218,7 +218,6 @@ void romstage_main_continue(EFI_STATUS status, void *hob_list_ptr)
int cbmem_was_initted;
void *cbmem_hob_ptr;
uint32_t prev_sleep_state;
struct romstage_handoff *handoff;
timestamp_add_now(TS_AFTER_INITRAM);
@ -257,11 +256,7 @@ void romstage_main_continue(EFI_STATUS status, void *hob_list_ptr)
*(u32*)cbmem_hob_ptr = (u32)hob_list_ptr;
post_code(0x4e);
handoff = romstage_handoff_find_or_add();
if (handoff != NULL)
handoff->s3_resume = (prev_sleep_state == ACPI_S3);
else
printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
romstage_handoff_init(prev_sleep_state == ACPI_S3);
post_code(0x4f);