From 3b2962929b9402ecaaea1b9e2fa72d6ca47cc29e Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Sat, 16 Aug 2025 15:15:43 +0200 Subject: [PATCH] lib/timestamp: Init TSC frequency early on x86 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When get_us_since_boot() is called in pre-ram stages on x86 init the TSC frequency. The TSC frequency is necessary to calculate the time spent since boot. When get_us_since_boot() is not used in pre-ram stages the function timestamp_tick_freq_mhz() will also be dropped by the linker, thus there's no code size increase for common code. Will be used in the following commit in pre-ram stages. Change-Id: I7fd9eeadf3063a629dd589498fcb957b9bd66536 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/88793 Reviewed-by: Paul Menzel Reviewed-by: Kyösti Mälkki Tested-by: build bot (Jenkins) Reviewed-by: Matt DeVillier --- src/lib/timestamp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c index c7e1c0cf4c..e25aaec412 100644 --- a/src/lib/timestamp.c +++ b/src/lib/timestamp.c @@ -274,6 +274,16 @@ uint32_t get_us_since_boot(void) { struct timestamp_table *ts = timestamp_table_get(); + /* + * Bootbock size is limited on some platforms, thus only + * enable get_us_since_boot() in PRERAM stages on x86 platforms + * for now. When get_us_since_boot() isn't used in preram the linker + * will drop timestamp_tick_freq_mhz(). + */ + if (CONFIG(ARCH_X86) && ENV_ROMSTAGE_OR_BEFORE && + ts && ts->tick_freq_mhz == 0) + ts->tick_freq_mhz = timestamp_tick_freq_mhz(); + if (ts == NULL || ts->tick_freq_mhz == 0) return 0; return (timestamp_get() - ts->base_time) / ts->tick_freq_mhz;