Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2021-2022 Intel Corporation */
0003 #ifndef _ASM_X86_TDX_H
0004 #define _ASM_X86_TDX_H
0005 
0006 #include <linux/init.h>
0007 #include <linux/bits.h>
0008 #include <asm/ptrace.h>
0009 #include <asm/shared/tdx.h>
0010 
0011 /*
0012  * SW-defined error codes.
0013  *
0014  * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
0015  * TDX module.
0016  */
0017 #define TDX_ERROR           _BITUL(63)
0018 #define TDX_SW_ERROR            (TDX_ERROR | GENMASK_ULL(47, 40))
0019 #define TDX_SEAMCALL_VMFAILINVALID  (TDX_SW_ERROR | _UL(0xFFFF0000))
0020 
0021 #ifndef __ASSEMBLY__
0022 
0023 /*
0024  * Used to gather the output registers values of the TDCALL and SEAMCALL
0025  * instructions when requesting services from the TDX module.
0026  *
0027  * This is a software only structure and not part of the TDX module/VMM ABI.
0028  */
0029 struct tdx_module_output {
0030     u64 rcx;
0031     u64 rdx;
0032     u64 r8;
0033     u64 r9;
0034     u64 r10;
0035     u64 r11;
0036 };
0037 
0038 /*
0039  * Used by the #VE exception handler to gather the #VE exception
0040  * info from the TDX module. This is a software only structure
0041  * and not part of the TDX module/VMM ABI.
0042  */
0043 struct ve_info {
0044     u64 exit_reason;
0045     u64 exit_qual;
0046     /* Guest Linear (virtual) Address */
0047     u64 gla;
0048     /* Guest Physical Address */
0049     u64 gpa;
0050     u32 instr_len;
0051     u32 instr_info;
0052 };
0053 
0054 #ifdef CONFIG_INTEL_TDX_GUEST
0055 
0056 void __init tdx_early_init(void);
0057 
0058 /* Used to communicate with the TDX module */
0059 u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
0060               struct tdx_module_output *out);
0061 
0062 void tdx_get_ve_info(struct ve_info *ve);
0063 
0064 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
0065 
0066 void tdx_safe_halt(void);
0067 
0068 bool tdx_early_handle_ve(struct pt_regs *regs);
0069 
0070 #else
0071 
0072 static inline void tdx_early_init(void) { };
0073 static inline void tdx_safe_halt(void) { };
0074 
0075 static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; }
0076 
0077 #endif /* CONFIG_INTEL_TDX_GUEST */
0078 
0079 #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_INTEL_TDX_GUEST)
0080 long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
0081                unsigned long p3, unsigned long p4);
0082 #else
0083 static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
0084                      unsigned long p2, unsigned long p3,
0085                      unsigned long p4)
0086 {
0087     return -ENODEV;
0088 }
0089 #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
0090 #endif /* !__ASSEMBLY__ */
0091 #endif /* _ASM_X86_TDX_H */