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 MP_SERVICES variable.
79 MP_SERVICES MpService
;
82 // Get MP Services Protocol
84 Status
= PeiServicesLocatePpi (
85 &gEfiPeiMpServicesPpiGuid
,
88 (VOID
**)&MpService
.Ppi
90 ASSERT_EFI_ERROR (Status
);
95 Worker function to return processor index.
97 @param CpuFeaturesData Cpu Feature Data structure.
99 @return The processor index.
103 IN CPU_FEATURES_DATA
*CpuFeaturesData
107 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
108 UINTN ProcessorIndex
;
110 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
113 // For two reasons which use NULL for WhoAmI:
114 // 1. This function will be called by APs and AP should not use PeiServices Table
115 // 2. Check WhoAmI implementation, this parameter will not be used.
117 Status
= CpuMpPpi
->WhoAmI(NULL
, CpuMpPpi
, &ProcessorIndex
);
118 ASSERT_EFI_ERROR (Status
);
119 return ProcessorIndex
;
123 Worker function to MP-related information on the requested processor at the
124 instant this call is made.
126 @param[in] ProcessorNumber The handle number of processor.
127 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
128 the requested processor is deposited.
130 @return Status of MpServices->GetProcessorInfo().
133 GetProcessorInformation (
134 IN UINTN ProcessorNumber
,
135 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
138 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
140 CPU_FEATURES_DATA
*CpuFeaturesData
;
142 CpuFeaturesData
= GetCpuFeaturesData ();
143 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
145 Status
= CpuMpPpi
->GetProcessorInfo (
146 GetPeiServicesTablePointer(),
155 Worker function to execute a caller provided function on all enabled APs.
157 @param[in] Procedure A pointer to the function to be run on
158 enabled APs of the system.
159 @param[in] MpEvent The Event used to sync the result.
164 IN EFI_AP_PROCEDURE Procedure
,
169 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
170 CPU_FEATURES_DATA
*CpuFeaturesData
;
172 CpuFeaturesData
= GetCpuFeaturesData ();
173 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
176 // Wakeup all APs for data collection.
178 Status
= CpuMpPpi
->StartupAllAPs (
179 GetPeiServicesTablePointer (),
186 ASSERT_EFI_ERROR (Status
);
190 Worker function to switch the requested AP to be the BSP from that point onward.
192 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
196 IN UINTN ProcessorNumber
200 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
201 CPU_FEATURES_DATA
*CpuFeaturesData
;
203 CpuFeaturesData
= GetCpuFeaturesData ();
204 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
207 // Wakeup all APs for data collection.
209 Status
= CpuMpPpi
->SwitchBSP (
210 GetPeiServicesTablePointer (),
215 ASSERT_EFI_ERROR (Status
);
219 Worker function to retrieve the number of logical processor in the platform.
221 @param[out] NumberOfCpus Pointer to the total number of logical
222 processors in the system, including the BSP
224 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
225 processors that exist in system, including
229 GetNumberOfProcessor (
230 OUT UINTN
*NumberOfCpus
,
231 OUT UINTN
*NumberOfEnabledProcessors
235 EFI_PEI_MP_SERVICES_PPI
*CpuMpPpi
;
236 CPU_FEATURES_DATA
*CpuFeaturesData
;
238 CpuFeaturesData
= GetCpuFeaturesData ();
239 CpuMpPpi
= CpuFeaturesData
->MpService
.Ppi
;
242 // Get the number of CPUs
244 Status
= CpuMpPpi
->GetNumberOfProcessors (
245 GetPeiServicesTablePointer (),
248 NumberOfEnabledProcessors
250 ASSERT_EFI_ERROR (Status
);
254 Performs CPU features Initialization.
256 This service will invoke MP service to perform CPU features
257 initialization on BSP/APs per user configuration.
259 @note This service could be called by BSP only.
263 CpuFeaturesInitialize (
267 CPU_FEATURES_DATA
*CpuFeaturesData
;
270 CpuFeaturesData
= GetCpuFeaturesData ();
272 OldBspNumber
= GetProcessorIndex (CpuFeaturesData
);
273 CpuFeaturesData
->BspNumber
= OldBspNumber
;
276 // Known limitation: In PEI phase, CpuFeatures driver not
277 // support async mode execute tasks. So semaphore type
278 // register can't been used for this instance, must use
279 // DXE type instance.
283 // Wakeup all APs for programming.
285 StartupAPsWorker (SetProcessorRegister
, NULL
);
289 SetProcessorRegister (CpuFeaturesData
);
292 // Switch to new BSP if required
294 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
295 SwitchNewBsp (CpuFeaturesData
->BspNumber
);