xref: /openbmc/linux/arch/x86/include/asm/tdx.h (revision d5cda142)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2021-2022 Intel Corporation */
3 #ifndef _ASM_X86_TDX_H
4 #define _ASM_X86_TDX_H
5 
6 #include <linux/init.h>
7 #include <linux/bits.h>
8 
9 #include <asm/errno.h>
10 #include <asm/ptrace.h>
11 #include <asm/shared/tdx.h>
12 
13 /*
14  * SW-defined error codes.
15  *
16  * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
17  * TDX module.
18  */
19 #define TDX_ERROR			_BITUL(63)
20 #define TDX_SW_ERROR			(TDX_ERROR | GENMASK_ULL(47, 40))
21 #define TDX_SEAMCALL_VMFAILINVALID	(TDX_SW_ERROR | _UL(0xFFFF0000))
22 
23 #ifndef __ASSEMBLY__
24 
25 /*
26  * Used by the #VE exception handler to gather the #VE exception
27  * info from the TDX module. This is a software only structure
28  * and not part of the TDX module/VMM ABI.
29  */
30 struct ve_info {
31 	u64 exit_reason;
32 	u64 exit_qual;
33 	/* Guest Linear (virtual) Address */
34 	u64 gla;
35 	/* Guest Physical Address */
36 	u64 gpa;
37 	u32 instr_len;
38 	u32 instr_info;
39 };
40 
41 #ifdef CONFIG_INTEL_TDX_GUEST
42 
43 void __init tdx_early_init(void);
44 
45 void tdx_get_ve_info(struct ve_info *ve);
46 
47 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
48 
49 void tdx_safe_halt(void);
50 
51 bool tdx_early_handle_ve(struct pt_regs *regs);
52 
53 int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
54 
55 #else
56 
57 static inline void tdx_early_init(void) { };
58 static inline void tdx_safe_halt(void) { };
59 
60 static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; }
61 
62 #endif /* CONFIG_INTEL_TDX_GUEST */
63 
64 #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_INTEL_TDX_GUEST)
65 long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
66 		       unsigned long p3, unsigned long p4);
67 #else
68 static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
69 				     unsigned long p2, unsigned long p3,
70 				     unsigned long p4)
71 {
72 	return -ENODEV;
73 }
74 #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
75 #endif /* !__ASSEMBLY__ */
76 #endif /* _ASM_X86_TDX_H */
77