diff options
-rw-r--r-- | src/arch/arm/include/arch/early_variables.h | 1 | ||||
-rw-r--r-- | src/arch/arm64/include/arch/early_variables.h | 1 | ||||
-rw-r--r-- | src/arch/riscv/include/arch/early_variables.h | 1 | ||||
-rw-r--r-- | src/arch/x86/include/arch/early_variables.h | 6 | ||||
-rw-r--r-- | src/cpu/x86/car.c | 32 | ||||
-rw-r--r-- | src/lib/cbmem_console.c | 2 |
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) |