xref: /openbmc/linux/arch/x86/include/asm/shared/tdx.h (revision 75d090fd)
14b05f815SKuppuswamy Sathyanarayanan /* SPDX-License-Identifier: GPL-2.0 */
24b05f815SKuppuswamy Sathyanarayanan #ifndef _ASM_X86_SHARED_TDX_H
34b05f815SKuppuswamy Sathyanarayanan #define _ASM_X86_SHARED_TDX_H
44b05f815SKuppuswamy Sathyanarayanan 
54c5b9aacSKirill A. Shutemov #include <linux/bits.h>
64c5b9aacSKirill A. Shutemov #include <linux/types.h>
74c5b9aacSKirill A. Shutemov 
84c5b9aacSKirill A. Shutemov #define TDX_HYPERCALL_STANDARD  0
94c5b9aacSKirill A. Shutemov 
104b05f815SKuppuswamy Sathyanarayanan #define TDX_CPUID_LEAF_ID	0x21
114b05f815SKuppuswamy Sathyanarayanan #define TDX_IDENT		"IntelTDX    "
124b05f815SKuppuswamy Sathyanarayanan 
13ff40b576SKirill A. Shutemov /* TDX module Call Leaf IDs */
14ff40b576SKirill A. Shutemov #define TDX_GET_INFO			1
15ff40b576SKirill A. Shutemov #define TDX_GET_VEINFO			3
16ff40b576SKirill A. Shutemov #define TDX_GET_REPORT			4
17ff40b576SKirill A. Shutemov #define TDX_ACCEPT_PAGE			6
18ff40b576SKirill A. Shutemov #define TDX_WR				8
19ff40b576SKirill A. Shutemov 
20ff40b576SKirill A. Shutemov /* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */
21ff40b576SKirill A. Shutemov #define TDCS_NOTIFY_ENABLES		0x9100000000000010
22ff40b576SKirill A. Shutemov 
23ff40b576SKirill A. Shutemov /* TDX hypercall Leaf IDs */
24ff40b576SKirill A. Shutemov #define TDVMCALL_MAP_GPA		0x10001
25ff40b576SKirill A. Shutemov #define TDVMCALL_REPORT_FATAL_ERROR	0x10003
26ff40b576SKirill A. Shutemov 
274c5b9aacSKirill A. Shutemov #ifndef __ASSEMBLY__
284c5b9aacSKirill A. Shutemov 
294c5b9aacSKirill A. Shutemov /*
304c5b9aacSKirill A. Shutemov  * Used in __tdx_hypercall() to pass down and get back registers' values of
314c5b9aacSKirill A. Shutemov  * the TDCALL instruction when requesting services from the VMM.
324c5b9aacSKirill A. Shutemov  *
334c5b9aacSKirill A. Shutemov  * This is a software only structure and not part of the TDX module/VMM ABI.
344c5b9aacSKirill A. Shutemov  */
354c5b9aacSKirill A. Shutemov struct tdx_hypercall_args {
360da908c2SKirill A. Shutemov 	u64 r8;
370da908c2SKirill A. Shutemov 	u64 r9;
384c5b9aacSKirill A. Shutemov 	u64 r10;
394c5b9aacSKirill A. Shutemov 	u64 r11;
404c5b9aacSKirill A. Shutemov 	u64 r12;
414c5b9aacSKirill A. Shutemov 	u64 r13;
424c5b9aacSKirill A. Shutemov 	u64 r14;
434c5b9aacSKirill A. Shutemov 	u64 r15;
440da908c2SKirill A. Shutemov 	u64 rdi;
450da908c2SKirill A. Shutemov 	u64 rsi;
460da908c2SKirill A. Shutemov 	u64 rbx;
470da908c2SKirill A. Shutemov 	u64 rdx;
484c5b9aacSKirill A. Shutemov };
494c5b9aacSKirill A. Shutemov 
504c5b9aacSKirill A. Shutemov /* Used to request services from the VMM */
517a3a4018SKirill A. Shutemov u64 __tdx_hypercall(struct tdx_hypercall_args *args);
527a3a4018SKirill A. Shutemov u64 __tdx_hypercall_ret(struct tdx_hypercall_args *args);
534c5b9aacSKirill A. Shutemov 
54ff40b576SKirill A. Shutemov /*
55ff40b576SKirill A. Shutemov  * Wrapper for standard use of __tdx_hypercall with no output aside from
56ff40b576SKirill A. Shutemov  * return code.
57ff40b576SKirill A. Shutemov  */
_tdx_hypercall(u64 fn,u64 r12,u64 r13,u64 r14,u64 r15)58ff40b576SKirill A. Shutemov static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
59ff40b576SKirill A. Shutemov {
60ff40b576SKirill A. Shutemov 	struct tdx_hypercall_args args = {
61ff40b576SKirill A. Shutemov 		.r10 = TDX_HYPERCALL_STANDARD,
62ff40b576SKirill A. Shutemov 		.r11 = fn,
63ff40b576SKirill A. Shutemov 		.r12 = r12,
64ff40b576SKirill A. Shutemov 		.r13 = r13,
65ff40b576SKirill A. Shutemov 		.r14 = r14,
66ff40b576SKirill A. Shutemov 		.r15 = r15,
67ff40b576SKirill A. Shutemov 	};
68ff40b576SKirill A. Shutemov 
69ff40b576SKirill A. Shutemov 	return __tdx_hypercall(&args);
70ff40b576SKirill A. Shutemov }
71ff40b576SKirill A. Shutemov 
72ff40b576SKirill A. Shutemov 
734c5b9aacSKirill A. Shutemov /* Called from __tdx_hypercall() for unrecoverable failure */
744c5b9aacSKirill A. Shutemov void __tdx_hypercall_failed(void);
754c5b9aacSKirill A. Shutemov 
76ff40b576SKirill A. Shutemov /*
77ff40b576SKirill A. Shutemov  * Used in __tdx_module_call() to gather the output registers' values of the
78ff40b576SKirill A. Shutemov  * TDCALL instruction when requesting services from the TDX module. This is a
79ff40b576SKirill A. Shutemov  * software only structure and not part of the TDX module/VMM ABI
80ff40b576SKirill A. Shutemov  */
81ff40b576SKirill A. Shutemov struct tdx_module_output {
82ff40b576SKirill A. Shutemov 	u64 rcx;
83ff40b576SKirill A. Shutemov 	u64 rdx;
84ff40b576SKirill A. Shutemov 	u64 r8;
85ff40b576SKirill A. Shutemov 	u64 r9;
86ff40b576SKirill A. Shutemov 	u64 r10;
87ff40b576SKirill A. Shutemov 	u64 r11;
88ff40b576SKirill A. Shutemov };
89ff40b576SKirill A. Shutemov 
90ff40b576SKirill A. Shutemov /* Used to communicate with the TDX module */
91ff40b576SKirill A. Shutemov u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
92ff40b576SKirill A. Shutemov 		      struct tdx_module_output *out);
93ff40b576SKirill A. Shutemov 
94*75d090fdSKirill A. Shutemov bool tdx_accept_memory(phys_addr_t start, phys_addr_t end);
95*75d090fdSKirill A. Shutemov 
964c5b9aacSKirill A. Shutemov /*
974b05f815SKuppuswamy Sathyanarayanan  * The TDG.VP.VMCALL-Instruction-execution sub-functions are defined
98  * independently from but are currently matched 1:1 with VMX EXIT_REASONs.
99  * Reusing the KVM EXIT_REASON macros makes it easier to connect the host and
100  * guest sides of these calls.
101  */
hcall_func(u64 exit_reason)102 static __always_inline u64 hcall_func(u64 exit_reason)
103 {
104         return exit_reason;
105 }
106 
107 #endif /* !__ASSEMBLY__ */
108 #endif /* _ASM_X86_SHARED_TDX_H */
109