machine_kexec.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * arch/ia64/kernel/machine_kexec.c
  3. *
  4. * Handle transition of Linux booting another kernel
  5. * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P.
  6. * Copyright (C) 2005 Khalid Aziz <khalid.aziz@hp.com>
  7. * Copyright (C) 2006 Intel Corp, Zou Nan hai <nanhai.zou@intel.com>
  8. *
  9. * This source code is licensed under the GNU General Public License,
  10. * Version 2. See the file COPYING for more details.
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/kexec.h>
  14. #include <linux/cpu.h>
  15. #include <linux/irq.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/setup.h>
  18. #include <asm/delay.h>
  19. #include <asm/meminit.h>
  20. typedef void (*relocate_new_kernel_t)(unsigned long, unsigned long,
  21. struct ia64_boot_param *, unsigned long);
  22. struct kimage *ia64_kimage;
  23. struct resource efi_memmap_res = {
  24. .name = "EFI Memory Map",
  25. .start = 0,
  26. .end = 0,
  27. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  28. };
  29. struct resource boot_param_res = {
  30. .name = "Boot parameter",
  31. .start = 0,
  32. .end = 0,
  33. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  34. };
  35. /*
  36. * Do what every setup is needed on image and the
  37. * reboot code buffer to allow us to avoid allocations
  38. * later.
  39. */
  40. int machine_kexec_prepare(struct kimage *image)
  41. {
  42. void *control_code_buffer;
  43. const unsigned long *func;
  44. func = (unsigned long *)&relocate_new_kernel;
  45. /* Pre-load control code buffer to minimize work in kexec path */
  46. control_code_buffer = page_address(image->control_code_page);
  47. memcpy((void *)control_code_buffer, (const void *)func[0],
  48. relocate_new_kernel_size);
  49. flush_icache_range((unsigned long)control_code_buffer,
  50. (unsigned long)control_code_buffer + relocate_new_kernel_size);
  51. ia64_kimage = image;
  52. return 0;
  53. }
  54. void machine_kexec_cleanup(struct kimage *image)
  55. {
  56. }
  57. void machine_shutdown(void)
  58. {
  59. int cpu;
  60. for_each_online_cpu(cpu) {
  61. if (cpu != smp_processor_id())
  62. cpu_down(cpu);
  63. }
  64. kexec_disable_iosapic();
  65. }
  66. /*
  67. * Do not allocate memory (or fail in any way) in machine_kexec().
  68. * We are past the point of no return, committed to rebooting now.
  69. */
  70. extern void *efi_get_pal_addr(void);
  71. static void ia64_machine_kexec(struct unw_frame_info *info, void *arg)
  72. {
  73. struct kimage *image = arg;
  74. relocate_new_kernel_t rnk;
  75. void *pal_addr = efi_get_pal_addr();
  76. unsigned long code_addr = (unsigned long)page_address(image->control_code_page);
  77. unsigned long vector;
  78. int ii;
  79. if (image->type == KEXEC_TYPE_CRASH) {
  80. crash_save_this_cpu();
  81. current->thread.ksp = (__u64)info->sw - 16;
  82. }
  83. /* Interrupts aren't acceptable while we reboot */
  84. local_irq_disable();
  85. /* Mask CMC and Performance Monitor interrupts */
  86. ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
  87. ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);
  88. /* Mask ITV and Local Redirect Registers */
  89. ia64_set_itv(1 << 16);
  90. ia64_set_lrr0(1 << 16);
  91. ia64_set_lrr1(1 << 16);
  92. /* terminate possible nested in-service interrupts */
  93. for (ii = 0; ii < 16; ii++)
  94. ia64_eoi();
  95. /* unmask TPR and clear any pending interrupts */
  96. ia64_setreg(_IA64_REG_CR_TPR, 0);
  97. ia64_srlz_d();
  98. vector = ia64_get_ivr();
  99. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  100. ia64_eoi();
  101. vector = ia64_get_ivr();
  102. }
  103. platform_kernel_launch_event();
  104. rnk = (relocate_new_kernel_t)&code_addr;
  105. (*rnk)(image->head, image->start, ia64_boot_param,
  106. GRANULEROUNDDOWN((unsigned long) pal_addr));
  107. BUG();
  108. }
  109. void machine_kexec(struct kimage *image)
  110. {
  111. unw_init_running(ia64_machine_kexec, image);
  112. for(;;);
  113. }