1 | /** @file
|
---|
2 | Features in MSR_IA32_FEATURE_CONTROL register.
|
---|
3 |
|
---|
4 | Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "CpuCommonFeatures.h"
|
---|
10 |
|
---|
11 | /**
|
---|
12 | Detects if VMX feature supported on current processor.
|
---|
13 |
|
---|
14 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
15 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
16 | structure for the CPU executing this function.
|
---|
17 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
18 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
19 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
20 | RegisterCpuFeature().
|
---|
21 |
|
---|
22 | @retval TRUE VMX feature is supported.
|
---|
23 | @retval FALSE VMX feature is not supported.
|
---|
24 |
|
---|
25 | @note This service could be called by BSP/APs.
|
---|
26 | **/
|
---|
27 | BOOLEAN
|
---|
28 | EFIAPI
|
---|
29 | VmxSupport (
|
---|
30 | IN UINTN ProcessorNumber,
|
---|
31 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
32 | IN VOID *ConfigData OPTIONAL
|
---|
33 | )
|
---|
34 | {
|
---|
35 | return (CpuInfo->CpuIdVersionInfoEcx.Bits.VMX == 1);
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | Initializes VMX feature to specific state.
|
---|
40 |
|
---|
41 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
42 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
43 | structure for the CPU executing this function.
|
---|
44 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
45 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
46 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
47 | RegisterCpuFeature().
|
---|
48 | @param[in] State If TRUE, then the VMX feature must be enabled.
|
---|
49 | If FALSE, then the VMX feature must be disabled.
|
---|
50 |
|
---|
51 | @retval RETURN_SUCCESS VMX feature is initialized.
|
---|
52 |
|
---|
53 | @note This service could be called by BSP only.
|
---|
54 | **/
|
---|
55 | RETURN_STATUS
|
---|
56 | EFIAPI
|
---|
57 | VmxInitialize (
|
---|
58 | IN UINTN ProcessorNumber,
|
---|
59 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
60 | IN VOID *ConfigData OPTIONAL,
|
---|
61 | IN BOOLEAN State
|
---|
62 | )
|
---|
63 | {
|
---|
64 | //
|
---|
65 | // The scope of EnableVmxOutsideSmx bit in the MSR_IA32_FEATURE_CONTROL is core for
|
---|
66 | // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
|
---|
67 | // core.
|
---|
68 | //
|
---|
69 | if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
70 | IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
71 | IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
---|
72 | {
|
---|
73 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
74 | return RETURN_SUCCESS;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
79 | ProcessorNumber,
|
---|
80 | Msr,
|
---|
81 | MSR_IA32_FEATURE_CONTROL,
|
---|
82 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
83 | Bits.EnableVmxOutsideSmx,
|
---|
84 | (State) ? 1 : 0
|
---|
85 | );
|
---|
86 |
|
---|
87 | return RETURN_SUCCESS;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Detects if Lock Feature Control Register feature supported on current processor.
|
---|
92 |
|
---|
93 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
94 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
95 | structure for the CPU executing this function.
|
---|
96 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
97 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
98 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
99 | RegisterCpuFeature().
|
---|
100 |
|
---|
101 | @retval TRUE Lock Feature Control Register feature is supported.
|
---|
102 | @retval FALSE Lock Feature Control Register feature is not supported.
|
---|
103 |
|
---|
104 | @note This service could be called by BSP/APs.
|
---|
105 | **/
|
---|
106 | BOOLEAN
|
---|
107 | EFIAPI
|
---|
108 | LockFeatureControlRegisterSupport (
|
---|
109 | IN UINTN ProcessorNumber,
|
---|
110 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
111 | IN VOID *ConfigData OPTIONAL
|
---|
112 | )
|
---|
113 | {
|
---|
114 | return TRUE;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | Initializes Lock Feature Control Register feature to specific state.
|
---|
119 |
|
---|
120 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
121 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
122 | structure for the CPU executing this function.
|
---|
123 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
124 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
125 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
126 | RegisterCpuFeature().
|
---|
127 | @param[in] State If TRUE, then the Lock Feature Control Register feature must be enabled.
|
---|
128 | If FALSE, then the Lock Feature Control Register feature must be disabled.
|
---|
129 |
|
---|
130 | @retval RETURN_SUCCESS Lock Feature Control Register feature is initialized.
|
---|
131 |
|
---|
132 | @note This service could be called by BSP only.
|
---|
133 | **/
|
---|
134 | RETURN_STATUS
|
---|
135 | EFIAPI
|
---|
136 | LockFeatureControlRegisterInitialize (
|
---|
137 | IN UINTN ProcessorNumber,
|
---|
138 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
139 | IN VOID *ConfigData OPTIONAL,
|
---|
140 | IN BOOLEAN State
|
---|
141 | )
|
---|
142 | {
|
---|
143 | //
|
---|
144 | // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
|
---|
145 | // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
|
---|
146 | // core.
|
---|
147 | //
|
---|
148 | if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
149 | IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
150 | IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
---|
151 | {
|
---|
152 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
153 | return RETURN_SUCCESS;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
158 | ProcessorNumber,
|
---|
159 | Msr,
|
---|
160 | MSR_IA32_FEATURE_CONTROL,
|
---|
161 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
162 | Bits.Lock,
|
---|
163 | 1
|
---|
164 | );
|
---|
165 |
|
---|
166 | return RETURN_SUCCESS;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | Detects if SMX feature supported on current processor.
|
---|
171 |
|
---|
172 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
173 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
174 | structure for the CPU executing this function.
|
---|
175 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
176 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
177 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
178 | RegisterCpuFeature().
|
---|
179 |
|
---|
180 | @retval TRUE SMX feature is supported.
|
---|
181 | @retval FALSE SMX feature is not supported.
|
---|
182 |
|
---|
183 | @note This service could be called by BSP/APs.
|
---|
184 | **/
|
---|
185 | BOOLEAN
|
---|
186 | EFIAPI
|
---|
187 | SmxSupport (
|
---|
188 | IN UINTN ProcessorNumber,
|
---|
189 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
190 | IN VOID *ConfigData OPTIONAL
|
---|
191 | )
|
---|
192 | {
|
---|
193 | return (CpuInfo->CpuIdVersionInfoEcx.Bits.SMX == 1);
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | Initializes SMX feature to specific state.
|
---|
198 |
|
---|
199 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
200 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
201 | structure for the CPU executing this function.
|
---|
202 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
203 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
204 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
205 | RegisterCpuFeature().
|
---|
206 | @param[in] State If TRUE, then SMX feature must be enabled.
|
---|
207 | If FALSE, then SMX feature must be disabled.
|
---|
208 |
|
---|
209 | @retval RETURN_SUCCESS SMX feature is initialized.
|
---|
210 | @retval RETURN_UNSUPPORTED VMX not initialized.
|
---|
211 |
|
---|
212 | @note This service could be called by BSP only.
|
---|
213 | **/
|
---|
214 | RETURN_STATUS
|
---|
215 | EFIAPI
|
---|
216 | SmxInitialize (
|
---|
217 | IN UINTN ProcessorNumber,
|
---|
218 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
219 | IN VOID *ConfigData OPTIONAL,
|
---|
220 | IN BOOLEAN State
|
---|
221 | )
|
---|
222 | {
|
---|
223 | RETURN_STATUS Status;
|
---|
224 |
|
---|
225 | //
|
---|
226 | // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
|
---|
227 | // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
|
---|
228 | // core.
|
---|
229 | //
|
---|
230 | if (IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
231 | IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
---|
232 | {
|
---|
233 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
234 | return RETURN_SUCCESS;
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | Status = RETURN_SUCCESS;
|
---|
239 |
|
---|
240 | if (State && (!IsCpuFeatureInSetting (CPU_FEATURE_VMX))) {
|
---|
241 | DEBUG ((DEBUG_WARN, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
|
---|
242 | State = FALSE;
|
---|
243 | Status = RETURN_UNSUPPORTED;
|
---|
244 | }
|
---|
245 |
|
---|
246 | CPU_REGISTER_TABLE_WRITE_FIELD (
|
---|
247 | ProcessorNumber,
|
---|
248 | ControlRegister,
|
---|
249 | 4,
|
---|
250 | IA32_CR4,
|
---|
251 | Bits.SMXE,
|
---|
252 | (State) ? 1 : 0
|
---|
253 | )
|
---|
254 |
|
---|
255 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
256 | ProcessorNumber,
|
---|
257 | Msr,
|
---|
258 | MSR_IA32_FEATURE_CONTROL,
|
---|
259 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
260 | Bits.SenterLocalFunctionEnables,
|
---|
261 | (State) ? 0x7F : 0
|
---|
262 | );
|
---|
263 |
|
---|
264 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
265 | ProcessorNumber,
|
---|
266 | Msr,
|
---|
267 | MSR_IA32_FEATURE_CONTROL,
|
---|
268 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
269 | Bits.SenterGlobalEnable,
|
---|
270 | (State) ? 1 : 0
|
---|
271 | );
|
---|
272 |
|
---|
273 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
274 | ProcessorNumber,
|
---|
275 | Msr,
|
---|
276 | MSR_IA32_FEATURE_CONTROL,
|
---|
277 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
278 | Bits.EnableVmxInsideSmx,
|
---|
279 | (State) ? 1 : 0
|
---|
280 | );
|
---|
281 |
|
---|
282 | return Status;
|
---|
283 | }
|
---|