1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2021-2022 Intel Corporation */
6 #include <linux/init.h>
7 #include <linux/bits.h>
10 #include <asm/ptrace.h>
11 #include <asm/trapnr.h>
12 #include <asm/shared/tdx.h>
15 * SW-defined error codes.
17 * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
20 #define TDX_ERROR _BITUL(63)
21 #define TDX_SW_ERROR (TDX_ERROR | GENMASK_ULL(47, 40))
22 #define TDX_SEAMCALL_VMFAILINVALID (TDX_SW_ERROR | _UL(0xFFFF0000))
24 #define TDX_SEAMCALL_GP (TDX_SW_ERROR | X86_TRAP_GP)
25 #define TDX_SEAMCALL_UD (TDX_SW_ERROR | X86_TRAP_UD)
28 * TDX module SEAMCALL leaf function error codes
30 #define TDX_SUCCESS 0ULL
31 #define TDX_RND_NO_ENTROPY 0x8000020300000000ULL
35 #include <uapi/asm/mce.h>
38 * Used by the #VE exception handler to gather the #VE exception
39 * info from the TDX module. This is a software only structure
40 * and not part of the TDX module/VMM ABI.
45 /* Guest Linear (virtual) Address */
47 /* Guest Physical Address */
53 #ifdef CONFIG_INTEL_TDX_GUEST
55 void __init tdx_early_init(void);
57 void tdx_get_ve_info(struct ve_info *ve);
59 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
61 void tdx_safe_halt(void);
63 bool tdx_early_handle_ve(struct pt_regs *regs);
65 int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
67 u64 tdx_hcall_get_quote(u8 *buf, size_t size);
69 void __init tdx_dump_attributes(u64 td_attr);
70 void __init tdx_dump_td_ctls(u64 td_ctls);
74 static inline void tdx_early_init(void) { };
75 static inline void tdx_safe_halt(void) { };
77 static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; }
79 #endif /* CONFIG_INTEL_TDX_GUEST */
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);
85 static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
86 unsigned long p2, unsigned long p3,
91 #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
93 #ifdef CONFIG_INTEL_TDX_HOST
94 u64 __seamcall(u64 fn, struct tdx_module_args *args);
95 u64 __seamcall_ret(u64 fn, struct tdx_module_args *args);
96 u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args);
99 #include <asm/archrandom.h>
101 typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args);
103 static inline u64 sc_retry(sc_func_t func, u64 fn,
104 struct tdx_module_args *args)
106 int retry = RDRAND_RETRY_LOOPS;
110 ret = func(fn, args);
111 } while (ret == TDX_RND_NO_ENTROPY && --retry);
116 #define seamcall(_fn, _args) sc_retry(__seamcall, (_fn), (_args))
117 #define seamcall_ret(_fn, _args) sc_retry(__seamcall_ret, (_fn), (_args))
118 #define seamcall_saved_ret(_fn, _args) sc_retry(__seamcall_saved_ret, (_fn), (_args))
119 int tdx_cpu_enable(void);
120 int tdx_enable(void);
121 const char *tdx_dump_mce_info(struct mce *m);
123 static inline void tdx_init(void) { }
124 static inline int tdx_cpu_enable(void) { return -ENODEV; }
125 static inline int tdx_enable(void) { return -ENODEV; }
126 static inline const char *tdx_dump_mce_info(struct mce *m) { return NULL; }
127 #endif /* CONFIG_INTEL_TDX_HOST */
129 #endif /* !__ASSEMBLY__ */
130 #endif /* _ASM_X86_TDX_H */