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