]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.c
MdeModulePkg/EbcDxe: add EBC Debugger configuration application
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.c
1 /** @file
2 CPU MP Initialize Library common functions.
3
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
9
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.
12
13 **/
14
15 #include "MpLib.h"
16
17 EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
18
19 /**
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.
23
24 @retval TRUE BSP Execute Disable is enabled.
25 @retval FALSE BSP Execute Disable is not enabled.
26 **/
27 BOOLEAN
28 IsBspExecuteDisableEnabled (
29 VOID
30 )
31 {
32 UINT32 Eax;
33 CPUID_EXTENDED_CPU_SIG_EDX Edx;
34 MSR_IA32_EFER_REGISTER EferMsr;
35 BOOLEAN Enabled;
36
37 Enabled = FALSE;
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);
41 //
42 // CPUID 0x80000001
43 // Bit 20: Execute Disable Bit available.
44 //
45 if (Edx.Bits.NX != 0) {
46 EferMsr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
47 //
48 // MSR 0xC0000080
49 // Bit 11: Execute Disable Bit enable.
50 //
51 if (EferMsr.Bits.NXE != 0) {
52 Enabled = TRUE;
53 }
54 }
55 }
56
57 return Enabled;
58 }
59
60 /**
61 Worker function for SwitchBSP().
62
63 Worker function for SwitchBSP(), assigned to the AP which is intended
64 to become BSP.
65
66 @param[in] Buffer Pointer to CPU MP Data
67 **/
68 VOID
69 EFIAPI
70 FutureBSPProc (
71 IN VOID *Buffer
72 )
73 {
74 CPU_MP_DATA *DataInHob;
75
76 DataInHob = (CPU_MP_DATA *) Buffer;
77 AsmExchangeRole (&DataInHob->APInfo, &DataInHob->BSPInfo);
78 }
79
80 /**
81 Get the Application Processors state.
82
83 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
84
85 @return The AP status
86 **/
87 CPU_STATE
88 GetApState (
89 IN CPU_AP_DATA *CpuData
90 )
91 {
92 return CpuData->State;
93 }
94
95 /**
96 Set the Application Processors state.
97
98 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
99 @param[in] State The AP status
100 **/
101 VOID
102 SetApState (
103 IN CPU_AP_DATA *CpuData,
104 IN CPU_STATE State
105 )
106 {
107 AcquireSpinLock (&CpuData->ApLock);
108 CpuData->State = State;
109 ReleaseSpinLock (&CpuData->ApLock);
110 }
111
112 /**
113 Save the volatile registers required to be restored following INIT IPI.
114
115 @param[out] VolatileRegisters Returns buffer saved the volatile resisters
116 **/
117 VOID
118 SaveVolatileRegisters (
119 OUT CPU_VOLATILE_REGISTERS *VolatileRegisters
120 )
121 {
122 CPUID_VERSION_INFO_EDX VersionInfoEdx;
123
124 VolatileRegisters->Cr0 = AsmReadCr0 ();
125 VolatileRegisters->Cr3 = AsmReadCr3 ();
126 VolatileRegisters->Cr4 = AsmReadCr4 ();
127
128 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32);
129 if (VersionInfoEdx.Bits.DE != 0) {
130 //
131 // If processor supports Debugging Extensions feature
132 // by CPUID.[EAX=01H]:EDX.BIT2
133 //
134 VolatileRegisters->Dr0 = AsmReadDr0 ();
135 VolatileRegisters->Dr1 = AsmReadDr1 ();
136 VolatileRegisters->Dr2 = AsmReadDr2 ();
137 VolatileRegisters->Dr3 = AsmReadDr3 ();
138 VolatileRegisters->Dr6 = AsmReadDr6 ();
139 VolatileRegisters->Dr7 = AsmReadDr7 ();
140 }
141 }
142
143 /**
144 Restore the volatile registers following INIT IPI.
145
146 @param[in] VolatileRegisters Pointer to volatile resisters
147 @param[in] IsRestoreDr TRUE: Restore DRx if supported
148 FALSE: Do not restore DRx
149 **/
150 VOID
151 RestoreVolatileRegisters (
152 IN CPU_VOLATILE_REGISTERS *VolatileRegisters,
153 IN BOOLEAN IsRestoreDr
154 )
155 {
156 CPUID_VERSION_INFO_EDX VersionInfoEdx;
157
158 AsmWriteCr0 (VolatileRegisters->Cr0);
159 AsmWriteCr3 (VolatileRegisters->Cr3);
160 AsmWriteCr4 (VolatileRegisters->Cr4);
161
162 if (IsRestoreDr) {
163 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32);
164 if (VersionInfoEdx.Bits.DE != 0) {
165 //
166 // If processor supports Debugging Extensions feature
167 // by CPUID.[EAX=01H]:EDX.BIT2
168 //
169 AsmWriteDr0 (VolatileRegisters->Dr0);
170 AsmWriteDr1 (VolatileRegisters->Dr1);
171 AsmWriteDr2 (VolatileRegisters->Dr2);
172 AsmWriteDr3 (VolatileRegisters->Dr3);
173 AsmWriteDr6 (VolatileRegisters->Dr6);
174 AsmWriteDr7 (VolatileRegisters->Dr7);
175 }
176 }
177 }
178
179 /**
180 Detect whether Mwait-monitor feature is supported.
181
182 @retval TRUE Mwait-monitor feature is supported.
183 @retval FALSE Mwait-monitor feature is not supported.
184 **/
185 BOOLEAN
186 IsMwaitSupport (
187 VOID
188 )
189 {
190 CPUID_VERSION_INFO_ECX VersionInfoEcx;
191
192 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &VersionInfoEcx.Uint32, NULL);
193 return (VersionInfoEcx.Bits.MONITOR == 1) ? TRUE : FALSE;
194 }
195
196 /**
197 Get AP loop mode.
198
199 @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.
200
201 @return The AP loop mode.
202 **/
203 UINT8
204 GetApLoopMode (
205 OUT UINT32 *MonitorFilterSize
206 )
207 {
208 UINT8 ApLoopMode;
209 CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx;
210
211 ASSERT (MonitorFilterSize != NULL);
212
213 ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
214 ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
215 if (ApLoopMode == ApInMwaitLoop) {
216 if (!IsMwaitSupport ()) {
217 //
218 // If processor does not support MONITOR/MWAIT feature,
219 // force AP in Hlt-loop mode
220 //
221 ApLoopMode = ApInHltLoop;
222 }
223 }
224
225 if (ApLoopMode != ApInMwaitLoop) {
226 *MonitorFilterSize = sizeof (UINT32);
227 } else {
228 //
229 // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
230 // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
231 //
232 AsmCpuid (CPUID_MONITOR_MWAIT, NULL, &MonitorMwaitEbx.Uint32, NULL, NULL);
233 *MonitorFilterSize = MonitorMwaitEbx.Bits.LargestMonitorLineSize;
234 }
235
236 return ApLoopMode;
237 }
238
239 /**
240 Sort the APIC ID of all processors.
241
242 This function sorts the APIC ID of all processors so that processor number is
243 assigned in the ascending order of APIC ID which eases MP debugging.
244
245 @param[in] CpuMpData Pointer to PEI CPU MP Data
246 **/
247 VOID
248 SortApicId (
249 IN CPU_MP_DATA *CpuMpData
250 )
251 {
252 UINTN Index1;
253 UINTN Index2;
254 UINTN Index3;
255 UINT32 ApicId;
256 CPU_INFO_IN_HOB CpuInfo;
257 UINT32 ApCount;
258 CPU_INFO_IN_HOB *CpuInfoInHob;
259
260 ApCount = CpuMpData->CpuCount - 1;
261 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
262 if (ApCount != 0) {
263 for (Index1 = 0; Index1 < ApCount; Index1++) {
264 Index3 = Index1;
265 //
266 // Sort key is the hardware default APIC ID
267 //
268 ApicId = CpuInfoInHob[Index1].ApicId;
269 for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
270 if (ApicId > CpuInfoInHob[Index2].ApicId) {
271 Index3 = Index2;
272 ApicId = CpuInfoInHob[Index2].ApicId;
273 }
274 }
275 if (Index3 != Index1) {
276 CopyMem (&CpuInfo, &CpuInfoInHob[Index3], sizeof (CPU_INFO_IN_HOB));
277 CopyMem (
278 &CpuInfoInHob[Index3],
279 &CpuInfoInHob[Index1],
280 sizeof (CPU_INFO_IN_HOB)
281 );
282 CopyMem (&CpuInfoInHob[Index1], &CpuInfo, sizeof (CPU_INFO_IN_HOB));
283 }
284 }
285
286 //
287 // Get the processor number for the BSP
288 //
289 ApicId = GetInitialApicId ();
290 for (Index1 = 0; Index1 < CpuMpData->CpuCount; Index1++) {
291 if (CpuInfoInHob[Index1].ApicId == ApicId) {
292 CpuMpData->BspNumber = (UINT32) Index1;
293 break;
294 }
295 }
296 }
297 }
298
299 /**
300 Enable x2APIC mode on APs.
301
302 @param[in, out] Buffer Pointer to private data buffer.
303 **/
304 VOID
305 EFIAPI
306 ApFuncEnableX2Apic (
307 IN OUT VOID *Buffer
308 )
309 {
310 SetApicMode (LOCAL_APIC_MODE_X2APIC);
311 }
312
313 /**
314 Do sync on APs.
315
316 @param[in, out] Buffer Pointer to private data buffer.
317 **/
318 VOID
319 EFIAPI
320 ApInitializeSync (
321 IN OUT VOID *Buffer
322 )
323 {
324 CPU_MP_DATA *CpuMpData;
325
326 CpuMpData = (CPU_MP_DATA *) Buffer;
327 //
328 // Sync BSP's MTRR table to AP
329 //
330 MtrrSetAllMtrrs (&CpuMpData->MtrrTable);
331 //
332 // Load microcode on AP
333 //
334 MicrocodeDetect (CpuMpData);
335 }
336
337 /**
338 Find the current Processor number by APIC ID.
339
340 @param[in] CpuMpData Pointer to PEI CPU MP Data
341 @param[in] ProcessorNumber Return the pocessor number found
342
343 @retval EFI_SUCCESS ProcessorNumber is found and returned.
344 @retval EFI_NOT_FOUND ProcessorNumber is not found.
345 **/
346 EFI_STATUS
347 GetProcessorNumber (
348 IN CPU_MP_DATA *CpuMpData,
349 OUT UINTN *ProcessorNumber
350 )
351 {
352 UINTN TotalProcessorNumber;
353 UINTN Index;
354 CPU_INFO_IN_HOB *CpuInfoInHob;
355
356 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
357
358 TotalProcessorNumber = CpuMpData->CpuCount;
359 for (Index = 0; Index < TotalProcessorNumber; Index ++) {
360 if (CpuInfoInHob[Index].ApicId == GetApicId ()) {
361 *ProcessorNumber = Index;
362 return EFI_SUCCESS;
363 }
364 }
365 return EFI_NOT_FOUND;
366 }
367
368 /**
369 This function will get CPU count in the system.
370
371 @param[in] CpuMpData Pointer to PEI CPU MP Data
372
373 @return CPU count detected
374 **/
375 UINTN
376 CollectProcessorCount (
377 IN CPU_MP_DATA *CpuMpData
378 )
379 {
380 //
381 // Send 1st broadcast IPI to APs to wakeup APs
382 //
383 CpuMpData->InitFlag = ApInitConfig;
384 CpuMpData->X2ApicEnable = FALSE;
385 WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL);
386 CpuMpData->InitFlag = ApInitDone;
387 ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
388 //
389 // Wait for all APs finished the initialization
390 //
391 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
392 CpuPause ();
393 }
394
395 if (CpuMpData->X2ApicEnable) {
396 DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n"));
397 //
398 // Wakeup all APs to enable x2APIC mode
399 //
400 WakeUpAP (CpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL);
401 //
402 // Wait for all known APs finished
403 //
404 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
405 CpuPause ();
406 }
407 //
408 // Enable x2APIC on BSP
409 //
410 SetApicMode (LOCAL_APIC_MODE_X2APIC);
411 }
412 DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ()));
413 //
414 // Sort BSP/Aps by CPU APIC ID in ascending order
415 //
416 SortApicId (CpuMpData);
417
418 DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));
419
420 return CpuMpData->CpuCount;
421 }
422
423 /*
424 Initialize CPU AP Data when AP is wakeup at the first time.
425
426 @param[in, out] CpuMpData Pointer to PEI CPU MP Data
427 @param[in] ProcessorNumber The handle number of processor
428 @param[in] BistData Processor BIST data
429
430 **/
431 VOID
432 InitializeApData (
433 IN OUT CPU_MP_DATA *CpuMpData,
434 IN UINTN ProcessorNumber,
435 IN UINT32 BistData,
436 IN UINT64 ApTopOfStack
437 )
438 {
439 CPU_INFO_IN_HOB *CpuInfoInHob;
440
441 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
442 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
443 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
444 CpuInfoInHob[ProcessorNumber].Health = BistData;
445 CpuInfoInHob[ProcessorNumber].ApTopOfStack = ApTopOfStack;
446
447 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
448 CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ? TRUE : FALSE;
449 if (CpuInfoInHob[ProcessorNumber].InitialApicId >= 0xFF) {
450 //
451 // Set x2APIC mode if there are any logical processor reporting
452 // an Initial APIC ID of 255 or greater.
453 //
454 AcquireSpinLock(&CpuMpData->MpLock);
455 CpuMpData->X2ApicEnable = TRUE;
456 ReleaseSpinLock(&CpuMpData->MpLock);
457 }
458
459 InitializeSpinLock(&CpuMpData->CpuData[ProcessorNumber].ApLock);
460 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
461 }
462
463 /**
464 This function will be called from AP reset code if BSP uses WakeUpAP.
465
466 @param[in] ExchangeInfo Pointer to the MP exchange info buffer
467 @param[in] NumApsExecuting Number of current executing AP
468 **/
469 VOID
470 EFIAPI
471 ApWakeupFunction (
472 IN MP_CPU_EXCHANGE_INFO *ExchangeInfo,
473 IN UINTN NumApsExecuting
474 )
475 {
476 CPU_MP_DATA *CpuMpData;
477 UINTN ProcessorNumber;
478 EFI_AP_PROCEDURE Procedure;
479 VOID *Parameter;
480 UINT32 BistData;
481 volatile UINT32 *ApStartupSignalBuffer;
482 CPU_INFO_IN_HOB *CpuInfoInHob;
483 UINT64 ApTopOfStack;
484
485 //
486 // AP finished assembly code and begin to execute C code
487 //
488 CpuMpData = ExchangeInfo->CpuMpData;
489
490 ProgramVirtualWireMode ();
491
492 while (TRUE) {
493 if (CpuMpData->InitFlag == ApInitConfig) {
494 //
495 // Add CPU number
496 //
497 InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount);
498 ProcessorNumber = NumApsExecuting;
499 //
500 // This is first time AP wakeup, get BIST information from AP stack
501 //
502 ApTopOfStack = CpuMpData->Buffer + (ProcessorNumber + 1) * CpuMpData->CpuApStackSize;
503 BistData = *(UINT32 *) ((UINTN) ApTopOfStack - sizeof (UINTN));
504 //
505 // Do some AP initialize sync
506 //
507 ApInitializeSync (CpuMpData);
508 //
509 // Sync BSP's Control registers to APs
510 //
511 RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);
512 InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);
513 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
514 } else {
515 //
516 // Execute AP function if AP is ready
517 //
518 GetProcessorNumber (CpuMpData, &ProcessorNumber);
519 //
520 // Clear AP start-up signal when AP waken up
521 //
522 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
523 InterlockedCompareExchange32 (
524 (UINT32 *) ApStartupSignalBuffer,
525 WAKEUP_AP_SIGNAL,
526 0
527 );
528 if (CpuMpData->ApLoopMode == ApInHltLoop) {
529 //
530 // Restore AP's volatile registers saved
531 //
532 RestoreVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters, TRUE);
533 }
534
535 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateReady) {
536 Procedure = (EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction;
537 Parameter = (VOID *) CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument;
538 if (Procedure != NULL) {
539 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy);
540 //
541 // Invoke AP function here
542 //
543 Procedure (Parameter);
544 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
545 if (CpuMpData->SwitchBspFlag) {
546 //
547 // Re-get the processor number due to BSP/AP maybe exchange in AP function
548 //
549 GetProcessorNumber (CpuMpData, &ProcessorNumber);
550 CpuMpData->CpuData[ProcessorNumber].ApFunction = 0;
551 CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument = 0;
552 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
553 CpuInfoInHob[ProcessorNumber].ApTopOfStack = CpuInfoInHob[CpuMpData->NewBspNumber].ApTopOfStack;
554 } else {
555 //
556 // Re-get the CPU APICID and Initial APICID
557 //
558 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
559 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
560 }
561 }
562 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
563 }
564 }
565
566 //
567 // AP finished executing C code
568 //
569 InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount);
570
571 //
572 // Place AP is specified loop mode
573 //
574 if (CpuMpData->ApLoopMode == ApInHltLoop) {
575 //
576 // Save AP volatile registers
577 //
578 SaveVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters);
579 //
580 // Place AP in HLT-loop
581 //
582 while (TRUE) {
583 DisableInterrupts ();
584 CpuSleep ();
585 CpuPause ();
586 }
587 }
588 while (TRUE) {
589 DisableInterrupts ();
590 if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
591 //
592 // Place AP in MWAIT-loop
593 //
594 AsmMonitor ((UINTN) ApStartupSignalBuffer, 0, 0);
595 if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
596 //
597 // Check AP start-up signal again.
598 // If AP start-up signal is not set, place AP into
599 // the specified C-state
600 //
601 AsmMwait (CpuMpData->ApTargetCState << 4, 0);
602 }
603 } else if (CpuMpData->ApLoopMode == ApInRunLoop) {
604 //
605 // Place AP in Run-loop
606 //
607 CpuPause ();
608 } else {
609 ASSERT (FALSE);
610 }
611
612 //
613 // If AP start-up signal is written, AP is waken up
614 // otherwise place AP in loop again
615 //
616 if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
617 break;
618 }
619 }
620 }
621 }
622
623 /**
624 Wait for AP wakeup and write AP start-up signal till AP is waken up.
625
626 @param[in] ApStartupSignalBuffer Pointer to AP wakeup signal
627 **/
628 VOID
629 WaitApWakeup (
630 IN volatile UINT32 *ApStartupSignalBuffer
631 )
632 {
633 //
634 // If AP is waken up, StartupApSignal should be cleared.
635 // Otherwise, write StartupApSignal again till AP waken up.
636 //
637 while (InterlockedCompareExchange32 (
638 (UINT32 *) ApStartupSignalBuffer,
639 WAKEUP_AP_SIGNAL,
640 WAKEUP_AP_SIGNAL
641 ) != 0) {
642 CpuPause ();
643 }
644 }
645
646 /**
647 This function will fill the exchange info structure.
648
649 @param[in] CpuMpData Pointer to CPU MP Data
650
651 **/
652 VOID
653 FillExchangeInfoData (
654 IN CPU_MP_DATA *CpuMpData
655 )
656 {
657 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
658
659 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
660 ExchangeInfo->Lock = 0;
661 ExchangeInfo->StackStart = CpuMpData->Buffer;
662 ExchangeInfo->StackSize = CpuMpData->CpuApStackSize;
663 ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer;
664 ExchangeInfo->ModeOffset = CpuMpData->AddressMap.ModeEntryOffset;
665
666 ExchangeInfo->CodeSegment = AsmReadCs ();
667 ExchangeInfo->DataSegment = AsmReadDs ();
668
669 ExchangeInfo->Cr3 = AsmReadCr3 ();
670
671 ExchangeInfo->CFunction = (UINTN) ApWakeupFunction;
672 ExchangeInfo->NumApsExecuting = 0;
673 ExchangeInfo->InitFlag = (UINTN) CpuMpData->InitFlag;
674 ExchangeInfo->CpuInfo = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
675 ExchangeInfo->CpuMpData = CpuMpData;
676
677 ExchangeInfo->EnableExecuteDisable = IsBspExecuteDisableEnabled ();
678
679 //
680 // Get the BSP's data of GDT and IDT
681 //
682 AsmReadGdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->GdtrProfile);
683 AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
684 }
685
686 /**
687 This function will be called by BSP to wakeup AP.
688
689 @param[in] CpuMpData Pointer to CPU MP Data
690 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
691 FALSE: Send IPI to AP by ApicId
692 @param[in] ProcessorNumber The handle number of specified processor
693 @param[in] Procedure The function to be invoked by AP
694 @param[in] ProcedureArgument The argument to be passed into AP function
695 **/
696 VOID
697 WakeUpAP (
698 IN CPU_MP_DATA *CpuMpData,
699 IN BOOLEAN Broadcast,
700 IN UINTN ProcessorNumber,
701 IN EFI_AP_PROCEDURE Procedure, OPTIONAL
702 IN VOID *ProcedureArgument OPTIONAL
703 )
704 {
705 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
706 UINTN Index;
707 CPU_AP_DATA *CpuData;
708 BOOLEAN ResetVectorRequired;
709 CPU_INFO_IN_HOB *CpuInfoInHob;
710
711 CpuMpData->FinishedCount = 0;
712 ResetVectorRequired = FALSE;
713
714 if (CpuMpData->ApLoopMode == ApInHltLoop ||
715 CpuMpData->InitFlag != ApInitDone) {
716 ResetVectorRequired = TRUE;
717 AllocateResetVector (CpuMpData);
718 FillExchangeInfoData (CpuMpData);
719 } else if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
720 //
721 // Get AP target C-state each time when waking up AP,
722 // for it maybe updated by platform again
723 //
724 CpuMpData->ApTargetCState = PcdGet8 (PcdCpuApTargetCstate);
725 }
726
727 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
728
729 if (Broadcast) {
730 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
731 if (Index != CpuMpData->BspNumber) {
732 CpuData = &CpuMpData->CpuData[Index];
733 CpuData->ApFunction = (UINTN) Procedure;
734 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
735 SetApState (CpuData, CpuStateReady);
736 if (CpuMpData->InitFlag != ApInitConfig) {
737 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
738 }
739 }
740 }
741 if (ResetVectorRequired) {
742 //
743 // Wakeup all APs
744 //
745 SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
746 }
747 if (CpuMpData->InitFlag == ApInitConfig) {
748 //
749 // Wait for all potential APs waken up in one specified period
750 //
751 MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds));
752 } else {
753 //
754 // Wait all APs waken up if this is not the 1st broadcast of SIPI
755 //
756 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
757 CpuData = &CpuMpData->CpuData[Index];
758 if (Index != CpuMpData->BspNumber) {
759 WaitApWakeup (CpuData->StartupApSignal);
760 }
761 }
762 }
763 } else {
764 CpuData = &CpuMpData->CpuData[ProcessorNumber];
765 CpuData->ApFunction = (UINTN) Procedure;
766 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
767 SetApState (CpuData, CpuStateReady);
768 //
769 // Wakeup specified AP
770 //
771 ASSERT (CpuMpData->InitFlag != ApInitConfig);
772 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
773 if (ResetVectorRequired) {
774 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
775 SendInitSipiSipi (
776 CpuInfoInHob[ProcessorNumber].ApicId,
777 (UINT32) ExchangeInfo->BufferStart
778 );
779 }
780 //
781 // Wait specified AP waken up
782 //
783 WaitApWakeup (CpuData->StartupApSignal);
784 }
785
786 if (ResetVectorRequired) {
787 FreeResetVector (CpuMpData);
788 }
789 }
790
791 /**
792 Calculate timeout value and return the current performance counter value.
793
794 Calculate the number of performance counter ticks required for a timeout.
795 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
796 as infinity.
797
798 @param[in] TimeoutInMicroseconds Timeout value in microseconds.
799 @param[out] CurrentTime Returns the current value of the performance counter.
800
801 @return Expected time stamp counter for timeout.
802 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
803 as infinity.
804
805 **/
806 UINT64
807 CalculateTimeout (
808 IN UINTN TimeoutInMicroseconds,
809 OUT UINT64 *CurrentTime
810 )
811 {
812 //
813 // Read the current value of the performance counter
814 //
815 *CurrentTime = GetPerformanceCounter ();
816
817 //
818 // If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
819 // as infinity.
820 //
821 if (TimeoutInMicroseconds == 0) {
822 return 0;
823 }
824
825 //
826 // GetPerformanceCounterProperties () returns the timestamp counter's frequency
827 // in Hz. So multiply the return value with TimeoutInMicroseconds and then divide
828 // it by 1,000,000, to get the number of ticks for the timeout value.
829 //
830 return DivU64x32 (
831 MultU64x64 (
832 GetPerformanceCounterProperties (NULL, NULL),
833 TimeoutInMicroseconds
834 ),
835 1000000
836 );
837 }
838
839 /**
840 Checks whether timeout expires.
841
842 Check whether the number of elapsed performance counter ticks required for
843 a timeout condition has been reached.
844 If Timeout is zero, which means infinity, return value is always FALSE.
845
846 @param[in, out] PreviousTime On input, the value of the performance counter
847 when it was last read.
848 On output, the current value of the performance
849 counter
850 @param[in] TotalTime The total amount of elapsed time in performance
851 counter ticks.
852 @param[in] Timeout The number of performance counter ticks required
853 to reach a timeout condition.
854
855 @retval TRUE A timeout condition has been reached.
856 @retval FALSE A timeout condition has not been reached.
857
858 **/
859 BOOLEAN
860 CheckTimeout (
861 IN OUT UINT64 *PreviousTime,
862 IN UINT64 *TotalTime,
863 IN UINT64 Timeout
864 )
865 {
866 UINT64 Start;
867 UINT64 End;
868 UINT64 CurrentTime;
869 INT64 Delta;
870 INT64 Cycle;
871
872 if (Timeout == 0) {
873 return FALSE;
874 }
875 GetPerformanceCounterProperties (&Start, &End);
876 Cycle = End - Start;
877 if (Cycle < 0) {
878 Cycle = -Cycle;
879 }
880 Cycle++;
881 CurrentTime = GetPerformanceCounter();
882 Delta = (INT64) (CurrentTime - *PreviousTime);
883 if (Start > End) {
884 Delta = -Delta;
885 }
886 if (Delta < 0) {
887 Delta += Cycle;
888 }
889 *TotalTime += Delta;
890 *PreviousTime = CurrentTime;
891 if (*TotalTime > Timeout) {
892 return TRUE;
893 }
894 return FALSE;
895 }
896
897 /**
898 Reset an AP to Idle state.
899
900 Any task being executed by the AP will be aborted and the AP
901 will be waiting for a new task in Wait-For-SIPI state.
902
903 @param[in] ProcessorNumber The handle number of processor.
904 **/
905 VOID
906 ResetProcessorToIdleState (
907 IN UINTN ProcessorNumber
908 )
909 {
910 CPU_MP_DATA *CpuMpData;
911
912 CpuMpData = GetCpuMpData ();
913
914 CpuMpData->InitFlag = ApInitReconfig;
915 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, NULL, NULL);
916 while (CpuMpData->FinishedCount < 1) {
917 CpuPause ();
918 }
919 CpuMpData->InitFlag = ApInitDone;
920
921 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
922 }
923
924 /**
925 Searches for the next waiting AP.
926
927 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
928
929 @param[out] NextProcessorNumber Pointer to the processor number of the next waiting AP.
930
931 @retval EFI_SUCCESS The next waiting AP has been found.
932 @retval EFI_NOT_FOUND No waiting AP exists.
933
934 **/
935 EFI_STATUS
936 GetNextWaitingProcessorNumber (
937 OUT UINTN *NextProcessorNumber
938 )
939 {
940 UINTN ProcessorNumber;
941 CPU_MP_DATA *CpuMpData;
942
943 CpuMpData = GetCpuMpData ();
944
945 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
946 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
947 *NextProcessorNumber = ProcessorNumber;
948 return EFI_SUCCESS;
949 }
950 }
951
952 return EFI_NOT_FOUND;
953 }
954
955 /** Checks status of specified AP.
956
957 This function checks whether the specified AP has finished the task assigned
958 by StartupThisAP(), and whether timeout expires.
959
960 @param[in] ProcessorNumber The handle number of processor.
961
962 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
963 @retval EFI_TIMEOUT The timeout expires.
964 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
965 **/
966 EFI_STATUS
967 CheckThisAP (
968 IN UINTN ProcessorNumber
969 )
970 {
971 CPU_MP_DATA *CpuMpData;
972 CPU_AP_DATA *CpuData;
973
974 CpuMpData = GetCpuMpData ();
975 CpuData = &CpuMpData->CpuData[ProcessorNumber];
976
977 //
978 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
979 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
980 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
981 //
982 //
983 // If the AP finishes for StartupThisAP(), return EFI_SUCCESS.
984 //
985 if (GetApState(CpuData) == CpuStateFinished) {
986 if (CpuData->Finished != NULL) {
987 *(CpuData->Finished) = TRUE;
988 }
989 SetApState (CpuData, CpuStateIdle);
990 return EFI_SUCCESS;
991 } else {
992 //
993 // If timeout expires for StartupThisAP(), report timeout.
994 //
995 if (CheckTimeout (&CpuData->CurrentTime, &CpuData->TotalTime, CpuData->ExpectedTime)) {
996 if (CpuData->Finished != NULL) {
997 *(CpuData->Finished) = FALSE;
998 }
999 //
1000 // Reset failed AP to idle state
1001 //
1002 ResetProcessorToIdleState (ProcessorNumber);
1003
1004 return EFI_TIMEOUT;
1005 }
1006 }
1007 return EFI_NOT_READY;
1008 }
1009
1010 /**
1011 Checks status of all APs.
1012
1013 This function checks whether all APs have finished task assigned by StartupAllAPs(),
1014 and whether timeout expires.
1015
1016 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
1017 @retval EFI_TIMEOUT The timeout expires.
1018 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
1019 **/
1020 EFI_STATUS
1021 CheckAllAPs (
1022 VOID
1023 )
1024 {
1025 UINTN ProcessorNumber;
1026 UINTN NextProcessorNumber;
1027 UINTN ListIndex;
1028 EFI_STATUS Status;
1029 CPU_MP_DATA *CpuMpData;
1030 CPU_AP_DATA *CpuData;
1031
1032 CpuMpData = GetCpuMpData ();
1033
1034 NextProcessorNumber = 0;
1035
1036 //
1037 // Go through all APs that are responsible for the StartupAllAPs().
1038 //
1039 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1040 if (!CpuMpData->CpuData[ProcessorNumber].Waiting) {
1041 continue;
1042 }
1043
1044 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1045 //
1046 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
1047 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
1048 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
1049 //
1050 if (GetApState(CpuData) == CpuStateFinished) {
1051 CpuMpData->RunningCount ++;
1052 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1053 SetApState(CpuData, CpuStateIdle);
1054
1055 //
1056 // If in Single Thread mode, then search for the next waiting AP for execution.
1057 //
1058 if (CpuMpData->SingleThread) {
1059 Status = GetNextWaitingProcessorNumber (&NextProcessorNumber);
1060
1061 if (!EFI_ERROR (Status)) {
1062 WakeUpAP (
1063 CpuMpData,
1064 FALSE,
1065 (UINT32) NextProcessorNumber,
1066 CpuMpData->Procedure,
1067 CpuMpData->ProcArguments
1068 );
1069 }
1070 }
1071 }
1072 }
1073
1074 //
1075 // If all APs finish, return EFI_SUCCESS.
1076 //
1077 if (CpuMpData->RunningCount == CpuMpData->StartCount) {
1078 return EFI_SUCCESS;
1079 }
1080
1081 //
1082 // If timeout expires, report timeout.
1083 //
1084 if (CheckTimeout (
1085 &CpuMpData->CurrentTime,
1086 &CpuMpData->TotalTime,
1087 CpuMpData->ExpectedTime)
1088 ) {
1089 //
1090 // If FailedCpuList is not NULL, record all failed APs in it.
1091 //
1092 if (CpuMpData->FailedCpuList != NULL) {
1093 *CpuMpData->FailedCpuList =
1094 AllocatePool ((CpuMpData->StartCount - CpuMpData->FinishedCount + 1) * sizeof (UINTN));
1095 ASSERT (*CpuMpData->FailedCpuList != NULL);
1096 }
1097 ListIndex = 0;
1098
1099 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1100 //
1101 // Check whether this processor is responsible for StartupAllAPs().
1102 //
1103 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1104 //
1105 // Reset failed APs to idle state
1106 //
1107 ResetProcessorToIdleState (ProcessorNumber);
1108 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1109 if (CpuMpData->FailedCpuList != NULL) {
1110 (*CpuMpData->FailedCpuList)[ListIndex++] = ProcessorNumber;
1111 }
1112 }
1113 }
1114 if (CpuMpData->FailedCpuList != NULL) {
1115 (*CpuMpData->FailedCpuList)[ListIndex] = END_OF_CPU_LIST;
1116 }
1117 return EFI_TIMEOUT;
1118 }
1119 return EFI_NOT_READY;
1120 }
1121
1122 /**
1123 MP Initialize Library initialization.
1124
1125 This service will allocate AP reset vector and wakeup all APs to do APs
1126 initialization.
1127
1128 This service must be invoked before all other MP Initialize Library
1129 service are invoked.
1130
1131 @retval EFI_SUCCESS MP initialization succeeds.
1132 @retval Others MP initialization fails.
1133
1134 **/
1135 EFI_STATUS
1136 EFIAPI
1137 MpInitLibInitialize (
1138 VOID
1139 )
1140 {
1141 CPU_MP_DATA *OldCpuMpData;
1142 CPU_INFO_IN_HOB *CpuInfoInHob;
1143 UINT32 MaxLogicalProcessorNumber;
1144 UINT32 ApStackSize;
1145 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
1146 UINTN BufferSize;
1147 UINT32 MonitorFilterSize;
1148 VOID *MpBuffer;
1149 UINTN Buffer;
1150 CPU_MP_DATA *CpuMpData;
1151 UINT8 ApLoopMode;
1152 UINT8 *MonitorBuffer;
1153 UINTN Index;
1154 UINTN ApResetVectorSize;
1155 UINTN BackupBufferAddr;
1156
1157 OldCpuMpData = GetCpuMpDataFromGuidedHob ();
1158 if (OldCpuMpData == NULL) {
1159 MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
1160 } else {
1161 MaxLogicalProcessorNumber = OldCpuMpData->CpuCount;
1162 }
1163 ASSERT (MaxLogicalProcessorNumber != 0);
1164
1165 AsmGetAddressMap (&AddressMap);
1166 ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO);
1167 ApStackSize = PcdGet32(PcdCpuApStackSize);
1168 ApLoopMode = GetApLoopMode (&MonitorFilterSize);
1169
1170 BufferSize = ApStackSize * MaxLogicalProcessorNumber;
1171 BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;
1172 BufferSize += sizeof (CPU_MP_DATA);
1173 BufferSize += ApResetVectorSize;
1174 BufferSize += (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* MaxLogicalProcessorNumber;
1175 MpBuffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));
1176 ASSERT (MpBuffer != NULL);
1177 ZeroMem (MpBuffer, BufferSize);
1178 Buffer = (UINTN) MpBuffer;
1179
1180 MonitorBuffer = (UINT8 *) (Buffer + ApStackSize * MaxLogicalProcessorNumber);
1181 BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber;
1182 CpuMpData = (CPU_MP_DATA *) (BackupBufferAddr + ApResetVectorSize);
1183 CpuMpData->Buffer = Buffer;
1184 CpuMpData->CpuApStackSize = ApStackSize;
1185 CpuMpData->BackupBuffer = BackupBufferAddr;
1186 CpuMpData->BackupBufferSize = ApResetVectorSize;
1187 CpuMpData->SaveRestoreFlag = FALSE;
1188 CpuMpData->WakeupBuffer = (UINTN) -1;
1189 CpuMpData->CpuCount = 1;
1190 CpuMpData->BspNumber = 0;
1191 CpuMpData->WaitEvent = NULL;
1192 CpuMpData->SwitchBspFlag = FALSE;
1193 CpuMpData->CpuData = (CPU_AP_DATA *) (CpuMpData + 1);
1194 CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + MaxLogicalProcessorNumber);
1195 InitializeSpinLock(&CpuMpData->MpLock);
1196 //
1197 // Save BSP's Control registers to APs
1198 //
1199 SaveVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters);
1200 //
1201 // Set BSP basic information
1202 //
1203 InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer);
1204 //
1205 // Save assembly code information
1206 //
1207 CopyMem (&CpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP));
1208 //
1209 // Finally set AP loop mode
1210 //
1211 CpuMpData->ApLoopMode = ApLoopMode;
1212 DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
1213 //
1214 // Set up APs wakeup signal buffer
1215 //
1216 for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
1217 CpuMpData->CpuData[Index].StartupApSignal =
1218 (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
1219 }
1220 //
1221 // Load Microcode on BSP
1222 //
1223 MicrocodeDetect (CpuMpData);
1224 //
1225 // Store BSP's MTRR setting
1226 //
1227 MtrrGetAllMtrrs (&CpuMpData->MtrrTable);
1228
1229 if (OldCpuMpData == NULL) {
1230 if (MaxLogicalProcessorNumber > 1) {
1231 //
1232 // Wakeup all APs and calculate the processor count in system
1233 //
1234 CollectProcessorCount (CpuMpData);
1235 }
1236 } else {
1237 //
1238 // APs have been wakeup before, just get the CPU Information
1239 // from HOB
1240 //
1241 CpuMpData->CpuCount = OldCpuMpData->CpuCount;
1242 CpuMpData->BspNumber = OldCpuMpData->BspNumber;
1243 CpuMpData->InitFlag = ApInitReconfig;
1244 CpuMpData->CpuInfoInHob = OldCpuMpData->CpuInfoInHob;
1245 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1246 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1247 InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
1248 if (CpuInfoInHob[Index].InitialApicId >= 255) {
1249 CpuMpData->X2ApicEnable = TRUE;
1250 }
1251 CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
1252 CpuMpData->CpuData[Index].ApFunction = 0;
1253 CopyMem (
1254 &CpuMpData->CpuData[Index].VolatileRegisters,
1255 &CpuMpData->CpuData[0].VolatileRegisters,
1256 sizeof (CPU_VOLATILE_REGISTERS)
1257 );
1258 }
1259 if (MaxLogicalProcessorNumber > 1) {
1260 //
1261 // Wakeup APs to do some AP initialize sync
1262 //
1263 WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData);
1264 //
1265 // Wait for all APs finished initialization
1266 //
1267 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
1268 CpuPause ();
1269 }
1270 CpuMpData->InitFlag = ApInitDone;
1271 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1272 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
1273 }
1274 }
1275 }
1276
1277 //
1278 // Initialize global data for MP support
1279 //
1280 InitMpGlobalData (CpuMpData);
1281
1282 return EFI_SUCCESS;
1283 }
1284
1285 /**
1286 Gets detailed MP-related information on the requested processor at the
1287 instant this call is made. This service may only be called from the BSP.
1288
1289 @param[in] ProcessorNumber The handle number of processor.
1290 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
1291 the requested processor is deposited.
1292 @param[out] HealthData Return processor health data.
1293
1294 @retval EFI_SUCCESS Processor information was returned.
1295 @retval EFI_DEVICE_ERROR The calling processor is an AP.
1296 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
1297 @retval EFI_NOT_FOUND The processor with the handle specified by
1298 ProcessorNumber does not exist in the platform.
1299 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1300
1301 **/
1302 EFI_STATUS
1303 EFIAPI
1304 MpInitLibGetProcessorInfo (
1305 IN UINTN ProcessorNumber,
1306 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,
1307 OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL
1308 )
1309 {
1310 CPU_MP_DATA *CpuMpData;
1311 UINTN CallerNumber;
1312 CPU_INFO_IN_HOB *CpuInfoInHob;
1313
1314 CpuMpData = GetCpuMpData ();
1315 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1316
1317 //
1318 // Check whether caller processor is BSP
1319 //
1320 MpInitLibWhoAmI (&CallerNumber);
1321 if (CallerNumber != CpuMpData->BspNumber) {
1322 return EFI_DEVICE_ERROR;
1323 }
1324
1325 if (ProcessorInfoBuffer == NULL) {
1326 return EFI_INVALID_PARAMETER;
1327 }
1328
1329 if (ProcessorNumber >= CpuMpData->CpuCount) {
1330 return EFI_NOT_FOUND;
1331 }
1332
1333 ProcessorInfoBuffer->ProcessorId = (UINT64) CpuInfoInHob[ProcessorNumber].ApicId;
1334 ProcessorInfoBuffer->StatusFlag = 0;
1335 if (ProcessorNumber == CpuMpData->BspNumber) {
1336 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_AS_BSP_BIT;
1337 }
1338 if (CpuMpData->CpuData[ProcessorNumber].CpuHealthy) {
1339 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_HEALTH_STATUS_BIT;
1340 }
1341 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
1342 ProcessorInfoBuffer->StatusFlag &= ~PROCESSOR_ENABLED_BIT;
1343 } else {
1344 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_ENABLED_BIT;
1345 }
1346
1347 //
1348 // Get processor location information
1349 //
1350 GetProcessorLocationByApicId (
1351 CpuInfoInHob[ProcessorNumber].ApicId,
1352 &ProcessorInfoBuffer->Location.Package,
1353 &ProcessorInfoBuffer->Location.Core,
1354 &ProcessorInfoBuffer->Location.Thread
1355 );
1356
1357 if (HealthData != NULL) {
1358 HealthData->Uint32 = CpuInfoInHob[ProcessorNumber].Health;
1359 }
1360
1361 return EFI_SUCCESS;
1362 }
1363
1364 /**
1365 Worker function to switch the requested AP to be the BSP from that point onward.
1366
1367 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
1368 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
1369 enabled AP. Otherwise, it will be disabled.
1370
1371 @retval EFI_SUCCESS BSP successfully switched.
1372 @retval others Failed to switch BSP.
1373
1374 **/
1375 EFI_STATUS
1376 SwitchBSPWorker (
1377 IN UINTN ProcessorNumber,
1378 IN BOOLEAN EnableOldBSP
1379 )
1380 {
1381 CPU_MP_DATA *CpuMpData;
1382 UINTN CallerNumber;
1383 CPU_STATE State;
1384 MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
1385
1386 CpuMpData = GetCpuMpData ();
1387
1388 //
1389 // Check whether caller processor is BSP
1390 //
1391 MpInitLibWhoAmI (&CallerNumber);
1392 if (CallerNumber != CpuMpData->BspNumber) {
1393 return EFI_SUCCESS;
1394 }
1395
1396 if (ProcessorNumber >= CpuMpData->CpuCount) {
1397 return EFI_NOT_FOUND;
1398 }
1399
1400 //
1401 // Check whether specified AP is disabled
1402 //
1403 State = GetApState (&CpuMpData->CpuData[ProcessorNumber]);
1404 if (State == CpuStateDisabled) {
1405 return EFI_INVALID_PARAMETER;
1406 }
1407
1408 //
1409 // Check whether ProcessorNumber specifies the current BSP
1410 //
1411 if (ProcessorNumber == CpuMpData->BspNumber) {
1412 return EFI_INVALID_PARAMETER;
1413 }
1414
1415 //
1416 // Check whether specified AP is busy
1417 //
1418 if (State == CpuStateBusy) {
1419 return EFI_NOT_READY;
1420 }
1421
1422 CpuMpData->BSPInfo.State = CPU_SWITCH_STATE_IDLE;
1423 CpuMpData->APInfo.State = CPU_SWITCH_STATE_IDLE;
1424 CpuMpData->SwitchBspFlag = TRUE;
1425 CpuMpData->NewBspNumber = ProcessorNumber;
1426
1427 //
1428 // Clear the BSP bit of MSR_IA32_APIC_BASE
1429 //
1430 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1431 ApicBaseMsr.Bits.BSP = 0;
1432 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1433
1434 //
1435 // Need to wakeUp AP (future BSP).
1436 //
1437 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, FutureBSPProc, CpuMpData);
1438
1439 AsmExchangeRole (&CpuMpData->BSPInfo, &CpuMpData->APInfo);
1440
1441 //
1442 // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP
1443 //
1444 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1445 ApicBaseMsr.Bits.BSP = 1;
1446 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1447
1448 //
1449 // Wait for old BSP finished AP task
1450 //
1451 while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) {
1452 CpuPause ();
1453 }
1454
1455 CpuMpData->SwitchBspFlag = FALSE;
1456 //
1457 // Set old BSP enable state
1458 //
1459 if (!EnableOldBSP) {
1460 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateDisabled);
1461 }
1462 //
1463 // Save new BSP number
1464 //
1465 CpuMpData->BspNumber = (UINT32) ProcessorNumber;
1466
1467 return EFI_SUCCESS;
1468 }
1469
1470 /**
1471 Worker function to let the caller enable or disable an AP from this point onward.
1472 This service may only be called from the BSP.
1473
1474 @param[in] ProcessorNumber The handle number of AP.
1475 @param[in] EnableAP Specifies the new state for the processor for
1476 enabled, FALSE for disabled.
1477 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
1478 the new health status of the AP.
1479
1480 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
1481 @retval others Failed to Enable/Disable AP.
1482
1483 **/
1484 EFI_STATUS
1485 EnableDisableApWorker (
1486 IN UINTN ProcessorNumber,
1487 IN BOOLEAN EnableAP,
1488 IN UINT32 *HealthFlag OPTIONAL
1489 )
1490 {
1491 CPU_MP_DATA *CpuMpData;
1492 UINTN CallerNumber;
1493
1494 CpuMpData = GetCpuMpData ();
1495
1496 //
1497 // Check whether caller processor is BSP
1498 //
1499 MpInitLibWhoAmI (&CallerNumber);
1500 if (CallerNumber != CpuMpData->BspNumber) {
1501 return EFI_DEVICE_ERROR;
1502 }
1503
1504 if (ProcessorNumber == CpuMpData->BspNumber) {
1505 return EFI_INVALID_PARAMETER;
1506 }
1507
1508 if (ProcessorNumber >= CpuMpData->CpuCount) {
1509 return EFI_NOT_FOUND;
1510 }
1511
1512 if (!EnableAP) {
1513 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateDisabled);
1514 } else {
1515 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
1516 }
1517
1518 if (HealthFlag != NULL) {
1519 CpuMpData->CpuData[ProcessorNumber].CpuHealthy =
1520 (BOOLEAN) ((*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT) != 0);
1521 }
1522
1523 return EFI_SUCCESS;
1524 }
1525
1526 /**
1527 This return the handle number for the calling processor. This service may be
1528 called from the BSP and APs.
1529
1530 @param[out] ProcessorNumber Pointer to the handle number of AP.
1531 The range is from 0 to the total number of
1532 logical processors minus 1. The total number of
1533 logical processors can be retrieved by
1534 MpInitLibGetNumberOfProcessors().
1535
1536 @retval EFI_SUCCESS The current processor handle number was returned
1537 in ProcessorNumber.
1538 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
1539 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1540
1541 **/
1542 EFI_STATUS
1543 EFIAPI
1544 MpInitLibWhoAmI (
1545 OUT UINTN *ProcessorNumber
1546 )
1547 {
1548 CPU_MP_DATA *CpuMpData;
1549
1550 if (ProcessorNumber == NULL) {
1551 return EFI_INVALID_PARAMETER;
1552 }
1553
1554 CpuMpData = GetCpuMpData ();
1555
1556 return GetProcessorNumber (CpuMpData, ProcessorNumber);
1557 }
1558
1559 /**
1560 Retrieves the number of logical processor in the platform and the number of
1561 those logical processors that are enabled on this boot. This service may only
1562 be called from the BSP.
1563
1564 @param[out] NumberOfProcessors Pointer to the total number of logical
1565 processors in the system, including the BSP
1566 and disabled APs.
1567 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
1568 processors that exist in system, including
1569 the BSP.
1570
1571 @retval EFI_SUCCESS The number of logical processors and enabled
1572 logical processors was retrieved.
1573 @retval EFI_DEVICE_ERROR The calling processor is an AP.
1574 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
1575 is NULL.
1576 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1577
1578 **/
1579 EFI_STATUS
1580 EFIAPI
1581 MpInitLibGetNumberOfProcessors (
1582 OUT UINTN *NumberOfProcessors, OPTIONAL
1583 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
1584 )
1585 {
1586 CPU_MP_DATA *CpuMpData;
1587 UINTN CallerNumber;
1588 UINTN ProcessorNumber;
1589 UINTN EnabledProcessorNumber;
1590 UINTN Index;
1591
1592 CpuMpData = GetCpuMpData ();
1593
1594 if ((NumberOfProcessors == NULL) && (NumberOfEnabledProcessors == NULL)) {
1595 return EFI_INVALID_PARAMETER;
1596 }
1597
1598 //
1599 // Check whether caller processor is BSP
1600 //
1601 MpInitLibWhoAmI (&CallerNumber);
1602 if (CallerNumber != CpuMpData->BspNumber) {
1603 return EFI_DEVICE_ERROR;
1604 }
1605
1606 ProcessorNumber = CpuMpData->CpuCount;
1607 EnabledProcessorNumber = 0;
1608 for (Index = 0; Index < ProcessorNumber; Index++) {
1609 if (GetApState (&CpuMpData->CpuData[Index]) != CpuStateDisabled) {
1610 EnabledProcessorNumber ++;
1611 }
1612 }
1613
1614 if (NumberOfProcessors != NULL) {
1615 *NumberOfProcessors = ProcessorNumber;
1616 }
1617 if (NumberOfEnabledProcessors != NULL) {
1618 *NumberOfEnabledProcessors = EnabledProcessorNumber;
1619 }
1620
1621 return EFI_SUCCESS;
1622 }
1623
1624
1625 /**
1626 Worker function to execute a caller provided function on all enabled APs.
1627
1628 @param[in] Procedure A pointer to the function to be run on
1629 enabled APs of the system.
1630 @param[in] SingleThread If TRUE, then all the enabled APs execute
1631 the function specified by Procedure one by
1632 one, in ascending order of processor handle
1633 number. If FALSE, then all the enabled APs
1634 execute the function specified by Procedure
1635 simultaneously.
1636 @param[in] WaitEvent The event created by the caller with CreateEvent()
1637 service.
1638 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
1639 APs to return from Procedure, either for
1640 blocking or non-blocking mode.
1641 @param[in] ProcedureArgument The parameter passed into Procedure for
1642 all APs.
1643 @param[out] FailedCpuList If all APs finish successfully, then its
1644 content is set to NULL. If not all APs
1645 finish before timeout expires, then its
1646 content is set to address of the buffer
1647 holding handle numbers of the failed APs.
1648
1649 @retval EFI_SUCCESS In blocking mode, all APs have finished before
1650 the timeout expired.
1651 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
1652 to all enabled APs.
1653 @retval others Failed to Startup all APs.
1654
1655 **/
1656 EFI_STATUS
1657 StartupAllAPsWorker (
1658 IN EFI_AP_PROCEDURE Procedure,
1659 IN BOOLEAN SingleThread,
1660 IN EFI_EVENT WaitEvent OPTIONAL,
1661 IN UINTN TimeoutInMicroseconds,
1662 IN VOID *ProcedureArgument OPTIONAL,
1663 OUT UINTN **FailedCpuList OPTIONAL
1664 )
1665 {
1666 EFI_STATUS Status;
1667 CPU_MP_DATA *CpuMpData;
1668 UINTN ProcessorCount;
1669 UINTN ProcessorNumber;
1670 UINTN CallerNumber;
1671 CPU_AP_DATA *CpuData;
1672 BOOLEAN HasEnabledAp;
1673 CPU_STATE ApState;
1674
1675 CpuMpData = GetCpuMpData ();
1676
1677 if (FailedCpuList != NULL) {
1678 *FailedCpuList = NULL;
1679 }
1680
1681 if (CpuMpData->CpuCount == 1) {
1682 return EFI_NOT_STARTED;
1683 }
1684
1685 if (Procedure == NULL) {
1686 return EFI_INVALID_PARAMETER;
1687 }
1688
1689 //
1690 // Check whether caller processor is BSP
1691 //
1692 MpInitLibWhoAmI (&CallerNumber);
1693 if (CallerNumber != CpuMpData->BspNumber) {
1694 return EFI_DEVICE_ERROR;
1695 }
1696
1697 //
1698 // Update AP state
1699 //
1700 CheckAndUpdateApsStatus ();
1701
1702 ProcessorCount = CpuMpData->CpuCount;
1703 HasEnabledAp = FALSE;
1704 //
1705 // Check whether all enabled APs are idle.
1706 // If any enabled AP is not idle, return EFI_NOT_READY.
1707 //
1708 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1709 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1710 if (ProcessorNumber != CpuMpData->BspNumber) {
1711 ApState = GetApState (CpuData);
1712 if (ApState != CpuStateDisabled) {
1713 HasEnabledAp = TRUE;
1714 if (ApState != CpuStateIdle) {
1715 //
1716 // If any enabled APs are busy, return EFI_NOT_READY.
1717 //
1718 return EFI_NOT_READY;
1719 }
1720 }
1721 }
1722 }
1723
1724 if (!HasEnabledAp) {
1725 //
1726 // If no enabled AP exists, return EFI_NOT_STARTED.
1727 //
1728 return EFI_NOT_STARTED;
1729 }
1730
1731 CpuMpData->StartCount = 0;
1732 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1733 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1734 CpuData->Waiting = FALSE;
1735 if (ProcessorNumber != CpuMpData->BspNumber) {
1736 if (CpuData->State == CpuStateIdle) {
1737 //
1738 // Mark this processor as responsible for current calling.
1739 //
1740 CpuData->Waiting = TRUE;
1741 CpuMpData->StartCount++;
1742 }
1743 }
1744 }
1745
1746 CpuMpData->Procedure = Procedure;
1747 CpuMpData->ProcArguments = ProcedureArgument;
1748 CpuMpData->SingleThread = SingleThread;
1749 CpuMpData->FinishedCount = 0;
1750 CpuMpData->RunningCount = 0;
1751 CpuMpData->FailedCpuList = FailedCpuList;
1752 CpuMpData->ExpectedTime = CalculateTimeout (
1753 TimeoutInMicroseconds,
1754 &CpuMpData->CurrentTime
1755 );
1756 CpuMpData->TotalTime = 0;
1757 CpuMpData->WaitEvent = WaitEvent;
1758
1759 if (!SingleThread) {
1760 WakeUpAP (CpuMpData, TRUE, 0, Procedure, ProcedureArgument);
1761 } else {
1762 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1763 if (ProcessorNumber == CallerNumber) {
1764 continue;
1765 }
1766 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1767 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument);
1768 break;
1769 }
1770 }
1771 }
1772
1773 Status = EFI_SUCCESS;
1774 if (WaitEvent == NULL) {
1775 do {
1776 Status = CheckAllAPs ();
1777 } while (Status == EFI_NOT_READY);
1778 }
1779
1780 return Status;
1781 }
1782
1783 /**
1784 Worker function to let the caller get one enabled AP to execute a caller-provided
1785 function.
1786
1787 @param[in] Procedure A pointer to the function to be run on
1788 enabled APs of the system.
1789 @param[in] ProcessorNumber The handle number of the AP.
1790 @param[in] WaitEvent The event created by the caller with CreateEvent()
1791 service.
1792 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
1793 APs to return from Procedure, either for
1794 blocking or non-blocking mode.
1795 @param[in] ProcedureArgument The parameter passed into Procedure for
1796 all APs.
1797 @param[out] Finished If AP returns from Procedure before the
1798 timeout expires, its content is set to TRUE.
1799 Otherwise, the value is set to FALSE.
1800
1801 @retval EFI_SUCCESS In blocking mode, specified AP finished before
1802 the timeout expires.
1803 @retval others Failed to Startup AP.
1804
1805 **/
1806 EFI_STATUS
1807 StartupThisAPWorker (
1808 IN EFI_AP_PROCEDURE Procedure,
1809 IN UINTN ProcessorNumber,
1810 IN EFI_EVENT WaitEvent OPTIONAL,
1811 IN UINTN TimeoutInMicroseconds,
1812 IN VOID *ProcedureArgument OPTIONAL,
1813 OUT BOOLEAN *Finished OPTIONAL
1814 )
1815 {
1816 EFI_STATUS Status;
1817 CPU_MP_DATA *CpuMpData;
1818 CPU_AP_DATA *CpuData;
1819 UINTN CallerNumber;
1820
1821 CpuMpData = GetCpuMpData ();
1822
1823 if (Finished != NULL) {
1824 *Finished = FALSE;
1825 }
1826
1827 //
1828 // Check whether caller processor is BSP
1829 //
1830 MpInitLibWhoAmI (&CallerNumber);
1831 if (CallerNumber != CpuMpData->BspNumber) {
1832 return EFI_DEVICE_ERROR;
1833 }
1834
1835 //
1836 // Check whether processor with the handle specified by ProcessorNumber exists
1837 //
1838 if (ProcessorNumber >= CpuMpData->CpuCount) {
1839 return EFI_NOT_FOUND;
1840 }
1841
1842 //
1843 // Check whether specified processor is BSP
1844 //
1845 if (ProcessorNumber == CpuMpData->BspNumber) {
1846 return EFI_INVALID_PARAMETER;
1847 }
1848
1849 //
1850 // Check parameter Procedure
1851 //
1852 if (Procedure == NULL) {
1853 return EFI_INVALID_PARAMETER;
1854 }
1855
1856 //
1857 // Update AP state
1858 //
1859 CheckAndUpdateApsStatus ();
1860
1861 //
1862 // Check whether specified AP is disabled
1863 //
1864 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
1865 return EFI_INVALID_PARAMETER;
1866 }
1867
1868 //
1869 // If WaitEvent is not NULL, execute in non-blocking mode.
1870 // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
1871 // CheckAPsStatus() will check completion and timeout periodically.
1872 //
1873 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1874 CpuData->WaitEvent = WaitEvent;
1875 CpuData->Finished = Finished;
1876 CpuData->ExpectedTime = CalculateTimeout (TimeoutInMicroseconds, &CpuData->CurrentTime);
1877 CpuData->TotalTime = 0;
1878
1879 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument);
1880
1881 //
1882 // If WaitEvent is NULL, execute in blocking mode.
1883 // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expires.
1884 //
1885 Status = EFI_SUCCESS;
1886 if (WaitEvent == NULL) {
1887 do {
1888 Status = CheckThisAP (ProcessorNumber);
1889 } while (Status == EFI_NOT_READY);
1890 }
1891
1892 return Status;
1893 }
1894
1895 /**
1896 Get pointer to CPU MP Data structure from GUIDed HOB.
1897
1898 @return The pointer to CPU MP Data structure.
1899 **/
1900 CPU_MP_DATA *
1901 GetCpuMpDataFromGuidedHob (
1902 VOID
1903 )
1904 {
1905 EFI_HOB_GUID_TYPE *GuidHob;
1906 VOID *DataInHob;
1907 CPU_MP_DATA *CpuMpData;
1908
1909 CpuMpData = NULL;
1910 GuidHob = GetFirstGuidHob (&mCpuInitMpLibHobGuid);
1911 if (GuidHob != NULL) {
1912 DataInHob = GET_GUID_HOB_DATA (GuidHob);
1913 CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
1914 }
1915 return CpuMpData;
1916 }
1917
1918 /**
1919 Get available system memory below 1MB by specified size.
1920
1921 @param[in] CpuMpData The pointer to CPU MP Data structure.
1922 **/
1923 VOID
1924 BackupAndPrepareWakeupBuffer(
1925 IN CPU_MP_DATA *CpuMpData
1926 )
1927 {
1928 CopyMem (
1929 (VOID *) CpuMpData->BackupBuffer,
1930 (VOID *) CpuMpData->WakeupBuffer,
1931 CpuMpData->BackupBufferSize
1932 );
1933 CopyMem (
1934 (VOID *) CpuMpData->WakeupBuffer,
1935 (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,
1936 CpuMpData->AddressMap.RendezvousFunnelSize
1937 );
1938 }
1939
1940 /**
1941 Restore wakeup buffer data.
1942
1943 @param[in] CpuMpData The pointer to CPU MP Data structure.
1944 **/
1945 VOID
1946 RestoreWakeupBuffer(
1947 IN CPU_MP_DATA *CpuMpData
1948 )
1949 {
1950 CopyMem (
1951 (VOID *) CpuMpData->WakeupBuffer,
1952 (VOID *) CpuMpData->BackupBuffer,
1953 CpuMpData->BackupBufferSize
1954 );
1955 }