machine_kexec.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <asm/machdep.h>
  16. #include <asm/prom.h>
  17. void machine_crash_shutdown(struct pt_regs *regs)
  18. {
  19. if (ppc_md.machine_crash_shutdown)
  20. ppc_md.machine_crash_shutdown(regs);
  21. }
  22. /*
  23. * Do what every setup is needed on image and the
  24. * reboot code buffer to allow us to avoid allocations
  25. * later.
  26. */
  27. int machine_kexec_prepare(struct kimage *image)
  28. {
  29. if (ppc_md.machine_kexec_prepare)
  30. return ppc_md.machine_kexec_prepare(image);
  31. /*
  32. * Fail if platform doesn't provide its own machine_kexec_prepare
  33. * implementation.
  34. */
  35. return -ENOSYS;
  36. }
  37. void machine_kexec_cleanup(struct kimage *image)
  38. {
  39. if (ppc_md.machine_kexec_cleanup)
  40. ppc_md.machine_kexec_cleanup(image);
  41. }
  42. /*
  43. * Do not allocate memory (or fail in any way) in machine_kexec().
  44. * We are past the point of no return, committed to rebooting now.
  45. */
  46. void machine_kexec(struct kimage *image)
  47. {
  48. if (ppc_md.machine_kexec)
  49. ppc_md.machine_kexec(image);
  50. else {
  51. /*
  52. * Fall back to normal restart if platform doesn't provide
  53. * its own kexec function, and user insist to kexec...
  54. */
  55. machine_restart(NULL);
  56. }
  57. for(;;);
  58. }
  59. void __init reserve_crashkernel(void)
  60. {
  61. unsigned long long crash_size, crash_base;
  62. int ret;
  63. /* this is necessary because of lmb_phys_mem_size() */
  64. lmb_analyze();
  65. /* use common parsing */
  66. ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
  67. &crash_size, &crash_base);
  68. if (ret == 0 && crash_size > 0) {
  69. crashk_res.start = crash_base;
  70. crashk_res.end = crash_base + crash_size - 1;
  71. }
  72. if (crashk_res.end == crashk_res.start) {
  73. crashk_res.start = crashk_res.end = 0;
  74. return;
  75. }
  76. /* We might have got these values via the command line or the
  77. * device tree, either way sanitise them now. */
  78. crash_size = crashk_res.end - crashk_res.start + 1;
  79. if (crashk_res.start != KDUMP_KERNELBASE)
  80. printk("Crash kernel location must be 0x%x\n",
  81. KDUMP_KERNELBASE);
  82. crashk_res.start = KDUMP_KERNELBASE;
  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. }