-/*++\r
-\r
+/** @file\r
+ EFI PEI Core dispatch services\r
+ \r
Copyright (c) 2006, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
-Module Name:\r
-\r
- Dispatcher.c\r
-\r
-Abstract:\r
-\r
- EFI PEI Core dispatch services\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
\r
#include <PeiMain.h>\r
\r
-//\r
-//CAR is filled with this initial value during SEC phase\r
-//\r
+///\r
+/// CAR is filled with this initial value during SEC phase\r
+///\r
#define INIT_CAR_VALUE 0x5AA55AA5\r
\r
typedef struct {\r
EFI_HANDLE Handle;\r
} PEIM_FILE_HANDLE_EXTENDED_DATA;\r
\r
-VOID\r
-DiscoverPeimsAndOrderWithApriori (\r
- IN PEI_CORE_INSTANCE *Private,\r
- IN EFI_PEI_FV_HANDLE VolumeHandle\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Discover all Peims and optional Apriori file in one FV. There is at most one\r
Apriori file in one FV.\r
\r
-Arguments:\r
-\r
- Private - Pointer to the private data passed in from caller\r
- VolumeHandle - Fv handle.\r
-Returns:\r
\r
- NONE\r
+ @param Private - Pointer to the private data passed in from caller\r
+ @param VolumeHandle - Fv handle.\r
\r
---*/\r
+**/\r
+VOID\r
+DiscoverPeimsAndOrderWithApriori (\r
+ IN PEI_CORE_INSTANCE *Private,\r
+ IN EFI_PEI_FV_HANDLE VolumeHandle\r
+ )\r
{\r
EFI_STATUS Status;\r
EFI_PEI_FV_HANDLE FileHandle;\r
\r
}\r
\r
+/**\r
+ Shadow PeiCore module from flash to installed memory.\r
+ \r
+ @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+ @param PrivateInMem PeiCore's private data structure\r
+\r
+**/\r
VOID*\r
ShadowPeiCore(\r
EFI_PEI_SERVICES **PeiServices,\r
return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r
}\r
\r
-VOID\r
-PeiDispatcher (\r
- IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
- IN PEI_CORE_INSTANCE *Private\r
- )\r
-\r
-/*++\r
-\r
-Routine Description:\r
-\r
+/**\r
Conduct PEIM dispatch.\r
\r
-Arguments:\r
-\r
- SecCoreData - Points to a data structure containing information about the PEI core's operating\r
+ @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
environment, such as the size and location of temporary RAM, the stack location and\r
the BFV location.\r
- PrivateData - Pointer to the private data passed in from caller\r
- DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.\r
-\r
-Returns:\r
+ @param Private Pointer to the private data passed in from caller\r
\r
- EFI_SUCCESS - Successfully dispatched PEIM.\r
- EFI_NOT_FOUND - The dispatch failed.\r
+ @retval EFI_SUCCESS - Successfully dispatched PEIM.\r
+ @retval EFI_NOT_FOUND - The dispatch failed.\r
\r
---*/\r
+**/\r
+VOID\r
+PeiDispatcher (\r
+ IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
+ IN PEI_CORE_INSTANCE *Private\r
+ )\r
{\r
EFI_STATUS Status;\r
UINT32 Index1;\r
TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r
EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable;\r
EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable;\r
- INTN Offset;\r
+ INTN StackOffset;\r
+ INTN HeapOffset;\r
PEI_CORE_INSTANCE *PrivateInMem;\r
UINT64 NewPeiStackSize;\r
UINT64 OldPeiStackSize;\r
// Update HandOffHob for new installed permenent memory\r
//\r
OldHandOffTable = Private->HobList.HandoffInformationTable;\r
- OldCheckingBottom = (UINTN)OldHandOffTable;\r
+ OldCheckingBottom = (UINTN)(SecCoreData->TemporaryRamBase);\r
OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);\r
\r
//\r
// CAUTION: The new base is computed accounding to gap of new stack.\r
//\r
NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r
- Offset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->TemporaryRamBase;\r
- NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + Offset);\r
- PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + Offset);\r
+ \r
+ //\r
+ // Caculate stack offset and heap offset between CAR and new permement \r
+ // memory seperately.\r
+ //\r
+ StackOffset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase;\r
+ HeapOffset = (INTN) ((UINTN) Private->PhysicalMemoryBegin + Private->StackSize - \\r
+ (UINTN) SecCoreData->PeiTemporaryRamBase);\r
+ DEBUG ((EFI_D_INFO, "Heap Offset = 0x%X Stack Offset = 0x%X\n", HeapOffset, StackOffset));\r
+ \r
+ //\r
+ // Caculate new HandOffTable and PrivateData address in permenet memory's stack\r
+ //\r
+ NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + HeapOffset);\r
+ PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + StackOffset);\r
\r
//\r
// TemporaryRamSupportPpi is produced by platform's SEC\r
\r
\r
if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Temporary Ram support Ppi is provided by platform, it will copy \r
+ // temporary memory to permenent memory and do stack switching.\r
+ // After invoken temporary Ram support, following code's stack is in \r
+ // memory but not in CAR.\r
+ //\r
TemporaryRamSupportPpi->TemporaryRamMigration (\r
(CONST EFI_PEI_SERVICES **) PeiServices,\r
(EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,\r
);\r
\r
} else {\r
- CopyMem (\r
- (VOID*)(UINTN) NewPermenentMemoryBase,\r
- SecCoreData->TemporaryRamBase,\r
- SecCoreData->TemporaryRamSize\r
- );\r
+ //\r
+ // In IA32/x64/Itanium architecture, we need platform provide\r
+ // TEMPORAY_RAM_MIGRATION_PPI.\r
+ //\r
+ ASSERT (FALSE);\r
}\r
\r
\r
//\r
PrivateInMem->PS = &PrivateInMem->ServiceTableShadow;\r
PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo;\r
- PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset);\r
+ PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + HeapOffset);\r
PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);\r
\r
PeiServices = &PrivateInMem->PS;\r
// Update HandOffHob for new installed permenent memory\r
//\r
NewHandOffTable->EfiEndOfHobList =\r
- (EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset);\r
+ (EFI_PHYSICAL_ADDRESS)((UINTN) NewHandOffTable->EfiEndOfHobList + HeapOffset);\r
NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin +\r
PrivateInMem->PhysicalMemoryLength;\r
NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin;\r
//\r
// We need convert the PPI desciptor's pointer\r
//\r
- ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices, \r
+ ConvertPpiPointers (PrivateInMem, \r
OldCheckingBottom, \r
OldCheckingTop, \r
- NewHandOffTable);\r
+ HeapOffset\r
+ );\r
\r
DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",\r
(UINTN)PrivateInMem->StackBase,\r
PrivateInMem->PeiMemoryInstalled = TRUE;\r
\r
//\r
- // Make sure we don't retry the same PEIM that added memory\r
+ // Restart scan of all PEIMs on next pass\r
//\r
- PrivateInMem->CurrentPeimCount++;\r
+ PrivateInMem->CurrentPeimCount = 0;\r
\r
//\r
// Shadow PEI Core. When permanent memory is avaiable, shadow\r
\r
}\r
\r
-VOID\r
-InitializeDispatcherData (\r
- IN PEI_CORE_INSTANCE *PrivateData,\r
- IN PEI_CORE_INSTANCE *OldCoreData,\r
- IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
+/**\r
Initialize the Dispatcher's data members\r
\r
-Arguments:\r
-\r
- PeiServices - The PEI core services table.\r
- OldCoreData - Pointer to old core data (before switching stack).\r
+ @param PrivateData PeiCore's private data structure\r
+ @param OldCoreData Old data from SecCore\r
NULL if being run in non-permament memory mode.\r
- SecCoreData - Points to a data structure containing information about the PEI core's operating\r
+ @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
environment, such as the size and location of temporary RAM, the stack location and\r
the BFV location.\r
\r
-Returns:\r
-\r
- None.\r
+ @return None.\r
\r
---*/\r
+**/\r
+VOID\r
+InitializeDispatcherData (\r
+ IN PEI_CORE_INSTANCE *PrivateData,\r
+ IN PEI_CORE_INSTANCE *OldCoreData,\r
+ IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
+ )\r
{\r
if (OldCoreData == NULL) {\r
PeiInitializeFv (PrivateData, SecCoreData);\r
return;\r
}\r
\r
+/**\r
+ This routine parses the Dependency Expression, if available, and\r
+ decides if the module can be executed.\r
+\r
\r
+ @param Private PeiCore's private data structure\r
+ @param FileHandle PEIM's file handle\r
+ @param PeimCount Peim count in all dispatched PEIMs.\r
+\r
+ @retval TRUE Can be dispatched\r
+ @retval FALSE Cannot be dispatched\r
+\r
+**/\r
BOOLEAN\r
DepexSatisfied (\r
IN PEI_CORE_INSTANCE *Private,\r
IN EFI_PEI_FILE_HANDLE FileHandle,\r
IN UINTN PeimCount\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine parses the Dependency Expression, if available, and\r
- decides if the module can be executed.\r
-\r
-Arguments:\r
- PeiServices - The PEI Service Table\r
- CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r
-\r
-Returns:\r
- TRUE - Can be dispatched\r
- FALSE - Cannot be dispatched\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
VOID *DepexData;\r
This routine enable a PEIM to register itself to shadow when PEI Foundation\r
discovery permanent memory.\r
\r
- @param FileHandle File handle of a PEIM.\r
+ @param FileHandle File handle of a PEIM.\r
\r
- @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
- @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
- @retval EFI_SUCCESS Successfully to register itself.\r
+ @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
+ @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
+ @retval EFI_SUCCESS Successfully to register itself.\r
\r
**/\r
EFI_STATUS\r
return EFI_SUCCESS;\r
}\r
\r
-\r
-\r
/**\r
Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r
\r
- @param PeiServices Pointer to the PEI Core Services Table.\r
- @param FileHandle File handle of a Fv type file.\r
+ @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+ @param FvFileHandle File handle of a Fv type file.\r
@param AuthenticationState Pointer to attestation authentication state of image.\r
\r
\r
- @retval EFI_NOT_FOUND FV image can't be found.\r
- @retval EFI_SUCCESS Successfully to process it.\r
+ @retval EFI_NOT_FOUND FV image can't be found.\r
+ @retval EFI_SUCCESS Successfully to process it.\r
\r
**/\r
EFI_STATUS\r
EFI_FV_INFO FvImageInfo;\r
UINT32 FvAlignment;\r
VOID *FvBuffer;\r
- EFI_PEI_HOB_POINTERS HobFv2;\r
+ EFI_PEI_HOB_POINTERS HobPtr;\r
\r
FvBuffer = NULL;\r
*AuthenticationState = 0;\r
// Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
// been extracted.\r
//\r
- HobFv2.Raw = GetHobList ();\r
- while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r
- if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) {\r
+ HobPtr.Raw = GetHobList ();\r
+ while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r
+ if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r
//\r
// this FILE has been dispatched, it will not be dispatched again.\r
//\r
return EFI_SUCCESS;\r
}\r
- HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r
+ HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r
}\r
\r
//\r
);\r
\r
//\r
- // Inform HOB consumer phase, i.e. DXE core, the existance of this FV\r
+ // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r
+ // based on its parent Fvimage is informed or not.\r
+ // If FvHob of its parent fvimage is built, the extracted FvImage will be built also. \r
+ // Or, the extracted FvImage will not be built.\r
//\r
- BuildFvHob (\r
- (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r
- FvImageInfo.FvSize\r
- );\r
+ HobPtr.Raw = GetHobList ();\r
+ while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV, HobPtr.Raw)) != NULL) {\r
+ if (((EFI_PHYSICAL_ADDRESS) (UINTN)FvFileHandle > HobPtr.FirmwareVolume->BaseAddress) && \r
+ ((EFI_PHYSICAL_ADDRESS) (UINTN)FvFileHandle < HobPtr.FirmwareVolume->BaseAddress + HobPtr.FirmwareVolume->Length)) {\r
+ BuildFvHob (\r
+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r
+ FvImageInfo.FvSize\r
+ );\r
+ break;\r
+ }\r
+ HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r
+ }\r
+\r
//\r
// Makes the encapsulated volume show up in DXE phase to skip processing of\r
// encapsulated file again.\r