machine_kexec.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * machine_kexec.c - handle transition of Linux booting another kernel
  3. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  4. *
  5. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  6. * LANDISK/sh4 supported by kogiidena
  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/mm.h>
  12. #include <linux/kexec.h>
  13. #include <linux/delay.h>
  14. #include <linux/reboot.h>
  15. #include <asm/pgtable.h>
  16. #include <asm/pgalloc.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/io.h>
  19. #include <asm/cacheflush.h>
  20. typedef NORET_TYPE void (*relocate_new_kernel_t)(
  21. unsigned long indirection_page,
  22. unsigned long reboot_code_buffer,
  23. unsigned long start_address,
  24. unsigned long vbr_reg) ATTRIB_NORET;
  25. extern const unsigned char relocate_new_kernel[];
  26. extern const unsigned int relocate_new_kernel_size;
  27. extern void *gdb_vbr_vector;
  28. void machine_shutdown(void)
  29. {
  30. }
  31. void machine_crash_shutdown(struct pt_regs *regs)
  32. {
  33. }
  34. /*
  35. * Do what every setup is needed on image and the
  36. * reboot code buffer to allow us to avoid allocations
  37. * later.
  38. */
  39. int machine_kexec_prepare(struct kimage *image)
  40. {
  41. return 0;
  42. }
  43. void machine_kexec_cleanup(struct kimage *image)
  44. {
  45. }
  46. static void kexec_info(struct kimage *image)
  47. {
  48. int i;
  49. printk("kexec information\n");
  50. for (i = 0; i < image->nr_segments; i++) {
  51. printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
  52. i,
  53. (unsigned int)image->segment[i].mem,
  54. (unsigned int)image->segment[i].mem +
  55. image->segment[i].memsz,
  56. (unsigned int)image->segment[i].memsz);
  57. }
  58. printk(" start : 0x%08x\n\n", (unsigned int)image->start);
  59. }
  60. /*
  61. * Do not allocate memory (or fail in any way) in machine_kexec().
  62. * We are past the point of no return, committed to rebooting now.
  63. */
  64. NORET_TYPE void machine_kexec(struct kimage *image)
  65. {
  66. unsigned long page_list;
  67. unsigned long reboot_code_buffer;
  68. unsigned long vbr_reg;
  69. relocate_new_kernel_t rnk;
  70. #if defined(CONFIG_SH_STANDARD_BIOS)
  71. vbr_reg = ((unsigned long )gdb_vbr_vector) - 0x100;
  72. #else
  73. vbr_reg = 0x80000000; // dummy
  74. #endif
  75. /* Interrupts aren't acceptable while we reboot */
  76. local_irq_disable();
  77. page_list = image->head;
  78. /* we need both effective and real address here */
  79. reboot_code_buffer =
  80. (unsigned long)page_address(image->control_code_page);
  81. /* copy our kernel relocation code to the control code page */
  82. memcpy((void *)reboot_code_buffer, relocate_new_kernel,
  83. relocate_new_kernel_size);
  84. kexec_info(image);
  85. flush_cache_all();
  86. /* now call it */
  87. rnk = (relocate_new_kernel_t) reboot_code_buffer;
  88. (*rnk)(page_list, reboot_code_buffer, image->start, vbr_reg);
  89. }
  90. /* crashkernel=size@addr specifies the location to reserve for
  91. * a crash kernel. By reserving this memory we guarantee
  92. * that linux never sets it up as a DMA target.
  93. * Useful for holding code to do something appropriate
  94. * after a kernel panic.
  95. */
  96. static int __init parse_crashkernel(char *arg)
  97. {
  98. unsigned long size, base;
  99. size = memparse(arg, &arg);
  100. if (*arg == '@') {
  101. base = memparse(arg+1, &arg);
  102. /* FIXME: Do I want a sanity check
  103. * to validate the memory range?
  104. */
  105. crashk_res.start = base;
  106. crashk_res.end = base + size - 1;
  107. }
  108. return 0;
  109. }
  110. early_param("crashkernel", parse_crashkernel);