]>
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 | |
24 | #define VMGEXIT_MAXIMUM_VC_COUNT 2\r | |
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 | |
33 | UINT32 Dr7Cached;\r | |
34 | UINT64 Dr7;\r | |
35 | \r | |
36 | UINTN VcCount;\r | |
37 | VOID *GhcbBackupPages;\r | |
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 | |
0afa1d08 TL |
50 | /**\r |
51 | Returns a boolean to indicate whether SEV-ES is enabled.\r | |
52 | \r | |
53 | @retval TRUE SEV-ES is enabled\r | |
54 | @retval FALSE SEV-ES is not enabled\r | |
55 | **/\r | |
56 | BOOLEAN\r | |
57 | EFIAPI\r | |
58 | MemEncryptSevEsIsEnabled (\r | |
59 | VOID\r | |
60 | );\r | |
61 | \r | |
a1f22614 BS |
62 | /**\r |
63 | Returns a boolean to indicate whether SEV is enabled\r | |
64 | \r | |
d4dd22c7 | 65 | @retval TRUE SEV is enabled\r |
a1f22614 | 66 | @retval FALSE SEV is not enabled\r |
d4dd22c7 | 67 | **/\r |
a1f22614 BS |
68 | BOOLEAN\r |
69 | EFIAPI\r | |
70 | MemEncryptSevIsEnabled (\r | |
71 | VOID\r | |
72 | );\r | |
73 | \r | |
74 | /**\r | |
5b5028e6 LE |
75 | This function clears memory encryption bit for the memory region specified by\r |
76 | BaseAddress and NumPages from the current page table context.\r | |
77 | \r | |
78 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
79 | current CR3)\r | |
80 | @param[in] BaseAddress The physical address that is the start\r | |
81 | address of a memory region.\r | |
82 | @param[in] NumPages The number of pages from start memory\r | |
83 | region.\r | |
5b5028e6 LE |
84 | \r |
85 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
86 | memory region.\r | |
87 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
88 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
89 | is not supported\r | |
90 | **/\r | |
a1f22614 BS |
91 | RETURN_STATUS\r |
92 | EFIAPI\r | |
93 | MemEncryptSevClearPageEncMask (\r | |
94 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
95 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
adfa3327 | 96 | IN UINTN NumPages\r |
a1f22614 BS |
97 | );\r |
98 | \r | |
99 | /**\r | |
100 | This function sets memory encryption bit for the memory region specified by\r | |
154dcd6c | 101 | BaseAddress and NumPages from the current page table context.\r |
a1f22614 | 102 | \r |
154dcd6c LE |
103 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
104 | current CR3)\r | |
105 | @param[in] BaseAddress The physical address that is the start\r | |
106 | address of a memory region.\r | |
107 | @param[in] NumPages The number of pages from start memory\r | |
108 | region.\r | |
a1f22614 | 109 | \r |
154dcd6c LE |
110 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
111 | region.\r | |
112 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
113 | @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r | |
114 | is not supported\r | |
115 | **/\r | |
a1f22614 BS |
116 | RETURN_STATUS\r |
117 | EFIAPI\r | |
118 | MemEncryptSevSetPageEncMask (\r | |
119 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
120 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
adfa3327 | 121 | IN UINTN NumPages\r |
a1f22614 | 122 | );\r |
61a044c6 LE |
123 | \r |
124 | \r | |
125 | /**\r | |
126 | Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM\r | |
127 | Save State Map.\r | |
128 | \r | |
129 | @param[out] BaseAddress The base address of the lowest-address page that\r | |
130 | covers the initial SMRAM Save State Map.\r | |
131 | \r | |
132 | @param[out] NumberOfPages The number of pages in the page range that covers\r | |
133 | the initial SMRAM Save State Map.\r | |
134 | \r | |
135 | @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on\r | |
136 | output.\r | |
137 | \r | |
138 | @retval RETURN_UNSUPPORTED SMM is unavailable.\r | |
139 | **/\r | |
140 | RETURN_STATUS\r | |
141 | EFIAPI\r | |
142 | MemEncryptSevLocateInitialSmramSaveStateMapPages (\r | |
143 | OUT UINTN *BaseAddress,\r | |
144 | OUT UINTN *NumberOfPages\r | |
145 | );\r | |
b97dc4b9 TL |
146 | \r |
147 | /**\r | |
148 | Returns the SEV encryption mask.\r | |
149 | \r | |
150 | @return The SEV pagetable encryption mask\r | |
151 | **/\r | |
152 | UINT64\r | |
153 | EFIAPI\r | |
154 | MemEncryptSevGetEncryptionMask (\r | |
155 | VOID\r | |
156 | );\r | |
157 | \r | |
c330af02 TL |
158 | /**\r |
159 | Returns the encryption state of the specified virtual address range.\r | |
160 | \r | |
161 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
162 | current CR3)\r | |
163 | @param[in] BaseAddress Base address to check\r | |
164 | @param[in] Length Length of virtual address range\r | |
165 | \r | |
166 | @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r | |
167 | unencrypted\r | |
168 | @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r | |
169 | encrypted\r | |
170 | @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r | |
171 | @retval MemEncryptSevAddressRangeError Address range is not mapped\r | |
172 | **/\r | |
173 | MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r | |
174 | EFIAPI\r | |
175 | MemEncryptSevGetAddressRangeState (\r | |
176 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
177 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
178 | IN UINTN Length\r | |
179 | );\r | |
180 | \r | |
901a9bfc BS |
181 | /**\r |
182 | This function clears memory encryption bit for the MMIO region specified by\r | |
183 | BaseAddress and NumPages.\r | |
184 | \r | |
185 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
186 | current CR3)\r | |
187 | @param[in] BaseAddress The physical address that is the start\r | |
188 | address of a MMIO region.\r | |
189 | @param[in] NumPages The number of pages from start memory\r | |
190 | region.\r | |
191 | \r | |
192 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
193 | memory region.\r | |
194 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
195 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
196 | is not supported\r | |
197 | **/\r | |
198 | RETURN_STATUS\r | |
199 | EFIAPI\r | |
200 | MemEncryptSevClearMmioPageEncMask (\r | |
201 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
202 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
203 | IN UINTN NumPages\r | |
204 | );\r | |
205 | \r | |
a1f22614 | 206 | #endif // _MEM_ENCRYPT_SEV_LIB_H_\r |