CBMEM: Replace cbmem_initialize() with cbmem_recovery()

The replacement function confirms CBMEM TOC is wiped clean on power
cycles and resets. It also introduces compatibility interface to ease
up transition to DYNAMIC_CBMEM.

Change-Id: Ic5445c5bff4aff22a43821f3064f2df458b9f250
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/4668
Reviewed-by: Aaron Durbin <adurbin@google.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Kyösti Mälkki
2014-01-06 17:20:31 +02:00
parent 97e1b11f41
commit 2d8520b275
25 changed files with 70 additions and 43 deletions

View File

@ -90,6 +90,9 @@ struct cbmem_entry;
#define DYN_CBMEM_ALIGN_SIZE (4096) #define DYN_CBMEM_ALIGN_SIZE (4096)
/* By default cbmem is attempted to be recovered. Returns 0 if cbmem was
* recovered or 1 if cbmem had to be reinitialized. */
int cbmem_initialize(void);
/* Initialize cbmem to be empty. */ /* Initialize cbmem to be empty. */
void cbmem_initialize_empty(void); void cbmem_initialize_empty(void);
@ -153,9 +156,9 @@ struct cbmem_entry *get_cbmem_toc(void);
unsigned long get_top_of_ram(void); unsigned long get_top_of_ram(void);
/* By default cbmem is attempted to be recovered. Returns 0 if cbmem was /* Returns 0 if old cbmem was recovered. Recovery is only attempted if
* recovered or 1 if cbmem had to be reinitialized. */ * s3resume is non-zero. */
int cbmem_initialize(void); int cbmem_recovery(int s3resume);
/* Add a cbmem entry of a given size and id. These return NULL on failure. The /* Add a cbmem entry of a given size and id. These return NULL on failure. The
* add function performs a find first and do not check against the original * add function performs a find first and do not check against the original
* size. */ * size. */

View File

