machine_kexec.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * machine_kexec.c - handle transition of Linux booting another kernel
  3. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  4. *
  5. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  6. * LANDISK/sh4 supported by kogiidena
  7. *
  8. * This source code is licensed under the GNU General Public License,
  9. * Version 2. See the file COPYING for more details.
  10. */
  11. #include <linux/mm.h>
  12. #include <linux/kexec.h>
  13. #include <linux/delay.h>
  14. #include <linux/reboot.h>
  15. #include <linux/numa.h>
  16. #include <linux/ftrace.h>
  17. #include <linux/suspend.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/mmu_context.h>
  21. #include <asm/io.h>
  22. #include <asm/cacheflush.h>
  23. typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
  24. unsigned long reboot_code_buffer,
  25. unsigned long start_address);
  26. extern const unsigned char relocate_new_kernel[];
  27. extern const unsigned int relocate_new_kernel_size;
  28. extern void *gdb_vbr_vector;
  29. extern void *vbr_base;
  30. void machine_shutdown(void)
  31. {
  32. }
  33. void machine_crash_shutdown(struct pt_regs *regs)
  34. {
  35. }
  36. /*
  37. * Do what every setup is needed on image and the
  38. * reboot code buffer to allow us to avoid allocations
  39. * later.
  40. */
  41. int machine_kexec_prepare(struct kimage *image)
  42. {
  43. /* older versions of kexec-tools are passing
  44. * the zImage entry point as a virtual address.
  45. */
  46. if (image->start != PHYSADDR(image->start))
  47. return -EINVAL; /* upgrade your kexec-tools */
  48. return 0;
  49. }
  50. void machine_kexec_cleanup(struct kimage *image)
  51. {
  52. }
  53. static void kexec_info(struct kimage *image)
  54. {
  55. int i;
  56. printk("kexec information\n");
  57. for (i = 0; i < image->nr_segments; i++) {
  58. printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
  59. i,
  60. (unsigned int)image->segment[i].mem,
  61. (unsigned int)image->segment[i].mem +
  62. image->segment[i].memsz,
  63. (unsigned int)image->segment[i].memsz);
  64. }
  65. printk(" start : 0x%08x\n\n", (unsigned int)image->start);
  66. }
  67. /*
  68. * Do not allocate memory (or fail in any way) in machine_kexec().
  69. * We are past the point of no return, committed to rebooting now.
  70. */
  71. void machine_kexec(struct kimage *image)
  72. {
  73. unsigned long page_list;
  74. unsigned long reboot_code_buffer;
  75. relocate_new_kernel_t rnk;
  76. unsigned long entry;
  77. unsigned long *ptr;
  78. int save_ftrace_enabled;
  79. /*
  80. * Nicked from the mips version of machine_kexec():
  81. * The generic kexec code builds a page list with physical
  82. * addresses. Use phys_to_virt() to convert them to virtual.
  83. */
  84. for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
  85. ptr = (entry & IND_INDIRECTION) ?
  86. phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
  87. if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
  88. *ptr & IND_DESTINATION)
  89. *ptr = (unsigned long) phys_to_virt(*ptr);
  90. }
  91. #ifdef CONFIG_KEXEC_JUMP
  92. if (image->preserve_context)
  93. save_processor_state();
  94. #endif
  95. save_ftrace_enabled = __ftrace_enabled_save();
  96. /* Interrupts aren't acceptable while we reboot */
  97. local_irq_disable();
  98. page_list = image->head;
  99. /* we need both effective and real address here */
  100. reboot_code_buffer =
  101. (unsigned long)page_address(image->control_code_page);
  102. /* copy our kernel relocation code to the control code page */
  103. memcpy((void *)reboot_code_buffer, relocate_new_kernel,
  104. relocate_new_kernel_size);
  105. kexec_info(image);
  106. flush_cache_all();
  107. #if defined(CONFIG_SH_STANDARD_BIOS)
  108. asm volatile("ldc %0, vbr" :
  109. : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
  110. : "memory");
  111. #endif
  112. /* now call it */
  113. rnk = (relocate_new_kernel_t) reboot_code_buffer;
  114. (*rnk)(page_list, reboot_code_buffer,
  115. (unsigned long)phys_to_virt(image->start));
  116. #ifdef CONFIG_KEXEC_JUMP
  117. asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
  118. if (image->preserve_context)
  119. restore_processor_state();
  120. /* Convert page list back to physical addresses, what a mess. */
  121. for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
  122. ptr = (*ptr & IND_INDIRECTION) ?
  123. phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
  124. if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
  125. *ptr & IND_DESTINATION)
  126. *ptr = virt_to_phys(*ptr);
  127. }
  128. #endif
  129. __ftrace_enabled_restore(save_ftrace_enabled);
  130. }
  131. void arch_crash_save_vmcoreinfo(void)
  132. {
  133. #ifdef CONFIG_NUMA
  134. VMCOREINFO_SYMBOL(node_data);
  135. VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
  136. #endif
  137. }