18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_KEXEC_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_KEXEC_H
48c2ecf20Sopenharmony_ci#ifdef __KERNEL__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#if defined(CONFIG_FSL_BOOKE) || defined(CONFIG_44x)
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci * On FSL-BookE we setup a 1:1 mapping which covers the first 2GiB of memory
108c2ecf20Sopenharmony_ci * and therefore we can only deal with memory within this range
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#define KEXEC_SOURCE_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
138c2ecf20Sopenharmony_ci#define KEXEC_DESTINATION_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
148c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL - 1)
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#else
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * Maximum page that is mapped directly into kernel memory.
208c2ecf20Sopenharmony_ci * XXX: Since we copy virt we can use any page we allocate
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * Maximum address we can reach in physical address mode.
268c2ecf20Sopenharmony_ci * XXX: I want to allow initrd in highmem. Otherwise set to rmo on LPAR.
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Maximum address we can use for the control code buffer */
318c2ecf20Sopenharmony_ci#ifdef __powerpc64__
328c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
338c2ecf20Sopenharmony_ci#else
348c2ecf20Sopenharmony_ci/* TASK_SIZE, probably left over from use_mm ?? */
358c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci#endif
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_PAGE_SIZE 4096
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* The native architecture */
428c2ecf20Sopenharmony_ci#ifdef __powerpc64__
438c2ecf20Sopenharmony_ci#define KEXEC_ARCH KEXEC_ARCH_PPC64
448c2ecf20Sopenharmony_ci#else
458c2ecf20Sopenharmony_ci#define KEXEC_ARCH KEXEC_ARCH_PPC
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define KEXEC_STATE_NONE 0
498c2ecf20Sopenharmony_ci#define KEXEC_STATE_IRQS_OFF 1
508c2ecf20Sopenharmony_ci#define KEXEC_STATE_REAL_MODE 2
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
538c2ecf20Sopenharmony_ci#include <asm/reg.h>
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_citypedef void (*crash_shutdown_t)(void);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#ifdef CONFIG_KEXEC_CORE
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * This function is responsible for capturing register states if coming
618c2ecf20Sopenharmony_ci * via panic or invoking dump using sysrq-trigger.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_cistatic inline void crash_setup_regs(struct pt_regs *newregs,
648c2ecf20Sopenharmony_ci					struct pt_regs *oldregs)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	if (oldregs)
678c2ecf20Sopenharmony_ci		memcpy(newregs, oldregs, sizeof(*newregs));
688c2ecf20Sopenharmony_ci	else
698c2ecf20Sopenharmony_ci		ppc_save_regs(newregs);
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciextern void kexec_smp_wait(void);	/* get and clear naca physid, wait for
738c2ecf20Sopenharmony_ci					  master to copy new code to 0 */
748c2ecf20Sopenharmony_ciextern int crashing_cpu;
758c2ecf20Sopenharmony_ciextern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
768c2ecf20Sopenharmony_ciextern void crash_ipi_callback(struct pt_regs *);
778c2ecf20Sopenharmony_ciextern int crash_wake_offline;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistruct kimage;
808c2ecf20Sopenharmony_cistruct pt_regs;
818c2ecf20Sopenharmony_ciextern void default_machine_kexec(struct kimage *image);
828c2ecf20Sopenharmony_ciextern int default_machine_kexec_prepare(struct kimage *image);
838c2ecf20Sopenharmony_ciextern void default_machine_crash_shutdown(struct pt_regs *regs);
848c2ecf20Sopenharmony_ciextern int crash_shutdown_register(crash_shutdown_t handler);
858c2ecf20Sopenharmony_ciextern int crash_shutdown_unregister(crash_shutdown_t handler);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciextern void crash_kexec_secondary(struct pt_regs *regs);
888c2ecf20Sopenharmony_ciextern int overlaps_crashkernel(unsigned long start, unsigned long size);
898c2ecf20Sopenharmony_ciextern void reserve_crashkernel(void);
908c2ecf20Sopenharmony_ciextern void machine_kexec_mask_interrupts(void);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic inline bool kdump_in_progress(void)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	return crashing_cpu >= 0;
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_civoid relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_code_buffer,
988c2ecf20Sopenharmony_ci			 unsigned long start_address) __noreturn;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#ifdef CONFIG_KEXEC_FILE
1018c2ecf20Sopenharmony_ciextern const struct kexec_file_ops kexec_elf64_ops;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define ARCH_HAS_KIMAGE_ARCH
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistruct kimage_arch {
1068c2ecf20Sopenharmony_ci	struct crash_mem *exclude_ranges;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	unsigned long backup_start;
1098c2ecf20Sopenharmony_ci	void *backup_buf;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	unsigned long elfcorehdr_addr;
1128c2ecf20Sopenharmony_ci	unsigned long elf_headers_sz;
1138c2ecf20Sopenharmony_ci	void *elf_headers;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_KEXEC
1168c2ecf20Sopenharmony_ci	phys_addr_t ima_buffer_addr;
1178c2ecf20Sopenharmony_ci	size_t ima_buffer_size;
1188c2ecf20Sopenharmony_ci#endif
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cichar *setup_kdump_cmdline(struct kimage *image, char *cmdline,
1228c2ecf20Sopenharmony_ci			  unsigned long cmdline_len);
1238c2ecf20Sopenharmony_ciint setup_purgatory(struct kimage *image, const void *slave_code,
1248c2ecf20Sopenharmony_ci		    const void *fdt, unsigned long kernel_load_addr,
1258c2ecf20Sopenharmony_ci		    unsigned long fdt_load_addr);
1268c2ecf20Sopenharmony_ciint setup_new_fdt(const struct kimage *image, void *fdt,
1278c2ecf20Sopenharmony_ci		  unsigned long initrd_load_addr, unsigned long initrd_len,
1288c2ecf20Sopenharmony_ci		  const char *cmdline);
1298c2ecf20Sopenharmony_ciint delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64
1328c2ecf20Sopenharmony_cistruct kexec_buf;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciint load_crashdump_segments_ppc64(struct kimage *image,
1358c2ecf20Sopenharmony_ci				  struct kexec_buf *kbuf);
1368c2ecf20Sopenharmony_ciint setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
1378c2ecf20Sopenharmony_ci			  const void *fdt, unsigned long kernel_load_addr,
1388c2ecf20Sopenharmony_ci			  unsigned long fdt_load_addr);
1398c2ecf20Sopenharmony_ciunsigned int kexec_fdt_totalsize_ppc64(struct kimage *image);
1408c2ecf20Sopenharmony_ciint setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
1418c2ecf20Sopenharmony_ci			unsigned long initrd_load_addr,
1428c2ecf20Sopenharmony_ci			unsigned long initrd_len, const char *cmdline);
1438c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC64 */
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#endif /* CONFIG_KEXEC_FILE */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#else /* !CONFIG_KEXEC_CORE */
1488c2ecf20Sopenharmony_cistatic inline void crash_kexec_secondary(struct pt_regs *regs) { }
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic inline int overlaps_crashkernel(unsigned long start, unsigned long size)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	return 0;
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic inline void reserve_crashkernel(void) { ; }
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic inline int crash_shutdown_register(crash_shutdown_t handler)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	return 0;
1608c2ecf20Sopenharmony_ci}
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cistatic inline int crash_shutdown_unregister(crash_shutdown_t handler)
1638c2ecf20Sopenharmony_ci{
1648c2ecf20Sopenharmony_ci	return 0;
1658c2ecf20Sopenharmony_ci}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic inline bool kdump_in_progress(void)
1688c2ecf20Sopenharmony_ci{
1698c2ecf20Sopenharmony_ci	return false;
1708c2ecf20Sopenharmony_ci}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_cistatic inline void crash_ipi_callback(struct pt_regs *regs) { }
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistatic inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
1758c2ecf20Sopenharmony_ci{
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#endif /* CONFIG_KEXEC_CORE */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
1818c2ecf20Sopenharmony_ci#include <asm/book3s/64/kexec.h>
1828c2ecf20Sopenharmony_ci#endif
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#ifndef reset_sprs
1858c2ecf20Sopenharmony_ci#define reset_sprs reset_sprs
1868c2ecf20Sopenharmony_cistatic inline void reset_sprs(void)
1878c2ecf20Sopenharmony_ci{
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci#endif
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#endif /* ! __ASSEMBLY__ */
1928c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1938c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_KEXEC_H */
194