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
,
125 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
128 @param[out] BaseAddress The base address of the lowest-address page that
129 covers the initial SMRAM Save State Map.
131 @param[out] NumberOfPages The number of pages in the page range that covers
132 the initial SMRAM Save State Map.
134 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
137 @retval RETURN_UNSUPPORTED SMM is unavailable.
141 MemEncryptSevLocateInitialSmramSaveStateMapPages (
142 OUT UINTN
*BaseAddress
,
143 OUT UINTN
*NumberOfPages
147 Returns the SEV encryption mask.
149 @return The SEV pagetable encryption mask
153 MemEncryptSevGetEncryptionMask (
158 Returns the encryption state of the specified virtual address range.
160 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
162 @param[in] BaseAddress Base address to check
163 @param[in] Length Length of virtual address range
165 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
167 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
169 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
170 @retval MemEncryptSevAddressRangeError Address range is not mapped
172 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
174 MemEncryptSevGetAddressRangeState (
175 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
176 IN PHYSICAL_ADDRESS BaseAddress
,
181 This function clears memory encryption bit for the MMIO region specified by
182 BaseAddress and NumPages.
184 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
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
191 @retval RETURN_SUCCESS The attributes were cleared for the
193 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
194 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
199 MemEncryptSevClearMmioPageEncMask (
200 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
201 IN PHYSICAL_ADDRESS BaseAddress
,
205 #endif // _MEM_ENCRYPT_SEV_LIB_H_