]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuMpPei/CpuMpPei.c
UefiCpuPkg: Simplify InitializeSeparateExceptionStacks
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuMpPei.c
CommitLineData
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 11extern 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 16EFI_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 26EFI_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
73EFI_STATUS\r
74EFIAPI\r
75PeiGetNumberOfProcessors (\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
118EFI_STATUS\r
119EFIAPI\r
120PeiGetProcessorInfo (\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
193EFI_STATUS\r
194EFIAPI\r
195PeiStartupAllAPs (\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
260EFI_STATUS\r
261EFIAPI\r
262PeiStartupThisAP (\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
315EFI_STATUS\r
316EFIAPI\r
317PeiSwitchBSP (\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
366EFI_STATUS\r
367EFIAPI\r
368PeiEnableDisableAP (\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
403EFI_STATUS\r
404EFIAPI\r
405PeiWhoAmI (\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
417typedef struct {\r
418 VOID *Buffer;\r
419 UINTN *BufferSize;\r
420} EXCEPTION_STACK_SWITCH_CONTEXT;\r
0a0d5296
JW
421\r
422/**\r
423 Initializes CPU exceptions handlers for the sake of stack switch requirement.\r
424\r
e7abb94d 425 This function is a wrapper of InitializeSeparateExceptionStacks. It's mainly\r
0a0d5296
JW
426 for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.\r
427\r
428 @param[in,out] Buffer The pointer to private data buffer.\r
ea0f431c
JF
429\r
430**/\r
0a0d5296 431VOID\r
ea0f431c 432EFIAPI\r
0a0d5296 433InitializeExceptionStackSwitchHandlers (\r
053e878b 434 IN OUT VOID *Buffer\r
0a0d5296
JW
435 )\r
436{\r
0f7bccf5
ZL
437 EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData;\r
438\r
439 SwitchStackData = (EXCEPTION_STACK_SWITCH_CONTEXT *)Buffer;\r
440 InitializeSeparateExceptionStacks (SwitchStackData->Buffer, SwitchStackData->BufferSize);\r
0a0d5296
JW
441}\r
442\r
443/**\r
444 Initializes MP exceptions handlers for the sake of stack switch requirement.\r
445\r
446 This function will allocate required resources required to setup stack switch\r
0f7bccf5 447 and pass them through SwitchStackData to each logic processor.\r
0a0d5296
JW
448\r
449**/\r
450VOID\r
451InitializeMpExceptionStackSwitchHandlers (\r
452 VOID\r
453 )\r
454{\r
0f7bccf5
ZL
455 UINTN Index;\r
456 UINTN Bsp;\r
457 EXCEPTION_STACK_SWITCH_CONTEXT SwitchStackData;\r
458 UINTN BufferSize;\r
459 UINTN NumberOfProcessors;\r
0a0d5296
JW
460\r
461 if (!PcdGetBool (PcdCpuStackGuard)) {\r
462 return;\r
463 }\r
464\r
0f7bccf5 465 SwitchStackData.BufferSize = &BufferSize;\r
053e878b 466 MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL);\r
0a0d5296
JW
467 MpInitLibWhoAmI (&Bsp);\r
468\r
0a0d5296 469 for (Index = 0; Index < NumberOfProcessors; ++Index) {\r
0f7bccf5
ZL
470 SwitchStackData.Buffer = NULL;\r
471 BufferSize = 0;\r
472\r
0a0d5296 473 if (Index == Bsp) {\r
0f7bccf5 474 InitializeExceptionStackSwitchHandlers (&SwitchStackData);\r
0a0d5296
JW
475 } else {\r
476 //\r
0f7bccf5 477 // AP might need different buffer size from BSP.\r
0a0d5296 478 //\r
0f7bccf5 479 MpInitLibStartupThisAP (InitializeExceptionStackSwitchHandlers, Index, NULL, 0, (VOID *)&SwitchStackData, NULL);\r
0a0d5296
JW
480 }\r
481\r
0f7bccf5
ZL
482 if (BufferSize == 0) {\r
483 continue;\r
0a0d5296
JW
484 }\r
485\r
0f7bccf5
ZL
486 SwitchStackData.Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));\r
487 ASSERT (SwitchStackData.Buffer != NULL);\r
488 ZeroMem (SwitchStackData.Buffer, EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (BufferSize)));\r
053e878b
MK
489 DEBUG ((\r
490 DEBUG_INFO,\r
0f7bccf5 491 "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x%lX with size 0x%x\n",\r
053e878b 492 (UINT64)(UINTN)Index,\r
0f7bccf5
ZL
493 (UINT64)(UINTN)SwitchStackData.Buffer,\r
494 (UINT32)BufferSize\r
053e878b 495 ));\r
0a0d5296
JW
496\r
497 if (Index == Bsp) {\r
0f7bccf5 498 InitializeExceptionStackSwitchHandlers (&SwitchStackData);\r
0a0d5296
JW
499 } else {\r
500 MpInitLibStartupThisAP (\r
501 InitializeExceptionStackSwitchHandlers,\r
502 Index,\r
503 NULL,\r
504 0,\r
0f7bccf5 505 (VOID *)&SwitchStackData,\r
0a0d5296
JW
506 NULL\r
507 );\r
508 }\r
0a0d5296
JW
509 }\r
510}\r
511\r
512/**\r
513 Initializes MP and exceptions handlers.\r
514\r
515 @param PeiServices The pointer to the PEI Services Table.\r
516\r
517 @retval EFI_SUCCESS MP was successfully initialized.\r
518 @retval others Error occurred in MP initialization.\r
519\r
520**/\r
521EFI_STATUS\r
522InitializeCpuMpWorker (\r
053e878b 523 IN CONST EFI_PEI_SERVICES **PeiServices\r
ea0f431c
JF
524 )\r
525{\r
053e878b
MK
526 EFI_STATUS Status;\r
527 EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r
528 EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r
ea0f431c 529\r
ea0f431c 530 //\r
9bedfb2f
JF
531 // Get Vector Hand-off Info PPI\r
532 //\r
533 VectorInfo = NULL;\r
053e878b
MK
534 Status = PeiServicesLocatePpi (\r
535 &gEfiVectorHandoffInfoPpiGuid,\r
536 0,\r
537 NULL,\r
538 (VOID **)&VectorHandoffInfoPpi\r
539 );\r
9bedfb2f
JF
540 if (Status == EFI_SUCCESS) {\r
541 VectorInfo = VectorHandoffInfoPpi->Info;\r
542 }\r
7367cc6c 543\r
9bedfb2f 544 //\r
0a0d5296 545 // Initialize default handlers\r
ea0f431c 546 //\r
0a0d5296
JW
547 Status = InitializeCpuExceptionHandlers (VectorInfo);\r
548 if (EFI_ERROR (Status)) {\r
549 return Status;\r
550 }\r
551\r
a1a4c7a4 552 Status = MpInitLibInitialize ();\r
0a0d5296
JW
553 if (EFI_ERROR (Status)) {\r
554 return Status;\r
555 }\r
556\r
557 //\r
558 // Special initialization for the sake of Stack Guard\r
559 //\r
560 InitializeMpExceptionStackSwitchHandlers ();\r
a1a4c7a4 561\r
ea0f431c
JF
562 //\r
563 // Update and publish CPU BIST information\r
564 //\r
a1a4c7a4
JF
565 CollectBistDataFromPpi (PeiServices);\r
566\r
ea0f431c
JF
567 //\r
568 // Install CPU MP PPI\r
569 //\r
053e878b 570 Status = PeiServicesInstallPpi (mPeiCpuMpPpiList);\r
ea0f431c
JF
571 ASSERT_EFI_ERROR (Status);\r
572\r
573 return Status;\r
574}\r
0a0d5296
JW
575\r
576/**\r
577 The Entry point of the MP CPU PEIM.\r
578\r
579 This function will wakeup APs and collect CPU AP count and install the\r
580 Mp Service Ppi.\r
581\r
582 @param FileHandle Handle of the file being invoked.\r
583 @param PeiServices Describes the list of possible PEI Services.\r
584\r
585 @retval EFI_SUCCESS MpServicePpi is installed successfully.\r
586\r
587**/\r
588EFI_STATUS\r
589EFIAPI\r
590CpuMpPeimInit (\r
591 IN EFI_PEI_FILE_HANDLE FileHandle,\r
592 IN CONST EFI_PEI_SERVICES **PeiServices\r
593 )\r
594{\r
053e878b 595 EFI_STATUS Status;\r
0a0d5296
JW
596\r
597 //\r
598 // For the sake of special initialization needing to be done right after\r
599 // memory discovery.\r
600 //\r
601 Status = PeiServicesNotifyPpi (&mPostMemNotifyList[0]);\r
602 ASSERT_EFI_ERROR (Status);\r
603\r
604 return Status;\r
605}\r