sclp_quiesce.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "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. /* Handler for quiesce event. Start shutdown procedure. */
  62. static void
  63. sclp_quiesce_handler(struct evbuf_header *evbuf)
  64. {
  65. _machine_restart = (void *) do_machine_quiesce;
  66. _machine_halt = do_machine_quiesce;
  67. _machine_power_off = do_machine_quiesce;
  68. ctrl_alt_del();
  69. }
  70. static struct sclp_register sclp_quiesce_event = {
  71. .receive_mask = EvTyp_SigQuiesce_Mask,
  72. .receiver_fn = sclp_quiesce_handler
  73. };
  74. /* Initialize quiesce driver. */
  75. static int __init
  76. sclp_quiesce_init(void)
  77. {
  78. int rc;
  79. rc = sclp_register(&sclp_quiesce_event);
  80. if (rc)
  81. printk(KERN_WARNING "sclp: could not register quiesce handler "
  82. "(rc=%d)\n", rc);
  83. return rc;
  84. }
  85. module_init(sclp_quiesce_init);