Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 1 | #ifndef LINUX_KEXEC_H |
| 2 | #define LINUX_KEXEC_H |
| 3 | |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 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. |
| 7 | */ |
| 8 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 9 | #include <linux/types.h> |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 10 | |
| 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 |
| 15 | |
| 16 | /* These values match the ELF architecture values. |
| 17 | * Unless there is a good reason that should continue to be the case. |
| 18 | */ |
| 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) |
| 30 | |
| 31 | /* The artificial cap on the number of segments passed to kexec_load. */ |
| 32 | #define KEXEC_SEGMENT_MAX 16 |
| 33 | |
| 34 | #ifndef __KERNEL__ |
| 35 | /* |
| 36 | * This structure is used to hold the arguments that are used when |
| 37 | * loading kernel binaries. |
| 38 | */ |
| 39 | struct kexec_segment { |
| 40 | const void *buf; |
| 41 | size_t bufsz; |
| 42 | const void *mem; |
| 43 | size_t memsz; |
| 44 | }; |
| 45 | |
| 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. |
| 49 | */ |
| 50 | extern int kexec_load(void *, size_t, struct kexec_segment *, |
| 51 | unsigned long int); |
| 52 | #endif /* __KERNEL__ */ |
| 53 | |
| 54 | #ifdef __KERNEL__ |
| 55 | #ifdef CONFIG_KEXEC |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 56 | #include <linux/list.h> |
| 57 | #include <linux/linkage.h> |
| 58 | #include <linux/compat.h> |
Haren Myneni | 9c15e85 | 2006-02-10 01:51:05 -0800 | [diff] [blame] | 59 | #include <linux/ioport.h> |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 60 | #include <linux/elfcore.h> |
| 61 | #include <linux/elf.h> |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 62 | #include <asm/kexec.h> |
| 63 | |
| 64 | /* Verify architecture specific macros are defined */ |
| 65 | |
| 66 | #ifndef KEXEC_SOURCE_MEMORY_LIMIT |
| 67 | #error KEXEC_SOURCE_MEMORY_LIMIT not defined |
| 68 | #endif |
| 69 | |
| 70 | #ifndef KEXEC_DESTINATION_MEMORY_LIMIT |
| 71 | #error KEXEC_DESTINATION_MEMORY_LIMIT not defined |
| 72 | #endif |
| 73 | |
| 74 | #ifndef KEXEC_CONTROL_MEMORY_LIMIT |
| 75 | #error KEXEC_CONTROL_MEMORY_LIMIT not defined |
| 76 | #endif |
| 77 | |
Huang Ying | 163f687 | 2008-08-15 00:40:22 -0700 | [diff] [blame] | 78 | #ifndef KEXEC_CONTROL_PAGE_SIZE |
| 79 | #error KEXEC_CONTROL_PAGE_SIZE not defined |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | #ifndef KEXEC_ARCH |
| 83 | #error KEXEC_ARCH not defined |
| 84 | #endif |
| 85 | |
Michael Holzheu | 3d214fa | 2011-10-30 15:16:36 +0100 | [diff] [blame] | 86 | #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT |
| 87 | #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT |
| 88 | #endif |
| 89 | |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 90 | #ifndef KEXEC_CRASH_MEM_ALIGN |
| 91 | #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE |
| 92 | #endif |
| 93 | |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 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) |
| 98 | /* |
| 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. |
| 102 | */ |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 103 | #ifndef KEXEC_NOTE_BYTES |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 104 | #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ |
| 105 | KEXEC_CORE_NOTE_NAME_BYTES + \ |
| 106 | KEXEC_CORE_NOTE_DESC_BYTES ) |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 107 | #endif |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 108 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 109 | /* |
| 110 | * This structure is used to hold the arguments that are used when loading |
| 111 | * kernel binaries. |
| 112 | */ |
| 113 | |
| 114 | typedef unsigned long kimage_entry_t; |
| 115 | #define IND_DESTINATION 0x1 |
| 116 | #define IND_INDIRECTION 0x2 |
| 117 | #define IND_DONE 0x4 |
| 118 | #define IND_SOURCE 0x8 |
| 119 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 120 | struct kexec_segment { |
| 121 | void __user *buf; |
| 122 | size_t bufsz; |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 123 | unsigned long mem; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 124 | size_t memsz; |
| 125 | }; |
| 126 | |
| 127 | #ifdef CONFIG_COMPAT |
| 128 | struct compat_kexec_segment { |
| 129 | compat_uptr_t buf; |
| 130 | compat_size_t bufsz; |
| 131 | compat_ulong_t mem; /* User space sees this as a (void *) ... */ |
| 132 | compat_size_t memsz; |
| 133 | }; |
| 134 | #endif |
| 135 | |
| 136 | struct kimage { |
| 137 | kimage_entry_t head; |
| 138 | kimage_entry_t *entry; |
| 139 | kimage_entry_t *last_entry; |
| 140 | |
| 141 | unsigned long destination; |
| 142 | |
| 143 | unsigned long start; |
| 144 | struct page *control_code_page; |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 145 | struct page *swap_page; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 146 | |
| 147 | unsigned long nr_segments; |
| 148 | struct kexec_segment segment[KEXEC_SEGMENT_MAX]; |
| 149 | |
| 150 | struct list_head control_pages; |
| 151 | struct list_head dest_pages; |
| 152 | struct list_head unuseable_pages; |
| 153 | |
| 154 | /* Address of next control page to allocate for crash kernels. */ |
| 155 | unsigned long control_page; |
| 156 | |
| 157 | /* Flags to indicate special processing */ |
| 158 | unsigned int type : 1; |
| 159 | #define KEXEC_TYPE_DEFAULT 0 |
| 160 | #define KEXEC_TYPE_CRASH 1 |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 161 | unsigned int preserve_context : 1; |
Huang Ying | 92be3d6 | 2008-10-31 09:48:08 +0800 | [diff] [blame] | 162 | |
| 163 | #ifdef ARCH_HAS_KIMAGE_ARCH |
| 164 | struct kimage_arch arch; |
| 165 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | |
| 169 | |
| 170 | /* kexec interface functions */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 171 | extern void machine_kexec(struct kimage *image); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 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, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 175 | unsigned long nr_segments, |
| 176 | struct kexec_segment __user *segments, |
| 177 | unsigned long flags); |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 178 | extern int kernel_kexec(void); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 179 | #ifdef CONFIG_COMPAT |
| 180 | extern asmlinkage long compat_sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 181 | unsigned long nr_segments, |
| 182 | struct compat_kexec_segment __user *segments, |
| 183 | unsigned long flags); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 184 | #endif |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 185 | extern struct page *kimage_alloc_control_pages(struct kimage *image, |
| 186 | unsigned int order); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 187 | extern void crash_kexec(struct pt_regs *); |
| 188 | int kexec_should_crash(struct task_struct *); |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 189 | void crash_save_cpu(struct pt_regs *regs, int cpu); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 190 | void crash_save_vmcoreinfo(void); |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 191 | void crash_map_reserved_pages(void); |
| 192 | void crash_unmap_reserved_pages(void); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 193 | void arch_crash_save_vmcoreinfo(void); |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 194 | __printf(1, 2) |
| 195 | void vmcoreinfo_append_str(const char *fmt, ...); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 196 | unsigned long paddr_vmcoreinfo_note(void); |
| 197 | |
Bernhard Walle | c6e2bee | 2008-08-05 13:01:05 -0700 | [diff] [blame] | 198 | #define VMCOREINFO_OSRELEASE(value) \ |
| 199 | vmcoreinfo_append_str("OSRELEASE=%s\n", value) |
Ken'ichi Ohmichi | bba1f60 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 200 | #define VMCOREINFO_PAGESIZE(value) \ |
| 201 | vmcoreinfo_append_str("PAGESIZE=%ld\n", value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 202 | #define VMCOREINFO_SYMBOL(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 203 | vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 204 | #define VMCOREINFO_SIZE(name) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 205 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 206 | (unsigned long)sizeof(name)) |
Ken'ichi Ohmichi | c76f860 | 2008-02-07 00:15:20 -0800 | [diff] [blame] | 207 | #define VMCOREINFO_STRUCT_SIZE(name) \ |
| 208 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
| 209 | (unsigned long)sizeof(struct name)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 210 | #define VMCOREINFO_OFFSET(name, field) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 211 | vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ |
Ken'ichi Ohmichi | 1e4f295 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 212 | (unsigned long)offsetof(struct name, field)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 213 | #define VMCOREINFO_LENGTH(name, value) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 214 | vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 215 | #define VMCOREINFO_NUMBER(name) \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 216 | vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 217 | #define VMCOREINFO_CONFIG(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 218 | vmcoreinfo_append_str("CONFIG_%s=y\n", #name) |
| 219 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 220 | extern struct kimage *kexec_image; |
Jeff Moyer | c330dda | 2006-06-23 02:05:07 -0700 | [diff] [blame] | 221 | extern struct kimage *kexec_crash_image; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 222 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 223 | #ifndef kexec_flush_icache_page |
| 224 | #define kexec_flush_icache_page(page) |
| 225 | #endif |
| 226 | |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 227 | /* List of defined/legal kexec flags */ |
| 228 | #ifndef CONFIG_KEXEC_JUMP |
| 229 | #define KEXEC_FLAGS KEXEC_ON_CRASH |
| 230 | #else |
| 231 | #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT) |
| 232 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 233 | |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 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) |
| 239 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 240 | /* Location of a reserved region to hold the crash kernel. |
| 241 | */ |
| 242 | extern struct resource crashk_res; |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 243 | typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; |
Tejun Heo | 43cf38e | 2010-02-02 14:38:57 +0900 | [diff] [blame] | 244 | extern note_buf_t __percpu *crash_notes; |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 245 | extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 246 | extern size_t vmcoreinfo_size; |
| 247 | extern size_t vmcoreinfo_max_size; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 248 | |
Bernhard Walle | cba63c3 | 2007-10-18 23:40:58 -0700 | [diff] [blame] | 249 | int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, |
| 250 | unsigned long long *crash_size, unsigned long long *crash_base); |
Amerigo Wang | 06a7f71 | 2009-12-15 16:47:46 -0800 | [diff] [blame] | 251 | int crash_shrink_memory(unsigned long new_size); |
| 252 | size_t crash_get_memory_size(void); |
Anton Blanchard | c0bb9e4 | 2010-08-25 10:22:58 +1000 | [diff] [blame] | 253 | 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] | 254 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 255 | #else /* !CONFIG_KEXEC */ |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 256 | struct pt_regs; |
| 257 | struct task_struct; |
| 258 | static inline void crash_kexec(struct pt_regs *regs) { } |
| 259 | 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] | 260 | #endif /* CONFIG_KEXEC */ |
maximilian attems | 29a5c67 | 2012-05-31 16:26:27 -0700 | [diff] [blame] | 261 | #endif /* __KERNEL__ */ |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 262 | #endif /* LINUX_KEXEC_H */ |