2 CPU Register Table Library functions.
4 Copyright (c) 2016, 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.
17 #include <Library/HobLib.h>
18 #include <Library/PeiServicesLib.h>
19 #include <Library/PeiServicesTablePointerLib.h>
20 #include <Ppi/MpServices.h>
21 #include "RegisterCpuFeatures.h"
23 #define REGISTER_CPU_FEATURES_GUID \
25 0xa694c467, 0x697a, 0x446b, { 0xb9, 0x29, 0x5b, 0x14, 0xa0, 0xcf, 0x39, 0xf } \
28 EFI_GUID mRegisterCpuFeaturesHobGuid
= REGISTER_CPU_FEATURES_GUID
;
31 Worker function to get CPU_FEATURES_DATA pointer.
33 @return Pointer to CPU_FEATURES_DATA.
40 CPU_FEATURES_DATA
*CpuInitData
;
41 EFI_HOB_GUID_TYPE
*GuidHob
;
46 GuidHob
= GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid
);
47 if (GuidHob
!= NULL
) {
48 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
49 CpuInitData
= (CPU_FEATURES_DATA
*) (*(UINTN
*) DataInHob
);
50 ASSERT (CpuInitData
!= NULL
);
52 CpuInitData
= AllocateZeroPool (sizeof (CPU_FEATURES_DATA
));
53 ASSERT (CpuInitData
!= NULL
);
55 // Build location of CPU MP DATA buffer in HOB
57 Data64
= (UINT64
) (UINTN
) CpuInitData
;
59 &mRegisterCpuFeaturesHobGuid
,
69 Worker function to get MP PPI service pointer.
71 @return PEI PPI service pointer.
73 EFI_PEI_MP_SERVICES_PPI
*
79 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
82 // Get MP Services Protocol
84 Status
= PeiServicesLocatePpi (
85 &gEfiPeiMpServicesPpiGuid
,
90 ASSERT_EFI_ERROR (Status
);
95 Worker function to return processor index.
97 @return The processor index.
105 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
106 UINTN ProcessorIndex
;
108 CpuMpPpi
= GetMpPpi ();
110 Status
= CpuMpPpi
->WhoAmI(GetPeiServicesTablePointer (), CpuMpPpi
, &ProcessorIndex
);
111 ASSERT_EFI_ERROR (Status
);
112 return ProcessorIndex
;
116 Worker function to MP-related information on the requested processor at the
117 instant this call is made.
119 @param[in] ProcessorNumber The handle number of processor.
120 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
121 the requested processor is deposited.
123 @return Status of MpServices->GetProcessorInfo().
126 GetProcessorInformation (
127 IN UINTN ProcessorNumber
,
128 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
131 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
134 CpuMpPpi
= GetMpPpi ();
135 Status
= CpuMpPpi
->GetProcessorInfo (
136 GetPeiServicesTablePointer(),
145 Worker function to execute a caller provided function on all enabled APs.
147 @param[in] Procedure A pointer to the function to be run on
148 enabled APs of the system.
152 IN EFI_AP_PROCEDURE Procedure
,
157 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
158 CPU_FEATURES_DATA
*CpuFeaturesData
;
160 CpuFeaturesData
= GetCpuFeaturesData ();
163 // Get MP Services Protocol
165 Status
= PeiServicesLocatePpi (
166 &gEfiPeiMpServicesPpiGuid
,
171 ASSERT_EFI_ERROR (Status
);
174 // Wakeup all APs for data collection.
176 Status
= CpuMpPpi
->StartupAllAPs (
177 GetPeiServicesTablePointer (),
184 ASSERT_EFI_ERROR (Status
);
188 Worker function to switch the requested AP to be the BSP from that point onward.
190 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
194 IN UINTN ProcessorNumber
198 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
201 // Get MP Services Protocol
203 Status
= PeiServicesLocatePpi (
204 &gEfiPeiMpServicesPpiGuid
,
209 ASSERT_EFI_ERROR (Status
);
212 // Wakeup all APs for data collection.
214 Status
= CpuMpPpi
->SwitchBSP (
215 GetPeiServicesTablePointer (),
220 ASSERT_EFI_ERROR (Status
);
224 Worker function to retrieve the number of logical processor in the platform.
226 @param[out] NumberOfCpus Pointer to the total number of logical
227 processors in the system, including the BSP
229 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
230 processors that exist in system, including
234 GetNumberOfProcessor (
235 OUT UINTN
*NumberOfCpus
,
236 OUT UINTN
*NumberOfEnabledProcessors
240 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
243 // Get MP Services Protocol
245 Status
= PeiServicesLocatePpi (
246 &gEfiPeiMpServicesPpiGuid
,
251 ASSERT_EFI_ERROR (Status
);
254 // Get the number of CPUs
256 Status
= CpuMpPpi
->GetNumberOfProcessors (
257 GetPeiServicesTablePointer (),
260 NumberOfEnabledProcessors
262 ASSERT_EFI_ERROR (Status
);
266 Performs CPU features Initialization.
268 This service will invoke MP service to perform CPU features
269 initialization on BSP/APs per user configuration.
271 @note This service could be called by BSP only.
275 CpuFeaturesInitialize (
279 CPU_FEATURES_DATA
*CpuFeaturesData
;
282 CpuFeaturesData
= GetCpuFeaturesData ();
284 OldBspNumber
= GetProcessorIndex();
285 CpuFeaturesData
->BspNumber
= OldBspNumber
;
288 // Known limitation: In PEI phase, CpuFeatures driver not
289 // support async mode execute tasks. So semaphore type
290 // register can't been used for this instance, must use
291 // DXE type instance.
295 // Wakeup all APs for programming.
297 StartupAPsWorker (SetProcessorRegister
, NULL
);
301 SetProcessorRegister (CpuFeaturesData
);
304 // Switch to new BSP if required
306 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
307 SwitchNewBsp (CpuFeaturesData
->BspNumber
);