Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * kexec for arm64
0004  *
0005  * Copyright (C) Linaro.
0006  * Copyright (C) Huawei Futurewei Technologies.
0007  */
0008 
0009 #ifndef _ARM64_KEXEC_H
0010 #define _ARM64_KEXEC_H
0011 
0012 /* Maximum physical address we can use pages from */
0013 
0014 #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
0015 
0016 /* Maximum address we can reach in physical address mode */
0017 
0018 #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
0019 
0020 /* Maximum address we can use for the control code buffer */
0021 
0022 #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
0023 
0024 #define KEXEC_CONTROL_PAGE_SIZE 4096
0025 
0026 #define KEXEC_ARCH KEXEC_ARCH_AARCH64
0027 
0028 #ifndef __ASSEMBLY__
0029 
0030 /**
0031  * crash_setup_regs() - save registers for the panic kernel
0032  *
0033  * @newregs: registers are saved here
0034  * @oldregs: registers to be saved (may be %NULL)
0035  */
0036 
0037 static inline void crash_setup_regs(struct pt_regs *newregs,
0038                     struct pt_regs *oldregs)
0039 {
0040     if (oldregs) {
0041         memcpy(newregs, oldregs, sizeof(*newregs));
0042     } else {
0043         u64 tmp1, tmp2;
0044 
0045         __asm__ __volatile__ (
0046             "stp     x0,   x1, [%2, #16 *  0]\n"
0047             "stp     x2,   x3, [%2, #16 *  1]\n"
0048             "stp     x4,   x5, [%2, #16 *  2]\n"
0049             "stp     x6,   x7, [%2, #16 *  3]\n"
0050             "stp     x8,   x9, [%2, #16 *  4]\n"
0051             "stp    x10,  x11, [%2, #16 *  5]\n"
0052             "stp    x12,  x13, [%2, #16 *  6]\n"
0053             "stp    x14,  x15, [%2, #16 *  7]\n"
0054             "stp    x16,  x17, [%2, #16 *  8]\n"
0055             "stp    x18,  x19, [%2, #16 *  9]\n"
0056             "stp    x20,  x21, [%2, #16 * 10]\n"
0057             "stp    x22,  x23, [%2, #16 * 11]\n"
0058             "stp    x24,  x25, [%2, #16 * 12]\n"
0059             "stp    x26,  x27, [%2, #16 * 13]\n"
0060             "stp    x28,  x29, [%2, #16 * 14]\n"
0061             "mov     %0,  sp\n"
0062             "stp    x30,  %0,  [%2, #16 * 15]\n"
0063 
0064             "/* faked current PSTATE */\n"
0065             "mrs     %0, CurrentEL\n"
0066             "mrs     %1, SPSEL\n"
0067             "orr     %0, %0, %1\n"
0068             "mrs     %1, DAIF\n"
0069             "orr     %0, %0, %1\n"
0070             "mrs     %1, NZCV\n"
0071             "orr     %0, %0, %1\n"
0072             /* pc */
0073             "adr     %1, 1f\n"
0074         "1:\n"
0075             "stp     %1, %0,   [%2, #16 * 16]\n"
0076             : "=&r" (tmp1), "=&r" (tmp2)
0077             : "r" (newregs)
0078             : "memory"
0079         );
0080     }
0081 }
0082 
0083 #if defined(CONFIG_KEXEC_CORE) && defined(CONFIG_HIBERNATION)
0084 extern bool crash_is_nosave(unsigned long pfn);
0085 extern void crash_prepare_suspend(void);
0086 extern void crash_post_resume(void);
0087 
0088 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
0089 #define crash_free_reserved_phys_range crash_free_reserved_phys_range
0090 #else
0091 static inline bool crash_is_nosave(unsigned long pfn) {return false; }
0092 static inline void crash_prepare_suspend(void) {}
0093 static inline void crash_post_resume(void) {}
0094 #endif
0095 
0096 struct kimage;
0097 
0098 #if defined(CONFIG_KEXEC_CORE)
0099 void cpu_soft_restart(unsigned long el2_switch, unsigned long entry,
0100               unsigned long arg0, unsigned long arg1,
0101               unsigned long arg2);
0102 
0103 int machine_kexec_post_load(struct kimage *image);
0104 #define machine_kexec_post_load machine_kexec_post_load
0105 
0106 void arch_kexec_protect_crashkres(void);
0107 #define arch_kexec_protect_crashkres arch_kexec_protect_crashkres
0108 
0109 void arch_kexec_unprotect_crashkres(void);
0110 #define arch_kexec_unprotect_crashkres arch_kexec_unprotect_crashkres
0111 #endif
0112 
0113 #define ARCH_HAS_KIMAGE_ARCH
0114 
0115 struct kimage_arch {
0116     void *dtb;
0117     phys_addr_t dtb_mem;
0118     phys_addr_t kern_reloc;
0119     phys_addr_t el2_vectors;
0120     phys_addr_t ttbr0;
0121     phys_addr_t ttbr1;
0122     phys_addr_t zero_page;
0123     unsigned long phys_offset;
0124     unsigned long t0sz;
0125 };
0126 
0127 #ifdef CONFIG_KEXEC_FILE
0128 extern const struct kexec_file_ops kexec_image_ops;
0129 
0130 int arch_kimage_file_post_load_cleanup(struct kimage *image);
0131 #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
0132 
0133 extern int load_other_segments(struct kimage *image,
0134         unsigned long kernel_load_addr, unsigned long kernel_size,
0135         char *initrd, unsigned long initrd_len,
0136         char *cmdline);
0137 #endif
0138 
0139 #endif /* __ASSEMBLY__ */
0140 
0141 #endif