sclp_quiesce.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/config.h>
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/cpumask.h>
  13. #include <linux/smp.h>
  14. #include <linux/init.h>
  15. #include <asm/atomic.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/sigp.h>
  18. #include "sclp.h"
  19. #ifdef CONFIG_SMP
  20. /* Signal completion of shutdown process. All CPUs except the first to enter
  21. * this function: go to stopped state. First CPU: wait until all other
  22. * CPUs are in stopped or check stop state. Afterwards, load special PSW
  23. * to indicate completion. */
  24. static void
  25. do_load_quiesce_psw(void * __unused)
  26. {
  27. static atomic_t cpuid = ATOMIC_INIT(-1);
  28. psw_t quiesce_psw;
  29. int cpu;
  30. if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1)
  31. signal_processor(smp_processor_id(), sigp_stop);
  32. /* Wait for all other cpus to enter stopped state */
  33. for_each_online_cpu(cpu) {
  34. if (cpu == smp_processor_id())
  35. continue;
  36. while(!smp_cpu_not_running(cpu))
  37. cpu_relax();
  38. }
  39. /* Quiesce the last cpu with the special psw */
  40. quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  41. quiesce_psw.addr = 0xfff;
  42. __load_psw(quiesce_psw);
  43. }
  44. /* Shutdown handler. Perform shutdown function on all CPUs. */
  45. static void
  46. do_machine_quiesce(void)
  47. {
  48. on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
  49. }
  50. #else
  51. /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
  52. static void
  53. do_machine_quiesce(void)
  54. {
  55. psw_t quiesce_psw;
  56. quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  57. quiesce_psw.addr = 0xfff;
  58. __load_psw(quiesce_psw);
  59. }
  60. #endif
  61. extern void ctrl_alt_del(void);
  62. /* Handler for quiesce event. Start shutdown procedure. */
  63. static void
  64. sclp_quiesce_handler(struct evbuf_header *evbuf)
  65. {
  66. _machine_restart = (void *) do_machine_quiesce;
  67. _machine_halt = do_machine_quiesce;
  68. _machine_power_off = do_machine_quiesce;
  69. ctrl_alt_del();
  70. }
  71. static struct sclp_register sclp_quiesce_event = {
  72. .receive_mask = EvTyp_SigQuiesce_Mask,
  73. .receiver_fn = sclp_quiesce_handler
  74. };
  75. /* Initialize quiesce driver. */
  76. static int __init
  77. sclp_quiesce_init(void)
  78. {
  79. int rc;
  80. rc = sclp_register(&sclp_quiesce_event);
  81. if (rc)
  82. printk(KERN_WARNING "sclp: could not register quiesce handler "
  83. "(rc=%d)\n", rc);
  84. return rc;
  85. }
  86. module_init(sclp_quiesce_init);