cbmem: Unify random on-CBMEM-init tasks under common CBMEM_INIT_HOOK() API

There are several use cases for performing a certain task when CBMEM is
first set up (usually to migrate some data into it that was previously
kept in BSS/SRAM/hammerspace), and unfortunately we handle each of them
differently: timestamp migration is called explicitly from
cbmem_initialize(), certain x86-chipset-specific tasks use the
CAR_MIGRATION() macro to register a hook, and the CBMEM console is
migrated through a direct call from romstage (on non-x86 and SandyBridge
boards).

This patch decouples the CAR_MIGRATION() hook mechanism from
cache-as-RAM and rechristens it to CBMEM_INIT_HOOK(), which is a clearer
description of what it really does. All of the above use cases are
ported to this new, consistent model, allowing us to have one less line
of boilerplate in non-CAR romstages.

BRANCH=None
BUG=None
TEST=Built and booted on Nyan_Blaze and Falco with and without
CONFIG_CBMEM_CONSOLE. Confirmed that 'cbmem -c' shows the full log after
boot (and the resume log after S3 resume on Falco). Compiled for Parrot,
Stout and Lumpy.

Change-Id: I1681b372664f5a1f15c3733cbd32b9b11f55f8ea
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/232612
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner 2014-12-01 18:08:03 -08:00 committed by chrome-internal-fetch
commit 7dd5bbd712
30 changed files with 48 additions and 105 deletions

View file

@ -26,7 +26,6 @@
#define CAR_GLOBAL
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)

View file

@ -26,7 +26,6 @@
#define CAR_GLOBAL
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)

View file

@ -21,7 +21,6 @@
#define __MIPS_ARCH_EARLY_VARIABLES_H
#define CAR_GLOBAL
#define CAR_MIGRATE(migrate_fn_)
static inline void car_migrate_variables(void) {}
#define car_get_var(var) (var)

View file

@ -27,12 +27,6 @@
#endif
#if CONFIG_CAR_MIGRATION && defined(__PRE_RAM__)
#define CAR_MIGRATE_ATTR __attribute__ ((used,section (".car.migrate")))
/* Call migrate_fn_() when CAR globals are migrated. */
#define CAR_MIGRATE(migrate_fn_) \
static void (* const migrate_fn_ ## _ptr)(void) CAR_MIGRATE_ATTR = \
migrate_fn_;
/* Get the correct pointer for the CAR global variable. */
void *car_get_var_ptr(void *var);
@ -47,7 +41,6 @@ void *car_get_var_ptr(void *var);
void car_migrate_variables(void);
#else
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)

View file

@ -31,14 +31,14 @@ SECTIONS
_rom = .;
*(.rom.text);
*(.rom.data);
. = ALIGN(4);
_cbmem_init_hooks = .;
KEEP(*(.rodata.cbmem_init_hooks));
_ecbmem_init_hooks = .;
*(.rodata);
*(.rodata.*);
*(.rom.data.*);
. = ALIGN(16);
_car_migrate_start = .;
*(.car.migrate);
_car_migrate_end = .;
. = ALIGN(16);
_erom = .;
}

View file

@ -23,11 +23,6 @@
#include <cbmem.h>
#include <arch/early_variables.h>
typedef void (* const car_migration_func_t)(void);
extern car_migration_func_t _car_migrate_start;
extern car_migration_func_t _car_migrate_end;
extern char _car_data_start[];
extern char _car_data_end[];
@ -77,7 +72,6 @@ void *car_get_var_ptr(void *var)
void car_migrate_variables(void)
{
void *migrated_base;
car_migration_func_t *migrate_func;
size_t car_data_size = &_car_data_end[0] - &_car_data_start[0];
migrated_base = cbmem_add(CBMEM_ID_CAR_GLOBALS, car_data_size);
@ -91,11 +85,4 @@ void car_migrate_variables(void)
/* Mark that the data has been moved. */
car_migrated = ~0;
/* Call all the migration functions. */
migrate_func = &_car_migrate_start;
while (migrate_func != &_car_migrate_end) {
(*migrate_func)();
migrate_func++;
}
}

View file

