// SPDX-License-Identifier: GPL-2.0-only/* * linux/kernel/reboot.c * * Copyright (C) 2013 Linus Torvalds */#define pr_fmt(fmt) "reboot: " fmt#include<linux/atomic.h>#include<linux/ctype.h>#include<linux/export.h>#include<linux/kexec.h>#include<linux/kmod.h>#include<linux/kmsg_dump.h>#include<linux/reboot.h>#include<linux/suspend.h>#include<linux/syscalls.h>#include<linux/syscore_ops.h>#include<linux/uaccess.h>/* * this indicates whether you can reboot with ctrl-alt-del: the default is yes */staticintC_A_D=1;structpid*cad_pid;EXPORT_SYMBOL(cad_pid);#if defined(CONFIG_ARM)#define DEFAULT_REBOOT_MODE = REBOOT_HARD#else#define DEFAULT_REBOOT_MODE#endifenumreboot_modereboot_modeDEFAULT_REBOOT_MODE;EXPORT_SYMBOL_GPL(reboot_mode);enumreboot_modepanic_reboot_mode=REBOOT_UNDEFINED;staticenumhw_protection_actionhw_protection_action=HWPROT_ACT_SHUTDOWN;/* * This variable is used privately to keep track of whether or not * reboot_type is still set to its default value (i.e., reboot= hasn't * been set on the command line). This is needed so that we can * suppress DMI scanning for reboot quirks. Without it, it's * impossible to override a faulty reboot quirk without recompiling. */intreboot_default=1;intreboot_cpu;enumreboot_typereboot_type=BOOT_ACPI;intreboot_force;structsys_off_handler{structnotifier_blocknb;int(*sys_off_cb)(structsys_off_data*data);void*cb_data;enumsys_off_modemode;boolblocking;void*list;structdevice*dev;};/* * This variable is used to indicate if a halt was initiated instead of a * reboot when the reboot call was invoked with LINUX_REBOOT_CMD_POWER_OFF, but * the system cannot be powered off. This allowes kernel_halt() to notify users * of that. */staticboolpoweroff_fallback_to_halt;/* * Temporary stub that prevents linkage failure while we're in process * of removing all uses of legacy pm_power_off() around the kernel. */void__weak(*pm_power_off)(void);/* * Notifier list for kernel code which wants to be called * at shutdown. This is used to stop any idling DMA operations * and the like. */staticBLOCKING_NOTIFIER_HEAD(reboot_notifier_list);/** * emergency_restart - reboot the system * * Without shutting down any hardware or taking any locks * reboot the system. This is called when we know we are in * trouble so this is our best effort to reboot. This is * safe to call in interrupt context. */voidemergency_restart(void){kmsg_dump(KMSG_DUMP_EMERG);system_state=SYSTEM_RESTART;machine_emergency_restart();}EXPORT_SYMBOL_GPL(emergency_restart);void