]>
Commit | Line | Data |
---|---|---|
8092f73c | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * poweroff.c - sysrq handler to gracefully power down machine. | |
1da177e4 LT |
4 | */ |
5 | ||
6 | #include <linux/kernel.h> | |
7 | #include <linux/sysrq.h> | |
8 | #include <linux/init.h> | |
9 | #include <linux/pm.h> | |
10 | #include <linux/workqueue.h> | |
ff319777 | 11 | #include <linux/reboot.h> |
2f15fc4b | 12 | #include <linux/cpumask.h> |
1da177e4 LT |
13 | |
14 | /* | |
15 | * When the user hits Sys-Rq o to power down the machine this is the | |
16 | * callback we use. | |
17 | */ | |
18 | ||
65f27f38 | 19 | static void do_poweroff(struct work_struct *dummy) |
1da177e4 | 20 | { |
ff319777 | 21 | kernel_power_off(); |
1da177e4 LT |
22 | } |
23 | ||
65f27f38 | 24 | static DECLARE_WORK(poweroff_work, do_poweroff); |
1da177e4 | 25 | |
1495cc9d | 26 | static void handle_poweroff(int key) |
1da177e4 | 27 | { |
2f15fc4b | 28 | /* run sysrq poweroff on boot cpu */ |
41c7bb95 | 29 | schedule_work_on(cpumask_first(cpu_online_mask), &poweroff_work); |
1da177e4 LT |
30 | } |
31 | ||
32 | static struct sysrq_key_op sysrq_poweroff_op = { | |
33 | .handler = handle_poweroff, | |
28ad585e | 34 | .help_msg = "poweroff(o)", |
1da177e4 | 35 | .action_msg = "Power Off", |
1dc492a0 | 36 | .enable_mask = SYSRQ_ENABLE_BOOT, |
1da177e4 LT |
37 | }; |
38 | ||
bbdc18a3 | 39 | static int __init pm_sysrq_init(void) |
1da177e4 LT |
40 | { |
41 | register_sysrq_key('o', &sysrq_poweroff_op); | |
42 | return 0; | |
43 | } | |
44 | ||
45 | subsys_initcall(pm_sysrq_init); |