machine_kexec.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/ia64/kernel/machine_kexec.c
  4. *
  5. * Handle transition of Linux booting another kernel
  6. * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P.
  7. * Copyright (C) 2005 Khalid Aziz <[email protected]>
  8. * Copyright (C) 2006 Intel Corp, Zou Nan hai <[email protected]>
  9. */
  10. #include <linux/mm.h>
  11. #include <linux/kexec.h>
  12. #include <linux/cpu.h>
  13. #include <linux/irq.h>
  14. #include <linux/efi.h>
  15. #include <linux/numa.h>
  16. #include <linux/mmzone.h>
  17. #include <asm/efi.h>
  18. #include <asm/numa.h>
  19. #include <asm/mmu_context.h>
  20. #include <asm/setup.h>
  21. #include <asm/delay.h>
  22. #include <asm/meminit.h>
  23. #include <asm/processor.h>
  24. #include <asm/sal.h>
  25. #include <asm/mca.h>
  26. typedef void (*relocate_new_kernel_t)(
  27. unsigned long indirection_page,
  28. unsigned long start_address,
  29. struct ia64_boot_param *boot_param,
  30. unsigned long pal_addr) __noreturn;
  31. struct kimage *ia64_kimage;
  32. struct resource efi_memmap_res = {
  33. .name = "EFI Memory Map",
  34. .start = 0,
  35. .end = 0,
  36. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  37. };
  38. struct resource boot_param_res = {
  39. .name = "Boot parameter",
  40. .start = 0,
  41. .end = 0,
  42. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  43. };
  44. /*
  45. * Do what every setup is needed on image and the
  46. * reboot code buffer to allow us to avoid allocations
  47. * later.
  48. */
  49. int machine_kexec_prepare(struct kimage *image)
  50. {
  51. void *control_code_buffer;
  52. const unsigned long *func;
  53. func = (unsigned long *)&relocate_new_kernel;
  54. /* Pre-load control code buffer to minimize work in kexec path */
  55. control_code_buffer = page_address(image->control_code_page);
  56. memcpy((void *)control_code_buffer, (const void *)func[0],
  57. relocate_new_kernel_size);
  58. flush_icache_range((unsigned long)control_code_buffer,
  59. (unsigned long)control_code_buffer + relocate_new_kernel_size);
  60. ia64_kimage = image;
  61. return 0;
  62. }
  63. void machine_kexec_cleanup(struct kimage *image)
  64. {
  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. static void ia64_machine_kexec(struct unw_frame_info *info, void *arg)
  71. {
  72. struct kimage *image = arg;
  73. relocate_new_kernel_t rnk;
  74. void *pal_addr = efi_get_pal_addr();
  75. unsigned long code_addr;
  76. int ii;
  77. u64 fp, gp;
  78. ia64_fptr_t *init_handler = (ia64_fptr_t *)ia64_os_init_on_kdump;
  79. BUG_ON(!image);
  80. code_addr = (unsigned long)page_address(image->control_code_page);
  81. if (image->type == KEXEC_TYPE_CRASH) {
  82. crash_save_this_cpu();
  83. current->thread.ksp = (__u64)info->sw - 16;
  84. /* Register noop init handler */
  85. fp = ia64_tpa(init_handler->fp);
  86. gp = ia64_tpa(ia64_getreg(_IA64_REG_GP));
  87. ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, fp, gp, 0, fp, gp, 0);
  88. } else {
  89. /* Unregister init handlers of current kernel */
  90. ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 0, 0, 0, 0, 0, 0);
  91. }
  92. /* Unregister mca handler - No more recovery on current kernel */
  93. ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 0, 0, 0, 0, 0, 0);
  94. /* Interrupts aren't acceptable while we reboot */
  95. local_irq_disable();
  96. /* Mask CMC and Performance Monitor interrupts */
  97. ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
  98. ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);
  99. /* Mask ITV and Local Redirect Registers */
  100. ia64_set_itv(1 << 16);
  101. ia64_set_lrr0(1 << 16);
  102. ia64_set_lrr1(1 << 16);
  103. /* terminate possible nested in-service interrupts */
  104. for (ii = 0; ii < 16; ii++)
  105. ia64_eoi();
  106. /* unmask TPR and clear any pending interrupts */
  107. ia64_setreg(_IA64_REG_CR_TPR, 0);
  108. ia64_srlz_d();
  109. while (ia64_get_ivr() != IA64_SPURIOUS_INT_VECTOR)
  110. ia64_eoi();
  111. rnk = (relocate_new_kernel_t)&code_addr;
  112. (*rnk)(image->head, image->start, ia64_boot_param,
  113. GRANULEROUNDDOWN((unsigned long) pal_addr));
  114. BUG();
  115. }
  116. void machine_kexec(struct kimage *image)
  117. {
  118. BUG_ON(!image);
  119. unw_init_running(ia64_machine_kexec, image);
  120. for(;;);
  121. }
  122. void arch_crash_save_vmcoreinfo(void)
  123. {
  124. #if defined(CONFIG_SPARSEMEM)
  125. VMCOREINFO_SYMBOL(pgdat_list);
  126. VMCOREINFO_LENGTH(pgdat_list, MAX_NUMNODES);
  127. #endif
  128. #ifdef CONFIG_NUMA
  129. VMCOREINFO_SYMBOL(node_memblk);
  130. VMCOREINFO_LENGTH(node_memblk, NR_NODE_MEMBLKS);
  131. VMCOREINFO_STRUCT_SIZE(node_memblk_s);
  132. VMCOREINFO_OFFSET(node_memblk_s, start_paddr);
  133. VMCOREINFO_OFFSET(node_memblk_s, size);
  134. #endif
  135. #if CONFIG_PGTABLE_LEVELS == 3
  136. VMCOREINFO_CONFIG(PGTABLE_3);
  137. #elif CONFIG_PGTABLE_LEVELS == 4
  138. VMCOREINFO_CONFIG(PGTABLE_4);
  139. #endif
  140. }