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 SPDX-License-Identifier: BSD-2-Clause-Patent
38 #include "CpuDriver.h"
41 MP_SYSTEM_DATA gMPSystem
;
42 EMU_THREAD_THUNK_PROTOCOL
*gThread
= NULL
;
43 EFI_EVENT gReadToBootEvent
;
44 BOOLEAN gReadToBoot
= FALSE
;
54 UINTN ProcessorNumber
;
56 Status
= CpuMpServicesWhoAmI (&mMpServicesTemplate
, &ProcessorNumber
);
57 if (EFI_ERROR (Status
)) {
61 return (gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0;
67 IN PROCESSOR_DATA_BLOCK
*Processor
,
68 IN EFI_AP_PROCEDURE Procedure
,
69 IN VOID
*ProcedureArgument
72 gThread
->MutexLock (Processor
->ProcedureLock
);
73 Processor
->Parameter
= ProcedureArgument
;
74 Processor
->Procedure
= Procedure
;
75 gThread
->MutexUnlock (Processor
->ProcedureLock
);
80 GetNextBlockedNumber (
85 PROCESSOR_STATE ProcessorState
;
86 PROCESSOR_DATA_BLOCK
*Data
;
88 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
89 Data
= &gMPSystem
.ProcessorData
[Number
];
90 if ((Data
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
95 gThread
->MutexLock (Data
->StateLock
);
96 ProcessorState
= Data
->State
;
97 gThread
->MutexUnlock (Data
->StateLock
);
99 if (ProcessorState
== CPU_STATE_BLOCKED
) {
100 *NextNumber
= Number
;
105 return EFI_NOT_FOUND
;
109 * Calculated and stalled the interval time by BSP to check whether
110 * the APs have finished.
112 * @param[in] Timeout The time limit in microseconds for
113 * APs to return from Procedure.
115 * @retval StallTime Time of execution stall.
118 CalculateAndStallInterval (
124 if (Timeout
< gPollInterval
&& Timeout
!= 0) {
127 StallTime
= gPollInterval
;
129 gBS
->Stall (StallTime
);
135 This service retrieves the number of logical processor in the platform
136 and the number of those logical processors that are enabled on this boot.
137 This service may only be called from the BSP.
139 This function is used to retrieve the following information:
140 - The number of logical processors that are present in the system.
141 - The number of enabled logical processors in the system at the instant
144 Because MP Service Protocol provides services to enable and disable processors
145 dynamically, the number of enabled logical processors may vary during the
146 course of a boot session.
148 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
149 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
150 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
151 is returned in NumberOfProcessors, the number of currently enabled processor
152 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
154 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
156 @param[out] NumberOfProcessors Pointer to the total number of logical
157 processors in the system, including the BSP
159 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
160 processors that exist in system, including
163 @retval EFI_SUCCESS The number of logical processors and enabled
164 logical processors was retrieved.
165 @retval EFI_DEVICE_ERROR The calling processor is an AP.
166 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
167 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
172 CpuMpServicesGetNumberOfProcessors (
173 IN EFI_MP_SERVICES_PROTOCOL
*This
,
174 OUT UINTN
*NumberOfProcessors
,
175 OUT UINTN
*NumberOfEnabledProcessors
178 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
179 return EFI_INVALID_PARAMETER
;
183 return EFI_DEVICE_ERROR
;
186 *NumberOfProcessors
= gMPSystem
.NumberOfProcessors
;
187 *NumberOfEnabledProcessors
= gMPSystem
.NumberOfEnabledProcessors
;
194 Gets detailed MP-related information on the requested processor at the
195 instant this call is made. This service may only be called from the BSP.
197 This service retrieves detailed MP-related information about any processor
198 on the platform. Note the following:
199 - The processor information may change during the course of a boot session.
200 - The information presented here is entirely MP related.
202 Information regarding the number of caches and their sizes, frequency of operation,
203 slot numbers is all considered platform-related information and is not provided
206 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
208 @param[in] ProcessorNumber The handle number of processor.
209 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
210 the requested processor is deposited.
212 @retval EFI_SUCCESS Processor information was returned.
213 @retval EFI_DEVICE_ERROR The calling processor is an AP.
214 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
215 @retval EFI_NOT_FOUND The processor with the handle specified by
216 ProcessorNumber does not exist in the platform.
221 CpuMpServicesGetProcessorInfo (
222 IN EFI_MP_SERVICES_PROTOCOL
*This
,
223 IN UINTN ProcessorNumber
,
224 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
227 if (ProcessorInfoBuffer
== NULL
) {
228 return EFI_INVALID_PARAMETER
;
232 return EFI_DEVICE_ERROR
;
235 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
236 return EFI_NOT_FOUND
;
239 CopyMem (ProcessorInfoBuffer
, &gMPSystem
.ProcessorData
[ProcessorNumber
], sizeof (EFI_PROCESSOR_INFORMATION
));
245 This service executes a caller provided function on all enabled APs. APs can
246 run either simultaneously or one at a time in sequence. This service supports
247 both blocking and non-blocking requests. The non-blocking requests use EFI
248 events so the BSP can detect when the APs have finished. This service may only
249 be called from the BSP.
251 This function is used to dispatch all the enabled APs to the function specified
252 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
253 immediately and Procedure is not started on any AP.
255 If SingleThread is TRUE, all the enabled APs execute the function specified by
256 Procedure one by one, in ascending order of processor handle number. Otherwise,
257 all the enabled APs execute the function specified by Procedure simultaneously.
259 If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all
260 APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking
261 mode, and the BSP returns from this service without waiting for APs. If a
262 non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
263 is signaled, then EFI_UNSUPPORTED must be returned.
265 If the timeout specified by TimeoutInMicroseconds expires before all APs return
266 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
267 are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
268 and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its
269 content points to the list of processor handle numbers in which Procedure was
272 Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
273 to make sure that the nature of the code that is executed on the BSP and the
274 dispatched APs is well controlled. The MP Services Protocol does not guarantee
275 that the Procedure function is MP-safe. Hence, the tasks that can be run in
276 parallel are limited to certain independent tasks and well-controlled exclusive
277 code. EFI services and protocols may not be called by APs unless otherwise
280 In blocking execution mode, BSP waits until all APs finish or
281 TimeoutInMicroseconds expires.
283 In non-blocking execution mode, BSP is freed to return to the caller and then
284 proceed to the next task without having to wait for APs. The following
285 sequence needs to occur in a non-blocking execution mode:
287 -# The caller that intends to use this MP Services Protocol in non-blocking
288 mode creates WaitEvent by calling the EFI CreateEvent() service. The caller
289 invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent
290 is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests
291 the function specified by Procedure to be started on all the enabled APs,
292 and releases the BSP to continue with other tasks.
293 -# The caller can use the CheckEvent() and WaitForEvent() services to check
294 the state of the WaitEvent created in step 1.
295 -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP
296 Service signals WaitEvent by calling the EFI SignalEvent() function. If
297 FailedCpuList is not NULL, its content is available when WaitEvent is
298 signaled. If all APs returned from Procedure prior to the timeout, then
299 FailedCpuList is set to NULL. If not all APs return from Procedure before
300 the timeout, then FailedCpuList is filled in with the list of the failed
301 APs. The buffer is allocated by MP Service Protocol using AllocatePool().
302 It is the caller's responsibility to free the buffer with FreePool() service.
303 -# This invocation of SignalEvent() function informs the caller that invoked
304 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed
305 the specified task or a timeout occurred. The contents of FailedCpuList
306 can be examined to determine which APs did not complete the specified task
307 prior to the timeout.
309 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
311 @param[in] Procedure A pointer to the function to be run on
312 enabled APs of the system. See type
314 @param[in] SingleThread If TRUE, then all the enabled APs execute
315 the function specified by Procedure one by
316 one, in ascending order of processor handle
317 number. If FALSE, then all the enabled APs
318 execute the function specified by Procedure
320 @param[in] WaitEvent The event created by the caller with CreateEvent()
321 service. If it is NULL, then execute in
322 blocking mode. BSP waits until all APs finish
323 or TimeoutInMicroseconds expires. If it's
324 not NULL, then execute in non-blocking mode.
325 BSP requests the function specified by
326 Procedure to be started on all the enabled
327 APs, and go on executing immediately. If
328 all return from Procedure, or TimeoutInMicroseconds
329 expires, this event is signaled. The BSP
330 can use the CheckEvent() or WaitForEvent()
331 services to check the state of event. Type
332 EFI_EVENT is defined in CreateEvent() in
333 the Unified Extensible Firmware Interface
335 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
336 APs to return from Procedure, either for
337 blocking or non-blocking mode. Zero means
338 infinity. If the timeout expires before
339 all APs return from Procedure, then Procedure
340 on the failed APs is terminated. All enabled
341 APs are available for next function assigned
342 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
343 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
344 If the timeout expires in blocking mode,
345 BSP returns EFI_TIMEOUT. If the timeout
346 expires in non-blocking mode, WaitEvent
347 is signaled with SignalEvent().
348 @param[in] ProcedureArgument The parameter passed into Procedure for
350 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
351 if all APs finish successfully, then its
352 content is set to NULL. If not all APs
353 finish before timeout expires, then its
354 content is set to address of the buffer
355 holding handle numbers of the failed APs.
356 The buffer is allocated by MP Service Protocol,
357 and it's the caller's responsibility to
358 free the buffer with FreePool() service.
359 In blocking mode, it is ready for consumption
360 when the call returns. In non-blocking mode,
361 it is ready when WaitEvent is signaled. The
362 list of failed CPU is terminated by
365 @retval EFI_SUCCESS In blocking mode, all APs have finished before
367 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
369 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
370 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
372 @retval EFI_DEVICE_ERROR Caller processor is AP.
373 @retval EFI_NOT_STARTED No enabled APs exist in the system.
374 @retval EFI_NOT_READY Any enabled APs are busy.
375 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
376 all enabled APs have finished.
377 @retval EFI_INVALID_PARAMETER Procedure is NULL.
382 CpuMpServicesStartupAllAps (
383 IN EFI_MP_SERVICES_PROTOCOL
*This
,
384 IN EFI_AP_PROCEDURE Procedure
,
385 IN BOOLEAN SingleThread
,
386 IN EFI_EVENT WaitEvent OPTIONAL
,
387 IN UINTN TimeoutInMicroseconds
,
388 IN VOID
*ProcedureArgument OPTIONAL
,
389 OUT UINTN
**FailedCpuList OPTIONAL
393 PROCESSOR_DATA_BLOCK
*ProcessorData
;
396 PROCESSOR_STATE APInitialState
;
397 PROCESSOR_STATE ProcessorState
;
402 return EFI_DEVICE_ERROR
;
405 if (gMPSystem
.NumberOfProcessors
== 1) {
406 return EFI_NOT_STARTED
;
409 if (Procedure
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 if ((WaitEvent
!= NULL
) && gReadToBoot
) {
414 return EFI_UNSUPPORTED
;
417 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
418 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
419 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
424 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
425 // Skip Disabled processors
428 gThread
->MutexLock(ProcessorData
->StateLock
);
429 if (ProcessorData
->State
!= CPU_STATE_IDLE
) {
430 gThread
->MutexUnlock (ProcessorData
->StateLock
);
431 return EFI_NOT_READY
;
433 gThread
->MutexUnlock(ProcessorData
->StateLock
);
436 if (FailedCpuList
!= NULL
) {
437 gMPSystem
.FailedList
= AllocatePool ((gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
));
438 if (gMPSystem
.FailedList
== NULL
) {
439 return EFI_OUT_OF_RESOURCES
;
441 SetMemN (gMPSystem
.FailedList
, (gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
), END_OF_CPU_LIST
);
442 gMPSystem
.FailedListIndex
= 0;
443 *FailedCpuList
= gMPSystem
.FailedList
;
446 Timeout
= TimeoutInMicroseconds
;
448 ProcessorData
= NULL
;
450 gMPSystem
.FinishCount
= 0;
451 gMPSystem
.StartCount
= 0;
452 gMPSystem
.SingleThread
= SingleThread
;
453 APInitialState
= CPU_STATE_READY
;
455 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
456 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
458 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
463 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
464 // Skip Disabled processors
465 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Number
;
470 // Get APs prepared, and put failing APs into FailedCpuList
471 // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready
472 // state 1 by 1, until the previous 1 finished its task
473 // if not "SingleThread", all APs are put to ready state from the beginning
475 gThread
->MutexLock(ProcessorData
->StateLock
);
476 ASSERT (ProcessorData
->State
== CPU_STATE_IDLE
);
477 ProcessorData
->State
= APInitialState
;
478 gThread
->MutexUnlock (ProcessorData
->StateLock
);
480 gMPSystem
.StartCount
++;
482 APInitialState
= CPU_STATE_BLOCKED
;
486 if (WaitEvent
!= NULL
) {
487 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
488 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
489 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
494 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
495 // Skip Disabled processors
499 gThread
->MutexLock (ProcessorData
->StateLock
);
500 ProcessorState
= ProcessorData
->State
;
501 gThread
->MutexUnlock (ProcessorData
->StateLock
);
503 if (ProcessorState
== CPU_STATE_READY
) {
504 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
509 // Save data into private data structure, and create timer to poll AP state before exiting
511 gMPSystem
.Procedure
= Procedure
;
512 gMPSystem
.ProcedureArgument
= ProcedureArgument
;
513 gMPSystem
.WaitEvent
= WaitEvent
;
514 gMPSystem
.Timeout
= TimeoutInMicroseconds
;
515 gMPSystem
.TimeoutActive
= (BOOLEAN
)(TimeoutInMicroseconds
!= 0);
516 Status
= gBS
->SetTimer (
517 gMPSystem
.CheckAllAPsEvent
,
526 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
527 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
528 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
533 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
534 // Skip Disabled processors
538 gThread
->MutexLock (ProcessorData
->StateLock
);
539 ProcessorState
= ProcessorData
->State
;
540 gThread
->MutexUnlock (ProcessorData
->StateLock
);
542 switch (ProcessorState
) {
543 case CPU_STATE_READY
:
544 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
547 case CPU_STATE_FINISHED
:
548 gMPSystem
.FinishCount
++;
550 Status
= GetNextBlockedNumber (&NextNumber
);
551 if (!EFI_ERROR (Status
)) {
552 gThread
->MutexLock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
553 gMPSystem
.ProcessorData
[NextNumber
].State
= CPU_STATE_READY
;
554 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
558 gThread
->MutexLock (ProcessorData
->StateLock
);
559 ProcessorData
->State
= CPU_STATE_IDLE
;
560 gThread
->MutexUnlock (ProcessorData
->StateLock
);
569 if (gMPSystem
.FinishCount
== gMPSystem
.StartCount
) {
570 Status
= EFI_SUCCESS
;
574 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
575 Status
= EFI_TIMEOUT
;
579 Timeout
-= CalculateAndStallInterval (Timeout
);
583 if (FailedCpuList
!= NULL
) {
584 if (gMPSystem
.FailedListIndex
== 0) {
585 FreePool (*FailedCpuList
);
586 *FailedCpuList
= NULL
;
595 This service lets the caller get one enabled AP to execute a caller-provided
596 function. The caller can request the BSP to either wait for the completion
597 of the AP or just proceed with the next task by using the EFI event mechanism.
598 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
599 execution support. This service may only be called from the BSP.
601 This function is used to dispatch one enabled AP to the function specified by
602 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
603 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
604 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
605 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
606 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
607 then EFI_UNSUPPORTED must be returned.
609 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
610 from Procedure, then execution of Procedure by the AP is terminated. The AP is
611 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
612 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
614 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
616 @param[in] Procedure A pointer to the function to be run on
617 enabled APs of the system. See type
619 @param[in] ProcessorNumber The handle number of the AP. The range is
620 from 0 to the total number of logical
621 processors minus 1. The total number of
622 logical processors can be retrieved by
623 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
624 @param[in] WaitEvent The event created by the caller with CreateEvent()
625 service. If it is NULL, then execute in
626 blocking mode. BSP waits until all APs finish
627 or TimeoutInMicroseconds expires. If it's
628 not NULL, then execute in non-blocking mode.
629 BSP requests the function specified by
630 Procedure to be started on all the enabled
631 APs, and go on executing immediately. If
632 all return from Procedure or TimeoutInMicroseconds
633 expires, this event is signaled. The BSP
634 can use the CheckEvent() or WaitForEvent()
635 services to check the state of event. Type
636 EFI_EVENT is defined in CreateEvent() in
637 the Unified Extensible Firmware Interface
639 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
640 APs to return from Procedure, either for
641 blocking or non-blocking mode. Zero means
642 infinity. If the timeout expires before
643 all APs return from Procedure, then Procedure
644 on the failed APs is terminated. All enabled
645 APs are available for next function assigned
646 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
647 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
648 If the timeout expires in blocking mode,
649 BSP returns EFI_TIMEOUT. If the timeout
650 expires in non-blocking mode, WaitEvent
651 is signaled with SignalEvent().
652 @param[in] ProcedureArgument The parameter passed into Procedure for
654 @param[out] Finished If NULL, this parameter is ignored. In
655 blocking mode, this parameter is ignored.
656 In non-blocking mode, if AP returns from
657 Procedure before the timeout expires, its
658 content is set to TRUE. Otherwise, the
659 value is set to FALSE. The caller can
660 determine if the AP returned from Procedure
661 by evaluating this value.
663 @retval EFI_SUCCESS In blocking mode, specified AP finished before
665 @retval EFI_SUCCESS In non-blocking mode, the function has been
666 dispatched to specified AP.
667 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
668 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
670 @retval EFI_DEVICE_ERROR The calling processor is an AP.
671 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
672 the specified AP has finished.
673 @retval EFI_NOT_READY The specified AP is busy.
674 @retval EFI_NOT_FOUND The processor with the handle specified by
675 ProcessorNumber does not exist.
676 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
677 @retval EFI_INVALID_PARAMETER Procedure is NULL.
682 CpuMpServicesStartupThisAP (
683 IN EFI_MP_SERVICES_PROTOCOL
*This
,
684 IN EFI_AP_PROCEDURE Procedure
,
685 IN UINTN ProcessorNumber
,
686 IN EFI_EVENT WaitEvent OPTIONAL
,
687 IN UINTN TimeoutInMicroseconds
,
688 IN VOID
*ProcedureArgument OPTIONAL
,
689 OUT BOOLEAN
*Finished OPTIONAL
695 return EFI_DEVICE_ERROR
;
698 if (Procedure
== NULL
) {
699 return EFI_INVALID_PARAMETER
;
702 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
703 return EFI_NOT_FOUND
;
706 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
707 return EFI_INVALID_PARAMETER
;
710 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
711 return EFI_INVALID_PARAMETER
;
714 gThread
->MutexLock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
715 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
716 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
717 return EFI_NOT_READY
;
719 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
721 if ((WaitEvent
!= NULL
) && gReadToBoot
) {
722 return EFI_UNSUPPORTED
;
725 Timeout
= TimeoutInMicroseconds
;
727 gMPSystem
.StartCount
= 1;
728 gMPSystem
.FinishCount
= 0;
730 SetApProcedure (&gMPSystem
.ProcessorData
[ProcessorNumber
], Procedure
, ProcedureArgument
);
732 if (WaitEvent
!= NULL
) {
734 gMPSystem
.WaitEvent
= WaitEvent
;
736 gMPSystem
.ProcessorData
[ProcessorNumber
].CheckThisAPEvent
,
745 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
746 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
== CPU_STATE_FINISHED
) {
747 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= CPU_STATE_IDLE
;
748 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
752 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
754 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
758 Timeout
-= CalculateAndStallInterval (Timeout
);
767 This service switches the requested AP to be the BSP from that point onward.
768 This service changes the BSP for all purposes. This call can only be performed
771 This service switches the requested AP to be the BSP from that point onward.
772 This service changes the BSP for all purposes. The new BSP can take over the
773 execution of the old BSP and continue seamlessly from where the old one left
774 off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
777 If the BSP cannot be switched prior to the return from this service, then
778 EFI_UNSUPPORTED must be returned.
780 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
781 @param[in] ProcessorNumber The handle number of AP that is to become the new
782 BSP. The range is from 0 to the total number of
783 logical processors minus 1. The total number of
784 logical processors can be retrieved by
785 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
786 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
787 enabled AP. Otherwise, it will be disabled.
789 @retval EFI_SUCCESS BSP successfully switched.
790 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
791 this service returning.
792 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
793 @retval EFI_SUCCESS The calling processor is an AP.
794 @retval EFI_NOT_FOUND The processor with the handle specified by
795 ProcessorNumber does not exist.
796 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
798 @retval EFI_NOT_READY The specified AP is busy.
803 CpuMpServicesSwitchBSP (
804 IN EFI_MP_SERVICES_PROTOCOL
*This
,
805 IN UINTN ProcessorNumber
,
806 IN BOOLEAN EnableOldBSP
812 return EFI_DEVICE_ERROR
;
815 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
816 return EFI_NOT_FOUND
;
819 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
820 return EFI_INVALID_PARAMETER
;
823 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
824 return EFI_INVALID_PARAMETER
;
827 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
828 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
832 ASSERT (Index
!= gMPSystem
.NumberOfProcessors
);
834 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
835 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
836 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
837 return EFI_NOT_READY
;
839 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
841 // Skip for now as we need switch a bunch of stack stuff around and it's complex
842 // May not be worth it?
843 return EFI_NOT_READY
;
848 This service lets the caller enable or disable an AP from this point onward.
849 This service may only be called from the BSP.
851 This service allows the caller enable or disable an AP from this point onward.
852 The caller can optionally specify the health status of the AP by Health. If
853 an AP is being disabled, then the state of the disabled AP is implementation
854 dependent. If an AP is enabled, then the implementation must guarantee that a
855 complete initialization sequence is performed on the AP, so the AP is in a state
856 that is compatible with an MP operating system. This service may not be supported
857 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
859 If the enable or disable AP operation cannot be completed prior to the return
860 from this service, then EFI_UNSUPPORTED must be returned.
862 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
863 @param[in] ProcessorNumber The handle number of AP that is to become the new
864 BSP. The range is from 0 to the total number of
865 logical processors minus 1. The total number of
866 logical processors can be retrieved by
867 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
868 @param[in] EnableAP Specifies the new state for the processor for
869 enabled, FALSE for disabled.
870 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
871 the new health status of the AP. This flag
872 corresponds to StatusFlag defined in
873 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
874 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
875 bits are ignored. If it is NULL, this parameter
878 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
879 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
880 prior to this service returning.
881 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
882 @retval EFI_DEVICE_ERROR The calling processor is an AP.
883 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
885 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
890 CpuMpServicesEnableDisableAP (
891 IN EFI_MP_SERVICES_PROTOCOL
*This
,
892 IN UINTN ProcessorNumber
,
894 IN UINT32
*HealthFlag OPTIONAL
898 return EFI_DEVICE_ERROR
;
901 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
902 return EFI_NOT_FOUND
;
905 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
906 return EFI_INVALID_PARAMETER
;
909 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
910 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
911 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
912 return EFI_UNSUPPORTED
;
914 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
917 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0 ) {
918 gMPSystem
.NumberOfEnabledProcessors
++;
920 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_ENABLED_BIT
;
922 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == PROCESSOR_ENABLED_BIT
) {
923 gMPSystem
.NumberOfEnabledProcessors
--;
925 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_ENABLED_BIT
;
928 if (HealthFlag
!= NULL
) {
929 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_HEALTH_STATUS_BIT
;
930 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= (*HealthFlag
& PROCESSOR_HEALTH_STATUS_BIT
);
938 This return the handle number for the calling processor. This service may be
939 called from the BSP and APs.
941 This service returns the processor handle number for the calling processor.
942 The returned value is in the range from 0 to the total number of logical
943 processors minus 1. The total number of logical processors can be retrieved
944 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
945 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
946 is returned. Otherwise, the current processors handle number is returned in
947 ProcessorNumber, and EFI_SUCCESS is returned.
949 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
950 @param[in] ProcessorNumber The handle number of AP that is to become the new
951 BSP. The range is from 0 to the total number of
952 logical processors minus 1. The total number of
953 logical processors can be retrieved by
954 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
956 @retval EFI_SUCCESS The current processor handle number was returned
958 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
963 CpuMpServicesWhoAmI (
964 IN EFI_MP_SERVICES_PROTOCOL
*This
,
965 OUT UINTN
*ProcessorNumber
971 if (ProcessorNumber
== NULL
) {
972 return EFI_INVALID_PARAMETER
;
975 ProcessorId
= gThread
->Self ();
976 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
977 if (gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
== ProcessorId
) {
982 *ProcessorNumber
= Index
;
988 EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate
= {
989 CpuMpServicesGetNumberOfProcessors
,
990 CpuMpServicesGetProcessorInfo
,
991 CpuMpServicesStartupAllAps
,
992 CpuMpServicesStartupThisAP
,
993 CpuMpServicesSwitchBSP
,
994 CpuMpServicesEnableDisableAP
,
1001 If timeout occurs in StartupAllAps(), a timer is set, which invokes this
1002 procedure periodically to check whether all APs have finished.
1008 CpuCheckAllAPsStatus (
1013 UINTN ProcessorNumber
;
1015 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1016 PROCESSOR_DATA_BLOCK
*NextData
;
1018 PROCESSOR_STATE ProcessorState
;
1022 if (gMPSystem
.TimeoutActive
) {
1023 gMPSystem
.Timeout
-= CalculateAndStallInterval (gMPSystem
.Timeout
);
1026 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1027 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1028 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1033 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1034 // Skip Disabled processors
1038 // This is an Interrupt Service routine.
1039 // This can grab a lock that is held in a non-interrupt
1040 // context. Meaning deadlock. Which is a bad thing.
1041 // So, try lock it. If we can get it, cool, do our thing.
1042 // otherwise, just dump out & try again on the next iteration.
1043 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1044 if (EFI_ERROR(Status
)) {
1047 ProcessorState
= ProcessorData
->State
;
1048 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1050 switch (ProcessorState
) {
1051 case CPU_STATE_FINISHED
:
1052 if (gMPSystem
.SingleThread
) {
1053 Status
= GetNextBlockedNumber (&NextNumber
);
1054 if (!EFI_ERROR (Status
)) {
1055 NextData
= &gMPSystem
.ProcessorData
[NextNumber
];
1057 gThread
->MutexLock (NextData
->StateLock
);
1058 NextData
->State
= CPU_STATE_READY
;
1059 gThread
->MutexUnlock (NextData
->StateLock
);
1061 SetApProcedure (NextData
, gMPSystem
.Procedure
, gMPSystem
.ProcedureArgument
);
1065 gThread
->MutexLock (ProcessorData
->StateLock
);
1066 ProcessorData
->State
= CPU_STATE_IDLE
;
1067 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1068 gMPSystem
.FinishCount
++;
1076 if (gMPSystem
.TimeoutActive
&& gMPSystem
.Timeout
== 0) {
1080 if (gMPSystem
.FailedList
!= NULL
) {
1081 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1082 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1083 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1088 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1089 // Skip Disabled processors
1094 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1095 if (EFI_ERROR(Status
)) {
1098 ProcessorState
= ProcessorData
->State
;
1099 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1101 if (ProcessorState
!= CPU_STATE_IDLE
) {
1102 // If we are retrying make sure we don't double count
1103 for (Cpu
= 0, Found
= FALSE
; Cpu
< gMPSystem
.NumberOfProcessors
; Cpu
++) {
1104 if (gMPSystem
.FailedList
[Cpu
] == END_OF_CPU_LIST
) {
1107 if (gMPSystem
.FailedList
[ProcessorNumber
] == Cpu
) {
1113 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Cpu
;
1118 // Force terminal exit
1119 gMPSystem
.FinishCount
= gMPSystem
.StartCount
;
1122 if (gMPSystem
.FinishCount
!= gMPSystem
.StartCount
) {
1127 gMPSystem
.CheckAllAPsEvent
,
1132 if (gMPSystem
.FailedListIndex
== 0) {
1133 if (gMPSystem
.FailedList
!= NULL
) {
1134 FreePool (gMPSystem
.FailedList
);
1135 gMPSystem
.FailedList
= NULL
;
1139 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1146 CpuCheckThisAPStatus (
1152 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1153 PROCESSOR_STATE ProcessorState
;
1155 ProcessorData
= (PROCESSOR_DATA_BLOCK
*) Context
;
1158 // This is an Interrupt Service routine.
1159 // that can grab a lock that is held in a non-interrupt
1160 // context. Meaning deadlock. Which is a badddd thing.
1161 // So, try lock it. If we can get it, cool, do our thing.
1162 // otherwise, just dump out & try again on the next iteration.
1164 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1165 if (EFI_ERROR(Status
)) {
1168 ProcessorState
= ProcessorData
->State
;
1169 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1171 if (ProcessorState
== CPU_STATE_FINISHED
) {
1172 Status
= gBS
->SetTimer (ProcessorData
->CheckThisAPEvent
, TimerCancel
, 0);
1173 ASSERT_EFI_ERROR (Status
);
1175 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1176 ASSERT_EFI_ERROR (Status
);
1178 gThread
->MutexLock (ProcessorData
->StateLock
);
1179 ProcessorData
->State
= CPU_STATE_IDLE
;
1180 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1188 This function is called by all processors (both BSP and AP) once and collects MP related data
1190 MPSystemData - Pointer to the data structure containing MP related data
1191 BSP - TRUE if the CPU is BSP
1193 EFI_SUCCESS - Data for the processor collected and filled in
1197 FillInProcessorInformation (
1199 IN UINTN ProcessorNumber
1202 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.ProcessorId
= gThread
->Self ();
1203 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
1205 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
1208 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Package
= (UINT32
) ProcessorNumber
;
1209 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Core
= 0;
1210 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Thread
= 0;
1211 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= BSP
? CPU_STATE_BUSY
: CPU_STATE_IDLE
;
1213 gMPSystem
.ProcessorData
[ProcessorNumber
].Procedure
= NULL
;
1214 gMPSystem
.ProcessorData
[ProcessorNumber
].Parameter
= NULL
;
1215 gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
= gThread
->MutexInit ();
1216 gMPSystem
.ProcessorData
[ProcessorNumber
].ProcedureLock
= gThread
->MutexInit ();
1223 CpuDriverApIdolLoop (
1227 EFI_AP_PROCEDURE Procedure
;
1229 UINTN ProcessorNumber
;
1230 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1232 ProcessorNumber
= (UINTN
)Context
;
1233 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1235 ProcessorData
->Info
.ProcessorId
= gThread
->Self ();
1239 // Make a local copy on the stack to be extra safe
1241 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1242 Procedure
= ProcessorData
->Procedure
;
1243 Parameter
= ProcessorData
->Parameter
;
1244 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1246 if (Procedure
!= NULL
) {
1247 gThread
->MutexLock (ProcessorData
->StateLock
);
1248 ProcessorData
->State
= CPU_STATE_BUSY
;
1249 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1251 Procedure (Parameter
);
1253 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1254 ProcessorData
->Procedure
= NULL
;
1255 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1257 gThread
->MutexLock (ProcessorData
->StateLock
);
1258 ProcessorData
->State
= CPU_STATE_FINISHED
;
1259 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1262 // Poll 5 times a seconds, 200ms
1263 // Don't want to burn too many system resources doing nothing.
1264 gEmuThunk
->Sleep (200 * 1000);
1272 InitializeMpSystemData (
1273 IN UINTN NumberOfProcessors
1281 // Clear the data structure area first.
1283 ZeroMem (&gMPSystem
, sizeof (MP_SYSTEM_DATA
));
1286 // First BSP fills and inits all known values, including it's own records.
1288 gMPSystem
.NumberOfProcessors
= NumberOfProcessors
;
1289 gMPSystem
.NumberOfEnabledProcessors
= NumberOfProcessors
;
1291 gMPSystem
.ProcessorData
= AllocateZeroPool (gMPSystem
.NumberOfProcessors
* sizeof (PROCESSOR_DATA_BLOCK
));
1292 ASSERT (gMPSystem
.ProcessorData
!= NULL
);
1294 FillInProcessorInformation (TRUE
, 0);
1296 Status
= gBS
->CreateEvent (
1297 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1299 CpuCheckAllAPsStatus
,
1301 &gMPSystem
.CheckAllAPsEvent
1303 ASSERT_EFI_ERROR (Status
);
1306 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
1307 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1312 FillInProcessorInformation (FALSE
, Index
);
1314 Status
= gThread
->CreateThread (
1315 (VOID
*)&gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
,
1317 CpuDriverApIdolLoop
,
1322 Status
= gBS
->CreateEvent (
1323 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1325 CpuCheckThisAPStatus
,
1326 (VOID
*) &gMPSystem
.ProcessorData
[Index
],
1327 &gMPSystem
.ProcessorData
[Index
].CheckThisAPEvent
1337 Invoke a notification event
1339 @param Event Event whose notification function is being invoked.
1340 @param Context The pointer to the notification function's context,
1341 which is implementation-dependent.
1346 CpuReadToBootFunction (
1363 EMU_IO_THUNK_PROTOCOL
*IoThunk
;
1365 *MaxCpus
= 1; // BSP
1366 IoThunk
= GetIoThunkInstance (&gEmuThreadThunkProtocolGuid
, 0);
1367 if (IoThunk
!= NULL
) {
1368 Status
= IoThunk
->Open (IoThunk
);
1369 if (!EFI_ERROR (Status
)) {
1370 if (IoThunk
->ConfigString
!= NULL
) {
1371 *MaxCpus
+= StrDecimalToUintn (IoThunk
->ConfigString
);
1372 gThread
= IoThunk
->Interface
;
1377 if (*MaxCpus
== 1) {
1378 // We are not MP so nothing to do
1382 gPollInterval
= (UINTN
) PcdGet64 (PcdEmuMpServicesPollingInterval
);
1384 Status
= InitializeMpSystemData (*MaxCpus
);
1385 if (EFI_ERROR (Status
)) {
1389 Status
= EfiCreateEventReadyToBootEx (TPL_CALLBACK
, CpuReadToBootFunction
, NULL
, &gReadToBootEvent
);
1390 ASSERT_EFI_ERROR (Status
);
1393 // Now install the MP services protocol.
1396 Status
= gBS
->InstallMultipleProtocolInterfaces (
1398 &gEfiMpServiceProtocolGuid
, &mMpServicesTemplate
,