Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 1 | #ifndef LINUX_KEXEC_H |
| 2 | #define LINUX_KEXEC_H |
| 3 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 4 | #include <uapi/linux/kexec.h> |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 5 | |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 6 | #ifdef CONFIG_KEXEC |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 7 | #include <linux/list.h> |
| 8 | #include <linux/linkage.h> |
| 9 | #include <linux/compat.h> |
Haren Myneni | 9c15e85 | 2006-02-10 01:51:05 -0800 | [diff] [blame] | 10 | #include <linux/ioport.h> |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 11 | #include <linux/elfcore.h> |
| 12 | #include <linux/elf.h> |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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 | |
Huang Ying | 163f687 | 2008-08-15 00:40:22 -0700 | [diff] [blame] | 29 | #ifndef KEXEC_CONTROL_PAGE_SIZE |
| 30 | #error KEXEC_CONTROL_PAGE_SIZE not defined |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #ifndef KEXEC_ARCH |
| 34 | #error KEXEC_ARCH not defined |
| 35 | #endif |
| 36 | |
Michael Holzheu | 3d214fa | 2011-10-30 15:16:36 +0100 | [diff] [blame] | 37 | #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT |
| 38 | #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT |
| 39 | #endif |
| 40 | |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 41 | #ifndef KEXEC_CRASH_MEM_ALIGN |
| 42 | #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE |
| 43 | #endif |
| 44 | |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 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 | */ |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 54 | #ifndef KEXEC_NOTE_BYTES |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 55 | #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ |
| 56 | KEXEC_CORE_NOTE_NAME_BYTES + \ |
| 57 | KEXEC_CORE_NOTE_DESC_BYTES ) |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 58 | #endif |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 59 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 71 | struct kexec_segment { |
Vivek Goyal | 815d570 | 2014-08-08 14:25:52 -0700 | [diff] [blame^] | 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 | }; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 84 | size_t bufsz; |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 85 | unsigned long mem; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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; |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 107 | struct page *swap_page; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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; |
Vivek Goyal | 7d3e2bc | 2014-08-08 14:25:43 -0700 | [diff] [blame] | 114 | struct list_head unusable_pages; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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 |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 123 | unsigned int preserve_context : 1; |
Huang Ying | 92be3d6 | 2008-10-31 09:48:08 +0800 | [diff] [blame] | 124 | |
| 125 | #ifdef ARCH_HAS_KIMAGE_ARCH |
| 126 | struct kimage_arch arch; |
| 127 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | |
| 131 | |
| 132 | /* kexec interface functions */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 133 | extern void machine_kexec(struct kimage *image); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 134 | extern int machine_kexec_prepare(struct kimage *image); |
| 135 | extern void machine_kexec_cleanup(struct kimage *image); |
| 136 | extern asmlinkage long sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 137 | unsigned long nr_segments, |
| 138 | struct kexec_segment __user *segments, |
| 139 | unsigned long flags); |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 140 | extern int kernel_kexec(void); |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 141 | extern struct page *kimage_alloc_control_pages(struct kimage *image, |
| 142 | unsigned int order); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 143 | extern void crash_kexec(struct pt_regs *); |
| 144 | int kexec_should_crash(struct task_struct *); |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 145 | void crash_save_cpu(struct pt_regs *regs, int cpu); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 146 | void crash_save_vmcoreinfo(void); |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 147 | void crash_map_reserved_pages(void); |
| 148 | void crash_unmap_reserved_pages(void); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 149 | void arch_crash_save_vmcoreinfo(void); |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 150 | __printf(1, 2) |
| 151 | void vmcoreinfo_append_str(const char *fmt, ...); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 152 | unsigned long paddr_vmcoreinfo_note(void); |
| 153 | |
Bernhard Walle | c6e2bee | 2008-08-05 13:01:05 -0700 | [diff] [blame] | 154 | #define VMCOREINFO_OSRELEASE(value) \ |
| 155 | vmcoreinfo_append_str("OSRELEASE=%s\n", value) |
Ken'ichi Ohmichi | bba1f60 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 156 | #define VMCOREINFO_PAGESIZE(value) \ |
| 157 | vmcoreinfo_append_str("PAGESIZE=%ld\n", value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 158 | #define VMCOREINFO_SYMBOL(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 159 | vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 160 | #define VMCOREINFO_SIZE(name) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 161 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 162 | (unsigned long)sizeof(name)) |
Ken'ichi Ohmichi | c76f860 | 2008-02-07 00:15:20 -0800 | [diff] [blame] | 163 | #define VMCOREINFO_STRUCT_SIZE(name) \ |
| 164 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
| 165 | (unsigned long)sizeof(struct name)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 166 | #define VMCOREINFO_OFFSET(name, field) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 167 | vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ |
Ken'ichi Ohmichi | 1e4f295 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 168 | (unsigned long)offsetof(struct name, field)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 169 | #define VMCOREINFO_LENGTH(name, value) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 170 | vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 171 | #define VMCOREINFO_NUMBER(name) \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 172 | vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 173 | #define VMCOREINFO_CONFIG(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 174 | vmcoreinfo_append_str("CONFIG_%s=y\n", #name) |
| 175 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 176 | extern struct kimage *kexec_image; |
Jeff Moyer | c330dda | 2006-06-23 02:05:07 -0700 | [diff] [blame] | 177 | extern struct kimage *kexec_crash_image; |
Kees Cook | 7984754 | 2014-01-23 15:55:59 -0800 | [diff] [blame] | 178 | extern int kexec_load_disabled; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 179 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 180 | #ifndef kexec_flush_icache_page |
| 181 | #define kexec_flush_icache_page(page) |
| 182 | #endif |
| 183 | |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 184 | /* List of defined/legal kexec flags */ |
| 185 | #ifndef CONFIG_KEXEC_JUMP |
| 186 | #define KEXEC_FLAGS KEXEC_ON_CRASH |
| 187 | #else |
| 188 | #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT) |
| 189 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 190 | |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 191 | #define VMCOREINFO_BYTES (4096) |
| 192 | #define VMCOREINFO_NOTE_NAME "VMCOREINFO" |
| 193 | #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4) |
| 194 | #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \ |
| 195 | + VMCOREINFO_NOTE_NAME_BYTES) |
| 196 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 197 | /* Location of a reserved region to hold the crash kernel. |
| 198 | */ |
| 199 | extern struct resource crashk_res; |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 200 | extern struct resource crashk_low_res; |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 201 | typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; |
Tejun Heo | 43cf38e | 2010-02-02 14:38:57 +0900 | [diff] [blame] | 202 | extern note_buf_t __percpu *crash_notes; |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 203 | extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 204 | extern size_t vmcoreinfo_size; |
| 205 | extern size_t vmcoreinfo_max_size; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 206 | |
Khalid Aziz | 4fc9bbf | 2013-11-27 15:19:25 -0700 | [diff] [blame] | 207 | /* flag to track if kexec reboot is in progress */ |
| 208 | extern bool kexec_in_progress; |
| 209 | |
Bernhard Walle | cba63c3 | 2007-10-18 23:40:58 -0700 | [diff] [blame] | 210 | int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, |
| 211 | unsigned long long *crash_size, unsigned long long *crash_base); |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 212 | int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, |
| 213 | unsigned long long *crash_size, unsigned long long *crash_base); |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 214 | int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, |
| 215 | unsigned long long *crash_size, unsigned long long *crash_base); |
Amerigo Wang | 06a7f71 | 2009-12-15 16:47:46 -0800 | [diff] [blame] | 216 | int crash_shrink_memory(unsigned long new_size); |
| 217 | size_t crash_get_memory_size(void); |
Anton Blanchard | c0bb9e4 | 2010-08-25 10:22:58 +1000 | [diff] [blame] | 218 | void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 219 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 220 | #else /* !CONFIG_KEXEC */ |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 221 | struct pt_regs; |
| 222 | struct task_struct; |
| 223 | static inline void crash_kexec(struct pt_regs *regs) { } |
| 224 | static inline int kexec_should_crash(struct task_struct *p) { return 0; } |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 225 | #endif /* CONFIG_KEXEC */ |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 226 | #endif /* LINUX_KEXEC_H */ |