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
20 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
21 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
24 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
25 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
28 #ifndef KEXEC_CONTROL_PAGE_SIZE
29 #error KEXEC_CONTROL_PAGE_SIZE not defined
33 #error KEXEC_ARCH not defined
36 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
37 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
40 #ifndef KEXEC_CRASH_MEM_ALIGN
41 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
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)
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.
53 #ifndef KEXEC_NOTE_BYTES
54 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
55 KEXEC_CORE_NOTE_NAME_BYTES + \
56 KEXEC_CORE_NOTE_DESC_BYTES )
59 #ifndef KEXEC_ARCH_HAS_PAGE_MACROS
60 #define kexec_page_to_pfn(page) page_to_pfn(page)
61 #define kexec_pfn_to_page(pfn) pfn_to_page(pfn)
62 #define kexec_virt_to_phys(addr) virt_to_phys(addr)
63 #define kexec_phys_to_virt(addr) phys_to_virt(addr)
67 * This structure is used to hold the arguments that are used when loading
71 typedef unsigned long kimage_entry_t;
72 #define IND_DESTINATION 0x1
73 #define IND_INDIRECTION 0x2
75 #define IND_SOURCE 0x8
77 #define KEXEC_SEGMENT_MAX 16
78 struct kexec_segment {
81 unsigned long mem; /* User space sees this as a (void *) ... */
86 struct compat_kexec_segment {
89 compat_ulong_t mem; /* User space sees this as a (void *) ... */
96 kimage_entry_t *entry;
97 kimage_entry_t *last_entry;
99 unsigned long destination;
102 struct page *control_code_page;
103 struct page *swap_page;
105 unsigned long nr_segments;
106 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
108 struct list_head control_pages;
109 struct list_head dest_pages;
110 struct list_head unuseable_pages;
112 /* Address of next control page to allocate for crash kernels. */
113 unsigned long control_page;
115 /* Flags to indicate special processing */
116 unsigned int type : 1;
117 #define KEXEC_TYPE_DEFAULT 0
118 #define KEXEC_TYPE_CRASH 1
119 unsigned int preserve_context : 1;
121 #ifdef ARCH_HAS_KIMAGE_ARCH
122 struct kimage_arch arch;
128 /* kexec interface functions */
129 extern void machine_kexec(struct kimage *image);
130 extern int machine_kexec_prepare(struct kimage *image);
131 extern void machine_kexec_cleanup(struct kimage *image);
133 extern int xen_machine_kexec_load(struct kimage *image);
134 extern void xen_machine_kexec_unload(struct kimage *image);
135 extern void xen_machine_kexec_setup_resources(void);
136 extern void xen_machine_kexec_register_resources(struct resource *res);
138 extern asmlinkage long sys_kexec_load(unsigned long entry,
139 unsigned long nr_segments,
140 struct kexec_segment __user *segments,
141 unsigned long flags);
142 extern int kernel_kexec(void);
144 extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
145 unsigned long nr_segments,
146 struct compat_kexec_segment __user *segments,
147 unsigned long flags);
149 extern struct page *kimage_alloc_control_pages(struct kimage *image,
151 extern void crash_kexec(struct pt_regs *);
152 int kexec_should_crash(struct task_struct *);
153 void crash_save_cpu(struct pt_regs *regs, int cpu);
154 void crash_save_vmcoreinfo(void);
155 void crash_map_reserved_pages(void);
156 void crash_unmap_reserved_pages(void);
157 void arch_crash_save_vmcoreinfo(void);
159 void vmcoreinfo_append_str(const char *fmt, ...);
160 unsigned long paddr_vmcoreinfo_note(void);
162 #define VMCOREINFO_OSRELEASE(value) \
163 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
164 #define VMCOREINFO_PAGESIZE(value) \
165 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
166 #define VMCOREINFO_SYMBOL(name) \
167 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
168 #define VMCOREINFO_SIZE(name) \
169 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
170 (unsigned long)sizeof(name))
171 #define VMCOREINFO_STRUCT_SIZE(name) \
172 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
173 (unsigned long)sizeof(struct name))
174 #define VMCOREINFO_OFFSET(name, field) \
175 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
176 (unsigned long)offsetof(struct name, field))
177 #define VMCOREINFO_LENGTH(name, value) \
178 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
179 #define VMCOREINFO_NUMBER(name) \
180 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
181 #define VMCOREINFO_CONFIG(name) \
182 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
184 extern struct kimage *kexec_image;
185 extern struct kimage *kexec_crash_image;
187 #ifndef kexec_flush_icache_page
188 #define kexec_flush_icache_page(page)
191 #define KEXEC_ON_CRASH 0x00000001
192 #define KEXEC_PRESERVE_CONTEXT 0x00000002
193 #define KEXEC_ARCH_MASK 0xffff0000
195 /* These values match the ELF architecture values.
196 * Unless there is a good reason that should continue to be the case.
198 #define KEXEC_ARCH_DEFAULT ( 0 << 16)
199 #define KEXEC_ARCH_386 ( 3 << 16)
200 #define KEXEC_ARCH_X86_64 (62 << 16)
201 #define KEXEC_ARCH_PPC (20 << 16)
202 #define KEXEC_ARCH_PPC64 (21 << 16)
203 #define KEXEC_ARCH_IA_64 (50 << 16)
204 #define KEXEC_ARCH_ARM (40 << 16)
205 #define KEXEC_ARCH_S390 (22 << 16)
206 #define KEXEC_ARCH_SH (42 << 16)
207 #define KEXEC_ARCH_MIPS_LE (10 << 16)
208 #define KEXEC_ARCH_MIPS ( 8 << 16)
210 /* List of defined/legal kexec flags */
211 #ifndef CONFIG_KEXEC_JUMP
212 #define KEXEC_FLAGS KEXEC_ON_CRASH
214 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
217 #define VMCOREINFO_BYTES (4096)
218 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
219 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
220 #if !defined(CONFIG_XEN) || !defined(CONFIG_X86)
221 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
222 + VMCOREINFO_NOTE_NAME_BYTES)
224 #define VMCOREINFO_NOTE_SIZE ALIGN(KEXEC_NOTE_HEAD_BYTES*2 \
226 + VMCOREINFO_NOTE_NAME_BYTES, \
230 /* Location of a reserved region to hold the crash kernel.
232 extern struct resource crashk_res;
233 typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
234 extern note_buf_t __percpu *crash_notes;
235 extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
236 extern size_t vmcoreinfo_size;
237 extern size_t vmcoreinfo_max_size;
239 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
240 unsigned long long *crash_size, unsigned long long *crash_base);
241 int crash_shrink_memory(unsigned long new_size);
242 size_t crash_get_memory_size(void);
243 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
245 #else /* !CONFIG_KEXEC */
248 static inline void crash_kexec(struct pt_regs *regs) { }
249 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
250 #endif /* CONFIG_KEXEC */
251 #endif /* LINUX_KEXEC_H */