2 CPU PEI Module installs CPU Multiple Processor PPI.
4 Copyright (c) 2015 - 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 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList
= {
18 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
19 &gEfiEndOfPeiSignalPpiGuid
,
24 Sort the APIC ID of all processors.
26 This function sorts the APIC ID of all processors so that processor number is
27 assigned in the ascending order of APIC ID which eases MP debugging.
29 @param PeiCpuMpData Pointer to PEI CPU MP Data
33 IN PEI_CPU_MP_DATA
*PeiCpuMpData
43 ApCount
= PeiCpuMpData
->CpuCount
- 1;
46 for (Index1
= 0; Index1
< ApCount
; Index1
++) {
49 // Sort key is the hardware default APIC ID
51 ApicId
= PeiCpuMpData
->CpuData
[Index1
].ApicId
;
52 for (Index2
= Index1
+ 1; Index2
<= ApCount
; Index2
++) {
53 if (ApicId
> PeiCpuMpData
->CpuData
[Index2
].ApicId
) {
55 ApicId
= PeiCpuMpData
->CpuData
[Index2
].ApicId
;
58 if (Index3
!= Index1
) {
59 CopyMem (&CpuData
, &PeiCpuMpData
->CpuData
[Index3
], sizeof (PEI_CPU_DATA
));
61 &PeiCpuMpData
->CpuData
[Index3
],
62 &PeiCpuMpData
->CpuData
[Index1
],
65 CopyMem (&PeiCpuMpData
->CpuData
[Index1
], &CpuData
, sizeof (PEI_CPU_DATA
));
70 // Get the processor number for the BSP
72 ApicId
= GetInitialApicId ();
73 for (Index1
= 0; Index1
< PeiCpuMpData
->CpuCount
; Index1
++) {
74 if (PeiCpuMpData
->CpuData
[Index1
].ApicId
== ApicId
) {
75 PeiCpuMpData
->BspNumber
= (UINT32
) Index1
;
83 Enable x2APIC mode on APs.
85 @param Buffer Pointer to private data buffer.
93 SetApicMode (LOCAL_APIC_MODE_X2APIC
);
99 @param MonitorFilterSize Returns the largest monitor-line size in bytes.
101 @return The AP loop mode.
105 OUT UINT16
*MonitorFilterSize
113 ASSERT (MonitorFilterSize
!= NULL
);
115 ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
116 ASSERT (ApLoopMode
>= ApInHltLoop
&& ApLoopMode
<= ApInRunLoop
);
117 if (ApLoopMode
== ApInMwaitLoop
) {
118 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, &RegEcx
, NULL
);
119 if ((RegEcx
& BIT3
) == 0) {
121 // If processor does not support MONITOR/MWAIT feature
122 // by CPUID.[EAX=01H]:ECX.BIT3, force AP in Hlt-loop mode
124 ApLoopMode
= ApInHltLoop
;
128 if (ApLoopMode
== ApInHltLoop
) {
129 *MonitorFilterSize
= 0;
130 } else if (ApLoopMode
== ApInRunLoop
) {
131 *MonitorFilterSize
= sizeof (UINT32
);
132 } else if (ApLoopMode
== ApInMwaitLoop
) {
134 // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
135 // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
137 AsmCpuid (CPUID_MONITOR_MWAIT
, NULL
, &RegEbx
, NULL
, &RegEdx
);
138 *MonitorFilterSize
= RegEbx
& 0xFFFF;
145 Get CPU MP Data pointer from the Guided HOB.
147 @return Pointer to Pointer to PEI CPU MP Data
154 EFI_HOB_GUID_TYPE
*GuidHob
;
156 PEI_CPU_MP_DATA
*CpuMpData
;
159 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
160 if (GuidHob
!= NULL
) {
161 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
162 CpuMpData
= (PEI_CPU_MP_DATA
*)(*(UINTN
*)DataInHob
);
164 ASSERT (CpuMpData
!= NULL
);
169 Save the volatile registers required to be restored following INIT IPI.
171 @param VolatileRegisters Returns buffer saved the volatile resisters
174 SaveVolatileRegisters (
175 OUT CPU_VOLATILE_REGISTERS
*VolatileRegisters
180 VolatileRegisters
->Cr0
= AsmReadCr0 ();
181 VolatileRegisters
->Cr3
= AsmReadCr3 ();
182 VolatileRegisters
->Cr4
= AsmReadCr4 ();
184 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, NULL
, &RegEdx
);
185 if ((RegEdx
& BIT2
) != 0) {
187 // If processor supports Debugging Extensions feature
188 // by CPUID.[EAX=01H]:EDX.BIT2
190 VolatileRegisters
->Dr0
= AsmReadDr0 ();
191 VolatileRegisters
->Dr1
= AsmReadDr1 ();
192 VolatileRegisters
->Dr2
= AsmReadDr2 ();
193 VolatileRegisters
->Dr3
= AsmReadDr3 ();
194 VolatileRegisters
->Dr6
= AsmReadDr6 ();
195 VolatileRegisters
->Dr7
= AsmReadDr7 ();
200 Restore the volatile registers following INIT IPI.
202 @param VolatileRegisters Pointer to volatile resisters
203 @param IsRestoreDr TRUE: Restore DRx if supported
204 FALSE: Do not restore DRx
207 RestoreVolatileRegisters (
208 IN CPU_VOLATILE_REGISTERS
*VolatileRegisters
,
209 IN BOOLEAN IsRestoreDr
214 AsmWriteCr0 (VolatileRegisters
->Cr0
);
215 AsmWriteCr3 (VolatileRegisters
->Cr3
);
216 AsmWriteCr4 (VolatileRegisters
->Cr4
);
219 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, NULL
, &RegEdx
);
220 if ((RegEdx
& BIT2
) != 0) {
222 // If processor supports Debugging Extensions feature
223 // by CPUID.[EAX=01H]:EDX.BIT2
225 AsmWriteDr0 (VolatileRegisters
->Dr0
);
226 AsmWriteDr1 (VolatileRegisters
->Dr1
);
227 AsmWriteDr2 (VolatileRegisters
->Dr2
);
228 AsmWriteDr3 (VolatileRegisters
->Dr3
);
229 AsmWriteDr6 (VolatileRegisters
->Dr6
);
230 AsmWriteDr7 (VolatileRegisters
->Dr7
);
236 This function will be called from AP reset code if BSP uses WakeUpAP.
238 @param ExchangeInfo Pointer to the MP exchange info buffer
239 @param NumApsExecuting Number of current executing AP
244 IN MP_CPU_EXCHANGE_INFO
*ExchangeInfo
,
245 IN UINTN NumApsExecuting
248 PEI_CPU_MP_DATA
*PeiCpuMpData
;
249 UINTN ProcessorNumber
;
250 EFI_AP_PROCEDURE Procedure
;
252 volatile UINT32
*ApStartupSignalBuffer
;
254 PeiCpuMpData
= ExchangeInfo
->PeiCpuMpData
;
256 if (PeiCpuMpData
->InitFlag
) {
257 ProcessorNumber
= NumApsExecuting
;
259 // Sync BSP's Control registers to APs
261 RestoreVolatileRegisters (&PeiCpuMpData
->CpuData
[0].VolatileRegisters
, FALSE
);
263 // This is first time AP wakeup, get BIST information from AP stack
265 BistData
= *(UINTN
*) (PeiCpuMpData
->Buffer
+ ProcessorNumber
* PeiCpuMpData
->CpuApStackSize
- sizeof (UINTN
));
266 PeiCpuMpData
->CpuData
[ProcessorNumber
].Health
.Uint32
= (UINT32
) BistData
;
267 PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
= GetInitialApicId ();
268 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
>= 0xFF) {
270 // Set x2APIC mode if there are any logical processor reporting
271 // an APIC ID of 255 or greater.
273 AcquireSpinLock(&PeiCpuMpData
->MpLock
);
274 PeiCpuMpData
->X2ApicEnable
= TRUE
;
275 ReleaseSpinLock(&PeiCpuMpData
->MpLock
);
278 // Sync BSP's Mtrr table to all wakeup APs and load microcode on APs.
280 MtrrSetAllMtrrs (&PeiCpuMpData
->MtrrTable
);
281 MicrocodeDetect (PeiCpuMpData
);
282 PeiCpuMpData
->CpuData
[ProcessorNumber
].State
= CpuStateIdle
;
285 // Execute AP function if AP is not disabled
287 GetProcessorNumber (PeiCpuMpData
, &ProcessorNumber
);
288 if (PeiCpuMpData
->ApLoopMode
== ApInHltLoop
) {
290 // Restore AP's volatile registers saved
292 RestoreVolatileRegisters (&PeiCpuMpData
->CpuData
[ProcessorNumber
].VolatileRegisters
, TRUE
);
295 if ((PeiCpuMpData
->CpuData
[ProcessorNumber
].State
!= CpuStateDisabled
) &&
296 (PeiCpuMpData
->ApFunction
!= 0)) {
297 PeiCpuMpData
->CpuData
[ProcessorNumber
].State
= CpuStateBusy
;
298 Procedure
= (EFI_AP_PROCEDURE
)(UINTN
)PeiCpuMpData
->ApFunction
;
300 // Invoke AP function here
302 Procedure ((VOID
*)(UINTN
)PeiCpuMpData
->ApFunctionArgument
);
304 // Re-get the processor number due to BSP/AP maybe exchange in AP function
306 GetProcessorNumber (PeiCpuMpData
, &ProcessorNumber
);
307 PeiCpuMpData
->CpuData
[ProcessorNumber
].State
= CpuStateIdle
;
312 // AP finished executing C code
314 InterlockedIncrement ((UINT32
*)&PeiCpuMpData
->FinishedCount
);
317 // Place AP is specified loop mode
319 if (PeiCpuMpData
->ApLoopMode
== ApInHltLoop
) {
321 // Save AP volatile registers
323 SaveVolatileRegisters (&PeiCpuMpData
->CpuData
[ProcessorNumber
].VolatileRegisters
);
325 // Place AP in Hlt-loop
328 DisableInterrupts ();
333 ApStartupSignalBuffer
= PeiCpuMpData
->CpuData
[ProcessorNumber
].StartupApSignal
;
335 DisableInterrupts ();
336 if (PeiCpuMpData
->ApLoopMode
== ApInMwaitLoop
) {
338 // Place AP in Mwait-loop
340 AsmMonitor ((UINTN
)ApStartupSignalBuffer
, 0, 0);
341 if (*ApStartupSignalBuffer
!= WAKEUP_AP_SIGNAL
) {
343 // If AP start-up signal is not set, place AP into
344 // the maximum C-state
346 AsmMwait (PeiCpuMpData
->ApTargetCState
<< 4, 0);
348 } else if (PeiCpuMpData
->ApLoopMode
== ApInRunLoop
) {
350 // Place AP in Run-loop
358 // If AP start-up signal is written, AP is waken up
359 // otherwise place AP in loop again
361 if (*ApStartupSignalBuffer
== WAKEUP_AP_SIGNAL
) {
363 // Clear AP start-up signal when AP waken up
365 InterlockedCompareExchange32 (
366 (UINT32
*)ApStartupSignalBuffer
,
377 Write AP start-up signal to wakeup AP.
379 @param ApStartupSignalBuffer Pointer to AP wakeup signal
383 IN
volatile UINT32
*ApStartupSignalBuffer
386 *ApStartupSignalBuffer
= WAKEUP_AP_SIGNAL
;
388 // If AP is waken up, StartupApSignal should be cleared.
389 // Otherwise, write StartupApSignal again till AP waken up.
391 while (InterlockedCompareExchange32 (
392 (UINT32
*)ApStartupSignalBuffer
,
401 This function will be called by BSP to wakeup AP.
403 @param PeiCpuMpData Pointer to PEI CPU MP Data
404 @param Broadcast TRUE: Send broadcast IPI to all APs
405 FALSE: Send IPI to AP by ApicId
406 @param ProcessorNumber The handle number of specified processor
407 @param Procedure The function to be invoked by AP
408 @param ProcedureArgument The argument to be passed into AP function
412 IN PEI_CPU_MP_DATA
*PeiCpuMpData
,
413 IN BOOLEAN Broadcast
,
414 IN UINTN ProcessorNumber
,
415 IN EFI_AP_PROCEDURE Procedure
, OPTIONAL
416 IN VOID
*ProcedureArgument OPTIONAL
419 volatile MP_CPU_EXCHANGE_INFO
*ExchangeInfo
;
422 PeiCpuMpData
->ApFunction
= (UINTN
) Procedure
;
423 PeiCpuMpData
->ApFunctionArgument
= (UINTN
) ProcedureArgument
;
424 PeiCpuMpData
->FinishedCount
= 0;
426 ExchangeInfo
= PeiCpuMpData
->MpCpuExchangeInfo
;
427 ExchangeInfo
->Lock
= 0;
428 ExchangeInfo
->StackStart
= PeiCpuMpData
->Buffer
;
429 ExchangeInfo
->StackSize
= PeiCpuMpData
->CpuApStackSize
;
430 ExchangeInfo
->BufferStart
= PeiCpuMpData
->WakeupBuffer
;
431 ExchangeInfo
->PmodeOffset
= PeiCpuMpData
->AddressMap
.PModeEntryOffset
;
432 ExchangeInfo
->LmodeOffset
= PeiCpuMpData
->AddressMap
.LModeEntryOffset
;
433 ExchangeInfo
->Cr3
= AsmReadCr3 ();
434 ExchangeInfo
->CodeSegment
= AsmReadCs ();
435 ExchangeInfo
->DataSegment
= AsmReadDs ();
436 ExchangeInfo
->CFunction
= (UINTN
) ApCFunction
;
437 ExchangeInfo
->NumApsExecuting
= 0;
438 ExchangeInfo
->PeiCpuMpData
= PeiCpuMpData
;
441 // Get the BSP's data of GDT and IDT
443 AsmReadGdtr ((IA32_DESCRIPTOR
*) &ExchangeInfo
->GdtrProfile
);
444 AsmReadIdtr ((IA32_DESCRIPTOR
*) &ExchangeInfo
->IdtrProfile
);
446 if (PeiCpuMpData
->ApLoopMode
== ApInMwaitLoop
) {
448 // Get AP target C-state each time when waking up AP,
449 // for it maybe updated by platform again
451 PeiCpuMpData
->ApTargetCState
= PcdGet8 (PcdCpuApTargetCstate
);
455 // Wakeup APs per AP loop state
457 if (PeiCpuMpData
->ApLoopMode
== ApInHltLoop
|| PeiCpuMpData
->InitFlag
) {
459 SendInitSipiSipiAllExcludingSelf ((UINT32
) ExchangeInfo
->BufferStart
);
462 PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
,
463 (UINT32
) ExchangeInfo
->BufferStart
466 } else if ((PeiCpuMpData
->ApLoopMode
== ApInMwaitLoop
) ||
467 (PeiCpuMpData
->ApLoopMode
== ApInRunLoop
)) {
469 for (Index
= 0; Index
< PeiCpuMpData
->CpuCount
; Index
++) {
470 if (Index
!= PeiCpuMpData
->BspNumber
) {
471 WriteStartupSignal (PeiCpuMpData
->CpuData
[Index
].StartupApSignal
);
475 WriteStartupSignal (PeiCpuMpData
->CpuData
[ProcessorNumber
].StartupApSignal
);
484 Get available system memory below 1MB by specified size.
486 @param WakeupBufferSize Wakeup buffer size required
488 @retval other Return wakeup buffer address below 1MB.
489 @retval -1 Cannot find free memory below 1MB.
493 IN UINTN WakeupBufferSize
496 EFI_PEI_HOB_POINTERS Hob
;
497 UINTN WakeupBufferStart
;
498 UINTN WakeupBufferEnd
;
501 // Get the HOB list for processing
503 Hob
.Raw
= GetHobList ();
506 // Collect memory ranges
508 while (!END_OF_HOB_LIST (Hob
)) {
509 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
510 if ((Hob
.ResourceDescriptor
->PhysicalStart
< BASE_1MB
) &&
511 (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) &&
512 ((Hob
.ResourceDescriptor
->ResourceAttribute
&
513 (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED
|
514 EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED
|
515 EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
519 // Need memory under 1MB to be collected here
521 WakeupBufferEnd
= (UINTN
) (Hob
.ResourceDescriptor
->PhysicalStart
+ Hob
.ResourceDescriptor
->ResourceLength
);
522 if (WakeupBufferEnd
> BASE_1MB
) {
524 // Wakeup buffer should be under 1MB
526 WakeupBufferEnd
= BASE_1MB
;
529 // Wakeup buffer should be aligned on 4KB
531 WakeupBufferStart
= (WakeupBufferEnd
- WakeupBufferSize
) & ~(SIZE_4KB
- 1);
532 if (WakeupBufferStart
< Hob
.ResourceDescriptor
->PhysicalStart
) {
536 // Create a memory allocation HOB.
538 BuildMemoryAllocationHob (
543 return WakeupBufferStart
;
549 Hob
.Raw
= GET_NEXT_HOB (Hob
);
556 Get available system memory below 1MB by specified size.
558 @param PeiCpuMpData Pointer to PEI CPU MP Data
561 BackupAndPrepareWakeupBuffer(
562 IN PEI_CPU_MP_DATA
*PeiCpuMpData
566 (VOID
*) PeiCpuMpData
->BackupBuffer
,
567 (VOID
*) PeiCpuMpData
->WakeupBuffer
,
568 PeiCpuMpData
->BackupBufferSize
571 (VOID
*) PeiCpuMpData
->WakeupBuffer
,
572 (VOID
*) PeiCpuMpData
->AddressMap
.RendezvousFunnelAddress
,
573 PeiCpuMpData
->AddressMap
.RendezvousFunnelSize
578 Restore wakeup buffer data.
580 @param PeiCpuMpData Pointer to PEI CPU MP Data
584 IN PEI_CPU_MP_DATA
*PeiCpuMpData
587 CopyMem ((VOID
*) PeiCpuMpData
->WakeupBuffer
, (VOID
*) PeiCpuMpData
->BackupBuffer
, PeiCpuMpData
->BackupBufferSize
);
591 This function will get CPU count in the system.
593 @param PeiCpuMpData Pointer to PEI CPU MP Data
595 @return AP processor count
598 CountProcessorNumber (
599 IN PEI_CPU_MP_DATA
*PeiCpuMpData
603 // Load Microcode on BSP
605 MicrocodeDetect (PeiCpuMpData
);
607 // Store BSP's MTRR setting
609 MtrrGetAllMtrrs (&PeiCpuMpData
->MtrrTable
);
612 // Only perform AP detection if PcdCpuMaxLogicalProcessorNumber is greater than 1
614 if (PcdGet32 (PcdCpuMaxLogicalProcessorNumber
) > 1) {
616 // Send 1st broadcast IPI to APs to wakeup APs
618 PeiCpuMpData
->InitFlag
= TRUE
;
619 PeiCpuMpData
->X2ApicEnable
= FALSE
;
620 WakeUpAP (PeiCpuMpData
, TRUE
, 0, NULL
, NULL
);
622 // Wait for AP task to complete and then exit.
624 MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds
));
625 PeiCpuMpData
->InitFlag
= FALSE
;
626 PeiCpuMpData
->CpuCount
+= (UINT32
)PeiCpuMpData
->MpCpuExchangeInfo
->NumApsExecuting
;
627 ASSERT (PeiCpuMpData
->CpuCount
<= PcdGet32 (PcdCpuMaxLogicalProcessorNumber
));
629 // Wait for all APs finished the initialization
631 while (PeiCpuMpData
->FinishedCount
< (PeiCpuMpData
->CpuCount
- 1)) {
635 if (PeiCpuMpData
->X2ApicEnable
) {
636 DEBUG ((EFI_D_INFO
, "Force x2APIC mode!\n"));
638 // Wakeup all APs to enable x2APIC mode
640 WakeUpAP (PeiCpuMpData
, TRUE
, 0, ApFuncEnableX2Apic
, NULL
);
642 // Wait for all known APs finished
644 while (PeiCpuMpData
->FinishedCount
< (PeiCpuMpData
->CpuCount
- 1)) {
648 // Enable x2APIC on BSP
650 SetApicMode (LOCAL_APIC_MODE_X2APIC
);
652 DEBUG ((EFI_D_INFO
, "APIC MODE is %d\n", GetApicMode ()));
654 // Sort BSP/Aps by CPU APIC ID in ascending order
656 SortApicId (PeiCpuMpData
);
659 DEBUG ((EFI_D_INFO
, "CpuMpPei: Find %d processors in system.\n", PeiCpuMpData
->CpuCount
));
660 return PeiCpuMpData
->CpuCount
;
664 Prepare for AP wakeup buffer and copy AP reset code into it.
666 Get wakeup buffer below 1MB. Allocate memory for CPU MP Data and APs Stack.
668 @return Pointer to PEI CPU MP Data
671 PrepareAPStartupVector (
677 PEI_CPU_MP_DATA
*PeiCpuMpData
;
678 EFI_PHYSICAL_ADDRESS Buffer
;
681 UINTN WakeupBufferSize
;
682 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
684 UINT16 MonitorFilterSize
;
685 UINT8
*MonitorBuffer
;
688 AsmGetAddressMap (&AddressMap
);
689 WakeupBufferSize
= AddressMap
.RendezvousFunnelSize
+ sizeof (MP_CPU_EXCHANGE_INFO
);
690 WakeupBuffer
= GetWakeupBuffer ((WakeupBufferSize
+ SIZE_4KB
- 1) & ~(SIZE_4KB
- 1));
691 ASSERT (WakeupBuffer
!= (UINTN
) -1);
692 DEBUG ((EFI_D_INFO
, "CpuMpPei: WakeupBuffer = 0x%x\n", WakeupBuffer
));
695 // Allocate Pages for APs stack, CPU MP Data, backup buffer for wakeup buffer,
696 // and monitor buffer if required.
698 MaxCpuCount
= PcdGet32(PcdCpuMaxLogicalProcessorNumber
);
699 BufferSize
= PcdGet32 (PcdCpuApStackSize
) * MaxCpuCount
+ sizeof (PEI_CPU_MP_DATA
)
700 + WakeupBufferSize
+ sizeof (PEI_CPU_DATA
) * MaxCpuCount
;
701 ApLoopMode
= GetApLoopMode (&MonitorFilterSize
);
702 BufferSize
+= MonitorFilterSize
* MaxCpuCount
;
703 Status
= PeiServicesAllocatePages (
705 EFI_SIZE_TO_PAGES (BufferSize
),
708 ASSERT_EFI_ERROR (Status
);
710 PeiCpuMpData
= (PEI_CPU_MP_DATA
*) (UINTN
) (Buffer
+ PcdGet32 (PcdCpuApStackSize
) * MaxCpuCount
);
711 PeiCpuMpData
->Buffer
= (UINTN
) Buffer
;
712 PeiCpuMpData
->CpuApStackSize
= PcdGet32 (PcdCpuApStackSize
);
713 PeiCpuMpData
->WakeupBuffer
= WakeupBuffer
;
714 PeiCpuMpData
->BackupBuffer
= (UINTN
)PeiCpuMpData
+ sizeof (PEI_CPU_MP_DATA
);
715 PeiCpuMpData
->BackupBufferSize
= WakeupBufferSize
;
716 PeiCpuMpData
->MpCpuExchangeInfo
= (MP_CPU_EXCHANGE_INFO
*) (UINTN
) (WakeupBuffer
+ AddressMap
.RendezvousFunnelSize
);
718 PeiCpuMpData
->CpuCount
= 1;
719 PeiCpuMpData
->BspNumber
= 0;
720 PeiCpuMpData
->CpuData
= (PEI_CPU_DATA
*) (PeiCpuMpData
->BackupBuffer
+
721 PeiCpuMpData
->BackupBufferSize
);
722 PeiCpuMpData
->CpuData
[0].ApicId
= GetInitialApicId ();
723 PeiCpuMpData
->CpuData
[0].Health
.Uint32
= 0;
724 PeiCpuMpData
->EndOfPeiFlag
= FALSE
;
725 InitializeSpinLock(&PeiCpuMpData
->MpLock
);
726 SaveVolatileRegisters (&PeiCpuMpData
->CpuData
[0].VolatileRegisters
);
727 CopyMem (&PeiCpuMpData
->AddressMap
, &AddressMap
, sizeof (MP_ASSEMBLY_ADDRESS_MAP
));
729 // Initialize AP loop mode
731 PeiCpuMpData
->ApLoopMode
= ApLoopMode
;
732 DEBUG ((EFI_D_INFO
, "AP Loop Mode is %d\n", PeiCpuMpData
->ApLoopMode
));
733 MonitorBuffer
= (UINT8
*)(PeiCpuMpData
->CpuData
+ MaxCpuCount
);
734 if (PeiCpuMpData
->ApLoopMode
!= ApInHltLoop
) {
736 // Set up APs wakeup signal buffer
738 for (Index
= 0; Index
< MaxCpuCount
; Index
++) {
739 PeiCpuMpData
->CpuData
[Index
].StartupApSignal
=
740 (UINT32
*)(MonitorBuffer
+ MonitorFilterSize
* Index
);
744 // Backup original data and copy AP reset code in it
746 BackupAndPrepareWakeupBuffer(PeiCpuMpData
);
752 Notify function on End Of Pei PPI.
754 On S3 boot, this function will restore wakeup buffer data.
755 On normal boot, this function will flag wakeup buffer to be un-used type.
757 @param PeiServices The pointer to the PEI Services Table.
758 @param NotifyDescriptor Address of the notification descriptor data structure.
759 @param Ppi Address of the PPI that was installed.
761 @retval EFI_SUCCESS When everything is OK.
766 CpuMpEndOfPeiCallback (
767 IN EFI_PEI_SERVICES
**PeiServices
,
768 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
773 EFI_BOOT_MODE BootMode
;
774 PEI_CPU_MP_DATA
*PeiCpuMpData
;
775 EFI_PEI_HOB_POINTERS Hob
;
776 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
778 DEBUG ((EFI_D_INFO
, "CpuMpPei: CpuMpEndOfPeiCallback () invoked\n"));
780 Status
= PeiServicesGetBootMode (&BootMode
);
781 ASSERT_EFI_ERROR (Status
);
783 PeiCpuMpData
= GetMpHobData ();
784 ASSERT (PeiCpuMpData
!= NULL
);
786 if (BootMode
!= BOOT_ON_S3_RESUME
) {
788 // Get the HOB list for processing
790 Hob
.Raw
= GetHobList ();
792 // Collect memory ranges
794 while (!END_OF_HOB_LIST (Hob
)) {
795 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
796 MemoryHob
= Hob
.MemoryAllocation
;
797 if(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
== PeiCpuMpData
->WakeupBuffer
) {
799 // Flag this HOB type to un-used
801 GET_HOB_TYPE (Hob
) = EFI_HOB_TYPE_UNUSED
;
805 Hob
.Raw
= GET_NEXT_HOB (Hob
);
808 RestoreWakeupBuffer (PeiCpuMpData
);
809 PeiCpuMpData
->EndOfPeiFlag
= TRUE
;
815 The Entry point of the MP CPU PEIM.
817 This function will wakeup APs and collect CPU AP count and install the
820 @param FileHandle Handle of the file being invoked.
821 @param PeiServices Describes the list of possible PEI Services.
823 @retval EFI_SUCCESS MpServicePpi is installed successfully.
829 IN EFI_PEI_FILE_HANDLE FileHandle
,
830 IN CONST EFI_PEI_SERVICES
**PeiServices
834 PEI_CPU_MP_DATA
*PeiCpuMpData
;
835 EFI_VECTOR_HANDOFF_INFO
*VectorInfo
;
836 EFI_PEI_VECTOR_HANDOFF_INFO_PPI
*VectorHandoffInfoPpi
;
839 // Get Vector Hand-off Info PPI
842 Status
= PeiServicesLocatePpi (
843 &gEfiVectorHandoffInfoPpiGuid
,
846 (VOID
**)&VectorHandoffInfoPpi
848 if (Status
== EFI_SUCCESS
) {
849 VectorInfo
= VectorHandoffInfoPpi
->Info
;
851 Status
= InitializeCpuExceptionHandlers (VectorInfo
);
852 ASSERT_EFI_ERROR (Status
);
854 // Get wakeup buffer and copy AP reset code in it
856 PeiCpuMpData
= PrepareAPStartupVector ();
858 // Count processor number and collect processor information
860 CountProcessorNumber (PeiCpuMpData
);
862 // Build location of PEI CPU MP DATA buffer in HOB
866 (VOID
*)&PeiCpuMpData
,
870 // Update and publish CPU BIST information
872 CollectBistDataFromPpi (PeiServices
, PeiCpuMpData
);
874 // register an event for EndOfPei
876 Status
= PeiServicesNotifyPpi (&mNotifyList
);
877 ASSERT_EFI_ERROR (Status
);
879 // Install CPU MP PPI
881 Status
= PeiServicesInstallPpi(&mPeiCpuMpPpiDesc
);
882 ASSERT_EFI_ERROR (Status
);