]>
Commit | Line | Data |
---|---|---|
a1f22614 BS |
1 | /** @file\r |
2 | \r | |
3 | Secure Encrypted Virtualization (SEV) library helper function\r | |
4 | \r | |
c330af02 | 5 | Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>\r |
a1f22614 | 6 | \r |
b26f0cf9 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a1f22614 BS |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
bd13ecf3 | 13 | #include <Library/MemEncryptSevLib.h>\r |
a1f22614 BS |
14 | #include <Register/Amd/Cpuid.h>\r |
15 | #include <Register/Amd/Msr.h>\r | |
bd13ecf3 | 16 | #include <Register/Cpuid.h>\r |
a1f22614 BS |
17 | \r |
18 | #include "VirtualMemory.h"\r | |
19 | \r | |
20 | /**\r | |
a1f22614 | 21 | This function clears memory encryption bit for the memory region specified by\r |
5b5028e6 | 22 | BaseAddress and NumPages from the current page table context.\r |
a1f22614 | 23 | \r |
4bd6bf31 LE |
24 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
25 | current CR3)\r | |
26 | @param[in] BaseAddress The physical address that is the start\r | |
27 | address of a memory region.\r | |
5b5028e6 | 28 | @param[in] NumPages The number of pages from start memory\r |
4bd6bf31 | 29 | region.\r |
a1f22614 | 30 | \r |
4bd6bf31 LE |
31 | @retval RETURN_SUCCESS The attributes were cleared for the\r |
32 | memory region.\r | |
a1f22614 | 33 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
4bd6bf31 LE |
34 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r |
35 | is not supported\r | |
5b5028e6 | 36 | **/\r |
a1f22614 BS |
37 | RETURN_STATUS\r |
38 | EFIAPI\r | |
39 | MemEncryptSevClearPageEncMask (\r | |
ac0a286f MK |
40 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
41 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
42 | IN UINTN NumPages\r | |
a1f22614 BS |
43 | )\r |
44 | {\r | |
4bd6bf31 LE |
45 | return InternalMemEncryptSevSetMemoryDecrypted (\r |
46 | Cr3BaseAddress,\r | |
47 | BaseAddress,\r | |
adfa3327 | 48 | EFI_PAGES_TO_SIZE (NumPages)\r |
4bd6bf31 | 49 | );\r |
a1f22614 BS |
50 | }\r |
51 | \r | |
52 | /**\r | |
154dcd6c LE |
53 | This function sets memory encryption bit for the memory region specified by\r |
54 | BaseAddress and NumPages from the current page table context.\r | |
a1f22614 | 55 | \r |
4bd6bf31 LE |
56 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
57 | current CR3)\r | |
58 | @param[in] BaseAddress The physical address that is the start\r | |
59 | address of a memory region.\r | |
154dcd6c | 60 | @param[in] NumPages The number of pages from start memory\r |
4bd6bf31 | 61 | region.\r |
a1f22614 | 62 | \r |
154dcd6c LE |
63 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
64 | region.\r | |
a1f22614 | 65 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
154dcd6c | 66 | @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r |
4bd6bf31 | 67 | is not supported\r |
154dcd6c | 68 | **/\r |
a1f22614 BS |
69 | RETURN_STATUS\r |
70 | EFIAPI\r | |
71 | MemEncryptSevSetPageEncMask (\r | |
ac0a286f MK |
72 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
73 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
74 | IN UINTN NumPages\r | |
a1f22614 BS |
75 | )\r |
76 | {\r | |
4bd6bf31 LE |
77 | return InternalMemEncryptSevSetMemoryEncrypted (\r |
78 | Cr3BaseAddress,\r | |
79 | BaseAddress,\r | |
adfa3327 | 80 | EFI_PAGES_TO_SIZE (NumPages)\r |
4bd6bf31 | 81 | );\r |
a1f22614 | 82 | }\r |
c330af02 TL |
83 | \r |
84 | /**\r | |
85 | Returns the encryption state of the specified virtual address range.\r | |
86 | \r | |
87 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
88 | current CR3)\r | |
89 | @param[in] BaseAddress Base address to check\r | |
90 | @param[in] Length Length of virtual address range\r | |
91 | \r | |
92 | @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r | |
93 | unencrypted\r | |
94 | @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r | |
95 | encrypted\r | |
96 | @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r | |
97 | @retval MemEncryptSevAddressRangeError Address range is not mapped\r | |
98 | **/\r | |
99 | MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r | |
100 | EFIAPI\r | |
101 | MemEncryptSevGetAddressRangeState (\r | |
ac0a286f MK |
102 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
103 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
104 | IN UINTN Length\r | |
c330af02 TL |
105 | )\r |
106 | {\r | |
107 | return InternalMemEncryptSevGetAddressRangeState (\r | |
108 | Cr3BaseAddress,\r | |
109 | BaseAddress,\r | |
110 | Length\r | |
111 | );\r | |
112 | }\r | |
901a9bfc BS |
113 | \r |
114 | /**\r | |
115 | This function clears memory encryption bit for the mmio region specified by\r | |
116 | BaseAddress and NumPages.\r | |
117 | \r | |
118 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
119 | current CR3)\r | |
120 | @param[in] BaseAddress The physical address that is the start\r | |
121 | address of a mmio region.\r | |
122 | @param[in] NumPages The number of pages from start memory\r | |
123 | region.\r | |
124 | \r | |
125 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
126 | memory region.\r | |
127 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
128 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
129 | is not supported\r | |
130 | **/\r | |
131 | RETURN_STATUS\r | |
132 | EFIAPI\r | |
133 | MemEncryptSevClearMmioPageEncMask (\r | |
ac0a286f MK |
134 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r |
135 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
136 | IN UINTN NumPages\r | |
901a9bfc BS |
137 | )\r |
138 | {\r | |
139 | return InternalMemEncryptSevClearMmioPageEncMask (\r | |
140 | Cr3BaseAddress,\r | |
141 | BaseAddress,\r | |
142 | EFI_PAGES_TO_SIZE (NumPages)\r | |
143 | );\r | |
901a9bfc | 144 | }\r |