3 Virtual Memory Management Services to set or clear the memory encryption bit
5 Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/CpuLib.h>
12 #include <Library/MemEncryptSevLib.h>
14 #include "VirtualMemory.h"
17 Return the pagetable memory encryption mask.
19 @return The pagetable memory encryption mask.
24 InternalGetMemEncryptionAddressMask (
28 UINT64 EncryptionMask
;
30 EncryptionMask
= MemEncryptSevGetEncryptionMask ();
31 EncryptionMask
&= PAGING_1G_ADDRESS_MASK_64
;
33 return EncryptionMask
;
37 This function clears memory encryption bit for the memory region specified by
38 PhysicalAddress and Length from the current page table context.
40 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
42 @param[in] PhysicalAddress The physical address that is the start
43 address of a memory region.
44 @param[in] Length The length of memory region
45 @param[in] Flush Flush the caches before applying the
48 @retval RETURN_SUCCESS The attributes were cleared for the
50 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
51 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
56 InternalMemEncryptSevSetMemoryDecrypted (
57 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
58 IN PHYSICAL_ADDRESS PhysicalAddress
,
64 // This function is not available during SEC.
66 return RETURN_UNSUPPORTED
;
70 This function sets memory encryption bit for the memory region specified by
71 PhysicalAddress and Length from the current page table context.
73 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
75 @param[in] PhysicalAddress The physical address that is the start
76 address of a memory region.
77 @param[in] Length The length of memory region
78 @param[in] Flush Flush the caches before applying the
81 @retval RETURN_SUCCESS The attributes were set for the memory
83 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
84 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute
89 InternalMemEncryptSevSetMemoryEncrypted (
90 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
91 IN PHYSICAL_ADDRESS PhysicalAddress
,
97 // This function is not available during SEC.
99 return RETURN_UNSUPPORTED
;
103 This function clears memory encryption bit for the MMIO region specified by
104 PhysicalAddress and Length.
106 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
108 @param[in] PhysicalAddress The physical address that is the start
109 address of a MMIO region.
110 @param[in] Length The length of memory region
112 @retval RETURN_SUCCESS The attributes were cleared for the
114 @retval RETURN_INVALID_PARAMETER Length is zero.
115 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
120 InternalMemEncryptSevClearMmioPageEncMask (
121 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
122 IN PHYSICAL_ADDRESS PhysicalAddress
,
127 // This function is not available during SEC.
129 return RETURN_UNSUPPORTED
;