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
31 @retval RETURN_SUCCESS The attributes were cleared for the
33 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
34 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
39 MemEncryptSevClearPageEncMask (
40 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
41 IN PHYSICAL_ADDRESS BaseAddress
,
45 return InternalMemEncryptSevSetMemoryDecrypted (
48 EFI_PAGES_TO_SIZE (NumPages
)
53 This function sets memory encryption bit for the memory region specified by
54 BaseAddress and NumPages from the current page table context.
56 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
58 @param[in] BaseAddress The physical address that is the start
59 address of a memory region.
60 @param[in] NumPages The number of pages from start memory
63 @retval RETURN_SUCCESS The attributes were set for the memory
65 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
66 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
71 MemEncryptSevSetPageEncMask (
72 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
73 IN PHYSICAL_ADDRESS BaseAddress
,
77 return InternalMemEncryptSevSetMemoryEncrypted (
80 EFI_PAGES_TO_SIZE (NumPages
)
85 Returns the encryption state of the specified virtual address range.
87 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
89 @param[in] BaseAddress Base address to check
90 @param[in] Length Length of virtual address range
92 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
94 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
96 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
97 @retval MemEncryptSevAddressRangeError Address range is not mapped
99 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
101 MemEncryptSevGetAddressRangeState (
102 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
103 IN PHYSICAL_ADDRESS BaseAddress
,
107 return InternalMemEncryptSevGetAddressRangeState (
115 This function clears memory encryption bit for the mmio region specified by
116 BaseAddress and NumPages.
118 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
120 @param[in] BaseAddress The physical address that is the start
121 address of a mmio region.
122 @param[in] NumPages The number of pages from start memory
125 @retval RETURN_SUCCESS The attributes were cleared for the
127 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
128 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
133 MemEncryptSevClearMmioPageEncMask (
134 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
135 IN PHYSICAL_ADDRESS BaseAddress
,
139 return InternalMemEncryptSevClearMmioPageEncMask (
142 EFI_PAGES_TO_SIZE (NumPages
)