1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_KEXEC_H 3 #define _ASM_POWERPC_KEXEC_H 4 #ifdef __KERNEL__ 5 6 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_44x) 7 8 /* 9 * On FSL-BookE we setup a 1:1 mapping which covers the first 2GiB of memory 10 * and therefore we can only deal with memory within this range 11 */ 12 #define KEXEC_SOURCE_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1) 13 #define KEXEC_DESTINATION_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1) 14 #define KEXEC_CONTROL_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1) 15 16 #else 17 18 /* 19 * Maximum page that is mapped directly into kernel memory. 20 * XXX: Since we copy virt we can use any page we allocate 21 */ 22 #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) 23 24 /* 25 * Maximum address we can reach in physical address mode. 26 * XXX: I want to allow initrd in highmem. Otherwise set to rmo on LPAR. 27 */ 28 #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) 29 30 /* Maximum address we can use for the control code buffer */ 31 #ifdef __powerpc64__ 32 #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL) 33 #else 34 /* TASK_SIZE, probably left over from use_mm ?? */ 35 #define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE 36 #endif 37 #endif 38 39 #define KEXEC_CONTROL_PAGE_SIZE 4096 40 41 /* The native architecture */ 42 #ifdef __powerpc64__ 43 #define KEXEC_ARCH KEXEC_ARCH_PPC64 44 #else 45 #define KEXEC_ARCH KEXEC_ARCH_PPC 46 #endif 47 48 #define KEXEC_STATE_NONE 0 49 #define KEXEC_STATE_IRQS_OFF 1 50 #define KEXEC_STATE_REAL_MODE 2 51 52 #ifndef __ASSEMBLER__ 53 #include <asm/reg.h> 54 55 typedef void (*crash_shutdown_t)(void); 56 57 #ifdef CONFIG_KEXEC_CORE 58 struct kimage; 59 struct pt_regs; 60 61 extern void kexec_smp_wait(void); /* get and clear naca physid, wait for 62 master to copy new code to 0 */ 63 extern void default_machine_kexec(struct kimage *image); 64 65 void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_code_buffer, 66 unsigned long start_address) __noreturn; 67 void kexec_copy_flush(struct kimage *image); 68 69 70 #if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP) 71 #define ARCH_HAS_KIMAGE_ARCH 72 struct kimage_arch { 73 struct crash_mem *exclude_ranges; 74 75 unsigned long backup_start; 76 void *backup_buf; 77 void *fdt; 78 }; 79 #endif 80 81 #ifdef CONFIG_KEXEC_FILE 82 extern const struct kexec_file_ops kexec_elf64_ops; 83 84 char *setup_kdump_cmdline(struct kimage *image, char *cmdline, 85 unsigned long cmdline_len); 86 int setup_purgatory(struct kimage *image, const void *slave_code, 87 const void *fdt, unsigned long kernel_load_addr, 88 unsigned long fdt_load_addr); 89 90 #ifdef CONFIG_PPC64 91 struct kexec_buf; 92 93 int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len); 94 #define arch_kexec_kernel_image_probe arch_kexec_kernel_image_probe 95 96 int arch_kimage_file_post_load_cleanup(struct kimage *image); 97 #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup 98 99 int arch_check_excluded_range(struct kimage *image, unsigned long start, 100 unsigned long end); 101 #define arch_check_excluded_range arch_check_excluded_range 102 103 104 int load_crashdump_segments_ppc64(struct kimage *image, 105 struct kexec_buf *kbuf); 106 int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, 107 const void *fdt, unsigned long kernel_load_addr, 108 unsigned long fdt_load_addr); 109 unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image, struct crash_mem *rmem); 110 int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, struct crash_mem *rmem); 111 #endif /* CONFIG_PPC64 */ 112 113 #endif /* CONFIG_KEXEC_FILE */ 114 115 #endif /* CONFIG_KEXEC_CORE */ 116 117 #ifdef CONFIG_CRASH_RESERVE 118 int __init overlaps_crashkernel(unsigned long start, unsigned long size); 119 extern void arch_reserve_crashkernel(void); 120 extern void kdump_cma_reserve(void); 121 #else 122 static inline void arch_reserve_crashkernel(void) {} 123 static inline int overlaps_crashkernel(unsigned long start, unsigned long size) { return 0; } 124 static inline void kdump_cma_reserve(void) { } 125 #endif 126 127 #if defined(CONFIG_CRASH_DUMP) 128 /* 129 * This function is responsible for capturing register states if coming 130 * via panic or invoking dump using sysrq-trigger. 131 */ 132 static inline void crash_setup_regs(struct pt_regs *newregs, 133 struct pt_regs *oldregs) 134 { 135 if (oldregs) 136 memcpy(newregs, oldregs, sizeof(*newregs)); 137 else 138 ppc_save_regs(newregs); 139 } 140 141 #ifdef CONFIG_CRASH_HOTPLUG 142 void arch_crash_handle_hotplug_event(struct kimage *image, void *arg); 143 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event 144 145 int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags); 146 #define arch_crash_hotplug_support arch_crash_hotplug_support 147 148 unsigned int arch_crash_get_elfcorehdr_size(void); 149 #define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size 150 151 int machine_kexec_post_load(struct kimage *image); 152 #define machine_kexec_post_load machine_kexec_post_load 153 154 #endif /* CONFIG_CRASH_HOTPLUG */ 155 156 extern int crashing_cpu; 157 extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *)); 158 extern void crash_ipi_callback(struct pt_regs *regs); 159 extern int crash_wake_offline; 160 161 extern int crash_shutdown_register(crash_shutdown_t handler); 162 extern int crash_shutdown_unregister(crash_shutdown_t handler); 163 extern void default_machine_crash_shutdown(struct pt_regs *regs); 164 165 extern void crash_kexec_prepare(void); 166 extern void crash_kexec_secondary(struct pt_regs *regs); 167 168 extern void sync_backup_region_phdr(struct kimage *image, Elf64_Ehdr *ehdr, 169 bool phdr_to_kimage); 170 static inline bool kdump_in_progress(void) 171 { 172 return crashing_cpu >= 0; 173 } 174 175 bool is_kdump_kernel(void); 176 #define is_kdump_kernel is_kdump_kernel 177 #if defined(CONFIG_PPC_RTAS) 178 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); 179 #define crash_free_reserved_phys_range crash_free_reserved_phys_range 180 #endif /* CONFIG_PPC_RTAS */ 181 182 #else /* !CONFIG_CRASH_DUMP */ 183 static inline void crash_kexec_secondary(struct pt_regs *regs) { } 184 185 static inline int crash_shutdown_register(crash_shutdown_t handler) 186 { 187 return 0; 188 } 189 190 static inline int crash_shutdown_unregister(crash_shutdown_t handler) 191 { 192 return 0; 193 } 194 195 static inline bool kdump_in_progress(void) 196 { 197 return false; 198 } 199 200 static inline void crash_ipi_callback(struct pt_regs *regs) { } 201 202 static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *)) 203 { 204 } 205 206 #endif /* CONFIG_CRASH_DUMP */ 207 208 #if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP) 209 int update_cpus_node(void *fdt); 210 #endif 211 212 #ifdef CONFIG_PPC_BOOK3S_64 213 #include <asm/book3s/64/kexec.h> 214 #endif 215 216 #ifndef reset_sprs 217 #define reset_sprs reset_sprs 218 static inline void reset_sprs(void) 219 { 220 } 221 #endif 222 223 #endif /* ! __ASSEMBLER__ */ 224 #endif /* __KERNEL__ */ 225 #endif /* _ASM_POWERPC_KEXEC_H */ 226