1 /* 2 * Copyright (c) 2008 Travis Geiselbrecht 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 #ifndef __PLATFORM_H 24 #define __PLATFORM_H 25 26 #include <sys/types.h> 27 #include <compiler.h> 28 29 __BEGIN_CDECLS; 30 31 typedef enum { 32 HALT_ACTION_HALT = 0, // Spin forever. 33 HALT_ACTION_REBOOT, // Reset the CPU. 34 HALT_ACTION_SHUTDOWN, // Shutdown and power off. 35 } platform_halt_action; 36 37 typedef enum { 38 HALT_REASON_UNKNOWN = 0, 39 HALT_REASON_POR, // Cold-boot 40 HALT_REASON_HW_WATCHDOG, // HW watchdog timer 41 HALT_REASON_LOWVOLTAGE, // LV/Brownout condition 42 HALT_REASON_HIGHVOLTAGE, // High voltage condition. 43 HALT_REASON_THERMAL, // Thermal reason (probably overtemp) 44 HALT_REASON_OTHER_HW, // Other hardware (platform) specific reason 45 HALT_REASON_SW_RESET, // Generic Software Initiated Reboot 46 HALT_REASON_SW_WATCHDOG, // Reboot triggered by a SW watchdog timer 47 HALT_REASON_SW_PANIC, // Reboot triggered by a SW panic or ASSERT 48 HALT_REASON_SW_UPDATE, // SW triggered reboot in order to begin firmware update 49 } platform_halt_reason; 50 51 lk_time_t current_time(void); 52 lk_time_ns_t current_time_ns(void); 53 54 /* super early platform initialization, before almost everything */ 55 void platform_early_init(void); 56 57 /* later init, after the kernel has come up */ 58 void platform_init(void); 59 60 /* called by the arch init code to get the platform to set up any mmu mappings it may need */ 61 void platform_init_mmu_mappings(void); 62 63 /* if the platform has knowledge of what caused the latest reboot, it can report 64 * it to applications with this function. */ 65 platform_halt_reason platform_get_reboot_reason(void); 66 67 /* platform_halt is a method which is called from various places in the LK 68 * system, and may be implemented by platforms and called by applications. This 69 * call represents the end of the life of SW for a device; there is no returning 70 * from this function. Callers will provide a reason for the halt, and a 71 * suggested action for the platform to take, but it is the platform's 72 * responsibility to determine the final action taken. For example, in the case 73 * of a failed ASSERT or a panic, LK will call platform halt and suggest a Halt 74 * action, but a release build on a platform with no debug channel may choose to 75 * reboot instead as there is no one to tell about the ASSERT, and no one 76 * waiting to debug the device in its halted state. If not overloaded by the 77 * platform, the default behavior of platform halt will be to dprintf the 78 * reason, and then halt execution by turning off interrupts and spinning 79 * forever. 80 */ 81 void platform_halt(platform_halt_action suggested_action, 82 platform_halt_reason reason) __NO_RETURN; 83 84 /* called during chain loading to make sure drivers and platform is put into a stopped state */ 85 void platform_quiesce(void); 86 87 /* called by LK idle thread to enter idle state. It is declared as WEAK 88 * (the default implementation is just calling arch_idle) and can be overridden 89 * by platform to implement platform specific handling. 90 */ 91 void platform_idle(void); 92 93 /* platform_early_halt is a simpler version of platform_halt() that can be 94 * called from any context, including early init and assembly with no stack. 95 */ 96 void platform_early_halt(void) __NO_RETURN; 97 98 /* called by LK thread_resched() and other functions in 'thread.c'. 99 * The purpose of this API is to set info in shared memory whenever the 100 * priority on a CPU changes. Such changes can occur when the current 101 * thread priority changes, or the scheduler switches to another 102 * thread, or when an IPI is sent to another CPU. 103 */ 104 void platform_cpu_priority_set(uint32_t cpu_nr, uint32_t priority); 105 106 __END_CDECLS; 107 108 #endif 109