machine_kexec.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Code to handle transition of Linux booting another kernel.
  3. *
  4. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  5. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  6. * Copyright (C) 2005 IBM Corporation.
  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/kexec.h>
  12. #include <linux/reboot.h>
  13. #include <linux/threads.h>
  14. #include <linux/memblock.h>
  15. #include <linux/of.h>
  16. #include <linux/irq.h>
  17. #include <linux/ftrace.h>
  18. #include <asm/machdep.h>
  19. #include <asm/prom.h>
  20. #include <asm/sections.h>
  21. void machine_kexec_mask_interrupts(void) {
  22. unsigned int i;
  23. for_each_irq(i) {
  24. struct irq_desc *desc = irq_to_desc(i);
  25. if (!desc || !desc->chip)
  26. continue;
  27. if (desc->chip->eoi &&
  28. desc->status & IRQ_INPROGRESS)
  29. desc->chip->eoi(i);
  30. if (desc->chip->mask)
  31. desc->chip->mask(i);
  32. if (desc->chip->disable &&
  33. !(desc->status & IRQ_DISABLED))
  34. desc->chip->disable(i);
  35. }
  36. }
  37. void machine_crash_shutdown(struct pt_regs *regs)
  38. {
  39. default_machine_crash_shutdown(regs);
  40. }
  41. /*
  42. * Do what every setup is needed on image and the
  43. * reboot code buffer to allow us to avoid allocations
  44. * later.
  45. */
  46. int machine_kexec_prepare(struct kimage *image)
  47. {
  48. if (ppc_md.machine_kexec_prepare)
  49. return ppc_md.machine_kexec_prepare(image);
  50. else
  51. return default_machine_kexec_prepare(image);
  52. }
  53. void machine_kexec_cleanup(struct kimage *image)
  54. {
  55. }
  56. void arch_crash_save_vmcoreinfo(void)
  57. {
  58. #ifdef CONFIG_NEED_MULTIPLE_NODES
  59. VMCOREINFO_SYMBOL(node_data);
  60. VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
  61. #endif
  62. #ifndef CONFIG_NEED_MULTIPLE_NODES
  63. VMCOREINFO_SYMBOL(contig_page_data);
  64. #endif
  65. }
  66. /*
  67. * Do not allocate memory (or fail in any way) in machine_kexec().
  68. * We are past the point of no return, committed to rebooting now.
  69. */
  70. void machine_kexec(struct kimage *image)
  71. {
  72. int save_ftrace_enabled;
  73. save_ftrace_enabled = __ftrace_enabled_save();
  74. if (ppc_md.machine_kexec)
  75. ppc_md.machine_kexec(image);
  76. else
  77. default_machine_kexec(image);
  78. __ftrace_enabled_restore(save_ftrace_enabled);
  79. /* Fall back to normal restart if we're still alive. */
  80. machine_restart(NULL);
  81. for(;;);
  82. }
  83. void __init reserve_crashkernel(void)
  84. {
  85. unsigned long long crash_size, crash_base;
  86. int ret;
  87. /* this is necessary because of memblock_phys_mem_size() */
  88. memblock_analyze();
  89. /* use common parsing */
  90. ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
  91. &crash_size, &crash_base);
  92. if (ret == 0 && crash_size > 0) {
  93. crashk_res.start = crash_base;
  94. crashk_res.end = crash_base + crash_size - 1;
  95. }
  96. if (crashk_res.end == crashk_res.start) {
  97. crashk_res.start = crashk_res.end = 0;
  98. return;
  99. }
  100. /* We might have got these values via the command line or the
  101. * device tree, either way sanitise them now. */
  102. crash_size = crashk_res.end - crashk_res.start + 1;
  103. #ifndef CONFIG_RELOCATABLE
  104. if (crashk_res.start != KDUMP_KERNELBASE)
  105. printk("Crash kernel location must be 0x%x\n",
  106. KDUMP_KERNELBASE);
  107. crashk_res.start = KDUMP_KERNELBASE;
  108. #else
  109. if (!crashk_res.start) {
  110. /*
  111. * unspecified address, choose a region of specified size
  112. * can overlap with initrd (ignoring corruption when retained)
  113. * ppc64 requires kernel and some stacks to be in first segemnt
  114. */
  115. crashk_res.start = KDUMP_KERNELBASE;
  116. }
  117. crash_base = PAGE_ALIGN(crashk_res.start);
  118. if (crash_base != crashk_res.start) {
  119. printk("Crash kernel base must be aligned to 0x%lx\n",
  120. PAGE_SIZE);
  121. crashk_res.start = crash_base;
  122. }
  123. #endif
  124. crash_size = PAGE_ALIGN(crash_size);
  125. crashk_res.end = crashk_res.start + crash_size - 1;
  126. /* The crash region must not overlap the current kernel */
  127. if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
  128. printk(KERN_WARNING
  129. "Crash kernel can not overlap current kernel\n");
  130. crashk_res.start = crashk_res.end = 0;
  131. return;
  132. }
  133. /* Crash kernel trumps memory limit */
  134. if (memory_limit && memory_limit <= crashk_res.end) {
  135. memory_limit = crashk_res.end + 1;
  136. printk("Adjusted memory limit for crashkernel, now 0x%llx\n",
  137. (unsigned long long)memory_limit);
  138. }
  139. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  140. "for crashkernel (System RAM: %ldMB)\n",
  141. (unsigned long)(crash_size >> 20),
  142. (unsigned long)(crashk_res.start >> 20),
  143. (unsigned long)(memblock_phys_mem_size() >> 20));
  144. memblock_reserve(crashk_res.start, crash_size);
  145. }
  146. int overlaps_crashkernel(unsigned long start, unsigned long size)
  147. {
  148. return (start + size) > crashk_res.start && start <= crashk_res.end;
  149. }
  150. /* Values we need to export to the second kernel via the device tree. */
  151. static phys_addr_t kernel_end;
  152. static phys_addr_t crashk_size;
  153. static struct property kernel_end_prop = {
  154. .name = "linux,kernel-end",
  155. .length = sizeof(phys_addr_t),
  156. .value = &kernel_end,
  157. };
  158. static struct property crashk_base_prop = {
  159. .name = "linux,crashkernel-base",
  160. .length = sizeof(phys_addr_t),
  161. .value = &crashk_res.start,
  162. };
  163. static struct property crashk_size_prop = {
  164. .name = "linux,crashkernel-size",
  165. .length = sizeof(phys_addr_t),
  166. .value = &crashk_size,
  167. };
  168. static void __init export_crashk_values(struct device_node *node)
  169. {
  170. struct property *prop;
  171. /* There might be existing crash kernel properties, but we can't
  172. * be sure what's in them, so remove them. */
  173. prop = of_find_property(node, "linux,crashkernel-base", NULL);
  174. if (prop)
  175. prom_remove_property(node, prop);
  176. prop = of_find_property(node, "linux,crashkernel-size", NULL);
  177. if (prop)
  178. prom_remove_property(node, prop);
  179. if (crashk_res.start != 0) {
  180. prom_add_property(node, &crashk_base_prop);
  181. crashk_size = crashk_res.end - crashk_res.start + 1;
  182. prom_add_property(node, &crashk_size_prop);
  183. }
  184. }
  185. static int __init kexec_setup(void)
  186. {
  187. struct device_node *node;
  188. struct property *prop;
  189. node = of_find_node_by_path("/chosen");
  190. if (!node)
  191. return -ENOENT;
  192. /* remove any stale properties so ours can be found */
  193. prop = of_find_property(node, kernel_end_prop.name, NULL);
  194. if (prop)
  195. prom_remove_property(node, prop);
  196. /* information needed by userspace when using default_machine_kexec */
  197. kernel_end = __pa(_end);
  198. prom_add_property(node, &kernel_end_prop);
  199. export_crashk_values(node);
  200. of_node_put(node);
  201. return 0;
  202. }
  203. late_initcall(kexec_setup);