]>
Commit | Line | Data |
---|---|---|
3e8ad6bd JF |
1 | /** @file\r |
2 | MP initialize support functions for DXE phase.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "MpLib.h"\r | |
96378861 JF |
16 | \r |
17 | #include <Library/UefiLib.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | \r | |
20 | #define AP_CHECK_INTERVAL (EFI_TIMER_PERIOD_MILLISECONDS (100))\r | |
21 | \r | |
93ca4c0f | 22 | CPU_MP_DATA *mCpuMpData = NULL;\r |
96378861 JF |
23 | EFI_EVENT mCheckAllApsEvent = NULL;\r |
24 | volatile BOOLEAN mStopCheckAllApsStatus = TRUE;\r | |
25 | \r | |
93ca4c0f JF |
26 | \r |
27 | /**\r | |
28 | Get the pointer to CPU MP Data structure.\r | |
29 | \r | |
30 | @return The pointer to CPU MP Data structure.\r | |
31 | **/\r | |
32 | CPU_MP_DATA *\r | |
33 | GetCpuMpData (\r | |
34 | VOID\r | |
35 | )\r | |
36 | {\r | |
37 | ASSERT (mCpuMpData != NULL);\r | |
38 | return mCpuMpData;\r | |
39 | }\r | |
40 | \r | |
41 | /**\r | |
42 | Save the pointer to CPU MP Data structure.\r | |
43 | \r | |
44 | @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.\r | |
45 | **/\r | |
46 | VOID\r | |
47 | SaveCpuMpData (\r | |
48 | IN CPU_MP_DATA *CpuMpData\r | |
49 | )\r | |
50 | {\r | |
51 | mCpuMpData = CpuMpData;\r | |
52 | }\r | |
53 | \r | |
96378861 | 54 | /**\r |
ed66e0e3 JF |
55 | Allocate reset vector buffer.\r |
56 | \r | |
57 | @param[in, out] CpuMpData The pointer to CPU MP Data structure.\r | |
58 | **/\r | |
59 | VOID\r | |
60 | AllocateResetVector (\r | |
61 | IN OUT CPU_MP_DATA *CpuMpData\r | |
62 | )\r | |
63 | {\r | |
64 | EFI_STATUS Status;\r | |
65 | UINTN ApResetVectorSize;\r | |
66 | EFI_PHYSICAL_ADDRESS StartAddress;\r | |
67 | \r | |
68 | ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r | |
69 | sizeof (MP_CPU_EXCHANGE_INFO);\r | |
70 | \r | |
71 | StartAddress = BASE_1MB;\r | |
72 | Status = gBS->AllocatePages (\r | |
73 | AllocateMaxAddress,\r | |
74 | EfiACPIMemoryNVS,\r | |
75 | EFI_SIZE_TO_PAGES (ApResetVectorSize),\r | |
76 | &StartAddress\r | |
77 | );\r | |
78 | ASSERT_EFI_ERROR (Status);\r | |
79 | \r | |
80 | CpuMpData->WakeupBuffer = (UINTN) StartAddress;\r | |
81 | CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)\r | |
82 | (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize);\r | |
83 | //\r | |
84 | // copy AP reset code in it\r | |
85 | //\r | |
86 | CopyMem (\r | |
87 | (VOID *) CpuMpData->WakeupBuffer,\r | |
88 | (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,\r | |
89 | CpuMpData->AddressMap.RendezvousFunnelSize\r | |
90 | );\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
94 | Free AP reset vector buffer.\r | |
95 | \r | |
96 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r | |
97 | **/\r | |
98 | VOID\r | |
99 | FreeResetVector (\r | |
100 | IN CPU_MP_DATA *CpuMpData\r | |
101 | )\r | |
102 | {\r | |
103 | EFI_STATUS Status;\r | |
104 | UINTN ApResetVectorSize;\r | |
105 | ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r | |
106 | sizeof (MP_CPU_EXCHANGE_INFO);\r | |
107 | Status = gBS->FreePages(\r | |
108 | (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer,\r | |
109 | EFI_SIZE_TO_PAGES (ApResetVectorSize)\r | |
110 | );\r | |
111 | ASSERT_EFI_ERROR (Status);\r | |
112 | }\r | |
113 | \r | |
96378861 JF |
114 | /**\r |
115 | Checks APs status and updates APs status if needed.\r | |
116 | \r | |
117 | **/\r | |
118 | VOID\r | |
119 | CheckAndUpdateApsStatus (\r | |
120 | VOID\r | |
121 | )\r | |
122 | {\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | Checks APs' status periodically.\r | |
127 | \r | |
128 | This function is triggerred by timer perodically to check the\r | |
129 | state of APs for StartupAllAPs() and StartupThisAP() executed\r | |
130 | in non-blocking mode.\r | |
131 | \r | |
132 | @param[in] Event Event triggered.\r | |
133 | @param[in] Context Parameter passed with the event.\r | |
134 | \r | |
135 | **/\r | |
136 | VOID\r | |
137 | EFIAPI\r | |
138 | CheckApsStatus (\r | |
139 | IN EFI_EVENT Event,\r | |
140 | IN VOID *Context\r | |
141 | )\r | |
142 | {\r | |
143 | //\r | |
144 | // If CheckApsStatus() is not stopped, otherwise return immediately.\r | |
145 | //\r | |
146 | if (!mStopCheckAllApsStatus) {\r | |
147 | CheckAndUpdateApsStatus ();\r | |
148 | }\r | |
149 | }\r | |
ed66e0e3 | 150 | \r |
93ca4c0f JF |
151 | /**\r |
152 | Initialize global data for MP support.\r | |
153 | \r | |
154 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r | |
155 | **/\r | |
156 | VOID\r | |
157 | InitMpGlobalData (\r | |
158 | IN CPU_MP_DATA *CpuMpData\r | |
159 | )\r | |
160 | {\r | |
96378861 JF |
161 | EFI_STATUS Status;\r |
162 | \r | |
93ca4c0f JF |
163 | SaveCpuMpData (CpuMpData);\r |
164 | \r | |
96378861 JF |
165 | Status = gBS->CreateEvent (\r |
166 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
167 | TPL_NOTIFY,\r | |
168 | CheckApsStatus,\r | |
169 | NULL,\r | |
170 | &mCheckAllApsEvent\r | |
171 | );\r | |
172 | ASSERT_EFI_ERROR (Status);\r | |
173 | \r | |
174 | //\r | |
175 | // Set timer to check all APs status.\r | |
176 | //\r | |
177 | Status = gBS->SetTimer (\r | |
178 | mCheckAllApsEvent,\r | |
179 | TimerPeriodic,\r | |
180 | AP_CHECK_INTERVAL\r | |
181 | );\r | |
182 | ASSERT_EFI_ERROR (Status);\r | |
93ca4c0f | 183 | }\r |
3e8ad6bd JF |
184 | \r |
185 | /**\r | |
186 | This service executes a caller provided function on all enabled APs.\r | |
187 | \r | |
188 | @param[in] Procedure A pointer to the function to be run on\r | |
189 | enabled APs of the system. See type\r | |
190 | EFI_AP_PROCEDURE.\r | |
191 | @param[in] SingleThread If TRUE, then all the enabled APs execute\r | |
192 | the function specified by Procedure one by\r | |
193 | one, in ascending order of processor handle\r | |
194 | number. If FALSE, then all the enabled APs\r | |
195 | execute the function specified by Procedure\r | |
196 | simultaneously.\r | |
197 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
198 | service. If it is NULL, then execute in\r | |
199 | blocking mode. BSP waits until all APs finish\r | |
200 | or TimeoutInMicroSeconds expires. If it's\r | |
201 | not NULL, then execute in non-blocking mode.\r | |
202 | BSP requests the function specified by\r | |
203 | Procedure to be started on all the enabled\r | |
204 | APs, and go on executing immediately. If\r | |
205 | all return from Procedure, or TimeoutInMicroSeconds\r | |
206 | expires, this event is signaled. The BSP\r | |
207 | can use the CheckEvent() or WaitForEvent()\r | |
208 | services to check the state of event. Type\r | |
209 | EFI_EVENT is defined in CreateEvent() in\r | |
210 | the Unified Extensible Firmware Interface\r | |
211 | Specification.\r | |
212 | @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r | |
213 | APs to return from Procedure, either for\r | |
214 | blocking or non-blocking mode. Zero means\r | |
215 | infinity. If the timeout expires before\r | |
216 | all APs return from Procedure, then Procedure\r | |
217 | on the failed APs is terminated. All enabled\r | |
218 | APs are available for next function assigned\r | |
219 | by MpInitLibStartupAllAPs() or\r | |
220 | MPInitLibStartupThisAP().\r | |
221 | If the timeout expires in blocking mode,\r | |
222 | BSP returns EFI_TIMEOUT. If the timeout\r | |
223 | expires in non-blocking mode, WaitEvent\r | |
224 | is signaled with SignalEvent().\r | |
225 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
226 | all APs.\r | |
227 | @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r | |
228 | if all APs finish successfully, then its\r | |
229 | content is set to NULL. If not all APs\r | |
230 | finish before timeout expires, then its\r | |
231 | content is set to address of the buffer\r | |
232 | holding handle numbers of the failed APs.\r | |
233 | The buffer is allocated by MP Initialization\r | |
234 | library, and it's the caller's responsibility to\r | |
235 | free the buffer with FreePool() service.\r | |
236 | In blocking mode, it is ready for consumption\r | |
237 | when the call returns. In non-blocking mode,\r | |
238 | it is ready when WaitEvent is signaled. The\r | |
239 | list of failed CPU is terminated by\r | |
240 | END_OF_CPU_LIST.\r | |
241 | \r | |
242 | @retval EFI_SUCCESS In blocking mode, all APs have finished before\r | |
243 | the timeout expired.\r | |
244 | @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r | |
245 | to all enabled APs.\r | |
246 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
247 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
248 | signaled.\r | |
249 | @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r | |
250 | supported.\r | |
251 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
252 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
253 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
254 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
255 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
256 | all enabled APs have finished.\r | |
257 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
258 | \r | |
259 | **/\r | |
260 | EFI_STATUS\r | |
261 | EFIAPI\r | |
262 | MpInitLibStartupAllAPs (\r | |
263 | IN EFI_AP_PROCEDURE Procedure,\r | |
264 | IN BOOLEAN SingleThread,\r | |
265 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
266 | IN UINTN TimeoutInMicroseconds,\r | |
267 | IN VOID *ProcedureArgument OPTIONAL,\r | |
268 | OUT UINTN **FailedCpuList OPTIONAL\r | |
269 | )\r | |
270 | {\r | |
271 | return EFI_UNSUPPORTED;\r | |
272 | }\r | |
273 | \r | |
274 | /**\r | |
275 | This service lets the caller get one enabled AP to execute a caller-provided\r | |
276 | function.\r | |
277 | \r | |
278 | @param[in] Procedure A pointer to the function to be run on the\r | |
279 | designated AP of the system. See type\r | |
280 | EFI_AP_PROCEDURE.\r | |
281 | @param[in] ProcessorNumber The handle number of the AP. The range is\r | |
282 | from 0 to the total number of logical\r | |
283 | processors minus 1. The total number of\r | |
284 | logical processors can be retrieved by\r | |
285 | MpInitLibGetNumberOfProcessors().\r | |
286 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
287 | service. If it is NULL, then execute in\r | |
288 | blocking mode. BSP waits until this AP finish\r | |
289 | or TimeoutInMicroSeconds expires. If it's\r | |
290 | not NULL, then execute in non-blocking mode.\r | |
291 | BSP requests the function specified by\r | |
292 | Procedure to be started on this AP,\r | |
293 | and go on executing immediately. If this AP\r | |
294 | return from Procedure or TimeoutInMicroSeconds\r | |
295 | expires, this event is signaled. The BSP\r | |
296 | can use the CheckEvent() or WaitForEvent()\r | |
297 | services to check the state of event. Type\r | |
298 | EFI_EVENT is defined in CreateEvent() in\r | |
299 | the Unified Extensible Firmware Interface\r | |
300 | Specification.\r | |
301 | @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r | |
302 | this AP to finish this Procedure, either for\r | |
303 | blocking or non-blocking mode. Zero means\r | |
304 | infinity. If the timeout expires before\r | |
305 | this AP returns from Procedure, then Procedure\r | |
306 | on the AP is terminated. The\r | |
307 | AP is available for next function assigned\r | |
308 | by MpInitLibStartupAllAPs() or\r | |
309 | MpInitLibStartupThisAP().\r | |
310 | If the timeout expires in blocking mode,\r | |
311 | BSP returns EFI_TIMEOUT. If the timeout\r | |
312 | expires in non-blocking mode, WaitEvent\r | |
313 | is signaled with SignalEvent().\r | |
314 | @param[in] ProcedureArgument The parameter passed into Procedure on the\r | |
315 | specified AP.\r | |
316 | @param[out] Finished If NULL, this parameter is ignored. In\r | |
317 | blocking mode, this parameter is ignored.\r | |
318 | In non-blocking mode, if AP returns from\r | |
319 | Procedure before the timeout expires, its\r | |
320 | content is set to TRUE. Otherwise, the\r | |
321 | value is set to FALSE. The caller can\r | |
322 | determine if the AP returned from Procedure\r | |
323 | by evaluating this value.\r | |
324 | \r | |
325 | @retval EFI_SUCCESS In blocking mode, specified AP finished before\r | |
326 | the timeout expires.\r | |
327 | @retval EFI_SUCCESS In non-blocking mode, the function has been\r | |
328 | dispatched to specified AP.\r | |
329 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
330 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
331 | signaled.\r | |
332 | @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r | |
333 | supported.\r | |
334 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
335 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
336 | the specified AP has finished.\r | |
337 | @retval EFI_NOT_READY The specified AP is busy.\r | |
338 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
339 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
340 | ProcessorNumber does not exist.\r | |
341 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
342 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
343 | \r | |
344 | **/\r | |
345 | EFI_STATUS\r | |
346 | EFIAPI\r | |
347 | MpInitLibStartupThisAP (\r | |
348 | IN EFI_AP_PROCEDURE Procedure,\r | |
349 | IN UINTN ProcessorNumber,\r | |
350 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
351 | IN UINTN TimeoutInMicroseconds,\r | |
352 | IN VOID *ProcedureArgument OPTIONAL,\r | |
353 | OUT BOOLEAN *Finished OPTIONAL\r | |
354 | )\r | |
355 | {\r | |
356 | return EFI_UNSUPPORTED;\r | |
357 | }\r | |
358 | \r | |
359 | /**\r | |
360 | This service switches the requested AP to be the BSP from that point onward.\r | |
361 | This service changes the BSP for all purposes. This call can only be performed\r | |
362 | by the current BSP.\r | |
363 | \r | |
364 | @param[in] ProcessorNumber The handle number of AP that is to become the new\r | |
365 | BSP. The range is from 0 to the total number of\r | |
366 | logical processors minus 1. The total number of\r | |
367 | logical processors can be retrieved by\r | |
368 | MpInitLibGetNumberOfProcessors().\r | |
369 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r | |
370 | enabled AP. Otherwise, it will be disabled.\r | |
371 | \r | |
372 | @retval EFI_SUCCESS BSP successfully switched.\r | |
373 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r | |
374 | this service returning.\r | |
375 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
376 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
377 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
378 | ProcessorNumber does not exist.\r | |
379 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r | |
380 | a disabled AP.\r | |
381 | @retval EFI_NOT_READY The specified AP is busy.\r | |
382 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
383 | \r | |
384 | **/\r | |
385 | EFI_STATUS\r | |
386 | EFIAPI\r | |
387 | MpInitLibSwitchBSP (\r | |
388 | IN UINTN ProcessorNumber,\r | |
389 | IN BOOLEAN EnableOldBSP\r | |
390 | )\r | |
391 | {\r | |
41be0da5 JF |
392 | EFI_STATUS Status;\r |
393 | BOOLEAN OldInterruptState;\r | |
394 | \r | |
395 | //\r | |
396 | // Before send both BSP and AP to a procedure to exchange their roles,\r | |
397 | // interrupt must be disabled. This is because during the exchange role\r | |
398 | // process, 2 CPU may use 1 stack. If interrupt happens, the stack will\r | |
399 | // be corrupted, since interrupt return address will be pushed to stack\r | |
400 | // by hardware.\r | |
401 | //\r | |
402 | OldInterruptState = SaveAndDisableInterrupts ();\r | |
403 | \r | |
404 | //\r | |
405 | // Mask LINT0 & LINT1 for the old BSP\r | |
406 | //\r | |
407 | DisableLvtInterrupts ();\r | |
408 | \r | |
409 | Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);\r | |
410 | \r | |
411 | //\r | |
412 | // Restore interrupt state.\r | |
413 | //\r | |
414 | SetInterruptState (OldInterruptState);\r | |
415 | \r | |
416 | return Status;\r | |
3e8ad6bd JF |
417 | }\r |
418 | \r | |
419 | /**\r | |
420 | This service lets the caller enable or disable an AP from this point onward.\r | |
421 | This service may only be called from the BSP.\r | |
422 | \r | |
423 | @param[in] ProcessorNumber The handle number of AP.\r | |
424 | The range is from 0 to the total number of\r | |
425 | logical processors minus 1. The total number of\r | |
426 | logical processors can be retrieved by\r | |
427 | MpInitLibGetNumberOfProcessors().\r | |
428 | @param[in] EnableAP Specifies the new state for the processor for\r | |
429 | enabled, FALSE for disabled.\r | |
430 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r | |
431 | the new health status of the AP. This flag\r | |
432 | corresponds to StatusFlag defined in\r | |
433 | EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r | |
434 | the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
435 | bits are ignored. If it is NULL, this parameter\r | |
436 | is ignored.\r | |
437 | \r | |
438 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
439 | @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r | |
440 | prior to this service returning.\r | |
441 | @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r | |
442 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
443 | @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r | |
444 | does not exist.\r | |
445 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r | |
446 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
447 | \r | |
448 | **/\r | |
449 | EFI_STATUS\r | |
450 | EFIAPI\r | |
451 | MpInitLibEnableDisableAP (\r | |
452 | IN UINTN ProcessorNumber,\r | |
453 | IN BOOLEAN EnableAP,\r | |
454 | IN UINT32 *HealthFlag OPTIONAL\r | |
455 | )\r | |
456 | {\r | |
e37109bc JF |
457 | EFI_STATUS Status;\r |
458 | BOOLEAN TempStopCheckState;\r | |
459 | \r | |
460 | TempStopCheckState = FALSE;\r | |
461 | //\r | |
462 | // temporarily stop checkAllAPsStatus for initialize parameters.\r | |
463 | //\r | |
464 | if (!mStopCheckAllApsStatus) {\r | |
465 | mStopCheckAllApsStatus = TRUE;\r | |
466 | TempStopCheckState = TRUE;\r | |
467 | }\r | |
468 | \r | |
469 | Status = EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);\r | |
470 | \r | |
471 | if (TempStopCheckState) {\r | |
472 | mStopCheckAllApsStatus = FALSE;\r | |
473 | }\r | |
474 | \r | |
475 | return Status;\r | |
3e8ad6bd | 476 | }\r |