VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/CpuMpPei/CpuMpPei.h@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette