xref: /linux/arch/powerpc/include/asm/kexec.h (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KEXEC_H
3 #define _ASM_POWERPC_KEXEC_H
4 #ifdef __KERNEL__
5 
6 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_44x)
7 
8 /*
9  * On FSL-BookE we setup a 1:1 mapping which covers the first 2GiB of memory
10  * and therefore we can only deal with memory within this range
11  */
12 #define KEXEC_SOURCE_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
13 #define KEXEC_DESTINATION_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
14 #define KEXEC_CONTROL_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
15 
16 #else
17 
18 /*
19  * Maximum page that is mapped directly into kernel memory.
20  * XXX: Since we copy virt we can use any page we allocate
21  */
22 #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
23 
24 /*
25  * Maximum address we can reach in physical address mode.
26  * XXX: I want to allow initrd in highmem. Otherwise set to rmo on LPAR.
27  */
28 #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
29 
30 /* Maximum address we can use for the control code buffer */
31 #ifdef __powerpc64__
32 #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
33 #else
34 /* TASK_SIZE, probably left over from use_mm ?? */
35 #define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
36 #endif
37 #endif
38 
39 #define KEXEC_CONTROL_PAGE_SIZE 4096
40 
41 /* The native architecture */
42 #ifdef __powerpc64__
43 #define KEXEC_ARCH KEXEC_ARCH_PPC64
44 #else
45 #define KEXEC_ARCH KEXEC_ARCH_PPC
46 #endif
47 
48 #define KEXEC_STATE_NONE 0
49 #define KEXEC_STATE_IRQS_OFF 1
50 #define KEXEC_STATE_REAL_MODE 2
51 
52 #ifndef __ASSEMBLY__
53 #include <asm/reg.h>
54 
55 typedef void (*crash_shutdown_t)(void);
56 
57 #ifdef CONFIG_KEXEC_CORE
58 struct kimage;
59 struct pt_regs;
60 
61 extern void kexec_smp_wait(void);	/* get and clear naca physid, wait for
62 					  master to copy new code to 0 */
63 extern void default_machine_kexec(struct kimage *image);
64 extern void machine_kexec_mask_interrupts(void);
65 
66 void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_code_buffer,
67 			 unsigned long start_address) __noreturn;
68 void kexec_copy_flush(struct kimage *image);
69 
70 #ifdef CONFIG_KEXEC_FILE
71 extern const struct kexec_file_ops kexec_elf64_ops;
72 
73 #define ARCH_HAS_KIMAGE_ARCH
74 
75 struct kimage_arch {
76 	struct crash_mem *exclude_ranges;
77 
78 	unsigned long backup_start;
79 	void *backup_buf;
80 	void *fdt;
81 };
82 
83 char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
84 			  unsigned long cmdline_len);
85 int setup_purgatory(struct kimage *image, const void *slave_code,
86 		    const void *fdt, unsigned long kernel_load_addr,
87 		    unsigned long fdt_load_addr);
88 
89 #ifdef CONFIG_PPC64
90 struct kexec_buf;
91 
92 int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len);
93 #define arch_kexec_kernel_image_probe arch_kexec_kernel_image_probe
94 
95 int arch_kimage_file_post_load_cleanup(struct kimage *image);
96 #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
97 
98 int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf);
99 #define arch_kexec_locate_mem_hole arch_kexec_locate_mem_hole
100 
101 int load_crashdump_segments_ppc64(struct kimage *image,
102 				  struct kexec_buf *kbuf);
103 int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
104 			  const void *fdt, unsigned long kernel_load_addr,
105 			  unsigned long fdt_load_addr);
106 unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);
107 int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
108 			unsigned long initrd_load_addr,
109 			unsigned long initrd_len, const char *cmdline);
110 #endif /* CONFIG_PPC64 */
111 
112 #endif /* CONFIG_KEXEC_FILE */
113 
114 #endif /* CONFIG_KEXEC_CORE */
115 
116 #ifdef CONFIG_CRASH_RESERVE
117 int __init overlaps_crashkernel(unsigned long start, unsigned long size);
118 extern void reserve_crashkernel(void);
119 #else
120 static inline void reserve_crashkernel(void) {}
121 static inline int overlaps_crashkernel(unsigned long start, unsigned long size) { return 0; }
122 #endif
123 
124 #if defined(CONFIG_CRASH_DUMP)
125 /*
126  * This function is responsible for capturing register states if coming
127  * via panic or invoking dump using sysrq-trigger.
128  */
129 static inline void crash_setup_regs(struct pt_regs *newregs,
130 					struct pt_regs *oldregs)
131 {
132 	if (oldregs)
133 		memcpy(newregs, oldregs, sizeof(*newregs));
134 	else
135 		ppc_save_regs(newregs);
136 }
137 
138 extern int crashing_cpu;
139 extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
140 extern void crash_ipi_callback(struct pt_regs *regs);
141 extern int crash_wake_offline;
142 
143 extern int crash_shutdown_register(crash_shutdown_t handler);
144 extern int crash_shutdown_unregister(crash_shutdown_t handler);
145 extern void default_machine_crash_shutdown(struct pt_regs *regs);
146 
147 extern void crash_kexec_prepare(void);
148 extern void crash_kexec_secondary(struct pt_regs *regs);
149 
150 static inline bool kdump_in_progress(void)
151 {
152 	return crashing_cpu >= 0;
153 }
154 
155 bool is_kdump_kernel(void);
156 #define is_kdump_kernel			is_kdump_kernel
157 #if defined(CONFIG_PPC_RTAS)
158 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
159 #define crash_free_reserved_phys_range crash_free_reserved_phys_range
160 #endif /* CONFIG_PPC_RTAS */
161 
162 #else /* !CONFIG_CRASH_DUMP */
163 static inline void crash_kexec_secondary(struct pt_regs *regs) { }
164 
165 static inline int crash_shutdown_register(crash_shutdown_t handler)
166 {
167 	return 0;
168 }
169 
170 static inline int crash_shutdown_unregister(crash_shutdown_t handler)
171 {
172 	return 0;
173 }
174 
175 static inline bool kdump_in_progress(void)
176 {
177 	return false;
178 }
179 
180 static inline void crash_ipi_callback(struct pt_regs *regs) { }
181 
182 static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
183 {
184 }
185 
186 #endif /* CONFIG_CRASH_DUMP */
187 
188 #ifdef CONFIG_PPC_BOOK3S_64
189 #include <asm/book3s/64/kexec.h>
190 #endif
191 
192 #ifndef reset_sprs
193 #define reset_sprs reset_sprs
194 static inline void reset_sprs(void)
195 {
196 }
197 #endif
198 
199 #endif /* ! __ASSEMBLY__ */
200 #endif /* __KERNEL__ */
201 #endif /* _ASM_POWERPC_KEXEC_H */
202