diff options
Diffstat (limited to 'UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c')
-rw-r--r-- | UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 160 |
1 files changed, 87 insertions, 73 deletions
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c index 4d1096b323..bea37fb18b 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c @@ -7,7 +7,7 @@ #include "UefiPayloadEntry.h"
-#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED | \
EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \
@@ -19,7 +19,7 @@ EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_PERSISTENT )
-#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED )
@@ -32,7 +32,7 @@ extern VOID *mHobList; **/
VOID
PrintHob (
- IN CONST VOID *HobStart
+ IN CONST VOID *HobStart
);
/**
@@ -48,17 +48,17 @@ PrintHob ( **/
EFI_STATUS
FixUpPcdDatabase (
- IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv
+ IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv
)
{
- EFI_STATUS Status;
- EFI_FFS_FILE_HEADER *FileHeader;
- VOID *PcdRawData;
- PEI_PCD_DATABASE *PeiDatabase;
- PEI_PCD_DATABASE *UplDatabase;
- EFI_HOB_GUID_TYPE *GuidHob;
- DYNAMICEX_MAPPING *ExMapTable;
- UINTN Index;
+ EFI_STATUS Status;
+ EFI_FFS_FILE_HEADER *FileHeader;
+ VOID *PcdRawData;
+ PEI_PCD_DATABASE *PeiDatabase;
+ PEI_PCD_DATABASE *UplDatabase;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ DYNAMICEX_MAPPING *ExMapTable;
+ UINTN Index;
GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
if (GuidHob == NULL) {
@@ -67,7 +67,8 @@ FixUpPcdDatabase ( //
return EFI_SUCCESS;
}
- PeiDatabase = (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);
+
+ PeiDatabase = (PEI_PCD_DATABASE *)GET_GUID_HOB_DATA (GuidHob);
DEBUG ((DEBUG_INFO, "Find the Pei PCD data base, the total local token number is %d\n", PeiDatabase->LocalTokenCount));
Status = FvFindFileByTypeGuid (DxeFv, EFI_FV_FILETYPE_DRIVER, PcdGetPtr (PcdPcdDriverFile), &FileHeader);
@@ -75,18 +76,20 @@ FixUpPcdDatabase ( if (EFI_ERROR (Status)) {
return Status;
}
+
Status = FileFindSection (FileHeader, EFI_SECTION_RAW, &PcdRawData);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
return Status;
}
- UplDatabase = (PEI_PCD_DATABASE *) PcdRawData;
- ExMapTable = (DYNAMICEX_MAPPING *) (UINTN) ((UINTN) PcdRawData + UplDatabase->ExMapTableOffset);
+ UplDatabase = (PEI_PCD_DATABASE *)PcdRawData;
+ ExMapTable = (DYNAMICEX_MAPPING *)(UINTN)((UINTN)PcdRawData + UplDatabase->ExMapTableOffset);
for (Index = 0; Index < UplDatabase->ExTokenCount; Index++) {
ExMapTable[Index].TokenNumber += PeiDatabase->LocalTokenCount;
}
+
DEBUG ((DEBUG_INFO, "Fix up UPL PCD database successfully\n"));
return EFI_SUCCESS;
}
@@ -98,14 +101,15 @@ FixUpPcdDatabase ( **/
VOID
AddNewHob (
- IN EFI_PEI_HOB_POINTERS *Hob
+ IN EFI_PEI_HOB_POINTERS *Hob
)
{
- EFI_PEI_HOB_POINTERS NewHob;
+ EFI_PEI_HOB_POINTERS NewHob;
if (Hob->Raw == NULL) {
return;
}
+
NewHob.Header = CreateHob (Hob->Header->HobType, Hob->Header->HobLength);
if (NewHob.Header != NULL) {
@@ -124,15 +128,15 @@ AddNewHob ( **/
EFI_HOB_RESOURCE_DESCRIPTOR *
FindResourceDescriptorByRange (
- IN VOID *HobList,
- IN EFI_PHYSICAL_ADDRESS Base,
- IN EFI_PHYSICAL_ADDRESS Top
+ IN VOID *HobList,
+ IN EFI_PHYSICAL_ADDRESS Base,
+ IN EFI_PHYSICAL_ADDRESS Top
)
{
- EFI_PEI_HOB_POINTERS Hob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- for (Hob.Raw = (UINT8 *) HobList; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = (UINT8 *)HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -147,6 +151,7 @@ FindResourceDescriptorByRange ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
@@ -157,11 +162,14 @@ FindResourceDescriptorByRange ( if (Base < ResourceHob->PhysicalStart) {
continue;
}
+
if (Top > (ResourceHob->PhysicalStart + ResourceHob->ResourceLength)) {
continue;
}
+
return ResourceHob;
}
+
return NULL;
}
@@ -176,17 +184,18 @@ FindResourceDescriptorByRange ( **/
EFI_HOB_RESOURCE_DESCRIPTOR *
FindAnotherHighestBelow4GResourceDescriptor (
- IN VOID *HobList,
- IN UINTN MinimalNeededSize,
- IN EFI_HOB_RESOURCE_DESCRIPTOR *ExceptResourceHob
+ IN VOID *HobList,
+ IN UINTN MinimalNeededSize,
+ IN EFI_HOB_RESOURCE_DESCRIPTOR *ExceptResourceHob
)
{
- EFI_PEI_HOB_POINTERS Hob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ReturnResourceHob;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ReturnResourceHob;
+
ReturnResourceHob = NULL;
- for (Hob.Raw = (UINT8 *) HobList; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = (UINT8 *)HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -201,6 +210,7 @@ FindAnotherHighestBelow4GResourceDescriptor ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
@@ -211,12 +221,14 @@ FindAnotherHighestBelow4GResourceDescriptor ( if (ResourceHob == ExceptResourceHob) {
continue;
}
+
//
// Skip Resource Descriptor HOBs that are beyond 4G
//
if ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength) > BASE_4GB) {
continue;
}
+
//
// Skip Resource Descriptor HOBs that are too small
//
@@ -235,6 +247,7 @@ FindAnotherHighestBelow4GResourceDescriptor ( }
}
}
+
return ReturnResourceHob;
}
@@ -253,39 +266,38 @@ BuildHobs ( OUT EFI_FIRMWARE_VOLUME_HEADER **DxeFv
)
{
- EFI_PEI_HOB_POINTERS Hob;
- UINTN MinimalNeededSize;
- EFI_PHYSICAL_ADDRESS FreeMemoryBottom;
- EFI_PHYSICAL_ADDRESS FreeMemoryTop;
- EFI_PHYSICAL_ADDRESS MemoryBottom;
- EFI_PHYSICAL_ADDRESS MemoryTop;
- EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- UNIVERSAL_PAYLOAD_EXTRA_DATA *ExtraData;
- UINT8 *GuidHob;
- EFI_HOB_FIRMWARE_VOLUME *FvHob;
- UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTable;
- ACPI_BOARD_INFO *AcpiBoardInfo;
-
- Hob.Raw = (UINT8 *) BootloaderParameter;
+ EFI_PEI_HOB_POINTERS Hob;
+ UINTN MinimalNeededSize;
+ EFI_PHYSICAL_ADDRESS FreeMemoryBottom;
+ EFI_PHYSICAL_ADDRESS FreeMemoryTop;
+ EFI_PHYSICAL_ADDRESS MemoryBottom;
+ EFI_PHYSICAL_ADDRESS MemoryTop;
+ EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ UNIVERSAL_PAYLOAD_EXTRA_DATA *ExtraData;
+ UINT8 *GuidHob;
+ EFI_HOB_FIRMWARE_VOLUME *FvHob;
+ UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTable;
+ ACPI_BOARD_INFO *AcpiBoardInfo;
+
+ Hob.Raw = (UINT8 *)BootloaderParameter;
MinimalNeededSize = FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
ASSERT (Hob.Raw != NULL);
- ASSERT ((UINTN) Hob.HandoffInformationTable->EfiFreeMemoryTop == Hob.HandoffInformationTable->EfiFreeMemoryTop);
- ASSERT ((UINTN) Hob.HandoffInformationTable->EfiMemoryTop == Hob.HandoffInformationTable->EfiMemoryTop);
- ASSERT ((UINTN) Hob.HandoffInformationTable->EfiFreeMemoryBottom == Hob.HandoffInformationTable->EfiFreeMemoryBottom);
- ASSERT ((UINTN) Hob.HandoffInformationTable->EfiMemoryBottom == Hob.HandoffInformationTable->EfiMemoryBottom);
-
+ ASSERT ((UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop == Hob.HandoffInformationTable->EfiFreeMemoryTop);
+ ASSERT ((UINTN)Hob.HandoffInformationTable->EfiMemoryTop == Hob.HandoffInformationTable->EfiMemoryTop);
+ ASSERT ((UINTN)Hob.HandoffInformationTable->EfiFreeMemoryBottom == Hob.HandoffInformationTable->EfiFreeMemoryBottom);
+ ASSERT ((UINTN)Hob.HandoffInformationTable->EfiMemoryBottom == Hob.HandoffInformationTable->EfiMemoryBottom);
//
// Try to find Resource Descriptor HOB that contains Hob range EfiMemoryBottom..EfiMemoryTop
//
- PhitResourceHob = FindResourceDescriptorByRange(Hob.Raw, Hob.HandoffInformationTable->EfiMemoryBottom, Hob.HandoffInformationTable->EfiMemoryTop);
+ PhitResourceHob = FindResourceDescriptorByRange (Hob.Raw, Hob.HandoffInformationTable->EfiMemoryBottom, Hob.HandoffInformationTable->EfiMemoryTop);
if (PhitResourceHob == NULL) {
//
// Boot loader's Phit Hob is not in an available Resource Descriptor, find another Resource Descriptor for new Phit Hob
//
- ResourceHob = FindAnotherHighestBelow4GResourceDescriptor(Hob.Raw, MinimalNeededSize, NULL);
+ ResourceHob = FindAnotherHighestBelow4GResourceDescriptor (Hob.Raw, MinimalNeededSize, NULL);
if (ResourceHob == NULL) {
return EFI_NOT_FOUND;
}
@@ -315,7 +327,7 @@ BuildHobs ( // In the Resource Descriptor HOB contains boot loader Hob, there is no enough free memory size for payload hob
// Find another Resource Descriptor Hob
//
- ResourceHob = FindAnotherHighestBelow4GResourceDescriptor(Hob.Raw, MinimalNeededSize, PhitResourceHob);
+ ResourceHob = FindAnotherHighestBelow4GResourceDescriptor (Hob.Raw, MinimalNeededSize, PhitResourceHob);
if (ResourceHob == NULL) {
return EFI_NOT_FOUND;
}
@@ -325,7 +337,8 @@ BuildHobs ( FreeMemoryTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength;
MemoryTop = FreeMemoryTop;
}
- HobConstructor ((VOID *) (UINTN) MemoryBottom, (VOID *) (UINTN) MemoryTop, (VOID *) (UINTN) FreeMemoryBottom, (VOID *) (UINTN) FreeMemoryTop);
+
+ HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID *)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);
//
// From now on, mHobList will point to the new Hob range.
//
@@ -333,7 +346,7 @@ BuildHobs ( //
// Create an empty FvHob for the DXE FV that contains DXE core.
//
- BuildFvHob ((EFI_PHYSICAL_ADDRESS) 0, 0);
+ BuildFvHob ((EFI_PHYSICAL_ADDRESS)0, 0);
//
// Since payload created new Hob, move all hobs except PHIT from boot loader hob list.
//
@@ -342,27 +355,28 @@ BuildHobs ( // Add this hob to payload HOB
AddNewHob (&Hob);
}
+
Hob.Raw = GET_NEXT_HOB (Hob);
}
//
// Get DXE FV location
//
- GuidHob = GetFirstGuidHob(&gUniversalPayloadExtraDataGuid);
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadExtraDataGuid);
ASSERT (GuidHob != NULL);
- ExtraData = (UNIVERSAL_PAYLOAD_EXTRA_DATA *) GET_GUID_HOB_DATA (GuidHob);
+ ExtraData = (UNIVERSAL_PAYLOAD_EXTRA_DATA *)GET_GUID_HOB_DATA (GuidHob);
ASSERT (ExtraData->Count == 1);
ASSERT (AsciiStrCmp (ExtraData->Entry[0].Identifier, "uefi_fv") == 0);
- *DxeFv = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) ExtraData->Entry[0].Base;
+ *DxeFv = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)ExtraData->Entry[0].Base;
ASSERT ((*DxeFv)->FvLength == ExtraData->Entry[0].Size);
//
// Create guid hob for acpi board information
//
- GuidHob = GetFirstGuidHob(&gUniversalPayloadAcpiTableGuid);
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);
if (GuidHob != NULL) {
- AcpiTable = (UNIVERSAL_PAYLOAD_ACPI_TABLE *) GET_GUID_HOB_DATA (GuidHob);
+ AcpiTable = (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GET_GUID_HOB_DATA (GuidHob);
AcpiBoardInfo = BuildHobFromAcpi ((UINT64)AcpiTable->Rsdp);
ASSERT (AcpiBoardInfo != NULL);
}
@@ -371,9 +385,9 @@ BuildHobs ( // Update DXE FV information to first fv hob in the hob list, which
// is the empty FvHob created before.
//
- FvHob = GetFirstHob (EFI_HOB_TYPE_FV);
- FvHob->BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) *DxeFv;
- FvHob->Length = (*DxeFv)->FvLength;
+ FvHob = GetFirstHob (EFI_HOB_TYPE_FV);
+ FvHob->BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)*DxeFv;
+ FvHob->Length = (*DxeFv)->FvLength;
return EFI_SUCCESS;
}
@@ -387,28 +401,28 @@ BuildHobs ( EFI_STATUS
EFIAPI
_ModuleEntryPoint (
- IN UINTN BootloaderParameter
+ IN UINTN BootloaderParameter
)
{
- EFI_STATUS Status;
- PHYSICAL_ADDRESS DxeCoreEntryPoint;
- EFI_PEI_HOB_POINTERS Hob;
- EFI_FIRMWARE_VOLUME_HEADER *DxeFv;
+ EFI_STATUS Status;
+ PHYSICAL_ADDRESS DxeCoreEntryPoint;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_FIRMWARE_VOLUME_HEADER *DxeFv;
- mHobList = (VOID *) BootloaderParameter;
+ mHobList = (VOID *)BootloaderParameter;
DxeFv = NULL;
// Call constructor for all libraries
ProcessLibraryConstructorList ();
DEBUG ((DEBUG_INFO, "Entering Universal Payload...\n"));
- DEBUG ((DEBUG_INFO, "sizeof(UINTN) = 0x%x\n", sizeof(UINTN)));
+ DEBUG ((DEBUG_INFO, "sizeof(UINTN) = 0x%x\n", sizeof (UINTN)));
DEBUG_CODE (
//
// Dump the Hobs from boot loader
//
PrintHob (mHobList);
- );
+ );
// Initialize floating point operating environment to be compliant with UEFI spec.
InitializeFloatingPointUnits ();
@@ -425,9 +439,9 @@ _ModuleEntryPoint ( // Mask off all legacy 8259 interrupt sources
//
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF);
- IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF);
+ IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF);
- Hob.HandoffInformationTable = (EFI_HOB_HANDOFF_INFO_TABLE *) GetFirstHob(EFI_HOB_TYPE_HANDOFF);
+ Hob.HandoffInformationTable = (EFI_HOB_HANDOFF_INFO_TABLE *)GetFirstHob (EFI_HOB_TYPE_HANDOFF);
HandOffToDxeCore (DxeCoreEntryPoint, Hob);
// Should not get here
|