machine_kexec.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 NORET_TYPE void (*relocate_new_kernel_t)(
  21. unsigned long indirection_page,
  22. unsigned long start_address,
  23. struct ia64_boot_param *boot_param,
  24. unsigned long pal_addr) ATTRIB_NORET;
  25. struct kimage *ia64_kimage;
  26. struct resource efi_memmap_res = {
  27. .name = "EFI Memory Map",
  28. .start = 0,
  29. .end = 0,
  30. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  31. };
  32. struct resource boot_param_res = {
  33. .name = "Boot parameter",
  34. .start = 0,
  35. .end = 0,
  36. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  37. };
  38. /*
  39. * Do what every setup is needed on image and the
  40. * reboot code buffer to allow us to avoid allocations
  41. * later.
  42. */
  43. int machine_kexec_prepare(struct kimage *image)
  44. {
  45. void *control_code_buffer;
  46. const unsigned long *func;
  47. func = (unsigned long *)&relocate_new_kernel;
  48. /* Pre-load control code buffer to minimize work in kexec path */
  49. control_code_buffer = page_address(image->control_code_page);
  50. memcpy((void *)control_code_buffer, (const void *)func[0],
  51. relocate_new_kernel_size);
  52. flush_icache_range((unsigned long)control_code_buffer,
  53. (unsigned long)control_code_buffer + relocate_new_kernel_size);
  54. ia64_kimage = image;
  55. return 0;
  56. }
  57. void machine_kexec_cleanup(struct kimage *image)
  58. {
  59. }
  60. void machine_shutdown(void)
  61. {
  62. int cpu;
  63. for_each_online_cpu(cpu) {
  64. if (cpu != smp_processor_id())
  65. cpu_down(cpu);
  66. }
  67. kexec_disable_iosapic();
  68. }
  69. /*
  70. * Do not allocate memory (or fail in any way) in machine_kexec().
  71. * We are past the point of no return, committed to rebooting now.
  72. */
  73. extern void *efi_get_pal_addr(void);
  74. static void ia64_machine_kexec(struct unw_frame_info *info, void *arg)
  75. {
  76. struct kimage *image = arg;
  77. relocate_new_kernel_t rnk;
  78. void *pal_addr = efi_get_pal_addr();
  79. unsigned long code_addr = (unsigned long)page_address(image->control_code_page);
  80. unsigned long vector;
  81. int ii;
  82. if (image->type == KEXEC_TYPE_CRASH) {
  83. crash_save_this_cpu();
  84. current->thread.ksp = (__u64)info->sw - 16;
  85. }
  86. /* Interrupts aren't acceptable while we reboot */
  87. local_irq_disable();
  88. /* Mask CMC and Performance Monitor interrupts */
  89. ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
  90. ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);
  91. /* Mask ITV and Local Redirect Registers */
  92. ia64_set_itv(1 << 16);
  93. ia64_set_lrr0(1 << 16);
  94. ia64_set_lrr1(1 << 16);
  95. /* terminate possible nested in-service interrupts */
  96. for (ii = 0; ii < 16; ii++)
  97. ia64_eoi();
  98. /* unmask TPR and clear any pending interrupts */
  99. ia64_setreg(_IA64_REG_CR_TPR, 0);
  100. ia64_srlz_d();
  101. vector = ia64_get_ivr();
  102. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  103. ia64_eoi();
  104. vector = ia64_get_ivr();
  105. }
  106. platform_kernel_launch_event();
  107. rnk = (relocate_new_kernel_t)&code_addr;
  108. (*rnk)(image->head, image->start, ia64_boot_param,
  109. GRANULEROUNDDOWN((unsigned long) pal_addr));
  110. BUG();
  111. }
  112. void machine_kexec(struct kimage *image)
  113. {
  114. unw_init_running(ia64_machine_kexec, image);
  115. for(;;);
  116. }