2 CPU Register Table Library functions.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/HobLib.h>
12 #include <Library/PeiServicesLib.h>
13 #include <Library/PeiServicesTablePointerLib.h>
14 #include <Ppi/MpServices.h>
15 #include "RegisterCpuFeatures.h"
17 #define REGISTER_CPU_FEATURES_GUID \
19 0xa694c467, 0x697a, 0x446b, { 0xb9, 0x29, 0x5b, 0x14, 0xa0, 0xcf, 0x39, 0xf } \
22 EFI_GUID mRegisterCpuFeaturesHobGuid
= REGISTER_CPU_FEATURES_GUID
;
25 Worker function to get CPU_FEATURES_DATA pointer.
27 @return Pointer to CPU_FEATURES_DATA.
34 CPU_FEATURES_DATA
*CpuInitData
;
35 EFI_HOB_GUID_TYPE
*GuidHob
;
40 GuidHob
= GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid
);
41 if (GuidHob
!= NULL
) {
42 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
43 CpuInitData
= (CPU_FEATURES_DATA
*) (*(UINTN
*) DataInHob
);
44 ASSERT (CpuInitData
!= NULL
);
46 CpuInitData
= AllocateZeroPool (sizeof (CPU_FEATURES_DATA
));
47 ASSERT (CpuInitData
!= NULL
);
49 // Build location of CPU MP DATA buffer in HOB
51 Data64
= (UINT64
) (UINTN
) CpuInitData
;
53 &mRegisterCpuFeaturesHobGuid
,
63 Worker function to get MP PPI service pointer.
65 @return MP_SERVICES variable.
73 MP_SERVICES MpService
;
76 // Get MP Services Protocol
78 Status
= PeiServicesLocatePpi (
79 &gEfiPeiMpServicesPpiGuid
,
82 (VOID
**)&MpService
.Ppi
84 ASSERT_EFI_ERROR (Status
);
89 Worker function to return processor index.
91 @param CpuFeaturesData Cpu Feature Data structure.
93 @return The processor index.
97 IN CPU_FEATURES_DATA
*CpuFeaturesData
101 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
102 UINTN ProcessorIndex
;
104 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
107 // For two reasons which use NULL for WhoAmI:
108 // 1. This function will be called by APs and AP should not use PeiServices Table
109 // 2. Check WhoAmI implementation, this parameter will not be used.
111 Status
= CpuMpPpi
->WhoAmI(NULL
, CpuMpPpi
, &ProcessorIndex
);
112 ASSERT_EFI_ERROR (Status
);
113 return ProcessorIndex
;
117 Worker function to MP-related information on the requested processor at the
118 instant this call is made.
120 @param[in] ProcessorNumber The handle number of processor.
121 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
122 the requested processor is deposited.
124 @return Status of MpServices->GetProcessorInfo().
127 GetProcessorInformation (
128 IN UINTN ProcessorNumber
,
129 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
132 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
134 CPU_FEATURES_DATA
*CpuFeaturesData
;
136 CpuFeaturesData
= GetCpuFeaturesData ();
137 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
139 Status
= CpuMpPpi
->GetProcessorInfo (
140 GetPeiServicesTablePointer(),
149 Worker function to execute a caller provided function on all enabled APs.
151 @param[in] Procedure A pointer to the function to be run on
152 enabled APs of the system.
153 @param[in] MpEvent The Event used to sync the result.
158 IN EFI_AP_PROCEDURE Procedure
,
163 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
164 CPU_FEATURES_DATA
*CpuFeaturesData
;
166 CpuFeaturesData
= GetCpuFeaturesData ();
167 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
170 // Wakeup all APs for data collection.
172 Status
= CpuMpPpi
->StartupAllAPs (
173 GetPeiServicesTablePointer (),
180 ASSERT_EFI_ERROR (Status
);
184 Worker function to switch the requested AP to be the BSP from that point onward.
186 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
190 IN UINTN ProcessorNumber
194 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
195 CPU_FEATURES_DATA
*CpuFeaturesData
;
197 CpuFeaturesData
= GetCpuFeaturesData ();
198 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
201 // Wakeup all APs for data collection.
203 Status
= CpuMpPpi
->SwitchBSP (
204 GetPeiServicesTablePointer (),
209 ASSERT_EFI_ERROR (Status
);
213 Worker function to retrieve the number of logical processor in the platform.
215 @param[out] NumberOfCpus Pointer to the total number of logical
216 processors in the system, including the BSP
218 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
219 processors that exist in system, including
223 GetNumberOfProcessor (
224 OUT UINTN
*NumberOfCpus
,
225 OUT UINTN
*NumberOfEnabledProcessors
229 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
230 CPU_FEATURES_DATA
*CpuFeaturesData
;
232 CpuFeaturesData
= GetCpuFeaturesData ();
233 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
236 // Get the number of CPUs
238 Status
= CpuMpPpi
->GetNumberOfProcessors (
239 GetPeiServicesTablePointer (),
242 NumberOfEnabledProcessors
244 ASSERT_EFI_ERROR (Status
);
248 Performs CPU features Initialization.
250 This service will invoke MP service to perform CPU features
251 initialization on BSP/APs per user configuration.
253 @note This service could be called by BSP only.
257 CpuFeaturesInitialize (
261 CPU_FEATURES_DATA
*CpuFeaturesData
;
264 CpuFeaturesData
= GetCpuFeaturesData ();
266 OldBspNumber
= GetProcessorIndex (CpuFeaturesData
);
267 CpuFeaturesData
->BspNumber
= OldBspNumber
;
270 // Known limitation: In PEI phase, CpuFeatures driver not
271 // support async mode execute tasks. So semaphore type
272 // register can't been used for this instance, must use
273 // DXE type instance.
277 // Wakeup all APs for programming.
279 StartupAPsWorker (SetProcessorRegister
, NULL
);
283 SetProcessorRegister (CpuFeaturesData
);
286 // Switch to new BSP if required
288 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
289 SwitchNewBsp (CpuFeaturesData
->BspNumber
);