]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/MpInitLib: Add InitFlag and CpuInfo in MP_CPU_EXCHANGE_INFO
[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 )
437 {
438 CPU_INFO_IN_HOB *CpuInfoInHob;
439
440 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
441 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
442 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
443 CpuInfoInHob[ProcessorNumber].Health = BistData;
444
445 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
446 CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ? TRUE : FALSE;
447 if (CpuInfoInHob[ProcessorNumber].InitialApicId >= 0xFF) {
448 //
449 // Set x2APIC mode if there are any logical processor reporting
450 // an Initial APIC ID of 255 or greater.
451 //
452 AcquireSpinLock(&CpuMpData->MpLock);
453 CpuMpData->X2ApicEnable = TRUE;
454 ReleaseSpinLock(&CpuMpData->MpLock);
455 }
456
457 InitializeSpinLock(&CpuMpData->CpuData[ProcessorNumber].ApLock);
458 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
459 }
460
461 /**
462 This function will be called from AP reset code if BSP uses WakeUpAP.
463
464 @param[in] ExchangeInfo Pointer to the MP exchange info buffer
465 @param[in] NumApsExecuting Number of current executing AP
466 **/
467 VOID
468 EFIAPI
469 ApWakeupFunction (
470 IN MP_CPU_EXCHANGE_INFO *ExchangeInfo,
471 IN UINTN NumApsExecuting
472 )
473 {
474 CPU_MP_DATA *CpuMpData;
475 UINTN ProcessorNumber;
476 EFI_AP_PROCEDURE Procedure;
477 VOID *Parameter;
478 UINT32 BistData;
479 volatile UINT32 *ApStartupSignalBuffer;
480 CPU_INFO_IN_HOB *CpuInfoInHob;
481
482 //
483 // AP finished assembly code and begin to execute C code
484 //
485 CpuMpData = ExchangeInfo->CpuMpData;
486
487 ProgramVirtualWireMode ();
488
489 while (TRUE) {
490 if (CpuMpData->InitFlag == ApInitConfig) {
491 //
492 // Add CPU number
493 //
494 InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount);
495 ProcessorNumber = NumApsExecuting;
496 //
497 // This is first time AP wakeup, get BIST information from AP stack
498 //
499 BistData = *(UINT32 *) (CpuMpData->Buffer + ProcessorNumber * CpuMpData->CpuApStackSize - sizeof (UINTN));
500 //
501 // Do some AP initialize sync
502 //
503 ApInitializeSync (CpuMpData);
504 //
505 // Sync BSP's Control registers to APs
506 //
507 RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);
508 InitializeApData (CpuMpData, ProcessorNumber, BistData);
509 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
510 } else {
511 //
512 // Execute AP function if AP is ready
513 //
514 GetProcessorNumber (CpuMpData, &ProcessorNumber);
515 //
516 // Clear AP start-up signal when AP waken up
517 //
518 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
519 InterlockedCompareExchange32 (
520 (UINT32 *) ApStartupSignalBuffer,
521 WAKEUP_AP_SIGNAL,
522 0
523 );
524 if (CpuMpData->ApLoopMode == ApInHltLoop) {
525 //
526 // Restore AP's volatile registers saved
527 //
528 RestoreVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters, TRUE);
529 }
530
531 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateReady) {
532 Procedure = (EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction;
533 Parameter = (VOID *) CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument;
534 if (Procedure != NULL) {
535 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy);
536 //
537 // Invoke AP function here
538 //
539 Procedure (Parameter);
540 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
541 if (CpuMpData->SwitchBspFlag) {
542 //
543 // Re-get the processor number due to BSP/AP maybe exchange in AP function
544 //
545 GetProcessorNumber (CpuMpData, &ProcessorNumber);
546 CpuMpData->CpuData[ProcessorNumber].ApFunction = 0;
547 CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument = 0;
548 } else {
549 //
550 // Re-get the CPU APICID and Initial APICID
551 //
552 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
553 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
554 }
555 }
556 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
557 }
558 }
559
560 //
561 // AP finished executing C code
562 //
563 InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount);
564
565 //
566 // Place AP is specified loop mode
567 //
568 if (CpuMpData->ApLoopMode == ApInHltLoop) {
569 //
570 // Save AP volatile registers
571 //
572 SaveVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters);
573 //
574 // Place AP in HLT-loop
575 //
576 while (TRUE) {
577 DisableInterrupts ();
578 CpuSleep ();
579 CpuPause ();
580 }
581 }
582 while (TRUE) {
583 DisableInterrupts ();
584 if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
585 //
586 // Place AP in MWAIT-loop
587 //
588 AsmMonitor ((UINTN) ApStartupSignalBuffer, 0, 0);
589 if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
590 //
591 // Check AP start-up signal again.
592 // If AP start-up signal is not set, place AP into
593 // the specified C-state
594 //
595 AsmMwait (CpuMpData->ApTargetCState << 4, 0);
596 }
597 } else if (CpuMpData->ApLoopMode == ApInRunLoop) {
598 //
599 // Place AP in Run-loop
600 //
601 CpuPause ();
602 } else {
603 ASSERT (FALSE);
604 }
605
606 //
607 // If AP start-up signal is written, AP is waken up
608 // otherwise place AP in loop again
609 //
610 if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
611 break;
612 }
613 }
614 }
615 }
616
617 /**
618 Wait for AP wakeup and write AP start-up signal till AP is waken up.
619
620 @param[in] ApStartupSignalBuffer Pointer to AP wakeup signal
621 **/
622 VOID
623 WaitApWakeup (
624 IN volatile UINT32 *ApStartupSignalBuffer
625 )
626 {
627 //
628 // If AP is waken up, StartupApSignal should be cleared.
629 // Otherwise, write StartupApSignal again till AP waken up.
630 //
631 while (InterlockedCompareExchange32 (
632 (UINT32 *) ApStartupSignalBuffer,
633 WAKEUP_AP_SIGNAL,
634 WAKEUP_AP_SIGNAL
635 ) != 0) {
636 CpuPause ();
637 }
638 }
639
640 /**
641 This function will fill the exchange info structure.
642
643 @param[in] CpuMpData Pointer to CPU MP Data
644
645 **/
646 VOID
647 FillExchangeInfoData (
648 IN CPU_MP_DATA *CpuMpData
649 )
650 {
651 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
652
653 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
654 ExchangeInfo->Lock = 0;
655 ExchangeInfo->StackStart = CpuMpData->Buffer;
656 ExchangeInfo->StackSize = CpuMpData->CpuApStackSize;
657 ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer;
658 ExchangeInfo->ModeOffset = CpuMpData->AddressMap.ModeEntryOffset;
659
660 ExchangeInfo->CodeSegment = AsmReadCs ();
661 ExchangeInfo->DataSegment = AsmReadDs ();
662
663 ExchangeInfo->Cr3 = AsmReadCr3 ();
664
665 ExchangeInfo->CFunction = (UINTN) ApWakeupFunction;
666 ExchangeInfo->NumApsExecuting = 0;
667 ExchangeInfo->InitFlag = (UINTN) CpuMpData->InitFlag;
668 ExchangeInfo->CpuInfo = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
669 ExchangeInfo->CpuMpData = CpuMpData;
670
671 ExchangeInfo->EnableExecuteDisable = IsBspExecuteDisableEnabled ();
672
673 //
674 // Get the BSP's data of GDT and IDT
675 //
676 AsmReadGdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->GdtrProfile);
677 AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
678 }
679
680 /**
681 This function will be called by BSP to wakeup AP.
682
683 @param[in] CpuMpData Pointer to CPU MP Data
684 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
685 FALSE: Send IPI to AP by ApicId
686 @param[in] ProcessorNumber The handle number of specified processor
687 @param[in] Procedure The function to be invoked by AP
688 @param[in] ProcedureArgument The argument to be passed into AP function
689 **/
690 VOID
691 WakeUpAP (
692 IN CPU_MP_DATA *CpuMpData,
693 IN BOOLEAN Broadcast,
694 IN UINTN ProcessorNumber,
695 IN EFI_AP_PROCEDURE Procedure, OPTIONAL
696 IN VOID *ProcedureArgument OPTIONAL
697 )
698 {
699 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
700 UINTN Index;
701 CPU_AP_DATA *CpuData;
702 BOOLEAN ResetVectorRequired;
703 CPU_INFO_IN_HOB *CpuInfoInHob;
704
705 CpuMpData->FinishedCount = 0;
706 ResetVectorRequired = FALSE;
707
708 if (CpuMpData->ApLoopMode == ApInHltLoop ||
709 CpuMpData->InitFlag != ApInitDone) {
710 ResetVectorRequired = TRUE;
711 AllocateResetVector (CpuMpData);
712 FillExchangeInfoData (CpuMpData);
713 } else if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
714 //
715 // Get AP target C-state each time when waking up AP,
716 // for it maybe updated by platform again
717 //
718 CpuMpData->ApTargetCState = PcdGet8 (PcdCpuApTargetCstate);
719 }
720
721 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
722
723 if (Broadcast) {
724 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
725 if (Index != CpuMpData->BspNumber) {
726 CpuData = &CpuMpData->CpuData[Index];
727 CpuData->ApFunction = (UINTN) Procedure;
728 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
729 SetApState (CpuData, CpuStateReady);
730 if (CpuMpData->InitFlag != ApInitConfig) {
731 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
732 }
733 }
734 }
735 if (ResetVectorRequired) {
736 //
737 // Wakeup all APs
738 //
739 SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
740 }
741 if (CpuMpData->InitFlag == ApInitConfig) {
742 //
743 // Wait for all potential APs waken up in one specified period
744 //
745 MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds));
746 } else {
747 //
748 // Wait all APs waken up if this is not the 1st broadcast of SIPI
749 //
750 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
751 CpuData = &CpuMpData->CpuData[Index];
752 if (Index != CpuMpData->BspNumber) {
753 WaitApWakeup (CpuData->StartupApSignal);
754 }
755 }
756 }
757 } else {
758 CpuData = &CpuMpData->CpuData[ProcessorNumber];
759 CpuData->ApFunction = (UINTN) Procedure;
760 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
761 SetApState (CpuData, CpuStateReady);
762 //
763 // Wakeup specified AP
764 //
765 ASSERT (CpuMpData->InitFlag != ApInitConfig);
766 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
767 if (ResetVectorRequired) {
768 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
769 SendInitSipiSipi (
770 CpuInfoInHob[ProcessorNumber].ApicId,
771 (UINT32) ExchangeInfo->BufferStart
772 );
773 }
774 //
775 // Wait specified AP waken up
776 //
777 WaitApWakeup (CpuData->StartupApSignal);
778 }
779
780 if (ResetVectorRequired) {
781 FreeResetVector (CpuMpData);
782 }
783 }
784
785 /**
786 Calculate timeout value and return the current performance counter value.
787
788 Calculate the number of performance counter ticks required for a timeout.
789 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
790 as infinity.
791
792 @param[in] TimeoutInMicroseconds Timeout value in microseconds.
793 @param[out] CurrentTime Returns the current value of the performance counter.
794
795 @return Expected time stamp counter for timeout.
796 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
797 as infinity.
798
799 **/
800 UINT64
801 CalculateTimeout (
802 IN UINTN TimeoutInMicroseconds,
803 OUT UINT64 *CurrentTime
804 )
805 {
806 //
807 // Read the current value of the performance counter
808 //
809 *CurrentTime = GetPerformanceCounter ();
810
811 //
812 // If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
813 // as infinity.
814 //
815 if (TimeoutInMicroseconds == 0) {
816 return 0;
817 }
818
819 //
820 // GetPerformanceCounterProperties () returns the timestamp counter's frequency
821 // in Hz. So multiply the return value with TimeoutInMicroseconds and then divide
822 // it by 1,000,000, to get the number of ticks for the timeout value.
823 //
824 return DivU64x32 (
825 MultU64x64 (
826 GetPerformanceCounterProperties (NULL, NULL),
827 TimeoutInMicroseconds
828 ),
829 1000000
830 );
831 }
832
833 /**
834 Checks whether timeout expires.
835
836 Check whether the number of elapsed performance counter ticks required for
837 a timeout condition has been reached.
838 If Timeout is zero, which means infinity, return value is always FALSE.
839
840 @param[in, out] PreviousTime On input, the value of the performance counter
841 when it was last read.
842 On output, the current value of the performance
843 counter
844 @param[in] TotalTime The total amount of elapsed time in performance
845 counter ticks.
846 @param[in] Timeout The number of performance counter ticks required
847 to reach a timeout condition.
848
849 @retval TRUE A timeout condition has been reached.
850 @retval FALSE A timeout condition has not been reached.
851
852 **/
853 BOOLEAN
854 CheckTimeout (
855 IN OUT UINT64 *PreviousTime,
856 IN UINT64 *TotalTime,
857 IN UINT64 Timeout
858 )
859 {
860 UINT64 Start;
861 UINT64 End;
862 UINT64 CurrentTime;
863 INT64 Delta;
864 INT64 Cycle;
865
866 if (Timeout == 0) {
867 return FALSE;
868 }
869 GetPerformanceCounterProperties (&Start, &End);
870 Cycle = End - Start;
871 if (Cycle < 0) {
872 Cycle = -Cycle;
873 }
874 Cycle++;
875 CurrentTime = GetPerformanceCounter();
876 Delta = (INT64) (CurrentTime - *PreviousTime);
877 if (Start > End) {
878 Delta = -Delta;
879 }
880 if (Delta < 0) {
881 Delta += Cycle;
882 }
883 *TotalTime += Delta;
884 *PreviousTime = CurrentTime;
885 if (*TotalTime > Timeout) {
886 return TRUE;
887 }
888 return FALSE;
889 }
890
891 /**
892 Reset an AP to Idle state.
893
894 Any task being executed by the AP will be aborted and the AP
895 will be waiting for a new task in Wait-For-SIPI state.
896
897 @param[in] ProcessorNumber The handle number of processor.
898 **/
899 VOID
900 ResetProcessorToIdleState (
901 IN UINTN ProcessorNumber
902 )
903 {
904 CPU_MP_DATA *CpuMpData;
905
906 CpuMpData = GetCpuMpData ();
907
908 CpuMpData->InitFlag = ApInitReconfig;
909 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, NULL, NULL);
910 while (CpuMpData->FinishedCount < 1) {
911 CpuPause ();
912 }
913 CpuMpData->InitFlag = ApInitDone;
914
915 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
916 }
917
918 /**
919 Searches for the next waiting AP.
920
921 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
922
923 @param[out] NextProcessorNumber Pointer to the processor number of the next waiting AP.
924
925 @retval EFI_SUCCESS The next waiting AP has been found.
926 @retval EFI_NOT_FOUND No waiting AP exists.
927
928 **/
929 EFI_STATUS
930 GetNextWaitingProcessorNumber (
931 OUT UINTN *NextProcessorNumber
932 )
933 {
934 UINTN ProcessorNumber;
935 CPU_MP_DATA *CpuMpData;
936
937 CpuMpData = GetCpuMpData ();
938
939 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
940 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
941 *NextProcessorNumber = ProcessorNumber;
942 return EFI_SUCCESS;
943 }
944 }
945
946 return EFI_NOT_FOUND;
947 }
948
949 /** Checks status of specified AP.
950
951 This function checks whether the specified AP has finished the task assigned
952 by StartupThisAP(), and whether timeout expires.
953
954 @param[in] ProcessorNumber The handle number of processor.
955
956 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
957 @retval EFI_TIMEOUT The timeout expires.
958 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
959 **/
960 EFI_STATUS
961 CheckThisAP (
962 IN UINTN ProcessorNumber
963 )
964 {
965 CPU_MP_DATA *CpuMpData;
966 CPU_AP_DATA *CpuData;
967
968 CpuMpData = GetCpuMpData ();
969 CpuData = &CpuMpData->CpuData[ProcessorNumber];
970
971 //
972 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
973 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
974 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
975 //
976 //
977 // If the AP finishes for StartupThisAP(), return EFI_SUCCESS.
978 //
979 if (GetApState(CpuData) == CpuStateFinished) {
980 if (CpuData->Finished != NULL) {
981 *(CpuData->Finished) = TRUE;
982 }
983 SetApState (CpuData, CpuStateIdle);
984 return EFI_SUCCESS;
985 } else {
986 //
987 // If timeout expires for StartupThisAP(), report timeout.
988 //
989 if (CheckTimeout (&CpuData->CurrentTime, &CpuData->TotalTime, CpuData->ExpectedTime)) {
990 if (CpuData->Finished != NULL) {
991 *(CpuData->Finished) = FALSE;
992 }
993 //
994 // Reset failed AP to idle state
995 //
996 ResetProcessorToIdleState (ProcessorNumber);
997
998 return EFI_TIMEOUT;
999 }
1000 }
1001 return EFI_NOT_READY;
1002 }
1003
1004 /**
1005 Checks status of all APs.
1006
1007 This function checks whether all APs have finished task assigned by StartupAllAPs(),
1008 and whether timeout expires.
1009
1010 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
1011 @retval EFI_TIMEOUT The timeout expires.
1012 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
1013 **/
1014 EFI_STATUS
1015 CheckAllAPs (
1016 VOID
1017 )
1018 {
1019 UINTN ProcessorNumber;
1020 UINTN NextProcessorNumber;
1021 UINTN ListIndex;
1022 EFI_STATUS Status;
1023 CPU_MP_DATA *CpuMpData;
1024 CPU_AP_DATA *CpuData;
1025
1026 CpuMpData = GetCpuMpData ();
1027
1028 NextProcessorNumber = 0;
1029
1030 //
1031 // Go through all APs that are responsible for the StartupAllAPs().
1032 //
1033 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1034 if (!CpuMpData->CpuData[ProcessorNumber].Waiting) {
1035 continue;
1036 }
1037
1038 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1039 //
1040 // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.
1041 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
1042 // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.
1043 //
1044 if (GetApState(CpuData) == CpuStateFinished) {
1045 CpuMpData->RunningCount ++;
1046 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1047 SetApState(CpuData, CpuStateIdle);
1048
1049 //
1050 // If in Single Thread mode, then search for the next waiting AP for execution.
1051 //
1052 if (CpuMpData->SingleThread) {
1053 Status = GetNextWaitingProcessorNumber (&NextProcessorNumber);
1054
1055 if (!EFI_ERROR (Status)) {
1056 WakeUpAP (
1057 CpuMpData,
1058 FALSE,
1059 (UINT32) NextProcessorNumber,
1060 CpuMpData->Procedure,
1061 CpuMpData->ProcArguments
1062 );
1063 }
1064 }
1065 }
1066 }
1067
1068 //
1069 // If all APs finish, return EFI_SUCCESS.
1070 //
1071 if (CpuMpData->RunningCount == CpuMpData->StartCount) {
1072 return EFI_SUCCESS;
1073 }
1074
1075 //
1076 // If timeout expires, report timeout.
1077 //
1078 if (CheckTimeout (
1079 &CpuMpData->CurrentTime,
1080 &CpuMpData->TotalTime,
1081 CpuMpData->ExpectedTime)
1082 ) {
1083 //
1084 // If FailedCpuList is not NULL, record all failed APs in it.
1085 //
1086 if (CpuMpData->FailedCpuList != NULL) {
1087 *CpuMpData->FailedCpuList =
1088 AllocatePool ((CpuMpData->StartCount - CpuMpData->FinishedCount + 1) * sizeof (UINTN));
1089 ASSERT (*CpuMpData->FailedCpuList != NULL);
1090 }
1091 ListIndex = 0;
1092
1093 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1094 //
1095 // Check whether this processor is responsible for StartupAllAPs().
1096 //
1097 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1098 //
1099 // Reset failed APs to idle state
1100 //
1101 ResetProcessorToIdleState (ProcessorNumber);
1102 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1103 if (CpuMpData->FailedCpuList != NULL) {
1104 (*CpuMpData->FailedCpuList)[ListIndex++] = ProcessorNumber;
1105 }
1106 }
1107 }
1108 if (CpuMpData->FailedCpuList != NULL) {
1109 (*CpuMpData->FailedCpuList)[ListIndex] = END_OF_CPU_LIST;
1110 }
1111 return EFI_TIMEOUT;
1112 }
1113 return EFI_NOT_READY;
1114 }
1115
1116 /**
1117 MP Initialize Library initialization.
1118
1119 This service will allocate AP reset vector and wakeup all APs to do APs
1120 initialization.
1121
1122 This service must be invoked before all other MP Initialize Library
1123 service are invoked.
1124
1125 @retval EFI_SUCCESS MP initialization succeeds.
1126 @retval Others MP initialization fails.
1127
1128 **/
1129 EFI_STATUS
1130 EFIAPI
1131 MpInitLibInitialize (
1132 VOID
1133 )
1134 {
1135 CPU_MP_DATA *OldCpuMpData;
1136 CPU_INFO_IN_HOB *CpuInfoInHob;
1137 UINT32 MaxLogicalProcessorNumber;
1138 UINT32 ApStackSize;
1139 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
1140 UINTN BufferSize;
1141 UINT32 MonitorFilterSize;
1142 VOID *MpBuffer;
1143 UINTN Buffer;
1144 CPU_MP_DATA *CpuMpData;
1145 UINT8 ApLoopMode;
1146 UINT8 *MonitorBuffer;
1147 UINTN Index;
1148 UINTN ApResetVectorSize;
1149 UINTN BackupBufferAddr;
1150
1151 OldCpuMpData = GetCpuMpDataFromGuidedHob ();
1152 if (OldCpuMpData == NULL) {
1153 MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
1154 } else {
1155 MaxLogicalProcessorNumber = OldCpuMpData->CpuCount;
1156 }
1157 ASSERT (MaxLogicalProcessorNumber != 0);
1158
1159 AsmGetAddressMap (&AddressMap);
1160 ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO);
1161 ApStackSize = PcdGet32(PcdCpuApStackSize);
1162 ApLoopMode = GetApLoopMode (&MonitorFilterSize);
1163
1164 BufferSize = ApStackSize * MaxLogicalProcessorNumber;
1165 BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;
1166 BufferSize += sizeof (CPU_MP_DATA);
1167 BufferSize += ApResetVectorSize;
1168 BufferSize += (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* MaxLogicalProcessorNumber;
1169 MpBuffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));
1170 ASSERT (MpBuffer != NULL);
1171 ZeroMem (MpBuffer, BufferSize);
1172 Buffer = (UINTN) MpBuffer;
1173
1174 MonitorBuffer = (UINT8 *) (Buffer + ApStackSize * MaxLogicalProcessorNumber);
1175 BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber;
1176 CpuMpData = (CPU_MP_DATA *) (BackupBufferAddr + ApResetVectorSize);
1177 CpuMpData->Buffer = Buffer;
1178 CpuMpData->CpuApStackSize = ApStackSize;
1179 CpuMpData->BackupBuffer = BackupBufferAddr;
1180 CpuMpData->BackupBufferSize = ApResetVectorSize;
1181 CpuMpData->SaveRestoreFlag = FALSE;
1182 CpuMpData->WakeupBuffer = (UINTN) -1;
1183 CpuMpData->CpuCount = 1;
1184 CpuMpData->BspNumber = 0;
1185 CpuMpData->WaitEvent = NULL;
1186 CpuMpData->SwitchBspFlag = FALSE;
1187 CpuMpData->CpuData = (CPU_AP_DATA *) (CpuMpData + 1);
1188 CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + MaxLogicalProcessorNumber);
1189 InitializeSpinLock(&CpuMpData->MpLock);
1190 //
1191 // Save BSP's Control registers to APs
1192 //
1193 SaveVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters);
1194 //
1195 // Set BSP basic information
1196 //
1197 InitializeApData (CpuMpData, 0, 0);
1198 //
1199 // Save assembly code information
1200 //
1201 CopyMem (&CpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP));
1202 //
1203 // Finally set AP loop mode
1204 //
1205 CpuMpData->ApLoopMode = ApLoopMode;
1206 DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
1207 //
1208 // Set up APs wakeup signal buffer
1209 //
1210 for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
1211 CpuMpData->CpuData[Index].StartupApSignal =
1212 (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
1213 }
1214 //
1215 // Load Microcode on BSP
1216 //
1217 MicrocodeDetect (CpuMpData);
1218 //
1219 // Store BSP's MTRR setting
1220 //
1221 MtrrGetAllMtrrs (&CpuMpData->MtrrTable);
1222
1223 if (OldCpuMpData == NULL) {
1224 if (MaxLogicalProcessorNumber > 1) {
1225 //
1226 // Wakeup all APs and calculate the processor count in system
1227 //
1228 CollectProcessorCount (CpuMpData);
1229 }
1230 } else {
1231 //
1232 // APs have been wakeup before, just get the CPU Information
1233 // from HOB
1234 //
1235 CpuMpData->CpuCount = OldCpuMpData->CpuCount;
1236 CpuMpData->BspNumber = OldCpuMpData->BspNumber;
1237 CpuMpData->InitFlag = ApInitReconfig;
1238 CpuMpData->CpuInfoInHob = OldCpuMpData->CpuInfoInHob;
1239 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1240 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1241 InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
1242 if (CpuInfoInHob[Index].InitialApicId >= 255) {
1243 CpuMpData->X2ApicEnable = TRUE;
1244 }
1245 CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
1246 CpuMpData->CpuData[Index].ApFunction = 0;
1247 CopyMem (
1248 &CpuMpData->CpuData[Index].VolatileRegisters,
1249 &CpuMpData->CpuData[0].VolatileRegisters,
1250 sizeof (CPU_VOLATILE_REGISTERS)
1251 );
1252 }
1253 if (MaxLogicalProcessorNumber > 1) {
1254 //
1255 // Wakeup APs to do some AP initialize sync
1256 //
1257 WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData);
1258 //
1259 // Wait for all APs finished initialization
1260 //
1261 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
1262 CpuPause ();
1263 }
1264 CpuMpData->InitFlag = ApInitDone;
1265 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1266 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
1267 }
1268 }
1269 }
1270
1271 //
1272 // Initialize global data for MP support
1273 //
1274 InitMpGlobalData (CpuMpData);
1275
1276 return EFI_SUCCESS;
1277 }
1278
1279 /**
1280 Gets detailed MP-related information on the requested processor at the
1281 instant this call is made. This service may only be called from the BSP.
1282
1283 @param[in] ProcessorNumber The handle number of processor.
1284 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
1285 the requested processor is deposited.
1286 @param[out] HealthData Return processor health data.
1287
1288 @retval EFI_SUCCESS Processor information was returned.
1289 @retval EFI_DEVICE_ERROR The calling processor is an AP.
1290 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
1291 @retval EFI_NOT_FOUND The processor with the handle specified by
1292 ProcessorNumber does not exist in the platform.
1293 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1294
1295 **/
1296 EFI_STATUS
1297 EFIAPI
1298 MpInitLibGetProcessorInfo (
1299 IN UINTN ProcessorNumber,
1300 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,
1301 OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL
1302 )
1303 {
1304 CPU_MP_DATA *CpuMpData;
1305 UINTN CallerNumber;
1306 CPU_INFO_IN_HOB *CpuInfoInHob;
1307
1308 CpuMpData = GetCpuMpData ();
1309 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1310
1311 //
1312 // Check whether caller processor is BSP
1313 //
1314 MpInitLibWhoAmI (&CallerNumber);
1315 if (CallerNumber != CpuMpData->BspNumber) {
1316 return EFI_DEVICE_ERROR;
1317 }
1318
1319 if (ProcessorInfoBuffer == NULL) {
1320 return EFI_INVALID_PARAMETER;
1321 }
1322
1323 if (ProcessorNumber >= CpuMpData->CpuCount) {
1324 return EFI_NOT_FOUND;
1325 }
1326
1327 ProcessorInfoBuffer->ProcessorId = (UINT64) CpuInfoInHob[ProcessorNumber].ApicId;
1328 ProcessorInfoBuffer->StatusFlag = 0;
1329 if (ProcessorNumber == CpuMpData->BspNumber) {
1330 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_AS_BSP_BIT;
1331 }
1332 if (CpuMpData->CpuData[ProcessorNumber].CpuHealthy) {
1333 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_HEALTH_STATUS_BIT;
1334 }
1335 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
1336 ProcessorInfoBuffer->StatusFlag &= ~PROCESSOR_ENABLED_BIT;
1337 } else {
1338 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_ENABLED_BIT;
1339 }
1340
1341 //
1342 // Get processor location information
1343 //
1344 GetProcessorLocationByApicId (
1345 CpuInfoInHob[ProcessorNumber].ApicId,
1346 &ProcessorInfoBuffer->Location.Package,
1347 &ProcessorInfoBuffer->Location.Core,
1348 &ProcessorInfoBuffer->Location.Thread
1349 );
1350
1351 if (HealthData != NULL) {
1352 HealthData->Uint32 = CpuInfoInHob[ProcessorNumber].Health;
1353 }
1354
1355 return EFI_SUCCESS;
1356 }
1357
1358 /**
1359 Worker function to switch the requested AP to be the BSP from that point onward.
1360
1361 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
1362 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
1363 enabled AP. Otherwise, it will be disabled.
1364
1365 @retval EFI_SUCCESS BSP successfully switched.
1366 @retval others Failed to switch BSP.
1367
1368 **/
1369 EFI_STATUS
1370 SwitchBSPWorker (
1371 IN UINTN ProcessorNumber,
1372 IN BOOLEAN EnableOldBSP
1373 )
1374 {
1375 CPU_MP_DATA *CpuMpData;
1376 UINTN CallerNumber;
1377 CPU_STATE State;
1378 MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
1379
1380 CpuMpData = GetCpuMpData ();
1381
1382 //
1383 // Check whether caller processor is BSP
1384 //
1385 MpInitLibWhoAmI (&CallerNumber);
1386 if (CallerNumber != CpuMpData->BspNumber) {
1387 return EFI_SUCCESS;
1388 }
1389
1390 if (ProcessorNumber >= CpuMpData->CpuCount) {
1391 return EFI_NOT_FOUND;
1392 }
1393
1394 //
1395 // Check whether specified AP is disabled
1396 //
1397 State = GetApState (&CpuMpData->CpuData[ProcessorNumber]);
1398 if (State == CpuStateDisabled) {
1399 return EFI_INVALID_PARAMETER;
1400 }
1401
1402 //
1403 // Check whether ProcessorNumber specifies the current BSP
1404 //
1405 if (ProcessorNumber == CpuMpData->BspNumber) {
1406 return EFI_INVALID_PARAMETER;
1407 }
1408
1409 //
1410 // Check whether specified AP is busy
1411 //
1412 if (State == CpuStateBusy) {
1413 return EFI_NOT_READY;
1414 }
1415
1416 CpuMpData->BSPInfo.State = CPU_SWITCH_STATE_IDLE;
1417 CpuMpData->APInfo.State = CPU_SWITCH_STATE_IDLE;
1418 CpuMpData->SwitchBspFlag = TRUE;
1419
1420 //
1421 // Clear the BSP bit of MSR_IA32_APIC_BASE
1422 //
1423 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1424 ApicBaseMsr.Bits.BSP = 0;
1425 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1426
1427 //
1428 // Need to wakeUp AP (future BSP).
1429 //
1430 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, FutureBSPProc, CpuMpData);
1431
1432 AsmExchangeRole (&CpuMpData->BSPInfo, &CpuMpData->APInfo);
1433
1434 //
1435 // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP
1436 //
1437 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1438 ApicBaseMsr.Bits.BSP = 1;
1439 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1440
1441 //
1442 // Wait for old BSP finished AP task
1443 //
1444 while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) {
1445 CpuPause ();
1446 }
1447
1448 CpuMpData->SwitchBspFlag = FALSE;
1449 //
1450 // Set old BSP enable state
1451 //
1452 if (!EnableOldBSP) {
1453 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateDisabled);
1454 }
1455 //
1456 // Save new BSP number
1457 //
1458 CpuMpData->BspNumber = (UINT32) ProcessorNumber;
1459
1460 return EFI_SUCCESS;
1461 }
1462
1463 /**
1464 Worker function to let the caller enable or disable an AP from this point onward.
1465 This service may only be called from the BSP.
1466
1467 @param[in] ProcessorNumber The handle number of AP.
1468 @param[in] EnableAP Specifies the new state for the processor for
1469 enabled, FALSE for disabled.
1470 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
1471 the new health status of the AP.
1472
1473 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
1474 @retval others Failed to Enable/Disable AP.
1475
1476 **/
1477 EFI_STATUS
1478 EnableDisableApWorker (
1479 IN UINTN ProcessorNumber,
1480 IN BOOLEAN EnableAP,
1481 IN UINT32 *HealthFlag OPTIONAL
1482 )
1483 {
1484 CPU_MP_DATA *CpuMpData;
1485 UINTN CallerNumber;
1486
1487 CpuMpData = GetCpuMpData ();
1488
1489 //
1490 // Check whether caller processor is BSP
1491 //
1492 MpInitLibWhoAmI (&CallerNumber);
1493 if (CallerNumber != CpuMpData->BspNumber) {
1494 return EFI_DEVICE_ERROR;
1495 }
1496
1497 if (ProcessorNumber == CpuMpData->BspNumber) {
1498 return EFI_INVALID_PARAMETER;
1499 }
1500
1501 if (ProcessorNumber >= CpuMpData->CpuCount) {
1502 return EFI_NOT_FOUND;
1503 }
1504
1505 if (!EnableAP) {
1506 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateDisabled);
1507 } else {
1508 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
1509 }
1510
1511 if (HealthFlag != NULL) {
1512 CpuMpData->CpuData[ProcessorNumber].CpuHealthy =
1513 (BOOLEAN) ((*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT) != 0);
1514 }
1515
1516 return EFI_SUCCESS;
1517 }
1518
1519 /**
1520 This return the handle number for the calling processor. This service may be
1521 called from the BSP and APs.
1522
1523 @param[out] ProcessorNumber Pointer to the handle number of AP.
1524 The range is from 0 to the total number of
1525 logical processors minus 1. The total number of
1526 logical processors can be retrieved by
1527 MpInitLibGetNumberOfProcessors().
1528
1529 @retval EFI_SUCCESS The current processor handle number was returned
1530 in ProcessorNumber.
1531 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
1532 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1533
1534 **/
1535 EFI_STATUS
1536 EFIAPI
1537 MpInitLibWhoAmI (
1538 OUT UINTN *ProcessorNumber
1539 )
1540 {
1541 CPU_MP_DATA *CpuMpData;
1542
1543 if (ProcessorNumber == NULL) {
1544 return EFI_INVALID_PARAMETER;
1545 }
1546
1547 CpuMpData = GetCpuMpData ();
1548
1549 return GetProcessorNumber (CpuMpData, ProcessorNumber);
1550 }
1551
1552 /**
1553 Retrieves the number of logical processor in the platform and the number of
1554 those logical processors that are enabled on this boot. This service may only
1555 be called from the BSP.
1556
1557 @param[out] NumberOfProcessors Pointer to the total number of logical
1558 processors in the system, including the BSP
1559 and disabled APs.
1560 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
1561 processors that exist in system, including
1562 the BSP.
1563
1564 @retval EFI_SUCCESS The number of logical processors and enabled
1565 logical processors was retrieved.
1566 @retval EFI_DEVICE_ERROR The calling processor is an AP.
1567 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
1568 is NULL.
1569 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1570
1571 **/
1572 EFI_STATUS
1573 EFIAPI
1574 MpInitLibGetNumberOfProcessors (
1575 OUT UINTN *NumberOfProcessors, OPTIONAL
1576 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
1577 )
1578 {
1579 CPU_MP_DATA *CpuMpData;
1580 UINTN CallerNumber;
1581 UINTN ProcessorNumber;
1582 UINTN EnabledProcessorNumber;
1583 UINTN Index;
1584
1585 CpuMpData = GetCpuMpData ();
1586
1587 if ((NumberOfProcessors == NULL) && (NumberOfEnabledProcessors == NULL)) {
1588 return EFI_INVALID_PARAMETER;
1589 }
1590
1591 //
1592 // Check whether caller processor is BSP
1593 //
1594 MpInitLibWhoAmI (&CallerNumber);
1595 if (CallerNumber != CpuMpData->BspNumber) {
1596 return EFI_DEVICE_ERROR;
1597 }
1598
1599 ProcessorNumber = CpuMpData->CpuCount;
1600 EnabledProcessorNumber = 0;
1601 for (Index = 0; Index < ProcessorNumber; Index++) {
1602 if (GetApState (&CpuMpData->CpuData[Index]) != CpuStateDisabled) {
1603 EnabledProcessorNumber ++;
1604 }
1605 }
1606
1607 if (NumberOfProcessors != NULL) {
1608 *NumberOfProcessors = ProcessorNumber;
1609 }
1610 if (NumberOfEnabledProcessors != NULL) {
1611 *NumberOfEnabledProcessors = EnabledProcessorNumber;
1612 }
1613
1614 return EFI_SUCCESS;
1615 }
1616
1617
1618 /**
1619 Worker function to execute a caller provided function on all enabled APs.
1620
1621 @param[in] Procedure A pointer to the function to be run on
1622 enabled APs of the system.
1623 @param[in] SingleThread If TRUE, then all the enabled APs execute
1624 the function specified by Procedure one by
1625 one, in ascending order of processor handle
1626 number. If FALSE, then all the enabled APs
1627 execute the function specified by Procedure
1628 simultaneously.
1629 @param[in] WaitEvent The event created by the caller with CreateEvent()
1630 service.
1631 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
1632 APs to return from Procedure, either for
1633 blocking or non-blocking mode.
1634 @param[in] ProcedureArgument The parameter passed into Procedure for
1635 all APs.
1636 @param[out] FailedCpuList If all APs finish successfully, then its
1637 content is set to NULL. If not all APs
1638 finish before timeout expires, then its
1639 content is set to address of the buffer
1640 holding handle numbers of the failed APs.
1641
1642 @retval EFI_SUCCESS In blocking mode, all APs have finished before
1643 the timeout expired.
1644 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
1645 to all enabled APs.
1646 @retval others Failed to Startup all APs.
1647
1648 **/
1649 EFI_STATUS
1650 StartupAllAPsWorker (
1651 IN EFI_AP_PROCEDURE Procedure,
1652 IN BOOLEAN SingleThread,
1653 IN EFI_EVENT WaitEvent OPTIONAL,
1654 IN UINTN TimeoutInMicroseconds,
1655 IN VOID *ProcedureArgument OPTIONAL,
1656 OUT UINTN **FailedCpuList OPTIONAL
1657 )
1658 {
1659 EFI_STATUS Status;
1660 CPU_MP_DATA *CpuMpData;
1661 UINTN ProcessorCount;
1662 UINTN ProcessorNumber;
1663 UINTN CallerNumber;
1664 CPU_AP_DATA *CpuData;
1665 BOOLEAN HasEnabledAp;
1666 CPU_STATE ApState;
1667
1668 CpuMpData = GetCpuMpData ();
1669
1670 if (FailedCpuList != NULL) {
1671 *FailedCpuList = NULL;
1672 }
1673
1674 if (CpuMpData->CpuCount == 1) {
1675 return EFI_NOT_STARTED;
1676 }
1677
1678 if (Procedure == NULL) {
1679 return EFI_INVALID_PARAMETER;
1680 }
1681
1682 //
1683 // Check whether caller processor is BSP
1684 //
1685 MpInitLibWhoAmI (&CallerNumber);
1686 if (CallerNumber != CpuMpData->BspNumber) {
1687 return EFI_DEVICE_ERROR;
1688 }
1689
1690 //
1691 // Update AP state
1692 //
1693 CheckAndUpdateApsStatus ();
1694
1695 ProcessorCount = CpuMpData->CpuCount;
1696 HasEnabledAp = FALSE;
1697 //
1698 // Check whether all enabled APs are idle.
1699 // If any enabled AP is not idle, return EFI_NOT_READY.
1700 //
1701 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1702 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1703 if (ProcessorNumber != CpuMpData->BspNumber) {
1704 ApState = GetApState (CpuData);
1705 if (ApState != CpuStateDisabled) {
1706 HasEnabledAp = TRUE;
1707 if (ApState != CpuStateIdle) {
1708 //
1709 // If any enabled APs are busy, return EFI_NOT_READY.
1710 //
1711 return EFI_NOT_READY;
1712 }
1713 }
1714 }
1715 }
1716
1717 if (!HasEnabledAp) {
1718 //
1719 // If no enabled AP exists, return EFI_NOT_STARTED.
1720 //
1721 return EFI_NOT_STARTED;
1722 }
1723
1724 CpuMpData->StartCount = 0;
1725 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1726 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1727 CpuData->Waiting = FALSE;
1728 if (ProcessorNumber != CpuMpData->BspNumber) {
1729 if (CpuData->State == CpuStateIdle) {
1730 //
1731 // Mark this processor as responsible for current calling.
1732 //
1733 CpuData->Waiting = TRUE;
1734 CpuMpData->StartCount++;
1735 }
1736 }
1737 }
1738
1739 CpuMpData->Procedure = Procedure;
1740 CpuMpData->ProcArguments = ProcedureArgument;
1741 CpuMpData->SingleThread = SingleThread;
1742 CpuMpData->FinishedCount = 0;
1743 CpuMpData->RunningCount = 0;
1744 CpuMpData->FailedCpuList = FailedCpuList;
1745 CpuMpData->ExpectedTime = CalculateTimeout (
1746 TimeoutInMicroseconds,
1747 &CpuMpData->CurrentTime
1748 );
1749 CpuMpData->TotalTime = 0;
1750 CpuMpData->WaitEvent = WaitEvent;
1751
1752 if (!SingleThread) {
1753 WakeUpAP (CpuMpData, TRUE, 0, Procedure, ProcedureArgument);
1754 } else {
1755 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
1756 if (ProcessorNumber == CallerNumber) {
1757 continue;
1758 }
1759 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1760 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument);
1761 break;
1762 }
1763 }
1764 }
1765
1766 Status = EFI_SUCCESS;
1767 if (WaitEvent == NULL) {
1768 do {
1769 Status = CheckAllAPs ();
1770 } while (Status == EFI_NOT_READY);
1771 }
1772
1773 return Status;
1774 }
1775
1776 /**
1777 Worker function to let the caller get one enabled AP to execute a caller-provided
1778 function.
1779
1780 @param[in] Procedure A pointer to the function to be run on
1781 enabled APs of the system.
1782 @param[in] ProcessorNumber The handle number of the AP.
1783 @param[in] WaitEvent The event created by the caller with CreateEvent()
1784 service.
1785 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
1786 APs to return from Procedure, either for
1787 blocking or non-blocking mode.
1788 @param[in] ProcedureArgument The parameter passed into Procedure for
1789 all APs.
1790 @param[out] Finished If AP returns from Procedure before the
1791 timeout expires, its content is set to TRUE.
1792 Otherwise, the value is set to FALSE.
1793
1794 @retval EFI_SUCCESS In blocking mode, specified AP finished before
1795 the timeout expires.
1796 @retval others Failed to Startup AP.
1797
1798 **/
1799 EFI_STATUS
1800 StartupThisAPWorker (
1801 IN EFI_AP_PROCEDURE Procedure,
1802 IN UINTN ProcessorNumber,
1803 IN EFI_EVENT WaitEvent OPTIONAL,
1804 IN UINTN TimeoutInMicroseconds,
1805 IN VOID *ProcedureArgument OPTIONAL,
1806 OUT BOOLEAN *Finished OPTIONAL
1807 )
1808 {
1809 EFI_STATUS Status;
1810 CPU_MP_DATA *CpuMpData;
1811 CPU_AP_DATA *CpuData;
1812 UINTN CallerNumber;
1813
1814 CpuMpData = GetCpuMpData ();
1815
1816 if (Finished != NULL) {
1817 *Finished = FALSE;
1818 }
1819
1820 //
1821 // Check whether caller processor is BSP
1822 //
1823 MpInitLibWhoAmI (&CallerNumber);
1824 if (CallerNumber != CpuMpData->BspNumber) {
1825 return EFI_DEVICE_ERROR;
1826 }
1827
1828 //
1829 // Check whether processor with the handle specified by ProcessorNumber exists
1830 //
1831 if (ProcessorNumber >= CpuMpData->CpuCount) {
1832 return EFI_NOT_FOUND;
1833 }
1834
1835 //
1836 // Check whether specified processor is BSP
1837 //
1838 if (ProcessorNumber == CpuMpData->BspNumber) {
1839 return EFI_INVALID_PARAMETER;
1840 }
1841
1842 //
1843 // Check parameter Procedure
1844 //
1845 if (Procedure == NULL) {
1846 return EFI_INVALID_PARAMETER;
1847 }
1848
1849 //
1850 // Update AP state
1851 //
1852 CheckAndUpdateApsStatus ();
1853
1854 //
1855 // Check whether specified AP is disabled
1856 //
1857 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
1858 return EFI_INVALID_PARAMETER;
1859 }
1860
1861 //
1862 // If WaitEvent is not NULL, execute in non-blocking mode.
1863 // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
1864 // CheckAPsStatus() will check completion and timeout periodically.
1865 //
1866 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1867 CpuData->WaitEvent = WaitEvent;
1868 CpuData->Finished = Finished;
1869 CpuData->ExpectedTime = CalculateTimeout (TimeoutInMicroseconds, &CpuData->CurrentTime);
1870 CpuData->TotalTime = 0;
1871
1872 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument);
1873
1874 //
1875 // If WaitEvent is NULL, execute in blocking mode.
1876 // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expires.
1877 //
1878 Status = EFI_SUCCESS;
1879 if (WaitEvent == NULL) {
1880 do {
1881 Status = CheckThisAP (ProcessorNumber);
1882 } while (Status == EFI_NOT_READY);
1883 }
1884
1885 return Status;
1886 }
1887
1888 /**
1889 Get pointer to CPU MP Data structure from GUIDed HOB.
1890
1891 @return The pointer to CPU MP Data structure.
1892 **/
1893 CPU_MP_DATA *
1894 GetCpuMpDataFromGuidedHob (
1895 VOID
1896 )
1897 {
1898 EFI_HOB_GUID_TYPE *GuidHob;
1899 VOID *DataInHob;
1900 CPU_MP_DATA *CpuMpData;
1901
1902 CpuMpData = NULL;
1903 GuidHob = GetFirstGuidHob (&mCpuInitMpLibHobGuid);
1904 if (GuidHob != NULL) {
1905 DataInHob = GET_GUID_HOB_DATA (GuidHob);
1906 CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
1907 }
1908 return CpuMpData;
1909 }
1910
1911 /**
1912 Get available system memory below 1MB by specified size.
1913
1914 @param[in] CpuMpData The pointer to CPU MP Data structure.
1915 **/
1916 VOID
1917 BackupAndPrepareWakeupBuffer(
1918 IN CPU_MP_DATA *CpuMpData
1919 )
1920 {
1921 CopyMem (
1922 (VOID *) CpuMpData->BackupBuffer,
1923 (VOID *) CpuMpData->WakeupBuffer,
1924 CpuMpData->BackupBufferSize
1925 );
1926 CopyMem (
1927 (VOID *) CpuMpData->WakeupBuffer,
1928 (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,
1929 CpuMpData->AddressMap.RendezvousFunnelSize
1930 );
1931 }
1932
1933 /**
1934 Restore wakeup buffer data.
1935
1936 @param[in] CpuMpData The pointer to CPU MP Data structure.
1937 **/
1938 VOID
1939 RestoreWakeupBuffer(
1940 IN CPU_MP_DATA *CpuMpData
1941 )
1942 {
1943 CopyMem (
1944 (VOID *) CpuMpData->WakeupBuffer,
1945 (VOID *) CpuMpData->BackupBuffer,
1946 CpuMpData->BackupBufferSize
1947 );
1948 }