UINTN PeimCount;\r
EFI_GUID *Guid;\r
EFI_PEI_FILE_HANDLE *TempFileHandles;\r
- EFI_GUID *FileGuid;\r
+ EFI_GUID *TempFileGuid;\r
EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r
EFI_FV_FILE_INFO FileInfo;\r
\r
// Walk the FV and find all the PEIMs and the Apriori file.\r
//\r
AprioriFileHandle = NULL;\r
- Private->CurrentFvFileHandles[0] = NULL;\r
+ Private->CurrentFvFileHandles = NULL;\r
Guid = NULL;\r
- FileHandle = NULL;\r
- TempFileHandles = Private->FileHandles;\r
- FileGuid = Private->FileGuid;\r
\r
//\r
- // If the current Fv has been scanned, directly get its cachable record.\r
+ // If the current Fv has been scanned, directly get its cached records.\r
//\r
- if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r
- CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
+ if (CoreFileHandle->ScanFv) {\r
+ Private->CurrentFvFileHandles = CoreFileHandle->FvFileHandles;\r
return;\r
}\r
\r
+ TempFileHandles = Private->TempFileHandles;\r
+ TempFileGuid = Private->TempFileGuid;\r
+\r
//\r
- // Go ahead to scan this Fv, and cache FileHandles within it.\r
+ // Go ahead to scan this Fv, get PeimCount and cache FileHandles within it to TempFileHandles.\r
//\r
- Status = EFI_NOT_FOUND;\r
- for (PeimCount = 0; PeimCount <= PcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
+ PeimCount = 0;\r
+ FileHandle = NULL;\r
+ do {\r
Status = FvPpi->FindFileByType (FvPpi, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle, &FileHandle);\r
- if (Status != EFI_SUCCESS || PeimCount == PcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
- break;\r
+ if (!EFI_ERROR (Status)) {\r
+ if (PeimCount >= Private->TempPeimCount) {\r
+ //\r
+ // Run out of room, grow the buffer.\r
+ //\r
+ TempFileHandles = AllocatePool (\r
+ sizeof (EFI_PEI_FILE_HANDLE) * (Private->TempPeimCount + TEMP_FILE_GROWTH_STEP));\r
+ ASSERT (TempFileHandles != NULL);\r
+ CopyMem (\r
+ TempFileHandles,\r
+ Private->TempFileHandles,\r
+ sizeof (EFI_PEI_FILE_HANDLE) * Private->TempPeimCount\r
+ );\r
+ Private->TempFileHandles = TempFileHandles;\r
+ TempFileGuid = AllocatePool (\r
+ sizeof (EFI_GUID) * (Private->TempPeimCount + TEMP_FILE_GROWTH_STEP));\r
+ ASSERT (TempFileGuid != NULL);\r
+ CopyMem (\r
+ TempFileGuid,\r
+ Private->TempFileGuid,\r
+ sizeof (EFI_GUID) * Private->TempPeimCount\r
+ );\r
+ Private->TempFileGuid = TempFileGuid;\r
+ Private->TempPeimCount = Private->TempPeimCount + TEMP_FILE_GROWTH_STEP;\r
+ }\r
+\r
+ TempFileHandles[PeimCount++] = FileHandle;\r
}\r
+ } while (!EFI_ERROR (Status));\r
+\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a(): Found 0x%x PEI FFS files in the %dth FV\n",\r
+ __FUNCTION__,\r
+ PeimCount,\r
+ Private->CurrentPeimFvCount\r
+ ));\r
\r
- Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
+ if (PeimCount == 0) {\r
+ //\r
+ // No PEIM FFS file is found, set ScanFv flag and return.\r
+ //\r
+ CoreFileHandle->ScanFv = TRUE;\r
+ return;\r
}\r
\r
//\r
- // Check whether the count of files exceeds the max support files in a FV image\r
- // If more files are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.\r
+ // Record PeimCount, allocate buffer for PeimState and FvFileHandles.\r
//\r
- ASSERT ((Status != EFI_SUCCESS) || (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)));\r
+ CoreFileHandle->PeimCount = PeimCount;\r
+ CoreFileHandle->PeimState = AllocateZeroPool (sizeof (UINT8) * PeimCount);\r
+ ASSERT (CoreFileHandle->PeimState != NULL);\r
+ CoreFileHandle->FvFileHandles = AllocateZeroPool (sizeof (EFI_PEI_FILE_HANDLE) * PeimCount);\r
+ ASSERT (CoreFileHandle->FvFileHandles != NULL);\r
\r
//\r
// Get Apriori File handle\r
Status = FvPpi->FindSectionByType (FvPpi, EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r
if (!EFI_ERROR (Status)) {\r
//\r
- // Calculate the number of PEIMs in the A Priori list\r
+ // Calculate the number of PEIMs in the Apriori file\r
//\r
Status = FvPpi->GetFileInfo (FvPpi, AprioriFileHandle, &FileInfo);\r
ASSERT_EFI_ERROR (Status);\r
// Make an array of file name guids that matches the FileHandle array so we can convert\r
// quickly from file name to file handle\r
//\r
- Status = FvPpi->GetFileInfo (FvPpi, Private->CurrentFvFileHandles[Index], &FileInfo);\r
- CopyMem (&FileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID));\r
+ Status = FvPpi->GetFileInfo (FvPpi, TempFileHandles[Index], &FileInfo);\r
+ ASSERT_EFI_ERROR (Status);\r
+ CopyMem (&TempFileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID));\r
}\r
\r
//\r
- // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r
- // Add available PEIMs in Apriori file into TempFileHandles array at first.\r
+ // Walk through TempFileGuid array to find out who is invalid PEIM guid in Apriori file.\r
+ // Add available PEIMs in Apriori file into FvFileHandles array.\r
//\r
- Index2 = 0;\r
- for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r
- while (Index2 < Private->AprioriCount) {\r
- Guid = ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2++]);\r
- if (Guid != NULL) {\r
- break;\r
- }\r
- }\r
- if (Guid == NULL) {\r
- break;\r
- }\r
- PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r
- TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r
+ Index = 0;\r
+ for (Index2 = 0; Index2 < Private->AprioriCount; Index2++) {\r
+ Guid = ScanGuid (TempFileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2]);\r
+ if (Guid != NULL) {\r
+ PeimIndex = ((UINTN)Guid - (UINTN)&TempFileGuid[0])/sizeof (EFI_GUID);\r
+ CoreFileHandle->FvFileHandles[Index++] = TempFileHandles[PeimIndex];\r
\r
- //\r
- // Since we have copied the file handle we can remove it from this list.\r
- //\r
- Private->CurrentFvFileHandles[PeimIndex] = NULL;\r
+ //\r
+ // Since we have copied the file handle we can remove it from this list.\r
+ //\r
+ TempFileHandles[PeimIndex] = NULL;\r
+ }\r
}\r
\r
//\r
- // Update valid Aprioricount\r
+ // Update valid AprioriCount\r
//\r
Private->AprioriCount = Index;\r
\r
//\r
// Add in any PEIMs not in the Apriori file\r
//\r
- for (;Index < PeimCount; Index++) {\r
- for (Index2 = 0; Index2 < PeimCount; Index2++) {\r
- if (Private->CurrentFvFileHandles[Index2] != NULL) {\r
- TempFileHandles[Index] = Private->CurrentFvFileHandles[Index2];\r
- Private->CurrentFvFileHandles[Index2] = NULL;\r
- break;\r
- }\r
+ for (Index2 = 0; Index2 < PeimCount; Index2++) {\r
+ if (TempFileHandles[Index2] != NULL) {\r
+ CoreFileHandle->FvFileHandles[Index++] = TempFileHandles[Index2];\r
+ TempFileHandles[Index2] = NULL;\r
}\r
}\r
- //\r
- //Index the end of array contains re-range Pei moudle.\r
- //\r
- TempFileHandles[Index] = NULL;\r
-\r
- //\r
- // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r
- // We need to update it to start with files in the A Priori list and\r
- // then the remaining files in PEIM order.\r
- //\r
- CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
+ ASSERT (Index == PeimCount);\r
}\r
+ } else {\r
+ CopyMem (CoreFileHandle->FvFileHandles, TempFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PeimCount);\r
}\r
+\r
//\r
- // Cache the current Fv File Handle. So that we don't have to scan the Fv again.\r
- // Instead, we can retrieve the file handles within this Fv from cachable data.\r
+ // The current Fv File Handles have been cached. So that we don't have to scan the Fv again.\r
+ // Instead, we can retrieve the file handles within this Fv from cached records.\r
//\r
- Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
- CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
-\r
+ CoreFileHandle->ScanFv = TRUE;\r
+ Private->CurrentFvFileHandles = CoreFileHandle->FvFileHandles;\r
}\r
\r
//\r
SaveCurrentFileHandle = Private->CurrentFileHandle;\r
\r
for (Index1 = 0; Index1 < Private->FvCount; Index1++) {\r
- for (Index2 = 0; (Index2 < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
+ for (Index2 = 0; Index2 < Private->Fv[Index1].PeimCount; Index2++) {\r
if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISTER_FOR_SHADOW) {\r
PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
Private->CurrentFileHandle = PeimFileHandle;\r
// Start to dispatch all modules within the current Fv.\r
//\r
for (PeimCount = Private->CurrentPeimCount;\r
- (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
+ PeimCount < Private->Fv[FvCount].PeimCount;\r
PeimCount++) {\r
Private->CurrentPeimCount = PeimCount;\r
PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
}\r
\r
//\r
- // We set to NULL here to optimize the 2nd entry to this routine after\r
- // memory is found. This reprevents rescanning of the FV. We set to\r
- // NULL here so we start at the begining of the next FV\r
+ // Before walking through the next FV, we should set them to NULL/0 to\r
+ // start at the begining of the next FV.\r
//\r
Private->CurrentFileHandle = NULL;\r
Private->CurrentPeimCount = 0;\r
- //\r
- // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
- //\r
- SetMem (Private->CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv), 0);\r
+ Private->CurrentFvFileHandles = NULL;\r
}\r
\r
//\r
- // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r
- // through all the FV.\r
+ // Before making another pass, we should set it to 0 to\r
+ // go through all the FVs.\r
//\r
Private->CurrentPeimFvCount = 0;\r
\r
\r
if (PeimCount < Private->AprioriCount) {\r
//\r
- // If its in the A priori file then we set Depex to TRUE\r
+ // If it's in the Apriori file then we set Depex to TRUE\r
//\r
DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (Apriori)\n"));\r
return TRUE;\r