x86/tdx: Add __tdx_module_call() and __tdx_hypercall() helper functions
[linux-block.git] / arch / x86 / include / asm / tdx.h
CommitLineData
59bd54a8
KS
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2021-2022 Intel Corporation */
3#ifndef _ASM_X86_TDX_H
4#define _ASM_X86_TDX_H
5
eb94f1b6 6#include <linux/bits.h>
59bd54a8 7#include <linux/init.h>
527a534c 8#include <linux/bits.h>
59bd54a8
KS
9
10#define TDX_CPUID_LEAF_ID 0x21
11#define TDX_IDENT "IntelTDX "
12
eb94f1b6
KS
13#define TDX_HYPERCALL_STANDARD 0
14
15#define TDX_HCALL_HAS_OUTPUT BIT(0)
16
527a534c
KS
17/*
18 * SW-defined error codes.
19 *
20 * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
21 * TDX module.
22 */
23#define TDX_ERROR _BITUL(63)
24#define TDX_SW_ERROR (TDX_ERROR | GENMASK_ULL(47, 40))
25#define TDX_SEAMCALL_VMFAILINVALID (TDX_SW_ERROR | _UL(0xFFFF0000))
26
27#ifndef __ASSEMBLY__
28
29/*
30 * Used to gather the output registers values of the TDCALL and SEAMCALL
31 * instructions when requesting services from the TDX module.
32 *
33 * This is a software only structure and not part of the TDX module/VMM ABI.
34 */
35struct tdx_module_output {
36 u64 rcx;
37 u64 rdx;
38 u64 r8;
39 u64 r9;
40 u64 r10;
41 u64 r11;
42};
43
eb94f1b6
KS
44/*
45 * Used in __tdx_hypercall() to pass down and get back registers' values of
46 * the TDCALL instruction when requesting services from the VMM.
47 *
48 * This is a software only structure and not part of the TDX module/VMM ABI.
49 */
50struct tdx_hypercall_args {
51 u64 r10;
52 u64 r11;
53 u64 r12;
54 u64 r13;
55 u64 r14;
56 u64 r15;
57};
58
59bd54a8
KS
59#ifdef CONFIG_INTEL_TDX_GUEST
60
61void __init tdx_early_init(void);
62
eb94f1b6
KS
63/* Used to communicate with the TDX module */
64u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
65 struct tdx_module_output *out);
66
67/* Used to request services from the VMM */
68u64 __tdx_hypercall(struct tdx_hypercall_args *args, unsigned long flags);
69
70/* Called from __tdx_hypercall() for unrecoverable failure */
71void __tdx_hypercall_failed(void);
72
59bd54a8
KS
73#else
74
75static inline void tdx_early_init(void) { };
76
77#endif /* CONFIG_INTEL_TDX_GUEST */
78
527a534c 79#endif /* !__ASSEMBLY__ */
59bd54a8 80#endif /* _ASM_X86_TDX_H */