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 #include "tdx_global_metadata.h"
7 
8 /*
9  * This file contains both macros and data structures defined by the TDX
10  * architecture and Linux defined software data structures and functions.
11  * The two should not be mixed together for better readability.  The
12  * architectural definitions come first.
13  */
14 
15 /*
16  * TDX module SEAMCALL leaf functions
17  */
18 #define TDH_PHYMEM_PAGE_RDMD	24
19 #define TDH_SYS_KEY_CONFIG	31
20 #define TDH_SYS_INIT		33
21 #define TDH_SYS_RD		34
22 #define TDH_SYS_LP_INIT		35
23 #define TDH_SYS_TDMR_INIT	36
24 #define TDH_SYS_CONFIG		45
25 
26 /* TDX page types */
27 #define	PT_NDA		0x0
28 #define	PT_RSVD		0x1
29 
30 struct tdmr_reserved_area {
31 	u64 offset;
32 	u64 size;
33 } __packed;
34 
35 #define TDMR_INFO_ALIGNMENT	512
36 #define TDMR_INFO_PA_ARRAY_ALIGNMENT	512
37 
38 struct tdmr_info {
39 	u64 base;
40 	u64 size;
41 	u64 pamt_1g_base;
42 	u64 pamt_1g_size;
43 	u64 pamt_2m_base;
44 	u64 pamt_2m_size;
45 	u64 pamt_4k_base;
46 	u64 pamt_4k_size;
47 	/*
48 	 * The actual number of reserved areas depends on the value of
49 	 * field MD_FIELD_ID_MAX_RESERVED_PER_TDMR in the TDX module
50 	 * global metadata.
51 	 */
52 	DECLARE_FLEX_ARRAY(struct tdmr_reserved_area, reserved_areas);
53 } __packed __aligned(TDMR_INFO_ALIGNMENT);
54 
55 /* Bit definitions of TDX_FEATURES0 metadata field */
56 #define TDX_FEATURES0_NO_RBP_MOD	BIT(18)
57 
58 /*
59  * Do not put any hardware-defined TDX structure representations below
60  * this comment!
61  */
62 
63 /* Kernel defined TDX module status during module initialization. */
64 enum tdx_module_status_t {
65 	TDX_MODULE_UNINITIALIZED,
66 	TDX_MODULE_INITIALIZED,
67 	TDX_MODULE_ERROR
68 };
69 
70 struct tdx_memblock {
71 	struct list_head list;
72 	unsigned long start_pfn;
73 	unsigned long end_pfn;
74 	int nid;
75 };
76 
77 /* Warn if kernel has less than TDMR_NR_WARN TDMRs after allocation */
78 #define TDMR_NR_WARN 4
79 
80 struct tdmr_info_list {
81 	void *tdmrs;	/* Flexible array to hold 'tdmr_info's */
82 	int nr_consumed_tdmrs;	/* How many 'tdmr_info's are in use */
83 
84 	/* Metadata for finding target 'tdmr_info' and freeing @tdmrs */
85 	int tdmr_sz;	/* Size of one 'tdmr_info' */
86 	int max_tdmrs;	/* How many 'tdmr_info's are allocated */
87 };
88 
89 #endif
90