xref: /OK3568_Linux_fs/kernel/include/linux/kexec.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef LINUX_KEXEC_H
3*4882a593Smuzhiyun #define LINUX_KEXEC_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #define IND_DESTINATION_BIT 0
6*4882a593Smuzhiyun #define IND_INDIRECTION_BIT 1
7*4882a593Smuzhiyun #define IND_DONE_BIT        2
8*4882a593Smuzhiyun #define IND_SOURCE_BIT      3
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #define IND_DESTINATION  (1 << IND_DESTINATION_BIT)
11*4882a593Smuzhiyun #define IND_INDIRECTION  (1 << IND_INDIRECTION_BIT)
12*4882a593Smuzhiyun #define IND_DONE         (1 << IND_DONE_BIT)
13*4882a593Smuzhiyun #define IND_SOURCE       (1 << IND_SOURCE_BIT)
14*4882a593Smuzhiyun #define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #if !defined(__ASSEMBLY__)
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include <linux/crash_core.h>
19*4882a593Smuzhiyun #include <asm/io.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include <uapi/linux/kexec.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_CORE
24*4882a593Smuzhiyun #include <linux/list.h>
25*4882a593Smuzhiyun #include <linux/compat.h>
26*4882a593Smuzhiyun #include <linux/ioport.h>
27*4882a593Smuzhiyun #include <linux/module.h>
28*4882a593Smuzhiyun #include <asm/kexec.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* Verify architecture specific macros are defined */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifndef KEXEC_SOURCE_MEMORY_LIMIT
33*4882a593Smuzhiyun #error KEXEC_SOURCE_MEMORY_LIMIT not defined
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
37*4882a593Smuzhiyun #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
38*4882a593Smuzhiyun #endif
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #ifndef KEXEC_CONTROL_MEMORY_LIMIT
41*4882a593Smuzhiyun #error KEXEC_CONTROL_MEMORY_LIMIT not defined
42*4882a593Smuzhiyun #endif
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #ifndef KEXEC_CONTROL_MEMORY_GFP
45*4882a593Smuzhiyun #define KEXEC_CONTROL_MEMORY_GFP (GFP_KERNEL | __GFP_NORETRY)
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #ifndef KEXEC_CONTROL_PAGE_SIZE
49*4882a593Smuzhiyun #error KEXEC_CONTROL_PAGE_SIZE not defined
50*4882a593Smuzhiyun #endif
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #ifndef KEXEC_ARCH
53*4882a593Smuzhiyun #error KEXEC_ARCH not defined
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
57*4882a593Smuzhiyun #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #ifndef KEXEC_CRASH_MEM_ALIGN
61*4882a593Smuzhiyun #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #define KEXEC_CORE_NOTE_NAME	CRASH_CORE_NOTE_NAME
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /*
67*4882a593Smuzhiyun  * This structure is used to hold the arguments that are used when loading
68*4882a593Smuzhiyun  * kernel binaries.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun typedef unsigned long kimage_entry_t;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct kexec_segment {
74*4882a593Smuzhiyun 	/*
75*4882a593Smuzhiyun 	 * This pointer can point to user memory if kexec_load() system
76*4882a593Smuzhiyun 	 * call is used or will point to kernel memory if
77*4882a593Smuzhiyun 	 * kexec_file_load() system call is used.
78*4882a593Smuzhiyun 	 *
79*4882a593Smuzhiyun 	 * Use ->buf when expecting to deal with user memory and use ->kbuf
80*4882a593Smuzhiyun 	 * when expecting to deal with kernel memory.
81*4882a593Smuzhiyun 	 */
82*4882a593Smuzhiyun 	union {
83*4882a593Smuzhiyun 		void __user *buf;
84*4882a593Smuzhiyun 		void *kbuf;
85*4882a593Smuzhiyun 	};
86*4882a593Smuzhiyun 	size_t bufsz;
87*4882a593Smuzhiyun 	unsigned long mem;
88*4882a593Smuzhiyun 	size_t memsz;
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
92*4882a593Smuzhiyun struct compat_kexec_segment {
93*4882a593Smuzhiyun 	compat_uptr_t buf;
94*4882a593Smuzhiyun 	compat_size_t bufsz;
95*4882a593Smuzhiyun 	compat_ulong_t mem;	/* User space sees this as a (void *) ... */
96*4882a593Smuzhiyun 	compat_size_t memsz;
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun #endif
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_FILE
101*4882a593Smuzhiyun struct purgatory_info {
102*4882a593Smuzhiyun 	/*
103*4882a593Smuzhiyun 	 * Pointer to elf header at the beginning of kexec_purgatory.
104*4882a593Smuzhiyun 	 * Note: kexec_purgatory is read only
105*4882a593Smuzhiyun 	 */
106*4882a593Smuzhiyun 	const Elf_Ehdr *ehdr;
107*4882a593Smuzhiyun 	/*
108*4882a593Smuzhiyun 	 * Temporary, modifiable buffer for sechdrs used for relocation.
109*4882a593Smuzhiyun 	 * This memory can be freed post image load.
110*4882a593Smuzhiyun 	 */
111*4882a593Smuzhiyun 	Elf_Shdr *sechdrs;
112*4882a593Smuzhiyun 	/*
113*4882a593Smuzhiyun 	 * Temporary, modifiable buffer for stripped purgatory used for
114*4882a593Smuzhiyun 	 * relocation. This memory can be freed post image load.
115*4882a593Smuzhiyun 	 */
116*4882a593Smuzhiyun 	void *purgatory_buf;
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun struct kimage;
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
122*4882a593Smuzhiyun typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
123*4882a593Smuzhiyun 			     unsigned long kernel_len, char *initrd,
124*4882a593Smuzhiyun 			     unsigned long initrd_len, char *cmdline,
125*4882a593Smuzhiyun 			     unsigned long cmdline_len);
126*4882a593Smuzhiyun typedef int (kexec_cleanup_t)(void *loader_data);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_SIG
129*4882a593Smuzhiyun typedef int (kexec_verify_sig_t)(const char *kernel_buf,
130*4882a593Smuzhiyun 				 unsigned long kernel_len);
131*4882a593Smuzhiyun #endif
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun struct kexec_file_ops {
134*4882a593Smuzhiyun 	kexec_probe_t *probe;
135*4882a593Smuzhiyun 	kexec_load_t *load;
136*4882a593Smuzhiyun 	kexec_cleanup_t *cleanup;
137*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_SIG
138*4882a593Smuzhiyun 	kexec_verify_sig_t *verify_sig;
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun };
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun extern const struct kexec_file_ops * const kexec_file_loaders[];
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun int kexec_image_probe_default(struct kimage *image, void *buf,
145*4882a593Smuzhiyun 			      unsigned long buf_len);
146*4882a593Smuzhiyun int kexec_image_post_load_cleanup_default(struct kimage *image);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /*
149*4882a593Smuzhiyun  * If kexec_buf.mem is set to this value, kexec_locate_mem_hole()
150*4882a593Smuzhiyun  * will try to allocate free memory. Arch may overwrite it.
151*4882a593Smuzhiyun  */
152*4882a593Smuzhiyun #ifndef KEXEC_BUF_MEM_UNKNOWN
153*4882a593Smuzhiyun #define KEXEC_BUF_MEM_UNKNOWN 0
154*4882a593Smuzhiyun #endif
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /**
157*4882a593Smuzhiyun  * struct kexec_buf - parameters for finding a place for a buffer in memory
158*4882a593Smuzhiyun  * @image:	kexec image in which memory to search.
159*4882a593Smuzhiyun  * @buffer:	Contents which will be copied to the allocated memory.
160*4882a593Smuzhiyun  * @bufsz:	Size of @buffer.
161*4882a593Smuzhiyun  * @mem:	On return will have address of the buffer in memory.
162*4882a593Smuzhiyun  * @memsz:	Size for the buffer in memory.
163*4882a593Smuzhiyun  * @buf_align:	Minimum alignment needed.
164*4882a593Smuzhiyun  * @buf_min:	The buffer can't be placed below this address.
165*4882a593Smuzhiyun  * @buf_max:	The buffer can't be placed above this address.
166*4882a593Smuzhiyun  * @top_down:	Allocate from top of memory.
167*4882a593Smuzhiyun  */
168*4882a593Smuzhiyun struct kexec_buf {
169*4882a593Smuzhiyun 	struct kimage *image;
170*4882a593Smuzhiyun 	void *buffer;
171*4882a593Smuzhiyun 	unsigned long bufsz;
172*4882a593Smuzhiyun 	unsigned long mem;
173*4882a593Smuzhiyun 	unsigned long memsz;
174*4882a593Smuzhiyun 	unsigned long buf_align;
175*4882a593Smuzhiyun 	unsigned long buf_min;
176*4882a593Smuzhiyun 	unsigned long buf_max;
177*4882a593Smuzhiyun 	bool top_down;
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun int kexec_load_purgatory(struct kimage *image, struct kexec_buf *kbuf);
181*4882a593Smuzhiyun int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
182*4882a593Smuzhiyun 				   void *buf, unsigned int size,
183*4882a593Smuzhiyun 				   bool get_value);
184*4882a593Smuzhiyun void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun /* Architectures may override the below functions */
187*4882a593Smuzhiyun int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
188*4882a593Smuzhiyun 				  unsigned long buf_len);
189*4882a593Smuzhiyun void *arch_kexec_kernel_image_load(struct kimage *image);
190*4882a593Smuzhiyun int arch_kimage_file_post_load_cleanup(struct kimage *image);
191*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_SIG
192*4882a593Smuzhiyun int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
193*4882a593Smuzhiyun 				 unsigned long buf_len);
194*4882a593Smuzhiyun #endif
195*4882a593Smuzhiyun int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun extern int kexec_add_buffer(struct kexec_buf *kbuf);
198*4882a593Smuzhiyun int kexec_locate_mem_hole(struct kexec_buf *kbuf);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun /* Alignment required for elf header segment */
201*4882a593Smuzhiyun #define ELF_CORE_HEADER_ALIGN   4096
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun struct crash_mem_range {
204*4882a593Smuzhiyun 	u64 start, end;
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun struct crash_mem {
208*4882a593Smuzhiyun 	unsigned int max_nr_ranges;
209*4882a593Smuzhiyun 	unsigned int nr_ranges;
210*4882a593Smuzhiyun 	struct crash_mem_range ranges[];
211*4882a593Smuzhiyun };
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun extern int crash_exclude_mem_range(struct crash_mem *mem,
214*4882a593Smuzhiyun 				   unsigned long long mstart,
215*4882a593Smuzhiyun 				   unsigned long long mend);
216*4882a593Smuzhiyun extern int crash_prepare_elf64_headers(struct crash_mem *mem, int kernel_map,
217*4882a593Smuzhiyun 				       void **addr, unsigned long *sz);
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun #ifndef arch_kexec_apply_relocations_add
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun  * arch_kexec_apply_relocations_add - apply relocations of type RELA
222*4882a593Smuzhiyun  * @pi:		Purgatory to be relocated.
223*4882a593Smuzhiyun  * @section:	Section relocations applying to.
224*4882a593Smuzhiyun  * @relsec:	Section containing RELAs.
225*4882a593Smuzhiyun  * @symtab:	Corresponding symtab.
226*4882a593Smuzhiyun  *
227*4882a593Smuzhiyun  * Return: 0 on success, negative errno on error.
228*4882a593Smuzhiyun  */
229*4882a593Smuzhiyun static inline int
arch_kexec_apply_relocations_add(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)230*4882a593Smuzhiyun arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
231*4882a593Smuzhiyun 				 const Elf_Shdr *relsec, const Elf_Shdr *symtab)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun 	pr_err("RELA relocation unsupported.\n");
234*4882a593Smuzhiyun 	return -ENOEXEC;
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun #endif
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun #ifndef arch_kexec_apply_relocations
239*4882a593Smuzhiyun /*
240*4882a593Smuzhiyun  * arch_kexec_apply_relocations - apply relocations of type REL
241*4882a593Smuzhiyun  * @pi:		Purgatory to be relocated.
242*4882a593Smuzhiyun  * @section:	Section relocations applying to.
243*4882a593Smuzhiyun  * @relsec:	Section containing RELs.
244*4882a593Smuzhiyun  * @symtab:	Corresponding symtab.
245*4882a593Smuzhiyun  *
246*4882a593Smuzhiyun  * Return: 0 on success, negative errno on error.
247*4882a593Smuzhiyun  */
248*4882a593Smuzhiyun static inline int
arch_kexec_apply_relocations(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)249*4882a593Smuzhiyun arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
250*4882a593Smuzhiyun 			     const Elf_Shdr *relsec, const Elf_Shdr *symtab)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun 	pr_err("REL relocation unsupported.\n");
253*4882a593Smuzhiyun 	return -ENOEXEC;
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun #endif
256*4882a593Smuzhiyun #endif /* CONFIG_KEXEC_FILE */
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_ELF
259*4882a593Smuzhiyun struct kexec_elf_info {
260*4882a593Smuzhiyun 	/*
261*4882a593Smuzhiyun 	 * Where the ELF binary contents are kept.
262*4882a593Smuzhiyun 	 * Memory managed by the user of the struct.
263*4882a593Smuzhiyun 	 */
264*4882a593Smuzhiyun 	const char *buffer;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	const struct elfhdr *ehdr;
267*4882a593Smuzhiyun 	const struct elf_phdr *proghdrs;
268*4882a593Smuzhiyun };
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun int kexec_build_elf_info(const char *buf, size_t len, struct elfhdr *ehdr,
271*4882a593Smuzhiyun 			       struct kexec_elf_info *elf_info);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
274*4882a593Smuzhiyun 			 struct kexec_elf_info *elf_info,
275*4882a593Smuzhiyun 			 struct kexec_buf *kbuf,
276*4882a593Smuzhiyun 			 unsigned long *lowest_load_addr);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun void kexec_free_elf_info(struct kexec_elf_info *elf_info);
279*4882a593Smuzhiyun int kexec_elf_probe(const char *buf, unsigned long len);
280*4882a593Smuzhiyun #endif
281*4882a593Smuzhiyun struct kimage {
282*4882a593Smuzhiyun 	kimage_entry_t head;
283*4882a593Smuzhiyun 	kimage_entry_t *entry;
284*4882a593Smuzhiyun 	kimage_entry_t *last_entry;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	unsigned long start;
287*4882a593Smuzhiyun 	struct page *control_code_page;
288*4882a593Smuzhiyun 	struct page *swap_page;
289*4882a593Smuzhiyun 	void *vmcoreinfo_data_copy; /* locates in the crash memory */
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	unsigned long nr_segments;
292*4882a593Smuzhiyun 	struct kexec_segment segment[KEXEC_SEGMENT_MAX];
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun 	struct list_head control_pages;
295*4882a593Smuzhiyun 	struct list_head dest_pages;
296*4882a593Smuzhiyun 	struct list_head unusable_pages;
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	/* Address of next control page to allocate for crash kernels. */
299*4882a593Smuzhiyun 	unsigned long control_page;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 	/* Flags to indicate special processing */
302*4882a593Smuzhiyun 	unsigned int type : 1;
303*4882a593Smuzhiyun #define KEXEC_TYPE_DEFAULT 0
304*4882a593Smuzhiyun #define KEXEC_TYPE_CRASH   1
305*4882a593Smuzhiyun 	unsigned int preserve_context : 1;
306*4882a593Smuzhiyun 	/* If set, we are using file mode kexec syscall */
307*4882a593Smuzhiyun 	unsigned int file_mode:1;
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun #ifdef ARCH_HAS_KIMAGE_ARCH
310*4882a593Smuzhiyun 	struct kimage_arch arch;
311*4882a593Smuzhiyun #endif
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_FILE
314*4882a593Smuzhiyun 	/* Additional fields for file based kexec syscall */
315*4882a593Smuzhiyun 	void *kernel_buf;
316*4882a593Smuzhiyun 	unsigned long kernel_buf_len;
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 	void *initrd_buf;
319*4882a593Smuzhiyun 	unsigned long initrd_buf_len;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	char *cmdline_buf;
322*4882a593Smuzhiyun 	unsigned long cmdline_buf_len;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	/* File operations provided by image loader */
325*4882a593Smuzhiyun 	const struct kexec_file_ops *fops;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	/* Image loader handling the kernel can store a pointer here */
328*4882a593Smuzhiyun 	void *image_loader_data;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	/* Information for loading purgatory */
331*4882a593Smuzhiyun 	struct purgatory_info purgatory_info;
332*4882a593Smuzhiyun #endif
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun #ifdef CONFIG_IMA_KEXEC
335*4882a593Smuzhiyun 	/* Virtual address of IMA measurement buffer for kexec syscall */
336*4882a593Smuzhiyun 	void *ima_buffer;
337*4882a593Smuzhiyun #endif
338*4882a593Smuzhiyun };
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun /* kexec interface functions */
341*4882a593Smuzhiyun extern void machine_kexec(struct kimage *image);
342*4882a593Smuzhiyun extern int machine_kexec_prepare(struct kimage *image);
343*4882a593Smuzhiyun extern void machine_kexec_cleanup(struct kimage *image);
344*4882a593Smuzhiyun extern int kernel_kexec(void);
345*4882a593Smuzhiyun extern struct page *kimage_alloc_control_pages(struct kimage *image,
346*4882a593Smuzhiyun 						unsigned int order);
347*4882a593Smuzhiyun extern void __crash_kexec(struct pt_regs *);
348*4882a593Smuzhiyun extern void crash_kexec(struct pt_regs *);
349*4882a593Smuzhiyun int kexec_should_crash(struct task_struct *);
350*4882a593Smuzhiyun int kexec_crash_loaded(void);
351*4882a593Smuzhiyun void crash_save_cpu(struct pt_regs *regs, int cpu);
352*4882a593Smuzhiyun extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun extern struct kimage *kexec_image;
355*4882a593Smuzhiyun extern struct kimage *kexec_crash_image;
356*4882a593Smuzhiyun extern int kexec_load_disabled;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun #ifndef kexec_flush_icache_page
359*4882a593Smuzhiyun #define kexec_flush_icache_page(page)
360*4882a593Smuzhiyun #endif
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun /* List of defined/legal kexec flags */
363*4882a593Smuzhiyun #ifndef CONFIG_KEXEC_JUMP
364*4882a593Smuzhiyun #define KEXEC_FLAGS    KEXEC_ON_CRASH
365*4882a593Smuzhiyun #else
366*4882a593Smuzhiyun #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
367*4882a593Smuzhiyun #endif
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun /* List of defined/legal kexec file flags */
370*4882a593Smuzhiyun #define KEXEC_FILE_FLAGS	(KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
371*4882a593Smuzhiyun 				 KEXEC_FILE_NO_INITRAMFS)
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun /* Location of a reserved region to hold the crash kernel.
374*4882a593Smuzhiyun  */
375*4882a593Smuzhiyun extern struct resource crashk_res;
376*4882a593Smuzhiyun extern struct resource crashk_low_res;
377*4882a593Smuzhiyun extern note_buf_t __percpu *crash_notes;
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun /* flag to track if kexec reboot is in progress */
380*4882a593Smuzhiyun extern bool kexec_in_progress;
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun int crash_shrink_memory(unsigned long new_size);
383*4882a593Smuzhiyun size_t crash_get_memory_size(void);
384*4882a593Smuzhiyun void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun void arch_kexec_protect_crashkres(void);
387*4882a593Smuzhiyun void arch_kexec_unprotect_crashkres(void);
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun #ifndef page_to_boot_pfn
page_to_boot_pfn(struct page * page)390*4882a593Smuzhiyun static inline unsigned long page_to_boot_pfn(struct page *page)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun 	return page_to_pfn(page);
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun #endif
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun #ifndef boot_pfn_to_page
boot_pfn_to_page(unsigned long boot_pfn)397*4882a593Smuzhiyun static inline struct page *boot_pfn_to_page(unsigned long boot_pfn)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun 	return pfn_to_page(boot_pfn);
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun #endif
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun #ifndef phys_to_boot_phys
phys_to_boot_phys(phys_addr_t phys)404*4882a593Smuzhiyun static inline unsigned long phys_to_boot_phys(phys_addr_t phys)
405*4882a593Smuzhiyun {
406*4882a593Smuzhiyun 	return phys;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun #endif
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun #ifndef boot_phys_to_phys
boot_phys_to_phys(unsigned long boot_phys)411*4882a593Smuzhiyun static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun 	return boot_phys;
414*4882a593Smuzhiyun }
415*4882a593Smuzhiyun #endif
416*4882a593Smuzhiyun 
virt_to_boot_phys(void * addr)417*4882a593Smuzhiyun static inline unsigned long virt_to_boot_phys(void *addr)
418*4882a593Smuzhiyun {
419*4882a593Smuzhiyun 	return phys_to_boot_phys(__pa((unsigned long)addr));
420*4882a593Smuzhiyun }
421*4882a593Smuzhiyun 
boot_phys_to_virt(unsigned long entry)422*4882a593Smuzhiyun static inline void *boot_phys_to_virt(unsigned long entry)
423*4882a593Smuzhiyun {
424*4882a593Smuzhiyun 	return phys_to_virt(boot_phys_to_phys(entry));
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun #ifndef arch_kexec_post_alloc_pages
arch_kexec_post_alloc_pages(void * vaddr,unsigned int pages,gfp_t gfp)428*4882a593Smuzhiyun static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, gfp_t gfp) { return 0; }
429*4882a593Smuzhiyun #endif
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun #ifndef arch_kexec_pre_free_pages
arch_kexec_pre_free_pages(void * vaddr,unsigned int pages)432*4882a593Smuzhiyun static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
433*4882a593Smuzhiyun #endif
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun #else /* !CONFIG_KEXEC_CORE */
436*4882a593Smuzhiyun struct pt_regs;
437*4882a593Smuzhiyun struct task_struct;
__crash_kexec(struct pt_regs * regs)438*4882a593Smuzhiyun static inline void __crash_kexec(struct pt_regs *regs) { }
crash_kexec(struct pt_regs * regs)439*4882a593Smuzhiyun static inline void crash_kexec(struct pt_regs *regs) { }
kexec_should_crash(struct task_struct * p)440*4882a593Smuzhiyun static inline int kexec_should_crash(struct task_struct *p) { return 0; }
kexec_crash_loaded(void)441*4882a593Smuzhiyun static inline int kexec_crash_loaded(void) { return 0; }
442*4882a593Smuzhiyun #define kexec_in_progress false
443*4882a593Smuzhiyun #endif /* CONFIG_KEXEC_CORE */
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun #ifdef CONFIG_KEXEC_SIG
446*4882a593Smuzhiyun void set_kexec_sig_enforced(void);
447*4882a593Smuzhiyun #else
set_kexec_sig_enforced(void)448*4882a593Smuzhiyun static inline void set_kexec_sig_enforced(void) {}
449*4882a593Smuzhiyun #endif
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun #endif /* !defined(__ASSEBMLY__) */
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun #endif /* LINUX_KEXEC_H */
454