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
;
424 if (FailedCpuList
!= NULL
) {
425 gMPSystem
.FailedList
= AllocatePool ((gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
));
426 if (gMPSystem
.FailedList
== NULL
) {
427 return EFI_OUT_OF_RESOURCES
;
429 SetMemN (gMPSystem
.FailedList
, (gMPSystem
.NumberOfProcessors
+ 1) * sizeof (UINTN
), END_OF_CPU_LIST
);
430 gMPSystem
.FailedListIndex
= 0;
431 *FailedCpuList
= gMPSystem
.FailedList
;
434 Timeout
= TimeoutInMicroseconds
;
436 ProcessorData
= NULL
;
438 gMPSystem
.FinishCount
= 0;
439 gMPSystem
.StartCount
= 0;
440 gMPSystem
.SingleThread
= SingleThread
;
441 APInitialState
= CPU_STATE_READY
;
443 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
444 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
446 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
451 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
452 // Skip Disabled processors
453 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Number
;
458 // Get APs prepared, and put failing APs into FailedCpuList
459 // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready
460 // state 1 by 1, until the previous 1 finished its task
461 // if not "SingleThread", all APs are put to ready state from the beginning
463 gThread
->MutexLock(ProcessorData
->StateLock
);
464 if (ProcessorData
->State
== CPU_STATE_IDLE
) {
465 ProcessorData
->State
= APInitialState
;
466 gThread
->MutexUnlock (ProcessorData
->StateLock
);
468 gMPSystem
.StartCount
++;
470 APInitialState
= CPU_STATE_BLOCKED
;
473 gThread
->MutexUnlock (ProcessorData
->StateLock
);
474 return EFI_NOT_READY
;
478 if (WaitEvent
!= NULL
) {
479 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
480 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
481 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
486 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
487 // Skip Disabled processors
491 gThread
->MutexLock (ProcessorData
->StateLock
);
492 ProcessorState
= ProcessorData
->State
;
493 gThread
->MutexUnlock (ProcessorData
->StateLock
);
495 if (ProcessorState
== CPU_STATE_READY
) {
496 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
501 // Save data into private data structure, and create timer to poll AP state before exiting
503 gMPSystem
.Procedure
= Procedure
;
504 gMPSystem
.ProcedureArgument
= ProcedureArgument
;
505 gMPSystem
.WaitEvent
= WaitEvent
;
506 gMPSystem
.Timeout
= TimeoutInMicroseconds
;
507 gMPSystem
.TimeoutActive
= (BOOLEAN
)(TimeoutInMicroseconds
!= 0);
508 Status
= gBS
->SetTimer (
509 gMPSystem
.CheckAllAPsEvent
,
518 for (Number
= 0; Number
< gMPSystem
.NumberOfProcessors
; Number
++) {
519 ProcessorData
= &gMPSystem
.ProcessorData
[Number
];
520 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
525 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
526 // Skip Disabled processors
530 gThread
->MutexLock (ProcessorData
->StateLock
);
531 ProcessorState
= ProcessorData
->State
;
532 gThread
->MutexUnlock (ProcessorData
->StateLock
);
534 switch (ProcessorState
) {
535 case CPU_STATE_READY
:
536 SetApProcedure (ProcessorData
, Procedure
, ProcedureArgument
);
539 case CPU_STATE_FINISHED
:
540 gMPSystem
.FinishCount
++;
542 Status
= GetNextBlockedNumber (&NextNumber
);
543 if (!EFI_ERROR (Status
)) {
544 gThread
->MutexLock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
545 gMPSystem
.ProcessorData
[NextNumber
].State
= CPU_STATE_READY
;
546 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[NextNumber
].StateLock
);
550 gThread
->MutexLock (ProcessorData
->StateLock
);
551 ProcessorData
->State
= CPU_STATE_IDLE
;
552 gThread
->MutexUnlock (ProcessorData
->StateLock
);
561 if (gMPSystem
.FinishCount
== gMPSystem
.StartCount
) {
562 Status
= EFI_SUCCESS
;
566 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
567 Status
= EFI_TIMEOUT
;
571 Timeout
-= CalculateAndStallInterval (Timeout
);
575 if (FailedCpuList
!= NULL
) {
576 if (gMPSystem
.FailedListIndex
== 0) {
577 FreePool (*FailedCpuList
);
578 *FailedCpuList
= NULL
;
587 This service lets the caller get one enabled AP to execute a caller-provided
588 function. The caller can request the BSP to either wait for the completion
589 of the AP or just proceed with the next task by using the EFI event mechanism.
590 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
591 execution support. This service may only be called from the BSP.
593 This function is used to dispatch one enabled AP to the function specified by
594 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
595 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
596 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
597 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
598 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
599 then EFI_UNSUPPORTED must be returned.
601 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
602 from Procedure, then execution of Procedure by the AP is terminated. The AP is
603 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
604 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
606 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
608 @param[in] Procedure A pointer to the function to be run on
609 enabled APs of the system. See type
611 @param[in] ProcessorNumber The handle number of the AP. The range is
612 from 0 to the total number of logical
613 processors minus 1. The total number of
614 logical processors can be retrieved by
615 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
616 @param[in] WaitEvent The event created by the caller with CreateEvent()
617 service. If it is NULL, then execute in
618 blocking mode. BSP waits until all APs finish
619 or TimeoutInMicroseconds expires. If it's
620 not NULL, then execute in non-blocking mode.
621 BSP requests the function specified by
622 Procedure to be started on all the enabled
623 APs, and go on executing immediately. If
624 all return from Procedure or TimeoutInMicroseconds
625 expires, this event is signaled. The BSP
626 can use the CheckEvent() or WaitForEvent()
627 services to check the state of event. Type
628 EFI_EVENT is defined in CreateEvent() in
629 the Unified Extensible Firmware Interface
631 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
632 APs to return from Procedure, either for
633 blocking or non-blocking mode. Zero means
634 infinity. If the timeout expires before
635 all APs return from Procedure, then Procedure
636 on the failed APs is terminated. All enabled
637 APs are available for next function assigned
638 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
639 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
640 If the timeout expires in blocking mode,
641 BSP returns EFI_TIMEOUT. If the timeout
642 expires in non-blocking mode, WaitEvent
643 is signaled with SignalEvent().
644 @param[in] ProcedureArgument The parameter passed into Procedure for
646 @param[out] Finished If NULL, this parameter is ignored. In
647 blocking mode, this parameter is ignored.
648 In non-blocking mode, if AP returns from
649 Procedure before the timeout expires, its
650 content is set to TRUE. Otherwise, the
651 value is set to FALSE. The caller can
652 determine if the AP returned from Procedure
653 by evaluating this value.
655 @retval EFI_SUCCESS In blocking mode, specified AP finished before
657 @retval EFI_SUCCESS In non-blocking mode, the function has been
658 dispatched to specified AP.
659 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
660 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
662 @retval EFI_DEVICE_ERROR The calling processor is an AP.
663 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
664 the specified AP has finished.
665 @retval EFI_NOT_READY The specified AP is busy.
666 @retval EFI_NOT_FOUND The processor with the handle specified by
667 ProcessorNumber does not exist.
668 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
669 @retval EFI_INVALID_PARAMETER Procedure is NULL.
674 CpuMpServicesStartupThisAP (
675 IN EFI_MP_SERVICES_PROTOCOL
*This
,
676 IN EFI_AP_PROCEDURE Procedure
,
677 IN UINTN ProcessorNumber
,
678 IN EFI_EVENT WaitEvent OPTIONAL
,
679 IN UINTN TimeoutInMicroseconds
,
680 IN VOID
*ProcedureArgument OPTIONAL
,
681 OUT BOOLEAN
*Finished OPTIONAL
687 return EFI_DEVICE_ERROR
;
690 if (Procedure
== NULL
) {
691 return EFI_INVALID_PARAMETER
;
694 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
695 return EFI_NOT_FOUND
;
698 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
699 return EFI_INVALID_PARAMETER
;
702 gThread
->MutexLock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
703 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
704 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
705 return EFI_NOT_READY
;
707 gThread
->MutexUnlock(gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
709 if ((WaitEvent
!= NULL
) && gReadToBoot
) {
710 return EFI_UNSUPPORTED
;
713 Timeout
= TimeoutInMicroseconds
;
715 gMPSystem
.StartCount
= 1;
716 gMPSystem
.FinishCount
= 0;
718 SetApProcedure (&gMPSystem
.ProcessorData
[ProcessorNumber
], Procedure
, ProcedureArgument
);
720 if (WaitEvent
!= NULL
) {
722 gMPSystem
.WaitEvent
= WaitEvent
;
724 gMPSystem
.ProcessorData
[ProcessorNumber
].CheckThisAPEvent
,
733 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
734 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
== CPU_STATE_FINISHED
) {
735 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= CPU_STATE_IDLE
;
736 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
740 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
742 if ((TimeoutInMicroseconds
!= 0) && (Timeout
== 0)) {
746 Timeout
-= CalculateAndStallInterval (Timeout
);
755 This service switches the requested AP to be the BSP from that point onward.
756 This service changes the BSP for all purposes. This call can only be performed
759 This service switches the requested AP to be the BSP from that point onward.
760 This service changes the BSP for all purposes. The new BSP can take over the
761 execution of the old BSP and continue seamlessly from where the old one left
762 off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
765 If the BSP cannot be switched prior to the return from this service, then
766 EFI_UNSUPPORTED must be returned.
768 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
769 @param[in] ProcessorNumber The handle number of AP that is to become the new
770 BSP. The range is from 0 to the total number of
771 logical processors minus 1. The total number of
772 logical processors can be retrieved by
773 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
774 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
775 enabled AP. Otherwise, it will be disabled.
777 @retval EFI_SUCCESS BSP successfully switched.
778 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
779 this service returning.
780 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
781 @retval EFI_SUCCESS The calling processor is an AP.
782 @retval EFI_NOT_FOUND The processor with the handle specified by
783 ProcessorNumber does not exist.
784 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
786 @retval EFI_NOT_READY The specified AP is busy.
791 CpuMpServicesSwitchBSP (
792 IN EFI_MP_SERVICES_PROTOCOL
*This
,
793 IN UINTN ProcessorNumber
,
794 IN BOOLEAN EnableOldBSP
800 return EFI_DEVICE_ERROR
;
803 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
804 return EFI_NOT_FOUND
;
807 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
808 return EFI_INVALID_PARAMETER
;
811 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
812 return EFI_INVALID_PARAMETER
;
815 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
816 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
820 ASSERT (Index
!= gMPSystem
.NumberOfProcessors
);
822 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
823 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
824 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
825 return EFI_NOT_READY
;
827 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
829 // Skip for now as we need switch a bunch of stack stuff around and it's complex
830 // May not be worth it?
831 return EFI_NOT_READY
;
836 This service lets the caller enable or disable an AP from this point onward.
837 This service may only be called from the BSP.
839 This service allows the caller enable or disable an AP from this point onward.
840 The caller can optionally specify the health status of the AP by Health. If
841 an AP is being disabled, then the state of the disabled AP is implementation
842 dependent. If an AP is enabled, then the implementation must guarantee that a
843 complete initialization sequence is performed on the AP, so the AP is in a state
844 that is compatible with an MP operating system. This service may not be supported
845 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
847 If the enable or disable AP operation cannot be completed prior to the return
848 from this service, then EFI_UNSUPPORTED must be returned.
850 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
851 @param[in] ProcessorNumber The handle number of AP that is to become the new
852 BSP. The range is from 0 to the total number of
853 logical processors minus 1. The total number of
854 logical processors can be retrieved by
855 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
856 @param[in] EnableAP Specifies the new state for the processor for
857 enabled, FALSE for disabled.
858 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
859 the new health status of the AP. This flag
860 corresponds to StatusFlag defined in
861 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
862 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
863 bits are ignored. If it is NULL, this parameter
866 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
867 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
868 prior to this service returning.
869 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
870 @retval EFI_DEVICE_ERROR The calling processor is an AP.
871 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
873 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
878 CpuMpServicesEnableDisableAP (
879 IN EFI_MP_SERVICES_PROTOCOL
*This
,
880 IN UINTN ProcessorNumber
,
882 IN UINT32
*HealthFlag OPTIONAL
886 return EFI_DEVICE_ERROR
;
889 if (ProcessorNumber
>= gMPSystem
.NumberOfProcessors
) {
890 return EFI_NOT_FOUND
;
893 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) != 0) {
894 return EFI_INVALID_PARAMETER
;
897 gThread
->MutexLock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
898 if (gMPSystem
.ProcessorData
[ProcessorNumber
].State
!= CPU_STATE_IDLE
) {
899 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
900 return EFI_UNSUPPORTED
;
902 gThread
->MutexUnlock (gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
);
905 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0 ) {
906 gMPSystem
.NumberOfEnabledProcessors
++;
908 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_ENABLED_BIT
;
910 if ((gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == PROCESSOR_ENABLED_BIT
) {
911 gMPSystem
.NumberOfEnabledProcessors
--;
913 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_ENABLED_BIT
;
916 if (HealthFlag
!= NULL
) {
917 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
&= ~PROCESSOR_HEALTH_STATUS_BIT
;
918 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= (*HealthFlag
& PROCESSOR_HEALTH_STATUS_BIT
);
926 This return the handle number for the calling processor. This service may be
927 called from the BSP and APs.
929 This service returns the processor handle number for the calling processor.
930 The returned value is in the range from 0 to the total number of logical
931 processors minus 1. The total number of logical processors can be retrieved
932 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
933 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
934 is returned. Otherwise, the current processors handle number is returned in
935 ProcessorNumber, and EFI_SUCCESS is returned.
937 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
938 @param[in] ProcessorNumber The handle number of AP that is to become the new
939 BSP. The range is from 0 to the total number of
940 logical processors minus 1. The total number of
941 logical processors can be retrieved by
942 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
944 @retval EFI_SUCCESS The current processor handle number was returned
946 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
951 CpuMpServicesWhoAmI (
952 IN EFI_MP_SERVICES_PROTOCOL
*This
,
953 OUT UINTN
*ProcessorNumber
959 if (ProcessorNumber
== NULL
) {
960 return EFI_INVALID_PARAMETER
;
963 ProcessorId
= gThread
->Self ();
964 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
965 if (gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
== ProcessorId
) {
970 *ProcessorNumber
= Index
;
976 EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate
= {
977 CpuMpServicesGetNumberOfProcessors
,
978 CpuMpServicesGetProcessorInfo
,
979 CpuMpServicesStartupAllAps
,
980 CpuMpServicesStartupThisAP
,
981 CpuMpServicesSwitchBSP
,
982 CpuMpServicesEnableDisableAP
,
989 If timeout occurs in StartupAllAps(), a timer is set, which invokes this
990 procedure periodically to check whether all APs have finished.
996 CpuCheckAllAPsStatus (
1001 UINTN ProcessorNumber
;
1003 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1004 PROCESSOR_DATA_BLOCK
*NextData
;
1006 PROCESSOR_STATE ProcessorState
;
1010 if (gMPSystem
.TimeoutActive
) {
1011 gMPSystem
.Timeout
-= CalculateAndStallInterval (gMPSystem
.Timeout
);
1014 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1015 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1016 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1021 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1022 // Skip Disabled processors
1026 // This is an Interrupt Service routine.
1027 // This can grab a lock that is held in a non-interrupt
1028 // context. Meaning deadlock. Which is a bad thing.
1029 // So, try lock it. If we can get it, cool, do our thing.
1030 // otherwise, just dump out & try again on the next iteration.
1031 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1032 if (EFI_ERROR(Status
)) {
1035 ProcessorState
= ProcessorData
->State
;
1036 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1038 switch (ProcessorState
) {
1039 case CPU_STATE_FINISHED
:
1040 if (gMPSystem
.SingleThread
) {
1041 Status
= GetNextBlockedNumber (&NextNumber
);
1042 if (!EFI_ERROR (Status
)) {
1043 NextData
= &gMPSystem
.ProcessorData
[NextNumber
];
1045 gThread
->MutexLock (NextData
->StateLock
);
1046 NextData
->State
= CPU_STATE_READY
;
1047 gThread
->MutexUnlock (NextData
->StateLock
);
1049 SetApProcedure (NextData
, gMPSystem
.Procedure
, gMPSystem
.ProcedureArgument
);
1053 gThread
->MutexLock (ProcessorData
->StateLock
);
1054 ProcessorData
->State
= CPU_STATE_IDLE
;
1055 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1056 gMPSystem
.FinishCount
++;
1064 if (gMPSystem
.TimeoutActive
&& gMPSystem
.Timeout
== 0) {
1068 if (gMPSystem
.FailedList
!= NULL
) {
1069 for (ProcessorNumber
= 0; ProcessorNumber
< gMPSystem
.NumberOfProcessors
; ProcessorNumber
++) {
1070 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1071 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1076 if ((ProcessorData
->Info
.StatusFlag
& PROCESSOR_ENABLED_BIT
) == 0) {
1077 // Skip Disabled processors
1082 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1083 if (EFI_ERROR(Status
)) {
1086 ProcessorState
= ProcessorData
->State
;
1087 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1089 if (ProcessorState
!= CPU_STATE_IDLE
) {
1090 // If we are retrying make sure we don't double count
1091 for (Cpu
= 0, Found
= FALSE
; Cpu
< gMPSystem
.NumberOfProcessors
; Cpu
++) {
1092 if (gMPSystem
.FailedList
[Cpu
] == END_OF_CPU_LIST
) {
1095 if (gMPSystem
.FailedList
[ProcessorNumber
] == Cpu
) {
1101 gMPSystem
.FailedList
[gMPSystem
.FailedListIndex
++] = Cpu
;
1106 // Force terminal exit
1107 gMPSystem
.FinishCount
= gMPSystem
.StartCount
;
1110 if (gMPSystem
.FinishCount
!= gMPSystem
.StartCount
) {
1115 gMPSystem
.CheckAllAPsEvent
,
1120 if (gMPSystem
.FailedListIndex
== 0) {
1121 if (gMPSystem
.FailedList
!= NULL
) {
1122 FreePool (gMPSystem
.FailedList
);
1123 gMPSystem
.FailedList
= NULL
;
1127 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1134 CpuCheckThisAPStatus (
1140 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1141 PROCESSOR_STATE ProcessorState
;
1143 ProcessorData
= (PROCESSOR_DATA_BLOCK
*) Context
;
1146 // This is an Interrupt Service routine.
1147 // that can grab a lock that is held in a non-interrupt
1148 // context. Meaning deadlock. Which is a badddd thing.
1149 // So, try lock it. If we can get it, cool, do our thing.
1150 // otherwise, just dump out & try again on the next iteration.
1152 Status
= gThread
->MutexTryLock (ProcessorData
->StateLock
);
1153 if (EFI_ERROR(Status
)) {
1156 ProcessorState
= ProcessorData
->State
;
1157 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1159 if (ProcessorState
== CPU_STATE_FINISHED
) {
1160 Status
= gBS
->SetTimer (ProcessorData
->CheckThisAPEvent
, TimerCancel
, 0);
1161 ASSERT_EFI_ERROR (Status
);
1163 Status
= gBS
->SignalEvent (gMPSystem
.WaitEvent
);
1164 ASSERT_EFI_ERROR (Status
);
1166 gThread
->MutexLock (ProcessorData
->StateLock
);
1167 ProcessorData
->State
= CPU_STATE_IDLE
;
1168 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1176 This function is called by all processors (both BSP and AP) once and collects MP related data
1178 MPSystemData - Pointer to the data structure containing MP related data
1179 BSP - TRUE if the CPU is BSP
1181 EFI_SUCCESS - Data for the processor collected and filled in
1185 FillInProcessorInformation (
1187 IN UINTN ProcessorNumber
1190 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.ProcessorId
= gThread
->Self ();
1191 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
1193 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
1196 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Package
= (UINT32
) ProcessorNumber
;
1197 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Core
= 0;
1198 gMPSystem
.ProcessorData
[ProcessorNumber
].Info
.Location
.Thread
= 0;
1199 gMPSystem
.ProcessorData
[ProcessorNumber
].State
= BSP
? CPU_STATE_BUSY
: CPU_STATE_IDLE
;
1201 gMPSystem
.ProcessorData
[ProcessorNumber
].Procedure
= NULL
;
1202 gMPSystem
.ProcessorData
[ProcessorNumber
].Parameter
= NULL
;
1203 gMPSystem
.ProcessorData
[ProcessorNumber
].StateLock
= gThread
->MutexInit ();
1204 gMPSystem
.ProcessorData
[ProcessorNumber
].ProcedureLock
= gThread
->MutexInit ();
1211 CpuDriverApIdolLoop (
1215 EFI_AP_PROCEDURE Procedure
;
1217 UINTN ProcessorNumber
;
1218 PROCESSOR_DATA_BLOCK
*ProcessorData
;
1220 ProcessorNumber
= (UINTN
)Context
;
1221 ProcessorData
= &gMPSystem
.ProcessorData
[ProcessorNumber
];
1223 ProcessorData
->Info
.ProcessorId
= gThread
->Self ();
1227 // Make a local copy on the stack to be extra safe
1229 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1230 Procedure
= ProcessorData
->Procedure
;
1231 Parameter
= ProcessorData
->Parameter
;
1232 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1234 if (Procedure
!= NULL
) {
1235 gThread
->MutexLock (ProcessorData
->StateLock
);
1236 ProcessorData
->State
= CPU_STATE_BUSY
;
1237 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1239 Procedure (Parameter
);
1241 gThread
->MutexLock (ProcessorData
->ProcedureLock
);
1242 ProcessorData
->Procedure
= NULL
;
1243 gThread
->MutexUnlock (ProcessorData
->ProcedureLock
);
1245 gThread
->MutexLock (ProcessorData
->StateLock
);
1246 ProcessorData
->State
= CPU_STATE_FINISHED
;
1247 gThread
->MutexUnlock (ProcessorData
->StateLock
);
1250 // Poll 5 times a seconds, 200ms
1251 // Don't want to burn too many system resources doing nothing.
1252 gEmuThunk
->Sleep (200 * 1000);
1260 InitializeMpSystemData (
1261 IN UINTN NumberOfProcessors
1269 // Clear the data structure area first.
1271 ZeroMem (&gMPSystem
, sizeof (MP_SYSTEM_DATA
));
1274 // First BSP fills and inits all known values, including it's own records.
1276 gMPSystem
.NumberOfProcessors
= NumberOfProcessors
;
1277 gMPSystem
.NumberOfEnabledProcessors
= NumberOfProcessors
;
1279 gMPSystem
.ProcessorData
= AllocateZeroPool (gMPSystem
.NumberOfProcessors
* sizeof (PROCESSOR_DATA_BLOCK
));
1280 ASSERT (gMPSystem
.ProcessorData
!= NULL
);
1282 FillInProcessorInformation (TRUE
, 0);
1284 Status
= gBS
->CreateEvent (
1285 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1287 CpuCheckAllAPsStatus
,
1289 &gMPSystem
.CheckAllAPsEvent
1291 ASSERT_EFI_ERROR (Status
);
1294 for (Index
= 0; Index
< gMPSystem
.NumberOfProcessors
; Index
++) {
1295 if ((gMPSystem
.ProcessorData
[Index
].Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) == PROCESSOR_AS_BSP_BIT
) {
1300 FillInProcessorInformation (FALSE
, Index
);
1302 Status
= gThread
->CreateThread (
1303 (VOID
*)&gMPSystem
.ProcessorData
[Index
].Info
.ProcessorId
,
1305 CpuDriverApIdolLoop
,
1310 Status
= gBS
->CreateEvent (
1311 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1313 CpuCheckThisAPStatus
,
1314 (VOID
*) &gMPSystem
.ProcessorData
[Index
],
1315 &gMPSystem
.ProcessorData
[Index
].CheckThisAPEvent
1325 Invoke a notification event
1327 @param Event Event whose notification function is being invoked.
1328 @param Context The pointer to the notification function's context,
1329 which is implementation-dependent.
1334 CpuReadToBootFunction (
1351 EMU_IO_THUNK_PROTOCOL
*IoThunk
;
1353 *MaxCpus
= 1; // BSP
1354 IoThunk
= GetIoThunkInstance (&gEmuThreadThunkProtocolGuid
, 0);
1355 if (IoThunk
!= NULL
) {
1356 Status
= IoThunk
->Open (IoThunk
);
1357 if (!EFI_ERROR (Status
)) {
1358 if (IoThunk
->ConfigString
!= NULL
) {
1359 *MaxCpus
+= StrDecimalToUintn (IoThunk
->ConfigString
);
1360 gThread
= IoThunk
->Interface
;
1365 if (*MaxCpus
== 1) {
1366 // We are not MP so nothing to do
1370 gPollInterval
= (UINTN
) PcdGet64 (PcdEmuMpServicesPollingInterval
);
1372 Status
= InitializeMpSystemData (*MaxCpus
);
1373 if (EFI_ERROR (Status
)) {
1377 Status
= EfiCreateEventReadyToBootEx (TPL_CALLBACK
, CpuReadToBootFunction
, NULL
, &gReadToBootEvent
);
1378 ASSERT_EFI_ERROR (Status
);
1381 // Now install the MP services protocol.
1384 Status
= gBS
->InstallMultipleProtocolInterfaces (
1386 &gEfiMpServiceProtocolGuid
, &mMpServicesTemplate
,