2 Multiple-Processor initialization Library for uniprocessor platforms.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Ppi/SecPlatformInformation.h>
11 #include <Protocol/MpService.h>
12 #include <Library/DebugLib.h>
13 #include <Library/LocalApicLib.h>
14 #include <Library/HobLib.h>
17 MP Initialize Library initialization.
19 This service will allocate AP reset vector and wakeup all APs to do APs
22 This service must be invoked before all other MP Initialize Library
25 @retval EFI_SUCCESS MP initialization succeeds.
26 @retval Others MP initialization fails.
36 // Enable the local APIC for Virtual Wire Mode.
38 ProgramVirtualWireMode ();
44 Retrieves the number of logical processor in the platform and the number of
45 those logical processors that are enabled on this boot. This service may only
46 be called from the BSP.
48 @param[out] NumberOfProcessors Pointer to the total number of logical
49 processors in the system, including the BSP
51 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
52 processors that exist in system, including
55 @retval EFI_SUCCESS The number of logical processors and enabled
56 logical processors was retrieved.
57 @retval EFI_DEVICE_ERROR The calling processor is an AP.
58 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
60 @retval EFI_NOT_READY MP Initialize Library is not initialized.
65 MpInitLibGetNumberOfProcessors (
66 OUT UINTN
*NumberOfProcessors OPTIONAL
,
67 OUT UINTN
*NumberOfEnabledProcessors OPTIONAL
70 *NumberOfProcessors
= 1;
71 *NumberOfEnabledProcessors
= 1;
76 Gets detailed MP-related information on the requested processor at the
77 instant this call is made. This service may only be called from the BSP.
79 @param[in] ProcessorNumber The handle number of processor.
80 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
81 the requested processor is deposited.
82 @param[out] HealthData Return processor health data.
84 @retval EFI_SUCCESS Processor information was returned.
85 @retval EFI_DEVICE_ERROR The calling processor is an AP.
86 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
87 @retval EFI_NOT_FOUND The processor with the handle specified by
88 ProcessorNumber does not exist in the platform.
89 @retval EFI_NOT_READY MP Initialize Library is not initialized.
94 MpInitLibGetProcessorInfo (
95 IN UINTN ProcessorNumber
,
96 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
,
97 OUT EFI_HEALTH_FLAGS
*HealthData OPTIONAL
100 EFI_HOB_GUID_TYPE
*GuidHob
;
101 EFI_SEC_PLATFORM_INFORMATION_RECORD
*SecPlatformInformation
;
103 if (ProcessorInfoBuffer
== NULL
) {
104 return EFI_INVALID_PARAMETER
;
107 if (ProcessorNumber
!= 0) {
108 return EFI_NOT_FOUND
;
111 ProcessorInfoBuffer
->ProcessorId
= 0;
112 ProcessorInfoBuffer
->StatusFlag
= PROCESSOR_AS_BSP_BIT
|
113 PROCESSOR_ENABLED_BIT
|
114 PROCESSOR_HEALTH_STATUS_BIT
;
115 ProcessorInfoBuffer
->Location
.Package
= 0;
116 ProcessorInfoBuffer
->Location
.Core
= 0;
117 ProcessorInfoBuffer
->Location
.Thread
= 0;
118 if (HealthData
!= NULL
) {
119 GuidHob
= GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid
);
120 if (GuidHob
!= NULL
) {
121 SecPlatformInformation
= GET_GUID_HOB_DATA (GuidHob
);
122 HealthData
->Uint32
= SecPlatformInformation
->IA32HealthFlags
.Uint32
;
124 DEBUG ((DEBUG_INFO
, "Does not find any HOB stored CPU BIST information!\n"));
125 HealthData
->Uint32
= 0;
133 This service executes a caller provided function on all enabled APs.
135 @param[in] Procedure A pointer to the function to be run on
136 enabled APs of the system. See type
138 @param[in] SingleThread If TRUE, then all the enabled APs execute
139 the function specified by Procedure one by
140 one, in ascending order of processor handle
141 number. If FALSE, then all the enabled APs
142 execute the function specified by Procedure
144 @param[in] WaitEvent The event created by the caller with CreateEvent()
145 service. If it is NULL, then execute in
146 blocking mode. BSP waits until all APs finish
147 or TimeoutInMicroSeconds expires. If it's
148 not NULL, then execute in non-blocking mode.
149 BSP requests the function specified by
150 Procedure to be started on all the enabled
151 APs, and go on executing immediately. If
152 all return from Procedure, or TimeoutInMicroSeconds
153 expires, this event is signaled. The BSP
154 can use the CheckEvent() or WaitForEvent()
155 services to check the state of event. Type
156 EFI_EVENT is defined in CreateEvent() in
157 the Unified Extensible Firmware Interface
159 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
160 APs to return from Procedure, either for
161 blocking or non-blocking mode. Zero means
162 infinity. If the timeout expires before
163 all APs return from Procedure, then Procedure
164 on the failed APs is terminated. All enabled
165 APs are available for next function assigned
166 by MpInitLibStartupAllAPs() or
167 MPInitLibStartupThisAP().
168 If the timeout expires in blocking mode,
169 BSP returns EFI_TIMEOUT. If the timeout
170 expires in non-blocking mode, WaitEvent
171 is signaled with SignalEvent().
172 @param[in] ProcedureArgument The parameter passed into Procedure for
174 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
175 if all APs finish successfully, then its
176 content is set to NULL. If not all APs
177 finish before timeout expires, then its
178 content is set to address of the buffer
179 holding handle numbers of the failed APs.
180 The buffer is allocated by MP Initialization
181 library, and it's the caller's responsibility to
182 free the buffer with FreePool() service.
183 In blocking mode, it is ready for consumption
184 when the call returns. In non-blocking mode,
185 it is ready when WaitEvent is signaled. The
186 list of failed CPU is terminated by
189 @retval EFI_SUCCESS In blocking mode, all APs have finished before
191 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
193 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
194 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
196 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
198 @retval EFI_DEVICE_ERROR Caller processor is AP.
199 @retval EFI_NOT_STARTED No enabled APs exist in the system.
200 @retval EFI_NOT_READY Any enabled APs are busy.
201 @retval EFI_NOT_READY MP Initialize Library is not initialized.
202 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
203 all enabled APs have finished.
204 @retval EFI_INVALID_PARAMETER Procedure is NULL.
209 MpInitLibStartupAllAPs (
210 IN EFI_AP_PROCEDURE Procedure
,
211 IN BOOLEAN SingleThread
,
212 IN EFI_EVENT WaitEvent OPTIONAL
,
213 IN UINTN TimeoutInMicroseconds
,
214 IN VOID
*ProcedureArgument OPTIONAL
,
215 OUT UINTN
**FailedCpuList OPTIONAL
218 return EFI_NOT_STARTED
;
222 This service lets the caller get one enabled AP to execute a caller-provided
225 @param[in] Procedure A pointer to the function to be run on the
226 designated AP of the system. See type
228 @param[in] ProcessorNumber The handle number of the AP. The range is
229 from 0 to the total number of logical
230 processors minus 1. The total number of
231 logical processors can be retrieved by
232 MpInitLibGetNumberOfProcessors().
233 @param[in] WaitEvent The event created by the caller with CreateEvent()
234 service. If it is NULL, then execute in
235 blocking mode. BSP waits until this AP finish
236 or TimeoutInMicroSeconds expires. If it's
237 not NULL, then execute in non-blocking mode.
238 BSP requests the function specified by
239 Procedure to be started on this AP,
240 and go on executing immediately. If this AP
241 return from Procedure or TimeoutInMicroSeconds
242 expires, this event is signaled. The BSP
243 can use the CheckEvent() or WaitForEvent()
244 services to check the state of event. Type
245 EFI_EVENT is defined in CreateEvent() in
246 the Unified Extensible Firmware Interface
248 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
249 this AP to finish this Procedure, either for
250 blocking or non-blocking mode. Zero means
251 infinity. If the timeout expires before
252 this AP returns from Procedure, then Procedure
253 on the AP is terminated. The
254 AP is available for next function assigned
255 by MpInitLibStartupAllAPs() or
256 MpInitLibStartupThisAP().
257 If the timeout expires in blocking mode,
258 BSP returns EFI_TIMEOUT. If the timeout
259 expires in non-blocking mode, WaitEvent
260 is signaled with SignalEvent().
261 @param[in] ProcedureArgument The parameter passed into Procedure on the
263 @param[out] Finished If NULL, this parameter is ignored. In
264 blocking mode, this parameter is ignored.
265 In non-blocking mode, if AP returns from
266 Procedure before the timeout expires, its
267 content is set to TRUE. Otherwise, the
268 value is set to FALSE. The caller can
269 determine if the AP returned from Procedure
270 by evaluating this value.
272 @retval EFI_SUCCESS In blocking mode, specified AP finished before
274 @retval EFI_SUCCESS In non-blocking mode, the function has been
275 dispatched to specified AP.
276 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
277 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
279 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
281 @retval EFI_DEVICE_ERROR The calling processor is an AP.
282 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
283 the specified AP has finished.
284 @retval EFI_NOT_READY The specified AP is busy.
285 @retval EFI_NOT_READY MP Initialize Library is not initialized.
286 @retval EFI_NOT_FOUND The processor with the handle specified by
287 ProcessorNumber does not exist.
288 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
289 @retval EFI_INVALID_PARAMETER Procedure is NULL.
294 MpInitLibStartupThisAP (
295 IN EFI_AP_PROCEDURE Procedure
,
296 IN UINTN ProcessorNumber
,
297 IN EFI_EVENT WaitEvent OPTIONAL
,
298 IN UINTN TimeoutInMicroseconds
,
299 IN VOID
*ProcedureArgument OPTIONAL
,
300 OUT BOOLEAN
*Finished OPTIONAL
303 return EFI_INVALID_PARAMETER
;
307 This service switches the requested AP to be the BSP from that point onward.
308 This service changes the BSP for all purposes. This call can only be performed
311 @param[in] ProcessorNumber The handle number of AP that is to become the new
312 BSP. The range is from 0 to the total number of
313 logical processors minus 1. The total number of
314 logical processors can be retrieved by
315 MpInitLibGetNumberOfProcessors().
316 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
317 enabled AP. Otherwise, it will be disabled.
319 @retval EFI_SUCCESS BSP successfully switched.
320 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
321 this service returning.
322 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
323 @retval EFI_DEVICE_ERROR The calling processor is an AP.
324 @retval EFI_NOT_FOUND The processor with the handle specified by
325 ProcessorNumber does not exist.
326 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
328 @retval EFI_NOT_READY The specified AP is busy.
329 @retval EFI_NOT_READY MP Initialize Library is not initialized.
335 IN UINTN ProcessorNumber
,
336 IN BOOLEAN EnableOldBSP
339 return EFI_UNSUPPORTED
;
343 This service lets the caller enable or disable an AP from this point onward.
344 This service may only be called from the BSP.
346 @param[in] ProcessorNumber The handle number of AP.
347 The range is from 0 to the total number of
348 logical processors minus 1. The total number of
349 logical processors can be retrieved by
350 MpInitLibGetNumberOfProcessors().
351 @param[in] EnableAP Specifies the new state for the processor for
352 enabled, FALSE for disabled.
353 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
354 the new health status of the AP. This flag
355 corresponds to StatusFlag defined in
356 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
357 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
358 bits are ignored. If it is NULL, this parameter
361 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
362 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
363 prior to this service returning.
364 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
365 @retval EFI_DEVICE_ERROR The calling processor is an AP.
366 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
368 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
369 @retval EFI_NOT_READY MP Initialize Library is not initialized.
374 MpInitLibEnableDisableAP (
375 IN UINTN ProcessorNumber
,
377 IN UINT32
*HealthFlag OPTIONAL
380 return EFI_UNSUPPORTED
;
384 This return the handle number for the calling processor. This service may be
385 called from the BSP and APs.
387 @param[out] ProcessorNumber Pointer to the handle number of AP.
388 The range is from 0 to the total number of
389 logical processors minus 1. The total number of
390 logical processors can be retrieved by
391 MpInitLibGetNumberOfProcessors().
393 @retval EFI_SUCCESS The current processor handle number was returned
395 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
396 @retval EFI_NOT_READY MP Initialize Library is not initialized.
402 OUT UINTN
*ProcessorNumber
405 if (ProcessorNumber
== NULL
) {
406 return EFI_INVALID_PARAMETER
;
409 *ProcessorNumber
= 0;
414 This service executes a caller provided function on all enabled CPUs.
416 @param[in] Procedure A pointer to the function to be run on
417 enabled APs of the system. See type
419 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
420 APs to return from Procedure, either for
421 blocking or non-blocking mode. Zero means
422 infinity. TimeoutInMicroseconds is ignored
424 @param[in] ProcedureArgument The parameter passed into Procedure for
427 @retval EFI_SUCCESS CPU have finished the procedure.
428 @retval EFI_INVALID_PARAMETER Procedure is NULL.
433 MpInitLibStartupAllCPUs (
434 IN EFI_AP_PROCEDURE Procedure
,
435 IN UINTN TimeoutInMicroseconds
,
436 IN VOID
*ProcedureArgument OPTIONAL
439 if (Procedure
== NULL
) {
440 return EFI_INVALID_PARAMETER
;
443 Procedure (ProcedureArgument
);