TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeRegisterCpuFeaturesLib.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
10
12#include <Library/UefiLib.h>
13
14#include "RegisterCpuFeatures.h"
15
16CPU_FEATURES_DATA mCpuFeaturesData = { 0 };
17
25 VOID
26 )
27{
28 return &mCpuFeaturesData;
29}
30
38 VOID
39 )
40{
41 EFI_STATUS Status;
42 MP_SERVICES MpService;
43
44 //
45 // Get MP Services Protocol
46 //
47 Status = gBS->LocateProtocol (
48 &gEfiMpServiceProtocolGuid,
49 NULL,
50 (VOID **)&MpService.Protocol
51 );
52 ASSERT_EFI_ERROR (Status);
53
54 return MpService;
55}
56
66 IN CPU_FEATURES_DATA *CpuFeaturesData
67 )
68{
69 EFI_STATUS Status;
70 UINTN ProcessorIndex;
71 EFI_MP_SERVICES_PROTOCOL *MpServices;
72
73 MpServices = CpuFeaturesData->MpService.Protocol;
74 Status = MpServices->WhoAmI (MpServices, &ProcessorIndex);
75 ASSERT_EFI_ERROR (Status);
76 return ProcessorIndex;
77}
78
91 IN UINTN ProcessorNumber,
92 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
93 )
94{
95 EFI_STATUS Status;
96 EFI_MP_SERVICES_PROTOCOL *MpServices;
97 CPU_FEATURES_DATA *CpuFeaturesData;
98
99 CpuFeaturesData = GetCpuFeaturesData ();
100 MpServices = CpuFeaturesData->MpService.Protocol;
101
102 Status = MpServices->GetProcessorInfo (
103 MpServices,
104 ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY,
105 ProcessorInfoBuffer
106 );
107 return Status;
108}
109
118VOID
120 IN EFI_AP_PROCEDURE Procedure,
121 IN EFI_EVENT MpEvent
122 )
123{
124 EFI_STATUS Status;
125 EFI_MP_SERVICES_PROTOCOL *MpServices;
126 CPU_FEATURES_DATA *CpuFeaturesData;
127
128 CpuFeaturesData = GetCpuFeaturesData ();
129 MpServices = CpuFeaturesData->MpService.Protocol;
130
131 //
132 // Wakeup all APs
133 //
134 Status = MpServices->StartupAllAPs (
135 MpServices,
136 Procedure,
137 FALSE,
138 MpEvent,
139 0,
140 CpuFeaturesData,
141 NULL
142 );
143 ASSERT_EFI_ERROR (Status);
144}
145
151VOID
153 IN UINTN ProcessorNumber
154 )
155{
156 EFI_STATUS Status;
157 EFI_MP_SERVICES_PROTOCOL *MpServices;
158 CPU_FEATURES_DATA *CpuFeaturesData;
159
160 CpuFeaturesData = GetCpuFeaturesData ();
161 MpServices = CpuFeaturesData->MpService.Protocol;
162
163 //
164 // Wakeup all APs
165 //
166 Status = MpServices->SwitchBSP (
167 MpServices,
168 ProcessorNumber,
169 TRUE
170 );
171 ASSERT_EFI_ERROR (Status);
172}
173
184VOID
186 OUT UINTN *NumberOfCpus,
187 OUT UINTN *NumberOfEnabledProcessors
188 )
189{
190 EFI_STATUS Status;
191 EFI_MP_SERVICES_PROTOCOL *MpServices;
192 CPU_FEATURES_DATA *CpuFeaturesData;
193
194 CpuFeaturesData = GetCpuFeaturesData ();
195 MpServices = CpuFeaturesData->MpService.Protocol;
196
197 //
198 // Get the number of CPUs
199 //
200 Status = MpServices->GetNumberOfProcessors (
201 MpServices,
202 NumberOfCpus,
203 NumberOfEnabledProcessors
204 );
205 ASSERT_EFI_ERROR (Status);
206}
207
216VOID
217EFIAPI
219 VOID
220 )
221{
222 CPU_FEATURES_DATA *CpuFeaturesData;
223 UINTN OldBspNumber;
224 EFI_EVENT MpEvent;
225 EFI_STATUS Status;
226
227 CpuFeaturesData = GetCpuFeaturesData ();
228
229 OldBspNumber = GetProcessorIndex (CpuFeaturesData);
230 CpuFeaturesData->BspNumber = OldBspNumber;
231
232 //
233 //
234 // Initialize MpEvent to suppress incorrect compiler/analyzer warnings.
235 //
236 MpEvent = NULL;
237
238 if (CpuFeaturesData->NumberOfCpus > 1) {
239 Status = gBS->CreateEvent (
240 EVT_NOTIFY_WAIT,
241 TPL_CALLBACK,
243 NULL,
244 &MpEvent
245 );
246 ASSERT_EFI_ERROR (Status);
247
248 //
249 // Wakeup all APs for programming.
250 //
252 }
253
254 //
255 // Programming BSP
256 //
257 SetProcessorRegister (CpuFeaturesData);
258
259 if (CpuFeaturesData->NumberOfCpus > 1) {
260 //
261 // Wait all processors to finish the task.
262 //
263 do {
264 Status = gBS->CheckEvent (MpEvent);
265 } while (Status == EFI_NOT_READY);
266
267 ASSERT_EFI_ERROR (Status);
268 }
269
270 //
271 // Switch to new BSP if required
272 //
273 if (CpuFeaturesData->BspNumber != OldBspNumber) {
274 SwitchNewBsp (CpuFeaturesData->BspNumber);
275 }
276}
UINT64 UINTN
VOID EFIAPI SetProcessorRegister(IN OUT VOID *Buffer)
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)
#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
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
EFI_BOOT_SERVICES * gBS
VOID EFIAPI EfiEventEmptyFunction(IN EFI_EVENT Event, IN VOID *Context)
Definition: UefiLib.c:354