machine_kexec.c 5.7 KB

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