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