]>
Commit | Line | Data |
---|---|---|
6022e28c JJ |
1 | /** @file\r |
2 | CPU DXE Module.\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2014, 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 "CpuDxe.h"\r | |
16 | #include "CpuMp.h"\r | |
17 | \r | |
6a26a597 CF |
18 | UINTN gMaxLogicalProcessorNumber;\r |
19 | UINTN gApStackSize;\r | |
3f4f0af8 | 20 | UINTN gPollInterval = 100; // 100 microseconds\r |
6a26a597 | 21 | \r |
03673ae1 CF |
22 | MP_SYSTEM_DATA mMpSystemData;\r |
23 | \r | |
fab82c18 JJ |
24 | VOID *mCommonStack = 0;\r |
25 | VOID *mTopOfApCommonStack = 0;\r | |
6a26a597 | 26 | VOID *mApStackStart = 0;\r |
fab82c18 | 27 | \r |
acb2172d CF |
28 | volatile BOOLEAN mStopCheckAllAPsStatus = TRUE;\r |
29 | \r | |
003973d9 | 30 | EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {\r |
d894d8b7 | 31 | GetNumberOfProcessors,\r |
e7938b5a | 32 | GetProcessorInfo,\r |
5fee172f | 33 | StartupAllAPs,\r |
3f4f0af8 | 34 | StartupThisAP,\r |
b7c05ba5 | 35 | SwitchBSP,\r |
fa7ce675 | 36 | EnableDisableAP,\r |
cfa2fac1 | 37 | WhoAmI\r |
003973d9 CF |
38 | };\r |
39 | \r | |
d894d8b7 CF |
40 | /**\r |
41 | Check whether caller processor is BSP.\r | |
42 | \r | |
43 | @retval TRUE the caller is BSP\r | |
44 | @retval FALSE the caller is AP\r | |
45 | \r | |
46 | **/\r | |
47 | BOOLEAN\r | |
48 | IsBSP (\r | |
49 | VOID\r | |
50 | )\r | |
51 | {\r | |
52 | UINTN CpuIndex;\r | |
53 | CPU_DATA_BLOCK *CpuData;\r | |
54 | \r | |
55 | CpuData = NULL;\r | |
56 | \r | |
57 | WhoAmI (&mMpServicesTemplate, &CpuIndex);\r | |
58 | CpuData = &mMpSystemData.CpuDatas[CpuIndex];\r | |
59 | \r | |
60 | return CpuData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT ? TRUE : FALSE;\r | |
61 | }\r | |
62 | \r | |
fa7ce675 CF |
63 | /**\r |
64 | Get the Application Processors state.\r | |
65 | \r | |
66 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
67 | \r | |
68 | @retval CPU_STATE the AP status\r | |
69 | \r | |
70 | **/\r | |
71 | CPU_STATE\r | |
72 | GetApState (\r | |
73 | IN CPU_DATA_BLOCK *CpuData\r | |
74 | )\r | |
75 | {\r | |
76 | CPU_STATE State;\r | |
77 | \r | |
78 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
79 | CpuPause ();\r | |
80 | }\r | |
81 | \r | |
82 | State = CpuData->State;\r | |
83 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
84 | \r | |
85 | return State;\r | |
86 | }\r | |
87 | \r | |
3f4f0af8 CF |
88 | /**\r |
89 | Set the Application Processors state.\r | |
90 | \r | |
91 | @param CpuData The pointer to CPU_DATA_BLOCK of specified AP\r | |
92 | @param State The AP status\r | |
93 | \r | |
94 | **/\r | |
95 | VOID\r | |
96 | SetApState (\r | |
97 | IN CPU_DATA_BLOCK *CpuData,\r | |
98 | IN CPU_STATE State\r | |
99 | )\r | |
100 | {\r | |
101 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
102 | CpuPause ();\r | |
103 | }\r | |
104 | \r | |
105 | CpuData->State = State;\r | |
106 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
107 | }\r | |
108 | \r | |
109 | /**\r | |
110 | Set the Application Processor prepare to run a function specified\r | |
111 | by Params.\r | |
112 | \r | |
113 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
114 | @param Procedure A pointer to the function to be run on enabled APs of the system\r | |
115 | @param ProcedureArgument Pointer to the optional parameter of the assigned function\r | |
116 | \r | |
117 | **/\r | |
118 | VOID\r | |
119 | SetApProcedure (\r | |
120 | IN CPU_DATA_BLOCK *CpuData,\r | |
121 | IN EFI_AP_PROCEDURE Procedure,\r | |
122 | IN VOID *ProcedureArgument\r | |
123 | )\r | |
124 | {\r | |
125 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
126 | CpuPause ();\r | |
127 | }\r | |
128 | \r | |
129 | CpuData->Parameter = ProcedureArgument;\r | |
130 | CpuData->Procedure = Procedure;\r | |
131 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
132 | }\r | |
133 | \r | |
fa7ce675 CF |
134 | /**\r |
135 | Check the Application Processors Status whether contains the Flags.\r | |
136 | \r | |
137 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
138 | @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r | |
139 | \r | |
140 | @retval TRUE the AP status includes the StatusFlag\r | |
141 | @retval FALSE the AP status excludes the StatusFlag\r | |
142 | \r | |
143 | **/\r | |
144 | BOOLEAN\r | |
145 | TestCpuStatusFlag (\r | |
146 | IN CPU_DATA_BLOCK *CpuData,\r | |
147 | IN UINT32 Flags\r | |
148 | )\r | |
149 | {\r | |
150 | UINT32 Ret;\r | |
151 | \r | |
152 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
153 | CpuPause ();\r | |
154 | }\r | |
155 | \r | |
156 | Ret = CpuData->Info.StatusFlag & Flags;\r | |
157 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
158 | \r | |
159 | return !!(Ret);\r | |
160 | }\r | |
161 | \r | |
162 | /**\r | |
163 | Bitwise-Or of the Application Processors Status with the Flags.\r | |
164 | \r | |
165 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
166 | @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r | |
167 | \r | |
168 | **/\r | |
169 | VOID\r | |
170 | CpuStatusFlagOr (\r | |
171 | IN CPU_DATA_BLOCK *CpuData,\r | |
172 | IN UINT32 Flags\r | |
173 | )\r | |
174 | {\r | |
175 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
176 | CpuPause ();\r | |
177 | }\r | |
178 | \r | |
179 | CpuData->Info.StatusFlag |= Flags;\r | |
180 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
181 | }\r | |
182 | \r | |
183 | /**\r | |
184 | Bitwise-AndNot of the Application Processors Status with the Flags.\r | |
185 | \r | |
186 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
187 | @param Flags the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r | |
188 | \r | |
189 | **/\r | |
190 | VOID\r | |
191 | CpuStatusFlagAndNot (\r | |
192 | IN CPU_DATA_BLOCK *CpuData,\r | |
193 | IN UINT32 Flags\r | |
194 | )\r | |
195 | {\r | |
196 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
197 | CpuPause ();\r | |
198 | }\r | |
199 | \r | |
200 | CpuData->Info.StatusFlag &= ~Flags;\r | |
201 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
202 | }\r | |
203 | \r | |
3f4f0af8 CF |
204 | /**\r |
205 | Searches for the next blocking AP.\r | |
206 | \r | |
207 | Search for the next AP that is put in blocking state by single-threaded StartupAllAPs().\r | |
208 | \r | |
209 | @param NextNumber Pointer to the processor number of the next blocking AP.\r | |
210 | \r | |
211 | @retval EFI_SUCCESS The next blocking AP has been found.\r | |
212 | @retval EFI_NOT_FOUND No blocking AP exists.\r | |
213 | \r | |
214 | **/\r | |
215 | EFI_STATUS\r | |
216 | GetNextBlockedNumber (\r | |
217 | OUT UINTN *NextNumber\r | |
218 | )\r | |
219 | {\r | |
220 | UINTN Number;\r | |
221 | CPU_STATE CpuState;\r | |
222 | CPU_DATA_BLOCK *CpuData;\r | |
223 | \r | |
224 | for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r | |
225 | CpuData = &mMpSystemData.CpuDatas[Number];\r | |
226 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
227 | //\r | |
228 | // Skip BSP\r | |
229 | //\r | |
230 | continue;\r | |
231 | }\r | |
232 | \r | |
233 | CpuState = GetApState (CpuData);\r | |
234 | if (CpuState == CpuStateBlocked) {\r | |
235 | *NextNumber = Number;\r | |
236 | return EFI_SUCCESS;\r | |
237 | }\r | |
238 | }\r | |
239 | \r | |
240 | return EFI_NOT_FOUND;\r | |
241 | }\r | |
242 | \r | |
5fee172f CF |
243 | /**\r |
244 | Check if the APs state are finished, and update them to idle state\r | |
245 | by StartupAllAPs().\r | |
246 | \r | |
247 | **/\r | |
248 | VOID\r | |
249 | CheckAndUpdateAllAPsToIdleState (\r | |
250 | VOID\r | |
251 | )\r | |
252 | {\r | |
253 | UINTN ProcessorNumber;\r | |
254 | UINTN NextNumber;\r | |
255 | CPU_DATA_BLOCK *CpuData;\r | |
256 | EFI_STATUS Status;\r | |
257 | CPU_STATE CpuState;\r | |
258 | \r | |
259 | for (ProcessorNumber = 0; ProcessorNumber < mMpSystemData.NumberOfProcessors; ProcessorNumber++) {\r | |
260 | CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r | |
261 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
262 | //\r | |
263 | // Skip BSP\r | |
264 | //\r | |
265 | continue;\r | |
266 | }\r | |
267 | \r | |
268 | if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
269 | //\r | |
270 | // Skip Disabled processors\r | |
271 | //\r | |
272 | continue;\r | |
273 | }\r | |
274 | \r | |
275 | CpuState = GetApState (CpuData);\r | |
276 | if (CpuState == CpuStateFinished) {\r | |
277 | mMpSystemData.FinishCount++;\r | |
278 | if (mMpSystemData.SingleThread) {\r | |
279 | Status = GetNextBlockedNumber (&NextNumber);\r | |
280 | if (!EFI_ERROR (Status)) {\r | |
281 | SetApState (&mMpSystemData.CpuDatas[NextNumber], CpuStateReady);\r | |
282 | SetApProcedure (&mMpSystemData.CpuDatas[NextNumber],\r | |
283 | mMpSystemData.Procedure,\r | |
284 | mMpSystemData.ProcedureArgument);\r | |
285 | }\r | |
286 | }\r | |
287 | \r | |
288 | SetApState (CpuData, CpuStateIdle);\r | |
289 | }\r | |
290 | }\r | |
291 | }\r | |
292 | \r | |
293 | /**\r | |
294 | If the timeout expires before all APs returns from Procedure,\r | |
295 | we should forcibly terminate the executing AP and fill FailedList back\r | |
296 | by StartupAllAPs().\r | |
297 | \r | |
298 | **/\r | |
299 | VOID\r | |
300 | ResetAllFailedAPs (\r | |
301 | VOID\r | |
302 | )\r | |
303 | {\r | |
304 | CPU_DATA_BLOCK *CpuData;\r | |
305 | UINTN Number;\r | |
306 | CPU_STATE CpuState;\r | |
307 | \r | |
308 | if (mMpSystemData.FailedList != NULL) {\r | |
309 | *mMpSystemData.FailedList = AllocatePool ((mMpSystemData.StartCount - mMpSystemData.FinishCount + 1) * sizeof(UINTN));\r | |
310 | ASSERT (*mMpSystemData.FailedList != NULL);\r | |
311 | }\r | |
312 | \r | |
313 | for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r | |
314 | CpuData = &mMpSystemData.CpuDatas[Number];\r | |
315 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
316 | //\r | |
317 | // Skip BSP\r | |
318 | //\r | |
319 | continue;\r | |
320 | }\r | |
321 | \r | |
322 | if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
323 | //\r | |
324 | // Skip Disabled processors\r | |
325 | //\r | |
326 | continue;\r | |
327 | }\r | |
328 | \r | |
329 | CpuState = GetApState (CpuData);\r | |
330 | if (CpuState != CpuStateIdle) {\r | |
331 | if (mMpSystemData.FailedList != NULL) {\r | |
332 | (*mMpSystemData.FailedList)[mMpSystemData.FailedListIndex++] = Number;\r | |
333 | }\r | |
334 | ResetProcessorToIdleState (CpuData);\r | |
335 | }\r | |
336 | }\r | |
337 | \r | |
338 | if (mMpSystemData.FailedList != NULL) {\r | |
339 | (*mMpSystemData.FailedList)[mMpSystemData.FailedListIndex] = END_OF_CPU_LIST;\r | |
340 | }\r | |
341 | }\r | |
342 | \r | |
d894d8b7 CF |
343 | /**\r |
344 | This service retrieves the number of logical processor in the platform\r | |
345 | and the number of those logical processors that are enabled on this boot.\r | |
346 | This service may only be called from the BSP.\r | |
347 | \r | |
348 | This function is used to retrieve the following information:\r | |
349 | - The number of logical processors that are present in the system.\r | |
350 | - The number of enabled logical processors in the system at the instant\r | |
351 | this call is made.\r | |
352 | \r | |
353 | Because MP Service Protocol provides services to enable and disable processors\r | |
354 | dynamically, the number of enabled logical processors may vary during the\r | |
355 | course of a boot session.\r | |
356 | \r | |
357 | If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r | |
358 | If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r | |
359 | EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r | |
360 | is returned in NumberOfProcessors, the number of currently enabled processor\r | |
361 | is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r | |
362 | \r | |
363 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r | |
364 | instance.\r | |
365 | @param[out] NumberOfProcessors Pointer to the total number of logical\r | |
366 | processors in the system, including the BSP\r | |
367 | and disabled APs.\r | |
368 | @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical\r | |
369 | processors that exist in system, including\r | |
370 | the BSP.\r | |
371 | \r | |
372 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
373 | logical processors was retrieved.\r | |
374 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
375 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r | |
376 | @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.\r | |
377 | \r | |
378 | **/\r | |
379 | EFI_STATUS\r | |
380 | EFIAPI\r | |
381 | GetNumberOfProcessors (\r | |
382 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
383 | OUT UINTN *NumberOfProcessors,\r | |
384 | OUT UINTN *NumberOfEnabledProcessors\r | |
385 | )\r | |
386 | {\r | |
387 | if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r | |
388 | return EFI_INVALID_PARAMETER;\r | |
389 | }\r | |
390 | \r | |
391 | if (!IsBSP ()) {\r | |
392 | return EFI_DEVICE_ERROR;\r | |
393 | }\r | |
394 | \r | |
395 | *NumberOfProcessors = mMpSystemData.NumberOfProcessors;\r | |
396 | *NumberOfEnabledProcessors = mMpSystemData.NumberOfEnabledProcessors;\r | |
397 | return EFI_SUCCESS;\r | |
398 | }\r | |
399 | \r | |
e7938b5a CF |
400 | /**\r |
401 | Gets detailed MP-related information on the requested processor at the\r | |
402 | instant this call is made. This service may only be called from the BSP.\r | |
403 | \r | |
404 | This service retrieves detailed MP-related information about any processor\r | |
405 | on the platform. Note the following:\r | |
406 | - The processor information may change during the course of a boot session.\r | |
407 | - The information presented here is entirely MP related.\r | |
408 | \r | |
409 | Information regarding the number of caches and their sizes, frequency of operation,\r | |
410 | slot numbers is all considered platform-related information and is not provided\r | |
411 | by this service.\r | |
412 | \r | |
413 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r | |
414 | instance.\r | |
415 | @param[in] ProcessorNumber The handle number of processor.\r | |
416 | @param[out] ProcessorInfoBuffer A pointer to the buffer where information for\r | |
417 | the requested processor is deposited.\r | |
418 | \r | |
419 | @retval EFI_SUCCESS Processor information was returned.\r | |
420 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
421 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
422 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
423 | ProcessorNumber does not exist in the platform.\r | |
424 | \r | |
425 | **/\r | |
426 | EFI_STATUS\r | |
427 | EFIAPI\r | |
428 | GetProcessorInfo (\r | |
429 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
430 | IN UINTN ProcessorNumber,\r | |
431 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r | |
432 | )\r | |
433 | {\r | |
434 | if (ProcessorInfoBuffer == NULL) {\r | |
435 | return EFI_INVALID_PARAMETER;\r | |
436 | }\r | |
437 | \r | |
438 | if (!IsBSP ()) {\r | |
439 | return EFI_DEVICE_ERROR;\r | |
440 | }\r | |
441 | \r | |
442 | if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r | |
443 | return EFI_NOT_FOUND;\r | |
444 | }\r | |
445 | \r | |
446 | CopyMem (ProcessorInfoBuffer, &mMpSystemData.CpuDatas[ProcessorNumber], sizeof (EFI_PROCESSOR_INFORMATION));\r | |
447 | return EFI_SUCCESS;\r | |
448 | }\r | |
449 | \r | |
5fee172f CF |
450 | /**\r |
451 | This service executes a caller provided function on all enabled APs. APs can\r | |
452 | run either simultaneously or one at a time in sequence. This service supports\r | |
453 | both blocking and non-blocking requests. The non-blocking requests use EFI\r | |
454 | events so the BSP can detect when the APs have finished. This service may only\r | |
455 | be called from the BSP.\r | |
456 | \r | |
457 | This function is used to dispatch all the enabled APs to the function specified\r | |
458 | by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r | |
459 | immediately and Procedure is not started on any AP.\r | |
460 | \r | |
461 | If SingleThread is TRUE, all the enabled APs execute the function specified by\r | |
462 | Procedure one by one, in ascending order of processor handle number. Otherwise,\r | |
463 | all the enabled APs execute the function specified by Procedure simultaneously.\r | |
464 | \r | |
465 | If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all\r | |
466 | APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking\r | |
467 | mode, and the BSP returns from this service without waiting for APs. If a\r | |
468 | non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT\r | |
469 | is signaled, then EFI_UNSUPPORTED must be returned.\r | |
470 | \r | |
471 | If the timeout specified by TimeoutInMicroseconds expires before all APs return\r | |
472 | from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r | |
473 | are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r | |
474 | and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its\r | |
475 | content points to the list of processor handle numbers in which Procedure was\r | |
476 | terminated.\r | |
477 | \r | |
478 | Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r | |
479 | to make sure that the nature of the code that is executed on the BSP and the\r | |
480 | dispatched APs is well controlled. The MP Services Protocol does not guarantee\r | |
481 | that the Procedure function is MP-safe. Hence, the tasks that can be run in\r | |
482 | parallel are limited to certain independent tasks and well-controlled exclusive\r | |
483 | code. EFI services and protocols may not be called by APs unless otherwise\r | |
484 | specified.\r | |
485 | \r | |
486 | In blocking execution mode, BSP waits until all APs finish or\r | |
487 | TimeoutInMicroseconds expires.\r | |
488 | \r | |
489 | In non-blocking execution mode, BSP is freed to return to the caller and then\r | |
490 | proceed to the next task without having to wait for APs. The following\r | |
491 | sequence needs to occur in a non-blocking execution mode:\r | |
492 | \r | |
493 | -# The caller that intends to use this MP Services Protocol in non-blocking\r | |
494 | mode creates WaitEvent by calling the EFI CreateEvent() service. The caller\r | |
495 | invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent\r | |
496 | is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests\r | |
497 | the function specified by Procedure to be started on all the enabled APs,\r | |
498 | and releases the BSP to continue with other tasks.\r | |
499 | -# The caller can use the CheckEvent() and WaitForEvent() services to check\r | |
500 | the state of the WaitEvent created in step 1.\r | |
501 | -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP\r | |
502 | Service signals WaitEvent by calling the EFI SignalEvent() function. If\r | |
503 | FailedCpuList is not NULL, its content is available when WaitEvent is\r | |
504 | signaled. If all APs returned from Procedure prior to the timeout, then\r | |
505 | FailedCpuList is set to NULL. If not all APs return from Procedure before\r | |
506 | the timeout, then FailedCpuList is filled in with the list of the failed\r | |
507 | APs. The buffer is allocated by MP Service Protocol using AllocatePool().\r | |
508 | It is the caller's responsibility to free the buffer with FreePool() service.\r | |
509 | -# This invocation of SignalEvent() function informs the caller that invoked\r | |
510 | EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed\r | |
511 | the specified task or a timeout occurred. The contents of FailedCpuList\r | |
512 | can be examined to determine which APs did not complete the specified task\r | |
513 | prior to the timeout.\r | |
514 | \r | |
515 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r | |
516 | instance.\r | |
517 | @param[in] Procedure A pointer to the function to be run on\r | |
518 | enabled APs of the system. See type\r | |
519 | EFI_AP_PROCEDURE.\r | |
520 | @param[in] SingleThread If TRUE, then all the enabled APs execute\r | |
521 | the function specified by Procedure one by\r | |
522 | one, in ascending order of processor handle\r | |
523 | number. If FALSE, then all the enabled APs\r | |
524 | execute the function specified by Procedure\r | |
525 | simultaneously.\r | |
526 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
527 | service. If it is NULL, then execute in\r | |
528 | blocking mode. BSP waits until all APs finish\r | |
529 | or TimeoutInMicroseconds expires. If it's\r | |
530 | not NULL, then execute in non-blocking mode.\r | |
531 | BSP requests the function specified by\r | |
532 | Procedure to be started on all the enabled\r | |
533 | APs, and go on executing immediately. If\r | |
534 | all return from Procedure, or TimeoutInMicroseconds\r | |
535 | expires, this event is signaled. The BSP\r | |
536 | can use the CheckEvent() or WaitForEvent()\r | |
537 | services to check the state of event. Type\r | |
538 | EFI_EVENT is defined in CreateEvent() in\r | |
539 | the Unified Extensible Firmware Interface\r | |
540 | Specification.\r | |
541 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r | |
542 | APs to return from Procedure, either for\r | |
543 | blocking or non-blocking mode. Zero means\r | |
544 | infinity. If the timeout expires before\r | |
545 | all APs return from Procedure, then Procedure\r | |
546 | on the failed APs is terminated. All enabled\r | |
547 | APs are available for next function assigned\r | |
548 | by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r | |
549 | or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r | |
550 | If the timeout expires in blocking mode,\r | |
551 | BSP returns EFI_TIMEOUT. If the timeout\r | |
552 | expires in non-blocking mode, WaitEvent\r | |
553 | is signaled with SignalEvent().\r | |
554 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
555 | all APs.\r | |
556 | @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r | |
557 | if all APs finish successfully, then its\r | |
558 | content is set to NULL. If not all APs\r | |
559 | finish before timeout expires, then its\r | |
560 | content is set to address of the buffer\r | |
561 | holding handle numbers of the failed APs.\r | |
562 | The buffer is allocated by MP Service Protocol,\r | |
563 | and it's the caller's responsibility to\r | |
564 | free the buffer with FreePool() service.\r | |
565 | In blocking mode, it is ready for consumption\r | |
566 | when the call returns. In non-blocking mode,\r | |
567 | it is ready when WaitEvent is signaled. The\r | |
568 | list of failed CPU is terminated by\r | |
569 | END_OF_CPU_LIST.\r | |
570 | \r | |
571 | @retval EFI_SUCCESS In blocking mode, all APs have finished before\r | |
572 | the timeout expired.\r | |
573 | @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r | |
574 | to all enabled APs.\r | |
575 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
576 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
577 | signaled.\r | |
578 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
579 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
580 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
581 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
582 | all enabled APs have finished.\r | |
583 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
584 | \r | |
585 | **/\r | |
586 | EFI_STATUS\r | |
587 | EFIAPI\r | |
588 | StartupAllAPs (\r | |
589 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
590 | IN EFI_AP_PROCEDURE Procedure,\r | |
591 | IN BOOLEAN SingleThread,\r | |
592 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
593 | IN UINTN TimeoutInMicroseconds,\r | |
594 | IN VOID *ProcedureArgument OPTIONAL,\r | |
595 | OUT UINTN **FailedCpuList OPTIONAL\r | |
596 | )\r | |
597 | {\r | |
598 | EFI_STATUS Status;\r | |
599 | CPU_DATA_BLOCK *CpuData;\r | |
600 | UINTN Number;\r | |
601 | CPU_STATE APInitialState;\r | |
602 | \r | |
603 | CpuData = NULL;\r | |
604 | \r | |
605 | if (FailedCpuList != NULL) {\r | |
606 | *FailedCpuList = NULL;\r | |
607 | }\r | |
608 | \r | |
609 | if (!IsBSP ()) {\r | |
610 | return EFI_DEVICE_ERROR;\r | |
611 | }\r | |
612 | \r | |
613 | if (mMpSystemData.NumberOfProcessors == 1) {\r | |
614 | return EFI_NOT_STARTED;\r | |
615 | }\r | |
616 | \r | |
617 | if (Procedure == NULL) {\r | |
618 | return EFI_INVALID_PARAMETER;\r | |
619 | }\r | |
620 | \r | |
621 | for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r | |
622 | CpuData = &mMpSystemData.CpuDatas[Number];\r | |
623 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
624 | //\r | |
625 | // Skip BSP\r | |
626 | //\r | |
627 | continue;\r | |
628 | }\r | |
629 | \r | |
630 | if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
631 | //\r | |
632 | // Skip Disabled processors\r | |
633 | //\r | |
634 | continue;\r | |
635 | }\r | |
636 | \r | |
637 | if (GetApState (CpuData) != CpuStateIdle) {\r | |
638 | return EFI_NOT_READY;\r | |
639 | }\r | |
640 | }\r | |
641 | \r | |
acb2172d CF |
642 | //\r |
643 | // temporarily stop checkAllAPsStatus for initialize parameters.\r | |
644 | //\r | |
645 | mStopCheckAllAPsStatus = TRUE;\r | |
646 | \r | |
5fee172f CF |
647 | mMpSystemData.Procedure = Procedure;\r |
648 | mMpSystemData.ProcedureArgument = ProcedureArgument;\r | |
649 | mMpSystemData.WaitEvent = WaitEvent;\r | |
650 | mMpSystemData.Timeout = TimeoutInMicroseconds;\r | |
651 | mMpSystemData.TimeoutActive = !!(TimeoutInMicroseconds);\r | |
652 | mMpSystemData.FinishCount = 0;\r | |
653 | mMpSystemData.StartCount = 0;\r | |
654 | mMpSystemData.SingleThread = SingleThread;\r | |
655 | mMpSystemData.FailedList = FailedCpuList;\r | |
656 | mMpSystemData.FailedListIndex = 0;\r | |
657 | APInitialState = CpuStateReady;\r | |
658 | \r | |
659 | for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r | |
660 | CpuData = &mMpSystemData.CpuDatas[Number];\r | |
661 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
662 | //\r | |
663 | // Skip BSP\r | |
664 | //\r | |
665 | continue;\r | |
666 | }\r | |
667 | \r | |
668 | if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
669 | //\r | |
670 | // Skip Disabled processors\r | |
671 | //\r | |
672 | continue;\r | |
673 | }\r | |
674 | \r | |
675 | //\r | |
676 | // Get APs prepared, and put failing APs into FailedCpuList\r | |
677 | // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready\r | |
678 | // state 1 by 1, until the previous 1 finished its task\r | |
679 | // if not "SingleThread", all APs are put to ready state from the beginning\r | |
680 | //\r | |
681 | if (GetApState (CpuData) == CpuStateIdle) {\r | |
682 | mMpSystemData.StartCount++;\r | |
683 | \r | |
684 | SetApState (CpuData, APInitialState);\r | |
685 | \r | |
686 | if (APInitialState == CpuStateReady) {\r | |
687 | SetApProcedure (CpuData, Procedure, ProcedureArgument);\r | |
688 | }\r | |
689 | \r | |
690 | if (SingleThread) {\r | |
691 | APInitialState = CpuStateBlocked;\r | |
692 | }\r | |
693 | }\r | |
694 | }\r | |
695 | \r | |
acb2172d CF |
696 | mStopCheckAllAPsStatus = FALSE;\r |
697 | \r | |
5fee172f | 698 | if (WaitEvent != NULL) {\r |
acb2172d CF |
699 | //\r |
700 | // non blocking\r | |
701 | //\r | |
702 | return EFI_SUCCESS;\r | |
5fee172f CF |
703 | }\r |
704 | \r | |
705 | while (TRUE) {\r | |
706 | CheckAndUpdateAllAPsToIdleState ();\r | |
707 | if (mMpSystemData.FinishCount == mMpSystemData.StartCount) {\r | |
708 | Status = EFI_SUCCESS;\r | |
709 | goto Done;\r | |
710 | }\r | |
711 | \r | |
712 | //\r | |
713 | // task timeout\r | |
714 | //\r | |
715 | if (mMpSystemData.TimeoutActive && mMpSystemData.Timeout < 0) {\r | |
716 | ResetAllFailedAPs();\r | |
717 | Status = EFI_TIMEOUT;\r | |
718 | goto Done;\r | |
719 | }\r | |
720 | \r | |
721 | gBS->Stall (gPollInterval);\r | |
722 | mMpSystemData.Timeout -= gPollInterval;\r | |
723 | }\r | |
724 | \r | |
725 | Done:\r | |
726 | \r | |
727 | return Status;\r | |
728 | }\r | |
729 | \r | |
3f4f0af8 CF |
730 | /**\r |
731 | This service lets the caller get one enabled AP to execute a caller-provided\r | |
732 | function. The caller can request the BSP to either wait for the completion\r | |
733 | of the AP or just proceed with the next task by using the EFI event mechanism.\r | |
734 | See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking\r | |
735 | execution support. This service may only be called from the BSP.\r | |
736 | \r | |
737 | This function is used to dispatch one enabled AP to the function specified by\r | |
738 | Procedure passing in the argument specified by ProcedureArgument. If WaitEvent\r | |
739 | is NULL, execution is in blocking mode. The BSP waits until the AP finishes or\r | |
740 | TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.\r | |
741 | BSP proceeds to the next task without waiting for the AP. If a non-blocking mode\r | |
742 | is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,\r | |
743 | then EFI_UNSUPPORTED must be returned.\r | |
744 | \r | |
745 | If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r | |
746 | from Procedure, then execution of Procedure by the AP is terminated. The AP is\r | |
747 | available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and\r | |
748 | EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r | |
749 | \r | |
750 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r | |
751 | instance.\r | |
752 | @param[in] Procedure A pointer to the function to be run on\r | |
753 | enabled APs of the system. See type\r | |
754 | EFI_AP_PROCEDURE.\r | |
755 | @param[in] ProcessorNumber The handle number of the AP. The range is\r | |
756 | from 0 to the total number of logical\r | |
757 | processors minus 1. The total number of\r | |
758 | logical processors can be retrieved by\r | |
759 | EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r | |
760 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
761 | service. If it is NULL, then execute in\r | |
762 | blocking mode. BSP waits until all APs finish\r | |
763 | or TimeoutInMicroseconds expires. If it's\r | |
764 | not NULL, then execute in non-blocking mode.\r | |
765 | BSP requests the function specified by\r | |
766 | Procedure to be started on all the enabled\r | |
767 | APs, and go on executing immediately. If\r | |
768 | all return from Procedure or TimeoutInMicroseconds\r | |
769 | expires, this event is signaled. The BSP\r | |
770 | can use the CheckEvent() or WaitForEvent()\r | |
771 | services to check the state of event. Type\r | |
772 | EFI_EVENT is defined in CreateEvent() in\r | |
773 | the Unified Extensible Firmware Interface\r | |
774 | Specification.\r | |
775 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r | |
776 | APs to return from Procedure, either for\r | |
777 | blocking or non-blocking mode. Zero means\r | |
778 | infinity. If the timeout expires before\r | |
779 | all APs return from Procedure, then Procedure\r | |
780 | on the failed APs is terminated. All enabled\r | |
781 | APs are available for next function assigned\r | |
782 | by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r | |
783 | or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r | |
784 | If the timeout expires in blocking mode,\r | |
785 | BSP returns EFI_TIMEOUT. If the timeout\r | |
786 | expires in non-blocking mode, WaitEvent\r | |
787 | is signaled with SignalEvent().\r | |
788 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
789 | all APs.\r | |
790 | @param[out] Finished If NULL, this parameter is ignored. In\r | |
791 | blocking mode, this parameter is ignored.\r | |
792 | In non-blocking mode, if AP returns from\r | |
793 | Procedure before the timeout expires, its\r | |
794 | content is set to TRUE. Otherwise, the\r | |
795 | value is set to FALSE. The caller can\r | |
796 | determine if the AP returned from Procedure\r | |
797 | by evaluating this value.\r | |
798 | \r | |
799 | @retval EFI_SUCCESS In blocking mode, specified AP finished before\r | |
800 | the timeout expires.\r | |
801 | @retval EFI_SUCCESS In non-blocking mode, the function has been\r | |
802 | dispatched to specified AP.\r | |
803 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
804 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
805 | signaled.\r | |
806 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
807 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
808 | the specified AP has finished.\r | |
809 | @retval EFI_NOT_READY The specified AP is busy.\r | |
810 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
811 | ProcessorNumber does not exist.\r | |
812 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
813 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
814 | \r | |
815 | **/\r | |
816 | EFI_STATUS\r | |
817 | EFIAPI\r | |
818 | StartupThisAP (\r | |
819 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
820 | IN EFI_AP_PROCEDURE Procedure,\r | |
821 | IN UINTN ProcessorNumber,\r | |
822 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
823 | IN UINTN TimeoutInMicroseconds,\r | |
824 | IN VOID *ProcedureArgument OPTIONAL,\r | |
825 | OUT BOOLEAN *Finished OPTIONAL\r | |
826 | )\r | |
827 | {\r | |
828 | CPU_DATA_BLOCK *CpuData;\r | |
3f4f0af8 CF |
829 | \r |
830 | CpuData = NULL;\r | |
831 | \r | |
832 | if (Finished != NULL) {\r | |
833 | *Finished = FALSE;\r | |
834 | }\r | |
835 | \r | |
836 | if (!IsBSP ()) {\r | |
837 | return EFI_DEVICE_ERROR;\r | |
838 | }\r | |
839 | \r | |
840 | if (Procedure == NULL) {\r | |
841 | return EFI_INVALID_PARAMETER;\r | |
842 | }\r | |
843 | \r | |
844 | if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r | |
845 | return EFI_NOT_FOUND;\r | |
846 | }\r | |
847 | \r | |
848 | CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r | |
849 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT) ||\r | |
850 | !TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
851 | return EFI_INVALID_PARAMETER;\r | |
852 | }\r | |
853 | \r | |
854 | if (GetApState (CpuData) != CpuStateIdle) {\r | |
855 | return EFI_NOT_READY;\r | |
856 | }\r | |
857 | \r | |
acb2172d CF |
858 | //\r |
859 | // temporarily stop checkAllAPsStatus for initialize parameters.\r | |
860 | //\r | |
861 | mStopCheckAllAPsStatus = TRUE;\r | |
862 | \r | |
3f4f0af8 CF |
863 | SetApState (CpuData, CpuStateReady);\r |
864 | \r | |
865 | SetApProcedure (CpuData, Procedure, ProcedureArgument);\r | |
866 | \r | |
867 | CpuData->Timeout = TimeoutInMicroseconds;\r | |
868 | CpuData->WaitEvent = WaitEvent;\r | |
869 | CpuData->TimeoutActive = !!(TimeoutInMicroseconds);\r | |
870 | CpuData->Finished = Finished;\r | |
871 | \r | |
acb2172d CF |
872 | mStopCheckAllAPsStatus = FALSE;\r |
873 | \r | |
3f4f0af8 CF |
874 | if (WaitEvent != NULL) {\r |
875 | //\r | |
876 | // Non Blocking\r | |
877 | //\r | |
acb2172d | 878 | return EFI_SUCCESS;\r |
3f4f0af8 CF |
879 | }\r |
880 | \r | |
881 | //\r | |
882 | // Blocking\r | |
883 | //\r | |
884 | while (TRUE) {\r | |
885 | if (GetApState (CpuData) == CpuStateFinished) {\r | |
886 | SetApState (CpuData, CpuStateIdle);\r | |
887 | break;\r | |
888 | }\r | |
889 | \r | |
890 | if (CpuData->TimeoutActive && CpuData->Timeout < 0) {\r | |
891 | ResetProcessorToIdleState (CpuData);\r | |
892 | return EFI_TIMEOUT;\r | |
893 | }\r | |
894 | \r | |
895 | gBS->Stall (gPollInterval);\r | |
896 | CpuData->Timeout -= gPollInterval;\r | |
897 | }\r | |
898 | \r | |
899 | return EFI_SUCCESS;\r | |
900 | }\r | |
901 | \r | |
b7c05ba5 CF |
902 | /**\r |
903 | This service switches the requested AP to be the BSP from that point onward.\r | |
904 | This service changes the BSP for all purposes. This call can only be performed\r | |
905 | by the current BSP.\r | |
906 | \r | |
907 | This service switches the requested AP to be the BSP from that point onward.\r | |
908 | This service changes the BSP for all purposes. The new BSP can take over the\r | |
909 | execution of the old BSP and continue seamlessly from where the old one left\r | |
910 | off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT\r | |
911 | is signaled.\r | |
912 | \r | |
913 | If the BSP cannot be switched prior to the return from this service, then\r | |
914 | EFI_UNSUPPORTED must be returned.\r | |
915 | \r | |
916 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r | |
917 | @param[in] ProcessorNumber The handle number of AP that is to become the new\r | |
918 | BSP. The range is from 0 to the total number of\r | |
919 | logical processors minus 1. The total number of\r | |
920 | logical processors can be retrieved by\r | |
921 | EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r | |
922 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r | |
923 | enabled AP. Otherwise, it will be disabled.\r | |
924 | \r | |
925 | @retval EFI_SUCCESS BSP successfully switched.\r | |
926 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r | |
927 | this service returning.\r | |
928 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
929 | @retval EFI_SUCCESS The calling processor is an AP.\r | |
930 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
931 | ProcessorNumber does not exist.\r | |
932 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r | |
933 | a disabled AP.\r | |
934 | @retval EFI_NOT_READY The specified AP is busy.\r | |
935 | \r | |
936 | **/\r | |
937 | EFI_STATUS\r | |
938 | EFIAPI\r | |
939 | SwitchBSP (\r | |
940 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
941 | IN UINTN ProcessorNumber,\r | |
942 | IN BOOLEAN EnableOldBSP\r | |
943 | )\r | |
944 | {\r | |
945 | //\r | |
946 | // Current always return unsupported.\r | |
947 | //\r | |
948 | return EFI_UNSUPPORTED;\r | |
949 | }\r | |
950 | \r | |
fa7ce675 CF |
951 | /**\r |
952 | This service lets the caller enable or disable an AP from this point onward.\r | |
953 | This service may only be called from the BSP.\r | |
954 | \r | |
955 | This service allows the caller enable or disable an AP from this point onward.\r | |
956 | The caller can optionally specify the health status of the AP by Health. If\r | |
957 | an AP is being disabled, then the state of the disabled AP is implementation\r | |
958 | dependent. If an AP is enabled, then the implementation must guarantee that a\r | |
959 | complete initialization sequence is performed on the AP, so the AP is in a state\r | |
960 | that is compatible with an MP operating system. This service may not be supported\r | |
961 | after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.\r | |
962 | \r | |
963 | If the enable or disable AP operation cannot be completed prior to the return\r | |
964 | from this service, then EFI_UNSUPPORTED must be returned.\r | |
965 | \r | |
966 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r | |
967 | @param[in] ProcessorNumber The handle number of AP that is to become the new\r | |
968 | BSP. The range is from 0 to the total number of\r | |
969 | logical processors minus 1. The total number of\r | |
970 | logical processors can be retrieved by\r | |
971 | EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r | |
972 | @param[in] EnableAP Specifies the new state for the processor for\r | |
973 | enabled, FALSE for disabled.\r | |
974 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r | |
975 | the new health status of the AP. This flag\r | |
976 | corresponds to StatusFlag defined in\r | |
977 | EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r | |
978 | the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
979 | bits are ignored. If it is NULL, this parameter\r | |
980 | is ignored.\r | |
981 | \r | |
982 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
983 | @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r | |
984 | prior to this service returning.\r | |
985 | @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r | |
986 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
987 | @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r | |
988 | does not exist.\r | |
989 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r | |
990 | \r | |
991 | **/\r | |
992 | EFI_STATUS\r | |
993 | EFIAPI\r | |
994 | EnableDisableAP (\r | |
995 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
996 | IN UINTN ProcessorNumber,\r | |
997 | IN BOOLEAN EnableAP,\r | |
998 | IN UINT32 *HealthFlag OPTIONAL\r | |
999 | )\r | |
1000 | {\r | |
1001 | CPU_DATA_BLOCK *CpuData;\r | |
1002 | \r | |
1003 | if (!IsBSP ()) {\r | |
1004 | return EFI_DEVICE_ERROR;\r | |
1005 | }\r | |
1006 | \r | |
1007 | if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r | |
1008 | return EFI_NOT_FOUND;\r | |
1009 | }\r | |
1010 | \r | |
1011 | CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r | |
1012 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
1013 | return EFI_INVALID_PARAMETER;\r | |
1014 | }\r | |
1015 | \r | |
1016 | if (GetApState (CpuData) != CpuStateIdle) {\r | |
1017 | return EFI_UNSUPPORTED;\r | |
1018 | }\r | |
1019 | \r | |
1020 | if (EnableAP) {\r | |
1021 | if (!(TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT))) {\r | |
1022 | mMpSystemData.NumberOfEnabledProcessors++;\r | |
1023 | }\r | |
1024 | CpuStatusFlagOr (CpuData, PROCESSOR_ENABLED_BIT);\r | |
1025 | } else {\r | |
1026 | if (TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
1027 | mMpSystemData.NumberOfEnabledProcessors--;\r | |
1028 | }\r | |
1029 | CpuStatusFlagAndNot (CpuData, PROCESSOR_ENABLED_BIT);\r | |
1030 | }\r | |
1031 | \r | |
1032 | if (HealthFlag != NULL) {\r | |
1033 | CpuStatusFlagAndNot (CpuData, (UINT32)~PROCESSOR_HEALTH_STATUS_BIT);\r | |
1034 | CpuStatusFlagOr (CpuData, (*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT));\r | |
1035 | }\r | |
1036 | \r | |
1037 | return EFI_SUCCESS;\r | |
1038 | }\r | |
1039 | \r | |
cfa2fac1 CF |
1040 | /**\r |
1041 | This return the handle number for the calling processor. This service may be\r | |
1042 | called from the BSP and APs.\r | |
1043 | \r | |
1044 | This service returns the processor handle number for the calling processor.\r | |
1045 | The returned value is in the range from 0 to the total number of logical\r | |
1046 | processors minus 1. The total number of logical processors can be retrieved\r | |
1047 | with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be\r | |
1048 | called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r | |
1049 | is returned. Otherwise, the current processors handle number is returned in\r | |
1050 | ProcessorNumber, and EFI_SUCCESS is returned.\r | |
1051 | \r | |
1052 | @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r | |
1053 | @param[out] ProcessorNumber The handle number of AP that is to become the new\r | |
1054 | BSP. The range is from 0 to the total number of\r | |
1055 | logical processors minus 1. The total number of\r | |
1056 | logical processors can be retrieved by\r | |
1057 | EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r | |
1058 | \r | |
1059 | @retval EFI_SUCCESS The current processor handle number was returned\r | |
1060 | in ProcessorNumber.\r | |
1061 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
1062 | \r | |
1063 | **/\r | |
1064 | EFI_STATUS\r | |
1065 | EFIAPI\r | |
1066 | WhoAmI (\r | |
1067 | IN EFI_MP_SERVICES_PROTOCOL *This,\r | |
1068 | OUT UINTN *ProcessorNumber\r | |
1069 | )\r | |
1070 | {\r | |
1071 | UINTN Index;\r | |
1072 | UINT32 ProcessorId;\r | |
1073 | \r | |
1074 | if (ProcessorNumber == NULL) {\r | |
1075 | return EFI_INVALID_PARAMETER;\r | |
1076 | }\r | |
1077 | \r | |
1078 | ProcessorId = GetApicId ();\r | |
1079 | for (Index = 0; Index < mMpSystemData.NumberOfProcessors; Index++) {\r | |
1080 | if (mMpSystemData.CpuDatas[Index].Info.ProcessorId == ProcessorId) {\r | |
1081 | break;\r | |
1082 | }\r | |
1083 | }\r | |
1084 | \r | |
1085 | *ProcessorNumber = Index;\r | |
1086 | return EFI_SUCCESS;\r | |
1087 | }\r | |
1088 | \r | |
3f4f0af8 CF |
1089 | /**\r |
1090 | Terminate AP's task and set it to idle state.\r | |
1091 | \r | |
1092 | This function terminates AP's task due to timeout by sending INIT-SIPI,\r | |
1093 | and sends it to idle state.\r | |
1094 | \r | |
1095 | @param CpuData the pointer to CPU_DATA_BLOCK of specified AP\r | |
1096 | \r | |
1097 | **/\r | |
1098 | VOID\r | |
1099 | ResetProcessorToIdleState (\r | |
1100 | IN CPU_DATA_BLOCK *CpuData\r | |
1101 | )\r | |
1102 | {\r | |
1103 | }\r | |
1104 | \r | |
e343f8f7 CF |
1105 | /**\r |
1106 | Application Processors do loop routine\r | |
1107 | after switch to its own stack.\r | |
1108 | \r | |
1109 | @param Context1 A pointer to the context to pass into the function.\r | |
1110 | @param Context2 A pointer to the context to pass into the function.\r | |
1111 | \r | |
1112 | **/\r | |
1113 | VOID\r | |
1114 | ProcessorToIdleState (\r | |
1115 | IN VOID *Context1, OPTIONAL\r | |
1116 | IN VOID *Context2 OPTIONAL\r | |
1117 | )\r | |
1118 | {\r | |
9908a829 CF |
1119 | UINTN ProcessorNumber;\r |
1120 | CPU_DATA_BLOCK *CpuData;\r | |
1121 | EFI_AP_PROCEDURE Procedure;\r | |
1122 | VOID *ProcedureArgument;\r | |
1123 | \r | |
1124 | WhoAmI (&mMpServicesTemplate, &ProcessorNumber);\r | |
1125 | CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r | |
e343f8f7 CF |
1126 | \r |
1127 | AsmApDoneWithCommonStack ();\r | |
1128 | \r | |
9908a829 CF |
1129 | while (TRUE) {\r |
1130 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
1131 | CpuPause ();\r | |
1132 | }\r | |
1133 | \r | |
1134 | ProcedureArgument = CpuData->Parameter;\r | |
1135 | Procedure = CpuData->Procedure;\r | |
1136 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
1137 | \r | |
1138 | if (Procedure != NULL) {\r | |
1139 | Procedure (ProcedureArgument);\r | |
1140 | \r | |
1141 | while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r | |
1142 | CpuPause ();\r | |
1143 | }\r | |
1144 | \r | |
1145 | CpuData->Procedure = NULL;\r | |
1146 | ReleaseSpinLock (&CpuData->CpuDataLock);\r | |
1147 | \r | |
1148 | SetApState (CpuData, CpuStateFinished);\r | |
1149 | }\r | |
1150 | \r | |
1151 | CpuPause ();\r | |
1152 | }\r | |
1153 | \r | |
e343f8f7 CF |
1154 | CpuSleep ();\r |
1155 | CpuDeadLoop ();\r | |
1156 | }\r | |
1157 | \r | |
3f4f0af8 CF |
1158 | /**\r |
1159 | Checks AP' status periodically.\r | |
1160 | \r | |
1161 | This function is triggerred by timer perodically to check the\r | |
1162 | state of AP forStartupThisAP() executed in non-blocking mode.\r | |
1163 | \r | |
1164 | @param Event Event triggered.\r | |
1165 | @param Context Parameter passed with the event.\r | |
1166 | \r | |
1167 | **/\r | |
1168 | VOID\r | |
1169 | EFIAPI\r | |
1170 | CheckThisAPStatus (\r | |
1171 | IN EFI_EVENT Event,\r | |
1172 | IN VOID *Context\r | |
1173 | )\r | |
1174 | {\r | |
1175 | CPU_DATA_BLOCK *CpuData;\r | |
1176 | CPU_STATE CpuState;\r | |
1177 | \r | |
1178 | CpuData = (CPU_DATA_BLOCK *) Context;\r | |
1179 | if (CpuData->TimeoutActive) {\r | |
1180 | CpuData->Timeout -= gPollInterval;\r | |
1181 | }\r | |
1182 | \r | |
1183 | CpuState = GetApState (CpuData);\r | |
1184 | \r | |
1185 | if (CpuState == CpuStateFinished) {\r | |
1186 | if (CpuData->Finished) {\r | |
1187 | *CpuData->Finished = TRUE;\r | |
1188 | }\r | |
1189 | SetApState (CpuData, CpuStateIdle);\r | |
1190 | goto out;\r | |
1191 | }\r | |
1192 | \r | |
1193 | if (CpuData->TimeoutActive && CpuData->Timeout < 0) {\r | |
1194 | if (CpuState != CpuStateIdle &&\r | |
1195 | CpuData->Finished) {\r | |
1196 | *CpuData->Finished = FALSE;\r | |
1197 | }\r | |
1198 | ResetProcessorToIdleState (CpuData);\r | |
1199 | goto out;\r | |
1200 | }\r | |
1201 | \r | |
1202 | return;\r | |
1203 | \r | |
1204 | out:\r | |
acb2172d CF |
1205 | CpuData->TimeoutActive = FALSE;\r |
1206 | gBS->SignalEvent (CpuData->WaitEvent);\r | |
1207 | CpuData->WaitEvent = NULL;\r | |
3f4f0af8 CF |
1208 | }\r |
1209 | \r | |
5fee172f CF |
1210 | /**\r |
1211 | Checks APs' status periodically.\r | |
1212 | \r | |
1213 | This function is triggerred by timer perodically to check the\r | |
1214 | state of APs for StartupAllAPs() executed in non-blocking mode.\r | |
1215 | \r | |
1216 | @param Event Event triggered.\r | |
1217 | @param Context Parameter passed with the event.\r | |
1218 | \r | |
1219 | **/\r | |
1220 | VOID\r | |
1221 | EFIAPI\r | |
1222 | CheckAllAPsStatus (\r | |
1223 | IN EFI_EVENT Event,\r | |
1224 | IN VOID *Context\r | |
1225 | )\r | |
1226 | {\r | |
acb2172d CF |
1227 | CPU_DATA_BLOCK *CpuData;\r |
1228 | UINTN Number;\r | |
1229 | \r | |
5fee172f CF |
1230 | if (mMpSystemData.TimeoutActive) {\r |
1231 | mMpSystemData.Timeout -= gPollInterval;\r | |
1232 | }\r | |
1233 | \r | |
acb2172d CF |
1234 | if (mStopCheckAllAPsStatus) {\r |
1235 | return;\r | |
1236 | }\r | |
5fee172f | 1237 | \r |
acb2172d CF |
1238 | if (mMpSystemData.WaitEvent != NULL) {\r |
1239 | CheckAndUpdateAllAPsToIdleState ();\r | |
5fee172f | 1240 | //\r |
acb2172d | 1241 | // task timeout\r |
5fee172f | 1242 | //\r |
acb2172d CF |
1243 | if (mMpSystemData.TimeoutActive && mMpSystemData.Timeout < 0) {\r |
1244 | ResetAllFailedAPs();\r | |
1245 | //\r | |
1246 | // force exit\r | |
1247 | //\r | |
1248 | mMpSystemData.FinishCount = mMpSystemData.StartCount;\r | |
1249 | }\r | |
5fee172f | 1250 | \r |
acb2172d CF |
1251 | if (mMpSystemData.FinishCount != mMpSystemData.StartCount) {\r |
1252 | return;\r | |
1253 | }\r | |
5fee172f | 1254 | \r |
acb2172d | 1255 | mMpSystemData.TimeoutActive = FALSE;\r |
5fee172f CF |
1256 | gBS->SignalEvent (mMpSystemData.WaitEvent);\r |
1257 | mMpSystemData.WaitEvent = NULL;\r | |
acb2172d CF |
1258 | mStopCheckAllAPsStatus = TRUE;\r |
1259 | }\r | |
1260 | \r | |
1261 | //\r | |
1262 | // check each AP status for StartupThisAP\r | |
1263 | //\r | |
1264 | for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r | |
1265 | CpuData = &mMpSystemData.CpuDatas[Number];\r | |
1266 | if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r | |
1267 | //\r | |
1268 | // Skip BSP\r | |
1269 | //\r | |
1270 | continue;\r | |
1271 | }\r | |
1272 | \r | |
1273 | if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r | |
1274 | //\r | |
1275 | // Skip Disabled processors\r | |
1276 | //\r | |
1277 | continue;\r | |
1278 | }\r | |
1279 | \r | |
1280 | if (CpuData->WaitEvent) {\r | |
1281 | CheckThisAPStatus (NULL, (VOID *)CpuData);\r | |
1282 | }\r | |
5fee172f CF |
1283 | }\r |
1284 | }\r | |
1285 | \r | |
1535c888 JJ |
1286 | /**\r |
1287 | Application Processor C code entry point.\r | |
1288 | \r | |
1289 | **/\r | |
1290 | VOID\r | |
1291 | EFIAPI\r | |
1292 | ApEntryPointInC (\r | |
1293 | VOID\r | |
1294 | )\r | |
1295 | {\r | |
03673ae1 CF |
1296 | VOID* TopOfApStack;\r |
1297 | \r | |
1298 | FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);\r | |
1299 | TopOfApStack = (UINT8*)mApStackStart + gApStackSize;\r | |
1300 | mApStackStart = TopOfApStack;\r | |
1301 | \r | |
1302 | mMpSystemData.NumberOfProcessors++;\r | |
e343f8f7 CF |
1303 | \r |
1304 | SwitchStack (\r | |
1305 | (SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,\r | |
1306 | NULL,\r | |
1307 | NULL,\r | |
03673ae1 CF |
1308 | TopOfApStack);\r |
1309 | }\r | |
1310 | \r | |
1311 | /**\r | |
1312 | This function is called by all processors (both BSP and AP) once and collects MP related data.\r | |
1313 | \r | |
1314 | @param Bsp TRUE if the CPU is BSP\r | |
1315 | @param ProcessorNumber The specific processor number\r | |
1316 | \r | |
1317 | @retval EFI_SUCCESS Data for the processor collected and filled in\r | |
1318 | \r | |
1319 | **/\r | |
1320 | EFI_STATUS\r | |
1321 | FillInProcessorInformation (\r | |
1322 | IN BOOLEAN Bsp,\r | |
1323 | IN UINTN ProcessorNumber\r | |
1324 | )\r | |
1325 | {\r | |
1326 | CPU_DATA_BLOCK *CpuData;\r | |
1327 | UINT32 ProcessorId;\r | |
1328 | \r | |
1329 | CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r | |
1330 | ProcessorId = GetApicId ();\r | |
1331 | CpuData->Info.ProcessorId = ProcessorId;\r | |
1332 | CpuData->Info.StatusFlag = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT;\r | |
1333 | if (Bsp) {\r | |
1334 | CpuData->Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;\r | |
1335 | }\r | |
1336 | CpuData->Info.Location.Package = ProcessorId;\r | |
1337 | CpuData->Info.Location.Core = 0;\r | |
1338 | CpuData->Info.Location.Thread = 0;\r | |
1339 | CpuData->State = Bsp ? CpuStateBuzy : CpuStateIdle;\r | |
1340 | \r | |
1341 | CpuData->Procedure = NULL;\r | |
1342 | CpuData->Parameter = NULL;\r | |
1343 | InitializeSpinLock (&CpuData->CpuDataLock);\r | |
1344 | \r | |
1345 | return EFI_SUCCESS;\r | |
1535c888 JJ |
1346 | }\r |
1347 | \r | |
03673ae1 CF |
1348 | /**\r |
1349 | Prepare the System Data.\r | |
1350 | \r | |
1351 | @retval EFI_SUCCESS the System Data finished initilization.\r | |
1352 | \r | |
1353 | **/\r | |
1354 | EFI_STATUS\r | |
1355 | InitMpSystemData (\r | |
1356 | VOID\r | |
1357 | )\r | |
1358 | {\r | |
3f4f0af8 CF |
1359 | EFI_STATUS Status;\r |
1360 | \r | |
03673ae1 CF |
1361 | ZeroMem (&mMpSystemData, sizeof (MP_SYSTEM_DATA));\r |
1362 | \r | |
1363 | mMpSystemData.NumberOfProcessors = 1;\r | |
1364 | mMpSystemData.NumberOfEnabledProcessors = 1;\r | |
1365 | \r | |
1366 | mMpSystemData.CpuDatas = AllocateZeroPool (sizeof (CPU_DATA_BLOCK) * gMaxLogicalProcessorNumber);\r | |
1367 | ASSERT(mMpSystemData.CpuDatas != NULL);\r | |
1368 | \r | |
5fee172f CF |
1369 | Status = gBS->CreateEvent (\r |
1370 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
1371 | TPL_CALLBACK,\r | |
1372 | CheckAllAPsStatus,\r | |
1373 | NULL,\r | |
1374 | &mMpSystemData.CheckAllAPsEvent\r | |
1375 | );\r | |
1376 | ASSERT_EFI_ERROR (Status);\r | |
1377 | \r | |
acb2172d CF |
1378 | //\r |
1379 | // Set timer to check all APs status.\r | |
1380 | //\r | |
1381 | Status = gBS->SetTimer (\r | |
1382 | mMpSystemData.CheckAllAPsEvent,\r | |
1383 | TimerPeriodic,\r | |
1384 | EFI_TIMER_PERIOD_MICROSECONDS (100)\r | |
1385 | );\r | |
1386 | ASSERT_EFI_ERROR (Status);\r | |
3f4f0af8 | 1387 | \r |
03673ae1 CF |
1388 | //\r |
1389 | // BSP\r | |
1390 | //\r | |
1391 | FillInProcessorInformation (TRUE, 0);\r | |
1392 | \r | |
1393 | return EFI_SUCCESS;\r | |
1394 | }\r | |
1535c888 | 1395 | \r |
6022e28c JJ |
1396 | /**\r |
1397 | Initialize Multi-processor support.\r | |
1398 | \r | |
1399 | **/\r | |
1400 | VOID\r | |
1401 | InitializeMpSupport (\r | |
1402 | VOID\r | |
1403 | )\r | |
1404 | {\r | |
6a26a597 CF |
1405 | gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r |
1406 | if (gMaxLogicalProcessorNumber < 1) {\r | |
1407 | DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));\r | |
1408 | return;\r | |
1409 | }\r | |
1410 | \r | |
1411 | if (gMaxLogicalProcessorNumber == 1) {\r | |
1412 | return;\r | |
1413 | }\r | |
1414 | \r | |
1415 | gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);\r | |
1416 | ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);\r | |
1417 | \r | |
1418 | mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r | |
1419 | ASSERT (mApStackStart != NULL);\r | |
6022e28c | 1420 | \r |
6a26a597 CF |
1421 | //\r |
1422 | // the first buffer of stack size used for common stack, when the amount of AP\r | |
1423 | // more than 1, we should never free the common stack which maybe used for AP reset.\r | |
1424 | //\r | |
1425 | mCommonStack = mApStackStart;\r | |
1426 | mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r | |
1427 | mApStackStart = mTopOfApCommonStack;\r | |
1428 | \r | |
03673ae1 | 1429 | InitMpSystemData ();\r |
6a26a597 | 1430 | \r |
03673ae1 | 1431 | if (mMpSystemData.NumberOfProcessors == 1) {\r |
6a26a597 CF |
1432 | FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r |
1433 | return;\r | |
1434 | }\r | |
1435 | \r | |
03673ae1 CF |
1436 | if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {\r |
1437 | FreePages (mApStackStart, EFI_SIZE_TO_PAGES (\r | |
1438 | (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *\r | |
1439 | gApStackSize));\r | |
6a26a597 CF |
1440 | }\r |
1441 | }\r |