2 Features in MSR_IA32_FEATURE_CONTROL register.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "CpuCommonFeatures.h"
18 Prepares for the data used by CPU feature detection and initialization.
20 @param[in] NumberOfProcessors The number of CPUs in the platform.
22 @return Pointer to a buffer of CPU related configuration data.
24 @note This service could be called by BSP only.
28 FeatureControlGetConfigData (
29 IN UINTN NumberOfProcessors
34 ConfigData
= AllocateZeroPool (sizeof (MSR_IA32_FEATURE_CONTROL_REGISTER
) * NumberOfProcessors
);
35 ASSERT (ConfigData
!= NULL
);
40 Detects if VMX feature supported on current processor.
42 @param[in] ProcessorNumber The index of the CPU executing this function.
43 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
44 structure for the CPU executing this function.
45 @param[in] ConfigData A pointer to the configuration buffer returned
46 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
47 CPU_FEATURE_GET_CONFIG_DATA was not provided in
50 @retval TRUE VMX feature is supported.
51 @retval FALSE VMX feature is not supported.
53 @note This service could be called by BSP/APs.
58 IN UINTN ProcessorNumber
,
59 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
60 IN VOID
*ConfigData OPTIONAL
63 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
65 ASSERT (ConfigData
!= NULL
);
66 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
67 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
68 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.VMX
== 1);
72 Initializes VMX feature to specific state.
74 @param[in] ProcessorNumber The index of the CPU executing this function.
75 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
76 structure for the CPU executing this function.
77 @param[in] ConfigData A pointer to the configuration buffer returned
78 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
79 CPU_FEATURE_GET_CONFIG_DATA was not provided in
81 @param[in] State If TRUE, then the VMX feature must be enabled.
82 If FALSE, then the VMX feature must be disabled.
84 @retval RETURN_SUCCESS VMX feature is initialized.
86 @note This service could be called by BSP only.
91 IN UINTN ProcessorNumber
,
92 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
93 IN VOID
*ConfigData
, OPTIONAL
97 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
99 ASSERT (ConfigData
!= NULL
);
100 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
101 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
102 CPU_REGISTER_TABLE_WRITE_FIELD (
105 MSR_IA32_FEATURE_CONTROL
,
106 MSR_IA32_FEATURE_CONTROL_REGISTER
,
107 Bits
.EnableVmxOutsideSmx
,
111 return RETURN_SUCCESS
;
115 Detects if Lock Feature Control Register feature supported on current processor.
117 @param[in] ProcessorNumber The index of the CPU executing this function.
118 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
119 structure for the CPU executing this function.
120 @param[in] ConfigData A pointer to the configuration buffer returned
121 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
122 CPU_FEATURE_GET_CONFIG_DATA was not provided in
123 RegisterCpuFeature().
125 @retval TRUE Lock Feature Control Register feature is supported.
126 @retval FALSE Lock Feature Control Register feature is not supported.
128 @note This service could be called by BSP/APs.
132 LockFeatureControlRegisterSupport (
133 IN UINTN ProcessorNumber
,
134 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
135 IN VOID
*ConfigData OPTIONAL
138 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
140 ASSERT (ConfigData
!= NULL
);
141 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
142 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
147 Initializes Lock Feature Control Register feature to specific state.
149 @param[in] ProcessorNumber The index of the CPU executing this function.
150 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
151 structure for the CPU executing this function.
152 @param[in] ConfigData A pointer to the configuration buffer returned
153 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
154 CPU_FEATURE_GET_CONFIG_DATA was not provided in
155 RegisterCpuFeature().
156 @param[in] State If TRUE, then the Lock Feature Control Register feature must be enabled.
157 If FALSE, then the Lock Feature Control Register feature must be disabled.
159 @retval RETURN_SUCCESS Lock Feature Control Register feature is initialized.
161 @note This service could be called by BSP only.
165 LockFeatureControlRegisterInitialize (
166 IN UINTN ProcessorNumber
,
167 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
168 IN VOID
*ConfigData
, OPTIONAL
172 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
174 ASSERT (ConfigData
!= NULL
);
175 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
176 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
177 CPU_REGISTER_TABLE_WRITE_FIELD (
180 MSR_IA32_FEATURE_CONTROL
,
181 MSR_IA32_FEATURE_CONTROL_REGISTER
,
186 return RETURN_SUCCESS
;
190 Detects if SMX feature supported on current processor.
192 @param[in] ProcessorNumber The index of the CPU executing this function.
193 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
194 structure for the CPU executing this function.
195 @param[in] ConfigData A pointer to the configuration buffer returned
196 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
197 CPU_FEATURE_GET_CONFIG_DATA was not provided in
198 RegisterCpuFeature().
200 @retval TRUE SMX feature is supported.
201 @retval FALSE SMX feature is not supported.
203 @note This service could be called by BSP/APs.
208 IN UINTN ProcessorNumber
,
209 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
210 IN VOID
*ConfigData OPTIONAL
213 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
215 ASSERT (ConfigData
!= NULL
);
216 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
217 MsrRegister
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL
);
218 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.SMX
== 1);
222 Initializes SMX feature to specific state.
224 @param[in] ProcessorNumber The index of the CPU executing this function.
225 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
226 structure for the CPU executing this function.
227 @param[in] ConfigData A pointer to the configuration buffer returned
228 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
229 CPU_FEATURE_GET_CONFIG_DATA was not provided in
230 RegisterCpuFeature().
231 @param[in] State If TRUE, then SMX feature must be enabled.
232 If FALSE, then SMX feature must be disabled.
234 @retval RETURN_SUCCESS SMX feature is initialized.
235 @retval RETURN_UNSUPPORTED VMX not initialized.
237 @note This service could be called by BSP only.
242 IN UINTN ProcessorNumber
,
243 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
244 IN VOID
*ConfigData
, OPTIONAL
248 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
249 RETURN_STATUS Status
;
251 Status
= RETURN_SUCCESS
;
253 if (State
&& (!IsCpuFeatureInSetting (CPU_FEATURE_VMX
))) {
254 DEBUG ((DEBUG_WARN
, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
256 Status
= RETURN_UNSUPPORTED
;
259 ASSERT (ConfigData
!= NULL
);
260 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
261 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
262 CPU_REGISTER_TABLE_WRITE_FIELD (
265 MSR_IA32_FEATURE_CONTROL
,
266 MSR_IA32_FEATURE_CONTROL_REGISTER
,
267 Bits
.SenterLocalFunctionEnables
,
271 CPU_REGISTER_TABLE_WRITE_FIELD (
274 MSR_IA32_FEATURE_CONTROL
,
275 MSR_IA32_FEATURE_CONTROL_REGISTER
,
276 Bits
.SenterGlobalEnable
,
280 CPU_REGISTER_TABLE_WRITE_FIELD (
283 MSR_IA32_FEATURE_CONTROL
,
284 MSR_IA32_FEATURE_CONTROL_REGISTER
,
285 Bits
.EnableVmxInsideSmx
,