]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuMpPei/CpuMp2Pei.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuMp2Pei.c
1 /** @file
2 EDKII_PEI_MP_SERVICES2_PPI Implementation code.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "CpuMpPei.h"
10
11 /**
12 This service retrieves the number of logical processor in the platform
13 and the number of those logical processors that are enabled on this boot.
14 This service may only be called from the BSP.
15
16 This function is used to retrieve the following information:
17 - The number of logical processors that are present in the system.
18 - The number of enabled logical processors in the system at the instant
19 this call is made.
20
21 Because MP Service Ppi provides services to enable and disable processors
22 dynamically, the number of enabled logical processors may vary during the
23 course of a boot session.
24
25 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
26 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
27 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
28 is returned in NumberOfProcessors, the number of currently enabled processor
29 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
30
31 @param[in] This Pointer to this instance of the PPI.
32 @param[out] NumberOfProcessors Pointer to the total number of logical processors in
33 the system, including the BSP and disabled APs.
34 @param[out] NumberOfEnabledProcessors
35 Number of processors in the system that are enabled.
36
37 @retval EFI_SUCCESS The number of logical processors and enabled
38 logical processors was retrieved.
39 @retval EFI_DEVICE_ERROR The calling processor is an AP.
40 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
41 NumberOfEnabledProcessors is NULL.
42 **/
43 EFI_STATUS
44 EFIAPI
45 EdkiiPeiGetNumberOfProcessors (
46 IN EDKII_PEI_MP_SERVICES2_PPI *This,
47 OUT UINTN *NumberOfProcessors,
48 OUT UINTN *NumberOfEnabledProcessors
49 )
50 {
51 if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {
52 return EFI_INVALID_PARAMETER;
53 }
54
55 return MpInitLibGetNumberOfProcessors (
56 NumberOfProcessors,
57 NumberOfEnabledProcessors
58 );
59 }
60
61 /**
62 Gets detailed MP-related information on the requested processor at the
63 instant this call is made. This service may only be called from the BSP.
64
65 This service retrieves detailed MP-related information about any processor
66 on the platform. Note the following:
67 - The processor information may change during the course of a boot session.
68 - The information presented here is entirely MP related.
69
70 Information regarding the number of caches and their sizes, frequency of operation,
71 slot numbers is all considered platform-related information and is not provided
72 by this service.
73
74 @param[in] This Pointer to this instance of the PPI.
75 @param[in] ProcessorNumber Pointer to the total number of logical processors in
76 the system, including the BSP and disabled APs.
77 @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.
78
79 @retval EFI_SUCCESS Processor information was returned.
80 @retval EFI_DEVICE_ERROR The calling processor is an AP.
81 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
82 @retval EFI_NOT_FOUND The processor with the handle specified by
83 ProcessorNumber does not exist in the platform.
84 **/
85 EFI_STATUS
86 EFIAPI
87 EdkiiPeiGetProcessorInfo (
88 IN EDKII_PEI_MP_SERVICES2_PPI *This,
89 IN UINTN ProcessorNumber,
90 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
91 )
92 {
93 return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);
94 }
95
96 /**
97 This service executes a caller provided function on all enabled APs. APs can
98 run either simultaneously or one at a time in sequence. This service supports
99 both blocking requests only. This service may only
100 be called from the BSP.
101
102 This function is used to dispatch all the enabled APs to the function specified
103 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
104 immediately and Procedure is not started on any AP.
105
106 If SingleThread is TRUE, all the enabled APs execute the function specified by
107 Procedure one by one, in ascending order of processor handle number. Otherwise,
108 all the enabled APs execute the function specified by Procedure simultaneously.
109
110 If the timeout specified by TimeoutInMicroSeconds expires before all APs return
111 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
112 are always available for further calls to EDKII_PEI_MP_SERVICES2_PPI.StartupAllAPs()
113 and EDKII_PEI_MP_SERVICES2_PPI.StartupThisAP(). If FailedCpuList is not NULL, its
114 content points to the list of processor handle numbers in which Procedure was
115 terminated.
116
117 Note: It is the responsibility of the consumer of the EDKII_PEI_MP_SERVICES2_PPI.StartupAllAPs()
118 to make sure that the nature of the code that is executed on the BSP and the
119 dispatched APs is well controlled. The MP Services Ppi does not guarantee
120 that the Procedure function is MP-safe. Hence, the tasks that can be run in
121 parallel are limited to certain independent tasks and well-controlled exclusive
122 code. PEI services and Ppis may not be called by APs unless otherwise
123 specified.
124
125 In blocking execution mode, BSP waits until all APs finish or
126 TimeoutInMicroSeconds expires.
127
128 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
129 @param[in] Procedure A pointer to the function to be run on enabled APs of
130 the system.
131 @param[in] SingleThread If TRUE, then all the enabled APs execute the function
132 specified by Procedure one by one, in ascending order
133 of processor handle number. If FALSE, then all the
134 enabled APs execute the function specified by Procedure
135 simultaneously.
136 @param[in] TimeoutInMicroSeconds
137 Indicates the time limit in microseconds for APs to
138 return from Procedure, for blocking mode only. Zero
139 means infinity. If the timeout expires before all APs
140 return from Procedure, then Procedure on the failed APs
141 is terminated. All enabled APs are available for next
142 function assigned by EDKII_PEI_MP_SERVICES2_PPI.StartupAllAPs()
143 or EDKII_PEI_MP_SERVICES2_PPI.StartupThisAP(). If the
144 timeout expires in blocking mode, BSP returns
145 EFI_TIMEOUT.
146 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
147
148 @retval EFI_SUCCESS In blocking mode, all APs have finished before the
149 timeout expired.
150 @retval EFI_DEVICE_ERROR Caller processor is AP.
151 @retval EFI_NOT_STARTED No enabled APs exist in the system.
152 @retval EFI_NOT_READY Any enabled APs are busy.
153 @retval EFI_TIMEOUT In blocking mode, the timeout expired before all
154 enabled APs have finished.
155 @retval EFI_INVALID_PARAMETER Procedure is NULL.
156 **/
157 EFI_STATUS
158 EFIAPI
159 EdkiiPeiStartupAllAPs (
160 IN EDKII_PEI_MP_SERVICES2_PPI *This,
161 IN EFI_AP_PROCEDURE Procedure,
162 IN BOOLEAN SingleThread,
163 IN UINTN TimeoutInMicroSeconds,
164 IN VOID *ProcedureArgument OPTIONAL
165 )
166 {
167 return MpInitLibStartupAllAPs (
168 Procedure,
169 SingleThread,
170 NULL,
171 TimeoutInMicroSeconds,
172 ProcedureArgument,
173 NULL
174 );
175 }
176
177 /**
178 This service lets the caller get one enabled AP to execute a caller-provided
179 function. The caller can request the BSP to wait for the completion
180 of the AP. This service may only be called from the BSP.
181
182 This function is used to dispatch one enabled AP to the function specified by
183 Procedure passing in the argument specified by ProcedureArgument.
184 The execution is in blocking mode. The BSP waits until the AP finishes or
185 TimeoutInMicroSecondss expires.
186
187 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
188 from Procedure, then execution of Procedure by the AP is terminated. The AP is
189 available for subsequent calls to EDKII_PEI_MP_SERVICES2_PPI.StartupAllAPs() and
190 EDKII_PEI_MP_SERVICES2_PPI.StartupThisAP().
191
192 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
193 @param[in] Procedure A pointer to the function to be run on enabled APs of
194 the system.
195 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
196 total number of logical processors minus 1. The total
197 number of logical processors can be retrieved by
198 EDKII_PEI_MP_SERVICES2_PPI.GetNumberOfProcessors().
199 @param[in] TimeoutInMicroseconds
200 Indicates the time limit in microseconds for APs to
201 return from Procedure, for blocking mode only. Zero
202 means infinity. If the timeout expires before all APs
203 return from Procedure, then Procedure on the failed APs
204 is terminated. All enabled APs are available for next
205 function assigned by EDKII_PEI_MP_SERVICES2_PPI.StartupAllAPs()
206 or EDKII_PEI_MP_SERVICES2_PPI.StartupThisAP(). If the
207 timeout expires in blocking mode, BSP returns
208 EFI_TIMEOUT.
209 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
210
211 @retval EFI_SUCCESS In blocking mode, specified AP finished before the
212 timeout expires.
213 @retval EFI_DEVICE_ERROR The calling processor is an AP.
214 @retval EFI_TIMEOUT In blocking mode, the timeout expired before the
215 specified AP has finished.
216 @retval EFI_NOT_FOUND The processor with the handle specified by
217 ProcessorNumber does not exist.
218 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
219 @retval EFI_INVALID_PARAMETER Procedure is NULL.
220 **/
221 EFI_STATUS
222 EFIAPI
223 EdkiiPeiStartupThisAP (
224 IN EDKII_PEI_MP_SERVICES2_PPI *This,
225 IN EFI_AP_PROCEDURE Procedure,
226 IN UINTN ProcessorNumber,
227 IN UINTN TimeoutInMicroseconds,
228 IN VOID *ProcedureArgument OPTIONAL
229 )
230 {
231 return MpInitLibStartupThisAP (
232 Procedure,
233 ProcessorNumber,
234 NULL,
235 TimeoutInMicroseconds,
236 ProcedureArgument,
237 NULL
238 );
239 }
240
241 /**
242 This service switches the requested AP to be the BSP from that point onward.
243 This service changes the BSP for all purposes. This call can only be performed
244 by the current BSP.
245
246 This service switches the requested AP to be the BSP from that point onward.
247 This service changes the BSP for all purposes. The new BSP can take over the
248 execution of the old BSP and continue seamlessly from where the old one left
249 off.
250
251 If the BSP cannot be switched prior to the return from this service, then
252 EFI_UNSUPPORTED must be returned.
253
254 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
255 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
256 total number of logical processors minus 1. The total
257 number of logical processors can be retrieved by
258 EDKII_PEI_MP_SERVICES2_PPI.GetNumberOfProcessors().
259 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled
260 AP. Otherwise, it will be disabled.
261
262 @retval EFI_SUCCESS BSP successfully switched.
263 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this
264 service returning.
265 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
266 @retval EFI_DEVICE_ERROR The calling processor is an AP.
267 @retval EFI_NOT_FOUND The processor with the handle specified by
268 ProcessorNumber does not exist.
269 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled
270 AP.
271 @retval EFI_NOT_READY The specified AP is busy.
272 **/
273 EFI_STATUS
274 EFIAPI
275 EdkiiPeiSwitchBSP (
276 IN EDKII_PEI_MP_SERVICES2_PPI *This,
277 IN UINTN ProcessorNumber,
278 IN BOOLEAN EnableOldBSP
279 )
280 {
281 return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);
282 }
283
284 /**
285 This service lets the caller enable or disable an AP from this point onward.
286 This service may only be called from the BSP.
287
288 This service allows the caller enable or disable an AP from this point onward.
289 The caller can optionally specify the health status of the AP by Health. If
290 an AP is being disabled, then the state of the disabled AP is implementation
291 dependent. If an AP is enabled, then the implementation must guarantee that a
292 complete initialization sequence is performed on the AP, so the AP is in a state
293 that is compatible with an MP operating system.
294
295 If the enable or disable AP operation cannot be completed prior to the return
296 from this service, then EFI_UNSUPPORTED must be returned.
297
298 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
299 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
300 total number of logical processors minus 1. The total
301 number of logical processors can be retrieved by
302 EDKII_PEI_MP_SERVICES2_PPI.GetNumberOfProcessors().
303 @param[in] EnableAP Specifies the new state for the processor for enabled,
304 FALSE for disabled.
305 @param[in] HealthFlag If not NULL, a pointer to a value that specifies the
306 new health status of the AP. This flag corresponds to
307 StatusFlag defined in EDKII_PEI_MP_SERVICES2_PPI.GetProcessorInfo().
308 Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other
309 bits are ignored. If it is NULL, this parameter is
310 ignored.
311
312 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
313 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior
314 to this service returning.
315 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
316 @retval EFI_DEVICE_ERROR The calling processor is an AP.
317 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
318 does not exist.
319 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
320 **/
321 EFI_STATUS
322 EFIAPI
323 EdkiiPeiEnableDisableAP (
324 IN EDKII_PEI_MP_SERVICES2_PPI *This,
325 IN UINTN ProcessorNumber,
326 IN BOOLEAN EnableAP,
327 IN UINT32 *HealthFlag OPTIONAL
328 )
329 {
330 return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);
331 }
332
333 /**
334 This return the handle number for the calling processor. This service may be
335 called from the BSP and APs.
336
337 This service returns the processor handle number for the calling processor.
338 The returned value is in the range from 0 to the total number of logical
339 processors minus 1. The total number of logical processors can be retrieved
340 with EDKII_PEI_MP_SERVICES2_PPI.GetNumberOfProcessors(). This service may be
341 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
342 is returned. Otherwise, the current processors handle number is returned in
343 ProcessorNumber, and EFI_SUCCESS is returned.
344
345 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
346 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
347 total number of logical processors minus 1. The total
348 number of logical processors can be retrieved by
349 EDKII_PEI_MP_SERVICES2_PPI.GetNumberOfProcessors().
350
351 @retval EFI_SUCCESS The current processor handle number was returned in
352 ProcessorNumber.
353 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
354 **/
355 EFI_STATUS
356 EFIAPI
357 EdkiiPeiWhoAmI (
358 IN EDKII_PEI_MP_SERVICES2_PPI *This,
359 OUT UINTN *ProcessorNumber
360 )
361 {
362 return MpInitLibWhoAmI (ProcessorNumber);
363 }
364
365 /**
366 This service executes a caller provided function on all enabled CPUs. CPUs can
367 run either simultaneously or one at a time in sequence. This service may only
368 be called from the BSP.
369
370 @param[in] This A pointer to the EDKII_PEI_MP_SERVICES2_PPI instance.
371 @param[in] Procedure A pointer to the function to be run on enabled APs of
372 the system.
373 @param[in] TimeoutInMicroSeconds
374 Indicates the time limit in microseconds for APs to
375 return from Procedure, for blocking mode only. Zero
376 means infinity. If the timeout expires in blocking
377 mode, BSP returns EFI_TIMEOUT.
378 @param[in] ProcedureArgument The parameter passed into Procedure for all CPUs.
379
380 @retval EFI_SUCCESS In blocking mode, all APs have finished before the
381 timeout expired.
382 @retval EFI_DEVICE_ERROR Caller processor is AP.
383 @retval EFI_NOT_READY Any enabled APs are busy.
384 @retval EFI_TIMEOUT In blocking mode, the timeout expired before all
385 enabled APs have finished.
386 @retval EFI_INVALID_PARAMETER Procedure is NULL.
387 **/
388 EFI_STATUS
389 EFIAPI
390 EdkiiPeiStartupAllCPUs (
391 IN EDKII_PEI_MP_SERVICES2_PPI *This,
392 IN EFI_AP_PROCEDURE Procedure,
393 IN UINTN TimeoutInMicroSeconds,
394 IN VOID *ProcedureArgument OPTIONAL
395 )
396 {
397 return MpInitLibStartupAllCPUs (
398 Procedure,
399 TimeoutInMicroSeconds,
400 ProcedureArgument
401 );
402 }
403
404 //
405 // CPU MP2 PPI to be installed
406 //
407 EDKII_PEI_MP_SERVICES2_PPI mMpServices2Ppi = {
408 EdkiiPeiGetNumberOfProcessors,
409 EdkiiPeiGetProcessorInfo,
410 EdkiiPeiStartupAllAPs,
411 EdkiiPeiStartupThisAP,
412 EdkiiPeiSwitchBSP,
413 EdkiiPeiEnableDisableAP,
414 EdkiiPeiWhoAmI,
415 EdkiiPeiStartupAllCPUs
416 };