machine_kexec.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. *
  7. * This source code is licensed under the GNU General Public License,
  8. * Version 2. See the file COPYING for more details.
  9. */
  10. #include <linux/mm.h>
  11. #include <linux/kexec.h>
  12. #include <linux/delay.h>
  13. #include <linux/reboot.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/pgalloc.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/io.h>
  18. #include <asm/hw_irq.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/machdep.h>
  21. typedef NORET_TYPE void (*relocate_new_kernel_t)(
  22. unsigned long indirection_page,
  23. unsigned long reboot_code_buffer,
  24. unsigned long start_address) ATTRIB_NORET;
  25. const extern unsigned char relocate_new_kernel[];
  26. const extern unsigned int relocate_new_kernel_size;
  27. /*
  28. * Provide a dummy crash_notes definition while crash dump arrives to ppc.
  29. * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
  30. */
  31. void *crash_notes = NULL;
  32. void machine_shutdown(void)
  33. {
  34. if (ppc_md.machine_shutdown)
  35. ppc_md.machine_shutdown();
  36. }
  37. void machine_crash_shutdown(struct pt_regs *regs)
  38. {
  39. if (ppc_md.machine_crash_shutdown)
  40. ppc_md.machine_crash_shutdown();
  41. }
  42. /*
  43. * Do what every setup is needed on image and the
  44. * reboot code buffer to allow us to avoid allocations
  45. * later.
  46. */
  47. int machine_kexec_prepare(struct kimage *image)
  48. {
  49. if (ppc_md.machine_kexec_prepare)
  50. return ppc_md.machine_kexec_prepare(image);
  51. /*
  52. * Fail if platform doesn't provide its own machine_kexec_prepare
  53. * implementation.
  54. */
  55. return -ENOSYS;
  56. }
  57. void machine_kexec_cleanup(struct kimage *image)
  58. {
  59. if (ppc_md.machine_kexec_cleanup)
  60. ppc_md.machine_kexec_cleanup(image);
  61. }
  62. /*
  63. * Do not allocate memory (or fail in any way) in machine_kexec().
  64. * We are past the point of no return, committed to rebooting now.
  65. */
  66. NORET_TYPE void machine_kexec(struct kimage *image)
  67. {
  68. if (ppc_md.machine_kexec)
  69. ppc_md.machine_kexec(image);
  70. else {
  71. /*
  72. * Fall back to normal restart if platform doesn't provide
  73. * its own kexec function, and user insist to kexec...
  74. */
  75. machine_restart(NULL);
  76. }
  77. for(;;);
  78. }
  79. /*
  80. * This is a generic machine_kexec function suitable at least for
  81. * non-OpenFirmware embedded platforms.
  82. * It merely copies the image relocation code to the control page and
  83. * jumps to it.
  84. * A platform specific function may just call this one.
  85. */
  86. void machine_kexec_simple(struct kimage *image)
  87. {
  88. unsigned long page_list;
  89. unsigned long reboot_code_buffer, reboot_code_buffer_phys;
  90. relocate_new_kernel_t rnk;
  91. /* Interrupts aren't acceptable while we reboot */
  92. local_irq_disable();
  93. page_list = image->head;
  94. /* we need both effective and real address here */
  95. reboot_code_buffer =
  96. (unsigned long)page_address(image->control_code_page);
  97. reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
  98. /* copy our kernel relocation code to the control code page */
  99. memcpy((void *)reboot_code_buffer, relocate_new_kernel,
  100. relocate_new_kernel_size);
  101. flush_icache_range(reboot_code_buffer,
  102. reboot_code_buffer + KEXEC_CONTROL_CODE_SIZE);
  103. printk(KERN_INFO "Bye!\n");
  104. /* now call it */
  105. rnk = (relocate_new_kernel_t) reboot_code_buffer;
  106. (*rnk)(page_list, reboot_code_buffer_phys, image->start);
  107. }