machine_kexec.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * machine_kexec.c - handle transition of Linux booting another kernel
  3. */
  4. #include <linux/mm.h>
  5. #include <linux/kexec.h>
  6. #include <linux/delay.h>
  7. #include <linux/reboot.h>
  8. #include <linux/io.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/pgalloc.h>
  11. #include <asm/mmu_context.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/mach-types.h>
  14. extern const unsigned char relocate_new_kernel[];
  15. extern const unsigned int relocate_new_kernel_size;
  16. extern void setup_mm_for_reboot(char mode);
  17. extern unsigned long kexec_start_address;
  18. extern unsigned long kexec_indirection_page;
  19. extern unsigned long kexec_mach_type;
  20. extern unsigned long kexec_boot_atags;
  21. static atomic_t waiting_for_crash_ipi;
  22. /*
  23. * Provide a dummy crash_notes definition while crash dump arrives to arm.
  24. * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
  25. */
  26. int machine_kexec_prepare(struct kimage *image)
  27. {
  28. return 0;
  29. }
  30. void machine_kexec_cleanup(struct kimage *image)
  31. {
  32. }
  33. void machine_crash_nonpanic_core(void *unused)
  34. {
  35. struct pt_regs regs;
  36. crash_setup_regs(&regs, NULL);
  37. printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n",
  38. smp_processor_id());
  39. crash_save_cpu(&regs, smp_processor_id());
  40. flush_cache_all();
  41. atomic_dec(&waiting_for_crash_ipi);
  42. while (1)
  43. cpu_relax();
  44. }
  45. void machine_crash_shutdown(struct pt_regs *regs)
  46. {
  47. unsigned long msecs;
  48. local_irq_disable();
  49. atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
  50. smp_call_function(machine_crash_nonpanic_core, NULL, false);
  51. msecs = 1000; /* Wait at most a second for the other cpus to stop */
  52. while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
  53. mdelay(1);
  54. msecs--;
  55. }
  56. if (atomic_read(&waiting_for_crash_ipi) > 0)
  57. printk(KERN_WARNING "Non-crashing CPUs did not react to IPI\n");
  58. crash_save_cpu(regs, smp_processor_id());
  59. printk(KERN_INFO "Loading crashdump kernel...\n");
  60. }
  61. /*
  62. * Function pointer to optional machine-specific reinitialization
  63. */
  64. void (*kexec_reinit)(void);
  65. void machine_kexec(struct kimage *image)
  66. {
  67. unsigned long page_list;
  68. unsigned long reboot_code_buffer_phys;
  69. void *reboot_code_buffer;
  70. page_list = image->head & PAGE_MASK;
  71. /* we need both effective and real address here */
  72. reboot_code_buffer_phys =
  73. page_to_pfn(image->control_code_page) << PAGE_SHIFT;
  74. reboot_code_buffer = page_address(image->control_code_page);
  75. /* Prepare parameters for reboot_code_buffer*/
  76. kexec_start_address = image->start;
  77. kexec_indirection_page = page_list;
  78. kexec_mach_type = machine_arch_type;
  79. kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
  80. /* copy our kernel relocation code to the control code page */
  81. memcpy(reboot_code_buffer,
  82. relocate_new_kernel, relocate_new_kernel_size);
  83. flush_icache_range((unsigned long) reboot_code_buffer,
  84. (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
  85. printk(KERN_INFO "Bye!\n");
  86. if (kexec_reinit)
  87. kexec_reinit();
  88. local_irq_disable();
  89. local_fiq_disable();
  90. setup_mm_for_reboot(0); /* mode is not used, so just pass 0*/
  91. flush_cache_all();
  92. outer_flush_all();
  93. outer_disable();
  94. cpu_proc_fin();
  95. outer_inv_all();
  96. flush_cache_all();
  97. cpu_reset(reboot_code_buffer_phys);
  98. }