4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuCommonFeatures.h"
12 Prepares for the data used by CPU feature detection and initialization.
14 @param[in] NumberOfProcessors The number of CPUs in the platform.
16 @return Pointer to a buffer of CPU related configuration data.
18 @note This service could be called by BSP only.
23 IN UINTN NumberOfProcessors
28 ConfigData
= AllocateZeroPool (sizeof (BOOLEAN
) * NumberOfProcessors
);
29 ASSERT (ConfigData
!= NULL
);
34 Detects if X2Apci feature supported on current processor.
36 Detect if X2Apci has been already enabled.
38 @param[in] ProcessorNumber The index of the CPU executing this function.
39 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
40 structure for the CPU executing this function.
41 @param[in] ConfigData A pointer to the configuration buffer returned
42 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
43 CPU_FEATURE_GET_CONFIG_DATA was not provided in
46 @retval TRUE X2Apci feature is supported.
47 @retval FALSE X2Apci feature is not supported.
49 @note This service could be called by BSP/APs.
54 IN UINTN ProcessorNumber
,
55 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
56 IN VOID
*ConfigData OPTIONAL
59 BOOLEAN
*X2ApicEnabled
;
61 ASSERT (ConfigData
!= NULL
);
62 X2ApicEnabled
= (BOOLEAN
*) ConfigData
;
64 // *ConfigData indicates if X2APIC enabled on current processor
66 X2ApicEnabled
[ProcessorNumber
] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC
) ? TRUE
: FALSE
;
68 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.x2APIC
== 1);
72 Initializes X2Apci 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 X2Apci feature must be enabled.
82 If FALSE, then the X2Apci feature must be disabled.
84 @retval RETURN_SUCCESS X2Apci 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 BOOLEAN
*X2ApicEnabled
;
100 // The scope of the MSR_IA32_APIC_BASE is core for below processor type, only program
101 // MSR_IA32_APIC_BASE for thread 0 in each core.
103 if (IS_SILVERMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
104 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
105 return RETURN_SUCCESS
;
109 ASSERT (ConfigData
!= NULL
);
110 X2ApicEnabled
= (BOOLEAN
*) ConfigData
;
111 if (X2ApicEnabled
[ProcessorNumber
]) {
112 PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
116 MSR_IA32_APIC_BASE_REGISTER
,
122 // Enable X2APIC mode only if X2APIC is not enabled,
123 // Needn't to disabe X2APIC mode again if X2APIC is not enabled
126 CPU_REGISTER_TABLE_WRITE_FIELD (
130 MSR_IA32_APIC_BASE_REGISTER
,
136 return RETURN_SUCCESS
;