blob: 37c5f7261142c24fa582121d2bdfd9479285f681 [file] [log] [blame]
Eric W. Biedermandc009d92005-06-25 14:57:52 -07001#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H
3
maximilian attems29a5c672012-05-31 16:26:27 -07004/* kexec system call - It loads the new kernel to boot into.
5 * kexec does not sync, or unmount filesystems so if you need
6 * that to happen you need to do that yourself.
7 */
8
Eric W. Biedermandc009d92005-06-25 14:57:52 -07009#include <linux/types.h>
maximilian attems29a5c672012-05-31 16:26:27 -070010
11/* kexec flags for different usage scenarios */
12#define KEXEC_ON_CRASH 0x00000001
13#define KEXEC_PRESERVE_CONTEXT 0x00000002
14#define KEXEC_ARCH_MASK 0xffff0000
15
16/* These values match the ELF architecture values.
17 * Unless there is a good reason that should continue to be the case.
18 */
19#define KEXEC_ARCH_DEFAULT ( 0 << 16)
20#define KEXEC_ARCH_386 ( 3 << 16)
21#define KEXEC_ARCH_X86_64 (62 << 16)
22#define KEXEC_ARCH_PPC (20 << 16)
23#define KEXEC_ARCH_PPC64 (21 << 16)
24#define KEXEC_ARCH_IA_64 (50 << 16)
25#define KEXEC_ARCH_ARM (40 << 16)
26#define KEXEC_ARCH_S390 (22 << 16)
27#define KEXEC_ARCH_SH (42 << 16)
28#define KEXEC_ARCH_MIPS_LE (10 << 16)
29#define KEXEC_ARCH_MIPS ( 8 << 16)
30
31/* The artificial cap on the number of segments passed to kexec_load. */
32#define KEXEC_SEGMENT_MAX 16
33
34#ifndef __KERNEL__
35/*
36 * This structure is used to hold the arguments that are used when
37 * loading kernel binaries.
38 */
39struct kexec_segment {
40 const void *buf;
41 size_t bufsz;
42 const void *mem;
43 size_t memsz;
44};
45
46/* Load a new kernel image as described by the kexec_segment array
47 * consisting of passed number of segments at the entry-point address.
48 * The flags allow different useage types.
49 */
50extern int kexec_load(void *, size_t, struct kexec_segment *,
51 unsigned long int);
52#endif /* __KERNEL__ */
53
54#ifdef __KERNEL__
55#ifdef CONFIG_KEXEC
Eric W. Biedermandc009d92005-06-25 14:57:52 -070056#include <linux/list.h>
57#include <linux/linkage.h>
58#include <linux/compat.h>
Haren Myneni9c15e852006-02-10 01:51:05 -080059#include <linux/ioport.h>
Simon Horman6672f762007-05-08 00:28:22 -070060#include <linux/elfcore.h>
61#include <linux/elf.h>
Eric W. Biedermandc009d92005-06-25 14:57:52 -070062#include <asm/kexec.h>
63
64/* Verify architecture specific macros are defined */
65
66#ifndef KEXEC_SOURCE_MEMORY_LIMIT
67#error KEXEC_SOURCE_MEMORY_LIMIT not defined
68#endif
69
70#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
71#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
72#endif
73
74#ifndef KEXEC_CONTROL_MEMORY_LIMIT
75#error KEXEC_CONTROL_MEMORY_LIMIT not defined
76#endif
77
Huang Ying163f6872008-08-15 00:40:22 -070078#ifndef KEXEC_CONTROL_PAGE_SIZE
79#error KEXEC_CONTROL_PAGE_SIZE not defined
Eric W. Biedermandc009d92005-06-25 14:57:52 -070080#endif
81
82#ifndef KEXEC_ARCH
83#error KEXEC_ARCH not defined
84#endif
85
Michael Holzheu3d214fa2011-10-30 15:16:36 +010086#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
87#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
88#endif
89
Michael Holzheu558df722011-10-30 15:16:43 +010090#ifndef KEXEC_CRASH_MEM_ALIGN
91#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
92#endif
93
Simon Horman6672f762007-05-08 00:28:22 -070094#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
95#define KEXEC_CORE_NOTE_NAME "CORE"
96#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
97#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
98/*
99 * The per-cpu notes area is a list of notes terminated by a "NULL"
100 * note header. For kdump, the code in vmcore.c runs in the context
101 * of the second kernel to combine them into one note.
102 */
Michael Holzheucb78edf2012-01-20 14:34:16 -0800103#ifndef KEXEC_NOTE_BYTES
Simon Horman6672f762007-05-08 00:28:22 -0700104#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
105 KEXEC_CORE_NOTE_NAME_BYTES + \
106 KEXEC_CORE_NOTE_DESC_BYTES )
Michael Holzheucb78edf2012-01-20 14:34:16 -0800107#endif
Simon Horman6672f762007-05-08 00:28:22 -0700108
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700109/*
110 * This structure is used to hold the arguments that are used when loading
111 * kernel binaries.
112 */
113
114typedef unsigned long kimage_entry_t;
115#define IND_DESTINATION 0x1
116#define IND_INDIRECTION 0x2
117#define IND_DONE 0x4
118#define IND_SOURCE 0x8
119
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700120struct kexec_segment {
121 void __user *buf;
122 size_t bufsz;
maximilian attems29a5c672012-05-31 16:26:27 -0700123 unsigned long mem;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700124 size_t memsz;
125};
126
127#ifdef CONFIG_COMPAT
128struct compat_kexec_segment {
129 compat_uptr_t buf;
130 compat_size_t bufsz;
131 compat_ulong_t mem; /* User space sees this as a (void *) ... */
132 compat_size_t memsz;
133};
134#endif
135
136struct kimage {
137 kimage_entry_t head;
138 kimage_entry_t *entry;
139 kimage_entry_t *last_entry;
140
141 unsigned long destination;
142
143 unsigned long start;
144 struct page *control_code_page;
Huang Ying3ab83522008-07-25 19:45:07 -0700145 struct page *swap_page;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700146
147 unsigned long nr_segments;
148 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
149
150 struct list_head control_pages;
151 struct list_head dest_pages;
152 struct list_head unuseable_pages;
153
154 /* Address of next control page to allocate for crash kernels. */
155 unsigned long control_page;
156
157 /* Flags to indicate special processing */
158 unsigned int type : 1;
159#define KEXEC_TYPE_DEFAULT 0
160#define KEXEC_TYPE_CRASH 1
Huang Ying3ab83522008-07-25 19:45:07 -0700161 unsigned int preserve_context : 1;
Huang Ying92be3d62008-10-31 09:48:08 +0800162
163#ifdef ARCH_HAS_KIMAGE_ARCH
164 struct kimage_arch arch;
165#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700166};
167
168
169
170/* kexec interface functions */
Huang Ying3ab83522008-07-25 19:45:07 -0700171extern void machine_kexec(struct kimage *image);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700172extern int machine_kexec_prepare(struct kimage *image);
173extern void machine_kexec_cleanup(struct kimage *image);
174extern asmlinkage long sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700175 unsigned long nr_segments,
176 struct kexec_segment __user *segments,
177 unsigned long flags);
Huang Ying3ab83522008-07-25 19:45:07 -0700178extern int kernel_kexec(void);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700179#ifdef CONFIG_COMPAT
180extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700181 unsigned long nr_segments,
182 struct compat_kexec_segment __user *segments,
183 unsigned long flags);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700184#endif
Maneesh Soni72414d32005-06-25 14:58:28 -0700185extern struct page *kimage_alloc_control_pages(struct kimage *image,
186 unsigned int order);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700187extern void crash_kexec(struct pt_regs *);
188int kexec_should_crash(struct task_struct *);
Magnus Damm85916f82006-12-06 20:40:41 -0800189void crash_save_cpu(struct pt_regs *regs, int cpu);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700190void crash_save_vmcoreinfo(void);
Michael Holzheu558df722011-10-30 15:16:43 +0100191void crash_map_reserved_pages(void);
192void crash_unmap_reserved_pages(void);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700193void arch_crash_save_vmcoreinfo(void);
Joe Perchesb9075fa2011-10-31 17:11:33 -0700194__printf(1, 2)
195void vmcoreinfo_append_str(const char *fmt, ...);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700196unsigned long paddr_vmcoreinfo_note(void);
197
Bernhard Wallec6e2bee2008-08-05 13:01:05 -0700198#define VMCOREINFO_OSRELEASE(value) \
199 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
Ken'ichi Ohmichibba1f602008-02-07 00:15:22 -0800200#define VMCOREINFO_PAGESIZE(value) \
201 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700202#define VMCOREINFO_SYMBOL(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700203 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700204#define VMCOREINFO_SIZE(name) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700205 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700206 (unsigned long)sizeof(name))
Ken'ichi Ohmichic76f8602008-02-07 00:15:20 -0800207#define VMCOREINFO_STRUCT_SIZE(name) \
208 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
209 (unsigned long)sizeof(struct name))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700210#define VMCOREINFO_OFFSET(name, field) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700211 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
Ken'ichi Ohmichi1e4f2952008-02-07 00:15:22 -0800212 (unsigned long)offsetof(struct name, field))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700213#define VMCOREINFO_LENGTH(name, value) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700214 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700215#define VMCOREINFO_NUMBER(name) \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700216 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700217#define VMCOREINFO_CONFIG(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700218 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
219
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700220extern struct kimage *kexec_image;
Jeff Moyerc330dda2006-06-23 02:05:07 -0700221extern struct kimage *kexec_crash_image;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700222
Zou Nan haia79561132006-12-07 09:51:35 -0800223#ifndef kexec_flush_icache_page
224#define kexec_flush_icache_page(page)
225#endif
226
Huang Ying3ab83522008-07-25 19:45:07 -0700227/* List of defined/legal kexec flags */
228#ifndef CONFIG_KEXEC_JUMP
229#define KEXEC_FLAGS KEXEC_ON_CRASH
230#else
231#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
232#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700233
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700234#define VMCOREINFO_BYTES (4096)
235#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
236#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
237#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
238 + VMCOREINFO_NOTE_NAME_BYTES)
239
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700240/* Location of a reserved region to hold the crash kernel.
241 */
242extern struct resource crashk_res;
Simon Horman6672f762007-05-08 00:28:22 -0700243typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
Tejun Heo43cf38e2010-02-02 14:38:57 +0900244extern note_buf_t __percpu *crash_notes;
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700245extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700246extern size_t vmcoreinfo_size;
247extern size_t vmcoreinfo_max_size;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700248
Bernhard Wallecba63c32007-10-18 23:40:58 -0700249int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
250 unsigned long long *crash_size, unsigned long long *crash_base);
Amerigo Wang06a7f712009-12-15 16:47:46 -0800251int crash_shrink_memory(unsigned long new_size);
252size_t crash_get_memory_size(void);
Anton Blanchardc0bb9e42010-08-25 10:22:58 +1000253void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
Zou Nan haia79561132006-12-07 09:51:35 -0800254
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700255#else /* !CONFIG_KEXEC */
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700256struct pt_regs;
257struct task_struct;
258static inline void crash_kexec(struct pt_regs *regs) { }
259static inline int kexec_should_crash(struct task_struct *p) { return 0; }
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700260#endif /* CONFIG_KEXEC */
maximilian attems29a5c672012-05-31 16:26:27 -0700261#endif /* __KERNEL__ */
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700262#endif /* LINUX_KEXEC_H */