cpu/x86/tsc: prepare for CAR_GLOBAL in delay_tsc.c
The current code in delay_tsc.c uses globals and is heavily guarded by a lot of preprocessor macros. In order to remove __PRE_RAM__ constraints one needs to use CAR_GLOBAL for the global variables. Therefore, abstract away direct access to the globals such that CAR_GLOBAL can be easily employed. Change-Id: I3350d1a762120476926c8d9f5f5a7aba138daf5f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/14300 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Andrey Petrov <andrey.petrov@intel.com>
This commit is contained in:
		
				
					committed by
					
						 Martin Roth
						Martin Roth
					
				
			
			
				
	
			
			
			
						parent
						
							6f3a55ae7e
						
					
				
				
					commit
					711bfa9710
				
			| @@ -137,32 +137,41 @@ static struct monotonic_counter { | |||||||
| 	int initialized; | 	int initialized; | ||||||
| 	struct mono_time time; | 	struct mono_time time; | ||||||
| 	uint64_t last_value; | 	uint64_t last_value; | ||||||
| } mono_counter; | } mono_counter_g; | ||||||
|  |  | ||||||
|  | static inline struct monotonic_counter *get_monotonic_context(void) | ||||||
|  | { | ||||||
|  | 	return &mono_counter_g; | ||||||
|  | } | ||||||
|  |  | ||||||
| void timer_monotonic_get(struct mono_time *mt) | void timer_monotonic_get(struct mono_time *mt) | ||||||
| { | { | ||||||
| 	uint64_t current_tick; | 	uint64_t current_tick; | ||||||
| 	uint64_t ticks_elapsed; | 	uint64_t ticks_elapsed; | ||||||
|  | 	unsigned long ticks_per_usec; | ||||||
|  | 	struct monotonic_counter *mono_counter; | ||||||
|  |  | ||||||
| 	if (!mono_counter.initialized) { | 	mono_counter = get_monotonic_context(); | ||||||
|  | 	if (!mono_counter->initialized) { | ||||||
| 		init_timer(); | 		init_timer(); | ||||||
| 		mono_counter.last_value = rdtscll(); | 		mono_counter->last_value = rdtscll(); | ||||||
| 		mono_counter.initialized = 1; | 		mono_counter->initialized = 1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	current_tick = rdtscll(); | 	current_tick = rdtscll(); | ||||||
| 	ticks_elapsed = current_tick - mono_counter.last_value; | 	ticks_elapsed = current_tick - mono_counter->last_value; | ||||||
|  | 	ticks_per_usec = get_clocks_per_usec(); | ||||||
|  |  | ||||||
| 	/* Update current time and tick values only if a full tick occurred. */ | 	/* Update current time and tick values only if a full tick occurred. */ | ||||||
| 	if (ticks_elapsed >= clocks_per_usec) { | 	if (ticks_elapsed >= ticks_per_usec) { | ||||||
| 		uint64_t usecs_elapsed; | 		uint64_t usecs_elapsed; | ||||||
|  |  | ||||||
| 		usecs_elapsed = ticks_elapsed / clocks_per_usec; | 		usecs_elapsed = ticks_elapsed / ticks_per_usec; | ||||||
| 		mono_time_add_usecs(&mono_counter.time, (long)usecs_elapsed); | 		mono_time_add_usecs(&mono_counter->time, (long)usecs_elapsed); | ||||||
| 		mono_counter.last_value = current_tick; | 		mono_counter->last_value = current_tick; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/* Save result. */ | 	/* Save result. */ | ||||||
| 	*mt = mono_counter.time; | 	*mt = mono_counter->time; | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user