]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | Secure Encrypted Virtualization (SEV) library helper function\r | |
4 | \r | |
5 | Copyright (c) 2017 - 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/BaseLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | #include <Library/MemEncryptSevLib.h>\r | |
14 | #include <Register/Amd/Cpuid.h>\r | |
15 | #include <Register/Amd/Msr.h>\r | |
16 | #include <Register/Cpuid.h>\r | |
17 | \r | |
18 | /**\r | |
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 | |
21 | \r | |
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 | |
28 | \r | |
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 | |
35 | RETURN_STATUS\r | |
36 | EFIAPI\r | |
37 | MemEncryptSevClearPageEncMask (\r | |
38 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
39 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
40 | IN UINTN NumPages\r | |
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 | |
51 | BaseAddress and NumPages from the current page table context.\r | |
52 | \r | |
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 | |
59 | \r | |
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 | |
66 | RETURN_STATUS\r | |
67 | EFIAPI\r | |
68 | MemEncryptSevSetPageEncMask (\r | |
69 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
70 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
71 | IN UINTN NumPages\r | |
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 | |
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 | |
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 | |
139 | \r | |
140 | /**\r | |
141 | Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.\r | |
142 | \r | |
143 | @param[in] BaseAddress Base address\r | |
144 | @param[in] NumPages Number of pages starting from the base address\r | |
145 | \r | |
146 | **/\r | |
147 | VOID\r | |
148 | EFIAPI\r | |
149 | MemEncryptSevSnpPreValidateSystemRam (\r | |
150 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
151 | IN UINTN NumPages\r | |
152 | )\r | |
153 | {\r | |
154 | ASSERT (FALSE);\r | |
155 | }\r |