machine_kexec.c 2.7 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. static int __init early_parse_crashk(char *p)
  59. {
  60. unsigned long size;
  61. if (!p)
  62. return 1;
  63. size = memparse(p, &p);
  64. if (*p == '@')
  65. crashk_res.start = memparse(p + 1, &p);
  66. else
  67. crashk_res.start = KDUMP_KERNELBASE;
  68. crashk_res.end = crashk_res.start + size - 1;
  69. return 0;
  70. }
  71. early_param("crashkernel", early_parse_crashk);
  72. void __init reserve_crashkernel(void)
  73. {
  74. unsigned long size;
  75. if (crashk_res.start == 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. size = crashk_res.end - crashk_res.start + 1;
  80. if (crashk_res.start != KDUMP_KERNELBASE)
  81. printk("Crash kernel location must be 0x%x\n",
  82. KDUMP_KERNELBASE);
  83. crashk_res.start = KDUMP_KERNELBASE;
  84. size = PAGE_ALIGN(size);
  85. crashk_res.end = crashk_res.start + size - 1;
  86. /* Crash kernel trumps memory limit */
  87. if (memory_limit && memory_limit <= crashk_res.end) {
  88. memory_limit = crashk_res.end + 1;
  89. printk("Adjusted memory limit for crashkernel, now 0x%lx\n",
  90. memory_limit);
  91. }
  92. lmb_reserve(crashk_res.start, size);
  93. }
  94. int overlaps_crashkernel(unsigned long start, unsigned long size)
  95. {
  96. return (start + size) > crashk_res.start && start <= crashk_res.end;
  97. }