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