]>
Commit | Line | Data |
---|---|---|
a1f22614 BS |
1 | /** @file\r |
2 | \r | |
3 | Virtual Memory Management Services to set or clear the memory encryption bit\r | |
4 | \r | |
4bd6bf31 | 5 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r |
c330af02 | 6 | Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>\r |
a1f22614 | 7 | \r |
b26f0cf9 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a1f22614 | 9 | \r |
4bd6bf31 | 10 | Code is derived from MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h\r |
a1f22614 BS |
11 | \r |
12 | **/\r | |
13 | \r | |
14 | #ifndef __VIRTUAL_MEMORY__\r | |
15 | #define __VIRTUAL_MEMORY__\r | |
16 | \r | |
9d686149 | 17 | #include <IndustryStandard/PageTable.h>\r |
a1f22614 BS |
18 | #include <Library/BaseLib.h>\r |
19 | #include <Library/BaseMemoryLib.h>\r | |
bd13ecf3 | 20 | #include <Library/CacheMaintenanceLib.h>\r |
a1f22614 BS |
21 | #include <Library/DebugLib.h>\r |
22 | #include <Library/MemoryAllocationLib.h>\r | |
bd13ecf3 | 23 | #include <Uefi.h>\r |
a1f22614 | 24 | \r |
ac0a286f | 25 | #define SYS_CODE64_SEL 0x38\r |
a1f22614 | 26 | \r |
ac0a286f MK |
27 | #define PAGE_TABLE_POOL_ALIGNMENT BASE_2MB\r |
28 | #define PAGE_TABLE_POOL_UNIT_SIZE SIZE_2MB\r | |
4bd6bf31 LE |
29 | #define PAGE_TABLE_POOL_UNIT_PAGES \\r |
30 | EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)\r | |
b721aa74 BS |
31 | #define PAGE_TABLE_POOL_ALIGN_MASK \\r |
32 | (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))\r | |
33 | \r | |
34 | typedef struct {\r | |
ac0a286f MK |
35 | VOID *NextPool;\r |
36 | UINTN Offset;\r | |
37 | UINTN FreePages;\r | |
b721aa74 BS |
38 | } PAGE_TABLE_POOL;\r |
39 | \r | |
c330af02 TL |
40 | /**\r |
41 | Return the pagetable memory encryption mask.\r | |
b721aa74 | 42 | \r |
c330af02 TL |
43 | @return The pagetable memory encryption mask.\r |
44 | \r | |
45 | **/\r | |
46 | UINT64\r | |
47 | EFIAPI\r | |
48 | InternalGetMemEncryptionAddressMask (\r | |
49 | VOID\r | |
50 | );\r | |
b721aa74 | 51 | \r |
a1f22614 | 52 | /**\r |
4bd6bf31 | 53 | This function clears memory encryption bit for the memory region specified by\r |
1532e5d5 | 54 | PhysicalAddress and Length from the current page table context.\r |
a1f22614 | 55 | \r |
1532e5d5 LE |
56 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
57 | current CR3)\r | |
4bd6bf31 LE |
58 | @param[in] PhysicalAddress The physical address that is the start\r |
59 | address of a memory region.\r | |
a1f22614 | 60 | @param[in] Length The length of memory region\r |
a1f22614 | 61 | \r |
4bd6bf31 LE |
62 | @retval RETURN_SUCCESS The attributes were cleared for the\r |
63 | memory region.\r | |
a1f22614 | 64 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
1532e5d5 | 65 | @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute\r |
4bd6bf31 | 66 | is not supported\r |
a1f22614 BS |
67 | **/\r |
68 | RETURN_STATUS\r | |
69 | EFIAPI\r | |
70 | InternalMemEncryptSevSetMemoryDecrypted (\r | |
ac0a286f MK |
71 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
72 | IN PHYSICAL_ADDRESS PhysicalAddress,\r | |
73 | IN UINTN Length\r | |
a1f22614 BS |
74 | );\r |
75 | \r | |
76 | /**\r | |
77 | This function sets memory encryption bit for the memory region specified by\r | |
68e60a38 | 78 | PhysicalAddress and Length from the current page table context.\r |
a1f22614 | 79 | \r |
68e60a38 LE |
80 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
81 | current CR3)\r | |
4bd6bf31 LE |
82 | @param[in] PhysicalAddress The physical address that is the start\r |
83 | address of a memory region.\r | |
a1f22614 | 84 | @param[in] Length The length of memory region\r |
a1f22614 | 85 | \r |
68e60a38 LE |
86 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
87 | region.\r | |
a1f22614 | 88 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
4bd6bf31 LE |
89 | @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute\r |
90 | is not supported\r | |
a1f22614 BS |
91 | **/\r |
92 | RETURN_STATUS\r | |
93 | EFIAPI\r | |
94 | InternalMemEncryptSevSetMemoryEncrypted (\r | |
ac0a286f MK |
95 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
96 | IN PHYSICAL_ADDRESS PhysicalAddress,\r | |
97 | IN UINTN Length\r | |
a1f22614 BS |
98 | );\r |
99 | \r | |
c330af02 TL |
100 | /**\r |
101 | Returns the encryption state of the specified virtual address range.\r | |
102 | \r | |
103 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
104 | current CR3)\r | |
105 | @param[in] BaseAddress Base address to check\r | |
106 | @param[in] Length Length of virtual address range\r | |
107 | \r | |
108 | @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r | |
109 | unencrypted\r | |
110 | @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r | |
111 | encrypted\r | |
112 | @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r | |
113 | @retval MemEncryptSevAddressRangeError Address range is not mapped\r | |
114 | **/\r | |
115 | MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r | |
116 | EFIAPI\r | |
117 | InternalMemEncryptSevGetAddressRangeState (\r | |
ac0a286f MK |
118 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
119 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
120 | IN UINTN Length\r | |
c330af02 TL |
121 | );\r |
122 | \r | |
901a9bfc BS |
123 | /**\r |
124 | This function clears memory encryption bit for the MMIO region specified by\r | |
125 | PhysicalAddress and Length.\r | |
126 | \r | |
127 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
128 | current CR3)\r | |
129 | @param[in] PhysicalAddress The physical address that is the start\r | |
130 | address of a MMIO region.\r | |
131 | @param[in] Length The length of memory region\r | |
132 | \r | |
133 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
134 | memory region.\r | |
135 | @retval RETURN_INVALID_PARAMETER Length is zero.\r | |
136 | @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute\r | |
137 | is not supported\r | |
138 | **/\r | |
139 | RETURN_STATUS\r | |
140 | EFIAPI\r | |
141 | InternalMemEncryptSevClearMmioPageEncMask (\r | |
ac0a286f MK |
142 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
143 | IN PHYSICAL_ADDRESS PhysicalAddress,\r | |
144 | IN UINTN Length\r | |
901a9bfc | 145 | );\r |
ac0a286f | 146 | \r |
d39f8d88 BS |
147 | /**\r |
148 | Create 1GB identity mapping for the specified virtual address range.\r | |
149 | \r | |
150 | The function is preliminary used by the SEV-SNP page state change\r | |
151 | APIs to build the page table required before issuing the PVALIDATE\r | |
152 | instruction. The function must be removed after the EDK2 core is\r | |
153 | enhanced to do the lazy validation.\r | |
154 | \r | |
155 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
156 | current CR3)\r | |
157 | @param[in] VirtualAddress Virtual address\r | |
158 | @param[in] Length Length of virtual address range\r | |
159 | \r | |
160 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
161 | \r | |
162 | **/\r | |
163 | RETURN_STATUS\r | |
164 | EFIAPI\r | |
165 | InternalMemEncryptSevCreateIdentityMap1G (\r | |
166 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
167 | IN PHYSICAL_ADDRESS PhysicalAddress,\r | |
168 | IN UINTN Length\r | |
169 | );\r | |
170 | \r | |
a1f22614 | 171 | #endif\r |