]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/kexec.h
kexec: implementation of new syscall kexec_file_load
[karo-tx-linux.git] / include / linux / kexec.h
1 #ifndef LINUX_KEXEC_H
2 #define LINUX_KEXEC_H
3
4 #include <uapi/linux/kexec.h>
5
6 #ifdef CONFIG_KEXEC
7 #include <linux/list.h>
8 #include <linux/linkage.h>
9 #include <linux/compat.h>
10 #include <linux/ioport.h>
11 #include <linux/elfcore.h>
12 #include <linux/elf.h>
13 #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
29 #ifndef KEXEC_CONTROL_PAGE_SIZE
30 #error KEXEC_CONTROL_PAGE_SIZE not defined
31 #endif
32
33 #ifndef KEXEC_ARCH
34 #error KEXEC_ARCH not defined
35 #endif
36
37 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
38 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
39 #endif
40
41 #ifndef KEXEC_CRASH_MEM_ALIGN
42 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
43 #endif
44
45 #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  */
54 #ifndef KEXEC_NOTE_BYTES
55 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) +                \
56                             KEXEC_CORE_NOTE_NAME_BYTES +                \
57                             KEXEC_CORE_NOTE_DESC_BYTES )
58 #endif
59
60 /*
61  * This structure is used to hold the arguments that are used when loading
62  * kernel binaries.
63  */
64
65 typedef 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
71 struct kexec_segment {
72         /*
73          * This pointer can point to user memory if kexec_load() system
74          * call is used or will point to kernel memory if
75          * kexec_file_load() system call is used.
76          *
77          * Use ->buf when expecting to deal with user memory and use ->kbuf
78          * when expecting to deal with kernel memory.
79          */
80         union {
81                 void __user *buf;
82                 void *kbuf;
83         };
84         size_t bufsz;
85         unsigned long mem;
86         size_t memsz;
87 };
88
89 #ifdef CONFIG_COMPAT
90 struct compat_kexec_segment {
91         compat_uptr_t buf;
92         compat_size_t bufsz;
93         compat_ulong_t mem;     /* User space sees this as a (void *) ... */
94         compat_size_t memsz;
95 };
96 #endif
97
98 struct kimage {
99         kimage_entry_t head;
100         kimage_entry_t *entry;
101         kimage_entry_t *last_entry;
102
103         unsigned long destination;
104
105         unsigned long start;
106         struct page *control_code_page;
107         struct page *swap_page;
108
109         unsigned long nr_segments;
110         struct kexec_segment segment[KEXEC_SEGMENT_MAX];
111
112         struct list_head control_pages;
113         struct list_head dest_pages;
114         struct list_head unusable_pages;
115
116         /* Address of next control page to allocate for crash kernels. */
117         unsigned long control_page;
118
119         /* Flags to indicate special processing */
120         unsigned int type : 1;
121 #define KEXEC_TYPE_DEFAULT 0
122 #define KEXEC_TYPE_CRASH   1
123         unsigned int preserve_context : 1;
124         /* If set, we are using file mode kexec syscall */
125         unsigned int file_mode:1;
126
127 #ifdef ARCH_HAS_KIMAGE_ARCH
128         struct kimage_arch arch;
129 #endif
130
131         /* Additional fields for file based kexec syscall */
132         void *kernel_buf;
133         unsigned long kernel_buf_len;
134
135         void *initrd_buf;
136         unsigned long initrd_buf_len;
137
138         char *cmdline_buf;
139         unsigned long cmdline_buf_len;
140
141         /* File operations provided by image loader */
142         struct kexec_file_ops *fops;
143
144         /* Image loader handling the kernel can store a pointer here */
145         void *image_loader_data;
146 };
147
148 /*
149  * Keeps track of buffer parameters as provided by caller for requesting
150  * memory placement of buffer.
151  */
152 struct kexec_buf {
153         struct kimage *image;
154         char *buffer;
155         unsigned long bufsz;
156         unsigned long memsz;
157         unsigned long buf_align;
158         unsigned long buf_min;
159         unsigned long buf_max;
160         bool top_down;          /* allocate from top of memory hole */
161 };
162
163 typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
164 typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
165                              unsigned long kernel_len, char *initrd,
166                              unsigned long initrd_len, char *cmdline,
167                              unsigned long cmdline_len);
168 typedef int (kexec_cleanup_t)(struct kimage *image);
169
170 struct kexec_file_ops {
171         kexec_probe_t *probe;
172         kexec_load_t *load;
173         kexec_cleanup_t *cleanup;
174 };
175
176 /* kexec interface functions */
177 extern void machine_kexec(struct kimage *image);
178 extern int machine_kexec_prepare(struct kimage *image);
179 extern void machine_kexec_cleanup(struct kimage *image);
180 extern asmlinkage long sys_kexec_load(unsigned long entry,
181                                         unsigned long nr_segments,
182                                         struct kexec_segment __user *segments,
183                                         unsigned long flags);
184 extern int kernel_kexec(void);
185 extern int kexec_add_buffer(struct kimage *image, char *buffer,
186                             unsigned long bufsz, unsigned long memsz,
187                             unsigned long buf_align, unsigned long buf_min,
188                             unsigned long buf_max, bool top_down,
189                             unsigned long *load_addr);
190 extern struct page *kimage_alloc_control_pages(struct kimage *image,
191                                                 unsigned int order);
192 extern void crash_kexec(struct pt_regs *);
193 int kexec_should_crash(struct task_struct *);
194 void crash_save_cpu(struct pt_regs *regs, int cpu);
195 void crash_save_vmcoreinfo(void);
196 void crash_map_reserved_pages(void);
197 void crash_unmap_reserved_pages(void);
198 void arch_crash_save_vmcoreinfo(void);
199 __printf(1, 2)
200 void vmcoreinfo_append_str(const char *fmt, ...);
201 unsigned long paddr_vmcoreinfo_note(void);
202
203 #define VMCOREINFO_OSRELEASE(value) \
204         vmcoreinfo_append_str("OSRELEASE=%s\n", value)
205 #define VMCOREINFO_PAGESIZE(value) \
206         vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
207 #define VMCOREINFO_SYMBOL(name) \
208         vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
209 #define VMCOREINFO_SIZE(name) \
210         vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
211                               (unsigned long)sizeof(name))
212 #define VMCOREINFO_STRUCT_SIZE(name) \
213         vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
214                               (unsigned long)sizeof(struct name))
215 #define VMCOREINFO_OFFSET(name, field) \
216         vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
217                               (unsigned long)offsetof(struct name, field))
218 #define VMCOREINFO_LENGTH(name, value) \
219         vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
220 #define VMCOREINFO_NUMBER(name) \
221         vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
222 #define VMCOREINFO_CONFIG(name) \
223         vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
224
225 extern struct kimage *kexec_image;
226 extern struct kimage *kexec_crash_image;
227 extern int kexec_load_disabled;
228
229 #ifndef kexec_flush_icache_page
230 #define kexec_flush_icache_page(page)
231 #endif
232
233 /* List of defined/legal kexec flags */
234 #ifndef CONFIG_KEXEC_JUMP
235 #define KEXEC_FLAGS    KEXEC_ON_CRASH
236 #else
237 #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
238 #endif
239
240 /* List of defined/legal kexec file flags */
241 #define KEXEC_FILE_FLAGS        (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
242                                  KEXEC_FILE_NO_INITRAMFS)
243
244 #define VMCOREINFO_BYTES           (4096)
245 #define VMCOREINFO_NOTE_NAME       "VMCOREINFO"
246 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
247 #define VMCOREINFO_NOTE_SIZE       (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
248                                     + VMCOREINFO_NOTE_NAME_BYTES)
249
250 /* Location of a reserved region to hold the crash kernel.
251  */
252 extern struct resource crashk_res;
253 extern struct resource crashk_low_res;
254 typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
255 extern note_buf_t __percpu *crash_notes;
256 extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
257 extern size_t vmcoreinfo_size;
258 extern size_t vmcoreinfo_max_size;
259
260 /* flag to track if kexec reboot is in progress */
261 extern bool kexec_in_progress;
262
263 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
264                 unsigned long long *crash_size, unsigned long long *crash_base);
265 int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
266                 unsigned long long *crash_size, unsigned long long *crash_base);
267 int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
268                 unsigned long long *crash_size, unsigned long long *crash_base);
269 int crash_shrink_memory(unsigned long new_size);
270 size_t crash_get_memory_size(void);
271 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
272
273 #else /* !CONFIG_KEXEC */
274 struct pt_regs;
275 struct task_struct;
276 static inline void crash_kexec(struct pt_regs *regs) { }
277 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
278 #endif /* CONFIG_KEXEC */
279 #endif /* LINUX_KEXEC_H */