]>
Commit | Line | Data |
---|---|---|
ea0f431c JF |
1 | /** @file\r |
2 | CPU PEI Module installs CPU Multiple Processor PPI.\r | |
3 | \r | |
7367cc6c | 4 | Copyright (c) 2015 - 2018, 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 "CpuMpPei.h"\r | |
89fa1bf2 JF |
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 | |
36 | /**\r | |
37 | This service retrieves the number of logical processor in the platform\r | |
38 | and the number of those logical processors that are enabled on this boot.\r | |
39 | This service may only be called from the BSP.\r | |
40 | \r | |
41 | This function is used to retrieve the following information:\r | |
42 | - The number of logical processors that are present in the system.\r | |
43 | - The number of enabled logical processors in the system at the instant\r | |
44 | this call is made.\r | |
45 | \r | |
46 | Because MP Service Ppi provides services to enable and disable processors\r | |
47 | dynamically, the number of enabled logical processors may vary during the\r | |
48 | course of a boot session.\r | |
49 | \r | |
50 | If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r | |
51 | If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r | |
52 | EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r | |
53 | is returned in NumberOfProcessors, the number of currently enabled processor\r | |
54 | is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r | |
55 | \r | |
56 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
57 | published by the PEI Foundation.\r | |
58 | @param[in] This Pointer to this instance of the PPI.\r | |
59 | @param[out] NumberOfProcessors Pointer to the total number of logical processors in\r | |
60 | the system, including the BSP and disabled APs.\r | |
61 | @param[out] NumberOfEnabledProcessors\r | |
62 | Number of processors in the system that are enabled.\r | |
63 | \r | |
64 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
65 | logical processors was retrieved.\r | |
66 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
67 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r | |
68 | NumberOfEnabledProcessors is NULL.\r | |
69 | **/\r | |
70 | EFI_STATUS\r | |
71 | EFIAPI\r | |
72 | PeiGetNumberOfProcessors (\r | |
73 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
74 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
75 | OUT UINTN *NumberOfProcessors,\r | |
76 | OUT UINTN *NumberOfEnabledProcessors\r | |
77 | )\r | |
78 | {\r | |
79 | if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r | |
80 | return EFI_INVALID_PARAMETER;\r | |
81 | }\r | |
82 | \r | |
83 | return MpInitLibGetNumberOfProcessors (\r | |
84 | NumberOfProcessors,\r | |
85 | NumberOfEnabledProcessors\r | |
86 | );\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Gets detailed MP-related information on the requested processor at the\r | |
91 | instant this call is made. This service may only be called from the BSP.\r | |
92 | \r | |
93 | This service retrieves detailed MP-related information about any processor\r | |
94 | on the platform. Note the following:\r | |
95 | - The processor information may change during the course of a boot session.\r | |
96 | - The information presented here is entirely MP related.\r | |
97 | \r | |
98 | Information regarding the number of caches and their sizes, frequency of operation,\r | |
99 | slot numbers is all considered platform-related information and is not provided\r | |
100 | by this service.\r | |
101 | \r | |
102 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
103 | published by the PEI Foundation.\r | |
104 | @param[in] This Pointer to this instance of the PPI.\r | |
105 | @param[in] ProcessorNumber Pointer to the total number of logical processors in\r | |
106 | the system, including the BSP and disabled APs.\r | |
107 | @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.\r | |
108 | \r | |
109 | @retval EFI_SUCCESS Processor information was returned.\r | |
110 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
111 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
112 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
113 | ProcessorNumber does not exist in the platform.\r | |
114 | **/\r | |
115 | EFI_STATUS\r | |
116 | EFIAPI\r | |
117 | PeiGetProcessorInfo (\r | |
118 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
119 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
120 | IN UINTN ProcessorNumber,\r | |
121 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r | |
122 | )\r | |
123 | {\r | |
124 | return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | This service executes a caller provided function on all enabled APs. APs can\r | |
129 | run either simultaneously or one at a time in sequence. This service supports\r | |
130 | both blocking requests only. This service may only\r | |
131 | be called from the BSP.\r | |
132 | \r | |
133 | This function is used to dispatch all the enabled APs to the function specified\r | |
134 | by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r | |
135 | immediately and Procedure is not started on any AP.\r | |
136 | \r | |
137 | If SingleThread is TRUE, all the enabled APs execute the function specified by\r | |
138 | Procedure one by one, in ascending order of processor handle number. Otherwise,\r | |
139 | all the enabled APs execute the function specified by Procedure simultaneously.\r | |
140 | \r | |
141 | If the timeout specified by TimeoutInMicroSeconds expires before all APs return\r | |
142 | from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r | |
143 | are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
144 | and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its\r | |
145 | content points to the list of processor handle numbers in which Procedure was\r | |
146 | terminated.\r | |
147 | \r | |
148 | Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
149 | to make sure that the nature of the code that is executed on the BSP and the\r | |
150 | dispatched APs is well controlled. The MP Services Ppi does not guarantee\r | |
151 | that the Procedure function is MP-safe. Hence, the tasks that can be run in\r | |
152 | parallel are limited to certain independent tasks and well-controlled exclusive\r | |
153 | code. PEI services and Ppis may not be called by APs unless otherwise\r | |
154 | specified.\r | |
155 | \r | |
156 | In blocking execution mode, BSP waits until all APs finish or\r | |
157 | TimeoutInMicroSeconds expires.\r | |
158 | \r | |
159 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
160 | published by the PEI Foundation.\r | |
161 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
162 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
163 | the system.\r | |
164 | @param[in] SingleThread If TRUE, then all the enabled APs execute the function\r | |
165 | specified by Procedure one by one, in ascending order\r | |
166 | of processor handle number. If FALSE, then all the\r | |
167 | enabled APs execute the function specified by Procedure\r | |
168 | simultaneously.\r | |
169 | @param[in] TimeoutInMicroSeconds\r | |
170 | Indicates the time limit in microseconds for APs to\r | |
171 | return from Procedure, for blocking mode only. Zero\r | |
172 | means infinity. If the timeout expires before all APs\r | |
173 | return from Procedure, then Procedure on the failed APs\r | |
174 | is terminated. All enabled APs are available for next\r | |
175 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
176 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
177 | timeout expires in blocking mode, BSP returns\r | |
178 | EFI_TIMEOUT.\r | |
179 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
180 | \r | |
181 | @retval EFI_SUCCESS In blocking mode, all APs have finished before the\r | |
182 | timeout expired.\r | |
183 | @retval EFI_DEVICE_ERROR Caller processor is AP.\r | |
184 | @retval EFI_NOT_STARTED No enabled APs exist in the system.\r | |
185 | @retval EFI_NOT_READY Any enabled APs are busy.\r | |
186 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before all\r | |
187 | enabled APs have finished.\r | |
188 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | EFIAPI\r | |
192 | PeiStartupAllAPs (\r | |
193 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
194 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
195 | IN EFI_AP_PROCEDURE Procedure,\r | |
196 | IN BOOLEAN SingleThread,\r | |
197 | IN UINTN TimeoutInMicroSeconds,\r | |
198 | IN VOID *ProcedureArgument OPTIONAL\r | |
199 | )\r | |
200 | {\r | |
201 | return MpInitLibStartupAllAPs (\r | |
202 | Procedure,\r | |
203 | SingleThread,\r | |
204 | NULL,\r | |
205 | TimeoutInMicroSeconds,\r | |
206 | ProcedureArgument,\r | |
207 | NULL\r | |
208 | );\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | This service lets the caller get one enabled AP to execute a caller-provided\r | |
213 | function. The caller can request the BSP to wait for the completion\r | |
214 | of the AP. This service may only be called from the BSP.\r | |
215 | \r | |
216 | This function is used to dispatch one enabled AP to the function specified by\r | |
217 | Procedure passing in the argument specified by ProcedureArgument.\r | |
218 | The execution is in blocking mode. The BSP waits until the AP finishes or\r | |
219 | TimeoutInMicroSecondss expires.\r | |
220 | \r | |
221 | If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r | |
222 | from Procedure, then execution of Procedure by the AP is terminated. The AP is\r | |
223 | available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and\r | |
224 | EFI_PEI_MP_SERVICES_PPI.StartupThisAP().\r | |
225 | \r | |
226 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
227 | published by the PEI Foundation.\r | |
228 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
229 | @param[in] Procedure A pointer to the function to be run on enabled APs of\r | |
230 | the system.\r | |
231 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
232 | total number of logical processors minus 1. The total\r | |
233 | number of logical processors can be retrieved by\r | |
234 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
235 | @param[in] TimeoutInMicroseconds\r | |
236 | Indicates the time limit in microseconds for APs to\r | |
237 | return from Procedure, for blocking mode only. Zero\r | |
238 | means infinity. If the timeout expires before all APs\r | |
239 | return from Procedure, then Procedure on the failed APs\r | |
240 | is terminated. All enabled APs are available for next\r | |
241 | function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()\r | |
242 | or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the\r | |
243 | timeout expires in blocking mode, BSP returns\r | |
244 | EFI_TIMEOUT.\r | |
245 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.\r | |
246 | \r | |
247 | @retval EFI_SUCCESS In blocking mode, specified AP finished before the\r | |
248 | timeout expires.\r | |
249 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
250 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before the\r | |
251 | specified AP has finished.\r | |
252 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
253 | ProcessorNumber does not exist.\r | |
254 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r | |
255 | @retval EFI_INVALID_PARAMETER Procedure is NULL.\r | |
256 | **/\r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | PeiStartupThisAP (\r | |
260 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
261 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
262 | IN EFI_AP_PROCEDURE Procedure,\r | |
263 | IN UINTN ProcessorNumber,\r | |
264 | IN UINTN TimeoutInMicroseconds,\r | |
265 | IN VOID *ProcedureArgument OPTIONAL\r | |
266 | )\r | |
267 | {\r | |
268 | return MpInitLibStartupThisAP (\r | |
269 | Procedure,\r | |
270 | ProcessorNumber,\r | |
271 | NULL,\r | |
272 | TimeoutInMicroseconds,\r | |
273 | ProcedureArgument,\r | |
274 | NULL\r | |
275 | );\r | |
276 | }\r | |
277 | \r | |
278 | /**\r | |
279 | This service switches the requested AP to be the BSP from that point onward.\r | |
280 | This service changes the BSP for all purposes. This call can only be performed\r | |
281 | by the current BSP.\r | |
282 | \r | |
283 | This service switches the requested AP to be the BSP from that point onward.\r | |
284 | This service changes the BSP for all purposes. The new BSP can take over the\r | |
285 | execution of the old BSP and continue seamlessly from where the old one left\r | |
286 | off.\r | |
287 | \r | |
288 | If the BSP cannot be switched prior to the return from this service, then\r | |
289 | EFI_UNSUPPORTED must be returned.\r | |
290 | \r | |
291 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
292 | published by the PEI Foundation.\r | |
293 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
294 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
295 | total number of logical processors minus 1. The total\r | |
296 | number of logical processors can be retrieved by\r | |
297 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
298 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled\r | |
299 | AP. Otherwise, it will be disabled.\r | |
300 | \r | |
301 | @retval EFI_SUCCESS BSP successfully switched.\r | |
302 | @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this\r | |
303 | service returning.\r | |
304 | @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r | |
e3ae7f52 | 305 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r |
89fa1bf2 JF |
306 | @retval EFI_NOT_FOUND The processor with the handle specified by\r |
307 | ProcessorNumber does not exist.\r | |
308 | @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled\r | |
309 | AP.\r | |
310 | @retval EFI_NOT_READY The specified AP is busy.\r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | EFIAPI\r | |
314 | PeiSwitchBSP (\r | |
315 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
316 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
317 | IN UINTN ProcessorNumber,\r | |
318 | IN BOOLEAN EnableOldBSP\r | |
319 | )\r | |
320 | {\r | |
321 | return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);\r | |
322 | }\r | |
323 | \r | |
324 | /**\r | |
325 | This service lets the caller enable or disable an AP from this point onward.\r | |
326 | This service may only be called from the BSP.\r | |
327 | \r | |
328 | This service allows the caller enable or disable an AP from this point onward.\r | |
329 | The caller can optionally specify the health status of the AP by Health. If\r | |
330 | an AP is being disabled, then the state of the disabled AP is implementation\r | |
331 | dependent. If an AP is enabled, then the implementation must guarantee that a\r | |
332 | complete initialization sequence is performed on the AP, so the AP is in a state\r | |
333 | that is compatible with an MP operating system.\r | |
334 | \r | |
335 | If the enable or disable AP operation cannot be completed prior to the return\r | |
336 | from this service, then EFI_UNSUPPORTED must be returned.\r | |
337 | \r | |
338 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
339 | published by the PEI Foundation.\r | |
340 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
341 | @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
342 | total number of logical processors minus 1. The total\r | |
343 | number of logical processors can be retrieved by\r | |
344 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
345 | @param[in] EnableAP Specifies the new state for the processor for enabled,\r | |
346 | FALSE for disabled.\r | |
347 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies the\r | |
348 | new health status of the AP. This flag corresponds to\r | |
349 | StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().\r | |
350 | Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r | |
351 | bits are ignored. If it is NULL, this parameter is\r | |
352 | 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 prior\r | |
356 | 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 | **/\r | |
363 | EFI_STATUS\r | |
364 | EFIAPI\r | |
365 | PeiEnableDisableAP (\r | |
366 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
367 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
368 | IN UINTN ProcessorNumber,\r | |
369 | IN BOOLEAN EnableAP,\r | |
370 | IN UINT32 *HealthFlag OPTIONAL\r | |
371 | )\r | |
372 | {\r | |
373 | return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);\r | |
374 | }\r | |
375 | \r | |
376 | /**\r | |
377 | This return the handle number for the calling processor. This service may be\r | |
378 | called from the BSP and APs.\r | |
379 | \r | |
380 | This service returns the processor handle number for the calling processor.\r | |
381 | The returned value is in the range from 0 to the total number of logical\r | |
382 | processors minus 1. The total number of logical processors can be retrieved\r | |
383 | with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be\r | |
384 | called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r | |
385 | is returned. Otherwise, the current processors handle number is returned in\r | |
386 | ProcessorNumber, and EFI_SUCCESS is returned.\r | |
387 | \r | |
388 | @param[in] PeiServices An indirect pointer to the PEI Services Table\r | |
389 | published by the PEI Foundation.\r | |
390 | @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.\r | |
391 | @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the\r | |
392 | total number of logical processors minus 1. The total\r | |
393 | number of logical processors can be retrieved by\r | |
394 | EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().\r | |
395 | \r | |
396 | @retval EFI_SUCCESS The current processor handle number was returned in\r | |
397 | ProcessorNumber.\r | |
398 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
399 | **/\r | |
400 | EFI_STATUS\r | |
401 | EFIAPI\r | |
402 | PeiWhoAmI (\r | |
403 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
404 | IN EFI_PEI_MP_SERVICES_PPI *This,\r | |
405 | OUT UINTN *ProcessorNumber\r | |
406 | )\r | |
407 | {\r | |
408 | return MpInitLibWhoAmI (ProcessorNumber);\r | |
409 | }\r | |
410 | \r | |
ea0f431c | 411 | /**\r |
0a0d5296 | 412 | Get GDT register value.\r |
ea0f431c | 413 | \r |
0a0d5296 JW |
414 | This function is mainly for AP purpose because AP may have different GDT\r |
415 | table than BSP.\r | |
ea0f431c | 416 | \r |
0a0d5296 | 417 | @param[in,out] Buffer The pointer to private data buffer.\r |
ea0f431c | 418 | \r |
0a0d5296 JW |
419 | **/\r |
420 | VOID\r | |
421 | EFIAPI\r | |
422 | GetGdtr (\r | |
423 | IN OUT VOID *Buffer\r | |
424 | )\r | |
425 | {\r | |
426 | AsmReadGdtr ((IA32_DESCRIPTOR *)Buffer);\r | |
427 | }\r | |
428 | \r | |
429 | /**\r | |
430 | Initializes CPU exceptions handlers for the sake of stack switch requirement.\r | |
431 | \r | |
432 | This function is a wrapper of InitializeCpuExceptionHandlersEx. It's mainly\r | |
433 | for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.\r | |
434 | \r | |
435 | @param[in,out] Buffer The pointer to private data buffer.\r | |
ea0f431c JF |
436 | \r |
437 | **/\r | |
0a0d5296 | 438 | VOID\r |
ea0f431c | 439 | EFIAPI\r |
0a0d5296 JW |
440 | InitializeExceptionStackSwitchHandlers (\r |
441 | IN OUT VOID *Buffer\r | |
442 | )\r | |
443 | {\r | |
444 | CPU_EXCEPTION_INIT_DATA *EssData;\r | |
445 | IA32_DESCRIPTOR Idtr;\r | |
446 | EFI_STATUS Status;\r | |
447 | \r | |
448 | EssData = Buffer;\r | |
449 | //\r | |
450 | // We don't plan to replace IDT table with a new one, but we should not assume\r | |
451 | // the AP's IDT is the same as BSP's IDT either.\r | |
452 | //\r | |
453 | AsmReadIdtr (&Idtr);\r | |
454 | EssData->Ia32.IdtTable = (VOID *)Idtr.Base;\r | |
455 | EssData->Ia32.IdtTableSize = Idtr.Limit + 1;\r | |
456 | Status = InitializeCpuExceptionHandlersEx (NULL, EssData);\r | |
457 | ASSERT_EFI_ERROR (Status);\r | |
458 | }\r | |
459 | \r | |
460 | /**\r | |
461 | Initializes MP exceptions handlers for the sake of stack switch requirement.\r | |
462 | \r | |
463 | This function will allocate required resources required to setup stack switch\r | |
464 | and pass them through CPU_EXCEPTION_INIT_DATA to each logic processor.\r | |
465 | \r | |
466 | **/\r | |
467 | VOID\r | |
468 | InitializeMpExceptionStackSwitchHandlers (\r | |
469 | VOID\r | |
470 | )\r | |
471 | {\r | |
472 | EFI_STATUS Status;\r | |
473 | UINTN Index;\r | |
474 | UINTN Bsp;\r | |
475 | UINTN ExceptionNumber;\r | |
476 | UINTN OldGdtSize;\r | |
477 | UINTN NewGdtSize;\r | |
478 | UINTN NewStackSize;\r | |
479 | IA32_DESCRIPTOR Gdtr;\r | |
480 | CPU_EXCEPTION_INIT_DATA EssData;\r | |
481 | UINT8 *GdtBuffer;\r | |
482 | UINT8 *StackTop;\r | |
483 | UINTN NumberOfProcessors;\r | |
484 | \r | |
485 | if (!PcdGetBool (PcdCpuStackGuard)) {\r | |
486 | return;\r | |
487 | }\r | |
488 | \r | |
489 | MpInitLibGetNumberOfProcessors(&NumberOfProcessors, NULL);\r | |
490 | MpInitLibWhoAmI (&Bsp);\r | |
491 | \r | |
492 | ExceptionNumber = FixedPcdGetSize (PcdCpuStackSwitchExceptionList);\r | |
493 | NewStackSize = FixedPcdGet32 (PcdCpuKnownGoodStackSize) * ExceptionNumber;\r | |
494 | \r | |
495 | Status = PeiServicesAllocatePool (\r | |
496 | NewStackSize * NumberOfProcessors,\r | |
497 | (VOID **)&StackTop\r | |
498 | );\r | |
499 | ASSERT(StackTop != NULL);\r | |
500 | if (EFI_ERROR (Status)) {\r | |
501 | ASSERT_EFI_ERROR (Status);\r | |
502 | return;\r | |
503 | }\r | |
504 | StackTop += NewStackSize * NumberOfProcessors;\r | |
505 | \r | |
506 | //\r | |
507 | // The default exception handlers must have been initialized. Let's just skip\r | |
508 | // it in this method.\r | |
509 | //\r | |
510 | EssData.Ia32.Revision = CPU_EXCEPTION_INIT_DATA_REV;\r | |
511 | EssData.Ia32.InitDefaultHandlers = FALSE;\r | |
512 | \r | |
513 | EssData.Ia32.StackSwitchExceptions = FixedPcdGetPtr(PcdCpuStackSwitchExceptionList);\r | |
514 | EssData.Ia32.StackSwitchExceptionNumber = ExceptionNumber;\r | |
515 | EssData.Ia32.KnownGoodStackSize = FixedPcdGet32(PcdCpuKnownGoodStackSize);\r | |
516 | \r | |
517 | //\r | |
518 | // Initialize Gdtr to suppress incorrect compiler/analyzer warnings.\r | |
519 | //\r | |
520 | Gdtr.Base = 0;\r | |
521 | Gdtr.Limit = 0;\r | |
522 | for (Index = 0; Index < NumberOfProcessors; ++Index) {\r | |
523 | //\r | |
524 | // To support stack switch, we need to re-construct GDT but not IDT.\r | |
525 | //\r | |
526 | if (Index == Bsp) {\r | |
527 | GetGdtr(&Gdtr);\r | |
528 | } else {\r | |
529 | //\r | |
530 | // AP might have different size of GDT from BSP.\r | |
531 | //\r | |
532 | MpInitLibStartupThisAP (GetGdtr, Index, NULL, 0, (VOID *)&Gdtr, NULL);\r | |
533 | }\r | |
534 | \r | |
535 | //\r | |
536 | // X64 needs only one TSS of current task working for all exceptions\r | |
537 | // because of its IST feature. IA32 needs one TSS for each exception\r | |
538 | // in addition to current task. Since AP is not supposed to allocate\r | |
539 | // memory, we have to do it in BSP. To simplify the code, we allocate\r | |
540 | // memory for IA32 case to cover both IA32 and X64 exception stack\r | |
541 | // switch.\r | |
542 | //\r | |
543 | // Layout of memory to allocate for each processor:\r | |
544 | // --------------------------------\r | |
545 | // | Alignment | (just in case)\r | |
546 | // --------------------------------\r | |
547 | // | |\r | |
548 | // | Original GDT |\r | |
549 | // | |\r | |
550 | // --------------------------------\r | |
551 | // | Current task descriptor |\r | |
552 | // --------------------------------\r | |
553 | // | |\r | |
554 | // | Exception task descriptors | X ExceptionNumber\r | |
555 | // | |\r | |
556 | // --------------------------------\r | |
557 | // | Current task-state segment |\r | |
558 | // --------------------------------\r | |
559 | // | |\r | |
560 | // | Exception task-state segment | X ExceptionNumber\r | |
561 | // | |\r | |
562 | // --------------------------------\r | |
563 | //\r | |
564 | OldGdtSize = Gdtr.Limit + 1;\r | |
565 | EssData.Ia32.ExceptionTssDescSize = sizeof (IA32_TSS_DESCRIPTOR) *\r | |
566 | (ExceptionNumber + 1);\r | |
567 | EssData.Ia32.ExceptionTssSize = sizeof (IA32_TASK_STATE_SEGMENT) *\r | |
568 | (ExceptionNumber + 1);\r | |
569 | NewGdtSize = sizeof (IA32_TSS_DESCRIPTOR) +\r | |
570 | OldGdtSize +\r | |
571 | EssData.Ia32.ExceptionTssDescSize +\r | |
572 | EssData.Ia32.ExceptionTssSize;\r | |
573 | \r | |
574 | Status = PeiServicesAllocatePool (\r | |
575 | NewGdtSize,\r | |
576 | (VOID **)&GdtBuffer\r | |
577 | );\r | |
578 | ASSERT (GdtBuffer != NULL);\r | |
579 | if (EFI_ERROR (Status)) {\r | |
580 | ASSERT_EFI_ERROR (Status);\r | |
581 | return;\r | |
582 | }\r | |
583 | \r | |
584 | //\r | |
585 | // Make sure GDT table alignment\r | |
586 | //\r | |
587 | EssData.Ia32.GdtTable = ALIGN_POINTER(GdtBuffer, sizeof (IA32_TSS_DESCRIPTOR));\r | |
588 | NewGdtSize -= ((UINT8 *)EssData.Ia32.GdtTable - GdtBuffer);\r | |
589 | EssData.Ia32.GdtTableSize = NewGdtSize;\r | |
590 | \r | |
591 | EssData.Ia32.ExceptionTssDesc = ((UINT8 *)EssData.Ia32.GdtTable + OldGdtSize);\r | |
592 | EssData.Ia32.ExceptionTss = ((UINT8 *)EssData.Ia32.GdtTable + OldGdtSize +\r | |
593 | EssData.Ia32.ExceptionTssDescSize);\r | |
594 | \r | |
595 | EssData.Ia32.KnownGoodStackTop = (UINTN)StackTop;\r | |
596 | DEBUG ((DEBUG_INFO,\r | |
597 | "Exception stack top[cpu%lu]: 0x%lX\n",\r | |
598 | (UINT64)(UINTN)Index,\r | |
599 | (UINT64)(UINTN)StackTop));\r | |
600 | \r | |
601 | if (Index == Bsp) {\r | |
602 | InitializeExceptionStackSwitchHandlers (&EssData);\r | |
603 | } else {\r | |
604 | MpInitLibStartupThisAP (\r | |
605 | InitializeExceptionStackSwitchHandlers,\r | |
606 | Index,\r | |
607 | NULL,\r | |
608 | 0,\r | |
609 | (VOID *)&EssData,\r | |
610 | NULL\r | |
611 | );\r | |
612 | }\r | |
613 | \r | |
614 | StackTop -= NewStackSize;\r | |
615 | }\r | |
616 | }\r | |
617 | \r | |
618 | /**\r | |
619 | Initializes MP and exceptions handlers.\r | |
620 | \r | |
621 | @param PeiServices The pointer to the PEI Services Table.\r | |
622 | \r | |
623 | @retval EFI_SUCCESS MP was successfully initialized.\r | |
624 | @retval others Error occurred in MP initialization.\r | |
625 | \r | |
626 | **/\r | |
627 | EFI_STATUS\r | |
628 | InitializeCpuMpWorker (\r | |
ea0f431c JF |
629 | IN CONST EFI_PEI_SERVICES **PeiServices\r |
630 | )\r | |
631 | {\r | |
0a0d5296 | 632 | EFI_STATUS Status;\r |
9bedfb2f JF |
633 | EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r |
634 | EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r | |
ea0f431c | 635 | \r |
ea0f431c | 636 | //\r |
9bedfb2f JF |
637 | // Get Vector Hand-off Info PPI\r |
638 | //\r | |
639 | VectorInfo = NULL;\r | |
640 | Status = PeiServicesLocatePpi (\r | |
641 | &gEfiVectorHandoffInfoPpiGuid,\r | |
642 | 0,\r | |
643 | NULL,\r | |
644 | (VOID **)&VectorHandoffInfoPpi\r | |
645 | );\r | |
646 | if (Status == EFI_SUCCESS) {\r | |
647 | VectorInfo = VectorHandoffInfoPpi->Info;\r | |
648 | }\r | |
7367cc6c | 649 | \r |
9bedfb2f | 650 | //\r |
0a0d5296 | 651 | // Initialize default handlers\r |
ea0f431c | 652 | //\r |
0a0d5296 JW |
653 | Status = InitializeCpuExceptionHandlers (VectorInfo);\r |
654 | if (EFI_ERROR (Status)) {\r | |
655 | return Status;\r | |
656 | }\r | |
657 | \r | |
a1a4c7a4 | 658 | Status = MpInitLibInitialize ();\r |
0a0d5296 JW |
659 | if (EFI_ERROR (Status)) {\r |
660 | return Status;\r | |
661 | }\r | |
662 | \r | |
663 | //\r | |
664 | // Special initialization for the sake of Stack Guard\r | |
665 | //\r | |
666 | InitializeMpExceptionStackSwitchHandlers ();\r | |
a1a4c7a4 | 667 | \r |
ea0f431c JF |
668 | //\r |
669 | // Update and publish CPU BIST information\r | |
670 | //\r | |
a1a4c7a4 JF |
671 | CollectBistDataFromPpi (PeiServices);\r |
672 | \r | |
ea0f431c JF |
673 | //\r |
674 | // Install CPU MP PPI\r | |
675 | //\r | |
676 | Status = PeiServicesInstallPpi(&mPeiCpuMpPpiDesc);\r | |
677 | ASSERT_EFI_ERROR (Status);\r | |
678 | \r | |
679 | return Status;\r | |
680 | }\r | |
0a0d5296 JW |
681 | \r |
682 | /**\r | |
683 | The Entry point of the MP CPU PEIM.\r | |
684 | \r | |
685 | This function will wakeup APs and collect CPU AP count and install the\r | |
686 | Mp Service Ppi.\r | |
687 | \r | |
688 | @param FileHandle Handle of the file being invoked.\r | |
689 | @param PeiServices Describes the list of possible PEI Services.\r | |
690 | \r | |
691 | @retval EFI_SUCCESS MpServicePpi is installed successfully.\r | |
692 | \r | |
693 | **/\r | |
694 | EFI_STATUS\r | |
695 | EFIAPI\r | |
696 | CpuMpPeimInit (\r | |
697 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
698 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
699 | )\r | |
700 | {\r | |
701 | EFI_STATUS Status;\r | |
702 | \r | |
703 | //\r | |
704 | // For the sake of special initialization needing to be done right after\r | |
705 | // memory discovery.\r | |
706 | //\r | |
707 | Status = PeiServicesNotifyPpi (&mPostMemNotifyList[0]);\r | |
708 | ASSERT_EFI_ERROR (Status);\r | |
709 | \r | |
710 | return Status;\r | |
711 | }\r |