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