diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-01-03 12:43:33 +0300 |
---|---|---|
committer | Anup Patel <anup.patel@wdc.com> | 2020-01-07 09:41:48 +0300 |
commit | a67fd68cbf02af84af9e6e7f8e28aadcecc94910 (patch) | |
tree | 87d35be847cacf6b2bac33d65a6a84259151b0e6 /lib/sbi/sbi_init.c | |
parent | 73c19e69f3000351dc30d272a17dffa694e9b6bf (diff) | |
download | opensbi-a67fd68cbf02af84af9e6e7f8e28aadcecc94910.tar.xz |
lib: Add sbi_init_count() API
We add sbi_init_count() API which provides number of times a
given HART completed init sequence (warmboot/coldboot).
This will be very useful in debugging. With upcoming SBI HSM
extension, it will also help in implementing one-time init
code for each HART.
Signed-off-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_init.c')
-rw-r--r-- | lib/sbi/sbi_init.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 3753800..4afeed2 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -70,11 +70,19 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid) sbi_hart_pmp_dump(scratch); } +static unsigned long init_count_offset; + static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) { int rc; + unsigned long *init_count; const struct sbi_platform *plat = sbi_platform_ptr(scratch); + init_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__, + "INIT_COUNT"); + if (!init_count_offset) + sbi_hart_hang(); + rc = sbi_system_early_init(scratch, TRUE); if (rc) sbi_hart_hang(); @@ -110,6 +118,9 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) sbi_hart_mark_available(hartid); + init_count = sbi_scratch_offset_ptr(scratch, init_count_offset); + (*init_count)++; + sbi_hart_switch_mode(hartid, scratch->next_arg1, scratch->next_addr, scratch->next_mode, FALSE); } @@ -117,10 +128,14 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid) { int rc; + unsigned long *init_count; const struct sbi_platform *plat = sbi_platform_ptr(scratch); sbi_hart_wait_for_coldboot(scratch, hartid); + if (!init_count_offset) + sbi_hart_hang(); + rc = sbi_system_early_init(scratch, FALSE); if (rc) sbi_hart_hang(); @@ -147,6 +162,9 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid) sbi_hart_mark_available(hartid); + init_count = sbi_scratch_offset_ptr(scratch, init_count_offset); + (*init_count)++; + sbi_hart_switch_mode(hartid, scratch->next_arg1, scratch->next_addr, scratch->next_mode, FALSE); @@ -184,6 +202,21 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) init_warmboot(scratch, hartid); } +unsigned long sbi_init_count(u32 hartid) +{ + struct sbi_scratch *scratch; + unsigned long *init_count; + + if (sbi_platform_hart_count(sbi_platform_thishart_ptr()) <= hartid || + !init_count_offset) + return 0; + + scratch = sbi_hart_id_to_scratch(sbi_scratch_thishart_ptr(), hartid); + init_count = sbi_scratch_offset_ptr(scratch, init_count_offset); + + return *init_count; +} + /** * Exit OpenSBI library for current HART and stop HART * |