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 | |
9 | #include <asm/errno.h> |
10 | #include <asm/ptrace.h> |
11 | #include <asm/trapnr.h> |
12 | #include <asm/shared/tdx.h> |
13 | |
14 | /* |
15 | * SW-defined error codes. |
16 | * |
17 | * Bits 47:40 == 0xFF indicate Reserved status code class that never used by |
18 | * TDX module. |
19 | */ |
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)) |
23 | |
24 | #define TDX_SEAMCALL_GP (TDX_SW_ERROR | X86_TRAP_GP) |
25 | #define TDX_SEAMCALL_UD (TDX_SW_ERROR | X86_TRAP_UD) |
26 | |
27 | #ifndef __ASSEMBLY__ |
28 | |
29 | /* |
30 | * Used by the #VE exception handler to gather the #VE exception |
31 | * info from the TDX module. This is a software only structure |
32 | * and not part of the TDX module/VMM ABI. |
33 | */ |
34 | struct ve_info { |
35 | u64 exit_reason; |
36 | u64 exit_qual; |
37 | /* Guest Linear (virtual) Address */ |
38 | u64 gla; |
39 | /* Guest Physical Address */ |
40 | u64 gpa; |
41 | u32 instr_len; |
42 | u32 instr_info; |
43 | }; |
44 | |
45 | #ifdef CONFIG_INTEL_TDX_GUEST |
46 | |
47 | void __init tdx_early_init(void); |
48 | |
49 | void tdx_get_ve_info(struct ve_info *ve); |
50 | |
51 | bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve); |
52 | |
53 | void tdx_safe_halt(void); |
54 | |
55 | bool tdx_early_handle_ve(struct pt_regs *regs); |
56 | |
57 | int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport); |
58 | |
59 | u64 tdx_hcall_get_quote(u8 *buf, size_t size); |
60 | |
61 | #else |
62 | |
63 | static inline void tdx_early_init(void) { }; |
64 | static inline void tdx_safe_halt(void) { }; |
65 | |
66 | static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; } |
67 | |
68 | #endif /* CONFIG_INTEL_TDX_GUEST */ |
69 | |
70 | #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_INTEL_TDX_GUEST) |
71 | long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2, |
72 | unsigned long p3, unsigned long p4); |
73 | #else |
74 | static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, |
75 | unsigned long p2, unsigned long p3, |
76 | unsigned long p4) |
77 | { |
78 | return -ENODEV; |
79 | } |
80 | #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */ |
81 | |
82 | #ifdef CONFIG_INTEL_TDX_HOST |
83 | u64 __seamcall(u64 fn, struct tdx_module_args *args); |
84 | u64 __seamcall_ret(u64 fn, struct tdx_module_args *args); |
85 | u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); |
86 | #endif /* CONFIG_INTEL_TDX_HOST */ |
87 | |
88 | #endif /* !__ASSEMBLY__ */ |
89 | #endif /* _ASM_X86_TDX_H */ |
90 | |