]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.c
d32adf0780b72cf7c9934832532e653c021c4b9f
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.c
1 /** @file
2 CPU MP Initialize Library common functions.
3
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "MpLib.h"
10
11 EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
12
13 /**
14 The function will check if BSP Execute Disable is enabled.
15
16 DxeIpl may have enabled Execute Disable for BSP, APs need to
17 get the status and sync up the settings.
18 If BSP's CR0.Paging is not set, BSP execute Disble feature is
19 not working actually.
20
21 @retval TRUE BSP Execute Disable is enabled.
22 @retval FALSE BSP Execute Disable is not enabled.
23 **/
24 BOOLEAN
25 IsBspExecuteDisableEnabled (
26 VOID
27 )
28 {
29 UINT32 Eax;
30 CPUID_EXTENDED_CPU_SIG_EDX Edx;
31 MSR_IA32_EFER_REGISTER EferMsr;
32 BOOLEAN Enabled;
33 IA32_CR0 Cr0;
34
35 Enabled = FALSE;
36 Cr0.UintN = AsmReadCr0 ();
37 if (Cr0.Bits.PG != 0) {
38 //
39 // If CR0 Paging bit is set
40 //
41 AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL);
42 if (Eax >= CPUID_EXTENDED_CPU_SIG) {
43 AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &Edx.Uint32);
44 //
45 // CPUID 0x80000001
46 // Bit 20: Execute Disable Bit available.
47 //
48 if (Edx.Bits.NX != 0) {
49 EferMsr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
50 //
51 // MSR 0xC0000080
52 // Bit 11: Execute Disable Bit enable.
53 //
54 if (EferMsr.Bits.NXE != 0) {
55 Enabled = TRUE;
56 }
57 }
58 }
59 }
60
61 return Enabled;
62 }
63
64 /**
65 Worker function for SwitchBSP().
66
67 Worker function for SwitchBSP(), assigned to the AP which is intended
68 to become BSP.
69
70 @param[in] Buffer Pointer to CPU MP Data
71 **/
72 VOID
73 EFIAPI
74 FutureBSPProc (
75 IN VOID *Buffer
76 )
77 {
78 CPU_MP_DATA *DataInHob;
79
80 DataInHob = (CPU_MP_DATA *) Buffer;
81 AsmExchangeRole (&DataInHob->APInfo, &DataInHob->BSPInfo);
82 }
83
84 /**
85 Get the Application Processors state.
86
87 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
88
89 @return The AP status
90 **/
91 CPU_STATE
92 GetApState (
93 IN CPU_AP_DATA *CpuData
94 )
95 {
96 return CpuData->State;
97 }
98
99 /**
100 Set the Application Processors state.
101
102 @param[in] CpuData The pointer to CPU_AP_DATA of specified AP
103 @param[in] State The AP status
104 **/
105 VOID
106 SetApState (
107 IN CPU_AP_DATA *CpuData,
108 IN CPU_STATE State
109 )
110 {
111 AcquireSpinLock (&CpuData->ApLock);
112 CpuData->State = State;
113 ReleaseSpinLock (&CpuData->ApLock);
114 }
115
116 /**
117 Save BSP's local APIC timer setting.
118
119 @param[in] CpuMpData Pointer to CPU MP Data
120 **/
121 VOID
122 SaveLocalApicTimerSetting (
123 IN CPU_MP_DATA *CpuMpData
124 )
125 {
126 //
127 // Record the current local APIC timer setting of BSP
128 //
129 GetApicTimerState (
130 &CpuMpData->DivideValue,
131 &CpuMpData->PeriodicMode,
132 &CpuMpData->Vector
133 );
134 CpuMpData->CurrentTimerCount = GetApicTimerCurrentCount ();
135 CpuMpData->TimerInterruptState = GetApicTimerInterruptState ();
136 }
137
138 /**
139 Sync local APIC timer setting from BSP to AP.
140
141 @param[in] CpuMpData Pointer to CPU MP Data
142 **/
143 VOID
144 SyncLocalApicTimerSetting (
145 IN CPU_MP_DATA *CpuMpData
146 )
147 {
148 //
149 // Sync local APIC timer setting from BSP to AP
150 //
151 InitializeApicTimer (
152 CpuMpData->DivideValue,
153 CpuMpData->CurrentTimerCount,
154 CpuMpData->PeriodicMode,
155 CpuMpData->Vector
156 );
157 //
158 // Disable AP's local APIC timer interrupt
159 //
160 DisableApicTimerInterrupt ();
161 }
162
163 /**
164 Save the volatile registers required to be restored following INIT IPI.
165
166 @param[out] VolatileRegisters Returns buffer saved the volatile resisters
167 **/
168 VOID
169 SaveVolatileRegisters (
170 OUT CPU_VOLATILE_REGISTERS *VolatileRegisters
171 )
172 {
173 CPUID_VERSION_INFO_EDX VersionInfoEdx;
174
175 VolatileRegisters->Cr0 = AsmReadCr0 ();
176 VolatileRegisters->Cr3 = AsmReadCr3 ();
177 VolatileRegisters->Cr4 = AsmReadCr4 ();
178
179 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32);
180 if (VersionInfoEdx.Bits.DE != 0) {
181 //
182 // If processor supports Debugging Extensions feature
183 // by CPUID.[EAX=01H]:EDX.BIT2
184 //
185 VolatileRegisters->Dr0 = AsmReadDr0 ();
186 VolatileRegisters->Dr1 = AsmReadDr1 ();
187 VolatileRegisters->Dr2 = AsmReadDr2 ();
188 VolatileRegisters->Dr3 = AsmReadDr3 ();
189 VolatileRegisters->Dr6 = AsmReadDr6 ();
190 VolatileRegisters->Dr7 = AsmReadDr7 ();
191 }
192
193 AsmReadGdtr (&VolatileRegisters->Gdtr);
194 AsmReadIdtr (&VolatileRegisters->Idtr);
195 VolatileRegisters->Tr = AsmReadTr ();
196 }
197
198 /**
199 Restore the volatile registers following INIT IPI.
200
201 @param[in] VolatileRegisters Pointer to volatile resisters
202 @param[in] IsRestoreDr TRUE: Restore DRx if supported
203 FALSE: Do not restore DRx
204 **/
205 VOID
206 RestoreVolatileRegisters (
207 IN CPU_VOLATILE_REGISTERS *VolatileRegisters,
208 IN BOOLEAN IsRestoreDr
209 )
210 {
211 CPUID_VERSION_INFO_EDX VersionInfoEdx;
212 IA32_TSS_DESCRIPTOR *Tss;
213
214 AsmWriteCr3 (VolatileRegisters->Cr3);
215 AsmWriteCr4 (VolatileRegisters->Cr4);
216 AsmWriteCr0 (VolatileRegisters->Cr0);
217
218 if (IsRestoreDr) {
219 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32);
220 if (VersionInfoEdx.Bits.DE != 0) {
221 //
222 // If processor supports Debugging Extensions feature
223 // by CPUID.[EAX=01H]:EDX.BIT2
224 //
225 AsmWriteDr0 (VolatileRegisters->Dr0);
226 AsmWriteDr1 (VolatileRegisters->Dr1);
227 AsmWriteDr2 (VolatileRegisters->Dr2);
228 AsmWriteDr3 (VolatileRegisters->Dr3);
229 AsmWriteDr6 (VolatileRegisters->Dr6);
230 AsmWriteDr7 (VolatileRegisters->Dr7);
231 }
232 }
233
234 AsmWriteGdtr (&VolatileRegisters->Gdtr);
235 AsmWriteIdtr (&VolatileRegisters->Idtr);
236 if (VolatileRegisters->Tr != 0 &&
237 VolatileRegisters->Tr < VolatileRegisters->Gdtr.Limit) {
238 Tss = (IA32_TSS_DESCRIPTOR *)(VolatileRegisters->Gdtr.Base +
239 VolatileRegisters->Tr);
240 if (Tss->Bits.P == 1) {
241 Tss->Bits.Type &= 0xD; // 1101 - Clear busy bit just in case
242 AsmWriteTr (VolatileRegisters->Tr);
243 }
244 }
245 }
246
247 /**
248 Detect whether Mwait-monitor feature is supported.
249
250 @retval TRUE Mwait-monitor feature is supported.
251 @retval FALSE Mwait-monitor feature is not supported.
252 **/
253 BOOLEAN
254 IsMwaitSupport (
255 VOID
256 )
257 {
258 CPUID_VERSION_INFO_ECX VersionInfoEcx;
259
260 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &VersionInfoEcx.Uint32, NULL);
261 return (VersionInfoEcx.Bits.MONITOR == 1) ? TRUE : FALSE;
262 }
263
264 /**
265 Get AP loop mode.
266
267 @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.
268
269 @return The AP loop mode.
270 **/
271 UINT8
272 GetApLoopMode (
273 OUT UINT32 *MonitorFilterSize
274 )
275 {
276 UINT8 ApLoopMode;
277 CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx;
278
279 ASSERT (MonitorFilterSize != NULL);
280
281 ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
282 ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
283 if (ApLoopMode == ApInMwaitLoop) {
284 if (!IsMwaitSupport ()) {
285 //
286 // If processor does not support MONITOR/MWAIT feature,
287 // force AP in Hlt-loop mode
288 //
289 ApLoopMode = ApInHltLoop;
290 }
291 }
292
293 if (ApLoopMode != ApInMwaitLoop) {
294 *MonitorFilterSize = sizeof (UINT32);
295 } else {
296 //
297 // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
298 // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
299 //
300 AsmCpuid (CPUID_MONITOR_MWAIT, NULL, &MonitorMwaitEbx.Uint32, NULL, NULL);
301 *MonitorFilterSize = MonitorMwaitEbx.Bits.LargestMonitorLineSize;
302 }
303
304 return ApLoopMode;
305 }
306
307 /**
308 Sort the APIC ID of all processors.
309
310 This function sorts the APIC ID of all processors so that processor number is
311 assigned in the ascending order of APIC ID which eases MP debugging.
312
313 @param[in] CpuMpData Pointer to PEI CPU MP Data
314 **/
315 VOID
316 SortApicId (
317 IN CPU_MP_DATA *CpuMpData
318 )
319 {
320 UINTN Index1;
321 UINTN Index2;
322 UINTN Index3;
323 UINT32 ApicId;
324 CPU_INFO_IN_HOB CpuInfo;
325 UINT32 ApCount;
326 CPU_INFO_IN_HOB *CpuInfoInHob;
327 volatile UINT32 *StartupApSignal;
328
329 ApCount = CpuMpData->CpuCount - 1;
330 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
331 if (ApCount != 0) {
332 for (Index1 = 0; Index1 < ApCount; Index1++) {
333 Index3 = Index1;
334 //
335 // Sort key is the hardware default APIC ID
336 //
337 ApicId = CpuInfoInHob[Index1].ApicId;
338 for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
339 if (ApicId > CpuInfoInHob[Index2].ApicId) {
340 Index3 = Index2;
341 ApicId = CpuInfoInHob[Index2].ApicId;
342 }
343 }
344 if (Index3 != Index1) {
345 CopyMem (&CpuInfo, &CpuInfoInHob[Index3], sizeof (CPU_INFO_IN_HOB));
346 CopyMem (
347 &CpuInfoInHob[Index3],
348 &CpuInfoInHob[Index1],
349 sizeof (CPU_INFO_IN_HOB)
350 );
351 CopyMem (&CpuInfoInHob[Index1], &CpuInfo, sizeof (CPU_INFO_IN_HOB));
352
353 //
354 // Also exchange the StartupApSignal.
355 //
356 StartupApSignal = CpuMpData->CpuData[Index3].StartupApSignal;
357 CpuMpData->CpuData[Index3].StartupApSignal =
358 CpuMpData->CpuData[Index1].StartupApSignal;
359 CpuMpData->CpuData[Index1].StartupApSignal = StartupApSignal;
360 }
361 }
362
363 //
364 // Get the processor number for the BSP
365 //
366 ApicId = GetInitialApicId ();
367 for (Index1 = 0; Index1 < CpuMpData->CpuCount; Index1++) {
368 if (CpuInfoInHob[Index1].ApicId == ApicId) {
369 CpuMpData->BspNumber = (UINT32) Index1;
370 break;
371 }
372 }
373 }
374 }
375
376 /**
377 Enable x2APIC mode on APs.
378
379 @param[in, out] Buffer Pointer to private data buffer.
380 **/
381 VOID
382 EFIAPI
383 ApFuncEnableX2Apic (
384 IN OUT VOID *Buffer
385 )
386 {
387 SetApicMode (LOCAL_APIC_MODE_X2APIC);
388 }
389
390 /**
391 Do sync on APs.
392
393 @param[in, out] Buffer Pointer to private data buffer.
394 **/
395 VOID
396 EFIAPI
397 ApInitializeSync (
398 IN OUT VOID *Buffer
399 )
400 {
401 CPU_MP_DATA *CpuMpData;
402
403 CpuMpData = (CPU_MP_DATA *) Buffer;
404 //
405 // Load microcode on AP
406 //
407 MicrocodeDetect (CpuMpData, FALSE);
408 //
409 // Sync BSP's MTRR table to AP
410 //
411 MtrrSetAllMtrrs (&CpuMpData->MtrrTable);
412 }
413
414 /**
415 Find the current Processor number by APIC ID.
416
417 @param[in] CpuMpData Pointer to PEI CPU MP Data
418 @param[out] ProcessorNumber Return the pocessor number found
419
420 @retval EFI_SUCCESS ProcessorNumber is found and returned.
421 @retval EFI_NOT_FOUND ProcessorNumber is not found.
422 **/
423 EFI_STATUS
424 GetProcessorNumber (
425 IN CPU_MP_DATA *CpuMpData,
426 OUT UINTN *ProcessorNumber
427 )
428 {
429 UINTN TotalProcessorNumber;
430 UINTN Index;
431 CPU_INFO_IN_HOB *CpuInfoInHob;
432 UINT32 CurrentApicId;
433
434 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
435
436 TotalProcessorNumber = CpuMpData->CpuCount;
437 CurrentApicId = GetApicId ();
438 for (Index = 0; Index < TotalProcessorNumber; Index ++) {
439 if (CpuInfoInHob[Index].ApicId == CurrentApicId) {
440 *ProcessorNumber = Index;
441 return EFI_SUCCESS;
442 }
443 }
444
445 return EFI_NOT_FOUND;
446 }
447
448 /**
449 This function will get CPU count in the system.
450
451 @param[in] CpuMpData Pointer to PEI CPU MP Data
452
453 @return CPU count detected
454 **/
455 UINTN
456 CollectProcessorCount (
457 IN CPU_MP_DATA *CpuMpData
458 )
459 {
460 UINTN Index;
461 CPU_INFO_IN_HOB *CpuInfoInHob;
462 BOOLEAN X2Apic;
463
464 //
465 // Send 1st broadcast IPI to APs to wakeup APs
466 //
467 CpuMpData->InitFlag = ApInitConfig;
468 WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
469 CpuMpData->InitFlag = ApInitDone;
470 ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
471 //
472 // Wait for all APs finished the initialization
473 //
474 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
475 CpuPause ();
476 }
477
478
479 //
480 // Enable x2APIC mode if
481 // 1. Number of CPU is greater than 255; or
482 // 2. There are any logical processors reporting an Initial APIC ID of 255 or greater.
483 //
484 X2Apic = FALSE;
485 if (CpuMpData->CpuCount > 255) {
486 //
487 // If there are more than 255 processor found, force to enable X2APIC
488 //
489 X2Apic = TRUE;
490 } else {
491 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
492 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
493 if (CpuInfoInHob[Index].InitialApicId >= 0xFF) {
494 X2Apic = TRUE;
495 break;
496 }
497 }
498 }
499
500 if (X2Apic) {
501 DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n"));
502 //
503 // Wakeup all APs to enable x2APIC mode
504 //
505 WakeUpAP (CpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL, TRUE);
506 //
507 // Wait for all known APs finished
508 //
509 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
510 CpuPause ();
511 }
512 //
513 // Enable x2APIC on BSP
514 //
515 SetApicMode (LOCAL_APIC_MODE_X2APIC);
516 //
517 // Set BSP/Aps state to IDLE
518 //
519 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
520 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
521 }
522 }
523 DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ()));
524 //
525 // Sort BSP/Aps by CPU APIC ID in ascending order
526 //
527 SortApicId (CpuMpData);
528
529 DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));
530
531 return CpuMpData->CpuCount;
532 }
533
534 /**
535 Initialize CPU AP Data when AP is wakeup at the first time.
536
537 @param[in, out] CpuMpData Pointer to PEI CPU MP Data
538 @param[in] ProcessorNumber The handle number of processor
539 @param[in] BistData Processor BIST data
540 @param[in] ApTopOfStack Top of AP stack
541
542 **/
543 VOID
544 InitializeApData (
545 IN OUT CPU_MP_DATA *CpuMpData,
546 IN UINTN ProcessorNumber,
547 IN UINT32 BistData,
548 IN UINT64 ApTopOfStack
549 )
550 {
551 CPU_INFO_IN_HOB *CpuInfoInHob;
552
553 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
554 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
555 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
556 CpuInfoInHob[ProcessorNumber].Health = BistData;
557 CpuInfoInHob[ProcessorNumber].ApTopOfStack = ApTopOfStack;
558
559 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
560 CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ? TRUE : FALSE;
561
562 InitializeSpinLock(&CpuMpData->CpuData[ProcessorNumber].ApLock);
563 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
564 }
565
566 /**
567 This function will be called from AP reset code if BSP uses WakeUpAP.
568
569 @param[in] ExchangeInfo Pointer to the MP exchange info buffer
570 @param[in] ApIndex Number of current executing AP
571 **/
572 VOID
573 EFIAPI
574 ApWakeupFunction (
575 IN MP_CPU_EXCHANGE_INFO *ExchangeInfo,
576 IN UINTN ApIndex
577 )
578 {
579 CPU_MP_DATA *CpuMpData;
580 UINTN ProcessorNumber;
581 EFI_AP_PROCEDURE Procedure;
582 VOID *Parameter;
583 UINT32 BistData;
584 volatile UINT32 *ApStartupSignalBuffer;
585 CPU_INFO_IN_HOB *CpuInfoInHob;
586 UINT64 ApTopOfStack;
587 UINTN CurrentApicMode;
588
589 //
590 // AP finished assembly code and begin to execute C code
591 //
592 CpuMpData = ExchangeInfo->CpuMpData;
593
594 //
595 // AP's local APIC settings will be lost after received INIT IPI
596 // We need to re-initialize them at here
597 //
598 ProgramVirtualWireMode ();
599 //
600 // Mask the LINT0 and LINT1 so that AP doesn't enter the system timer interrupt handler.
601 //
602 DisableLvtInterrupts ();
603 SyncLocalApicTimerSetting (CpuMpData);
604
605 CurrentApicMode = GetApicMode ();
606 while (TRUE) {
607 if (CpuMpData->InitFlag == ApInitConfig) {
608 //
609 // Add CPU number
610 //
611 InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount);
612 ProcessorNumber = ApIndex;
613 //
614 // This is first time AP wakeup, get BIST information from AP stack
615 //
616 ApTopOfStack = CpuMpData->Buffer + (ProcessorNumber + 1) * CpuMpData->CpuApStackSize;
617 BistData = *(UINT32 *) ((UINTN) ApTopOfStack - sizeof (UINTN));
618 //
619 // Do some AP initialize sync
620 //
621 ApInitializeSync (CpuMpData);
622 //
623 // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP environment,
624 // to initialize AP in InitConfig path.
625 // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters points to a different IDT shared by all APs.
626 //
627 RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);
628 InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);
629 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
630
631 InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumApsExecuting);
632 } else {
633 //
634 // Execute AP function if AP is ready
635 //
636 GetProcessorNumber (CpuMpData, &ProcessorNumber);
637 //
638 // Clear AP start-up signal when AP waken up
639 //
640 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
641 InterlockedCompareExchange32 (
642 (UINT32 *) ApStartupSignalBuffer,
643 WAKEUP_AP_SIGNAL,
644 0
645 );
646 if (CpuMpData->ApLoopMode == ApInHltLoop) {
647 //
648 // Restore AP's volatile registers saved
649 //
650 RestoreVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters, TRUE);
651 } else {
652 //
653 // The CPU driver might not flush TLB for APs on spot after updating
654 // page attributes. AP in mwait loop mode needs to take care of it when
655 // woken up.
656 //
657 CpuFlushTlb ();
658 }
659
660 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateReady) {
661 Procedure = (EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction;
662 Parameter = (VOID *) CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument;
663 if (Procedure != NULL) {
664 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy);
665 //
666 // Enable source debugging on AP function
667 //
668 EnableDebugAgent ();
669 //
670 // Invoke AP function here
671 //
672 Procedure (Parameter);
673 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
674 if (CpuMpData->SwitchBspFlag) {
675 //
676 // Re-get the processor number due to BSP/AP maybe exchange in AP function
677 //
678 GetProcessorNumber (CpuMpData, &ProcessorNumber);
679 CpuMpData->CpuData[ProcessorNumber].ApFunction = 0;
680 CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument = 0;
681 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
682 CpuInfoInHob[ProcessorNumber].ApTopOfStack = CpuInfoInHob[CpuMpData->NewBspNumber].ApTopOfStack;
683 } else {
684 if (CpuInfoInHob[ProcessorNumber].ApicId != GetApicId () ||
685 CpuInfoInHob[ProcessorNumber].InitialApicId != GetInitialApicId ()) {
686 if (CurrentApicMode != GetApicMode ()) {
687 //
688 // If APIC mode change happened during AP function execution,
689 // we do not support APIC ID value changed.
690 //
691 ASSERT (FALSE);
692 CpuDeadLoop ();
693 } else {
694 //
695 // Re-get the CPU APICID and Initial APICID if they are changed
696 //
697 CpuInfoInHob[ProcessorNumber].ApicId = GetApicId ();
698 CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
699 }
700 }
701 }
702 }
703 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
704 }
705 }
706
707 //
708 // AP finished executing C code
709 //
710 InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount);
711
712 //
713 // Place AP is specified loop mode
714 //
715 if (CpuMpData->ApLoopMode == ApInHltLoop) {
716 //
717 // Save AP volatile registers
718 //
719 SaveVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].VolatileRegisters);
720 //
721 // Place AP in HLT-loop
722 //
723 while (TRUE) {
724 DisableInterrupts ();
725 CpuSleep ();
726 CpuPause ();
727 }
728 }
729 while (TRUE) {
730 DisableInterrupts ();
731 if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
732 //
733 // Place AP in MWAIT-loop
734 //
735 AsmMonitor ((UINTN) ApStartupSignalBuffer, 0, 0);
736 if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
737 //
738 // Check AP start-up signal again.
739 // If AP start-up signal is not set, place AP into
740 // the specified C-state
741 //
742 AsmMwait (CpuMpData->ApTargetCState << 4, 0);
743 }
744 } else if (CpuMpData->ApLoopMode == ApInRunLoop) {
745 //
746 // Place AP in Run-loop
747 //
748 CpuPause ();
749 } else {
750 ASSERT (FALSE);
751 }
752
753 //
754 // If AP start-up signal is written, AP is waken up
755 // otherwise place AP in loop again
756 //
757 if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
758 break;
759 }
760 }
761 }
762 }
763
764 /**
765 Wait for AP wakeup and write AP start-up signal till AP is waken up.
766
767 @param[in] ApStartupSignalBuffer Pointer to AP wakeup signal
768 **/
769 VOID
770 WaitApWakeup (
771 IN volatile UINT32 *ApStartupSignalBuffer
772 )
773 {
774 //
775 // If AP is waken up, StartupApSignal should be cleared.
776 // Otherwise, write StartupApSignal again till AP waken up.
777 //
778 while (InterlockedCompareExchange32 (
779 (UINT32 *) ApStartupSignalBuffer,
780 WAKEUP_AP_SIGNAL,
781 WAKEUP_AP_SIGNAL
782 ) != 0) {
783 CpuPause ();
784 }
785 }
786
787 /**
788 This function will fill the exchange info structure.
789
790 @param[in] CpuMpData Pointer to CPU MP Data
791
792 **/
793 VOID
794 FillExchangeInfoData (
795 IN CPU_MP_DATA *CpuMpData
796 )
797 {
798 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
799 UINTN Size;
800 IA32_SEGMENT_DESCRIPTOR *Selector;
801 IA32_CR4 Cr4;
802
803 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
804 ExchangeInfo->Lock = 0;
805 ExchangeInfo->StackStart = CpuMpData->Buffer;
806 ExchangeInfo->StackSize = CpuMpData->CpuApStackSize;
807 ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer;
808 ExchangeInfo->ModeOffset = CpuMpData->AddressMap.ModeEntryOffset;
809
810 ExchangeInfo->CodeSegment = AsmReadCs ();
811 ExchangeInfo->DataSegment = AsmReadDs ();
812
813 ExchangeInfo->Cr3 = AsmReadCr3 ();
814
815 ExchangeInfo->CFunction = (UINTN) ApWakeupFunction;
816 ExchangeInfo->ApIndex = 0;
817 ExchangeInfo->NumApsExecuting = 0;
818 ExchangeInfo->InitFlag = (UINTN) CpuMpData->InitFlag;
819 ExchangeInfo->CpuInfo = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
820 ExchangeInfo->CpuMpData = CpuMpData;
821
822 ExchangeInfo->EnableExecuteDisable = IsBspExecuteDisableEnabled ();
823
824 ExchangeInfo->InitializeFloatingPointUnitsAddress = (UINTN)InitializeFloatingPointUnits;
825
826 //
827 // We can check either CPUID(7).ECX[bit16] or check CR4.LA57[bit12]
828 // to determin whether 5-Level Paging is enabled.
829 // CPUID(7).ECX[bit16] shows CPU's capability, CR4.LA57[bit12] shows
830 // current system setting.
831 // Using latter way is simpler because it also eliminates the needs to
832 // check whether platform wants to enable it.
833 //
834 Cr4.UintN = AsmReadCr4 ();
835 ExchangeInfo->Enable5LevelPaging = (BOOLEAN) (Cr4.Bits.LA57 == 1);
836 DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));
837
838 //
839 // Get the BSP's data of GDT and IDT
840 //
841 AsmReadGdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->GdtrProfile);
842 AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
843
844 //
845 // Find a 32-bit code segment
846 //
847 Selector = (IA32_SEGMENT_DESCRIPTOR *)ExchangeInfo->GdtrProfile.Base;
848 Size = ExchangeInfo->GdtrProfile.Limit + 1;
849 while (Size > 0) {
850 if (Selector->Bits.L == 0 && Selector->Bits.Type >= 8) {
851 ExchangeInfo->ModeTransitionSegment =
852 (UINT16)((UINTN)Selector - ExchangeInfo->GdtrProfile.Base);
853 break;
854 }
855 Selector += 1;
856 Size -= sizeof (IA32_SEGMENT_DESCRIPTOR);
857 }
858
859 //
860 // Copy all 32-bit code and 64-bit code into memory with type of
861 // EfiBootServicesCode to avoid page fault if NX memory protection is enabled.
862 //
863 if (CpuMpData->WakeupBufferHigh != 0) {
864 Size = CpuMpData->AddressMap.RendezvousFunnelSize -
865 CpuMpData->AddressMap.ModeTransitionOffset;
866 CopyMem (
867 (VOID *)CpuMpData->WakeupBufferHigh,
868 CpuMpData->AddressMap.RendezvousFunnelAddress +
869 CpuMpData->AddressMap.ModeTransitionOffset,
870 Size
871 );
872
873 ExchangeInfo->ModeTransitionMemory = (UINT32)CpuMpData->WakeupBufferHigh;
874 } else {
875 ExchangeInfo->ModeTransitionMemory = (UINT32)
876 (ExchangeInfo->BufferStart + CpuMpData->AddressMap.ModeTransitionOffset);
877 }
878
879 ExchangeInfo->ModeHighMemory = ExchangeInfo->ModeTransitionMemory +
880 (UINT32)ExchangeInfo->ModeOffset -
881 (UINT32)CpuMpData->AddressMap.ModeTransitionOffset;
882 ExchangeInfo->ModeHighSegment = (UINT16)ExchangeInfo->CodeSegment;
883 }
884
885 /**
886 Helper function that waits until the finished AP count reaches the specified
887 limit, or the specified timeout elapses (whichever comes first).
888
889 @param[in] CpuMpData Pointer to CPU MP Data.
890 @param[in] FinishedApLimit The number of finished APs to wait for.
891 @param[in] TimeLimit The number of microseconds to wait for.
892 **/
893 VOID
894 TimedWaitForApFinish (
895 IN CPU_MP_DATA *CpuMpData,
896 IN UINT32 FinishedApLimit,
897 IN UINT32 TimeLimit
898 );
899
900 /**
901 Get available system memory below 1MB by specified size.
902
903 @param[in] CpuMpData The pointer to CPU MP Data structure.
904 **/
905 VOID
906 BackupAndPrepareWakeupBuffer(
907 IN CPU_MP_DATA *CpuMpData
908 )
909 {
910 CopyMem (
911 (VOID *) CpuMpData->BackupBuffer,
912 (VOID *) CpuMpData->WakeupBuffer,
913 CpuMpData->BackupBufferSize
914 );
915 CopyMem (
916 (VOID *) CpuMpData->WakeupBuffer,
917 (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,
918 CpuMpData->AddressMap.RendezvousFunnelSize
919 );
920 }
921
922 /**
923 Restore wakeup buffer data.
924
925 @param[in] CpuMpData The pointer to CPU MP Data structure.
926 **/
927 VOID
928 RestoreWakeupBuffer(
929 IN CPU_MP_DATA *CpuMpData
930 )
931 {
932 CopyMem (
933 (VOID *) CpuMpData->WakeupBuffer,
934 (VOID *) CpuMpData->BackupBuffer,
935 CpuMpData->BackupBufferSize
936 );
937 }
938
939 /**
940 Allocate reset vector buffer.
941
942 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
943 **/
944 VOID
945 AllocateResetVector (
946 IN OUT CPU_MP_DATA *CpuMpData
947 )
948 {
949 UINTN ApResetVectorSize;
950
951 if (CpuMpData->WakeupBuffer == (UINTN) -1) {
952 ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +
953 sizeof (MP_CPU_EXCHANGE_INFO);
954
955 CpuMpData->WakeupBuffer = GetWakeupBuffer (ApResetVectorSize);
956 CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)
957 (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize);
958 CpuMpData->WakeupBufferHigh = GetModeTransitionBuffer (
959 CpuMpData->AddressMap.RendezvousFunnelSize -
960 CpuMpData->AddressMap.ModeTransitionOffset
961 );
962 }
963 BackupAndPrepareWakeupBuffer (CpuMpData);
964 }
965
966 /**
967 Free AP reset vector buffer.
968
969 @param[in] CpuMpData The pointer to CPU MP Data structure.
970 **/
971 VOID
972 FreeResetVector (
973 IN CPU_MP_DATA *CpuMpData
974 )
975 {
976 RestoreWakeupBuffer (CpuMpData);
977 }
978
979 /**
980 This function will be called by BSP to wakeup AP.
981
982 @param[in] CpuMpData Pointer to CPU MP Data
983 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
984 FALSE: Send IPI to AP by ApicId
985 @param[in] ProcessorNumber The handle number of specified processor
986 @param[in] Procedure The function to be invoked by AP
987 @param[in] ProcedureArgument The argument to be passed into AP function
988 @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in broadcast mode.
989 **/
990 VOID
991 WakeUpAP (
992 IN CPU_MP_DATA *CpuMpData,
993 IN BOOLEAN Broadcast,
994 IN UINTN ProcessorNumber,
995 IN EFI_AP_PROCEDURE Procedure, OPTIONAL
996 IN VOID *ProcedureArgument, OPTIONAL
997 IN BOOLEAN WakeUpDisabledAps
998 )
999 {
1000 volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;
1001 UINTN Index;
1002 CPU_AP_DATA *CpuData;
1003 BOOLEAN ResetVectorRequired;
1004 CPU_INFO_IN_HOB *CpuInfoInHob;
1005
1006 CpuMpData->FinishedCount = 0;
1007 ResetVectorRequired = FALSE;
1008
1009 if (CpuMpData->WakeUpByInitSipiSipi ||
1010 CpuMpData->InitFlag != ApInitDone) {
1011 ResetVectorRequired = TRUE;
1012 AllocateResetVector (CpuMpData);
1013 FillExchangeInfoData (CpuMpData);
1014 SaveLocalApicTimerSetting (CpuMpData);
1015 }
1016
1017 if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
1018 //
1019 // Get AP target C-state each time when waking up AP,
1020 // for it maybe updated by platform again
1021 //
1022 CpuMpData->ApTargetCState = PcdGet8 (PcdCpuApTargetCstate);
1023 }
1024
1025 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
1026
1027 if (Broadcast) {
1028 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1029 if (Index != CpuMpData->BspNumber) {
1030 CpuData = &CpuMpData->CpuData[Index];
1031 //
1032 // All AP(include disabled AP) will be woke up by INIT-SIPI-SIPI, but
1033 // the AP procedure will be skipped for disabled AP because AP state
1034 // is not CpuStateReady.
1035 //
1036 if (GetApState (CpuData) == CpuStateDisabled && !WakeUpDisabledAps) {
1037 continue;
1038 }
1039
1040 CpuData->ApFunction = (UINTN) Procedure;
1041 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
1042 SetApState (CpuData, CpuStateReady);
1043 if (CpuMpData->InitFlag != ApInitConfig) {
1044 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
1045 }
1046 }
1047 }
1048 if (ResetVectorRequired) {
1049 //
1050 // Wakeup all APs
1051 //
1052 SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
1053 }
1054 if (CpuMpData->InitFlag == ApInitConfig) {
1055 if (PcdGet32 (PcdCpuBootLogicalProcessorNumber) > 0) {
1056 //
1057 // The AP enumeration algorithm below is suitable only when the
1058 // platform can tell us the *exact* boot CPU count in advance.
1059 //
1060 // The wait below finishes only when the detected AP count reaches
1061 // (PcdCpuBootLogicalProcessorNumber - 1), regardless of how long that
1062 // takes. If at least one AP fails to check in (meaning a platform
1063 // hardware bug), the detection hangs forever, by design. If the actual
1064 // boot CPU count in the system is higher than
1065 // PcdCpuBootLogicalProcessorNumber (meaning a platform
1066 // misconfiguration), then some APs may complete initialization after
1067 // the wait finishes, and cause undefined behavior.
1068 //
1069 TimedWaitForApFinish (
1070 CpuMpData,
1071 PcdGet32 (PcdCpuBootLogicalProcessorNumber) - 1,
1072 MAX_UINT32 // approx. 71 minutes
1073 );
1074 } else {
1075 //
1076 // The AP enumeration algorithm below is suitable for two use cases.
1077 //
1078 // (1) The check-in time for an individual AP is bounded, and APs run
1079 // through their initialization routines strongly concurrently. In
1080 // particular, the number of concurrently running APs
1081 // ("NumApsExecuting") is never expected to fall to zero
1082 // *temporarily* -- it is expected to fall to zero only when all
1083 // APs have checked-in.
1084 //
1085 // In this case, the platform is supposed to set
1086 // PcdCpuApInitTimeOutInMicroSeconds to a low-ish value (just long
1087 // enough for one AP to start initialization). The timeout will be
1088 // reached soon, and remaining APs are collected by watching
1089 // NumApsExecuting fall to zero. If NumApsExecuting falls to zero
1090 // mid-process, while some APs have not completed initialization,
1091 // the behavior is undefined.
1092 //
1093 // (2) The check-in time for an individual AP is unbounded, and/or APs
1094 // may complete their initializations widely spread out. In
1095 // particular, some APs may finish initialization before some APs
1096 // even start.
1097 //
1098 // In this case, the platform is supposed to set
1099 // PcdCpuApInitTimeOutInMicroSeconds to a high-ish value. The AP
1100 // enumeration will always take that long (except when the boot CPU
1101 // count happens to be maximal, that is,
1102 // PcdCpuMaxLogicalProcessorNumber). All APs are expected to
1103 // check-in before the timeout, and NumApsExecuting is assumed zero
1104 // at timeout. APs that miss the time-out may cause undefined
1105 // behavior.
1106 //
1107 TimedWaitForApFinish (
1108 CpuMpData,
1109 PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1,
1110 PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds)
1111 );
1112
1113 while (CpuMpData->MpCpuExchangeInfo->NumApsExecuting != 0) {
1114 CpuPause();
1115 }
1116 }
1117 } else {
1118 //
1119 // Wait all APs waken up if this is not the 1st broadcast of SIPI
1120 //
1121 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1122 CpuData = &CpuMpData->CpuData[Index];
1123 if (Index != CpuMpData->BspNumber) {
1124 WaitApWakeup (CpuData->StartupApSignal);
1125 }
1126 }
1127 }
1128 } else {
1129 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1130 CpuData->ApFunction = (UINTN) Procedure;
1131 CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
1132 SetApState (CpuData, CpuStateReady);
1133 //
1134 // Wakeup specified AP
1135 //
1136 ASSERT (CpuMpData->InitFlag != ApInitConfig);
1137 *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
1138 if (ResetVectorRequired) {
1139 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1140 SendInitSipiSipi (
1141 CpuInfoInHob[ProcessorNumber].ApicId,
1142 (UINT32) ExchangeInfo->BufferStart
1143 );
1144 }
1145 //
1146 // Wait specified AP waken up
1147 //
1148 WaitApWakeup (CpuData->StartupApSignal);
1149 }
1150
1151 if (ResetVectorRequired) {
1152 FreeResetVector (CpuMpData);
1153 }
1154
1155 //
1156 // After one round of Wakeup Ap actions, need to re-sync ApLoopMode with
1157 // WakeUpByInitSipiSipi flag. WakeUpByInitSipiSipi flag maybe changed by
1158 // S3SmmInitDone Ppi.
1159 //
1160 CpuMpData->WakeUpByInitSipiSipi = (CpuMpData->ApLoopMode == ApInHltLoop);
1161 }
1162
1163 /**
1164 Calculate timeout value and return the current performance counter value.
1165
1166 Calculate the number of performance counter ticks required for a timeout.
1167 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1168 as infinity.
1169
1170 @param[in] TimeoutInMicroseconds Timeout value in microseconds.
1171 @param[out] CurrentTime Returns the current value of the performance counter.
1172
1173 @return Expected time stamp counter for timeout.
1174 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1175 as infinity.
1176
1177 **/
1178 UINT64
1179 CalculateTimeout (
1180 IN UINTN TimeoutInMicroseconds,
1181 OUT UINT64 *CurrentTime
1182 )
1183 {
1184 UINT64 TimeoutInSeconds;
1185 UINT64 TimestampCounterFreq;
1186
1187 //
1188 // Read the current value of the performance counter
1189 //
1190 *CurrentTime = GetPerformanceCounter ();
1191
1192 //
1193 // If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
1194 // as infinity.
1195 //
1196 if (TimeoutInMicroseconds == 0) {
1197 return 0;
1198 }
1199
1200 //
1201 // GetPerformanceCounterProperties () returns the timestamp counter's frequency
1202 // in Hz.
1203 //
1204 TimestampCounterFreq = GetPerformanceCounterProperties (NULL, NULL);
1205
1206 //
1207 // Check the potential overflow before calculate the number of ticks for the timeout value.
1208 //
1209 if (DivU64x64Remainder (MAX_UINT64, TimeoutInMicroseconds, NULL) < TimestampCounterFreq) {
1210 //
1211 // Convert microseconds into seconds if direct multiplication overflows
1212 //
1213 TimeoutInSeconds = DivU64x32 (TimeoutInMicroseconds, 1000000);
1214 //
1215 // Assertion if the final tick count exceeds MAX_UINT64
1216 //
1217 ASSERT (DivU64x64Remainder (MAX_UINT64, TimeoutInSeconds, NULL) >= TimestampCounterFreq);
1218 return MultU64x64 (TimestampCounterFreq, TimeoutInSeconds);
1219 } else {
1220 //
1221 // No overflow case, multiply the return value with TimeoutInMicroseconds and then divide
1222 // it by 1,000,000, to get the number of ticks for the timeout value.
1223 //
1224 return DivU64x32 (
1225 MultU64x64 (
1226 TimestampCounterFreq,
1227 TimeoutInMicroseconds
1228 ),
1229 1000000
1230 );
1231 }
1232 }
1233
1234 /**
1235 Checks whether timeout expires.
1236
1237 Check whether the number of elapsed performance counter ticks required for
1238 a timeout condition has been reached.
1239 If Timeout is zero, which means infinity, return value is always FALSE.
1240
1241 @param[in, out] PreviousTime On input, the value of the performance counter
1242 when it was last read.
1243 On output, the current value of the performance
1244 counter
1245 @param[in] TotalTime The total amount of elapsed time in performance
1246 counter ticks.
1247 @param[in] Timeout The number of performance counter ticks required
1248 to reach a timeout condition.
1249
1250 @retval TRUE A timeout condition has been reached.
1251 @retval FALSE A timeout condition has not been reached.
1252
1253 **/
1254 BOOLEAN
1255 CheckTimeout (
1256 IN OUT UINT64 *PreviousTime,
1257 IN UINT64 *TotalTime,
1258 IN UINT64 Timeout
1259 )
1260 {
1261 UINT64 Start;
1262 UINT64 End;
1263 UINT64 CurrentTime;
1264 INT64 Delta;
1265 INT64 Cycle;
1266
1267 if (Timeout == 0) {
1268 return FALSE;
1269 }
1270 GetPerformanceCounterProperties (&Start, &End);
1271 Cycle = End - Start;
1272 if (Cycle < 0) {
1273 Cycle = -Cycle;
1274 }
1275 Cycle++;
1276 CurrentTime = GetPerformanceCounter();
1277 Delta = (INT64) (CurrentTime - *PreviousTime);
1278 if (Start > End) {
1279 Delta = -Delta;
1280 }
1281 if (Delta < 0) {
1282 Delta += Cycle;
1283 }
1284 *TotalTime += Delta;
1285 *PreviousTime = CurrentTime;
1286 if (*TotalTime > Timeout) {
1287 return TRUE;
1288 }
1289 return FALSE;
1290 }
1291
1292 /**
1293 Helper function that waits until the finished AP count reaches the specified
1294 limit, or the specified timeout elapses (whichever comes first).
1295
1296 @param[in] CpuMpData Pointer to CPU MP Data.
1297 @param[in] FinishedApLimit The number of finished APs to wait for.
1298 @param[in] TimeLimit The number of microseconds to wait for.
1299 **/
1300 VOID
1301 TimedWaitForApFinish (
1302 IN CPU_MP_DATA *CpuMpData,
1303 IN UINT32 FinishedApLimit,
1304 IN UINT32 TimeLimit
1305 )
1306 {
1307 //
1308 // CalculateTimeout() and CheckTimeout() consider a TimeLimit of 0
1309 // "infinity", so check for (TimeLimit == 0) explicitly.
1310 //
1311 if (TimeLimit == 0) {
1312 return;
1313 }
1314
1315 CpuMpData->TotalTime = 0;
1316 CpuMpData->ExpectedTime = CalculateTimeout (
1317 TimeLimit,
1318 &CpuMpData->CurrentTime
1319 );
1320 while (CpuMpData->FinishedCount < FinishedApLimit &&
1321 !CheckTimeout (
1322 &CpuMpData->CurrentTime,
1323 &CpuMpData->TotalTime,
1324 CpuMpData->ExpectedTime
1325 )) {
1326 CpuPause ();
1327 }
1328
1329 if (CpuMpData->FinishedCount >= FinishedApLimit) {
1330 DEBUG ((
1331 DEBUG_VERBOSE,
1332 "%a: reached FinishedApLimit=%u in %Lu microseconds\n",
1333 __FUNCTION__,
1334 FinishedApLimit,
1335 DivU64x64Remainder (
1336 MultU64x32 (CpuMpData->TotalTime, 1000000),
1337 GetPerformanceCounterProperties (NULL, NULL),
1338 NULL
1339 )
1340 ));
1341 }
1342 }
1343
1344 /**
1345 Reset an AP to Idle state.
1346
1347 Any task being executed by the AP will be aborted and the AP
1348 will be waiting for a new task in Wait-For-SIPI state.
1349
1350 @param[in] ProcessorNumber The handle number of processor.
1351 **/
1352 VOID
1353 ResetProcessorToIdleState (
1354 IN UINTN ProcessorNumber
1355 )
1356 {
1357 CPU_MP_DATA *CpuMpData;
1358
1359 CpuMpData = GetCpuMpData ();
1360
1361 CpuMpData->InitFlag = ApInitReconfig;
1362 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, NULL, NULL, TRUE);
1363 while (CpuMpData->FinishedCount < 1) {
1364 CpuPause ();
1365 }
1366 CpuMpData->InitFlag = ApInitDone;
1367
1368 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
1369 }
1370
1371 /**
1372 Searches for the next waiting AP.
1373
1374 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
1375
1376 @param[out] NextProcessorNumber Pointer to the processor number of the next waiting AP.
1377
1378 @retval EFI_SUCCESS The next waiting AP has been found.
1379 @retval EFI_NOT_FOUND No waiting AP exists.
1380
1381 **/
1382 EFI_STATUS
1383 GetNextWaitingProcessorNumber (
1384 OUT UINTN *NextProcessorNumber
1385 )
1386 {
1387 UINTN ProcessorNumber;
1388 CPU_MP_DATA *CpuMpData;
1389
1390 CpuMpData = GetCpuMpData ();
1391
1392 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1393 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1394 *NextProcessorNumber = ProcessorNumber;
1395 return EFI_SUCCESS;
1396 }
1397 }
1398
1399 return EFI_NOT_FOUND;
1400 }
1401
1402 /** Checks status of specified AP.
1403
1404 This function checks whether the specified AP has finished the task assigned
1405 by StartupThisAP(), and whether timeout expires.
1406
1407 @param[in] ProcessorNumber The handle number of processor.
1408
1409 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
1410 @retval EFI_TIMEOUT The timeout expires.
1411 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
1412 **/
1413 EFI_STATUS
1414 CheckThisAP (
1415 IN UINTN ProcessorNumber
1416 )
1417 {
1418 CPU_MP_DATA *CpuMpData;
1419 CPU_AP_DATA *CpuData;
1420
1421 CpuMpData = GetCpuMpData ();
1422 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1423
1424 //
1425 // Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task.
1426 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
1427 // value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value.
1428 //
1429 //
1430 // If the AP finishes for StartupThisAP(), return EFI_SUCCESS.
1431 //
1432 if (GetApState(CpuData) == CpuStateFinished) {
1433 if (CpuData->Finished != NULL) {
1434 *(CpuData->Finished) = TRUE;
1435 }
1436 SetApState (CpuData, CpuStateIdle);
1437 return EFI_SUCCESS;
1438 } else {
1439 //
1440 // If timeout expires for StartupThisAP(), report timeout.
1441 //
1442 if (CheckTimeout (&CpuData->CurrentTime, &CpuData->TotalTime, CpuData->ExpectedTime)) {
1443 if (CpuData->Finished != NULL) {
1444 *(CpuData->Finished) = FALSE;
1445 }
1446 //
1447 // Reset failed AP to idle state
1448 //
1449 ResetProcessorToIdleState (ProcessorNumber);
1450
1451 return EFI_TIMEOUT;
1452 }
1453 }
1454 return EFI_NOT_READY;
1455 }
1456
1457 /**
1458 Checks status of all APs.
1459
1460 This function checks whether all APs have finished task assigned by StartupAllAPs(),
1461 and whether timeout expires.
1462
1463 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
1464 @retval EFI_TIMEOUT The timeout expires.
1465 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
1466 **/
1467 EFI_STATUS
1468 CheckAllAPs (
1469 VOID
1470 )
1471 {
1472 UINTN ProcessorNumber;
1473 UINTN NextProcessorNumber;
1474 UINTN ListIndex;
1475 EFI_STATUS Status;
1476 CPU_MP_DATA *CpuMpData;
1477 CPU_AP_DATA *CpuData;
1478
1479 CpuMpData = GetCpuMpData ();
1480
1481 NextProcessorNumber = 0;
1482
1483 //
1484 // Go through all APs that are responsible for the StartupAllAPs().
1485 //
1486 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1487 if (!CpuMpData->CpuData[ProcessorNumber].Waiting) {
1488 continue;
1489 }
1490
1491 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1492 //
1493 // Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task.
1494 // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the
1495 // value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value.
1496 //
1497 if (GetApState(CpuData) == CpuStateFinished) {
1498 CpuMpData->RunningCount --;
1499 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1500 SetApState(CpuData, CpuStateIdle);
1501
1502 //
1503 // If in Single Thread mode, then search for the next waiting AP for execution.
1504 //
1505 if (CpuMpData->SingleThread) {
1506 Status = GetNextWaitingProcessorNumber (&NextProcessorNumber);
1507
1508 if (!EFI_ERROR (Status)) {
1509 WakeUpAP (
1510 CpuMpData,
1511 FALSE,
1512 (UINT32) NextProcessorNumber,
1513 CpuMpData->Procedure,
1514 CpuMpData->ProcArguments,
1515 TRUE
1516 );
1517 }
1518 }
1519 }
1520 }
1521
1522 //
1523 // If all APs finish, return EFI_SUCCESS.
1524 //
1525 if (CpuMpData->RunningCount == 0) {
1526 return EFI_SUCCESS;
1527 }
1528
1529 //
1530 // If timeout expires, report timeout.
1531 //
1532 if (CheckTimeout (
1533 &CpuMpData->CurrentTime,
1534 &CpuMpData->TotalTime,
1535 CpuMpData->ExpectedTime)
1536 ) {
1537 //
1538 // If FailedCpuList is not NULL, record all failed APs in it.
1539 //
1540 if (CpuMpData->FailedCpuList != NULL) {
1541 *CpuMpData->FailedCpuList =
1542 AllocatePool ((CpuMpData->RunningCount + 1) * sizeof (UINTN));
1543 ASSERT (*CpuMpData->FailedCpuList != NULL);
1544 }
1545 ListIndex = 0;
1546
1547 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1548 //
1549 // Check whether this processor is responsible for StartupAllAPs().
1550 //
1551 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1552 //
1553 // Reset failed APs to idle state
1554 //
1555 ResetProcessorToIdleState (ProcessorNumber);
1556 CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;
1557 if (CpuMpData->FailedCpuList != NULL) {
1558 (*CpuMpData->FailedCpuList)[ListIndex++] = ProcessorNumber;
1559 }
1560 }
1561 }
1562 if (CpuMpData->FailedCpuList != NULL) {
1563 (*CpuMpData->FailedCpuList)[ListIndex] = END_OF_CPU_LIST;
1564 }
1565 return EFI_TIMEOUT;
1566 }
1567 return EFI_NOT_READY;
1568 }
1569
1570 /**
1571 MP Initialize Library initialization.
1572
1573 This service will allocate AP reset vector and wakeup all APs to do APs
1574 initialization.
1575
1576 This service must be invoked before all other MP Initialize Library
1577 service are invoked.
1578
1579 @retval EFI_SUCCESS MP initialization succeeds.
1580 @retval Others MP initialization fails.
1581
1582 **/
1583 EFI_STATUS
1584 EFIAPI
1585 MpInitLibInitialize (
1586 VOID
1587 )
1588 {
1589 CPU_MP_DATA *OldCpuMpData;
1590 CPU_INFO_IN_HOB *CpuInfoInHob;
1591 UINT32 MaxLogicalProcessorNumber;
1592 UINT32 ApStackSize;
1593 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
1594 CPU_VOLATILE_REGISTERS VolatileRegisters;
1595 UINTN BufferSize;
1596 UINT32 MonitorFilterSize;
1597 VOID *MpBuffer;
1598 UINTN Buffer;
1599 CPU_MP_DATA *CpuMpData;
1600 UINT8 ApLoopMode;
1601 UINT8 *MonitorBuffer;
1602 UINTN Index;
1603 UINTN ApResetVectorSize;
1604 UINTN BackupBufferAddr;
1605 UINTN ApIdtBase;
1606 VOID *MicrocodePatchInRam;
1607
1608 OldCpuMpData = GetCpuMpDataFromGuidedHob ();
1609 if (OldCpuMpData == NULL) {
1610 MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
1611 } else {
1612 MaxLogicalProcessorNumber = OldCpuMpData->CpuCount;
1613 }
1614 ASSERT (MaxLogicalProcessorNumber != 0);
1615
1616 AsmGetAddressMap (&AddressMap);
1617 ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO);
1618 ApStackSize = PcdGet32(PcdCpuApStackSize);
1619 ApLoopMode = GetApLoopMode (&MonitorFilterSize);
1620
1621 //
1622 // Save BSP's Control registers for APs.
1623 //
1624 SaveVolatileRegisters (&VolatileRegisters);
1625
1626 BufferSize = ApStackSize * MaxLogicalProcessorNumber;
1627 BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;
1628 BufferSize += ApResetVectorSize;
1629 BufferSize = ALIGN_VALUE (BufferSize, 8);
1630 BufferSize += VolatileRegisters.Idtr.Limit + 1;
1631 BufferSize += sizeof (CPU_MP_DATA);
1632 BufferSize += (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* MaxLogicalProcessorNumber;
1633 MpBuffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));
1634 ASSERT (MpBuffer != NULL);
1635 ZeroMem (MpBuffer, BufferSize);
1636 Buffer = (UINTN) MpBuffer;
1637
1638 //
1639 // The layout of the Buffer is as below:
1640 //
1641 // +--------------------+ <-- Buffer
1642 // AP Stacks (N)
1643 // +--------------------+ <-- MonitorBuffer
1644 // AP Monitor Filters (N)
1645 // +--------------------+ <-- BackupBufferAddr (CpuMpData->BackupBuffer)
1646 // Backup Buffer
1647 // +--------------------+
1648 // Padding
1649 // +--------------------+ <-- ApIdtBase (8-byte boundary)
1650 // AP IDT All APs share one separate IDT. So AP can get address of CPU_MP_DATA from IDT Base.
1651 // +--------------------+ <-- CpuMpData
1652 // CPU_MP_DATA
1653 // +--------------------+ <-- CpuMpData->CpuData
1654 // CPU_AP_DATA (N)
1655 // +--------------------+ <-- CpuMpData->CpuInfoInHob
1656 // CPU_INFO_IN_HOB (N)
1657 // +--------------------+
1658 //
1659 MonitorBuffer = (UINT8 *) (Buffer + ApStackSize * MaxLogicalProcessorNumber);
1660 BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber;
1661 ApIdtBase = ALIGN_VALUE (BackupBufferAddr + ApResetVectorSize, 8);
1662 CpuMpData = (CPU_MP_DATA *) (ApIdtBase + VolatileRegisters.Idtr.Limit + 1);
1663 CpuMpData->Buffer = Buffer;
1664 CpuMpData->CpuApStackSize = ApStackSize;
1665 CpuMpData->BackupBuffer = BackupBufferAddr;
1666 CpuMpData->BackupBufferSize = ApResetVectorSize;
1667 CpuMpData->WakeupBuffer = (UINTN) -1;
1668 CpuMpData->CpuCount = 1;
1669 CpuMpData->BspNumber = 0;
1670 CpuMpData->WaitEvent = NULL;
1671 CpuMpData->SwitchBspFlag = FALSE;
1672 CpuMpData->CpuData = (CPU_AP_DATA *) (CpuMpData + 1);
1673 CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + MaxLogicalProcessorNumber);
1674 if (OldCpuMpData == NULL) {
1675 CpuMpData->MicrocodePatchRegionSize = PcdGet64 (PcdCpuMicrocodePatchRegionSize);
1676 //
1677 // If platform has more than one CPU, relocate microcode to memory to reduce
1678 // loading microcode time.
1679 //
1680 MicrocodePatchInRam = NULL;
1681 if (MaxLogicalProcessorNumber > 1) {
1682 MicrocodePatchInRam = AllocatePages (
1683 EFI_SIZE_TO_PAGES (
1684 (UINTN)CpuMpData->MicrocodePatchRegionSize
1685 )
1686 );
1687 }
1688 if (MicrocodePatchInRam == NULL) {
1689 //
1690 // there is only one processor, or no microcode patch is available, or
1691 // memory allocation failed
1692 //
1693 CpuMpData->MicrocodePatchAddress = PcdGet64 (PcdCpuMicrocodePatchAddress);
1694 } else {
1695 //
1696 // there are multiple processors, and a microcode patch is available, and
1697 // memory allocation succeeded
1698 //
1699 CopyMem (
1700 MicrocodePatchInRam,
1701 (VOID *)(UINTN)PcdGet64 (PcdCpuMicrocodePatchAddress),
1702 (UINTN)CpuMpData->MicrocodePatchRegionSize
1703 );
1704 CpuMpData->MicrocodePatchAddress = (UINTN)MicrocodePatchInRam;
1705 }
1706 }else {
1707 CpuMpData->MicrocodePatchRegionSize = OldCpuMpData->MicrocodePatchRegionSize;
1708 CpuMpData->MicrocodePatchAddress = OldCpuMpData->MicrocodePatchAddress;
1709 }
1710 InitializeSpinLock(&CpuMpData->MpLock);
1711
1712 //
1713 // Make sure no memory usage outside of the allocated buffer.
1714 //
1715 ASSERT ((CpuMpData->CpuInfoInHob + sizeof (CPU_INFO_IN_HOB) * MaxLogicalProcessorNumber) ==
1716 Buffer + BufferSize);
1717
1718 //
1719 // Duplicate BSP's IDT to APs.
1720 // All APs share one separate IDT. So AP can get the address of CpuMpData by using IDTR.BASE + IDTR.LIMIT + 1
1721 //
1722 CopyMem ((VOID *)ApIdtBase, (VOID *)VolatileRegisters.Idtr.Base, VolatileRegisters.Idtr.Limit + 1);
1723 VolatileRegisters.Idtr.Base = ApIdtBase;
1724 //
1725 // Don't pass BSP's TR to APs to avoid AP init failure.
1726 //
1727 VolatileRegisters.Tr = 0;
1728 CopyMem (&CpuMpData->CpuData[0].VolatileRegisters, &VolatileRegisters, sizeof (VolatileRegisters));
1729 //
1730 // Set BSP basic information
1731 //
1732 InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);
1733 //
1734 // Save assembly code information
1735 //
1736 CopyMem (&CpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP));
1737 //
1738 // Finally set AP loop mode
1739 //
1740 CpuMpData->ApLoopMode = ApLoopMode;
1741 DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
1742
1743 CpuMpData->WakeUpByInitSipiSipi = (CpuMpData->ApLoopMode == ApInHltLoop);
1744
1745 //
1746 // Set up APs wakeup signal buffer
1747 //
1748 for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
1749 CpuMpData->CpuData[Index].StartupApSignal =
1750 (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
1751 }
1752 //
1753 // Load Microcode on BSP
1754 //
1755 MicrocodeDetect (CpuMpData, TRUE);
1756 //
1757 // Store BSP's MTRR setting
1758 //
1759 MtrrGetAllMtrrs (&CpuMpData->MtrrTable);
1760 //
1761 // Enable the local APIC for Virtual Wire Mode.
1762 //
1763 ProgramVirtualWireMode ();
1764
1765 if (OldCpuMpData == NULL) {
1766 if (MaxLogicalProcessorNumber > 1) {
1767 //
1768 // Wakeup all APs and calculate the processor count in system
1769 //
1770 CollectProcessorCount (CpuMpData);
1771 }
1772 } else {
1773 //
1774 // APs have been wakeup before, just get the CPU Information
1775 // from HOB
1776 //
1777 CpuMpData->CpuCount = OldCpuMpData->CpuCount;
1778 CpuMpData->BspNumber = OldCpuMpData->BspNumber;
1779 CpuMpData->InitFlag = ApInitReconfig;
1780 CpuMpData->CpuInfoInHob = OldCpuMpData->CpuInfoInHob;
1781 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1782 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1783 InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
1784 CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
1785 CpuMpData->CpuData[Index].ApFunction = 0;
1786 CopyMem (&CpuMpData->CpuData[Index].VolatileRegisters, &VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));
1787 }
1788 if (MaxLogicalProcessorNumber > 1) {
1789 //
1790 // Wakeup APs to do some AP initialize sync
1791 //
1792 WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE);
1793 //
1794 // Wait for all APs finished initialization
1795 //
1796 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
1797 CpuPause ();
1798 }
1799 CpuMpData->InitFlag = ApInitDone;
1800 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1801 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
1802 }
1803 }
1804 }
1805
1806 //
1807 // Initialize global data for MP support
1808 //
1809 InitMpGlobalData (CpuMpData);
1810
1811 return EFI_SUCCESS;
1812 }
1813
1814 /**
1815 Gets detailed MP-related information on the requested processor at the
1816 instant this call is made. This service may only be called from the BSP.
1817
1818 @param[in] ProcessorNumber The handle number of processor.
1819 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
1820 the requested processor is deposited.
1821 @param[out] HealthData Return processor health data.
1822
1823 @retval EFI_SUCCESS Processor information was returned.
1824 @retval EFI_DEVICE_ERROR The calling processor is an AP.
1825 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
1826 @retval EFI_NOT_FOUND The processor with the handle specified by
1827 ProcessorNumber does not exist in the platform.
1828 @retval EFI_NOT_READY MP Initialize Library is not initialized.
1829
1830 **/
1831 EFI_STATUS
1832 EFIAPI
1833 MpInitLibGetProcessorInfo (
1834 IN UINTN ProcessorNumber,
1835 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,
1836 OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL
1837 )
1838 {
1839 CPU_MP_DATA *CpuMpData;
1840 UINTN CallerNumber;
1841 CPU_INFO_IN_HOB *CpuInfoInHob;
1842
1843 CpuMpData = GetCpuMpData ();
1844 CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
1845
1846 //
1847 // Check whether caller processor is BSP
1848 //
1849 MpInitLibWhoAmI (&CallerNumber);
1850 if (CallerNumber != CpuMpData->BspNumber) {
1851 return EFI_DEVICE_ERROR;
1852 }
1853
1854 if (ProcessorInfoBuffer == NULL) {
1855 return EFI_INVALID_PARAMETER;
1856 }
1857
1858 if (ProcessorNumber >= CpuMpData->CpuCount) {
1859 return EFI_NOT_FOUND;
1860 }
1861
1862 ProcessorInfoBuffer->ProcessorId = (UINT64) CpuInfoInHob[ProcessorNumber].ApicId;
1863 ProcessorInfoBuffer->StatusFlag = 0;
1864 if (ProcessorNumber == CpuMpData->BspNumber) {
1865 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_AS_BSP_BIT;
1866 }
1867 if (CpuMpData->CpuData[ProcessorNumber].CpuHealthy) {
1868 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_HEALTH_STATUS_BIT;
1869 }
1870 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
1871 ProcessorInfoBuffer->StatusFlag &= ~PROCESSOR_ENABLED_BIT;
1872 } else {
1873 ProcessorInfoBuffer->StatusFlag |= PROCESSOR_ENABLED_BIT;
1874 }
1875
1876 //
1877 // Get processor location information
1878 //
1879 GetProcessorLocationByApicId (
1880 CpuInfoInHob[ProcessorNumber].ApicId,
1881 &ProcessorInfoBuffer->Location.Package,
1882 &ProcessorInfoBuffer->Location.Core,
1883 &ProcessorInfoBuffer->Location.Thread
1884 );
1885
1886 if (HealthData != NULL) {
1887 HealthData->Uint32 = CpuInfoInHob[ProcessorNumber].Health;
1888 }
1889
1890 return EFI_SUCCESS;
1891 }
1892
1893 /**
1894 Worker function to switch the requested AP to be the BSP from that point onward.
1895
1896 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
1897 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
1898 enabled AP. Otherwise, it will be disabled.
1899
1900 @retval EFI_SUCCESS BSP successfully switched.
1901 @retval others Failed to switch BSP.
1902
1903 **/
1904 EFI_STATUS
1905 SwitchBSPWorker (
1906 IN UINTN ProcessorNumber,
1907 IN BOOLEAN EnableOldBSP
1908 )
1909 {
1910 CPU_MP_DATA *CpuMpData;
1911 UINTN CallerNumber;
1912 CPU_STATE State;
1913 MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
1914 BOOLEAN OldInterruptState;
1915 BOOLEAN OldTimerInterruptState;
1916
1917 //
1918 // Save and Disable Local APIC timer interrupt
1919 //
1920 OldTimerInterruptState = GetApicTimerInterruptState ();
1921 DisableApicTimerInterrupt ();
1922 //
1923 // Before send both BSP and AP to a procedure to exchange their roles,
1924 // interrupt must be disabled. This is because during the exchange role
1925 // process, 2 CPU may use 1 stack. If interrupt happens, the stack will
1926 // be corrupted, since interrupt return address will be pushed to stack
1927 // by hardware.
1928 //
1929 OldInterruptState = SaveAndDisableInterrupts ();
1930
1931 //
1932 // Mask LINT0 & LINT1 for the old BSP
1933 //
1934 DisableLvtInterrupts ();
1935
1936 CpuMpData = GetCpuMpData ();
1937
1938 //
1939 // Check whether caller processor is BSP
1940 //
1941 MpInitLibWhoAmI (&CallerNumber);
1942 if (CallerNumber != CpuMpData->BspNumber) {
1943 return EFI_DEVICE_ERROR;
1944 }
1945
1946 if (ProcessorNumber >= CpuMpData->CpuCount) {
1947 return EFI_NOT_FOUND;
1948 }
1949
1950 //
1951 // Check whether specified AP is disabled
1952 //
1953 State = GetApState (&CpuMpData->CpuData[ProcessorNumber]);
1954 if (State == CpuStateDisabled) {
1955 return EFI_INVALID_PARAMETER;
1956 }
1957
1958 //
1959 // Check whether ProcessorNumber specifies the current BSP
1960 //
1961 if (ProcessorNumber == CpuMpData->BspNumber) {
1962 return EFI_INVALID_PARAMETER;
1963 }
1964
1965 //
1966 // Check whether specified AP is busy
1967 //
1968 if (State == CpuStateBusy) {
1969 return EFI_NOT_READY;
1970 }
1971
1972 CpuMpData->BSPInfo.State = CPU_SWITCH_STATE_IDLE;
1973 CpuMpData->APInfo.State = CPU_SWITCH_STATE_IDLE;
1974 CpuMpData->SwitchBspFlag = TRUE;
1975 CpuMpData->NewBspNumber = ProcessorNumber;
1976
1977 //
1978 // Clear the BSP bit of MSR_IA32_APIC_BASE
1979 //
1980 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1981 ApicBaseMsr.Bits.BSP = 0;
1982 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1983
1984 //
1985 // Need to wakeUp AP (future BSP).
1986 //
1987 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, FutureBSPProc, CpuMpData, TRUE);
1988
1989 AsmExchangeRole (&CpuMpData->BSPInfo, &CpuMpData->APInfo);
1990
1991 //
1992 // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP
1993 //
1994 ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
1995 ApicBaseMsr.Bits.BSP = 1;
1996 AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
1997 ProgramVirtualWireMode ();
1998
1999 //
2000 // Wait for old BSP finished AP task
2001 //
2002 while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) {
2003 CpuPause ();
2004 }
2005
2006 CpuMpData->SwitchBspFlag = FALSE;
2007 //
2008 // Set old BSP enable state
2009 //
2010 if (!EnableOldBSP) {
2011 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateDisabled);
2012 } else {
2013 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateIdle);
2014 }
2015 //
2016 // Save new BSP number
2017 //
2018 CpuMpData->BspNumber = (UINT32) ProcessorNumber;
2019
2020 //
2021 // Restore interrupt state.
2022 //
2023 SetInterruptState (OldInterruptState);
2024
2025 if (OldTimerInterruptState) {
2026 EnableApicTimerInterrupt ();
2027 }
2028
2029 return EFI_SUCCESS;
2030 }
2031
2032 /**
2033 Worker function to let the caller enable or disable an AP from this point onward.
2034 This service may only be called from the BSP.
2035
2036 @param[in] ProcessorNumber The handle number of AP.
2037 @param[in] EnableAP Specifies the new state for the processor for
2038 enabled, FALSE for disabled.
2039 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
2040 the new health status of the AP.
2041
2042 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
2043 @retval others Failed to Enable/Disable AP.
2044
2045 **/
2046 EFI_STATUS
2047 EnableDisableApWorker (
2048 IN UINTN ProcessorNumber,
2049 IN BOOLEAN EnableAP,
2050 IN UINT32 *HealthFlag OPTIONAL
2051 )
2052 {
2053 CPU_MP_DATA *CpuMpData;
2054 UINTN CallerNumber;
2055
2056 CpuMpData = GetCpuMpData ();
2057
2058 //
2059 // Check whether caller processor is BSP
2060 //
2061 MpInitLibWhoAmI (&CallerNumber);
2062 if (CallerNumber != CpuMpData->BspNumber) {
2063 return EFI_DEVICE_ERROR;
2064 }
2065
2066 if (ProcessorNumber == CpuMpData->BspNumber) {
2067 return EFI_INVALID_PARAMETER;
2068 }
2069
2070 if (ProcessorNumber >= CpuMpData->CpuCount) {
2071 return EFI_NOT_FOUND;
2072 }
2073
2074 if (!EnableAP) {
2075 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateDisabled);
2076 } else {
2077 ResetProcessorToIdleState (ProcessorNumber);
2078 }
2079
2080 if (HealthFlag != NULL) {
2081 CpuMpData->CpuData[ProcessorNumber].CpuHealthy =
2082 (BOOLEAN) ((*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT) != 0);
2083 }
2084
2085 return EFI_SUCCESS;
2086 }
2087
2088 /**
2089 This return the handle number for the calling processor. This service may be
2090 called from the BSP and APs.
2091
2092 @param[out] ProcessorNumber Pointer to the handle number of AP.
2093 The range is from 0 to the total number of
2094 logical processors minus 1. The total number of
2095 logical processors can be retrieved by
2096 MpInitLibGetNumberOfProcessors().
2097
2098 @retval EFI_SUCCESS The current processor handle number was returned
2099 in ProcessorNumber.
2100 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
2101 @retval EFI_NOT_READY MP Initialize Library is not initialized.
2102
2103 **/
2104 EFI_STATUS
2105 EFIAPI
2106 MpInitLibWhoAmI (
2107 OUT UINTN *ProcessorNumber
2108 )
2109 {
2110 CPU_MP_DATA *CpuMpData;
2111
2112 if (ProcessorNumber == NULL) {
2113 return EFI_INVALID_PARAMETER;
2114 }
2115
2116 CpuMpData = GetCpuMpData ();
2117
2118 return GetProcessorNumber (CpuMpData, ProcessorNumber);
2119 }
2120
2121 /**
2122 Retrieves the number of logical processor in the platform and the number of
2123 those logical processors that are enabled on this boot. This service may only
2124 be called from the BSP.
2125
2126 @param[out] NumberOfProcessors Pointer to the total number of logical
2127 processors in the system, including the BSP
2128 and disabled APs.
2129 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
2130 processors that exist in system, including
2131 the BSP.
2132
2133 @retval EFI_SUCCESS The number of logical processors and enabled
2134 logical processors was retrieved.
2135 @retval EFI_DEVICE_ERROR The calling processor is an AP.
2136 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
2137 is NULL.
2138 @retval EFI_NOT_READY MP Initialize Library is not initialized.
2139
2140 **/
2141 EFI_STATUS
2142 EFIAPI
2143 MpInitLibGetNumberOfProcessors (
2144 OUT UINTN *NumberOfProcessors, OPTIONAL
2145 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
2146 )
2147 {
2148 CPU_MP_DATA *CpuMpData;
2149 UINTN CallerNumber;
2150 UINTN ProcessorNumber;
2151 UINTN EnabledProcessorNumber;
2152 UINTN Index;
2153
2154 CpuMpData = GetCpuMpData ();
2155
2156 if ((NumberOfProcessors == NULL) && (NumberOfEnabledProcessors == NULL)) {
2157 return EFI_INVALID_PARAMETER;
2158 }
2159
2160 //
2161 // Check whether caller processor is BSP
2162 //
2163 MpInitLibWhoAmI (&CallerNumber);
2164 if (CallerNumber != CpuMpData->BspNumber) {
2165 return EFI_DEVICE_ERROR;
2166 }
2167
2168 ProcessorNumber = CpuMpData->CpuCount;
2169 EnabledProcessorNumber = 0;
2170 for (Index = 0; Index < ProcessorNumber; Index++) {
2171 if (GetApState (&CpuMpData->CpuData[Index]) != CpuStateDisabled) {
2172 EnabledProcessorNumber ++;
2173 }
2174 }
2175
2176 if (NumberOfProcessors != NULL) {
2177 *NumberOfProcessors = ProcessorNumber;
2178 }
2179 if (NumberOfEnabledProcessors != NULL) {
2180 *NumberOfEnabledProcessors = EnabledProcessorNumber;
2181 }
2182
2183 return EFI_SUCCESS;
2184 }
2185
2186
2187 /**
2188 Worker function to execute a caller provided function on all enabled APs.
2189
2190 @param[in] Procedure A pointer to the function to be run on
2191 enabled APs of the system.
2192 @param[in] SingleThread If TRUE, then all the enabled APs execute
2193 the function specified by Procedure one by
2194 one, in ascending order of processor handle
2195 number. If FALSE, then all the enabled APs
2196 execute the function specified by Procedure
2197 simultaneously.
2198 @param[in] ExcludeBsp Whether let BSP also trig this task.
2199 @param[in] WaitEvent The event created by the caller with CreateEvent()
2200 service.
2201 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
2202 APs to return from Procedure, either for
2203 blocking or non-blocking mode.
2204 @param[in] ProcedureArgument The parameter passed into Procedure for
2205 all APs.
2206 @param[out] FailedCpuList If all APs finish successfully, then its
2207 content is set to NULL. If not all APs
2208 finish before timeout expires, then its
2209 content is set to address of the buffer
2210 holding handle numbers of the failed APs.
2211
2212 @retval EFI_SUCCESS In blocking mode, all APs have finished before
2213 the timeout expired.
2214 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
2215 to all enabled APs.
2216 @retval others Failed to Startup all APs.
2217
2218 **/
2219 EFI_STATUS
2220 StartupAllCPUsWorker (
2221 IN EFI_AP_PROCEDURE Procedure,
2222 IN BOOLEAN SingleThread,
2223 IN BOOLEAN ExcludeBsp,
2224 IN EFI_EVENT WaitEvent OPTIONAL,
2225 IN UINTN TimeoutInMicroseconds,
2226 IN VOID *ProcedureArgument OPTIONAL,
2227 OUT UINTN **FailedCpuList OPTIONAL
2228 )
2229 {
2230 EFI_STATUS Status;
2231 CPU_MP_DATA *CpuMpData;
2232 UINTN ProcessorCount;
2233 UINTN ProcessorNumber;
2234 UINTN CallerNumber;
2235 CPU_AP_DATA *CpuData;
2236 BOOLEAN HasEnabledAp;
2237 CPU_STATE ApState;
2238
2239 CpuMpData = GetCpuMpData ();
2240
2241 if (FailedCpuList != NULL) {
2242 *FailedCpuList = NULL;
2243 }
2244
2245 if (CpuMpData->CpuCount == 1 && ExcludeBsp) {
2246 return EFI_NOT_STARTED;
2247 }
2248
2249 if (Procedure == NULL) {
2250 return EFI_INVALID_PARAMETER;
2251 }
2252
2253 //
2254 // Check whether caller processor is BSP
2255 //
2256 MpInitLibWhoAmI (&CallerNumber);
2257 if (CallerNumber != CpuMpData->BspNumber) {
2258 return EFI_DEVICE_ERROR;
2259 }
2260
2261 //
2262 // Update AP state
2263 //
2264 CheckAndUpdateApsStatus ();
2265
2266 ProcessorCount = CpuMpData->CpuCount;
2267 HasEnabledAp = FALSE;
2268 //
2269 // Check whether all enabled APs are idle.
2270 // If any enabled AP is not idle, return EFI_NOT_READY.
2271 //
2272 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
2273 CpuData = &CpuMpData->CpuData[ProcessorNumber];
2274 if (ProcessorNumber != CpuMpData->BspNumber) {
2275 ApState = GetApState (CpuData);
2276 if (ApState != CpuStateDisabled) {
2277 HasEnabledAp = TRUE;
2278 if (ApState != CpuStateIdle) {
2279 //
2280 // If any enabled APs are busy, return EFI_NOT_READY.
2281 //
2282 return EFI_NOT_READY;
2283 }
2284 }
2285 }
2286 }
2287
2288 if (!HasEnabledAp && ExcludeBsp) {
2289 //
2290 // If no enabled AP exists and not include Bsp to do the procedure, return EFI_NOT_STARTED.
2291 //
2292 return EFI_NOT_STARTED;
2293 }
2294
2295 CpuMpData->RunningCount = 0;
2296 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
2297 CpuData = &CpuMpData->CpuData[ProcessorNumber];
2298 CpuData->Waiting = FALSE;
2299 if (ProcessorNumber != CpuMpData->BspNumber) {
2300 if (CpuData->State == CpuStateIdle) {
2301 //
2302 // Mark this processor as responsible for current calling.
2303 //
2304 CpuData->Waiting = TRUE;
2305 CpuMpData->RunningCount++;
2306 }
2307 }
2308 }
2309
2310 CpuMpData->Procedure = Procedure;
2311 CpuMpData->ProcArguments = ProcedureArgument;
2312 CpuMpData->SingleThread = SingleThread;
2313 CpuMpData->FinishedCount = 0;
2314 CpuMpData->FailedCpuList = FailedCpuList;
2315 CpuMpData->ExpectedTime = CalculateTimeout (
2316 TimeoutInMicroseconds,
2317 &CpuMpData->CurrentTime
2318 );
2319 CpuMpData->TotalTime = 0;
2320 CpuMpData->WaitEvent = WaitEvent;
2321
2322 if (!SingleThread) {
2323 WakeUpAP (CpuMpData, TRUE, 0, Procedure, ProcedureArgument, FALSE);
2324 } else {
2325 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
2326 if (ProcessorNumber == CallerNumber) {
2327 continue;
2328 }
2329 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
2330 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument, TRUE);
2331 break;
2332 }
2333 }
2334 }
2335
2336 if (!ExcludeBsp) {
2337 //
2338 // Start BSP.
2339 //
2340 Procedure (ProcedureArgument);
2341 }
2342
2343 Status = EFI_SUCCESS;
2344 if (WaitEvent == NULL) {
2345 do {
2346 Status = CheckAllAPs ();
2347 } while (Status == EFI_NOT_READY);
2348 }
2349
2350 return Status;
2351 }
2352
2353 /**
2354 Worker function to let the caller get one enabled AP to execute a caller-provided
2355 function.
2356
2357 @param[in] Procedure A pointer to the function to be run on
2358 enabled APs of the system.
2359 @param[in] ProcessorNumber The handle number of the AP.
2360 @param[in] WaitEvent The event created by the caller with CreateEvent()
2361 service.
2362 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
2363 APs to return from Procedure, either for
2364 blocking or non-blocking mode.
2365 @param[in] ProcedureArgument The parameter passed into Procedure for
2366 all APs.
2367 @param[out] Finished If AP returns from Procedure before the
2368 timeout expires, its content is set to TRUE.
2369 Otherwise, the value is set to FALSE.
2370
2371 @retval EFI_SUCCESS In blocking mode, specified AP finished before
2372 the timeout expires.
2373 @retval others Failed to Startup AP.
2374
2375 **/
2376 EFI_STATUS
2377 StartupThisAPWorker (
2378 IN EFI_AP_PROCEDURE Procedure,
2379 IN UINTN ProcessorNumber,
2380 IN EFI_EVENT WaitEvent OPTIONAL,
2381 IN UINTN TimeoutInMicroseconds,
2382 IN VOID *ProcedureArgument OPTIONAL,
2383 OUT BOOLEAN *Finished OPTIONAL
2384 )
2385 {
2386 EFI_STATUS Status;
2387 CPU_MP_DATA *CpuMpData;
2388 CPU_AP_DATA *CpuData;
2389 UINTN CallerNumber;
2390
2391 CpuMpData = GetCpuMpData ();
2392
2393 if (Finished != NULL) {
2394 *Finished = FALSE;
2395 }
2396
2397 //
2398 // Check whether caller processor is BSP
2399 //
2400 MpInitLibWhoAmI (&CallerNumber);
2401 if (CallerNumber != CpuMpData->BspNumber) {
2402 return EFI_DEVICE_ERROR;
2403 }
2404
2405 //
2406 // Check whether processor with the handle specified by ProcessorNumber exists
2407 //
2408 if (ProcessorNumber >= CpuMpData->CpuCount) {
2409 return EFI_NOT_FOUND;
2410 }
2411
2412 //
2413 // Check whether specified processor is BSP
2414 //
2415 if (ProcessorNumber == CpuMpData->BspNumber) {
2416 return EFI_INVALID_PARAMETER;
2417 }
2418
2419 //
2420 // Check parameter Procedure
2421 //
2422 if (Procedure == NULL) {
2423 return EFI_INVALID_PARAMETER;
2424 }
2425
2426 //
2427 // Update AP state
2428 //
2429 CheckAndUpdateApsStatus ();
2430
2431 //
2432 // Check whether specified AP is disabled
2433 //
2434 if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
2435 return EFI_INVALID_PARAMETER;
2436 }
2437
2438 //
2439 // If WaitEvent is not NULL, execute in non-blocking mode.
2440 // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
2441 // CheckAPsStatus() will check completion and timeout periodically.
2442 //
2443 CpuData = &CpuMpData->CpuData[ProcessorNumber];
2444 CpuData->WaitEvent = WaitEvent;
2445 CpuData->Finished = Finished;
2446 CpuData->ExpectedTime = CalculateTimeout (TimeoutInMicroseconds, &CpuData->CurrentTime);
2447 CpuData->TotalTime = 0;
2448
2449 WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument, TRUE);
2450
2451 //
2452 // If WaitEvent is NULL, execute in blocking mode.
2453 // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expires.
2454 //
2455 Status = EFI_SUCCESS;
2456 if (WaitEvent == NULL) {
2457 do {
2458 Status = CheckThisAP (ProcessorNumber);
2459 } while (Status == EFI_NOT_READY);
2460 }
2461
2462 return Status;
2463 }
2464
2465 /**
2466 Get pointer to CPU MP Data structure from GUIDed HOB.
2467
2468 @return The pointer to CPU MP Data structure.
2469 **/
2470 CPU_MP_DATA *
2471 GetCpuMpDataFromGuidedHob (
2472 VOID
2473 )
2474 {
2475 EFI_HOB_GUID_TYPE *GuidHob;
2476 VOID *DataInHob;
2477 CPU_MP_DATA *CpuMpData;
2478
2479 CpuMpData = NULL;
2480 GuidHob = GetFirstGuidHob (&mCpuInitMpLibHobGuid);
2481 if (GuidHob != NULL) {
2482 DataInHob = GET_GUID_HOB_DATA (GuidHob);
2483 CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
2484 }
2485 return CpuMpData;
2486 }
2487
2488 /**
2489 This service executes a caller provided function on all enabled CPUs.
2490
2491 @param[in] Procedure A pointer to the function to be run on
2492 enabled APs of the system. See type
2493 EFI_AP_PROCEDURE.
2494 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
2495 APs to return from Procedure, either for
2496 blocking or non-blocking mode. Zero means
2497 infinity. TimeoutInMicroseconds is ignored
2498 for BSP.
2499 @param[in] ProcedureArgument The parameter passed into Procedure for
2500 all APs.
2501
2502 @retval EFI_SUCCESS In blocking mode, all CPUs have finished before
2503 the timeout expired.
2504 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
2505 to all enabled CPUs.
2506 @retval EFI_DEVICE_ERROR Caller processor is AP.
2507 @retval EFI_NOT_READY Any enabled APs are busy.
2508 @retval EFI_NOT_READY MP Initialize Library is not initialized.
2509 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
2510 all enabled APs have finished.
2511 @retval EFI_INVALID_PARAMETER Procedure is NULL.
2512
2513 **/
2514 EFI_STATUS
2515 EFIAPI
2516 MpInitLibStartupAllCPUs (
2517 IN EFI_AP_PROCEDURE Procedure,
2518 IN UINTN TimeoutInMicroseconds,
2519 IN VOID *ProcedureArgument OPTIONAL
2520 )
2521 {
2522 return StartupAllCPUsWorker (
2523 Procedure,
2524 FALSE,
2525 FALSE,
2526 NULL,
2527 TimeoutInMicroseconds,
2528 ProcedureArgument,
2529 NULL
2530 );
2531 }