poweroff.c 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * poweroff.c - sysrq handler to gracefully power down machine.
  3. *
  4. * This file is released under the GPL v2
  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>
  11. #include <linux/reboot.h>
  12. #include <linux/cpumask.h>
  13. /*
  14. * When the user hits Sys-Rq o to power down the machine this is the
  15. * callback we use.
  16. */
  17. static void do_poweroff(struct work_struct *dummy)
  18. {
  19. kernel_power_off();
  20. }
  21. static DECLARE_WORK(poweroff_work, do_poweroff);
  22. static void handle_poweroff(int key)
  23. {
  24. /* run sysrq poweroff on boot cpu */
  25. schedule_work_on(cpumask_first(cpu_online_mask), &poweroff_work);
  26. }
  27. static struct sysrq_key_op sysrq_poweroff_op = {
  28. .handler = handle_poweroff,
  29. .help_msg = "poweroff(o)",
  30. .action_msg = "Power Off",
  31. .enable_mask = SYSRQ_ENABLE_BOOT,
  32. };
  33. static int __init pm_sysrq_init(void)
  34. {
  35. register_sysrq_key('o', &sysrq_poweroff_op);
  36. return 0;
  37. }
  38. subsys_initcall(pm_sysrq_init);