machine_kexec.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. const extern unsigned char relocate_new_kernel[];
  26. const extern unsigned int relocate_new_kernel_size;
  27. extern void *gdb_vbr_vector;
  28. /*
  29. * Provide a dummy crash_notes definition while crash dump arrives to ppc.
  30. * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
  31. */
  32. void *crash_notes = NULL;
  33. void machine_shutdown(void)
  34. {
  35. }
  36. void machine_crash_shutdown(struct pt_regs *regs)
  37. {
  38. }
  39. /*
  40. * Do what every setup is needed on image and the
  41. * reboot code buffer to allow us to avoid allocations
  42. * later.
  43. */
  44. int machine_kexec_prepare(struct kimage *image)
  45. {
  46. return 0;
  47. }
  48. void machine_kexec_cleanup(struct kimage *image)
  49. {
  50. }
  51. static void kexec_info(struct kimage *image)
  52. {
  53. int i;
  54. printk("kexec information\n");
  55. for (i = 0; i < image->nr_segments; i++) {
  56. printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
  57. i,
  58. (unsigned int)image->segment[i].mem,
  59. (unsigned int)image->segment[i].mem + image->segment[i].memsz,
  60. (unsigned int)image->segment[i].memsz);
  61. }
  62. printk(" start : 0x%08x\n\n", (unsigned int)image->start);
  63. }
  64. /*
  65. * Do not allocate memory (or fail in any way) in machine_kexec().
  66. * We are past the point of no return, committed to rebooting now.
  67. */
  68. NORET_TYPE void machine_kexec(struct kimage *image)
  69. {
  70. unsigned long page_list;
  71. unsigned long reboot_code_buffer;
  72. unsigned long vbr_reg;
  73. relocate_new_kernel_t rnk;
  74. #if defined(CONFIG_SH_STANDARD_BIOS)
  75. vbr_reg = ((unsigned long )gdb_vbr_vector) - 0x100;
  76. #else
  77. vbr_reg = 0x80000000; // dummy
  78. #endif
  79. /* Interrupts aren't acceptable while we reboot */
  80. local_irq_disable();
  81. page_list = image->head;
  82. /* we need both effective and real address here */
  83. reboot_code_buffer =
  84. (unsigned long)page_address(image->control_code_page);
  85. /* copy our kernel relocation code to the control code page */
  86. memcpy((void *)reboot_code_buffer, relocate_new_kernel,
  87. relocate_new_kernel_size);
  88. kexec_info(image);
  89. flush_cache_all();
  90. /* now call it */
  91. rnk = (relocate_new_kernel_t) reboot_code_buffer;
  92. (*rnk)(page_list, reboot_code_buffer, image->start, vbr_reg);
  93. }