2 MP initialize support functions for PEI phase.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Enable Debug Agent to support source debugging on AP function.
29 Get pointer to CPU MP Data structure.
31 @return The pointer to CPU MP Data structure.
38 CPU_MP_DATA
*CpuMpData
;
40 CpuMpData
= GetCpuMpDataFromGuidedHob ();
41 ASSERT (CpuMpData
!= NULL
);
46 Save the pointer to CPU MP Data structure.
48 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
52 IN CPU_MP_DATA
*CpuMpData
57 // Build location of CPU MP DATA buffer in HOB
59 Data64
= (UINT64
) (UINTN
) CpuMpData
;
61 &mCpuInitMpLibHobGuid
,
68 Check if AP wakeup buffer is overlapped with existing allocated buffer.
70 @param[in] WakeupBufferStart AP wakeup buffer start address.
71 @param[in] WakeupBufferEnd AP wakeup buffer end address.
73 @retval TRUE There is overlap.
74 @retval FALSE There is no overlap.
77 CheckOverlapWithAllocatedBuffer (
78 IN UINT64 WakeupBufferStart
,
79 IN UINT64 WakeupBufferEnd
82 EFI_PEI_HOB_POINTERS Hob
;
83 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
90 // Get the HOB list for processing
92 Hob
.Raw
= GetHobList ();
94 // Collect memory ranges
96 while (!END_OF_HOB_LIST (Hob
)) {
97 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
98 MemoryHob
= Hob
.MemoryAllocation
;
99 MemoryStart
= MemoryHob
->AllocDescriptor
.MemoryBaseAddress
;
100 MemoryEnd
= MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
;
101 if (!((WakeupBufferStart
>= MemoryEnd
) || (WakeupBufferEnd
<= MemoryStart
))) {
106 Hob
.Raw
= GET_NEXT_HOB (Hob
);
112 Get available system memory below 1MB by specified size.
114 @param[in] WakeupBufferSize Wakeup buffer size required
116 @retval other Return wakeup buffer address below 1MB.
117 @retval -1 Cannot find free memory below 1MB.
121 IN UINTN WakeupBufferSize
124 EFI_PEI_HOB_POINTERS Hob
;
125 UINT64 WakeupBufferStart
;
126 UINT64 WakeupBufferEnd
;
128 WakeupBufferSize
= (WakeupBufferSize
+ SIZE_4KB
- 1) & ~(SIZE_4KB
- 1);
131 // Get the HOB list for processing
133 Hob
.Raw
= GetHobList ();
136 // Collect memory ranges
138 while (!END_OF_HOB_LIST (Hob
)) {
139 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
140 if ((Hob
.ResourceDescriptor
->PhysicalStart
< BASE_1MB
) &&
141 (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) &&
142 ((Hob
.ResourceDescriptor
->ResourceAttribute
&
143 (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED
|
144 EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED
|
145 EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
149 // Need memory under 1MB to be collected here
151 WakeupBufferEnd
= Hob
.ResourceDescriptor
->PhysicalStart
+ Hob
.ResourceDescriptor
->ResourceLength
;
152 if (WakeupBufferEnd
> BASE_1MB
) {
154 // Wakeup buffer should be under 1MB
156 WakeupBufferEnd
= BASE_1MB
;
158 while (WakeupBufferEnd
> WakeupBufferSize
) {
160 // Wakeup buffer should be aligned on 4KB
162 WakeupBufferStart
= (WakeupBufferEnd
- WakeupBufferSize
) & ~(SIZE_4KB
- 1);
163 if (WakeupBufferStart
< Hob
.ResourceDescriptor
->PhysicalStart
) {
166 if (CheckOverlapWithAllocatedBuffer (WakeupBufferStart
, WakeupBufferEnd
)) {
168 // If this range is overlapped with existing allocated buffer, skip it
169 // and find the next range
171 WakeupBufferEnd
-= WakeupBufferSize
;
174 DEBUG ((DEBUG_INFO
, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
175 WakeupBufferStart
, WakeupBufferSize
));
176 return (UINTN
)WakeupBufferStart
;
183 Hob
.Raw
= GET_NEXT_HOB (Hob
);
190 Get available EfiBootServicesCode memory below 4GB by specified size.
192 This buffer is required to safely transfer AP from real address mode to
193 protected mode or long mode, due to the fact that the buffer returned by
194 GetWakeupBuffer() may be marked as non-executable.
196 @param[in] BufferSize Wakeup transition buffer size.
198 @retval other Return wakeup transition buffer address below 4GB.
199 @retval 0 Cannot find free memory below 4GB.
202 GetModeTransitionBuffer (
207 // PEI phase doesn't need to do such transition. So simply return 0.
213 Checks APs status and updates APs status if needed.
217 CheckAndUpdateApsStatus (
224 Initialize global data for MP support.
226 @param[in] CpuMpData The pointer to CPU MP Data structure.
230 IN CPU_MP_DATA
*CpuMpData
233 SaveCpuMpData (CpuMpData
);
237 This service executes a caller provided function on all enabled APs.
239 @param[in] Procedure A pointer to the function to be run on
240 enabled APs of the system. See type
242 @param[in] SingleThread If TRUE, then all the enabled APs execute
243 the function specified by Procedure one by
244 one, in ascending order of processor handle
245 number. If FALSE, then all the enabled APs
246 execute the function specified by Procedure
248 @param[in] WaitEvent The event created by the caller with CreateEvent()
249 service. If it is NULL, then execute in
250 blocking mode. BSP waits until all APs finish
251 or TimeoutInMicroSeconds expires. If it's
252 not NULL, then execute in non-blocking mode.
253 BSP requests the function specified by
254 Procedure to be started on all the enabled
255 APs, and go on executing immediately. If
256 all return from Procedure, or TimeoutInMicroSeconds
257 expires, this event is signaled. The BSP
258 can use the CheckEvent() or WaitForEvent()
259 services to check the state of event. Type
260 EFI_EVENT is defined in CreateEvent() in
261 the Unified Extensible Firmware Interface
263 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
264 APs to return from Procedure, either for
265 blocking or non-blocking mode. Zero means
266 infinity. If the timeout expires before
267 all APs return from Procedure, then Procedure
268 on the failed APs is terminated. All enabled
269 APs are available for next function assigned
270 by MpInitLibStartupAllAPs() or
271 MPInitLibStartupThisAP().
272 If the timeout expires in blocking mode,
273 BSP returns EFI_TIMEOUT. If the timeout
274 expires in non-blocking mode, WaitEvent
275 is signaled with SignalEvent().
276 @param[in] ProcedureArgument The parameter passed into Procedure for
278 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
279 if all APs finish successfully, then its
280 content is set to NULL. If not all APs
281 finish before timeout expires, then its
282 content is set to address of the buffer
283 holding handle numbers of the failed APs.
284 The buffer is allocated by MP Initialization
285 library, and it's the caller's responsibility to
286 free the buffer with FreePool() service.
287 In blocking mode, it is ready for consumption
288 when the call returns. In non-blocking mode,
289 it is ready when WaitEvent is signaled. The
290 list of failed CPU is terminated by
293 @retval EFI_SUCCESS In blocking mode, all APs have finished before
295 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
297 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
298 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
300 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
302 @retval EFI_DEVICE_ERROR Caller processor is AP.
303 @retval EFI_NOT_STARTED No enabled APs exist in the system.
304 @retval EFI_NOT_READY Any enabled APs are busy.
305 @retval EFI_NOT_READY MP Initialize Library is not initialized.
306 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
307 all enabled APs have finished.
308 @retval EFI_INVALID_PARAMETER Procedure is NULL.
313 MpInitLibStartupAllAPs (
314 IN EFI_AP_PROCEDURE Procedure
,
315 IN BOOLEAN SingleThread
,
316 IN EFI_EVENT WaitEvent OPTIONAL
,
317 IN UINTN TimeoutInMicroseconds
,
318 IN VOID
*ProcedureArgument OPTIONAL
,
319 OUT UINTN
**FailedCpuList OPTIONAL
322 if (WaitEvent
!= NULL
) {
323 return EFI_UNSUPPORTED
;
326 return StartupAllAPsWorker (
330 TimeoutInMicroseconds
,
337 This service lets the caller get one enabled AP to execute a caller-provided
340 @param[in] Procedure A pointer to the function to be run on the
341 designated AP of the system. See type
343 @param[in] ProcessorNumber The handle number of the AP. The range is
344 from 0 to the total number of logical
345 processors minus 1. The total number of
346 logical processors can be retrieved by
347 MpInitLibGetNumberOfProcessors().
348 @param[in] WaitEvent The event created by the caller with CreateEvent()
349 service. If it is NULL, then execute in
350 blocking mode. BSP waits until this AP finish
351 or TimeoutInMicroSeconds expires. If it's
352 not NULL, then execute in non-blocking mode.
353 BSP requests the function specified by
354 Procedure to be started on this AP,
355 and go on executing immediately. If this AP
356 return from Procedure or TimeoutInMicroSeconds
357 expires, this event is signaled. The BSP
358 can use the CheckEvent() or WaitForEvent()
359 services to check the state of event. Type
360 EFI_EVENT is defined in CreateEvent() in
361 the Unified Extensible Firmware Interface
363 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
364 this AP to finish this Procedure, either for
365 blocking or non-blocking mode. Zero means
366 infinity. If the timeout expires before
367 this AP returns from Procedure, then Procedure
368 on the AP is terminated. The
369 AP is available for next function assigned
370 by MpInitLibStartupAllAPs() or
371 MpInitLibStartupThisAP().
372 If the timeout expires in blocking mode,
373 BSP returns EFI_TIMEOUT. If the timeout
374 expires in non-blocking mode, WaitEvent
375 is signaled with SignalEvent().
376 @param[in] ProcedureArgument The parameter passed into Procedure on the
378 @param[out] Finished If NULL, this parameter is ignored. In
379 blocking mode, this parameter is ignored.
380 In non-blocking mode, if AP returns from
381 Procedure before the timeout expires, its
382 content is set to TRUE. Otherwise, the
383 value is set to FALSE. The caller can
384 determine if the AP returned from Procedure
385 by evaluating this value.
387 @retval EFI_SUCCESS In blocking mode, specified AP finished before
389 @retval EFI_SUCCESS In non-blocking mode, the function has been
390 dispatched to specified AP.
391 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
392 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
394 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
396 @retval EFI_DEVICE_ERROR The calling processor is an AP.
397 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
398 the specified AP has finished.
399 @retval EFI_NOT_READY The specified AP is busy.
400 @retval EFI_NOT_READY MP Initialize Library is not initialized.
401 @retval EFI_NOT_FOUND The processor with the handle specified by
402 ProcessorNumber does not exist.
403 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
404 @retval EFI_INVALID_PARAMETER Procedure is NULL.
409 MpInitLibStartupThisAP (
410 IN EFI_AP_PROCEDURE Procedure
,
411 IN UINTN ProcessorNumber
,
412 IN EFI_EVENT WaitEvent OPTIONAL
,
413 IN UINTN TimeoutInMicroseconds
,
414 IN VOID
*ProcedureArgument OPTIONAL
,
415 OUT BOOLEAN
*Finished OPTIONAL
418 if (WaitEvent
!= NULL
) {
419 return EFI_UNSUPPORTED
;
422 return StartupThisAPWorker (
426 TimeoutInMicroseconds
,
433 This service switches the requested AP to be the BSP from that point onward.
434 This service changes the BSP for all purposes. This call can only be performed
437 @param[in] ProcessorNumber The handle number of AP that is to become the new
438 BSP. The range is from 0 to the total number of
439 logical processors minus 1. The total number of
440 logical processors can be retrieved by
441 MpInitLibGetNumberOfProcessors().
442 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
443 enabled AP. Otherwise, it will be disabled.
445 @retval EFI_SUCCESS BSP successfully switched.
446 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
447 this service returning.
448 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
449 @retval EFI_DEVICE_ERROR The calling processor is an AP.
450 @retval EFI_NOT_FOUND The processor with the handle specified by
451 ProcessorNumber does not exist.
452 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
454 @retval EFI_NOT_READY The specified AP is busy.
455 @retval EFI_NOT_READY MP Initialize Library is not initialized.
461 IN UINTN ProcessorNumber
,
462 IN BOOLEAN EnableOldBSP
465 return SwitchBSPWorker (ProcessorNumber
, EnableOldBSP
);
469 This service lets the caller enable or disable an AP from this point onward.
470 This service may only be called from the BSP.
472 @param[in] ProcessorNumber The handle number of AP.
473 The range is from 0 to the total number of
474 logical processors minus 1. The total number of
475 logical processors can be retrieved by
476 MpInitLibGetNumberOfProcessors().
477 @param[in] EnableAP Specifies the new state for the processor for
478 enabled, FALSE for disabled.
479 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
480 the new health status of the AP. This flag
481 corresponds to StatusFlag defined in
482 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
483 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
484 bits are ignored. If it is NULL, this parameter
487 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
488 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
489 prior to this service returning.
490 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
491 @retval EFI_DEVICE_ERROR The calling processor is an AP.
492 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
494 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
495 @retval EFI_NOT_READY MP Initialize Library is not initialized.
500 MpInitLibEnableDisableAP (
501 IN UINTN ProcessorNumber
,
503 IN UINT32
*HealthFlag OPTIONAL
506 return EnableDisableApWorker (ProcessorNumber
, EnableAP
, HealthFlag
);