]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg/MpInitLib: Move two functions location
[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 25volatile BOOLEAN mStopCheckAllApsStatus = TRUE;\r
5183fb37 26VOID *mReservedApLoopFunc = NULL;\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
b31c1ad1 192 @return Protected mode code segment value.\r
4d3314f6
JF
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
5183fb37 261\r
4d3314f6
JF
262 CpuMpData = GetCpuMpData ();\r
263 CpuMpData->PmCodeSegment = GetProtectedModeCS ();\r
264 CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);\r
5183fb37 265 WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, mReservedApLoopFunc);\r
4d3314f6
JF
266 DEBUG ((DEBUG_INFO, "MpInitExitBootServicesCallback() done!\n"));\r
267}\r
268\r
93ca4c0f
JF
269/**\r
270 Initialize global data for MP support.\r
271\r
272 @param[in] CpuMpData The pointer to CPU MP Data structure.\r
273**/\r
274VOID\r
275InitMpGlobalData (\r
276 IN CPU_MP_DATA *CpuMpData\r
277 )\r
278{\r
96378861
JF
279 EFI_STATUS Status;\r
280\r
93ca4c0f
JF
281 SaveCpuMpData (CpuMpData);\r
282\r
5183fb37
JF
283 //\r
284 // Avoid APs access invalid buff data which allocated by BootServices,\r
285 // so we will allocate reserved data for AP loop code.\r
286 // Allocating it in advance since memory services are not available in\r
287 // Exit Boot Services callback function.\r
288 //\r
289 mReservedApLoopFunc = AllocateReservedCopyPool (\r
290 CpuMpData->AddressMap.RelocateApLoopFuncSize,\r
291 CpuMpData->AddressMap.RelocateApLoopFuncAddress\r
292 );\r
293 ASSERT (mReservedApLoopFunc != NULL);\r
294\r
96378861
JF
295 Status = gBS->CreateEvent (\r
296 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
297 TPL_NOTIFY,\r
298 CheckApsStatus,\r
299 NULL,\r
300 &mCheckAllApsEvent\r
301 );\r
302 ASSERT_EFI_ERROR (Status);\r
303\r
304 //\r
305 // Set timer to check all APs status.\r
306 //\r
307 Status = gBS->SetTimer (\r
308 mCheckAllApsEvent,\r
309 TimerPeriodic,\r
310 AP_CHECK_INTERVAL\r
311 );\r
312 ASSERT_EFI_ERROR (Status);\r
4d3314f6
JF
313 Status = gBS->CreateEvent (\r
314 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
315 TPL_CALLBACK,\r
316 MpInitExitBootServicesCallback,\r
317 NULL,\r
318 &mMpInitExitBootServicesEvent\r
319 );\r
320 ASSERT_EFI_ERROR (Status);\r
93ca4c0f 321}\r
3e8ad6bd
JF
322\r
323/**\r
324 This service executes a caller provided function on all enabled APs.\r
325\r
326 @param[in] Procedure A pointer to the function to be run on\r
327 enabled APs of the system. See type\r
328 EFI_AP_PROCEDURE.\r
329 @param[in] SingleThread If TRUE, then all the enabled APs execute\r
330 the function specified by Procedure one by\r
331 one, in ascending order of processor handle\r
332 number. If FALSE, then all the enabled APs\r
333 execute the function specified by Procedure\r
334 simultaneously.\r
335 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
336 service. If it is NULL, then execute in\r
337 blocking mode. BSP waits until all APs finish\r
338 or TimeoutInMicroSeconds expires. If it's\r
339 not NULL, then execute in non-blocking mode.\r
340 BSP requests the function specified by\r
341 Procedure to be started on all the enabled\r
342 APs, and go on executing immediately. If\r
343 all return from Procedure, or TimeoutInMicroSeconds\r
344 expires, this event is signaled. The BSP\r
345 can use the CheckEvent() or WaitForEvent()\r
346 services to check the state of event. Type\r
347 EFI_EVENT is defined in CreateEvent() in\r
348 the Unified Extensible Firmware Interface\r
349 Specification.\r
350 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r
351 APs to return from Procedure, either for\r
352 blocking or non-blocking mode. Zero means\r
353 infinity. If the timeout expires before\r
354 all APs return from Procedure, then Procedure\r
355 on the failed APs is terminated. All enabled\r
356 APs are available for next function assigned\r
357 by MpInitLibStartupAllAPs() or\r
358 MPInitLibStartupThisAP().\r
359 If the timeout expires in blocking mode,\r
360 BSP returns EFI_TIMEOUT. If the timeout\r
361 expires in non-blocking mode, WaitEvent\r
362 is signaled with SignalEvent().\r
363 @param[in] ProcedureArgument The parameter passed into Procedure for\r
364 all APs.\r
365 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r
366 if all APs finish successfully, then its\r
367 content is set to NULL. If not all APs\r
368 finish before timeout expires, then its\r
369 content is set to address of the buffer\r
370 holding handle numbers of the failed APs.\r
371 The buffer is allocated by MP Initialization\r
372 library, and it's the caller's responsibility to\r
373 free the buffer with FreePool() service.\r
374 In blocking mode, it is ready for consumption\r
375 when the call returns. In non-blocking mode,\r
376 it is ready when WaitEvent is signaled. The\r
377 list of failed CPU is terminated by\r
378 END_OF_CPU_LIST.\r
379\r
380 @retval EFI_SUCCESS In blocking mode, all APs have finished before\r
381 the timeout expired.\r
382 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r
383 to all enabled APs.\r
384 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
385 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
386 signaled.\r
387 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r
388 supported.\r
389 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
390 @retval EFI_NOT_STARTED No enabled APs exist in the system.\r
391 @retval EFI_NOT_READY Any enabled APs are busy.\r
392 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
393 @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
394 all enabled APs have finished.\r
395 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
396\r
397**/\r
398EFI_STATUS\r
399EFIAPI\r
400MpInitLibStartupAllAPs (\r
401 IN EFI_AP_PROCEDURE Procedure,\r
402 IN BOOLEAN SingleThread,\r
403 IN EFI_EVENT WaitEvent OPTIONAL,\r
404 IN UINTN TimeoutInMicroseconds,\r
405 IN VOID *ProcedureArgument OPTIONAL,\r
406 OUT UINTN **FailedCpuList OPTIONAL\r
407 )\r
408{\r
86efe976
JF
409 EFI_STATUS Status;\r
410\r
411 //\r
412 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.\r
413 //\r
414 mStopCheckAllApsStatus = TRUE;\r
415\r
416 Status = StartupAllAPsWorker (\r
417 Procedure,\r
418 SingleThread,\r
419 WaitEvent,\r
420 TimeoutInMicroseconds,\r
421 ProcedureArgument,\r
422 FailedCpuList\r
423 );\r
424\r
425 //\r
426 // Start checkAllApsStatus\r
427 //\r
428 mStopCheckAllApsStatus = FALSE;\r
429\r
430 return Status;\r
3e8ad6bd
JF
431}\r
432\r
433/**\r
434 This service lets the caller get one enabled AP to execute a caller-provided\r
435 function.\r
436\r
437 @param[in] Procedure A pointer to the function to be run on the\r
438 designated AP of the system. See type\r
439 EFI_AP_PROCEDURE.\r
440 @param[in] ProcessorNumber The handle number of the AP. The range is\r
441 from 0 to the total number of logical\r
442 processors minus 1. The total number of\r
443 logical processors can be retrieved by\r
444 MpInitLibGetNumberOfProcessors().\r
445 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
446 service. If it is NULL, then execute in\r
447 blocking mode. BSP waits until this AP finish\r
448 or TimeoutInMicroSeconds expires. If it's\r
449 not NULL, then execute in non-blocking mode.\r
450 BSP requests the function specified by\r
451 Procedure to be started on this AP,\r
452 and go on executing immediately. If this AP\r
453 return from Procedure or TimeoutInMicroSeconds\r
454 expires, this event is signaled. The BSP\r
455 can use the CheckEvent() or WaitForEvent()\r
456 services to check the state of event. Type\r
457 EFI_EVENT is defined in CreateEvent() in\r
458 the Unified Extensible Firmware Interface\r
459 Specification.\r
460 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r
461 this AP to finish this Procedure, either for\r
462 blocking or non-blocking mode. Zero means\r
463 infinity. If the timeout expires before\r
464 this AP returns from Procedure, then Procedure\r
465 on the AP is terminated. The\r
466 AP is available for next function assigned\r
467 by MpInitLibStartupAllAPs() or\r
468 MpInitLibStartupThisAP().\r
469 If the timeout expires in blocking mode,\r
470 BSP returns EFI_TIMEOUT. If the timeout\r
471 expires in non-blocking mode, WaitEvent\r
472 is signaled with SignalEvent().\r
473 @param[in] ProcedureArgument The parameter passed into Procedure on the\r
474 specified AP.\r
475 @param[out] Finished If NULL, this parameter is ignored. In\r
476 blocking mode, this parameter is ignored.\r
477 In non-blocking mode, if AP returns from\r
478 Procedure before the timeout expires, its\r
479 content is set to TRUE. Otherwise, the\r
480 value is set to FALSE. The caller can\r
481 determine if the AP returned from Procedure\r
482 by evaluating this value.\r
483\r
484 @retval EFI_SUCCESS In blocking mode, specified AP finished before\r
485 the timeout expires.\r
486 @retval EFI_SUCCESS In non-blocking mode, the function has been\r
487 dispatched to specified AP.\r
488 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
489 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
490 signaled.\r
491 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r
492 supported.\r
493 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
494 @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
495 the specified AP has finished.\r
496 @retval EFI_NOT_READY The specified AP is busy.\r
497 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
498 @retval EFI_NOT_FOUND The processor with the handle specified by\r
499 ProcessorNumber does not exist.\r
500 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
501 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
502\r
503**/\r
504EFI_STATUS\r
505EFIAPI\r
506MpInitLibStartupThisAP (\r
507 IN EFI_AP_PROCEDURE Procedure,\r
508 IN UINTN ProcessorNumber,\r
509 IN EFI_EVENT WaitEvent OPTIONAL,\r
510 IN UINTN TimeoutInMicroseconds,\r
511 IN VOID *ProcedureArgument OPTIONAL,\r
512 OUT BOOLEAN *Finished OPTIONAL\r
513 )\r
514{\r
20ae5774
JF
515 EFI_STATUS Status;\r
516\r
517 //\r
518 // temporarily stop checkAllApsStatus for avoid resource dead-lock.\r
519 //\r
520 mStopCheckAllApsStatus = TRUE;\r
521\r
522 Status = StartupThisAPWorker (\r
523 Procedure,\r
524 ProcessorNumber,\r
525 WaitEvent,\r
526 TimeoutInMicroseconds,\r
527 ProcedureArgument,\r
528 Finished\r
529 );\r
530\r
531 mStopCheckAllApsStatus = FALSE;\r
532\r
533 return Status;\r
3e8ad6bd
JF
534}\r
535\r
536/**\r
537 This service switches the requested AP to be the BSP from that point onward.\r
538 This service changes the BSP for all purposes. This call can only be performed\r
539 by the current BSP.\r
540\r
541 @param[in] ProcessorNumber The handle number of AP that is to become the new\r
542 BSP. The range is from 0 to the total number of\r
543 logical processors minus 1. The total number of\r
544 logical processors can be retrieved by\r
545 MpInitLibGetNumberOfProcessors().\r
546 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r
547 enabled AP. Otherwise, it will be disabled.\r
548\r
549 @retval EFI_SUCCESS BSP successfully switched.\r
550 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r
551 this service returning.\r
552 @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r
553 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
554 @retval EFI_NOT_FOUND The processor with the handle specified by\r
555 ProcessorNumber does not exist.\r
556 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r
557 a disabled AP.\r
558 @retval EFI_NOT_READY The specified AP is busy.\r
559 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
560\r
561**/\r
562EFI_STATUS\r
563EFIAPI\r
564MpInitLibSwitchBSP (\r
565 IN UINTN ProcessorNumber,\r
566 IN BOOLEAN EnableOldBSP\r
567 )\r
568{\r
41be0da5
JF
569 EFI_STATUS Status;\r
570 BOOLEAN OldInterruptState;\r
571\r
572 //\r
573 // Before send both BSP and AP to a procedure to exchange their roles,\r
574 // interrupt must be disabled. This is because during the exchange role\r
575 // process, 2 CPU may use 1 stack. If interrupt happens, the stack will\r
576 // be corrupted, since interrupt return address will be pushed to stack\r
577 // by hardware.\r
578 //\r
579 OldInterruptState = SaveAndDisableInterrupts ();\r
580\r
581 //\r
582 // Mask LINT0 & LINT1 for the old BSP\r
583 //\r
584 DisableLvtInterrupts ();\r
585\r
586 Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);\r
587\r
588 //\r
589 // Restore interrupt state.\r
590 //\r
591 SetInterruptState (OldInterruptState);\r
592\r
593 return Status;\r
3e8ad6bd
JF
594}\r
595\r
596/**\r
597 This service lets the caller enable or disable an AP from this point onward.\r
598 This service may only be called from the BSP.\r
599\r
600 @param[in] ProcessorNumber The handle number of AP.\r
601 The range is from 0 to the total number of\r
602 logical processors minus 1. The total number of\r
603 logical processors can be retrieved by\r
604 MpInitLibGetNumberOfProcessors().\r
605 @param[in] EnableAP Specifies the new state for the processor for\r
606 enabled, FALSE for disabled.\r
607 @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r
608 the new health status of the AP. This flag\r
609 corresponds to StatusFlag defined in\r
610 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r
611 the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r
612 bits are ignored. If it is NULL, this parameter\r
613 is ignored.\r
614\r
615 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r
616 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r
617 prior to this service returning.\r
618 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r
619 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
620 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r
621 does not exist.\r
622 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r
623 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
624\r
625**/\r
626EFI_STATUS\r
627EFIAPI\r
628MpInitLibEnableDisableAP (\r
629 IN UINTN ProcessorNumber,\r
630 IN BOOLEAN EnableAP,\r
631 IN UINT32 *HealthFlag OPTIONAL\r
632 )\r
633{\r
e37109bc
JF
634 EFI_STATUS Status;\r
635 BOOLEAN TempStopCheckState;\r
636\r
637 TempStopCheckState = FALSE;\r
638 //\r
639 // temporarily stop checkAllAPsStatus for initialize parameters.\r
640 //\r
641 if (!mStopCheckAllApsStatus) {\r
642 mStopCheckAllApsStatus = TRUE;\r
643 TempStopCheckState = TRUE;\r
644 }\r
645\r
646 Status = EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);\r
647\r
648 if (TempStopCheckState) {\r
649 mStopCheckAllApsStatus = FALSE;\r
650 }\r
651\r
652 return Status;\r
3e8ad6bd 653}\r