]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Use StrnCat instead of StrCat to avoid target buffer overflow.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 EFI PEI Core dispatch services\r
3 \r
21d9882c 4Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
192f6d4c 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
615c6dd0 13**/\r
192f6d4c 14\r
0d516397 15#include "PeiMain.h"\r
192f6d4c 16\r
b1f6a7c6 17///\r
3d4d0c34 18/// temporary memory is filled with this initial value during SEC phase\r
b1f6a7c6 19///\r
a7715e73 20#define INIT_CAR_VALUE 0x5AA55AA5\r
21\r
797a9d67 22typedef struct {\r
23 EFI_STATUS_CODE_DATA DataHeader;\r
24 EFI_HANDLE Handle;\r
25} PEIM_FILE_HANDLE_EXTENDED_DATA;\r
26\r
b1f6a7c6 27/**\r
b0d803fe 28\r
29 Discover all Peims and optional Apriori file in one FV. There is at most one\r
30 Apriori file in one FV.\r
31\r
b0d803fe 32\r
3b428ade 33 @param Private Pointer to the private data passed in from caller\r
34 @param CoreFileHandle The instance of PEI_CORE_FV_HANDLE.\r
b0d803fe 35\r
b1f6a7c6 36**/\r
37VOID\r
38DiscoverPeimsAndOrderWithApriori (\r
39 IN PEI_CORE_INSTANCE *Private,\r
3b428ade 40 IN PEI_CORE_FV_HANDLE *CoreFileHandle\r
b1f6a7c6 41 )\r
b0d803fe 42{\r
43 EFI_STATUS Status;\r
890e5417 44 EFI_PEI_FILE_HANDLE FileHandle;\r
177aabe6 45 EFI_PEI_FILE_HANDLE AprioriFileHandle;\r
b0d803fe 46 EFI_GUID *Apriori;\r
47 UINTN Index;\r
48 UINTN Index2;\r
49 UINTN PeimIndex;\r
50 UINTN PeimCount;\r
51 EFI_GUID *Guid;\r
9b8e61be 52 EFI_PEI_FILE_HANDLE TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv) + 1];\r
177aabe6 53 EFI_GUID FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
3b428ade 54 EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r
55 EFI_FV_FILE_INFO FileInfo;\r
56 \r
57 FvPpi = CoreFileHandle->FvPpi;\r
58 \r
b0d803fe 59 //\r
60 // Walk the FV and find all the PEIMs and the Apriori file.\r
61 //\r
62 AprioriFileHandle = NULL;\r
63 Private->CurrentFvFileHandles[0] = NULL;\r
64 Guid = NULL;\r
65 FileHandle = NULL;\r
66\r
67 //\r
68 // If the current Fv has been scanned, directly get its cachable record.\r
69 //\r
70 if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r
71 CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
72 return;\r
73 }\r
74\r
75 //\r
76 // Go ahead to scan this Fv, and cache FileHandles within it.\r
77 //\r
9b8e61be
LG
78 Status = EFI_NOT_FOUND;\r
79 for (PeimCount = 0; PeimCount <= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
3b428ade 80 Status = FvPpi->FindFileByType (FvPpi, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle, &FileHandle);\r
9b8e61be 81 if (Status != EFI_SUCCESS || PeimCount == FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
b0d803fe 82 break;\r
83 }\r
58dcdada 84\r
b0d803fe 85 Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
86 }\r
9b8e61be 87\r
97b2c9b5 88 //\r
21d9882c
LG
89 // Check whether the count of files exceeds the max support files in a FV image\r
90 // If more files are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.\r
97b2c9b5 91 //\r
9b8e61be 92 ASSERT ((Status != EFI_SUCCESS) || (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)));\r
b0d803fe 93\r
3b428ade 94 //\r
95 // Get Apriori File handle\r
96 //\r
58dcdada 97 Private->AprioriCount = 0;\r
3b428ade 98 Status = FvPpi->FindFileByName (FvPpi, &gPeiAprioriFileNameGuid, &CoreFileHandle->FvHandle, &AprioriFileHandle);\r
99 if (!EFI_ERROR(Status) && AprioriFileHandle != NULL) {\r
b0d803fe 100 //\r
101 // Read the Apriori file\r
102 //\r
3b428ade 103 Status = FvPpi->FindSectionByType (FvPpi, EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r
b0d803fe 104 if (!EFI_ERROR (Status)) {\r
105 //\r
106 // Calculate the number of PEIMs in the A Priori list\r
107 //\r
3b428ade 108 Status = FvPpi->GetFileInfo (FvPpi, AprioriFileHandle, &FileInfo);\r
109 ASSERT_EFI_ERROR (Status);\r
890e5417
SZ
110 Private->AprioriCount = FileInfo.BufferSize;\r
111 if (IS_SECTION2 (FileInfo.Buffer)) {\r
112 Private->AprioriCount -= sizeof (EFI_COMMON_SECTION_HEADER2);\r
113 } else {\r
114 Private->AprioriCount -= sizeof (EFI_COMMON_SECTION_HEADER);\r
115 }\r
b0d803fe 116 Private->AprioriCount /= sizeof (EFI_GUID);\r
58dcdada 117\r
82b8c8df 118 ZeroMem (FileGuid, sizeof (FileGuid));\r
b0d803fe 119 for (Index = 0; Index < PeimCount; Index++) {\r
120 //\r
121 // Make an array of file name guids that matches the FileHandle array so we can convert\r
122 // quickly from file name to file handle\r
123 //\r
3b428ade 124 Status = FvPpi->GetFileInfo (FvPpi, Private->CurrentFvFileHandles[Index], &FileInfo);\r
125 CopyMem (&FileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID));\r
b0d803fe 126 }\r
127\r
128 //\r
129 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r
890e5417 130 // Add available PEIMs in Apriori file into TempFileHandles array at first.\r
b0d803fe 131 //\r
132 Index2 = 0;\r
133 for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r
134 while (Index2 < Private->AprioriCount) {\r
135 Guid = ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2++]);\r
136 if (Guid != NULL) {\r
137 break;\r
138 }\r
139 }\r
140 if (Guid == NULL) {\r
58dcdada 141 break;\r
b0d803fe 142 }\r
143 PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r
144 TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r
145\r
146 //\r
147 // Since we have copied the file handle we can remove it from this list.\r
148 //\r
149 Private->CurrentFvFileHandles[PeimIndex] = NULL;\r
150 }\r
151\r
152 //\r
153 // Update valid Aprioricount\r
154 //\r
155 Private->AprioriCount = Index;\r
58dcdada 156\r
b0d803fe 157 //\r
158 // Add in any PEIMs not in the Apriori file\r
159 //\r
160 for (;Index < PeimCount; Index++) {\r
161 for (Index2 = 0; Index2 < PeimCount; Index2++) {\r
162 if (Private->CurrentFvFileHandles[Index2] != NULL) {\r
163 TempFileHandles[Index] = Private->CurrentFvFileHandles[Index2];\r
164 Private->CurrentFvFileHandles[Index2] = NULL;\r
165 break;\r
166 }\r
167 }\r
168 }\r
169 //\r
170 //Index the end of array contains re-range Pei moudle.\r
171 //\r
172 TempFileHandles[Index] = NULL;\r
58dcdada 173\r
b0d803fe 174 //\r
175 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r
58dcdada 176 // We need to update it to start with files in the A Priori list and\r
177 // then the remaining files in PEIM order.\r
b0d803fe 178 //\r
179 CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r
180 }\r
181 }\r
182 //\r
183 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.\r
184 // Instead, we can retrieve the file handles within this Fv from cachable data.\r
185 //\r
186 Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
187 CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
58dcdada 188\r
189}\r
190\r
54ea99a7 191//\r
192// This is the minimum memory required by DxeCore initialization. When LMFA feature enabled,\r
193// This part of memory still need reserved on the very top of memory so that the DXE Core could \r
194// use these memory for data initialization. This macro should be sync with the same marco\r
195// defined in DXE Core.\r
196//\r
197#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000\r
9bfb4940 198/**\r
199 This function is to test if the memory range described in resource HOB is available or not. \r
200 \r
201 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. Some platform may allocate the \r
202 memory before PeiLoadFixAddressHook in invoked. so this function is to test if the memory range described by the input resource HOB is\r
203 available or not.\r
204\r
205 @param PrivateData Pointer to the private data passed in from caller\r
206 @param ResourceHob Pointer to a resource HOB which described the memory range described by the input resource HOB\r
207**/\r
208BOOLEAN\r
209PeiLoadFixAddressIsMemoryRangeAvailable (\r
210 IN PEI_CORE_INSTANCE *PrivateData,\r
211 IN EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob\r
212 )\r
213{\r
214 EFI_HOB_MEMORY_ALLOCATION *MemoryHob;\r
215 BOOLEAN IsAvailable;\r
216 EFI_PEI_HOB_POINTERS Hob;\r
217 \r
218 IsAvailable = TRUE;\r
219 if (PrivateData == NULL || ResourceHob == NULL) {\r
220 return FALSE;\r
221 }\r
222 //\r
223 // test if the memory range describe in the HOB is already allocated.\r
224 //\r
225 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
226 // \r
227 // See if this is a memory allocation HOB \r
228 //\r
229 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) { \r
230 MemoryHob = Hob.MemoryAllocation;\r
231 if(MemoryHob->AllocDescriptor.MemoryBaseAddress == ResourceHob->PhysicalStart && \r
232 MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength == ResourceHob->PhysicalStart + ResourceHob->ResourceLength) {\r
233 IsAvailable = FALSE;\r
234 break; \r
235 }\r
236 }\r
237 }\r
238 \r
239 return IsAvailable;\r
240 \r
241}\r
54ea99a7 242/**\r
243 Hook function for Loading Module at Fixed Address feature\r
244 \r
245 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. When feature is\r
246 configured as Load Modules at Fix Absolute Address, this function is to validate the top address assigned by user. When \r
247 feature is configured as Load Modules at Fixed Offset, the functino is to find the top address which is TOLM-TSEG in general. \r
248 And also the function will re-install PEI memory. \r
b0d803fe 249\r
54ea99a7 250 @param PrivateData Pointer to the private data passed in from caller\r
251\r
252**/\r
253VOID\r
254PeiLoadFixAddressHook(\r
255 IN PEI_CORE_INSTANCE *PrivateData\r
256 )\r
257{\r
258 EFI_PHYSICAL_ADDRESS TopLoadingAddress;\r
259 UINT64 PeiMemorySize;\r
260 UINT64 TotalReservedMemorySize;\r
261 UINT64 MemoryRangeEnd;\r
262 EFI_PHYSICAL_ADDRESS HighAddress; \r
263 EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;\r
264 EFI_HOB_RESOURCE_DESCRIPTOR *NextResourceHob;\r
265 EFI_HOB_RESOURCE_DESCRIPTOR *CurrentResourceHob;\r
266 EFI_PEI_HOB_POINTERS CurrentHob;\r
267 EFI_PEI_HOB_POINTERS Hob;\r
268 EFI_PEI_HOB_POINTERS NextHob;\r
9bfb4940 269 EFI_HOB_MEMORY_ALLOCATION *MemoryHob;\r
54ea99a7 270 //\r
271 // Initialize Local Variables\r
272 //\r
273 CurrentResourceHob = NULL;\r
274 ResourceHob = NULL;\r
275 NextResourceHob = NULL;\r
54ea99a7 276 HighAddress = 0;\r
277 TopLoadingAddress = 0;\r
278 MemoryRangeEnd = 0;\r
279 CurrentHob.Raw = PrivateData->HobList.Raw;\r
280 PeiMemorySize = PrivateData->PhysicalMemoryLength;\r
281 //\r
282 // The top reserved memory include 3 parts: the topest range is for DXE core initialization with the size MINIMUM_INITIAL_MEMORY_SIZE\r
283 // then RuntimeCodePage range and Boot time code range.\r
284 // \r
e18fa167 285 TotalReservedMemorySize = MINIMUM_INITIAL_MEMORY_SIZE + EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber));\r
286 TotalReservedMemorySize+= EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber)) ; \r
54ea99a7 287 //\r
288 // PEI memory range lies below the top reserved memory\r
289 // \r
290 TotalReservedMemorySize += PeiMemorySize;\r
e18fa167 291 \r
852081fc 292 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: PcdLoadFixAddressRuntimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber)));\r
293 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: PcdLoadFixAddressBootTimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber)));\r
294 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: PcdLoadFixAddressPeiCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressPeiCodePageNumber))); \r
295 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: Total Reserved Memory Size = 0x%lx.\n", TotalReservedMemorySize));\r
54ea99a7 296 //\r
297 // Loop through the system memory typed hob to merge the adjacent memory range \r
298 //\r
299 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
300 // \r
301 // See if this is a resource descriptor HOB \r
302 //\r
303 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
304 \r
305 ResourceHob = Hob.ResourceDescriptor; \r
306 //\r
307 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.\r
308 //\r
63e70348 309 if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY ||\r
54ea99a7 310 ResourceHob->PhysicalStart + ResourceHob->ResourceLength > MAX_ADDRESS) {\r
311 continue;\r
312 } \r
313 \r
314 for (NextHob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(NextHob); NextHob.Raw = GET_NEXT_HOB(NextHob)) { \r
315 if (NextHob.Raw == Hob.Raw){\r
316 continue;\r
317 } \r
318 //\r
319 // See if this is a resource descriptor HOB\r
320 //\r
321 if (GET_HOB_TYPE (NextHob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
322 \r
323 NextResourceHob = NextHob.ResourceDescriptor;\r
324 //\r
325 // test if range described in this NextResourceHob is system memory and have the same attribute.\r
326 // Note: Here is a assumption that system memory should always be healthy even without test.\r
327 // \r
328 if (NextResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY &&\r
329 (((NextResourceHob->ResourceAttribute^ResourceHob->ResourceAttribute)&(~EFI_RESOURCE_ATTRIBUTE_TESTED)) == 0)){\r
330 \r
331 //\r
332 // See if the memory range described in ResourceHob and NextResourceHob is adjacent\r
333 //\r
334 if ((ResourceHob->PhysicalStart <= NextResourceHob->PhysicalStart && \r
335 ResourceHob->PhysicalStart + ResourceHob->ResourceLength >= NextResourceHob->PhysicalStart)|| \r
336 (ResourceHob->PhysicalStart >= NextResourceHob->PhysicalStart&&\r
337 ResourceHob->PhysicalStart <= NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength)) {\r
338 \r
339 MemoryRangeEnd = ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength)>(NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength)) ?\r
340 (ResourceHob->PhysicalStart + ResourceHob->ResourceLength):(NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength);\r
341 \r
342 ResourceHob->PhysicalStart = (ResourceHob->PhysicalStart < NextResourceHob->PhysicalStart) ? \r
343 ResourceHob->PhysicalStart : NextResourceHob->PhysicalStart;\r
344 \r
345 \r
346 ResourceHob->ResourceLength = (MemoryRangeEnd - ResourceHob->PhysicalStart);\r
347 \r
348 ResourceHob->ResourceAttribute = ResourceHob->ResourceAttribute & (~EFI_RESOURCE_ATTRIBUTE_TESTED);\r
349 //\r
350 // Delete the NextResourceHob by marking it as unused.\r
351 //\r
352 GET_HOB_TYPE (NextHob) = EFI_HOB_TYPE_UNUSED;\r
353 \r
354 }\r
355 }\r
356 } \r
357 }\r
358 } \r
359 }\r
9bfb4940 360 //\r
361 // Some platform is already allocated pages before the HOB re-org. Here to build dedicated resource HOB to describe\r
362 // the allocated memory range\r
363 //\r
364 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
365 // \r
366 // See if this is a memory allocation HOB \r
367 //\r
368 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
369 MemoryHob = Hob.MemoryAllocation;\r
370 for (NextHob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(NextHob); NextHob.Raw = GET_NEXT_HOB(NextHob)) {\r
371 //\r
372 // See if this is a resource descriptor HOB\r
373 //\r
374 if (GET_HOB_TYPE (NextHob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
375 NextResourceHob = NextHob.ResourceDescriptor;\r
376 //\r
377 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.\r
378 //\r
63e70348 379 if (NextResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY || NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength > MAX_ADDRESS) {\r
9bfb4940 380 continue;\r
381 }\r
382 //\r
383 // If the range describe in memory allocation HOB belongs to the memroy range described by the resource hob\r
384 // \r
385 if (MemoryHob->AllocDescriptor.MemoryBaseAddress >= NextResourceHob->PhysicalStart && \r
386 MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength <= NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength) {\r
387 //\r
388 // Build seperate resource hob for this allocated range\r
389 // \r
390 if (MemoryHob->AllocDescriptor.MemoryBaseAddress > NextResourceHob->PhysicalStart) {\r
391 BuildResourceDescriptorHob (\r
392 EFI_RESOURCE_SYSTEM_MEMORY, \r
393 NextResourceHob->ResourceAttribute,\r
394 NextResourceHob->PhysicalStart, \r
395 (MemoryHob->AllocDescriptor.MemoryBaseAddress - NextResourceHob->PhysicalStart) \r
396 );\r
397 }\r
398 if (MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength < NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength) {\r
399 BuildResourceDescriptorHob (\r
400 EFI_RESOURCE_SYSTEM_MEMORY, \r
401 NextResourceHob->ResourceAttribute,\r
402 MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength, \r
403 (NextResourceHob->PhysicalStart + NextResourceHob->ResourceLength -(MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength)) \r
404 );\r
405 }\r
406 NextResourceHob->PhysicalStart = MemoryHob->AllocDescriptor.MemoryBaseAddress;\r
407 NextResourceHob->ResourceLength = MemoryHob->AllocDescriptor.MemoryLength;\r
408 break;\r
409 }\r
410 }\r
411 }\r
412 }\r
413 }\r
414\r
54ea99a7 415 //\r
416 // Try to find and validate the TOP address.\r
417 // \r
852081fc 418 if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) > 0 ) {\r
54ea99a7 419 //\r
420 // The LMFA feature is enabled as load module at fixed absolute address.\r
421 //\r
852081fc 422 TopLoadingAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64(PcdLoadModuleAtFixAddressEnable);\r
54ea99a7 423 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: Loading module at fixed absolute address.\n"));\r
424 //\r
425 // validate the Address. Loop the resource descriptor HOB to make sure the address is in valid memory range\r
426 //\r
427 if ((TopLoadingAddress & EFI_PAGE_MASK) != 0) {\r
852081fc 428 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid since top address should be page align. \n", TopLoadingAddress)); \r
54ea99a7 429 ASSERT (FALSE); \r
430 }\r
431 //\r
432 // Search for a memory region that is below MAX_ADDRESS and in which TopLoadingAddress lies \r
433 //\r
434 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
435 //\r
436 // See if this is a resource descriptor HOB\r
437 //\r
438 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
439\r
440 ResourceHob = Hob.ResourceDescriptor;\r
441 //\r
442 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS\r
443 // \r
444 if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY &&\r
445 ResourceHob->PhysicalStart + ResourceHob->ResourceLength <= MAX_ADDRESS) {\r
446 //\r
447 // See if Top address specified by user is valid.\r
448 //\r
449 if (ResourceHob->PhysicalStart + TotalReservedMemorySize < TopLoadingAddress && \r
9bfb4940 450 (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - MINIMUM_INITIAL_MEMORY_SIZE) >= TopLoadingAddress && \r
451 PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData, ResourceHob)) {\r
54ea99a7 452 CurrentResourceHob = ResourceHob; \r
453 CurrentHob = Hob;\r
454 break;\r
9bfb4940 455 }\r
54ea99a7 456 }\r
457 } \r
458 } \r
459 if (CurrentResourceHob != NULL) {\r
852081fc 460 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO:Top Address 0x%lx is valid \n", TopLoadingAddress));\r
54ea99a7 461 TopLoadingAddress += MINIMUM_INITIAL_MEMORY_SIZE; \r
462 } else {\r
852081fc 463 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid \n", TopLoadingAddress)); \r
54ea99a7 464 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR:The recommended Top Address for the platform is: \n")); \r
465 //\r
466 // Print the recomended Top address range.\r
467 // \r
468 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
469 //\r
470 // See if this is a resource descriptor HOB\r
471 //\r
472 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
473 \r
474 ResourceHob = Hob.ResourceDescriptor;\r
475 //\r
476 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS\r
477 // \r
478 if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY &&\r
479 ResourceHob->PhysicalStart + ResourceHob->ResourceLength <= MAX_ADDRESS) {\r
480 //\r
481 // See if Top address specified by user is valid.\r
482 //\r
9bfb4940 483 if (ResourceHob->ResourceLength > TotalReservedMemorySize && PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData, ResourceHob)) {\r
852081fc 484 DEBUG ((EFI_D_INFO, "(0x%lx, 0x%lx)\n", \r
54ea99a7 485 (ResourceHob->PhysicalStart + TotalReservedMemorySize -MINIMUM_INITIAL_MEMORY_SIZE), \r
486 (ResourceHob->PhysicalStart + ResourceHob->ResourceLength -MINIMUM_INITIAL_MEMORY_SIZE) \r
487 )); \r
488 }\r
489 }\r
490 }\r
491 } \r
492 //\r
493 // Assert here \r
494 //\r
9bfb4940 495 ASSERT (FALSE); \r
496 return; \r
54ea99a7 497 } \r
498 } else {\r
499 //\r
500 // The LMFA feature is enabled as load module at fixed offset relative to TOLM\r
501 // Parse the Hob list to find the topest available memory. Generally it is (TOLM - TSEG)\r
502 //\r
503 //\r
504 // Search for a tested memory region that is below MAX_ADDRESS\r
505 //\r
506 for (Hob.Raw = PrivateData->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
507 //\r
508 // See if this is a resource descriptor HOB \r
509 //\r
510 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
511 \r
512 ResourceHob = Hob.ResourceDescriptor; \r
513 //\r
514 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS\r
515 //\r
516 if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY && \r
517 ResourceHob->PhysicalStart + ResourceHob->ResourceLength <= MAX_ADDRESS &&\r
9bfb4940 518 ResourceHob->ResourceLength > TotalReservedMemorySize && PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData, ResourceHob)) {\r
54ea99a7 519 //\r
520 // See if this is the highest largest system memory region below MaxAddress\r
521 //\r
522 if (ResourceHob->PhysicalStart > HighAddress) {\r
523 CurrentResourceHob = ResourceHob;\r
524 CurrentHob = Hob;\r
525 HighAddress = CurrentResourceHob->PhysicalStart;\r
526 }\r
527 }\r
528 } \r
529 }\r
530 if (CurrentResourceHob == NULL) {\r
531 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR:The System Memory is too small\n")); \r
532 //\r
533 // Assert here \r
534 //\r
9bfb4940 535 ASSERT (FALSE);\r
536 return; \r
54ea99a7 537 } else {\r
538 TopLoadingAddress = CurrentResourceHob->PhysicalStart + CurrentResourceHob->ResourceLength ; \r
539 } \r
540 }\r
541 \r
542 if (CurrentResourceHob != NULL) {\r
543 //\r
9bfb4940 544 // rebuild resource HOB for PEI memmory and reserved memory\r
54ea99a7 545 //\r
546 BuildResourceDescriptorHob (\r
9bfb4940 547 EFI_RESOURCE_SYSTEM_MEMORY, \r
54ea99a7 548 (\r
549 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
550 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
551 EFI_RESOURCE_ATTRIBUTE_TESTED |\r
552 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
553 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
554 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
555 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
556 ),\r
9bfb4940 557 (TopLoadingAddress - TotalReservedMemorySize), \r
558 TotalReservedMemorySize \r
54ea99a7 559 );\r
560 //\r
9bfb4940 561 // rebuild resource for the remain memory if necessary\r
54ea99a7 562 //\r
563 if (CurrentResourceHob->PhysicalStart < TopLoadingAddress - TotalReservedMemorySize) {\r
564 BuildResourceDescriptorHob (\r
9bfb4940 565 EFI_RESOURCE_SYSTEM_MEMORY, \r
54ea99a7 566 (\r
567 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
568 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
569 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
570 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
571 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
572 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
573 ),\r
9bfb4940 574 CurrentResourceHob->PhysicalStart, \r
575 (TopLoadingAddress - TotalReservedMemorySize - CurrentResourceHob->PhysicalStart) \r
54ea99a7 576 );\r
577 }\r
578 if (CurrentResourceHob->PhysicalStart + CurrentResourceHob->ResourceLength > TopLoadingAddress ) {\r
579 BuildResourceDescriptorHob (\r
580 EFI_RESOURCE_SYSTEM_MEMORY, \r
581 (\r
582 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
583 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
584 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
585 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
586 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
587 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
588 ),\r
589 TopLoadingAddress, \r
590 (CurrentResourceHob->PhysicalStart + CurrentResourceHob->ResourceLength - TopLoadingAddress) \r
591 );\r
592 }\r
593 //\r
594 // Delete CurrentHob by marking it as unused since the the memory range described by is rebuilt.\r
595 //\r
596 GET_HOB_TYPE (CurrentHob) = EFI_HOB_TYPE_UNUSED; \r
597 }\r
598\r
599 //\r
600 // Cache the top address for Loading Module at Fixed Address feature\r
601 //\r
602 PrivateData->LoadModuleAtFixAddressTopAddress = TopLoadingAddress - MINIMUM_INITIAL_MEMORY_SIZE;\r
852081fc 603 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: Top address = 0x%lx\n", PrivateData->LoadModuleAtFixAddressTopAddress)); \r
54ea99a7 604 //\r
605 // reinstall the PEI memory relative to TopLoadingAddress\r
606 //\r
607 PrivateData->PhysicalMemoryBegin = TopLoadingAddress - TotalReservedMemorySize;\r
608 PrivateData->FreePhysicalMemoryTop = PrivateData->PhysicalMemoryBegin + PeiMemorySize;\r
609}\r
0f9ebb32
LG
610\r
611/**\r
612 This routine is invoked in switch stack as PeiCore Entry.\r
613\r
614 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
615 environment, such as the size and location of temporary RAM, the stack location and\r
616 the BFV location.\r
617 @param Private Pointer to old core data that is used to initialize the\r
618 core's data areas.\r
619**/\r
620VOID\r
621EFIAPI\r
622PeiCoreEntry (\r
623 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
624 IN PEI_CORE_INSTANCE *Private\r
625 )\r
626{\r
627 //\r
628 // Entry PEI Phase 2\r
629 //\r
630 PeiCore (SecCoreData, NULL, Private);\r
631}\r
632\r
b1f6a7c6 633/**\r
192f6d4c 634 Conduct PEIM dispatch.\r
635\r
b1f6a7c6 636 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 637 environment, such as the size and location of temporary RAM, the stack location and\r
638 the BFV location.\r
b1f6a7c6 639 @param Private Pointer to the private data passed in from caller\r
192f6d4c 640\r
b1f6a7c6 641**/\r
642VOID\r
643PeiDispatcher (\r
644 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
645 IN PEI_CORE_INSTANCE *Private\r
646 )\r
192f6d4c 647{\r
b0d803fe 648 EFI_STATUS Status;\r
649 UINT32 Index1;\r
650 UINT32 Index2;\r
6c7a807a 651 CONST EFI_PEI_SERVICES **PeiServices;\r
b0d803fe 652 EFI_PEI_FILE_HANDLE PeimFileHandle;\r
653 UINTN FvCount;\r
654 UINTN PeimCount;\r
655 UINT32 AuthenticationState;\r
656 EFI_PHYSICAL_ADDRESS EntryPoint;\r
797a9d67 657 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint;\r
b0d803fe 658 UINTN SaveCurrentPeimCount;\r
1053e0c5 659 UINTN SaveCurrentFvCount;\r
b0d803fe 660 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r
797a9d67 661 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;\r
d0a3ead2 662 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r
ef05e063 663 UINT64 NewStackSize;\r
18d3e280 664 UINTN HeapTemporaryRamSize;\r
0f9ebb32 665 EFI_PHYSICAL_ADDRESS BaseOfNewHeap;\r
ef05e063 666 EFI_PHYSICAL_ADDRESS TopOfNewStack;\r
667 EFI_PHYSICAL_ADDRESS TopOfOldStack;\r
668 EFI_PHYSICAL_ADDRESS TemporaryRamBase;\r
669 UINTN TemporaryRamSize;\r
0f9ebb32
LG
670 UINTN TemporaryStackSize;\r
671 VOID *TemporaryStackBase;\r
672 UINTN PeiTemporaryRamSize;\r
673 VOID *PeiTemporaryRamBase;\r
ef05e063 674 UINTN StackOffset;\r
675 BOOLEAN StackOffsetPositive;\r
0f9ebb32
LG
676 EFI_PHYSICAL_ADDRESS HoleMemBase;\r
677 UINTN HoleMemSize;\r
288f9b38 678 EFI_FV_FILE_INFO FvFileInfo;\r
3b428ade 679 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
54ea99a7 680 VOID *LoadFixPeiCodeBegin;\r
0f9ebb32
LG
681 EFI_PHYSICAL_ADDRESS TempBase1;\r
682 UINTN TempSize1;\r
683 EFI_PHYSICAL_ADDRESS TempBase2;\r
684 UINTN TempSize2;\r
685 UINTN Index;\r
686 \r
4140a663 687 PeiServices = (CONST EFI_PEI_SERVICES **) &Private->Ps;\r
b0d803fe 688 PeimEntryPoint = NULL;\r
689 PeimFileHandle = NULL;\r
288f9b38 690 EntryPoint = 0;\r
b0d803fe 691\r
5d7f3126 692 if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
b0d803fe 693 //\r
694 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r
695 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r
696 //\r
697 SaveCurrentPeimCount = Private->CurrentPeimCount;\r
1053e0c5 698 SaveCurrentFvCount = Private->CurrentPeimFvCount;\r
b0d803fe 699 SaveCurrentFileHandle = Private->CurrentFileHandle;\r
700\r
1053e0c5 701 for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
4140a663 702 for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
b0d803fe 703 if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
58dcdada 704 PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
b0d803fe 705 Status = PeiLoadImage (\r
4140a663 706 (CONST EFI_PEI_SERVICES **) &Private->Ps,\r
58dcdada 707 PeimFileHandle,\r
341a658f 708 PEIM_STATE_REGISITER_FOR_SHADOW,\r
58dcdada 709 &EntryPoint,\r
b0d803fe 710 &AuthenticationState\r
711 );\r
712 if (Status == EFI_SUCCESS) {\r
713 //\r
714 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
715 //\r
716 Private->Fv[Index1].PeimState[Index2]++;\r
1053e0c5 717 Private->CurrentFileHandle = PeimFileHandle;\r
58dcdada 718 Private->CurrentPeimFvCount = Index1;\r
719 Private->CurrentPeimCount = Index2;\r
b0d803fe 720 //\r
721 // Call the PEIM entry point\r
722 //\r
797a9d67 723 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
58dcdada 724\r
087e13cb 725 PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
4140a663 726 PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->Ps);\r
087e13cb 727 PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
58dcdada 728 }\r
729\r
b0d803fe 730 //\r
731 // Process the Notify list and dispatch any notifies for\r
732 // newly installed PPIs.\r
733 //\r
734 ProcessNotifyList (Private);\r
735 }\r
736 }\r
737 }\r
58dcdada 738 Private->CurrentFileHandle = SaveCurrentFileHandle;\r
739 Private->CurrentPeimFvCount = SaveCurrentFvCount;\r
740 Private->CurrentPeimCount = SaveCurrentPeimCount;\r
b0d803fe 741 }\r
192f6d4c 742\r
743 //\r
744 // This is the main dispatch loop. It will search known FVs for PEIMs and\r
745 // attempt to dispatch them. If any PEIM gets dispatched through a single\r
746 // pass of the dispatcher, it will start over from the Bfv again to see\r
747 // if any new PEIMs dependencies got satisfied. With a well ordered\r
748 // FV where PEIMs are found in the order their dependencies are also\r
749 // satisfied, this dipatcher should run only once.\r
750 //\r
b0d803fe 751 do {\r
82b8c8df 752 //\r
753 // In case that reenter PeiCore happens, the last pass record is still available. \r
754 //\r
755 if (!Private->PeimDispatcherReenter) {\r
756 Private->PeimNeedingDispatch = FALSE;\r
757 Private->PeimDispatchOnThisPass = FALSE;\r
758 } else {\r
759 Private->PeimDispatcherReenter = FALSE;\r
760 }\r
761 \r
b0d803fe 762 for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r
3b428ade 763 CoreFvHandle = FindNextCoreFvHandle (Private, FvCount);\r
764 ASSERT (CoreFvHandle != NULL);\r
765 \r
2a00326e 766 //\r
3b428ade 767 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.\r
2a00326e 768 //\r
3b428ade 769 if (CoreFvHandle->FvPpi == NULL) {\r
770 continue;\r
771 }\r
772 \r
773 Private->CurrentPeimFvCount = FvCount;\r
192f6d4c 774\r
b0d803fe 775 if (Private->CurrentPeimCount == 0) {\r
776 //\r
777 // When going through each FV, at first, search Apriori file to\r
58dcdada 778 // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r
b0d803fe 779 // dispatch at first.\r
780 //\r
3b428ade 781 DiscoverPeimsAndOrderWithApriori (Private, CoreFvHandle);\r
b0d803fe 782 }\r
192f6d4c 783\r
784 //\r
b0d803fe 785 // Start to dispatch all modules within the current Fv.\r
192f6d4c 786 //\r
58dcdada 787 for (PeimCount = Private->CurrentPeimCount;\r
4140a663 788 (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
b0d803fe 789 PeimCount++) {\r
790 Private->CurrentPeimCount = PeimCount;\r
791 PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
792\r
793 if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r
794 if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r
82b8c8df 795 Private->PeimNeedingDispatch = TRUE;\r
b0d803fe 796 } else {\r
3b428ade 797 Status = CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, PeimFileHandle, &FvFileInfo);\r
288f9b38
LG
798 ASSERT_EFI_ERROR (Status);\r
799 if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
800 //\r
801 // For Fv type file, Produce new FV PPI and FV hob\r
802 //\r
c7935105
SZ
803 Status = ProcessFvFile (Private, &Private->Fv[FvCount], PeimFileHandle);\r
804 if (Status == EFI_SUCCESS) {\r
805 //\r
806 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
807 //\r
808 Private->Fv[FvCount].PeimState[PeimCount]++;\r
809 Private->PeimDispatchOnThisPass = TRUE;\r
810 }\r
288f9b38
LG
811 } else {\r
812 //\r
813 // For PEIM driver, Load its entry point\r
814 //\r
815 Status = PeiLoadImage (\r
58dcdada 816 PeiServices,\r
817 PeimFileHandle,\r
341a658f 818 PEIM_STATE_NOT_DISPATCHED,\r
58dcdada 819 &EntryPoint,\r
288f9b38
LG
820 &AuthenticationState\r
821 );\r
c7935105 822 if (Status == EFI_SUCCESS) {\r
b0d803fe 823 //\r
c7935105
SZ
824 // The PEIM has its dependencies satisfied, and its entry point\r
825 // has been found, so invoke it.\r
b0d803fe 826 //\r
c7935105 827 PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
58dcdada 828\r
c7935105
SZ
829 ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r
830\r
831 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
832 EFI_PROGRESS_CODE,\r
833 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN),\r
834 (VOID *)(&ExtendedData),\r
835 sizeof (ExtendedData)\r
836 );\r
837\r
838 Status = VerifyPeim (Private, CoreFvHandle->FvHandle, PeimFileHandle, AuthenticationState);\r
839 if (Status != EFI_SECURITY_VIOLATION) {\r
840 //\r
841 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
842 //\r
843 Private->Fv[FvCount].PeimState[PeimCount]++;\r
288f9b38
LG
844 //\r
845 // Call the PEIM entry point for PEIM driver\r
846 //\r
797a9d67 847 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
848 PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
c7935105 849 Private->PeimDispatchOnThisPass = TRUE;\r
288f9b38 850 }\r
797a9d67 851\r
c7935105
SZ
852 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
853 EFI_PROGRESS_CODE,\r
854 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END),\r
855 (VOID *)(&ExtendedData),\r
856 sizeof (ExtendedData)\r
857 );\r
858 PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
b0d803fe 859\r
c7935105 860 }\r
58dcdada 861 }\r
862\r
863 if (Private->SwitchStackSignal) {\r
a7715e73 864 //\r
3d4d0c34 865 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack\r
a7715e73 866 // usage in temporary memory for debuging.\r
867 //\r
868 DEBUG_CODE_BEGIN ();\r
96317468 869 UINT32 *StackPointer;\r
a7715e73 870 \r
96317468 871 for (StackPointer = (UINT32*)SecCoreData->StackBase;\r
872 (StackPointer < (UINT32*)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)) \\r
a7715e73 873 && (*StackPointer == INIT_CAR_VALUE);\r
874 StackPointer ++);\r
875 \r
ef05e063 876 DEBUG ((EFI_D_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
877 DEBUG ((EFI_D_INFO, "Temp Heap : BaseAddress=0x%p Length=0x%X\n", Private->HobList.Raw, (UINT32)((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN) Private->HobList.Raw)));\r
3d4d0c34 878 DEBUG ((EFI_D_INFO, "Total temporary memory: %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
879 DEBUG ((EFI_D_INFO, " temporary memory stack ever used: %d bytes.\n",\r
ef05e063 880 (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
a7715e73 881 ));\r
3d4d0c34 882 DEBUG ((EFI_D_INFO, " temporary memory heap used: %d bytes.\n",\r
ef05e063 883 (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
a7715e73 884 ));\r
885 DEBUG_CODE_END ();\r
886 \r
f73b3df8 887 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
54ea99a7 888 //\r
889 // Loading Module at Fixed Address is enabled\r
890 //\r
ef05e063 891 PeiLoadFixAddressHook (Private);\r
892\r
4fb72076 893 //\r
ef05e063 894 // If Loading Module at Fixed Address is enabled, Allocating memory range for Pei code range.\r
4fb72076 895 //\r
896 LoadFixPeiCodeBegin = AllocatePages((UINTN)PcdGet32(PcdLoadFixAddressPeiCodePageNumber));\r
3978f5d9 897 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: PeiCodeBegin = 0x%lX, PeiCodeTop= 0x%lX\n", (UINT64)(UINTN)LoadFixPeiCodeBegin, (UINT64)((UINTN)LoadFixPeiCodeBegin + PcdGet32(PcdLoadFixAddressPeiCodePageNumber) * EFI_PAGE_SIZE)));\r
54ea99a7 898 }\r
899 \r
a3a15d21 900 //\r
58dcdada 901 // Reserve the size of new stack at bottom of physical memory\r
a3a15d21 902 //\r
ef05e063 903 // The size of new stack in permenent memory must be the same size \r
904 // or larger than the size of old stack in temporary memory.\r
58dcdada 905 // But if new stack is smaller than the size of old stack, we also reserve\r
906 // the size of old stack at bottom of permenent memory.\r
907 //\r
ef05e063 908 NewStackSize = RShiftU64 (Private->PhysicalMemoryLength, 1);\r
909 NewStackSize = ALIGN_VALUE (NewStackSize, EFI_PAGE_SIZE);\r
910 NewStackSize = MIN (PcdGet32(PcdPeiCoreMaxPeiStackSize), NewStackSize);\r
911 DEBUG ((EFI_D_INFO, "Old Stack size %d, New stack size %d\n", (UINT32)SecCoreData->StackSize, (UINT32)NewStackSize));\r
912 ASSERT (NewStackSize >= SecCoreData->StackSize);\r
d74eeda8 913\r
58dcdada 914 //\r
ef05e063 915 // Caculate stack offset and heap offset between temporary memory and new permement \r
916 // memory seperately.\r
58dcdada 917 //\r
ef05e063 918 TopOfOldStack = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;\r
919 TopOfNewStack = Private->PhysicalMemoryBegin + NewStackSize;\r
ef05e063 920 if (TopOfNewStack >= TopOfOldStack) {\r
921 StackOffsetPositive = TRUE;\r
922 StackOffset = (UINTN)(TopOfNewStack - TopOfOldStack);\r
923 } else {\r
924 StackOffsetPositive = FALSE;\r
925 StackOffset = (UINTN)(TopOfOldStack - TopOfNewStack);\r
926 }\r
424b7c9f 927 Private->StackOffsetPositive = StackOffsetPositive;\r
928 Private->StackOffset = StackOffset;\r
ef05e063 929\r
192f6d4c 930 //\r
ef05e063 931 // Build Stack HOB that describes the permanent memory stack\r
192f6d4c 932 //\r
ef05e063 933 DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n", TopOfNewStack - NewStackSize, NewStackSize));\r
934 BuildStackHob (TopOfNewStack - NewStackSize, NewStackSize);\r
935\r
40f26b8f 936 //\r
ef05e063 937 // Cache information from SecCoreData into locals before SecCoreData is converted to a permanent memory address\r
40f26b8f 938 //\r
0f9ebb32
LG
939 TemporaryRamBase = (EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;\r
940 TemporaryRamSize = SecCoreData->TemporaryRamSize;\r
941 TemporaryStackSize = SecCoreData->StackSize;\r
942 TemporaryStackBase = SecCoreData->StackBase;\r
943 PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize;\r
944 PeiTemporaryRamBase = SecCoreData->PeiTemporaryRamBase;\r
945 \r
192f6d4c 946 //\r
58dcdada 947 // TemporaryRamSupportPpi is produced by platform's SEC\r
192f6d4c 948 //\r
ef05e063 949 Status = PeiServicesLocatePpi (\r
58dcdada 950 &gEfiTemporaryRamSupportPpiGuid,\r
951 0,\r
952 NULL,\r
953 (VOID**)&TemporaryRamSupportPpi\r
954 );\r
58dcdada 955 if (!EFI_ERROR (Status)) {\r
0f9ebb32
LG
956 //\r
957 // Heap Offset\r
958 //\r
959 BaseOfNewHeap = TopOfNewStack;\r
960 if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {\r
961 Private->HeapOffsetPositive = TRUE;\r
962 Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);\r
963 } else {\r
964 Private->HeapOffsetPositive = FALSE;\r
965 Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
966 }\r
6c8cfb07
SZ
967\r
968 DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64) Private->HeapOffset, (UINT64) Private->StackOffset));\r
969\r
0f9ebb32
LG
970 //\r
971 // Caculate new HandOffTable and PrivateData address in permanent memory's stack\r
972 //\r
973 if (StackOffsetPositive) {\r
974 SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset);\r
975 Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset);\r
976 } else {\r
977 SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset);\r
978 Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset);\r
979 }\r
980\r
40f26b8f 981 //\r
ef05e063 982 // Temporary Ram Support PPI is provided by platform, it will copy \r
40f26b8f 983 // temporary memory to permenent memory and do stack switching.\r
ef05e063 984 // After invoking Temporary Ram Support PPI, the following code's \r
985 // stack is in permanent memory.\r
40f26b8f 986 //\r
58dcdada 987 TemporaryRamSupportPpi->TemporaryRamMigration (\r
ef05e063 988 PeiServices,\r
989 TemporaryRamBase,\r
990 (EFI_PHYSICAL_ADDRESS)(UINTN)(TopOfNewStack - TemporaryStackSize),\r
991 TemporaryRamSize\r
58dcdada 992 );\r
993\r
0f9ebb32
LG
994 //\r
995 // Entry PEI Phase 2\r
996 //\r
997 PeiCore (SecCoreData, NULL, Private);\r
58dcdada 998 } else {\r
ffd332ca
LG
999 //\r
1000 // Migrate the PEI Services Table pointer from temporary RAM to permanent RAM.\r
1001 //\r
1002 MigratePeiServicesTablePointer ();\r
1003 \r
b414ea4b 1004 //\r
0f9ebb32 1005 // Heap Offset\r
b414ea4b 1006 //\r
0f9ebb32
LG
1007 BaseOfNewHeap = TopOfNewStack;\r
1008 HoleMemBase = TopOfNewStack;\r
1009 HoleMemSize = TemporaryRamSize - PeiTemporaryRamSize - TemporaryStackSize;\r
1010 if (HoleMemSize != 0) {\r
9b8e61be
LG
1011 //\r
1012 // Make sure HOB List start address is 8 byte alignment.\r
1013 //\r
1014 BaseOfNewHeap = ALIGN_VALUE (BaseOfNewHeap + HoleMemSize, 8);\r
0f9ebb32
LG
1015 }\r
1016 if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {\r
1017 Private->HeapOffsetPositive = TRUE;\r
1018 Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);\r
1019 } else {\r
1020 Private->HeapOffsetPositive = FALSE;\r
1021 Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
1022 }\r
58dcdada 1023\r
6c8cfb07
SZ
1024 DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64) Private->HeapOffset, (UINT64) Private->StackOffset));\r
1025\r
0f9ebb32
LG
1026 //\r
1027 // Migrate Heap\r
1028 //\r
18d3e280
LG
1029 HeapTemporaryRamSize = (UINTN) (Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - Private->HobList.HandoffInformationTable->EfiMemoryBottom);\r
1030 ASSERT (BaseOfNewHeap + HeapTemporaryRamSize <= Private->FreePhysicalMemoryTop);\r
1031 CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, HeapTemporaryRamSize);\r
0f9ebb32
LG
1032 \r
1033 //\r
1034 // Migrate Stack\r
1035 //\r
1036 CopyMem ((UINT8 *) (UINTN) (TopOfNewStack - TemporaryStackSize), TemporaryStackBase, TemporaryStackSize);\r
1037 \r
1038 //\r
1039 // Copy Hole Range Data\r
1040 // Convert PPI from Hole. \r
1041 //\r
1042 if (HoleMemSize != 0) {\r
1043 //\r
1044 // Prepare Hole\r
1045 //\r
1046 if (PeiTemporaryRamBase < TemporaryStackBase) {\r
1047 TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;\r
1048 TempSize1 = PeiTemporaryRamSize;\r
1049 TempBase2 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;\r
1050 TempSize2 = TemporaryStackSize;\r
1051 } else {\r
1052 TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;\r
1053 TempSize1 = TemporaryStackSize;\r
1054 TempBase2 =(EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;\r
1055 TempSize2 = PeiTemporaryRamSize;\r
1056 }\r
1057 if (TemporaryRamBase < TempBase1) {\r
1058 Private->HoleData[0].Base = TemporaryRamBase;\r
1059 Private->HoleData[0].Size = (UINTN) (TempBase1 - TemporaryRamBase);\r
1060 }\r
1061 if (TempBase1 + TempSize1 < TempBase2) {\r
1062 Private->HoleData[1].Base = TempBase1 + TempSize1;\r
1063 Private->HoleData[1].Size = (UINTN) (TempBase2 - TempBase1 - TempSize1);\r
1064 }\r
1065 if (TempBase2 + TempSize2 < TemporaryRamBase + TemporaryRamSize) {\r
1066 Private->HoleData[2].Base = TempBase2 + TempSize2;\r
1067 Private->HoleData[2].Size = (UINTN) (TemporaryRamBase + TemporaryRamSize - TempBase2 - TempSize2);\r
1068 }\r
1069 \r
1070 //\r
1071 // Copy Hole Range data.\r
1072 //\r
1073 for (Index = 0; Index < HOLE_MAX_NUMBER; Index ++) {\r
1074 if (Private->HoleData[Index].Size > 0) {\r
1075 if (HoleMemBase > Private->HoleData[Index].Base) {\r
1076 Private->HoleData[Index].OffsetPositive = TRUE;\r
1077 Private->HoleData[Index].Offset = (UINTN) (HoleMemBase - Private->HoleData[Index].Base);\r
1078 } else {\r
1079 Private->HoleData[Index].OffsetPositive = FALSE;\r
1080 Private->HoleData[Index].Offset = (UINTN) (Private->HoleData[Index].Base - HoleMemBase);\r
1081 }\r
1082 CopyMem ((VOID *) (UINTN) HoleMemBase, (VOID *) (UINTN) Private->HoleData[Index].Base, Private->HoleData[Index].Size);\r
1083 HoleMemBase = HoleMemBase + Private->HoleData[Index].Size;\r
1084 }\r
1085 }\r
1086 }\r
1087\r
1088 //\r
1089 // Switch new stack\r
1090 //\r
1091 SwitchStack (\r
1092 (SWITCH_STACK_ENTRY_POINT)(UINTN)PeiCoreEntry,\r
1093 (VOID *) SecCoreData,\r
1094 (VOID *) Private,\r
1095 (VOID *) (UINTN) TopOfNewStack\r
1096 );\r
1097 }\r
b0d803fe 1098\r
58dcdada 1099 //\r
1100 // Code should not come here\r
1101 //\r
ef05e063 1102 ASSERT (FALSE);\r
192f6d4c 1103 }\r
192f6d4c 1104\r
58dcdada 1105 //\r
1106 // Process the Notify list and dispatch any notifies for\r
1107 // newly installed PPIs.\r
1108 //\r
1109 ProcessNotifyList (Private);\r
1110\r
b0d803fe 1111 if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
5d7f3126 1112 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
b0d803fe 1113 //\r
58dcdada 1114 // If memory is availble we shadow images by default for performance reasons.\r
1115 // We call the entry point a 2nd time so the module knows it's shadowed.\r
b0d803fe 1116 //\r
1117 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
e67ca95c 1118 ASSERT (PeimEntryPoint != NULL);\r
797a9d67 1119 PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
b0d803fe 1120 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
58dcdada 1121\r
b0d803fe 1122 //\r
1123 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
1124 //\r
1125 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 1126\r
192f6d4c 1127 //\r
b0d803fe 1128 // Process the Notify list and dispatch any notifies for\r
1129 // newly installed PPIs.\r
192f6d4c 1130 //\r
b0d803fe 1131 ProcessNotifyList (Private);\r
192f6d4c 1132 }\r
1133 }\r
1134 }\r
192f6d4c 1135 }\r
192f6d4c 1136\r
b0d803fe 1137 //\r
1138 // We set to NULL here to optimize the 2nd entry to this routine after\r
1139 // memory is found. This reprevents rescanning of the FV. We set to\r
1140 // NULL here so we start at the begining of the next FV\r
1141 //\r
1142 Private->CurrentFileHandle = NULL;\r
1143 Private->CurrentPeimCount = 0;\r
1144 //\r
1145 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
1146 //\r
1147 SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
192f6d4c 1148 }\r
1149\r
1150 //\r
58dcdada 1151 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r
b0d803fe 1152 // through all the FV.\r
192f6d4c 1153 //\r
b0d803fe 1154 Private->CurrentPeimFvCount = 0;\r
192f6d4c 1155\r
1156 //\r
58dcdada 1157 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r
b0d803fe 1158 // dispatched. So we need to make another pass\r
192f6d4c 1159 //\r
58dcdada 1160 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r
b0d803fe 1161 // pass. If we did not dispatch a PEIM there is no point in trying again\r
1162 // as it will fail the next time too (nothing has changed).\r
192f6d4c 1163 //\r
82b8c8df 1164 } while (Private->PeimNeedingDispatch && Private->PeimDispatchOnThisPass);\r
192f6d4c 1165\r
192f6d4c 1166}\r
1167\r
b1f6a7c6 1168/**\r
192f6d4c 1169 Initialize the Dispatcher's data members\r
1170\r
b1f6a7c6 1171 @param PrivateData PeiCore's private data structure\r
1172 @param OldCoreData Old data from SecCore\r
192f6d4c 1173 NULL if being run in non-permament memory mode.\r
b1f6a7c6 1174 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 1175 environment, such as the size and location of temporary RAM, the stack location and\r
1176 the BFV location.\r
192f6d4c 1177\r
b1f6a7c6 1178 @return None.\r
192f6d4c 1179\r
b1f6a7c6 1180**/\r
1181VOID\r
1182InitializeDispatcherData (\r
1183 IN PEI_CORE_INSTANCE *PrivateData,\r
1184 IN PEI_CORE_INSTANCE *OldCoreData,\r
1185 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
1186 )\r
192f6d4c 1187{\r
192f6d4c 1188 if (OldCoreData == NULL) {\r
82b8c8df 1189 PrivateData->PeimDispatcherReenter = FALSE;\r
b0d803fe 1190 PeiInitializeFv (PrivateData, SecCoreData);\r
8e0e40ed 1191 } else {\r
7ec93917 1192 PeiReinitializeFv (PrivateData);\r
192f6d4c 1193 }\r
1194\r
1195 return;\r
1196}\r
1197\r
b1f6a7c6 1198/**\r
1199 This routine parses the Dependency Expression, if available, and\r
1200 decides if the module can be executed.\r
1201\r
1202\r
1203 @param Private PeiCore's private data structure\r
1204 @param FileHandle PEIM's file handle\r
1205 @param PeimCount Peim count in all dispatched PEIMs.\r
192f6d4c 1206\r
b1f6a7c6 1207 @retval TRUE Can be dispatched\r
1208 @retval FALSE Cannot be dispatched\r
1209\r
1210**/\r
192f6d4c 1211BOOLEAN\r
1212DepexSatisfied (\r
b0d803fe 1213 IN PEI_CORE_INSTANCE *Private,\r
1214 IN EFI_PEI_FILE_HANDLE FileHandle,\r
1215 IN UINTN PeimCount\r
192f6d4c 1216 )\r
192f6d4c 1217{\r
288f9b38
LG
1218 EFI_STATUS Status;\r
1219 VOID *DepexData;\r
6a55eea3 1220 EFI_FV_FILE_INFO FileInfo;\r
b0d803fe 1221\r
6a55eea3 1222 Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);\r
1223 if (EFI_ERROR (Status)) {\r
1224 DEBUG ((DEBUG_DISPATCH, "Evaluate PEI DEPEX for FFS(Unknown)\n"));\r
1225 } else {\r
1226 DEBUG ((DEBUG_DISPATCH, "Evaluate PEI DEPEX for FFS(%g)\n", &FileInfo.FileName));\r
1227 }\r
1228 \r
b0d803fe 1229 if (PeimCount < Private->AprioriCount) {\r
1230 //\r
1231 // If its in the A priori file then we set Depex to TRUE\r
1232 //\r
6a55eea3 1233 DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (Apriori)\n"));\r
b0d803fe 1234 return TRUE;\r
1235 }\r
58dcdada 1236\r
288f9b38 1237 //\r
58dcdada 1238 // Depex section not in the encapsulated section.\r
288f9b38
LG
1239 //\r
1240 Status = PeiServicesFfsFindSectionData (\r
1241 EFI_SECTION_PEI_DEPEX,\r
58dcdada 1242 FileHandle,\r
288f9b38
LG
1243 (VOID **)&DepexData\r
1244 );\r
b0d803fe 1245\r
192f6d4c 1246 if (EFI_ERROR (Status)) {\r
b0d803fe 1247 //\r
1248 // If there is no DEPEX, assume the module can be executed\r
1249 //\r
6a55eea3 1250 DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (No DEPEX)\n"));\r
192f6d4c 1251 return TRUE;\r
1252 }\r
1253\r
1254 //\r
1255 // Evaluate a given DEPEX\r
1256 //\r
4140a663 1257 return PeimDispatchReadiness (&Private->Ps, DepexData);\r
192f6d4c 1258}\r
1259\r
14e8823a 1260/**\r
1261 This routine enable a PEIM to register itself to shadow when PEI Foundation\r
1262 discovery permanent memory.\r
1263\r
b1f6a7c6 1264 @param FileHandle File handle of a PEIM.\r
58dcdada 1265\r
b1f6a7c6 1266 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
1267 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
1268 @retval EFI_SUCCESS Successfully to register itself.\r
14e8823a 1269\r
58dcdada 1270**/\r
14e8823a 1271EFI_STATUS\r
1272EFIAPI\r
1273PeiRegisterForShadow (\r
1274 IN EFI_PEI_FILE_HANDLE FileHandle\r
1275 )\r
1276{\r
1277 PEI_CORE_INSTANCE *Private;\r
1278 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
1279\r
1280 if (Private->CurrentFileHandle != FileHandle) {\r
1281 //\r
1282 // The FileHandle must be for the current PEIM\r
1283 //\r
1284 return EFI_NOT_FOUND;\r
1285 }\r
1286\r
1287 if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r
1288 //\r
1289 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r
1290 //\r
1291 return EFI_ALREADY_STARTED;\r
1292 }\r
58dcdada 1293\r
14e8823a 1294 Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
1295\r
1296 return EFI_SUCCESS;\r
1297}\r
1298\r
3b428ade 1299\r
341a658f 1300\r