]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
56b776d3d81631b56e45d3b90f9412c5efae2ebb
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / DxeMpLib.c
1 /** @file
2 MP initialize support functions for DXE phase.
3
4 Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "MpLib.h"
10
11 #include <Library/UefiLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/DebugAgentLib.h>
14 #include <Library/DxeServicesTableLib.h>
15
16 #include <Protocol/Timer.h>
17
18 #define AP_SAFE_STACK_SIZE 128
19
20 CPU_MP_DATA *mCpuMpData = NULL;
21 EFI_EVENT mCheckAllApsEvent = NULL;
22 EFI_EVENT mMpInitExitBootServicesEvent = NULL;
23 EFI_EVENT mLegacyBootEvent = NULL;
24 volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
25 VOID *mReservedApLoopFunc = NULL;
26 UINTN mReservedTopOfApStack;
27 volatile UINT32 mNumberToFinish = 0;
28
29 /**
30 Enable Debug Agent to support source debugging on AP function.
31
32 **/
33 VOID
34 EnableDebugAgent (
35 VOID
36 )
37 {
38 //
39 // Initialize Debug Agent to support source level debug in DXE phase
40 //
41 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP, NULL, NULL);
42 }
43
44 /**
45 Get the pointer to CPU MP Data structure.
46
47 @return The pointer to CPU MP Data structure.
48 **/
49 CPU_MP_DATA *
50 GetCpuMpData (
51 VOID
52 )
53 {
54 ASSERT (mCpuMpData != NULL);
55 return mCpuMpData;
56 }
57
58 /**
59 Save the pointer to CPU MP Data structure.
60
61 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
62 **/
63 VOID
64 SaveCpuMpData (
65 IN CPU_MP_DATA *CpuMpData
66 )
67 {
68 mCpuMpData = CpuMpData;
69 }
70
71 /**
72 Get available system memory below 0x88000 by specified size.
73
74 @param[in] WakeupBufferSize Wakeup buffer size required
75
76 @retval other Return wakeup buffer address below 1MB.
77 @retval -1 Cannot find free memory below 1MB.
78 **/
79 UINTN
80 GetWakeupBuffer (
81 IN UINTN WakeupBufferSize
82 )
83 {
84 EFI_STATUS Status;
85 EFI_PHYSICAL_ADDRESS StartAddress;
86
87 //
88 // Try to allocate buffer below 1M for waking vector.
89 // LegacyBios driver only reports warning when page allocation in range
90 // [0x60000, 0x88000) fails.
91 // This library is consumed by CpuDxe driver to produce CPU Arch protocol.
92 // LagacyBios driver depends on CPU Arch protocol which guarantees below
93 // allocation runs earlier than LegacyBios driver.
94 //
95 StartAddress = 0x88000;
96 Status = gBS->AllocatePages (
97 AllocateMaxAddress,
98 EfiBootServicesData,
99 EFI_SIZE_TO_PAGES (WakeupBufferSize),
100 &StartAddress
101 );
102 ASSERT_EFI_ERROR (Status);
103 if (EFI_ERROR (Status)) {
104 StartAddress = (EFI_PHYSICAL_ADDRESS) -1;
105 }
106
107 DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
108 (UINTN) StartAddress, WakeupBufferSize));
109
110 return (UINTN) StartAddress;
111 }
112
113 /**
114 Get available EfiBootServicesCode memory below 4GB by specified size.
115
116 This buffer is required to safely transfer AP from real address mode to
117 protected mode or long mode, due to the fact that the buffer returned by
118 GetWakeupBuffer() may be marked as non-executable.
119
120 @param[in] BufferSize Wakeup transition buffer size.
121
122 @retval other Return wakeup transition buffer address below 4GB.
123 @retval 0 Cannot find free memory below 4GB.
124 **/
125 UINTN
126 GetModeTransitionBuffer (
127 IN UINTN BufferSize
128 )
129 {
130 EFI_STATUS Status;
131 EFI_PHYSICAL_ADDRESS StartAddress;
132
133 StartAddress = BASE_4GB - 1;
134 Status = gBS->AllocatePages (
135 AllocateMaxAddress,
136 EfiBootServicesCode,
137 EFI_SIZE_TO_PAGES (BufferSize),
138 &StartAddress
139 );
140 if (EFI_ERROR (Status)) {
141 StartAddress = 0;
142 }
143
144 return (UINTN)StartAddress;
145 }
146
147 /**
148 Checks APs status and updates APs status if needed.
149
150 **/
151 VOID
152 CheckAndUpdateApsStatus (
153 VOID
154 )
155 {
156 UINTN ProcessorNumber;
157 EFI_STATUS Status;
158 CPU_MP_DATA *CpuMpData;
159
160 CpuMpData = GetCpuMpData ();
161
162 //
163 // First, check whether pending StartupAllAPs() exists.
164 //
165 if (CpuMpData->WaitEvent != NULL) {
166
167 Status = CheckAllAPs ();
168 //
169 // If all APs finish for StartupAllAPs(), signal the WaitEvent for it.
170 //
171 if (Status != EFI_NOT_READY) {
172 Status = gBS->SignalEvent (CpuMpData->WaitEvent);
173 CpuMpData->WaitEvent = NULL;
174 }
175 }
176
177 //
178 // Second, check whether pending StartupThisAPs() callings exist.
179 //
180 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
181
182 if (CpuMpData->CpuData[ProcessorNumber].WaitEvent == NULL) {
183 continue;
184 }
185
186 Status = CheckThisAP (ProcessorNumber);
187
188 if (Status != EFI_NOT_READY) {
189 gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent);
190 CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;
191 }
192 }
193 }
194
195 /**
196 Checks APs' status periodically.
197
198 This function is triggered by timer periodically to check the
199 state of APs for StartupAllAPs() and StartupThisAP() executed
200 in non-blocking mode.
201
202 @param[in] Event Event triggered.
203 @param[in] Context Parameter passed with the event.
204
205 **/
206 VOID
207 EFIAPI
208 CheckApsStatus (
209 IN EFI_EVENT Event,
210 IN VOID *Context
211 )
212 {
213 //
214 // If CheckApsStatus() is not stopped, otherwise return immediately.
215 //
216 if (!mStopCheckAllApsStatus) {
217 CheckAndUpdateApsStatus ();
218 }
219 }
220
221 /**
222 Get Protected mode code segment from current GDT table.
223
224 @return Protected mode code segment value.
225 **/
226 UINT16
227 GetProtectedModeCS (
228 VOID
229 )
230 {
231 IA32_DESCRIPTOR GdtrDesc;
232 IA32_SEGMENT_DESCRIPTOR *GdtEntry;
233 UINTN GdtEntryCount;
234 UINT16 Index;
235
236 AsmReadGdtr (&GdtrDesc);
237 GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);
238 GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;
239 for (Index = 0; Index < GdtEntryCount; Index++) {
240 if (GdtEntry->Bits.L == 0) {
241 if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L == 0) {
242 break;
243 }
244 }
245 GdtEntry++;
246 }
247 ASSERT (Index != GdtEntryCount);
248 return Index * 8;
249 }
250
251 /**
252 Do sync on APs.
253
254 @param[in, out] Buffer Pointer to private data buffer.
255 **/
256 VOID
257 EFIAPI
258 RelocateApLoop (
259 IN OUT VOID *Buffer
260 )
261 {
262 CPU_MP_DATA *CpuMpData;
263 BOOLEAN MwaitSupport;
264 ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
265 UINTN ProcessorNumber;
266
267 MpInitLibWhoAmI (&ProcessorNumber);
268 CpuMpData = GetCpuMpData ();
269 MwaitSupport = IsMwaitSupport ();
270 AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;
271 AsmRelocateApLoopFunc (
272 MwaitSupport,
273 CpuMpData->ApTargetCState,
274 CpuMpData->PmCodeSegment,
275 mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE,
276 (UINTN) &mNumberToFinish
277 );
278 //
279 // It should never reach here
280 //
281 ASSERT (FALSE);
282 }
283
284 /**
285 Callback function for ExitBootServices.
286
287 @param[in] Event Event whose notification function is being invoked.
288 @param[in] Context The pointer to the notification function's context,
289 which is implementation-dependent.
290
291 **/
292 VOID
293 EFIAPI
294 MpInitChangeApLoopCallback (
295 IN EFI_EVENT Event,
296 IN VOID *Context
297 )
298 {
299 CPU_MP_DATA *CpuMpData;
300
301 CpuMpData = GetCpuMpData ();
302 CpuMpData->PmCodeSegment = GetProtectedModeCS ();
303 CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
304 mNumberToFinish = CpuMpData->CpuCount - 1;
305 WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
306 while (mNumberToFinish > 0) {
307 CpuPause ();
308 }
309 DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__));
310 }
311
312 /**
313 Initialize global data for MP support.
314
315 @param[in] CpuMpData The pointer to CPU MP Data structure.
316 **/
317 VOID
318 InitMpGlobalData (
319 IN CPU_MP_DATA *CpuMpData
320 )
321 {
322 EFI_STATUS Status;
323 EFI_PHYSICAL_ADDRESS Address;
324 UINTN ApSafeBufferSize;
325 UINTN Index;
326 EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
327 UINTN StackBase;
328 CPU_INFO_IN_HOB *CpuInfoInHob;
329
330 SaveCpuMpData (CpuMpData);
331
332 if (CpuMpData->CpuCount == 1) {
333 //
334 // If only BSP exists, return
335 //
336 return;
337 }
338
339 if (PcdGetBool (PcdCpuStackGuard)) {
340 //
341 // One extra page at the bottom of the stack is needed for Guard page.
342 //
343 if (CpuMpData->CpuApStackSize <= EFI_PAGE_SIZE) {
344 DEBUG ((DEBUG_ERROR, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));
345 ASSERT (FALSE);
346 }
347
348 //
349 // DXE will reuse stack allocated for APs at PEI phase if it's available.
350 // Let's check it here.
351 //
352 // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of
353 // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be
354 // set here.
355 //
356 CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
357 for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
358 if (CpuInfoInHob != NULL && CpuInfoInHob[Index].ApTopOfStack != 0) {
359 StackBase = (UINTN)CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize;
360 } else {
361 StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;
362 }
363
364 Status = gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);
365 ASSERT_EFI_ERROR (Status);
366
367 Status = gDS->SetMemorySpaceAttributes (
368 StackBase,
369 EFI_PAGES_TO_SIZE (1),
370 MemDesc.Attributes | EFI_MEMORY_RP
371 );
372 ASSERT_EFI_ERROR (Status);
373
374 DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
375 (UINT64)StackBase, (UINT64)Index));
376 }
377 }
378
379 //
380 // Avoid APs access invalid buffer data which allocated by BootServices,
381 // so we will allocate reserved data for AP loop code. We also need to
382 // allocate this buffer below 4GB due to APs may be transferred to 32bit
383 // protected mode on long mode DXE.
384 // Allocating it in advance since memory services are not available in
385 // Exit Boot Services callback function.
386 //
387 ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
388 CpuMpData->AddressMap.RelocateApLoopFuncSize
389 ));
390 Address = BASE_4GB - 1;
391 Status = gBS->AllocatePages (
392 AllocateMaxAddress,
393 EfiReservedMemoryType,
394 EFI_SIZE_TO_PAGES (ApSafeBufferSize),
395 &Address
396 );
397 ASSERT_EFI_ERROR (Status);
398
399 mReservedApLoopFunc = (VOID *) (UINTN) Address;
400 ASSERT (mReservedApLoopFunc != NULL);
401
402 //
403 // Make sure that the buffer memory is executable if NX protection is enabled
404 // for EfiReservedMemoryType.
405 //
406 // TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD
407 // service.
408 //
409 Status = gDS->GetMemorySpaceDescriptor (Address, &MemDesc);
410 if (!EFI_ERROR (Status)) {
411 gDS->SetMemorySpaceAttributes (
412 Address,
413 ApSafeBufferSize,
414 MemDesc.Attributes & (~EFI_MEMORY_XP)
415 );
416 }
417
418 ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
419 CpuMpData->CpuCount * AP_SAFE_STACK_SIZE
420 ));
421 Address = BASE_4GB - 1;
422 Status = gBS->AllocatePages (
423 AllocateMaxAddress,
424 EfiReservedMemoryType,
425 EFI_SIZE_TO_PAGES (ApSafeBufferSize),
426 &Address
427 );
428 ASSERT_EFI_ERROR (Status);
429
430 mReservedTopOfApStack = (UINTN) Address + ApSafeBufferSize;
431 ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);
432 CopyMem (
433 mReservedApLoopFunc,
434 CpuMpData->AddressMap.RelocateApLoopFuncAddress,
435 CpuMpData->AddressMap.RelocateApLoopFuncSize
436 );
437
438 Status = gBS->CreateEvent (
439 EVT_TIMER | EVT_NOTIFY_SIGNAL,
440 TPL_NOTIFY,
441 CheckApsStatus,
442 NULL,
443 &mCheckAllApsEvent
444 );
445 ASSERT_EFI_ERROR (Status);
446
447 //
448 // Set timer to check all APs status.
449 //
450 Status = gBS->SetTimer (
451 mCheckAllApsEvent,
452 TimerPeriodic,
453 EFI_TIMER_PERIOD_MICROSECONDS (
454 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds)
455 )
456 );
457 ASSERT_EFI_ERROR (Status);
458
459 Status = gBS->CreateEvent (
460 EVT_SIGNAL_EXIT_BOOT_SERVICES,
461 TPL_CALLBACK,
462 MpInitChangeApLoopCallback,
463 NULL,
464 &mMpInitExitBootServicesEvent
465 );
466 ASSERT_EFI_ERROR (Status);
467
468 Status = gBS->CreateEventEx (
469 EVT_NOTIFY_SIGNAL,
470 TPL_CALLBACK,
471 MpInitChangeApLoopCallback,
472 NULL,
473 &gEfiEventLegacyBootGuid,
474 &mLegacyBootEvent
475 );
476 ASSERT_EFI_ERROR (Status);
477 }
478
479 /**
480 This service executes a caller provided function on all enabled APs.
481
482 @param[in] Procedure A pointer to the function to be run on
483 enabled APs of the system. See type
484 EFI_AP_PROCEDURE.
485 @param[in] SingleThread If TRUE, then all the enabled APs execute
486 the function specified by Procedure one by
487 one, in ascending order of processor handle
488 number. If FALSE, then all the enabled APs
489 execute the function specified by Procedure
490 simultaneously.
491 @param[in] WaitEvent The event created by the caller with CreateEvent()
492 service. If it is NULL, then execute in
493 blocking mode. BSP waits until all APs finish
494 or TimeoutInMicroSeconds expires. If it's
495 not NULL, then execute in non-blocking mode.
496 BSP requests the function specified by
497 Procedure to be started on all the enabled
498 APs, and go on executing immediately. If
499 all return from Procedure, or TimeoutInMicroSeconds
500 expires, this event is signaled. The BSP
501 can use the CheckEvent() or WaitForEvent()
502 services to check the state of event. Type
503 EFI_EVENT is defined in CreateEvent() in
504 the Unified Extensible Firmware Interface
505 Specification.
506 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
507 APs to return from Procedure, either for
508 blocking or non-blocking mode. Zero means
509 infinity. If the timeout expires before
510 all APs return from Procedure, then Procedure
511 on the failed APs is terminated. All enabled
512 APs are available for next function assigned
513 by MpInitLibStartupAllAPs() or
514 MPInitLibStartupThisAP().
515 If the timeout expires in blocking mode,
516 BSP returns EFI_TIMEOUT. If the timeout
517 expires in non-blocking mode, WaitEvent
518 is signaled with SignalEvent().
519 @param[in] ProcedureArgument The parameter passed into Procedure for
520 all APs.
521 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
522 if all APs finish successfully, then its
523 content is set to NULL. If not all APs
524 finish before timeout expires, then its
525 content is set to address of the buffer
526 holding handle numbers of the failed APs.
527 The buffer is allocated by MP Initialization
528 library, and it's the caller's responsibility to
529 free the buffer with FreePool() service.
530 In blocking mode, it is ready for consumption
531 when the call returns. In non-blocking mode,
532 it is ready when WaitEvent is signaled. The
533 list of failed CPU is terminated by
534 END_OF_CPU_LIST.
535
536 @retval EFI_SUCCESS In blocking mode, all APs have finished before
537 the timeout expired.
538 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
539 to all enabled APs.
540 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
541 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
542 signaled.
543 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
544 supported.
545 @retval EFI_DEVICE_ERROR Caller processor is AP.
546 @retval EFI_NOT_STARTED No enabled APs exist in the system.
547 @retval EFI_NOT_READY Any enabled APs are busy.
548 @retval EFI_NOT_READY MP Initialize Library is not initialized.
549 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
550 all enabled APs have finished.
551 @retval EFI_INVALID_PARAMETER Procedure is NULL.
552
553 **/
554 EFI_STATUS
555 EFIAPI
556 MpInitLibStartupAllAPs (
557 IN EFI_AP_PROCEDURE Procedure,
558 IN BOOLEAN SingleThread,
559 IN EFI_EVENT WaitEvent OPTIONAL,
560 IN UINTN TimeoutInMicroseconds,
561 IN VOID *ProcedureArgument OPTIONAL,
562 OUT UINTN **FailedCpuList OPTIONAL
563 )
564 {
565 EFI_STATUS Status;
566
567 //
568 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.
569 //
570 mStopCheckAllApsStatus = TRUE;
571
572 Status = StartupAllCPUsWorker (
573 Procedure,
574 SingleThread,
575 TRUE,
576 WaitEvent,
577 TimeoutInMicroseconds,
578 ProcedureArgument,
579 FailedCpuList
580 );
581
582 //
583 // Start checkAllApsStatus
584 //
585 mStopCheckAllApsStatus = FALSE;
586
587 return Status;
588 }
589
590 /**
591 This service lets the caller get one enabled AP to execute a caller-provided
592 function.
593
594 @param[in] Procedure A pointer to the function to be run on the
595 designated AP of the system. See type
596 EFI_AP_PROCEDURE.
597 @param[in] ProcessorNumber The handle number of the AP. The range is
598 from 0 to the total number of logical
599 processors minus 1. The total number of
600 logical processors can be retrieved by
601 MpInitLibGetNumberOfProcessors().
602 @param[in] WaitEvent The event created by the caller with CreateEvent()
603 service. If it is NULL, then execute in
604 blocking mode. BSP waits until this AP finish
605 or TimeoutInMicroSeconds expires. If it's
606 not NULL, then execute in non-blocking mode.
607 BSP requests the function specified by
608 Procedure to be started on this AP,
609 and go on executing immediately. If this AP
610 return from Procedure or TimeoutInMicroSeconds
611 expires, this event is signaled. The BSP
612 can use the CheckEvent() or WaitForEvent()
613 services to check the state of event. Type
614 EFI_EVENT is defined in CreateEvent() in
615 the Unified Extensible Firmware Interface
616 Specification.
617 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
618 this AP to finish this Procedure, either for
619 blocking or non-blocking mode. Zero means
620 infinity. If the timeout expires before
621 this AP returns from Procedure, then Procedure
622 on the AP is terminated. The
623 AP is available for next function assigned
624 by MpInitLibStartupAllAPs() or
625 MpInitLibStartupThisAP().
626 If the timeout expires in blocking mode,
627 BSP returns EFI_TIMEOUT. If the timeout
628 expires in non-blocking mode, WaitEvent
629 is signaled with SignalEvent().
630 @param[in] ProcedureArgument The parameter passed into Procedure on the
631 specified AP.
632 @param[out] Finished If NULL, this parameter is ignored. In
633 blocking mode, this parameter is ignored.
634 In non-blocking mode, if AP returns from
635 Procedure before the timeout expires, its
636 content is set to TRUE. Otherwise, the
637 value is set to FALSE. The caller can
638 determine if the AP returned from Procedure
639 by evaluating this value.
640
641 @retval EFI_SUCCESS In blocking mode, specified AP finished before
642 the timeout expires.
643 @retval EFI_SUCCESS In non-blocking mode, the function has been
644 dispatched to specified AP.
645 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
646 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
647 signaled.
648 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
649 supported.
650 @retval EFI_DEVICE_ERROR The calling processor is an AP.
651 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
652 the specified AP has finished.
653 @retval EFI_NOT_READY The specified AP is busy.
654 @retval EFI_NOT_READY MP Initialize Library is not initialized.
655 @retval EFI_NOT_FOUND The processor with the handle specified by
656 ProcessorNumber does not exist.
657 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
658 @retval EFI_INVALID_PARAMETER Procedure is NULL.
659
660 **/
661 EFI_STATUS
662 EFIAPI
663 MpInitLibStartupThisAP (
664 IN EFI_AP_PROCEDURE Procedure,
665 IN UINTN ProcessorNumber,
666 IN EFI_EVENT WaitEvent OPTIONAL,
667 IN UINTN TimeoutInMicroseconds,
668 IN VOID *ProcedureArgument OPTIONAL,
669 OUT BOOLEAN *Finished OPTIONAL
670 )
671 {
672 EFI_STATUS Status;
673
674 //
675 // temporarily stop checkAllApsStatus for avoid resource dead-lock.
676 //
677 mStopCheckAllApsStatus = TRUE;
678
679 Status = StartupThisAPWorker (
680 Procedure,
681 ProcessorNumber,
682 WaitEvent,
683 TimeoutInMicroseconds,
684 ProcedureArgument,
685 Finished
686 );
687
688 mStopCheckAllApsStatus = FALSE;
689
690 return Status;
691 }
692
693 /**
694 This service switches the requested AP to be the BSP from that point onward.
695 This service changes the BSP for all purposes. This call can only be performed
696 by the current BSP.
697
698 @param[in] ProcessorNumber The handle number of AP that is to become the new
699 BSP. The range is from 0 to the total number of
700 logical processors minus 1. The total number of
701 logical processors can be retrieved by
702 MpInitLibGetNumberOfProcessors().
703 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
704 enabled AP. Otherwise, it will be disabled.
705
706 @retval EFI_SUCCESS BSP successfully switched.
707 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
708 this service returning.
709 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
710 @retval EFI_DEVICE_ERROR The calling processor is an AP.
711 @retval EFI_NOT_FOUND The processor with the handle specified by
712 ProcessorNumber does not exist.
713 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
714 a disabled AP.
715 @retval EFI_NOT_READY The specified AP is busy.
716 @retval EFI_NOT_READY MP Initialize Library is not initialized.
717
718 **/
719 EFI_STATUS
720 EFIAPI
721 MpInitLibSwitchBSP (
722 IN UINTN ProcessorNumber,
723 IN BOOLEAN EnableOldBSP
724 )
725 {
726 EFI_STATUS Status;
727 EFI_TIMER_ARCH_PROTOCOL *Timer;
728 UINT64 TimerPeriod;
729
730 TimerPeriod = 0;
731 //
732 // Locate Timer Arch Protocol
733 //
734 Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Timer);
735 if (EFI_ERROR (Status)) {
736 Timer = NULL;
737 }
738
739 if (Timer != NULL) {
740 //
741 // Save current rate of DXE Timer
742 //
743 Timer->GetTimerPeriod (Timer, &TimerPeriod);
744 //
745 // Disable DXE Timer and drain pending interrupts
746 //
747 Timer->SetTimerPeriod (Timer, 0);
748 }
749
750 Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);
751
752 if (Timer != NULL) {
753 //
754 // Enable and restore rate of DXE Timer
755 //
756 Timer->SetTimerPeriod (Timer, TimerPeriod);
757 }
758
759 return Status;
760 }
761
762 /**
763 This service lets the caller enable or disable an AP from this point onward.
764 This service may only be called from the BSP.
765
766 @param[in] ProcessorNumber The handle number of AP.
767 The range is from 0 to the total number of
768 logical processors minus 1. The total number of
769 logical processors can be retrieved by
770 MpInitLibGetNumberOfProcessors().
771 @param[in] EnableAP Specifies the new state for the processor for
772 enabled, FALSE for disabled.
773 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
774 the new health status of the AP. This flag
775 corresponds to StatusFlag defined in
776 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
777 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
778 bits are ignored. If it is NULL, this parameter
779 is ignored.
780
781 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
782 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
783 prior to this service returning.
784 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
785 @retval EFI_DEVICE_ERROR The calling processor is an AP.
786 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
787 does not exist.
788 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
789 @retval EFI_NOT_READY MP Initialize Library is not initialized.
790
791 **/
792 EFI_STATUS
793 EFIAPI
794 MpInitLibEnableDisableAP (
795 IN UINTN ProcessorNumber,
796 IN BOOLEAN EnableAP,
797 IN UINT32 *HealthFlag OPTIONAL
798 )
799 {
800 EFI_STATUS Status;
801 BOOLEAN TempStopCheckState;
802
803 TempStopCheckState = FALSE;
804 //
805 // temporarily stop checkAllAPsStatus for initialize parameters.
806 //
807 if (!mStopCheckAllApsStatus) {
808 mStopCheckAllApsStatus = TRUE;
809 TempStopCheckState = TRUE;
810 }
811
812 Status = EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);
813
814 if (TempStopCheckState) {
815 mStopCheckAllApsStatus = FALSE;
816 }
817
818 return Status;
819 }
820
821 /**
822 This funtion will try to invoke platform specific microcode shadow logic to
823 relocate microcode update patches into memory.
824
825 @param[in] CpuMpData The pointer to CPU MP Data structure.
826
827 @retval EFI_SUCCESS Shadow microcode success.
828 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
829 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
830 PPI/Protocol.
831 **/
832 EFI_STATUS
833 PlatformShadowMicrocode (
834 IN OUT CPU_MP_DATA *CpuMpData
835 )
836 {
837 //
838 // There is no DXE version of platform shadow microcode protocol so far.
839 // A platform which only uses DxeMpInitLib instance could only supports
840 // the PCD based microcode shadowing.
841 //
842 return EFI_UNSUPPORTED;
843 }