summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2014-12-31 18:34:59 +0200
committerKyösti Mälkki <kyosti.malkki@gmail.com>2015-01-27 22:42:10 +0100
commite45542580c1765720dbfbd8b4076296e442a211b (patch)
treed07d5d17d9cd265d711d5818eb1585c023099414 /src
parent823edda98e6512d3f455b61549efea6fa68ee2b0 (diff)
CBMEM console: Fix CAR migration step
With the change it becomes irrelevant if memcpy() car.global_data or cbmemc_reinit() is done first. Change-Id: Ie479eef346c959e97dcc55861ccb0db1321fb7b2 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/8032 Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@google.com> Tested-by: build bot (Jenkins)
Diffstat (limited to 'src')
-rw-r--r--src/arch/arm/include/arch/early_variables.h1
-rw-r--r--src/arch/arm64/include/arch/early_variables.h1
-rw-r--r--src/arch/riscv/include/arch/early_variables.h1
-rw-r--r--src/arch/x86/include/arch/early_variables.h6
-rw-r--r--src/cpu/x86/car.c32
-rw-r--r--src/lib/cbmem_console.c2
6 files changed, 42 insertions, 1 deletions
diff --git a/src/arch/arm/include/arch/early_variables.h b/src/arch/arm/include/arch/early_variables.h
index 5b58baa271..cb0872e8f0 100644
--- a/src/arch/arm/include/arch/early_variables.h
+++ b/src/arch/arm/include/arch/early_variables.h
@@ -25,6 +25,7 @@
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
+#define car_sync_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)
static inline void car_migrate_variables(void) { }
diff --git a/src/arch/arm64/include/arch/early_variables.h b/src/arch/arm64/include/arch/early_variables.h
index 5b58baa271..cb0872e8f0 100644
--- a/src/arch/arm64/include/arch/early_variables.h
+++ b/src/arch/arm64/include/arch/early_variables.h
@@ -25,6 +25,7 @@
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
+#define car_sync_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)
static inline void car_migrate_variables(void) { }
diff --git a/src/arch/riscv/include/arch/early_variables.h b/src/arch/riscv/include/arch/early_variables.h
index 3a1f20d041..f9516a4c19 100644
--- a/src/arch/riscv/include/arch/early_variables.h
+++ b/src/arch/riscv/include/arch/early_variables.h
@@ -29,6 +29,7 @@
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
+#define car_sync_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)
static inline void car_migrate_variables(void) { }
diff --git a/src/arch/x86/include/arch/early_variables.h b/src/arch/x86/include/arch/early_variables.h
index f76c0481ab..2d5ae859ff 100644
--- a/src/arch/x86/include/arch/early_variables.h
+++ b/src/arch/x86/include/arch/early_variables.h
@@ -39,9 +39,14 @@ asm(".previous");
/* Get the correct pointer for the CAR global variable. */
void *car_get_var_ptr(void *var);
+/* Get and update a CAR_GLOBAL pointing elsewhere in car.global_data*/
+void *car_sync_var_ptr(void *var);
+
/* Get and set a primitive type global variable. */
#define car_get_var(var) \
*(typeof(var) *)car_get_var_ptr(&(var))
+#define car_sync_var(var) \
+ *(typeof (var) *)car_sync_var_ptr(&(var))
#define car_set_var(var, val) \
do { car_get_var(var) = (val); } while(0)
@@ -49,6 +54,7 @@ void *car_get_var_ptr(void *var);
#define CAR_MIGRATE(migrate_fn_)
static inline void *car_get_var_ptr(void *var) { return var; }
#define car_get_var(var) (var)
+#define car_sync_var(var) (var)
#define car_set_var(var, val) do { (var) = (val); } while (0)
#endif
diff --git a/src/cpu/x86/car.c b/src/cpu/x86/car.c
index c9cc6d6178..e757f0912c 100644
--- a/src/cpu/x86/car.c
+++ b/src/cpu/x86/car.c
@@ -73,6 +73,38 @@ void *car_get_var_ptr(void *var)
return &migrated_base[offset];
}
+/*
+ * Update a CAR_GLOBAL variable var, originally pointing to CAR region,
+ * with the address in migrated CAR region in DRAM.
+ */
+void *car_sync_var_ptr(void *var)
+{
+ void ** mig_var = car_get_var_ptr(var);
+ void * _car_start = &_car_data_start;
+ void * _car_end = &_car_data_end;
+
+ /* Not moved or migrated yet. */
+ if (mig_var == var)
+ return mig_var;
+
+ /* It's already pointing outside car.global_data. */
+ if (*mig_var < _car_start || *mig_var > _car_end)
+ return mig_var;
+
+#if !IS_ENABLED(CONFIG_PLATFORM_USES_FSP)
+ /* Keep console buffer in CAR until cbmemc_reinit() moves it. */
+ if (*mig_var == _car_end)
+ return mig_var;
+#endif
+
+ /* Move the pointer by the same amount the variable storing it was
+ * moved by.
+ */
+ *mig_var += (char *)mig_var - (char *)var;
+
+ return mig_var;
+}
+
static void do_car_migrate_variables(void)
{
void *migrated_base;
diff --git a/src/lib/cbmem_console.c b/src/lib/cbmem_console.c
index 997bb7d9b2..a8195a6a3d 100644
--- a/src/lib/cbmem_console.c
+++ b/src/lib/cbmem_console.c
@@ -65,7 +65,7 @@ static u8 static_console[STATIC_CONSOLE_SIZE];
static inline struct cbmem_console *current_console(void)
{
- return car_get_var(cbmem_console_p);
+ return car_sync_var(cbmem_console_p);
}
static inline void current_console_set(struct cbmem_console *new_console_p)