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