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.
29 IN UINTN NumberOfProcessors
34 ConfigData
= AllocateZeroPool (sizeof (UINT64
) * NumberOfProcessors
);
35 ASSERT (ConfigData
!= NULL
);
40 Detects if AESNI 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 AESNI feature is supported.
51 @retval FALSE AESNI 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_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER
*MsrFeatureConfig
;
65 if (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.AESNI
== 1) {
66 if (IS_SANDY_BRIDGE_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
67 IS_SILVERMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
68 IS_XEON_5600_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
69 IS_XEON_E7_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
70 IS_XEON_PHI_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
71 MsrFeatureConfig
= (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER
*) ConfigData
;
72 ASSERT (MsrFeatureConfig
!= NULL
);
73 MsrFeatureConfig
[ProcessorNumber
].Uint64
= AsmReadMsr64 (MSR_SANDY_BRIDGE_FEATURE_CONFIG
);
81 Initializes AESNI feature to specific state.
83 @param[in] ProcessorNumber The index of the CPU executing this function.
84 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
85 structure for the CPU executing this function.
86 @param[in] ConfigData A pointer to the configuration buffer returned
87 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
88 CPU_FEATURE_GET_CONFIG_DATA was not provided in
90 @param[in] State If TRUE, then the AESNI feature must be enabled.
91 If FALSE, then the AESNI feature must be disabled.
93 @retval RETURN_SUCCESS AESNI feature is initialized.
95 @note This service could be called by BSP only.
100 IN UINTN ProcessorNumber
,
101 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
102 IN VOID
*ConfigData
, OPTIONAL
106 MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER
*MsrFeatureConfig
;
109 // SANDY_BRIDGE, SILVERMONT, XEON_5600, XEON_7, and XEON_PHI have the same MSR index,
110 // Simply use MSR_SANDY_BRIDGE_FEATURE_CONFIG here
112 // The scope of the MSR_SANDY_BRIDGE_FEATURE_CONFIG is Core, only program MSR_FEATURE_CONFIG for thread 0
113 // of each core. Otherwise, once a thread in the core disabled AES, the other thread will cause GP when
116 if (CpuInfo
->ProcessorInfo
.Location
.Thread
== 0) {
117 MsrFeatureConfig
= (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER
*) ConfigData
;
118 ASSERT (MsrFeatureConfig
!= NULL
);
119 if ((MsrFeatureConfig
[ProcessorNumber
].Bits
.AESConfiguration
& BIT0
) == 0) {
120 CPU_REGISTER_TABLE_WRITE_FIELD (
123 MSR_SANDY_BRIDGE_FEATURE_CONFIG
,
124 MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER
,
125 Bits
.AESConfiguration
,
126 BIT1
| ((State
) ? 0 : BIT0
)
130 return RETURN_SUCCESS
;