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 #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)
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.
45 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
46 KEXEC_CORE_NOTE_NAME_BYTES + \
47 KEXEC_CORE_NOTE_DESC_BYTES )
50 * This structure is used to hold the arguments that are used when loading
54 typedef unsigned long kimage_entry_t
;
55 #define IND_DESTINATION 0x1
56 #define IND_INDIRECTION 0x2
58 #define IND_SOURCE 0x8
60 #define KEXEC_SEGMENT_MAX 16
61 struct kexec_segment
{
64 unsigned long mem
; /* User space sees this as a (void *) ... */
69 struct compat_kexec_segment
{
72 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
79 kimage_entry_t
*entry
;
80 kimage_entry_t
*last_entry
;
82 unsigned long destination
;
85 struct page
*control_code_page
;
86 struct page
*swap_page
;
88 unsigned long nr_segments
;
89 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
91 struct list_head control_pages
;
92 struct list_head dest_pages
;
93 struct list_head unuseable_pages
;
95 /* Address of next control page to allocate for crash kernels. */
96 unsigned long control_page
;
98 /* Flags to indicate special processing */
99 unsigned int type
: 1;
100 #define KEXEC_TYPE_DEFAULT 0
101 #define KEXEC_TYPE_CRASH 1
102 unsigned int preserve_context
: 1;
107 /* kexec interface functions */
108 extern void machine_kexec(struct kimage
*image
);
109 extern int machine_kexec_prepare(struct kimage
*image
);
110 extern void machine_kexec_cleanup(struct kimage
*image
);
111 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
112 unsigned long nr_segments
,
113 struct kexec_segment __user
*segments
,
114 unsigned long flags
);
115 extern int kernel_kexec(void);
117 extern asmlinkage
long compat_sys_kexec_load(unsigned long entry
,
118 unsigned long nr_segments
,
119 struct compat_kexec_segment __user
*segments
,
120 unsigned long flags
);
122 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
124 extern void crash_kexec(struct pt_regs
*);
125 int kexec_should_crash(struct task_struct
*);
126 void crash_save_cpu(struct pt_regs
*regs
, int cpu
);
127 void crash_save_vmcoreinfo(void);
128 void arch_crash_save_vmcoreinfo(void);
129 void vmcoreinfo_append_str(const char *fmt
, ...)
130 __attribute__ ((format (printf
, 1, 2)));
131 unsigned long paddr_vmcoreinfo_note(void);
133 #define VMCOREINFO_OSRELEASE(value) \
134 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
135 #define VMCOREINFO_PAGESIZE(value) \
136 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
137 #define VMCOREINFO_SYMBOL(name) \
138 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
139 #define VMCOREINFO_SIZE(name) \
140 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
141 (unsigned long)sizeof(name))
142 #define VMCOREINFO_STRUCT_SIZE(name) \
143 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
144 (unsigned long)sizeof(struct name))
145 #define VMCOREINFO_OFFSET(name, field) \
146 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
147 (unsigned long)offsetof(struct name, field))
148 #define VMCOREINFO_LENGTH(name, value) \
149 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
150 #define VMCOREINFO_NUMBER(name) \
151 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
152 #define VMCOREINFO_CONFIG(name) \
153 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
155 extern struct kimage
*kexec_image
;
156 extern struct kimage
*kexec_crash_image
;
158 #ifndef kexec_flush_icache_page
159 #define kexec_flush_icache_page(page)
162 #define KEXEC_ON_CRASH 0x00000001
163 #define KEXEC_PRESERVE_CONTEXT 0x00000002
164 #define KEXEC_ARCH_MASK 0xffff0000
166 /* These values match the ELF architecture values.
167 * Unless there is a good reason that should continue to be the case.
169 #define KEXEC_ARCH_DEFAULT ( 0 << 16)
170 #define KEXEC_ARCH_386 ( 3 << 16)
171 #define KEXEC_ARCH_X86_64 (62 << 16)
172 #define KEXEC_ARCH_PPC (20 << 16)
173 #define KEXEC_ARCH_PPC64 (21 << 16)
174 #define KEXEC_ARCH_IA_64 (50 << 16)
175 #define KEXEC_ARCH_ARM (40 << 16)
176 #define KEXEC_ARCH_S390 (22 << 16)
177 #define KEXEC_ARCH_SH (42 << 16)
178 #define KEXEC_ARCH_MIPS_LE (10 << 16)
179 #define KEXEC_ARCH_MIPS ( 8 << 16)
181 /* List of defined/legal kexec flags */
182 #ifndef CONFIG_KEXEC_JUMP
183 #define KEXEC_FLAGS KEXEC_ON_CRASH
185 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
188 #define VMCOREINFO_BYTES (4096)
189 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
190 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
191 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
192 + VMCOREINFO_NOTE_NAME_BYTES)
194 /* Location of a reserved region to hold the crash kernel.
196 extern struct resource crashk_res
;
197 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
198 extern note_buf_t
*crash_notes
;
199 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
200 extern size_t vmcoreinfo_size
;
201 extern size_t vmcoreinfo_max_size
;
203 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
204 unsigned long long *crash_size
, unsigned long long *crash_base
);
206 #else /* !CONFIG_KEXEC */
209 static inline void crash_kexec(struct pt_regs
*regs
) { }
210 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
211 #endif /* CONFIG_KEXEC */
212 #endif /* LINUX_KEXEC_H */