2 CPU MP Initialize Library common functions.
4 Copyright (c) 2016, 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.
17 EFI_GUID mCpuInitMpLibHobGuid
= CPU_INIT_MP_LIB_HOB_GUID
;
20 The function will check if BSP Execute Disable is enabled.
21 DxeIpl may have enabled Execute Disable for BSP,
22 APs need to get the status and sync up the settings.
24 @retval TRUE BSP Execute Disable is enabled.
25 @retval FALSE BSP Execute Disable is not enabled.
28 IsBspExecuteDisableEnabled (
33 CPUID_EXTENDED_CPU_SIG_EDX Edx
;
34 MSR_IA32_EFER_REGISTER EferMsr
;
38 AsmCpuid (CPUID_EXTENDED_FUNCTION
, &Eax
, NULL
, NULL
, NULL
);
39 if (Eax
>= CPUID_EXTENDED_CPU_SIG
) {
40 AsmCpuid (CPUID_EXTENDED_CPU_SIG
, NULL
, NULL
, NULL
, &Edx
.Uint32
);
43 // Bit 20: Execute Disable Bit available.
45 if (Edx
.Bits
.NX
!= 0) {
46 EferMsr
.Uint64
= AsmReadMsr64 (MSR_IA32_EFER
);
49 // Bit 11: Execute Disable Bit enable.
51 if (EferMsr
.Bits
.NXE
!= 0) {
61 Get the Application Processors state.
63 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
69 IN CPU_AP_DATA
*CpuData
72 return CpuData
->State
;
76 Set the Application Processors state.
78 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
79 @param[in] State The AP status
83 IN CPU_AP_DATA
*CpuData
,
87 AcquireSpinLock (&CpuData
->ApLock
);
88 CpuData
->State
= State
;
89 ReleaseSpinLock (&CpuData
->ApLock
);
93 Save the volatile registers required to be restored following INIT IPI.
95 @param[out] VolatileRegisters Returns buffer saved the volatile resisters
98 SaveVolatileRegisters (
99 OUT CPU_VOLATILE_REGISTERS
*VolatileRegisters
102 CPUID_VERSION_INFO_EDX VersionInfoEdx
;
104 VolatileRegisters
->Cr0
= AsmReadCr0 ();
105 VolatileRegisters
->Cr3
= AsmReadCr3 ();
106 VolatileRegisters
->Cr4
= AsmReadCr4 ();
108 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, NULL
, &VersionInfoEdx
.Uint32
);
109 if (VersionInfoEdx
.Bits
.DE
!= 0) {
111 // If processor supports Debugging Extensions feature
112 // by CPUID.[EAX=01H]:EDX.BIT2
114 VolatileRegisters
->Dr0
= AsmReadDr0 ();
115 VolatileRegisters
->Dr1
= AsmReadDr1 ();
116 VolatileRegisters
->Dr2
= AsmReadDr2 ();
117 VolatileRegisters
->Dr3
= AsmReadDr3 ();
118 VolatileRegisters
->Dr6
= AsmReadDr6 ();
119 VolatileRegisters
->Dr7
= AsmReadDr7 ();
124 Restore the volatile registers following INIT IPI.
126 @param[in] VolatileRegisters Pointer to volatile resisters
127 @param[in] IsRestoreDr TRUE: Restore DRx if supported
128 FALSE: Do not restore DRx
131 RestoreVolatileRegisters (
132 IN CPU_VOLATILE_REGISTERS
*VolatileRegisters
,
133 IN BOOLEAN IsRestoreDr
136 CPUID_VERSION_INFO_EDX VersionInfoEdx
;
138 AsmWriteCr0 (VolatileRegisters
->Cr0
);
139 AsmWriteCr3 (VolatileRegisters
->Cr3
);
140 AsmWriteCr4 (VolatileRegisters
->Cr4
);
143 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, NULL
, &VersionInfoEdx
.Uint32
);
144 if (VersionInfoEdx
.Bits
.DE
!= 0) {
146 // If processor supports Debugging Extensions feature
147 // by CPUID.[EAX=01H]:EDX.BIT2
149 AsmWriteDr0 (VolatileRegisters
->Dr0
);
150 AsmWriteDr1 (VolatileRegisters
->Dr1
);
151 AsmWriteDr2 (VolatileRegisters
->Dr2
);
152 AsmWriteDr3 (VolatileRegisters
->Dr3
);
153 AsmWriteDr6 (VolatileRegisters
->Dr6
);
154 AsmWriteDr7 (VolatileRegisters
->Dr7
);
160 Detect whether Mwait-monitor feature is supported.
162 @retval TRUE Mwait-monitor feature is supported.
163 @retval FALSE Mwait-monitor feature is not supported.
170 CPUID_VERSION_INFO_ECX VersionInfoEcx
;
172 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, &VersionInfoEcx
.Uint32
, NULL
);
173 return (VersionInfoEcx
.Bits
.MONITOR
== 1) ? TRUE
: FALSE
;
179 @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.
181 @return The AP loop mode.
185 OUT UINT32
*MonitorFilterSize
189 CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx
;
191 ASSERT (MonitorFilterSize
!= NULL
);
193 ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
194 ASSERT (ApLoopMode
>= ApInHltLoop
&& ApLoopMode
<= ApInRunLoop
);
195 if (ApLoopMode
== ApInMwaitLoop
) {
196 if (!IsMwaitSupport ()) {
198 // If processor does not support MONITOR/MWAIT feature,
199 // force AP in Hlt-loop mode
201 ApLoopMode
= ApInHltLoop
;
205 if (ApLoopMode
!= ApInMwaitLoop
) {
206 *MonitorFilterSize
= sizeof (UINT32
);
209 // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
210 // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
212 AsmCpuid (CPUID_MONITOR_MWAIT
, NULL
, &MonitorMwaitEbx
.Uint32
, NULL
, NULL
);
213 *MonitorFilterSize
= MonitorMwaitEbx
.Bits
.LargestMonitorLineSize
;
222 @param[in, out] Buffer Pointer to private data buffer.
230 CPU_MP_DATA
*CpuMpData
;
232 CpuMpData
= (CPU_MP_DATA
*) Buffer
;
234 // Sync BSP's MTRR table to AP
236 MtrrSetAllMtrrs (&CpuMpData
->MtrrTable
);
238 // Load microcode on AP
240 MicrocodeDetect (CpuMpData
);
244 Find the current Processor number by APIC ID.
246 @param[in] CpuMpData Pointer to PEI CPU MP Data
247 @param[in] ProcessorNumber Return the pocessor number found
249 @retval EFI_SUCCESS ProcessorNumber is found and returned.
250 @retval EFI_NOT_FOUND ProcessorNumber is not found.
254 IN CPU_MP_DATA
*CpuMpData
,
255 OUT UINTN
*ProcessorNumber
258 UINTN TotalProcessorNumber
;
261 TotalProcessorNumber
= CpuMpData
->CpuCount
;
262 for (Index
= 0; Index
< TotalProcessorNumber
; Index
++) {
263 if (CpuMpData
->CpuData
[Index
].ApicId
== GetApicId ()) {
264 *ProcessorNumber
= Index
;
268 return EFI_NOT_FOUND
;
272 This function will get CPU count in the system.
274 @param[in] CpuMpData Pointer to PEI CPU MP Data
276 @return CPU count detected
279 CollectProcessorCount (
280 IN CPU_MP_DATA
*CpuMpData
284 // Send 1st broadcast IPI to APs to wakeup APs
286 CpuMpData
->InitFlag
= ApInitConfig
;
287 CpuMpData
->X2ApicEnable
= FALSE
;
288 WakeUpAP (CpuMpData
, TRUE
, 0, NULL
, NULL
);
290 // Wait for AP task to complete and then exit.
292 MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds
));
293 CpuMpData
->InitFlag
= ApInitDone
;
294 ASSERT (CpuMpData
->CpuCount
<= PcdGet32 (PcdCpuMaxLogicalProcessorNumber
));
296 // Wait for all APs finished the initialization
298 while (CpuMpData
->FinishedCount
< (CpuMpData
->CpuCount
- 1)) {
302 DEBUG ((DEBUG_INFO
, "MpInitLib: Find %d processors in system.\n", CpuMpData
->CpuCount
));
304 return CpuMpData
->CpuCount
;
308 Initialize CPU AP Data when AP is wakeup at the first time.
310 @param[in, out] CpuMpData Pointer to PEI CPU MP Data
311 @param[in] ProcessorNumber The handle number of processor
312 @param[in] BistData Processor BIST data
317 IN OUT CPU_MP_DATA
*CpuMpData
,
318 IN UINTN ProcessorNumber
,
322 CpuMpData
->CpuData
[ProcessorNumber
].Waiting
= FALSE
;
323 CpuMpData
->CpuData
[ProcessorNumber
].Health
= BistData
;
324 CpuMpData
->CpuData
[ProcessorNumber
].CpuHealthy
= (BistData
== 0) ? TRUE
: FALSE
;
325 CpuMpData
->CpuData
[ProcessorNumber
].ApicId
= GetApicId ();
326 CpuMpData
->CpuData
[ProcessorNumber
].InitialApicId
= GetInitialApicId ();
327 if (CpuMpData
->CpuData
[ProcessorNumber
].InitialApicId
>= 0xFF) {
329 // Set x2APIC mode if there are any logical processor reporting
330 // an Initial APIC ID of 255 or greater.
332 AcquireSpinLock(&CpuMpData
->MpLock
);
333 CpuMpData
->X2ApicEnable
= TRUE
;
334 ReleaseSpinLock(&CpuMpData
->MpLock
);
337 InitializeSpinLock(&CpuMpData
->CpuData
[ProcessorNumber
].ApLock
);
338 SetApState (&CpuMpData
->CpuData
[ProcessorNumber
], CpuStateIdle
);
342 This function will be called from AP reset code if BSP uses WakeUpAP.
344 @param[in] ExchangeInfo Pointer to the MP exchange info buffer
345 @param[in] NumApsExecuting Number of current executing AP
350 IN MP_CPU_EXCHANGE_INFO
*ExchangeInfo
,
351 IN UINTN NumApsExecuting
354 CPU_MP_DATA
*CpuMpData
;
355 UINTN ProcessorNumber
;
356 EFI_AP_PROCEDURE Procedure
;
359 volatile UINT32
*ApStartupSignalBuffer
;
362 // AP finished assembly code and begin to execute C code
364 CpuMpData
= ExchangeInfo
->CpuMpData
;
366 ProgramVirtualWireMode ();
369 if (CpuMpData
->InitFlag
== ApInitConfig
) {
373 InterlockedIncrement ((UINT32
*) &CpuMpData
->CpuCount
);
374 ProcessorNumber
= NumApsExecuting
;
376 // This is first time AP wakeup, get BIST information from AP stack
378 BistData
= *(UINT32
*) (CpuMpData
->Buffer
+ ProcessorNumber
* CpuMpData
->CpuApStackSize
- sizeof (UINTN
));
380 // Do some AP initialize sync
382 ApInitializeSync (CpuMpData
);
384 // Sync BSP's Control registers to APs
386 RestoreVolatileRegisters (&CpuMpData
->CpuData
[0].VolatileRegisters
, FALSE
);
387 InitializeApData (CpuMpData
, ProcessorNumber
, BistData
);
388 ApStartupSignalBuffer
= CpuMpData
->CpuData
[ProcessorNumber
].StartupApSignal
;
391 // Execute AP function if AP is ready
393 GetProcessorNumber (CpuMpData
, &ProcessorNumber
);
395 // Clear AP start-up signal when AP waken up
397 ApStartupSignalBuffer
= CpuMpData
->CpuData
[ProcessorNumber
].StartupApSignal
;
398 InterlockedCompareExchange32 (
399 (UINT32
*) ApStartupSignalBuffer
,
403 if (CpuMpData
->ApLoopMode
== ApInHltLoop
) {
405 // Restore AP's volatile registers saved
407 RestoreVolatileRegisters (&CpuMpData
->CpuData
[ProcessorNumber
].VolatileRegisters
, TRUE
);
410 if (GetApState (&CpuMpData
->CpuData
[ProcessorNumber
]) == CpuStateReady
) {
411 Procedure
= (EFI_AP_PROCEDURE
)CpuMpData
->CpuData
[ProcessorNumber
].ApFunction
;
412 Parameter
= (VOID
*) CpuMpData
->CpuData
[ProcessorNumber
].ApFunctionArgument
;
413 if (Procedure
!= NULL
) {
414 SetApState (&CpuMpData
->CpuData
[ProcessorNumber
], CpuStateBusy
);
416 // Invoke AP function here
418 Procedure (Parameter
);
420 // Re-get the CPU APICID and Initial APICID
422 CpuMpData
->CpuData
[ProcessorNumber
].ApicId
= GetApicId ();
423 CpuMpData
->CpuData
[ProcessorNumber
].InitialApicId
= GetInitialApicId ();
425 SetApState (&CpuMpData
->CpuData
[ProcessorNumber
], CpuStateFinished
);
430 // AP finished executing C code
432 InterlockedIncrement ((UINT32
*) &CpuMpData
->FinishedCount
);
435 // Place AP is specified loop mode
437 if (CpuMpData
->ApLoopMode
== ApInHltLoop
) {
439 // Save AP volatile registers
441 SaveVolatileRegisters (&CpuMpData
->CpuData
[ProcessorNumber
].VolatileRegisters
);
443 // Place AP in HLT-loop
446 DisableInterrupts ();
452 DisableInterrupts ();
453 if (CpuMpData
->ApLoopMode
== ApInMwaitLoop
) {
455 // Place AP in MWAIT-loop
457 AsmMonitor ((UINTN
) ApStartupSignalBuffer
, 0, 0);
458 if (*ApStartupSignalBuffer
!= WAKEUP_AP_SIGNAL
) {
460 // Check AP start-up signal again.
461 // If AP start-up signal is not set, place AP into
462 // the specified C-state
464 AsmMwait (CpuMpData
->ApTargetCState
<< 4, 0);
466 } else if (CpuMpData
->ApLoopMode
== ApInRunLoop
) {
468 // Place AP in Run-loop
476 // If AP start-up signal is written, AP is waken up
477 // otherwise place AP in loop again
479 if (*ApStartupSignalBuffer
== WAKEUP_AP_SIGNAL
) {
487 Wait for AP wakeup and write AP start-up signal till AP is waken up.
489 @param[in] ApStartupSignalBuffer Pointer to AP wakeup signal
493 IN
volatile UINT32
*ApStartupSignalBuffer
497 // If AP is waken up, StartupApSignal should be cleared.
498 // Otherwise, write StartupApSignal again till AP waken up.
500 while (InterlockedCompareExchange32 (
501 (UINT32
*) ApStartupSignalBuffer
,
510 This function will fill the exchange info structure.
512 @param[in] CpuMpData Pointer to CPU MP Data
516 FillExchangeInfoData (
517 IN CPU_MP_DATA
*CpuMpData
520 volatile MP_CPU_EXCHANGE_INFO
*ExchangeInfo
;
522 ExchangeInfo
= CpuMpData
->MpCpuExchangeInfo
;
523 ExchangeInfo
->Lock
= 0;
524 ExchangeInfo
->StackStart
= CpuMpData
->Buffer
;
525 ExchangeInfo
->StackSize
= CpuMpData
->CpuApStackSize
;
526 ExchangeInfo
->BufferStart
= CpuMpData
->WakeupBuffer
;
527 ExchangeInfo
->ModeOffset
= CpuMpData
->AddressMap
.ModeEntryOffset
;
529 ExchangeInfo
->CodeSegment
= AsmReadCs ();
530 ExchangeInfo
->DataSegment
= AsmReadDs ();
532 ExchangeInfo
->Cr3
= AsmReadCr3 ();
534 ExchangeInfo
->CFunction
= (UINTN
) ApWakeupFunction
;
535 ExchangeInfo
->NumApsExecuting
= 0;
536 ExchangeInfo
->CpuMpData
= CpuMpData
;
538 ExchangeInfo
->EnableExecuteDisable
= IsBspExecuteDisableEnabled ();
541 // Get the BSP's data of GDT and IDT
543 AsmReadGdtr ((IA32_DESCRIPTOR
*) &ExchangeInfo
->GdtrProfile
);
544 AsmReadIdtr ((IA32_DESCRIPTOR
*) &ExchangeInfo
->IdtrProfile
);
548 This function will be called by BSP to wakeup AP.
550 @param[in] CpuMpData Pointer to CPU MP Data
551 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
552 FALSE: Send IPI to AP by ApicId
553 @param[in] ProcessorNumber The handle number of specified processor
554 @param[in] Procedure The function to be invoked by AP
555 @param[in] ProcedureArgument The argument to be passed into AP function
559 IN CPU_MP_DATA
*CpuMpData
,
560 IN BOOLEAN Broadcast
,
561 IN UINTN ProcessorNumber
,
562 IN EFI_AP_PROCEDURE Procedure
, OPTIONAL
563 IN VOID
*ProcedureArgument OPTIONAL
566 volatile MP_CPU_EXCHANGE_INFO
*ExchangeInfo
;
568 CPU_AP_DATA
*CpuData
;
569 BOOLEAN ResetVectorRequired
;
571 CpuMpData
->FinishedCount
= 0;
572 ResetVectorRequired
= FALSE
;
574 if (CpuMpData
->ApLoopMode
== ApInHltLoop
||
575 CpuMpData
->InitFlag
!= ApInitDone
) {
576 ResetVectorRequired
= TRUE
;
577 AllocateResetVector (CpuMpData
);
578 FillExchangeInfoData (CpuMpData
);
579 } else if (CpuMpData
->ApLoopMode
== ApInMwaitLoop
) {
581 // Get AP target C-state each time when waking up AP,
582 // for it maybe updated by platform again
584 CpuMpData
->ApTargetCState
= PcdGet8 (PcdCpuApTargetCstate
);
587 ExchangeInfo
= CpuMpData
->MpCpuExchangeInfo
;
590 for (Index
= 0; Index
< CpuMpData
->CpuCount
; Index
++) {
591 if (Index
!= CpuMpData
->BspNumber
) {
592 CpuData
= &CpuMpData
->CpuData
[Index
];
593 CpuData
->ApFunction
= (UINTN
) Procedure
;
594 CpuData
->ApFunctionArgument
= (UINTN
) ProcedureArgument
;
595 SetApState (CpuData
, CpuStateReady
);
596 if (CpuMpData
->InitFlag
!= ApInitConfig
) {
597 *(UINT32
*) CpuData
->StartupApSignal
= WAKEUP_AP_SIGNAL
;
601 if (ResetVectorRequired
) {
605 SendInitSipiSipiAllExcludingSelf ((UINT32
) ExchangeInfo
->BufferStart
);
607 if (CpuMpData
->InitFlag
!= ApInitConfig
) {
609 // Wait all APs waken up if this is not the 1st broadcast of SIPI
611 for (Index
= 0; Index
< CpuMpData
->CpuCount
; Index
++) {
612 CpuData
= &CpuMpData
->CpuData
[Index
];
613 if (Index
!= CpuMpData
->BspNumber
) {
614 WaitApWakeup (CpuData
->StartupApSignal
);
619 CpuData
= &CpuMpData
->CpuData
[ProcessorNumber
];
620 CpuData
->ApFunction
= (UINTN
) Procedure
;
621 CpuData
->ApFunctionArgument
= (UINTN
) ProcedureArgument
;
622 SetApState (CpuData
, CpuStateReady
);
624 // Wakeup specified AP
626 ASSERT (CpuMpData
->InitFlag
!= ApInitConfig
);
627 *(UINT32
*) CpuData
->StartupApSignal
= WAKEUP_AP_SIGNAL
;
628 if (ResetVectorRequired
) {
631 (UINT32
) ExchangeInfo
->BufferStart
635 // Wait specified AP waken up
637 WaitApWakeup (CpuData
->StartupApSignal
);
640 if (ResetVectorRequired
) {
641 FreeResetVector (CpuMpData
);
646 MP Initialize Library initialization.
648 This service will allocate AP reset vector and wakeup all APs to do APs
651 This service must be invoked before all other MP Initialize Library
654 @retval EFI_SUCCESS MP initialization succeeds.
655 @retval Others MP initialization fails.
660 MpInitLibInitialize (
664 UINT32 MaxLogicalProcessorNumber
;
666 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
668 UINT32 MonitorFilterSize
;
671 CPU_MP_DATA
*CpuMpData
;
673 UINT8
*MonitorBuffer
;
675 UINTN ApResetVectorSize
;
676 UINTN BackupBufferAddr
;
677 MaxLogicalProcessorNumber
= PcdGet32(PcdCpuMaxLogicalProcessorNumber
);
679 AsmGetAddressMap (&AddressMap
);
680 ApResetVectorSize
= AddressMap
.RendezvousFunnelSize
+ sizeof (MP_CPU_EXCHANGE_INFO
);
681 ApStackSize
= PcdGet32(PcdCpuApStackSize
);
682 ApLoopMode
= GetApLoopMode (&MonitorFilterSize
);
684 BufferSize
= ApStackSize
* MaxLogicalProcessorNumber
;
685 BufferSize
+= MonitorFilterSize
* MaxLogicalProcessorNumber
;
686 BufferSize
+= sizeof (CPU_MP_DATA
);
687 BufferSize
+= ApResetVectorSize
;
688 BufferSize
+= (sizeof (CPU_AP_DATA
) + sizeof (CPU_INFO_IN_HOB
))* MaxLogicalProcessorNumber
;
689 MpBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (BufferSize
));
690 ASSERT (MpBuffer
!= NULL
);
691 ZeroMem (MpBuffer
, BufferSize
);
692 Buffer
= (UINTN
) MpBuffer
;
694 MonitorBuffer
= (UINT8
*) (Buffer
+ ApStackSize
* MaxLogicalProcessorNumber
);
695 BackupBufferAddr
= (UINTN
) MonitorBuffer
+ MonitorFilterSize
* MaxLogicalProcessorNumber
;
696 CpuMpData
= (CPU_MP_DATA
*) (BackupBufferAddr
+ ApResetVectorSize
);
697 CpuMpData
->Buffer
= Buffer
;
698 CpuMpData
->CpuApStackSize
= ApStackSize
;
699 CpuMpData
->BackupBuffer
= BackupBufferAddr
;
700 CpuMpData
->BackupBufferSize
= ApResetVectorSize
;
701 CpuMpData
->EndOfPeiFlag
= FALSE
;
702 CpuMpData
->WakeupBuffer
= (UINTN
) -1;
703 CpuMpData
->CpuCount
= 1;
704 CpuMpData
->BspNumber
= 0;
705 CpuMpData
->WaitEvent
= NULL
;
706 CpuMpData
->CpuData
= (CPU_AP_DATA
*) (CpuMpData
+ 1);
707 CpuMpData
->CpuInfoInHob
= (UINT64
) (UINTN
) (CpuMpData
->CpuData
+ MaxLogicalProcessorNumber
);
708 InitializeSpinLock(&CpuMpData
->MpLock
);
710 // Save BSP's Control registers to APs
712 SaveVolatileRegisters (&CpuMpData
->CpuData
[0].VolatileRegisters
);
714 // Set BSP basic information
716 InitializeApData (CpuMpData
, 0, 0);
718 // Save assembly code information
720 CopyMem (&CpuMpData
->AddressMap
, &AddressMap
, sizeof (MP_ASSEMBLY_ADDRESS_MAP
));
722 // Finally set AP loop mode
724 CpuMpData
->ApLoopMode
= ApLoopMode
;
725 DEBUG ((DEBUG_INFO
, "AP Loop Mode is %d\n", CpuMpData
->ApLoopMode
));
727 // Set up APs wakeup signal buffer
729 for (Index
= 0; Index
< MaxLogicalProcessorNumber
; Index
++) {
730 CpuMpData
->CpuData
[Index
].StartupApSignal
=
731 (UINT32
*)(MonitorBuffer
+ MonitorFilterSize
* Index
);
734 // Load Microcode on BSP
736 MicrocodeDetect (CpuMpData
);
738 // Store BSP's MTRR setting
740 MtrrGetAllMtrrs (&CpuMpData
->MtrrTable
);
744 // Wakeup all APs and calculate the processor count in system
746 CollectProcessorCount (CpuMpData
);
748 // Initialize global data for MP support
750 InitMpGlobalData (CpuMpData
);
756 Gets detailed MP-related information on the requested processor at the
757 instant this call is made. This service may only be called from the BSP.
759 @param[in] ProcessorNumber The handle number of processor.
760 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
761 the requested processor is deposited.
762 @param[out] HealthData Return processor health data.
764 @retval EFI_SUCCESS Processor information was returned.
765 @retval EFI_DEVICE_ERROR The calling processor is an AP.
766 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
767 @retval EFI_NOT_FOUND The processor with the handle specified by
768 ProcessorNumber does not exist in the platform.
769 @retval EFI_NOT_READY MP Initialize Library is not initialized.
774 MpInitLibGetProcessorInfo (
775 IN UINTN ProcessorNumber
,
776 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
,
777 OUT EFI_HEALTH_FLAGS
*HealthData OPTIONAL
780 return EFI_UNSUPPORTED
;
783 This return the handle number for the calling processor. This service may be
784 called from the BSP and APs.
786 @param[out] ProcessorNumber Pointer to the handle number of AP.
787 The range is from 0 to the total number of
788 logical processors minus 1. The total number of
789 logical processors can be retrieved by
790 MpInitLibGetNumberOfProcessors().
792 @retval EFI_SUCCESS The current processor handle number was returned
794 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
795 @retval EFI_NOT_READY MP Initialize Library is not initialized.
801 OUT UINTN
*ProcessorNumber
804 return EFI_UNSUPPORTED
;
807 Retrieves the number of logical processor in the platform and the number of
808 those logical processors that are enabled on this boot. This service may only
809 be called from the BSP.
811 @param[out] NumberOfProcessors Pointer to the total number of logical
812 processors in the system, including the BSP
814 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
815 processors that exist in system, including
818 @retval EFI_SUCCESS The number of logical processors and enabled
819 logical processors was retrieved.
820 @retval EFI_DEVICE_ERROR The calling processor is an AP.
821 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
823 @retval EFI_NOT_READY MP Initialize Library is not initialized.
828 MpInitLibGetNumberOfProcessors (
829 OUT UINTN
*NumberOfProcessors
, OPTIONAL
830 OUT UINTN
*NumberOfEnabledProcessors OPTIONAL
833 return EFI_UNSUPPORTED
;
836 Get pointer to CPU MP Data structure from GUIDed HOB.
838 @return The pointer to CPU MP Data structure.
841 GetCpuMpDataFromGuidedHob (
845 EFI_HOB_GUID_TYPE
*GuidHob
;
847 CPU_MP_DATA
*CpuMpData
;
850 GuidHob
= GetFirstGuidHob (&mCpuInitMpLibHobGuid
);
851 if (GuidHob
!= NULL
) {
852 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
853 CpuMpData
= (CPU_MP_DATA
*) (*(UINTN
*) DataInHob
);