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