opal-power.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * PowerNV OPAL power control for graceful shutdown handling
  3. *
  4. * Copyright 2015 IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/reboot.h>
  13. #include <linux/notifier.h>
  14. #include <asm/opal.h>
  15. #include <asm/machdep.h>
  16. #define SOFT_OFF 0x00
  17. #define SOFT_REBOOT 0x01
  18. static int opal_power_control_event(struct notifier_block *nb,
  19. unsigned long msg_type, void *msg)
  20. {
  21. struct opal_msg *power_msg = msg;
  22. uint64_t type;
  23. type = be64_to_cpu(power_msg->params[0]);
  24. switch (type) {
  25. case SOFT_REBOOT:
  26. pr_info("OPAL: reboot requested\n");
  27. orderly_reboot();
  28. break;
  29. case SOFT_OFF:
  30. pr_info("OPAL: poweroff requested\n");
  31. orderly_poweroff(true);
  32. break;
  33. default:
  34. pr_err("OPAL: power control type unexpected %016llx\n", type);
  35. }
  36. return 0;
  37. }
  38. static struct notifier_block opal_power_control_nb = {
  39. .notifier_call = opal_power_control_event,
  40. .next = NULL,
  41. .priority = 0,
  42. };
  43. static int __init opal_power_control_init(void)
  44. {
  45. int ret;
  46. ret = opal_message_notifier_register(OPAL_MSG_SHUTDOWN,
  47. &opal_power_control_nb);
  48. if (ret) {
  49. pr_err("%s: Can't register OPAL event notifier (%d)\n",
  50. __func__, ret);
  51. return ret;
  52. }
  53. return 0;
  54. }
  55. machine_subsys_initcall(powernv, opal_power_control_init);