4 #include <uapi/linux/kexec.h>
7 #include <linux/list.h>
8 #include <linux/linkage.h>
9 #include <linux/compat.h>
10 #include <linux/ioport.h>
11 #include <linux/elfcore.h>
12 #include <linux/elf.h>
13 #include <asm/kexec.h>
15 /* Verify architecture specific macros are defined */
17 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
18 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
21 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
22 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
25 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
26 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
29 #ifndef KEXEC_CONTROL_PAGE_SIZE
30 #error KEXEC_CONTROL_PAGE_SIZE not defined
34 #error KEXEC_ARCH not defined
37 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
38 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
41 #ifndef KEXEC_CRASH_MEM_ALIGN
42 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
45 #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
46 #define KEXEC_CORE_NOTE_NAME "CORE"
47 #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
48 #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
50 * The per-cpu notes area is a list of notes terminated by a "NULL"
51 * note header. For kdump, the code in vmcore.c runs in the context
52 * of the second kernel to combine them into one note.
54 #ifndef KEXEC_NOTE_BYTES
55 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
56 KEXEC_CORE_NOTE_NAME_BYTES + \
57 KEXEC_CORE_NOTE_DESC_BYTES )
61 * This structure is used to hold the arguments that are used when loading
65 typedef unsigned long kimage_entry_t
;
66 #define IND_DESTINATION 0x1
67 #define IND_INDIRECTION 0x2
69 #define IND_SOURCE 0x8
71 struct kexec_segment
{
79 struct compat_kexec_segment
{
82 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
89 kimage_entry_t
*entry
;
90 kimage_entry_t
*last_entry
;
92 unsigned long destination
;
95 struct page
*control_code_page
;
96 struct page
*swap_page
;
98 unsigned long nr_segments
;
99 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
101 struct list_head control_pages
;
102 struct list_head dest_pages
;
103 struct list_head unuseable_pages
;
105 /* Address of next control page to allocate for crash kernels. */
106 unsigned long control_page
;
108 /* Flags to indicate special processing */
109 unsigned int type
: 1;
110 #define KEXEC_TYPE_DEFAULT 0
111 #define KEXEC_TYPE_CRASH 1
112 unsigned int preserve_context
: 1;
114 #ifdef ARCH_HAS_KIMAGE_ARCH
115 struct kimage_arch arch
;
121 /* kexec interface functions */
122 extern void machine_kexec(struct kimage
*image
);
123 extern int machine_kexec_prepare(struct kimage
*image
);
124 extern void machine_kexec_cleanup(struct kimage
*image
);
125 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
126 unsigned long nr_segments
,
127 struct kexec_segment __user
*segments
,
128 unsigned long flags
);
129 extern int kernel_kexec(void);
130 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
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 crash_map_reserved_pages(void);
137 void crash_unmap_reserved_pages(void);
138 void arch_crash_save_vmcoreinfo(void);
140 void vmcoreinfo_append_str(const char *fmt
, ...);
141 unsigned long paddr_vmcoreinfo_note(void);
143 #define VMCOREINFO_OSRELEASE(value) \
144 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
145 #define VMCOREINFO_PAGESIZE(value) \
146 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
147 #define VMCOREINFO_SYMBOL(name) \
148 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
149 #define VMCOREINFO_SIZE(name) \
150 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
151 (unsigned long)sizeof(name))
152 #define VMCOREINFO_STRUCT_SIZE(name) \
153 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
154 (unsigned long)sizeof(struct name))
155 #define VMCOREINFO_OFFSET(name, field) \
156 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
157 (unsigned long)offsetof(struct name, field))
158 #define VMCOREINFO_LENGTH(name, value) \
159 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
160 #define VMCOREINFO_NUMBER(name) \
161 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
162 #define VMCOREINFO_CONFIG(name) \
163 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
165 extern struct kimage
*kexec_image
;
166 extern struct kimage
*kexec_crash_image
;
167 extern int kexec_load_disabled
;
169 #ifndef kexec_flush_icache_page
170 #define kexec_flush_icache_page(page)
173 /* List of defined/legal kexec flags */
174 #ifndef CONFIG_KEXEC_JUMP
175 #define KEXEC_FLAGS KEXEC_ON_CRASH
177 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
180 #define VMCOREINFO_BYTES (4096)
181 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
182 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
183 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
184 + VMCOREINFO_NOTE_NAME_BYTES)
186 /* Location of a reserved region to hold the crash kernel.
188 extern struct resource crashk_res
;
189 extern struct resource crashk_low_res
;
190 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
191 extern note_buf_t __percpu
*crash_notes
;
192 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
193 extern size_t vmcoreinfo_size
;
194 extern size_t vmcoreinfo_max_size
;
196 /* flag to track if kexec reboot is in progress */
197 extern bool kexec_in_progress
;
199 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
200 unsigned long long *crash_size
, unsigned long long *crash_base
);
201 int parse_crashkernel_high(char *cmdline
, unsigned long long system_ram
,
202 unsigned long long *crash_size
, unsigned long long *crash_base
);
203 int parse_crashkernel_low(char *cmdline
, unsigned long long system_ram
,
204 unsigned long long *crash_size
, unsigned long long *crash_base
);
205 int crash_shrink_memory(unsigned long new_size
);
206 size_t crash_get_memory_size(void);
207 void crash_free_reserved_phys_range(unsigned long begin
, unsigned long end
);
209 #else /* !CONFIG_KEXEC */
212 static inline void crash_kexec(struct pt_regs
*regs
) { }
213 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
214 #endif /* CONFIG_KEXEC */
215 #endif /* LINUX_KEXEC_H */