blob: 6a4f055fb104b27723adfc0ceed36968dad8b2e9 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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
31typedef 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
37typedef 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
51lk_time_t current_time(void);
52lk_bigtime_t current_time_hires(void);
53
54/* Add the function for platform to have a chance to initialize hardware
55 * in EL3. This function would be called by start.S.
56 */
57void platform_el3_init(void);
58
59/* super early platform initialization, before almost everything */
60void platform_early_init(void);
61
62/* later init, after the kernel has come up */
63void platform_init(void);
64
65/* called by the arch init code to get the platform to set up any mmu mappings it may need */
66void platform_init_mmu_mappings(void);
67
68/* if the platform has knowledge of what caused the latest reboot, it can report
69 * it to applications with this function. */
70platform_halt_reason platform_get_reboot_reason(void);
71
72/* platform_halt is a method which is called from various places in the LK
73 * system, and may be implemented by platforms and called by applications. This
74 * call represents the end of the life of SW for a device; there is no returning
75 * from this function. Callers will provide a reason for the halt, and a
76 * suggested action for the platform to take, but it is the platform's
77 * responsibility to determine the final action taken. For example, in the case
78 * of a failed ASSERT or a panic, LK will call platform halt and suggest a Halt
79 * action, but a release build on a platform with no debug channel may choose to
80 * reboot instead as there is no one to tell about the ASSERT, and no one
81 * waiting to debug the device in its halted state. If not overloaded by the
82 * platform, the default behavior of platform halt will be to dprintf the
83 * reason, and then halt execution by turning off interrupts and spinning
84 * forever.
85 */
86void platform_halt(platform_halt_action suggested_action,
87 platform_halt_reason reason) __NO_RETURN;
88
89/* called during chain loading to make sure drivers and platform is put into a stopped state */
90void platform_quiesce(void);
91
92__END_CDECLS;
93
94#endif