xref: /openbmc/linux/arch/x86/include/asm/tdx.h (revision 84cc6674)
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 #include <asm/ptrace.h>
9 #include <asm/shared/tdx.h>
10 
11 /*
12  * SW-defined error codes.
13  *
14  * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
15  * TDX module.
16  */
17 #define TDX_ERROR			_BITUL(63)
18 #define TDX_SW_ERROR			(TDX_ERROR | GENMASK_ULL(47, 40))
19 #define TDX_SEAMCALL_VMFAILINVALID	(TDX_SW_ERROR | _UL(0xFFFF0000))
20 
21 #ifndef __ASSEMBLY__
22 
23 /*
24  * Used to gather the output registers values of the TDCALL and SEAMCALL
25  * instructions when requesting services from the TDX module.
26  *
27  * This is a software only structure and not part of the TDX module/VMM ABI.
28  */
29 struct tdx_module_output {
30 	u64 rcx;
31 	u64 rdx;
32 	u64 r8;
33 	u64 r9;
34 	u64 r10;
35 	u64 r11;
36 };
37 
38 /*
39  * Used by the #VE exception handler to gather the #VE exception
40  * info from the TDX module. This is a software only structure
41  * and not part of the TDX module/VMM ABI.
42  */
43 struct ve_info {
44 	u64 exit_reason;
45 	u64 exit_qual;
46 	/* Guest Linear (virtual) Address */
47 	u64 gla;
48 	/* Guest Physical Address */
49 	u64 gpa;
50 	u32 instr_len;
51 	u32 instr_info;
52 };
53 
54 #ifdef CONFIG_INTEL_TDX_GUEST
55 
56 void __init tdx_early_init(void);
57 
58 /* Used to communicate with the TDX module */
59 u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
60 		      struct tdx_module_output *out);
61 
62 void tdx_get_ve_info(struct ve_info *ve);
63 
64 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
65 
66 void tdx_safe_halt(void);
67 
68 bool tdx_early_handle_ve(struct pt_regs *regs);
69 
70 int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
71 
72 #else
73 
74 static inline void tdx_early_init(void) { };
75 static inline void tdx_safe_halt(void) { };
76 
77 static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; }
78 
79 #endif /* CONFIG_INTEL_TDX_GUEST */
80 
81 #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_INTEL_TDX_GUEST)
82 long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
83 		       unsigned long p3, unsigned long p4);
84 #else
85 static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
86 				     unsigned long p2, unsigned long p3,
87 				     unsigned long p4)
88 {
89 	return -ENODEV;
90 }
91 #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
92 #endif /* !__ASSEMBLY__ */
93 #endif /* _ASM_X86_TDX_H */
94