machine_kexec.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. void machine_kexec(struct kimage *image)
  62. {
  63. unsigned long page_list;
  64. unsigned long reboot_code_buffer_phys;
  65. void *reboot_code_buffer;
  66. page_list = image->head & PAGE_MASK;
  67. /* we need both effective and real address here */
  68. reboot_code_buffer_phys =
  69. page_to_pfn(image->control_code_page) << PAGE_SHIFT;
  70. reboot_code_buffer = page_address(image->control_code_page);
  71. /* Prepare parameters for reboot_code_buffer*/
  72. kexec_start_address = image->start;
  73. kexec_indirection_page = page_list;
  74. kexec_mach_type = machine_arch_type;
  75. kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
  76. /* copy our kernel relocation code to the control code page */
  77. memcpy(reboot_code_buffer,
  78. relocate_new_kernel, relocate_new_kernel_size);
  79. flush_icache_range((unsigned long) reboot_code_buffer,
  80. (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
  81. printk(KERN_INFO "Bye!\n");
  82. local_irq_disable();
  83. local_fiq_disable();
  84. setup_mm_for_reboot(0); /* mode is not used, so just pass 0*/
  85. flush_cache_all();
  86. outer_flush_all();
  87. outer_disable();
  88. cpu_proc_fin();
  89. outer_inv_all();
  90. flush_cache_all();
  91. cpu_reset(reboot_code_buffer_phys);
  92. }