blob: d78d28a733b15afdc25a620ca5925f6619f82a2c [file] [log] [blame]
Eric W. Biedermandc009d92005-06-25 14:57:52 -07001#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H
3
David Howells607ca462012-10-13 10:46:48 +01004#include <uapi/linux/kexec.h>
maximilian attems29a5c672012-05-31 16:26:27 -07005
maximilian attems29a5c672012-05-31 16:26:27 -07006#ifdef CONFIG_KEXEC
Eric W. Biedermandc009d92005-06-25 14:57:52 -07007#include <linux/list.h>
8#include <linux/linkage.h>
9#include <linux/compat.h>
Haren Myneni9c15e852006-02-10 01:51:05 -080010#include <linux/ioport.h>
Simon Horman6672f762007-05-08 00:28:22 -070011#include <linux/elfcore.h>
12#include <linux/elf.h>
Eric W. Biedermandc009d92005-06-25 14:57:52 -070013#include <asm/kexec.h>
14
15/* Verify architecture specific macros are defined */
16
17#ifndef KEXEC_SOURCE_MEMORY_LIMIT
18#error KEXEC_SOURCE_MEMORY_LIMIT not defined
19#endif
20
21#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
22#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
23#endif
24
25#ifndef KEXEC_CONTROL_MEMORY_LIMIT
26#error KEXEC_CONTROL_MEMORY_LIMIT not defined
27#endif
28
Huang Ying163f6872008-08-15 00:40:22 -070029#ifndef KEXEC_CONTROL_PAGE_SIZE
30#error KEXEC_CONTROL_PAGE_SIZE not defined
Eric W. Biedermandc009d92005-06-25 14:57:52 -070031#endif
32
33#ifndef KEXEC_ARCH
34#error KEXEC_ARCH not defined
35#endif
36
Michael Holzheu3d214fa2011-10-30 15:16:36 +010037#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
38#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
39#endif
40
Michael Holzheu558df722011-10-30 15:16:43 +010041#ifndef KEXEC_CRASH_MEM_ALIGN
42#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
43#endif
44
Simon Horman6672f762007-05-08 00:28:22 -070045#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
46#define KEXEC_CORE_NOTE_NAME "CORE"
47#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
48#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
49/*
50 * The per-cpu notes area is a list of notes terminated by a "NULL"
51 * note header. For kdump, the code in vmcore.c runs in the context
52 * of the second kernel to combine them into one note.
53 */
Michael Holzheucb78edf2012-01-20 14:34:16 -080054#ifndef KEXEC_NOTE_BYTES
Simon Horman6672f762007-05-08 00:28:22 -070055#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
56 KEXEC_CORE_NOTE_NAME_BYTES + \
57 KEXEC_CORE_NOTE_DESC_BYTES )
Michael Holzheucb78edf2012-01-20 14:34:16 -080058#endif
Simon Horman6672f762007-05-08 00:28:22 -070059
Eric W. Biedermandc009d92005-06-25 14:57:52 -070060/*
61 * This structure is used to hold the arguments that are used when loading
62 * kernel binaries.
63 */
64
65typedef unsigned long kimage_entry_t;
66#define IND_DESTINATION 0x1
67#define IND_INDIRECTION 0x2
68#define IND_DONE 0x4
69#define IND_SOURCE 0x8
70
Eric W. Biedermandc009d92005-06-25 14:57:52 -070071struct kexec_segment {
72 void __user *buf;
73 size_t bufsz;
maximilian attems29a5c672012-05-31 16:26:27 -070074 unsigned long mem;
Eric W. Biedermandc009d92005-06-25 14:57:52 -070075 size_t memsz;
76};
77
78#ifdef CONFIG_COMPAT
79struct compat_kexec_segment {
80 compat_uptr_t buf;
81 compat_size_t bufsz;
82 compat_ulong_t mem; /* User space sees this as a (void *) ... */
83 compat_size_t memsz;
84};
85#endif
86
87struct kimage {
88 kimage_entry_t head;
89 kimage_entry_t *entry;
90 kimage_entry_t *last_entry;
91
92 unsigned long destination;
93
94 unsigned long start;
95 struct page *control_code_page;
Huang Ying3ab83522008-07-25 19:45:07 -070096 struct page *swap_page;
Eric W. Biedermandc009d92005-06-25 14:57:52 -070097
98 unsigned long nr_segments;
99 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
100
101 struct list_head control_pages;
102 struct list_head dest_pages;
103 struct list_head unuseable_pages;
104
105 /* Address of next control page to allocate for crash kernels. */
106 unsigned long control_page;
107
108 /* Flags to indicate special processing */
109 unsigned int type : 1;
110#define KEXEC_TYPE_DEFAULT 0
111#define KEXEC_TYPE_CRASH 1
Huang Ying3ab83522008-07-25 19:45:07 -0700112 unsigned int preserve_context : 1;
Huang Ying92be3d62008-10-31 09:48:08 +0800113
114#ifdef ARCH_HAS_KIMAGE_ARCH
115 struct kimage_arch arch;
116#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700117};
118
119
120
121/* kexec interface functions */
Huang Ying3ab83522008-07-25 19:45:07 -0700122extern void machine_kexec(struct kimage *image);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700123extern int machine_kexec_prepare(struct kimage *image);
124extern void machine_kexec_cleanup(struct kimage *image);
125extern asmlinkage long sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700126 unsigned long nr_segments,
127 struct kexec_segment __user *segments,
128 unsigned long flags);
Huang Ying3ab83522008-07-25 19:45:07 -0700129extern int kernel_kexec(void);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700130#ifdef CONFIG_COMPAT
131extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700132 unsigned long nr_segments,
133 struct compat_kexec_segment __user *segments,
134 unsigned long flags);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700135#endif
Maneesh Soni72414d32005-06-25 14:58:28 -0700136extern struct page *kimage_alloc_control_pages(struct kimage *image,
137 unsigned int order);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700138extern void crash_kexec(struct pt_regs *);
139int kexec_should_crash(struct task_struct *);
Magnus Damm85916f82006-12-06 20:40:41 -0800140void crash_save_cpu(struct pt_regs *regs, int cpu);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700141void crash_save_vmcoreinfo(void);
Michael Holzheu558df722011-10-30 15:16:43 +0100142void crash_map_reserved_pages(void);
143void crash_unmap_reserved_pages(void);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700144void arch_crash_save_vmcoreinfo(void);
Joe Perchesb9075fa2011-10-31 17:11:33 -0700145__printf(1, 2)
146void vmcoreinfo_append_str(const char *fmt, ...);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700147unsigned long paddr_vmcoreinfo_note(void);
148
Bernhard Wallec6e2bee2008-08-05 13:01:05 -0700149#define VMCOREINFO_OSRELEASE(value) \
150 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
Ken'ichi Ohmichibba1f602008-02-07 00:15:22 -0800151#define VMCOREINFO_PAGESIZE(value) \
152 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700153#define VMCOREINFO_SYMBOL(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700154 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700155#define VMCOREINFO_SIZE(name) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700156 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700157 (unsigned long)sizeof(name))
Ken'ichi Ohmichic76f8602008-02-07 00:15:20 -0800158#define VMCOREINFO_STRUCT_SIZE(name) \
159 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
160 (unsigned long)sizeof(struct name))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700161#define VMCOREINFO_OFFSET(name, field) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700162 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
Ken'ichi Ohmichi1e4f2952008-02-07 00:15:22 -0800163 (unsigned long)offsetof(struct name, field))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700164#define VMCOREINFO_LENGTH(name, value) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700165 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700166#define VMCOREINFO_NUMBER(name) \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700167 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700168#define VMCOREINFO_CONFIG(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700169 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
170
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700171extern struct kimage *kexec_image;
Jeff Moyerc330dda2006-06-23 02:05:07 -0700172extern struct kimage *kexec_crash_image;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700173
Zou Nan haia79561132006-12-07 09:51:35 -0800174#ifndef kexec_flush_icache_page
175#define kexec_flush_icache_page(page)
176#endif
177
Huang Ying3ab83522008-07-25 19:45:07 -0700178/* List of defined/legal kexec flags */
179#ifndef CONFIG_KEXEC_JUMP
180#define KEXEC_FLAGS KEXEC_ON_CRASH
181#else
182#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
183#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700184
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700185#define VMCOREINFO_BYTES (4096)
186#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
187#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
188#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
189 + VMCOREINFO_NOTE_NAME_BYTES)
190
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700191/* Location of a reserved region to hold the crash kernel.
192 */
193extern struct resource crashk_res;
Yinghai Lu0212f912013-01-24 12:20:11 -0800194extern struct resource crashk_low_res;
Simon Horman6672f762007-05-08 00:28:22 -0700195typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
Tejun Heo43cf38e2010-02-02 14:38:57 +0900196extern note_buf_t __percpu *crash_notes;
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700197extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700198extern size_t vmcoreinfo_size;
199extern size_t vmcoreinfo_max_size;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700200
Bernhard Wallecba63c32007-10-18 23:40:58 -0700201int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
202 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu55a20ee2013-04-15 22:23:47 -0700203int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
204 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu0212f912013-01-24 12:20:11 -0800205int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
206 unsigned long long *crash_size, unsigned long long *crash_base);
Amerigo Wang06a7f712009-12-15 16:47:46 -0800207int crash_shrink_memory(unsigned long new_size);
208size_t crash_get_memory_size(void);
Anton Blanchardc0bb9e42010-08-25 10:22:58 +1000209void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
Zou Nan haia79561132006-12-07 09:51:35 -0800210
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700211#else /* !CONFIG_KEXEC */
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700212struct pt_regs;
213struct task_struct;
214static inline void crash_kexec(struct pt_regs *regs) { }
215static inline int kexec_should_crash(struct task_struct *p) { return 0; }
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700216#endif /* CONFIG_KEXEC */
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700217#endif /* LINUX_KEXEC_H */