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