162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __ASM_SH_KEXEC_H
362306a36Sopenharmony_ci#define __ASM_SH_KEXEC_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <asm/ptrace.h>
662306a36Sopenharmony_ci#include <asm/string.h>
762306a36Sopenharmony_ci#include <linux/kernel.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
1162306a36Sopenharmony_ci * I.e. Maximum page that is mapped directly into kernel memory,
1262306a36Sopenharmony_ci * and kmap is not required.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * Someone correct me if FIXADDR_START - PAGEOFFSET is not the correct
1562306a36Sopenharmony_ci * calculation for the amount of memory directly mappable into the
1662306a36Sopenharmony_ci * kernel memory space.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* Maximum physical address we can use pages from */
2062306a36Sopenharmony_ci#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
2162306a36Sopenharmony_ci/* Maximum address we can reach in physical address mode */
2262306a36Sopenharmony_ci#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
2362306a36Sopenharmony_ci/* Maximum address we can use for the control code buffer */
2462306a36Sopenharmony_ci#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define KEXEC_CONTROL_PAGE_SIZE	4096
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* The native architecture */
2962306a36Sopenharmony_ci#define KEXEC_ARCH KEXEC_ARCH_SH
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#ifdef CONFIG_KEXEC
3262306a36Sopenharmony_ci/* arch/sh/kernel/machine_kexec.c */
3362306a36Sopenharmony_civoid reserve_crashkernel(void);
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistatic inline void crash_setup_regs(struct pt_regs *newregs,
3662306a36Sopenharmony_ci				    struct pt_regs *oldregs)
3762306a36Sopenharmony_ci{
3862306a36Sopenharmony_ci	if (oldregs)
3962306a36Sopenharmony_ci		memcpy(newregs, oldregs, sizeof(*newregs));
4062306a36Sopenharmony_ci	else {
4162306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r0, %0" : "=r" (newregs->regs[0]));
4262306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r1, %0" : "=r" (newregs->regs[1]));
4362306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r2, %0" : "=r" (newregs->regs[2]));
4462306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r3, %0" : "=r" (newregs->regs[3]));
4562306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r4, %0" : "=r" (newregs->regs[4]));
4662306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r5, %0" : "=r" (newregs->regs[5]));
4762306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r6, %0" : "=r" (newregs->regs[6]));
4862306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r7, %0" : "=r" (newregs->regs[7]));
4962306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r8, %0" : "=r" (newregs->regs[8]));
5062306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r9, %0" : "=r" (newregs->regs[9]));
5162306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r10, %0" : "=r" (newregs->regs[10]));
5262306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r11, %0" : "=r" (newregs->regs[11]));
5362306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r12, %0" : "=r" (newregs->regs[12]));
5462306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r13, %0" : "=r" (newregs->regs[13]));
5562306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r14, %0" : "=r" (newregs->regs[14]));
5662306a36Sopenharmony_ci		__asm__ __volatile__ ("mov r15, %0" : "=r" (newregs->regs[15]));
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci		__asm__ __volatile__ ("sts pr, %0" : "=r" (newregs->pr));
5962306a36Sopenharmony_ci		__asm__ __volatile__ ("sts macl, %0" : "=r" (newregs->macl));
6062306a36Sopenharmony_ci		__asm__ __volatile__ ("sts mach, %0" : "=r" (newregs->mach));
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci		__asm__ __volatile__ ("stc gbr, %0" : "=r" (newregs->gbr));
6362306a36Sopenharmony_ci		__asm__ __volatile__ ("stc sr, %0" : "=r" (newregs->sr));
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci		newregs->pc = _THIS_IP_;
6662306a36Sopenharmony_ci	}
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci#else
6962306a36Sopenharmony_cistatic inline void reserve_crashkernel(void) { }
7062306a36Sopenharmony_ci#endif /* CONFIG_KEXEC */
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#endif /* __ASM_SH_KEXEC_H */
73