]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Fix two issues in PeiCore.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 EFI PEI Core dispatch services\r
3 \r
63e70348 4Copyright (c) 2006 - 2013, 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
LG
88 //\r
89 // Check whether the count of Peims exceeds the max support PEIMs in a FV image\r
90 // If more Peims are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.\r
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
0f9ebb32 664 EFI_PHYSICAL_ADDRESS BaseOfNewHeap;\r
ef05e063 665 EFI_PHYSICAL_ADDRESS TopOfNewStack;\r
666 EFI_PHYSICAL_ADDRESS TopOfOldStack;\r
667 EFI_PHYSICAL_ADDRESS TemporaryRamBase;\r
668 UINTN TemporaryRamSize;\r
0f9ebb32
LG
669 UINTN TemporaryStackSize;\r
670 VOID *TemporaryStackBase;\r
671 UINTN PeiTemporaryRamSize;\r
672 VOID *PeiTemporaryRamBase;\r
ef05e063 673 UINTN StackOffset;\r
674 BOOLEAN StackOffsetPositive;\r
0f9ebb32
LG
675 EFI_PHYSICAL_ADDRESS HoleMemBase;\r
676 UINTN HoleMemSize;\r
288f9b38 677 EFI_FV_FILE_INFO FvFileInfo;\r
3b428ade 678 PEI_CORE_FV_HANDLE *CoreFvHandle;\r
54ea99a7 679 VOID *LoadFixPeiCodeBegin;\r
0f9ebb32
LG
680 EFI_PHYSICAL_ADDRESS TempBase1;\r
681 UINTN TempSize1;\r
682 EFI_PHYSICAL_ADDRESS TempBase2;\r
683 UINTN TempSize2;\r
684 UINTN Index;\r
685 \r
4140a663 686 PeiServices = (CONST EFI_PEI_SERVICES **) &Private->Ps;\r
b0d803fe 687 PeimEntryPoint = NULL;\r
688 PeimFileHandle = NULL;\r
288f9b38 689 EntryPoint = 0;\r
b0d803fe 690\r
5d7f3126 691 if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
b0d803fe 692 //\r
693 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r
694 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r
695 //\r
696 SaveCurrentPeimCount = Private->CurrentPeimCount;\r
1053e0c5 697 SaveCurrentFvCount = Private->CurrentPeimFvCount;\r
b0d803fe 698 SaveCurrentFileHandle = Private->CurrentFileHandle;\r
699\r
1053e0c5 700 for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
4140a663 701 for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
b0d803fe 702 if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
58dcdada 703 PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
b0d803fe 704 Status = PeiLoadImage (\r
4140a663 705 (CONST EFI_PEI_SERVICES **) &Private->Ps,\r
58dcdada 706 PeimFileHandle,\r
341a658f 707 PEIM_STATE_REGISITER_FOR_SHADOW,\r
58dcdada 708 &EntryPoint,\r
b0d803fe 709 &AuthenticationState\r
710 );\r
711 if (Status == EFI_SUCCESS) {\r
712 //\r
713 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
714 //\r
715 Private->Fv[Index1].PeimState[Index2]++;\r
1053e0c5 716 Private->CurrentFileHandle = PeimFileHandle;\r
58dcdada 717 Private->CurrentPeimFvCount = Index1;\r
718 Private->CurrentPeimCount = Index2;\r
b0d803fe 719 //\r
720 // Call the PEIM entry point\r
721 //\r
797a9d67 722 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
58dcdada 723\r
087e13cb 724 PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
4140a663 725 PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->Ps);\r
087e13cb 726 PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
58dcdada 727 }\r
728\r
b0d803fe 729 //\r
730 // Process the Notify list and dispatch any notifies for\r
731 // newly installed PPIs.\r
732 //\r
733 ProcessNotifyList (Private);\r
734 }\r
735 }\r
736 }\r
58dcdada 737 Private->CurrentFileHandle = SaveCurrentFileHandle;\r
738 Private->CurrentPeimFvCount = SaveCurrentFvCount;\r
739 Private->CurrentPeimCount = SaveCurrentPeimCount;\r
b0d803fe 740 }\r
192f6d4c 741\r
742 //\r
743 // This is the main dispatch loop. It will search known FVs for PEIMs and\r
744 // attempt to dispatch them. If any PEIM gets dispatched through a single\r
745 // pass of the dispatcher, it will start over from the Bfv again to see\r
746 // if any new PEIMs dependencies got satisfied. With a well ordered\r
747 // FV where PEIMs are found in the order their dependencies are also\r
748 // satisfied, this dipatcher should run only once.\r
749 //\r
b0d803fe 750 do {\r
82b8c8df 751 //\r
752 // In case that reenter PeiCore happens, the last pass record is still available. \r
753 //\r
754 if (!Private->PeimDispatcherReenter) {\r
755 Private->PeimNeedingDispatch = FALSE;\r
756 Private->PeimDispatchOnThisPass = FALSE;\r
757 } else {\r
758 Private->PeimDispatcherReenter = FALSE;\r
759 }\r
760 \r
b0d803fe 761 for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r
3b428ade 762 CoreFvHandle = FindNextCoreFvHandle (Private, FvCount);\r
763 ASSERT (CoreFvHandle != NULL);\r
764 \r
2a00326e 765 //\r
3b428ade 766 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.\r
2a00326e 767 //\r
3b428ade 768 if (CoreFvHandle->FvPpi == NULL) {\r
769 continue;\r
770 }\r
771 \r
772 Private->CurrentPeimFvCount = FvCount;\r
192f6d4c 773\r
b0d803fe 774 if (Private->CurrentPeimCount == 0) {\r
775 //\r
776 // When going through each FV, at first, search Apriori file to\r
58dcdada 777 // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r
b0d803fe 778 // dispatch at first.\r
779 //\r
3b428ade 780 DiscoverPeimsAndOrderWithApriori (Private, CoreFvHandle);\r
b0d803fe 781 }\r
192f6d4c 782\r
783 //\r
b0d803fe 784 // Start to dispatch all modules within the current Fv.\r
192f6d4c 785 //\r
58dcdada 786 for (PeimCount = Private->CurrentPeimCount;\r
4140a663 787 (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
b0d803fe 788 PeimCount++) {\r
789 Private->CurrentPeimCount = PeimCount;\r
790 PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
791\r
792 if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r
793 if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r
82b8c8df 794 Private->PeimNeedingDispatch = TRUE;\r
b0d803fe 795 } else {\r
3b428ade 796 Status = CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, PeimFileHandle, &FvFileInfo);\r
288f9b38
LG
797 ASSERT_EFI_ERROR (Status);\r
798 if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
799 //\r
800 // For Fv type file, Produce new FV PPI and FV hob\r
801 //\r
c7935105
SZ
802 Status = ProcessFvFile (Private, &Private->Fv[FvCount], PeimFileHandle);\r
803 if (Status == EFI_SUCCESS) {\r
804 //\r
805 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
806 //\r
807 Private->Fv[FvCount].PeimState[PeimCount]++;\r
808 Private->PeimDispatchOnThisPass = TRUE;\r
809 }\r
288f9b38
LG
810 } else {\r
811 //\r
812 // For PEIM driver, Load its entry point\r
813 //\r
814 Status = PeiLoadImage (\r
58dcdada 815 PeiServices,\r
816 PeimFileHandle,\r
341a658f 817 PEIM_STATE_NOT_DISPATCHED,\r
58dcdada 818 &EntryPoint,\r
288f9b38
LG
819 &AuthenticationState\r
820 );\r
c7935105 821 if (Status == EFI_SUCCESS) {\r
b0d803fe 822 //\r
c7935105
SZ
823 // The PEIM has its dependencies satisfied, and its entry point\r
824 // has been found, so invoke it.\r
b0d803fe 825 //\r
c7935105 826 PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
58dcdada 827\r
c7935105
SZ
828 ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r
829\r
830 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
831 EFI_PROGRESS_CODE,\r
832 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN),\r
833 (VOID *)(&ExtendedData),\r
834 sizeof (ExtendedData)\r
835 );\r
836\r
837 Status = VerifyPeim (Private, CoreFvHandle->FvHandle, PeimFileHandle, AuthenticationState);\r
838 if (Status != EFI_SECURITY_VIOLATION) {\r
839 //\r
840 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
841 //\r
842 Private->Fv[FvCount].PeimState[PeimCount]++;\r
288f9b38
LG
843 //\r
844 // Call the PEIM entry point for PEIM driver\r
845 //\r
797a9d67 846 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
847 PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
c7935105 848 Private->PeimDispatchOnThisPass = TRUE;\r
288f9b38 849 }\r
797a9d67 850\r
c7935105
SZ
851 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
852 EFI_PROGRESS_CODE,\r
853 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END),\r
854 (VOID *)(&ExtendedData),\r
855 sizeof (ExtendedData)\r
856 );\r
857 PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
b0d803fe 858\r
c7935105 859 }\r
58dcdada 860 }\r
861\r
862 if (Private->SwitchStackSignal) {\r
a7715e73 863 //\r
3d4d0c34 864 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack\r
a7715e73 865 // usage in temporary memory for debuging.\r
866 //\r
867 DEBUG_CODE_BEGIN ();\r
96317468 868 UINT32 *StackPointer;\r
a7715e73 869 \r
96317468 870 for (StackPointer = (UINT32*)SecCoreData->StackBase;\r
871 (StackPointer < (UINT32*)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)) \\r
a7715e73 872 && (*StackPointer == INIT_CAR_VALUE);\r
873 StackPointer ++);\r
874 \r
ef05e063 875 DEBUG ((EFI_D_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
876 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 877 DEBUG ((EFI_D_INFO, "Total temporary memory: %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
878 DEBUG ((EFI_D_INFO, " temporary memory stack ever used: %d bytes.\n",\r
ef05e063 879 (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
a7715e73 880 ));\r
3d4d0c34 881 DEBUG ((EFI_D_INFO, " temporary memory heap used: %d bytes.\n",\r
ef05e063 882 (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
a7715e73 883 ));\r
884 DEBUG_CODE_END ();\r
885 \r
f73b3df8 886 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
54ea99a7 887 //\r
888 // Loading Module at Fixed Address is enabled\r
889 //\r
ef05e063 890 PeiLoadFixAddressHook (Private);\r
891\r
4fb72076 892 //\r
ef05e063 893 // If Loading Module at Fixed Address is enabled, Allocating memory range for Pei code range.\r
4fb72076 894 //\r
895 LoadFixPeiCodeBegin = AllocatePages((UINTN)PcdGet32(PcdLoadFixAddressPeiCodePageNumber));\r
3978f5d9 896 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 897 }\r
898 \r
a3a15d21 899 //\r
58dcdada 900 // Reserve the size of new stack at bottom of physical memory\r
a3a15d21 901 //\r
ef05e063 902 // The size of new stack in permenent memory must be the same size \r
903 // or larger than the size of old stack in temporary memory.\r
58dcdada 904 // But if new stack is smaller than the size of old stack, we also reserve\r
905 // the size of old stack at bottom of permenent memory.\r
906 //\r
ef05e063 907 NewStackSize = RShiftU64 (Private->PhysicalMemoryLength, 1);\r
908 NewStackSize = ALIGN_VALUE (NewStackSize, EFI_PAGE_SIZE);\r
909 NewStackSize = MIN (PcdGet32(PcdPeiCoreMaxPeiStackSize), NewStackSize);\r
910 DEBUG ((EFI_D_INFO, "Old Stack size %d, New stack size %d\n", (UINT32)SecCoreData->StackSize, (UINT32)NewStackSize));\r
911 ASSERT (NewStackSize >= SecCoreData->StackSize);\r
d74eeda8 912\r
58dcdada 913 //\r
ef05e063 914 // Caculate stack offset and heap offset between temporary memory and new permement \r
915 // memory seperately.\r
58dcdada 916 //\r
ef05e063 917 TopOfOldStack = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;\r
918 TopOfNewStack = Private->PhysicalMemoryBegin + NewStackSize;\r
ef05e063 919 if (TopOfNewStack >= TopOfOldStack) {\r
920 StackOffsetPositive = TRUE;\r
921 StackOffset = (UINTN)(TopOfNewStack - TopOfOldStack);\r
922 } else {\r
923 StackOffsetPositive = FALSE;\r
924 StackOffset = (UINTN)(TopOfOldStack - TopOfNewStack);\r
925 }\r
424b7c9f 926 Private->StackOffsetPositive = StackOffsetPositive;\r
927 Private->StackOffset = StackOffset;\r
ef05e063 928\r
929 DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64)Private->HeapOffset, (UINT64)(StackOffset)));\r
192f6d4c 930\r
931 //\r
ef05e063 932 // Build Stack HOB that describes the permanent memory stack\r
192f6d4c 933 //\r
ef05e063 934 DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n", TopOfNewStack - NewStackSize, NewStackSize));\r
935 BuildStackHob (TopOfNewStack - NewStackSize, NewStackSize);\r
936\r
40f26b8f 937 //\r
ef05e063 938 // Cache information from SecCoreData into locals before SecCoreData is converted to a permanent memory address\r
40f26b8f 939 //\r
0f9ebb32
LG
940 TemporaryRamBase = (EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;\r
941 TemporaryRamSize = SecCoreData->TemporaryRamSize;\r
942 TemporaryStackSize = SecCoreData->StackSize;\r
943 TemporaryStackBase = SecCoreData->StackBase;\r
944 PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize;\r
945 PeiTemporaryRamBase = SecCoreData->PeiTemporaryRamBase;\r
946 \r
192f6d4c 947 //\r
58dcdada 948 // TemporaryRamSupportPpi is produced by platform's SEC\r
192f6d4c 949 //\r
ef05e063 950 Status = PeiServicesLocatePpi (\r
58dcdada 951 &gEfiTemporaryRamSupportPpiGuid,\r
952 0,\r
953 NULL,\r
954 (VOID**)&TemporaryRamSupportPpi\r
955 );\r
58dcdada 956 if (!EFI_ERROR (Status)) {\r
0f9ebb32
LG
957 //\r
958 // Heap Offset\r
959 //\r
960 BaseOfNewHeap = TopOfNewStack;\r
961 if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {\r
962 Private->HeapOffsetPositive = TRUE;\r
963 Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);\r
964 } else {\r
965 Private->HeapOffsetPositive = FALSE;\r
966 Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
967 }\r
968 \r
969 //\r
970 // Caculate new HandOffTable and PrivateData address in permanent memory's stack\r
971 //\r
972 if (StackOffsetPositive) {\r
973 SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset);\r
974 Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset);\r
975 } else {\r
976 SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset);\r
977 Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset);\r
978 }\r
979\r
40f26b8f 980 //\r
ef05e063 981 // Temporary Ram Support PPI is provided by platform, it will copy \r
40f26b8f 982 // temporary memory to permenent memory and do stack switching.\r
ef05e063 983 // After invoking Temporary Ram Support PPI, the following code's \r
984 // stack is in permanent memory.\r
40f26b8f 985 //\r
58dcdada 986 TemporaryRamSupportPpi->TemporaryRamMigration (\r
ef05e063 987 PeiServices,\r
988 TemporaryRamBase,\r
989 (EFI_PHYSICAL_ADDRESS)(UINTN)(TopOfNewStack - TemporaryStackSize),\r
990 TemporaryRamSize\r
58dcdada 991 );\r
992\r
0f9ebb32
LG
993 //\r
994 // Entry PEI Phase 2\r
995 //\r
996 PeiCore (SecCoreData, NULL, Private);\r
58dcdada 997 } else {\r
b414ea4b 998 //\r
0f9ebb32 999 // Heap Offset\r
b414ea4b 1000 //\r
0f9ebb32
LG
1001 BaseOfNewHeap = TopOfNewStack;\r
1002 HoleMemBase = TopOfNewStack;\r
1003 HoleMemSize = TemporaryRamSize - PeiTemporaryRamSize - TemporaryStackSize;\r
1004 if (HoleMemSize != 0) {\r
9b8e61be
LG
1005 //\r
1006 // Make sure HOB List start address is 8 byte alignment.\r
1007 //\r
1008 BaseOfNewHeap = ALIGN_VALUE (BaseOfNewHeap + HoleMemSize, 8);\r
0f9ebb32
LG
1009 }\r
1010 if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {\r
1011 Private->HeapOffsetPositive = TRUE;\r
1012 Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);\r
1013 } else {\r
1014 Private->HeapOffsetPositive = FALSE;\r
1015 Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
1016 }\r
58dcdada 1017\r
0f9ebb32
LG
1018 //\r
1019 // Migrate Heap\r
1020 //\r
1021 CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, PeiTemporaryRamSize);\r
1022 \r
1023 //\r
1024 // Migrate Stack\r
1025 //\r
1026 CopyMem ((UINT8 *) (UINTN) (TopOfNewStack - TemporaryStackSize), TemporaryStackBase, TemporaryStackSize);\r
1027 \r
1028 //\r
1029 // Copy Hole Range Data\r
1030 // Convert PPI from Hole. \r
1031 //\r
1032 if (HoleMemSize != 0) {\r
1033 //\r
1034 // Prepare Hole\r
1035 //\r
1036 if (PeiTemporaryRamBase < TemporaryStackBase) {\r
1037 TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;\r
1038 TempSize1 = PeiTemporaryRamSize;\r
1039 TempBase2 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;\r
1040 TempSize2 = TemporaryStackSize;\r
1041 } else {\r
1042 TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;\r
1043 TempSize1 = TemporaryStackSize;\r
1044 TempBase2 =(EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;\r
1045 TempSize2 = PeiTemporaryRamSize;\r
1046 }\r
1047 if (TemporaryRamBase < TempBase1) {\r
1048 Private->HoleData[0].Base = TemporaryRamBase;\r
1049 Private->HoleData[0].Size = (UINTN) (TempBase1 - TemporaryRamBase);\r
1050 }\r
1051 if (TempBase1 + TempSize1 < TempBase2) {\r
1052 Private->HoleData[1].Base = TempBase1 + TempSize1;\r
1053 Private->HoleData[1].Size = (UINTN) (TempBase2 - TempBase1 - TempSize1);\r
1054 }\r
1055 if (TempBase2 + TempSize2 < TemporaryRamBase + TemporaryRamSize) {\r
1056 Private->HoleData[2].Base = TempBase2 + TempSize2;\r
1057 Private->HoleData[2].Size = (UINTN) (TemporaryRamBase + TemporaryRamSize - TempBase2 - TempSize2);\r
1058 }\r
1059 \r
1060 //\r
1061 // Copy Hole Range data.\r
1062 //\r
1063 for (Index = 0; Index < HOLE_MAX_NUMBER; Index ++) {\r
1064 if (Private->HoleData[Index].Size > 0) {\r
1065 if (HoleMemBase > Private->HoleData[Index].Base) {\r
1066 Private->HoleData[Index].OffsetPositive = TRUE;\r
1067 Private->HoleData[Index].Offset = (UINTN) (HoleMemBase - Private->HoleData[Index].Base);\r
1068 } else {\r
1069 Private->HoleData[Index].OffsetPositive = FALSE;\r
1070 Private->HoleData[Index].Offset = (UINTN) (Private->HoleData[Index].Base - HoleMemBase);\r
1071 }\r
1072 CopyMem ((VOID *) (UINTN) HoleMemBase, (VOID *) (UINTN) Private->HoleData[Index].Base, Private->HoleData[Index].Size);\r
1073 HoleMemBase = HoleMemBase + Private->HoleData[Index].Size;\r
1074 }\r
1075 }\r
1076 }\r
1077\r
1078 //\r
1079 // Switch new stack\r
1080 //\r
1081 SwitchStack (\r
1082 (SWITCH_STACK_ENTRY_POINT)(UINTN)PeiCoreEntry,\r
1083 (VOID *) SecCoreData,\r
1084 (VOID *) Private,\r
1085 (VOID *) (UINTN) TopOfNewStack\r
1086 );\r
1087 }\r
b0d803fe 1088\r
58dcdada 1089 //\r
1090 // Code should not come here\r
1091 //\r
ef05e063 1092 ASSERT (FALSE);\r
192f6d4c 1093 }\r
192f6d4c 1094\r
58dcdada 1095 //\r
1096 // Process the Notify list and dispatch any notifies for\r
1097 // newly installed PPIs.\r
1098 //\r
1099 ProcessNotifyList (Private);\r
1100\r
b0d803fe 1101 if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
5d7f3126 1102 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
b0d803fe 1103 //\r
58dcdada 1104 // If memory is availble we shadow images by default for performance reasons.\r
1105 // We call the entry point a 2nd time so the module knows it's shadowed.\r
b0d803fe 1106 //\r
1107 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
e67ca95c 1108 ASSERT (PeimEntryPoint != NULL);\r
797a9d67 1109 PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
b0d803fe 1110 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
58dcdada 1111\r
b0d803fe 1112 //\r
1113 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
1114 //\r
1115 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 1116\r
192f6d4c 1117 //\r
b0d803fe 1118 // Process the Notify list and dispatch any notifies for\r
1119 // newly installed PPIs.\r
192f6d4c 1120 //\r
b0d803fe 1121 ProcessNotifyList (Private);\r
192f6d4c 1122 }\r
1123 }\r
1124 }\r
192f6d4c 1125 }\r
192f6d4c 1126\r
b0d803fe 1127 //\r
1128 // We set to NULL here to optimize the 2nd entry to this routine after\r
1129 // memory is found. This reprevents rescanning of the FV. We set to\r
1130 // NULL here so we start at the begining of the next FV\r
1131 //\r
1132 Private->CurrentFileHandle = NULL;\r
1133 Private->CurrentPeimCount = 0;\r
1134 //\r
1135 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
1136 //\r
1137 SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
192f6d4c 1138 }\r
1139\r
1140 //\r
58dcdada 1141 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r
b0d803fe 1142 // through all the FV.\r
192f6d4c 1143 //\r
b0d803fe 1144 Private->CurrentPeimFvCount = 0;\r
192f6d4c 1145\r
1146 //\r
58dcdada 1147 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r
b0d803fe 1148 // dispatched. So we need to make another pass\r
192f6d4c 1149 //\r
58dcdada 1150 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r
b0d803fe 1151 // pass. If we did not dispatch a PEIM there is no point in trying again\r
1152 // as it will fail the next time too (nothing has changed).\r
192f6d4c 1153 //\r
82b8c8df 1154 } while (Private->PeimNeedingDispatch && Private->PeimDispatchOnThisPass);\r
192f6d4c 1155\r
192f6d4c 1156}\r
1157\r
b1f6a7c6 1158/**\r
192f6d4c 1159 Initialize the Dispatcher's data members\r
1160\r
b1f6a7c6 1161 @param PrivateData PeiCore's private data structure\r
1162 @param OldCoreData Old data from SecCore\r
192f6d4c 1163 NULL if being run in non-permament memory mode.\r
b1f6a7c6 1164 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 1165 environment, such as the size and location of temporary RAM, the stack location and\r
1166 the BFV location.\r
192f6d4c 1167\r
b1f6a7c6 1168 @return None.\r
192f6d4c 1169\r
b1f6a7c6 1170**/\r
1171VOID\r
1172InitializeDispatcherData (\r
1173 IN PEI_CORE_INSTANCE *PrivateData,\r
1174 IN PEI_CORE_INSTANCE *OldCoreData,\r
1175 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
1176 )\r
192f6d4c 1177{\r
192f6d4c 1178 if (OldCoreData == NULL) {\r
82b8c8df 1179 PrivateData->PeimDispatcherReenter = FALSE;\r
b0d803fe 1180 PeiInitializeFv (PrivateData, SecCoreData);\r
8e0e40ed 1181 } else {\r
7ec93917 1182 PeiReinitializeFv (PrivateData);\r
192f6d4c 1183 }\r
1184\r
1185 return;\r
1186}\r
1187\r
b1f6a7c6 1188/**\r
1189 This routine parses the Dependency Expression, if available, and\r
1190 decides if the module can be executed.\r
1191\r
1192\r
1193 @param Private PeiCore's private data structure\r
1194 @param FileHandle PEIM's file handle\r
1195 @param PeimCount Peim count in all dispatched PEIMs.\r
192f6d4c 1196\r
b1f6a7c6 1197 @retval TRUE Can be dispatched\r
1198 @retval FALSE Cannot be dispatched\r
1199\r
1200**/\r
192f6d4c 1201BOOLEAN\r
1202DepexSatisfied (\r
b0d803fe 1203 IN PEI_CORE_INSTANCE *Private,\r
1204 IN EFI_PEI_FILE_HANDLE FileHandle,\r
1205 IN UINTN PeimCount\r
192f6d4c 1206 )\r
192f6d4c 1207{\r
288f9b38
LG
1208 EFI_STATUS Status;\r
1209 VOID *DepexData;\r
6a55eea3 1210 EFI_FV_FILE_INFO FileInfo;\r
b0d803fe 1211\r
6a55eea3 1212 Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);\r
1213 if (EFI_ERROR (Status)) {\r
1214 DEBUG ((DEBUG_DISPATCH, "Evaluate PEI DEPEX for FFS(Unknown)\n"));\r
1215 } else {\r
1216 DEBUG ((DEBUG_DISPATCH, "Evaluate PEI DEPEX for FFS(%g)\n", &FileInfo.FileName));\r
1217 }\r
1218 \r
b0d803fe 1219 if (PeimCount < Private->AprioriCount) {\r
1220 //\r
1221 // If its in the A priori file then we set Depex to TRUE\r
1222 //\r
6a55eea3 1223 DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (Apriori)\n"));\r
b0d803fe 1224 return TRUE;\r
1225 }\r
58dcdada 1226\r
288f9b38 1227 //\r
58dcdada 1228 // Depex section not in the encapsulated section.\r
288f9b38
LG
1229 //\r
1230 Status = PeiServicesFfsFindSectionData (\r
1231 EFI_SECTION_PEI_DEPEX,\r
58dcdada 1232 FileHandle,\r
288f9b38
LG
1233 (VOID **)&DepexData\r
1234 );\r
b0d803fe 1235\r
192f6d4c 1236 if (EFI_ERROR (Status)) {\r
b0d803fe 1237 //\r
1238 // If there is no DEPEX, assume the module can be executed\r
1239 //\r
6a55eea3 1240 DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (No DEPEX)\n"));\r
192f6d4c 1241 return TRUE;\r
1242 }\r
1243\r
1244 //\r
1245 // Evaluate a given DEPEX\r
1246 //\r
4140a663 1247 return PeimDispatchReadiness (&Private->Ps, DepexData);\r
192f6d4c 1248}\r
1249\r
14e8823a 1250/**\r
1251 This routine enable a PEIM to register itself to shadow when PEI Foundation\r
1252 discovery permanent memory.\r
1253\r
b1f6a7c6 1254 @param FileHandle File handle of a PEIM.\r
58dcdada 1255\r
b1f6a7c6 1256 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
1257 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
1258 @retval EFI_SUCCESS Successfully to register itself.\r
14e8823a 1259\r
58dcdada 1260**/\r
14e8823a 1261EFI_STATUS\r
1262EFIAPI\r
1263PeiRegisterForShadow (\r
1264 IN EFI_PEI_FILE_HANDLE FileHandle\r
1265 )\r
1266{\r
1267 PEI_CORE_INSTANCE *Private;\r
1268 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
1269\r
1270 if (Private->CurrentFileHandle != FileHandle) {\r
1271 //\r
1272 // The FileHandle must be for the current PEIM\r
1273 //\r
1274 return EFI_NOT_FOUND;\r
1275 }\r
1276\r
1277 if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r
1278 //\r
1279 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r
1280 //\r
1281 return EFI_ALREADY_STARTED;\r
1282 }\r
58dcdada 1283\r
14e8823a 1284 Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
1285\r
1286 return EFI_SUCCESS;\r
1287}\r
1288\r
3b428ade 1289\r
341a658f 1290\r