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