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