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>
19 This function clears memory encryption bit for the memory region specified by
20 BaseAddress and NumPages from the current page table context.
22 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
24 @param[in] BaseAddress The physical address that is the start
25 address of a memory region.
26 @param[in] NumPages The number of pages from start memory
28 @param[in] Flush Flush the caches before clearing the bit
29 (mostly TRUE except MMIO addresses)
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
,
47 // Memory encryption bit is not accessible in 32-bit mode
49 return RETURN_UNSUPPORTED
;
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
62 @param[in] Flush Flush the caches before setting the bit
63 (mostly TRUE except MMIO addresses)
65 @retval RETURN_SUCCESS The attributes were set for the memory
67 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
68 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
73 MemEncryptSevSetPageEncMask (
74 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
75 IN PHYSICAL_ADDRESS BaseAddress
,
81 // Memory encryption bit is not accessible in 32-bit mode
83 return RETURN_UNSUPPORTED
;
87 Returns the encryption state of the specified virtual address range.
89 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
91 @param[in] BaseAddress Base address to check
92 @param[in] Length Length of virtual address range
94 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
96 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
98 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
99 @retval MemEncryptSevAddressRangeError Address range is not mapped
101 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
103 MemEncryptSevGetAddressRangeState (
104 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
105 IN PHYSICAL_ADDRESS BaseAddress
,
110 // Memory is always encrypted in 32-bit mode
112 return MemEncryptSevAddressRangeEncrypted
;