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. unsigned long page_list;
  29. void *reboot_code_buffer;
  30. page_list = image->head & PAGE_MASK;
  31. reboot_code_buffer = page_address(image->control_code_page);
  32. /* Prepare parameters for reboot_code_buffer*/
  33. kexec_start_address = image->start;
  34. kexec_indirection_page = page_list;
  35. kexec_mach_type = machine_arch_type;
  36. kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
  37. /* copy our kernel relocation code to the control code page */
  38. memcpy(reboot_code_buffer,
  39. relocate_new_kernel, relocate_new_kernel_size);
  40. flush_icache_range((unsigned long) reboot_code_buffer,
  41. (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
  42. return 0;
  43. }
  44. void machine_kexec_cleanup(struct kimage *image)
  45. {
  46. }
  47. void machine_crash_nonpanic_core(void *unused)
  48. {
  49. struct pt_regs regs;
  50. crash_setup_regs(&regs, NULL);
  51. printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n",
  52. smp_processor_id());
  53. crash_save_cpu(&regs, smp_processor_id());
  54. flush_cache_all();
  55. atomic_dec(&waiting_for_crash_ipi);
  56. while (1)
  57. cpu_relax();
  58. }
  59. void machine_crash_shutdown(struct pt_regs *regs)
  60. {
  61. unsigned long msecs;
  62. local_irq_disable();
  63. atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
  64. smp_call_function(machine_crash_nonpanic_core, NULL, false);
  65. msecs = 1000; /* Wait at most a second for the other cpus to stop */
  66. while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
  67. mdelay(1);
  68. msecs--;
  69. }
  70. if (atomic_read(&waiting_for_crash_ipi) > 0)
  71. printk(KERN_WARNING "Non-crashing CPUs did not react to IPI\n");
  72. crash_save_cpu(regs, smp_processor_id());
  73. printk(KERN_INFO "Loading crashdump kernel...\n");
  74. }
  75. /*
  76. * Function pointer to optional machine-specific reinitialization
  77. */
  78. void (*kexec_reinit)(void);
  79. void machine_kexec(struct kimage *image)
  80. {
  81. unsigned long reboot_code_buffer_phys;
  82. void *reboot_code_buffer;
  83. /* we need both effective and real address here */
  84. reboot_code_buffer_phys =
  85. page_to_pfn(image->control_code_page) << PAGE_SHIFT;
  86. reboot_code_buffer = page_address(image->control_code_page);
  87. printk(KERN_INFO "Bye!\n");
  88. if (kexec_reinit)
  89. kexec_reinit();
  90. local_irq_disable();
  91. local_fiq_disable();
  92. setup_mm_for_reboot(0); /* mode is not used, so just pass 0*/
  93. flush_cache_all();
  94. outer_flush_all();
  95. outer_disable();
  96. cpu_proc_fin();
  97. outer_inv_all();
  98. flush_cache_all();
  99. cpu_reset(reboot_code_buffer_phys);
  100. }