Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 1 | #ifndef LINUX_KEXEC_H |
| 2 | #define LINUX_KEXEC_H |
| 3 | |
| 4 | #ifdef CONFIG_KEXEC |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/list.h> |
| 7 | #include <linux/linkage.h> |
| 8 | #include <linux/compat.h> |
Haren Myneni | 9c15e85 | 2006-02-10 01:51:05 -0800 | [diff] [blame] | 9 | #include <linux/ioport.h> |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 10 | #include <linux/elfcore.h> |
| 11 | #include <linux/elf.h> |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 12 | #include <asm/kexec.h> |
| 13 | |
| 14 | /* Verify architecture specific macros are defined */ |
| 15 | |
| 16 | #ifndef KEXEC_SOURCE_MEMORY_LIMIT |
| 17 | #error KEXEC_SOURCE_MEMORY_LIMIT not defined |
| 18 | #endif |
| 19 | |
| 20 | #ifndef KEXEC_DESTINATION_MEMORY_LIMIT |
| 21 | #error KEXEC_DESTINATION_MEMORY_LIMIT not defined |
| 22 | #endif |
| 23 | |
| 24 | #ifndef KEXEC_CONTROL_MEMORY_LIMIT |
| 25 | #error KEXEC_CONTROL_MEMORY_LIMIT not defined |
| 26 | #endif |
| 27 | |
Huang Ying | 163f687 | 2008-08-15 00:40:22 -0700 | [diff] [blame] | 28 | #ifndef KEXEC_CONTROL_PAGE_SIZE |
| 29 | #error KEXEC_CONTROL_PAGE_SIZE not defined |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | #ifndef KEXEC_ARCH |
| 33 | #error KEXEC_ARCH not defined |
| 34 | #endif |
| 35 | |
Michael Holzheu | 3d214fa | 2011-10-30 15:16:36 +0100 | [diff] [blame] | 36 | #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT |
| 37 | #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT |
| 38 | #endif |
| 39 | |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 40 | #ifndef KEXEC_CRASH_MEM_ALIGN |
| 41 | #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE |
| 42 | #endif |
| 43 | |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 44 | #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) |
| 45 | #define KEXEC_CORE_NOTE_NAME "CORE" |
| 46 | #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4) |
| 47 | #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4) |
| 48 | /* |
| 49 | * The per-cpu notes area is a list of notes terminated by a "NULL" |
| 50 | * note header. For kdump, the code in vmcore.c runs in the context |
| 51 | * of the second kernel to combine them into one note. |
| 52 | */ |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 53 | #ifndef KEXEC_NOTE_BYTES |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 54 | #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ |
| 55 | KEXEC_CORE_NOTE_NAME_BYTES + \ |
| 56 | KEXEC_CORE_NOTE_DESC_BYTES ) |
Michael Holzheu | cb78edf | 2012-01-20 14:34:16 -0800 | [diff] [blame] | 57 | #endif |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 58 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 59 | /* |
| 60 | * This structure is used to hold the arguments that are used when loading |
| 61 | * kernel binaries. |
| 62 | */ |
| 63 | |
| 64 | typedef unsigned long kimage_entry_t; |
| 65 | #define IND_DESTINATION 0x1 |
| 66 | #define IND_INDIRECTION 0x2 |
| 67 | #define IND_DONE 0x4 |
| 68 | #define IND_SOURCE 0x8 |
| 69 | |
akpm@osdl.org | 720e1a9 | 2006-01-09 20:51:51 -0800 | [diff] [blame] | 70 | #define KEXEC_SEGMENT_MAX 16 |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 71 | struct kexec_segment { |
| 72 | void __user *buf; |
| 73 | size_t bufsz; |
| 74 | unsigned long mem; /* User space sees this as a (void *) ... */ |
| 75 | size_t memsz; |
| 76 | }; |
| 77 | |
| 78 | #ifdef CONFIG_COMPAT |
| 79 | struct 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 | |
| 87 | struct 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 Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 96 | struct page *swap_page; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 97 | |
| 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 Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 112 | unsigned int preserve_context : 1; |
Huang Ying | 92be3d6 | 2008-10-31 09:48:08 +0800 | [diff] [blame] | 113 | |
| 114 | #ifdef ARCH_HAS_KIMAGE_ARCH |
| 115 | struct kimage_arch arch; |
| 116 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | |
| 120 | |
| 121 | /* kexec interface functions */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 122 | extern void machine_kexec(struct kimage *image); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 123 | extern int machine_kexec_prepare(struct kimage *image); |
| 124 | extern void machine_kexec_cleanup(struct kimage *image); |
| 125 | extern asmlinkage long sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 126 | unsigned long nr_segments, |
| 127 | struct kexec_segment __user *segments, |
| 128 | unsigned long flags); |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 129 | extern int kernel_kexec(void); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 130 | #ifdef CONFIG_COMPAT |
| 131 | extern asmlinkage long compat_sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 132 | unsigned long nr_segments, |
| 133 | struct compat_kexec_segment __user *segments, |
| 134 | unsigned long flags); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 135 | #endif |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 136 | extern struct page *kimage_alloc_control_pages(struct kimage *image, |
| 137 | unsigned int order); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 138 | extern void crash_kexec(struct pt_regs *); |
| 139 | int kexec_should_crash(struct task_struct *); |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 140 | void crash_save_cpu(struct pt_regs *regs, int cpu); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 141 | void crash_save_vmcoreinfo(void); |
Michael Holzheu | 558df72 | 2011-10-30 15:16:43 +0100 | [diff] [blame] | 142 | void crash_map_reserved_pages(void); |
| 143 | void crash_unmap_reserved_pages(void); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 144 | void arch_crash_save_vmcoreinfo(void); |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 145 | __printf(1, 2) |
| 146 | void vmcoreinfo_append_str(const char *fmt, ...); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 147 | unsigned long paddr_vmcoreinfo_note(void); |
| 148 | |
Bernhard Walle | c6e2bee | 2008-08-05 13:01:05 -0700 | [diff] [blame] | 149 | #define VMCOREINFO_OSRELEASE(value) \ |
| 150 | vmcoreinfo_append_str("OSRELEASE=%s\n", value) |
Ken'ichi Ohmichi | bba1f60 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 151 | #define VMCOREINFO_PAGESIZE(value) \ |
| 152 | vmcoreinfo_append_str("PAGESIZE=%ld\n", value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 153 | #define VMCOREINFO_SYMBOL(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 154 | vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 155 | #define VMCOREINFO_SIZE(name) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 156 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 157 | (unsigned long)sizeof(name)) |
Ken'ichi Ohmichi | c76f860 | 2008-02-07 00:15:20 -0800 | [diff] [blame] | 158 | #define VMCOREINFO_STRUCT_SIZE(name) \ |
| 159 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
| 160 | (unsigned long)sizeof(struct name)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 161 | #define VMCOREINFO_OFFSET(name, field) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 162 | vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ |
Ken'ichi Ohmichi | 1e4f295 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 163 | (unsigned long)offsetof(struct name, field)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 164 | #define VMCOREINFO_LENGTH(name, value) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 165 | vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 166 | #define VMCOREINFO_NUMBER(name) \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 167 | vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 168 | #define VMCOREINFO_CONFIG(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 169 | vmcoreinfo_append_str("CONFIG_%s=y\n", #name) |
| 170 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 171 | extern struct kimage *kexec_image; |
Jeff Moyer | c330dda | 2006-06-23 02:05:07 -0700 | [diff] [blame] | 172 | extern struct kimage *kexec_crash_image; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 173 | |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 174 | #ifndef kexec_flush_icache_page |
| 175 | #define kexec_flush_icache_page(page) |
| 176 | #endif |
| 177 | |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 178 | #define KEXEC_ON_CRASH 0x00000001 |
| 179 | #define KEXEC_PRESERVE_CONTEXT 0x00000002 |
| 180 | #define KEXEC_ARCH_MASK 0xffff0000 |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 181 | |
| 182 | /* These values match the ELF architecture values. |
| 183 | * Unless there is a good reason that should continue to be the case. |
| 184 | */ |
| 185 | #define KEXEC_ARCH_DEFAULT ( 0 << 16) |
| 186 | #define KEXEC_ARCH_386 ( 3 << 16) |
| 187 | #define KEXEC_ARCH_X86_64 (62 << 16) |
| 188 | #define KEXEC_ARCH_PPC (20 << 16) |
| 189 | #define KEXEC_ARCH_PPC64 (21 << 16) |
| 190 | #define KEXEC_ARCH_IA_64 (50 << 16) |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 191 | #define KEXEC_ARCH_ARM (40 << 16) |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 192 | #define KEXEC_ARCH_S390 (22 << 16) |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 193 | #define KEXEC_ARCH_SH (42 << 16) |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 194 | #define KEXEC_ARCH_MIPS_LE (10 << 16) |
| 195 | #define KEXEC_ARCH_MIPS ( 8 << 16) |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 196 | |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 197 | /* List of defined/legal kexec flags */ |
| 198 | #ifndef CONFIG_KEXEC_JUMP |
| 199 | #define KEXEC_FLAGS KEXEC_ON_CRASH |
| 200 | #else |
| 201 | #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT) |
| 202 | #endif |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 203 | |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 204 | #define VMCOREINFO_BYTES (4096) |
| 205 | #define VMCOREINFO_NOTE_NAME "VMCOREINFO" |
| 206 | #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4) |
| 207 | #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \ |
| 208 | + VMCOREINFO_NOTE_NAME_BYTES) |
| 209 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 210 | /* Location of a reserved region to hold the crash kernel. |
| 211 | */ |
| 212 | extern struct resource crashk_res; |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 213 | typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; |
Tejun Heo | 43cf38e | 2010-02-02 14:38:57 +0900 | [diff] [blame] | 214 | extern note_buf_t __percpu *crash_notes; |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 215 | extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 216 | extern size_t vmcoreinfo_size; |
| 217 | extern size_t vmcoreinfo_max_size; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 218 | |
Bernhard Walle | cba63c3 | 2007-10-18 23:40:58 -0700 | [diff] [blame] | 219 | int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, |
| 220 | unsigned long long *crash_size, unsigned long long *crash_base); |
Amerigo Wang | 06a7f71 | 2009-12-15 16:47:46 -0800 | [diff] [blame] | 221 | int crash_shrink_memory(unsigned long new_size); |
| 222 | size_t crash_get_memory_size(void); |
Anton Blanchard | c0bb9e4 | 2010-08-25 10:22:58 +1000 | [diff] [blame] | 223 | void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 224 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 225 | #else /* !CONFIG_KEXEC */ |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 226 | struct pt_regs; |
| 227 | struct task_struct; |
| 228 | static inline void crash_kexec(struct pt_regs *regs) { } |
| 229 | 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] | 230 | #endif /* CONFIG_KEXEC */ |
| 231 | #endif /* LINUX_KEXEC_H */ |