kexec.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * kexec for arm64
  4. *
  5. * Copyright (C) Linaro.
  6. * Copyright (C) Huawei Futurewei Technologies.
  7. */
  8. #ifndef _ARM64_KEXEC_H
  9. #define _ARM64_KEXEC_H
  10. /* Maximum physical address we can use pages from */
  11. #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
  12. /* Maximum address we can reach in physical address mode */
  13. #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
  14. /* Maximum address we can use for the control code buffer */
  15. #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
  16. #define KEXEC_CONTROL_PAGE_SIZE 4096
  17. #define KEXEC_ARCH KEXEC_ARCH_AARCH64
  18. #ifndef __ASSEMBLY__
  19. /**
  20. * crash_setup_regs() - save registers for the panic kernel
  21. *
  22. * @newregs: registers are saved here
  23. * @oldregs: registers to be saved (may be %NULL)
  24. */
  25. static inline void crash_setup_regs(struct pt_regs *newregs,
  26. struct pt_regs *oldregs)
  27. {
  28. if (oldregs) {
  29. memcpy(newregs, oldregs, sizeof(*newregs));
  30. } else {
  31. u64 tmp1, tmp2;
  32. __asm__ __volatile__ (
  33. "stp x0, x1, [%2, #16 * 0]\n"
  34. "stp x2, x3, [%2, #16 * 1]\n"
  35. "stp x4, x5, [%2, #16 * 2]\n"
  36. "stp x6, x7, [%2, #16 * 3]\n"
  37. "stp x8, x9, [%2, #16 * 4]\n"
  38. "stp x10, x11, [%2, #16 * 5]\n"
  39. "stp x12, x13, [%2, #16 * 6]\n"
  40. "stp x14, x15, [%2, #16 * 7]\n"
  41. "stp x16, x17, [%2, #16 * 8]\n"
  42. "stp x18, x19, [%2, #16 * 9]\n"
  43. "stp x20, x21, [%2, #16 * 10]\n"
  44. "stp x22, x23, [%2, #16 * 11]\n"
  45. "stp x24, x25, [%2, #16 * 12]\n"
  46. "stp x26, x27, [%2, #16 * 13]\n"
  47. "stp x28, x29, [%2, #16 * 14]\n"
  48. "mov %0, sp\n"
  49. "stp x30, %0, [%2, #16 * 15]\n"
  50. "/* faked current PSTATE */\n"
  51. "mrs %0, CurrentEL\n"
  52. "mrs %1, SPSEL\n"
  53. "orr %0, %0, %1\n"
  54. "mrs %1, DAIF\n"
  55. "orr %0, %0, %1\n"
  56. "mrs %1, NZCV\n"
  57. "orr %0, %0, %1\n"
  58. /* pc */
  59. "adr %1, 1f\n"
  60. "1:\n"
  61. "stp %1, %0, [%2, #16 * 16]\n"
  62. : "=&r" (tmp1), "=&r" (tmp2)
  63. : "r" (newregs)
  64. : "memory"
  65. );
  66. }
  67. }
  68. #if defined(CONFIG_KEXEC_CORE) && defined(CONFIG_HIBERNATION)
  69. extern bool crash_is_nosave(unsigned long pfn);
  70. extern void crash_prepare_suspend(void);
  71. extern void crash_post_resume(void);
  72. void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
  73. #define crash_free_reserved_phys_range crash_free_reserved_phys_range
  74. #else
  75. static inline bool crash_is_nosave(unsigned long pfn) {return false; }
  76. static inline void crash_prepare_suspend(void) {}
  77. static inline void crash_post_resume(void) {}
  78. #endif
  79. struct kimage;
  80. #if defined(CONFIG_KEXEC_CORE)
  81. void cpu_soft_restart(unsigned long el2_switch, unsigned long entry,
  82. unsigned long arg0, unsigned long arg1,
  83. unsigned long arg2);
  84. int machine_kexec_post_load(struct kimage *image);
  85. #define machine_kexec_post_load machine_kexec_post_load
  86. void arch_kexec_protect_crashkres(void);
  87. #define arch_kexec_protect_crashkres arch_kexec_protect_crashkres
  88. void arch_kexec_unprotect_crashkres(void);
  89. #define arch_kexec_unprotect_crashkres arch_kexec_unprotect_crashkres
  90. #endif
  91. #define ARCH_HAS_KIMAGE_ARCH
  92. struct kimage_arch {
  93. void *dtb;
  94. phys_addr_t dtb_mem;
  95. phys_addr_t kern_reloc;
  96. phys_addr_t el2_vectors;
  97. phys_addr_t ttbr0;
  98. phys_addr_t ttbr1;
  99. phys_addr_t zero_page;
  100. unsigned long phys_offset;
  101. unsigned long t0sz;
  102. };
  103. #ifdef CONFIG_KEXEC_FILE
  104. extern const struct kexec_file_ops kexec_image_ops;
  105. int arch_kimage_file_post_load_cleanup(struct kimage *image);
  106. #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
  107. extern int load_other_segments(struct kimage *image,
  108. unsigned long kernel_load_addr, unsigned long kernel_size,
  109. char *initrd, unsigned long initrd_len,
  110. char *cmdline);
  111. #endif
  112. #endif /* __ASSEMBLY__ */
  113. #endif