d35726d6a415bca10fd44c7fcec34b76241b05f5
[linux-block.git] / include / linux / crash_core.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_CRASH_CORE_H
3 #define LINUX_CRASH_CORE_H
4
5 #include <linux/linkage.h>
6 #include <linux/elfcore.h>
7 #include <linux/elf.h>
8
9 struct kimage;
10
11 struct crash_mem {
12         unsigned int max_nr_ranges;
13         unsigned int nr_ranges;
14         struct range ranges[] __counted_by(max_nr_ranges);
15 };
16
17 #ifdef CONFIG_CRASH_DUMP
18
19 int crash_shrink_memory(unsigned long new_size);
20 ssize_t crash_get_memory_size(void);
21
22 #ifndef arch_kexec_protect_crashkres
23 /*
24  * Protection mechanism for crashkernel reserved memory after
25  * the kdump kernel is loaded.
26  *
27  * Provide an empty default implementation here -- architecture
28  * code may override this
29  */
30 static inline void arch_kexec_protect_crashkres(void) { }
31 #endif
32
33 #ifndef arch_kexec_unprotect_crashkres
34 static inline void arch_kexec_unprotect_crashkres(void) { }
35 #endif
36
37 #ifdef CONFIG_CRASH_DM_CRYPT
38 int crash_load_dm_crypt_keys(struct kimage *image);
39 ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos);
40 #else
41 static inline int crash_load_dm_crypt_keys(struct kimage *image) {return 0; }
42 #endif
43
44 #ifndef arch_crash_handle_hotplug_event
45 static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
46 #endif
47
48 int crash_check_hotplug_support(void);
49
50 #ifndef arch_crash_hotplug_support
51 static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
52 {
53         return 0;
54 }
55 #endif
56
57 #ifndef crash_get_elfcorehdr_size
58 static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; }
59 #endif
60
61 /* Alignment required for elf header segment */
62 #define ELF_CORE_HEADER_ALIGN   4096
63
64 extern int crash_exclude_mem_range(struct crash_mem *mem,
65                                    unsigned long long mstart,
66                                    unsigned long long mend);
67 extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
68                                        void **addr, unsigned long *sz);
69
70 struct kimage;
71 struct kexec_segment;
72
73 #define KEXEC_CRASH_HP_NONE                     0
74 #define KEXEC_CRASH_HP_ADD_CPU                  1
75 #define KEXEC_CRASH_HP_REMOVE_CPU               2
76 #define KEXEC_CRASH_HP_ADD_MEMORY               3
77 #define KEXEC_CRASH_HP_REMOVE_MEMORY            4
78 #define KEXEC_CRASH_HP_INVALID_CPU              -1U
79
80 extern void __crash_kexec(struct pt_regs *regs);
81 extern void crash_kexec(struct pt_regs *regs);
82 int kexec_should_crash(struct task_struct *p);
83 int kexec_crash_loaded(void);
84 void crash_save_cpu(struct pt_regs *regs, int cpu);
85 extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
86
87 #else /* !CONFIG_CRASH_DUMP*/
88 struct pt_regs;
89 struct task_struct;
90 struct kimage;
91 static inline void __crash_kexec(struct pt_regs *regs) { }
92 static inline void crash_kexec(struct pt_regs *regs) { }
93 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
94 static inline int kexec_crash_loaded(void) { return 0; }
95 static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};
96 static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { return 0; };
97 #endif /* CONFIG_CRASH_DUMP*/
98
99 #endif /* LINUX_CRASH_CORE_H */