Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv: sbi: Prefer SRST shutdown over legacy

Currently, the sbi_init() always attempts to register the legacy shutdown
function as the sys-off handler which is fine when RISCV_SBI_V01 is not
enabled. However, if RISCV_SBI_V01 is enabled in the kernel and the SBI
v0.1 is not supported by the underlying SBI implementation then the
legacy shutdown fails. Fix this by not registering the legacy shutdown
when SRST shutdown is available.

Fixes: 70ddf86d76c1 ("riscv: sbi: Switch to new sys-off handler API")
Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://patch.msgid.link/20251114065808.304430-1-mchitale@ventanamicro.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>

authored by

Mayuresh Chitale and committed by
Paul Walmsley
7b090e7b 91f815b7

+5 -1
+5 -1
arch/riscv/kernel/sbi.c
··· 648 648 649 649 void __init sbi_init(void) 650 650 { 651 + bool srst_power_off = false; 651 652 int ret; 652 653 653 - sbi_set_power_off(); 654 654 ret = sbi_get_spec_version(); 655 655 if (ret > 0) 656 656 sbi_spec_version = ret; ··· 683 683 sbi_probe_extension(SBI_EXT_SRST)) { 684 684 pr_info("SBI SRST extension detected\n"); 685 685 register_platform_power_off(sbi_srst_power_off); 686 + srst_power_off = true; 686 687 sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot; 687 688 sbi_srst_reboot_nb.priority = 192; 688 689 register_restart_handler(&sbi_srst_reboot_nb); ··· 703 702 __sbi_send_ipi = __sbi_send_ipi_v01; 704 703 __sbi_rfence = __sbi_rfence_v01; 705 704 } 705 + 706 + if (!srst_power_off) 707 + sbi_set_power_off(); 706 708 }