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 const char *platform_halt_action_string(platform_halt_action action); 25 26 typedef enum { 27 HALT_REASON_UNKNOWN = 0, 28 HALT_REASON_POR, // Cold-boot 29 HALT_REASON_HW_WATCHDOG, // HW watchdog timer 30 HALT_REASON_LOWVOLTAGE, // LV/Brownout condition 31 HALT_REASON_HIGHVOLTAGE, // High voltage condition. 32 HALT_REASON_THERMAL, // Thermal reason (probably overtemp) 33 HALT_REASON_OTHER_HW, // Other hardware (platform) specific reason 34 HALT_REASON_SW_RESET, // Generic Software Initiated Reboot 35 HALT_REASON_SW_WATCHDOG, // Reboot triggered by a SW watchdog timer 36 HALT_REASON_SW_PANIC, // Reboot triggered by a SW panic or ASSERT 37 HALT_REASON_SW_UPDATE, // SW triggered reboot in order to begin firmware update 38 } platform_halt_reason; 39 40 const char *platform_halt_reason_string(platform_halt_reason reason); 41 42 /* if the platform has knowledge of what caused the latest reboot, it can report 43 * it to applications with this function. */ 44 platform_halt_reason platform_get_reboot_reason(void); 45 46 /* platform_halt is a method which is called from various places in the LK 47 * system, and may be implemented by platforms and called by applications. This 48 * call represents the end of the life of SW for a device; there is no returning 49 * from this function. Callers will provide a reason for the halt, and a 50 * suggested action for the platform to take, but it is the platform's 51 * responsibility to determine the final action taken. For example, in the case 52 * of a failed ASSERT or a panic, LK will call platform halt and suggest a Halt 53 * action, but a release build on a platform with no debug channel may choose to 54 * reboot instead as there is no one to tell about the ASSERT, and no one 55 * waiting to debug the device in its halted state. If not overloaded by the 56 * platform, the default behavior of platform halt will be to dprintf the 57 * reason, and then halt execution by turning off interrupts and spinning 58 * forever. 59 */ 60 __WEAK void platform_halt(platform_halt_action suggested_action, 61 platform_halt_reason reason) __NO_RETURN; 62 63 /* Default implementation of the above routine, which platforms can call with 64 * appropriate hooks to implement platform specific reboot and shutdown behavior. 65 */ 66 typedef void (*platform_reboot_hook)(void); 67 typedef void (*platform_shutdown_hook)(void); 68 void platform_halt_default(platform_halt_action suggested_action, 69 platform_halt_reason reason, 70 platform_reboot_hook prh, 71 platform_shutdown_hook psh) __NO_RETURN; 72 73 /* called during chain loading to make sure drivers and platform is put into a stopped state */ 74 void platform_quiesce(void); 75 76 /* super early platform initialization, before almost everything */ 77 void platform_early_init(void); 78 79 /* later init, after the kernel has come up */ 80 void platform_init(void); 81 82 /* called by the arch init code to get the platform to set up any mmu mappings it may need */ 83 void platform_init_mmu_mappings(void); 84 85 /* Called by LK to get the device tree */ 86 const void *get_fdt(void); 87 88 __END_CDECLS 89 90