Commit | Line | Data |
---|---|---|
65e79f93 JF |
1 | /** @file |
2 | CPU PEI Module installs CPU Multiple Processor PPI. | |
3 | ||
4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> | |
5 | This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | **/ | |
14 | ||
15 | #include "CpuMpPei.h" | |
16 | ||
f9d30595 JF |
17 | // |
18 | // Global Descriptor Table (GDT) | |
19 | // | |
20 | GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = { | |
21 | /* selector { Global Segment Descriptor } */ | |
22 | /* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor | |
23 | /* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor | |
24 | /* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor | |
25 | /* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor | |
26 | /* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor | |
27 | /* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor | |
28 | /* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor | |
29 | /* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor | |
30 | /* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor | |
31 | }; | |
32 | ||
33 | // | |
34 | // IA32 Gdt register | |
35 | // | |
36 | GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = { | |
37 | sizeof (mGdtEntries) - 1, | |
38 | (UINTN) mGdtEntries | |
39 | }; | |
40 | ||
8f7b315b JF |
41 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = { |
42 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), | |
43 | &gEfiEndOfPeiSignalPpiGuid, | |
44 | CpuMpEndOfPeiCallback | |
45 | }; | |
46 | ||
f8e4e86b JF |
47 | /** |
48 | Sort the APIC ID of all processors. | |
49 | ||
50 | This function sorts the APIC ID of all processors so that processor number is | |
51 | assigned in the ascending order of APIC ID which eases MP debugging. | |
52 | ||
53 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
54 | **/ | |
55 | VOID | |
56 | SortApicId ( | |
57 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
58 | ) | |
59 | { | |
60 | UINTN Index1; | |
61 | UINTN Index2; | |
62 | UINTN Index3; | |
63 | UINT32 ApicId; | |
64 | EFI_HEALTH_FLAGS Health; | |
65 | UINT32 ApCount; | |
66 | ||
67 | ApCount = PeiCpuMpData->CpuCount - 1; | |
68 | ||
69 | if (ApCount != 0) { | |
70 | for (Index1 = 0; Index1 < ApCount; Index1++) { | |
71 | Index3 = Index1; | |
72 | // | |
73 | // Sort key is the hardware default APIC ID | |
74 | // | |
75 | ApicId = PeiCpuMpData->CpuData[Index1].ApicId; | |
76 | for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) { | |
77 | if (ApicId > PeiCpuMpData->CpuData[Index2].ApicId) { | |
78 | Index3 = Index2; | |
79 | ApicId = PeiCpuMpData->CpuData[Index2].ApicId; | |
80 | } | |
81 | } | |
82 | if (Index3 != Index1) { | |
83 | PeiCpuMpData->CpuData[Index3].ApicId = PeiCpuMpData->CpuData[Index1].ApicId; | |
84 | PeiCpuMpData->CpuData[Index1].ApicId = ApicId; | |
85 | Health = PeiCpuMpData->CpuData[Index3].Health; | |
86 | PeiCpuMpData->CpuData[Index3].Health = PeiCpuMpData->CpuData[Index1].Health; | |
87 | PeiCpuMpData->CpuData[Index1].Health = Health; | |
88 | } | |
89 | } | |
90 | ||
91 | // | |
92 | // Get the processor number for the BSP | |
93 | // | |
94 | ApicId = GetInitialApicId (); | |
95 | for (Index1 = 0; Index1 < PeiCpuMpData->CpuCount; Index1++) { | |
96 | if (PeiCpuMpData->CpuData[Index1].ApicId == ApicId) { | |
97 | PeiCpuMpData->BspNumber = (UINT32) Index1; | |
98 | break; | |
99 | } | |
100 | } | |
101 | } | |
102 | } | |
8805c912 JF |
103 | |
104 | /** | |
105 | Get CPU MP Data pointer from the Guided HOB. | |
106 | ||
107 | @return Pointer to Pointer to PEI CPU MP Data | |
108 | **/ | |
109 | PEI_CPU_MP_DATA * | |
110 | GetMpHobData ( | |
111 | VOID | |
112 | ) | |
113 | { | |
114 | EFI_HOB_GUID_TYPE *GuidHob; | |
115 | VOID *DataInHob; | |
116 | PEI_CPU_MP_DATA *CpuMpData; | |
117 | ||
118 | CpuMpData = NULL; | |
119 | GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid); | |
120 | if (GuidHob != NULL) { | |
121 | DataInHob = GET_GUID_HOB_DATA (GuidHob); | |
122 | CpuMpData = (PEI_CPU_MP_DATA *)(*(UINTN *)DataInHob); | |
123 | } | |
124 | ASSERT (CpuMpData != NULL); | |
125 | return CpuMpData; | |
126 | } | |
127 | ||
7d51bf5c JF |
128 | /** |
129 | This function will be called from AP reset code if BSP uses WakeUpAP. | |
130 | ||
131 | @param ExchangeInfo Pointer to the MP exchange info buffer | |
132 | @param NumApsExecuting Number of curret executing AP | |
133 | **/ | |
134 | VOID | |
135 | EFIAPI | |
136 | ApCFunction ( | |
137 | IN MP_CPU_EXCHANGE_INFO *ExchangeInfo, | |
138 | IN UINTN NumApsExecuting | |
139 | ) | |
140 | { | |
141 | PEI_CPU_MP_DATA *PeiCpuMpData; | |
60ca9e8c JF |
142 | UINTN ProcessorNumber; |
143 | EFI_AP_PROCEDURE Procedure; | |
7d51bf5c JF |
144 | UINTN BistData; |
145 | ||
146 | PeiCpuMpData = ExchangeInfo->PeiCpuMpData; | |
147 | if (PeiCpuMpData->InitFlag) { | |
148 | // | |
149 | // This is first time AP wakeup, get BIST inforamtion from AP stack | |
150 | // | |
151 | BistData = *(UINTN *) (PeiCpuMpData->Buffer + NumApsExecuting * PeiCpuMpData->CpuApStackSize - sizeof (UINTN)); | |
152 | PeiCpuMpData->CpuData[NumApsExecuting].ApicId = GetInitialApicId (); | |
153 | PeiCpuMpData->CpuData[NumApsExecuting].Health.Uint32 = (UINT32) BistData; | |
b4cd9f78 | 154 | // |
d1cf9333 | 155 | // Sync BSP's Mtrr table to all wakeup APs and load microcode on APs. |
b4cd9f78 JF |
156 | // |
157 | MtrrSetAllMtrrs (&PeiCpuMpData->MtrrTable); | |
d1cf9333 | 158 | MicrocodeDetect (); |
60ca9e8c JF |
159 | } else { |
160 | // | |
161 | // Execute AP function if AP is not disabled | |
162 | // | |
163 | GetProcessorNumber (PeiCpuMpData, &ProcessorNumber); | |
164 | if ((PeiCpuMpData->CpuData[ProcessorNumber].State != CpuStateDisabled) && | |
165 | (PeiCpuMpData->ApFunction != 0)) { | |
166 | PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateBusy; | |
167 | Procedure = (EFI_AP_PROCEDURE)(UINTN)PeiCpuMpData->ApFunction; | |
168 | Procedure ((VOID *)(UINTN)PeiCpuMpData->ApFunctionArgument); | |
169 | PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateIdle; | |
170 | } | |
7d51bf5c JF |
171 | } |
172 | ||
173 | // | |
174 | // AP finished executing C code | |
175 | // | |
176 | InterlockedIncrement ((UINT32 *)&PeiCpuMpData->FinishedCount); | |
177 | ||
fcc82734 | 178 | AsmCliHltLoop (); |
7d51bf5c JF |
179 | } |
180 | ||
181 | /** | |
182 | This function will be called by BSP to wakeup AP. | |
183 | ||
184 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
185 | @param Broadcast TRUE: Send broadcast IPI to all APs | |
186 | FALSE: Send IPI to AP by ApicId | |
187 | @param ApicId Apic ID for the processor to be waked | |
188 | @param Procedure The function to be invoked by AP | |
189 | @param ProcedureArgument The argument to be passed into AP function | |
190 | **/ | |
191 | VOID | |
192 | WakeUpAP ( | |
193 | IN PEI_CPU_MP_DATA *PeiCpuMpData, | |
194 | IN BOOLEAN Broadcast, | |
195 | IN UINT32 ApicId, | |
196 | IN EFI_AP_PROCEDURE Procedure, OPTIONAL | |
197 | IN VOID *ProcedureArgument OPTIONAL | |
198 | ) | |
199 | { | |
200 | volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo; | |
201 | ||
202 | PeiCpuMpData->ApFunction = (UINTN) Procedure; | |
203 | PeiCpuMpData->ApFunctionArgument = (UINTN) ProcedureArgument; | |
204 | PeiCpuMpData->FinishedCount = 0; | |
205 | ||
206 | ExchangeInfo = PeiCpuMpData->MpCpuExchangeInfo; | |
207 | ExchangeInfo->Lock = 0; | |
208 | ExchangeInfo->StackStart = PeiCpuMpData->Buffer; | |
209 | ExchangeInfo->StackSize = PeiCpuMpData->CpuApStackSize; | |
210 | ExchangeInfo->BufferStart = PeiCpuMpData->WakeupBuffer; | |
211 | ExchangeInfo->PmodeOffset = PeiCpuMpData->AddressMap.PModeEntryOffset; | |
212 | ExchangeInfo->LmodeOffset = PeiCpuMpData->AddressMap.LModeEntryOffset; | |
213 | ExchangeInfo->Cr3 = AsmReadCr3 (); | |
214 | ExchangeInfo->CFunction = (UINTN) ApCFunction; | |
215 | ExchangeInfo->NumApsExecuting = 0; | |
216 | ExchangeInfo->PeiCpuMpData = PeiCpuMpData; | |
217 | ||
218 | // | |
219 | // Get the BSP's data of GDT and IDT | |
220 | // | |
221 | CopyMem ((VOID *)&ExchangeInfo->GdtrProfile, &mGdt, sizeof(mGdt)); | |
222 | AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile); | |
223 | ||
224 | if (Broadcast) { | |
225 | SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart); | |
226 | } else { | |
227 | SendInitSipiSipi (ApicId, (UINT32) ExchangeInfo->BufferStart); | |
228 | } | |
229 | ||
230 | return ; | |
231 | } | |
232 | ||
05e107f8 JF |
233 | /** |
234 | Get available system memory below 1MB by specified size. | |
235 | ||
236 | @param WakeupBufferSize Wakeup buffer size required | |
237 | ||
238 | @retval other Return wakeup buffer address below 1MB. | |
239 | @retval -1 Cannot find free memory below 1MB. | |
240 | **/ | |
241 | UINTN | |
242 | GetWakeupBuffer ( | |
243 | IN UINTN WakeupBufferSize | |
244 | ) | |
245 | { | |
246 | EFI_PEI_HOB_POINTERS Hob; | |
247 | UINTN WakeupBufferStart; | |
248 | UINTN WakeupBufferEnd; | |
249 | ||
250 | // | |
251 | // Get the HOB list for processing | |
252 | // | |
253 | Hob.Raw = GetHobList (); | |
254 | ||
255 | // | |
256 | // Collect memory ranges | |
257 | // | |
258 | while (!END_OF_HOB_LIST (Hob)) { | |
259 | if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { | |
260 | if ((Hob.ResourceDescriptor->PhysicalStart < BASE_1MB) && | |
261 | (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && | |
262 | ((Hob.ResourceDescriptor->ResourceAttribute & | |
263 | (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | | |
264 | EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | | |
265 | EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | |
266 | )) == 0) | |
267 | ) { | |
268 | // | |
269 | // Need memory under 1MB to be collected here | |
270 | // | |
271 | WakeupBufferEnd = (UINTN) (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength); | |
272 | if (WakeupBufferEnd > BASE_1MB) { | |
273 | // | |
274 | // Wakeup buffer should be under 1MB | |
275 | // | |
276 | WakeupBufferEnd = BASE_1MB; | |
277 | } | |
278 | // | |
279 | // Wakeup buffer should be aligned on 4KB | |
280 | // | |
281 | WakeupBufferStart = (WakeupBufferEnd - WakeupBufferSize) & ~(SIZE_4KB - 1); | |
282 | if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) { | |
283 | continue; | |
284 | } | |
285 | // | |
286 | // Create a memory allocation HOB. | |
287 | // | |
288 | BuildMemoryAllocationHob ( | |
289 | WakeupBufferStart, | |
290 | WakeupBufferSize, | |
291 | EfiBootServicesData | |
292 | ); | |
293 | return WakeupBufferStart; | |
294 | } | |
295 | } | |
296 | // | |
297 | // Find the next HOB | |
298 | // | |
299 | Hob.Raw = GET_NEXT_HOB (Hob); | |
300 | } | |
301 | ||
302 | return (UINTN) -1; | |
303 | } | |
65e79f93 | 304 | |
e66d675d JF |
305 | /** |
306 | Get available system memory below 1MB by specified size. | |
307 | ||
308 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
309 | **/ | |
310 | VOID | |
311 | BackupAndPrepareWakeupBuffer( | |
312 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
313 | ) | |
314 | { | |
315 | CopyMem ( | |
316 | (VOID *) PeiCpuMpData->BackupBuffer, | |
317 | (VOID *) PeiCpuMpData->WakeupBuffer, | |
318 | PeiCpuMpData->BackupBufferSize | |
319 | ); | |
320 | CopyMem ( | |
321 | (VOID *) PeiCpuMpData->WakeupBuffer, | |
322 | (VOID *) PeiCpuMpData->AddressMap.RendezvousFunnelAddress, | |
323 | PeiCpuMpData->AddressMap.RendezvousFunnelSize | |
324 | ); | |
325 | } | |
8f7b315b JF |
326 | |
327 | /** | |
328 | Restore wakeup buffer data. | |
329 | ||
330 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
331 | **/ | |
332 | VOID | |
333 | RestoreWakeupBuffer( | |
334 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
335 | ) | |
336 | { | |
337 | CopyMem ((VOID *) PeiCpuMpData->WakeupBuffer, (VOID *) PeiCpuMpData->BackupBuffer, PeiCpuMpData->BackupBufferSize); | |
338 | } | |
339 | ||
7d51bf5c JF |
340 | /** |
341 | This function will get CPU count in the system. | |
342 | ||
343 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
344 | ||
345 | @return AP processor count | |
346 | **/ | |
347 | UINT32 | |
348 | CountProcessorNumber ( | |
349 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
350 | ) | |
351 | { | |
d1cf9333 JF |
352 | // |
353 | // Load Microcode on BSP | |
354 | // | |
355 | MicrocodeDetect (); | |
b4cd9f78 JF |
356 | // |
357 | // Store BSP's MTRR setting | |
358 | // | |
359 | MtrrGetAllMtrrs (&PeiCpuMpData->MtrrTable); | |
7d51bf5c JF |
360 | // |
361 | // Send broadcast IPI to APs to wakeup APs | |
362 | // | |
363 | PeiCpuMpData->InitFlag = 1; | |
364 | WakeUpAP (PeiCpuMpData, TRUE, 0, NULL, NULL); | |
365 | // | |
366 | // Wait for AP task to complete and then exit. | |
367 | // | |
368 | MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds)); | |
369 | PeiCpuMpData->InitFlag = 0; | |
370 | PeiCpuMpData->CpuCount += (UINT32) PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting; | |
f8e4e86b JF |
371 | // |
372 | // Sort BSP/Aps by CPU APIC ID in ascending order | |
373 | // | |
374 | SortApicId (PeiCpuMpData); | |
7d51bf5c JF |
375 | |
376 | DEBUG ((EFI_D_INFO, "CpuMpPei: Find %d processors in system.\n", PeiCpuMpData->CpuCount)); | |
377 | return PeiCpuMpData->CpuCount; | |
378 | } | |
379 | ||
e66d675d JF |
380 | /** |
381 | Prepare for AP wakeup buffer and copy AP reset code into it. | |
382 | ||
383 | Get wakeup buffer below 1MB. Allocate memory for CPU MP Data and APs Stack. | |
384 | ||
385 | @return Pointer to PEI CPU MP Data | |
386 | **/ | |
387 | PEI_CPU_MP_DATA * | |
388 | PrepareAPStartupVector ( | |
389 | VOID | |
390 | ) | |
391 | { | |
392 | EFI_STATUS Status; | |
393 | UINT32 MaxCpuCount; | |
394 | PEI_CPU_MP_DATA *PeiCpuMpData; | |
395 | EFI_PHYSICAL_ADDRESS Buffer; | |
396 | UINTN BufferSize; | |
397 | UINTN WakeupBuffer; | |
398 | UINTN WakeupBufferSize; | |
399 | MP_ASSEMBLY_ADDRESS_MAP AddressMap; | |
400 | ||
401 | AsmGetAddressMap (&AddressMap); | |
402 | WakeupBufferSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO); | |
403 | WakeupBuffer = GetWakeupBuffer ((WakeupBufferSize + SIZE_4KB - 1) & ~(SIZE_4KB - 1)); | |
8f7b315b | 404 | ASSERT (WakeupBuffer != (UINTN) -1); |
e66d675d JF |
405 | DEBUG ((EFI_D_INFO, "CpuMpPei: WakeupBuffer = 0x%x\n", WakeupBuffer)); |
406 | ||
407 | // | |
408 | // Allocate Pages for APs stack, CPU MP Data and backup buffer for wakeup buffer | |
409 | // | |
410 | MaxCpuCount = PcdGet32(PcdCpuMaxLogicalProcessorNumber); | |
411 | BufferSize = PcdGet32 (PcdCpuApStackSize) * MaxCpuCount + sizeof (PEI_CPU_MP_DATA) | |
412 | + WakeupBufferSize + sizeof (PEI_CPU_DATA) * MaxCpuCount; | |
413 | Status = PeiServicesAllocatePages ( | |
414 | EfiBootServicesData, | |
415 | EFI_SIZE_TO_PAGES (BufferSize), | |
416 | &Buffer | |
417 | ); | |
418 | ASSERT_EFI_ERROR (Status); | |
419 | ||
420 | PeiCpuMpData = (PEI_CPU_MP_DATA *) (UINTN) (Buffer + PcdGet32 (PcdCpuApStackSize) * MaxCpuCount); | |
421 | PeiCpuMpData->Buffer = (UINTN) Buffer; | |
422 | PeiCpuMpData->CpuApStackSize = PcdGet32 (PcdCpuApStackSize); | |
423 | PeiCpuMpData->WakeupBuffer = WakeupBuffer; | |
424 | PeiCpuMpData->BackupBuffer = (UINTN)PeiCpuMpData + sizeof (PEI_CPU_MP_DATA); | |
425 | PeiCpuMpData->BackupBufferSize = WakeupBufferSize; | |
426 | PeiCpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) (WakeupBuffer + AddressMap.RendezvousFunnelSize); | |
427 | ||
428 | PeiCpuMpData->CpuCount = 1; | |
429 | PeiCpuMpData->BspNumber = 0; | |
430 | PeiCpuMpData->CpuData = (PEI_CPU_DATA *) (PeiCpuMpData->MpCpuExchangeInfo + 1); | |
431 | PeiCpuMpData->CpuData[0].ApicId = GetInitialApicId (); | |
432 | PeiCpuMpData->CpuData[0].Health.Uint32 = 0; | |
8f7b315b | 433 | PeiCpuMpData->EndOfPeiFlag = FALSE; |
e66d675d JF |
434 | CopyMem (&PeiCpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP)); |
435 | ||
436 | // | |
437 | // Backup original data and copy AP reset code in it | |
438 | // | |
439 | BackupAndPrepareWakeupBuffer(PeiCpuMpData); | |
440 | ||
441 | return PeiCpuMpData; | |
442 | } | |
8f7b315b JF |
443 | |
444 | /** | |
445 | Notify function on End Of Pei PPI. | |
446 | ||
447 | On S3 boot, this function will restore wakeup buffer data. | |
448 | On normal boot, this function will flag wakeup buffer to be un-used type. | |
449 | ||
450 | @param PeiServices The pointer to the PEI Services Table. | |
451 | @param NotifyDescriptor Address of the notification descriptor data structure. | |
452 | @param Ppi Address of the PPI that was installed. | |
453 | ||
454 | @retval EFI_SUCCESS When everything is OK. | |
455 | ||
456 | **/ | |
457 | EFI_STATUS | |
458 | EFIAPI | |
459 | CpuMpEndOfPeiCallback ( | |
460 | IN EFI_PEI_SERVICES **PeiServices, | |
461 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, | |
462 | IN VOID *Ppi | |
463 | ) | |
464 | { | |
465 | EFI_STATUS Status; | |
466 | EFI_BOOT_MODE BootMode; | |
467 | PEI_CPU_MP_DATA *PeiCpuMpData; | |
468 | EFI_PEI_HOB_POINTERS Hob; | |
469 | EFI_HOB_MEMORY_ALLOCATION *MemoryHob; | |
470 | ||
471 | DEBUG ((EFI_D_INFO, "CpuMpPei: CpuMpEndOfPeiCallback () invokded\n")); | |
472 | ||
473 | Status = PeiServicesGetBootMode (&BootMode); | |
474 | ASSERT_EFI_ERROR (Status); | |
475 | ||
476 | PeiCpuMpData = GetMpHobData (); | |
477 | ASSERT (PeiCpuMpData != NULL); | |
478 | ||
479 | if (BootMode != BOOT_ON_S3_RESUME) { | |
480 | // | |
481 | // Get the HOB list for processing | |
482 | // | |
483 | Hob.Raw = GetHobList (); | |
484 | // | |
485 | // Collect memory ranges | |
486 | // | |
487 | while (!END_OF_HOB_LIST (Hob)) { | |
488 | if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) { | |
489 | MemoryHob = Hob.MemoryAllocation; | |
490 | if(MemoryHob->AllocDescriptor.MemoryBaseAddress == PeiCpuMpData->WakeupBuffer) { | |
491 | // | |
492 | // Flag this HOB type to un-used | |
493 | // | |
494 | GET_HOB_TYPE (Hob) = EFI_HOB_TYPE_UNUSED; | |
495 | break; | |
496 | } | |
497 | } | |
498 | Hob.Raw = GET_NEXT_HOB (Hob); | |
499 | } | |
500 | } else { | |
501 | RestoreWakeupBuffer (PeiCpuMpData); | |
502 | PeiCpuMpData->EndOfPeiFlag = TRUE; | |
503 | } | |
504 | return EFI_SUCCESS; | |
505 | } | |
506 | ||
65e79f93 JF |
507 | /** |
508 | The Entry point of the MP CPU PEIM. | |
509 | ||
510 | This function will wakeup APs and collect CPU AP count and install the | |
511 | Mp Service Ppi. | |
512 | ||
513 | @param FileHandle Handle of the file being invoked. | |
514 | @param PeiServices Describes the list of possible PEI Services. | |
515 | ||
516 | @retval EFI_SUCCESS MpServicePpi is installed successfully. | |
517 | ||
518 | **/ | |
519 | EFI_STATUS | |
520 | EFIAPI | |
521 | CpuMpPeimInit ( | |
522 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
523 | IN CONST EFI_PEI_SERVICES **PeiServices | |
524 | ) | |
525 | { | |
e35d0347 | 526 | EFI_STATUS Status; |
e66d675d | 527 | PEI_CPU_MP_DATA *PeiCpuMpData; |
7d51bf5c | 528 | UINT32 ProcessorCount; |
65e79f93 | 529 | |
f9d30595 JF |
530 | // |
531 | // Load new GDT table on BSP | |
532 | // | |
533 | AsmInitializeGdt (&mGdt); | |
e66d675d JF |
534 | // |
535 | // Get wakeup buffer and copy AP reset code in it | |
536 | // | |
537 | PeiCpuMpData = PrepareAPStartupVector (); | |
7d51bf5c JF |
538 | // |
539 | // Count processor number and collect processor information | |
540 | // | |
541 | ProcessorCount = CountProcessorNumber (PeiCpuMpData); | |
8805c912 JF |
542 | // |
543 | // Build location of PEI CPU MP DATA buffer in HOB | |
544 | // | |
545 | BuildGuidDataHob ( | |
546 | &gEfiCallerIdGuid, | |
547 | (VOID *)&PeiCpuMpData, | |
548 | sizeof(UINT64) | |
549 | ); | |
a21fe428 JF |
550 | // |
551 | // Update and publish CPU BIST information | |
552 | // | |
553 | CollectBistDataFromPpi (PeiServices, PeiCpuMpData); | |
e35d0347 | 554 | // |
8f7b315b JF |
555 | // register an event for EndOfPei |
556 | // | |
557 | Status = PeiServicesNotifyPpi (&mNotifyList); | |
558 | ASSERT_EFI_ERROR (Status); | |
559 | // | |
e35d0347 JF |
560 | // Install CPU MP PPI |
561 | // | |
562 | Status = PeiServicesInstallPpi(&mPeiCpuMpPpiDesc); | |
563 | ASSERT_EFI_ERROR (Status); | |
65e79f93 | 564 | |
e35d0347 | 565 | return Status; |
65e79f93 | 566 | } |