3 Secure Encrypted Virtualization (SEV) library helper function
5 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemEncryptSevLib.h>
14 #include <Register/Amd/Cpuid.h>
15 #include <Register/Amd/Msr.h>
16 #include <Register/Cpuid.h>
18 #include "VirtualMemory.h"
21 This function clears memory encryption bit for the memory region specified by
22 BaseAddress and NumPages from the current page table context.
24 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
26 @param[in] BaseAddress The physical address that is the start
27 address of a memory region.
28 @param[in] NumPages The number of pages from start memory
30 @param[in] Flush Flush the caches before clearing the bit
31 (mostly TRUE except MMIO addresses)
33 @retval RETURN_SUCCESS The attributes were cleared for the
35 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
36 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
41 MemEncryptSevClearPageEncMask (
42 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
43 IN PHYSICAL_ADDRESS BaseAddress
,
48 return InternalMemEncryptSevSetMemoryDecrypted (
51 EFI_PAGES_TO_SIZE (NumPages
),
57 This function sets memory encryption bit for the memory region specified by
58 BaseAddress and NumPages from the current page table context.
60 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
62 @param[in] BaseAddress The physical address that is the start
63 address of a memory region.
64 @param[in] NumPages The number of pages from start memory
66 @param[in] Flush Flush the caches before setting the bit
67 (mostly TRUE except MMIO addresses)
69 @retval RETURN_SUCCESS The attributes were set for the memory
71 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
72 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
77 MemEncryptSevSetPageEncMask (
78 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
79 IN PHYSICAL_ADDRESS BaseAddress
,
84 return InternalMemEncryptSevSetMemoryEncrypted (
87 EFI_PAGES_TO_SIZE (NumPages
),
93 Returns the encryption state of the specified virtual address range.
95 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
97 @param[in] BaseAddress Base address to check
98 @param[in] Length Length of virtual address range
100 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
102 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
104 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
105 @retval MemEncryptSevAddressRangeError Address range is not mapped
107 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
109 MemEncryptSevGetAddressRangeState (
110 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
111 IN PHYSICAL_ADDRESS BaseAddress
,
115 return InternalMemEncryptSevGetAddressRangeState (
123 This function clears memory encryption bit for the mmio region specified by
124 BaseAddress and NumPages.
126 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
128 @param[in] BaseAddress The physical address that is the start
129 address of a mmio region.
130 @param[in] NumPages The number of pages from start memory
133 @retval RETURN_SUCCESS The attributes were cleared for the
135 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
136 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
141 MemEncryptSevClearMmioPageEncMask (
142 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
143 IN PHYSICAL_ADDRESS BaseAddress
,
147 return InternalMemEncryptSevClearMmioPageEncMask (
150 EFI_PAGES_TO_SIZE (NumPages
)