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