@ -203,13 +203,19 @@ void *cbmem_add(u32 id, u64 size);
/* Find a cbmem entry of a given id. These return NULL on failure. */
void *cbmem_find(u32 id);
typedef void (* const cbmem_init_hook_t)(void);
#define CBMEM_INIT_HOOK(init_fn_) static cbmem_init_hook_t init_fn_ ## _ptr \
__attribute__((used, section(".rodata.cbmem_init_hooks"))) = init_fn_;
#ifndef __PRE_RAM__
/* Ramstage only functions. */
void cbmem_list(void);
void cbmem_arch_init(void);
void cbmem_print_entry(int n, u32 id, u64 start, u64 size);
static inline void cbmem_run_init_hooks(void) {}
#else
static inline void cbmem_arch_init(void) {}
void cbmem_run_init_hooks(void);
#endif /* __PRE_RAM__ */
#endif /* __ASSEMBLER__ */

View file

@ -90,11 +90,6 @@ void timestamp_init(uint64_t base);
void timestamp_add(enum timestamp_id id, uint64_t ts_time);
/* Calls timestamp_add with current timestamp. */
void timestamp_add_now(enum timestamp_id id);
/*
* Sync all timestamps from timestamp_cache to cbmem area. Called by
* cbmem_initialize.
*/
void timestamp_sync(void);
/* Implemented by the architecture code */
uint64_t timestamp_get(void);
#else

View file

@ -116,7 +116,8 @@ else
ramstage-y += cbmem.c
romstage-$(CONFIG_HAVE_ACPI_RESUME) += cbmem.c
endif # CONFIG_DYNAMIC_CBMEM
ramstage-y += cbmem_info.c
romstage-y += cbmem_common.c
ramstage-y += cbmem_common.c
ramstage-y += hexdump.c
romstage-y += hexdump.c

View file

@ -230,12 +230,11 @@ int cbmem_initialize(void)
#ifndef __PRE_RAM__
cbmem_arch_init();
#endif
cbmem_run_init_hooks();
/* Migrate cache-as-ram variables. */
car_migrate_variables();
/* Pull in all timestamps from timestamp cache into cbmem area */
timestamp_sync();
return rv;
}
#endif
@ -271,6 +270,6 @@ void cbmem_list(void)
cbmem_toc[i].size);
}
}
#endif
#endif /* ! __PRE_RAM__ */

View file

@ -20,6 +20,8 @@
#include <cbmem.h>
#include <stdlib.h>
#ifndef __PRE_RAM__
static const struct cbmem_id_to_name cbmem_ids[] = { CBMEM_ID_TO_NAME_TABLE };
void cbmem_print_entry(int n, u32 id, u64 base, u64 size)
@ -43,3 +45,19 @@ void cbmem_print_entry(int n, u32 id, u64 base, u64 size)
printk(BIOS_DEBUG, "%08llx ", base);
printk(BIOS_DEBUG, "%08llx\n", size);
}
#else /* __PRE_RAM__ */
extern cbmem_init_hook_t _cbmem_init_hooks;
extern cbmem_init_hook_t _ecbmem_init_hooks;
void cbmem_run_init_hooks(void)
{
cbmem_init_hook_t *init_hook_ptr = &_cbmem_init_hooks;
while (init_hook_ptr != &_ecbmem_init_hooks) {
(*init_hook_ptr)();
init_hook_ptr++;
}
}
#endif /* __PRE_RAM__ */

View file

@ -233,5 +233,5 @@ void cbmemc_reinit(void)
current_console_set(cbm_cons_p);
}
/* Call cbmemc_reinit() at CAR migration time. */
CAR_MIGRATE(cbmemc_reinit)
/* Call cbmemc_reinit() at cbmem_initialize() time. */
CBMEM_INIT_HOOK(cbmemc_reinit)

View file

@ -184,20 +184,16 @@ void cbmem_initialize_empty(void)
root, root->max_entries);
cbmem_arch_init();
cbmem_run_init_hooks();
/* Migrate cache-as-ram variables. */
car_migrate_variables();
/* Pull in all timestamps from timestamp cache into cbmem area */
timestamp_sync();
}
static inline int cbmem_fail_recovery(void)
{
cbmem_initialize_empty();
cbmem_handle_acpi_resume();
/* Migrate cache-as-ram variables. */
car_migrate_variables();
return 1;
}
@ -265,13 +261,11 @@ int cbmem_initialize(void)
#endif
cbmem_arch_init();
cbmem_run_init_hooks();
/* Migrate cache-as-ram variables. */
car_migrate_variables();
/* Pull in all timestamps from timestamp cache into cbmem area */
timestamp_sync();
/* Recovery successful. */
return 0;
}

