1use crate::{ecall2, RestrictedRange, SbiError};
9
10pub const EXTENSION_ID: usize = 0x53525354;
12
13#[derive(Debug, Clone, Copy)]
15#[non_exhaustive]
16pub enum ResetType {
17 Shutdown,
19 ColdReboot,
21 WarmReboot,
23 PlatformSpecific(RestrictedRange<0xF0000000, 0xFFFFFFFF>),
25}
26
27impl From<ResetType> for u32 {
28 fn from(value: ResetType) -> Self {
29 match value {
30 ResetType::Shutdown => 0,
31 ResetType::ColdReboot => 1,
32 ResetType::WarmReboot => 2,
33 ResetType::PlatformSpecific(n) => n.0,
34 }
35 }
36}
37
38#[derive(Debug, Clone, Copy)]
40#[non_exhaustive]
41pub enum ResetReason {
42 NoReason,
44 SystemFailure,
46 SbiSpecific(RestrictedRange<0xE0000000, 0xEFFFFFFF>),
48 PlatformSpecific(RestrictedRange<0xF0000000, 0xFFFFFFFF>),
50}
51
52impl From<ResetReason> for u32 {
53 fn from(value: ResetReason) -> Self {
54 match value {
55 ResetReason::NoReason => 0,
56 ResetReason::SystemFailure => 1,
57 ResetReason::SbiSpecific(n) => n.0,
58 ResetReason::PlatformSpecific(n) => n.0,
59 }
60 }
61}
62
63pub fn system_reset(
72 kind: ResetType,
73 reason: ResetReason,
74) -> Result<core::convert::Infallible, SbiError> {
75 match unsafe {
76 ecall2(
77 u32::from(kind) as usize,
78 u32::from(reason) as usize,
79 EXTENSION_ID,
80 0,
81 )
82 } {
83 Ok(_) => unreachable!("SBI returned `Ok` after a system reset call"),
84 Err(e) => Err(e),
85 }
86}