Skip to main content

platform_rs/
power.rs

1// Copyright 2026 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7#[repr(u32)]
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum PlatformHaltAction {
10    /// Spin forever.
11    Halt = 0,
12
13    /// Reset the CPU.
14    Reboot = 1,
15
16    /// Reboot into the bootloader.
17    RebootBootloader = 2,
18
19    /// Reboot into the recovery partition.
20    RebootRecovery = 3,
21
22    /// Shutdown and power off.
23    Shutdown = 4,
24}
25
26/// TODO(https://fxbug.dev/534467534): For now, these values are copied from zircon/system/public/zircon/boot/crash-reason.h.
27#[repr(u32)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub enum ZirconCrashReason {
30    /// 0 is reserved for "Invalid".  It will never be used by a functioning
31    /// crash-logger.
32    Invalid = 0,
33
34    /// "Unknown" indicates that the system does not know the reason for a recent
35    /// crash.  The primary use of this reason is to be something which can be left
36    /// in the crashlog in case the system spontaneously reboots without a chance to
37    /// gracefully finalize the log, perhaps because of something like a hardware
38    /// watchdog timer.
39    Unknown = 1,
40
41    /// "No Crash" indicates that the system deliberately rebooted in an
42    /// orderly fashion.  No crash occurred.
43    NoCrash = 2,
44
45    /// "OOM" indicates a crash triggered by the system because of an unrecoverable
46    /// out-of-memory situation.
47    Oom = 3,
48
49    /// "Panic" indicates a crash triggered by the system because of an unrecoverable
50    /// kernel panic situation.
51    Panic = 4,
52
53    /// "Software watchdog" indicates a crash triggered by a kernel level software
54    /// watchdog construct.  Note that this is distinct from a hardware based WDT.
55    /// If the system reboots because of a hardware watchdog, it will have no chance
56    /// to record the reboot reason, and the crashlog will indicate "unknown".  The
57    /// HW reboot reason may be known, but only if the bootloader reports it to us.
58    SoftwareWatchdog = 5,
59
60    /// "Userspace root job termination" indicates a crash triggered by the system
61    /// because it detected the termination of the userspace root job, most likely
62    /// because one of its critical processes crashed.
63    UserspaceRootJobTermination = 6,
64}
65
66unsafe extern "C" {
67    fn cpp_platform_halt(action: u32, reason: u32) -> !;
68}
69
70/// Halts the platform.
71#[inline]
72pub fn platform_halt(action: PlatformHaltAction, reason: ZirconCrashReason) -> ! {
73    unsafe { cpp_platform_halt(action as u32, reason as u32) }
74}