[PATCH 1/2] x86/tdx: Move port I/O definitions to a shared header
From: Vishal Verma
Date: Thu Sep 10 2026 - 18:38:03 EST
In preparation for switching early_printk to use direct TDVMCALLs for
I/O, factor out the PORT_READ and PORT_WRITE definitions from
arch/x86/coco/tdx/tdx.c into arch/x86/include/asm/shared/tdx.h, and
namespace them with 'TDVMCALL_'.
The decompressor also used 0/1 literals in its tdx_io_{in,out} helpers -
switch those to use the new definitions.
Signed-off-by: Vishal Verma <vishal.l.verma@xxxxxxxxx>
Cc: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
---
arch/x86/include/asm/shared/tdx.h | 4 ++++
arch/x86/boot/compressed/tdx.c | 4 ++--
arch/x86/coco/tdx/tdx.c | 8 ++------
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
index f20e91d7ac35..25429d515cc5 100644
--- a/arch/x86/include/asm/shared/tdx.h
+++ b/arch/x86/include/asm/shared/tdx.h
@@ -84,6 +84,10 @@
#define TDVMCALL_STATUS_ALIGN_ERROR 0x8000000000000002ULL
#define TDVMCALL_STATUS_SUBFUNC_UNSUPPORTED 0x8000000000000003ULL
+/* TDG.VP.VMCALL<Instruction.IO> direction, passed in R13 */
+#define TDVMCALL_PORT_READ 0
+#define TDVMCALL_PORT_WRITE 1
+
/*
* Bitmasks of exposed registers (with VMM).
*/
diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c
index 8451d6a1030c..ed278bac3c93 100644
--- a/arch/x86/boot/compressed/tdx.c
+++ b/arch/x86/boot/compressed/tdx.c
@@ -22,7 +22,7 @@ static inline unsigned int tdx_io_in(int size, u16 port)
.r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size,
- .r13 = 0,
+ .r13 = TDVMCALL_PORT_READ,
.r14 = port,
};
@@ -38,7 +38,7 @@ static inline void tdx_io_out(int size, u16 port, u32 value)
.r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size,
- .r13 = 1,
+ .r13 = TDVMCALL_PORT_WRITE,
.r14 = port,
.r15 = value,
};
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index f904a636d449..7d1a93ee2534 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -24,10 +24,6 @@
#define EPT_READ 0
#define EPT_WRITE 1
-/* Port I/O direction */
-#define PORT_READ 0
-#define PORT_WRITE 1
-
/* See Exit Qualification for I/O Instructions in VMX documentation */
#define VE_IS_IO_IN(e) ((e) & BIT(3))
#define VE_GET_IO_SIZE(e) (((e) & GENMASK(2, 0)) + 1)
@@ -691,7 +687,7 @@ static bool handle_in(struct pt_regs *regs, int size, int port)
.r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size,
- .r13 = PORT_READ,
+ .r13 = TDVMCALL_PORT_READ,
.r14 = port,
};
bool success;
@@ -720,7 +716,7 @@ static bool handle_out(struct pt_regs *regs, int size, int port)
* "TDG.VP.VMCALL<Instruction.IO>".
*/
return !_tdx_hypercall(hcall_func(EXIT_REASON_IO_INSTRUCTION), size,
- PORT_WRITE, port, regs->ax & mask);
+ TDVMCALL_PORT_WRITE, port, regs->ax & mask);
}
/*
--
2.55.0