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