xref: /openbmc/linux/arch/powerpc/include/asm/kexec.h (revision 1f00b5ab)
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_FSL_BOOKE) || 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 
59 /*
60  * This function is responsible for capturing register states if coming
61  * via panic or invoking dump using sysrq-trigger.
62  */
63 static inline void crash_setup_regs(struct pt_regs *newregs,
64 					struct pt_regs *oldregs)
65 {
66 	if (oldregs)
67 		memcpy(newregs, oldregs, sizeof(*newregs));
68 	else
69 		ppc_save_regs(newregs);
70 }
71 
72 extern void kexec_smp_wait(void);	/* get and clear naca physid, wait for
73 					  master to copy new code to 0 */
74 extern int crashing_cpu;
75 extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
76 extern void crash_ipi_callback(struct pt_regs *);
77 extern int crash_wake_offline;
78 
79 struct kimage;
80 struct pt_regs;
81 extern void default_machine_kexec(struct kimage *image);
82 extern void default_machine_crash_shutdown(struct pt_regs *regs);
83 extern int crash_shutdown_register(crash_shutdown_t handler);
84 extern int crash_shutdown_unregister(crash_shutdown_t handler);
85 
86 extern void crash_kexec_prepare(void);
87 extern void crash_kexec_secondary(struct pt_regs *regs);
88 int __init overlaps_crashkernel(unsigned long start, unsigned long size);
89 extern void reserve_crashkernel(void);
90 extern void machine_kexec_mask_interrupts(void);
91 
92 static inline bool kdump_in_progress(void)
93 {
94 	return crashing_cpu >= 0;
95 }
96 
97 void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_code_buffer,
98 			 unsigned long start_address) __noreturn;
99 
100 void kexec_copy_flush(struct kimage *image);
101 
102 #ifdef CONFIG_KEXEC_FILE
103 extern const struct kexec_file_ops kexec_elf64_ops;
104 
105 #define ARCH_HAS_KIMAGE_ARCH
106 
107 struct kimage_arch {
108 	struct crash_mem *exclude_ranges;
109 
110 	unsigned long backup_start;
111 	void *backup_buf;
112 	void *fdt;
113 };
114 
115 char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
116 			  unsigned long cmdline_len);
117 int setup_purgatory(struct kimage *image, const void *slave_code,
118 		    const void *fdt, unsigned long kernel_load_addr,
119 		    unsigned long fdt_load_addr);
120 
121 #ifdef CONFIG_PPC64
122 struct kexec_buf;
123 
124 int load_crashdump_segments_ppc64(struct kimage *image,
125 				  struct kexec_buf *kbuf);
126 int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
127 			  const void *fdt, unsigned long kernel_load_addr,
128 			  unsigned long fdt_load_addr);
129 unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);
130 int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
131 			unsigned long initrd_load_addr,
132 			unsigned long initrd_len, const char *cmdline);
133 #endif /* CONFIG_PPC64 */
134 
135 #endif /* CONFIG_KEXEC_FILE */
136 
137 #else /* !CONFIG_KEXEC_CORE */
138 static inline void crash_kexec_secondary(struct pt_regs *regs) { }
139 
140 static inline int overlaps_crashkernel(unsigned long start, unsigned long size)
141 {
142 	return 0;
143 }
144 
145 static inline void reserve_crashkernel(void) { ; }
146 
147 static inline int crash_shutdown_register(crash_shutdown_t handler)
148 {
149 	return 0;
150 }
151 
152 static inline int crash_shutdown_unregister(crash_shutdown_t handler)
153 {
154 	return 0;
155 }
156 
157 static inline bool kdump_in_progress(void)
158 {
159 	return false;
160 }
161 
162 static inline void crash_ipi_callback(struct pt_regs *regs) { }
163 
164 static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
165 {
166 }
167 
168 #endif /* CONFIG_KEXEC_CORE */
169 
170 #ifdef CONFIG_PPC_BOOK3S_64
171 #include <asm/book3s/64/kexec.h>
172 #endif
173 
174 #ifndef reset_sprs
175 #define reset_sprs reset_sprs
176 static inline void reset_sprs(void)
177 {
178 }
179 #endif
180 
181 #endif /* ! __ASSEMBLY__ */
182 #endif /* __KERNEL__ */
183 #endif /* _ASM_POWERPC_KEXEC_H */
184