Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_REBOOT_H
0003 #define _LINUX_REBOOT_H
0004 
0005 
0006 #include <linux/notifier.h>
0007 #include <uapi/linux/reboot.h>
0008 
0009 struct device;
0010 struct sys_off_handler;
0011 
0012 #define SYS_DOWN    0x0001  /* Notify of system down */
0013 #define SYS_RESTART SYS_DOWN
0014 #define SYS_HALT    0x0002  /* Notify of system halt */
0015 #define SYS_POWER_OFF   0x0003  /* Notify of system power off */
0016 
0017 enum reboot_mode {
0018     REBOOT_UNDEFINED = -1,
0019     REBOOT_COLD = 0,
0020     REBOOT_WARM,
0021     REBOOT_HARD,
0022     REBOOT_SOFT,
0023     REBOOT_GPIO,
0024 };
0025 extern enum reboot_mode reboot_mode;
0026 extern enum reboot_mode panic_reboot_mode;
0027 
0028 enum reboot_type {
0029     BOOT_TRIPLE = 't',
0030     BOOT_KBD    = 'k',
0031     BOOT_BIOS   = 'b',
0032     BOOT_ACPI   = 'a',
0033     BOOT_EFI    = 'e',
0034     BOOT_CF9_FORCE  = 'p',
0035     BOOT_CF9_SAFE   = 'q',
0036 };
0037 extern enum reboot_type reboot_type;
0038 
0039 extern int reboot_default;
0040 extern int reboot_cpu;
0041 extern int reboot_force;
0042 
0043 
0044 extern int register_reboot_notifier(struct notifier_block *);
0045 extern int unregister_reboot_notifier(struct notifier_block *);
0046 
0047 extern int devm_register_reboot_notifier(struct device *, struct notifier_block *);
0048 
0049 extern int register_restart_handler(struct notifier_block *);
0050 extern int unregister_restart_handler(struct notifier_block *);
0051 extern void do_kernel_restart(char *cmd);
0052 
0053 /*
0054  * Architecture-specific implementations of sys_reboot commands.
0055  */
0056 
0057 extern void migrate_to_reboot_cpu(void);
0058 extern void machine_restart(char *cmd);
0059 extern void machine_halt(void);
0060 extern void machine_power_off(void);
0061 
0062 extern void machine_shutdown(void);
0063 struct pt_regs;
0064 extern void machine_crash_shutdown(struct pt_regs *);
0065 
0066 void do_kernel_power_off(void);
0067 
0068 /*
0069  * sys-off handler API.
0070  */
0071 
0072 /*
0073  * Standard sys-off priority levels. Users are expected to set priorities
0074  * relative to the standard levels.
0075  *
0076  * SYS_OFF_PRIO_PLATFORM:   Use this for platform-level handlers.
0077  *
0078  * SYS_OFF_PRIO_LOW:        Use this for handler of last resort.
0079  *
0080  * SYS_OFF_PRIO_DEFAULT:    Use this for normal handlers.
0081  *
0082  * SYS_OFF_PRIO_HIGH:       Use this for higher priority handlers.
0083  *
0084  * SYS_OFF_PRIO_FIRMWARE:   Use this if handler uses firmware call.
0085  */
0086 #define SYS_OFF_PRIO_PLATFORM       -256
0087 #define SYS_OFF_PRIO_LOW        -128
0088 #define SYS_OFF_PRIO_DEFAULT        0
0089 #define SYS_OFF_PRIO_HIGH       192
0090 #define SYS_OFF_PRIO_FIRMWARE       224
0091 
0092 enum sys_off_mode {
0093     /**
0094      * @SYS_OFF_MODE_POWER_OFF_PREPARE:
0095      *
0096      * Handlers prepare system to be powered off. Handlers are
0097      * allowed to sleep.
0098      */
0099     SYS_OFF_MODE_POWER_OFF_PREPARE,
0100 
0101     /**
0102      * @SYS_OFF_MODE_POWER_OFF:
0103      *
0104      * Handlers power-off system. Handlers are disallowed to sleep.
0105      */
0106     SYS_OFF_MODE_POWER_OFF,
0107 
0108     /**
0109      * @SYS_OFF_MODE_RESTART:
0110      *
0111      * Handlers restart system. Handlers are disallowed to sleep.
0112      */
0113     SYS_OFF_MODE_RESTART,
0114 };
0115 
0116 /**
0117  * struct sys_off_data - sys-off callback argument
0118  *
0119  * @mode: Mode ID. Currently used only by the sys-off restart mode,
0120  *        see enum reboot_mode for the available modes.
0121  * @cb_data: User's callback data.
0122  * @cmd: Command string. Currently used only by the sys-off restart mode,
0123  *       NULL otherwise.
0124  */
0125 struct sys_off_data {
0126     int mode;
0127     void *cb_data;
0128     const char *cmd;
0129 };
0130 
0131 struct sys_off_handler *
0132 register_sys_off_handler(enum sys_off_mode mode,
0133              int priority,
0134              int (*callback)(struct sys_off_data *data),
0135              void *cb_data);
0136 void unregister_sys_off_handler(struct sys_off_handler *handler);
0137 
0138 int devm_register_sys_off_handler(struct device *dev,
0139                   enum sys_off_mode mode,
0140                   int priority,
0141                   int (*callback)(struct sys_off_data *data),
0142                   void *cb_data);
0143 
0144 int devm_register_power_off_handler(struct device *dev,
0145                     int (*callback)(struct sys_off_data *data),
0146                     void *cb_data);
0147 
0148 int devm_register_restart_handler(struct device *dev,
0149                   int (*callback)(struct sys_off_data *data),
0150                   void *cb_data);
0151 
0152 int register_platform_power_off(void (*power_off)(void));
0153 void unregister_platform_power_off(void (*power_off)(void));
0154 
0155 /*
0156  * Architecture independent implemenations of sys_reboot commands.
0157  */
0158 
0159 extern void kernel_restart_prepare(char *cmd);
0160 extern void kernel_restart(char *cmd);
0161 extern void kernel_halt(void);
0162 extern void kernel_power_off(void);
0163 extern bool kernel_can_power_off(void);
0164 
0165 void ctrl_alt_del(void);
0166 
0167 extern void orderly_poweroff(bool force);
0168 extern void orderly_reboot(void);
0169 void hw_protection_shutdown(const char *reason, int ms_until_forced);
0170 
0171 /*
0172  * Emergency restart, callable from an interrupt handler.
0173  */
0174 
0175 extern void emergency_restart(void);
0176 #include <asm/emergency-restart.h>
0177 
0178 #endif /* _LINUX_REBOOT_H */