]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/Aesni.c
UefiCpuPkg CpuCommonFeaturesLib: Remove CPU generation check
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / Aesni.c
CommitLineData
80c4b236
JF
1/** @file\r
2 AESNI feature.\r
3\r
34b162d0 4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
80c4b236
JF
6\r
7**/\r
8\r
9#include "CpuCommonFeatures.h"\r
10\r
11/**\r
12 Prepares for the data used by CPU feature detection and initialization.\r
13\r
14 @param[in] NumberOfProcessors The number of CPUs in the platform.\r
15\r
16 @return Pointer to a buffer of CPU related configuration data.\r
17\r
18 @note This service could be called by BSP only.\r
19**/\r
20VOID *\r
21EFIAPI\r
22AesniGetConfigData (\r
23 IN UINTN NumberOfProcessors\r
24 )\r
25{\r
26 UINT64 *ConfigData;\r
27\r
28 ConfigData = AllocateZeroPool (sizeof (UINT64) * NumberOfProcessors);\r
29 ASSERT (ConfigData != NULL);\r
30 return ConfigData;\r
31}\r
32\r
33/**\r
34 Detects if AESNI feature supported on current processor.\r
35\r
36 @param[in] ProcessorNumber The index of the CPU executing this function.\r
37 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
38 structure for the CPU executing this function.\r
39 @param[in] ConfigData A pointer to the configuration buffer returned\r
40 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
41 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
42 RegisterCpuFeature().\r
43\r
44 @retval TRUE AESNI feature is supported.\r
45 @retval FALSE AESNI feature is not supported.\r
46\r
47 @note This service could be called by BSP/APs.\r
48**/\r
49BOOLEAN\r
50EFIAPI\r
51AesniSupport (\r
52 IN UINTN ProcessorNumber,\r
53 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
54 IN VOID *ConfigData OPTIONAL\r
55 )\r
56{\r
57 MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;\r
58\r
9d02c34f 59 if (CpuInfo->CpuIdVersionInfoEcx.Bits.AESNI == 1) {\r
41ac2076
SZ
60 MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *) ConfigData;\r
61 ASSERT (MsrFeatureConfig != NULL);\r
62 MsrFeatureConfig[ProcessorNumber].Uint64 = AsmReadMsr64 (MSR_SANDY_BRIDGE_FEATURE_CONFIG);\r
9d02c34f 63 return TRUE;\r
80c4b236
JF
64 }\r
65 return FALSE;\r
66}\r
67\r
68/**\r
69 Initializes AESNI feature to specific state.\r
70\r
71 @param[in] ProcessorNumber The index of the CPU executing this function.\r
72 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
73 structure for the CPU executing this function.\r
74 @param[in] ConfigData A pointer to the configuration buffer returned\r
75 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
76 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
77 RegisterCpuFeature().\r
78 @param[in] State If TRUE, then the AESNI feature must be enabled.\r
79 If FALSE, then the AESNI feature must be disabled.\r
80\r
81 @retval RETURN_SUCCESS AESNI feature is initialized.\r
82\r
83 @note This service could be called by BSP only.\r
84**/\r
85RETURN_STATUS\r
86EFIAPI\r
87AesniInitialize (\r
88 IN UINTN ProcessorNumber,\r
89 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
90 IN VOID *ConfigData, OPTIONAL\r
91 IN BOOLEAN State\r
92 )\r
93{\r
94 MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;\r
95\r
96 //\r
97 // SANDY_BRIDGE, SILVERMONT, XEON_5600, XEON_7, and XEON_PHI have the same MSR index,\r
98 // Simply use MSR_SANDY_BRIDGE_FEATURE_CONFIG here\r
99 //\r
100 // The scope of the MSR_SANDY_BRIDGE_FEATURE_CONFIG is Core, only program MSR_FEATURE_CONFIG for thread 0\r
101 // of each core. Otherwise, once a thread in the core disabled AES, the other thread will cause GP when\r
102 // programming it.\r
103 //\r
104 if (CpuInfo->ProcessorInfo.Location.Thread == 0) {\r
105 MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *) ConfigData;\r
3dcb5325 106 ASSERT (MsrFeatureConfig != NULL);\r
80c4b236
JF
107 if ((MsrFeatureConfig[ProcessorNumber].Bits.AESConfiguration & BIT0) == 0) {\r
108 CPU_REGISTER_TABLE_WRITE_FIELD (\r
109 ProcessorNumber,\r
110 Msr,\r
111 MSR_SANDY_BRIDGE_FEATURE_CONFIG,\r
112 MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER,\r
113 Bits.AESConfiguration,\r
34b162d0 114 BIT0 | ((State) ? 0 : BIT1)\r
80c4b236
JF
115 );\r
116 }\r
117 }\r
118 return RETURN_SUCCESS;\r
119}\r