machine_kexec.c 6.2 KB

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