cpu/x86/tsc: compile same code for all stages

The delay_tsc.c code took different paths depending
__PRE_RAM__ being defined or not. Also, timer_monotonic_get()
was only compiled in a !__PRE_RAM__ environment. Clean up
the code paths by employing CAR_GLOBAL for the global state
which allows the same code to be used in all stages.

Lastly, handle apollolake fallout now that init_timer() is
not needed in placeholders.c.

Change-Id: Ia769fa71e2c9d8b11201a3896d117097f2cb7c56
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/14301
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:
Aaron Durbin 2016-04-08 21:28:11 -05:00 committed by Martin Roth
parent 711bfa9710
commit 01dfdc5369
2 changed files with 8 additions and 22 deletions

View File

@ -1,3 +1,4 @@
#include <arch/early_variables.h>
#include <console/console.h> #include <console/console.h>
#include <arch/io.h> #include <arch/io.h>
#include <cpu/x86/msr.h> #include <cpu/x86/msr.h>
@ -6,9 +7,7 @@
#include <delay.h> #include <delay.h>
#include <thread.h> #include <thread.h>
#if !defined(__PRE_RAM__) static unsigned long clocks_per_usec CAR_GLOBAL;
static unsigned long clocks_per_usec;
#if CONFIG_TSC_CONSTANT_RATE #if CONFIG_TSC_CONSTANT_RATE
static unsigned long calibrate_tsc(void) static unsigned long calibrate_tsc(void)
@ -94,22 +93,15 @@ bad_ctc:
void init_timer(void) void init_timer(void)
{ {
if (!clocks_per_usec) if (!car_get_var(clocks_per_usec))
clocks_per_usec = calibrate_tsc(); car_set_var(clocks_per_usec, calibrate_tsc());
} }
static inline unsigned long get_clocks_per_usec(void) static inline unsigned long get_clocks_per_usec(void)
{ {
init_timer(); init_timer();
return clocks_per_usec; return car_get_var(clocks_per_usec);
} }
#else /* !defined(__PRE_RAM__) */
/* romstage calls into cpu/board specific function every time. */
static inline unsigned long get_clocks_per_usec(void)
{
return tsc_freq_mhz();
}
#endif /* !defined(__PRE_RAM__) */
void udelay(unsigned us) void udelay(unsigned us)
{ {
@ -130,18 +122,18 @@ void udelay(unsigned us)
} }
} }
#if CONFIG_TSC_MONOTONIC_TIMER && !defined(__PRE_RAM__) #if CONFIG_TSC_MONOTONIC_TIMER
#include <timer.h> #include <timer.h>
static struct monotonic_counter { 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_g; } mono_counter_g CAR_GLOBAL;
static inline struct monotonic_counter *get_monotonic_context(void) static inline struct monotonic_counter *get_monotonic_context(void)
{ {
return &mono_counter_g; return car_get_var_ptr(&mono_counter_g);
} }
void timer_monotonic_get(struct mono_time *mt) void timer_monotonic_get(struct mono_time *mt)

View File

@ -6,9 +6,3 @@
void southbridge_smi_set_eos(void) void southbridge_smi_set_eos(void)
{ {
} }
#if ENV_BOOTBLOCK
void init_timer(void)
{
}
#endif