diff --git a/sys/riscv/riscv/sbi.c b/sys/riscv/riscv/sbi.c index 3e4312ed9ffa..bc8327cdfb9a 100644 --- a/sys/riscv/riscv/sbi.c +++ b/sys/riscv/riscv/sbi.c @@ -29,8 +29,11 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include +#include +#include #include #include @@ -80,6 +83,13 @@ sbi_get_mimpid(void) return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID)); } +static void +sbi_shutdown_final(void *dummy __unused, int howto) +{ + if ((howto & RB_POWEROFF) != 0) + sbi_shutdown(); +} + void sbi_print_version(void) { @@ -187,3 +197,12 @@ sbi_init(void) KASSERT(sbi_probe_extension(SBI_SHUTDOWN) != 0, ("SBI doesn't implement sbi_shutdown()")); } + +static void +sbi_late_init(void *dummy __unused) +{ + EVENTHANDLER_REGISTER(shutdown_final, sbi_shutdown_final, NULL, + SHUTDOWN_PRI_LAST); +} + +SYSINIT(sbi, SI_SUB_KLD, SI_ORDER_ANY, sbi_late_init, NULL);