2 Construct MP Services Protocol on top of the EMU Thread protocol.
3 This code makes APs show up in the emulator. PcdEmuApCount is the
4 number of APs the emulator should produce.
6 The MP Services Protocol provides a generalized way of performing following tasks:
7 - Retrieving information of multi-processor environment and MP-related status of
9 - Dispatching user-provided function to APs.
10 - Maintain MP-related processor status.
12 The MP Services Protocol must be produced on any system with more than one logical
15 The Protocol is available only during boot time.
17 MP Services Protocol is hardware-independent. Most of the logic of this protocol
18 is architecturally neutral. It abstracts the multi-processor environment and
19 status of processors, and provides interfaces to retrieve information, maintain,
22 MP Services Protocol may be consumed by ACPI module. The ACPI module may use this
23 protocol to retrieve data that are needed for an MP platform and report them to OS.
24 MP Services Protocol may also be used to program and configure processors, such
25 as MTRR synchronization for memory space attributes setting in DXE Services.
26 MP Services Protocol may be used by non-CPU DXE drivers to speed up platform boot
27 by taking advantage of the processing capabilities of the APs, for example, using
28 APs to help test system memory in parallel with other device initialization.
29 Diagnostics applications may also use this protocol for multi-processor.
31 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
32 Portitions Copyright (c) 2011, Apple Inc. All rights reserved.
33 This program and the accompanying materials are licensed and made available under
34 the terms and conditions of the BSD License that accompanies this distribution.
35 The full text of the license may be found at
36 http://opensource.org/licenses/bsd-license.php.
38 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
39 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
44 #include "CpuDriver.h"
47 MP_SYSTEM_DATA gMPSystem
;
48 EMU_THREAD_THUNK_PROTOCOL
*gThread
= NULL
;
49 EFI_EVENT gReadToBootEvent
;
50 BOOLEAN gReadToBoot
= FALSE
;
60 UINTN ProcessorNumber
;
62 Status
= CpuMpServicesWhoAmI (&mMpServicesTemplate
, &ProcessorNumber
);
63 if (EFI_ERROR (Status
)) {
67 return (gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0;
73 IN PROCESSOR_DATA_BLOCK
*Processor
,
74 IN EFI_AP_PROCEDURE Procedure
,
75 IN VOID
*ProcedureArgument
78 gThread
->MutexLock (Processor
->ProcedureLock
);
79 Processor
->Parameter
= ProcedureArgument
;
80 Processor
->Procedure
= Procedure
;
81 gThread
->MutexUnlock (Processor
->ProcedureLock
);
86 GetNextBlockedNumber (
91 PROCESSOR_STATE ProcessorState
;
92 PROCESSOR_DATA_BLOCK
*Data
;
94 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
95 Data
= &gMPSystem
.ProcessorData
[Number
];
96 if ((Data
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
101 gThread
->MutexLock (Data
->StateLock
);
102 ProcessorState
= Data
->State
;
103 gThread
->MutexUnlock (Data
->StateLock
);
105 if (ProcessorState
== CPU_STATE_BLOCKED
) {
106 *NextNumber
= Number
;
111 return EFI_NOT_FOUND
;
115 * Calculated and stalled the interval time by BSP to check whether
116 * the APs have finished.
118 * @param[in] Timeout The time limit in microseconds for
119 * APs to return from Procedure.
121 * @retval StallTime Time of execution stall.
124 CalculateAndStallInterval (
130 if (Timeout
< gPollInterval
&& Timeout
!= 0) {
133 StallTime
= gPollInterval
;
135 gBS
->Stall (StallTime
);
141 This service retrieves the number of logical processor in the platform
142 and the number of those logical processors that are enabled on this boot.
143 This service may only be called from the BSP.
145 This function is used to retrieve the following information:
146 - The number of logical processors that are present in the system.
147 - The number of enabled logical processors in the system at the instant
150 Because MP Service Protocol provides services to enable and disable processors
151 dynamically, the number of enabled logical processors may vary during the
152 course of a boot session.
154 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
155 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
156 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
157 is returned in NumberOfProcessors, the number of currently enabled processor
158 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
160 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
162 @param[out] NumberOfProcessors Pointer to the total number of logical
163 processors in the system, including the BSP
165 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
166 processors that exist in system, including
169 @retval EFI_SUCCESS The number of logical processors and enabled
170 logical processors was retrieved.
171 @retval EFI_DEVICE_ERROR The calling processor is an AP.
172 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
173 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
178 CpuMpServicesGetNumberOfProcessors (
179 IN EFI_MP_SERVICES_PROTOCOL
*This
,
180 OUT UINTN
*NumberOfProcessors
,
181 OUT UINTN
*NumberOfEnabledProcessors
184 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
185 return EFI_INVALID_PARAMETER
;
189 return EFI_DEVICE_ERROR
;
192 *NumberOfProcessors
= gMPSystem
.NumberOfProcessors
;
193 *NumberOfEnabledProcessors
= gMPSystem
.NumberOfEnabledProcessors
;
200 Gets detailed MP-related information on the requested processor at the
201 instant this call is made. This service may only be called from the BSP.
203 This service retrieves detailed MP-related information about any processor
204 on the platform. Note the following:
205 - The processor information may change during the course of a boot session.
206 - The information presented here is entirely MP related.
208 Information regarding the number of caches and their sizes, frequency of operation,
209 slot numbers is all considered platform-related information and is not provided
212 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
214 @param[in] ProcessorNumber The handle number of processor.
215 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
216 the requested processor is deposited.
218 @retval EFI_SUCCESS Processor information was returned.
219 @retval EFI_DEVICE_ERROR The calling processor is an AP.
220 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
221 @retval EFI_NOT_FOUND The processor with the handle specified by
222 ProcessorNumber does not exist in the platform.
227 CpuMpServicesGetProcessorInfo (
228 IN EFI_MP_SERVICES_PROTOCOL
*This
,
229 IN UINTN ProcessorNumber
,
230 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
233 if (ProcessorInfoBuffer
== NULL
) {
234 return EFI_INVALID_PARAMETER
;
238 return EFI_DEVICE_ERROR
;
241 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
242 return EFI_NOT_FOUND
;
245 CopyMem (ProcessorInfoBuffer
, &gMPSystem
.ProcessorData
[ProcessorNumber
], sizeof (EFI_PROCESSOR_INFORMATION
));
251 This service executes a caller provided function on all enabled APs. APs can
252 run either simultaneously or one at a time in sequence. This service supports
253 both blocking and non-blocking requests. The non-blocking requests use EFI
254 events so the BSP can detect when the APs have finished. This service may only
255 be called from the BSP.
257 This function is used to dispatch all the enabled APs to the function specified
258 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
259 immediately and Procedure is not started on any AP.
261 If SingleThread is TRUE, all the enabled APs execute the function specified by
262 Procedure one by one, in ascending order of processor handle number. Otherwise,
263 all the enabled APs execute the function specified by Procedure simultaneously.
265 If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all
266 APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking
267 mode, and the BSP returns from this service without waiting for APs. If a
268 non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
269 is signaled, then EFI_UNSUPPORTED must be returned.
271 If the timeout specified by TimeoutInMicroseconds expires before all APs return
272 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
273 are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
274 and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its
275 content points to the list of processor handle numbers in which Procedure was
278 Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
279 to make sure that the nature of the code that is executed on the BSP and the
280 dispatched APs is well controlled. The MP Services Protocol does not guarantee
281 that the Procedure function is MP-safe. Hence, the tasks that can be run in
282 parallel are limited to certain independent tasks and well-controlled exclusive
283 code. EFI services and protocols may not be called by APs unless otherwise
286 In blocking execution mode, BSP waits until all APs finish or
287 TimeoutInMicroseconds expires.
289 In non-blocking execution mode, BSP is freed to return to the caller and then
290 proceed to the next task without having to wait for APs. The following
291 sequence needs to occur in a non-blocking execution mode:
293 -# The caller that intends to use this MP Services Protocol in non-blocking
294 mode creates WaitEvent by calling the EFI CreateEvent() service. The caller
295 invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent
296 is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests
297 the function specified by Procedure to be started on all the enabled APs,
298 and releases the BSP to continue with other tasks.
299 -# The caller can use the CheckEvent() and WaitForEvent() services to check
300 the state of the WaitEvent created in step 1.
301 -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP
302 Service signals WaitEvent by calling the EFI SignalEvent() function. If
303 FailedCpuList is not NULL, its content is available when WaitEvent is
304 signaled. If all APs returned from Procedure prior to the timeout, then
305 FailedCpuList is set to NULL. If not all APs return from Procedure before
306 the timeout, then FailedCpuList is filled in with the list of the failed
307 APs. The buffer is allocated by MP Service Protocol using AllocatePool().
308 It is the caller's responsibility to free the buffer with FreePool() service.
309 -# This invocation of SignalEvent() function informs the caller that invoked
310 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed
311 the specified task or a timeout occurred. The contents of FailedCpuList
312 can be examined to determine which APs did not complete the specified task
313 prior to the timeout.
315 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
317 @param[in] Procedure A pointer to the function to be run on
318 enabled APs of the system. See type
320 @param[in] SingleThread If TRUE, then all the enabled APs execute
321 the function specified by Procedure one by
322 one, in ascending order of processor handle
323 number. If FALSE, then all the enabled APs
324 execute the function specified by Procedure
326 @param[in] WaitEvent The event created by the caller with CreateEvent()
327 service. If it is NULL, then execute in
328 blocking mode. BSP waits until all APs finish
329 or TimeoutInMicroseconds expires. If it's
330 not NULL, then execute in non-blocking mode.
331 BSP requests the function specified by
332 Procedure to be started on all the enabled
333 APs, and go on executing immediately. If
334 all return from Procedure, or TimeoutInMicroseconds
335 expires, this event is signaled. The BSP
336 can use the CheckEvent() or WaitForEvent()
337 services to check the state of event. Type
338 EFI_EVENT is defined in CreateEvent() in
339 the Unified Extensible Firmware Interface
341 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
342 APs to return from Procedure, either for
343 blocking or non-blocking mode. Zero means
344 infinity. If the timeout expires before
345 all APs return from Procedure, then Procedure
346 on the failed APs is terminated. All enabled
347 APs are available for next function assigned
348 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
349 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
350 If the timeout expires in blocking mode,
351 BSP returns EFI_TIMEOUT. If the timeout
352 expires in non-blocking mode, WaitEvent
353 is signaled with SignalEvent().
354 @param[in] ProcedureArgument The parameter passed into Procedure for
356 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
357 if all APs finish successfully, then its
358 content is set to NULL. If not all APs
359 finish before timeout expires, then its
360 content is set to address of the buffer
361 holding handle numbers of the failed APs.
362 The buffer is allocated by MP Service Protocol,
363 and it's the caller's responsibility to
364 free the buffer with FreePool() service.
365 In blocking mode, it is ready for consumption
366 when the call returns. In non-blocking mode,
367 it is ready when WaitEvent is signaled. The
368 list of failed CPU is terminated by
371 @retval EFI_SUCCESS In blocking mode, all APs have finished before
373 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
375 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
376 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
378 @retval EFI_DEVICE_ERROR Caller processor is AP.
379 @retval EFI_NOT_STARTED No enabled APs exist in the system.
380 @retval EFI_NOT_READY Any enabled APs are busy.
381 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
382 all enabled APs have finished.
383 @retval EFI_INVALID_PARAMETER Procedure is NULL.
388 CpuMpServicesStartupAllAps (
389 IN EFI_MP_SERVICES_PROTOCOL
*This
,
390 IN EFI_AP_PROCEDURE Procedure
,
391 IN BOOLEAN SingleThread
,
392 IN EFI_EVENT WaitEvent OPTIONAL
,
393 IN UINTN TimeoutInMicroseconds
,
394 IN VOID
*ProcedureArgument OPTIONAL
,
395 OUT UINTN
**FailedCpuList OPTIONAL
399 PROCESSOR_DATA_BLOCK
*ProcessorData
;
402 PROCESSOR_STATE APInitialState
;
403 PROCESSOR_STATE ProcessorState
;
408 return EFI_DEVICE_ERROR
;
411 if (gMPSystem
.NumberOfProcessors
== 1) {
412 return EFI_NOT_STARTED
;
415 if (Procedure
== NULL
) {
416 return EFI_INVALID_PARAMETER
;
419 if ((WaitEvent
!= NULL
) && gReadToBoot
) {
420 return EFI_UNSUPPORTED
;
423 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
424 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
425 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
430 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
431 // Skip Disabled processors
434 gThread
->MutexLock(ProcessorData
->StateLock
);
435 if (ProcessorData
->State
!= CPU_STATE_IDLE
) {
436 gThread
->MutexUnlock (ProcessorData
->StateLock
);
437 return EFI_NOT_READY
;
439 gThread
->MutexUnlock(ProcessorData
->StateLock
);
442 if (FailedCpuList
!= NULL
) {
443 gMPSystem
.FailedList
= AllocatePool ((gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
));
444 if (gMPSystem
.FailedList
== NULL
) {
445 return EFI_OUT_OF_RESOURCES
;
447 SetMemN (gMPSystem
.FailedList
, (gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
), END_OF_CPU_LIST
);
448 gMPSystem
.FailedListIndex
= 0;
449 *FailedCpuList
= gMPSystem
.FailedList
;
452 Timeout
= TimeoutInMicroseconds
;
454 ProcessorData
= NULL
;
456 gMPSystem
.FinishCount
= 0;
457 gMPSystem
.StartCount
= 0;
458 gMPSystem
.SingleThread
= SingleThread
;
459 APInitialState
= CPU_STATE_READY
;
461 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
462 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
464 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
469 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
470 // Skip Disabled processors
471 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Number
;
476 // Get APs prepared, and put failing APs into FailedCpuList
477 // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready
478 // state 1 by 1, until the previous 1 finished its task
479 // if not "SingleThread", all APs are put to ready state from the beginning
481 gThread
->MutexLock(ProcessorData
->StateLock
);
482 ASSERT (ProcessorData
->State
== CPU_STATE_IDLE
);
483 ProcessorData
->State
= APInitialState
;
484 gThread
->MutexUnlock (ProcessorData
->StateLock
);
486 gMPSystem
.StartCount
++;
488 APInitialState
= CPU_STATE_BLOCKED
;
492 if (WaitEvent
!= NULL
) {
493 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
494 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
495 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
500 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
501 // Skip Disabled processors
505 gThread
->MutexLock (ProcessorData
->StateLock
);
506 ProcessorState
= ProcessorData
->State
;
507 gThread
->MutexUnlock (ProcessorData
->StateLock
);
509 if (ProcessorState
== CPU_STATE_READY
) {
510 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
515 // Save data into private data structure, and create timer to poll AP state before exiting
517 gMPSystem
.Procedure
= Procedure
;
518 gMPSystem
.ProcedureArgument
= ProcedureArgument
;
519 gMPSystem
.WaitEvent
= WaitEvent
;
520 gMPSystem
.Timeout
= TimeoutInMicroseconds
;
521 gMPSystem
.TimeoutActive
= (BOOLEAN
)(TimeoutInMicroseconds
!= 0);
522 Status
= gBS
->SetTimer (
523 gMPSystem
.CheckAllAPsEvent
,
532 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
533 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
534 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
539 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
540 // Skip Disabled processors
544 gThread
->MutexLock (ProcessorData
->StateLock
);
545 ProcessorState
= ProcessorData
->State
;
546 gThread
->MutexUnlock (ProcessorData
->StateLock
);
548 switch (ProcessorState
) {
549 case CPU_STATE_READY
:
550 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
553 case CPU_STATE_FINISHED
:
554 gMPSystem
.FinishCount
++;
556 Status
= GetNextBlockedNumber (&NextNumber
);
557 if (!EFI_ERROR (Status
)) {
558 gThread
->MutexLock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
559 gMPSystem
.ProcessorData
[NextNumber
].State
= CPU_STATE_READY
;
560 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
564 gThread
->MutexLock (ProcessorData
->StateLock
);
565 ProcessorData
->State
= CPU_STATE_IDLE
;
566 gThread
->MutexUnlock (ProcessorData
->StateLock
);
575 if (gMPSystem
.FinishCount
== gMPSystem
.StartCount
) {
576 Status
= EFI_SUCCESS
;
580 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
581 Status
= EFI_TIMEOUT
;
585 Timeout
-= CalculateAndStallInterval (Timeout
);
589 if (FailedCpuList
!= NULL
) {
590 if (gMPSystem
.FailedListIndex
== 0) {
591 FreePool (*FailedCpuList
);
592 *FailedCpuList
= NULL
;
601 This service lets the caller get one enabled AP to execute a caller-provided
602 function. The caller can request the BSP to either wait for the completion
603 of the AP or just proceed with the next task by using the EFI event mechanism.
604 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
605 execution support. This service may only be called from the BSP.
607 This function is used to dispatch one enabled AP to the function specified by
608 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
609 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
610 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
611 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
612 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
613 then EFI_UNSUPPORTED must be returned.
615 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
616 from Procedure, then execution of Procedure by the AP is terminated. The AP is
617 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
618 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
620 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
622 @param[in] Procedure A pointer to the function to be run on
623 enabled APs of the system. See type
625 @param[in] ProcessorNumber The handle number of the AP. The range is
626 from 0 to the total number of logical
627 processors minus 1. The total number of
628 logical processors can be retrieved by
629 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
630 @param[in] WaitEvent The event created by the caller with CreateEvent()
631 service. If it is NULL, then execute in
632 blocking mode. BSP waits until all APs finish
633 or TimeoutInMicroseconds expires. If it's
634 not NULL, then execute in non-blocking mode.
635 BSP requests the function specified by
636 Procedure to be started on all the enabled
637 APs, and go on executing immediately. If
638 all return from Procedure or TimeoutInMicroseconds
639 expires, this event is signaled. The BSP
640 can use the CheckEvent() or WaitForEvent()
641 services to check the state of event. Type
642 EFI_EVENT is defined in CreateEvent() in
643 the Unified Extensible Firmware Interface
645 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
646 APs to return from Procedure, either for
647 blocking or non-blocking mode. Zero means
648 infinity. If the timeout expires before
649 all APs return from Procedure, then Procedure
650 on the failed APs is terminated. All enabled
651 APs are available for next function assigned
652 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
653 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
654 If the timeout expires in blocking mode,
655 BSP returns EFI_TIMEOUT. If the timeout
656 expires in non-blocking mode, WaitEvent
657 is signaled with SignalEvent().
658 @param[in] ProcedureArgument The parameter passed into Procedure for
660 @param[out] Finished If NULL, this parameter is ignored. In
661 blocking mode, this parameter is ignored.
662 In non-blocking mode, if AP returns from
663 Procedure before the timeout expires, its
664 content is set to TRUE. Otherwise, the
665 value is set to FALSE. The caller can
666 determine if the AP returned from Procedure
667 by evaluating this value.
669 @retval EFI_SUCCESS In blocking mode, specified AP finished before
671 @retval EFI_SUCCESS In non-blocking mode, the function has been
672 dispatched to specified AP.
673 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
674 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
676 @retval EFI_DEVICE_ERROR The calling processor is an AP.
677 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
678 the specified AP has finished.
679 @retval EFI_NOT_READY The specified AP is busy.
680 @retval EFI_NOT_FOUND The processor with the handle specified by
681 ProcessorNumber does not exist.
682 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
683 @retval EFI_INVALID_PARAMETER Procedure is NULL.
688 CpuMpServicesStartupThisAP (
689 IN EFI_MP_SERVICES_PROTOCOL
*This
,
690 IN EFI_AP_PROCEDURE Procedure
,
691 IN UINTN ProcessorNumber
,
692 IN EFI_EVENT WaitEvent OPTIONAL
,
693 IN UINTN TimeoutInMicroseconds
,
694 IN VOID
*ProcedureArgument OPTIONAL
,
695 OUT BOOLEAN
*Finished OPTIONAL
701 return EFI_DEVICE_ERROR
;
704 if (Procedure
== NULL
) {
705 return EFI_INVALID_PARAMETER
;
708 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
709 return EFI_NOT_FOUND
;
712 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
713 return EFI_INVALID_PARAMETER
;
716 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
717 return EFI_INVALID_PARAMETER
;
720 gThread
->MutexLock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
721 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
722 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
723 return EFI_NOT_READY
;
725 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
727 if ((WaitEvent
!= NULL
) && gReadToBoot
) {
728 return EFI_UNSUPPORTED
;
731 Timeout
= TimeoutInMicroseconds
;
733 gMPSystem
.StartCount
= 1;
734 gMPSystem
.FinishCount
= 0;
736 SetApProcedure (&gMPSystem
.ProcessorData
[ProcessorNumber
], Procedure
, ProcedureArgument
);
738 if (WaitEvent
!= NULL
) {
740 gMPSystem
.WaitEvent
= WaitEvent
;
742 gMPSystem
.ProcessorData
[ProcessorNumber
].CheckThisAPEvent
,
751 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
752 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
== CPU_STATE_FINISHED
) {
753 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= CPU_STATE_IDLE
;
754 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
758 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
760 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
764 Timeout
-= CalculateAndStallInterval (Timeout
);
773 This service switches the requested AP to be the BSP from that point onward.
774 This service changes the BSP for all purposes. This call can only be performed
777 This service switches the requested AP to be the BSP from that point onward.
778 This service changes the BSP for all purposes. The new BSP can take over the
779 execution of the old BSP and continue seamlessly from where the old one left
780 off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
783 If the BSP cannot be switched prior to the return from this service, then
784 EFI_UNSUPPORTED must be returned.
786 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
787 @param[in] ProcessorNumber The handle number of AP that is to become the new
788 BSP. The range is from 0 to the total number of
789 logical processors minus 1. The total number of
790 logical processors can be retrieved by
791 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
792 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
793 enabled AP. Otherwise, it will be disabled.
795 @retval EFI_SUCCESS BSP successfully switched.
796 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
797 this service returning.
798 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
799 @retval EFI_SUCCESS The calling processor is an AP.
800 @retval EFI_NOT_FOUND The processor with the handle specified by
801 ProcessorNumber does not exist.
802 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
804 @retval EFI_NOT_READY The specified AP is busy.
809 CpuMpServicesSwitchBSP (
810 IN EFI_MP_SERVICES_PROTOCOL
*This
,
811 IN UINTN ProcessorNumber
,
812 IN BOOLEAN EnableOldBSP
818 return EFI_DEVICE_ERROR
;
821 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
822 return EFI_NOT_FOUND
;
825 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
826 return EFI_INVALID_PARAMETER
;
829 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
830 return EFI_INVALID_PARAMETER
;
833 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
834 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
838 ASSERT (Index
!= gMPSystem
.NumberOfProcessors
);
840 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
841 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
842 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
843 return EFI_NOT_READY
;
845 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
847 // Skip for now as we need switch a bunch of stack stuff around and it's complex
848 // May not be worth it?
849 return EFI_NOT_READY
;
854 This service lets the caller enable or disable an AP from this point onward.
855 This service may only be called from the BSP.
857 This service allows the caller enable or disable an AP from this point onward.
858 The caller can optionally specify the health status of the AP by Health. If
859 an AP is being disabled, then the state of the disabled AP is implementation
860 dependent. If an AP is enabled, then the implementation must guarantee that a
861 complete initialization sequence is performed on the AP, so the AP is in a state
862 that is compatible with an MP operating system. This service may not be supported
863 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
865 If the enable or disable AP operation cannot be completed prior to the return
866 from this service, then EFI_UNSUPPORTED must be returned.
868 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
869 @param[in] ProcessorNumber The handle number of AP that is to become the new
870 BSP. The range is from 0 to the total number of
871 logical processors minus 1. The total number of
872 logical processors can be retrieved by
873 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
874 @param[in] EnableAP Specifies the new state for the processor for
875 enabled, FALSE for disabled.
876 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
877 the new health status of the AP. This flag
878 corresponds to StatusFlag defined in
879 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
880 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
881 bits are ignored. If it is NULL, this parameter
884 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
885 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
886 prior to this service returning.
887 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
888 @retval EFI_DEVICE_ERROR The calling processor is an AP.
889 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
891 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
896 CpuMpServicesEnableDisableAP (
897 IN EFI_MP_SERVICES_PROTOCOL
*This
,
898 IN UINTN ProcessorNumber
,
900 IN UINT32
*HealthFlag OPTIONAL
904 return EFI_DEVICE_ERROR
;
907 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
908 return EFI_NOT_FOUND
;
911 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
912 return EFI_INVALID_PARAMETER
;
915 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
916 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
917 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
918 return EFI_UNSUPPORTED
;
920 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
923 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0 ) {
924 gMPSystem
.NumberOfEnabledProcessors
++;
926 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_ENABLED_BIT
;
928 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == PROCESSOR_ENABLED_BIT
) {
929 gMPSystem
.NumberOfEnabledProcessors
--;
931 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_ENABLED_BIT
;
934 if (HealthFlag
!= NULL
) {
935 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_HEALTH_STATUS_BIT
;
936 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= (*HealthFlag
& PROCESSOR_HEALTH_STATUS_BIT
);
944 This return the handle number for the calling processor. This service may be
945 called from the BSP and APs.
947 This service returns the processor handle number for the calling processor.
948 The returned value is in the range from 0 to the total number of logical
949 processors minus 1. The total number of logical processors can be retrieved
950 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
951 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
952 is returned. Otherwise, the current processors handle number is returned in
953 ProcessorNumber, and EFI_SUCCESS is returned.
955 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
956 @param[in] ProcessorNumber The handle number of AP that is to become the new
957 BSP. The range is from 0 to the total number of
958 logical processors minus 1. The total number of
959 logical processors can be retrieved by
960 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
962 @retval EFI_SUCCESS The current processor handle number was returned
964 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
969 CpuMpServicesWhoAmI (
970 IN EFI_MP_SERVICES_PROTOCOL
*This
,
971 OUT UINTN
*ProcessorNumber
977 if (ProcessorNumber
== NULL
) {
978 return EFI_INVALID_PARAMETER
;
981 ProcessorId
= gThread
->Self ();
982 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
983 if (gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
== ProcessorId
) {
988 *ProcessorNumber
= Index
;
994 EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate
= {
995 CpuMpServicesGetNumberOfProcessors
,
996 CpuMpServicesGetProcessorInfo
,
997 CpuMpServicesStartupAllAps
,
998 CpuMpServicesStartupThisAP
,
999 CpuMpServicesSwitchBSP
,
1000 CpuMpServicesEnableDisableAP
,
1007 If timeout occurs in StartupAllAps(), a timer is set, which invokes this
1008 procedure periodically to check whether all APs have finished.
1014 CpuCheckAllAPsStatus (
1019 UINTN ProcessorNumber
;
1021 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1022 PROCESSOR_DATA_BLOCK
*NextData
;
1024 PROCESSOR_STATE ProcessorState
;
1028 if (gMPSystem
.TimeoutActive
) {
1029 gMPSystem
.Timeout
-= CalculateAndStallInterval (gMPSystem
.Timeout
);
1032 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1033 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1034 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1039 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1040 // Skip Disabled processors
1044 // This is an Interrupt Service routine.
1045 // This can grab a lock that is held in a non-interrupt
1046 // context. Meaning deadlock. Which is a bad thing.
1047 // So, try lock it. If we can get it, cool, do our thing.
1048 // otherwise, just dump out & try again on the next iteration.
1049 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1050 if (EFI_ERROR(Status
)) {
1053 ProcessorState
= ProcessorData
->State
;
1054 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1056 switch (ProcessorState
) {
1057 case CPU_STATE_FINISHED
:
1058 if (gMPSystem
.SingleThread
) {
1059 Status
= GetNextBlockedNumber (&NextNumber
);
1060 if (!EFI_ERROR (Status
)) {
1061 NextData
= &gMPSystem
.ProcessorData
[NextNumber
];
1063 gThread
->MutexLock (NextData
->StateLock
);
1064 NextData
->State
= CPU_STATE_READY
;
1065 gThread
->MutexUnlock (NextData
->StateLock
);
1067 SetApProcedure (NextData
, gMPSystem
.Procedure
, gMPSystem
.ProcedureArgument
);
1071 gThread
->MutexLock (ProcessorData
->StateLock
);
1072 ProcessorData
->State
= CPU_STATE_IDLE
;
1073 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1074 gMPSystem
.FinishCount
++;
1082 if (gMPSystem
.TimeoutActive
&& gMPSystem
.Timeout
== 0) {
1086 if (gMPSystem
.FailedList
!= NULL
) {
1087 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1088 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1089 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1094 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1095 // Skip Disabled processors
1100 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1101 if (EFI_ERROR(Status
)) {
1104 ProcessorState
= ProcessorData
->State
;
1105 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1107 if (ProcessorState
!= CPU_STATE_IDLE
) {
1108 // If we are retrying make sure we don't double count
1109 for (Cpu
= 0, Found
= FALSE
; Cpu
< gMPSystem
.NumberOfProcessors
; Cpu
++) {
1110 if (gMPSystem
.FailedList
[Cpu
] == END_OF_CPU_LIST
) {
1113 if (gMPSystem
.FailedList
[ProcessorNumber
] == Cpu
) {
1119 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Cpu
;
1124 // Force terminal exit
1125 gMPSystem
.FinishCount
= gMPSystem
.StartCount
;
1128 if (gMPSystem
.FinishCount
!= gMPSystem
.StartCount
) {
1133 gMPSystem
.CheckAllAPsEvent
,
1138 if (gMPSystem
.FailedListIndex
== 0) {
1139 if (gMPSystem
.FailedList
!= NULL
) {
1140 FreePool (gMPSystem
.FailedList
);
1141 gMPSystem
.FailedList
= NULL
;
1145 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1152 CpuCheckThisAPStatus (
1158 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1159 PROCESSOR_STATE ProcessorState
;
1161 ProcessorData
= (PROCESSOR_DATA_BLOCK
*) Context
;
1164 // This is an Interrupt Service routine.
1165 // that can grab a lock that is held in a non-interrupt
1166 // context. Meaning deadlock. Which is a badddd thing.
1167 // So, try lock it. If we can get it, cool, do our thing.
1168 // otherwise, just dump out & try again on the next iteration.
1170 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1171 if (EFI_ERROR(Status
)) {
1174 ProcessorState
= ProcessorData
->State
;
1175 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1177 if (ProcessorState
== CPU_STATE_FINISHED
) {
1178 Status
= gBS
->SetTimer (ProcessorData
->CheckThisAPEvent
, TimerCancel
, 0);
1179 ASSERT_EFI_ERROR (Status
);
1181 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1182 ASSERT_EFI_ERROR (Status
);
1184 gThread
->MutexLock (ProcessorData
->StateLock
);
1185 ProcessorData
->State
= CPU_STATE_IDLE
;
1186 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1194 This function is called by all processors (both BSP and AP) once and collects MP related data
1196 MPSystemData - Pointer to the data structure containing MP related data
1197 BSP - TRUE if the CPU is BSP
1199 EFI_SUCCESS - Data for the processor collected and filled in
1203 FillInProcessorInformation (
1205 IN UINTN ProcessorNumber
1208 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.ProcessorId
= gThread
->Self ();
1209 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
1211 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
1214 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Package
= (UINT32
) ProcessorNumber
;
1215 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Core
= 0;
1216 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Thread
= 0;
1217 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= BSP
? CPU_STATE_BUSY
: CPU_STATE_IDLE
;
1219 gMPSystem
.ProcessorData
[ProcessorNumber
].Procedure
= NULL
;
1220 gMPSystem
.ProcessorData
[ProcessorNumber
].Parameter
= NULL
;
1221 gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
= gThread
->MutexInit ();
1222 gMPSystem
.ProcessorData
[ProcessorNumber
].ProcedureLock
= gThread
->MutexInit ();
1229 CpuDriverApIdolLoop (
1233 EFI_AP_PROCEDURE Procedure
;
1235 UINTN ProcessorNumber
;
1236 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1238 ProcessorNumber
= (UINTN
)Context
;
1239 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1241 ProcessorData
->Info
.ProcessorId
= gThread
->Self ();
1245 // Make a local copy on the stack to be extra safe
1247 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1248 Procedure
= ProcessorData
->Procedure
;
1249 Parameter
= ProcessorData
->Parameter
;
1250 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1252 if (Procedure
!= NULL
) {
1253 gThread
->MutexLock (ProcessorData
->StateLock
);
1254 ProcessorData
->State
= CPU_STATE_BUSY
;
1255 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1257 Procedure (Parameter
);
1259 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1260 ProcessorData
->Procedure
= NULL
;
1261 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1263 gThread
->MutexLock (ProcessorData
->StateLock
);
1264 ProcessorData
->State
= CPU_STATE_FINISHED
;
1265 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1268 // Poll 5 times a seconds, 200ms
1269 // Don't want to burn too many system resources doing nothing.
1270 gEmuThunk
->Sleep (200 * 1000);
1278 InitializeMpSystemData (
1279 IN UINTN NumberOfProcessors
1287 // Clear the data structure area first.
1289 ZeroMem (&gMPSystem
, sizeof (MP_SYSTEM_DATA
));
1292 // First BSP fills and inits all known values, including it's own records.
1294 gMPSystem
.NumberOfProcessors
= NumberOfProcessors
;
1295 gMPSystem
.NumberOfEnabledProcessors
= NumberOfProcessors
;
1297 gMPSystem
.ProcessorData
= AllocateZeroPool (gMPSystem
.NumberOfProcessors
* sizeof (PROCESSOR_DATA_BLOCK
));
1298 ASSERT (gMPSystem
.ProcessorData
!= NULL
);
1300 FillInProcessorInformation (TRUE
, 0);
1302 Status
= gBS
->CreateEvent (
1303 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1305 CpuCheckAllAPsStatus
,
1307 &gMPSystem
.CheckAllAPsEvent
1309 ASSERT_EFI_ERROR (Status
);
1312 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
1313 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1318 FillInProcessorInformation (FALSE
, Index
);
1320 Status
= gThread
->CreateThread (
1321 (VOID
*)&gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
,
1323 CpuDriverApIdolLoop
,
1328 Status
= gBS
->CreateEvent (
1329 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1331 CpuCheckThisAPStatus
,
1332 (VOID
*) &gMPSystem
.ProcessorData
[Index
],
1333 &gMPSystem
.ProcessorData
[Index
].CheckThisAPEvent
1343 Invoke a notification event
1345 @param Event Event whose notification function is being invoked.
1346 @param Context The pointer to the notification function's context,
1347 which is implementation-dependent.
1352 CpuReadToBootFunction (
1369 EMU_IO_THUNK_PROTOCOL
*IoThunk
;
1371 *MaxCpus
= 1; // BSP
1372 IoThunk
= GetIoThunkInstance (&gEmuThreadThunkProtocolGuid
, 0);
1373 if (IoThunk
!= NULL
) {
1374 Status
= IoThunk
->Open (IoThunk
);
1375 if (!EFI_ERROR (Status
)) {
1376 if (IoThunk
->ConfigString
!= NULL
) {
1377 *MaxCpus
+= StrDecimalToUintn (IoThunk
->ConfigString
);
1378 gThread
= IoThunk
->Interface
;
1383 if (*MaxCpus
== 1) {
1384 // We are not MP so nothing to do
1388 gPollInterval
= (UINTN
) PcdGet64 (PcdEmuMpServicesPollingInterval
);
1390 Status
= InitializeMpSystemData (*MaxCpus
);
1391 if (EFI_ERROR (Status
)) {
1395 Status
= EfiCreateEventReadyToBootEx (TPL_CALLBACK
, CpuReadToBootFunction
, NULL
, &gReadToBootEvent
);
1396 ASSERT_EFI_ERROR (Status
);
1399 // Now install the MP services protocol.
1402 Status
= gBS
->InstallMultipleProtocolInterfaces (
1404 &gEfiMpServiceProtocolGuid
, &mMpServicesTemplate
,