machine_kexec.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/lmb.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. /*
  44. * Do not allocate memory (or fail in any way) in machine_kexec().
  45. * We are past the point of no return, committed to rebooting now.
  46. */
  47. void machine_kexec(struct kimage *image)
  48. {
  49. if (ppc_md.machine_kexec)
  50. ppc_md.machine_kexec(image);
  51. else
  52. default_machine_kexec(image);
  53. /* Fall back to normal restart if we're still alive. */
  54. machine_restart(NULL);
  55. for(;;);
  56. }
  57. void __init reserve_crashkernel(void)
  58. {
  59. unsigned long long crash_size, crash_base;
  60. int ret;
  61. /* this is necessary because of lmb_phys_mem_size() */
  62. lmb_analyze();
  63. /* use common parsing */
  64. ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
  65. &crash_size, &crash_base);
  66. if (ret == 0 && crash_size > 0) {
  67. crashk_res.start = crash_base;
  68. crashk_res.end = crash_base + crash_size - 1;
  69. }
  70. if (crashk_res.end == crashk_res.start) {
  71. crashk_res.start = crashk_res.end = 0;
  72. return;
  73. }
  74. /* We might have got these values via the command line or the
  75. * device tree, either way sanitise them now. */
  76. crash_size = crashk_res.end - crashk_res.start + 1;
  77. #ifndef CONFIG_RELOCATABLE
  78. if (crashk_res.start != KDUMP_KERNELBASE)
  79. printk("Crash kernel location must be 0x%x\n",
  80. KDUMP_KERNELBASE);
  81. crashk_res.start = KDUMP_KERNELBASE;
  82. #endif
  83. crash_size = PAGE_ALIGN(crash_size);
  84. crashk_res.end = crashk_res.start + crash_size - 1;
  85. /* Crash kernel trumps memory limit */
  86. if (memory_limit && memory_limit <= crashk_res.end) {
  87. memory_limit = crashk_res.end + 1;
  88. printk("Adjusted memory limit for crashkernel, now 0x%lx\n",
  89. memory_limit);
  90. }
  91. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  92. "for crashkernel (System RAM: %ldMB)\n",
  93. (unsigned long)(crash_size >> 20),
  94. (unsigned long)(crashk_res.start >> 20),
  95. (unsigned long)(lmb_phys_mem_size() >> 20));
  96. lmb_reserve(crashk_res.start, crash_size);
  97. }
  98. int overlaps_crashkernel(unsigned long start, unsigned long size)
  99. {
  100. return (start + size) > crashk_res.start && start <= crashk_res.end;
  101. }
  102. /* Values we need to export to the second kernel via the device tree. */
  103. static unsigned long kernel_end;
  104. static unsigned long crashk_size;
  105. static struct property kernel_end_prop = {
  106. .name = "linux,kernel-end",
  107. .length = sizeof(unsigned long),
  108. .value = &kernel_end,
  109. };
  110. static struct property crashk_base_prop = {
  111. .name = "linux,crashkernel-base",
  112. .length = sizeof(unsigned long),
  113. .value = &crashk_res.start,
  114. };
  115. static struct property crashk_size_prop = {
  116. .name = "linux,crashkernel-size",
  117. .length = sizeof(unsigned long),
  118. .value = &crashk_size,
  119. };
  120. static void __init export_crashk_values(struct device_node *node)
  121. {
  122. struct property *prop;
  123. /* There might be existing crash kernel properties, but we can't
  124. * be sure what's in them, so remove them. */
  125. prop = of_find_property(node, "linux,crashkernel-base", NULL);
  126. if (prop)
  127. prom_remove_property(node, prop);
  128. prop = of_find_property(node, "linux,crashkernel-size", NULL);
  129. if (prop)
  130. prom_remove_property(node, prop);
  131. if (crashk_res.start != 0) {
  132. prom_add_property(node, &crashk_base_prop);
  133. crashk_size = crashk_res.end - crashk_res.start + 1;
  134. prom_add_property(node, &crashk_size_prop);
  135. }
  136. }
  137. static int __init kexec_setup(void)
  138. {
  139. struct device_node *node;
  140. struct property *prop;
  141. node = of_find_node_by_path("/chosen");
  142. if (!node)
  143. return -ENOENT;
  144. /* remove any stale properties so ours can be found */
  145. prop = of_find_property(node, kernel_end_prop.name, NULL);
  146. if (prop)
  147. prom_remove_property(node, prop);
  148. /* information needed by userspace when using default_machine_kexec */
  149. kernel_end = __pa(_end);
  150. prom_add_property(node, &kernel_end_prop);
  151. export_crashk_values(node);
  152. of_node_put(node);
  153. return 0;
  154. }
  155. late_initcall(kexec_setup);