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