]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.c
UefiCpuPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLibUp / MpInitLibUp.c
1 /** @file
2 Multiple-Processor initialization Library for uniprocessor platforms.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10 #include <Ppi/SecPlatformInformation.h>
11 #include <Protocol/MpService.h>
12 #include <Library/DebugLib.h>
13 #include <Library/LocalApicLib.h>
14 #include <Library/HobLib.h>
15
16 /**
17 MP Initialize Library initialization.
18
19 This service will allocate AP reset vector and wakeup all APs to do APs
20 initialization.
21
22 This service must be invoked before all other MP Initialize Library
23 service are invoked.
24
25 @retval EFI_SUCCESS MP initialization succeeds.
26 @retval Others MP initialization fails.
27
28 **/
29 EFI_STATUS
30 EFIAPI
31 MpInitLibInitialize (
32 VOID
33 )
34 {
35 //
36 // Enable the local APIC for Virtual Wire Mode.
37 //
38 ProgramVirtualWireMode ();
39
40 return EFI_SUCCESS;
41 }
42
43 /**
44 Retrieves the number of logical processor in the platform and the number of
45 those logical processors that are enabled on this boot. This service may only
46 be called from the BSP.
47
48 @param[out] NumberOfProcessors Pointer to the total number of logical
49 processors in the system, including the BSP
50 and disabled APs.
51 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
52 processors that exist in system, including
53 the BSP.
54
55 @retval EFI_SUCCESS The number of logical processors and enabled
56 logical processors was retrieved.
57 @retval EFI_DEVICE_ERROR The calling processor is an AP.
58 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
59 is NULL.
60 @retval EFI_NOT_READY MP Initialize Library is not initialized.
61
62 **/
63 EFI_STATUS
64 EFIAPI
65 MpInitLibGetNumberOfProcessors (
66 OUT UINTN *NumberOfProcessors OPTIONAL,
67 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
68 )
69 {
70 *NumberOfProcessors = 1;
71 *NumberOfEnabledProcessors = 1;
72 return EFI_SUCCESS;
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 @param[in] ProcessorNumber The handle number of processor.
80 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
81 the requested processor is deposited.
82 @param[out] HealthData Return processor health data.
83
84 @retval EFI_SUCCESS Processor information was returned.
85 @retval EFI_DEVICE_ERROR The calling processor is an AP.
86 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
87 @retval EFI_NOT_FOUND The processor with the handle specified by
88 ProcessorNumber does not exist in the platform.
89 @retval EFI_NOT_READY MP Initialize Library is not initialized.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 MpInitLibGetProcessorInfo (
95 IN UINTN ProcessorNumber,
96 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,
97 OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL
98 )
99 {
100 EFI_HOB_GUID_TYPE *GuidHob;
101 EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInformation;
102
103 if (ProcessorInfoBuffer == NULL) {
104 return EFI_INVALID_PARAMETER;
105 }
106
107 if (ProcessorNumber != 0) {
108 return EFI_NOT_FOUND;
109 }
110
111 ProcessorInfoBuffer->ProcessorId = 0;
112 ProcessorInfoBuffer->StatusFlag = PROCESSOR_AS_BSP_BIT |
113 PROCESSOR_ENABLED_BIT |
114 PROCESSOR_HEALTH_STATUS_BIT;
115 ProcessorInfoBuffer->Location.Package = 0;
116 ProcessorInfoBuffer->Location.Core = 0;
117 ProcessorInfoBuffer->Location.Thread = 0;
118 if (HealthData != NULL) {
119 GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);
120 if (GuidHob != NULL) {
121 SecPlatformInformation = GET_GUID_HOB_DATA (GuidHob);
122 HealthData->Uint32 = SecPlatformInformation->IA32HealthFlags.Uint32;
123 } else {
124 DEBUG ((DEBUG_INFO, "Does not find any HOB stored CPU BIST information!\n"));
125 HealthData->Uint32 = 0;
126 }
127 }
128
129 return EFI_SUCCESS;
130 }
131
132 /**
133 This service executes a caller provided function on all enabled APs.
134
135 @param[in] Procedure A pointer to the function to be run on
136 enabled APs of the system. See type
137 EFI_AP_PROCEDURE.
138 @param[in] SingleThread If TRUE, then all the enabled APs execute
139 the function specified by Procedure one by
140 one, in ascending order of processor handle
141 number. If FALSE, then all the enabled APs
142 execute the function specified by Procedure
143 simultaneously.
144 @param[in] WaitEvent The event created by the caller with CreateEvent()
145 service. If it is NULL, then execute in
146 blocking mode. BSP waits until all APs finish
147 or TimeoutInMicroSeconds expires. If it's
148 not NULL, then execute in non-blocking mode.
149 BSP requests the function specified by
150 Procedure to be started on all the enabled
151 APs, and go on executing immediately. If
152 all return from Procedure, or TimeoutInMicroSeconds
153 expires, this event is signaled. The BSP
154 can use the CheckEvent() or WaitForEvent()
155 services to check the state of event. Type
156 EFI_EVENT is defined in CreateEvent() in
157 the Unified Extensible Firmware Interface
158 Specification.
159 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
160 APs to return from Procedure, either for
161 blocking or non-blocking mode. Zero means
162 infinity. If the timeout expires before
163 all APs return from Procedure, then Procedure
164 on the failed APs is terminated. All enabled
165 APs are available for next function assigned
166 by MpInitLibStartupAllAPs() or
167 MPInitLibStartupThisAP().
168 If the timeout expires in blocking mode,
169 BSP returns EFI_TIMEOUT. If the timeout
170 expires in non-blocking mode, WaitEvent
171 is signaled with SignalEvent().
172 @param[in] ProcedureArgument The parameter passed into Procedure for
173 all APs.
174 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
175 if all APs finish successfully, then its
176 content is set to NULL. If not all APs
177 finish before timeout expires, then its
178 content is set to address of the buffer
179 holding handle numbers of the failed APs.
180 The buffer is allocated by MP Initialization
181 library, and it's the caller's responsibility to
182 free the buffer with FreePool() service.
183 In blocking mode, it is ready for consumption
184 when the call returns. In non-blocking mode,
185 it is ready when WaitEvent is signaled. The
186 list of failed CPU is terminated by
187 END_OF_CPU_LIST.
188
189 @retval EFI_SUCCESS In blocking mode, all APs have finished before
190 the timeout expired.
191 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
192 to all enabled APs.
193 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
194 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
195 signaled.
196 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
197 supported.
198 @retval EFI_DEVICE_ERROR Caller processor is AP.
199 @retval EFI_NOT_STARTED No enabled APs exist in the system.
200 @retval EFI_NOT_READY Any enabled APs are busy.
201 @retval EFI_NOT_READY MP Initialize Library is not initialized.
202 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
203 all enabled APs have finished.
204 @retval EFI_INVALID_PARAMETER Procedure is NULL.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 MpInitLibStartupAllAPs (
210 IN EFI_AP_PROCEDURE Procedure,
211 IN BOOLEAN SingleThread,
212 IN EFI_EVENT WaitEvent OPTIONAL,
213 IN UINTN TimeoutInMicroseconds,
214 IN VOID *ProcedureArgument OPTIONAL,
215 OUT UINTN **FailedCpuList OPTIONAL
216 )
217 {
218 return EFI_NOT_STARTED;
219 }
220
221 /**
222 This service lets the caller get one enabled AP to execute a caller-provided
223 function.
224
225 @param[in] Procedure A pointer to the function to be run on the
226 designated AP of the system. See type
227 EFI_AP_PROCEDURE.
228 @param[in] ProcessorNumber The handle number of the AP. The range is
229 from 0 to the total number of logical
230 processors minus 1. The total number of
231 logical processors can be retrieved by
232 MpInitLibGetNumberOfProcessors().
233 @param[in] WaitEvent The event created by the caller with CreateEvent()
234 service. If it is NULL, then execute in
235 blocking mode. BSP waits until this AP finish
236 or TimeoutInMicroSeconds expires. If it's
237 not NULL, then execute in non-blocking mode.
238 BSP requests the function specified by
239 Procedure to be started on this AP,
240 and go on executing immediately. If this AP
241 return from Procedure or TimeoutInMicroSeconds
242 expires, this event is signaled. The BSP
243 can use the CheckEvent() or WaitForEvent()
244 services to check the state of event. Type
245 EFI_EVENT is defined in CreateEvent() in
246 the Unified Extensible Firmware Interface
247 Specification.
248 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
249 this AP to finish this Procedure, either for
250 blocking or non-blocking mode. Zero means
251 infinity. If the timeout expires before
252 this AP returns from Procedure, then Procedure
253 on the AP is terminated. The
254 AP is available for next function assigned
255 by MpInitLibStartupAllAPs() or
256 MpInitLibStartupThisAP().
257 If the timeout expires in blocking mode,
258 BSP returns EFI_TIMEOUT. If the timeout
259 expires in non-blocking mode, WaitEvent
260 is signaled with SignalEvent().
261 @param[in] ProcedureArgument The parameter passed into Procedure on the
262 specified AP.
263 @param[out] Finished If NULL, this parameter is ignored. In
264 blocking mode, this parameter is ignored.
265 In non-blocking mode, if AP returns from
266 Procedure before the timeout expires, its
267 content is set to TRUE. Otherwise, the
268 value is set to FALSE. The caller can
269 determine if the AP returned from Procedure
270 by evaluating this value.
271
272 @retval EFI_SUCCESS In blocking mode, specified AP finished before
273 the timeout expires.
274 @retval EFI_SUCCESS In non-blocking mode, the function has been
275 dispatched to specified AP.
276 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
277 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
278 signaled.
279 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
280 supported.
281 @retval EFI_DEVICE_ERROR The calling processor is an AP.
282 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
283 the specified AP has finished.
284 @retval EFI_NOT_READY The specified AP is busy.
285 @retval EFI_NOT_READY MP Initialize Library is not initialized.
286 @retval EFI_NOT_FOUND The processor with the handle specified by
287 ProcessorNumber does not exist.
288 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
289 @retval EFI_INVALID_PARAMETER Procedure is NULL.
290
291 **/
292 EFI_STATUS
293 EFIAPI
294 MpInitLibStartupThisAP (
295 IN EFI_AP_PROCEDURE Procedure,
296 IN UINTN ProcessorNumber,
297 IN EFI_EVENT WaitEvent OPTIONAL,
298 IN UINTN TimeoutInMicroseconds,
299 IN VOID *ProcedureArgument OPTIONAL,
300 OUT BOOLEAN *Finished OPTIONAL
301 )
302 {
303 return EFI_INVALID_PARAMETER;
304 }
305
306 /**
307 This service switches the requested AP to be the BSP from that point onward.
308 This service changes the BSP for all purposes. This call can only be performed
309 by the current BSP.
310
311 @param[in] ProcessorNumber The handle number of AP that is to become the new
312 BSP. The range is from 0 to the total number of
313 logical processors minus 1. The total number of
314 logical processors can be retrieved by
315 MpInitLibGetNumberOfProcessors().
316 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
317 enabled AP. Otherwise, it will be disabled.
318
319 @retval EFI_SUCCESS BSP successfully switched.
320 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
321 this service returning.
322 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
323 @retval EFI_DEVICE_ERROR The calling processor is an AP.
324 @retval EFI_NOT_FOUND The processor with the handle specified by
325 ProcessorNumber does not exist.
326 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
327 a disabled AP.
328 @retval EFI_NOT_READY The specified AP is busy.
329 @retval EFI_NOT_READY MP Initialize Library is not initialized.
330
331 **/
332 EFI_STATUS
333 EFIAPI
334 MpInitLibSwitchBSP (
335 IN UINTN ProcessorNumber,
336 IN BOOLEAN EnableOldBSP
337 )
338 {
339 return EFI_UNSUPPORTED;
340 }
341
342 /**
343 This service lets the caller enable or disable an AP from this point onward.
344 This service may only be called from the BSP.
345
346 @param[in] ProcessorNumber The handle number of AP.
347 The range is from 0 to the total number of
348 logical processors minus 1. The total number of
349 logical processors can be retrieved by
350 MpInitLibGetNumberOfProcessors().
351 @param[in] EnableAP Specifies the new state for the processor for
352 enabled, FALSE for disabled.
353 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
354 the new health status of the AP. This flag
355 corresponds to StatusFlag defined in
356 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
357 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
358 bits are ignored. If it is NULL, this parameter
359 is ignored.
360
361 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
362 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
363 prior to this service returning.
364 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
365 @retval EFI_DEVICE_ERROR The calling processor is an AP.
366 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
367 does not exist.
368 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
369 @retval EFI_NOT_READY MP Initialize Library is not initialized.
370
371 **/
372 EFI_STATUS
373 EFIAPI
374 MpInitLibEnableDisableAP (
375 IN UINTN ProcessorNumber,
376 IN BOOLEAN EnableAP,
377 IN UINT32 *HealthFlag OPTIONAL
378 )
379 {
380 return EFI_UNSUPPORTED;
381 }
382
383 /**
384 This return the handle number for the calling processor. This service may be
385 called from the BSP and APs.
386
387 @param[out] ProcessorNumber Pointer to the handle number of AP.
388 The range is from 0 to the total number of
389 logical processors minus 1. The total number of
390 logical processors can be retrieved by
391 MpInitLibGetNumberOfProcessors().
392
393 @retval EFI_SUCCESS The current processor handle number was returned
394 in ProcessorNumber.
395 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
396 @retval EFI_NOT_READY MP Initialize Library is not initialized.
397
398 **/
399 EFI_STATUS
400 EFIAPI
401 MpInitLibWhoAmI (
402 OUT UINTN *ProcessorNumber
403 )
404 {
405 if (ProcessorNumber == NULL) {
406 return EFI_INVALID_PARAMETER;
407 }
408
409 *ProcessorNumber = 0;
410 return EFI_SUCCESS;
411 }
412
413 /**
414 This service executes a caller provided function on all enabled CPUs.
415
416 @param[in] Procedure A pointer to the function to be run on
417 enabled APs of the system. See type
418 EFI_AP_PROCEDURE.
419 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
420 APs to return from Procedure, either for
421 blocking or non-blocking mode. Zero means
422 infinity. TimeoutInMicroseconds is ignored
423 for BSP.
424 @param[in] ProcedureArgument The parameter passed into Procedure for
425 all APs.
426
427 @retval EFI_SUCCESS CPU have finished the procedure.
428 @retval EFI_INVALID_PARAMETER Procedure is NULL.
429
430 **/
431 EFI_STATUS
432 EFIAPI
433 MpInitLibStartupAllCPUs (
434 IN EFI_AP_PROCEDURE Procedure,
435 IN UINTN TimeoutInMicroseconds,
436 IN VOID *ProcedureArgument OPTIONAL
437 )
438 {
439 if (Procedure == NULL) {
440 return EFI_INVALID_PARAMETER;
441 }
442
443 Procedure (ProcedureArgument);
444
445 return EFI_SUCCESS;
446 }