summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2014-01-06 17:20:31 +0200
committerKyösti Mälkki <kyosti.malkki@gmail.com>2014-01-22 20:54:57 +0100
commit2d8520b275d47e0670e7f9e166e0f63c32855548 (patch)
tree71b69480daeb5e800b3863448cd0776dba265b7c
parent97e1b11f416aa23787e71b6133702b82daf1552e (diff)
downloadcoreboot-2d8520b275d47e0670e7f9e166e0f63c32855548.tar.xz
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)
-rw-r--r--src/include/cbmem.h9
-rw-r--r--src/lib/cbmem.c44
-rw-r--r--src/lib/dynamic_cbmem.c10
-rw-r--r--src/mainboard/emulation/qemu-i440fx/romstage.c2
-rw-r--r--src/mainboard/emulation/qemu-q35/romstage.c2
-rw-r--r--src/mainboard/getac/p470/romstage.c2
-rw-r--r--src/mainboard/google/butterfly/romstage.c2
-rw-r--r--src/mainboard/google/link/romstage.c2
-rw-r--r--src/mainboard/google/parrot/romstage.c2
-rw-r--r--src/mainboard/google/stout/romstage.c2
-rw-r--r--src/mainboard/ibase/mb899/romstage.c2
-rw-r--r--src/mainboard/intel/cougar_canyon2/romstage.c2
-rw-r--r--src/mainboard/intel/d945gclf/romstage.c2
-rw-r--r--src/mainboard/intel/emeraldlake2/romstage.c2
-rw-r--r--src/mainboard/kontron/986lcd-m/romstage.c2
-rw-r--r--src/mainboard/kontron/ktqm77/romstage.c2
-rw-r--r--src/mainboard/lenovo/t60/romstage.c2
-rw-r--r--src/mainboard/lenovo/x201/romstage.c6
-rw-r--r--src/mainboard/lenovo/x60/romstage.c2
-rw-r--r--src/mainboard/roda/rk886ex/romstage.c2
-rw-r--r--src/mainboard/roda/rk9/romstage.c2
-rw-r--r--src/mainboard/samsung/lumpy/romstage.c2
-rw-r--r--src/mainboard/samsung/stumpy/romstage.c2
-rw-r--r--src/mainboard/via/epia-m850/romstage.c2
-rw-r--r--src/northbridge/intel/nehalem/raminit.c2
25 files changed, 69 insertions, 42 deletions
diff --git a/src/include/cbmem.h b/src/include/cbmem.h
index 5f1ac3c581..eff18956cc 100644
--- a/src/include/cbmem.h
+++ b/src/include/cbmem.h
@@ -90,6 +90,9 @@ struct cbmem_entry;
#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. */
void cbmem_initialize_empty(void);
@@ -153,9 +156,9 @@ struct cbmem_entry *get_cbmem_toc(void);
unsigned long get_top_of_ram(void);
-/* 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);
+/* Returns 0 if old cbmem was recovered. Recovery is only attempted if
+ * s3resume is non-zero. */
+int cbmem_recovery(int s3resume);
/* 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
* size. */
diff --git a/src/lib/cbmem.c b/src/lib/cbmem.c
index 6cdf7721c9..05f195a43b 100644
--- a/src/lib/cbmem.c
+++ b/src/lib/cbmem.c
@@ -95,8 +95,7 @@ void cbmem_late_set_table(uint64_t base, uint64_t size)
* - suspend/resume backup memory
*/
-#if CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__)
-static void cbmem_init(void)
+static void cbmem_initialize_empty(void)
{
uint64_t baseaddr, size;
struct cbmem_entry *cbmem_toc;
@@ -119,7 +118,6 @@ static void cbmem_init(void)
.size = size - CBMEM_TOC_RESERVED
};
}
-#endif
int cbmem_reinit(void)
{
@@ -219,32 +217,44 @@ void *cbmem_find(u32 id)
return (void *)NULL;
}
-#if CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__)
/* 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. */
- if (!cbmem_reinit()) {
- cbmem_init();
+ /* CBMEM TOC is wiped clean when we are not waking up from S3
+ * suspend. Boards with EARLY_CBMEM_INIT do this in romstage,
+ * 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();
- rv = 1;
}
-#ifndef __PRE_RAM__
+
cbmem_arch_init();
-#endif
- /* Migrate cache-as-ram variables. */
car_migrate_variables();
-
- return rv;
+ return !found;
}
-#endif
#ifndef __PRE_RAM__
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
cbmemc_reinit();
#endif
diff --git a/src/lib/dynamic_cbmem.c b/src/lib/dynamic_cbmem.c
index 0ab8f81224..0cc6295545 100644
--- a/src/lib/dynamic_cbmem.c
+++ b/src/lib/dynamic_cbmem.c
@@ -256,6 +256,16 @@ int cbmem_initialize(void)
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)
{
struct cbmem_root *root;
diff --git a/src/mainboard/emulation/qemu-i440fx/romstage.c b/src/mainboard/emulation/qemu-i440fx/romstage.c
index db8891ee21..0613d82b51 100644
--- a/src/mainboard/emulation/qemu-i440fx/romstage.c
+++ b/src/mainboard/emulation/qemu-i440fx/romstage.c
@@ -48,7 +48,7 @@ void main(unsigned long bist)
//print_pci_devices();
//dump_pci_devices();
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(0);
timestamp_init(rdtsc());
timestamp_add_now(TS_START_ROMSTAGE);
diff --git a/src/mainboard/emulation/qemu-q35/romstage.c b/src/mainboard/emulation/qemu-q35/romstage.c
index fae5095af0..190c775def 100644
--- a/src/mainboard/emulation/qemu-q35/romstage.c
+++ b/src/mainboard/emulation/qemu-q35/romstage.c
@@ -50,7 +50,7 @@ void main(unsigned long bist)
//print_pci_devices();
//dump_pci_devices();
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(0);
timestamp_init(rdtsc());
timestamp_add_now(TS_START_ROMSTAGE);
diff --git a/src/mainboard/getac/p470/romstage.c b/src/mainboard/getac/p470/romstage.c
index 87af8cadcb..a081a8a8a2 100644
--- a/src/mainboard/getac/p470/romstage.c
+++ b/src/mainboard/getac/p470/romstage.c
@@ -357,7 +357,7 @@ void main(unsigned long bist)
#endif
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/google/butterfly/romstage.c b/src/mainboard/google/butterfly/romstage.c
index b7ec01107d..d32f3f0a1a 100644
--- a/src/mainboard/google/butterfly/romstage.c
+++ b/src/mainboard/google/butterfly/romstage.c
@@ -244,7 +244,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/google/link/romstage.c b/src/mainboard/google/link/romstage.c
index 1e4b42c393..66d206757e 100644
--- a/src/mainboard/google/link/romstage.c
+++ b/src/mainboard/google/link/romstage.c
@@ -288,7 +288,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/google/parrot/romstage.c b/src/mainboard/google/parrot/romstage.c
index b6bacaedfe..361c19beba 100644
--- a/src/mainboard/google/parrot/romstage.c
+++ b/src/mainboard/google/parrot/romstage.c
@@ -244,7 +244,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/google/stout/romstage.c b/src/mainboard/google/stout/romstage.c
index a775e69cdf..0ea53e7ac8 100644
--- a/src/mainboard/google/stout/romstage.c
+++ b/src/mainboard/google/stout/romstage.c
@@ -296,7 +296,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/ibase/mb899/romstage.c b/src/mainboard/ibase/mb899/romstage.c
index 222c376b4d..0b9d408570 100644
--- a/src/mainboard/ibase/mb899/romstage.c
+++ b/src/mainboard/ibase/mb899/romstage.c
@@ -311,7 +311,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/intel/cougar_canyon2/romstage.c b/src/mainboard/intel/cougar_canyon2/romstage.c
index 42b19e4129..afd7e25655 100644
--- a/src/mainboard/intel/cougar_canyon2/romstage.c
+++ b/src/mainboard/intel/cougar_canyon2/romstage.c
@@ -322,7 +322,7 @@ void romstage_main_continue(EFI_STATUS status, VOID *HobListPtr) {
quick_ram_check();
post_code(0x4e);
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(0);
if(cbmem_was_initted) {
reset_system();
diff --git a/src/mainboard/intel/d945gclf/romstage.c b/src/mainboard/intel/d945gclf/romstage.c
index 166743f552..69d4232edd 100644
--- a/src/mainboard/intel/d945gclf/romstage.c
+++ b/src/mainboard/intel/d945gclf/romstage.c
@@ -269,7 +269,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/intel/emeraldlake2/romstage.c b/src/mainboard/intel/emeraldlake2/romstage.c
index 3534700236..9308e9617a 100644
--- a/src/mainboard/intel/emeraldlake2/romstage.c
+++ b/src/mainboard/intel/emeraldlake2/romstage.c
@@ -296,7 +296,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/kontron/986lcd-m/romstage.c b/src/mainboard/kontron/986lcd-m/romstage.c
index 1875a10ad4..549facd333 100644
--- a/src/mainboard/kontron/986lcd-m/romstage.c
+++ b/src/mainboard/kontron/986lcd-m/romstage.c
@@ -410,7 +410,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/kontron/ktqm77/romstage.c b/src/mainboard/kontron/ktqm77/romstage.c
index 15c10b29ba..b5959b1bec 100644
--- a/src/mainboard/kontron/ktqm77/romstage.c
+++ b/src/mainboard/kontron/ktqm77/romstage.c
@@ -295,7 +295,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/lenovo/t60/romstage.c b/src/mainboard/lenovo/t60/romstage.c
index 1b7e693d80..dae917c925 100644
--- a/src/mainboard/lenovo/t60/romstage.c
+++ b/src/mainboard/lenovo/t60/romstage.c
@@ -321,7 +321,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/lenovo/x201/romstage.c b/src/mainboard/lenovo/x201/romstage.c
index 18645acb05..7935e5618e 100644
--- a/src/mainboard/lenovo/x201/romstage.c
+++ b/src/mainboard/lenovo/x201/romstage.c
@@ -331,7 +331,11 @@ void main(unsigned long bist)
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 there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/lenovo/x60/romstage.c b/src/mainboard/lenovo/x60/romstage.c
index 26a7b9b6fa..1198fb2007 100644
--- a/src/mainboard/lenovo/x60/romstage.c
+++ b/src/mainboard/lenovo/x60/romstage.c
@@ -323,7 +323,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/roda/rk886ex/romstage.c b/src/mainboard/roda/rk886ex/romstage.c
index e08c1c025f..ad323f5501 100644
--- a/src/mainboard/roda/rk886ex/romstage.c
+++ b/src/mainboard/roda/rk886ex/romstage.c
@@ -346,7 +346,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
#if CONFIG_HAVE_ACPI_RESUME
/* If there is no high memory area, we didn't boot before, so
diff --git a/src/mainboard/roda/rk9/romstage.c b/src/mainboard/roda/rk9/romstage.c
index e71e9c4851..90392b9eb5 100644
--- a/src/mainboard/roda/rk9/romstage.c
+++ b/src/mainboard/roda/rk9/romstage.c
@@ -184,7 +184,7 @@ void main(unsigned long bist)
init_iommu();
- cbmem_initted = !cbmem_initialize();
+ cbmem_initted = !cbmem_recovery(0);
#if CONFIG_HAVE_ACPI_RESUME
/* 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.
diff --git a/src/mainboard/samsung/lumpy/romstage.c b/src/mainboard/samsung/lumpy/romstage.c
index 1f4fd02574..993345958d 100644
--- a/src/mainboard/samsung/lumpy/romstage.c
+++ b/src/mainboard/samsung/lumpy/romstage.c
@@ -317,7 +317,7 @@ void main(unsigned long bist)
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/samsung/stumpy/romstage.c b/src/mainboard/samsung/stumpy/romstage.c
index 7630c05549..e5b55b5059 100644
--- a/src/mainboard/samsung/stumpy/romstage.c
+++ b/src/mainboard/samsung/stumpy/romstage.c
@@ -324,7 +324,7 @@ void main(unsigned long bist)
post_code(0x3e);
MCHBAR16(SSKPD) = 0xCAFE;
- cbmem_was_initted = !cbmem_initialize();
+ cbmem_was_initted = !cbmem_recovery(boot_mode==2);
if (boot_mode!=2)
save_mrc_data(&pei_data);
diff --git a/src/mainboard/via/epia-m850/romstage.c b/src/mainboard/via/epia-m850/romstage.c
index 39f4253d38..262bee7aa8 100644
--- a/src/mainboard/via/epia-m850/romstage.c
+++ b/src/mainboard/via/epia-m850/romstage.c
@@ -95,7 +95,7 @@ void main(unsigned long bist)
/* We got RAM working, now we can write the timestamps to RAM */
#if CONFIG_EARLY_CBMEM_INIT
- cbmem_initialize();
+ cbmem_recovery(0);
#endif
timestamp_add_now(TS_END_ROMSTAGE);
/* FIXME: See if this is needed or take this out please */
diff --git a/src/northbridge/intel/nehalem/raminit.c b/src/northbridge/intel/nehalem/raminit.c
index 19af3bbde2..c7acd477bd 100644
--- a/src/northbridge/intel/nehalem/raminit.c
+++ b/src/northbridge/intel/nehalem/raminit.c
@@ -1699,7 +1699,7 @@ static void save_timings(struct raminfo *info)
train.reg_10b = read_1d0(0x10b, 6);
/* Save the MRC S3 restore data to cbmem */
- cbmem_initialize();
+ cbmem_recovery(0);
mrcdata = cbmem_add
(CBMEM_ID_MRCDATA, output_len + sizeof(struct mrc_data_container));