1 // SPDX-License-Identifier: GPL-2.0
3 #include "../cpuflags.h"
8 #include <vdso/limits.h>
9 #include <uapi/asm/vmx.h>
11 #include <asm/shared/tdx.h>
13 /* Called from __tdx_hypercall() for unrecoverable failure */
14 void __tdx_hypercall_failed(void)
16 error("TDVMCALL failed. TDX module bug?");
19 static inline unsigned int tdx_io_in(int size, u16 port)
21 struct tdx_hypercall_args args = {
22 .r10 = TDX_HYPERCALL_STANDARD,
23 .r11 = EXIT_REASON_IO_INSTRUCTION,
29 if (__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT))
35 static inline void tdx_io_out(int size, u16 port, u32 value)
37 struct tdx_hypercall_args args = {
38 .r10 = TDX_HYPERCALL_STANDARD,
39 .r11 = EXIT_REASON_IO_INSTRUCTION,
46 __tdx_hypercall(&args, 0);
49 static inline u8 tdx_inb(u16 port)
51 return tdx_io_in(1, port);
54 static inline void tdx_outb(u8 value, u16 port)
56 tdx_io_out(1, port, value);
59 static inline void tdx_outw(u16 value, u16 port)
61 tdx_io_out(2, port, value);
64 void early_tdx_detect(void)
68 cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &sig[0], &sig[2], &sig[1]);
70 if (memcmp(TDX_IDENT, sig, sizeof(sig)))
73 /* Use hypercalls instead of I/O instructions */
74 pio_ops.f_inb = tdx_inb;
75 pio_ops.f_outb = tdx_outb;
76 pio_ops.f_outw = tdx_outw;