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