18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ARCH_X86_REALMODE_H 38c2ecf20Sopenharmony_ci#define _ARCH_X86_REALMODE_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Flag bit definitions for use with the flags field of the trampoline header 78c2ecf20Sopenharmony_ci * in the CONFIG_X86_64 variant. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#define TH_FLAGS_SME_ACTIVE_BIT 0 108c2ecf20Sopenharmony_ci#define TH_FLAGS_SME_ACTIVE BIT(TH_FLAGS_SME_ACTIVE_BIT) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/types.h> 158c2ecf20Sopenharmony_ci#include <asm/io.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* This must match data at realmode/rm/header.S */ 188c2ecf20Sopenharmony_cistruct real_mode_header { 198c2ecf20Sopenharmony_ci u32 text_start; 208c2ecf20Sopenharmony_ci u32 ro_end; 218c2ecf20Sopenharmony_ci /* SMP trampoline */ 228c2ecf20Sopenharmony_ci u32 trampoline_start; 238c2ecf20Sopenharmony_ci u32 trampoline_header; 248c2ecf20Sopenharmony_ci#ifdef CONFIG_AMD_MEM_ENCRYPT 258c2ecf20Sopenharmony_ci u32 sev_es_trampoline_start; 268c2ecf20Sopenharmony_ci#endif 278c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 288c2ecf20Sopenharmony_ci u32 trampoline_pgd; 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci /* ACPI S3 wakeup */ 318c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_SLEEP 328c2ecf20Sopenharmony_ci u32 wakeup_start; 338c2ecf20Sopenharmony_ci u32 wakeup_header; 348c2ecf20Sopenharmony_ci#endif 358c2ecf20Sopenharmony_ci /* APM/BIOS reboot */ 368c2ecf20Sopenharmony_ci u32 machine_real_restart_asm; 378c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 388c2ecf20Sopenharmony_ci u32 machine_real_restart_seg; 398c2ecf20Sopenharmony_ci#endif 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* This must match data at realmode/rm/trampoline_{32,64}.S */ 438c2ecf20Sopenharmony_cistruct trampoline_header { 448c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32 458c2ecf20Sopenharmony_ci u32 start; 468c2ecf20Sopenharmony_ci u16 gdt_pad; 478c2ecf20Sopenharmony_ci u16 gdt_limit; 488c2ecf20Sopenharmony_ci u32 gdt_base; 498c2ecf20Sopenharmony_ci#else 508c2ecf20Sopenharmony_ci u64 start; 518c2ecf20Sopenharmony_ci u64 efer; 528c2ecf20Sopenharmony_ci u32 cr4; 538c2ecf20Sopenharmony_ci u32 flags; 548c2ecf20Sopenharmony_ci#endif 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciextern struct real_mode_header *real_mode_header; 588c2ecf20Sopenharmony_ciextern unsigned char real_mode_blob_end[]; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciextern unsigned long initial_code; 618c2ecf20Sopenharmony_ciextern unsigned long initial_gs; 628c2ecf20Sopenharmony_ciextern unsigned long initial_stack; 638c2ecf20Sopenharmony_ci#ifdef CONFIG_AMD_MEM_ENCRYPT 648c2ecf20Sopenharmony_ciextern unsigned long initial_vc_handler; 658c2ecf20Sopenharmony_ci#endif 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciextern unsigned char real_mode_blob[]; 688c2ecf20Sopenharmony_ciextern unsigned char real_mode_relocs[]; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32 718c2ecf20Sopenharmony_ciextern unsigned char startup_32_smp[]; 728c2ecf20Sopenharmony_ciextern unsigned char boot_gdt[]; 738c2ecf20Sopenharmony_ci#else 748c2ecf20Sopenharmony_ciextern unsigned char secondary_startup_64[]; 758c2ecf20Sopenharmony_ciextern unsigned char secondary_startup_64_no_verify[]; 768c2ecf20Sopenharmony_ci#endif 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic inline size_t real_mode_size_needed(void) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci if (real_mode_header) 818c2ecf20Sopenharmony_ci return 0; /* already allocated. */ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic inline void set_real_mode_mem(phys_addr_t mem) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci real_mode_header = (struct real_mode_header *) __va(mem); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid reserve_real_mode(void); 928c2ecf20Sopenharmony_civoid load_trampoline_pgtable(void); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#endif /* _ARCH_X86_REALMODE_H */ 97