libpayload: timer: Revert timer_hz() return type to 64-bits

It seems that reducing the return type of timer_hz() to uint32_t in
CB:78888 was a bad idea... some Intel platforms actually use their raw
CPU clock for the timestamp counter which can be higher than 4GHz. This
patch reverts it back to uint64_t.

Also remove the redundant assertion in timer/generic.c since timer_us()
itself already does that check.

Cq-Depend: chromium:5274555
Change-Id: I471c7de7a28aec5bb965b23525ed579481ac8361
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/80320
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Yidi Lin <yidilin@google.com>
This commit is contained in:
Julius Werner
2024-02-06 22:52:06 -08:00
parent ddc5260e3b
commit 5ec3deac6b
5 changed files with 8 additions and 10 deletions

View File

@ -32,7 +32,7 @@
#include <arch/lib_helpers.h> #include <arch/lib_helpers.h>
#include <libpayload.h> #include <libpayload.h>
uint32_t timer_hz(void) uint64_t timer_hz(void)
{ {
return raw_read_cntfrq_el0(); return raw_read_cntfrq_el0();
} }

View File

@ -33,10 +33,8 @@
#include <assert.h> #include <assert.h>
#include <libpayload.h> #include <libpayload.h>
uint32_t timer_hz(void) uint64_t timer_hz(void)
{ {
/* libc/time.c currently requires all timers to be at least 1MHz. */
assert(CONFIG_LP_TIMER_GENERIC_HZ >= 1000000);
return CONFIG_LP_TIMER_GENERIC_HZ; return CONFIG_LP_TIMER_GENERIC_HZ;
} }

View File

@ -35,10 +35,9 @@
#include <arch/rdtsc.h> #include <arch/rdtsc.h>
#include <assert.h> #include <assert.h>
uint32_t timer_hz(void) uint64_t timer_hz(void)
{ {
assert(UINT32_MAX / 1000 >= lib_sysinfo.cpu_khz); return (uint64_t)lib_sysinfo.cpu_khz * 1000;
return lib_sysinfo.cpu_khz * 1000;
} }
uint64_t timer_raw_value(void) uint64_t timer_raw_value(void)

View File

@ -519,7 +519,7 @@ void lib_sysinfo_get_memranges(struct memrange **ranges,
/* Timer functions. */ /* Timer functions. */
/* Defined by each architecture. */ /* Defined by each architecture. */
uint32_t timer_hz(void); uint64_t timer_hz(void);
uint64_t timer_raw_value(void); uint64_t timer_raw_value(void);
uint64_t timer_us(uint64_t base); uint64_t timer_us(uint64_t base);
/* Generic. */ /* Generic. */

View File

@ -171,14 +171,15 @@ void arch_ndelay(uint64_t ns)
u64 timer_us(u64 base) u64 timer_us(u64 base)
{ {
static u32 hz, mult = USECS_PER_SEC; static u64 hz;
static u32 mult = USECS_PER_SEC;
u32 div; u32 div;
// Only check timer_hz once. Assume it doesn't change. // Only check timer_hz once. Assume it doesn't change.
if (hz == 0) { if (hz == 0) {
hz = timer_hz(); hz = timer_hz();
if (hz < mult) { if (hz < mult) {
printf("Timer frequency %" PRIu32 " is too low, " printf("Timer frequency %" PRIu64 " is too low, "
"must be at least 1MHz.\n", hz); "must be at least 1MHz.\n", hz);
halt(); halt();
} }