machine_kexec.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <linux/irq.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/pgalloc.h>
  12. #include <asm/mmu_context.h>
  13. #include <asm/cacheflush.h>
  14. #include <asm/mach-types.h>
  15. #include <asm/system_misc.h>
  16. extern const unsigned char relocate_new_kernel[];
  17. extern const unsigned int relocate_new_kernel_size;
  18. extern unsigned long kexec_start_address;
  19. extern unsigned long kexec_indirection_page;
  20. extern unsigned long kexec_mach_type;
  21. extern unsigned long kexec_boot_atags;
  22. static atomic_t waiting_for_crash_ipi;
  23. /*
  24. * Provide a dummy crash_notes definition while crash dump arrives to arm.
  25. * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
  26. */
  27. int machine_kexec_prepare(struct kimage *image)
  28. {
  29. return 0;
  30. }
  31. void machine_kexec_cleanup(struct kimage *image)
  32. {
  33. }
  34. void machine_crash_nonpanic_core(void *unused)
  35. {
  36. struct pt_regs regs;
  37. crash_setup_regs(&regs, NULL);
  38. printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n",
  39. smp_processor_id());
  40. crash_save_cpu(&regs, smp_processor_id());
  41. flush_cache_all();
  42. atomic_dec(&waiting_for_crash_ipi);
  43. while (1)
  44. cpu_relax();
  45. }
  46. static void machine_kexec_mask_interrupts(void)
  47. {
  48. unsigned int i;
  49. struct irq_desc *desc;
  50. for_each_irq_desc(i, desc) {
  51. struct irq_chip *chip;
  52. chip = irq_desc_get_chip(desc);
  53. if (!chip)
  54. continue;
  55. if (chip->irq_eoi && irqd_irq_inprogress(&desc->irq_data))
  56. chip->irq_eoi(&desc->irq_data);
  57. if (chip->irq_mask)
  58. chip->irq_mask(&desc->irq_data);
  59. if (chip->irq_disable && !irqd_irq_disabled(&desc->irq_data))
  60. chip->irq_disable(&desc->irq_data);
  61. }
  62. }
  63. void machine_crash_shutdown(struct pt_regs *regs)
  64. {
  65. unsigned long msecs;
  66. local_irq_disable();
  67. atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
  68. smp_call_function(machine_crash_nonpanic_core, NULL, false);
  69. msecs = 1000; /* Wait at most a second for the other cpus to stop */
  70. while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
  71. mdelay(1);
  72. msecs--;
  73. }
  74. if (atomic_read(&waiting_for_crash_ipi) > 0)
  75. printk(KERN_WARNING "Non-crashing CPUs did not react to IPI\n");
  76. crash_save_cpu(regs, smp_processor_id());
  77. machine_kexec_mask_interrupts();
  78. printk(KERN_INFO "Loading crashdump kernel...\n");
  79. }
  80. /*
  81. * Function pointer to optional machine-specific reinitialization
  82. */
  83. void (*kexec_reinit)(void);
  84. void machine_kexec(struct kimage *image)
  85. {
  86. unsigned long page_list;
  87. unsigned long reboot_code_buffer_phys;
  88. void *reboot_code_buffer;
  89. arch_kexec();
  90. page_list = image->head & PAGE_MASK;
  91. /* we need both effective and real address here */
  92. reboot_code_buffer_phys =
  93. page_to_pfn(image->control_code_page) << PAGE_SHIFT;
  94. reboot_code_buffer = page_address(image->control_code_page);
  95. /* Prepare parameters for reboot_code_buffer*/
  96. kexec_start_address = image->start;
  97. kexec_indirection_page = page_list;
  98. kexec_mach_type = machine_arch_type;
  99. kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
  100. /* copy our kernel relocation code to the control code page */
  101. memcpy(reboot_code_buffer,
  102. relocate_new_kernel, relocate_new_kernel_size);
  103. flush_icache_range((unsigned long) reboot_code_buffer,
  104. (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
  105. printk(KERN_INFO "Bye!\n");
  106. if (kexec_reinit)
  107. kexec_reinit();
  108. soft_restart(reboot_code_buffer_phys);
  109. }
  110. void arch_crash_save_vmcoreinfo(void)
  111. {
  112. #ifdef CONFIG_ARM_LPAE
  113. VMCOREINFO_CONFIG(ARM_LPAE);
  114. #endif
  115. }