18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ARM_KEXEC_H 38c2ecf20Sopenharmony_ci#define _ARM_KEXEC_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#ifdef CONFIG_KEXEC 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* Maximum physical address we can use pages from */ 88c2ecf20Sopenharmony_ci#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) 98c2ecf20Sopenharmony_ci/* Maximum address we can reach in physical address mode */ 108c2ecf20Sopenharmony_ci#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) 118c2ecf20Sopenharmony_ci/* Maximum address we can use for the control code buffer */ 128c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define KEXEC_CONTROL_PAGE_SIZE 4096 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define KEXEC_ARCH KEXEC_ARCH_ARM 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define KEXEC_ARM_ATAGS_OFFSET 0x1000 198c2ecf20Sopenharmony_ci#define KEXEC_ARM_ZIMAGE_OFFSET 0x8000 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define ARCH_HAS_KIMAGE_ARCH 248c2ecf20Sopenharmony_cistruct kimage_arch { 258c2ecf20Sopenharmony_ci u32 kernel_r2; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/** 298c2ecf20Sopenharmony_ci * crash_setup_regs() - save registers for the panic kernel 308c2ecf20Sopenharmony_ci * @newregs: registers are saved here 318c2ecf20Sopenharmony_ci * @oldregs: registers to be saved (may be %NULL) 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * Function copies machine registers from @oldregs to @newregs. If @oldregs is 348c2ecf20Sopenharmony_ci * %NULL then current registers are stored there. 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_cistatic inline void crash_setup_regs(struct pt_regs *newregs, 378c2ecf20Sopenharmony_ci struct pt_regs *oldregs) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci if (oldregs) { 408c2ecf20Sopenharmony_ci memcpy(newregs, oldregs, sizeof(*newregs)); 418c2ecf20Sopenharmony_ci } else { 428c2ecf20Sopenharmony_ci __asm__ __volatile__ ( 438c2ecf20Sopenharmony_ci "stmia %[regs_base], {r0-r12}\n\t" 448c2ecf20Sopenharmony_ci "mov %[_ARM_sp], sp\n\t" 458c2ecf20Sopenharmony_ci "str lr, %[_ARM_lr]\n\t" 468c2ecf20Sopenharmony_ci "adr %[_ARM_pc], 1f\n\t" 478c2ecf20Sopenharmony_ci "mrs %[_ARM_cpsr], cpsr\n\t" 488c2ecf20Sopenharmony_ci "1:" 498c2ecf20Sopenharmony_ci : [_ARM_pc] "=r" (newregs->ARM_pc), 508c2ecf20Sopenharmony_ci [_ARM_cpsr] "=r" (newregs->ARM_cpsr), 518c2ecf20Sopenharmony_ci [_ARM_sp] "=r" (newregs->ARM_sp), 528c2ecf20Sopenharmony_ci [_ARM_lr] "=o" (newregs->ARM_lr) 538c2ecf20Sopenharmony_ci : [regs_base] "r" (&newregs->ARM_r0) 548c2ecf20Sopenharmony_ci : "memory" 558c2ecf20Sopenharmony_ci ); 568c2ecf20Sopenharmony_ci } 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Function pointer to optional machine-specific reinitialization */ 608c2ecf20Sopenharmony_ciextern void (*kexec_reinit)(void); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline unsigned long phys_to_boot_phys(phys_addr_t phys) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return phys_to_idmap(phys); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci#define phys_to_boot_phys phys_to_boot_phys 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic inline phys_addr_t boot_phys_to_phys(unsigned long entry) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return idmap_to_phys(entry); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci#define boot_phys_to_phys boot_phys_to_phys 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic inline unsigned long page_to_boot_pfn(struct page *page) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci return page_to_pfn(page) + (arch_phys_to_idmap_offset >> PAGE_SHIFT); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci#define page_to_boot_pfn page_to_boot_pfn 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline struct page *boot_pfn_to_page(unsigned long boot_pfn) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci return pfn_to_page(boot_pfn - (arch_phys_to_idmap_offset >> PAGE_SHIFT)); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci#define boot_pfn_to_page boot_pfn_to_page 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#endif /* CONFIG_KEXEC */ 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#endif /* _ARM_KEXEC_H */ 91