1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ARM_KEXEC_H
3*4882a593Smuzhiyun #define _ARM_KEXEC_H
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun /* Maximum physical address we can use pages from */
8*4882a593Smuzhiyun #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
9*4882a593Smuzhiyun /* Maximum address we can reach in physical address mode */
10*4882a593Smuzhiyun #define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
11*4882a593Smuzhiyun /* Maximum address we can use for the control code buffer */
12*4882a593Smuzhiyun #define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #define KEXEC_CONTROL_PAGE_SIZE 4096
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define KEXEC_ARCH KEXEC_ARCH_ARM
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #define KEXEC_ARM_ATAGS_OFFSET 0x1000
19*4882a593Smuzhiyun #define KEXEC_ARM_ZIMAGE_OFFSET 0x8000
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #ifndef __ASSEMBLY__
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #define ARCH_HAS_KIMAGE_ARCH
24*4882a593Smuzhiyun struct kimage_arch {
25*4882a593Smuzhiyun u32 kernel_r2;
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun * crash_setup_regs() - save registers for the panic kernel
30*4882a593Smuzhiyun * @newregs: registers are saved here
31*4882a593Smuzhiyun * @oldregs: registers to be saved (may be %NULL)
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * Function copies machine registers from @oldregs to @newregs. If @oldregs is
34*4882a593Smuzhiyun * %NULL then current registers are stored there.
35*4882a593Smuzhiyun */
crash_setup_regs(struct pt_regs * newregs,struct pt_regs * oldregs)36*4882a593Smuzhiyun static inline void crash_setup_regs(struct pt_regs *newregs,
37*4882a593Smuzhiyun struct pt_regs *oldregs)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun if (oldregs) {
40*4882a593Smuzhiyun memcpy(newregs, oldregs, sizeof(*newregs));
41*4882a593Smuzhiyun } else {
42*4882a593Smuzhiyun __asm__ __volatile__ (
43*4882a593Smuzhiyun "stmia %[regs_base], {r0-r12}\n\t"
44*4882a593Smuzhiyun "mov %[_ARM_sp], sp\n\t"
45*4882a593Smuzhiyun "str lr, %[_ARM_lr]\n\t"
46*4882a593Smuzhiyun "adr %[_ARM_pc], 1f\n\t"
47*4882a593Smuzhiyun "mrs %[_ARM_cpsr], cpsr\n\t"
48*4882a593Smuzhiyun "1:"
49*4882a593Smuzhiyun : [_ARM_pc] "=r" (newregs->ARM_pc),
50*4882a593Smuzhiyun [_ARM_cpsr] "=r" (newregs->ARM_cpsr),
51*4882a593Smuzhiyun [_ARM_sp] "=r" (newregs->ARM_sp),
52*4882a593Smuzhiyun [_ARM_lr] "=o" (newregs->ARM_lr)
53*4882a593Smuzhiyun : [regs_base] "r" (&newregs->ARM_r0)
54*4882a593Smuzhiyun : "memory"
55*4882a593Smuzhiyun );
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Function pointer to optional machine-specific reinitialization */
60*4882a593Smuzhiyun extern void (*kexec_reinit)(void);
61*4882a593Smuzhiyun
phys_to_boot_phys(phys_addr_t phys)62*4882a593Smuzhiyun static inline unsigned long phys_to_boot_phys(phys_addr_t phys)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun return phys_to_idmap(phys);
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun #define phys_to_boot_phys phys_to_boot_phys
67*4882a593Smuzhiyun
boot_phys_to_phys(unsigned long entry)68*4882a593Smuzhiyun static inline phys_addr_t boot_phys_to_phys(unsigned long entry)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun return idmap_to_phys(entry);
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun #define boot_phys_to_phys boot_phys_to_phys
73*4882a593Smuzhiyun
page_to_boot_pfn(struct page * page)74*4882a593Smuzhiyun static inline unsigned long page_to_boot_pfn(struct page *page)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun return page_to_pfn(page) + (arch_phys_to_idmap_offset >> PAGE_SHIFT);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun #define page_to_boot_pfn page_to_boot_pfn
79*4882a593Smuzhiyun
boot_pfn_to_page(unsigned long boot_pfn)80*4882a593Smuzhiyun static inline struct page *boot_pfn_to_page(unsigned long boot_pfn)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun return pfn_to_page(boot_pfn - (arch_phys_to_idmap_offset >> PAGE_SHIFT));
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun #define boot_pfn_to_page boot_pfn_to_page
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #endif /* CONFIG_KEXEC */
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun #endif /* _ARM_KEXEC_H */
91