sclp_quiesce.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <linux/reboot.h>
  16. #include <asm/atomic.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/sigp.h>
  19. #include "sclp.h"
  20. #ifdef CONFIG_SMP
  21. /* Signal completion of shutdown process. All CPUs except the first to enter
  22. * this function: go to stopped state. First CPU: wait until all other
  23. * CPUs are in stopped or check stop state. Afterwards, load special PSW
  24. * to indicate completion. */
  25. static void
  26. do_load_quiesce_psw(void * __unused)
  27. {
  28. static atomic_t cpuid = ATOMIC_INIT(-1);
  29. psw_t quiesce_psw;
  30. int cpu;
  31. if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1)
  32. signal_processor(smp_processor_id(), sigp_stop);
  33. /* Wait for all other cpus to enter stopped state */
  34. for_each_online_cpu(cpu) {
  35. if (cpu == smp_processor_id())
  36. continue;
  37. while(!smp_cpu_not_running(cpu))
  38. cpu_relax();
  39. }
  40. /* Quiesce the last cpu with the special psw */
  41. quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  42. quiesce_psw.addr = 0xfff;
  43. __load_psw(quiesce_psw);
  44. }
  45. /* Shutdown handler. Perform shutdown function on all CPUs. */
  46. static void
  47. do_machine_quiesce(void)
  48. {
  49. on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
  50. }
  51. #else
  52. /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
  53. static void
  54. do_machine_quiesce(void)
  55. {
  56. psw_t quiesce_psw;
  57. quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  58. quiesce_psw.addr = 0xfff;
  59. __load_psw(quiesce_psw);
  60. }
  61. #endif
  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);