machine_kexec.c 3.0 KB

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