Merge branch 'akpm' (Andrew's incoming)
[pandora-kernel.git] / include / linux / kexec.h
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>
9 #include <linux/ioport.h>
10 #include <linux/elfcore.h>
11 #include <linux/elf.h>
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_PAGE_SIZE
29 #error KEXEC_CONTROL_PAGE_SIZE not defined
30 #endif
31
32 #ifndef KEXEC_ARCH
33 #error KEXEC_ARCH not defined
34 #endif
35
36 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
37 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
38 #endif
39
40 #ifndef KEXEC_CRASH_MEM_ALIGN
41 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
42 #endif
43
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  */
53 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) +                \
54                             KEXEC_CORE_NOTE_NAME_BYTES +                \
55                             KEXEC_CORE_NOTE_DESC_BYTES )
56
57 /*
58  * This structure is used to hold the arguments that are used when loading
59  * kernel binaries.
60  */
61
62 typedef unsigned long kimage_entry_t;
63 #define IND_DESTINATION  0x1
64 #define IND_INDIRECTION  0x2
65 #define IND_DONE         0x4
66 #define IND_SOURCE       0x8
67
68 #define KEXEC_SEGMENT_MAX 16
69 struct kexec_segment {
70         void __user *buf;
71         size_t bufsz;
72         unsigned long mem;      /* User space sees this as a (void *) ... */
73         size_t memsz;
74 };
75
76 #ifdef CONFIG_COMPAT
77 struct compat_kexec_segment {
78         compat_uptr_t buf;
79         compat_size_t bufsz;
80         compat_ulong_t mem;     /* User space sees this as a (void *) ... */
81         compat_size_t memsz;
82 };
83 #endif
84
85 struct kimage {
86         kimage_entry_t head;
87         kimage_entry_t *entry;
88         kimage_entry_t *last_entry;
89
90         unsigned long destination;
91
92         unsigned long start;
93         struct page *control_code_page;
94         struct page *swap_page;
95
96         unsigned long nr_segments;
97         struct kexec_segment segment[KEXEC_SEGMENT_MAX];
98
99         struct list_head control_pages;
100         struct list_head dest_pages;
101         struct list_head unuseable_pages;
102
103         /* Address of next control page to allocate for crash kernels. */
104         unsigned long control_page;
105
106         /* Flags to indicate special processing */
107         unsigned int type : 1;
108 #define KEXEC_TYPE_DEFAULT 0
109 #define KEXEC_TYPE_CRASH   1
110         unsigned int preserve_context : 1;
111
112 #ifdef ARCH_HAS_KIMAGE_ARCH
113         struct kimage_arch arch;
114 #endif
115 };
116
117
118
119 /* kexec interface functions */
120 extern void machine_kexec(struct kimage *image);
121 extern int machine_kexec_prepare(struct kimage *image);
122 extern void machine_kexec_cleanup(struct kimage *image);
123 extern asmlinkage long sys_kexec_load(unsigned long entry,
124                                         unsigned long nr_segments,
125                                         struct kexec_segment __user *segments,
126                                         unsigned long flags);
127 extern int kernel_kexec(void);
128 #ifdef CONFIG_COMPAT
129 extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
130                                 unsigned long nr_segments,
131                                 struct compat_kexec_segment __user *segments,
132                                 unsigned long flags);
133 #endif
134 extern struct page *kimage_alloc_control_pages(struct kimage *image,
135                                                 unsigned int order);
136 extern void crash_kexec(struct pt_regs *);
137 int kexec_should_crash(struct task_struct *);
138 void crash_save_cpu(struct pt_regs *regs, int cpu);
139 void crash_save_vmcoreinfo(void);
140 void crash_map_reserved_pages(void);
141 void crash_unmap_reserved_pages(void);
142 void arch_crash_save_vmcoreinfo(void);
143 __printf(1, 2)
144 void vmcoreinfo_append_str(const char *fmt, ...);
145 unsigned long paddr_vmcoreinfo_note(void);
146
147 #define VMCOREINFO_OSRELEASE(value) \
148         vmcoreinfo_append_str("OSRELEASE=%s\n", value)
149 #define VMCOREINFO_PAGESIZE(value) \
150         vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
151 #define VMCOREINFO_SYMBOL(name) \
152         vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
153 #define VMCOREINFO_SIZE(name) \
154         vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
155                               (unsigned long)sizeof(name))
156 #define VMCOREINFO_STRUCT_SIZE(name) \
157         vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
158                               (unsigned long)sizeof(struct name))
159 #define VMCOREINFO_OFFSET(name, field) \
160         vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
161                               (unsigned long)offsetof(struct name, field))
162 #define VMCOREINFO_LENGTH(name, value) \
163         vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
164 #define VMCOREINFO_NUMBER(name) \
165         vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
166 #define VMCOREINFO_CONFIG(name) \
167         vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
168
169 extern struct kimage *kexec_image;
170 extern struct kimage *kexec_crash_image;
171
172 #ifndef kexec_flush_icache_page
173 #define kexec_flush_icache_page(page)
174 #endif
175
176 #define KEXEC_ON_CRASH          0x00000001
177 #define KEXEC_PRESERVE_CONTEXT  0x00000002
178 #define KEXEC_ARCH_MASK         0xffff0000
179
180 /* These values match the ELF architecture values.
181  * Unless there is a good reason that should continue to be the case.
182  */
183 #define KEXEC_ARCH_DEFAULT ( 0 << 16)
184 #define KEXEC_ARCH_386     ( 3 << 16)
185 #define KEXEC_ARCH_X86_64  (62 << 16)
186 #define KEXEC_ARCH_PPC     (20 << 16)
187 #define KEXEC_ARCH_PPC64   (21 << 16)
188 #define KEXEC_ARCH_IA_64   (50 << 16)
189 #define KEXEC_ARCH_ARM     (40 << 16)
190 #define KEXEC_ARCH_S390    (22 << 16)
191 #define KEXEC_ARCH_SH      (42 << 16)
192 #define KEXEC_ARCH_MIPS_LE (10 << 16)
193 #define KEXEC_ARCH_MIPS    ( 8 << 16)
194
195 /* List of defined/legal kexec flags */
196 #ifndef CONFIG_KEXEC_JUMP
197 #define KEXEC_FLAGS    KEXEC_ON_CRASH
198 #else
199 #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
200 #endif
201
202 #define VMCOREINFO_BYTES           (4096)
203 #define VMCOREINFO_NOTE_NAME       "VMCOREINFO"
204 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
205 #define VMCOREINFO_NOTE_SIZE       (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
206                                     + VMCOREINFO_NOTE_NAME_BYTES)
207
208 /* Location of a reserved region to hold the crash kernel.
209  */
210 extern struct resource crashk_res;
211 typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
212 extern note_buf_t __percpu *crash_notes;
213 extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
214 extern size_t vmcoreinfo_size;
215 extern size_t vmcoreinfo_max_size;
216
217 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
218                 unsigned long long *crash_size, unsigned long long *crash_base);
219 int crash_shrink_memory(unsigned long new_size);
220 size_t crash_get_memory_size(void);
221 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
222
223 #else /* !CONFIG_KEXEC */
224 struct pt_regs;
225 struct task_struct;
226 static inline void crash_kexec(struct pt_regs *regs) { }
227 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
228 #endif /* CONFIG_KEXEC */
229 #endif /* LINUX_KEXEC_H */