1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <asm/asm-offsets.h>
6 * TDCALL and SEAMCALL are supported in Binutils >= 2.36.
8 #define tdcall .byte 0x66,0x0f,0x01,0xcc
9 #define seamcall .byte 0x66,0x0f,0x01,0xcf
12 * TDX_MODULE_CALL - common helper macro for both
13 * TDCALL and SEAMCALL instructions.
15 * TDCALL - used by TDX guests to make requests to the
16 * TDX module and hypercalls to the VMM.
17 * SEAMCALL - used by TDX hosts to make requests to the
20 .macro TDX_MODULE_CALL host:req
22 * R12 will be used as temporary storage for struct tdx_module_output
23 * pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL
24 * services supported by this function, it can be reused.
27 /* Callee saved, so preserve it */
31 * Push output pointer to stack.
32 * After the operation, it will be fetched into R12 register.
36 /* Mangle function call ABI into TDCALL/SEAMCALL ABI: */
37 /* Move Leaf ID to RAX */
39 /* Move input 4 to R9 */
41 /* Move input 3 to R8 */
43 /* Move input 1 to RCX */
45 /* Leave input param 2 in RDX */
50 * SEAMCALL instruction is essentially a VMExit from VMX root
51 * mode to SEAM VMX root mode. VMfailInvalid (CF=1) indicates
52 * that the targeted SEAM firmware is not loaded or disabled,
53 * or P-SEAMLDR is busy with another SEAMCALL. %rax is not
54 * changed in this case.
56 * Set %rax to TDX_SEAMCALL_VMFAILINVALID for VMfailInvalid.
57 * This value will never be used as actual SEAMCALL error code as
58 * it is from the Reserved status code class.
60 jnc .Lno_vmfailinvalid
61 mov $TDX_SEAMCALL_VMFAILINVALID, %rax
69 * Fetch output pointer from stack to R12 (It is used
70 * as temporary storage)
75 * Since this macro can be invoked with NULL as an output pointer,
76 * check if caller provided an output struct before storing output
79 * Update output registers, even if the call failed (RAX != 0).
80 * Other registers may contain details of the failure.
85 /* Copy result registers to output struct: */
86 movq %rcx, TDX_MODULE_rcx(%r12)
87 movq %rdx, TDX_MODULE_rdx(%r12)
88 movq %r8, TDX_MODULE_r8(%r12)
89 movq %r9, TDX_MODULE_r9(%r12)
90 movq %r10, TDX_MODULE_r10(%r12)
91 movq %r11, TDX_MODULE_r11(%r12)
94 /* Restore the state of R12 register */