]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuMpPei/CpuMpPei.h
UefiCpuPkg/CpuMp: Fix hang when StackGuard is enabled in 16-core cpu
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuMpPei.h
CommitLineData
ea0f431c
JF
1/** @file\r
2 Definitions to install Multiple Processor PPI.\r
3\r
3b769c51 4 Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
ea0f431c
JF
6\r
7**/\r
8\r
9#ifndef _CPU_MP_PEI_H_\r
10#define _CPU_MP_PEI_H_\r
11\r
12#include <PiPei.h>\r
13\r
14#include <Ppi/MpServices.h>\r
15#include <Ppi/SecPlatformInformation.h>\r
16#include <Ppi/SecPlatformInformation2.h>\r
17#include <Ppi/EndOfPeiPhase.h>\r
a430589c 18#include <Ppi/MpServices2.h>\r
ea0f431c
JF
19\r
20#include <Library/BaseLib.h>\r
ea0f431c
JF
21#include <Library/DebugLib.h>\r
22#include <Library/HobLib.h>\r
23#include <Library/LocalApicLib.h>\r
ea0f431c
JF
24#include <Library/PeimEntryPoint.h>\r
25#include <Library/PeiServicesLib.h>\r
26#include <Library/ReportStatusCodeLib.h>\r
9bedfb2f 27#include <Library/CpuExceptionHandlerLib.h>\r
a1a4c7a4 28#include <Library/MpInitLib.h>\r
86432994 29#include <Library/BaseMemoryLib.h>\r
3b769c51 30#include <Library/MemoryAllocationLib.h>\r
ea0f431c 31\r
ea0f431c
JF
32extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;\r
33\r
89fa1bf2
JF
34/**\r
35 This service retrieves the number of logical processor in the platform\r
36 and the number of those logical processors that are enabled on this boot.\r
37 This service may only be called from the BSP.\r
38\r
39 This function is used to retrieve the following information:\r
40 - The number of logical processors that are present in the system.\r
41 - The number of enabled logical processors in the system at the instant\r
42 this call is made.\r
43\r
44 Because MP Service Ppi provides services to enable and disable processors\r
45 dynamically, the number of enabled logical processors may vary during the\r
46 course of a boot session.\r
47\r
48 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r
49 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r
50 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r
51 is returned in NumberOfProcessors, the number of currently enabled processor\r
52 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r
53\r
54 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
55 published by the PEI Foundation.\r
56 @param[in] This Pointer to this instance of the PPI.\r
57 @param[out] NumberOfProcessors Pointer to the total number of logical processors in\r
58 the system, including the BSP and disabled APs.\r
59 @param[out] NumberOfEnabledProcessors\r
60 Number of processors in the system that are enabled.\r
61\r
62 @retval EFI_SUCCESS The number of logical processors and enabled\r
63 logical processors was retrieved.\r
64 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
65 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r
66 NumberOfEnabledProcessors is NULL.\r
67**/\r
68EFI_STATUS\r
69EFIAPI\r
70PeiGetNumberOfProcessors (\r
71 IN CONST EFI_PEI_SERVICES **PeiServices,\r
72 IN EFI_PEI_MP_SERVICES_PPI *This,\r
73 OUT UINTN *NumberOfProcessors,\r
74 OUT UINTN *NumberOfEnabledProcessors\r
75 );\r
76\r
77/**\r
78 Gets detailed MP-related information on the requested processor at the\r
79 instant this call is made. This service may only be called from the BSP.\r
80\r
81 This service retrieves detailed MP-related information about any processor\r
82 on the platform. Note the following:\r
83 - The processor information may change during the course of a boot session.\r
84 - The information presented here is entirely MP related.\r
85\r
86 Information regarding the number of caches and their sizes, frequency of operation,\r
87 slot numbers is all considered platform-related information and is not provided\r
88 by this service.\r
89\r
90 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
91 published by the PEI Foundation.\r
92 @param[in] This Pointer to this instance of the PPI.\r
93 @param[in] ProcessorNumber Pointer to the total number of logical processors in\r
94 the system, including the BSP and disabled APs.\r
95 @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.\r
96\r
97 @retval EFI_SUCCESS Processor information was returned.\r
98 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
99 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r
100 @retval EFI_NOT_FOUND The processor with the handle specified by\r
101 ProcessorNumber does not exist in the platform.\r
102**/\r
103EFI_STATUS\r
104EFIAPI\r
105PeiGetProcessorInfo (\r
106 IN CONST EFI_PEI_SERVICES **PeiServices,\r
107 IN EFI_PEI_MP_SERVICES_PPI *This,\r
108 IN UINTN ProcessorNumber,\r
109 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r
110 );\r
111\r
112/**\r
113 This service executes a caller provided function on all enabled APs. APs can\r
114 run either simultaneously or one at a time in sequence. This service supports\r
115 both blocking requests only. This service may only\r
116 be called from the BSP.\r
117\r
118 This function is used to dispatch all the enabled APs to the function specified\r
119 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r
120 immediately and Procedure is not started on any AP.\r
121\r
122 If SingleThread is TRUE, all the enabled APs execute the function specified by\r
123 Procedure one by one, in ascending order of processor handle number. Otherwise,\r
124 all the enabled APs execute the function specified by Procedure simultaneously.\r
125\r
126 If the timeout specified by TimeoutInMicroSeconds expires before all APs return\r
127 from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r
128 are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r
129 and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its\r
130 content points to the list of processor handle numbers in which Procedure was\r
131 terminated.\r
132\r
133 Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r
134 to make sure that the nature of the code that is executed on the BSP and the\r
135 dispatched APs is well controlled. The MP Services Ppi does not guarantee\r
136 that the Procedure function is MP-safe. Hence, the tasks that can be run in\r
137 parallel are limited to certain independent tasks and well-controlled exclusive\r
138 code. PEI services and Ppis may not be called by APs unless otherwise\r
139 specified.\r
140\r
141 In blocking execution mode, BSP waits until all APs finish or\r
142 TimeoutInMicroSeconds expires.\r
143\r
144 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
145 published by the PEI Foundation.\r
146 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r
147 @param[in] Procedure A pointer to the function to be run on enabled APs of\r
148 the system.\r
149 @param[in] SingleThread If TRUE, then all the enabled APs execute the function\r
150 specified by Procedure one by one, in ascending order\r
151 of processor handle number. If FALSE, then all the\r
152 enabled APs execute the function specified by Procedure\r
153 simultaneously.\r
154 @param[in] TimeoutInMicroSeconds\r
155 Indicates the time limit in microseconds for APs to\r
156 return from Procedure, for blocking mode only. Zero\r
157 means infinity. If the timeout expires before all APs\r
158 return from Procedure, then Procedure on the failed APs\r
159 is terminated. All enabled APs are available for next\r
160 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r
161 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r
162 timeout expires in blocking mode, BSP returns\r
163 EFI_TIMEOUT.\r
164 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r
165\r
166 @retval EFI_SUCCESS In blocking mode, all APs have finished before the\r
167 timeout expired.\r
168 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
169 @retval EFI_NOT_STARTED No enabled APs exist in the system.\r
170 @retval EFI_NOT_READY Any enabled APs are busy.\r
171 @retval EFI_TIMEOUT In blocking mode, the timeout expired before all\r
172 enabled APs have finished.\r
173 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
174**/\r
175EFI_STATUS\r
176EFIAPI\r
177PeiStartupAllAPs (\r
178 IN CONST EFI_PEI_SERVICES **PeiServices,\r
179 IN EFI_PEI_MP_SERVICES_PPI *This,\r
180 IN EFI_AP_PROCEDURE Procedure,\r
181 IN BOOLEAN SingleThread,\r
182 IN UINTN TimeoutInMicroSeconds,\r
183 IN VOID *ProcedureArgument OPTIONAL\r
184 );\r
185\r
186/**\r
187 This service lets the caller get one enabled AP to execute a caller-provided\r
188 function. The caller can request the BSP to wait for the completion\r
189 of the AP. This service may only be called from the BSP.\r
190\r
191 This function is used to dispatch one enabled AP to the function specified by\r
192 Procedure passing in the argument specified by ProcedureArgument.\r
193 The execution is in blocking mode. The BSP waits until the AP finishes or\r
194 TimeoutInMicroSecondss expires.\r
195\r
196 If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r
197 from Procedure, then execution of Procedure by the AP is terminated. The AP is\r
198 available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and\r
199 EFI_PEI_MP_SERVICES_PPI.StartupThisAP().\r
200\r
201 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
202 published by the PEI Foundation.\r
203 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r
204 @param[in] Procedure A pointer to the function to be run on enabled APs of\r
205 the system.\r
206 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r
207 total number of logical processors minus 1. The total\r
208 number of logical processors can be retrieved by\r
209 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r
210 @param[in] TimeoutInMicroseconds\r
211 Indicates the time limit in microseconds for APs to\r
212 return from Procedure, for blocking mode only. Zero\r
213 means infinity. If the timeout expires before all APs\r
214 return from Procedure, then Procedure on the failed APs\r
215 is terminated. All enabled APs are available for next\r
216 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r
217 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r
218 timeout expires in blocking mode, BSP returns\r
219 EFI_TIMEOUT.\r
220 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r
221\r
222 @retval EFI_SUCCESS In blocking mode, specified AP finished before the\r
223 timeout expires.\r
224 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
225 @retval EFI_TIMEOUT In blocking mode, the timeout expired before the\r
226 specified AP has finished.\r
227 @retval EFI_NOT_FOUND The processor with the handle specified by\r
228 ProcessorNumber does not exist.\r
229 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
230 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234PeiStartupThisAP (\r
235 IN CONST EFI_PEI_SERVICES **PeiServices,\r
236 IN EFI_PEI_MP_SERVICES_PPI *This,\r
237 IN EFI_AP_PROCEDURE Procedure,\r
238 IN UINTN ProcessorNumber,\r
239 IN UINTN TimeoutInMicroseconds,\r
240 IN VOID *ProcedureArgument OPTIONAL\r
241 );\r
242\r
243/**\r
244 This service switches the requested AP to be the BSP from that point onward.\r
245 This service changes the BSP for all purposes. This call can only be performed\r
246 by the current BSP.\r
247\r
248 This service switches the requested AP to be the BSP from that point onward.\r
249 This service changes the BSP for all purposes. The new BSP can take over the\r
250 execution of the old BSP and continue seamlessly from where the old one left\r
251 off.\r
252\r
253 If the BSP cannot be switched prior to the return from this service, then\r
254 EFI_UNSUPPORTED must be returned.\r
255\r
256 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
257 published by the PEI Foundation.\r
258 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r
259 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r
260 total number of logical processors minus 1. The total\r
261 number of logical processors can be retrieved by\r
262 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r
263 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled\r
264 AP. Otherwise, it will be disabled.\r
265\r
266 @retval EFI_SUCCESS BSP successfully switched.\r
267 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this\r
268 service returning.\r
269 @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r
e3ae7f52 270 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
89fa1bf2
JF
271 @retval EFI_NOT_FOUND The processor with the handle specified by\r
272 ProcessorNumber does not exist.\r
273 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled\r
274 AP.\r
275 @retval EFI_NOT_READY The specified AP is busy.\r
276**/\r
277EFI_STATUS\r
278EFIAPI\r
279PeiSwitchBSP (\r
280 IN CONST EFI_PEI_SERVICES **PeiServices,\r
281 IN EFI_PEI_MP_SERVICES_PPI *This,\r
282 IN UINTN ProcessorNumber,\r
283 IN BOOLEAN EnableOldBSP\r
284 );\r
285\r
286/**\r
287 This service lets the caller enable or disable an AP from this point onward.\r
288 This service may only be called from the BSP.\r
289\r
290 This service allows the caller enable or disable an AP from this point onward.\r
291 The caller can optionally specify the health status of the AP by Health. If\r
292 an AP is being disabled, then the state of the disabled AP is implementation\r
293 dependent. If an AP is enabled, then the implementation must guarantee that a\r
294 complete initialization sequence is performed on the AP, so the AP is in a state\r
295 that is compatible with an MP operating system.\r
296\r
297 If the enable or disable AP operation cannot be completed prior to the return\r
298 from this service, then EFI_UNSUPPORTED must be returned.\r
299\r
300 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
301 published by the PEI Foundation.\r
302 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r
303 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r
304 total number of logical processors minus 1. The total\r
305 number of logical processors can be retrieved by\r
306 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r
307 @param[in] EnableAP Specifies the new state for the processor for enabled,\r
308 FALSE for disabled.\r
309 @param[in] HealthFlag If not NULL, a pointer to a value that specifies the\r
310 new health status of the AP. This flag corresponds to\r
311 StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().\r
312 Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r
313 bits are ignored. If it is NULL, this parameter is\r
314 ignored.\r
315\r
316 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r
317 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior\r
318 to this service returning.\r
319 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r
320 @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
321 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r
322 does not exist.\r
323 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r
324**/\r
325EFI_STATUS\r
326EFIAPI\r
327PeiEnableDisableAP (\r
328 IN CONST EFI_PEI_SERVICES **PeiServices,\r
329 IN EFI_PEI_MP_SERVICES_PPI *This,\r
330 IN UINTN ProcessorNumber,\r
331 IN BOOLEAN EnableAP,\r
332 IN UINT32 *HealthFlag OPTIONAL\r
333 );\r
334\r
335/**\r
336 This return the handle number for the calling processor. This service may be\r
337 called from the BSP and APs.\r
338\r
339 This service returns the processor handle number for the calling processor.\r
340 The returned value is in the range from 0 to the total number of logical\r
341 processors minus 1. The total number of logical processors can be retrieved\r
342 with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be\r
343 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r
344 is returned. Otherwise, the current processors handle number is returned in\r
345 ProcessorNumber, and EFI_SUCCESS is returned.\r
346\r
347 @param[in] PeiServices An indirect pointer to the PEI Services Table\r
348 published by the PEI Foundation.\r
349 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r
350 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the\r
351 total number of logical processors minus 1. The total\r
352 number of logical processors can be retrieved by\r
353 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r
354\r
355 @retval EFI_SUCCESS The current processor handle number was returned in\r
356 ProcessorNumber.\r
357 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r
358**/\r
359EFI_STATUS\r
360EFIAPI\r
361PeiWhoAmI (\r
362 IN CONST EFI_PEI_SERVICES **PeiServices,\r
363 IN EFI_PEI_MP_SERVICES_PPI *This,\r
364 OUT UINTN *ProcessorNumber\r
365 );\r
ea0f431c 366\r
ea0f431c
JF
367/**\r
368 Collects BIST data from PPI.\r
369\r
370 This function collects BIST data from Sec Platform Information2 PPI\r
371 or SEC Platform Information PPI.\r
372\r
373 @param PeiServices Pointer to PEI Services Table\r
ea0f431c
JF
374\r
375**/\r
376VOID\r
377CollectBistDataFromPpi (\r
a1a4c7a4 378 IN CONST EFI_PEI_SERVICES **PeiServices\r
ea0f431c
JF
379 );\r
380\r
381/**\r
382 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
383\r
384 @param PeiServices The pointer to the PEI Services Table.\r
385 @param StructureSize The pointer to the variable describing size of the input buffer.\r
386 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
387\r
388 @retval EFI_SUCCESS The data was successfully returned.\r
389 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
390 hold the record is returned in StructureSize.\r
391\r
392**/\r
393EFI_STATUS\r
394EFIAPI\r
395SecPlatformInformation2 (\r
396 IN CONST EFI_PEI_SERVICES **PeiServices,\r
397 IN OUT UINT64 *StructureSize,\r
398 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
399 );\r
400\r
60b12e69
MK
401/**\r
402 Migrates the Global Descriptor Table (GDT) to permanent memory.\r
403\r
404 @retval EFI_SUCCESS The GDT was migrated successfully.\r
405 @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lack of available memory.\r
406\r
407**/\r
408EFI_STATUS\r
409MigrateGdt (\r
410 VOID\r
411 );\r
412\r
0a0d5296
JW
413/**\r
414 Initializes MP and exceptions handlers.\r
415\r
416 @param PeiServices The pointer to the PEI Services Table.\r
417\r
418 @retval EFI_SUCCESS MP was successfully initialized.\r
419 @retval others Error occurred in MP initialization.\r
420\r
421**/\r
422EFI_STATUS\r
423InitializeCpuMpWorker (\r
424 IN CONST EFI_PEI_SERVICES **PeiServices\r
425 );\r
426\r
427/**\r
92c19c68 428 Enable/setup stack guard for each processor if PcdCpuStackGuard is set to TRUE.\r
0a0d5296
JW
429\r
430 Doing this in the memory-discovered callback is to make sure the Stack Guard\r
431 feature to cover as most PEI code as possible.\r
432\r
433 @param[in] PeiServices General purpose services available to every PEIM.\r
434 @param[in] NotifyDescriptor The notification structure this PEIM registered on install.\r
435 @param[in] Ppi The memory discovered PPI. Not used.\r
436\r
437 @retval EFI_SUCCESS The function completed successfully.\r
438 @retval others There's error in MP initialization.\r
439**/\r
440EFI_STATUS\r
441EFIAPI\r
442MemoryDiscoveredPpiNotifyCallback (\r
443 IN EFI_PEI_SERVICES **PeiServices,\r
444 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
445 IN VOID *Ppi\r
446 );\r
447\r
448extern EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList[];\r
449\r
ea0f431c 450#endif\r