2 Implementation of Multiple Processor PPI services.
4 Copyright (c) 2015 - 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.
15 #include "PeiMpServices.h"
18 // CPU MP PPI to be installed
20 EFI_PEI_MP_SERVICES_PPI mMpServicesPpi
= {
21 PeiGetNumberOfProcessors
,
30 EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc
= {
31 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
32 &gEfiPeiMpServicesPpiGuid
,
38 This service retrieves the number of logical processor in the platform
39 and the number of those logical processors that are enabled on this boot.
40 This service may only be called from the BSP.
42 This function is used to retrieve the following information:
43 - The number of logical processors that are present in the system.
44 - The number of enabled logical processors in the system at the instant
47 Because MP Service Ppi provides services to enable and disable processors
48 dynamically, the number of enabled logical processors may vary during the
49 course of a boot session.
51 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
52 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
53 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
54 is returned in NumberOfProcessors, the number of currently enabled processor
55 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
57 @param[in] PeiServices An indirect pointer to the PEI Services Table
58 published by the PEI Foundation.
59 @param[in] This Pointer to this instance of the PPI.
60 @param[out] NumberOfProcessors Pointer to the total number of logical processors in
61 the system, including the BSP and disabled APs.
62 @param[out] NumberOfEnabledProcessors
63 Number of processors in the system that are enabled.
65 @retval EFI_SUCCESS The number of logical processors and enabled
66 logical processors was retrieved.
67 @retval EFI_DEVICE_ERROR The calling processor is an AP.
68 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
69 NumberOfEnabledProcessors is NULL.
73 PeiGetNumberOfProcessors (
74 IN CONST EFI_PEI_SERVICES
**PeiServices
,
75 IN EFI_PEI_MP_SERVICES_PPI
*This
,
76 OUT UINTN
*NumberOfProcessors
,
77 OUT UINTN
*NumberOfEnabledProcessors
80 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
81 return EFI_INVALID_PARAMETER
;
84 return MpInitLibGetNumberOfProcessors (
86 NumberOfEnabledProcessors
91 Gets detailed MP-related information on the requested processor at the
92 instant this call is made. This service may only be called from the BSP.
94 This service retrieves detailed MP-related information about any processor
95 on the platform. Note the following:
96 - The processor information may change during the course of a boot session.
97 - The information presented here is entirely MP related.
99 Information regarding the number of caches and their sizes, frequency of operation,
100 slot numbers is all considered platform-related information and is not provided
103 @param[in] PeiServices An indirect pointer to the PEI Services Table
104 published by the PEI Foundation.
105 @param[in] This Pointer to this instance of the PPI.
106 @param[in] ProcessorNumber Pointer to the total number of logical processors in
107 the system, including the BSP and disabled APs.
108 @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.
110 @retval EFI_SUCCESS Processor information was returned.
111 @retval EFI_DEVICE_ERROR The calling processor is an AP.
112 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
113 @retval EFI_NOT_FOUND The processor with the handle specified by
114 ProcessorNumber does not exist in the platform.
118 PeiGetProcessorInfo (
119 IN CONST EFI_PEI_SERVICES
**PeiServices
,
120 IN EFI_PEI_MP_SERVICES_PPI
*This
,
121 IN UINTN ProcessorNumber
,
122 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
125 return MpInitLibGetProcessorInfo (ProcessorNumber
, ProcessorInfoBuffer
, NULL
);
129 This service executes a caller provided function on all enabled APs. APs can
130 run either simultaneously or one at a time in sequence. This service supports
131 both blocking requests only. This service may only
132 be called from the BSP.
134 This function is used to dispatch all the enabled APs to the function specified
135 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
136 immediately and Procedure is not started on any AP.
138 If SingleThread is TRUE, all the enabled APs execute the function specified by
139 Procedure one by one, in ascending order of processor handle number. Otherwise,
140 all the enabled APs execute the function specified by Procedure simultaneously.
142 If the timeout specified by TimeoutInMicroSeconds expires before all APs return
143 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
144 are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
145 and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its
146 content points to the list of processor handle numbers in which Procedure was
149 Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
150 to make sure that the nature of the code that is executed on the BSP and the
151 dispatched APs is well controlled. The MP Services Ppi does not guarantee
152 that the Procedure function is MP-safe. Hence, the tasks that can be run in
153 parallel are limited to certain independent tasks and well-controlled exclusive
154 code. PEI services and Ppis may not be called by APs unless otherwise
157 In blocking execution mode, BSP waits until all APs finish or
158 TimeoutInMicroSeconds expires.
160 @param[in] PeiServices An indirect pointer to the PEI Services Table
161 published by the PEI Foundation.
162 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
163 @param[in] Procedure A pointer to the function to be run on enabled APs of
165 @param[in] SingleThread If TRUE, then all the enabled APs execute the function
166 specified by Procedure one by one, in ascending order
167 of processor handle number. If FALSE, then all the
168 enabled APs execute the function specified by Procedure
170 @param[in] TimeoutInMicroSeconds
171 Indicates the time limit in microseconds for APs to
172 return from Procedure, for blocking mode only. Zero
173 means infinity. If the timeout expires before all APs
174 return from Procedure, then Procedure on the failed APs
175 is terminated. All enabled APs are available for next
176 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
177 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
178 timeout expires in blocking mode, BSP returns
180 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
182 @retval EFI_SUCCESS In blocking mode, all APs have finished before the
184 @retval EFI_DEVICE_ERROR Caller processor is AP.
185 @retval EFI_NOT_STARTED No enabled APs exist in the system.
186 @retval EFI_NOT_READY Any enabled APs are busy.
187 @retval EFI_TIMEOUT In blocking mode, the timeout expired before all
188 enabled APs have finished.
189 @retval EFI_INVALID_PARAMETER Procedure is NULL.
194 IN CONST EFI_PEI_SERVICES
**PeiServices
,
195 IN EFI_PEI_MP_SERVICES_PPI
*This
,
196 IN EFI_AP_PROCEDURE Procedure
,
197 IN BOOLEAN SingleThread
,
198 IN UINTN TimeoutInMicroSeconds
,
199 IN VOID
*ProcedureArgument OPTIONAL
202 return MpInitLibStartupAllAPs (
206 TimeoutInMicroSeconds
,
213 This service lets the caller get one enabled AP to execute a caller-provided
214 function. The caller can request the BSP to wait for the completion
215 of the AP. This service may only be called from the BSP.
217 This function is used to dispatch one enabled AP to the function specified by
218 Procedure passing in the argument specified by ProcedureArgument.
219 The execution is in blocking mode. The BSP waits until the AP finishes or
220 TimeoutInMicroSecondss expires.
222 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
223 from Procedure, then execution of Procedure by the AP is terminated. The AP is
224 available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and
225 EFI_PEI_MP_SERVICES_PPI.StartupThisAP().
227 @param[in] PeiServices An indirect pointer to the PEI Services Table
228 published by the PEI Foundation.
229 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
230 @param[in] Procedure A pointer to the function to be run on enabled APs of
232 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
233 total number of logical processors minus 1. The total
234 number of logical processors can be retrieved by
235 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
236 @param[in] TimeoutInMicroseconds
237 Indicates the time limit in microseconds for APs to
238 return from Procedure, for blocking mode only. Zero
239 means infinity. If the timeout expires before all APs
240 return from Procedure, then Procedure on the failed APs
241 is terminated. All enabled APs are available for next
242 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
243 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
244 timeout expires in blocking mode, BSP returns
246 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
248 @retval EFI_SUCCESS In blocking mode, specified AP finished before the
250 @retval EFI_DEVICE_ERROR The calling processor is an AP.
251 @retval EFI_TIMEOUT In blocking mode, the timeout expired before the
252 specified AP has finished.
253 @retval EFI_NOT_FOUND The processor with the handle specified by
254 ProcessorNumber does not exist.
255 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
256 @retval EFI_INVALID_PARAMETER Procedure is NULL.
261 IN CONST EFI_PEI_SERVICES
**PeiServices
,
262 IN EFI_PEI_MP_SERVICES_PPI
*This
,
263 IN EFI_AP_PROCEDURE Procedure
,
264 IN UINTN ProcessorNumber
,
265 IN UINTN TimeoutInMicroseconds
,
266 IN VOID
*ProcedureArgument OPTIONAL
269 return MpInitLibStartupThisAP (
273 TimeoutInMicroseconds
,
280 This service switches the requested AP to be the BSP from that point onward.
281 This service changes the BSP for all purposes. This call can only be performed
284 This service switches the requested AP to be the BSP from that point onward.
285 This service changes the BSP for all purposes. The new BSP can take over the
286 execution of the old BSP and continue seamlessly from where the old one left
289 If the BSP cannot be switched prior to the return from this service, then
290 EFI_UNSUPPORTED must be returned.
292 @param[in] PeiServices An indirect pointer to the PEI Services Table
293 published by the PEI Foundation.
294 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
295 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
296 total number of logical processors minus 1. The total
297 number of logical processors can be retrieved by
298 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
299 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled
300 AP. Otherwise, it will be disabled.
302 @retval EFI_SUCCESS BSP successfully switched.
303 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this
305 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
306 @retval EFI_SUCCESS The calling processor is an AP.
307 @retval EFI_NOT_FOUND The processor with the handle specified by
308 ProcessorNumber does not exist.
309 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled
311 @retval EFI_NOT_READY The specified AP is busy.
316 IN CONST EFI_PEI_SERVICES
**PeiServices
,
317 IN EFI_PEI_MP_SERVICES_PPI
*This
,
318 IN UINTN ProcessorNumber
,
319 IN BOOLEAN EnableOldBSP
322 return MpInitLibSwitchBSP (ProcessorNumber
, EnableOldBSP
);
326 This service lets the caller enable or disable an AP from this point onward.
327 This service may only be called from the BSP.
329 This service allows the caller enable or disable an AP from this point onward.
330 The caller can optionally specify the health status of the AP by Health. If
331 an AP is being disabled, then the state of the disabled AP is implementation
332 dependent. If an AP is enabled, then the implementation must guarantee that a
333 complete initialization sequence is performed on the AP, so the AP is in a state
334 that is compatible with an MP operating system.
336 If the enable or disable AP operation cannot be completed prior to the return
337 from this service, then EFI_UNSUPPORTED must be returned.
339 @param[in] PeiServices An indirect pointer to the PEI Services Table
340 published by the PEI Foundation.
341 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
342 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
343 total number of logical processors minus 1. The total
344 number of logical processors can be retrieved by
345 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
346 @param[in] EnableAP Specifies the new state for the processor for enabled,
348 @param[in] HealthFlag If not NULL, a pointer to a value that specifies the
349 new health status of the AP. This flag corresponds to
350 StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().
351 Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other
352 bits are ignored. If it is NULL, this parameter is
355 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
356 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior
357 to this service returning.
358 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
359 @retval EFI_DEVICE_ERROR The calling processor is an AP.
360 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
362 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
367 IN CONST EFI_PEI_SERVICES
**PeiServices
,
368 IN EFI_PEI_MP_SERVICES_PPI
*This
,
369 IN UINTN ProcessorNumber
,
371 IN UINT32
*HealthFlag OPTIONAL
374 return MpInitLibEnableDisableAP (ProcessorNumber
, EnableAP
, HealthFlag
);
378 This return the handle number for the calling processor. This service may be
379 called from the BSP and APs.
381 This service returns the processor handle number for the calling processor.
382 The returned value is in the range from 0 to the total number of logical
383 processors minus 1. The total number of logical processors can be retrieved
384 with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be
385 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
386 is returned. Otherwise, the current processors handle number is returned in
387 ProcessorNumber, and EFI_SUCCESS is returned.
389 @param[in] PeiServices An indirect pointer to the PEI Services Table
390 published by the PEI Foundation.
391 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
392 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
393 total number of logical processors minus 1. The total
394 number of logical processors can be retrieved by
395 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
397 @retval EFI_SUCCESS The current processor handle number was returned in
399 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
404 IN CONST EFI_PEI_SERVICES
**PeiServices
,
405 IN EFI_PEI_MP_SERVICES_PPI
*This
,
406 OUT UINTN
*ProcessorNumber
409 return MpInitLibWhoAmI (ProcessorNumber
);