1 /*
2  * Copyright (c) 2008 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <lk/compiler.h>
11 #include <sys/types.h>
12 
13 /* TODO: move all callers to using time.h directly */
14 #include <platform/time.h>
15 
16 __BEGIN_CDECLS
17 
18 typedef enum {
19     HALT_ACTION_HALT = 0,       // Spin forever.
20     HALT_ACTION_REBOOT,         // Reset the CPU.
21     HALT_ACTION_SHUTDOWN,       // Shutdown and power off.
22 } platform_halt_action;
23 
24 typedef enum {
25     HALT_REASON_UNKNOWN = 0,
26     HALT_REASON_POR,            // Cold-boot
27     HALT_REASON_HW_WATCHDOG,    // HW watchdog timer
28     HALT_REASON_LOWVOLTAGE,     // LV/Brownout condition
29     HALT_REASON_HIGHVOLTAGE,    // High voltage condition.
30     HALT_REASON_THERMAL,        // Thermal reason (probably overtemp)
31     HALT_REASON_OTHER_HW,       // Other hardware (platform) specific reason
32     HALT_REASON_SW_RESET,       // Generic Software Initiated Reboot
33     HALT_REASON_SW_WATCHDOG,    // Reboot triggered by a SW watchdog timer
34     HALT_REASON_SW_PANIC,       // Reboot triggered by a SW panic or ASSERT
35     HALT_REASON_SW_UPDATE,      // SW triggered reboot in order to begin firmware update
36 } platform_halt_reason;
37 
38 /* super early platform initialization, before almost everything */
39 void platform_early_init(void);
40 
41 /* later init, after the kernel has come up */
42 void platform_init(void);
43 
44 /* called by the arch init code to get the platform to set up any mmu mappings it may need */
45 void platform_init_mmu_mappings(void);
46 
47 /* if the platform has knowledge of what caused the latest reboot, it can report
48  * it to applications with this function.  */
49 platform_halt_reason platform_get_reboot_reason(void);
50 
51 /* platform_halt is a method which is called from various places in the LK
52  * system, and may be implemented by platforms and called by applications.  This
53  * call represents the end of the life of SW for a device; there is no returning
54  * from this function.  Callers will provide a reason for the halt, and a
55  * suggested action for the platform to take, but it is the platform's
56  * responsibility to determine the final action taken.  For example, in the case
57  * of a failed ASSERT or a panic, LK will call platform halt and suggest a Halt
58  * action, but a release build on a platform with no debug channel may choose to
59  * reboot instead as there is no one to tell about the ASSERT, and no one
60  * waiting to debug the device in its halted state.  If not overloaded by the
61  * platform, the default behavior of platform halt will be to dprintf the
62  * reason, and then halt execution by turning off interrupts and spinning
63  * forever.
64  */
65 void platform_halt(platform_halt_action suggested_action,
66                    platform_halt_reason reason) __NO_RETURN;
67 
68 /* called during chain loading to make sure drivers and platform is put into a stopped state */
69 void platform_quiesce(void);
70 
71 __END_CDECLS
72 
73