]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c
UefiCpuPkg/CpuCommonFeaturesLib: Register MSR base on scope Info.
[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
d28daadd
ED
105 //\r
106 // The scope of the MSR_IA32_APIC_BASE is core for below processor type, only program\r
107 // MSR_IA32_APIC_BASE for thread 0 in each core.\r
108 //\r
109 if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {\r
110 if (CpuInfo->ProcessorInfo.Location.Thread != 0) {\r
111 return RETURN_SUCCESS;\r
112 }\r
113 }\r
114\r
6661abb6
JF
115 ASSERT (ConfigData != NULL);\r
116 X2ApicEnabled = (BOOLEAN *) ConfigData;\r
117 if (X2ApicEnabled[ProcessorNumber]) {\r
118 PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (\r
119 ProcessorNumber,\r
120 Msr,\r
121 MSR_IA32_APIC_BASE,\r
122 MSR_IA32_APIC_BASE_REGISTER,\r
123 Bits.EXTD,\r
124 1\r
125 );\r
126 } else {\r
127 //\r
128 // Enable X2APIC mode only if X2APIC is not enabled,\r
129 // Needn't to disabe X2APIC mode again if X2APIC is not enabled\r
130 //\r
131 if (State) {\r
132 CPU_REGISTER_TABLE_WRITE_FIELD (\r
133 ProcessorNumber,\r
134 Msr,\r
135 MSR_IA32_APIC_BASE,\r
136 MSR_IA32_APIC_BASE_REGISTER,\r
137 Bits.EXTD,\r
138 1\r
139 );\r
140 }\r
141 }\r
80c4b236
JF
142 return RETURN_SUCCESS;\r
143}\r