1 /* SPDX-License-Identifier: GPL-2.0 */
3 * AMD Encrypted Register State Support
5 * Author: Joerg Roedel <jroedel@suse.de>
8 #ifndef __ASM_ENCRYPTED_STATE_H
9 #define __ASM_ENCRYPTED_STATE_H
11 #include <linux/types.h>
13 #include <asm/sev-common.h>
15 #define GHCB_PROTO_OUR 0x0001UL
16 #define GHCB_PROTOCOL_MAX 1ULL
17 #define GHCB_DEFAULT_USAGE 0ULL
19 #define VMGEXIT() { asm volatile("rep; vmmcall\n\r"); }
23 ES_UNSUPPORTED, /* Requested operation not supported */
24 ES_VMM_ERROR, /* Unexpected state from the VMM */
25 ES_DECODE_FAILED, /* Instruction decoding failed */
26 ES_EXCEPTION, /* Instruction caused exception */
27 ES_RETRY, /* Retry instruction emulation */
30 struct es_fault_info {
32 unsigned long error_code;
38 /* ES instruction emulation context */
42 struct es_fault_info fi;
45 void do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code);
47 static inline u64 lower_bits(u64 val, unsigned int bits)
49 u64 mask = (1ULL << bits) - 1;
54 struct real_mode_header;
57 /* Early IDT entry points for #VC handler */
58 extern void vc_no_ghcb(void);
59 extern void vc_boot_ghcb(void);
60 extern bool handle_vc_boot_ghcb(struct pt_regs *regs);
62 #ifdef CONFIG_AMD_MEM_ENCRYPT
63 extern struct static_key_false sev_es_enable_key;
64 extern void __sev_es_ist_enter(struct pt_regs *regs);
65 extern void __sev_es_ist_exit(void);
66 static __always_inline void sev_es_ist_enter(struct pt_regs *regs)
68 if (static_branch_unlikely(&sev_es_enable_key))
69 __sev_es_ist_enter(regs);
71 static __always_inline void sev_es_ist_exit(void)
73 if (static_branch_unlikely(&sev_es_enable_key))
76 extern int sev_es_setup_ap_jump_table(struct real_mode_header *rmh);
77 extern void __sev_es_nmi_complete(void);
78 static __always_inline void sev_es_nmi_complete(void)
80 if (static_branch_unlikely(&sev_es_enable_key))
81 __sev_es_nmi_complete();
83 extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd);
85 static inline void sev_es_ist_enter(struct pt_regs *regs) { }
86 static inline void sev_es_ist_exit(void) { }
87 static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; }
88 static inline void sev_es_nmi_complete(void) { }
89 static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; }