VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Include/Library/MemEncryptSevLib.h@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 7.2 KB
Line 
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//
32typedef 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//
43typedef 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-SNP is enabled
52
53 @retval TRUE SEV-SNP is enabled
54 @retval FALSE SEV-SNP is not enabled
55**/
56BOOLEAN
57EFIAPI
58MemEncryptSevSnpIsEnabled (
59 VOID
60 );
61
62/**
63 Returns a boolean to indicate whether SEV-ES is enabled.
64
65 @retval TRUE SEV-ES is enabled
66 @retval FALSE SEV-ES is not enabled
67**/
68BOOLEAN
69EFIAPI
70MemEncryptSevEsIsEnabled (
71 VOID
72 );
73
74/**
75 Returns a boolean to indicate whether SEV is enabled
76
77 @retval TRUE SEV is enabled
78 @retval FALSE SEV is not enabled
79**/
80BOOLEAN
81EFIAPI
82MemEncryptSevIsEnabled (
83 VOID
84 );
85
86/**
87 This function clears memory encryption bit for the memory region specified by
88 BaseAddress and NumPages from the current page table context.
89
90 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
91 current CR3)
92 @param[in] BaseAddress The physical address that is the start
93 address of a memory region.
94 @param[in] NumPages The number of pages from start memory
95 region.
96
97 @retval RETURN_SUCCESS The attributes were cleared for the
98 memory region.
99 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
100 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
101 is not supported
102**/
103RETURN_STATUS
104EFIAPI
105MemEncryptSevClearPageEncMask (
106 IN PHYSICAL_ADDRESS Cr3BaseAddress,
107 IN PHYSICAL_ADDRESS BaseAddress,
108 IN UINTN NumPages
109 );
110
111/**
112 This function sets memory encryption bit for the memory region specified by
113 BaseAddress and NumPages from the current page table context.
114
115 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
116 current CR3)
117 @param[in] BaseAddress The physical address that is the start
118 address of a memory region.
119 @param[in] NumPages The number of pages from start memory
120 region.
121
122 @retval RETURN_SUCCESS The attributes were set for the memory
123 region.
124 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
125 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
126 is not supported
127**/
128RETURN_STATUS
129EFIAPI
130MemEncryptSevSetPageEncMask (
131 IN PHYSICAL_ADDRESS Cr3BaseAddress,
132 IN PHYSICAL_ADDRESS BaseAddress,
133 IN UINTN NumPages
134 );
135
136/**
137 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
138 Save State Map.
139
140 @param[out] BaseAddress The base address of the lowest-address page that
141 covers the initial SMRAM Save State Map.
142
143 @param[out] NumberOfPages The number of pages in the page range that covers
144 the initial SMRAM Save State Map.
145
146 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
147 output.
148
149 @retval RETURN_UNSUPPORTED SMM is unavailable.
150**/
151RETURN_STATUS
152EFIAPI
153MemEncryptSevLocateInitialSmramSaveStateMapPages (
154 OUT UINTN *BaseAddress,
155 OUT UINTN *NumberOfPages
156 );
157
158/**
159 Returns the SEV encryption mask.
160
161 @return The SEV pagetable encryption mask
162**/
163UINT64
164EFIAPI
165MemEncryptSevGetEncryptionMask (
166 VOID
167 );
168
169/**
170 Returns a boolean to indicate whether DebugVirtualization is enabled.
171
172 @retval TRUE DebugVirtualization is enabled
173 @retval FALSE DebugVirtualization is not enabled
174**/
175BOOLEAN
176EFIAPI
177MemEncryptSevEsDebugVirtualizationIsEnabled (
178 VOID
179 );
180
181/**
182 Returns the encryption state of the specified virtual address range.
183
184 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
185 current CR3)
186 @param[in] BaseAddress Base address to check
187 @param[in] Length Length of virtual address range
188
189 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
190 unencrypted
191 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
192 encrypted
193 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
194 @retval MemEncryptSevAddressRangeError Address range is not mapped
195**/
196MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
197EFIAPI
198MemEncryptSevGetAddressRangeState (
199 IN PHYSICAL_ADDRESS Cr3BaseAddress,
200 IN PHYSICAL_ADDRESS BaseAddress,
201 IN UINTN Length
202 );
203
204/**
205 This function clears memory encryption bit for the MMIO region specified by
206 BaseAddress and NumPages.
207
208 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
209 current CR3)
210 @param[in] BaseAddress The physical address that is the start
211 address of a MMIO region.
212 @param[in] NumPages The number of pages from start memory
213 region.
214
215 @retval RETURN_SUCCESS The attributes were cleared for the
216 memory region.
217 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
218 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
219 is not supported
220**/
221RETURN_STATUS
222EFIAPI
223MemEncryptSevClearMmioPageEncMask (
224 IN PHYSICAL_ADDRESS Cr3BaseAddress,
225 IN PHYSICAL_ADDRESS BaseAddress,
226 IN UINTN NumPages
227 );
228
229/**
230 Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.
231
232 @param[in] BaseAddress Base address
233 @param[in] NumPages Number of pages starting from the base address
234
235**/
236VOID
237EFIAPI
238MemEncryptSevSnpPreValidateSystemRam (
239 IN PHYSICAL_ADDRESS BaseAddress,
240 IN UINTN NumPages
241 );
242
243#endif // _MEM_ENCRYPT_SEV_LIB_H_
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette