| 1 |
|
| 2 | #ifndef _LINUX_REBOOT_H
|
| 3 | #define _LINUX_REBOOT_H
|
| 4 |
|
| 5 |
|
| 6 | #include <linux/notifier.h>
|
| 7 | #include <uapi/linux/reboot.h>
|
| 8 |
|
| 9 | struct device;
|
| 10 | struct sys_off_handler;
|
| 11 |
|
| 12 | #define SYS_DOWN 0x0001
|
| 13 | #define SYS_RESTART SYS_DOWN
|
| 14 | #define SYS_HALT 0x0002
|
| 15 | #define SYS_POWER_OFF 0x0003
|
| 16 |
|
| 17 | enum reboot_mode {
|
| 18 | REBOOT_UNDEFINED = -1,
|
| 19 | REBOOT_COLD = 0,
|
| 20 | REBOOT_WARM,
|
| 21 | REBOOT_HARD,
|
| 22 | REBOOT_SOFT,
|
| 23 | REBOOT_GPIO,
|
| 24 | };
|
| 25 | extern enum reboot_mode reboot_mode;
|
| 26 | extern enum reboot_mode panic_reboot_mode;
|
| 27 |
|
| 28 | enum reboot_type {
|
| 29 | BOOT_TRIPLE = 't',
|
| 30 | BOOT_KBD = 'k',
|
| 31 | BOOT_BIOS = 'b',
|
| 32 | BOOT_ACPI = 'a',
|
| 33 | BOOT_EFI = 'e',
|
| 34 | BOOT_CF9_FORCE = 'p',
|
| 35 | BOOT_CF9_SAFE = 'q',
|
| 36 | };
|
| 37 | extern enum reboot_type reboot_type;
|
| 38 |
|
| 39 | extern int reboot_default;
|
| 40 | extern int reboot_cpu;
|
| 41 | extern int reboot_force;
|
| 42 |
|
| 43 |
|
| 44 | extern int register_reboot_notifier(struct notifier_block *);
|
| 45 | extern int unregister_reboot_notifier(struct notifier_block *);
|
| 46 |
|
| 47 | extern int devm_register_reboot_notifier(struct device *, struct notifier_block *);
|
| 48 |
|
| 49 | extern int register_restart_handler(struct notifier_block *);
|
| 50 | extern int unregister_restart_handler(struct notifier_block *);
|
| 51 | extern void do_kernel_restart(char *cmd);
|
| 52 |
|
| 53 | |
| 54 | * Architecture-specific implementations of sys_reboot commands.
|
| 55 |
|
| 56 |
|
| 57 | extern void migrate_to_reboot_cpu(void);
|
| 58 | extern void machine_restart(char *cmd);
|
| 59 | extern void machine_halt(void);
|
| 60 | extern void machine_power_off(void);
|
| 61 |
|
| 62 | extern void machine_shutdown(void);
|
| 63 | struct pt_regs;
|
| 64 | extern void machine_crash_shutdown(struct pt_regs *);
|
| 65 |
|
| 66 | void do_kernel_power_off(void);
|
| 67 |
|
| 68 | |
| 69 | * sys-off handler API.
|
| 70 |
|
| 71 |
|
| 72 | |
| 73 | * Standard sys-off priority levels. Users are expected to set priorities
|
| 74 | * relative to the standard levels.
|
| 75 | *
|
| 76 | * SYS_OFF_PRIO_PLATFORM: Use this for platform-level handlers.
|
| 77 | *
|
| 78 | * SYS_OFF_PRIO_LOW: Use this for handler of last resort.
|
| 79 | *
|
| 80 | * SYS_OFF_PRIO_DEFAULT: Use this for normal handlers.
|
| 81 | *
|
| 82 | * SYS_OFF_PRIO_HIGH: Use this for higher priority handlers.
|
| 83 | *
|
| 84 | * SYS_OFF_PRIO_FIRMWARE: Use this if handler uses firmware call.
|
| 85 |
|
| 86 | #define SYS_OFF_PRIO_PLATFORM -256
|
| 87 | #define SYS_OFF_PRIO_LOW -128
|
| 88 | #define SYS_OFF_PRIO_DEFAULT 0
|
| 89 | #define SYS_OFF_PRIO_HIGH 192
|
| 90 | #define SYS_OFF_PRIO_FIRMWARE 224
|
| 91 |
|
| 92 | enum sys_off_mode {
|
| 93 | |
| 94 | * @SYS_OFF_MODE_POWER_OFF_PREPARE:
|
| 95 | *
|
| 96 | * Handlers prepare system to be powered off. Handlers are
|
| 97 | * allowed to sleep.
|
| 98 |
|
| 99 | SYS_OFF_MODE_POWER_OFF_PREPARE,
|
| 100 |
|
| 101 | |
| 102 | * @SYS_OFF_MODE_POWER_OFF:
|
| 103 | *
|
| 104 | * Handlers power-off system. Handlers are disallowed to sleep.
|
| 105 |
|
| 106 | SYS_OFF_MODE_POWER_OFF,
|
| 107 |
|
| 108 | |
| 109 | * @SYS_OFF_MODE_RESTART_PREPARE:
|
| 110 | *
|
| 111 | * Handlers prepare system to be restarted. Handlers are
|
| 112 | * allowed to sleep.
|
| 113 |
|
| 114 | SYS_OFF_MODE_RESTART_PREPARE,
|
| 115 |
|
| 116 | |
| 117 | * @SYS_OFF_MODE_RESTART:
|
| 118 | *
|
| 119 | * Handlers restart system. Handlers are disallowed to sleep.
|
| 120 |
|
| 121 | SYS_OFF_MODE_RESTART,
|
| 122 | };
|
| 123 |
|
| 124 | |
| 125 | * struct sys_off_data - sys-off callback argument
|
| 126 | *
|
| 127 | * @mode: Mode ID. Currently used only by the sys-off restart mode,
|
| 128 | * see enum reboot_mode for the available modes.
|
| 129 | * @cb_data: User's callback data.
|
| 130 | * @cmd: Command string. Currently used only by the sys-off restart mode,
|
| 131 | * NULL otherwise.
|
| 132 | * @dev: Device of the sys-off handler. Only if known (devm_register_*),
|
| 133 | * NULL otherwise.
|
| 134 |
|
| 135 | struct sys_off_data {
|
| 136 | int mode;
|
| 137 | void *cb_data;
|
| 138 | const char *cmd;
|
| 139 | struct device *dev;
|
| 140 | };
|
| 141 |
|
| 142 | struct sys_off_handler *
|
| 143 | register_sys_off_handler(enum sys_off_mode mode,
|
| 144 | int priority,
|
| 145 | int (*callback)(struct sys_off_data *data),
|
| 146 | void *cb_data);
|
| 147 | void unregister_sys_off_handler(struct sys_off_handler *handler);
|
| 148 |
|
| 149 | int devm_register_sys_off_handler(struct device *dev,
|
| 150 | enum sys_off_mode mode,
|
| 151 | int priority,
|
| 152 | int (*callback)(struct sys_off_data *data),
|
| 153 | void *cb_data);
|
| 154 |
|
| 155 | int devm_register_power_off_handler(struct device *dev,
|
| 156 | int (*callback)(struct sys_off_data *data),
|
| 157 | void *cb_data);
|
| 158 |
|
| 159 | int devm_register_restart_handler(struct device *dev,
|
| 160 | int (*callback)(struct sys_off_data *data),
|
| 161 | void *cb_data);
|
| 162 |
|
| 163 | int register_platform_power_off(void (*power_off)(void));
|
| 164 | void unregister_platform_power_off(void (*power_off)(void));
|
| 165 |
|
| 166 | |
| 167 | * Architecture independent implemenations of sys_reboot commands.
|
| 168 |
|
| 169 |
|
| 170 | extern void kernel_restart_prepare(char *cmd);
|
| 171 | extern void kernel_restart(char *cmd);
|
| 172 | extern void kernel_halt(void);
|
| 173 | extern void kernel_power_off(void);
|
| 174 | extern bool kernel_can_power_off(void);
|
| 175 |
|
| 176 | void ctrl_alt_del(void);
|
| 177 |
|
| 178 | extern void orderly_poweroff(bool force);
|
| 179 | extern void orderly_reboot(void);
|
| 180 |
|
| 181 | |
| 182 | * enum hw_protection_action - Hardware protection action
|
| 183 | *
|
| 184 | * @HWPROT_ACT_DEFAULT:
|
| 185 | * The default action should be taken. This is HWPROT_ACT_SHUTDOWN
|
| 186 | * by default, but can be overridden.
|
| 187 | * @HWPROT_ACT_SHUTDOWN:
|
| 188 | * The system should be shut down (powered off) for HW protection.
|
| 189 | * @HWPROT_ACT_REBOOT:
|
| 190 | * The system should be rebooted for HW protection.
|
| 191 |
|
| 192 | enum hw_protection_action { HWPROT_ACT_DEFAULT, HWPROT_ACT_SHUTDOWN, HWPROT_ACT_REBOOT };
|
| 193 |
|
| 194 | void __hw_protection_trigger(const char *reason, int ms_until_forced,
|
| 195 | enum hw_protection_action action);
|
| 196 |
|
| 197 | |
| 198 | * hw_protection_trigger - Trigger default emergency system hardware protection action
|
| 199 | *
|
| 200 | * @reason: Reason of emergency shutdown or reboot to be printed.
|
| 201 | * @ms_until_forced: Time to wait for orderly shutdown or reboot before
|
| 202 | * triggering it. Negative value disables the forced
|
| 203 | * shutdown or reboot.
|
| 204 | *
|
| 205 | * Initiate an emergency system shutdown or reboot in order to protect
|
| 206 | * hardware from further damage. The exact action taken is controllable at
|
| 207 | * runtime and defaults to shutdown.
|
| 208 |
|
| 209 | static inline void hw_protection_trigger(const char *reason, int ms_until_forced)
|
| 210 | {
|
| 211 | __hw_protection_trigger(reason, ms_until_forced, HWPROT_ACT_DEFAULT);
|
| 212 | }
|
| 213 |
|
| 214 | |
| 215 | * Emergency restart, callable from an interrupt handler.
|
| 216 |
|
| 217 |
|
| 218 | extern void emergency_restart(void);
|
| 219 | #include <asm/emergency-restart.h>
|
| 220 |
|
| 221 | #endif
|