[RFC PATCH 11/15] x86/tdx: Add TDG.TDI.START module call wrapper for TDX Connect

From: Zhenzhong Duan

Date: Thu Sep 24 2026 - 00:13:04 EST


Add tdx_mcall_tdi_start() to signal that the TD is ready to start a TDI
instance. After a successful module call, the TDX module authorizes the
host to start the TDI with the TDH.TDI.START seamcall.

Translate TDX module return codes into Linux errno values.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx>
---
arch/x86/coco/tdx/tdx_connect.c | 27 +++++++++++++++++++++++++++
arch/x86/include/asm/shared/tdx.h | 1 +
arch/x86/include/asm/tdx.h | 1 +
3 files changed, 29 insertions(+)

diff --git a/arch/x86/coco/tdx/tdx_connect.c b/arch/x86/coco/tdx/tdx_connect.c
index 09a92fe23357..3ef10b1df401 100644
--- a/arch/x86/coco/tdx/tdx_connect.c
+++ b/arch/x86/coco/tdx/tdx_connect.c
@@ -109,3 +109,30 @@ int tdx_mcall_mmio_accept(u64 func_id, u64 index, u32 pg_offset, u32 page_cnt, p
return tdx_mcall_tdi_to_errno(ret);
}
EXPORT_SYMBOL_FOR_MODULES(tdx_mcall_mmio_accept, "tdx-guest");
+
+/**
+ * tdx_mcall_tdi_start() - Authorize TDX module to start the TDI instance
+ * @func_id: Function identifier specifying the TDI instance
+ * @exp_bind_session: Expected bind session ID
+ *
+ * Signal TDX module that TD is ready to start TDI. Upon success, TDX module
+ * allows host to initiate TDI via TDH.TDI.START seamcall.
+ *
+ * Return 0 on success, -ENXIO for invalid operands, -EBUSY for busy operation,
+ * -ENODEV for TDI not present or invalid metadata, or -EIO on other TDCALL failures.
+ */
+int tdx_mcall_tdi_start(u64 func_id, u64 exp_bind_session)
+{
+ struct tdx_module_args args = {
+ .rcx = func_id,
+ .rdx = exp_bind_session,
+ };
+ u64 ret;
+
+ ret = __tdcall(TDG_TDI_START, &args);
+ if (!ret)
+ return 0;
+
+ return tdx_mcall_tdi_to_errno(ret);
+}
+EXPORT_SYMBOL_FOR_MODULES(tdx_mcall_tdi_start, "tdx-guest");
diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
index ce80fb2116fb..72520f09ef3f 100644
--- a/arch/x86/include/asm/shared/tdx.h
+++ b/arch/x86/include/asm/shared/tdx.h
@@ -21,6 +21,7 @@
#define TDG_VM_RD 7
#define TDG_VM_WR 8
#define TDG_TDI_READ 67
+#define TDG_TDI_START 68
#define TDG_MMIO_ACCEPT 71

/* TDX TD attributes */
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index e6493f3bc0d1..787b3039ef5a 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -156,6 +156,7 @@ struct tdcm_rsp_check_teeio_supp {
u64 tdx_hcall_tdcm(u16 devid, void *buf, size_t size, u8 vector);
int tdx_mcall_tdi_read(u64 func_id, u64 field, u64 *value);
int tdx_mcall_mmio_accept(u64 func_id, u64 index, u32 pg_offset, u32 page_cnt, phys_addr_t gpa);
+int tdx_mcall_tdi_start(u64 func_id, u64 exp_bind_session);
#endif

void __init tdx_dump_attributes(u64 td_attr);
--
2.52.0