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