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