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 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
73 | return RETURN_SUCCESS;
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
78 | ProcessorNumber,
|
---|
79 | Msr,
|
---|
80 | MSR_IA32_FEATURE_CONTROL,
|
---|
81 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
82 | Bits.EnableVmxOutsideSmx,
|
---|
83 | (State) ? 1 : 0
|
---|
84 | );
|
---|
85 |
|
---|
86 | return RETURN_SUCCESS;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | Detects if Lock Feature Control Register feature supported on current processor.
|
---|
91 |
|
---|
92 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
93 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
94 | structure for the CPU executing this function.
|
---|
95 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
96 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
97 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
98 | RegisterCpuFeature().
|
---|
99 |
|
---|
100 | @retval TRUE Lock Feature Control Register feature is supported.
|
---|
101 | @retval FALSE Lock Feature Control Register feature is not supported.
|
---|
102 |
|
---|
103 | @note This service could be called by BSP/APs.
|
---|
104 | **/
|
---|
105 | BOOLEAN
|
---|
106 | EFIAPI
|
---|
107 | LockFeatureControlRegisterSupport (
|
---|
108 | IN UINTN ProcessorNumber,
|
---|
109 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
110 | IN VOID *ConfigData OPTIONAL
|
---|
111 | )
|
---|
112 | {
|
---|
113 | return TRUE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | Initializes Lock Feature Control Register feature to specific state.
|
---|
118 |
|
---|
119 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
120 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
121 | structure for the CPU executing this function.
|
---|
122 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
123 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
124 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
125 | RegisterCpuFeature().
|
---|
126 | @param[in] State If TRUE, then the Lock Feature Control Register feature must be enabled.
|
---|
127 | If FALSE, then the Lock Feature Control Register feature must be disabled.
|
---|
128 |
|
---|
129 | @retval RETURN_SUCCESS Lock Feature Control Register feature is initialized.
|
---|
130 |
|
---|
131 | @note This service could be called by BSP only.
|
---|
132 | **/
|
---|
133 | RETURN_STATUS
|
---|
134 | EFIAPI
|
---|
135 | LockFeatureControlRegisterInitialize (
|
---|
136 | IN UINTN ProcessorNumber,
|
---|
137 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
138 | IN VOID *ConfigData, OPTIONAL
|
---|
139 | IN BOOLEAN State
|
---|
140 | )
|
---|
141 | {
|
---|
142 | //
|
---|
143 | // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
|
---|
144 | // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
|
---|
145 | // core.
|
---|
146 | //
|
---|
147 | if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
148 | IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
149 | IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
|
---|
150 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
151 | return RETURN_SUCCESS;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
156 | ProcessorNumber,
|
---|
157 | Msr,
|
---|
158 | MSR_IA32_FEATURE_CONTROL,
|
---|
159 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
160 | Bits.Lock,
|
---|
161 | 1
|
---|
162 | );
|
---|
163 |
|
---|
164 | return RETURN_SUCCESS;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /**
|
---|
168 | Detects if SMX feature supported on current processor.
|
---|
169 |
|
---|
170 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
171 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
172 | structure for the CPU executing this function.
|
---|
173 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
174 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
175 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
176 | RegisterCpuFeature().
|
---|
177 |
|
---|
178 | @retval TRUE SMX feature is supported.
|
---|
179 | @retval FALSE SMX feature is not supported.
|
---|
180 |
|
---|
181 | @note This service could be called by BSP/APs.
|
---|
182 | **/
|
---|
183 | BOOLEAN
|
---|
184 | EFIAPI
|
---|
185 | SmxSupport (
|
---|
186 | IN UINTN ProcessorNumber,
|
---|
187 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
188 | IN VOID *ConfigData OPTIONAL
|
---|
189 | )
|
---|
190 | {
|
---|
191 | return (CpuInfo->CpuIdVersionInfoEcx.Bits.SMX == 1);
|
---|
192 | }
|
---|
193 |
|
---|
194 | /**
|
---|
195 | Initializes SMX feature to specific state.
|
---|
196 |
|
---|
197 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
198 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
199 | structure for the CPU executing this function.
|
---|
200 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
201 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
202 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
203 | RegisterCpuFeature().
|
---|
204 | @param[in] State If TRUE, then SMX feature must be enabled.
|
---|
205 | If FALSE, then SMX feature must be disabled.
|
---|
206 |
|
---|
207 | @retval RETURN_SUCCESS SMX feature is initialized.
|
---|
208 | @retval RETURN_UNSUPPORTED VMX not initialized.
|
---|
209 |
|
---|
210 | @note This service could be called by BSP only.
|
---|
211 | **/
|
---|
212 | RETURN_STATUS
|
---|
213 | EFIAPI
|
---|
214 | SmxInitialize (
|
---|
215 | IN UINTN ProcessorNumber,
|
---|
216 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
217 | IN VOID *ConfigData, OPTIONAL
|
---|
218 | IN BOOLEAN State
|
---|
219 | )
|
---|
220 | {
|
---|
221 | RETURN_STATUS Status;
|
---|
222 |
|
---|
223 | //
|
---|
224 | // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
|
---|
225 | // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
|
---|
226 | // core.
|
---|
227 | //
|
---|
228 | if (IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
229 | IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
|
---|
230 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
231 | return RETURN_SUCCESS;
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | Status = RETURN_SUCCESS;
|
---|
236 |
|
---|
237 | if (State && (!IsCpuFeatureInSetting (CPU_FEATURE_VMX))) {
|
---|
238 | DEBUG ((DEBUG_WARN, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
|
---|
239 | State = FALSE;
|
---|
240 | Status = RETURN_UNSUPPORTED;
|
---|
241 | }
|
---|
242 |
|
---|
243 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
244 | ProcessorNumber,
|
---|
245 | Msr,
|
---|
246 | MSR_IA32_FEATURE_CONTROL,
|
---|
247 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
248 | Bits.SenterLocalFunctionEnables,
|
---|
249 | (State) ? 0x7F : 0
|
---|
250 | );
|
---|
251 |
|
---|
252 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
253 | ProcessorNumber,
|
---|
254 | Msr,
|
---|
255 | MSR_IA32_FEATURE_CONTROL,
|
---|
256 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
257 | Bits.SenterGlobalEnable,
|
---|
258 | (State) ? 1 : 0
|
---|
259 | );
|
---|
260 |
|
---|
261 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
262 | ProcessorNumber,
|
---|
263 | Msr,
|
---|
264 | MSR_IA32_FEATURE_CONTROL,
|
---|
265 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
266 | Bits.EnableVmxInsideSmx,
|
---|
267 | (State) ? 1 : 0
|
---|
268 | );
|
---|
269 |
|
---|
270 | return Status;
|
---|
271 | }
|
---|