]>
Commit | Line | Data |
---|---|---|
ea0f431c JF |
1 | /** @file\r |
2 | CPU PEI Module installs CPU Multiple Processor PPI.\r | |
3 | \r | |
0f7bccf5 | 4 | Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>\r |
0acd8697 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ea0f431c JF |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "CpuMpPei.h"\r | |
89fa1bf2 | 10 | \r |
053e878b | 11 | extern EDKII_PEI_MP_SERVICES2_PPI mMpServices2Ppi;\r |
a430589c | 12 | \r |
89fa1bf2 JF |
13 | //\r |
14 | // CPU MP PPI to be installed\r | |
15 | //\r | |
053e878b | 16 | EFI_PEI_MP_SERVICES_PPI mMpServicesPpi = {\r |
89fa1bf2 JF |
17 | PeiGetNumberOfProcessors,\r |
18 | PeiGetProcessorInfo,\r | |
19 | PeiStartupAllAPs,\r | |
20 | PeiStartupThisAP,\r | |
21 | PeiSwitchBSP,\r | |
22 | PeiEnableDisableAP,\r | |
23 | PeiWhoAmI,\r | |
24 | };\r | |
25 | \r | |
053e878b | 26 | EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiList[] = {\r |
a430589c ED |
27 | {\r |
28 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
29 | &gEdkiiPeiMpServices2PpiGuid,\r | |
30 | &mMpServices2Ppi\r | |
31 | },\r | |
32 | {\r | |
33 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
34 | &gEfiPeiMpServicesPpiGuid,\r | |
35 | &mMpServicesPpi\r | |
36 | }\r | |
89fa1bf2 JF |
37 | };\r |
38 | \r | |
39 | /**\r | |
40 | This service retrieves the number of logical processor in the platform\r | |
41 | and the number of those logical processors that are enabled on this boot.\r | |
42 | This service may only be called from the BSP.\r | |
43 | \r | |
44 | This function is used to retrieve the following information:\r | |
45 | - The number of logical processors that are present in the system.\r | |
46 | - The number of enabled logical processors in the system at the instant\r | |
47 | this call is made.\r | |
48 | \r | |
49 | Because MP Service Ppi provides services to enable and disable processors\r | |
50 | dynamically, the number of enabled logical processors may vary during the\r | |
51 | course of a boot session.\r | |
52 | \r | |
53 | If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r | |
54 | If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r | |
55 | EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r | |
56 | is returned in NumberOfProcessors, the number of currently enabled processor\r | |
57 | is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r | |
58 | \r | |
59 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
60 | published by the PEI Foundation.\r | |
61 | @param[in] This Pointer to this instance of the PPI.\r | |
62 | @param[out] NumberOfProcessors Pointer to the total number of logical processors in\r | |
63 | the system, including the BSP and disabled APs.\r | |
64 | @param[out] NumberOfEnabledProcessors\r | |
65 | Number of processors in the system that are enabled.\r | |
66 | \r | |
67 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
68 | logical processors was retrieved.\r | |
69 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
70 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r | |
71 | NumberOfEnabledProcessors is NULL.\r | |
72 | **/\r | |
73 | EFI_STATUS\r | |
74 | EFIAPI\r | |
75 | PeiGetNumberOfProcessors (\r | |
053e878b MK |
76 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
77 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
78 | OUT UINTN *NumberOfProcessors,\r | |
79 | OUT UINTN *NumberOfEnabledProcessors\r | |
89fa1bf2 JF |
80 | )\r |
81 | {\r | |
82 | if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r | |
83 | return EFI_INVALID_PARAMETER;\r | |
84 | }\r | |
85 | \r | |
86 | return MpInitLibGetNumberOfProcessors (\r | |
87 | NumberOfProcessors,\r | |
88 | NumberOfEnabledProcessors\r | |
89 | );\r | |
90 | }\r | |
91 | \r | |
92 | /**\r | |
93 | Gets detailed MP-related information on the requested processor at the\r | |
94 | instant this call is made. This service may only be called from the BSP.\r | |
95 | \r | |
96 | This service retrieves detailed MP-related information about any processor\r | |
97 | on the platform. Note the following:\r | |
98 | - The processor information may change during the course of a boot session.\r | |
99 | - The information presented here is entirely MP related.\r | |
100 | \r | |
101 | Information regarding the number of caches and their sizes, frequency of operation,\r | |
102 | slot numbers is all considered platform-related information and is not provided\r | |
103 | by this service.\r | |
104 | \r | |
105 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
106 | published by the PEI Foundation.\r | |
107 | @param[in] This Pointer to this instance of the PPI.\r | |
108 | @param[in] ProcessorNumber Pointer to the total number of logical processors in\r | |
109 | the system, including the BSP and disabled APs.\r | |
110 | @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS Processor information was returned.\r | |
113 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
114 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
115 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
116 | ProcessorNumber does not exist in the platform.\r | |
117 | **/\r | |
118 | EFI_STATUS\r | |
119 | EFIAPI\r | |
120 | PeiGetProcessorInfo (\r | |
121 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
122 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
123 | IN UINTN ProcessorNumber,\r | |
124 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r | |
125 | )\r | |
126 | {\r | |
127 | return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);\r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | This service executes a caller provided function on all enabled APs. APs can\r | |
132 | run either simultaneously or one at a time in sequence. This service supports\r | |
133 | both blocking requests only. This service may only\r | |
134 | be called from the BSP.\r | |
135 | \r | |
136 | This function is used to dispatch all the enabled APs to the function specified\r | |
137 | by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r | |
138 | immediately and Procedure is not started on any AP.\r | |
139 | \r | |
140 | If SingleThread is TRUE, all the enabled APs execute the function specified by\r | |
141 | Procedure one by one, in ascending order of processor handle number. Otherwise,\r | |
142 | all the enabled APs execute the function specified by Procedure simultaneously.\r | |
143 | \r | |
144 | If the timeout specified by TimeoutInMicroSeconds expires before all APs return\r | |
145 | from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r | |
146 | are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
147 | and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its\r | |
148 | content points to the list of processor handle numbers in which Procedure was\r | |
149 | terminated.\r | |
150 | \r | |
151 | Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
152 | to make sure that the nature of the code that is executed on the BSP and the\r | |
153 | dispatched APs is well controlled. The MP Services Ppi does not guarantee\r | |
154 | that the Procedure function is MP-safe. Hence, the tasks that can be run in\r | |
155 | parallel are limited to certain independent tasks and well-controlled exclusive\r | |
156 | code. PEI services and Ppis may not be called by APs unless otherwise\r | |
157 | specified.\r | |
158 | \r | |
159 | In blocking execution mode, BSP waits until all APs finish or\r | |
160 | TimeoutInMicroSeconds expires.\r | |
161 | \r | |
162 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
163 | published by the PEI Foundation.\r | |
164 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
165 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
166 | the system.\r | |
167 | @param[in] SingleThread If TRUE, then all the enabled APs execute the function\r | |
168 | specified by Procedure one by one, in ascending order\r | |
169 | of processor handle number. If FALSE, then all the\r | |
170 | enabled APs execute the function specified by Procedure\r | |
171 | simultaneously.\r | |
172 | @param[in] TimeoutInMicroSeconds\r | |
173 | Indicates the time limit in microseconds for APs to\r | |
174 | return from Procedure, for blocking mode only. Zero\r | |
175 | means infinity. If the timeout expires before all APs\r | |
176 | return from Procedure, then Procedure on the failed APs\r | |
177 | is terminated. All enabled APs are available for next\r | |
178 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
179 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
180 | timeout expires in blocking mode, BSP returns\r | |
181 | EFI_TIMEOUT.\r | |
182 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
183 | \r | |
184 | @retval EFI_SUCCESS In blocking mode, all APs have finished before the\r | |
185 | timeout expired.\r | |
186 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
187 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
188 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
189 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before all\r | |
190 | enabled APs have finished.\r | |
191 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
192 | **/\r | |
193 | EFI_STATUS\r | |
194 | EFIAPI\r | |
195 | PeiStartupAllAPs (\r | |
053e878b MK |
196 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
197 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
198 | IN EFI_AP_PROCEDURE Procedure,\r | |
199 | IN BOOLEAN SingleThread,\r | |
200 | IN UINTN TimeoutInMicroSeconds,\r | |
201 | IN VOID *ProcedureArgument OPTIONAL\r | |
89fa1bf2 JF |
202 | )\r |
203 | {\r | |
204 | return MpInitLibStartupAllAPs (\r | |
205 | Procedure,\r | |
206 | SingleThread,\r | |
207 | NULL,\r | |
208 | TimeoutInMicroSeconds,\r | |
209 | ProcedureArgument,\r | |
210 | NULL\r | |
211 | );\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. The caller can request the BSP to wait for the completion\r | |
217 | of the AP. This service may only be called from the BSP.\r | |
218 | \r | |
219 | This function is used to dispatch one enabled AP to the function specified by\r | |
220 | Procedure passing in the argument specified by ProcedureArgument.\r | |
221 | The execution is in blocking mode. The BSP waits until the AP finishes or\r | |
222 | TimeoutInMicroSecondss expires.\r | |
223 | \r | |
224 | If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r | |
225 | from Procedure, then execution of Procedure by the AP is terminated. The AP is\r | |
226 | available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and\r | |
227 | EFI_PEI_MP_SERVICES_PPI.StartupThisAP().\r | |
228 | \r | |
229 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
230 | published by the PEI Foundation.\r | |
231 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
232 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
233 | the system.\r | |
234 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
235 | total number of logical processors minus 1. The total\r | |
236 | number of logical processors can be retrieved by\r | |
237 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
238 | @param[in] TimeoutInMicroseconds\r | |
239 | Indicates the time limit in microseconds for APs to\r | |
240 | return from Procedure, for blocking mode only. Zero\r | |
241 | means infinity. If the timeout expires before all APs\r | |
242 | return from Procedure, then Procedure on the failed APs\r | |
243 | is terminated. All enabled APs are available for next\r | |
244 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
245 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
246 | timeout expires in blocking mode, BSP returns\r | |
247 | EFI_TIMEOUT.\r | |
248 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
249 | \r | |
250 | @retval EFI_SUCCESS In blocking mode, specified AP finished before the\r | |
251 | timeout expires.\r | |
252 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
253 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before the\r | |
254 | specified AP has finished.\r | |
255 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
256 | ProcessorNumber does not exist.\r | |
257 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
258 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
259 | **/\r | |
260 | EFI_STATUS\r | |
261 | EFIAPI\r | |
262 | PeiStartupThisAP (\r | |
053e878b MK |
263 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
264 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
265 | IN EFI_AP_PROCEDURE Procedure,\r | |
266 | IN UINTN ProcessorNumber,\r | |
267 | IN UINTN TimeoutInMicroseconds,\r | |
268 | IN VOID *ProcedureArgument OPTIONAL\r | |
89fa1bf2 JF |
269 | )\r |
270 | {\r | |
271 | return MpInitLibStartupThisAP (\r | |
272 | Procedure,\r | |
273 | ProcessorNumber,\r | |
274 | NULL,\r | |
275 | TimeoutInMicroseconds,\r | |
276 | ProcedureArgument,\r | |
277 | NULL\r | |
278 | );\r | |
279 | }\r | |
280 | \r | |
281 | /**\r | |
282 | This service switches the requested AP to be the BSP from that point onward.\r | |
283 | This service changes the BSP for all purposes. This call can only be performed\r | |
284 | by the current BSP.\r | |
285 | \r | |
286 | This service switches the requested AP to be the BSP from that point onward.\r | |
287 | This service changes the BSP for all purposes. The new BSP can take over the\r | |
288 | execution of the old BSP and continue seamlessly from where the old one left\r | |
289 | off.\r | |
290 | \r | |
291 | If the BSP cannot be switched prior to the return from this service, then\r | |
292 | EFI_UNSUPPORTED must be returned.\r | |
293 | \r | |
294 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
295 | published by the PEI Foundation.\r | |
296 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
297 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
298 | total number of logical processors minus 1. The total\r | |
299 | number of logical processors can be retrieved by\r | |
300 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
301 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled\r | |
302 | AP. Otherwise, it will be disabled.\r | |
303 | \r | |
304 | @retval EFI_SUCCESS BSP successfully switched.\r | |
305 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this\r | |
306 | service returning.\r | |
307 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
e3ae7f52 | 308 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r |
89fa1bf2 JF |
309 | @retval EFI_NOT_FOUND The processor with the handle specified by\r |
310 | ProcessorNumber does not exist.\r | |
311 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled\r | |
312 | AP.\r | |
313 | @retval EFI_NOT_READY The specified AP is busy.\r | |
314 | **/\r | |
315 | EFI_STATUS\r | |
316 | EFIAPI\r | |
317 | PeiSwitchBSP (\r | |
318 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
319 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
320 | IN UINTN ProcessorNumber,\r | |
321 | IN BOOLEAN EnableOldBSP\r | |
322 | )\r | |
323 | {\r | |
324 | return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);\r | |
325 | }\r | |
326 | \r | |
327 | /**\r | |
328 | This service lets the caller enable or disable an AP from this point onward.\r | |
329 | This service may only be called from the BSP.\r | |
330 | \r | |
331 | This service allows the caller enable or disable an AP from this point onward.\r | |
332 | The caller can optionally specify the health status of the AP by Health. If\r | |
333 | an AP is being disabled, then the state of the disabled AP is implementation\r | |
334 | dependent. If an AP is enabled, then the implementation must guarantee that a\r | |
335 | complete initialization sequence is performed on the AP, so the AP is in a state\r | |
336 | that is compatible with an MP operating system.\r | |
337 | \r | |
338 | If the enable or disable AP operation cannot be completed prior to the return\r | |
339 | from this service, then EFI_UNSUPPORTED must be returned.\r | |
340 | \r | |
341 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
342 | published by the PEI Foundation.\r | |
343 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
344 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
345 | total number of logical processors minus 1. The total\r | |
346 | number of logical processors can be retrieved by\r | |
347 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
348 | @param[in] EnableAP Specifies the new state for the processor for enabled,\r | |
349 | FALSE for disabled.\r | |
350 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies the\r | |
351 | new health status of the AP. This flag corresponds to\r | |
352 | StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().\r | |
353 | Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
354 | bits are ignored. If it is NULL, this parameter is\r | |
355 | ignored.\r | |
356 | \r | |
357 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
358 | @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior\r | |
359 | to this service returning.\r | |
360 | @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r | |
361 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
362 | @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r | |
363 | does not exist.\r | |
364 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r | |
365 | **/\r | |
366 | EFI_STATUS\r | |
367 | EFIAPI\r | |
368 | PeiEnableDisableAP (\r | |
053e878b MK |
369 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
370 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
371 | IN UINTN ProcessorNumber,\r | |
372 | IN BOOLEAN EnableAP,\r | |
373 | IN UINT32 *HealthFlag OPTIONAL\r | |
89fa1bf2 JF |
374 | )\r |
375 | {\r | |
376 | return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | This return the handle number for the calling processor. This service may be\r | |
381 | called from the BSP and APs.\r | |
382 | \r | |
383 | This service returns the processor handle number for the calling processor.\r | |
384 | The returned value is in the range from 0 to the total number of logical\r | |
385 | processors minus 1. The total number of logical processors can be retrieved\r | |
386 | with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be\r | |
387 | called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r | |
388 | is returned. Otherwise, the current processors handle number is returned in\r | |
389 | ProcessorNumber, and EFI_SUCCESS is returned.\r | |
390 | \r | |
391 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
392 | published by the PEI Foundation.\r | |
393 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
394 | @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
395 | total number of logical processors minus 1. The total\r | |
396 | number of logical processors can be retrieved by\r | |
397 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
398 | \r | |
399 | @retval EFI_SUCCESS The current processor handle number was returned in\r | |
400 | ProcessorNumber.\r | |
401 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
402 | **/\r | |
403 | EFI_STATUS\r | |
404 | EFIAPI\r | |
405 | PeiWhoAmI (\r | |
406 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
407 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
408 | OUT UINTN *ProcessorNumber\r | |
409 | )\r | |
410 | {\r | |
411 | return MpInitLibWhoAmI (ProcessorNumber);\r | |
412 | }\r | |
413 | \r | |
0f7bccf5 ZL |
414 | //\r |
415 | // Structure for InitializeSeparateExceptionStacks\r | |
416 | //\r | |
417 | typedef struct {\r | |
4b7bd4c5 ZL |
418 | VOID *Buffer;\r |
419 | UINTN BufferSize;\r | |
420 | EFI_STATUS Status;\r | |
0f7bccf5 | 421 | } EXCEPTION_STACK_SWITCH_CONTEXT;\r |
0a0d5296 JW |
422 | \r |
423 | /**\r | |
424 | Initializes CPU exceptions handlers for the sake of stack switch requirement.\r | |
425 | \r | |
e7abb94d | 426 | This function is a wrapper of InitializeSeparateExceptionStacks. It's mainly\r |
0a0d5296 JW |
427 | for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.\r |
428 | \r | |
429 | @param[in,out] Buffer The pointer to private data buffer.\r | |
ea0f431c JF |
430 | \r |
431 | **/\r | |
0a0d5296 | 432 | VOID\r |
ea0f431c | 433 | EFIAPI\r |
0a0d5296 | 434 | InitializeExceptionStackSwitchHandlers (\r |
053e878b | 435 | IN OUT VOID *Buffer\r |
0a0d5296 JW |
436 | )\r |
437 | {\r | |
0f7bccf5 | 438 | EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData;\r |
4b7bd4c5 | 439 | UINTN Index;\r |
0f7bccf5 | 440 | \r |
4b7bd4c5 | 441 | MpInitLibWhoAmI (&Index);\r |
0f7bccf5 | 442 | SwitchStackData = (EXCEPTION_STACK_SWITCH_CONTEXT *)Buffer;\r |
4b7bd4c5 ZL |
443 | \r |
444 | //\r | |
445 | // This function may be called twice for each Cpu. Only run InitializeSeparateExceptionStacks\r | |
446 | // if this is the first call or the first call failed because of size too small.\r | |
447 | //\r | |
448 | if ((SwitchStackData[Index].Status == EFI_NOT_STARTED) || (SwitchStackData[Index].Status == EFI_BUFFER_TOO_SMALL)) {\r | |
449 | SwitchStackData[Index].Status = InitializeSeparateExceptionStacks (SwitchStackData[Index].Buffer, &SwitchStackData[Index].BufferSize);\r | |
450 | }\r | |
0a0d5296 JW |
451 | }\r |
452 | \r | |
453 | /**\r | |
454 | Initializes MP exceptions handlers for the sake of stack switch requirement.\r | |
455 | \r | |
456 | This function will allocate required resources required to setup stack switch\r | |
0f7bccf5 | 457 | and pass them through SwitchStackData to each logic processor.\r |
0a0d5296 JW |
458 | \r |
459 | **/\r | |
460 | VOID\r | |
461 | InitializeMpExceptionStackSwitchHandlers (\r | |
462 | VOID\r | |
463 | )\r | |
464 | {\r | |
0f7bccf5 | 465 | UINTN Index;\r |
0f7bccf5 | 466 | UINTN NumberOfProcessors;\r |
4b7bd4c5 ZL |
467 | EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData;\r |
468 | UINTN BufferSize;\r | |
469 | EFI_STATUS Status;\r | |
470 | UINT8 *Buffer;\r | |
0a0d5296 JW |
471 | \r |
472 | if (!PcdGetBool (PcdCpuStackGuard)) {\r | |
473 | return;\r | |
474 | }\r | |
475 | \r | |
053e878b | 476 | MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL);\r |
4b7bd4c5 ZL |
477 | SwitchStackData = AllocatePages (EFI_SIZE_TO_PAGES (NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)));\r |
478 | ASSERT (SwitchStackData != NULL);\r | |
479 | ZeroMem (SwitchStackData, NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT));\r | |
0a0d5296 | 480 | for (Index = 0; Index < NumberOfProcessors; ++Index) {\r |
4b7bd4c5 ZL |
481 | //\r |
482 | // Because the procedure may runs multiple times, use the status EFI_NOT_STARTED\r | |
483 | // to indicate the procedure haven't been run yet.\r | |
484 | //\r | |
485 | SwitchStackData[Index].Status = EFI_NOT_STARTED;\r | |
486 | }\r | |
487 | \r | |
488 | Status = MpInitLibStartupAllCPUs (\r | |
489 | InitializeExceptionStackSwitchHandlers,\r | |
490 | 0,\r | |
491 | SwitchStackData\r | |
492 | );\r | |
493 | ASSERT_EFI_ERROR (Status);\r | |
0f7bccf5 | 494 | \r |
4b7bd4c5 ZL |
495 | BufferSize = 0;\r |
496 | for (Index = 0; Index < NumberOfProcessors; ++Index) {\r | |
497 | if (SwitchStackData[Index].Status == EFI_BUFFER_TOO_SMALL) {\r | |
498 | ASSERT (SwitchStackData[Index].BufferSize != 0);\r | |
499 | BufferSize += SwitchStackData[Index].BufferSize;\r | |
0a0d5296 | 500 | } else {\r |
4b7bd4c5 ZL |
501 | ASSERT (SwitchStackData[Index].Status == EFI_SUCCESS);\r |
502 | ASSERT (SwitchStackData[Index].BufferSize == 0);\r | |
0a0d5296 | 503 | }\r |
4b7bd4c5 | 504 | }\r |
0a0d5296 | 505 | \r |
4b7bd4c5 ZL |
506 | if (BufferSize != 0) {\r |
507 | Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));\r | |
508 | ASSERT (Buffer != NULL);\r | |
509 | BufferSize = 0;\r | |
510 | for (Index = 0; Index < NumberOfProcessors; ++Index) {\r | |
511 | if (SwitchStackData[Index].Status == EFI_BUFFER_TOO_SMALL) {\r | |
512 | SwitchStackData[Index].Buffer = (VOID *)(&Buffer[BufferSize]);\r | |
513 | BufferSize += SwitchStackData[Index].BufferSize;\r | |
514 | DEBUG ((\r | |
515 | DEBUG_INFO,\r | |
516 | "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x%lX with size 0x%lX\n",\r | |
517 | (UINT64)(UINTN)Index,\r | |
518 | (UINT64)(UINTN)SwitchStackData[Index].Buffer,\r | |
519 | (UINT64)(UINTN)SwitchStackData[Index].BufferSize\r | |
520 | ));\r | |
521 | }\r | |
0a0d5296 JW |
522 | }\r |
523 | \r | |
4b7bd4c5 ZL |
524 | Status = MpInitLibStartupAllCPUs (\r |
525 | InitializeExceptionStackSwitchHandlers,\r | |
526 | 0,\r | |
527 | SwitchStackData\r | |
528 | );\r | |
529 | ASSERT_EFI_ERROR (Status);\r | |
530 | for (Index = 0; Index < NumberOfProcessors; ++Index) {\r | |
531 | ASSERT (SwitchStackData[Index].Status == EFI_SUCCESS);\r | |
0a0d5296 | 532 | }\r |
0a0d5296 | 533 | }\r |
4b7bd4c5 ZL |
534 | \r |
535 | FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)));\r | |
0a0d5296 JW |
536 | }\r |
537 | \r | |
538 | /**\r | |
539 | Initializes MP and exceptions handlers.\r | |
540 | \r | |
541 | @param PeiServices The pointer to the PEI Services Table.\r | |
542 | \r | |
543 | @retval EFI_SUCCESS MP was successfully initialized.\r | |
544 | @retval others Error occurred in MP initialization.\r | |
545 | \r | |
546 | **/\r | |
547 | EFI_STATUS\r | |
548 | InitializeCpuMpWorker (\r | |
053e878b | 549 | IN CONST EFI_PEI_SERVICES **PeiServices\r |
ea0f431c JF |
550 | )\r |
551 | {\r | |
053e878b MK |
552 | EFI_STATUS Status;\r |
553 | EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r | |
554 | EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r | |
ea0f431c | 555 | \r |
ea0f431c | 556 | //\r |
9bedfb2f JF |
557 | // Get Vector Hand-off Info PPI\r |
558 | //\r | |
559 | VectorInfo = NULL;\r | |
053e878b MK |
560 | Status = PeiServicesLocatePpi (\r |
561 | &gEfiVectorHandoffInfoPpiGuid,\r | |
562 | 0,\r | |
563 | NULL,\r | |
564 | (VOID **)&VectorHandoffInfoPpi\r | |
565 | );\r | |
9bedfb2f JF |
566 | if (Status == EFI_SUCCESS) {\r |
567 | VectorInfo = VectorHandoffInfoPpi->Info;\r | |
568 | }\r | |
7367cc6c | 569 | \r |
9bedfb2f | 570 | //\r |
0a0d5296 | 571 | // Initialize default handlers\r |
ea0f431c | 572 | //\r |
0a0d5296 JW |
573 | Status = InitializeCpuExceptionHandlers (VectorInfo);\r |
574 | if (EFI_ERROR (Status)) {\r | |
575 | return Status;\r | |
576 | }\r | |
577 | \r | |
a1a4c7a4 | 578 | Status = MpInitLibInitialize ();\r |
0a0d5296 JW |
579 | if (EFI_ERROR (Status)) {\r |
580 | return Status;\r | |
581 | }\r | |
582 | \r | |
583 | //\r | |
584 | // Special initialization for the sake of Stack Guard\r | |
585 | //\r | |
586 | InitializeMpExceptionStackSwitchHandlers ();\r | |
a1a4c7a4 | 587 | \r |
ea0f431c JF |
588 | //\r |
589 | // Update and publish CPU BIST information\r | |
590 | //\r | |
a1a4c7a4 JF |
591 | CollectBistDataFromPpi (PeiServices);\r |
592 | \r | |
ea0f431c JF |
593 | //\r |
594 | // Install CPU MP PPI\r | |
595 | //\r | |
053e878b | 596 | Status = PeiServicesInstallPpi (mPeiCpuMpPpiList);\r |
ea0f431c JF |
597 | ASSERT_EFI_ERROR (Status);\r |
598 | \r | |
599 | return Status;\r | |
600 | }\r | |
0a0d5296 JW |
601 | \r |
602 | /**\r | |
603 | The Entry point of the MP CPU PEIM.\r | |
604 | \r | |
605 | This function will wakeup APs and collect CPU AP count and install the\r | |
606 | Mp Service Ppi.\r | |
607 | \r | |
608 | @param FileHandle Handle of the file being invoked.\r | |
609 | @param PeiServices Describes the list of possible PEI Services.\r | |
610 | \r | |
611 | @retval EFI_SUCCESS MpServicePpi is installed successfully.\r | |
612 | \r | |
613 | **/\r | |
614 | EFI_STATUS\r | |
615 | EFIAPI\r | |
616 | CpuMpPeimInit (\r | |
617 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
618 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
619 | )\r | |
620 | {\r | |
053e878b | 621 | EFI_STATUS Status;\r |
0a0d5296 JW |
622 | \r |
623 | //\r | |
624 | // For the sake of special initialization needing to be done right after\r | |
625 | // memory discovery.\r | |
626 | //\r | |
627 | Status = PeiServicesNotifyPpi (&mPostMemNotifyList[0]);\r | |
628 | ASSERT_EFI_ERROR (Status);\r | |
629 | \r | |
630 | return Status;\r | |
631 | }\r |