From 1f9d7cd6a6a6bb90276cfdafaae8e4425f0be1c7 Mon Sep 17 00:00:00 2001 From: Zhouqi Jiang Date: Thu, 24 Oct 2024 16:04:10 +0800 Subject: [PATCH] riscv64: use SBI SRST extension instead of legacy SBI for system shutdown Legacy SBI have been deprecated years ago (on Jun 9, 2021). Modern RISC-V SBI firmware would use SBI SRST extension to shutdown an S-mode environment; we use `sbi-rt` crate for this purpose. Unused feature gate `opensbi` is removed, as RISC-V SBI support does not usually satisfy which implementation we'd use, unless e.g. fixing implementation-specific bugs. Signed-off-by: Zhouqi Jiang --- Cargo.lock | 16 ++++++++++++++++ riscv64/Cargo.toml | 2 +- riscv64/src/sbi.rs | 6 ++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea85257..6da4c4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,8 +243,24 @@ name = "riscv64" version = "0.1.0" dependencies = [ "port", + "sbi-rt", ] +[[package]] +name = "sbi-rt" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fbaa69be1eedc61c426e6d489b2260482e928b465360576900d52d496a58bd0" +dependencies = [ + "sbi-spec", +] + +[[package]] +name = "sbi-spec" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e36312fb5ddc10d08ecdc65187402baba4ac34585cb9d1b78522ae2358d890" + [[package]] name = "serde" version = "1.0.210" diff --git a/riscv64/Cargo.toml b/riscv64/Cargo.toml index a2a6a1b..d10fec6 100644 --- a/riscv64/Cargo.toml +++ b/riscv64/Cargo.toml @@ -8,9 +8,9 @@ default-target = "riscv64gc-unknown-none-elf" [dependencies] port = { path = "../port" } +sbi-rt = "0.0.3" [features] -opensbi = [] [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(platform, values("nezha"))', 'cfg(platform, values("virt"))'] } diff --git a/riscv64/src/sbi.rs b/riscv64/src/sbi.rs index db35524..8c6e4e1 100644 --- a/riscv64/src/sbi.rs +++ b/riscv64/src/sbi.rs @@ -49,6 +49,8 @@ pub fn _consgetb() -> u8 { } pub fn shutdown() -> ! { - sbi_call_legacy(SBI_SHUTDOWN, 0, 0, 0); - panic!("shutdown failed!"); + sbi_rt::system_reset(sbi_rt::Shutdown, sbi_rt::NoReason); + loop { + unsafe { core::arch::asm!("wfi") } + } }