3 Define Secure Encrypted Virtualization (SEV) base library helper function
5 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _MEM_ENCRYPT_SEV_LIB_H_
12 #define _MEM_ENCRYPT_SEV_LIB_H_
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.
24 #define VMGEXIT_MAXIMUM_VC_COUNT 2
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.
37 VOID
*GhcbBackupPages
;
38 } SEV_ES_PER_CPU_DATA
;
41 // Memory encryption address range states.
44 MemEncryptSevAddressRangeUnencrypted
,
45 MemEncryptSevAddressRangeEncrypted
,
46 MemEncryptSevAddressRangeMixed
,
47 MemEncryptSevAddressRangeError
,
48 } MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
;
51 Returns a boolean to indicate whether SEV-ES is enabled.
53 @retval TRUE SEV-ES is enabled
54 @retval FALSE SEV-ES is not enabled
58 MemEncryptSevEsIsEnabled (
63 Returns a boolean to indicate whether SEV is enabled
65 @retval TRUE SEV is enabled
66 @retval FALSE SEV is not enabled
70 MemEncryptSevIsEnabled (
75 This function clears memory encryption bit for the memory region specified by
76 BaseAddress and NumPages from the current page table context.
78 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
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
85 @retval RETURN_SUCCESS The attributes were cleared for the
87 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
88 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
93 MemEncryptSevClearPageEncMask (
94 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
95 IN PHYSICAL_ADDRESS BaseAddress
,
100 This function sets memory encryption bit for the memory region specified by
101 BaseAddress and NumPages from the current page table context.
103 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
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
110 @retval RETURN_SUCCESS The attributes were set for the memory
112 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
113 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
118 MemEncryptSevSetPageEncMask (
119 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
120 IN PHYSICAL_ADDRESS BaseAddress
,
126 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
129 @param[out] BaseAddress The base address of the lowest-address page that
130 covers the initial SMRAM Save State Map.
132 @param[out] NumberOfPages The number of pages in the page range that covers
133 the initial SMRAM Save State Map.
135 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
138 @retval RETURN_UNSUPPORTED SMM is unavailable.
142 MemEncryptSevLocateInitialSmramSaveStateMapPages (
143 OUT UINTN
*BaseAddress
,
144 OUT UINTN
*NumberOfPages
148 Returns the SEV encryption mask.
150 @return The SEV pagetable encryption mask
154 MemEncryptSevGetEncryptionMask (
159 Returns the encryption state of the specified virtual address range.
161 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
163 @param[in] BaseAddress Base address to check
164 @param[in] Length Length of virtual address range
166 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
168 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
170 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
171 @retval MemEncryptSevAddressRangeError Address range is not mapped
173 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
175 MemEncryptSevGetAddressRangeState (
176 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
177 IN PHYSICAL_ADDRESS BaseAddress
,
182 This function clears memory encryption bit for the MMIO region specified by
183 BaseAddress and NumPages.
185 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
187 @param[in] BaseAddress The physical address that is the start
188 address of a MMIO region.
189 @param[in] NumPages The number of pages from start memory
192 @retval RETURN_SUCCESS The attributes were cleared for the
194 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
195 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
200 MemEncryptSevClearMmioPageEncMask (
201 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
202 IN PHYSICAL_ADDRESS BaseAddress
,
206 #endif // _MEM_ENCRYPT_SEV_LIB_H_