1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2dc009d92SEric W. Biederman #ifndef LINUX_KEXEC_H
3dc009d92SEric W. Biederman #define LINUX_KEXEC_H
4dc009d92SEric W. Biederman
5cf2df639SGeoff Levand #define IND_DESTINATION_BIT 0
6cf2df639SGeoff Levand #define IND_INDIRECTION_BIT 1
7cf2df639SGeoff Levand #define IND_DONE_BIT 2
8cf2df639SGeoff Levand #define IND_SOURCE_BIT 3
9cf2df639SGeoff Levand
10cf2df639SGeoff Levand #define IND_DESTINATION (1 << IND_DESTINATION_BIT)
11cf2df639SGeoff Levand #define IND_INDIRECTION (1 << IND_INDIRECTION_BIT)
12cf2df639SGeoff Levand #define IND_DONE (1 << IND_DONE_BIT)
13cf2df639SGeoff Levand #define IND_SOURCE (1 << IND_SOURCE_BIT)
14b28c2ee8SGeoff Levand #define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
15cf2df639SGeoff Levand
16cf2df639SGeoff Levand #if !defined(__ASSEMBLY__)
17cf2df639SGeoff Levand
18443cbaf9SBaoquan He #include <linux/vmcore_info.h>
1985fcde40SBaoquan He #include <linux/crash_reserve.h>
2043546d86SRussell King #include <asm/io.h>
21cade589fSLi Chen #include <linux/range.h>
2243546d86SRussell King
23607ca46eSDavid Howells #include <uapi/linux/kexec.h>
24c903dae8SCoiby Xu #include <linux/verification.h>
2529a5c67eSmaximilian attems
26f05fa109SJisheng Zhang extern note_buf_t __percpu *crash_notes;
27f05fa109SJisheng Zhang
282965faa5SDave Young #ifdef CONFIG_KEXEC_CORE
29dc009d92SEric W. Biederman #include <linux/list.h>
30dc009d92SEric W. Biederman #include <linux/compat.h>
319c15e852SHaren Myneni #include <linux/ioport.h>
3212db5562SVivek Goyal #include <linux/module.h>
3324726275SEric DeVolder #include <linux/highmem.h>
34dc009d92SEric W. Biederman #include <asm/kexec.h>
3502aff848SBaoquan He #include <linux/crash_core.h>
36dc009d92SEric W. Biederman
37dc009d92SEric W. Biederman /* Verify architecture specific macros are defined */
38dc009d92SEric W. Biederman
39dc009d92SEric W. Biederman #ifndef KEXEC_SOURCE_MEMORY_LIMIT
40dc009d92SEric W. Biederman #error KEXEC_SOURCE_MEMORY_LIMIT not defined
41dc009d92SEric W. Biederman #endif
42dc009d92SEric W. Biederman
43dc009d92SEric W. Biederman #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
44dc009d92SEric W. Biederman #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
45dc009d92SEric W. Biederman #endif
46dc009d92SEric W. Biederman
47dc009d92SEric W. Biederman #ifndef KEXEC_CONTROL_MEMORY_LIMIT
48dc009d92SEric W. Biederman #error KEXEC_CONTROL_MEMORY_LIMIT not defined
49dc009d92SEric W. Biederman #endif
50dc009d92SEric W. Biederman
517e01b5acSMartin Schwidefsky #ifndef KEXEC_CONTROL_MEMORY_GFP
52dc5cccacSRussell King #define KEXEC_CONTROL_MEMORY_GFP (GFP_KERNEL | __GFP_NORETRY)
537e01b5acSMartin Schwidefsky #endif
547e01b5acSMartin Schwidefsky
55163f6876SHuang Ying #ifndef KEXEC_CONTROL_PAGE_SIZE
56163f6876SHuang Ying #error KEXEC_CONTROL_PAGE_SIZE not defined
57dc009d92SEric W. Biederman #endif
58dc009d92SEric W. Biederman
59dc009d92SEric W. Biederman #ifndef KEXEC_ARCH
60dc009d92SEric W. Biederman #error KEXEC_ARCH not defined
61dc009d92SEric W. Biederman #endif
62dc009d92SEric W. Biederman
633d214faeSMichael Holzheu #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
643d214faeSMichael Holzheu #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
653d214faeSMichael Holzheu #endif
663d214faeSMichael Holzheu
67558df720SMichael Holzheu #ifndef KEXEC_CRASH_MEM_ALIGN
68558df720SMichael Holzheu #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
69558df720SMichael Holzheu #endif
70558df720SMichael Holzheu
71692f66f2SHari Bathini /*
72692f66f2SHari Bathini * This structure is used to hold the arguments that are used when loading
736672f76aSSimon Horman * kernel binaries.
74dc009d92SEric W. Biederman */
75dc009d92SEric W. Biederman
76dc009d92SEric W. Biederman typedef unsigned long kimage_entry_t;
77dc009d92SEric W. Biederman
78dc009d92SEric W. Biederman struct kexec_segment {
79dc009d92SEric W. Biederman /*
80dc009d92SEric W. Biederman * This pointer can point to user memory if kexec_load() system
81815d5704SVivek Goyal * call is used or will point to kernel memory if
82815d5704SVivek Goyal * kexec_file_load() system call is used.
83815d5704SVivek Goyal *
84815d5704SVivek Goyal * Use ->buf when expecting to deal with user memory and use ->kbuf
85815d5704SVivek Goyal * when expecting to deal with kernel memory.
86815d5704SVivek Goyal */
87815d5704SVivek Goyal union {
88815d5704SVivek Goyal void __user *buf;
89815d5704SVivek Goyal void *kbuf;
90dc009d92SEric W. Biederman };
91815d5704SVivek Goyal size_t bufsz;
92815d5704SVivek Goyal unsigned long mem;
93dc009d92SEric W. Biederman size_t memsz;
9429a5c67eSmaximilian attems };
95dc009d92SEric W. Biederman
96dc009d92SEric W. Biederman #ifdef CONFIG_COMPAT
97dc009d92SEric W. Biederman struct compat_kexec_segment {
98dc009d92SEric W. Biederman compat_uptr_t buf;
99dc009d92SEric W. Biederman compat_size_t bufsz;
100dc009d92SEric W. Biederman compat_ulong_t mem; /* User space sees this as a (void *) ... */
101dc009d92SEric W. Biederman compat_size_t memsz;
102dc009d92SEric W. Biederman };
103dc009d92SEric W. Biederman #endif
104dc009d92SEric W. Biederman
105dc009d92SEric W. Biederman #ifdef CONFIG_KEXEC_FILE
106dc009d92SEric W. Biederman struct purgatory_info {
107978e30c9SXunlei Pang /*
10812db5562SVivek Goyal * Pointer to elf header at the beginning of kexec_purgatory.
10965c225d3SPhilipp Rudo * Note: kexec_purgatory is read only
11065c225d3SPhilipp Rudo */
11165c225d3SPhilipp Rudo const Elf_Ehdr *ehdr;
11265c225d3SPhilipp Rudo /*
11365c225d3SPhilipp Rudo * Temporary, modifiable buffer for sechdrs used for relocation.
11465c225d3SPhilipp Rudo * This memory can be freed post image load.
11565c225d3SPhilipp Rudo */
11665c225d3SPhilipp Rudo Elf_Shdr *sechdrs;
11765c225d3SPhilipp Rudo /*
11812db5562SVivek Goyal * Temporary, modifiable buffer for stripped purgatory used for
11912db5562SVivek Goyal * relocation. This memory can be freed post image load.
12065c225d3SPhilipp Rudo */
12165c225d3SPhilipp Rudo void *purgatory_buf;
12212db5562SVivek Goyal };
12312db5562SVivek Goyal
12412db5562SVivek Goyal struct kimage;
12512db5562SVivek Goyal
126ee6ebedaSPhilipp Rudo typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
127ee6ebedaSPhilipp Rudo typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
128978e30c9SXunlei Pang unsigned long kernel_len, char *initrd,
129978e30c9SXunlei Pang unsigned long initrd_len, char *cmdline,
130978e30c9SXunlei Pang unsigned long cmdline_len);
131978e30c9SXunlei Pang typedef int (kexec_cleanup_t)(void *loader_data);
132978e30c9SXunlei Pang
133978e30c9SXunlei Pang #ifdef CONFIG_KEXEC_SIG
134978e30c9SXunlei Pang typedef int (kexec_verify_sig_t)(const char *kernel_buf,
13599d5cadfSJiri Bohac unsigned long kernel_len);
136978e30c9SXunlei Pang #endif
137978e30c9SXunlei Pang
138978e30c9SXunlei Pang struct kexec_file_ops {
139978e30c9SXunlei Pang kexec_probe_t *probe;
140978e30c9SXunlei Pang kexec_load_t *load;
141978e30c9SXunlei Pang kexec_cleanup_t *cleanup;
142978e30c9SXunlei Pang #ifdef CONFIG_KEXEC_SIG
143978e30c9SXunlei Pang kexec_verify_sig_t *verify_sig;
14499d5cadfSJiri Bohac #endif
145978e30c9SXunlei Pang };
146978e30c9SXunlei Pang
147978e30c9SXunlei Pang extern const struct kexec_file_ops * const kexec_file_loaders[];
14860fe3910SThiago Jung Bauermann
1499ec4ecefSAKASHI Takahiro int kexec_image_probe_default(struct kimage *image, void *buf,
1509ec4ecefSAKASHI Takahiro unsigned long buf_len);
1519ec4ecefSAKASHI Takahiro int kexec_image_post_load_cleanup_default(struct kimage *image);
1529ec4ecefSAKASHI Takahiro
15392a98a2bSAKASHI Takahiro /*
1549ec4ecefSAKASHI Takahiro * If kexec_buf.mem is set to this value, kexec_locate_mem_hole()
155b6664ba4SAKASHI Takahiro * will try to allocate free memory. Arch may overwrite it.
156b6664ba4SAKASHI Takahiro */
157b6664ba4SAKASHI Takahiro #ifndef KEXEC_BUF_MEM_UNKNOWN
158b6664ba4SAKASHI Takahiro #define KEXEC_BUF_MEM_UNKNOWN 0
159b6664ba4SAKASHI Takahiro #endif
160b6664ba4SAKASHI Takahiro
161b6664ba4SAKASHI Takahiro /**
162b6664ba4SAKASHI Takahiro * struct kexec_buf - parameters for finding a place for a buffer in memory
16360fe3910SThiago Jung Bauermann * @image: kexec image in which memory to search.
16460fe3910SThiago Jung Bauermann * @buffer: Contents which will be copied to the allocated memory.
16560fe3910SThiago Jung Bauermann * @bufsz: Size of @buffer.
16660fe3910SThiago Jung Bauermann * @mem: On return will have address of the buffer in memory.
16760fe3910SThiago Jung Bauermann * @memsz: Size for the buffer in memory.
16860fe3910SThiago Jung Bauermann * @buf_align: Minimum alignment needed.
16960fe3910SThiago Jung Bauermann * @buf_min: The buffer can't be placed below this address.
17060fe3910SThiago Jung Bauermann * @buf_max: The buffer can't be placed above this address.
17160fe3910SThiago Jung Bauermann * @top_down: Allocate from top of memory.
17260fe3910SThiago Jung Bauermann */
17360fe3910SThiago Jung Bauermann struct kexec_buf {
17460fe3910SThiago Jung Bauermann struct kimage *image;
17560fe3910SThiago Jung Bauermann void *buffer;
17660fe3910SThiago Jung Bauermann unsigned long bufsz;
177ec2b9bfaSThiago Jung Bauermann unsigned long mem;
17860fe3910SThiago Jung Bauermann unsigned long memsz;
17960fe3910SThiago Jung Bauermann unsigned long buf_align;
18060fe3910SThiago Jung Bauermann unsigned long buf_min;
18160fe3910SThiago Jung Bauermann unsigned long buf_max;
18260fe3910SThiago Jung Bauermann bool top_down;
18360fe3910SThiago Jung Bauermann };
18460fe3910SThiago Jung Bauermann
18560fe3910SThiago Jung Bauermann int kexec_load_purgatory(struct kimage *image, struct kexec_buf *kbuf);
18660fe3910SThiago Jung Bauermann int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
1873be3f61dSPhilipp Rudo void *buf, unsigned int size,
1883be3f61dSPhilipp Rudo bool get_value);
1893be3f61dSPhilipp Rudo void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
1903be3f61dSPhilipp Rudo
1913be3f61dSPhilipp Rudo #ifndef arch_kexec_kernel_image_probe
1923be3f61dSPhilipp Rudo static inline int
arch_kexec_kernel_image_probe(struct kimage * image,void * buf,unsigned long buf_len)19365d9a9a6SNaveen N. Rao arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len)
19465d9a9a6SNaveen N. Rao {
19565d9a9a6SNaveen N. Rao return kexec_image_probe_default(image, buf, buf_len);
19665d9a9a6SNaveen N. Rao }
19765d9a9a6SNaveen N. Rao #endif
19865d9a9a6SNaveen N. Rao
19965d9a9a6SNaveen N. Rao #ifndef arch_kimage_file_post_load_cleanup
arch_kimage_file_post_load_cleanup(struct kimage * image)20065d9a9a6SNaveen N. Rao static inline int arch_kimage_file_post_load_cleanup(struct kimage *image)
20165d9a9a6SNaveen N. Rao {
20265d9a9a6SNaveen N. Rao return kexec_image_post_load_cleanup_default(image);
20365d9a9a6SNaveen N. Rao }
20465d9a9a6SNaveen N. Rao #endif
20565d9a9a6SNaveen N. Rao
20665d9a9a6SNaveen N. Rao #ifndef arch_check_excluded_range
arch_check_excluded_range(struct kimage * image,unsigned long start,unsigned long end)20765d9a9a6SNaveen N. Rao static inline int arch_check_excluded_range(struct kimage *image,
208*9f0552c9SSourabh Jain unsigned long start,
209*9f0552c9SSourabh Jain unsigned long end)
210*9f0552c9SSourabh Jain {
211*9f0552c9SSourabh Jain return 0;
212*9f0552c9SSourabh Jain }
213*9f0552c9SSourabh Jain #endif
214*9f0552c9SSourabh Jain
215*9f0552c9SSourabh Jain #ifdef CONFIG_KEXEC_SIG
216*9f0552c9SSourabh Jain #ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION
217c903dae8SCoiby Xu int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len);
218c903dae8SCoiby Xu #endif
219c903dae8SCoiby Xu #endif
220c903dae8SCoiby Xu
221c903dae8SCoiby Xu extern int kexec_add_buffer(struct kexec_buf *kbuf);
222c903dae8SCoiby Xu int kexec_locate_mem_hole(struct kexec_buf *kbuf);
223ec2b9bfaSThiago Jung Bauermann
224e2e806f9SThiago Jung Bauermann #ifndef arch_kexec_locate_mem_hole
225babac4a8SAKASHI Takahiro /**
22665d9a9a6SNaveen N. Rao * arch_kexec_locate_mem_hole - Find free memory to place the segments.
22765d9a9a6SNaveen N. Rao * @kbuf: Parameters for the memory search.
22865d9a9a6SNaveen N. Rao *
22965d9a9a6SNaveen N. Rao * On success, kbuf->mem will have the start address of the memory region found.
23065d9a9a6SNaveen N. Rao *
23165d9a9a6SNaveen N. Rao * Return: 0 on success, negative errno on error.
23265d9a9a6SNaveen N. Rao */
arch_kexec_locate_mem_hole(struct kexec_buf * kbuf)23365d9a9a6SNaveen N. Rao static inline int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
23465d9a9a6SNaveen N. Rao {
23565d9a9a6SNaveen N. Rao return kexec_locate_mem_hole(kbuf);
23665d9a9a6SNaveen N. Rao }
23765d9a9a6SNaveen N. Rao #endif
23865d9a9a6SNaveen N. Rao
23965d9a9a6SNaveen N. Rao #ifndef arch_kexec_apply_relocations_add
24065d9a9a6SNaveen N. Rao /*
2413e35142eSNaveen N. Rao * arch_kexec_apply_relocations_add - apply relocations of type RELA
2423e35142eSNaveen N. Rao * @pi: Purgatory to be relocated.
2433e35142eSNaveen N. Rao * @section: Section relocations applying to.
2443e35142eSNaveen N. Rao * @relsec: Section containing RELAs.
2453e35142eSNaveen N. Rao * @symtab: Corresponding symtab.
2463e35142eSNaveen N. Rao *
2473e35142eSNaveen N. Rao * Return: 0 on success, negative errno on error.
2483e35142eSNaveen N. Rao */
2493e35142eSNaveen N. Rao static inline int
arch_kexec_apply_relocations_add(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)2503e35142eSNaveen N. Rao arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
2513e35142eSNaveen N. Rao const Elf_Shdr *relsec, const Elf_Shdr *symtab)
2523e35142eSNaveen N. Rao {
2533e35142eSNaveen N. Rao pr_err("RELA relocation unsupported.\n");
2543e35142eSNaveen N. Rao return -ENOEXEC;
2553e35142eSNaveen N. Rao }
2563e35142eSNaveen N. Rao #endif
2573e35142eSNaveen N. Rao
2583e35142eSNaveen N. Rao #ifndef arch_kexec_apply_relocations
2593e35142eSNaveen N. Rao /*
2603e35142eSNaveen N. Rao * arch_kexec_apply_relocations - apply relocations of type REL
2613e35142eSNaveen N. Rao * @pi: Purgatory to be relocated.
2623e35142eSNaveen N. Rao * @section: Section relocations applying to.
2633e35142eSNaveen N. Rao * @relsec: Section containing RELs.
2643e35142eSNaveen N. Rao * @symtab: Corresponding symtab.
2653e35142eSNaveen N. Rao *
2663e35142eSNaveen N. Rao * Return: 0 on success, negative errno on error.
2673e35142eSNaveen N. Rao */
2683e35142eSNaveen N. Rao static inline int
arch_kexec_apply_relocations(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)2693e35142eSNaveen N. Rao arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
2703e35142eSNaveen N. Rao const Elf_Shdr *relsec, const Elf_Shdr *symtab)
2713e35142eSNaveen N. Rao {
2723e35142eSNaveen N. Rao pr_err("REL relocation unsupported.\n");
2733e35142eSNaveen N. Rao return -ENOEXEC;
2743e35142eSNaveen N. Rao }
2753e35142eSNaveen N. Rao #endif
2763e35142eSNaveen N. Rao #endif /* CONFIG_KEXEC_FILE */
2773e35142eSNaveen N. Rao
27860fe3910SThiago Jung Bauermann #ifdef CONFIG_KEXEC_ELF
279978e30c9SXunlei Pang struct kexec_elf_info {
280175fca3bSSven Schnelle /*
281175fca3bSSven Schnelle * Where the ELF binary contents are kept.
282175fca3bSSven Schnelle * Memory managed by the user of the struct.
283175fca3bSSven Schnelle */
284175fca3bSSven Schnelle const char *buffer;
285175fca3bSSven Schnelle
286175fca3bSSven Schnelle const struct elfhdr *ehdr;
287175fca3bSSven Schnelle const struct elf_phdr *proghdrs;
288175fca3bSSven Schnelle };
289175fca3bSSven Schnelle
290175fca3bSSven Schnelle int kexec_build_elf_info(const char *buf, size_t len, struct elfhdr *ehdr,
291175fca3bSSven Schnelle struct kexec_elf_info *elf_info);
292175fca3bSSven Schnelle
293175fca3bSSven Schnelle int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
294175fca3bSSven Schnelle struct kexec_elf_info *elf_info,
295175fca3bSSven Schnelle struct kexec_buf *kbuf,
296175fca3bSSven Schnelle unsigned long *lowest_load_addr);
297175fca3bSSven Schnelle
298175fca3bSSven Schnelle void kexec_free_elf_info(struct kexec_elf_info *elf_info);
299175fca3bSSven Schnelle int kexec_elf_probe(const char *buf, unsigned long len);
300175fca3bSSven Schnelle #endif
301175fca3bSSven Schnelle struct kimage {
302175fca3bSSven Schnelle kimage_entry_t head;
303dc009d92SEric W. Biederman kimage_entry_t *entry;
304dc009d92SEric W. Biederman kimage_entry_t *last_entry;
305dc009d92SEric W. Biederman
306dc009d92SEric W. Biederman unsigned long start;
307dc009d92SEric W. Biederman struct page *control_code_page;
308dc009d92SEric W. Biederman struct page *swap_page;
309dc009d92SEric W. Biederman void *vmcoreinfo_data_copy; /* locates in the crash memory */
3103ab83521SHuang Ying
3111229384fSXunlei Pang unsigned long nr_segments;
312dc009d92SEric W. Biederman struct kexec_segment segment[KEXEC_SEGMENT_MAX];
313dc009d92SEric W. Biederman
314dc009d92SEric W. Biederman struct list_head control_pages;
315dc009d92SEric W. Biederman struct list_head dest_pages;
316dc009d92SEric W. Biederman struct list_head unusable_pages;
317dc009d92SEric W. Biederman
3187d3e2bcaSVivek Goyal /* Address of next control page to allocate for crash kernels. */
319dc009d92SEric W. Biederman unsigned long control_page;
320dc009d92SEric W. Biederman
321dc009d92SEric W. Biederman /* Flags to indicate special processing */
322dc009d92SEric W. Biederman unsigned int type : 1;
323dc009d92SEric W. Biederman #define KEXEC_TYPE_DEFAULT 0
324dc009d92SEric W. Biederman #define KEXEC_TYPE_CRASH 1
325dc009d92SEric W. Biederman unsigned int preserve_context : 1;
326dc009d92SEric W. Biederman /* If set, we are using file mode kexec syscall */
3273ab83521SHuang Ying unsigned int file_mode:1;
328cb105258SVivek Goyal #ifdef CONFIG_CRASH_HOTPLUG
329cb105258SVivek Goyal /* If set, it is safe to update kexec segments that are
330a72bbec7SEric DeVolder * excluded from SHA calculation.
33179365026SSourabh Jain */
33279365026SSourabh Jain unsigned int hotplug_support:1;
33379365026SSourabh Jain #endif
33479365026SSourabh Jain
335a72bbec7SEric DeVolder #ifdef ARCH_HAS_KIMAGE_ARCH
33692be3d6bSHuang Ying struct kimage_arch arch;
33792be3d6bSHuang Ying #endif
33892be3d6bSHuang Ying
33992be3d6bSHuang Ying #ifdef CONFIG_KEXEC_FILE
340cb105258SVivek Goyal /* Additional fields for file based kexec syscall */
341978e30c9SXunlei Pang void *kernel_buf;
342cb105258SVivek Goyal unsigned long kernel_buf_len;
343cb105258SVivek Goyal
344cb105258SVivek Goyal void *initrd_buf;
345cb105258SVivek Goyal unsigned long initrd_buf_len;
346cb105258SVivek Goyal
347cb105258SVivek Goyal char *cmdline_buf;
348cb105258SVivek Goyal unsigned long cmdline_buf_len;
349cb105258SVivek Goyal
350cb105258SVivek Goyal /* File operations provided by image loader */
351cb105258SVivek Goyal const struct kexec_file_ops *fops;
352cb105258SVivek Goyal
3539ec4ecefSAKASHI Takahiro /* Image loader handling the kernel can store a pointer here */
354cb105258SVivek Goyal void *image_loader_data;
355cb105258SVivek Goyal
356cb105258SVivek Goyal /* Information for loading purgatory */
35712db5562SVivek Goyal struct purgatory_info purgatory_info;
35812db5562SVivek Goyal #endif
35912db5562SVivek Goyal
360978e30c9SXunlei Pang #ifdef CONFIG_CRASH_HOTPLUG
361f31e3386SLakshmi Ramasubramanian int hp_action;
36224726275SEric DeVolder int elfcorehdr_index;
36324726275SEric DeVolder bool elfcorehdr_updated;
36424726275SEric DeVolder #endif
36524726275SEric DeVolder
36624726275SEric DeVolder #ifdef CONFIG_IMA_KEXEC
36724726275SEric DeVolder /* Virtual address of IMA measurement buffer for kexec syscall */
368f31e3386SLakshmi Ramasubramanian void *ima_buffer;
369f31e3386SLakshmi Ramasubramanian
370f31e3386SLakshmi Ramasubramanian phys_addr_t ima_buffer_addr;
3710c605158SLakshmi Ramasubramanian size_t ima_buffer_size;
3720c605158SLakshmi Ramasubramanian #endif
3730c605158SLakshmi Ramasubramanian
374f31e3386SLakshmi Ramasubramanian /* Core ELF header buffer */
3759336a5f6SLakshmi Ramasubramanian void *elf_headers;
3769336a5f6SLakshmi Ramasubramanian unsigned long elf_headers_sz;
3779336a5f6SLakshmi Ramasubramanian unsigned long elf_load_addr;
3789336a5f6SLakshmi Ramasubramanian };
3799336a5f6SLakshmi Ramasubramanian
380cb105258SVivek Goyal /* kexec interface functions */
381dc009d92SEric W. Biederman extern void machine_kexec(struct kimage *image);
382dc009d92SEric W. Biederman extern int machine_kexec_prepare(struct kimage *image);
3833ab83521SHuang Ying extern void machine_kexec_cleanup(struct kimage *image);
384dc009d92SEric W. Biederman extern int kernel_kexec(void);
385dc009d92SEric W. Biederman extern struct page *kimage_alloc_control_pages(struct kimage *image,
3863ab83521SHuang Ying unsigned int order);
38772414d3fSManeesh Soni
38872414d3fSManeesh Soni #ifndef machine_kexec_post_load
machine_kexec_post_load(struct kimage * image)3890738ecebSNaveen N. Rao static inline int machine_kexec_post_load(struct kimage *image) { return 0; }
3900738ecebSNaveen N. Rao #endif
3910738ecebSNaveen N. Rao
3920738ecebSNaveen N. Rao extern struct kimage *kexec_image;
3932596b6aeSPavel Tatashin extern struct kimage *kexec_crash_image;
394dc009d92SEric W. Biederman
395c330dda9SJeff Moyer bool kexec_load_permitted(int kexec_image_type);
3967e99f8b6SRicardo Ribalda
397a42aaad2SRicardo Ribalda #ifndef kexec_flush_icache_page
398dc009d92SEric W. Biederman #define kexec_flush_icache_page(page)
399a7956113SZou Nan hai #endif
400a7956113SZou Nan hai
401a7956113SZou Nan hai /* List of defined/legal kexec flags */
402a7956113SZou Nan hai #ifndef CONFIG_KEXEC_JUMP
4033ab83521SHuang Ying #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
4043ab83521SHuang Ying #else
40579365026SSourabh Jain #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
4063ab83521SHuang Ying KEXEC_CRASH_HOTPLUG_SUPPORT)
40779365026SSourabh Jain #endif
40879365026SSourabh Jain
4093ab83521SHuang Ying /* List of defined/legal kexec file flags */
410dc009d92SEric W. Biederman #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
411cb105258SVivek Goyal KEXEC_FILE_NO_INITRAMFS | KEXEC_FILE_DEBUG)
412cb105258SVivek Goyal
413cbc2fe9dSBaoquan He /* flag to track if kexec reboot is in progress */
414cb105258SVivek Goyal extern bool kexec_in_progress;
4154fc9bbf9SKhalid Aziz
4164fc9bbf9SKhalid Aziz #ifndef page_to_boot_pfn
page_to_boot_pfn(struct page * page)4174fc9bbf9SKhalid Aziz static inline unsigned long page_to_boot_pfn(struct page *page)
41843546d86SRussell King {
41943546d86SRussell King return page_to_pfn(page);
42043546d86SRussell King }
42143546d86SRussell King #endif
42243546d86SRussell King
42343546d86SRussell King #ifndef boot_pfn_to_page
boot_pfn_to_page(unsigned long boot_pfn)42443546d86SRussell King static inline struct page *boot_pfn_to_page(unsigned long boot_pfn)
42543546d86SRussell King {
42643546d86SRussell King return pfn_to_page(boot_pfn);
42743546d86SRussell King }
42843546d86SRussell King #endif
42943546d86SRussell King
43043546d86SRussell King #ifndef phys_to_boot_phys
phys_to_boot_phys(phys_addr_t phys)43143546d86SRussell King static inline unsigned long phys_to_boot_phys(phys_addr_t phys)
43243546d86SRussell King {
43343546d86SRussell King return phys;
43443546d86SRussell King }
43543546d86SRussell King #endif
43643546d86SRussell King
43743546d86SRussell King #ifndef boot_phys_to_phys
boot_phys_to_phys(unsigned long boot_phys)43843546d86SRussell King static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)
43943546d86SRussell King {
44043546d86SRussell King return boot_phys;
44143546d86SRussell King }
44243546d86SRussell King #endif
44343546d86SRussell King
44443546d86SRussell King #ifndef crash_free_reserved_phys_range
crash_free_reserved_phys_range(unsigned long begin,unsigned long end)44543546d86SRussell King static inline void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
4460738ecebSNaveen N. Rao {
4470738ecebSNaveen N. Rao unsigned long addr;
4480738ecebSNaveen N. Rao
4490738ecebSNaveen N. Rao for (addr = begin; addr < end; addr += PAGE_SIZE)
4500738ecebSNaveen N. Rao free_reserved_page(boot_pfn_to_page(addr >> PAGE_SHIFT));
4510738ecebSNaveen N. Rao }
4520738ecebSNaveen N. Rao #endif
4530738ecebSNaveen N. Rao
virt_to_boot_phys(void * addr)4540738ecebSNaveen N. Rao static inline unsigned long virt_to_boot_phys(void *addr)
4550738ecebSNaveen N. Rao {
45643546d86SRussell King return phys_to_boot_phys(__pa((unsigned long)addr));
45743546d86SRussell King }
45843546d86SRussell King
boot_phys_to_virt(unsigned long entry)45943546d86SRussell King static inline void *boot_phys_to_virt(unsigned long entry)
46043546d86SRussell King {
46143546d86SRussell King return phys_to_virt(boot_phys_to_phys(entry));
46243546d86SRussell King }
46343546d86SRussell King
46443546d86SRussell King #ifndef arch_kexec_post_alloc_pages
arch_kexec_post_alloc_pages(void * vaddr,unsigned int pages,gfp_t gfp)46543546d86SRussell King static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, gfp_t gfp) { return 0; }
466bba4ed01STom Lendacky #endif
467bba4ed01STom Lendacky
468bba4ed01STom Lendacky #ifndef arch_kexec_pre_free_pages
arch_kexec_pre_free_pages(void * vaddr,unsigned int pages)469bba4ed01STom Lendacky static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
470bba4ed01STom Lendacky #endif
471bba4ed01STom Lendacky
472bba4ed01STom Lendacky extern bool kexec_file_dbg_print;
473bba4ed01STom Lendacky
474cbc2fe9dSBaoquan He #define kexec_dprintk(fmt, arg...) \
475cbc2fe9dSBaoquan He do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
476f4af41bfSBaoquan He
477f4af41bfSBaoquan He #else /* !CONFIG_KEXEC_CORE */
478cbc2fe9dSBaoquan He struct pt_regs;
4792965faa5SDave Young struct task_struct;
__crash_kexec(struct pt_regs * regs)4806e274d14SAlexander Nyberg static inline void __crash_kexec(struct pt_regs *regs) { }
crash_kexec(struct pt_regs * regs)4816e274d14SAlexander Nyberg static inline void crash_kexec(struct pt_regs *regs) { }
kexec_should_crash(struct task_struct * p)4827bbee5caSHidehiro Kawai static inline int kexec_should_crash(struct task_struct *p) { return 0; }
kexec_crash_loaded(void)4836e274d14SAlexander Nyberg static inline int kexec_crash_loaded(void) { return 0; }
4846e274d14SAlexander Nyberg #define kexec_in_progress false
48521db79e8SPetr Tesarik #endif /* CONFIG_KEXEC_CORE */
4862b94ed24SVitaly Kuznetsov
4872965faa5SDave Young #ifdef CONFIG_KEXEC_SIG
488cf2df639SGeoff Levand void set_kexec_sig_enforced(void);
489af16df54SCoiby Xu #else
set_kexec_sig_enforced(void)490af16df54SCoiby Xu static inline void set_kexec_sig_enforced(void) {}
491af16df54SCoiby Xu #endif
492af16df54SCoiby Xu
493af16df54SCoiby Xu #endif /* !defined(__ASSEBMLY__) */
494af16df54SCoiby Xu
495cf2df639SGeoff Levand #endif /* LINUX_KEXEC_H */
496cf2df639SGeoff Levand