machine_kexec.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * machine_kexec.c for kexec
  3. * Created by <nschichan@corp.free.fr> on Thu Oct 12 15:15:06 2006
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <linux/compiler.h>
  9. #include <linux/kexec.h>
  10. #include <linux/mm.h>
  11. #include <linux/delay.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/page.h>
  14. extern const unsigned char relocate_new_kernel[];
  15. extern const size_t relocate_new_kernel_size;
  16. extern unsigned long kexec_start_address;
  17. extern unsigned long kexec_indirection_page;
  18. int (*_machine_kexec_prepare)(struct kimage *) = NULL;
  19. void (*_machine_kexec_shutdown)(void) = NULL;
  20. void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL;
  21. #ifdef CONFIG_SMP
  22. void (*relocated_kexec_smp_wait) (void *);
  23. atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0);
  24. void (*_crash_smp_send_stop)(void) = NULL;
  25. #endif
  26. int
  27. machine_kexec_prepare(struct kimage *kimage)
  28. {
  29. if (_machine_kexec_prepare)
  30. return _machine_kexec_prepare(kimage);
  31. return 0;
  32. }
  33. void
  34. machine_kexec_cleanup(struct kimage *kimage)
  35. {
  36. }
  37. void
  38. machine_shutdown(void)
  39. {
  40. if (_machine_kexec_shutdown)
  41. _machine_kexec_shutdown();
  42. }
  43. void
  44. machine_crash_shutdown(struct pt_regs *regs)
  45. {
  46. if (_machine_crash_shutdown)
  47. _machine_crash_shutdown(regs);
  48. else
  49. default_machine_crash_shutdown(regs);
  50. }
  51. typedef void (*noretfun_t)(void) __noreturn;
  52. void
  53. machine_kexec(struct kimage *image)
  54. {
  55. unsigned long reboot_code_buffer;
  56. unsigned long entry;
  57. unsigned long *ptr;
  58. reboot_code_buffer =
  59. (unsigned long)page_address(image->control_code_page);
  60. kexec_start_address =
  61. (unsigned long) phys_to_virt(image->start);
  62. if (image->type == KEXEC_TYPE_DEFAULT) {
  63. kexec_indirection_page =
  64. (unsigned long) phys_to_virt(image->head & PAGE_MASK);
  65. } else {
  66. kexec_indirection_page = (unsigned long)&image->head;
  67. }
  68. memcpy((void*)reboot_code_buffer, relocate_new_kernel,
  69. relocate_new_kernel_size);
  70. /*
  71. * The generic kexec code builds a page list with physical
  72. * addresses. they are directly accessible through KSEG0 (or
  73. * CKSEG0 or XPHYS if on 64bit system), hence the
  74. * phys_to_virt() call.
  75. */
  76. for (ptr = &image->head; (entry = *ptr) && !(entry &IND_DONE);
  77. ptr = (entry & IND_INDIRECTION) ?
  78. phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
  79. if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
  80. *ptr & IND_DESTINATION)
  81. *ptr = (unsigned long) phys_to_virt(*ptr);
  82. }
  83. /*
  84. * we do not want to be bothered.
  85. */
  86. local_irq_disable();
  87. printk("Will call new kernel at %08lx\n", image->start);
  88. printk("Bye ...\n");
  89. __flush_cache_all();
  90. #ifdef CONFIG_SMP
  91. /* All secondary cpus now may jump to kexec_wait cycle */
  92. relocated_kexec_smp_wait = reboot_code_buffer +
  93. (void *)(kexec_smp_wait - relocate_new_kernel);
  94. smp_wmb();
  95. atomic_set(&kexec_ready_to_reboot, 1);
  96. #endif
  97. ((noretfun_t) reboot_code_buffer)();
  98. }