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