]>
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 JF |
54 | /**\r |
55 | /**\r | |
56 | Checks APs status and updates APs status if needed.\r | |
57 | \r | |
58 | **/\r | |
59 | VOID\r | |
60 | CheckAndUpdateApsStatus (\r | |
61 | VOID\r | |
62 | )\r | |
63 | {\r | |
64 | }\r | |
65 | \r | |
66 | /**\r | |
67 | Checks APs' status periodically.\r | |
68 | \r | |
69 | This function is triggerred by timer perodically to check the\r | |
70 | state of APs for StartupAllAPs() and StartupThisAP() executed\r | |
71 | in non-blocking mode.\r | |
72 | \r | |
73 | @param[in] Event Event triggered.\r | |
74 | @param[in] Context Parameter passed with the event.\r | |
75 | \r | |
76 | **/\r | |
77 | VOID\r | |
78 | EFIAPI\r | |
79 | CheckApsStatus (\r | |
80 | IN EFI_EVENT Event,\r | |
81 | IN VOID *Context\r | |
82 | )\r | |
83 | {\r | |
84 | //\r | |
85 | // If CheckApsStatus() is not stopped, otherwise return immediately.\r | |
86 | //\r | |
87 | if (!mStopCheckAllApsStatus) {\r | |
88 | CheckAndUpdateApsStatus ();\r | |
89 | }\r | |
90 | }\r | |
93ca4c0f JF |
91 | /**\r |
92 | Initialize global data for MP support.\r | |
93 | \r | |
94 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r | |
95 | **/\r | |
96 | VOID\r | |
97 | InitMpGlobalData (\r | |
98 | IN CPU_MP_DATA *CpuMpData\r | |
99 | )\r | |
100 | {\r | |
96378861 JF |
101 | EFI_STATUS Status;\r |
102 | \r | |
93ca4c0f JF |
103 | SaveCpuMpData (CpuMpData);\r |
104 | \r | |
96378861 JF |
105 | Status = gBS->CreateEvent (\r |
106 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
107 | TPL_NOTIFY,\r | |
108 | CheckApsStatus,\r | |
109 | NULL,\r | |
110 | &mCheckAllApsEvent\r | |
111 | );\r | |
112 | ASSERT_EFI_ERROR (Status);\r | |
113 | \r | |
114 | //\r | |
115 | // Set timer to check all APs status.\r | |
116 | //\r | |
117 | Status = gBS->SetTimer (\r | |
118 | mCheckAllApsEvent,\r | |
119 | TimerPeriodic,\r | |
120 | AP_CHECK_INTERVAL\r | |
121 | );\r | |
122 | ASSERT_EFI_ERROR (Status);\r | |
93ca4c0f | 123 | }\r |
3e8ad6bd JF |
124 | \r |
125 | /**\r | |
126 | This service executes a caller provided function on all enabled APs.\r | |
127 | \r | |
128 | @param[in] Procedure A pointer to the function to be run on\r | |
129 | enabled APs of the system. See type\r | |
130 | EFI_AP_PROCEDURE.\r | |
131 | @param[in] SingleThread If TRUE, then all the enabled APs execute\r | |
132 | the function specified by Procedure one by\r | |
133 | one, in ascending order of processor handle\r | |
134 | number. If FALSE, then all the enabled APs\r | |
135 | execute the function specified by Procedure\r | |
136 | simultaneously.\r | |
137 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
138 | service. If it is NULL, then execute in\r | |
139 | blocking mode. BSP waits until all APs finish\r | |
140 | or TimeoutInMicroSeconds expires. If it's\r | |
141 | not NULL, then execute in non-blocking mode.\r | |
142 | BSP requests the function specified by\r | |
143 | Procedure to be started on all the enabled\r | |
144 | APs, and go on executing immediately. If\r | |
145 | all return from Procedure, or TimeoutInMicroSeconds\r | |
146 | expires, this event is signaled. The BSP\r | |
147 | can use the CheckEvent() or WaitForEvent()\r | |
148 | services to check the state of event. Type\r | |
149 | EFI_EVENT is defined in CreateEvent() in\r | |
150 | the Unified Extensible Firmware Interface\r | |
151 | Specification.\r | |
152 | @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r | |
153 | APs to return from Procedure, either for\r | |
154 | blocking or non-blocking mode. Zero means\r | |
155 | infinity. If the timeout expires before\r | |
156 | all APs return from Procedure, then Procedure\r | |
157 | on the failed APs is terminated. All enabled\r | |
158 | APs are available for next function assigned\r | |
159 | by MpInitLibStartupAllAPs() or\r | |
160 | MPInitLibStartupThisAP().\r | |
161 | If the timeout expires in blocking mode,\r | |
162 | BSP returns EFI_TIMEOUT. If the timeout\r | |
163 | expires in non-blocking mode, WaitEvent\r | |
164 | is signaled with SignalEvent().\r | |
165 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
166 | all APs.\r | |
167 | @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r | |
168 | if all APs finish successfully, then its\r | |
169 | content is set to NULL. If not all APs\r | |
170 | finish before timeout expires, then its\r | |
171 | content is set to address of the buffer\r | |
172 | holding handle numbers of the failed APs.\r | |
173 | The buffer is allocated by MP Initialization\r | |
174 | library, and it's the caller's responsibility to\r | |
175 | free the buffer with FreePool() service.\r | |
176 | In blocking mode, it is ready for consumption\r | |
177 | when the call returns. In non-blocking mode,\r | |
178 | it is ready when WaitEvent is signaled. The\r | |
179 | list of failed CPU is terminated by\r | |
180 | END_OF_CPU_LIST.\r | |
181 | \r | |
182 | @retval EFI_SUCCESS In blocking mode, all APs have finished before\r | |
183 | the timeout expired.\r | |
184 | @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r | |
185 | to all enabled APs.\r | |
186 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
187 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
188 | signaled.\r | |
189 | @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r | |
190 | supported.\r | |
191 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
192 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
193 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
194 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
195 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
196 | all enabled APs have finished.\r | |
197 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
198 | \r | |
199 | **/\r | |
200 | EFI_STATUS\r | |
201 | EFIAPI\r | |
202 | MpInitLibStartupAllAPs (\r | |
203 | IN EFI_AP_PROCEDURE Procedure,\r | |
204 | IN BOOLEAN SingleThread,\r | |
205 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
206 | IN UINTN TimeoutInMicroseconds,\r | |
207 | IN VOID *ProcedureArgument OPTIONAL,\r | |
208 | OUT UINTN **FailedCpuList OPTIONAL\r | |
209 | )\r | |
210 | {\r | |
211 | return EFI_UNSUPPORTED;\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | This service lets the caller get one enabled AP to execute a caller-provided\r | |
216 | function.\r | |
217 | \r | |
218 | @param[in] Procedure A pointer to the function to be run on the\r | |
219 | designated AP of the system. See type\r | |
220 | EFI_AP_PROCEDURE.\r | |
221 | @param[in] ProcessorNumber The handle number of the AP. The range is\r | |
222 | from 0 to the total number of logical\r | |
223 | processors minus 1. The total number of\r | |
224 | logical processors can be retrieved by\r | |
225 | MpInitLibGetNumberOfProcessors().\r | |
226 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
227 | service. If it is NULL, then execute in\r | |
228 | blocking mode. BSP waits until this AP finish\r | |
229 | or TimeoutInMicroSeconds expires. If it's\r | |
230 | not NULL, then execute in non-blocking mode.\r | |
231 | BSP requests the function specified by\r | |
232 | Procedure to be started on this AP,\r | |
233 | and go on executing immediately. If this AP\r | |
234 | return from Procedure or TimeoutInMicroSeconds\r | |
235 | expires, this event is signaled. The BSP\r | |
236 | can use the CheckEvent() or WaitForEvent()\r | |
237 | services to check the state of event. Type\r | |
238 | EFI_EVENT is defined in CreateEvent() in\r | |
239 | the Unified Extensible Firmware Interface\r | |
240 | Specification.\r | |
241 | @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for\r | |
242 | this AP to finish this Procedure, either for\r | |
243 | blocking or non-blocking mode. Zero means\r | |
244 | infinity. If the timeout expires before\r | |
245 | this AP returns from Procedure, then Procedure\r | |
246 | on the AP is terminated. The\r | |
247 | AP is available for next function assigned\r | |
248 | by MpInitLibStartupAllAPs() or\r | |
249 | MpInitLibStartupThisAP().\r | |
250 | If the timeout expires in blocking mode,\r | |
251 | BSP returns EFI_TIMEOUT. If the timeout\r | |
252 | expires in non-blocking mode, WaitEvent\r | |
253 | is signaled with SignalEvent().\r | |
254 | @param[in] ProcedureArgument The parameter passed into Procedure on the\r | |
255 | specified AP.\r | |
256 | @param[out] Finished If NULL, this parameter is ignored. In\r | |
257 | blocking mode, this parameter is ignored.\r | |
258 | In non-blocking mode, if AP returns from\r | |
259 | Procedure before the timeout expires, its\r | |
260 | content is set to TRUE. Otherwise, the\r | |
261 | value is set to FALSE. The caller can\r | |
262 | determine if the AP returned from Procedure\r | |
263 | by evaluating this value.\r | |
264 | \r | |
265 | @retval EFI_SUCCESS In blocking mode, specified AP finished before\r | |
266 | the timeout expires.\r | |
267 | @retval EFI_SUCCESS In non-blocking mode, the function has been\r | |
268 | dispatched to specified AP.\r | |
269 | @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r | |
270 | UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r | |
271 | signaled.\r | |
272 | @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not\r | |
273 | supported.\r | |
274 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
275 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r | |
276 | the specified AP has finished.\r | |
277 | @retval EFI_NOT_READY The specified AP is busy.\r | |
278 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
279 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
280 | ProcessorNumber does not exist.\r | |
281 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
282 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
283 | \r | |
284 | **/\r | |
285 | EFI_STATUS\r | |
286 | EFIAPI\r | |
287 | MpInitLibStartupThisAP (\r | |
288 | IN EFI_AP_PROCEDURE Procedure,\r | |
289 | IN UINTN ProcessorNumber,\r | |
290 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
291 | IN UINTN TimeoutInMicroseconds,\r | |
292 | IN VOID *ProcedureArgument OPTIONAL,\r | |
293 | OUT BOOLEAN *Finished OPTIONAL\r | |
294 | )\r | |
295 | {\r | |
296 | return EFI_UNSUPPORTED;\r | |
297 | }\r | |
298 | \r | |
299 | /**\r | |
300 | This service switches the requested AP to be the BSP from that point onward.\r | |
301 | This service changes the BSP for all purposes. This call can only be performed\r | |
302 | by the current BSP.\r | |
303 | \r | |
304 | @param[in] ProcessorNumber The handle number of AP that is to become the new\r | |
305 | BSP. The range is from 0 to the total number of\r | |
306 | logical processors minus 1. The total number of\r | |
307 | logical processors can be retrieved by\r | |
308 | MpInitLibGetNumberOfProcessors().\r | |
309 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r | |
310 | enabled AP. Otherwise, it will be disabled.\r | |
311 | \r | |
312 | @retval EFI_SUCCESS BSP successfully switched.\r | |
313 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r | |
314 | this service returning.\r | |
315 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
316 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
317 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
318 | ProcessorNumber does not exist.\r | |
319 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r | |
320 | a disabled AP.\r | |
321 | @retval EFI_NOT_READY The specified AP is busy.\r | |
322 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
323 | \r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | EFIAPI\r | |
327 | MpInitLibSwitchBSP (\r | |
328 | IN UINTN ProcessorNumber,\r | |
329 | IN BOOLEAN EnableOldBSP\r | |
330 | )\r | |
331 | {\r | |
332 | return EFI_UNSUPPORTED;\r | |
333 | }\r | |
334 | \r | |
335 | /**\r | |
336 | This service lets the caller enable or disable an AP from this point onward.\r | |
337 | This service may only be called from the BSP.\r | |
338 | \r | |
339 | @param[in] ProcessorNumber The handle number of AP.\r | |
340 | The range is from 0 to the total number of\r | |
341 | logical processors minus 1. The total number of\r | |
342 | logical processors can be retrieved by\r | |
343 | MpInitLibGetNumberOfProcessors().\r | |
344 | @param[in] EnableAP Specifies the new state for the processor for\r | |
345 | enabled, FALSE for disabled.\r | |
346 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r | |
347 | the new health status of the AP. This flag\r | |
348 | corresponds to StatusFlag defined in\r | |
349 | EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r | |
350 | the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
351 | bits are ignored. If it is NULL, this parameter\r | |
352 | is ignored.\r | |
353 | \r | |
354 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
355 | @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r | |
356 | prior to this service returning.\r | |
357 | @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r | |
358 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
359 | @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r | |
360 | does not exist.\r | |
361 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r | |
362 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
363 | \r | |
364 | **/\r | |
365 | EFI_STATUS\r | |
366 | EFIAPI\r | |
367 | MpInitLibEnableDisableAP (\r | |
368 | IN UINTN ProcessorNumber,\r | |
369 | IN BOOLEAN EnableAP,\r | |
370 | IN UINT32 *HealthFlag OPTIONAL\r | |
371 | )\r | |
372 | {\r | |
373 | return EFI_UNSUPPORTED;\r | |
374 | }\r |