]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c
UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / X2Apic.c
CommitLineData
80c4b236
JF
1/** @file\r
2 X2Apic feature.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "CpuCommonFeatures.h"\r
16\r
6661abb6
JF
17/**\r
18 Prepares for the data used by CPU feature detection and initialization.\r
19\r
20 @param[in] NumberOfProcessors The number of CPUs in the platform.\r
21\r
22 @return Pointer to a buffer of CPU related configuration data.\r
23\r
24 @note This service could be called by BSP only.\r
25**/\r
26VOID *\r
27EFIAPI\r
28X2ApicGetConfigData (\r
29 IN UINTN NumberOfProcessors\r
30 )\r
31{\r
32 BOOLEAN *ConfigData;\r
33\r
34 ConfigData = AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors);\r
35 ASSERT (ConfigData != NULL);\r
36 return ConfigData;\r
37}\r
38\r
80c4b236
JF
39/**\r
40 Detects if X2Apci feature supported on current processor.\r
41\r
42 Detect if X2Apci has been already enabled.\r
43\r
44 @param[in] ProcessorNumber The index of the CPU executing this function.\r
45 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
46 structure for the CPU executing this function.\r
47 @param[in] ConfigData A pointer to the configuration buffer returned\r
48 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
49 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
50 RegisterCpuFeature().\r
51\r
52 @retval TRUE X2Apci feature is supported.\r
53 @retval FALSE X2Apci feature is not supported.\r
54\r
55 @note This service could be called by BSP/APs.\r
56**/\r
57BOOLEAN\r
58EFIAPI\r
59X2ApicSupport (\r
60 IN UINTN ProcessorNumber,\r
61 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
62 IN VOID *ConfigData OPTIONAL\r
63 )\r
64{\r
6661abb6
JF
65 BOOLEAN *X2ApicEnabled;\r
66\r
67 ASSERT (ConfigData != NULL);\r
68 X2ApicEnabled = (BOOLEAN *) ConfigData;\r
69 //\r
70 // *ConfigData indicates if X2APIC enabled on current processor\r
71 //\r
72 X2ApicEnabled[ProcessorNumber] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC) ? TRUE : FALSE;\r
73\r
74 return (CpuInfo->CpuIdVersionInfoEcx.Bits.x2APIC == 1);\r
80c4b236
JF
75}\r
76\r
77/**\r
78 Initializes X2Apci feature to specific state.\r
79\r
80 @param[in] ProcessorNumber The index of the CPU executing this function.\r
81 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
82 structure for the CPU executing this function.\r
83 @param[in] ConfigData A pointer to the configuration buffer returned\r
84 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
85 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
86 RegisterCpuFeature().\r
87 @param[in] State If TRUE, then the X2Apci feature must be enabled.\r
88 If FALSE, then the X2Apci feature must be disabled.\r
89\r
90 @retval RETURN_SUCCESS X2Apci feature is initialized.\r
91\r
92 @note This service could be called by BSP only.\r
93**/\r
94RETURN_STATUS\r
95EFIAPI\r
96X2ApicInitialize (\r
97 IN UINTN ProcessorNumber,\r
98 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
99 IN VOID *ConfigData, OPTIONAL\r
100 IN BOOLEAN State\r
101 )\r
102{\r
6661abb6
JF
103 BOOLEAN *X2ApicEnabled;\r
104\r
105 ASSERT (ConfigData != NULL);\r
106 X2ApicEnabled = (BOOLEAN *) ConfigData;\r
107 if (X2ApicEnabled[ProcessorNumber]) {\r
108 PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (\r
109 ProcessorNumber,\r
110 Msr,\r
111 MSR_IA32_APIC_BASE,\r
112 MSR_IA32_APIC_BASE_REGISTER,\r
113 Bits.EXTD,\r
114 1\r
115 );\r
116 } else {\r
117 //\r
118 // Enable X2APIC mode only if X2APIC is not enabled,\r
119 // Needn't to disabe X2APIC mode again if X2APIC is not enabled\r
120 //\r
121 if (State) {\r
122 CPU_REGISTER_TABLE_WRITE_FIELD (\r
123 ProcessorNumber,\r
124 Msr,\r
125 MSR_IA32_APIC_BASE,\r
126 MSR_IA32_APIC_BASE_REGISTER,\r
127 Bits.EXTD,\r
128 1\r
129 );\r
130 }\r
131 }\r
80c4b236
JF
132 return RETURN_SUCCESS;\r
133}\r