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 (BOOLEAN
) * NumberOfProcessors
);
35 ASSERT (ConfigData
!= NULL
);
40 Detects if X2Apci feature supported on current processor.
42 Detect if X2Apci has been already enabled.
44 @param[in] ProcessorNumber The index of the CPU executing this function.
45 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
46 structure for the CPU executing this function.
47 @param[in] ConfigData A pointer to the configuration buffer returned
48 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
49 CPU_FEATURE_GET_CONFIG_DATA was not provided in
52 @retval TRUE X2Apci feature is supported.
53 @retval FALSE X2Apci feature is not supported.
55 @note This service could be called by BSP/APs.
60 IN UINTN ProcessorNumber
,
61 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
62 IN VOID
*ConfigData OPTIONAL
65 BOOLEAN
*X2ApicEnabled
;
67 ASSERT (ConfigData
!= NULL
);
68 X2ApicEnabled
= (BOOLEAN
*) ConfigData
;
70 // *ConfigData indicates if X2APIC enabled on current processor
72 X2ApicEnabled
[ProcessorNumber
] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC
) ? TRUE
: FALSE
;
74 return (CpuInfo
->CpuIdVersionInfoEcx
.Bits
.x2APIC
== 1);
78 Initializes X2Apci feature to specific state.
80 @param[in] ProcessorNumber The index of the CPU executing this function.
81 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
82 structure for the CPU executing this function.
83 @param[in] ConfigData A pointer to the configuration buffer returned
84 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
85 CPU_FEATURE_GET_CONFIG_DATA was not provided in
87 @param[in] State If TRUE, then the X2Apci feature must be enabled.
88 If FALSE, then the X2Apci feature must be disabled.
90 @retval RETURN_SUCCESS X2Apci feature is initialized.
92 @note This service could be called by BSP only.
97 IN UINTN ProcessorNumber
,
98 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
99 IN VOID
*ConfigData
, OPTIONAL
103 BOOLEAN
*X2ApicEnabled
;
105 ASSERT (ConfigData
!= NULL
);
106 X2ApicEnabled
= (BOOLEAN
*) ConfigData
;
107 if (X2ApicEnabled
[ProcessorNumber
]) {
108 PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
112 MSR_IA32_APIC_BASE_REGISTER
,
118 // Enable X2APIC mode only if X2APIC is not enabled,
119 // Needn't to disabe X2APIC mode again if X2APIC is not enabled
122 CPU_REGISTER_TABLE_WRITE_FIELD (
126 MSR_IA32_APIC_BASE_REGISTER
,
132 return RETURN_SUCCESS
;