linux/arch/x86/include/asm/kexec.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_KEXEC_H
#define _ASM_X86_KEXEC_H

#ifdef CONFIG_X86_32
#define PA_CONTROL_PAGE
#define VA_CONTROL_PAGE
#define PA_PGD
#define PA_SWAP_PAGE
#define PAGES_NR
#else
#define PA_CONTROL_PAGE
#define VA_CONTROL_PAGE
#define PA_TABLE_PAGE
#define PA_SWAP_PAGE
#define PAGES_NR
#endif

#define KEXEC_CONTROL_CODE_MAX_SIZE

#ifndef __ASSEMBLY__

#include <linux/string.h>
#include <linux/kernel.h>

#include <asm/page.h>
#include <asm/ptrace.h>

struct kimage;

/*
 * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
 * I.e. Maximum page that is mapped directly into kernel memory,
 * and kmap is not required.
 *
 * So far x86_64 is limited to 40 physical address bits.
 */
#ifdef CONFIG_X86_32
/* Maximum physical address we can use pages from */
#define KEXEC_SOURCE_MEMORY_LIMIT
/* Maximum address we can reach in physical address mode */
#define KEXEC_DESTINATION_MEMORY_LIMIT
/* Maximum address we can use for the control code buffer */
#define KEXEC_CONTROL_MEMORY_LIMIT

#define KEXEC_CONTROL_PAGE_SIZE

/* The native architecture */
#define KEXEC_ARCH

/* We can also handle crash dumps from 64 bit kernel. */
#define vmcore_elf_check_arch_cross
#else
/* Maximum physical address we can use pages from */
#define KEXEC_SOURCE_MEMORY_LIMIT
/* Maximum address we can reach in physical address mode */
#define KEXEC_DESTINATION_MEMORY_LIMIT
/* Maximum address we can use for the control pages */
#define KEXEC_CONTROL_MEMORY_LIMIT

/* Allocate one page for the pdp and the second for the code */
#define KEXEC_CONTROL_PAGE_SIZE

/* The native architecture */
#define KEXEC_ARCH
#endif

/*
 * This function is responsible for capturing register states if coming
 * via panic otherwise just fix up the ss and sp if coming via kernel
 * mode exception.
 */
static inline void crash_setup_regs(struct pt_regs *newregs,
				    struct pt_regs *oldregs)
{}

#ifdef CONFIG_X86_32
asmlinkage unsigned long
relocate_kernel(unsigned long indirection_page,
		unsigned long control_page,
		unsigned long start_address,
		unsigned int has_pae,
		unsigned int preserve_context);
#else
unsigned long
relocate_kernel(unsigned long indirection_page,
		unsigned long page_list,
		unsigned long start_address,
		unsigned int preserve_context,
		unsigned int host_mem_enc_active);
#endif

#define ARCH_HAS_KIMAGE_ARCH

#ifdef CONFIG_X86_32
struct kimage_arch {
	pgd_t *pgd;
#ifdef CONFIG_X86_PAE
	pmd_t *pmd0;
	pmd_t *pmd1;
#endif
	pte_t *pte0;
	pte_t *pte1;
};
#else
struct kimage_arch {};
#endif /* CONFIG_X86_32 */

#ifdef CONFIG_X86_64
/*
 * Number of elements and order of elements in this structure should match
 * with the ones in arch/x86/purgatory/entry64.S. If you make a change here
 * make an appropriate change in purgatory too.
 */
struct kexec_entry64_regs {};

extern int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages,
				       gfp_t gfp);
#define arch_kexec_post_alloc_pages

extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
#define arch_kexec_pre_free_pages

void arch_kexec_protect_crashkres(void);
#define arch_kexec_protect_crashkres

void arch_kexec_unprotect_crashkres(void);
#define arch_kexec_unprotect_crashkres

#ifdef CONFIG_KEXEC_FILE
struct purgatory_info;
int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
				     Elf_Shdr *section,
				     const Elf_Shdr *relsec,
				     const Elf_Shdr *symtab);
#define arch_kexec_apply_relocations_add

int arch_kimage_file_post_load_cleanup(struct kimage *image);
#define arch_kimage_file_post_load_cleanup
#endif
#endif

extern void kdump_nmi_shootdown_cpus(void);

#ifdef CONFIG_CRASH_HOTPLUG
void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
#define arch_crash_handle_hotplug_event

int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
#define arch_crash_hotplug_support

unsigned int arch_crash_get_elfcorehdr_size(void);
#define crash_get_elfcorehdr_size
#endif

#endif /* __ASSEMBLY__ */

#endif /* _ASM_X86_KEXEC_H */