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
46 @retval RETURN_SUCCESS The attributes were cleared for the
48 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
49 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
54 InternalMemEncryptSevSetMemoryDecrypted (
55 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
56 IN PHYSICAL_ADDRESS PhysicalAddress
,
61 // This function is not available during SEC.
63 return RETURN_UNSUPPORTED
;
67 This function sets memory encryption bit for the memory region specified by
68 PhysicalAddress and Length from the current page table context.
70 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
72 @param[in] PhysicalAddress The physical address that is the start
73 address of a memory region.
74 @param[in] Length The length of memory region
75 @param[in] Flush Flush the caches before applying the
78 @retval RETURN_SUCCESS The attributes were set for the memory
80 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
81 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute
86 InternalMemEncryptSevSetMemoryEncrypted (
87 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
88 IN PHYSICAL_ADDRESS PhysicalAddress
,
93 // This function is not available during SEC.
95 return RETURN_UNSUPPORTED
;
99 This function clears memory encryption bit for the MMIO region specified by
100 PhysicalAddress and Length.
102 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
104 @param[in] PhysicalAddress The physical address that is the start
105 address of a MMIO region.
106 @param[in] Length The length of memory region
108 @retval RETURN_SUCCESS The attributes were cleared for the
110 @retval RETURN_INVALID_PARAMETER Length is zero.
111 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
116 InternalMemEncryptSevClearMmioPageEncMask (
117 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
118 IN PHYSICAL_ADDRESS PhysicalAddress
,
123 // This function is not available during SEC.
125 return RETURN_UNSUPPORTED
;