]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/Library/MemEncryptSevLib.h
OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask()
[mirror_edk2.git] / OvmfPkg / Include / Library / MemEncryptSevLib.h
CommitLineData
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
15\r
5667dc43
TL
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
31typedef 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
b78de543
TL
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
7cb96c47 47// OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm\r
b78de543
TL
48// any changes must stay in sync with its usage.\r
49//\r
50typedef struct _SEC_SEV_ES_WORK_AREA {\r
51 UINT8 SevEsEnabled;\r
7cb96c47
TL
52 UINT8 Reserved1[7];\r
53\r
54 UINT64 RandomData;\r
3b32be7e
TL
55\r
56 UINT64 EncryptionMask;\r
b78de543
TL
57} SEC_SEV_ES_WORK_AREA;\r
58\r
c330af02
TL
59//\r
60// Memory encryption address range states.\r
61//\r
62typedef enum {\r
63 MemEncryptSevAddressRangeUnencrypted,\r
64 MemEncryptSevAddressRangeEncrypted,\r
65 MemEncryptSevAddressRangeMixed,\r
66 MemEncryptSevAddressRangeError,\r
67} MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE;\r
68\r
0afa1d08
TL
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
75BOOLEAN\r
76EFIAPI\r
77MemEncryptSevEsIsEnabled (\r
78 VOID\r
79 );\r
80\r
a1f22614
BS
81/**\r
82 Returns a boolean to indicate whether SEV is enabled\r
83\r
d4dd22c7 84 @retval TRUE SEV is enabled\r
a1f22614 85 @retval FALSE SEV is not enabled\r
d4dd22c7 86**/\r
a1f22614
BS
87BOOLEAN\r
88EFIAPI\r
89MemEncryptSevIsEnabled (\r
90 VOID\r
91 );\r
92\r
93/**\r
5b5028e6
LE
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 @param[in] Flush Flush the caches before clearing the bit\r
104 (mostly TRUE except MMIO addresses)\r
105\r
106 @retval RETURN_SUCCESS The attributes were cleared for the\r
107 memory region.\r
108 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
109 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r
110 is not supported\r
111**/\r
a1f22614
BS
112RETURN_STATUS\r
113EFIAPI\r
114MemEncryptSevClearPageEncMask (\r
115 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
116 IN PHYSICAL_ADDRESS BaseAddress,\r
5b5028e6
LE
117 IN UINTN NumPages,\r
118 IN BOOLEAN Flush\r
a1f22614
BS
119 );\r
120\r
121/**\r
122 This function sets memory encryption bit for the memory region specified by\r
154dcd6c 123 BaseAddress and NumPages from the current page table context.\r
a1f22614 124\r
154dcd6c
LE
125 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
126 current CR3)\r
127 @param[in] BaseAddress The physical address that is the start\r
128 address of a memory region.\r
129 @param[in] NumPages The number of pages from start memory\r
130 region.\r
131 @param[in] Flush Flush the caches before setting the bit\r
132 (mostly TRUE except MMIO addresses)\r
a1f22614 133\r
154dcd6c
LE
134 @retval RETURN_SUCCESS The attributes were set for the memory\r
135 region.\r
136 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
137 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r
138 is not supported\r
139**/\r
a1f22614
BS
140RETURN_STATUS\r
141EFIAPI\r
142MemEncryptSevSetPageEncMask (\r
143 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
144 IN PHYSICAL_ADDRESS BaseAddress,\r
154dcd6c
LE
145 IN UINTN NumPages,\r
146 IN BOOLEAN Flush\r
a1f22614 147 );\r
61a044c6
LE
148\r
149\r
150/**\r
151 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM\r
152 Save State Map.\r
153\r
154 @param[out] BaseAddress The base address of the lowest-address page that\r
155 covers the initial SMRAM Save State Map.\r
156\r
157 @param[out] NumberOfPages The number of pages in the page range that covers\r
158 the initial SMRAM Save State Map.\r
159\r
160 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on\r
161 output.\r
162\r
163 @retval RETURN_UNSUPPORTED SMM is unavailable.\r
164**/\r
165RETURN_STATUS\r
166EFIAPI\r
167MemEncryptSevLocateInitialSmramSaveStateMapPages (\r
168 OUT UINTN *BaseAddress,\r
169 OUT UINTN *NumberOfPages\r
170 );\r
b97dc4b9
TL
171\r
172/**\r
173 Returns the SEV encryption mask.\r
174\r
175 @return The SEV pagetable encryption mask\r
176**/\r
177UINT64\r
178EFIAPI\r
179MemEncryptSevGetEncryptionMask (\r
180 VOID\r
181 );\r
182\r
c330af02
TL
183/**\r
184 Returns the encryption state of the specified virtual address range.\r
185\r
186 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
187 current CR3)\r
188 @param[in] BaseAddress Base address to check\r
189 @param[in] Length Length of virtual address range\r
190\r
191 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r
192 unencrypted\r
193 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r
194 encrypted\r
195 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r
196 @retval MemEncryptSevAddressRangeError Address range is not mapped\r
197**/\r
198MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r
199EFIAPI\r
200MemEncryptSevGetAddressRangeState (\r
201 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
202 IN PHYSICAL_ADDRESS BaseAddress,\r
203 IN UINTN Length\r
204 );\r
205\r
901a9bfc
BS
206/**\r
207 This function clears memory encryption bit for the MMIO region specified by\r
208 BaseAddress and NumPages.\r
209\r
210 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
211 current CR3)\r
212 @param[in] BaseAddress The physical address that is the start\r
213 address of a MMIO region.\r
214 @param[in] NumPages The number of pages from start memory\r
215 region.\r
216\r
217 @retval RETURN_SUCCESS The attributes were cleared for the\r
218 memory region.\r
219 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
220 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r
221 is not supported\r
222**/\r
223RETURN_STATUS\r
224EFIAPI\r
225MemEncryptSevClearMmioPageEncMask (\r
226 IN PHYSICAL_ADDRESS Cr3BaseAddress,\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