4 #define IND_DESTINATION_BIT 0
5 #define IND_INDIRECTION_BIT 1
7 #define IND_SOURCE_BIT 3
9 #define IND_DESTINATION (1 << IND_DESTINATION_BIT)
10 #define IND_INDIRECTION (1 << IND_INDIRECTION_BIT)
11 #define IND_DONE (1 << IND_DONE_BIT)
12 #define IND_SOURCE (1 << IND_SOURCE_BIT)
13 #define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
15 #if !defined(__ASSEMBLY__)
19 #include <uapi/linux/kexec.h>
21 #ifdef CONFIG_KEXEC_CORE
22 #include <linux/list.h>
23 #include <linux/linkage.h>
24 #include <linux/compat.h>
25 #include <linux/ioport.h>
26 #include <linux/elfcore.h>
27 #include <linux/elf.h>
28 #include <linux/module.h>
29 #include <asm/kexec.h>
31 /* Verify architecture specific macros are defined */
33 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
34 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
37 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
38 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
41 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
42 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
45 #ifndef KEXEC_CONTROL_MEMORY_GFP
46 #define KEXEC_CONTROL_MEMORY_GFP (GFP_KERNEL | __GFP_NORETRY)
49 #ifndef KEXEC_CONTROL_PAGE_SIZE
50 #error KEXEC_CONTROL_PAGE_SIZE not defined
54 #error KEXEC_ARCH not defined
57 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
58 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
61 #ifndef KEXEC_CRASH_MEM_ALIGN
62 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
65 #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
66 #define KEXEC_CORE_NOTE_NAME "CORE"
67 #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
68 #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
70 * The per-cpu notes area is a list of notes terminated by a "NULL"
71 * note header. For kdump, the code in vmcore.c runs in the context
72 * of the second kernel to combine them into one note.
74 #ifndef KEXEC_NOTE_BYTES
75 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
76 KEXEC_CORE_NOTE_NAME_BYTES + \
77 KEXEC_CORE_NOTE_DESC_BYTES )
81 * This structure is used to hold the arguments that are used when loading
85 typedef unsigned long kimage_entry_t
;
87 struct kexec_segment
{
89 * This pointer can point to user memory if kexec_load() system
90 * call is used or will point to kernel memory if
91 * kexec_file_load() system call is used.
93 * Use ->buf when expecting to deal with user memory and use ->kbuf
94 * when expecting to deal with kernel memory.
106 struct compat_kexec_segment
{
109 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
114 #ifdef CONFIG_KEXEC_FILE
115 struct purgatory_info
{
116 /* Pointer to elf header of read only purgatory */
119 /* Pointer to purgatory sechdrs which are modifiable */
122 * Temporary buffer location where purgatory is loaded and relocated
123 * This memory can be freed post image load
127 /* Address where purgatory is finally loaded and is executed from */
128 unsigned long purgatory_load_addr
;
131 typedef int (kexec_probe_t
)(const char *kernel_buf
, unsigned long kernel_size
);
132 typedef void *(kexec_load_t
)(struct kimage
*image
, char *kernel_buf
,
133 unsigned long kernel_len
, char *initrd
,
134 unsigned long initrd_len
, char *cmdline
,
135 unsigned long cmdline_len
);
136 typedef int (kexec_cleanup_t
)(void *loader_data
);
138 #ifdef CONFIG_KEXEC_VERIFY_SIG
139 typedef int (kexec_verify_sig_t
)(const char *kernel_buf
,
140 unsigned long kernel_len
);
143 struct kexec_file_ops
{
144 kexec_probe_t
*probe
;
146 kexec_cleanup_t
*cleanup
;
147 #ifdef CONFIG_KEXEC_VERIFY_SIG
148 kexec_verify_sig_t
*verify_sig
;
153 * struct kexec_buf - parameters for finding a place for a buffer in memory
154 * @image: kexec image in which memory to search.
155 * @buffer: Contents which will be copied to the allocated memory.
156 * @bufsz: Size of @buffer.
157 * @mem: On return will have address of the buffer in memory.
158 * @memsz: Size for the buffer in memory.
159 * @buf_align: Minimum alignment needed.
160 * @buf_min: The buffer can't be placed below this address.
161 * @buf_max: The buffer can't be placed above this address.
162 * @top_down: Allocate from top of memory.
165 struct kimage
*image
;
170 unsigned long buf_align
;
171 unsigned long buf_min
;
172 unsigned long buf_max
;
176 int __weak
arch_kexec_walk_mem(struct kexec_buf
*kbuf
,
177 int (*func
)(u64
, u64
, void *));
178 extern int kexec_add_buffer(struct kexec_buf
*kbuf
);
179 int kexec_locate_mem_hole(struct kexec_buf
*kbuf
);
180 #endif /* CONFIG_KEXEC_FILE */
184 kimage_entry_t
*entry
;
185 kimage_entry_t
*last_entry
;
188 struct page
*control_code_page
;
189 struct page
*swap_page
;
191 unsigned long nr_segments
;
192 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
194 struct list_head control_pages
;
195 struct list_head dest_pages
;
196 struct list_head unusable_pages
;
198 /* Address of next control page to allocate for crash kernels. */
199 unsigned long control_page
;
201 /* Flags to indicate special processing */
202 unsigned int type
: 1;
203 #define KEXEC_TYPE_DEFAULT 0
204 #define KEXEC_TYPE_CRASH 1
205 unsigned int preserve_context
: 1;
206 /* If set, we are using file mode kexec syscall */
207 unsigned int file_mode
:1;
209 #ifdef ARCH_HAS_KIMAGE_ARCH
210 struct kimage_arch arch
;
213 #ifdef CONFIG_KEXEC_FILE
214 /* Additional fields for file based kexec syscall */
216 unsigned long kernel_buf_len
;
219 unsigned long initrd_buf_len
;
222 unsigned long cmdline_buf_len
;
224 /* File operations provided by image loader */
225 struct kexec_file_ops
*fops
;
227 /* Image loader handling the kernel can store a pointer here */
228 void *image_loader_data
;
230 /* Information for loading purgatory */
231 struct purgatory_info purgatory_info
;
235 /* kexec interface functions */
236 extern void machine_kexec(struct kimage
*image
);
237 extern int machine_kexec_prepare(struct kimage
*image
);
238 extern void machine_kexec_cleanup(struct kimage
*image
);
239 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
240 unsigned long nr_segments
,
241 struct kexec_segment __user
*segments
,
242 unsigned long flags
);
243 extern int kernel_kexec(void);
244 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
246 extern int kexec_load_purgatory(struct kimage
*image
, unsigned long min
,
247 unsigned long max
, int top_down
,
248 unsigned long *load_addr
);
249 extern int kexec_purgatory_get_set_symbol(struct kimage
*image
,
250 const char *name
, void *buf
,
251 unsigned int size
, bool get_value
);
252 extern void *kexec_purgatory_get_symbol_addr(struct kimage
*image
,
254 extern void __crash_kexec(struct pt_regs
*);
255 extern void crash_kexec(struct pt_regs
*);
256 int kexec_should_crash(struct task_struct
*);
257 int kexec_crash_loaded(void);
258 void crash_save_cpu(struct pt_regs
*regs
, int cpu
);
259 void crash_save_vmcoreinfo(void);
260 void arch_crash_save_vmcoreinfo(void);
262 void vmcoreinfo_append_str(const char *fmt
, ...);
263 phys_addr_t
paddr_vmcoreinfo_note(void);
265 #define VMCOREINFO_OSRELEASE(value) \
266 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
267 #define VMCOREINFO_PAGESIZE(value) \
268 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
269 #define VMCOREINFO_SYMBOL(name) \
270 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
271 #define VMCOREINFO_SIZE(name) \
272 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
273 (unsigned long)sizeof(name))
274 #define VMCOREINFO_STRUCT_SIZE(name) \
275 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
276 (unsigned long)sizeof(struct name))
277 #define VMCOREINFO_OFFSET(name, field) \
278 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
279 (unsigned long)offsetof(struct name, field))
280 #define VMCOREINFO_LENGTH(name, value) \
281 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
282 #define VMCOREINFO_NUMBER(name) \
283 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
284 #define VMCOREINFO_CONFIG(name) \
285 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
287 extern struct kimage
*kexec_image
;
288 extern struct kimage
*kexec_crash_image
;
289 extern int kexec_load_disabled
;
291 #ifndef kexec_flush_icache_page
292 #define kexec_flush_icache_page(page)
295 /* List of defined/legal kexec flags */
296 #ifndef CONFIG_KEXEC_JUMP
297 #define KEXEC_FLAGS KEXEC_ON_CRASH
299 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
302 /* List of defined/legal kexec file flags */
303 #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
304 KEXEC_FILE_NO_INITRAMFS)
306 #define VMCOREINFO_BYTES (4096)
307 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
308 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
309 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
310 + VMCOREINFO_NOTE_NAME_BYTES)
312 /* Location of a reserved region to hold the crash kernel.
314 extern struct resource crashk_res
;
315 extern struct resource crashk_low_res
;
316 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
317 extern note_buf_t __percpu
*crash_notes
;
318 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
319 extern size_t vmcoreinfo_size
;
320 extern size_t vmcoreinfo_max_size
;
322 /* flag to track if kexec reboot is in progress */
323 extern bool kexec_in_progress
;
325 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
326 unsigned long long *crash_size
, unsigned long long *crash_base
);
327 int parse_crashkernel_high(char *cmdline
, unsigned long long system_ram
,
328 unsigned long long *crash_size
, unsigned long long *crash_base
);
329 int parse_crashkernel_low(char *cmdline
, unsigned long long system_ram
,
330 unsigned long long *crash_size
, unsigned long long *crash_base
);
331 int crash_shrink_memory(unsigned long new_size
);
332 size_t crash_get_memory_size(void);
333 void crash_free_reserved_phys_range(unsigned long begin
, unsigned long end
);
335 int __weak
arch_kexec_kernel_image_probe(struct kimage
*image
, void *buf
,
336 unsigned long buf_len
);
337 void * __weak
arch_kexec_kernel_image_load(struct kimage
*image
);
338 int __weak
arch_kimage_file_post_load_cleanup(struct kimage
*image
);
339 int __weak
arch_kexec_kernel_verify_sig(struct kimage
*image
, void *buf
,
340 unsigned long buf_len
);
341 int __weak
arch_kexec_apply_relocations_add(const Elf_Ehdr
*ehdr
,
342 Elf_Shdr
*sechdrs
, unsigned int relsec
);
343 int __weak
arch_kexec_apply_relocations(const Elf_Ehdr
*ehdr
, Elf_Shdr
*sechdrs
,
344 unsigned int relsec
);
345 void arch_kexec_protect_crashkres(void);
346 void arch_kexec_unprotect_crashkres(void);
348 #ifndef page_to_boot_pfn
349 static inline unsigned long page_to_boot_pfn(struct page
*page
)
351 return page_to_pfn(page
);
355 #ifndef boot_pfn_to_page
356 static inline struct page
*boot_pfn_to_page(unsigned long boot_pfn
)
358 return pfn_to_page(boot_pfn
);
362 #ifndef phys_to_boot_phys
363 static inline unsigned long phys_to_boot_phys(phys_addr_t phys
)
369 #ifndef boot_phys_to_phys
370 static inline phys_addr_t
boot_phys_to_phys(unsigned long boot_phys
)
376 static inline unsigned long virt_to_boot_phys(void *addr
)
378 return phys_to_boot_phys(__pa((unsigned long)addr
));
381 static inline void *boot_phys_to_virt(unsigned long entry
)
383 return phys_to_virt(boot_phys_to_phys(entry
));
386 #else /* !CONFIG_KEXEC_CORE */
389 static inline void __crash_kexec(struct pt_regs
*regs
) { }
390 static inline void crash_kexec(struct pt_regs
*regs
) { }
391 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
392 static inline int kexec_crash_loaded(void) { return 0; }
393 #define kexec_in_progress false
394 #endif /* CONFIG_KEXEC_CORE */
396 #endif /* !defined(__ASSEBMLY__) */
398 #endif /* LINUX_KEXEC_H */