2 MP initialize support functions for PEI phase.
4 Copyright (c) 2016, 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.
16 #include <Ppi/EndOfPeiPhase.h>
17 #include <Library/PeiServicesLib.h>
20 // Global PEI notify function descriptor on EndofPei event
22 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMpInitLibNotifyList
= {
23 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
24 &gEfiEndOfPeiSignalPpiGuid
,
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
,
70 Notify function on End Of PEI PPI.
72 On S3 boot, this function will restore wakeup buffer data.
73 On normal boot, this function will flag wakeup buffer to be un-used type.
75 @param[in] PeiServices The pointer to the PEI Services Table.
76 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
77 @param[in] Ppi Address of the PPI that was installed.
79 @retval EFI_SUCCESS When everything is OK.
83 CpuMpEndOfPeiCallback (
84 IN EFI_PEI_SERVICES
**PeiServices
,
85 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
90 DEBUG ((DEBUG_INFO
, "PeiMpInitLib: CpuMpEndOfPeiCallback () invoked\n"));
95 Initialize global data for MP support.
97 @param[in] CpuMpData The pointer to CPU MP Data structure.
101 IN CPU_MP_DATA
*CpuMpData
106 SaveCpuMpData (CpuMpData
);
108 // Register an event for EndOfPei
110 Status
= PeiServicesNotifyPpi (&mMpInitLibNotifyList
);
111 ASSERT_EFI_ERROR (Status
);
115 This service executes a caller provided function on all enabled APs.
117 @param[in] Procedure A pointer to the function to be run on
118 enabled APs of the system. See type
120 @param[in] SingleThread If TRUE, then all the enabled APs execute
121 the function specified by Procedure one by
122 one, in ascending order of processor handle
123 number. If FALSE, then all the enabled APs
124 execute the function specified by Procedure
126 @param[in] WaitEvent The event created by the caller with CreateEvent()
127 service. If it is NULL, then execute in
128 blocking mode. BSP waits until all APs finish
129 or TimeoutInMicroSeconds expires. If it's
130 not NULL, then execute in non-blocking mode.
131 BSP requests the function specified by
132 Procedure to be started on all the enabled
133 APs, and go on executing immediately. If
134 all return from Procedure, or TimeoutInMicroSeconds
135 expires, this event is signaled. The BSP
136 can use the CheckEvent() or WaitForEvent()
137 services to check the state of event. Type
138 EFI_EVENT is defined in CreateEvent() in
139 the Unified Extensible Firmware Interface
141 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
142 APs to return from Procedure, either for
143 blocking or non-blocking mode. Zero means
144 infinity. If the timeout expires before
145 all APs return from Procedure, then Procedure
146 on the failed APs is terminated. All enabled
147 APs are available for next function assigned
148 by MpInitLibStartupAllAPs() or
149 MPInitLibStartupThisAP().
150 If the timeout expires in blocking mode,
151 BSP returns EFI_TIMEOUT. If the timeout
152 expires in non-blocking mode, WaitEvent
153 is signaled with SignalEvent().
154 @param[in] ProcedureArgument The parameter passed into Procedure for
156 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
157 if all APs finish successfully, then its
158 content is set to NULL. If not all APs
159 finish before timeout expires, then its
160 content is set to address of the buffer
161 holding handle numbers of the failed APs.
162 The buffer is allocated by MP Initialization
163 library, and it's the caller's responsibility to
164 free the buffer with FreePool() service.
165 In blocking mode, it is ready for consumption
166 when the call returns. In non-blocking mode,
167 it is ready when WaitEvent is signaled. The
168 list of failed CPU is terminated by
171 @retval EFI_SUCCESS In blocking mode, all APs have finished before
173 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
175 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
176 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
178 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
180 @retval EFI_DEVICE_ERROR Caller processor is AP.
181 @retval EFI_NOT_STARTED No enabled APs exist in the system.
182 @retval EFI_NOT_READY Any enabled APs are busy.
183 @retval EFI_NOT_READY MP Initialize Library is not initialized.
184 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
185 all enabled APs have finished.
186 @retval EFI_INVALID_PARAMETER Procedure is NULL.
191 MpInitLibStartupAllAPs (
192 IN EFI_AP_PROCEDURE Procedure
,
193 IN BOOLEAN SingleThread
,
194 IN EFI_EVENT WaitEvent OPTIONAL
,
195 IN UINTN TimeoutInMicroseconds
,
196 IN VOID
*ProcedureArgument OPTIONAL
,
197 OUT UINTN
**FailedCpuList OPTIONAL
200 return EFI_UNSUPPORTED
;
204 This service lets the caller get one enabled AP to execute a caller-provided
207 @param[in] Procedure A pointer to the function to be run on the
208 designated AP of the system. See type
210 @param[in] ProcessorNumber The handle number of the AP. The range is
211 from 0 to the total number of logical
212 processors minus 1. The total number of
213 logical processors can be retrieved by
214 MpInitLibGetNumberOfProcessors().
215 @param[in] WaitEvent The event created by the caller with CreateEvent()
216 service. If it is NULL, then execute in
217 blocking mode. BSP waits until this AP finish
218 or TimeoutInMicroSeconds expires. If it's
219 not NULL, then execute in non-blocking mode.
220 BSP requests the function specified by
221 Procedure to be started on this AP,
222 and go on executing immediately. If this AP
223 return from Procedure or TimeoutInMicroSeconds
224 expires, this event is signaled. The BSP
225 can use the CheckEvent() or WaitForEvent()
226 services to check the state of event. Type
227 EFI_EVENT is defined in CreateEvent() in
228 the Unified Extensible Firmware Interface
230 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
231 this AP to finish this Procedure, either for
232 blocking or non-blocking mode. Zero means
233 infinity. If the timeout expires before
234 this AP returns from Procedure, then Procedure
235 on the AP is terminated. The
236 AP is available for next function assigned
237 by MpInitLibStartupAllAPs() or
238 MpInitLibStartupThisAP().
239 If the timeout expires in blocking mode,
240 BSP returns EFI_TIMEOUT. If the timeout
241 expires in non-blocking mode, WaitEvent
242 is signaled with SignalEvent().
243 @param[in] ProcedureArgument The parameter passed into Procedure on the
245 @param[out] Finished If NULL, this parameter is ignored. In
246 blocking mode, this parameter is ignored.
247 In non-blocking mode, if AP returns from
248 Procedure before the timeout expires, its
249 content is set to TRUE. Otherwise, the
250 value is set to FALSE. The caller can
251 determine if the AP returned from Procedure
252 by evaluating this value.
254 @retval EFI_SUCCESS In blocking mode, specified AP finished before
256 @retval EFI_SUCCESS In non-blocking mode, the function has been
257 dispatched to specified AP.
258 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
259 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
261 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
263 @retval EFI_DEVICE_ERROR The calling processor is an AP.
264 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
265 the specified AP has finished.
266 @retval EFI_NOT_READY The specified AP is busy.
267 @retval EFI_NOT_READY MP Initialize Library is not initialized.
268 @retval EFI_NOT_FOUND The processor with the handle specified by
269 ProcessorNumber does not exist.
270 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
271 @retval EFI_INVALID_PARAMETER Procedure is NULL.
276 MpInitLibStartupThisAP (
277 IN EFI_AP_PROCEDURE Procedure
,
278 IN UINTN ProcessorNumber
,
279 IN EFI_EVENT WaitEvent OPTIONAL
,
280 IN UINTN TimeoutInMicroseconds
,
281 IN VOID
*ProcedureArgument OPTIONAL
,
282 OUT BOOLEAN
*Finished OPTIONAL
285 return EFI_UNSUPPORTED
;
289 This service switches the requested AP to be the BSP from that point onward.
290 This service changes the BSP for all purposes. This call can only be performed
293 @param[in] ProcessorNumber The handle number of AP that is to become the new
294 BSP. The range is from 0 to the total number of
295 logical processors minus 1. The total number of
296 logical processors can be retrieved by
297 MpInitLibGetNumberOfProcessors().
298 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
299 enabled AP. Otherwise, it will be disabled.
301 @retval EFI_SUCCESS BSP successfully switched.
302 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
303 this service returning.
304 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
305 @retval EFI_DEVICE_ERROR The calling processor is an AP.
306 @retval EFI_NOT_FOUND The processor with the handle specified by
307 ProcessorNumber does not exist.
308 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
310 @retval EFI_NOT_READY The specified AP is busy.
311 @retval EFI_NOT_READY MP Initialize Library is not initialized.
317 IN UINTN ProcessorNumber
,
318 IN BOOLEAN EnableOldBSP
321 return EFI_UNSUPPORTED
;
325 This service lets the caller enable or disable an AP from this point onward.
326 This service may only be called from the BSP.
328 @param[in] ProcessorNumber The handle number of AP.
329 The range is from 0 to the total number of
330 logical processors minus 1. The total number of
331 logical processors can be retrieved by
332 MpInitLibGetNumberOfProcessors().
333 @param[in] EnableAP Specifies the new state for the processor for
334 enabled, FALSE for disabled.
335 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
336 the new health status of the AP. This flag
337 corresponds to StatusFlag defined in
338 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
339 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
340 bits are ignored. If it is NULL, this parameter
343 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
344 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
345 prior to this service returning.
346 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
347 @retval EFI_DEVICE_ERROR The calling processor is an AP.
348 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
350 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
351 @retval EFI_NOT_READY MP Initialize Library is not initialized.
356 MpInitLibEnableDisableAP (
357 IN UINTN ProcessorNumber
,
359 IN UINT32
*HealthFlag OPTIONAL
362 return EFI_UNSUPPORTED
;