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