sclp_quiesce.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * signal quiesce handler
  3. *
  4. * Copyright IBM Corp. 1999, 2004
  5. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/smp.h>
  12. #include <linux/init.h>
  13. #include <linux/reboot.h>
  14. #include <linux/atomic.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/smp.h>
  17. #include "sclp.h"
  18. static void (*old_machine_restart)(char *);
  19. static void (*old_machine_halt)(void);
  20. static void (*old_machine_power_off)(void);
  21. /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
  22. static void do_machine_quiesce(void)
  23. {
  24. psw_t quiesce_psw;
  25. smp_send_stop();
  26. quiesce_psw.mask =
  27. PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA | PSW_MASK_WAIT;
  28. quiesce_psw.addr = 0xfff;
  29. __load_psw(quiesce_psw);
  30. }
  31. /* Handler for quiesce event. Start shutdown procedure. */
  32. static void sclp_quiesce_handler(struct evbuf_header *evbuf)
  33. {
  34. if (_machine_restart != (void *) do_machine_quiesce) {
  35. old_machine_restart = _machine_restart;
  36. old_machine_halt = _machine_halt;
  37. old_machine_power_off = _machine_power_off;
  38. _machine_restart = (void *) do_machine_quiesce;
  39. _machine_halt = do_machine_quiesce;
  40. _machine_power_off = do_machine_quiesce;
  41. }
  42. ctrl_alt_del();
  43. }
  44. /* Undo machine restart/halt/power_off modification on resume */
  45. static void sclp_quiesce_pm_event(struct sclp_register *reg,
  46. enum sclp_pm_event sclp_pm_event)
  47. {
  48. switch (sclp_pm_event) {
  49. case SCLP_PM_EVENT_RESTORE:
  50. if (old_machine_restart) {
  51. _machine_restart = old_machine_restart;
  52. _machine_halt = old_machine_halt;
  53. _machine_power_off = old_machine_power_off;
  54. old_machine_restart = NULL;
  55. old_machine_halt = NULL;
  56. old_machine_power_off = NULL;
  57. }
  58. break;
  59. case SCLP_PM_EVENT_FREEZE:
  60. case SCLP_PM_EVENT_THAW:
  61. break;
  62. }
  63. }
  64. static struct sclp_register sclp_quiesce_event = {
  65. .receive_mask = EVTYP_SIGQUIESCE_MASK,
  66. .receiver_fn = sclp_quiesce_handler,
  67. .pm_event_fn = sclp_quiesce_pm_event
  68. };
  69. /* Initialize quiesce driver. */
  70. static int __init sclp_quiesce_init(void)
  71. {
  72. return sclp_register(&sclp_quiesce_event);
  73. }
  74. module_init(sclp_quiesce_init);