TianoCore EDK2 master
Loading...
Searching...
No Matches
PeiRegisterCpuFeaturesLib.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10
11#include <Library/HobLib.h>
14#include <Ppi/MpServices2.h>
15
16#include "RegisterCpuFeatures.h"
17
18#define REGISTER_CPU_FEATURES_GUID \
19 { \
20 0xa694c467, 0x697a, 0x446b, { 0xb9, 0x29, 0x5b, 0x14, 0xa0, 0xcf, 0x39, 0xf } \
21 }
22
23EFI_GUID mRegisterCpuFeaturesHobGuid = REGISTER_CPU_FEATURES_GUID;
24
32 VOID
33 )
34{
35 CPU_FEATURES_DATA *CpuInitData;
36 EFI_HOB_GUID_TYPE *GuidHob;
37 VOID *DataInHob;
38 UINT64 Data64;
39
40 CpuInitData = NULL;
41 GuidHob = GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid);
42 if (GuidHob != NULL) {
43 DataInHob = GET_GUID_HOB_DATA (GuidHob);
44 CpuInitData = (CPU_FEATURES_DATA *)(*(UINTN *)DataInHob);
45 ASSERT (CpuInitData != NULL);
46 } else {
47 CpuInitData = AllocateZeroPool (sizeof (CPU_FEATURES_DATA));
48 ASSERT (CpuInitData != NULL);
49 //
50 // Build location of CPU MP DATA buffer in HOB
51 //
52 Data64 = (UINT64)(UINTN)CpuInitData;
54 &mRegisterCpuFeaturesHobGuid,
55 (VOID *)&Data64,
56 sizeof (UINT64)
57 );
58 }
59
60 return CpuInitData;
61}
62
70 VOID
71 )
72{
73 EFI_STATUS Status;
74 MP_SERVICES MpService;
75
76 //
77 // Get MP Services2 Ppi
78 //
79 Status = PeiServicesLocatePpi (
80 &gEdkiiPeiMpServices2PpiGuid,
81 0,
82 NULL,
83 (VOID **)&MpService.Ppi
84 );
85 ASSERT_EFI_ERROR (Status);
86 return MpService;
87}
88
98 IN CPU_FEATURES_DATA *CpuFeaturesData
99 )
100{
101 EFI_STATUS Status;
103 UINTN ProcessorIndex;
104
105 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
106
107 //
108 // For two reasons which use NULL for WhoAmI:
109 // 1. This function will be called by APs and AP should not use PeiServices Table
110 // 2. Check WhoAmI implementation, this parameter will not be used.
111 //
112 Status = CpuMp2Ppi->WhoAmI (CpuMp2Ppi, &ProcessorIndex);
113 ASSERT_EFI_ERROR (Status);
114 return ProcessorIndex;
115}
116
129 IN UINTN ProcessorNumber,
130 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
131 )
132{
134 EFI_STATUS Status;
135 CPU_FEATURES_DATA *CpuFeaturesData;
136
137 CpuFeaturesData = GetCpuFeaturesData ();
138 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
139
140 Status = CpuMp2Ppi->GetProcessorInfo (
141 CpuMp2Ppi,
142 ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY,
143 ProcessorInfoBuffer
144 );
145 return Status;
146}
147
156VOID
158 IN EFI_AP_PROCEDURE Procedure,
159 IN EFI_EVENT MpEvent
160 )
161{
162 EFI_STATUS Status;
164 CPU_FEATURES_DATA *CpuFeaturesData;
165
166 CpuFeaturesData = GetCpuFeaturesData ();
167 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
168
169 //
170 // Wakeup all APs for data collection.
171 //
172 Status = CpuMp2Ppi->StartupAllAPs (
173 CpuMp2Ppi,
174 Procedure,
175 FALSE,
176 0,
177 CpuFeaturesData
178 );
179 ASSERT_EFI_ERROR (Status);
180}
181
189VOID
191 IN EFI_AP_PROCEDURE Procedure
192 )
193{
194 EFI_STATUS Status;
196 CPU_FEATURES_DATA *CpuFeaturesData;
197
198 CpuFeaturesData = GetCpuFeaturesData ();
199
200 //
201 // Get MP Services2 Ppi
202 //
203 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
204 Status = CpuMp2Ppi->StartupAllCPUs (
205 CpuMp2Ppi,
206 Procedure,
207 0,
208 CpuFeaturesData
209 );
210 ASSERT_EFI_ERROR (Status);
211}
212
218VOID
220 IN UINTN ProcessorNumber
221 )
222{
223 EFI_STATUS Status;
225 CPU_FEATURES_DATA *CpuFeaturesData;
226
227 CpuFeaturesData = GetCpuFeaturesData ();
228 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
229
230 //
231 // Wakeup all APs for data collection.
232 //
233 Status = CpuMp2Ppi->SwitchBSP (
234 CpuMp2Ppi,
235 ProcessorNumber,
236 TRUE
237 );
238 ASSERT_EFI_ERROR (Status);
239}
240
251VOID
253 OUT UINTN *NumberOfCpus,
254 OUT UINTN *NumberOfEnabledProcessors
255 )
256{
257 EFI_STATUS Status;
259 CPU_FEATURES_DATA *CpuFeaturesData;
260
261 CpuFeaturesData = GetCpuFeaturesData ();
262 CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
263
264 //
265 // Get the number of CPUs
266 //
267 Status = CpuMp2Ppi->GetNumberOfProcessors (
268 CpuMp2Ppi,
269 NumberOfCpus,
270 NumberOfEnabledProcessors
271 );
272 ASSERT_EFI_ERROR (Status);
273}
274
283VOID
284EFIAPI
286 VOID
287 )
288{
289 CPU_FEATURES_DATA *CpuFeaturesData;
290 UINTN OldBspNumber;
291
292 CpuFeaturesData = GetCpuFeaturesData ();
293
294 OldBspNumber = GetProcessorIndex (CpuFeaturesData);
295 CpuFeaturesData->BspNumber = OldBspNumber;
296
297 //
298 // Start to program register for all CPUs.
299 //
301
302 //
303 // Switch to new BSP if required
304 //
305 if (CpuFeaturesData->BspNumber != OldBspNumber) {
306 SwitchNewBsp (CpuFeaturesData->BspNumber);
307 }
308}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID EFIAPI SetProcessorRegister(IN OUT VOID *Buffer)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define CPU_V2_EXTENDED_TOPOLOGY
Definition: MpService.h:53
UINTN GetProcessorIndex(IN CPU_FEATURES_DATA *CpuFeaturesData)
CPU_FEATURES_DATA * GetCpuFeaturesData(VOID)
VOID SwitchNewBsp(IN UINTN ProcessorNumber)
VOID GetNumberOfProcessor(OUT UINTN *NumberOfCpus, OUT UINTN *NumberOfEnabledProcessors)
EFI_STATUS GetProcessorInformation(IN UINTN ProcessorNumber, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer)
VOID EFIAPI CpuFeaturesInitialize(VOID)
VOID StartupAllAPsWorker(IN EFI_AP_PROCEDURE Procedure, IN EFI_EVENT MpEvent)
MP_SERVICES GetMpService(VOID)
VOID StartupAllCPUsWorker(IN EFI_AP_PROCEDURE Procedure)
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
Definition: PiMultiPhase.h:198
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
Definition: Base.h:213