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;
58 /* Early IDT entry points for #VC handler */
59 extern void vc_no_ghcb(void);
60 extern void vc_boot_ghcb(void);
61 extern bool handle_vc_boot_ghcb(struct pt_regs *regs);
63 #ifdef CONFIG_AMD_MEM_ENCRYPT
64 extern struct static_key_false sev_es_enable_key;
65 extern void __sev_es_ist_enter(struct pt_regs *regs);
66 extern void __sev_es_ist_exit(void);
67 static __always_inline void sev_es_ist_enter(struct pt_regs *regs)
69 if (static_branch_unlikely(&sev_es_enable_key))
70 __sev_es_ist_enter(regs);
72 static __always_inline void sev_es_ist_exit(void)
74 if (static_branch_unlikely(&sev_es_enable_key))
77 extern int sev_es_setup_ap_jump_table(struct real_mode_header *rmh);
78 extern void __sev_es_nmi_complete(void);
79 static __always_inline void sev_es_nmi_complete(void)
81 if (static_branch_unlikely(&sev_es_enable_key))
82 __sev_es_nmi_complete();
84 extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd);
85 extern enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb,
87 struct es_em_ctxt *ctxt,
88 u64 exit_code, u64 exit_info_1,
91 static inline void sev_es_ist_enter(struct pt_regs *regs) { }
92 static inline void sev_es_ist_exit(void) { }
93 static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; }
94 static inline void sev_es_nmi_complete(void) { }
95 static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; }