1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_KEXEC_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_KEXEC_H
4b8b572e1SStephen Rothwell #ifdef __KERNEL__
5b8b572e1SStephen Rothwell
6*dfc3095cSChristophe Leroy #if defined(CONFIG_PPC_85xx) || defined(CONFIG_44x)
7b3df895aSSebastian Andrzej Siewior
8b3df895aSSebastian Andrzej Siewior /*
9b3df895aSSebastian Andrzej Siewior * On FSL-BookE we setup a 1:1 mapping which covers the first 2GiB of memory
10b3df895aSSebastian Andrzej Siewior * and therefore we can only deal with memory within this range
11b3df895aSSebastian Andrzej Siewior */
1223dcab8fSKumar Gala #define KEXEC_SOURCE_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1)
1323dcab8fSKumar Gala #define KEXEC_DESTINATION_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1)
1423dcab8fSKumar Gala #define KEXEC_CONTROL_MEMORY_LIMIT (2 * 1024 * 1024 * 1024UL - 1)
15b3df895aSSebastian Andrzej Siewior
16b3df895aSSebastian Andrzej Siewior #else
17b3df895aSSebastian Andrzej Siewior
18b8b572e1SStephen Rothwell /*
19b8b572e1SStephen Rothwell * Maximum page that is mapped directly into kernel memory.
20b8b572e1SStephen Rothwell * XXX: Since we copy virt we can use any page we allocate
21b8b572e1SStephen Rothwell */
22b8b572e1SStephen Rothwell #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
23b8b572e1SStephen Rothwell
24b8b572e1SStephen Rothwell /*
25b8b572e1SStephen Rothwell * Maximum address we can reach in physical address mode.
26b8b572e1SStephen Rothwell * XXX: I want to allow initrd in highmem. Otherwise set to rmo on LPAR.
27b8b572e1SStephen Rothwell */
28b8b572e1SStephen Rothwell #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
29b8b572e1SStephen Rothwell
30b8b572e1SStephen Rothwell /* Maximum address we can use for the control code buffer */
31b8b572e1SStephen Rothwell #ifdef __powerpc64__
32b8b572e1SStephen Rothwell #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
33b8b572e1SStephen Rothwell #else
34b8b572e1SStephen Rothwell /* TASK_SIZE, probably left over from use_mm ?? */
35b8b572e1SStephen Rothwell #define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
36b8b572e1SStephen Rothwell #endif
37b3df895aSSebastian Andrzej Siewior #endif
38b8b572e1SStephen Rothwell
39163f6876SHuang Ying #define KEXEC_CONTROL_PAGE_SIZE 4096
40b8b572e1SStephen Rothwell
41b8b572e1SStephen Rothwell /* The native architecture */
42b8b572e1SStephen Rothwell #ifdef __powerpc64__
43b8b572e1SStephen Rothwell #define KEXEC_ARCH KEXEC_ARCH_PPC64
44b8b572e1SStephen Rothwell #else
45b8b572e1SStephen Rothwell #define KEXEC_ARCH KEXEC_ARCH_PPC
46b8b572e1SStephen Rothwell #endif
47b8b572e1SStephen Rothwell
481fc711f7SMichael Neuling #define KEXEC_STATE_NONE 0
491fc711f7SMichael Neuling #define KEXEC_STATE_IRQS_OFF 1
501fc711f7SMichael Neuling #define KEXEC_STATE_REAL_MODE 2
511fc711f7SMichael Neuling
52b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
5373753313SAnton Vorontsov #include <asm/reg.h>
54b8b572e1SStephen Rothwell
55b8b572e1SStephen Rothwell typedef void (*crash_shutdown_t)(void);
56b8b572e1SStephen Rothwell
57da665885SThiago Jung Bauermann #ifdef CONFIG_KEXEC_CORE
58b8b572e1SStephen Rothwell
59b8b572e1SStephen Rothwell /*
60b8b572e1SStephen Rothwell * This function is responsible for capturing register states if coming
61b8b572e1SStephen Rothwell * via panic or invoking dump using sysrq-trigger.
62b8b572e1SStephen Rothwell */
crash_setup_regs(struct pt_regs * newregs,struct pt_regs * oldregs)63b8b572e1SStephen Rothwell static inline void crash_setup_regs(struct pt_regs *newregs,
64b8b572e1SStephen Rothwell struct pt_regs *oldregs)
65b8b572e1SStephen Rothwell {
66b8b572e1SStephen Rothwell if (oldregs)
67b8b572e1SStephen Rothwell memcpy(newregs, oldregs, sizeof(*newregs));
6873753313SAnton Vorontsov else
6973753313SAnton Vorontsov ppc_save_regs(newregs);
7073753313SAnton Vorontsov }
71b8b572e1SStephen Rothwell
72b8b572e1SStephen Rothwell extern void kexec_smp_wait(void); /* get and clear naca physid, wait for
73b8b572e1SStephen Rothwell master to copy new code to 0 */
74b8b572e1SStephen Rothwell extern int crashing_cpu;
75b8b572e1SStephen Rothwell extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
764145f358SBalbir Singh extern void crash_ipi_callback(struct pt_regs *);
774145f358SBalbir Singh extern int crash_wake_offline;
78b8b572e1SStephen Rothwell
79b8b572e1SStephen Rothwell struct kimage;
80b8b572e1SStephen Rothwell struct pt_regs;
81b8b572e1SStephen Rothwell extern void default_machine_kexec(struct kimage *image);
82b8b572e1SStephen Rothwell extern void default_machine_crash_shutdown(struct pt_regs *regs);
83b8b572e1SStephen Rothwell extern int crash_shutdown_register(crash_shutdown_t handler);
84b8b572e1SStephen Rothwell extern int crash_shutdown_unregister(crash_shutdown_t handler);
85b8b572e1SStephen Rothwell
86c7255058SHari Bathini extern void crash_kexec_prepare(void);
87b8b572e1SStephen Rothwell extern void crash_kexec_secondary(struct pt_regs *regs);
88d276960dSNick Child int __init overlaps_crashkernel(unsigned long start, unsigned long size);
89b8b572e1SStephen Rothwell extern void reserve_crashkernel(void);
90c71635d2SMatthew McClintock extern void machine_kexec_mask_interrupts(void);
91b8b572e1SStephen Rothwell
kdump_in_progress(void)92c1caae3dSHari Bathini static inline bool kdump_in_progress(void)
93c1caae3dSHari Bathini {
94c1caae3dSHari Bathini return crashing_cpu >= 0;
95c1caae3dSHari Bathini }
96c1caae3dSHari Bathini
976c284228SChristophe Leroy void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_code_buffer,
986c284228SChristophe Leroy unsigned long start_address) __noreturn;
996c284228SChristophe Leroy
10076222808SChristophe Leroy void kexec_copy_flush(struct kimage *image);
10176222808SChristophe Leroy
1020738ecebSNaveen N. Rao #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PPC_RTAS)
1030738ecebSNaveen N. Rao void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
1040738ecebSNaveen N. Rao #define crash_free_reserved_phys_range crash_free_reserved_phys_range
1050738ecebSNaveen N. Rao #endif
1060738ecebSNaveen N. Rao
107a0458284SThiago Jung Bauermann #ifdef CONFIG_KEXEC_FILE
1089ec4ecefSAKASHI Takahiro extern const struct kexec_file_ops kexec_elf64_ops;
109a0458284SThiago Jung Bauermann
110ab6b1d1fSThiago Jung Bauermann #define ARCH_HAS_KIMAGE_ARCH
111ab6b1d1fSThiago Jung Bauermann
112ab6b1d1fSThiago Jung Bauermann struct kimage_arch {
113b8e55a3eSHari Bathini struct crash_mem *exclude_ranges;
114b8e55a3eSHari Bathini
1151a1cf93cSHari Bathini unsigned long backup_start;
1161a1cf93cSHari Bathini void *backup_buf;
1173c985d31SRob Herring void *fdt;
118b8e55a3eSHari Bathini };
119ab6b1d1fSThiago Jung Bauermann
120cb350c1fSHari Bathini char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
121cb350c1fSHari Bathini unsigned long cmdline_len);
122a0458284SThiago Jung Bauermann int setup_purgatory(struct kimage *image, const void *slave_code,
123a0458284SThiago Jung Bauermann const void *fdt, unsigned long kernel_load_addr,
124a0458284SThiago Jung Bauermann unsigned long fdt_load_addr);
12519031275SHari Bathini
12619031275SHari Bathini #ifdef CONFIG_PPC64
1271a1cf93cSHari Bathini struct kexec_buf;
1281a1cf93cSHari Bathini
12965d9a9a6SNaveen N. Rao int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len);
13065d9a9a6SNaveen N. Rao #define arch_kexec_kernel_image_probe arch_kexec_kernel_image_probe
13165d9a9a6SNaveen N. Rao
13265d9a9a6SNaveen N. Rao int arch_kimage_file_post_load_cleanup(struct kimage *image);
13365d9a9a6SNaveen N. Rao #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
13465d9a9a6SNaveen N. Rao
13565d9a9a6SNaveen N. Rao int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf);
13665d9a9a6SNaveen N. Rao #define arch_kexec_locate_mem_hole arch_kexec_locate_mem_hole
13765d9a9a6SNaveen N. Rao
1381a1cf93cSHari Bathini int load_crashdump_segments_ppc64(struct kimage *image,
1391a1cf93cSHari Bathini struct kexec_buf *kbuf);
14019031275SHari Bathini int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
14119031275SHari Bathini const void *fdt, unsigned long kernel_load_addr,
14219031275SHari Bathini unsigned long fdt_load_addr);
143886db323SThiago Jung Bauermann unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);
14419031275SHari Bathini int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
14519031275SHari Bathini unsigned long initrd_load_addr,
14619031275SHari Bathini unsigned long initrd_len, const char *cmdline);
14719031275SHari Bathini #endif /* CONFIG_PPC64 */
148b8e55a3eSHari Bathini
149a0458284SThiago Jung Bauermann #endif /* CONFIG_KEXEC_FILE */
150a0458284SThiago Jung Bauermann
151da665885SThiago Jung Bauermann #else /* !CONFIG_KEXEC_CORE */
crash_kexec_secondary(struct pt_regs * regs)152b8b572e1SStephen Rothwell static inline void crash_kexec_secondary(struct pt_regs *regs) { }
153b8b572e1SStephen Rothwell
overlaps_crashkernel(unsigned long start,unsigned long size)154b8b572e1SStephen Rothwell static inline int overlaps_crashkernel(unsigned long start, unsigned long size)
155b8b572e1SStephen Rothwell {
156b8b572e1SStephen Rothwell return 0;
157b8b572e1SStephen Rothwell }
158b8b572e1SStephen Rothwell
reserve_crashkernel(void)159b8b572e1SStephen Rothwell static inline void reserve_crashkernel(void) { ; }
160b8b572e1SStephen Rothwell
crash_shutdown_register(crash_shutdown_t handler)161b8b572e1SStephen Rothwell static inline int crash_shutdown_register(crash_shutdown_t handler)
162b8b572e1SStephen Rothwell {
163b8b572e1SStephen Rothwell return 0;
164b8b572e1SStephen Rothwell }
165b8b572e1SStephen Rothwell
crash_shutdown_unregister(crash_shutdown_t handler)166b8b572e1SStephen Rothwell static inline int crash_shutdown_unregister(crash_shutdown_t handler)
167b8b572e1SStephen Rothwell {
168b8b572e1SStephen Rothwell return 0;
169b8b572e1SStephen Rothwell }
170b8b572e1SStephen Rothwell
kdump_in_progress(void)171c1caae3dSHari Bathini static inline bool kdump_in_progress(void)
172c1caae3dSHari Bathini {
173c1caae3dSHari Bathini return false;
174c1caae3dSHari Bathini }
175c1caae3dSHari Bathini
crash_ipi_callback(struct pt_regs * regs)17691096175SGuenter Roeck static inline void crash_ipi_callback(struct pt_regs *regs) { }
17791096175SGuenter Roeck
crash_send_ipi(void (* crash_ipi_callback)(struct pt_regs *))17891096175SGuenter Roeck static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
17991096175SGuenter Roeck {
18091096175SGuenter Roeck }
18191096175SGuenter Roeck
182da665885SThiago Jung Bauermann #endif /* CONFIG_KEXEC_CORE */
183000a42b3SAneesh Kumar K.V
184000a42b3SAneesh Kumar K.V #ifdef CONFIG_PPC_BOOK3S_64
185000a42b3SAneesh Kumar K.V #include <asm/book3s/64/kexec.h>
186000a42b3SAneesh Kumar K.V #endif
187000a42b3SAneesh Kumar K.V
188000a42b3SAneesh Kumar K.V #ifndef reset_sprs
189000a42b3SAneesh Kumar K.V #define reset_sprs reset_sprs
reset_sprs(void)190000a42b3SAneesh Kumar K.V static inline void reset_sprs(void)
191000a42b3SAneesh Kumar K.V {
192000a42b3SAneesh Kumar K.V }
193000a42b3SAneesh Kumar K.V #endif
194000a42b3SAneesh Kumar K.V
195b8b572e1SStephen Rothwell #endif /* ! __ASSEMBLY__ */
196b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
197b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_KEXEC_H */
198