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)
This commit is contained in:
		@@ -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) { }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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) { }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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) { }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user