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__)
17 #include <uapi/linux/kexec.h>
20 #include <linux/list.h>
21 #include <linux/linkage.h>
22 #include <linux/compat.h>
23 #include <linux/ioport.h>
24 #include <linux/elfcore.h>
25 #include <linux/elf.h>
26 #include <linux/module.h>
27 #include <asm/kexec.h>
29 /* Verify architecture specific macros are defined */
31 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
32 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
35 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
36 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
39 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
40 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
43 #ifndef KEXEC_CONTROL_PAGE_SIZE
44 #error KEXEC_CONTROL_PAGE_SIZE not defined
48 #error KEXEC_ARCH not defined
51 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
52 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
55 #ifndef KEXEC_CRASH_MEM_ALIGN
56 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
59 #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
60 #define KEXEC_CORE_NOTE_NAME "CORE"
61 #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
62 #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
64 * The per-cpu notes area is a list of notes terminated by a "NULL"
65 * note header. For kdump, the code in vmcore.c runs in the context
66 * of the second kernel to combine them into one note.
68 #ifndef KEXEC_NOTE_BYTES
69 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
70 KEXEC_CORE_NOTE_NAME_BYTES + \
71 KEXEC_CORE_NOTE_DESC_BYTES )
75 * This structure is used to hold the arguments that are used when loading
79 typedef unsigned long kimage_entry_t
;
81 struct kexec_segment
{
83 * This pointer can point to user memory if kexec_load() system
84 * call is used or will point to kernel memory if
85 * kexec_file_load() system call is used.
87 * Use ->buf when expecting to deal with user memory and use ->kbuf
88 * when expecting to deal with kernel memory.
100 struct compat_kexec_segment
{
103 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
108 struct kexec_sha_region
{
113 struct purgatory_info
{
114 /* Pointer to elf header of read only purgatory */
117 /* Pointer to purgatory sechdrs which are modifiable */
120 * Temporary buffer location where purgatory is loaded and relocated
121 * This memory can be freed post image load
125 /* Address where purgatory is finally loaded and is executed from */
126 unsigned long purgatory_load_addr
;
131 kimage_entry_t
*entry
;
132 kimage_entry_t
*last_entry
;
135 struct page
*control_code_page
;
136 struct page
*swap_page
;
138 unsigned long nr_segments
;
139 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
141 struct list_head control_pages
;
142 struct list_head dest_pages
;
143 struct list_head unusable_pages
;
145 /* Address of next control page to allocate for crash kernels. */
146 unsigned long control_page
;
148 /* Flags to indicate special processing */
149 unsigned int type
: 1;
150 #define KEXEC_TYPE_DEFAULT 0
151 #define KEXEC_TYPE_CRASH 1
152 unsigned int preserve_context
: 1;
153 /* If set, we are using file mode kexec syscall */
154 unsigned int file_mode
:1;
156 #ifdef ARCH_HAS_KIMAGE_ARCH
157 struct kimage_arch arch
;
160 /* Additional fields for file based kexec syscall */
162 unsigned long kernel_buf_len
;
165 unsigned long initrd_buf_len
;
168 unsigned long cmdline_buf_len
;
170 /* File operations provided by image loader */
171 struct kexec_file_ops
*fops
;
173 /* Image loader handling the kernel can store a pointer here */
174 void *image_loader_data
;
176 /* Information for loading purgatory */
177 struct purgatory_info purgatory_info
;
181 * Keeps track of buffer parameters as provided by caller for requesting
182 * memory placement of buffer.
185 struct kimage
*image
;
190 unsigned long buf_align
;
191 unsigned long buf_min
;
192 unsigned long buf_max
;
193 bool top_down
; /* allocate from top of memory hole */
196 typedef int (kexec_probe_t
)(const char *kernel_buf
, unsigned long kernel_size
);
197 typedef void *(kexec_load_t
)(struct kimage
*image
, char *kernel_buf
,
198 unsigned long kernel_len
, char *initrd
,
199 unsigned long initrd_len
, char *cmdline
,
200 unsigned long cmdline_len
);
201 typedef int (kexec_cleanup_t
)(void *loader_data
);
202 typedef int (kexec_verify_sig_t
)(const char *kernel_buf
,
203 unsigned long kernel_len
);
205 struct kexec_file_ops
{
206 kexec_probe_t
*probe
;
208 kexec_cleanup_t
*cleanup
;
209 kexec_verify_sig_t
*verify_sig
;
212 /* kexec interface functions */
213 extern void machine_kexec(struct kimage
*image
);
214 extern int machine_kexec_prepare(struct kimage
*image
);
215 extern void machine_kexec_cleanup(struct kimage
*image
);
216 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
217 unsigned long nr_segments
,
218 struct kexec_segment __user
*segments
,
219 unsigned long flags
);
220 extern int kernel_kexec(void);
221 extern int kexec_add_buffer(struct kimage
*image
, char *buffer
,
222 unsigned long bufsz
, unsigned long memsz
,
223 unsigned long buf_align
, unsigned long buf_min
,
224 unsigned long buf_max
, bool top_down
,
225 unsigned long *load_addr
);
226 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
228 extern int kexec_load_purgatory(struct kimage
*image
, unsigned long min
,
229 unsigned long max
, int top_down
,
230 unsigned long *load_addr
);
231 extern int kexec_purgatory_get_set_symbol(struct kimage
*image
,
232 const char *name
, void *buf
,
233 unsigned int size
, bool get_value
);
234 extern void *kexec_purgatory_get_symbol_addr(struct kimage
*image
,
236 extern void crash_kexec(struct pt_regs
*);
237 int kexec_should_crash(struct task_struct
*);
238 void crash_save_cpu(struct pt_regs
*regs
, int cpu
);
239 void crash_save_vmcoreinfo(void);
240 void crash_map_reserved_pages(void);
241 void crash_unmap_reserved_pages(void);
242 void arch_crash_save_vmcoreinfo(void);
244 void vmcoreinfo_append_str(const char *fmt
, ...);
245 unsigned long paddr_vmcoreinfo_note(void);
247 #define VMCOREINFO_OSRELEASE(value) \
248 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
249 #define VMCOREINFO_PAGESIZE(value) \
250 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
251 #define VMCOREINFO_SYMBOL(name) \
252 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
253 #define VMCOREINFO_SIZE(name) \
254 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
255 (unsigned long)sizeof(name))
256 #define VMCOREINFO_STRUCT_SIZE(name) \
257 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
258 (unsigned long)sizeof(struct name))
259 #define VMCOREINFO_OFFSET(name, field) \
260 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
261 (unsigned long)offsetof(struct name, field))
262 #define VMCOREINFO_LENGTH(name, value) \
263 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
264 #define VMCOREINFO_NUMBER(name) \
265 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
266 #define VMCOREINFO_CONFIG(name) \
267 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
269 extern struct kimage
*kexec_image
;
270 extern struct kimage
*kexec_crash_image
;
271 extern int kexec_load_disabled
;
273 #ifndef kexec_flush_icache_page
274 #define kexec_flush_icache_page(page)
277 /* List of defined/legal kexec flags */
278 #ifndef CONFIG_KEXEC_JUMP
279 #define KEXEC_FLAGS KEXEC_ON_CRASH
281 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
284 /* List of defined/legal kexec file flags */
285 #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
286 KEXEC_FILE_NO_INITRAMFS)
288 #define VMCOREINFO_BYTES (4096)
289 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
290 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
291 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
292 + VMCOREINFO_NOTE_NAME_BYTES)
294 /* Location of a reserved region to hold the crash kernel.
296 extern struct resource crashk_res
;
297 extern struct resource crashk_low_res
;
298 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
299 extern note_buf_t __percpu
*crash_notes
;
300 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
301 extern size_t vmcoreinfo_size
;
302 extern size_t vmcoreinfo_max_size
;
304 /* flag to track if kexec reboot is in progress */
305 extern bool kexec_in_progress
;
307 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
308 unsigned long long *crash_size
, unsigned long long *crash_base
);
309 int parse_crashkernel_high(char *cmdline
, unsigned long long system_ram
,
310 unsigned long long *crash_size
, unsigned long long *crash_base
);
311 int parse_crashkernel_low(char *cmdline
, unsigned long long system_ram
,
312 unsigned long long *crash_size
, unsigned long long *crash_base
);
313 int crash_shrink_memory(unsigned long new_size
);
314 size_t crash_get_memory_size(void);
315 void crash_free_reserved_phys_range(unsigned long begin
, unsigned long end
);
317 #else /* !CONFIG_KEXEC */
320 static inline void crash_kexec(struct pt_regs
*regs
) { }
321 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
322 #endif /* CONFIG_KEXEC */
324 #endif /* !defined(__ASSEBMLY__) */
326 #endif /* LINUX_KEXEC_H */