Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * poweroff.c - sysrq handler to gracefully power down machine.
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/sysrq.h>
0008 #include <linux/init.h>
0009 #include <linux/pm.h>
0010 #include <linux/workqueue.h>
0011 #include <linux/reboot.h>
0012 #include <linux/cpumask.h>
0013 
0014 /*
0015  * When the user hits Sys-Rq o to power down the machine this is the
0016  * callback we use.
0017  */
0018 
0019 static void do_poweroff(struct work_struct *dummy)
0020 {
0021     kernel_power_off();
0022 }
0023 
0024 static DECLARE_WORK(poweroff_work, do_poweroff);
0025 
0026 static void handle_poweroff(int key)
0027 {
0028     /* run sysrq poweroff on boot cpu */
0029     schedule_work_on(cpumask_first(cpu_online_mask), &poweroff_work);
0030 }
0031 
0032 static const struct sysrq_key_op    sysrq_poweroff_op = {
0033     .handler        = handle_poweroff,
0034     .help_msg       = "poweroff(o)",
0035     .action_msg     = "Power Off",
0036     .enable_mask    = SYSRQ_ENABLE_BOOT,
0037 };
0038 
0039 static int __init pm_sysrq_init(void)
0040 {
0041     register_sysrq_key('o', &sysrq_poweroff_op);
0042     return 0;
0043 }
0044 
0045 subsys_initcall(pm_sysrq_init);