at v3.6 7.9 kB view raw
1#ifndef LINUX_KEXEC_H 2#define LINUX_KEXEC_H 3 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 9#include <linux/types.h> 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 */ 39struct 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 */ 50extern int kexec_load(void *, size_t, struct kexec_segment *, 51 unsigned long int); 52#endif /* __KERNEL__ */ 53 54#ifdef __KERNEL__ 55#ifdef CONFIG_KEXEC 56#include <linux/list.h> 57#include <linux/linkage.h> 58#include <linux/compat.h> 59#include <linux/ioport.h> 60#include <linux/elfcore.h> 61#include <linux/elf.h> 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 78#ifndef KEXEC_CONTROL_PAGE_SIZE 79#error KEXEC_CONTROL_PAGE_SIZE not defined 80#endif 81 82#ifndef KEXEC_ARCH 83#error KEXEC_ARCH not defined 84#endif 85 86#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT 87#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT 88#endif 89 90#ifndef KEXEC_CRASH_MEM_ALIGN 91#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE 92#endif 93 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 */ 103#ifndef KEXEC_NOTE_BYTES 104#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ 105 KEXEC_CORE_NOTE_NAME_BYTES + \ 106 KEXEC_CORE_NOTE_DESC_BYTES ) 107#endif 108 109/* 110 * This structure is used to hold the arguments that are used when loading 111 * kernel binaries. 112 */ 113 114typedef 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 120struct kexec_segment { 121 void __user *buf; 122 size_t bufsz; 123 unsigned long mem; 124 size_t memsz; 125}; 126 127#ifdef CONFIG_COMPAT 128struct 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 136struct 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; 145 struct page *swap_page; 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 161 unsigned int preserve_context : 1; 162 163#ifdef ARCH_HAS_KIMAGE_ARCH 164 struct kimage_arch arch; 165#endif 166}; 167 168 169 170/* kexec interface functions */ 171extern void machine_kexec(struct kimage *image); 172extern int machine_kexec_prepare(struct kimage *image); 173extern void machine_kexec_cleanup(struct kimage *image); 174extern asmlinkage long sys_kexec_load(unsigned long entry, 175 unsigned long nr_segments, 176 struct kexec_segment __user *segments, 177 unsigned long flags); 178extern int kernel_kexec(void); 179#ifdef CONFIG_COMPAT 180extern asmlinkage long compat_sys_kexec_load(unsigned long entry, 181 unsigned long nr_segments, 182 struct compat_kexec_segment __user *segments, 183 unsigned long flags); 184#endif 185extern struct page *kimage_alloc_control_pages(struct kimage *image, 186 unsigned int order); 187extern void crash_kexec(struct pt_regs *); 188int kexec_should_crash(struct task_struct *); 189void crash_save_cpu(struct pt_regs *regs, int cpu); 190void crash_save_vmcoreinfo(void); 191void crash_map_reserved_pages(void); 192void crash_unmap_reserved_pages(void); 193void arch_crash_save_vmcoreinfo(void); 194__printf(1, 2) 195void vmcoreinfo_append_str(const char *fmt, ...); 196unsigned long paddr_vmcoreinfo_note(void); 197 198#define VMCOREINFO_OSRELEASE(value) \ 199 vmcoreinfo_append_str("OSRELEASE=%s\n", value) 200#define VMCOREINFO_PAGESIZE(value) \ 201 vmcoreinfo_append_str("PAGESIZE=%ld\n", value) 202#define VMCOREINFO_SYMBOL(name) \ 203 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) 204#define VMCOREINFO_SIZE(name) \ 205 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 206 (unsigned long)sizeof(name)) 207#define VMCOREINFO_STRUCT_SIZE(name) \ 208 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 209 (unsigned long)sizeof(struct name)) 210#define VMCOREINFO_OFFSET(name, field) \ 211 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 212 (unsigned long)offsetof(struct name, field)) 213#define VMCOREINFO_LENGTH(name, value) \ 214 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) 215#define VMCOREINFO_NUMBER(name) \ 216 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) 217#define VMCOREINFO_CONFIG(name) \ 218 vmcoreinfo_append_str("CONFIG_%s=y\n", #name) 219 220extern struct kimage *kexec_image; 221extern struct kimage *kexec_crash_image; 222 223#ifndef kexec_flush_icache_page 224#define kexec_flush_icache_page(page) 225#endif 226 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 233 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 240/* Location of a reserved region to hold the crash kernel. 241 */ 242extern struct resource crashk_res; 243typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; 244extern note_buf_t __percpu *crash_notes; 245extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; 246extern size_t vmcoreinfo_size; 247extern size_t vmcoreinfo_max_size; 248 249int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, 250 unsigned long long *crash_size, unsigned long long *crash_base); 251int crash_shrink_memory(unsigned long new_size); 252size_t crash_get_memory_size(void); 253void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); 254 255#else /* !CONFIG_KEXEC */ 256struct pt_regs; 257struct task_struct; 258static inline void crash_kexec(struct pt_regs *regs) { } 259static inline int kexec_should_crash(struct task_struct *p) { return 0; } 260#endif /* CONFIG_KEXEC */ 261#endif /* __KERNEL__ */ 262#endif /* LINUX_KEXEC_H */