]>
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 | /**\r | |
5b5028e6 LE |
19 | This function clears memory encryption bit for the memory region specified by\r |
20 | BaseAddress and NumPages from the current page table context.\r | |
a1f22614 | 21 | \r |
5b5028e6 LE |
22 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
23 | current CR3)\r | |
24 | @param[in] BaseAddress The physical address that is the start\r | |
25 | address of a memory region.\r | |
26 | @param[in] NumPages The number of pages from start memory\r | |
27 | region.\r | |
a1f22614 | 28 | \r |
5b5028e6 LE |
29 | @retval RETURN_SUCCESS The attributes were cleared for the\r |
30 | memory region.\r | |
31 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
32 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
33 | is not supported\r | |
34 | **/\r | |
a1f22614 BS |
35 | RETURN_STATUS\r |
36 | EFIAPI\r | |
37 | MemEncryptSevClearPageEncMask (\r | |
38 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
39 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
adfa3327 | 40 | IN UINTN NumPages\r |
a1f22614 BS |
41 | )\r |
42 | {\r | |
43 | //\r | |
44 | // Memory encryption bit is not accessible in 32-bit mode\r | |
45 | //\r | |
46 | return RETURN_UNSUPPORTED;\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | This function sets memory encryption bit for the memory region specified by\r | |
154dcd6c | 51 | BaseAddress and NumPages from the current page table context.\r |
a1f22614 | 52 | \r |
154dcd6c LE |
53 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
54 | current CR3)\r | |
55 | @param[in] BaseAddress The physical address that is the start\r | |
56 | address of a memory region.\r | |
57 | @param[in] NumPages The number of pages from start memory\r | |
58 | region.\r | |
a1f22614 | 59 | \r |
154dcd6c LE |
60 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
61 | region.\r | |
62 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
63 | @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r | |
64 | is not supported\r | |
65 | **/\r | |
a1f22614 BS |
66 | RETURN_STATUS\r |
67 | EFIAPI\r | |
68 | MemEncryptSevSetPageEncMask (\r | |
69 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
70 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
adfa3327 | 71 | IN UINTN NumPages\r |
a1f22614 BS |
72 | )\r |
73 | {\r | |
74 | //\r | |
75 | // Memory encryption bit is not accessible in 32-bit mode\r | |
76 | //\r | |
77 | return RETURN_UNSUPPORTED;\r | |
78 | }\r | |
c330af02 TL |
79 | \r |
80 | /**\r | |
81 | Returns the encryption state of the specified virtual address range.\r | |
82 | \r | |
83 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
84 | current CR3)\r | |
85 | @param[in] BaseAddress Base address to check\r | |
86 | @param[in] Length Length of virtual address range\r | |
87 | \r | |
88 | @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r | |
89 | unencrypted\r | |
90 | @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r | |
91 | encrypted\r | |
92 | @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r | |
93 | @retval MemEncryptSevAddressRangeError Address range is not mapped\r | |
94 | **/\r | |
95 | MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r | |
96 | EFIAPI\r | |
97 | MemEncryptSevGetAddressRangeState (\r | |
98 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
99 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
100 | IN UINTN Length\r | |
101 | )\r | |
102 | {\r | |
103 | //\r | |
104 | // Memory is always encrypted in 32-bit mode\r | |
105 | //\r | |
106 | return MemEncryptSevAddressRangeEncrypted;\r | |
107 | }\r | |
901a9bfc BS |
108 | \r |
109 | /**\r | |
110 | This function clears memory encryption bit for the MMIO region specified by\r | |
111 | BaseAddress and NumPages.\r | |
112 | \r | |
113 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r | |
114 | current CR3)\r | |
115 | @param[in] BaseAddress The physical address that is the start\r | |
116 | address of a MMIO region.\r | |
117 | @param[in] NumPages The number of pages from start memory\r | |
118 | region.\r | |
119 | \r | |
120 | @retval RETURN_SUCCESS The attributes were cleared for the\r | |
121 | memory region.\r | |
122 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r | |
123 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r | |
124 | is not supported\r | |
125 | **/\r | |
126 | RETURN_STATUS\r | |
127 | EFIAPI\r | |
128 | MemEncryptSevClearMmioPageEncMask (\r | |
129 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
130 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
131 | IN UINTN NumPages\r | |
132 | )\r | |
133 | {\r | |
134 | //\r | |
135 | // Memory encryption bit is not accessible in 32-bit mode\r | |
136 | //\r | |
137 | return RETURN_UNSUPPORTED;\r | |
138 | }\r |