4 /* 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.
9 #include <linux/types.h>
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
16 /* These values match the ELF architecture values.
17 * Unless there is a good reason that should continue to be the case.
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)
31 /* The artificial cap on the number of segments passed to kexec_load. */
32 #define KEXEC_SEGMENT_MAX 16
36 * This structure is used to hold the arguments that are used when
37 * loading kernel binaries.
39 struct kexec_segment
{
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.
50 extern int kexec_load(void *, size_t, struct kexec_segment
*,
52 #endif /* __KERNEL__ */
56 #include <linux/list.h>
57 #include <linux/linkage.h>
58 #include <linux/compat.h>
59 #include <linux/ioport.h>
60 #include <linux/elfcore.h>
61 #include <linux/elf.h>
62 #include <asm/kexec.h>
64 /* Verify architecture specific macros are defined */
66 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
67 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
70 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
71 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
74 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
75 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
78 #ifndef KEXEC_CONTROL_PAGE_SIZE
79 #error KEXEC_CONTROL_PAGE_SIZE not defined
83 #error KEXEC_ARCH not defined
86 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
87 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
90 #ifndef KEXEC_CRASH_MEM_ALIGN
91 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
94 #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)
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.
103 #ifndef KEXEC_NOTE_BYTES
104 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
105 KEXEC_CORE_NOTE_NAME_BYTES + \
106 KEXEC_CORE_NOTE_DESC_BYTES )
110 * This structure is used to hold the arguments that are used when loading
114 typedef unsigned long kimage_entry_t
;
115 #define IND_DESTINATION 0x1
116 #define IND_INDIRECTION 0x2
118 #define IND_SOURCE 0x8
120 struct kexec_segment
{
128 struct compat_kexec_segment
{
131 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
138 kimage_entry_t
*entry
;
139 kimage_entry_t
*last_entry
;
141 unsigned long destination
;
144 struct page
*control_code_page
;
145 struct page
*swap_page
;
147 unsigned long nr_segments
;
148 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
150 struct list_head control_pages
;
151 struct list_head dest_pages
;
152 struct list_head unuseable_pages
;
154 /* Address of next control page to allocate for crash kernels. */
155 unsigned long control_page
;
157 /* Flags to indicate special processing */
158 unsigned int type
: 1;
159 #define KEXEC_TYPE_DEFAULT 0
160 #define KEXEC_TYPE_CRASH 1
161 unsigned int preserve_context
: 1;
163 #ifdef ARCH_HAS_KIMAGE_ARCH
164 struct kimage_arch arch
;
170 /* kexec interface functions */
171 extern void machine_kexec(struct kimage
*image
);
172 extern int machine_kexec_prepare(struct kimage
*image
);
173 extern void machine_kexec_cleanup(struct kimage
*image
);
174 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
175 unsigned long nr_segments
,
176 struct kexec_segment __user
*segments
,
177 unsigned long flags
);
178 extern int kernel_kexec(void);
180 extern asmlinkage
long compat_sys_kexec_load(unsigned long entry
,
181 unsigned long nr_segments
,
182 struct compat_kexec_segment __user
*segments
,
183 unsigned long flags
);
185 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
187 extern void crash_kexec(struct pt_regs
*);
188 int kexec_should_crash(struct task_struct
*);
189 void crash_save_cpu(struct pt_regs
*regs
, int cpu
);
190 void crash_save_vmcoreinfo(void);
191 void crash_map_reserved_pages(void);
192 void crash_unmap_reserved_pages(void);
193 void arch_crash_save_vmcoreinfo(void);
195 void vmcoreinfo_append_str(const char *fmt
, ...);
196 unsigned long paddr_vmcoreinfo_note(void);
198 #define VMCOREINFO_OSRELEASE(value) \
199 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
200 #define VMCOREINFO_PAGESIZE(value) \
201 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
202 #define VMCOREINFO_SYMBOL(name) \
203 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
204 #define VMCOREINFO_SIZE(name) \
205 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
206 (unsigned long)sizeof(name))
207 #define VMCOREINFO_STRUCT_SIZE(name) \
208 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
209 (unsigned long)sizeof(struct name))
210 #define VMCOREINFO_OFFSET(name, field) \
211 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
212 (unsigned long)offsetof(struct name, field))
213 #define VMCOREINFO_LENGTH(name, value) \
214 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
215 #define VMCOREINFO_NUMBER(name) \
216 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
217 #define VMCOREINFO_CONFIG(name) \
218 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
220 extern struct kimage
*kexec_image
;
221 extern struct kimage
*kexec_crash_image
;
223 #ifndef kexec_flush_icache_page
224 #define kexec_flush_icache_page(page)
227 /* List of defined/legal kexec flags */
228 #ifndef CONFIG_KEXEC_JUMP
229 #define KEXEC_FLAGS KEXEC_ON_CRASH
231 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
234 #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)
240 /* Location of a reserved region to hold the crash kernel.
242 extern struct resource crashk_res
;
243 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
244 extern note_buf_t __percpu
*crash_notes
;
245 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
246 extern size_t vmcoreinfo_size
;
247 extern size_t vmcoreinfo_max_size
;
249 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
250 unsigned long long *crash_size
, unsigned long long *crash_base
);
251 int crash_shrink_memory(unsigned long new_size
);
252 size_t crash_get_memory_size(void);
253 void crash_free_reserved_phys_range(unsigned long begin
, unsigned long end
);
255 #else /* !CONFIG_KEXEC */
258 static inline void crash_kexec(struct pt_regs
*regs
) { }
259 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
260 #endif /* CONFIG_KEXEC */
261 #endif /* __KERNEL__ */
262 #endif /* LINUX_KEXEC_H */