4 Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINTN gMaxLogicalProcessorNumber
;
20 UINTN gPollInterval
= 100; // 100 microseconds
22 MP_SYSTEM_DATA mMpSystemData
;
24 VOID
*mCommonStack
= 0;
25 VOID
*mTopOfApCommonStack
= 0;
26 VOID
*mApStackStart
= 0;
28 EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate
= {
29 GetNumberOfProcessors
,
31 NULL
, // StartupAllAPs,
39 Check whether caller processor is BSP.
41 @retval TRUE the caller is BSP
42 @retval FALSE the caller is AP
51 CPU_DATA_BLOCK
*CpuData
;
55 WhoAmI (&mMpServicesTemplate
, &CpuIndex
);
56 CpuData
= &mMpSystemData
.CpuDatas
[CpuIndex
];
58 return CpuData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
? TRUE
: FALSE
;
62 Get the Application Processors state.
64 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
66 @retval CPU_STATE the AP status
71 IN CPU_DATA_BLOCK
*CpuData
76 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
80 State
= CpuData
->State
;
81 ReleaseSpinLock (&CpuData
->CpuDataLock
);
87 Set the Application Processors state.
89 @param CpuData The pointer to CPU_DATA_BLOCK of specified AP
90 @param State The AP status
95 IN CPU_DATA_BLOCK
*CpuData
,
99 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
103 CpuData
->State
= State
;
104 ReleaseSpinLock (&CpuData
->CpuDataLock
);
108 Set the Application Processor prepare to run a function specified
111 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
112 @param Procedure A pointer to the function to be run on enabled APs of the system
113 @param ProcedureArgument Pointer to the optional parameter of the assigned function
118 IN CPU_DATA_BLOCK
*CpuData
,
119 IN EFI_AP_PROCEDURE Procedure
,
120 IN VOID
*ProcedureArgument
123 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
127 CpuData
->Parameter
= ProcedureArgument
;
128 CpuData
->Procedure
= Procedure
;
129 ReleaseSpinLock (&CpuData
->CpuDataLock
);
133 Check the Application Processors Status whether contains the Flags.
135 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
136 @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION
138 @retval TRUE the AP status includes the StatusFlag
139 @retval FALSE the AP status excludes the StatusFlag
144 IN CPU_DATA_BLOCK
*CpuData
,
150 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
154 Ret
= CpuData
->Info
.StatusFlag
& Flags
;
155 ReleaseSpinLock (&CpuData
->CpuDataLock
);
161 Bitwise-Or of the Application Processors Status with the Flags.
163 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
164 @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION
169 IN CPU_DATA_BLOCK
*CpuData
,
173 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
177 CpuData
->Info
.StatusFlag
|= Flags
;
178 ReleaseSpinLock (&CpuData
->CpuDataLock
);
182 Bitwise-AndNot of the Application Processors Status with the Flags.
184 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
185 @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION
189 CpuStatusFlagAndNot (
190 IN CPU_DATA_BLOCK
*CpuData
,
194 while (!AcquireSpinLockOrFail (&CpuData
->CpuDataLock
)) {
198 CpuData
->Info
.StatusFlag
&= ~Flags
;
199 ReleaseSpinLock (&CpuData
->CpuDataLock
);
203 Searches for the next blocking AP.
205 Search for the next AP that is put in blocking state by single-threaded StartupAllAPs().
207 @param NextNumber Pointer to the processor number of the next blocking AP.
209 @retval EFI_SUCCESS The next blocking AP has been found.
210 @retval EFI_NOT_FOUND No blocking AP exists.
214 GetNextBlockedNumber (
215 OUT UINTN
*NextNumber
220 CPU_DATA_BLOCK
*CpuData
;
222 for (Number
= 0; Number
< mMpSystemData
.NumberOfProcessors
; Number
++) {
223 CpuData
= &mMpSystemData
.CpuDatas
[Number
];
224 if (TestCpuStatusFlag (CpuData
, PROCESSOR_AS_BSP_BIT
)) {
231 CpuState
= GetApState (CpuData
);
232 if (CpuState
== CpuStateBlocked
) {
233 *NextNumber
= Number
;
238 return EFI_NOT_FOUND
;
242 This service retrieves the number of logical processor in the platform
243 and the number of those logical processors that are enabled on this boot.
244 This service may only be called from the BSP.
246 This function is used to retrieve the following information:
247 - The number of logical processors that are present in the system.
248 - The number of enabled logical processors in the system at the instant
251 Because MP Service Protocol provides services to enable and disable processors
252 dynamically, the number of enabled logical processors may vary during the
253 course of a boot session.
255 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
256 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
257 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
258 is returned in NumberOfProcessors, the number of currently enabled processor
259 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
261 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
263 @param[out] NumberOfProcessors Pointer to the total number of logical
264 processors in the system, including the BSP
266 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
267 processors that exist in system, including
270 @retval EFI_SUCCESS The number of logical processors and enabled
271 logical processors was retrieved.
272 @retval EFI_DEVICE_ERROR The calling processor is an AP.
273 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
274 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
279 GetNumberOfProcessors (
280 IN EFI_MP_SERVICES_PROTOCOL
*This
,
281 OUT UINTN
*NumberOfProcessors
,
282 OUT UINTN
*NumberOfEnabledProcessors
285 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
286 return EFI_INVALID_PARAMETER
;
290 return EFI_DEVICE_ERROR
;
293 *NumberOfProcessors
= mMpSystemData
.NumberOfProcessors
;
294 *NumberOfEnabledProcessors
= mMpSystemData
.NumberOfEnabledProcessors
;
299 Gets detailed MP-related information on the requested processor at the
300 instant this call is made. This service may only be called from the BSP.
302 This service retrieves detailed MP-related information about any processor
303 on the platform. Note the following:
304 - The processor information may change during the course of a boot session.
305 - The information presented here is entirely MP related.
307 Information regarding the number of caches and their sizes, frequency of operation,
308 slot numbers is all considered platform-related information and is not provided
311 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
313 @param[in] ProcessorNumber The handle number of processor.
314 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
315 the requested processor is deposited.
317 @retval EFI_SUCCESS Processor information was returned.
318 @retval EFI_DEVICE_ERROR The calling processor is an AP.
319 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
320 @retval EFI_NOT_FOUND The processor with the handle specified by
321 ProcessorNumber does not exist in the platform.
327 IN EFI_MP_SERVICES_PROTOCOL
*This
,
328 IN UINTN ProcessorNumber
,
329 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
332 if (ProcessorInfoBuffer
== NULL
) {
333 return EFI_INVALID_PARAMETER
;
337 return EFI_DEVICE_ERROR
;
340 if (ProcessorNumber
>= mMpSystemData
.NumberOfProcessors
) {
341 return EFI_NOT_FOUND
;
344 CopyMem (ProcessorInfoBuffer
, &mMpSystemData
.CpuDatas
[ProcessorNumber
], sizeof (EFI_PROCESSOR_INFORMATION
));
349 This service lets the caller get one enabled AP to execute a caller-provided
350 function. The caller can request the BSP to either wait for the completion
351 of the AP or just proceed with the next task by using the EFI event mechanism.
352 See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
353 execution support. This service may only be called from the BSP.
355 This function is used to dispatch one enabled AP to the function specified by
356 Procedure passing in the argument specified by ProcedureArgument. If WaitEvent
357 is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
358 TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
359 BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
360 is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
361 then EFI_UNSUPPORTED must be returned.
363 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
364 from Procedure, then execution of Procedure by the AP is terminated. The AP is
365 available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
366 EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
368 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
370 @param[in] Procedure A pointer to the function to be run on
371 enabled APs of the system. See type
373 @param[in] ProcessorNumber The handle number of the AP. The range is
374 from 0 to the total number of logical
375 processors minus 1. The total number of
376 logical processors can be retrieved by
377 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
378 @param[in] WaitEvent The event created by the caller with CreateEvent()
379 service. If it is NULL, then execute in
380 blocking mode. BSP waits until all APs finish
381 or TimeoutInMicroseconds expires. If it's
382 not NULL, then execute in non-blocking mode.
383 BSP requests the function specified by
384 Procedure to be started on all the enabled
385 APs, and go on executing immediately. If
386 all return from Procedure or TimeoutInMicroseconds
387 expires, this event is signaled. The BSP
388 can use the CheckEvent() or WaitForEvent()
389 services to check the state of event. Type
390 EFI_EVENT is defined in CreateEvent() in
391 the Unified Extensible Firmware Interface
393 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
394 APs to return from Procedure, either for
395 blocking or non-blocking mode. Zero means
396 infinity. If the timeout expires before
397 all APs return from Procedure, then Procedure
398 on the failed APs is terminated. All enabled
399 APs are available for next function assigned
400 by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
401 or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
402 If the timeout expires in blocking mode,
403 BSP returns EFI_TIMEOUT. If the timeout
404 expires in non-blocking mode, WaitEvent
405 is signaled with SignalEvent().
406 @param[in] ProcedureArgument The parameter passed into Procedure for
408 @param[out] Finished If NULL, this parameter is ignored. In
409 blocking mode, this parameter is ignored.
410 In non-blocking mode, if AP returns from
411 Procedure before the timeout expires, its
412 content is set to TRUE. Otherwise, the
413 value is set to FALSE. The caller can
414 determine if the AP returned from Procedure
415 by evaluating this value.
417 @retval EFI_SUCCESS In blocking mode, specified AP finished before
419 @retval EFI_SUCCESS In non-blocking mode, the function has been
420 dispatched to specified AP.
421 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
422 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
424 @retval EFI_DEVICE_ERROR The calling processor is an AP.
425 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
426 the specified AP has finished.
427 @retval EFI_NOT_READY The specified AP is busy.
428 @retval EFI_NOT_FOUND The processor with the handle specified by
429 ProcessorNumber does not exist.
430 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
431 @retval EFI_INVALID_PARAMETER Procedure is NULL.
437 IN EFI_MP_SERVICES_PROTOCOL
*This
,
438 IN EFI_AP_PROCEDURE Procedure
,
439 IN UINTN ProcessorNumber
,
440 IN EFI_EVENT WaitEvent OPTIONAL
,
441 IN UINTN TimeoutInMicroseconds
,
442 IN VOID
*ProcedureArgument OPTIONAL
,
443 OUT BOOLEAN
*Finished OPTIONAL
446 CPU_DATA_BLOCK
*CpuData
;
451 if (Finished
!= NULL
) {
456 return EFI_DEVICE_ERROR
;
459 if (Procedure
== NULL
) {
460 return EFI_INVALID_PARAMETER
;
463 if (ProcessorNumber
>= mMpSystemData
.NumberOfProcessors
) {
464 return EFI_NOT_FOUND
;
467 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
468 if (TestCpuStatusFlag (CpuData
, PROCESSOR_AS_BSP_BIT
) ||
469 !TestCpuStatusFlag (CpuData
, PROCESSOR_ENABLED_BIT
)) {
470 return EFI_INVALID_PARAMETER
;
473 if (GetApState (CpuData
) != CpuStateIdle
) {
474 return EFI_NOT_READY
;
477 SetApState (CpuData
, CpuStateReady
);
479 SetApProcedure (CpuData
, Procedure
, ProcedureArgument
);
481 CpuData
->Timeout
= TimeoutInMicroseconds
;
482 CpuData
->WaitEvent
= WaitEvent
;
483 CpuData
->TimeoutActive
= !!(TimeoutInMicroseconds
);
484 CpuData
->Finished
= Finished
;
486 if (WaitEvent
!= NULL
) {
490 Status
= gBS
->SetTimer (
491 CpuData
->CheckThisAPEvent
,
493 EFI_TIMER_PERIOD_MICROSECONDS (100)
502 if (GetApState (CpuData
) == CpuStateFinished
) {
503 SetApState (CpuData
, CpuStateIdle
);
507 if (CpuData
->TimeoutActive
&& CpuData
->Timeout
< 0) {
508 ResetProcessorToIdleState (CpuData
);
512 gBS
->Stall (gPollInterval
);
513 CpuData
->Timeout
-= gPollInterval
;
520 This service lets the caller enable or disable an AP from this point onward.
521 This service may only be called from the BSP.
523 This service allows the caller enable or disable an AP from this point onward.
524 The caller can optionally specify the health status of the AP by Health. If
525 an AP is being disabled, then the state of the disabled AP is implementation
526 dependent. If an AP is enabled, then the implementation must guarantee that a
527 complete initialization sequence is performed on the AP, so the AP is in a state
528 that is compatible with an MP operating system. This service may not be supported
529 after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
531 If the enable or disable AP operation cannot be completed prior to the return
532 from this service, then EFI_UNSUPPORTED must be returned.
534 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
535 @param[in] ProcessorNumber The handle number of AP that is to become the new
536 BSP. The range is from 0 to the total number of
537 logical processors minus 1. The total number of
538 logical processors can be retrieved by
539 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
540 @param[in] EnableAP Specifies the new state for the processor for
541 enabled, FALSE for disabled.
542 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
543 the new health status of the AP. This flag
544 corresponds to StatusFlag defined in
545 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
546 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
547 bits are ignored. If it is NULL, this parameter
550 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
551 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
552 prior to this service returning.
553 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
554 @retval EFI_DEVICE_ERROR The calling processor is an AP.
555 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
557 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
563 IN EFI_MP_SERVICES_PROTOCOL
*This
,
564 IN UINTN ProcessorNumber
,
566 IN UINT32
*HealthFlag OPTIONAL
569 CPU_DATA_BLOCK
*CpuData
;
572 return EFI_DEVICE_ERROR
;
575 if (ProcessorNumber
>= mMpSystemData
.NumberOfProcessors
) {
576 return EFI_NOT_FOUND
;
579 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
580 if (TestCpuStatusFlag (CpuData
, PROCESSOR_AS_BSP_BIT
)) {
581 return EFI_INVALID_PARAMETER
;
584 if (GetApState (CpuData
) != CpuStateIdle
) {
585 return EFI_UNSUPPORTED
;
589 if (!(TestCpuStatusFlag (CpuData
, PROCESSOR_ENABLED_BIT
))) {
590 mMpSystemData
.NumberOfEnabledProcessors
++;
592 CpuStatusFlagOr (CpuData
, PROCESSOR_ENABLED_BIT
);
594 if (TestCpuStatusFlag (CpuData
, PROCESSOR_ENABLED_BIT
)) {
595 mMpSystemData
.NumberOfEnabledProcessors
--;
597 CpuStatusFlagAndNot (CpuData
, PROCESSOR_ENABLED_BIT
);
600 if (HealthFlag
!= NULL
) {
601 CpuStatusFlagAndNot (CpuData
, (UINT32
)~PROCESSOR_HEALTH_STATUS_BIT
);
602 CpuStatusFlagOr (CpuData
, (*HealthFlag
& PROCESSOR_HEALTH_STATUS_BIT
));
609 This return the handle number for the calling processor. This service may be
610 called from the BSP and APs.
612 This service returns the processor handle number for the calling processor.
613 The returned value is in the range from 0 to the total number of logical
614 processors minus 1. The total number of logical processors can be retrieved
615 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
616 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
617 is returned. Otherwise, the current processors handle number is returned in
618 ProcessorNumber, and EFI_SUCCESS is returned.
620 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
621 @param[out] ProcessorNumber The handle number of AP that is to become the new
622 BSP. The range is from 0 to the total number of
623 logical processors minus 1. The total number of
624 logical processors can be retrieved by
625 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
627 @retval EFI_SUCCESS The current processor handle number was returned
629 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
635 IN EFI_MP_SERVICES_PROTOCOL
*This
,
636 OUT UINTN
*ProcessorNumber
642 if (ProcessorNumber
== NULL
) {
643 return EFI_INVALID_PARAMETER
;
646 ProcessorId
= GetApicId ();
647 for (Index
= 0; Index
< mMpSystemData
.NumberOfProcessors
; Index
++) {
648 if (mMpSystemData
.CpuDatas
[Index
].Info
.ProcessorId
== ProcessorId
) {
653 *ProcessorNumber
= Index
;
658 Terminate AP's task and set it to idle state.
660 This function terminates AP's task due to timeout by sending INIT-SIPI,
661 and sends it to idle state.
663 @param CpuData the pointer to CPU_DATA_BLOCK of specified AP
667 ResetProcessorToIdleState (
668 IN CPU_DATA_BLOCK
*CpuData
674 Application Processors do loop routine
675 after switch to its own stack.
677 @param Context1 A pointer to the context to pass into the function.
678 @param Context2 A pointer to the context to pass into the function.
682 ProcessorToIdleState (
683 IN VOID
*Context1
, OPTIONAL
684 IN VOID
*Context2 OPTIONAL
687 DEBUG ((DEBUG_INFO
, "Ap apicid is %d\n", GetApicId ()));
689 AsmApDoneWithCommonStack ();
696 Checks AP' status periodically.
698 This function is triggerred by timer perodically to check the
699 state of AP forStartupThisAP() executed in non-blocking mode.
701 @param Event Event triggered.
702 @param Context Parameter passed with the event.
712 CPU_DATA_BLOCK
*CpuData
;
715 CpuData
= (CPU_DATA_BLOCK
*) Context
;
716 if (CpuData
->TimeoutActive
) {
717 CpuData
->Timeout
-= gPollInterval
;
720 CpuState
= GetApState (CpuData
);
722 if (CpuState
== CpuStateFinished
) {
723 if (CpuData
->Finished
) {
724 *CpuData
->Finished
= TRUE
;
726 SetApState (CpuData
, CpuStateIdle
);
730 if (CpuData
->TimeoutActive
&& CpuData
->Timeout
< 0) {
731 if (CpuState
!= CpuStateIdle
&&
733 *CpuData
->Finished
= FALSE
;
735 ResetProcessorToIdleState (CpuData
);
742 gBS
->SetTimer (CpuData
->CheckThisAPEvent
, TimerCancel
, 0);
743 if (CpuData
->WaitEvent
) {
744 gBS
->SignalEvent (CpuData
->WaitEvent
);
745 CpuData
->WaitEvent
= NULL
;
750 Application Processor C code entry point.
761 FillInProcessorInformation (FALSE
, mMpSystemData
.NumberOfProcessors
);
762 TopOfApStack
= (UINT8
*)mApStackStart
+ gApStackSize
;
763 mApStackStart
= TopOfApStack
;
765 mMpSystemData
.NumberOfProcessors
++;
768 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)ProcessorToIdleState
,
775 This function is called by all processors (both BSP and AP) once and collects MP related data.
777 @param Bsp TRUE if the CPU is BSP
778 @param ProcessorNumber The specific processor number
780 @retval EFI_SUCCESS Data for the processor collected and filled in
784 FillInProcessorInformation (
786 IN UINTN ProcessorNumber
789 CPU_DATA_BLOCK
*CpuData
;
792 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
793 ProcessorId
= GetApicId ();
794 CpuData
->Info
.ProcessorId
= ProcessorId
;
795 CpuData
->Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
797 CpuData
->Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
799 CpuData
->Info
.Location
.Package
= ProcessorId
;
800 CpuData
->Info
.Location
.Core
= 0;
801 CpuData
->Info
.Location
.Thread
= 0;
802 CpuData
->State
= Bsp
? CpuStateBuzy
: CpuStateIdle
;
804 CpuData
->Procedure
= NULL
;
805 CpuData
->Parameter
= NULL
;
806 InitializeSpinLock (&CpuData
->CpuDataLock
);
812 Prepare the System Data.
814 @retval EFI_SUCCESS the System Data finished initilization.
822 UINTN ProcessorNumber
;
823 CPU_DATA_BLOCK
*CpuData
;
826 ZeroMem (&mMpSystemData
, sizeof (MP_SYSTEM_DATA
));
828 mMpSystemData
.NumberOfProcessors
= 1;
829 mMpSystemData
.NumberOfEnabledProcessors
= 1;
831 mMpSystemData
.CpuDatas
= AllocateZeroPool (sizeof (CPU_DATA_BLOCK
) * gMaxLogicalProcessorNumber
);
832 ASSERT(mMpSystemData
.CpuDatas
!= NULL
);
834 for (ProcessorNumber
= 0; ProcessorNumber
< gMaxLogicalProcessorNumber
; ProcessorNumber
++) {
835 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
836 Status
= gBS
->CreateEvent (
837 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
841 &CpuData
->CheckThisAPEvent
843 ASSERT_EFI_ERROR (Status
);
849 FillInProcessorInformation (TRUE
, 0);
855 Initialize Multi-processor support.
859 InitializeMpSupport (
863 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
864 if (gMaxLogicalProcessorNumber
< 1) {
865 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
869 if (gMaxLogicalProcessorNumber
== 1) {
873 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
874 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
876 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
877 ASSERT (mApStackStart
!= NULL
);
880 // the first buffer of stack size used for common stack, when the amount of AP
881 // more than 1, we should never free the common stack which maybe used for AP reset.
883 mCommonStack
= mApStackStart
;
884 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
885 mApStackStart
= mTopOfApCommonStack
;
889 if (mMpSystemData
.NumberOfProcessors
== 1) {
890 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
894 if (mMpSystemData
.NumberOfProcessors
< gMaxLogicalProcessorNumber
) {
895 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES (
896 (gMaxLogicalProcessorNumber
- mMpSystemData
.NumberOfProcessors
) *