Debian Codegraph @

arch/x86/virt/vmx/tdx/tdx.h

raw
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _X86_VIRT_TDX_H
3 #define _X86_VIRT_TDX_H
4
5 #include <linux/bits.h>
6
7 /*
8 * This file contains both macros and data structures defined by the TDX
9 * architecture and Linux defined software data structures and functions.
10 * The two should not be mixed together for better readability. The
11 * architectural definitions come first.
12 */
13
14 /*
15 * TDX module SEAMCALL leaf functions
16 */
17 #define TDH_VP_ENTER 0
18 #define TDH_MNG_ADDCX 1
19 #define TDH_MEM_PAGE_ADD 2
20 #define TDH_MEM_SEPT_ADD 3
21 #define TDH_VP_ADDCX 4
22 #define TDH_MEM_PAGE_AUG 6
23 #define TDH_MEM_RANGE_BLOCK 7
24 #define TDH_MNG_KEY_CONFIG 8
25 #define TDH_MNG_CREATE 9
26 #define TDH_MNG_RD 11
27 #define TDH_MR_EXTEND 16
28 #define TDH_MR_FINALIZE 17
29 #define TDH_VP_FLUSH 18
30 #define TDH_MNG_VPFLUSHDONE 19
31 #define TDH_VP_CREATE 10
32 #define TDH_MNG_KEY_FREEID 20
33 #define TDH_MNG_INIT 21
34 #define TDH_VP_INIT 22
35 #define TDH_PHYMEM_PAGE_RDMD 24
36 #define TDH_VP_RD 26
37 #define TDH_PHYMEM_PAGE_RECLAIM 28
38 #define TDH_MEM_PAGE_REMOVE 29
39 #define TDH_SYS_KEY_CONFIG 31
40 #define TDH_SYS_INIT 33
41 #define TDH_SYS_RD 34
42 #define TDH_SYS_LP_INIT 35
43 #define TDH_SYS_TDMR_INIT 36
44 #define TDH_MEM_TRACK 38
45 #define TDH_PHYMEM_CACHE_WB 40
46 #define TDH_PHYMEM_PAGE_WBINVD 41
47 #define TDH_VP_WR 43
48 #define TDH_SYS_CONFIG 45
49
50 /*
51 * SEAMCALL leaf:
52 *
53 * Bit 15:0 Leaf number
54 * Bit 23:16 Version number
55 */
56 #define TDX_VERSION_SHIFT 16
57
58 /* TDX page types */
59 #define PT_NDA 0x0
60 #define PT_RSVD 0x1
61
62 struct tdmr_reserved_area {
63 u64 offset;
64 u64 size;
65 } __packed;
66
67 #define TDMR_INFO_ALIGNMENT 512
68 #define TDMR_INFO_PA_ARRAY_ALIGNMENT 512
69
70 struct tdmr_info {
71 u64 base;
72 u64 size;
73 u64 pamt_1g_base;
74 u64 pamt_1g_size;
75 u64 pamt_2m_base;
76 u64 pamt_2m_size;
77 u64 pamt_4k_base;
78 u64 pamt_4k_size;
79 /*
80 * The actual number of reserved areas depends on the value of
81 * field MD_FIELD_ID_MAX_RESERVED_PER_TDMR in the TDX module
82 * global metadata.
83 */
84 DECLARE_FLEX_ARRAY(struct tdmr_reserved_area, reserved_areas);
85 } __packed __aligned(TDMR_INFO_ALIGNMENT);
86
87 /* Bit definitions of TDX_FEATURES0 metadata field */
88 #define TDX_FEATURES0_NO_RBP_MOD BIT(18)
89
90 /*
91 * Do not put any hardware-defined TDX structure representations below
92 * this comment!
93 */
94
95 /* Kernel defined TDX module status during module initialization. */
96 enum tdx_module_status_t {
97 TDX_MODULE_UNINITIALIZED,
98 TDX_MODULE_INITIALIZED,
99 TDX_MODULE_ERROR
100 };
101
102 struct tdx_memblock {
103 struct list_head list;
104 unsigned long start_pfn;
105 unsigned long end_pfn;
106 int nid;
107 };
108
109 /* Warn if kernel has less than TDMR_NR_WARN TDMRs after allocation */
110 #define TDMR_NR_WARN 4
111
112 struct tdmr_info_list {
113 void *tdmrs; /* Flexible array to hold 'tdmr_info's */
114 int nr_consumed_tdmrs; /* How many 'tdmr_info's are in use */
115
116 /* Metadata for finding target 'tdmr_info' and freeing @tdmrs */
117 int tdmr_sz; /* Size of one 'tdmr_info' */
118 int max_tdmrs; /* How many 'tdmr_info's are allocated */
119 };
120
121 #endif