View file

@ -29,6 +29,10 @@
} : to_load
.data . : {
. = ALIGN(8);
_cbmem_init_hooks = .;
KEEP(*(.rodata.cbmem_init_hooks));
_ecbmem_init_hooks = .;
*(.rodata);
*(.rodata.*);
*(.data);

View file

@ -155,7 +155,7 @@ static void timestamp_add_table_entry(struct timestamp_table *ts_table,
tse->entry_stamp = ts_time - ts_table->base_time;
}
void timestamp_sync(void)
static void timestamp_sync(void)
{
uint32_t i;
@ -214,6 +214,7 @@ void timestamp_sync(void)
if (ts_cbmem_table->base_time == 0)
ts_cbmem_table->base_time = ts_cache_table->base_time;
}
CBMEM_INIT_HOOK(timestamp_sync)
void timestamp_early_init(uint64_t base)
{

View file

@ -52,10 +52,4 @@ void main(unsigned long bist)
timestamp_init(rdtsc());
timestamp_add_now(TS_START_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -289,9 +289,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -331,9 +331,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -89,10 +89,6 @@ static void __attribute__((noinline)) romstage(void)
early_mainboard_init();
#if CONFIG_CONSOLE_CBMEM
cbmemc_reinit();
#endif
vboot_verify_firmware(romstage_handoff_find_or_add());
timestamp_add_now(TS_START_COPYRAM);

View file

@ -89,10 +89,6 @@ static void __attribute__((noinline)) romstage(void)
early_mainboard_init();
#if CONFIG_CONSOLE_CBMEM
cbmemc_reinit();
#endif
vboot_verify_firmware(romstage_handoff_find_or_add());
timestamp_add_now(TS_START_COPYRAM);

View file

@ -92,10 +92,6 @@ static void __attribute__((noinline)) romstage(void)
cbmem_initialize_empty();
#if CONFIG_CONSOLE_CBMEM
cbmemc_reinit();
#endif
#if CONFIG_VBOOT2_VERIFY_FIRMWARE
entry = vboot2_load_ramstage();
#else

View file

@ -289,9 +289,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -346,9 +346,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -343,9 +343,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -362,9 +362,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -367,9 +367,4 @@ void main(unsigned long bist)
timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
timestamp_add(TS_AFTER_INITRAM, after_dram_time );
timestamp_add_now(TS_END_ROMSTAGE);
#if CONFIG_CONSOLE_CBMEM
/* Keep this the last thing this function does. */
cbmemc_reinit();
#endif
}

View file

@ -63,6 +63,9 @@ static void save_mrc_data(struct pei_data *pei_data)
int output_len = ALIGN(pei_data->mrc_output_len, 16);
/* Save the MRC S3 restore data to cbmem */
/* TODO: cbmem_initialize() must not be called twice! Most sandybridge
* boards call it again from mainboard/romstage.c. Clean up these code
* paths to ensure it is called at most once with every config. */
cbmem_initialize();
mrcdata = cbmem_add
(CBMEM_ID_MRCDATA,

View file

@ -154,7 +154,7 @@ static void migrate_power_state(void)
}
memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem));
}
CAR_MIGRATE(migrate_power_state);
CBMEM_INIT_HOOK(migrate_power_state)
static struct chipset_power_state *fill_power_state(void)
{

View file

@ -50,7 +50,7 @@ static void migrate_power_state(void)
}
memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem));
}
CAR_MIGRATE(migrate_power_state);
CBMEM_INIT_HOOK(migrate_power_state)
/* Return 0, 3, or 5 to indicate the previous sleep state. */
static int prev_sleep_state(struct chipset_power_state *ps)

View file

@ -123,8 +123,6 @@ void romstage(void)
clock_halt_avp();
}
cbmemc_reinit();
timestamp_add_now(TS_END_ROMSTAGE);
ccplex_cpu_start(entry);