lib: sbi_timer: Call driver warm_init from SBI core

Currently, the platform's timer device is tracked in two places: the
core SBI implementation has `timer_dev`, and the FDT timer layer has
`current_driver`. The latter is used for warm initialization of the
timer device. However, this warm init is not specific to FDT-based
platforms; other platforms call exactly the same functions from the
same point in the boot sequence.

The code is simplified and made common across platforms by treating warm
init and exit as properties of the driver, not the platform. Then the
platform's only role is to select and prepare a driver during cold boot.

For now, only add a .warm_init hook, since none of the existing drivers
need an .exit hook. It could be added in the future if needed.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-09-02 21:06:49 -07:00
committed by Anup Patel
parent 1a2e507d23
commit 4500828743
13 changed files with 36 additions and 23 deletions

View File

@@ -183,6 +183,7 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
{
u64 *time_delta;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
int ret;
if (cold_boot) {
time_delta_off = sbi_scratch_alloc_offset(sizeof(*time_delta));
@@ -199,7 +200,17 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
*time_delta = 0;
return sbi_platform_timer_init(plat, cold_boot);
ret = sbi_platform_timer_init(plat, cold_boot);
if (ret)
return ret;
if (timer_dev && timer_dev->warm_init) {
ret = timer_dev->warm_init();
if (ret)
return ret;
}
return 0;
}
void sbi_timer_exit(struct sbi_scratch *scratch)