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 | |
| 28 | #ifndef KEXEC_CONTROL_CODE_SIZE |
| 29 | #error KEXEC_CONTROL_CODE_SIZE not defined |
| 30 | #endif |
| 31 | |
| 32 | #ifndef KEXEC_ARCH |
| 33 | #error KEXEC_ARCH not defined |
| 34 | #endif |
| 35 | |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 36 | #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) |
| 37 | #define KEXEC_CORE_NOTE_NAME "CORE" |
| 38 | #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4) |
| 39 | #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4) |
| 40 | /* |
| 41 | * The per-cpu notes area is a list of notes terminated by a "NULL" |
| 42 | * note header. For kdump, the code in vmcore.c runs in the context |
| 43 | * of the second kernel to combine them into one note. |
| 44 | */ |
| 45 | #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ |
| 46 | KEXEC_CORE_NOTE_NAME_BYTES + \ |
| 47 | KEXEC_CORE_NOTE_DESC_BYTES ) |
| 48 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 49 | /* |
| 50 | * This structure is used to hold the arguments that are used when loading |
| 51 | * kernel binaries. |
| 52 | */ |
| 53 | |
| 54 | typedef unsigned long kimage_entry_t; |
| 55 | #define IND_DESTINATION 0x1 |
| 56 | #define IND_INDIRECTION 0x2 |
| 57 | #define IND_DONE 0x4 |
| 58 | #define IND_SOURCE 0x8 |
| 59 | |
akpm@osdl.org | 720e1a9 | 2006-01-09 20:51:51 -0800 | [diff] [blame] | 60 | #define KEXEC_SEGMENT_MAX 16 |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 61 | struct kexec_segment { |
| 62 | void __user *buf; |
| 63 | size_t bufsz; |
| 64 | unsigned long mem; /* User space sees this as a (void *) ... */ |
| 65 | size_t memsz; |
| 66 | }; |
| 67 | |
| 68 | #ifdef CONFIG_COMPAT |
| 69 | struct compat_kexec_segment { |
| 70 | compat_uptr_t buf; |
| 71 | compat_size_t bufsz; |
| 72 | compat_ulong_t mem; /* User space sees this as a (void *) ... */ |
| 73 | compat_size_t memsz; |
| 74 | }; |
| 75 | #endif |
| 76 | |
| 77 | struct kimage { |
| 78 | kimage_entry_t head; |
| 79 | kimage_entry_t *entry; |
| 80 | kimage_entry_t *last_entry; |
| 81 | |
| 82 | unsigned long destination; |
| 83 | |
| 84 | unsigned long start; |
| 85 | struct page *control_code_page; |
| 86 | |
| 87 | unsigned long nr_segments; |
| 88 | struct kexec_segment segment[KEXEC_SEGMENT_MAX]; |
| 89 | |
| 90 | struct list_head control_pages; |
| 91 | struct list_head dest_pages; |
| 92 | struct list_head unuseable_pages; |
| 93 | |
| 94 | /* Address of next control page to allocate for crash kernels. */ |
| 95 | unsigned long control_page; |
| 96 | |
| 97 | /* Flags to indicate special processing */ |
| 98 | unsigned int type : 1; |
| 99 | #define KEXEC_TYPE_DEFAULT 0 |
| 100 | #define KEXEC_TYPE_CRASH 1 |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | /* kexec interface functions */ |
| 106 | extern NORET_TYPE void machine_kexec(struct kimage *image) ATTRIB_NORET; |
| 107 | extern int machine_kexec_prepare(struct kimage *image); |
| 108 | extern void machine_kexec_cleanup(struct kimage *image); |
| 109 | extern asmlinkage long sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 110 | unsigned long nr_segments, |
| 111 | struct kexec_segment __user *segments, |
| 112 | unsigned long flags); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 113 | #ifdef CONFIG_COMPAT |
| 114 | extern asmlinkage long compat_sys_kexec_load(unsigned long entry, |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 115 | unsigned long nr_segments, |
| 116 | struct compat_kexec_segment __user *segments, |
| 117 | unsigned long flags); |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 118 | #endif |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 119 | extern struct page *kimage_alloc_control_pages(struct kimage *image, |
| 120 | unsigned int order); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 121 | extern void crash_kexec(struct pt_regs *); |
| 122 | int kexec_should_crash(struct task_struct *); |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 123 | void crash_save_cpu(struct pt_regs *regs, int cpu); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 124 | void crash_save_vmcoreinfo(void); |
| 125 | void arch_crash_save_vmcoreinfo(void); |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 126 | void vmcoreinfo_append_str(const char *fmt, ...) |
| 127 | __attribute__ ((format (printf, 1, 2))); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 128 | unsigned long paddr_vmcoreinfo_note(void); |
| 129 | |
Ken'ichi Ohmichi | bba1f60 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 130 | #define VMCOREINFO_OSRELEASE(name) \ |
| 131 | vmcoreinfo_append_str("OSRELEASE=%s\n", #name) |
| 132 | #define VMCOREINFO_PAGESIZE(value) \ |
| 133 | vmcoreinfo_append_str("PAGESIZE=%ld\n", value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 134 | #define VMCOREINFO_SYMBOL(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 135 | vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 136 | #define VMCOREINFO_SIZE(name) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 137 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 138 | (unsigned long)sizeof(name)) |
Ken'ichi Ohmichi | c76f860 | 2008-02-07 00:15:20 -0800 | [diff] [blame] | 139 | #define VMCOREINFO_STRUCT_SIZE(name) \ |
| 140 | vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ |
| 141 | (unsigned long)sizeof(struct name)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 142 | #define VMCOREINFO_OFFSET(name, field) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 143 | vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ |
Ken'ichi Ohmichi | 1e4f295 | 2008-02-07 00:15:22 -0800 | [diff] [blame] | 144 | (unsigned long)offsetof(struct name, field)) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 145 | #define VMCOREINFO_LENGTH(name, value) \ |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 146 | vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 147 | #define VMCOREINFO_NUMBER(name) \ |
Ken'ichi Ohmichi | 6cfa062 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 148 | vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 149 | #define VMCOREINFO_CONFIG(name) \ |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 150 | vmcoreinfo_append_str("CONFIG_%s=y\n", #name) |
| 151 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 152 | extern struct kimage *kexec_image; |
Jeff Moyer | c330dda | 2006-06-23 02:05:07 -0700 | [diff] [blame] | 153 | extern struct kimage *kexec_crash_image; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 154 | |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 155 | #ifndef kexec_flush_icache_page |
| 156 | #define kexec_flush_icache_page(page) |
| 157 | #endif |
| 158 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 159 | #define KEXEC_ON_CRASH 0x00000001 |
| 160 | #define KEXEC_ARCH_MASK 0xffff0000 |
| 161 | |
| 162 | /* These values match the ELF architecture values. |
| 163 | * Unless there is a good reason that should continue to be the case. |
| 164 | */ |
| 165 | #define KEXEC_ARCH_DEFAULT ( 0 << 16) |
| 166 | #define KEXEC_ARCH_386 ( 3 << 16) |
| 167 | #define KEXEC_ARCH_X86_64 (62 << 16) |
| 168 | #define KEXEC_ARCH_PPC (20 << 16) |
| 169 | #define KEXEC_ARCH_PPC64 (21 << 16) |
| 170 | #define KEXEC_ARCH_IA_64 (50 << 16) |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 171 | #define KEXEC_ARCH_ARM (40 << 16) |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 172 | #define KEXEC_ARCH_S390 (22 << 16) |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 173 | #define KEXEC_ARCH_SH (42 << 16) |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 174 | #define KEXEC_ARCH_MIPS_LE (10 << 16) |
| 175 | #define KEXEC_ARCH_MIPS ( 8 << 16) |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 176 | |
| 177 | #define KEXEC_FLAGS (KEXEC_ON_CRASH) /* List of defined/legal kexec flags */ |
| 178 | |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 179 | #define VMCOREINFO_BYTES (4096) |
| 180 | #define VMCOREINFO_NOTE_NAME "VMCOREINFO" |
| 181 | #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4) |
| 182 | #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \ |
| 183 | + VMCOREINFO_NOTE_NAME_BYTES) |
| 184 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 185 | /* Location of a reserved region to hold the crash kernel. |
| 186 | */ |
| 187 | extern struct resource crashk_res; |
Simon Horman | 6672f76 | 2007-05-08 00:28:22 -0700 | [diff] [blame] | 188 | typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; |
Vivek Goyal | cc57165 | 2006-01-09 20:51:41 -0800 | [diff] [blame] | 189 | extern note_buf_t *crash_notes; |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 190 | extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; |
Ken'ichi Ohmichi | d768281 | 2007-10-16 23:27:28 -0700 | [diff] [blame] | 191 | extern size_t vmcoreinfo_size; |
| 192 | extern size_t vmcoreinfo_max_size; |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 193 | |
Bernhard Walle | cba63c3 | 2007-10-18 23:40:58 -0700 | [diff] [blame] | 194 | int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, |
| 195 | unsigned long long *crash_size, unsigned long long *crash_base); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 196 | |
Eric W. Biederman | dc009d9 | 2005-06-25 14:57:52 -0700 | [diff] [blame] | 197 | #else /* !CONFIG_KEXEC */ |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 198 | struct pt_regs; |
| 199 | struct task_struct; |
| 200 | static inline void crash_kexec(struct pt_regs *regs) { } |
| 201 | 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] | 202 | #endif /* CONFIG_KEXEC */ |
| 203 | #endif /* LINUX_KEXEC_H */ |