2 Produces PI MP Services Protocol on top of Framework MP Services Protocol.
4 Intel's Framework MP Services Protocol is replaced by EFI_MP_SERVICES_PROTOCOL in PI 1.1.
5 This module produces PI MP Services Protocol on top of Framework MP Services Protocol.
7 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "MpServicesOnFrameworkMpServicesThunk.h"
21 EFI_HANDLE mHandle
= NULL
;
22 MP_SYSTEM_DATA mMPSystemData
;
23 EFI_PHYSICAL_ADDRESS mStartupVector
;
24 MP_CPU_EXCHANGE_INFO
*mExchangeInfo
;
25 VOID
*mStackStartAddress
;
26 BOOLEAN mStopCheckAPsStatus
= FALSE
;
27 UINTN mNumberOfProcessors
;
28 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*mGenMemoryTest
;
30 FRAMEWORK_EFI_MP_SERVICES_PROTOCOL
*mFrameworkMpService
;
31 EFI_MP_SERVICES_PROTOCOL mMpService
= {
32 GetNumberOfProcessors
,
43 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
45 This service retrieves the number of logical processor in the platform
46 and the number of those logical processors that are enabled on this boot.
47 This service may only be called from the BSP.
49 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
50 @param NumberOfProcessors Pointer to the total number of logical processors in the system,
51 including the BSP and disabled APs.
52 @param NumberOfEnabledProcessors Pointer to the number of enabled logical processors that exist
53 in system, including the BSP.
55 @retval EFI_SUCCESS Number of logical processors and enabled logical processors retrieved..
56 @retval EFI_DEVICE_ERROR Caller processor is AP.
57 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL
58 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL
63 GetNumberOfProcessors (
64 IN EFI_MP_SERVICES_PROTOCOL
*This
,
65 OUT UINTN
*NumberOfProcessors
,
66 OUT UINTN
*NumberOfEnabledProcessors
73 // Check whether caller processor is BSP
75 WhoAmI (This
, &CallerNumber
);
76 if (CallerNumber
!= GetBspNumber ()) {
77 return EFI_DEVICE_ERROR
;
81 // Check parameter NumberOfProcessors
83 if (NumberOfProcessors
== NULL
) {
84 return EFI_INVALID_PARAMETER
;
88 // Check parameter NumberOfEnabledProcessors
90 if (NumberOfEnabledProcessors
== NULL
) {
91 return EFI_INVALID_PARAMETER
;
94 Status
= mFrameworkMpService
->GetGeneralMPInfo (
98 NumberOfEnabledProcessors
,
102 ASSERT_EFI_ERROR (Status
);
108 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
110 Gets detailed MP-related information on the requested processor at the
111 instant this call is made. This service may only be called from the BSP.
113 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
114 @param ProcessorNumber The handle number of processor.
115 @param ProcessorInfoBuffer A pointer to the buffer where information for the requested processor is deposited.
117 @retval EFI_SUCCESS Processor information successfully returned.
118 @retval EFI_DEVICE_ERROR Caller processor is AP.
119 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL
120 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
126 IN EFI_MP_SERVICES_PROTOCOL
*This
,
127 IN UINTN ProcessorNumber
,
128 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
134 EFI_MP_PROC_CONTEXT ProcessorContextBuffer
;
137 // Check whether caller processor is BSP
139 WhoAmI (This
, &CallerNumber
);
140 if (CallerNumber
!= GetBspNumber ()) {
141 return EFI_DEVICE_ERROR
;
145 // Check parameter ProcessorInfoBuffer
147 if (ProcessorInfoBuffer
== NULL
) {
148 return EFI_INVALID_PARAMETER
;
152 // Check whether processor with the handle specified by ProcessorNumber exists
154 if (ProcessorNumber
>= mNumberOfProcessors
) {
155 return EFI_NOT_FOUND
;
158 BufferSize
= sizeof (EFI_MP_PROC_CONTEXT
);
159 Status
= mFrameworkMpService
->GetProcessorContext (
163 &ProcessorContextBuffer
165 ASSERT_EFI_ERROR (Status
);
167 ProcessorInfoBuffer
->ProcessorId
= (UINT64
) ProcessorContextBuffer
.ApicID
;
170 // Get Status Flag of specified processor
172 ProcessorInfoBuffer
->StatusFlag
= 0;
174 if (ProcessorContextBuffer
.Enabled
) {
175 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_ENABLED_BIT
;
178 if (ProcessorContextBuffer
.Designation
== EfiCpuBSP
) {
179 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
182 if (ProcessorContextBuffer
.Health
.Flags
.Uint32
== 0) {
183 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_HEALTH_STATUS_BIT
;
186 ProcessorInfoBuffer
->Location
.Package
= (UINT32
) ProcessorContextBuffer
.PackageNumber
;
187 ProcessorInfoBuffer
->Location
.Core
= (UINT32
) ProcessorContextBuffer
.NumberOfCores
;
188 ProcessorInfoBuffer
->Location
.Thread
= (UINT32
) ProcessorContextBuffer
.NumberOfThreads
;
194 Implementation of StartupAllAPs() service of MP Services Protocol.
196 This service lets the caller get all enabled APs to execute a caller-provided function.
197 This service may only be called from the BSP.
199 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
200 @param Procedure A pointer to the function to be run on enabled APs of the system.
201 @param SingleThread Indicates whether to execute the function simultaneously or one by one..
202 @param WaitEvent The event created by the caller.
203 If it is NULL, then execute in blocking mode.
204 If it is not NULL, then execute in non-blocking mode.
205 @param TimeoutInMicroSeconds The time limit in microseconds for this AP to finish the function.
207 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
208 @param FailedCpuList The list of processor numbers that fail to finish the function before
209 TimeoutInMicrosecsond expires.
211 @retval EFI_SUCCESS In blocking mode, all APs have finished before the timeout expired.
212 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to all enabled APs.
213 @retval EFI_DEVICE_ERROR Caller processor is AP.
214 @retval EFI_NOT_STARTED No enabled AP exists in the system.
215 @retval EFI_NOT_READY Any enabled AP is busy.
216 @retval EFI_TIMEOUT In blocking mode, The timeout expired before all enabled APs have finished.
217 @retval EFI_INVALID_PARAMETER Procedure is NULL.
223 IN EFI_MP_SERVICES_PROTOCOL
*This
,
224 IN EFI_AP_PROCEDURE Procedure
,
225 IN BOOLEAN SingleThread
,
226 IN EFI_EVENT WaitEvent OPTIONAL
,
227 IN UINTN TimeoutInMicroSeconds
,
228 IN VOID
*ProcedureArgument OPTIONAL
,
229 OUT UINTN
**FailedCpuList OPTIONAL
233 UINTN ProcessorNumber
;
234 CPU_DATA_BLOCK
*CpuData
;
238 if (FailedCpuList
!= NULL
) {
239 *FailedCpuList
= NULL
;
243 // Check whether caller processor is BSP
245 BspNumber
= GetBspNumber ();
246 WhoAmI (This
, &ProcessorNumber
);
247 if (ProcessorNumber
!= BspNumber
) {
248 return EFI_DEVICE_ERROR
;
252 // Check parameter Procedure
254 if (Procedure
== NULL
) {
255 return EFI_INVALID_PARAMETER
;
259 // Temporarily suppress CheckAPsStatus()
261 mStopCheckAPsStatus
= TRUE
;
264 // Check whether all enabled APs are idle.
265 // If any enabled AP is not idle, return EFI_NOT_READY.
267 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
269 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
271 mMPSystemData
.CpuList
[ProcessorNumber
] = FALSE
;
272 if (ProcessorNumber
!= BspNumber
) {
273 if (CpuData
->State
!= CpuStateDisabled
) {
274 if (CpuData
->State
!= CpuStateIdle
) {
275 mStopCheckAPsStatus
= FALSE
;
276 return EFI_NOT_READY
;
279 // Mark this processor as responsible for current calling.
281 mMPSystemData
.CpuList
[ProcessorNumber
] = TRUE
;
287 mMPSystemData
.FinishCount
= 0;
288 mMPSystemData
.StartCount
= 0;
291 // Go through all enabled APs to wakeup them for Procedure.
292 // If in Single Thread mode, then only one AP is woken up, and others are waiting.
294 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
296 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
298 // Check whether this processor is responsible for current calling.
300 if (mMPSystemData
.CpuList
[ProcessorNumber
]) {
302 mMPSystemData
.StartCount
++;
304 AcquireSpinLock (&CpuData
->CpuDataLock
);
305 CpuData
->State
= CpuStateReady
;
306 ReleaseSpinLock (&CpuData
->CpuDataLock
);
323 // If no enabled AP exists, return EFI_NOT_STARTED.
325 if (mMPSystemData
.StartCount
== 0) {
326 mStopCheckAPsStatus
= FALSE
;
327 return EFI_NOT_STARTED
;
331 // If WaitEvent is not NULL, execute in non-blocking mode.
332 // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
333 // CheckAPsStatus() will check completion and timeout periodically.
335 mMPSystemData
.Procedure
= Procedure
;
336 mMPSystemData
.ProcArguments
= ProcedureArgument
;
337 mMPSystemData
.SingleThread
= SingleThread
;
338 mMPSystemData
.FailedCpuList
= FailedCpuList
;
339 mMPSystemData
.ExpectedTime
= CalculateTimeout (TimeoutInMicroSeconds
, &mMPSystemData
.CurrentTime
);
340 mMPSystemData
.WaitEvent
= WaitEvent
;
343 // Allow CheckAPsStatus()
345 mStopCheckAPsStatus
= FALSE
;
347 if (WaitEvent
!= NULL
) {
352 // If WaitEvent is NULL, execute in blocking mode.
353 // BSP checks APs'state until all APs finish or TimeoutInMicrosecsond expires.
356 Status
= CheckAllAPs ();
357 } while (Status
== EFI_NOT_READY
);
363 Implementation of StartupThisAP() service of MP Services Protocol.
365 This service lets the caller get one enabled AP to execute a caller-provided function.
366 This service may only be called from the BSP.
368 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
369 @param Procedure A pointer to the function to be run on the designated AP.
370 @param ProcessorNumber The handle number of AP..
371 @param WaitEvent The event created by the caller.
372 If it is NULL, then execute in blocking mode.
373 If it is not NULL, then execute in non-blocking mode.
374 @param TimeoutInMicroseconds The time limit in microseconds for this AP to finish the function.
376 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
377 @param Finished Indicates whether AP has finished assigned function.
378 In blocking mode, it is ignored.
380 @retval EFI_SUCCESS In blocking mode, specified AP has finished before the timeout expires.
381 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to specified AP.
382 @retval EFI_DEVICE_ERROR Caller processor is AP.
383 @retval EFI_TIMEOUT In blocking mode, the timeout expires before specified AP has finished.
384 @retval EFI_NOT_READY Specified AP is busy.
385 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
386 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
387 @retval EFI_INVALID_PARAMETER Procedure is NULL.
393 IN EFI_MP_SERVICES_PROTOCOL
*This
,
394 IN EFI_AP_PROCEDURE Procedure
,
395 IN UINTN ProcessorNumber
,
396 IN EFI_EVENT WaitEvent OPTIONAL
,
397 IN UINTN TimeoutInMicroseconds
,
398 IN VOID
*ProcedureArgument OPTIONAL
,
399 OUT BOOLEAN
*Finished OPTIONAL
402 CPU_DATA_BLOCK
*CpuData
;
407 if (Finished
!= NULL
) {
412 // Check whether caller processor is BSP
414 BspNumber
= GetBspNumber ();
415 WhoAmI (This
, &CallerNumber
);
416 if (CallerNumber
!= BspNumber
) {
417 return EFI_DEVICE_ERROR
;
421 // Check whether processor with the handle specified by ProcessorNumber exists
423 if (ProcessorNumber
>= mNumberOfProcessors
) {
424 return EFI_NOT_FOUND
;
428 // Check whether specified processor is BSP
430 if (ProcessorNumber
== BspNumber
) {
431 return EFI_INVALID_PARAMETER
;
435 // Check parameter Procedure
437 if (Procedure
== NULL
) {
438 return EFI_INVALID_PARAMETER
;
441 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
444 // Temporarily suppress CheckAPsStatus()
446 mStopCheckAPsStatus
= TRUE
;
449 // Check whether specified AP is disabled
451 if (CpuData
->State
== CpuStateDisabled
) {
452 mStopCheckAPsStatus
= FALSE
;
453 return EFI_INVALID_PARAMETER
;
457 // Check whether specified AP is busy
459 if (CpuData
->State
!= CpuStateIdle
) {
460 mStopCheckAPsStatus
= FALSE
;
461 return EFI_NOT_READY
;
465 // Wakeup specified AP for Procedure.
467 AcquireSpinLock (&CpuData
->CpuDataLock
);
468 CpuData
->State
= CpuStateReady
;
469 ReleaseSpinLock (&CpuData
->CpuDataLock
);
478 // If WaitEvent is not NULL, execute in non-blocking mode.
479 // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
480 // CheckAPsStatus() will check completion and timeout periodically.
482 CpuData
->WaitEvent
= WaitEvent
;
483 CpuData
->Finished
= Finished
;
484 CpuData
->ExpectedTime
= CalculateTimeout (TimeoutInMicroseconds
, &CpuData
->CurrentTime
);
487 // Allow CheckAPsStatus()
489 mStopCheckAPsStatus
= FALSE
;
491 if (WaitEvent
!= NULL
) {
496 // If WaitEvent is NULL, execute in blocking mode.
497 // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expires.
500 Status
= CheckThisAP (ProcessorNumber
);
501 } while (Status
== EFI_NOT_READY
);
507 Implementation of SwitchBSP() service of MP Services Protocol.
509 This service switches the requested AP to be the BSP from that point onward.
510 This service may only be called from the current BSP.
512 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
513 @param ProcessorNumber The handle number of processor.
514 @param EnableOldBSP Whether to enable or disable the original BSP.
516 @retval EFI_SUCCESS BSP successfully switched.
517 @retval EFI_DEVICE_ERROR Caller processor is AP.
518 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
519 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
520 @retval EFI_NOT_READY Specified AP is busy.
526 IN EFI_MP_SERVICES_PROTOCOL
*This
,
527 IN UINTN ProcessorNumber
,
528 IN BOOLEAN EnableOldBSP
532 CPU_DATA_BLOCK
*CpuData
;
536 UINT32 CurrentTimerValue
;
537 UINT32 CurrentTimerRegister
;
538 UINT32 CurrentTimerDivide
;
539 UINT64 CurrentTscValue
;
540 BOOLEAN OldInterruptState
;
543 // Check whether caller processor is BSP
545 BspNumber
= GetBspNumber ();
546 WhoAmI (This
, &CallerNumber
);
547 if (CallerNumber
!= BspNumber
) {
548 return EFI_DEVICE_ERROR
;
552 // Check whether processor with the handle specified by ProcessorNumber exists
554 if (ProcessorNumber
>= mNumberOfProcessors
) {
555 return EFI_NOT_FOUND
;
559 // Check whether specified processor is BSP
561 if (ProcessorNumber
== BspNumber
) {
562 return EFI_INVALID_PARAMETER
;
565 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
568 // Check whether specified AP is disabled
570 if (CpuData
->State
== CpuStateDisabled
) {
571 return EFI_INVALID_PARAMETER
;
575 // Check whether specified AP is busy
577 if (CpuData
->State
!= CpuStateIdle
) {
578 return EFI_NOT_READY
;
582 // Save and disable interrupt.
584 OldInterruptState
= SaveAndDisableInterrupts ();
587 // Record the current local APIC timer setting of BSP
589 ApicBase
= (UINTN
)AsmMsrBitFieldRead64 (MSR_IA32_APIC_BASE
, 12, 35) << 12;
590 CurrentTimerValue
= MmioRead32 (ApicBase
+ APIC_REGISTER_TIMER_COUNT
);
591 CurrentTimerRegister
= MmioRead32 (ApicBase
+ APIC_REGISTER_LVT_TIMER
);
592 CurrentTimerDivide
= MmioRead32 (ApicBase
+ APIC_REGISTER_TIMER_DIVIDE
);
594 // Set mask bit (BIT 16) of LVT Timer Register to disable its interrupt
596 MmioBitFieldWrite32 (ApicBase
+ APIC_REGISTER_LVT_TIMER
, 16, 16, 1);
599 // Record the current TSC value
601 CurrentTscValue
= AsmReadTsc ();
603 Status
= mFrameworkMpService
->SwitchBSP (
608 ASSERT_EFI_ERROR (Status
);
613 AsmWriteMsr64 (MSR_IA32_TIME_STAMP_COUNTER
, CurrentTscValue
);
616 // Restore local APIC timer setting to new BSP
618 MmioWrite32 (ApicBase
+ APIC_REGISTER_TIMER_DIVIDE
, CurrentTimerDivide
);
619 MmioWrite32 (ApicBase
+ APIC_REGISTER_TIMER_INIT_COUNT
, CurrentTimerValue
);
620 MmioWrite32 (ApicBase
+ APIC_REGISTER_LVT_TIMER
, CurrentTimerRegister
);
623 // Restore interrupt state.
625 SetInterruptState (OldInterruptState
);
627 ChangeCpuState (BspNumber
, EnableOldBSP
);
633 Implementation of EnableDisableAP() service of MP Services Protocol.
635 This service lets the caller enable or disable an AP.
636 This service may only be called from the BSP.
638 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
639 @param ProcessorNumber The handle number of processor.
640 @param EnableAP Indicates whether the newstate of the AP is enabled or disabled.
641 @param HealthFlag Indicates new health state of the AP..
643 @retval EFI_SUCCESS AP successfully enabled or disabled.
644 @retval EFI_DEVICE_ERROR Caller processor is AP.
645 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
646 @retval EFI_INVALID_PARAMETERS ProcessorNumber specifies the BSP.
652 IN EFI_MP_SERVICES_PROTOCOL
*This
,
653 IN UINTN ProcessorNumber
,
655 IN UINT32
*HealthFlag OPTIONAL
660 EFI_MP_HEALTH HealthState
;
661 EFI_MP_HEALTH
*HealthStatePointer
;
665 // Check whether caller processor is BSP
667 BspNumber
= GetBspNumber ();
668 WhoAmI (This
, &CallerNumber
);
669 if (CallerNumber
!= BspNumber
) {
670 return EFI_DEVICE_ERROR
;
674 // Check whether processor with the handle specified by ProcessorNumber exists
676 if (ProcessorNumber
>= mNumberOfProcessors
) {
677 return EFI_NOT_FOUND
;
681 // Check whether specified processor is BSP
683 if (ProcessorNumber
== BspNumber
) {
684 return EFI_INVALID_PARAMETER
;
687 if (HealthFlag
== NULL
) {
688 HealthStatePointer
= NULL
;
690 if ((*HealthFlag
& PROCESSOR_HEALTH_STATUS_BIT
) == 0) {
691 HealthState
.Flags
.Uint32
= 1;
693 HealthState
.Flags
.Uint32
= 0;
695 HealthState
.TestStatus
= 0;
697 HealthStatePointer
= &HealthState
;
700 Status
= mFrameworkMpService
->EnableDisableAP (
706 ASSERT_EFI_ERROR (Status
);
708 ChangeCpuState (ProcessorNumber
, EnableAP
);
714 Implementation of WhoAmI() service of MP Services Protocol.
716 This service lets the caller processor get its handle number.
717 This service may be called from the BSP and APs.
719 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
720 @param ProcessorNumber Pointer to the handle number of AP.
722 @retval EFI_SUCCESS Processor number successfully returned.
723 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL
729 IN EFI_MP_SERVICES_PROTOCOL
*This
,
730 OUT UINTN
*ProcessorNumber
735 if (ProcessorNumber
== NULL
) {
736 return EFI_INVALID_PARAMETER
;
739 Status
= mFrameworkMpService
->WhoAmI (
743 ASSERT_EFI_ERROR (Status
);
749 Checks APs' status periodically.
751 This function is triggerred by timer perodically to check the
752 state of APs for StartupAllAPs() and StartupThisAP() executed
753 in non-blocking mode.
755 @param Event Event triggered.
756 @param Context Parameter passed with the event.
766 UINTN ProcessorNumber
;
767 CPU_DATA_BLOCK
*CpuData
;
771 // If CheckAPsStatus() is stopped, then return immediately.
773 if (mStopCheckAPsStatus
) {
778 // First, check whether pending StartupAllAPs() exists.
780 if (mMPSystemData
.WaitEvent
!= NULL
) {
782 Status
= CheckAllAPs ();
784 // If all APs finish for StartupAllAPs(), signal the WaitEvent for it..
786 if (Status
!= EFI_NOT_READY
) {
787 Status
= gBS
->SignalEvent (mMPSystemData
.WaitEvent
);
788 mMPSystemData
.WaitEvent
= NULL
;
793 // Second, check whether pending StartupThisAPs() callings exist.
795 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
797 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
799 if (CpuData
->WaitEvent
== NULL
) {
803 Status
= CheckThisAP (ProcessorNumber
);
805 if (Status
!= EFI_NOT_READY
) {
806 gBS
->SignalEvent (CpuData
->WaitEvent
);
807 CpuData
->WaitEvent
= NULL
;
814 Checks status of all APs.
816 This function checks whether all APs have finished task assigned by StartupAllAPs(),
817 and whether timeout expires.
819 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
820 @retval EFI_TIMEOUT The timeout expires.
821 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
829 UINTN ProcessorNumber
;
830 UINTN NextProcessorNumber
;
834 CPU_DATA_BLOCK
*CpuData
;
836 NextProcessorNumber
= 0;
839 // Go through all APs that are responsible for the StartupAllAPs().
841 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
842 if (!mMPSystemData
.CpuList
[ProcessorNumber
]) {
846 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
849 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
850 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
851 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
853 AcquireSpinLock (&CpuData
->CpuDataLock
);
854 CpuState
= CpuData
->State
;
855 ReleaseSpinLock (&CpuData
->CpuDataLock
);
857 if (CpuState
== CpuStateFinished
) {
858 mMPSystemData
.FinishCount
++;
859 mMPSystemData
.CpuList
[ProcessorNumber
] = FALSE
;
861 AcquireSpinLock (&CpuData
->CpuDataLock
);
862 CpuData
->State
= CpuStateIdle
;
863 ReleaseSpinLock (&CpuData
->CpuDataLock
);
866 // If in Single Thread mode, then search for the next waiting AP for execution.
868 if (mMPSystemData
.SingleThread
) {
869 Status
= GetNextWaitingProcessorNumber (&NextProcessorNumber
);
871 if (!EFI_ERROR (Status
)) {
874 mMPSystemData
.Procedure
,
875 mMPSystemData
.ProcArguments
883 // If all APs finish, return EFI_SUCCESS.
885 if (mMPSystemData
.FinishCount
== mMPSystemData
.StartCount
) {
890 // If timeout expires, report timeout.
892 if (CheckTimeout (&mMPSystemData
.CurrentTime
, &mMPSystemData
.TotalTime
, mMPSystemData
.ExpectedTime
)) {
894 // If FailedCpuList is not NULL, record all failed APs in it.
896 if (mMPSystemData
.FailedCpuList
!= NULL
) {
897 *mMPSystemData
.FailedCpuList
= AllocatePool ((mMPSystemData
.StartCount
- mMPSystemData
.FinishCount
+ 1) * sizeof(UINTN
));
898 ASSERT (*mMPSystemData
.FailedCpuList
!= NULL
);
902 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
904 // Check whether this processor is responsible for StartupAllAPs().
906 if (mMPSystemData
.CpuList
[ProcessorNumber
]) {
908 // Reset failed APs to idle state
910 ResetProcessorToIdleState (ProcessorNumber
);
911 mMPSystemData
.CpuList
[ProcessorNumber
] = FALSE
;
912 if (mMPSystemData
.FailedCpuList
!= NULL
) {
913 (*mMPSystemData
.FailedCpuList
)[ListIndex
++] = ProcessorNumber
;
917 if (mMPSystemData
.FailedCpuList
!= NULL
) {
918 (*mMPSystemData
.FailedCpuList
)[ListIndex
] = END_OF_CPU_LIST
;
922 return EFI_NOT_READY
;
926 Checks status of specified AP.
928 This function checks whether specified AP has finished task assigned by StartupThisAP(),
929 and whether timeout expires.
931 @param ProcessorNumber The handle number of processor.
933 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
934 @retval EFI_TIMEOUT The timeout expires.
935 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
940 UINTN ProcessorNumber
943 CPU_DATA_BLOCK
*CpuData
;
946 ASSERT (ProcessorNumber
< mNumberOfProcessors
);
947 ASSERT (ProcessorNumber
< MAX_CPU_NUMBER
);
949 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
952 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
953 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
954 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
956 AcquireSpinLock (&CpuData
->CpuDataLock
);
957 CpuState
= CpuData
->State
;
958 ReleaseSpinLock (&CpuData
->CpuDataLock
);
961 // If the APs finishes for StartupThisAP(), return EFI_SUCCESS.
963 if (CpuState
== CpuStateFinished
) {
965 AcquireSpinLock (&CpuData
->CpuDataLock
);
966 CpuData
->State
= CpuStateIdle
;
967 ReleaseSpinLock (&CpuData
->CpuDataLock
);
969 if (CpuData
->Finished
!= NULL
) {
970 *(CpuData
->Finished
) = TRUE
;
975 // If timeout expires for StartupThisAP(), report timeout.
977 if (CheckTimeout (&CpuData
->CurrentTime
, &CpuData
->TotalTime
, CpuData
->ExpectedTime
)) {
979 if (CpuData
->Finished
!= NULL
) {
980 *(CpuData
->Finished
) = FALSE
;
983 // Reset failed AP to idle state
985 ResetProcessorToIdleState (ProcessorNumber
);
990 return EFI_NOT_READY
;
994 Calculate timeout value and return the current performance counter value.
996 Calculate the number of performance counter ticks required for a timeout.
997 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1000 @param TimeoutInMicroseconds Timeout value in microseconds.
1001 @param CurrentTime Returns the current value of the performance counter.
1003 @return Expected timestamp counter for timeout.
1004 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1010 IN UINTN TimeoutInMicroseconds
,
1011 OUT UINT64
*CurrentTime
1015 // Read the current value of the performance counter
1017 *CurrentTime
= GetPerformanceCounter ();
1020 // If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1023 if (TimeoutInMicroseconds
== 0) {
1028 // GetPerformanceCounterProperties () returns the timestamp counter's frequency
1029 // in Hz. So multiply the return value with TimeoutInMicroseconds and then divide
1030 // it by 1,000,000, to get the number of ticks for the timeout value.
1034 GetPerformanceCounterProperties (NULL
, NULL
),
1035 TimeoutInMicroseconds
1042 Checks whether timeout expires.
1044 Check whether the number of ellapsed performance counter ticks required for a timeout condition
1045 has been reached. If Timeout is zero, which means infinity, return value is always FALSE.
1047 @param PreviousTime On input, the value of the performance counter when it was last read.
1048 On output, the current value of the performance counter
1049 @param TotalTime The total amount of ellapsed time in performance counter ticks.
1050 @param Timeout The number of performance counter ticks required to reach a timeout condition.
1052 @retval TRUE A timeout condition has been reached.
1053 @retval FALSE A timeout condition has not been reached.
1058 IN OUT UINT64
*PreviousTime
,
1059 IN UINT64
*TotalTime
,
1072 GetPerformanceCounterProperties (&Start
, &End
);
1073 Cycle
= End
- Start
;
1078 CurrentTime
= GetPerformanceCounter();
1079 Delta
= (INT64
) (CurrentTime
- *PreviousTime
);
1086 *TotalTime
+= Delta
;
1087 *PreviousTime
= CurrentTime
;
1088 if (*TotalTime
> Timeout
) {
1095 Searches for the next waiting AP.
1097 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
1099 @param NextProcessorNumber Pointer to the processor number of the next waiting AP.
1101 @retval EFI_SUCCESS The next waiting AP has been found.
1102 @retval EFI_NOT_FOUND No waiting AP exists.
1106 GetNextWaitingProcessorNumber (
1107 OUT UINTN
*NextProcessorNumber
1110 UINTN ProcessorNumber
;
1112 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
1114 if (mMPSystemData
.CpuList
[ProcessorNumber
]) {
1115 *NextProcessorNumber
= ProcessorNumber
;
1120 return EFI_NOT_FOUND
;
1124 Programs Local APIC registers for virtual wire mode.
1126 This function programs Local APIC registers for virtual wire mode.
1128 @param Bsp Indicates whether the programmed processor is going to be BSP
1132 ProgramVirtualWireMode (
1139 ApicBase
= (UINTN
)AsmMsrBitFieldRead64 (MSR_IA32_APIC_BASE
, 12, 35) << 12;
1142 // Program the Spurious Vector entry
1143 // Set bit 8 (APIC Software Enable/Disable) to enable local APIC,
1144 // and set Spurious Vector as 0x0F.
1146 MmioBitFieldWrite32 (ApicBase
+ APIC_REGISTER_SPURIOUS_VECTOR_OFFSET
, 0, 9, 0x10F);
1149 // Program the LINT0 vector entry as ExtInt
1150 // Set bits 8..10 to 7 as ExtInt Delivery Mode,
1151 // and clear bits for Delivery Status, Interrupt Input Pin Polarity, Remote IRR,
1152 // Trigger Mode, and Mask
1155 DisableInterrupts ();
1157 Value
= MmioRead32 (ApicBase
+ APIC_REGISTER_LINT0_VECTOR_OFFSET
);
1158 Value
= BitFieldWrite32 (Value
, 8, 10, 7);
1159 Value
= BitFieldWrite32 (Value
, 12, 16, 0);
1162 // For APs, LINT0 is masked
1164 Value
= BitFieldWrite32 (Value
, 16, 16, 1);
1166 MmioWrite32 (ApicBase
+ APIC_REGISTER_LINT0_VECTOR_OFFSET
, Value
);
1169 // Program the LINT1 vector entry as NMI
1170 // Set bits 8..10 to 4 as NMI Delivery Mode,
1171 // and clear bits for Delivery Status, Interrupt Input Pin Polarity, Remote IRR,
1173 // For BSP clear Mask bit, and for AP set mask bit.
1175 Value
= MmioRead32 (ApicBase
+ APIC_REGISTER_LINT1_VECTOR_OFFSET
);
1176 Value
= BitFieldWrite32 (Value
, 8, 10, 4);
1177 Value
= BitFieldWrite32 (Value
, 12, 16, 0);
1180 // For APs, LINT1 is masked
1182 Value
= BitFieldWrite32 (Value
, 16, 16, 1);
1184 MmioWrite32 (ApicBase
+ APIC_REGISTER_LINT1_VECTOR_OFFSET
, Value
);
1189 Wrapper function for all procedures assigned to AP.
1191 Wrapper function for all procedures assigned to AP via MP service protocol.
1192 It controls states of AP and invokes assigned precedure.
1200 EFI_AP_PROCEDURE Procedure
;
1202 UINTN ProcessorNumber
;
1203 CPU_DATA_BLOCK
*CpuData
;
1206 // Program virtual wire mode for AP, since it will be lost after AP wake up
1208 ProgramVirtualWireMode (FALSE
);
1211 // Initialize Debug Agent to support source level debug on AP code.
1213 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP
, NULL
, NULL
);
1215 WhoAmI (&mMpService
, &ProcessorNumber
);
1216 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
1218 AcquireSpinLock (&CpuData
->CpuDataLock
);
1219 CpuData
->State
= CpuStateBusy
;
1220 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1223 // Now let us check it out.
1225 AcquireSpinLock (&CpuData
->CpuDataLock
);
1226 Procedure
= CpuData
->Procedure
;
1227 Parameter
= CpuData
->Parameter
;
1228 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1230 if (Procedure
!= NULL
) {
1232 Procedure (Parameter
);
1235 // if BSP is switched to AP, it continue execute from here, but it carries register state
1236 // of the old AP, so need to reload CpuData (might be stored in a register after compiler
1237 // optimization) to make sure it points to the right data
1239 WhoAmI (&mMpService
, &ProcessorNumber
);
1240 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
1242 AcquireSpinLock (&CpuData
->CpuDataLock
);
1243 CpuData
->Procedure
= NULL
;
1244 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1247 AcquireSpinLock (&CpuData
->CpuDataLock
);
1248 CpuData
->State
= CpuStateFinished
;
1249 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1253 Sends INIT-SIPI-SIPI to AP.
1255 This function sends INIT-SIPI-SIPI to AP, and assign procedure specified by ApFunction.
1257 @param Broadcast If TRUE, broadcase IPI to all APs; otherwise, send to specified AP.
1258 @param ApicID The Local APIC ID of the specified AP. If Broadcast is TRUE, it is ignored.
1259 @param ApFunction The procedure for AP to work on.
1264 IN BOOLEAN Broadcast
,
1273 UINT32 VectorNumber
;
1274 UINT32 DeliveryMode
;
1276 mExchangeInfo
->ApFunction
= ApFunction
;
1277 mExchangeInfo
->StackStart
= mStackStartAddress
;
1281 ICRLow
= BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT
| TRIGGER_MODE_LEVEL_BIT
| ASSERT_BIT
;
1283 ICRHigh
= ApicID
<< 24;
1284 ICRLow
= SPECIFY_CPU_MODE_BIT
| TRIGGER_MODE_LEVEL_BIT
| ASSERT_BIT
;
1288 DeliveryMode
= DELIVERY_MODE_INIT
;
1289 ICRLow
|= VectorNumber
| (DeliveryMode
<< 8);
1291 ApicBase
= (UINTN
)AsmMsrBitFieldRead64 (MSR_IA32_APIC_BASE
, 12, 35) << 12;;
1294 // Write Interrupt Command Registers to send INIT IPI.
1296 MmioWrite32 (ApicBase
+ APIC_REGISTER_ICR_HIGH_OFFSET
, ICRHigh
);
1297 MmioWrite32 (ApicBase
+ APIC_REGISTER_ICR_LOW_OFFSET
, ICRLow
);
1299 MicroSecondDelay (10);
1301 VectorNumber
= (UINT32
) RShiftU64 (mStartupVector
, 12);
1302 DeliveryMode
= DELIVERY_MODE_SIPI
;
1304 ICRLow
= BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT
| TRIGGER_MODE_LEVEL_BIT
| ASSERT_BIT
;
1306 ICRLow
= SPECIFY_CPU_MODE_BIT
| TRIGGER_MODE_LEVEL_BIT
| ASSERT_BIT
;
1309 ICRLow
|= VectorNumber
| (DeliveryMode
<< 8);
1312 // Write Interrupt Command Register to send first SIPI IPI.
1314 MmioWrite32 (ApicBase
+ APIC_REGISTER_ICR_LOW_OFFSET
, ICRLow
);
1316 MicroSecondDelay (200);
1319 // Write Interrupt Command Register to send second SIPI IPI.
1321 MmioWrite32 (ApicBase
+ APIC_REGISTER_ICR_LOW_OFFSET
, ICRLow
);
1325 Function to wake up a specified AP and assign procedure to it.
1327 @param ProcessorNumber Handle number of the specified processor.
1328 @param Procedure Procedure to assign.
1329 @param ProcArguments Argument for Procedure.
1334 IN UINTN ProcessorNumber
,
1335 IN EFI_AP_PROCEDURE Procedure
,
1336 IN VOID
*ProcArguments
1340 CPU_DATA_BLOCK
*CpuData
;
1341 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
1343 ASSERT (ProcessorNumber
< mNumberOfProcessors
);
1344 ASSERT (ProcessorNumber
< MAX_CPU_NUMBER
);
1346 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
1348 AcquireSpinLock (&CpuData
->CpuDataLock
);
1349 CpuData
->Parameter
= ProcArguments
;
1350 CpuData
->Procedure
= Procedure
;
1351 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1353 Status
= GetProcessorInfo (
1356 &ProcessorInfoBuffer
1358 ASSERT_EFI_ERROR (Status
);
1362 (UINT32
) ProcessorInfoBuffer
.ProcessorId
,
1363 (VOID
*) (UINTN
) ApProcWrapper
1368 Terminate AP's task and set it to idle state.
1370 This function terminates AP's task due to timeout by sending INIT-SIPI,
1371 and sends it to idle state.
1373 @param ProcessorNumber Handle number of the specified processor.
1377 ResetProcessorToIdleState (
1378 UINTN ProcessorNumber
1382 CPU_DATA_BLOCK
*CpuData
;
1383 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
1385 Status
= GetProcessorInfo (
1388 &ProcessorInfoBuffer
1390 ASSERT_EFI_ERROR (Status
);
1394 (UINT32
) ProcessorInfoBuffer
.ProcessorId
,
1398 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
1400 AcquireSpinLock (&CpuData
->CpuDataLock
);
1401 CpuData
->State
= CpuStateIdle
;
1402 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1406 Worker function of EnableDisableAP ()
1408 Worker function of EnableDisableAP (). Changes state of specified processor.
1410 @param ProcessorNumber Processor number of specified AP.
1411 @param NewState Desired state of the specified AP.
1413 @retval EFI_SUCCESS AP's state successfully changed.
1418 IN UINTN ProcessorNumber
,
1422 CPU_DATA_BLOCK
*CpuData
;
1424 ASSERT (ProcessorNumber
< mNumberOfProcessors
);
1425 ASSERT (ProcessorNumber
< MAX_CPU_NUMBER
);
1427 CpuData
= &mMPSystemData
.CpuData
[ProcessorNumber
];
1430 AcquireSpinLock (&CpuData
->CpuDataLock
);
1431 CpuData
->State
= CpuStateDisabled
;
1432 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1434 AcquireSpinLock (&CpuData
->CpuDataLock
);
1435 CpuData
->State
= CpuStateIdle
;
1436 ReleaseSpinLock (&CpuData
->CpuDataLock
);
1443 Test memory region of EfiGcdMemoryTypeReserved.
1445 @param Length The length of memory region to test.
1447 @retval EFI_SUCCESS The memory region passes test.
1448 @retval EFI_NOT_FOUND The memory region is not reserved memory.
1449 @retval EFI_DEVICE_ERROR The memory fails on test.
1453 TestReservedMemory (
1458 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor
;
1459 EFI_PHYSICAL_ADDRESS Address
;
1460 UINTN LengthCovered
;
1461 UINTN RemainingLength
;
1464 // Walk through the memory descriptors covering the memory range.
1466 Address
= mStartupVector
;
1467 RemainingLength
= Length
;
1468 while (Address
< mStartupVector
+ Length
) {
1469 Status
= gDS
->GetMemorySpaceDescriptor(
1473 if (EFI_ERROR (Status
)) {
1474 return EFI_NOT_FOUND
;
1477 if (Descriptor
.GcdMemoryType
!= EfiGcdMemoryTypeReserved
) {
1478 return EFI_NOT_FOUND
;
1481 // Calculated the length of the intersected range.
1483 LengthCovered
= (UINTN
) (Descriptor
.BaseAddress
+ Descriptor
.Length
- Address
);
1484 if (LengthCovered
> RemainingLength
) {
1485 LengthCovered
= RemainingLength
;
1488 Status
= mGenMemoryTest
->CompatibleRangeTest (
1493 if (EFI_ERROR (Status
)) {
1494 return EFI_DEVICE_ERROR
;
1497 Address
+= LengthCovered
;
1498 RemainingLength
-= LengthCovered
;
1505 Allocates startup vector for APs.
1507 This function allocates Startup vector for APs.
1509 @param Size The size of startup vector.
1513 AllocateStartupVector (
1519 Status
= gBS
->LocateProtocol (
1520 &gEfiGenericMemTestProtocolGuid
,
1522 (VOID
**) &mGenMemoryTest
1524 if (EFI_ERROR (Status
)) {
1525 mGenMemoryTest
= NULL
;
1528 for (mStartupVector
= 0x7F000; mStartupVector
>= 0x2000; mStartupVector
-= EFI_PAGE_SIZE
) {
1529 if (mGenMemoryTest
!= NULL
) {
1531 // Test memory if it is EfiGcdMemoryTypeReserved.
1533 Status
= TestReservedMemory (EFI_SIZE_TO_PAGES (Size
) * EFI_PAGE_SIZE
);
1534 if (Status
== EFI_DEVICE_ERROR
) {
1539 Status
= gBS
->AllocatePages (
1541 EfiBootServicesCode
,
1542 EFI_SIZE_TO_PAGES (Size
),
1546 if (!EFI_ERROR (Status
)) {
1551 ASSERT_EFI_ERROR (Status
);
1555 Prepares Startup Vector for APs.
1557 This function prepares Startup Vector for APs.
1561 PrepareAPStartupVector (
1565 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
1566 IA32_DESCRIPTOR GdtrForBSP
;
1567 IA32_DESCRIPTOR IdtrForBSP
;
1568 EFI_PHYSICAL_ADDRESS GdtForAP
;
1569 EFI_PHYSICAL_ADDRESS IdtForAP
;
1573 // Get the address map of startup code for AP,
1574 // including code size, and offset of long jump instructions to redirect.
1576 AsmGetAddressMap (&AddressMap
);
1579 // Allocate a 4K-aligned region under 1M for startup vector for AP.
1580 // The region contains AP startup code and exchange data between BSP and AP.
1582 AllocateStartupVector (AddressMap
.Size
+ sizeof (MP_CPU_EXCHANGE_INFO
));
1585 // Copy AP startup code to startup vector, and then redirect the long jump
1586 // instructions for mode switching.
1588 CopyMem ((VOID
*) (UINTN
) mStartupVector
, AddressMap
.RendezvousFunnelAddress
, AddressMap
.Size
);
1589 *(UINT32
*) (UINTN
) (mStartupVector
+ AddressMap
.FlatJumpOffset
+ 3) = (UINT32
) (mStartupVector
+ AddressMap
.PModeEntryOffset
);
1591 // For IA32 mode, LongJumpOffset is filled with zero. If non-zero, then we are in X64 mode, so further redirect for long mode switch.
1593 if (AddressMap
.LongJumpOffset
!= 0) {
1594 *(UINT32
*) (UINTN
) (mStartupVector
+ AddressMap
.LongJumpOffset
+ 2) = (UINT32
) (mStartupVector
+ AddressMap
.LModeEntryOffset
);
1598 // Get the start address of exchange data between BSP and AP.
1600 mExchangeInfo
= (MP_CPU_EXCHANGE_INFO
*) (UINTN
) (mStartupVector
+ AddressMap
.Size
);
1602 ZeroMem ((VOID
*) mExchangeInfo
, sizeof (MP_CPU_EXCHANGE_INFO
));
1604 mStackStartAddress
= AllocatePages (EFI_SIZE_TO_PAGES (MAX_CPU_NUMBER
* AP_STACK_SIZE
));
1605 mExchangeInfo
->StackSize
= AP_STACK_SIZE
;
1607 AsmReadGdtr (&GdtrForBSP
);
1608 AsmReadIdtr (&IdtrForBSP
);
1611 // Allocate memory under 4G to hold GDT for APs
1613 GdtForAP
= 0xffffffff;
1614 Status
= gBS
->AllocatePages (
1616 EfiBootServicesData
,
1617 EFI_SIZE_TO_PAGES ((GdtrForBSP
.Limit
+ 1) + (IdtrForBSP
.Limit
+ 1)),
1620 ASSERT_EFI_ERROR (Status
);
1622 IdtForAP
= (UINTN
) GdtForAP
+ GdtrForBSP
.Limit
+ 1;
1624 CopyMem ((VOID
*) (UINTN
) GdtForAP
, (VOID
*) GdtrForBSP
.Base
, GdtrForBSP
.Limit
+ 1);
1625 CopyMem ((VOID
*) (UINTN
) IdtForAP
, (VOID
*) IdtrForBSP
.Base
, IdtrForBSP
.Limit
+ 1);
1627 mExchangeInfo
->GdtrProfile
.Base
= (UINTN
) GdtForAP
;
1628 mExchangeInfo
->GdtrProfile
.Limit
= GdtrForBSP
.Limit
;
1629 mExchangeInfo
->IdtrProfile
.Base
= (UINTN
) IdtForAP
;
1630 mExchangeInfo
->IdtrProfile
.Limit
= IdtrForBSP
.Limit
;
1632 mExchangeInfo
->BufferStart
= (UINT32
) mStartupVector
;
1633 mExchangeInfo
->Cr3
= (UINT32
) (AsmReadCr3 ());
1637 Prepares memory region for processor configuration.
1639 This function prepares memory region for processor configuration.
1643 PrepareMemoryForConfiguration (
1650 // Initialize Spin Locks for system
1652 InitializeSpinLock (&mMPSystemData
.APSerializeLock
);
1653 for (Index
= 0; Index
< MAX_CPU_NUMBER
; Index
++) {
1654 InitializeSpinLock (&mMPSystemData
.CpuData
[Index
].CpuDataLock
);
1657 PrepareAPStartupVector ();
1661 Gets the processor number of BSP.
1663 @return The processor number of BSP.
1671 UINTN ProcessorNumber
;
1672 EFI_MP_PROC_CONTEXT ProcessorContextBuffer
;
1676 BufferSize
= sizeof (EFI_MP_PROC_CONTEXT
);
1678 for (ProcessorNumber
= 0; ProcessorNumber
< mNumberOfProcessors
; ProcessorNumber
++) {
1679 Status
= mFrameworkMpService
->GetProcessorContext (
1680 mFrameworkMpService
,
1683 &ProcessorContextBuffer
1685 ASSERT_EFI_ERROR (Status
);
1687 if (ProcessorContextBuffer
.Designation
== EfiCpuBSP
) {
1691 ASSERT (ProcessorNumber
< mNumberOfProcessors
);
1693 return ProcessorNumber
;
1697 Entrypoint of MP Services Protocol thunk driver.
1699 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1700 @param[in] SystemTable A pointer to the EFI System Table.
1702 @retval EFI_SUCCESS The entry point is executed successfully.
1707 InitializeMpServicesProtocol (
1708 IN EFI_HANDLE ImageHandle
,
1709 IN EFI_SYSTEM_TABLE
*SystemTable
1714 PrepareMemoryForConfiguration ();
1717 // Locates Framework version MP Services Protocol
1719 Status
= gBS
->LocateProtocol (
1720 &gFrameworkEfiMpServiceProtocolGuid
,
1722 (VOID
**) &mFrameworkMpService
1724 ASSERT_EFI_ERROR (Status
);
1726 Status
= mFrameworkMpService
->GetGeneralMPInfo (
1727 mFrameworkMpService
,
1728 &mNumberOfProcessors
,
1734 ASSERT_EFI_ERROR (Status
);
1735 ASSERT (mNumberOfProcessors
< MAX_CPU_NUMBER
);
1738 // Create timer event to check AP state for non-blocking execution.
1740 Status
= gBS
->CreateEvent (
1741 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1745 &mMPSystemData
.CheckAPsEvent
1747 ASSERT_EFI_ERROR (Status
);
1750 // Now install the MP services protocol.
1752 Status
= gBS
->InstallProtocolInterface (
1754 &gEfiMpServiceProtocolGuid
,
1755 EFI_NATIVE_INTERFACE
,
1758 ASSERT_EFI_ERROR (Status
);
1761 // Launch the timer event to check AP state.
1763 Status
= gBS
->SetTimer (
1764 mMPSystemData
.CheckAPsEvent
,
1768 ASSERT_EFI_ERROR (Status
);