Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / include / linux / kexec.h
blob07d9aba7556298afc63719fa6af5342884f67811
1 #ifndef LINUX_KEXEC_H
2 #define LINUX_KEXEC_H
4 #ifdef CONFIG_KEXEC
5 #include <linux/types.h>
6 #include <linux/list.h>
7 #include <linux/linkage.h>
8 #include <linux/compat.h>
9 #include <linux/ioport.h>
10 #include <linux/elfcore.h>
11 #include <linux/elf.h>
12 #include <asm/kexec.h>
14 /* Verify architecture specific macros are defined */
16 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
17 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
18 #endif
20 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
21 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
22 #endif
24 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
25 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
26 #endif
28 #ifndef KEXEC_CONTROL_PAGE_SIZE
29 #error KEXEC_CONTROL_PAGE_SIZE not defined
30 #endif
32 #ifndef KEXEC_ARCH
33 #error KEXEC_ARCH not defined
34 #endif
36 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
37 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
38 #endif
40 #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
41 #define KEXEC_CORE_NOTE_NAME "CORE"
42 #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
43 #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
45 * The per-cpu notes area is a list of notes terminated by a "NULL"
46 * note header. For kdump, the code in vmcore.c runs in the context
47 * of the second kernel to combine them into one note.
49 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
50 KEXEC_CORE_NOTE_NAME_BYTES + \
51 KEXEC_CORE_NOTE_DESC_BYTES )
54 * This structure is used to hold the arguments that are used when loading
55 * kernel binaries.
58 typedef unsigned long kimage_entry_t;
59 #define IND_DESTINATION 0x1
60 #define IND_INDIRECTION 0x2
61 #define IND_DONE 0x4
62 #define IND_SOURCE 0x8
64 #define KEXEC_SEGMENT_MAX 16
65 struct kexec_segment {
66 void __user *buf;
67 size_t bufsz;
68 unsigned long mem; /* User space sees this as a (void *) ... */
69 size_t memsz;
72 #ifdef CONFIG_COMPAT
73 struct compat_kexec_segment {
74 compat_uptr_t buf;
75 compat_size_t bufsz;
76 compat_ulong_t mem; /* User space sees this as a (void *) ... */
77 compat_size_t memsz;
79 #endif
81 struct kimage {
82 kimage_entry_t head;
83 kimage_entry_t *entry;
84 kimage_entry_t *last_entry;
86 unsigned long destination;
88 unsigned long start;
89 struct page *control_code_page;
90 struct page *swap_page;
92 unsigned long nr_segments;
93 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
95 struct list_head control_pages;
96 struct list_head dest_pages;
97 struct list_head unuseable_pages;
99 /* Address of next control page to allocate for crash kernels. */
100 unsigned long control_page;
102 /* Flags to indicate special processing */
103 unsigned int type : 1;
104 #define KEXEC_TYPE_DEFAULT 0
105 #define KEXEC_TYPE_CRASH 1
106 unsigned int preserve_context : 1;
108 #ifdef ARCH_HAS_KIMAGE_ARCH
109 struct kimage_arch arch;
110 #endif
115 /* kexec interface functions */
116 extern void machine_kexec(struct kimage *image);
117 extern int machine_kexec_prepare(struct kimage *image);
118 extern void machine_kexec_cleanup(struct kimage *image);
119 extern asmlinkage long sys_kexec_load(unsigned long entry,
120 unsigned long nr_segments,
121 struct kexec_segment __user *segments,
122 unsigned long flags);
123 extern int kernel_kexec(void);
124 #ifdef CONFIG_COMPAT
125 extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
126 unsigned long nr_segments,
127 struct compat_kexec_segment __user *segments,
128 unsigned long flags);
129 #endif
130 extern struct page *kimage_alloc_control_pages(struct kimage *image,
131 unsigned int order);
132 extern void crash_kexec(struct pt_regs *);
133 int kexec_should_crash(struct task_struct *);
134 void crash_save_cpu(struct pt_regs *regs, int cpu);
135 void crash_save_vmcoreinfo(void);
136 void arch_crash_save_vmcoreinfo(void);
137 void vmcoreinfo_append_str(const char *fmt, ...)
138 __attribute__ ((format (printf, 1, 2)));
139 unsigned long paddr_vmcoreinfo_note(void);
141 #define VMCOREINFO_OSRELEASE(value) \
142 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
143 #define VMCOREINFO_PAGESIZE(value) \
144 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
145 #define VMCOREINFO_SYMBOL(name) \
146 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
147 #define VMCOREINFO_SIZE(name) \
148 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
149 (unsigned long)sizeof(name))
150 #define VMCOREINFO_STRUCT_SIZE(name) \
151 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
152 (unsigned long)sizeof(struct name))
153 #define VMCOREINFO_OFFSET(name, field) \
154 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
155 (unsigned long)offsetof(struct name, field))
156 #define VMCOREINFO_LENGTH(name, value) \
157 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
158 #define VMCOREINFO_NUMBER(name) \
159 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
160 #define VMCOREINFO_CONFIG(name) \
161 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
163 extern struct kimage *kexec_image;
164 extern struct kimage *kexec_crash_image;
166 #ifndef kexec_flush_icache_page
167 #define kexec_flush_icache_page(page)
168 #endif
170 #define KEXEC_ON_CRASH 0x00000001
171 #define KEXEC_PRESERVE_CONTEXT 0x00000002
172 #define KEXEC_ARCH_MASK 0xffff0000
174 /* These values match the ELF architecture values.
175 * Unless there is a good reason that should continue to be the case.
177 #define KEXEC_ARCH_DEFAULT ( 0 << 16)
178 #define KEXEC_ARCH_386 ( 3 << 16)
179 #define KEXEC_ARCH_X86_64 (62 << 16)
180 #define KEXEC_ARCH_PPC (20 << 16)
181 #define KEXEC_ARCH_PPC64 (21 << 16)
182 #define KEXEC_ARCH_IA_64 (50 << 16)
183 #define KEXEC_ARCH_ARM (40 << 16)
184 #define KEXEC_ARCH_S390 (22 << 16)
185 #define KEXEC_ARCH_SH (42 << 16)
186 #define KEXEC_ARCH_MIPS_LE (10 << 16)
187 #define KEXEC_ARCH_MIPS ( 8 << 16)
189 /* List of defined/legal kexec flags */
190 #ifndef CONFIG_KEXEC_JUMP
191 #define KEXEC_FLAGS KEXEC_ON_CRASH
192 #else
193 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
194 #endif
196 #define VMCOREINFO_BYTES (4096)
197 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
198 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
199 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
200 + VMCOREINFO_NOTE_NAME_BYTES)
202 /* Location of a reserved region to hold the crash kernel.
204 extern struct resource crashk_res;
205 typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
206 extern note_buf_t __percpu *crash_notes;
207 extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
208 extern size_t vmcoreinfo_size;
209 extern size_t vmcoreinfo_max_size;
211 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
212 unsigned long long *crash_size, unsigned long long *crash_base);
213 int crash_shrink_memory(unsigned long new_size);
214 size_t crash_get_memory_size(void);
215 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
217 #else /* !CONFIG_KEXEC */
218 struct pt_regs;
219 struct task_struct;
220 static inline void crash_kexec(struct pt_regs *regs) { }
221 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
222 #endif /* CONFIG_KEXEC */
223 #endif /* LINUX_KEXEC_H */