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