2 Features in MSR_IA32_FEATURE_CONTROL register.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuCommonFeatures.h"
12 Prepares for the data used by CPU feature detection and initialization.
14 @param[in] NumberOfProcessors The number of CPUs in the platform.
16 @return Pointer to a buffer of CPU related configuration data.
18 @note This service could be called by BSP only.
22 FeatureControlGetConfigData (
23 IN UINTN NumberOfProcessors
28 ConfigData
= AllocateZeroPool (sizeof (MSR_IA32_FEATURE_CONTROL_REGISTER
) * NumberOfProcessors
);
29 ASSERT (ConfigData
!= NULL
);
34 Detects if VMX feature supported on current processor.
36 @param[in] ProcessorNumber The index of the CPU executing this function.
37 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
38 structure for the CPU executing this function.
39 @param[in] ConfigData A pointer to the configuration buffer returned
40 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
41 CPU_FEATURE_GET_CONFIG_DATA was not provided in
44 @retval TRUE VMX feature is supported.
45 @retval FALSE VMX feature is not supported.
47 @note This service could be called by BSP/APs.
52 IN UINTN ProcessorNumber
,
53 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
54 IN VOID
*ConfigData OPTIONAL
57 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
59 ASSERT (ConfigData
!= NULL
);
60 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
61 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
62 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.VMX
== 1);
66 Initializes VMX feature to specific state.
68 @param[in] ProcessorNumber The index of the CPU executing this function.
69 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
70 structure for the CPU executing this function.
71 @param[in] ConfigData A pointer to the configuration buffer returned
72 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
73 CPU_FEATURE_GET_CONFIG_DATA was not provided in
75 @param[in] State If TRUE, then the VMX feature must be enabled.
76 If FALSE, then the VMX feature must be disabled.
78 @retval RETURN_SUCCESS VMX feature is initialized.
80 @note This service could be called by BSP only.
85 IN UINTN ProcessorNumber
,
86 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
87 IN VOID
*ConfigData
, OPTIONAL
91 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
94 // The scope of EnableVmxOutsideSmx bit in the MSR_IA32_FEATURE_CONTROL is core for
95 // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
98 if (IS_SILVERMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
99 IS_GOLDMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
100 IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
101 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
102 return RETURN_SUCCESS
;
106 ASSERT (ConfigData
!= NULL
);
107 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
108 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
109 CPU_REGISTER_TABLE_WRITE_FIELD (
112 MSR_IA32_FEATURE_CONTROL
,
113 MSR_IA32_FEATURE_CONTROL_REGISTER
,
114 Bits
.EnableVmxOutsideSmx
,
118 return RETURN_SUCCESS
;
122 Detects if Lock Feature Control Register feature supported on current processor.
124 @param[in] ProcessorNumber The index of the CPU executing this function.
125 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
126 structure for the CPU executing this function.
127 @param[in] ConfigData A pointer to the configuration buffer returned
128 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
129 CPU_FEATURE_GET_CONFIG_DATA was not provided in
130 RegisterCpuFeature().
132 @retval TRUE Lock Feature Control Register feature is supported.
133 @retval FALSE Lock Feature Control Register feature is not supported.
135 @note This service could be called by BSP/APs.
139 LockFeatureControlRegisterSupport (
140 IN UINTN ProcessorNumber
,
141 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
142 IN VOID
*ConfigData OPTIONAL
145 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
147 ASSERT (ConfigData
!= NULL
);
148 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
149 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
154 Initializes Lock Feature Control Register feature to specific state.
156 @param[in] ProcessorNumber The index of the CPU executing this function.
157 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
158 structure for the CPU executing this function.
159 @param[in] ConfigData A pointer to the configuration buffer returned
160 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
161 CPU_FEATURE_GET_CONFIG_DATA was not provided in
162 RegisterCpuFeature().
163 @param[in] State If TRUE, then the Lock Feature Control Register feature must be enabled.
164 If FALSE, then the Lock Feature Control Register feature must be disabled.
166 @retval RETURN_SUCCESS Lock Feature Control Register feature is initialized.
168 @note This service could be called by BSP only.
172 LockFeatureControlRegisterInitialize (
173 IN UINTN ProcessorNumber
,
174 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
175 IN VOID
*ConfigData
, OPTIONAL
179 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
182 // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
183 // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
186 if (IS_SILVERMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
187 IS_GOLDMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
188 IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
189 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
190 return RETURN_SUCCESS
;
194 ASSERT (ConfigData
!= NULL
);
195 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
196 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
197 CPU_REGISTER_TABLE_WRITE_FIELD (
200 MSR_IA32_FEATURE_CONTROL
,
201 MSR_IA32_FEATURE_CONTROL_REGISTER
,
206 return RETURN_SUCCESS
;
210 Detects if SMX feature supported on current processor.
212 @param[in] ProcessorNumber The index of the CPU executing this function.
213 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
214 structure for the CPU executing this function.
215 @param[in] ConfigData A pointer to the configuration buffer returned
216 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
217 CPU_FEATURE_GET_CONFIG_DATA was not provided in
218 RegisterCpuFeature().
220 @retval TRUE SMX feature is supported.
221 @retval FALSE SMX feature is not supported.
223 @note This service could be called by BSP/APs.
228 IN UINTN ProcessorNumber
,
229 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
230 IN VOID
*ConfigData OPTIONAL
233 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
235 ASSERT (ConfigData
!= NULL
);
236 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
237 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
238 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.SMX
== 1);
242 Initializes SMX feature to specific state.
244 @param[in] ProcessorNumber The index of the CPU executing this function.
245 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
246 structure for the CPU executing this function.
247 @param[in] ConfigData A pointer to the configuration buffer returned
248 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
249 CPU_FEATURE_GET_CONFIG_DATA was not provided in
250 RegisterCpuFeature().
251 @param[in] State If TRUE, then SMX feature must be enabled.
252 If FALSE, then SMX feature must be disabled.
254 @retval RETURN_SUCCESS SMX feature is initialized.
255 @retval RETURN_UNSUPPORTED VMX not initialized.
257 @note This service could be called by BSP only.
262 IN UINTN ProcessorNumber
,
263 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
264 IN VOID
*ConfigData
, OPTIONAL
268 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
269 RETURN_STATUS Status
;
272 // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
273 // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
276 if (IS_GOLDMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
277 IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
278 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
279 return RETURN_SUCCESS
;
283 Status
= RETURN_SUCCESS
;
285 if (State
&& (!IsCpuFeatureInSetting (CPU_FEATURE_VMX
))) {
286 DEBUG ((DEBUG_WARN
, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
288 Status
= RETURN_UNSUPPORTED
;
291 ASSERT (ConfigData
!= NULL
);
292 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
293 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
294 CPU_REGISTER_TABLE_WRITE_FIELD (
297 MSR_IA32_FEATURE_CONTROL
,
298 MSR_IA32_FEATURE_CONTROL_REGISTER
,
299 Bits
.SenterLocalFunctionEnables
,
303 CPU_REGISTER_TABLE_WRITE_FIELD (
306 MSR_IA32_FEATURE_CONTROL
,
307 MSR_IA32_FEATURE_CONTROL_REGISTER
,
308 Bits
.SenterGlobalEnable
,
312 CPU_REGISTER_TABLE_WRITE_FIELD (
315 MSR_IA32_FEATURE_CONTROL
,
316 MSR_IA32_FEATURE_CONTROL_REGISTER
,
317 Bits
.EnableVmxInsideSmx
,