sclp_quiesce.c 2.2 KB

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