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