1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_X86_SHARED_TDX_H 3 #define _ASM_X86_SHARED_TDX_H 4 5 #include <linux/bits.h> 6 #include <linux/types.h> 7 8 #define TDX_HYPERCALL_STANDARD 0 9 10 #define TDX_CPUID_LEAF_ID 0x21 11 #define TDX_IDENT "IntelTDX " 12 13 /* TDX module Call Leaf IDs */ 14 #define TDG_VP_INFO 1 15 #define TDG_VP_VEINFO_GET 3 16 #define TDG_MR_REPORT 4 17 #define TDG_MEM_PAGE_ACCEPT 6 18 #define TDG_VM_RD 7 19 #define TDG_VM_WR 8 20 21 /* TDX TD-Scope Metadata. To be used by TDG.VM.WR and TDG.VM.RD */ 22 #define TDCS_CONFIG_FLAGS 0x1110000300000016 23 #define TDCS_TD_CTLS 0x1110000300000017 24 #define TDCS_NOTIFY_ENABLES 0x9100000000000010 25 26 /* TDCS_CONFIG_FLAGS bits */ 27 #define TDCS_CONFIG_FLEXIBLE_PENDING_VE BIT_ULL(1) 28 29 /* TDCS_TD_CTLS bits */ 30 #define TD_CTLS_PENDING_VE_DISABLE BIT_ULL(0) 31 32 /* TDX hypercall Leaf IDs */ 33 #define TDVMCALL_MAP_GPA 0x10001 34 #define TDVMCALL_REPORT_FATAL_ERROR 0x10003 35 36 #ifndef __ASSEMBLY__ 37 38 /* 39 * Used in __tdx_hypercall() to pass down and get back registers' values of 40 * the TDCALL instruction when requesting services from the VMM. 41 * 42 * This is a software only structure and not part of the TDX module/VMM ABI. 43 */ 44 struct tdx_hypercall_args { 45 u64 r8; 46 u64 r9; 47 u64 r10; 48 u64 r11; 49 u64 r12; 50 u64 r13; 51 u64 r14; 52 u64 r15; 53 u64 rdi; 54 u64 rsi; 55 u64 rbx; 56 u64 rdx; 57 }; 58 59 /* Used to request services from the VMM */ 60 u64 __tdx_hypercall(struct tdx_hypercall_args *args); 61 u64 __tdx_hypercall_ret(struct tdx_hypercall_args *args); 62 63 /* 64 * Wrapper for standard use of __tdx_hypercall with no output aside from 65 * return code. 66 */ 67 static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15) 68 { 69 struct tdx_hypercall_args args = { 70 .r10 = TDX_HYPERCALL_STANDARD, 71 .r11 = fn, 72 .r12 = r12, 73 .r13 = r13, 74 .r14 = r14, 75 .r15 = r15, 76 }; 77 78 return __tdx_hypercall(&args); 79 } 80 81 82 /* Called from __tdx_hypercall() for unrecoverable failure */ 83 void __tdx_hypercall_failed(void); 84 85 /* 86 * Used in __tdcall*() to gather the input/output registers' values of the 87 * TDCALL instruction when requesting services from the TDX module. This is a 88 * software only structure and not part of the TDX module/VMM ABI 89 */ 90 struct tdx_module_args { 91 u64 rcx; 92 u64 rdx; 93 u64 r8; 94 u64 r9; 95 u64 r10; 96 u64 r11; 97 }; 98 99 /* Used to communicate with the TDX module */ 100 u64 __tdcall(u64 fn, struct tdx_module_args *args); 101 u64 __tdcall_ret(u64 fn, struct tdx_module_args *args); 102 103 bool tdx_accept_memory(phys_addr_t start, phys_addr_t end); 104 105 /* 106 * The TDG.VP.VMCALL-Instruction-execution sub-functions are defined 107 * independently from but are currently matched 1:1 with VMX EXIT_REASONs. 108 * Reusing the KVM EXIT_REASON macros makes it easier to connect the host and 109 * guest sides of these calls. 110 */ 111 static __always_inline u64 hcall_func(u64 exit_reason) 112 { 113 return exit_reason; 114 } 115 116 #endif /* !__ASSEMBLY__ */ 117 #endif /* _ASM_X86_SHARED_TDX_H */ 118