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