]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/Library/MemEncryptSevLib.h
OvmfPkg/BaseMemEncryptSevLib: remove Flush parameter
[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
5b5028e6
LE
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
a1f22614
BS
110RETURN_STATUS\r
111EFIAPI\r
112MemEncryptSevClearPageEncMask (\r
113 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
114 IN PHYSICAL_ADDRESS BaseAddress,\r
adfa3327 115 IN UINTN NumPages\r
a1f22614
BS
116 );\r
117\r
118/**\r
119 This function sets memory encryption bit for the memory region specified by\r
154dcd6c 120 BaseAddress and NumPages from the current page table context.\r
a1f22614 121\r
154dcd6c
LE
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
a1f22614 128\r
154dcd6c
LE
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
a1f22614
BS
135RETURN_STATUS\r
136EFIAPI\r
137MemEncryptSevSetPageEncMask (\r
138 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
139 IN PHYSICAL_ADDRESS BaseAddress,\r
adfa3327 140 IN UINTN NumPages\r
a1f22614 141 );\r
61a044c6
LE
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
159RETURN_STATUS\r
160EFIAPI\r
161MemEncryptSevLocateInitialSmramSaveStateMapPages (\r
162 OUT UINTN *BaseAddress,\r
163 OUT UINTN *NumberOfPages\r
164 );\r
b97dc4b9
TL
165\r
166/**\r
167 Returns the SEV encryption mask.\r
168\r
169 @return The SEV pagetable encryption mask\r
170**/\r
171UINT64\r
172EFIAPI\r
173MemEncryptSevGetEncryptionMask (\r
174 VOID\r
175 );\r
176\r
c330af02
TL
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
192MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r
193EFIAPI\r
194MemEncryptSevGetAddressRangeState (\r
195 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
196 IN PHYSICAL_ADDRESS BaseAddress,\r
197 IN UINTN Length\r
198 );\r
199\r
901a9bfc
BS
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
217RETURN_STATUS\r
218EFIAPI\r
219MemEncryptSevClearMmioPageEncMask (\r
220 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
221 IN PHYSICAL_ADDRESS BaseAddress,\r
222 IN UINTN NumPages\r
223 );\r
224\r
a1f22614 225#endif // _MEM_ENCRYPT_SEV_LIB_H_\r