@ -95,8 +95,7 @@ void cbmem_late_set_table(uint64_t base, uint64_t size)
* - suspend/resume backup memory * - suspend/resume backup memory
*/ */
#if CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__) static void cbmem_initialize_empty(void)
static void cbmem_init(void)
{ {
uint64_t baseaddr, size; uint64_t baseaddr, size;
struct cbmem_entry *cbmem_toc; struct cbmem_entry *cbmem_toc;
@ -119,7 +118,6 @@ static void cbmem_init(void)
.size = size - CBMEM_TOC_RESERVED .size = size - CBMEM_TOC_RESERVED
}; };
} }
#endif
int cbmem_reinit(void) int cbmem_reinit(void)
{ {
@ -219,32 +217,44 @@ void *cbmem_find(u32 id)
return (void *)NULL; return (void *)NULL;
} }
#if CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__)
/* Returns True if it was not initialized before. */ /* Returns True if it was not initialized before. */
int cbmem_initialize(void) int cbmem_recovery(int is_wakeup)
{ {
int rv = 0; int found = cbmem_reinit();
int wipe = 0;
/* We expect the romstage to always initialize it. */ /* CBMEM TOC is wiped clean when we are not waking up from S3
if (!cbmem_reinit()) { * suspend. Boards with EARLY_CBMEM_INIT do this in romstage,
cbmem_init(); * boards without EARLY_CBMEM_INIT do this in ramstage.
*/
#if defined(__PRE_RAM__) && CONFIG_EARLY_CBMEM_INIT
wipe = 1;
#endif
#if !defined(__PRE_RAM__) && !CONFIG_EARLY_CBMEM_INIT
wipe = 1;
#endif
if (!is_wakeup && wipe)
cbmem_initialize_empty();
if (is_wakeup && !found) {
cbmem_initialize_empty();
cbmem_fail_resume(); cbmem_fail_resume();
rv = 1;
} }
#ifndef __PRE_RAM__
cbmem_arch_init();
#endif
/* Migrate cache-as-ram variables. */
car_migrate_variables();
return rv; cbmem_arch_init();
car_migrate_variables();
return !found;
} }
#endif
#ifndef __PRE_RAM__ #ifndef __PRE_RAM__
static void init_cbmem_post_device(void *unused) static void init_cbmem_post_device(void *unused)
{ {
cbmem_initialize(); #if CONFIG_HAVE_ACPI_RESUME
cbmem_recovery(acpi_is_wakeup());
#else
cbmem_recovery(0);
#endif
#if CONFIG_CONSOLE_CBMEM #if CONFIG_CONSOLE_CBMEM
cbmemc_reinit(); cbmemc_reinit();
#endif #endif

View File

@ -256,6 +256,16 @@ int cbmem_initialize(void)
return 0; return 0;
} }
int cbmem_recovery(int is_wakeup)
{
int rv = 0;
if (!is_wakeup)
cbmem_initialize_empty();
else
rv = cbmem_initialize();
return rv;
}
static void *cbmem_base(void) static void *cbmem_base(void)
{ {
struct cbmem_root *root; struct cbmem_root *root;

View File

@ -48,7 +48,7 @@ void main(unsigned long bist)
//print_pci_devices(); //print_pci_devices();
//dump_pci_devices(); //dump_pci_devices();
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(0);
timestamp_init(rdtsc()); timestamp_init(rdtsc());
timestamp_add_now(TS_START_ROMSTAGE); timestamp_add_now(TS_START_ROMSTAGE);

View File

@ -50,7 +50,7 @@ void main(unsigned long bist)
//print_pci_devices(); //print_pci_devices();
//dump_pci_devices(); //dump_pci_devices();
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(0);
timestamp_init(rdtsc()); timestamp_init(rdtsc());
timestamp_add_now(TS_START_ROMSTAGE); timestamp_add_now(TS_START_ROMSTAGE);

View File

@ -357,7 +357,7 @@ void main(unsigned long bist)
#endif #endif
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -244,7 +244,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -288,7 +288,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -244,7 +244,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -296,7 +296,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -311,7 +311,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -322,7 +322,7 @@ void romstage_main_continue(EFI_STATUS status, VOID *HobListPtr) {
quick_ram_check(); quick_ram_check();
post_code(0x4e); post_code(0x4e);
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(0);
if(cbmem_was_initted) { if(cbmem_was_initted) {
reset_system(); reset_system();

View File

@ -269,7 +269,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -296,7 +296,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -410,7 +410,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -295,7 +295,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -321,7 +321,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -331,7 +331,11 @@ void main(unsigned long bist)
outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04); outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04);
} }
cbmem_initted = !cbmem_initialize(); /* FIXME: If not in s3resume, raminit() calls cbmem_recovery(0),
* clears all of CBMEM region and puts in MRC training results.
* Tell here we are doing resume to avoid wiping CBMEM region
* again. */
cbmem_initted = !cbmem_recovery(1);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -323,7 +323,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -346,7 +346,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so

View File

@ -184,7 +184,7 @@ void main(unsigned long bist)
init_iommu(); init_iommu();
cbmem_initted = !cbmem_initialize(); cbmem_initted = !cbmem_recovery(0);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so /* If there is no high memory area, we didn't boot before, so
* this is not a resume. In that case we just create the cbmem toc. * this is not a resume. In that case we just create the cbmem toc.

View File

@ -317,7 +317,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -324,7 +324,7 @@ void main(unsigned long bist)
post_code(0x3e); post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE; MCHBAR16(SSKPD) = 0xCAFE;
cbmem_was_initted = !cbmem_initialize(); cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2) if (boot_mode!=2)
save_mrc_data(&pei_data); save_mrc_data(&pei_data);

View File

@ -95,7 +95,7 @@ void main(unsigned long bist)
/* We got RAM working, now we can write the timestamps to RAM */ /* We got RAM working, now we can write the timestamps to RAM */
#if CONFIG_EARLY_CBMEM_INIT #if CONFIG_EARLY_CBMEM_INIT
cbmem_initialize(); cbmem_recovery(0);
#endif #endif
timestamp_add_now(TS_END_ROMSTAGE); timestamp_add_now(TS_END_ROMSTAGE);
/* FIXME: See if this is needed or take this out please */ /* FIXME: See if this is needed or take this out please */

View File

@ -1699,7 +1699,7 @@ static void save_timings(struct raminfo *info)
train.reg_10b = read_1d0(0x10b, 6); train.reg_10b = read_1d0(0x10b, 6);
/* Save the MRC S3 restore data to cbmem */ /* Save the MRC S3 restore data to cbmem */
cbmem_initialize(); cbmem_recovery(0);
mrcdata = cbmem_add mrcdata = cbmem_add
(CBMEM_ID_MRCDATA, output_len + sizeof(struct mrc_data_container)); (CBMEM_ID_MRCDATA, output_len + sizeof(struct mrc_data_container));