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