xref: /openbmc/linux/arch/x86/include/asm/shared/tdx.h (revision ff40b576)
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 
13*ff40b576SKirill A. Shutemov /* TDX module Call Leaf IDs */
14*ff40b576SKirill A. Shutemov #define TDX_GET_INFO			1
15*ff40b576SKirill A. Shutemov #define TDX_GET_VEINFO			3
16*ff40b576SKirill A. Shutemov #define TDX_GET_REPORT			4
17*ff40b576SKirill A. Shutemov #define TDX_ACCEPT_PAGE			6
18*ff40b576SKirill A. Shutemov #define TDX_WR				8
19*ff40b576SKirill A. Shutemov 
20*ff40b576SKirill A. Shutemov /* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */
21*ff40b576SKirill A. Shutemov #define TDCS_NOTIFY_ENABLES		0x9100000000000010
22*ff40b576SKirill A. Shutemov 
23*ff40b576SKirill A. Shutemov /* TDX hypercall Leaf IDs */
24*ff40b576SKirill A. Shutemov #define TDVMCALL_MAP_GPA		0x10001
25*ff40b576SKirill A. Shutemov #define TDVMCALL_REPORT_FATAL_ERROR	0x10003
26*ff40b576SKirill 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 
54*ff40b576SKirill A. Shutemov /*
55*ff40b576SKirill A. Shutemov  * Wrapper for standard use of __tdx_hypercall with no output aside from
56*ff40b576SKirill A. Shutemov  * return code.
57*ff40b576SKirill A. Shutemov  */
58*ff40b576SKirill A. Shutemov static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
59*ff40b576SKirill A. Shutemov {
60*ff40b576SKirill A. Shutemov 	struct tdx_hypercall_args args = {
61*ff40b576SKirill A. Shutemov 		.r10 = TDX_HYPERCALL_STANDARD,
62*ff40b576SKirill A. Shutemov 		.r11 = fn,
63*ff40b576SKirill A. Shutemov 		.r12 = r12,
64*ff40b576SKirill A. Shutemov 		.r13 = r13,
65*ff40b576SKirill A. Shutemov 		.r14 = r14,
66*ff40b576SKirill A. Shutemov 		.r15 = r15,
67*ff40b576SKirill A. Shutemov 	};
68*ff40b576SKirill A. Shutemov 
69*ff40b576SKirill A. Shutemov 	return __tdx_hypercall(&args);
70*ff40b576SKirill A. Shutemov }
71*ff40b576SKirill A. Shutemov 
72*ff40b576SKirill A. Shutemov 
734c5b9aacSKirill A. Shutemov /* Called from __tdx_hypercall() for unrecoverable failure */
744c5b9aacSKirill A. Shutemov void __tdx_hypercall_failed(void);
754c5b9aacSKirill A. Shutemov 
76*ff40b576SKirill A. Shutemov /*
77*ff40b576SKirill A. Shutemov  * Used in __tdx_module_call() to gather the output registers' values of the
78*ff40b576SKirill A. Shutemov  * TDCALL instruction when requesting services from the TDX module. This is a
79*ff40b576SKirill A. Shutemov  * software only structure and not part of the TDX module/VMM ABI
80*ff40b576SKirill A. Shutemov  */
81*ff40b576SKirill A. Shutemov struct tdx_module_output {
82*ff40b576SKirill A. Shutemov 	u64 rcx;
83*ff40b576SKirill A. Shutemov 	u64 rdx;
84*ff40b576SKirill A. Shutemov 	u64 r8;
85*ff40b576SKirill A. Shutemov 	u64 r9;
86*ff40b576SKirill A. Shutemov 	u64 r10;
87*ff40b576SKirill A. Shutemov 	u64 r11;
88*ff40b576SKirill A. Shutemov };
89*ff40b576SKirill A. Shutemov 
90*ff40b576SKirill A. Shutemov /* Used to communicate with the TDX module */
91*ff40b576SKirill A. Shutemov u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
92*ff40b576SKirill A. Shutemov 		      struct tdx_module_output *out);
93*ff40b576SKirill A. Shutemov 
944c5b9aacSKirill A. Shutemov #endif /* !__ASSEMBLY__ */
954b05f815SKuppuswamy Sathyanarayanan #endif /* _ASM_X86_SHARED_TDX_H */
96