summaryrefslogtreecommitdiff
path: root/src/lib/cbmem.c
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 /src/lib/cbmem.c
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)
Diffstat (limited to 'src/lib/cbmem.c')
-rw-r--r--src/lib/cbmem.c44
1 files changed, 27 insertions, 17 deletions
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