machine_kexec.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * arch/s390/kernel/machine_kexec.c
  3. *
  4. * (C) Copyright IBM Corp. 2005
  5. *
  6. * Author(s): Rolf Adelsberger <adelsberger@de.ibm.com>
  7. *
  8. */
  9. /*
  10. * s390_machine_kexec.c - handle the transition of Linux booting another kernel
  11. * on the S390 architecture.
  12. */
  13. #include <asm/cio.h>
  14. #include <asm/setup.h>
  15. #include <linux/device.h>
  16. #include <linux/mm.h>
  17. #include <linux/kexec.h>
  18. #include <linux/delay.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/pgalloc.h>
  21. #include <asm/system.h>
  22. static void kexec_halt_all_cpus(void *);
  23. typedef void (*relocate_kernel_t) (kimage_entry_t *, unsigned long);
  24. const extern unsigned char relocate_kernel[];
  25. const extern unsigned long long relocate_kernel_len;
  26. int
  27. machine_kexec_prepare(struct kimage *image)
  28. {
  29. unsigned long reboot_code_buffer;
  30. /* We don't support anything but the default image type for now. */
  31. if (image->type != KEXEC_TYPE_DEFAULT)
  32. return -EINVAL;
  33. /* Get the destination where the assembler code should be copied to.*/
  34. reboot_code_buffer = page_to_pfn(image->control_code_page)<<PAGE_SHIFT;
  35. /* Then copy it */
  36. memcpy((void *) reboot_code_buffer, relocate_kernel,
  37. relocate_kernel_len);
  38. return 0;
  39. }
  40. void
  41. machine_kexec_cleanup(struct kimage *image)
  42. {
  43. }
  44. void
  45. machine_shutdown(void)
  46. {
  47. printk(KERN_INFO "kexec: machine_shutdown called\n");
  48. }
  49. NORET_TYPE void
  50. machine_kexec(struct kimage *image)
  51. {
  52. clear_all_subchannels();
  53. /* Disable lowcore protection */
  54. ctl_clear_bit(0,28);
  55. on_each_cpu(kexec_halt_all_cpus, image, 0, 0);
  56. for (;;);
  57. }
  58. static void
  59. kexec_halt_all_cpus(void *kernel_image)
  60. {
  61. static atomic_t cpuid = ATOMIC_INIT(-1);
  62. int cpu;
  63. struct kimage *image;
  64. relocate_kernel_t data_mover;
  65. if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid))
  66. signal_processor(smp_processor_id(), sigp_stop);
  67. /* Wait for all other cpus to enter stopped state */
  68. for_each_online_cpu(cpu) {
  69. if (cpu == smp_processor_id())
  70. continue;
  71. while (!smp_cpu_not_running(cpu))
  72. cpu_relax();
  73. }
  74. image = (struct kimage *) kernel_image;
  75. data_mover = (relocate_kernel_t)
  76. (page_to_pfn(image->control_code_page) << PAGE_SHIFT);
  77. /* Call the moving routine */
  78. (*data_mover) (&image->head, image->start);
  79. }