Mathew King has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36664 )
Change subject: x86/tsc: Only call tsc_freq_mhz once to init clock ......................................................................
x86/tsc: Only call tsc_freq_mhz once to init clock
This change partially reverts https://review.coreboot.org/c/coreboot/+/33928 by only calling tsc_freq_mhz on timer init and storing the result.
The change caused an error on Drallion where coreboot could not communicate with the TPM on a cold boot causing the system to not boot.
BUG=b:144002424 TEST=Repeatedly cold boot drallion without TPM errors
Change-Id: I8e9edafa3007568e8d27e3c19c9fd6fa7637786c Signed-off-by: Mathew King mathewk@chromium.org --- M src/cpu/x86/tsc/delay_tsc.c 1 file changed, 12 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/64/36664/1
diff --git a/src/cpu/x86/tsc/delay_tsc.c b/src/cpu/x86/tsc/delay_tsc.c index 7aa887a..dcec4fb 100644 --- a/src/cpu/x86/tsc/delay_tsc.c +++ b/src/cpu/x86/tsc/delay_tsc.c @@ -18,9 +18,18 @@ #include <delay.h> #include <thread.h>
+static unsigned long clocks_per_usec CAR_GLOBAL; + void init_timer(void) { - (void)tsc_freq_mhz(); + if (!car_get_var(clocks_per_usec)) + car_set_var(clocks_per_usec, tsc_freq_mhz()); +} + +static inline unsigned long get_clocks_per_usec(void) +{ + init_timer(); + return car_get_var(clocks_per_usec); }
void udelay(unsigned int us) @@ -34,7 +43,7 @@
start = rdtscll(); clocks = us; - clocks *= tsc_freq_mhz(); + clocks *= get_clocks_per_usec(); current = rdtscll(); while ((current - start) < clocks) { cpu_relax(); @@ -72,7 +81,7 @@
current_tick = rdtscll(); ticks_elapsed = current_tick - mono_counter->last_value; - ticks_per_usec = tsc_freq_mhz(); + ticks_per_usec = get_clocks_per_usec();
/* Update current time and tick values only if a full tick occurred. */ if (ticks_elapsed >= ticks_per_usec) {