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
;
105 Define MP data block which consumes individual processor block.
109 CPU_DATA_BLOCK
*CpuDatas
;
110 UINTN NumberOfProcessors
;
111 UINTN NumberOfEnabledProcessors
;
113 EFI_AP_PROCEDURE Procedure
;
114 VOID
*ProcedureArgument
;
117 BOOLEAN SingleThread
;
119 UINTN FailedListIndex
;
122 BOOLEAN TimeoutActive
;
123 EFI_EVENT CheckAllAPsEvent
;
127 This function is called by all processors (both BSP and AP) once and collects MP related data.
129 @param Bsp TRUE if the CPU is BSP
130 @param ProcessorNumber The specific processor number
132 @retval EFI_SUCCESS Data for the processor collected and filled in
136 FillInProcessorInformation (
138 IN UINTN ProcessorNumber
142 This service retrieves the number of logical processor in the platform
143 and the number of those logical processors that are enabled on this boot.
144 This service may only be called from the BSP.
146 This function is used to retrieve the following information:
147 - The number of logical processors that are present in the system.
148 - The number of enabled logical processors in the system at the instant
151 Because MP Service Protocol provides services to enable and disable processors
152 dynamically, the number of enabled logical processors may vary during the
153 course of a boot session.
155 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
156 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
157 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
158 is returned in NumberOfProcessors, the number of currently enabled processor
159 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
161 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
163 @param[out] NumberOfProcessors Pointer to the total number of logical
164 processors in the system, including the BSP
166 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
167 processors that exist in system, including
170 @retval EFI_SUCCESS The number of logical processors and enabled
171 logical processors was retrieved.
172 @retval EFI_DEVICE_ERROR The calling processor is an AP.
173 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
174 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
179 GetNumberOfProcessors (
180 IN EFI_MP_SERVICES_PROTOCOL
*This
,
181 OUT UINTN
*NumberOfProcessors
,
182 OUT UINTN
*NumberOfEnabledProcessors
186 Gets detailed MP-related information on the requested processor at the
187 instant this call is made. This service may only be called from the BSP.
189 This service retrieves detailed MP-related information about any processor
190 on the platform. Note the following:
191 - The processor information may change during the course of a boot session.
192 - The information presented here is entirely MP related.
194 Information regarding the number of caches and their sizes, frequency of operation,
195 slot numbers is all considered platform-related information and is not provided
198 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
200 @param[in] ProcessorNumber The handle number of processor.
201 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
202 the requested processor is deposited.
204 @retval EFI_SUCCESS Processor information was returned.
205 @retval EFI_DEVICE_ERROR The calling processor is an AP.
206 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
207 @retval EFI_NOT_FOUND The processor with the handle specified by
208 ProcessorNumber does not exist in the platform.
214 IN EFI_MP_SERVICES_PROTOCOL
*This
,
215 IN UINTN ProcessorNumber
,
216 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
220 This service executes a caller provided function on all enabled APs. APs can
221 run either simultaneously or one at a time in sequence. This service supports
222 both blocking and non-blocking requests. The non-blocking requests use EFI
223 events so the BSP can detect when the APs have finished. This service may only
224 be called from the BSP.
226 This function is used to dispatch all the enabled APs to the function specified
227 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
228 immediately and Procedure is not started on any AP.
230 If SingleThread is TRUE, all the enabled APs execute the function specified by
231 Procedure one by one, in ascending order of processor handle number. Otherwise,
232 all the enabled APs execute the function specified by Procedure simultaneously.
234 If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all
235 APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking
236 mode, and the BSP returns from this service without waiting for APs. If a
237 non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
238 is signaled, then EFI_UNSUPPORTED must be returned.
240 If the timeout specified by TimeoutInMicroseconds expires before all APs return
241 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
242 are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
243 and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its
244 content points to the list of processor handle numbers in which Procedure was
247 Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
248 to make sure that the nature of the code that is executed on the BSP and the
249 dispatched APs is well controlled. The MP Services Protocol does not guarantee
250 that the Procedure function is MP-safe. Hence, the tasks that can be run in
251 parallel are limited to certain independent tasks and well-controlled exclusive
252 code. EFI services and protocols may not be called by APs unless otherwise
255 In blocking execution mode, BSP waits until all APs finish or
256 TimeoutInMicroseconds expires.
258 In non-blocking execution mode, BSP is freed to return to the caller and then
259 proceed to the next task without having to wait for APs. The following
260 sequence needs to occur in a non-blocking execution mode:
262 -# The caller that intends to use this MP Services Protocol in non-blocking
263 mode creates WaitEvent by calling the EFI CreateEvent() service. The caller
264 invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent
265 is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests
266 the function specified by Procedure to be started on all the enabled APs,
267 and releases the BSP to continue with other tasks.
268 -# The caller can use the CheckEvent() and WaitForEvent() services to check
269 the state of the WaitEvent created in step 1.
270 -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP
271 Service signals WaitEvent by calling the EFI SignalEvent() function. If
272 FailedCpuList is not NULL, its content is available when WaitEvent is
273 signaled. If all APs returned from Procedure prior to the timeout, then
274 FailedCpuList is set to NULL. If not all APs return from Procedure before
275 the timeout, then FailedCpuList is filled in with the list of the failed
276 APs. The buffer is allocated by MP Service Protocol using AllocatePool().
277 It is the caller's responsibility to free the buffer with FreePool() service.
278 -# This invocation of SignalEvent() function informs the caller that invoked
279 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed
280 the specified task or a timeout occurred. The contents of FailedCpuList
281 can be examined to determine which APs did not complete the specified task
282 prior to the timeout.
284 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
286 @param[in] Procedure A pointer to the function to be run on
287 enabled APs of the system. See type
289 @param[in] SingleThread If TRUE, then all the enabled APs execute
290 the function specified by Procedure one by
291 one, in ascending order of processor handle
292 number. If FALSE, then all the enabled APs
293 execute the function specified by Procedure
295 @param[in] WaitEvent The event created by the caller with CreateEvent()
296 service. If it is NULL, then execute in
297 blocking mode. BSP waits until all APs finish
298 or TimeoutInMicroseconds expires. If it's
299 not NULL, then execute in non-blocking mode.
300 BSP requests the function specified by
301 Procedure to be started on all the enabled
302 APs, and go on executing immediately. If
303 all return from Procedure, or TimeoutInMicroseconds
304 expires, this event is signaled. The BSP
305 can use the CheckEvent() or WaitForEvent()
306 services to check the state of event. Type
307 EFI_EVENT is defined in CreateEvent() in
308 the Unified Extensible Firmware Interface
310 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
311 APs to return from Procedure, either for
312 blocking or non-blocking mode. Zero means
313 infinity. If the timeout expires before
314 all APs return from Procedure, then Procedure
315 on the failed APs is terminated. All enabled
316 APs are available for next function assigned
317 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
318 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
319 If the timeout expires in blocking mode,
320 BSP returns EFI_TIMEOUT. If the timeout
321 expires in non-blocking mode, WaitEvent
322 is signaled with SignalEvent().
323 @param[in] ProcedureArgument The parameter passed into Procedure for
325 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
326 if all APs finish successfully, then its
327 content is set to NULL. If not all APs
328 finish before timeout expires, then its
329 content is set to address of the buffer
330 holding handle numbers of the failed APs.
331 The buffer is allocated by MP Service Protocol,
332 and it's the caller's responsibility to
333 free the buffer with FreePool() service.
334 In blocking mode, it is ready for consumption
335 when the call returns. In non-blocking mode,
336 it is ready when WaitEvent is signaled. The
337 list of failed CPU is terminated by
340 @retval EFI_SUCCESS In blocking mode, all APs have finished before
342 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
344 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
345 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
347 @retval EFI_DEVICE_ERROR Caller processor is AP.
348 @retval EFI_NOT_STARTED No enabled APs exist in the system.
349 @retval EFI_NOT_READY Any enabled APs are busy.
350 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
351 all enabled APs have finished.
352 @retval EFI_INVALID_PARAMETER Procedure is NULL.
358 IN EFI_MP_SERVICES_PROTOCOL
*This
,
359 IN EFI_AP_PROCEDURE Procedure
,
360 IN BOOLEAN SingleThread
,
361 IN EFI_EVENT WaitEvent OPTIONAL
,
362 IN UINTN TimeoutInMicroseconds
,
363 IN VOID
*ProcedureArgument OPTIONAL
,
364 OUT UINTN
**FailedCpuList OPTIONAL
368 This service lets the caller get one enabled AP to execute a caller-provided
369 function. The caller can request the BSP to either wait for the completion
370 of the AP or just proceed with the next task by using the EFI event mechanism.
371 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
372 execution support. This service may only be called from the BSP.
374 This function is used to dispatch one enabled AP to the function specified by
375 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
376 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
377 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
378 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
379 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
380 then EFI_UNSUPPORTED must be returned.
382 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
383 from Procedure, then execution of Procedure by the AP is terminated. The AP is
384 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
385 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
387 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
389 @param[in] Procedure A pointer to the function to be run on
390 enabled APs of the system. See type
392 @param[in] ProcessorNumber The handle number of the AP. The range is
393 from 0 to the total number of logical
394 processors minus 1. The total number of
395 logical processors can be retrieved by
396 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
397 @param[in] WaitEvent The event created by the caller with CreateEvent()
398 service. If it is NULL, then execute in
399 blocking mode. BSP waits until all APs finish
400 or TimeoutInMicroseconds expires. If it's
401 not NULL, then execute in non-blocking mode.
402 BSP requests the function specified by
403 Procedure to be started on all the enabled
404 APs, and go on executing immediately. If
405 all return from Procedure or TimeoutInMicroseconds
406 expires, this event is signaled. The BSP
407 can use the CheckEvent() or WaitForEvent()
408 services to check the state of event. Type
409 EFI_EVENT is defined in CreateEvent() in
410 the Unified Extensible Firmware Interface
412 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
413 APs to return from Procedure, either for
414 blocking or non-blocking mode. Zero means
415 infinity. If the timeout expires before
416 all APs return from Procedure, then Procedure
417 on the failed APs is terminated. All enabled
418 APs are available for next function assigned
419 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
420 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
421 If the timeout expires in blocking mode,
422 BSP returns EFI_TIMEOUT. If the timeout
423 expires in non-blocking mode, WaitEvent
424 is signaled with SignalEvent().
425 @param[in] ProcedureArgument The parameter passed into Procedure for
427 @param[out] Finished If NULL, this parameter is ignored. In
428 blocking mode, this parameter is ignored.
429 In non-blocking mode, if AP returns from
430 Procedure before the timeout expires, its
431 content is set to TRUE. Otherwise, the
432 value is set to FALSE. The caller can
433 determine if the AP returned from Procedure
434 by evaluating this value.
436 @retval EFI_SUCCESS In blocking mode, specified AP finished before
438 @retval EFI_SUCCESS In non-blocking mode, the function has been
439 dispatched to specified AP.
440 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
441 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
443 @retval EFI_DEVICE_ERROR The calling processor is an AP.
444 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
445 the specified AP has finished.
446 @retval EFI_NOT_READY The specified AP is busy.
447 @retval EFI_NOT_FOUND The processor with the handle specified by
448 ProcessorNumber does not exist.
449 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
450 @retval EFI_INVALID_PARAMETER Procedure is NULL.
456 IN EFI_MP_SERVICES_PROTOCOL
*This
,
457 IN EFI_AP_PROCEDURE Procedure
,
458 IN UINTN ProcessorNumber
,
459 IN EFI_EVENT WaitEvent OPTIONAL
,
460 IN UINTN TimeoutInMicroseconds
,
461 IN VOID
*ProcedureArgument OPTIONAL
,
462 OUT BOOLEAN
*Finished OPTIONAL
466 This service switches the requested AP to be the BSP from that point onward.
467 This service changes the BSP for all purposes. This call can only be performed
470 This service switches the requested AP to be the BSP from that point onward.
471 This service changes the BSP for all purposes. The new BSP can take over the
472 execution of the old BSP and continue seamlessly from where the old one left
473 off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
476 If the BSP cannot be switched prior to the return from this service, then
477 EFI_UNSUPPORTED must be returned.
479 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
480 @param[in] ProcessorNumber The handle number of AP that is to become the new
481 BSP. The range is from 0 to the total number of
482 logical processors minus 1. The total number of
483 logical processors can be retrieved by
484 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
485 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
486 enabled AP. Otherwise, it will be disabled.
488 @retval EFI_SUCCESS BSP successfully switched.
489 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
490 this service returning.
491 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
492 @retval EFI_SUCCESS The calling processor is an AP.
493 @retval EFI_NOT_FOUND The processor with the handle specified by
494 ProcessorNumber does not exist.
495 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
497 @retval EFI_NOT_READY The specified AP is busy.
503 IN EFI_MP_SERVICES_PROTOCOL
*This
,
504 IN UINTN ProcessorNumber
,
505 IN BOOLEAN EnableOldBSP
509 This service lets the caller enable or disable an AP from this point onward.
510 This service may only be called from the BSP.
512 This service allows the caller enable or disable an AP from this point onward.
513 The caller can optionally specify the health status of the AP by Health. If
514 an AP is being disabled, then the state of the disabled AP is implementation
515 dependent. If an AP is enabled, then the implementation must guarantee that a
516 complete initialization sequence is performed on the AP, so the AP is in a state
517 that is compatible with an MP operating system. This service may not be supported
518 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
520 If the enable or disable AP operation cannot be completed prior to the return
521 from this service, then EFI_UNSUPPORTED must be returned.
523 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
524 @param[in] ProcessorNumber The handle number of AP that is to become the new
525 BSP. The range is from 0 to the total number of
526 logical processors minus 1. The total number of
527 logical processors can be retrieved by
528 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
529 @param[in] EnableAP Specifies the new state for the processor for
530 enabled, FALSE for disabled.
531 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
532 the new health status of the AP. This flag
533 corresponds to StatusFlag defined in
534 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
535 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
536 bits are ignored. If it is NULL, this parameter
539 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
540 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
541 prior to this service returning.
542 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
543 @retval EFI_DEVICE_ERROR The calling processor is an AP.
544 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
546 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
552 IN EFI_MP_SERVICES_PROTOCOL
*This
,
553 IN UINTN ProcessorNumber
,
555 IN UINT32
*HealthFlag OPTIONAL
559 This return the handle number for the calling processor. This service may be
560 called from the BSP and APs.
562 This service returns the processor handle number for the calling processor.
563 The returned value is in the range from 0 to the total number of logical
564 processors minus 1. The total number of logical processors can be retrieved
565 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
566 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
567 is returned. Otherwise, the current processors handle number is returned in
568 ProcessorNumber, and EFI_SUCCESS is returned.
570 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
571 @param[out] ProcessorNumber The handle number of AP that is to become the new
572 BSP. The range is from 0 to the total number of
573 logical processors minus 1. The total number of
574 logical processors can be retrieved by
575 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
577 @retval EFI_SUCCESS The current processor handle number was returned
579 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
585 IN EFI_MP_SERVICES_PROTOCOL
*This
,
586 OUT UINTN
*ProcessorNumber
590 Terminate AP's task and set it to idle state.
592 This function terminates AP's task due to timeout by sending INIT-SIPI,
593 and sends it to idle state.
595 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
599 ResetProcessorToIdleState (
600 IN CPU_DATA_BLOCK
*CpuData
604 Prepares Startup Code for APs.
605 This function prepares Startup Code for APs.
607 @retval EFI_SUCCESS The APs were started
608 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory to start APs
612 PrepareAPStartupCode (
617 Free the code buffer of startup AP.