summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arch/arm/include/arch/early_variables.h4
-rw-r--r--src/arch/arm64/include/arch/early_variables.h4
-rw-r--r--src/arch/mips/include/arch/early_variables.h4
-rw-r--r--src/arch/ppc64/include/arch/early_variables.h5
-rw-r--r--src/arch/riscv/include/arch/early_variables.h4
-rw-r--r--src/arch/x86/include/arch/early_variables.h19
-rw-r--r--src/cpu/x86/car.c49
-rw-r--r--src/lib/cbmem_console.c4
8 files changed, 52 insertions, 41 deletions
diff --git a/src/arch/arm/include/arch/early_variables.h b/src/arch/arm/include/arch/early_variables.h
index 9f069232a6..7002a8805e 100644
--- a/src/arch/arm/include/arch/early_variables.h
+++ b/src/arch/arm/include/arch/early_variables.h
@@ -18,7 +18,9 @@
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)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+
#endif
diff --git a/src/arch/arm64/include/arch/early_variables.h b/src/arch/arm64/include/arch/early_variables.h
index 9f069232a6..7002a8805e 100644
--- a/src/arch/arm64/include/arch/early_variables.h
+++ b/src/arch/arm64/include/arch/early_variables.h
@@ -18,7 +18,9 @@
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)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+
#endif
diff --git a/src/arch/mips/include/arch/early_variables.h b/src/arch/mips/include/arch/early_variables.h
index 8fc9c19050..6ad82606c4 100644
--- a/src/arch/mips/include/arch/early_variables.h
+++ b/src/arch/mips/include/arch/early_variables.h
@@ -19,7 +19,9 @@
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) { (var) = (val); }
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+
#endif /* __MIPS_ARCH_EARLY_VARIABLES_H */
diff --git a/src/arch/ppc64/include/arch/early_variables.h b/src/arch/ppc64/include/arch/early_variables.h
index 22c375051e..05b8bc7e48 100644
--- a/src/arch/ppc64/include/arch/early_variables.h
+++ b/src/arch/ppc64/include/arch/early_variables.h
@@ -19,8 +19,9 @@
#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)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+
#endif
diff --git a/src/arch/riscv/include/arch/early_variables.h b/src/arch/riscv/include/arch/early_variables.h
index acc5ac3c6b..a2da5f86ee 100644
--- a/src/arch/riscv/include/arch/early_variables.h
+++ b/src/arch/riscv/include/arch/early_variables.h
@@ -21,7 +21,9 @@
#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)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+
#endif
diff --git a/src/arch/x86/include/arch/early_variables.h b/src/arch/x86/include/arch/early_variables.h
index 3910a820da..8111e7e10b 100644
--- a/src/arch/x86/include/arch/early_variables.h
+++ b/src/arch/x86/include/arch/early_variables.h
@@ -33,19 +33,25 @@ 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);
-
/* Return 1 when currently running with globals in Cache-as-RAM, 0 otherwise. */
int car_active(void);
/* 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) car_get_var(var) = (val)
+/* Get and set a CAR_GLOBAL pointing elsewhere inside CAR. */
+#if !CONFIG(PLATFORM_USES_FSP1_0)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
+#else
+void *car_get_reloc_ptr(void *var);
+void car_set_reloc_ptr(void *var, void *val);
+#define car_get_ptr(var) car_get_reloc_ptr(&(var))
+#define car_set_ptr(var, val) car_set_reloc_ptr(&(var), (val))
+#endif
+
static inline size_t car_data_size(void)
{
size_t car_size = _car_relocatable_data_size;
@@ -66,8 +72,9 @@ static inline size_t car_object_offset(void *ptr)
#define CAR_GLOBAL
#define car_get_var(var) (var)
-#define car_sync_var(var) (var)
#define car_set_var(var, val) (var) = (val)
+#define car_get_ptr car_get_var
+#define car_set_ptr car_set_var
static inline void *car_get_var_ptr(void *var)
{
diff --git a/src/cpu/x86/car.c b/src/cpu/x86/car.c
index 6fc61686df..009ac192cc 100644
--- a/src/cpu/x86/car.c
+++ b/src/cpu/x86/car.c
@@ -77,41 +77,36 @@ void *car_get_var_ptr(void *var)
return &migrated_base[offset];
}
+#if CONFIG(PLATFORM_USES_FSP1_0)
/*
- * Update a CAR_GLOBAL variable var, originally pointing to CAR region,
- * with the address in migrated CAR region in DRAM.
+ * When a CAR_GLOBAL points to target object inside CAR, use relative
+ * addressing. Such CAR_GLOBAL has to be expicitly accessed using
+ * car_set_reloc_ptr() and car_get_reloc_ptr() as the stored value is now
+ * an offset instead of the absolute address (pointer) of the target.
+ *
+ * This way discovery of objects that are not CAR_GLOBALs themselves,
+ * remain discoverable after CAR migration has implicitly happened.
*/
-void *car_sync_var_ptr(void *var)
+void car_set_reloc_ptr(void *var, void *val)
{
- void **mig_var = car_get_var_ptr(var);
- void *_car_start = _car_relocatable_data_start;
- void *_car_end = _car_relocatable_data_end;
+ uintptr_t *offset = car_get_var_ptr(var);
+ *offset = 0;
- /* Not moved or migrated yet. */
- if (mig_var == var)
- return mig_var;
-
- /*
- * Migrate the cbmem console pointer for FSP 1.0 platforms. Otherwise,
- * keep console buffer in CAR until cbmemc_reinit() moves it.
- */
- if (*mig_var == _preram_cbmem_console) {
- if (CONFIG(PLATFORM_USES_FSP1_0))
- *mig_var += (char *)mig_var - (char *)var;
- return mig_var;
- }
+ if (val)
+ *offset = (uintptr_t)offset - (uintptr_t)val;
+}
- /* It's already pointing outside car.global_data. */
- if (*mig_var < _car_start || *mig_var > _car_end)
- return mig_var;
+void *car_get_reloc_ptr(void *var)
+{
+ uintptr_t *offset = car_get_var_ptr(var);
+ void *val = NULL;
- /* Move the pointer by the same amount the variable storing it was
- * moved by.
- */
- *mig_var += (char *)mig_var - (char *)var;
+ if (*offset)
+ val = (void *)((uintptr_t)offset - *offset);
- return mig_var;
+ return val;
}
+#endif
int car_active(void)
{
diff --git a/src/lib/cbmem_console.c b/src/lib/cbmem_console.c
index df2d1ffa96..18c3b71b4f 100644
--- a/src/lib/cbmem_console.c
+++ b/src/lib/cbmem_console.c
@@ -73,12 +73,12 @@ static u8 static_console[STATIC_CONSOLE_SIZE];
static struct cbmem_console *current_console(void)
{
- return car_sync_var(cbmem_console_p);
+ return car_get_ptr(cbmem_console_p);
}
static void current_console_set(struct cbmem_console *new_console_p)
{
- car_set_var(cbmem_console_p, new_console_p);
+ car_set_ptr(cbmem_console_p, new_console_p);
}
static int buffer_valid(struct cbmem_console *cbm_cons_p, u32 total_space)