Commit | Line | Data |
---|---|---|
a1f22614 BS |
1 | /** @file\r |
2 | \r | |
3 | Define Secure Encrypted Virtualization (SEV) base library helper function\r | |
4 | \r | |
b78de543 | 5 | Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>\r |
a1f22614 | 6 | \r |
b26f0cf9 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a1f22614 BS |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #ifndef _MEM_ENCRYPT_SEV_LIB_H_\r | |
12 | #define _MEM_ENCRYPT_SEV_LIB_H_\r | |
13 | \r | |
14 | #include <Base.h>\r | |
80e67af9 | 15 | #include <WorkArea.h>\r |
a1f22614 | 16 | \r |
5667dc43 TL |
17 | //\r |
18 | // Define the maximum number of #VCs allowed (e.g. the level of nesting\r | |
19 | // that is allowed => 2 allows for 1 nested #VCs). I this value is changed,\r | |
20 | // be sure to increase the size of\r | |
21 | // gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize\r | |
22 | // in any FDF file using this PCD.\r | |
23 | //\r | |
ac0a286f | 24 | #define VMGEXIT_MAXIMUM_VC_COUNT 2\r |
5667dc43 TL |
25 | \r |
26 | //\r | |
27 | // Per-CPU data mapping structure\r | |
28 | // Use UINT32 for cached indicators and compare to a specific value\r | |
29 | // so that the hypervisor can't indicate a value is cached by just\r | |
30 | // writing random data to that area.\r | |
31 | //\r | |
32 | typedef struct {\r | |
ac0a286f MK |
33 | UINT32 Dr7Cached;\r |
34 | UINT64 Dr7;\r | |
5667dc43 | 35 | \r |
ac0a286f MK |
36 | UINTN VcCount;\r |
37 | VOID *GhcbBackupPages;\r | |
5667dc43 TL |
38 | } SEV_ES_PER_CPU_DATA;\r |
39 | \r | |
c330af02 TL |
40 | //\r |
41 | // Memory encryption address range states.\r | |
42 | //\r | |
43 | typedef enum {\r | |
44 | MemEncryptSevAddressRangeUnencrypted,\r | |
45 | MemEncryptSevAddressRangeEncrypted,\r | |
46 | MemEncryptSevAddressRangeMixed,\r | |
47 | MemEncryptSevAddressRangeError,\r | |
48 | } MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE;\r | |
49 | \r | |
d9822304 BS |
50 | /**\r |
51 | Returns a boolean to indicate whether SEV-SNP is enabled\r | |
52 | \r | |
53 | @retval TRUE SEV-SNP is enabled\r | |
54 | @retval FALSE SEV-SNP is not enabled\r | |
55 | **/\r | |
56 | BOOLEAN\r | |
57 | EFIAPI\r | |
58 | MemEncryptSevSnpIsEnabled (\r | |
59 | VOID\r | |
60 | );\r | |
61 | \r | |
0afa1d08 TL |
62 | /**\r |
63 | Returns a boolean to indicate whether SEV-ES is enabled.\r | |
64 | \r | |
65 | @retval TRUE SEV-ES is enabled\r | |
66 | @retval FALSE SEV-ES is not enabled\r | |
67 | **/\r | |
68 | BOOLEAN\r | |
69 | EFIAPI\r | |
70 | MemEncryptSevEsIsEnabled (\r | |
71 | VOID\r | |
72 | );\r | |
73 | \r | |
a1f22614 BS |
74 | /**\r |
75 | Returns a boolean to indicate whether SEV is enabled\r | |
76 | \r | |
d4dd22c7 | 77 | @retval TRUE SEV is enabled\r |
a1f22614 | 78 | @retval FALSE SEV is not enabled\r |
d4dd22c7 | 79 | **/\r |
a1f22614 BS |
80 | BOOLEAN\r |
81 | EFIAPI\r | |
82 | MemEncryptSevIsEnabled (\r | |
83 | VOID\r | |
84 | );\r | |
85 | \r | |
86 | /**\r | |
5b5028e6 LE |
87 | This function clears memory encryption bit for the memory region specified by\r |
88 | BaseAddress and NumPages from the current page table context.\r | |
89 | \r | |
90 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
91 | current CR3)\r | |
92 | @param[in] BaseAddress The physical address that is the start\r | |
93 | address of a memory region.\r | |
94 | @param[in] NumPages The number of pages from start memory\r | |
95 | region.\r | |
5b5028e6 LE |
96 | \r |
97 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
98 | memory region.\r | |
99 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
100 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
101 | is not supported\r | |
102 | **/\r | |
a1f22614 BS |
103 | RETURN_STATUS\r |
104 | EFIAPI\r | |
105 | MemEncryptSevClearPageEncMask (\r | |
ac0a286f MK |
106 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
107 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
108 | IN UINTN NumPages\r | |
a1f22614 BS |
109 | );\r |
110 | \r | |
111 | /**\r | |
112 | This function sets memory encryption bit for the memory region specified by\r | |
154dcd6c | 113 | BaseAddress and NumPages from the current page table context.\r |
a1f22614 | 114 | \r |
154dcd6c LE |
115 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
116 | current CR3)\r | |
117 | @param[in] BaseAddress The physical address that is the start\r | |
118 | address of a memory region.\r | |
119 | @param[in] NumPages The number of pages from start memory\r | |
120 | region.\r | |
a1f22614 | 121 | \r |
154dcd6c LE |
122 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
123 | region.\r | |
124 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
125 | @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r | |
126 | is not supported\r | |
127 | **/\r | |
a1f22614 BS |
128 | RETURN_STATUS\r |
129 | EFIAPI\r | |
130 | MemEncryptSevSetPageEncMask (\r | |
ac0a286f MK |
131 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
132 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
133 | IN UINTN NumPages\r | |
a1f22614 | 134 | );\r |
61a044c6 | 135 | \r |
61a044c6 LE |
136 | /**\r |
137 | Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM\r | |
138 | Save State Map.\r | |
139 | \r | |
140 | @param[out] BaseAddress The base address of the lowest-address page that\r | |
141 | covers the initial SMRAM Save State Map.\r | |
142 | \r | |
143 | @param[out] NumberOfPages The number of pages in the page range that covers\r | |
144 | the initial SMRAM Save State Map.\r | |
145 | \r | |
146 | @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on\r | |
147 | output.\r | |
148 | \r | |
149 | @retval RETURN_UNSUPPORTED SMM is unavailable.\r | |
150 | **/\r | |
151 | RETURN_STATUS\r | |
152 | EFIAPI\r | |
153 | MemEncryptSevLocateInitialSmramSaveStateMapPages (\r | |
ac0a286f MK |
154 | OUT UINTN *BaseAddress,\r |
155 | OUT UINTN *NumberOfPages\r | |
61a044c6 | 156 | );\r |
b97dc4b9 TL |
157 | \r |
158 | /**\r | |
159 | Returns the SEV encryption mask.\r | |
160 | \r | |
161 | @return The SEV pagetable encryption mask\r | |
162 | **/\r | |
163 | UINT64\r | |
164 | EFIAPI\r | |
165 | MemEncryptSevGetEncryptionMask (\r | |
166 | VOID\r | |
167 | );\r | |
168 | \r | |
c330af02 TL |
169 | /**\r |
170 | Returns the encryption state of the specified virtual address range.\r | |
171 | \r | |
172 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
173 | current CR3)\r | |
174 | @param[in] BaseAddress Base address to check\r | |
175 | @param[in] Length Length of virtual address range\r | |
176 | \r | |
177 | @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r | |
178 | unencrypted\r | |
179 | @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r | |
180 | encrypted\r | |
181 | @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r | |
182 | @retval MemEncryptSevAddressRangeError Address range is not mapped\r | |
183 | **/\r | |
184 | MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r | |
185 | EFIAPI\r | |
186 | MemEncryptSevGetAddressRangeState (\r | |
ac0a286f MK |
187 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
188 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
189 | IN UINTN Length\r | |
c330af02 TL |
190 | );\r |
191 | \r | |
901a9bfc BS |
192 | /**\r |
193 | This function clears memory encryption bit for the MMIO region specified by\r | |
194 | BaseAddress and NumPages.\r | |
195 | \r | |
196 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
197 | current CR3)\r | |
198 | @param[in] BaseAddress The physical address that is the start\r | |
199 | address of a MMIO region.\r | |
200 | @param[in] NumPages The number of pages from start memory\r | |
201 | region.\r | |
202 | \r | |
203 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
204 | memory region.\r | |
205 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
206 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
207 | is not supported\r | |
208 | **/\r | |
209 | RETURN_STATUS\r | |
210 | EFIAPI\r | |
211 | MemEncryptSevClearMmioPageEncMask (\r | |
ac0a286f MK |
212 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
213 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
214 | IN UINTN NumPages\r | |
901a9bfc BS |
215 | );\r |
216 | \r | |
ade62c18 BS |
217 | /**\r |
218 | Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.\r | |
219 | \r | |
220 | @param[in] BaseAddress Base address\r | |
221 | @param[in] NumPages Number of pages starting from the base address\r | |
222 | \r | |
223 | **/\r | |
224 | VOID\r | |
225 | EFIAPI\r | |
226 | MemEncryptSevSnpPreValidateSystemRam (\r | |
227 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
228 | IN UINTN NumPages\r | |
229 | );\r | |
230 | \r | |
a1f22614 | 231 | #endif // _MEM_ENCRYPT_SEV_LIB_H_\r |