]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg/MpInitLib: Add out attribute for parameter.
[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
c788c2b1 4 Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
3e8ad6bd
JF
6\r
7**/\r
8\r
9#include "MpLib.h"\r
96378861
JF
10\r
11#include <Library/UefiLib.h>\r
12#include <Library/UefiBootServicesTableLib.h>\r
43c9fdcc 13#include <Library/DebugAgentLib.h>\r
15720a6c 14#include <Library/DxeServicesTableLib.h>\r
96378861 15\r
b6e45716
JF
16#include <Protocol/Timer.h>\r
17\r
bf2786dc 18#define AP_SAFE_STACK_SIZE 128\r
96378861 19\r
93ca4c0f 20CPU_MP_DATA *mCpuMpData = NULL;\r
96378861 21EFI_EVENT mCheckAllApsEvent = NULL;\r
4d3314f6 22EFI_EVENT mMpInitExitBootServicesEvent = NULL;\r
8677a56a 23EFI_EVENT mLegacyBootEvent = NULL;\r
96378861 24volatile BOOLEAN mStopCheckAllApsStatus = TRUE;\r
5183fb37 25VOID *mReservedApLoopFunc = NULL;\r
bf2786dc 26UINTN mReservedTopOfApStack;\r
9f91cb01 27volatile UINT32 mNumberToFinish = 0;\r
93ca4c0f 28\r
43c9fdcc
JF
29/**\r
30 Enable Debug Agent to support source debugging on AP function.\r
31\r
32**/\r
33VOID\r
34EnableDebugAgent (\r
35 VOID\r
36 )\r
37{\r
38 //\r
39 // Initialize Debug Agent to support source level debug in DXE phase\r
40 //\r
41 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP, NULL, NULL);\r
42}\r
43\r
93ca4c0f
JF
44/**\r
45 Get the pointer to CPU MP Data structure.\r
46\r
47 @return The pointer to CPU MP Data structure.\r
48**/\r
49CPU_MP_DATA *\r
50GetCpuMpData (\r
51 VOID\r
52 )\r
53{\r
54 ASSERT (mCpuMpData != NULL);\r
55 return mCpuMpData;\r
56}\r
57\r
58/**\r
59 Save the pointer to CPU MP Data structure.\r
60\r
61 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.\r
62**/\r
63VOID\r
64SaveCpuMpData (\r
65 IN CPU_MP_DATA *CpuMpData\r
66 )\r
67{\r
68 mCpuMpData = CpuMpData;\r
69}\r
70\r
96378861 71/**\r
e4ff6349 72 Get available system memory below 0x88000 by specified size.\r
ed66e0e3 73\r
a6b3d753 74 @param[in] WakeupBufferSize Wakeup buffer size required\r
3ed4e502 75\r
a6b3d753
SZ
76 @retval other Return wakeup buffer address below 1MB.\r
77 @retval -1 Cannot find free memory below 1MB.\r
ed66e0e3 78**/\r
a6b3d753
SZ
79UINTN\r
80GetWakeupBuffer (\r
81 IN UINTN WakeupBufferSize\r
ed66e0e3
JF
82 )\r
83{\r
a6b3d753
SZ
84 EFI_STATUS Status;\r
85 EFI_PHYSICAL_ADDRESS StartAddress;\r
86\r
e4ff6349
ED
87 //\r
88 // Try to allocate buffer below 1M for waking vector.\r
89 // LegacyBios driver only reports warning when page allocation in range\r
90 // [0x60000, 0x88000) fails.\r
91 // This library is consumed by CpuDxe driver to produce CPU Arch protocol.\r
92 // LagacyBios driver depends on CPU Arch protocol which guarantees below\r
93 // allocation runs earlier than LegacyBios driver.\r
94 //\r
95 StartAddress = 0x88000;\r
a6b3d753
SZ
96 Status = gBS->AllocatePages (\r
97 AllocateMaxAddress,\r
98 EfiBootServicesData,\r
99 EFI_SIZE_TO_PAGES (WakeupBufferSize),\r
100 &StartAddress\r
101 );\r
102 ASSERT_EFI_ERROR (Status);\r
e4ff6349 103 if (EFI_ERROR (Status)) {\r
a6b3d753 104 StartAddress = (EFI_PHYSICAL_ADDRESS) -1;\r
3ed4e502 105 }\r
e4ff6349
ED
106\r
107 DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",\r
108 (UINTN) StartAddress, WakeupBufferSize));\r
109\r
a6b3d753 110 return (UINTN) StartAddress;\r
ed66e0e3
JF
111}\r
112\r
f32bfe6d
JW
113/**\r
114 Get available EfiBootServicesCode memory below 4GB by specified size.\r
115\r
116 This buffer is required to safely transfer AP from real address mode to\r
117 protected mode or long mode, due to the fact that the buffer returned by\r
118 GetWakeupBuffer() may be marked as non-executable.\r
119\r
120 @param[in] BufferSize Wakeup transition buffer size.\r
121\r
122 @retval other Return wakeup transition buffer address below 4GB.\r
123 @retval 0 Cannot find free memory below 4GB.\r
124**/\r
125UINTN\r
126GetModeTransitionBuffer (\r
127 IN UINTN BufferSize\r
128 )\r
129{\r
130 EFI_STATUS Status;\r
131 EFI_PHYSICAL_ADDRESS StartAddress;\r
132\r
133 StartAddress = BASE_4GB - 1;\r
134 Status = gBS->AllocatePages (\r
135 AllocateMaxAddress,\r
136 EfiBootServicesCode,\r
137 EFI_SIZE_TO_PAGES (BufferSize),\r
138 &StartAddress\r
139 );\r
140 if (EFI_ERROR (Status)) {\r
141 StartAddress = 0;\r
142 }\r
143\r
144 return (UINTN)StartAddress;\r
145}\r
146\r
96378861
JF
147/**\r
148 Checks APs status and updates APs status if needed.\r
149\r
150**/\r
151VOID\r
152CheckAndUpdateApsStatus (\r
153 VOID\r
154 )\r
155{\r
08085f08
JF
156 UINTN ProcessorNumber;\r
157 EFI_STATUS Status;\r
158 CPU_MP_DATA *CpuMpData;\r
159\r
160 CpuMpData = GetCpuMpData ();\r
161\r
162 //\r
163 // First, check whether pending StartupAllAPs() exists.\r
164 //\r
165 if (CpuMpData->WaitEvent != NULL) {\r
166\r
167 Status = CheckAllAPs ();\r
168 //\r
169 // If all APs finish for StartupAllAPs(), signal the WaitEvent for it.\r
170 //\r
171 if (Status != EFI_NOT_READY) {\r
172 Status = gBS->SignalEvent (CpuMpData->WaitEvent);\r
173 CpuMpData->WaitEvent = NULL;\r
174 }\r
175 }\r
176\r
177 //\r
178 // Second, check whether pending StartupThisAPs() callings exist.\r
179 //\r
180 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {\r
181\r
182 if (CpuMpData->CpuData[ProcessorNumber].WaitEvent == NULL) {\r
183 continue;\r
184 }\r
185\r
186 Status = CheckThisAP (ProcessorNumber);\r
187\r
188 if (Status != EFI_NOT_READY) {\r
189 gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent);\r
190 CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;\r
191 }\r
192 }\r
96378861
JF
193}\r
194\r
195/**\r
196 Checks APs' status periodically.\r
197\r
438f1766 198 This function is triggered by timer periodically to check the\r
96378861
JF
199 state of APs for StartupAllAPs() and StartupThisAP() executed\r
200 in non-blocking mode.\r
201\r
202 @param[in] Event Event triggered.\r
203 @param[in] Context Parameter passed with the event.\r
204\r
205**/\r
206VOID\r
207EFIAPI\r
208CheckApsStatus (\r
209 IN EFI_EVENT Event,\r
210 IN VOID *Context\r
211 )\r
212{\r
213 //\r
214 // If CheckApsStatus() is not stopped, otherwise return immediately.\r
215 //\r
216 if (!mStopCheckAllApsStatus) {\r
217 CheckAndUpdateApsStatus ();\r
218 }\r
219}\r
ed66e0e3 220\r
4d3314f6
JF
221/**\r
222 Get Protected mode code segment from current GDT table.\r
223\r
b31c1ad1 224 @return Protected mode code segment value.\r
4d3314f6
JF
225**/\r
226UINT16\r
227GetProtectedModeCS (\r
228 VOID\r
229 )\r
230{\r
231 IA32_DESCRIPTOR GdtrDesc;\r
232 IA32_SEGMENT_DESCRIPTOR *GdtEntry;\r
233 UINTN GdtEntryCount;\r
234 UINT16 Index;\r
235\r
4d3314f6
JF
236 AsmReadGdtr (&GdtrDesc);\r
237 GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);\r
238 GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;\r
239 for (Index = 0; Index < GdtEntryCount; Index++) {\r
240 if (GdtEntry->Bits.L == 0) {\r
241 if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L == 0) {\r
242 break;\r
243 }\r
244 }\r
245 GdtEntry++;\r
246 }\r
37fba7c2 247 ASSERT (Index != GdtEntryCount);\r
4d3314f6
JF
248 return Index * 8;\r
249}\r
250\r
251/**\r
252 Do sync on APs.\r
253\r
254 @param[in, out] Buffer Pointer to private data buffer.\r
255**/\r
256VOID\r
257EFIAPI\r
258RelocateApLoop (\r
259 IN OUT VOID *Buffer\r
260 )\r
261{\r
262 CPU_MP_DATA *CpuMpData;\r
263 BOOLEAN MwaitSupport;\r
264 ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;\r
bf2786dc 265 UINTN ProcessorNumber;\r
4d3314f6 266\r
7367cc6c 267 MpInitLibWhoAmI (&ProcessorNumber);\r
4d3314f6
JF
268 CpuMpData = GetCpuMpData ();\r
269 MwaitSupport = IsMwaitSupport ();\r
081f6416 270 AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;\r
bf2786dc
JF
271 AsmRelocateApLoopFunc (\r
272 MwaitSupport,\r
273 CpuMpData->ApTargetCState,\r
274 CpuMpData->PmCodeSegment,\r
9f91cb01
JF
275 mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE,\r
276 (UINTN) &mNumberToFinish\r
bf2786dc 277 );\r
4d3314f6
JF
278 //\r
279 // It should never reach here\r
280 //\r
281 ASSERT (FALSE);\r
282}\r
283\r
284/**\r
285 Callback function for ExitBootServices.\r
286\r
287 @param[in] Event Event whose notification function is being invoked.\r
288 @param[in] Context The pointer to the notification function's context,\r
289 which is implementation-dependent.\r
290\r
291**/\r
292VOID\r
293EFIAPI\r
86af2eb8 294MpInitChangeApLoopCallback (\r
4d3314f6
JF
295 IN EFI_EVENT Event,\r
296 IN VOID *Context\r
297 )\r
298{\r
299 CPU_MP_DATA *CpuMpData;\r
5183fb37 300\r
4d3314f6
JF
301 CpuMpData = GetCpuMpData ();\r
302 CpuMpData->PmCodeSegment = GetProtectedModeCS ();\r
303 CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);\r
9f91cb01 304 mNumberToFinish = CpuMpData->CpuCount - 1;\r
cf4e79e4 305 WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);\r
9f91cb01
JF
306 while (mNumberToFinish > 0) {\r
307 CpuPause ();\r
308 }\r
86af2eb8 309 DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__));\r
4d3314f6
JF
310}\r
311\r
93ca4c0f
JF
312/**\r
313 Initialize global data for MP support.\r
314\r
315 @param[in] CpuMpData The pointer to CPU MP Data structure.\r
316**/\r
317VOID\r
318InitMpGlobalData (\r
319 IN CPU_MP_DATA *CpuMpData\r
320 )\r
321{\r
15720a6c
JW
322 EFI_STATUS Status;\r
323 EFI_PHYSICAL_ADDRESS Address;\r
324 UINTN ApSafeBufferSize;\r
325 UINTN Index;\r
326 EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;\r
327 UINTN StackBase;\r
52315261 328 CPU_INFO_IN_HOB *CpuInfoInHob;\r
96378861 329\r
93ca4c0f
JF
330 SaveCpuMpData (CpuMpData);\r
331\r
14e8137c
JF
332 if (CpuMpData->CpuCount == 1) {\r
333 //\r
334 // If only BSP exists, return\r
335 //\r
336 return;\r
337 }\r
338\r
15720a6c
JW
339 if (PcdGetBool (PcdCpuStackGuard)) {\r
340 //\r
341 // One extra page at the bottom of the stack is needed for Guard page.\r
342 //\r
343 if (CpuMpData->CpuApStackSize <= EFI_PAGE_SIZE) {\r
344 DEBUG ((DEBUG_ERROR, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));\r
345 ASSERT (FALSE);\r
346 }\r
347\r
52315261
JW
348 //\r
349 // DXE will reuse stack allocated for APs at PEI phase if it's available.\r
350 // Let's check it here.\r
351 //\r
352 // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of\r
353 // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be\r
354 // set here.\r
355 //\r
356 CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;\r
15720a6c 357 for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {\r
52315261 358 if (CpuInfoInHob != NULL && CpuInfoInHob[Index].ApTopOfStack != 0) {\r
20737c2f 359 StackBase = (UINTN)CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize;\r
52315261
JW
360 } else {\r
361 StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;\r
362 }\r
15720a6c
JW
363\r
364 Status = gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);\r
365 ASSERT_EFI_ERROR (Status);\r
366\r
367 Status = gDS->SetMemorySpaceAttributes (\r
368 StackBase,\r
369 EFI_PAGES_TO_SIZE (1),\r
370 MemDesc.Attributes | EFI_MEMORY_RP\r
371 );\r
372 ASSERT_EFI_ERROR (Status);\r
52315261
JW
373\r
374 DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",\r
375 (UINT64)StackBase, (UINT64)Index));\r
15720a6c
JW
376 }\r
377 }\r
378\r
5183fb37 379 //\r
ffd6b0b1
JF
380 // Avoid APs access invalid buffer data which allocated by BootServices,\r
381 // so we will allocate reserved data for AP loop code. We also need to\r
382 // allocate this buffer below 4GB due to APs may be transferred to 32bit\r
383 // protected mode on long mode DXE.\r
5183fb37
JF
384 // Allocating it in advance since memory services are not available in\r
385 // Exit Boot Services callback function.\r
386 //\r
bc2288f5
JW
387 ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (\r
388 CpuMpData->AddressMap.RelocateApLoopFuncSize\r
389 ));\r
ffd6b0b1
JF
390 Address = BASE_4GB - 1;\r
391 Status = gBS->AllocatePages (\r
392 AllocateMaxAddress,\r
393 EfiReservedMemoryType,\r
bf2786dc 394 EFI_SIZE_TO_PAGES (ApSafeBufferSize),\r
ffd6b0b1
JF
395 &Address\r
396 );\r
397 ASSERT_EFI_ERROR (Status);\r
bc2288f5 398\r
ffd6b0b1 399 mReservedApLoopFunc = (VOID *) (UINTN) Address;\r
5183fb37 400 ASSERT (mReservedApLoopFunc != NULL);\r
bc2288f5
JW
401\r
402 //\r
403 // Make sure that the buffer memory is executable if NX protection is enabled\r
404 // for EfiReservedMemoryType.\r
7367cc6c 405 //\r
bc2288f5
JW
406 // TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD\r
407 // service.\r
408 //\r
409 Status = gDS->GetMemorySpaceDescriptor (Address, &MemDesc);\r
410 if (!EFI_ERROR (Status)) {\r
411 gDS->SetMemorySpaceAttributes (\r
412 Address,\r
413 ApSafeBufferSize,\r
414 MemDesc.Attributes & (~EFI_MEMORY_XP)\r
415 );\r
416 }\r
417\r
418 ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (\r
419 CpuMpData->CpuCount * AP_SAFE_STACK_SIZE\r
420 ));\r
421 Address = BASE_4GB - 1;\r
422 Status = gBS->AllocatePages (\r
423 AllocateMaxAddress,\r
424 EfiReservedMemoryType,\r
425 EFI_SIZE_TO_PAGES (ApSafeBufferSize),\r
426 &Address\r
427 );\r
428 ASSERT_EFI_ERROR (Status);\r
429\r
430 mReservedTopOfApStack = (UINTN) Address + ApSafeBufferSize;\r
bf2786dc 431 ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);\r
ffd6b0b1
JF
432 CopyMem (\r
433 mReservedApLoopFunc,\r
434 CpuMpData->AddressMap.RelocateApLoopFuncAddress,\r
435 CpuMpData->AddressMap.RelocateApLoopFuncSize\r
436 );\r
5183fb37 437\r
96378861
JF
438 Status = gBS->CreateEvent (\r
439 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
440 TPL_NOTIFY,\r
441 CheckApsStatus,\r
442 NULL,\r
443 &mCheckAllApsEvent\r
444 );\r
445 ASSERT_EFI_ERROR (Status);\r
446\r
447 //\r
448 // Set timer to check all APs status.\r
449 //\r
450 Status = gBS->SetTimer (\r
451 mCheckAllApsEvent,\r
452 TimerPeriodic,\r
a1c35ff3
HW
453 EFI_TIMER_PERIOD_MICROSECONDS (\r
454 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds)\r
455 )\r
96378861
JF
456 );\r
457 ASSERT_EFI_ERROR (Status);\r
8677a56a 458\r
4d3314f6
JF
459 Status = gBS->CreateEvent (\r
460 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
461 TPL_CALLBACK,\r
86af2eb8 462 MpInitChangeApLoopCallback,\r
4d3314f6
JF
463 NULL,\r
464 &mMpInitExitBootServicesEvent\r
465 );\r
466 ASSERT_EFI_ERROR (Status);\r
8677a56a
JF
467\r
468 Status = gBS->CreateEventEx (\r
469 EVT_NOTIFY_SIGNAL,\r
470 TPL_CALLBACK,\r
471 MpInitChangeApLoopCallback,\r
472 NULL,\r
473 &gEfiEventLegacyBootGuid,\r
474 &mLegacyBootEvent\r
475 );\r
476 ASSERT_EFI_ERROR (Status);\r
93ca4c0f 477}\r
3e8ad6bd
JF
478\r
479/**\r
480 This service executes a caller provided function on all enabled APs.\r
481\r
482 @param[in] Procedure A pointer to the function to be run on\r
483 enabled APs of the system. See type\r
484 EFI_AP_PROCEDURE.\r
485 @param[in] SingleThread If TRUE, then all the enabled APs execute\r
486 the function specified by Procedure one by\r
487 one, in ascending order of processor handle\r
488 number. If FALSE, then all the enabled APs\r
489 execute the function specified by Procedure\r
490 simultaneously.\r
491 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
492 service. If it is NULL, then execute in\r
493 blocking mode. BSP waits until all APs finish\r
494 or TimeoutInMicroSeconds expires. If it's\r
495 not NULL, then execute in non-blocking mode.\r
496 BSP requests the function specified by\r
497 Procedure to be started on all the enabled\r
498 APs, and go on executing immediately. If\r
499 all return from Procedure, or TimeoutInMicroSeconds\r
500 expires, this event is signaled. The BSP\r
501 can use the CheckEvent() or WaitForEvent()\r
502 services to check the state of event. Type\r
503 EFI_EVENT is defined in CreateEvent() in\r
504 the Unified Extensible Firmware Interface\r
505 Specification.\r
367284e7 506 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
3e8ad6bd
JF
507 APs to return from Procedure, either for\r
508 blocking or non-blocking mode. Zero means\r
509 infinity. If the timeout expires before\r
510 all APs return from Procedure, then Procedure\r
511 on the failed APs is terminated. All enabled\r
512 APs are available for next function assigned\r
513 by MpInitLibStartupAllAPs() or\r
514 MPInitLibStartupThisAP().\r
515 If the timeout expires in blocking mode,\r
516 BSP returns EFI_TIMEOUT. If the timeout\r
517 expires in non-blocking mode, WaitEvent\r
518 is signaled with SignalEvent().\r
519 @param[in] ProcedureArgument The parameter passed into Procedure for\r
520 all APs.\r
521 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r
522 if all APs finish successfully, then its\r
523 content is set to NULL. If not all APs\r
524 finish before timeout expires, then its\r
525 content is set to address of the buffer\r
526 holding handle numbers of the failed APs.\r
527 The buffer is allocated by MP Initialization\r
528 library, and it's the caller's responsibility to\r
529 free the buffer with FreePool() service.\r
530 In blocking mode, it is ready for consumption\r
531 when the call returns. In non-blocking mode,\r
532 it is ready when WaitEvent is signaled. The\r
533 list of failed CPU is terminated by\r
534 END_OF_CPU_LIST.\r
535\r
536 @retval EFI_SUCCESS In blocking mode, all APs have finished before\r
537 the timeout expired.\r
538 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r
539 to all enabled APs.\r
540 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
541 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
542 signaled.\r
543 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r
544 supported.\r
545 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
546 @retval EFI_NOT_STARTED No enabled APs exist in the system.\r
547 @retval EFI_NOT_READY Any enabled APs are busy.\r
548 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
549 @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
550 all enabled APs have finished.\r
551 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
552\r
553**/\r
554EFI_STATUS\r
555EFIAPI\r
556MpInitLibStartupAllAPs (\r
557 IN EFI_AP_PROCEDURE Procedure,\r
558 IN BOOLEAN SingleThread,\r
559 IN EFI_EVENT WaitEvent OPTIONAL,\r
560 IN UINTN TimeoutInMicroseconds,\r
561 IN VOID *ProcedureArgument OPTIONAL,\r
562 OUT UINTN **FailedCpuList OPTIONAL\r
563 )\r
564{\r
86efe976
JF
565 EFI_STATUS Status;\r
566\r
567 //\r
568 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.\r
569 //\r
570 mStopCheckAllApsStatus = TRUE;\r
571\r
ee0c39fa 572 Status = StartupAllCPUsWorker (\r
86efe976
JF
573 Procedure,\r
574 SingleThread,\r
ee0c39fa 575 TRUE,\r
86efe976
JF
576 WaitEvent,\r
577 TimeoutInMicroseconds,\r
578 ProcedureArgument,\r
579 FailedCpuList\r
580 );\r
581\r
582 //\r
583 // Start checkAllApsStatus\r
584 //\r
585 mStopCheckAllApsStatus = FALSE;\r
586\r
587 return Status;\r
3e8ad6bd
JF
588}\r
589\r
590/**\r
591 This service lets the caller get one enabled AP to execute a caller-provided\r
592 function.\r
593\r
594 @param[in] Procedure A pointer to the function to be run on the\r
595 designated AP of the system. See type\r
596 EFI_AP_PROCEDURE.\r
597 @param[in] ProcessorNumber The handle number of the AP. The range is\r
598 from 0 to the total number of logical\r
599 processors minus 1. The total number of\r
600 logical processors can be retrieved by\r
601 MpInitLibGetNumberOfProcessors().\r
602 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
603 service. If it is NULL, then execute in\r
604 blocking mode. BSP waits until this AP finish\r
605 or TimeoutInMicroSeconds expires. If it's\r
606 not NULL, then execute in non-blocking mode.\r
607 BSP requests the function specified by\r
608 Procedure to be started on this AP,\r
609 and go on executing immediately. If this AP\r
610 return from Procedure or TimeoutInMicroSeconds\r
611 expires, this event is signaled. The BSP\r
612 can use the CheckEvent() or WaitForEvent()\r
613 services to check the state of event. Type\r
614 EFI_EVENT is defined in CreateEvent() in\r
615 the Unified Extensible Firmware Interface\r
616 Specification.\r
367284e7 617 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
3e8ad6bd
JF
618 this AP to finish this Procedure, either for\r
619 blocking or non-blocking mode. Zero means\r
620 infinity. If the timeout expires before\r
621 this AP returns from Procedure, then Procedure\r
622 on the AP is terminated. The\r
623 AP is available for next function assigned\r
624 by MpInitLibStartupAllAPs() or\r
625 MpInitLibStartupThisAP().\r
626 If the timeout expires in blocking mode,\r
627 BSP returns EFI_TIMEOUT. If the timeout\r
628 expires in non-blocking mode, WaitEvent\r
629 is signaled with SignalEvent().\r
630 @param[in] ProcedureArgument The parameter passed into Procedure on the\r
631 specified AP.\r
632 @param[out] Finished If NULL, this parameter is ignored. In\r
633 blocking mode, this parameter is ignored.\r
634 In non-blocking mode, if AP returns from\r
635 Procedure before the timeout expires, its\r
636 content is set to TRUE. Otherwise, the\r
637 value is set to FALSE. The caller can\r
638 determine if the AP returned from Procedure\r
639 by evaluating this value.\r
640\r
641 @retval EFI_SUCCESS In blocking mode, specified AP finished before\r
642 the timeout expires.\r
643 @retval EFI_SUCCESS In non-blocking mode, the function has been\r
644 dispatched to specified AP.\r
645 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
646 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
647 signaled.\r
648 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r
649 supported.\r
650 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
651 @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
652 the specified AP has finished.\r
653 @retval EFI_NOT_READY The specified AP is busy.\r
654 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
655 @retval EFI_NOT_FOUND The processor with the handle specified by\r
656 ProcessorNumber does not exist.\r
657 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
658 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
659\r
660**/\r
661EFI_STATUS\r
662EFIAPI\r
663MpInitLibStartupThisAP (\r
664 IN EFI_AP_PROCEDURE Procedure,\r
665 IN UINTN ProcessorNumber,\r
666 IN EFI_EVENT WaitEvent OPTIONAL,\r
667 IN UINTN TimeoutInMicroseconds,\r
668 IN VOID *ProcedureArgument OPTIONAL,\r
669 OUT BOOLEAN *Finished OPTIONAL\r
670 )\r
671{\r
20ae5774
JF
672 EFI_STATUS Status;\r
673\r
674 //\r
675 // temporarily stop checkAllApsStatus for avoid resource dead-lock.\r
676 //\r
677 mStopCheckAllApsStatus = TRUE;\r
678\r
679 Status = StartupThisAPWorker (\r
680 Procedure,\r
681 ProcessorNumber,\r
682 WaitEvent,\r
683 TimeoutInMicroseconds,\r
684 ProcedureArgument,\r
685 Finished\r
686 );\r
687\r
688 mStopCheckAllApsStatus = FALSE;\r
689\r
690 return Status;\r
3e8ad6bd
JF
691}\r
692\r
693/**\r
694 This service switches the requested AP to be the BSP from that point onward.\r
695 This service changes the BSP for all purposes. This call can only be performed\r
696 by the current BSP.\r
697\r
698 @param[in] ProcessorNumber The handle number of AP that is to become the new\r
699 BSP. The range is from 0 to the total number of\r
700 logical processors minus 1. The total number of\r
701 logical processors can be retrieved by\r
702 MpInitLibGetNumberOfProcessors().\r
703 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r
704 enabled AP. Otherwise, it will be disabled.\r
705\r
706 @retval EFI_SUCCESS BSP successfully switched.\r
707 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r
708 this service returning.\r
709 @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r
710 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
711 @retval EFI_NOT_FOUND The processor with the handle specified by\r
712 ProcessorNumber does not exist.\r
713 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r
714 a disabled AP.\r
715 @retval EFI_NOT_READY The specified AP is busy.\r
716 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
717\r
718**/\r
719EFI_STATUS\r
720EFIAPI\r
721MpInitLibSwitchBSP (\r
722 IN UINTN ProcessorNumber,\r
723 IN BOOLEAN EnableOldBSP\r
724 )\r
725{\r
b6e45716
JF
726 EFI_STATUS Status;\r
727 EFI_TIMER_ARCH_PROTOCOL *Timer;\r
728 UINT64 TimerPeriod;\r
41be0da5 729\r
8ad05bd2 730 TimerPeriod = 0;\r
b6e45716
JF
731 //\r
732 // Locate Timer Arch Protocol\r
733 //\r
734 Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Timer);\r
735 if (EFI_ERROR (Status)) {\r
736 Timer = NULL;\r
737 }\r
738\r
739 if (Timer != NULL) {\r
740 //\r
741 // Save current rate of DXE Timer\r
742 //\r
743 Timer->GetTimerPeriod (Timer, &TimerPeriod);\r
744 //\r
745 // Disable DXE Timer and drain pending interrupts\r
746 //\r
747 Timer->SetTimerPeriod (Timer, 0);\r
748 }\r
41be0da5
JF
749\r
750 Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);\r
751\r
b6e45716
JF
752 if (Timer != NULL) {\r
753 //\r
754 // Enable and restore rate of DXE Timer\r
755 //\r
756 Timer->SetTimerPeriod (Timer, TimerPeriod);\r
757 }\r
758\r
41be0da5 759 return Status;\r
3e8ad6bd
JF
760}\r
761\r
762/**\r
763 This service lets the caller enable or disable an AP from this point onward.\r
764 This service may only be called from the BSP.\r
765\r
766 @param[in] ProcessorNumber The handle number of AP.\r
767 The range is from 0 to the total number of\r
768 logical processors minus 1. The total number of\r
769 logical processors can be retrieved by\r
770 MpInitLibGetNumberOfProcessors().\r
771 @param[in] EnableAP Specifies the new state for the processor for\r
772 enabled, FALSE for disabled.\r
773 @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r
774 the new health status of the AP. This flag\r
775 corresponds to StatusFlag defined in\r
776 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r
777 the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r
778 bits are ignored. If it is NULL, this parameter\r
779 is ignored.\r
780\r
781 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r
782 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r
783 prior to this service returning.\r
784 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r
785 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
786 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r
787 does not exist.\r
788 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r
789 @retval EFI_NOT_READY MP Initialize Library is not initialized.\r
790\r
791**/\r
792EFI_STATUS\r
793EFIAPI\r
794MpInitLibEnableDisableAP (\r
795 IN UINTN ProcessorNumber,\r
796 IN BOOLEAN EnableAP,\r
797 IN UINT32 *HealthFlag OPTIONAL\r
798 )\r
799{\r
e37109bc
JF
800 EFI_STATUS Status;\r
801 BOOLEAN TempStopCheckState;\r
802\r
803 TempStopCheckState = FALSE;\r
804 //\r
805 // temporarily stop checkAllAPsStatus for initialize parameters.\r
806 //\r
807 if (!mStopCheckAllApsStatus) {\r
808 mStopCheckAllApsStatus = TRUE;\r
809 TempStopCheckState = TRUE;\r
810 }\r
811\r
812 Status = EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);\r
813\r
814 if (TempStopCheckState) {\r
815 mStopCheckAllApsStatus = FALSE;\r
816 }\r
817\r
818 return Status;\r
3e8ad6bd 819}\r
c788c2b1
SF
820\r
821/**\r
822 This funtion will try to invoke platform specific microcode shadow logic to\r
823 relocate microcode update patches into memory.\r
824\r
4ac82ea1 825 @param[in, out] CpuMpData The pointer to CPU MP Data structure.\r
c788c2b1
SF
826\r
827 @retval EFI_SUCCESS Shadow microcode success.\r
828 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.\r
829 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow\r
830 PPI/Protocol.\r
831**/\r
832EFI_STATUS\r
833PlatformShadowMicrocode (\r
834 IN OUT CPU_MP_DATA *CpuMpData\r
835 )\r
836{\r
837 //\r
838 // There is no DXE version of platform shadow microcode protocol so far.\r
839 // A platform which only uses DxeMpInitLib instance could only supports\r
840 // the PCD based microcode shadowing.\r
841 //\r
842 return EFI_UNSUPPORTED;\r
843}\r