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