]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
UefiCpuPkg/MpInitLib: Register one period event to check APs status
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / PeiMpLib.c
1 /** @file
2 MP initialize support functions for PEI phase.
3
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "MpLib.h"
16 #include <Ppi/EndOfPeiPhase.h>
17 #include <Library/PeiServicesLib.h>
18
19 //
20 // Global PEI notify function descriptor on EndofPei event
21 //
22 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMpInitLibNotifyList = {
23 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
24 &gEfiEndOfPeiSignalPpiGuid,
25 CpuMpEndOfPeiCallback
26 };
27
28 /**
29 Get pointer to CPU MP Data structure.
30
31 @return The pointer to CPU MP Data structure.
32 **/
33 CPU_MP_DATA *
34 GetCpuMpData (
35 VOID
36 )
37 {
38 CPU_MP_DATA *CpuMpData;
39
40 CpuMpData = GetCpuMpDataFromGuidedHob ();
41 ASSERT (CpuMpData != NULL);
42 return CpuMpData;
43 }
44
45 /**
46 Save the pointer to CPU MP Data structure.
47
48 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
49 **/
50 VOID
51 SaveCpuMpData (
52 IN CPU_MP_DATA *CpuMpData
53 )
54 {
55 UINT64 Data64;
56 //
57 // Build location of CPU MP DATA buffer in HOB
58 //
59 Data64 = (UINT64) (UINTN) CpuMpData;
60 BuildGuidDataHob (
61 &mCpuInitMpLibHobGuid,
62 (VOID *) &Data64,
63 sizeof (UINT64)
64 );
65 }
66
67
68 /**
69 /**
70 Notify function on End Of PEI PPI.
71
72 On S3 boot, this function will restore wakeup buffer data.
73 On normal boot, this function will flag wakeup buffer to be un-used type.
74
75 @param[in] PeiServices The pointer to the PEI Services Table.
76 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
77 @param[in] Ppi Address of the PPI that was installed.
78
79 @retval EFI_SUCCESS When everything is OK.
80 **/
81 EFI_STATUS
82 EFIAPI
83 CpuMpEndOfPeiCallback (
84 IN EFI_PEI_SERVICES **PeiServices,
85 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
86 IN VOID *Ppi
87 )
88 {
89
90 DEBUG ((DEBUG_INFO, "PeiMpInitLib: CpuMpEndOfPeiCallback () invoked\n"));
91
92 return EFI_SUCCESS;
93 }
94 /**
95 Initialize global data for MP support.
96
97 @param[in] CpuMpData The pointer to CPU MP Data structure.
98 **/
99 VOID
100 InitMpGlobalData (
101 IN CPU_MP_DATA *CpuMpData
102 )
103 {
104 EFI_STATUS Status;
105
106 SaveCpuMpData (CpuMpData);
107 //
108 // Register an event for EndOfPei
109 //
110 Status = PeiServicesNotifyPpi (&mMpInitLibNotifyList);
111 ASSERT_EFI_ERROR (Status);
112 }
113
114 /**
115 This service executes a caller provided function on all enabled APs.
116
117 @param[in] Procedure A pointer to the function to be run on
118 enabled APs of the system. See type
119 EFI_AP_PROCEDURE.
120 @param[in] SingleThread If TRUE, then all the enabled APs execute
121 the function specified by Procedure one by
122 one, in ascending order of processor handle
123 number. If FALSE, then all the enabled APs
124 execute the function specified by Procedure
125 simultaneously.
126 @param[in] WaitEvent The event created by the caller with CreateEvent()
127 service. If it is NULL, then execute in
128 blocking mode. BSP waits until all APs finish
129 or TimeoutInMicroSeconds expires. If it's
130 not NULL, then execute in non-blocking mode.
131 BSP requests the function specified by
132 Procedure to be started on all the enabled
133 APs, and go on executing immediately. If
134 all return from Procedure, or TimeoutInMicroSeconds
135 expires, this event is signaled. The BSP
136 can use the CheckEvent() or WaitForEvent()
137 services to check the state of event. Type
138 EFI_EVENT is defined in CreateEvent() in
139 the Unified Extensible Firmware Interface
140 Specification.
141 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
142 APs to return from Procedure, either for
143 blocking or non-blocking mode. Zero means
144 infinity. If the timeout expires before
145 all APs return from Procedure, then Procedure
146 on the failed APs is terminated. All enabled
147 APs are available for next function assigned
148 by MpInitLibStartupAllAPs() or
149 MPInitLibStartupThisAP().
150 If the timeout expires in blocking mode,
151 BSP returns EFI_TIMEOUT. If the timeout
152 expires in non-blocking mode, WaitEvent
153 is signaled with SignalEvent().
154 @param[in] ProcedureArgument The parameter passed into Procedure for
155 all APs.
156 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
157 if all APs finish successfully, then its
158 content is set to NULL. If not all APs
159 finish before timeout expires, then its
160 content is set to address of the buffer
161 holding handle numbers of the failed APs.
162 The buffer is allocated by MP Initialization
163 library, and it's the caller's responsibility to
164 free the buffer with FreePool() service.
165 In blocking mode, it is ready for consumption
166 when the call returns. In non-blocking mode,
167 it is ready when WaitEvent is signaled. The
168 list of failed CPU is terminated by
169 END_OF_CPU_LIST.
170
171 @retval EFI_SUCCESS In blocking mode, all APs have finished before
172 the timeout expired.
173 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
174 to all enabled APs.
175 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
176 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
177 signaled.
178 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
179 supported.
180 @retval EFI_DEVICE_ERROR Caller processor is AP.
181 @retval EFI_NOT_STARTED No enabled APs exist in the system.
182 @retval EFI_NOT_READY Any enabled APs are busy.
183 @retval EFI_NOT_READY MP Initialize Library is not initialized.
184 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
185 all enabled APs have finished.
186 @retval EFI_INVALID_PARAMETER Procedure is NULL.
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 MpInitLibStartupAllAPs (
192 IN EFI_AP_PROCEDURE Procedure,
193 IN BOOLEAN SingleThread,
194 IN EFI_EVENT WaitEvent OPTIONAL,
195 IN UINTN TimeoutInMicroseconds,
196 IN VOID *ProcedureArgument OPTIONAL,
197 OUT UINTN **FailedCpuList OPTIONAL
198 )
199 {
200 return EFI_UNSUPPORTED;
201 }
202
203 /**
204 This service lets the caller get one enabled AP to execute a caller-provided
205 function.
206
207 @param[in] Procedure A pointer to the function to be run on the
208 designated AP of the system. See type
209 EFI_AP_PROCEDURE.
210 @param[in] ProcessorNumber The handle number of the AP. The range is
211 from 0 to the total number of logical
212 processors minus 1. The total number of
213 logical processors can be retrieved by
214 MpInitLibGetNumberOfProcessors().
215 @param[in] WaitEvent The event created by the caller with CreateEvent()
216 service. If it is NULL, then execute in
217 blocking mode. BSP waits until this AP finish
218 or TimeoutInMicroSeconds expires. If it's
219 not NULL, then execute in non-blocking mode.
220 BSP requests the function specified by
221 Procedure to be started on this AP,
222 and go on executing immediately. If this AP
223 return from Procedure or TimeoutInMicroSeconds
224 expires, this event is signaled. The BSP
225 can use the CheckEvent() or WaitForEvent()
226 services to check the state of event. Type
227 EFI_EVENT is defined in CreateEvent() in
228 the Unified Extensible Firmware Interface
229 Specification.
230 @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for
231 this AP to finish this Procedure, either for
232 blocking or non-blocking mode. Zero means
233 infinity. If the timeout expires before
234 this AP returns from Procedure, then Procedure
235 on the AP is terminated. The
236 AP is available for next function assigned
237 by MpInitLibStartupAllAPs() or
238 MpInitLibStartupThisAP().
239 If the timeout expires in blocking mode,
240 BSP returns EFI_TIMEOUT. If the timeout
241 expires in non-blocking mode, WaitEvent
242 is signaled with SignalEvent().
243 @param[in] ProcedureArgument The parameter passed into Procedure on the
244 specified AP.
245 @param[out] Finished If NULL, this parameter is ignored. In
246 blocking mode, this parameter is ignored.
247 In non-blocking mode, if AP returns from
248 Procedure before the timeout expires, its
249 content is set to TRUE. Otherwise, the
250 value is set to FALSE. The caller can
251 determine if the AP returned from Procedure
252 by evaluating this value.
253
254 @retval EFI_SUCCESS In blocking mode, specified AP finished before
255 the timeout expires.
256 @retval EFI_SUCCESS In non-blocking mode, the function has been
257 dispatched to specified AP.
258 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
259 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
260 signaled.
261 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
262 supported.
263 @retval EFI_DEVICE_ERROR The calling processor is an AP.
264 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
265 the specified AP has finished.
266 @retval EFI_NOT_READY The specified AP is busy.
267 @retval EFI_NOT_READY MP Initialize Library is not initialized.
268 @retval EFI_NOT_FOUND The processor with the handle specified by
269 ProcessorNumber does not exist.
270 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
271 @retval EFI_INVALID_PARAMETER Procedure is NULL.
272
273 **/
274 EFI_STATUS
275 EFIAPI
276 MpInitLibStartupThisAP (
277 IN EFI_AP_PROCEDURE Procedure,
278 IN UINTN ProcessorNumber,
279 IN EFI_EVENT WaitEvent OPTIONAL,
280 IN UINTN TimeoutInMicroseconds,
281 IN VOID *ProcedureArgument OPTIONAL,
282 OUT BOOLEAN *Finished OPTIONAL
283 )
284 {
285 return EFI_UNSUPPORTED;
286 }
287
288 /**
289 This service switches the requested AP to be the BSP from that point onward.
290 This service changes the BSP for all purposes. This call can only be performed
291 by the current BSP.
292
293 @param[in] ProcessorNumber The handle number of AP that is to become the new
294 BSP. The range is from 0 to the total number of
295 logical processors minus 1. The total number of
296 logical processors can be retrieved by
297 MpInitLibGetNumberOfProcessors().
298 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
299 enabled AP. Otherwise, it will be disabled.
300
301 @retval EFI_SUCCESS BSP successfully switched.
302 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
303 this service returning.
304 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
305 @retval EFI_DEVICE_ERROR The calling processor is an AP.
306 @retval EFI_NOT_FOUND The processor with the handle specified by
307 ProcessorNumber does not exist.
308 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
309 a disabled AP.
310 @retval EFI_NOT_READY The specified AP is busy.
311 @retval EFI_NOT_READY MP Initialize Library is not initialized.
312
313 **/
314 EFI_STATUS
315 EFIAPI
316 MpInitLibSwitchBSP (
317 IN UINTN ProcessorNumber,
318 IN BOOLEAN EnableOldBSP
319 )
320 {
321 return EFI_UNSUPPORTED;
322 }
323
324 /**
325 This service lets the caller enable or disable an AP from this point onward.
326 This service may only be called from the BSP.
327
328 @param[in] ProcessorNumber The handle number of AP.
329 The range is from 0 to the total number of
330 logical processors minus 1. The total number of
331 logical processors can be retrieved by
332 MpInitLibGetNumberOfProcessors().
333 @param[in] EnableAP Specifies the new state for the processor for
334 enabled, FALSE for disabled.
335 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
336 the new health status of the AP. This flag
337 corresponds to StatusFlag defined in
338 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
339 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
340 bits are ignored. If it is NULL, this parameter
341 is ignored.
342
343 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
344 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
345 prior to this service returning.
346 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
347 @retval EFI_DEVICE_ERROR The calling processor is an AP.
348 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
349 does not exist.
350 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
351 @retval EFI_NOT_READY MP Initialize Library is not initialized.
352
353 **/
354 EFI_STATUS
355 EFIAPI
356 MpInitLibEnableDisableAP (
357 IN UINTN ProcessorNumber,
358 IN BOOLEAN EnableAP,
359 IN UINT32 *HealthFlag OPTIONAL
360 )
361 {
362 return EFI_UNSUPPORTED;
363 }
364
365