]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c
OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask()
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / X64 / SecVirtualMemory.c
1 /** @file
2
3 Virtual Memory Management Services to set or clear the memory encryption bit
4
5 Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/CpuLib.h>
12 #include <Library/MemEncryptSevLib.h>
13
14 #include "VirtualMemory.h"
15
16 /**
17 Return the pagetable memory encryption mask.
18
19 @return The pagetable memory encryption mask.
20
21 **/
22 UINT64
23 EFIAPI
24 InternalGetMemEncryptionAddressMask (
25 VOID
26 )
27 {
28 UINT64 EncryptionMask;
29
30 EncryptionMask = MemEncryptSevGetEncryptionMask ();
31 EncryptionMask &= PAGING_1G_ADDRESS_MASK_64;
32
33 return EncryptionMask;
34 }
35
36 /**
37 This function clears memory encryption bit for the memory region specified by
38 PhysicalAddress and Length from the current page table context.
39
40 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
41 current CR3)
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
46 encryption mask
47
48 @retval RETURN_SUCCESS The attributes were cleared for the
49 memory region.
50 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
51 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
52 is not supported
53 **/
54 RETURN_STATUS
55 EFIAPI
56 InternalMemEncryptSevSetMemoryDecrypted (
57 IN PHYSICAL_ADDRESS Cr3BaseAddress,
58 IN PHYSICAL_ADDRESS PhysicalAddress,
59 IN UINTN Length,
60 IN BOOLEAN Flush
61 )
62 {
63 //
64 // This function is not available during SEC.
65 //
66 return RETURN_UNSUPPORTED;
67 }
68
69 /**
70 This function sets memory encryption bit for the memory region specified by
71 PhysicalAddress and Length from the current page table context.
72
73 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
74 current CR3)
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
79 encryption mask
80
81 @retval RETURN_SUCCESS The attributes were set for the memory
82 region.
83 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
84 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute
85 is not supported
86 **/
87 RETURN_STATUS
88 EFIAPI
89 InternalMemEncryptSevSetMemoryEncrypted (
90 IN PHYSICAL_ADDRESS Cr3BaseAddress,
91 IN PHYSICAL_ADDRESS PhysicalAddress,
92 IN UINTN Length,
93 IN BOOLEAN Flush
94 )
95 {
96 //
97 // This function is not available during SEC.
98 //
99 return RETURN_UNSUPPORTED;
100 }
101
102 /**
103 This function clears memory encryption bit for the MMIO region specified by
104 PhysicalAddress and Length.
105
106 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
107 current CR3)
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
111
112 @retval RETURN_SUCCESS The attributes were cleared for the
113 memory region.
114 @retval RETURN_INVALID_PARAMETER Length is zero.
115 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
116 is not supported
117 **/
118 RETURN_STATUS
119 EFIAPI
120 InternalMemEncryptSevClearMmioPageEncMask (
121 IN PHYSICAL_ADDRESS Cr3BaseAddress,
122 IN PHYSICAL_ADDRESS PhysicalAddress,
123 IN UINTN Length
124 )
125 {
126 //
127 // This function is not available during SEC.
128 //
129 return RETURN_UNSUPPORTED;
130 }