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