4 Copyright (c) 2006 - 2014, 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.
18 #include <Protocol/MpService.h>
19 #include <Library/SynchronizationLib.h>
22 Initialize Multi-processor support.
32 (EFIAPI
*STACKLESS_AP_ENTRY_POINT
)(
37 Starts the Application Processors and directs them to jump to the
40 The processor jumps to this code in flat mode, but the processor's
41 stack is not initialized.
43 @retval EFI_SUCCESS The APs were started
52 The AP entry point that the Startup-IPI target code will jump to.
54 The processor jumps to this code in flat mode, but the processor's
55 stack is not initialized.
65 Releases the lock preventing other APs from using the shared AP
68 Once the AP has transitioned to using a new stack, it can call this
69 function to allow another AP to proceed with using the shared stack.
74 AsmApDoneWithCommonStack (
87 Define Individual Processor Data block.
91 EFI_PROCESSOR_INFORMATION Info
;
92 SPIN_LOCK CpuDataLock
;
93 volatile CPU_STATE State
;
95 EFI_AP_PROCEDURE Procedure
;
100 BOOLEAN TimeoutActive
;
101 EFI_EVENT CheckThisAPEvent
;
106 Define MP data block which consumes individual processor block.
110 CPU_DATA_BLOCK
*CpuDatas
;
111 UINTN NumberOfProcessors
;
112 UINTN NumberOfEnabledProcessors
;
114 EFI_AP_PROCEDURE Procedure
;
115 VOID
*ProcedureArgument
;
118 BOOLEAN SingleThread
;
120 UINTN FailedListIndex
;
123 BOOLEAN TimeoutActive
;
124 EFI_EVENT CheckAllAPsEvent
;
128 This function is called by all processors (both BSP and AP) once and collects MP related data.
130 @param Bsp TRUE if the CPU is BSP
131 @param ProcessorNumber The specific processor number
133 @retval EFI_SUCCESS Data for the processor collected and filled in
137 FillInProcessorInformation (
139 IN UINTN ProcessorNumber
143 This service retrieves the number of logical processor in the platform
144 and the number of those logical processors that are enabled on this boot.
145 This service may only be called from the BSP.
147 This function is used to retrieve the following information:
148 - The number of logical processors that are present in the system.
149 - The number of enabled logical processors in the system at the instant
152 Because MP Service Protocol provides services to enable and disable processors
153 dynamically, the number of enabled logical processors may vary during the
154 course of a boot session.
156 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
157 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
158 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
159 is returned in NumberOfProcessors, the number of currently enabled processor
160 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
162 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
164 @param[out] NumberOfProcessors Pointer to the total number of logical
165 processors in the system, including the BSP
167 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
168 processors that exist in system, including
171 @retval EFI_SUCCESS The number of logical processors and enabled
172 logical processors was retrieved.
173 @retval EFI_DEVICE_ERROR The calling processor is an AP.
174 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
175 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
180 GetNumberOfProcessors (
181 IN EFI_MP_SERVICES_PROTOCOL
*This
,
182 OUT UINTN
*NumberOfProcessors
,
183 OUT UINTN
*NumberOfEnabledProcessors
187 Gets detailed MP-related information on the requested processor at the
188 instant this call is made. This service may only be called from the BSP.
190 This service retrieves detailed MP-related information about any processor
191 on the platform. Note the following:
192 - The processor information may change during the course of a boot session.
193 - The information presented here is entirely MP related.
195 Information regarding the number of caches and their sizes, frequency of operation,
196 slot numbers is all considered platform-related information and is not provided
199 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
201 @param[in] ProcessorNumber The handle number of processor.
202 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
203 the requested processor is deposited.
205 @retval EFI_SUCCESS Processor information was returned.
206 @retval EFI_DEVICE_ERROR The calling processor is an AP.
207 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
208 @retval EFI_NOT_FOUND The processor with the handle specified by
209 ProcessorNumber does not exist in the platform.
215 IN EFI_MP_SERVICES_PROTOCOL
*This
,
216 IN UINTN ProcessorNumber
,
217 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
221 This service executes a caller provided function on all enabled APs. APs can
222 run either simultaneously or one at a time in sequence. This service supports
223 both blocking and non-blocking requests. The non-blocking requests use EFI
224 events so the BSP can detect when the APs have finished. This service may only
225 be called from the BSP.
227 This function is used to dispatch all the enabled APs to the function specified
228 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
229 immediately and Procedure is not started on any AP.
231 If SingleThread is TRUE, all the enabled APs execute the function specified by
232 Procedure one by one, in ascending order of processor handle number. Otherwise,
233 all the enabled APs execute the function specified by Procedure simultaneously.
235 If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all
236 APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking
237 mode, and the BSP returns from this service without waiting for APs. If a
238 non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
239 is signaled, then EFI_UNSUPPORTED must be returned.
241 If the timeout specified by TimeoutInMicroseconds expires before all APs return
242 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
243 are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
244 and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its
245 content points to the list of processor handle numbers in which Procedure was
248 Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
249 to make sure that the nature of the code that is executed on the BSP and the
250 dispatched APs is well controlled. The MP Services Protocol does not guarantee
251 that the Procedure function is MP-safe. Hence, the tasks that can be run in
252 parallel are limited to certain independent tasks and well-controlled exclusive
253 code. EFI services and protocols may not be called by APs unless otherwise
256 In blocking execution mode, BSP waits until all APs finish or
257 TimeoutInMicroseconds expires.
259 In non-blocking execution mode, BSP is freed to return to the caller and then
260 proceed to the next task without having to wait for APs. The following
261 sequence needs to occur in a non-blocking execution mode:
263 -# The caller that intends to use this MP Services Protocol in non-blocking
264 mode creates WaitEvent by calling the EFI CreateEvent() service. The caller
265 invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent
266 is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests
267 the function specified by Procedure to be started on all the enabled APs,
268 and releases the BSP to continue with other tasks.
269 -# The caller can use the CheckEvent() and WaitForEvent() services to check
270 the state of the WaitEvent created in step 1.
271 -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP
272 Service signals WaitEvent by calling the EFI SignalEvent() function. If
273 FailedCpuList is not NULL, its content is available when WaitEvent is
274 signaled. If all APs returned from Procedure prior to the timeout, then
275 FailedCpuList is set to NULL. If not all APs return from Procedure before
276 the timeout, then FailedCpuList is filled in with the list of the failed
277 APs. The buffer is allocated by MP Service Protocol using AllocatePool().
278 It is the caller's responsibility to free the buffer with FreePool() service.
279 -# This invocation of SignalEvent() function informs the caller that invoked
280 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed
281 the specified task or a timeout occurred. The contents of FailedCpuList
282 can be examined to determine which APs did not complete the specified task
283 prior to the timeout.
285 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
287 @param[in] Procedure A pointer to the function to be run on
288 enabled APs of the system. See type
290 @param[in] SingleThread If TRUE, then all the enabled APs execute
291 the function specified by Procedure one by
292 one, in ascending order of processor handle
293 number. If FALSE, then all the enabled APs
294 execute the function specified by Procedure
296 @param[in] WaitEvent The event created by the caller with CreateEvent()
297 service. If it is NULL, then execute in
298 blocking mode. BSP waits until all APs finish
299 or TimeoutInMicroseconds expires. If it's
300 not NULL, then execute in non-blocking mode.
301 BSP requests the function specified by
302 Procedure to be started on all the enabled
303 APs, and go on executing immediately. If
304 all return from Procedure, or TimeoutInMicroseconds
305 expires, this event is signaled. The BSP
306 can use the CheckEvent() or WaitForEvent()
307 services to check the state of event. Type
308 EFI_EVENT is defined in CreateEvent() in
309 the Unified Extensible Firmware Interface
311 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
312 APs to return from Procedure, either for
313 blocking or non-blocking mode. Zero means
314 infinity. If the timeout expires before
315 all APs return from Procedure, then Procedure
316 on the failed APs is terminated. All enabled
317 APs are available for next function assigned
318 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
319 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
320 If the timeout expires in blocking mode,
321 BSP returns EFI_TIMEOUT. If the timeout
322 expires in non-blocking mode, WaitEvent
323 is signaled with SignalEvent().
324 @param[in] ProcedureArgument The parameter passed into Procedure for
326 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
327 if all APs finish successfully, then its
328 content is set to NULL. If not all APs
329 finish before timeout expires, then its
330 content is set to address of the buffer
331 holding handle numbers of the failed APs.
332 The buffer is allocated by MP Service Protocol,
333 and it's the caller's responsibility to
334 free the buffer with FreePool() service.
335 In blocking mode, it is ready for consumption
336 when the call returns. In non-blocking mode,
337 it is ready when WaitEvent is signaled. The
338 list of failed CPU is terminated by
341 @retval EFI_SUCCESS In blocking mode, all APs have finished before
343 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
345 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
346 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
348 @retval EFI_DEVICE_ERROR Caller processor is AP.
349 @retval EFI_NOT_STARTED No enabled APs exist in the system.
350 @retval EFI_NOT_READY Any enabled APs are busy.
351 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
352 all enabled APs have finished.
353 @retval EFI_INVALID_PARAMETER Procedure is NULL.
359 IN EFI_MP_SERVICES_PROTOCOL
*This
,
360 IN EFI_AP_PROCEDURE Procedure
,
361 IN BOOLEAN SingleThread
,
362 IN EFI_EVENT WaitEvent OPTIONAL
,
363 IN UINTN TimeoutInMicroseconds
,
364 IN VOID
*ProcedureArgument OPTIONAL
,
365 OUT UINTN
**FailedCpuList OPTIONAL
369 This service lets the caller get one enabled AP to execute a caller-provided
370 function. The caller can request the BSP to either wait for the completion
371 of the AP or just proceed with the next task by using the EFI event mechanism.
372 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
373 execution support. This service may only be called from the BSP.
375 This function is used to dispatch one enabled AP to the function specified by
376 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
377 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
378 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
379 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
380 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
381 then EFI_UNSUPPORTED must be returned.
383 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
384 from Procedure, then execution of Procedure by the AP is terminated. The AP is
385 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
386 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
388 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
390 @param[in] Procedure A pointer to the function to be run on
391 enabled APs of the system. See type
393 @param[in] ProcessorNumber The handle number of the AP. The range is
394 from 0 to the total number of logical
395 processors minus 1. The total number of
396 logical processors can be retrieved by
397 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
398 @param[in] WaitEvent The event created by the caller with CreateEvent()
399 service. If it is NULL, then execute in
400 blocking mode. BSP waits until all APs finish
401 or TimeoutInMicroseconds expires. If it's
402 not NULL, then execute in non-blocking mode.
403 BSP requests the function specified by
404 Procedure to be started on all the enabled
405 APs, and go on executing immediately. If
406 all return from Procedure or TimeoutInMicroseconds
407 expires, this event is signaled. The BSP
408 can use the CheckEvent() or WaitForEvent()
409 services to check the state of event. Type
410 EFI_EVENT is defined in CreateEvent() in
411 the Unified Extensible Firmware Interface
413 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
414 APs to return from Procedure, either for
415 blocking or non-blocking mode. Zero means
416 infinity. If the timeout expires before
417 all APs return from Procedure, then Procedure
418 on the failed APs is terminated. All enabled
419 APs are available for next function assigned
420 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
421 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
422 If the timeout expires in blocking mode,
423 BSP returns EFI_TIMEOUT. If the timeout
424 expires in non-blocking mode, WaitEvent
425 is signaled with SignalEvent().
426 @param[in] ProcedureArgument The parameter passed into Procedure for
428 @param[out] Finished If NULL, this parameter is ignored. In
429 blocking mode, this parameter is ignored.
430 In non-blocking mode, if AP returns from
431 Procedure before the timeout expires, its
432 content is set to TRUE. Otherwise, the
433 value is set to FALSE. The caller can
434 determine if the AP returned from Procedure
435 by evaluating this value.
437 @retval EFI_SUCCESS In blocking mode, specified AP finished before
439 @retval EFI_SUCCESS In non-blocking mode, the function has been
440 dispatched to specified AP.
441 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
442 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
444 @retval EFI_DEVICE_ERROR The calling processor is an AP.
445 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
446 the specified AP has finished.
447 @retval EFI_NOT_READY The specified AP is busy.
448 @retval EFI_NOT_FOUND The processor with the handle specified by
449 ProcessorNumber does not exist.
450 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
451 @retval EFI_INVALID_PARAMETER Procedure is NULL.
457 IN EFI_MP_SERVICES_PROTOCOL
*This
,
458 IN EFI_AP_PROCEDURE Procedure
,
459 IN UINTN ProcessorNumber
,
460 IN EFI_EVENT WaitEvent OPTIONAL
,
461 IN UINTN TimeoutInMicroseconds
,
462 IN VOID
*ProcedureArgument OPTIONAL
,
463 OUT BOOLEAN
*Finished OPTIONAL
467 This service switches the requested AP to be the BSP from that point onward.
468 This service changes the BSP for all purposes. This call can only be performed
471 This service switches the requested AP to be the BSP from that point onward.
472 This service changes the BSP for all purposes. The new BSP can take over the
473 execution of the old BSP and continue seamlessly from where the old one left
474 off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
477 If the BSP cannot be switched prior to the return from this service, then
478 EFI_UNSUPPORTED must be returned.
480 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
481 @param[in] ProcessorNumber The handle number of AP that is to become the new
482 BSP. The range is from 0 to the total number of
483 logical processors minus 1. The total number of
484 logical processors can be retrieved by
485 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
486 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
487 enabled AP. Otherwise, it will be disabled.
489 @retval EFI_SUCCESS BSP successfully switched.
490 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
491 this service returning.
492 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
493 @retval EFI_SUCCESS The calling processor is an AP.
494 @retval EFI_NOT_FOUND The processor with the handle specified by
495 ProcessorNumber does not exist.
496 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
498 @retval EFI_NOT_READY The specified AP is busy.
504 IN EFI_MP_SERVICES_PROTOCOL
*This
,
505 IN UINTN ProcessorNumber
,
506 IN BOOLEAN EnableOldBSP
510 This service lets the caller enable or disable an AP from this point onward.
511 This service may only be called from the BSP.
513 This service allows the caller enable or disable an AP from this point onward.
514 The caller can optionally specify the health status of the AP by Health. If
515 an AP is being disabled, then the state of the disabled AP is implementation
516 dependent. If an AP is enabled, then the implementation must guarantee that a
517 complete initialization sequence is performed on the AP, so the AP is in a state
518 that is compatible with an MP operating system. This service may not be supported
519 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
521 If the enable or disable AP operation cannot be completed prior to the return
522 from this service, then EFI_UNSUPPORTED must be returned.
524 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
525 @param[in] ProcessorNumber The handle number of AP that is to become the new
526 BSP. The range is from 0 to the total number of
527 logical processors minus 1. The total number of
528 logical processors can be retrieved by
529 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
530 @param[in] EnableAP Specifies the new state for the processor for
531 enabled, FALSE for disabled.
532 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
533 the new health status of the AP. This flag
534 corresponds to StatusFlag defined in
535 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
536 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
537 bits are ignored. If it is NULL, this parameter
540 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
541 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
542 prior to this service returning.
543 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
544 @retval EFI_DEVICE_ERROR The calling processor is an AP.
545 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
547 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
553 IN EFI_MP_SERVICES_PROTOCOL
*This
,
554 IN UINTN ProcessorNumber
,
556 IN UINT32
*HealthFlag OPTIONAL
560 This return the handle number for the calling processor. This service may be
561 called from the BSP and APs.
563 This service returns the processor handle number for the calling processor.
564 The returned value is in the range from 0 to the total number of logical
565 processors minus 1. The total number of logical processors can be retrieved
566 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
567 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
568 is returned. Otherwise, the current processors handle number is returned in
569 ProcessorNumber, and EFI_SUCCESS is returned.
571 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
572 @param[out] ProcessorNumber The handle number of AP that is to become the new
573 BSP. The range is from 0 to the total number of
574 logical processors minus 1. The total number of
575 logical processors can be retrieved by
576 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
578 @retval EFI_SUCCESS The current processor handle number was returned
580 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
586 IN EFI_MP_SERVICES_PROTOCOL
*This
,
587 OUT UINTN
*ProcessorNumber
591 Terminate AP's task and set it to idle state.
593 This function terminates AP's task due to timeout by sending INIT-SIPI,
594 and sends it to idle state.
596 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
600 ResetProcessorToIdleState (
601 IN CPU_DATA_BLOCK
*CpuData
605 Prepares Startup Code for APs.
606 This function prepares Startup Code for APs.
608 @retval EFI_SUCCESS The APs were started
609 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory to start APs
613 PrepareAPStartupCode (
618 Free the code buffer of startup AP.
627 Resets the Application Processor and directs it to jump to the
630 The processor jumps to this code in flat mode, but the processor's
631 stack is not initialized.
633 @param ProcessorId the AP of ProcessorId was reset
637 IN UINT32 ProcessorId