]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Include/Library/MemEncryptSevLib.h
OvmfPkg: Apply uncrustify changes
[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 #include <WorkArea.h>
16
17 //
18 // Define the maximum number of #VCs allowed (e.g. the level of nesting
19 // that is allowed => 2 allows for 1 nested #VCs). I this value is changed,
20 // be sure to increase the size of
21 // gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize
22 // in any FDF file using this PCD.
23 //
24 #define VMGEXIT_MAXIMUM_VC_COUNT 2
25
26 //
27 // Per-CPU data mapping structure
28 // Use UINT32 for cached indicators and compare to a specific value
29 // so that the hypervisor can't indicate a value is cached by just
30 // writing random data to that area.
31 //
32 typedef struct {
33 UINT32 Dr7Cached;
34 UINT64 Dr7;
35
36 UINTN VcCount;
37 VOID *GhcbBackupPages;
38 } SEV_ES_PER_CPU_DATA;
39
40 //
41 // Memory encryption address range states.
42 //
43 typedef enum {
44 MemEncryptSevAddressRangeUnencrypted,
45 MemEncryptSevAddressRangeEncrypted,
46 MemEncryptSevAddressRangeMixed,
47 MemEncryptSevAddressRangeError,
48 } MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE;
49
50 /**
51 Returns a boolean to indicate whether SEV-ES is enabled.
52
53 @retval TRUE SEV-ES is enabled
54 @retval FALSE SEV-ES is not enabled
55 **/
56 BOOLEAN
57 EFIAPI
58 MemEncryptSevEsIsEnabled (
59 VOID
60 );
61
62 /**
63 Returns a boolean to indicate whether SEV is enabled
64
65 @retval TRUE SEV is enabled
66 @retval FALSE SEV is not enabled
67 **/
68 BOOLEAN
69 EFIAPI
70 MemEncryptSevIsEnabled (
71 VOID
72 );
73
74 /**
75 This function clears memory encryption bit for the memory region specified by
76 BaseAddress and NumPages from the current page table context.
77
78 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
79 current CR3)
80 @param[in] BaseAddress The physical address that is the start
81 address of a memory region.
82 @param[in] NumPages The number of pages from start memory
83 region.
84
85 @retval RETURN_SUCCESS The attributes were cleared for the
86 memory region.
87 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
88 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
89 is not supported
90 **/
91 RETURN_STATUS
92 EFIAPI
93 MemEncryptSevClearPageEncMask (
94 IN PHYSICAL_ADDRESS Cr3BaseAddress,
95 IN PHYSICAL_ADDRESS BaseAddress,
96 IN UINTN NumPages
97 );
98
99 /**
100 This function sets memory encryption bit for the memory region specified by
101 BaseAddress and NumPages from the current page table context.
102
103 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
104 current CR3)
105 @param[in] BaseAddress The physical address that is the start
106 address of a memory region.
107 @param[in] NumPages The number of pages from start memory
108 region.
109
110 @retval RETURN_SUCCESS The attributes were set for the memory
111 region.
112 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
113 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
114 is not supported
115 **/
116 RETURN_STATUS
117 EFIAPI
118 MemEncryptSevSetPageEncMask (
119 IN PHYSICAL_ADDRESS Cr3BaseAddress,
120 IN PHYSICAL_ADDRESS BaseAddress,
121 IN UINTN NumPages
122 );
123
124 /**
125 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
126 Save State Map.
127
128 @param[out] BaseAddress The base address of the lowest-address page that
129 covers the initial SMRAM Save State Map.
130
131 @param[out] NumberOfPages The number of pages in the page range that covers
132 the initial SMRAM Save State Map.
133
134 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
135 output.
136
137 @retval RETURN_UNSUPPORTED SMM is unavailable.
138 **/
139 RETURN_STATUS
140 EFIAPI
141 MemEncryptSevLocateInitialSmramSaveStateMapPages (
142 OUT UINTN *BaseAddress,
143 OUT UINTN *NumberOfPages
144 );
145
146 /**
147 Returns the SEV encryption mask.
148
149 @return The SEV pagetable encryption mask
150 **/
151 UINT64
152 EFIAPI
153 MemEncryptSevGetEncryptionMask (
154 VOID
155 );
156
157 /**
158 Returns the encryption state of the specified virtual address range.
159
160 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
161 current CR3)
162 @param[in] BaseAddress Base address to check
163 @param[in] Length Length of virtual address range
164
165 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
166 unencrypted
167 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
168 encrypted
169 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
170 @retval MemEncryptSevAddressRangeError Address range is not mapped
171 **/
172 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
173 EFIAPI
174 MemEncryptSevGetAddressRangeState (
175 IN PHYSICAL_ADDRESS Cr3BaseAddress,
176 IN PHYSICAL_ADDRESS BaseAddress,
177 IN UINTN Length
178 );
179
180 /**
181 This function clears memory encryption bit for the MMIO region specified by
182 BaseAddress and NumPages.
183
184 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
185 current CR3)
186 @param[in] BaseAddress The physical address that is the start
187 address of a MMIO region.
188 @param[in] NumPages The number of pages from start memory
189 region.
190
191 @retval RETURN_SUCCESS The attributes were cleared for the
192 memory region.
193 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
194 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
195 is not supported
196 **/
197 RETURN_STATUS
198 EFIAPI
199 MemEncryptSevClearMmioPageEncMask (
200 IN PHYSICAL_ADDRESS Cr3BaseAddress,
201 IN PHYSICAL_ADDRESS BaseAddress,
202 IN UINTN NumPages
203 );
204
205 #endif // _MEM_ENCRYPT_SEV_LIB_H_