]>
Commit | Line | Data |
---|---|---|
ea0f431c JF |
1 | /** @file\r |
2 | Implementation of Multiple Processor PPI services.\r | |
3 | \r | |
a742e186 | 4 | Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r |
ea0f431c JF |
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 "PeiMpServices.h"\r | |
16 | \r | |
17 | //\r | |
18 | // CPU MP PPI to be installed\r | |
19 | //\r | |
20 | EFI_PEI_MP_SERVICES_PPI mMpServicesPpi = {\r | |
21 | PeiGetNumberOfProcessors,\r | |
22 | PeiGetProcessorInfo,\r | |
23 | PeiStartupAllAPs,\r | |
24 | PeiStartupThisAP,\r | |
25 | PeiSwitchBSP,\r | |
26 | PeiEnableDisableAP,\r | |
27 | PeiWhoAmI,\r | |
28 | };\r | |
29 | \r | |
30 | EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc = {\r | |
31 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
32 | &gEfiPeiMpServicesPpiGuid,\r | |
33 | &mMpServicesPpi\r | |
34 | };\r | |
35 | \r | |
a1a4c7a4 | 36 | \r |
ea0f431c JF |
37 | /**\r |
38 | This service retrieves the number of logical processor in the platform\r | |
39 | and the number of those logical processors that are enabled on this boot.\r | |
40 | This service may only be called from the BSP.\r | |
41 | \r | |
42 | This function is used to retrieve the following information:\r | |
43 | - The number of logical processors that are present in the system.\r | |
44 | - The number of enabled logical processors in the system at the instant\r | |
45 | this call is made.\r | |
46 | \r | |
47 | Because MP Service Ppi provides services to enable and disable processors\r | |
48 | dynamically, the number of enabled logical processors may vary during the\r | |
49 | course of a boot session.\r | |
50 | \r | |
51 | If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r | |
52 | If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r | |
53 | EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r | |
54 | is returned in NumberOfProcessors, the number of currently enabled processor\r | |
55 | is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r | |
56 | \r | |
57 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
58 | published by the PEI Foundation.\r | |
59 | @param[in] This Pointer to this instance of the PPI.\r | |
60 | @param[out] NumberOfProcessors Pointer to the total number of logical processors in\r | |
61 | the system, including the BSP and disabled APs.\r | |
62 | @param[out] NumberOfEnabledProcessors\r | |
63 | Number of processors in the system that are enabled.\r | |
64 | \r | |
65 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
66 | logical processors was retrieved.\r | |
67 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
68 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r | |
69 | NumberOfEnabledProcessors is NULL.\r | |
70 | **/\r | |
71 | EFI_STATUS\r | |
72 | EFIAPI\r | |
73 | PeiGetNumberOfProcessors (\r | |
74 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
75 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
76 | OUT UINTN *NumberOfProcessors,\r | |
77 | OUT UINTN *NumberOfEnabledProcessors\r | |
78 | )\r | |
79 | {\r | |
ea0f431c JF |
80 | if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r |
81 | return EFI_INVALID_PARAMETER;\r | |
82 | }\r | |
83 | \r | |
a1a4c7a4 JF |
84 | return MpInitLibGetNumberOfProcessors (\r |
85 | NumberOfProcessors,\r | |
86 | NumberOfEnabledProcessors\r | |
87 | );\r | |
ea0f431c JF |
88 | }\r |
89 | \r | |
90 | /**\r | |
91 | Gets detailed MP-related information on the requested processor at the\r | |
92 | instant this call is made. This service may only be called from the BSP.\r | |
93 | \r | |
94 | This service retrieves detailed MP-related information about any processor\r | |
95 | on the platform. Note the following:\r | |
96 | - The processor information may change during the course of a boot session.\r | |
97 | - The information presented here is entirely MP related.\r | |
98 | \r | |
99 | Information regarding the number of caches and their sizes, frequency of operation,\r | |
100 | slot numbers is all considered platform-related information and is not provided\r | |
101 | by this service.\r | |
102 | \r | |
103 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
104 | published by the PEI Foundation.\r | |
105 | @param[in] This Pointer to this instance of the PPI.\r | |
106 | @param[in] ProcessorNumber Pointer to the total number of logical processors in\r | |
107 | the system, including the BSP and disabled APs.\r | |
108 | @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.\r | |
109 | \r | |
110 | @retval EFI_SUCCESS Processor information was returned.\r | |
111 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
112 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
113 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
114 | ProcessorNumber does not exist in the platform.\r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | PeiGetProcessorInfo (\r | |
119 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
120 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
121 | IN UINTN ProcessorNumber,\r | |
122 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r | |
123 | )\r | |
124 | {\r | |
a1a4c7a4 | 125 | return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);\r |
ea0f431c JF |
126 | }\r |
127 | \r | |
128 | /**\r | |
129 | This service executes a caller provided function on all enabled APs. APs can\r | |
130 | run either simultaneously or one at a time in sequence. This service supports\r | |
131 | both blocking requests only. This service may only\r | |
132 | be called from the BSP.\r | |
133 | \r | |
134 | This function is used to dispatch all the enabled APs to the function specified\r | |
135 | by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r | |
136 | immediately and Procedure is not started on any AP.\r | |
137 | \r | |
138 | If SingleThread is TRUE, all the enabled APs execute the function specified by\r | |
139 | Procedure one by one, in ascending order of processor handle number. Otherwise,\r | |
140 | all the enabled APs execute the function specified by Procedure simultaneously.\r | |
141 | \r | |
142 | If the timeout specified by TimeoutInMicroSeconds expires before all APs return\r | |
143 | from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r | |
144 | are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
145 | and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its\r | |
146 | content points to the list of processor handle numbers in which Procedure was\r | |
147 | terminated.\r | |
148 | \r | |
149 | Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
150 | to make sure that the nature of the code that is executed on the BSP and the\r | |
151 | dispatched APs is well controlled. The MP Services Ppi does not guarantee\r | |
152 | that the Procedure function is MP-safe. Hence, the tasks that can be run in\r | |
153 | parallel are limited to certain independent tasks and well-controlled exclusive\r | |
154 | code. PEI services and Ppis may not be called by APs unless otherwise\r | |
155 | specified.\r | |
156 | \r | |
157 | In blocking execution mode, BSP waits until all APs finish or\r | |
158 | TimeoutInMicroSeconds expires.\r | |
159 | \r | |
160 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
161 | published by the PEI Foundation.\r | |
162 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
163 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
164 | the system.\r | |
165 | @param[in] SingleThread If TRUE, then all the enabled APs execute the function\r | |
166 | specified by Procedure one by one, in ascending order\r | |
167 | of processor handle number. If FALSE, then all the\r | |
168 | enabled APs execute the function specified by Procedure\r | |
169 | simultaneously.\r | |
170 | @param[in] TimeoutInMicroSeconds\r | |
171 | Indicates the time limit in microseconds for APs to\r | |
172 | return from Procedure, for blocking mode only. Zero\r | |
173 | means infinity. If the timeout expires before all APs\r | |
174 | return from Procedure, then Procedure on the failed APs\r | |
175 | is terminated. All enabled APs are available for next\r | |
176 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
177 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
178 | timeout expires in blocking mode, BSP returns\r | |
179 | EFI_TIMEOUT.\r | |
180 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
181 | \r | |
182 | @retval EFI_SUCCESS In blocking mode, all APs have finished before the\r | |
183 | timeout expired.\r | |
184 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
185 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
186 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
187 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before all\r | |
188 | enabled APs have finished.\r | |
189 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
190 | **/\r | |
191 | EFI_STATUS\r | |
192 | EFIAPI\r | |
193 | PeiStartupAllAPs (\r | |
194 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
195 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
196 | IN EFI_AP_PROCEDURE Procedure,\r | |
197 | IN BOOLEAN SingleThread,\r | |
198 | IN UINTN TimeoutInMicroSeconds,\r | |
199 | IN VOID *ProcedureArgument OPTIONAL\r | |
200 | )\r | |
201 | {\r | |
a1a4c7a4 JF |
202 | return MpInitLibStartupAllAPs (\r |
203 | Procedure,\r | |
204 | SingleThread,\r | |
205 | NULL,\r | |
206 | TimeoutInMicroSeconds,\r | |
207 | ProcedureArgument,\r | |
208 | NULL\r | |
209 | );\r | |
ea0f431c JF |
210 | }\r |
211 | \r | |
212 | /**\r | |
213 | This service lets the caller get one enabled AP to execute a caller-provided\r | |
214 | function. The caller can request the BSP to wait for the completion\r | |
215 | of the AP. This service may only be called from the BSP.\r | |
216 | \r | |
217 | This function is used to dispatch one enabled AP to the function specified by\r | |
218 | Procedure passing in the argument specified by ProcedureArgument.\r | |
219 | The execution is in blocking mode. The BSP waits until the AP finishes or\r | |
220 | TimeoutInMicroSecondss expires.\r | |
221 | \r | |
222 | If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r | |
223 | from Procedure, then execution of Procedure by the AP is terminated. The AP is\r | |
224 | available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and\r | |
225 | EFI_PEI_MP_SERVICES_PPI.StartupThisAP().\r | |
226 | \r | |
227 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
228 | published by the PEI Foundation.\r | |
229 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
230 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
231 | the system.\r | |
232 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
233 | total number of logical processors minus 1. The total\r | |
234 | number of logical processors can be retrieved by\r | |
235 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
236 | @param[in] TimeoutInMicroseconds\r | |
237 | Indicates the time limit in microseconds for APs to\r | |
238 | return from Procedure, for blocking mode only. Zero\r | |
239 | means infinity. If the timeout expires before all APs\r | |
240 | return from Procedure, then Procedure on the failed APs\r | |
241 | is terminated. All enabled APs are available for next\r | |
242 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
243 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
244 | timeout expires in blocking mode, BSP returns\r | |
245 | EFI_TIMEOUT.\r | |
246 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
247 | \r | |
248 | @retval EFI_SUCCESS In blocking mode, specified AP finished before the\r | |
249 | timeout expires.\r | |
250 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
251 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before the\r | |
252 | specified AP has finished.\r | |
253 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
254 | ProcessorNumber does not exist.\r | |
255 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
256 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
257 | **/\r | |
258 | EFI_STATUS\r | |
259 | EFIAPI\r | |
260 | PeiStartupThisAP (\r | |
261 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
262 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
263 | IN EFI_AP_PROCEDURE Procedure,\r | |
264 | IN UINTN ProcessorNumber,\r | |
265 | IN UINTN TimeoutInMicroseconds,\r | |
266 | IN VOID *ProcedureArgument OPTIONAL\r | |
267 | )\r | |
268 | {\r | |
a1a4c7a4 JF |
269 | return MpInitLibStartupThisAP (\r |
270 | Procedure,\r | |
271 | ProcessorNumber,\r | |
272 | NULL,\r | |
273 | TimeoutInMicroseconds,\r | |
274 | ProcedureArgument,\r | |
275 | NULL\r | |
276 | );\r | |
ea0f431c JF |
277 | }\r |
278 | \r | |
279 | /**\r | |
280 | This service switches the requested AP to be the BSP from that point onward.\r | |
281 | This service changes the BSP for all purposes. This call can only be performed\r | |
282 | by the current BSP.\r | |
283 | \r | |
284 | This service switches the requested AP to be the BSP from that point onward.\r | |
285 | This service changes the BSP for all purposes. The new BSP can take over the\r | |
286 | execution of the old BSP and continue seamlessly from where the old one left\r | |
287 | off.\r | |
288 | \r | |
289 | If the BSP cannot be switched prior to the return from this service, then\r | |
290 | EFI_UNSUPPORTED must be returned.\r | |
291 | \r | |
292 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
293 | published by the PEI Foundation.\r | |
294 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
295 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
296 | total number of logical processors minus 1. The total\r | |
297 | number of logical processors can be retrieved by\r | |
298 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
299 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled\r | |
300 | AP. Otherwise, it will be disabled.\r | |
301 | \r | |
302 | @retval EFI_SUCCESS BSP successfully switched.\r | |
303 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this\r | |
304 | service returning.\r | |
305 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
306 | @retval EFI_SUCCESS The calling processor is an AP.\r | |
307 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
308 | ProcessorNumber does not exist.\r | |
309 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled\r | |
310 | AP.\r | |
311 | @retval EFI_NOT_READY The specified AP is busy.\r | |
312 | **/\r | |
313 | EFI_STATUS\r | |
314 | EFIAPI\r | |
315 | PeiSwitchBSP (\r | |
316 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
317 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
318 | IN UINTN ProcessorNumber,\r | |
319 | IN BOOLEAN EnableOldBSP\r | |
320 | )\r | |
321 | {\r | |
a1a4c7a4 | 322 | return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);\r |
ea0f431c JF |
323 | }\r |
324 | \r | |
325 | /**\r | |
326 | This service lets the caller enable or disable an AP from this point onward.\r | |
327 | This service may only be called from the BSP.\r | |
328 | \r | |
329 | This service allows the caller enable or disable an AP from this point onward.\r | |
330 | The caller can optionally specify the health status of the AP by Health. If\r | |
331 | an AP is being disabled, then the state of the disabled AP is implementation\r | |
332 | dependent. If an AP is enabled, then the implementation must guarantee that a\r | |
333 | complete initialization sequence is performed on the AP, so the AP is in a state\r | |
334 | that is compatible with an MP operating system.\r | |
335 | \r | |
336 | If the enable or disable AP operation cannot be completed prior to the return\r | |
337 | from this service, then EFI_UNSUPPORTED must be returned.\r | |
338 | \r | |
339 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
340 | published by the PEI Foundation.\r | |
341 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
342 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
343 | total number of logical processors minus 1. The total\r | |
344 | number of logical processors can be retrieved by\r | |
345 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
346 | @param[in] EnableAP Specifies the new state for the processor for enabled,\r | |
347 | FALSE for disabled.\r | |
348 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies the\r | |
349 | new health status of the AP. This flag corresponds to\r | |
350 | StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().\r | |
351 | Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
352 | bits are ignored. If it is NULL, this parameter is\r | |
353 | ignored.\r | |
354 | \r | |
355 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
356 | @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior\r | |
357 | to this service returning.\r | |
358 | @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r | |
359 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
360 | @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r | |
361 | does not exist.\r | |
362 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r | |
363 | **/\r | |
364 | EFI_STATUS\r | |
365 | EFIAPI\r | |
366 | PeiEnableDisableAP (\r | |
367 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
368 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
369 | IN UINTN ProcessorNumber,\r | |
370 | IN BOOLEAN EnableAP,\r | |
371 | IN UINT32 *HealthFlag OPTIONAL\r | |
372 | )\r | |
373 | {\r | |
a1a4c7a4 | 374 | return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);\r |
ea0f431c JF |
375 | }\r |
376 | \r | |
377 | /**\r | |
378 | This return the handle number for the calling processor. This service may be\r | |
379 | called from the BSP and APs.\r | |
380 | \r | |
381 | This service returns the processor handle number for the calling processor.\r | |
382 | The returned value is in the range from 0 to the total number of logical\r | |
383 | processors minus 1. The total number of logical processors can be retrieved\r | |
384 | with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be\r | |
385 | called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r | |
386 | is returned. Otherwise, the current processors handle number is returned in\r | |
387 | ProcessorNumber, and EFI_SUCCESS is returned.\r | |
388 | \r | |
389 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
390 | published by the PEI Foundation.\r | |
391 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
392 | @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
393 | total number of logical processors minus 1. The total\r | |
394 | number of logical processors can be retrieved by\r | |
395 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
396 | \r | |
397 | @retval EFI_SUCCESS The current processor handle number was returned in\r | |
398 | ProcessorNumber.\r | |
399 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
400 | **/\r | |
401 | EFI_STATUS\r | |
402 | EFIAPI\r | |
403 | PeiWhoAmI (\r | |
404 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
405 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
406 | OUT UINTN *ProcessorNumber\r | |
407 | )\r | |
408 | {\r | |
a1a4c7a4 | 409 | return MpInitLibWhoAmI (ProcessorNumber);\r |
ea0f431c | 410 | }\r |