From 60c6486f798f863a11fd96c4473375dfff51c498 Mon Sep 17 00:00:00 2001 From: Linus Liu Date: Fri, 20 Sep 2024 00:22:12 -0700 Subject: [PATCH] =?UTF-8?q?UefiPayloadPkg=EF=BC=9AAdd=20SMBIOS=20node.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per other platform request , need to add SMBIOS device node into FDT. In the current phase(1) , only supporting SM3EntryPoint structure. Signed-off-by: Linus Liu --- .../Library/BuildFdtLib/X86_BuildFdtLib.c | 49 ++++++++++++++----- .../CustomFdtNodeParserLib.c | 4 ++ .../CustomFdtNodeParserLib.inf | 1 + .../Library/FdtParserLib/FdtParserLib.c | 25 +++++----- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c b/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c index 58a354a348..3c190bf0d9 100644 --- a/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c +++ b/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -142,19 +143,22 @@ BuildFdtForMemAlloc ( IN VOID *FdtBase ) { - EFI_STATUS Status; - EFI_PEI_HOB_POINTERS Hob; - VOID *HobStart; - VOID *Fdt; - INT32 ParentNode; - INT32 TempNode; - CHAR8 TempStr[32]; - UINT64 RegTmp[2]; - UINT32 AllocMemType; - EFI_GUID *AllocMemName; - UINT8 IsStackHob; - UINT8 IsBspStore; - UINT32 Data32; + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS Hob; + VOID *HobStart; + VOID *Fdt; + INT32 ParentNode; + INT32 TempNode; + CHAR8 TempStr[32]; + UINT64 RegTmp[2]; + UINT32 AllocMemType; + EFI_GUID *AllocMemName; + UINT8 IsStackHob; + UINT8 IsBspStore; + UINT32 Data32; + UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmbiosTable; + UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTable; + EFI_HOB_GUID_TYPE *GuidHob; Fdt = FdtBase; @@ -165,6 +169,25 @@ BuildFdtForMemAlloc ( Status = FdtSetProperty (Fdt, ParentNode, "#address-cells", &Data32, sizeof (UINT32)); Status = FdtSetProperty (Fdt, ParentNode, "#size-cells", &Data32, sizeof (UINT32)); + GuidHob = NULL; + SmbiosTable = NULL; + GuidHob = GetFirstGuidHob (&gUniversalPayloadSmbios3TableGuid); + if (GuidHob != NULL) { + SmbiosTable = GET_GUID_HOB_DATA (GuidHob); + DEBUG ((DEBUG_INFO, "To build Smbios memory FDT ,SmbiosTable :%lx, SmBiosEntryPoint :%lx\n", (UINTN)SmbiosTable, SmbiosTable->SmBiosEntryPoint)); + Status = AsciiSPrint (TempStr, sizeof (TempStr), "memory@%lX", SmbiosTable->SmBiosEntryPoint); + DEBUG ((DEBUG_INFO, "To build Smbios memory FDT #2, SmbiosTable->Header.Length :%x\n", SmbiosTable->Header.Length)); + TempNode = 0; + TempNode = FdtAddSubnode (Fdt, ParentNode, TempStr); + DEBUG ((DEBUG_INFO, "FdtAddSubnode %x", TempNode)); + RegTmp[0] = CpuToFdt64 (SmbiosTable->SmBiosEntryPoint); + RegTmp[1] = CpuToFdt64 (SmbiosTable->Header.Length); + FdtSetProperty (Fdt, TempNode, "reg", &RegTmp, sizeof (RegTmp)); + ASSERT_EFI_ERROR (Status); + FdtSetProperty (Fdt, TempNode, "compatible", "smbios", (UINT32)(AsciiStrLen ("smbios")+1)); + ASSERT_EFI_ERROR (Status); + } + HobStart = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION); // // Scan memory allocation hobs to set memory type diff --git a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c index 0c454496dc..5ce0aa315c 100644 --- a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c +++ b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c @@ -87,6 +87,10 @@ FitIsHobNeed ( } if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { + if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadSmbios3TableGuid)) { + return FALSE; + } + if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadSerialPortInfoGuid)) { return FALSE; } diff --git a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf index 036ed4315d..6f1e5fc8c9 100644 --- a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf +++ b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf @@ -40,6 +40,7 @@ gUniversalPayloadSerialPortInfoGuid gUniversalPayloadDeviceTreeGuid gUniversalPayloadAcpiTableGuid + gUniversalPayloadSmbios3TableGuid gEfiHobMemoryAllocModuleGuid [Pcd] diff --git a/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c b/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c index 9bece35e5c..7403099300 100644 --- a/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c +++ b/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c @@ -253,7 +253,7 @@ ParseReservedMemory ( StartAddress = Fdt64ToCpu (*Data64); NumberOfBytes = Fdt64ToCpu (*(Data64 + 1)); DEBUG ((DEBUG_INFO, "\n Property %a", TempStr)); - DEBUG ((DEBUG_INFO, " %016lX %016lX", StartAddress, NumberOfBytes)); + DEBUG ((DEBUG_INFO, " %016lX %016lX\n", StartAddress, NumberOfBytes)); } RecordMemoryNode (SubNode); @@ -264,34 +264,38 @@ ParseReservedMemory ( } else { PropertyPtr = FdtGetProperty (Fdt, SubNode, "compatible", &TempLen); TempStr = (CHAR8 *)(PropertyPtr->Data); + DEBUG ((DEBUG_INFO, "compatible: %a\n", TempStr)); if (AsciiStrnCmp (TempStr, "boot-code", AsciiStrLen ("boot-code")) == 0) { - DEBUG ((DEBUG_INFO, " boot-code")); + DEBUG ((DEBUG_INFO, " boot-code\n")); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiBootServicesCode); } else if (AsciiStrnCmp (TempStr, "boot-data", AsciiStrLen ("boot-data")) == 0) { - DEBUG ((DEBUG_INFO, " boot-data")); + DEBUG ((DEBUG_INFO, " boot-data\n")); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiBootServicesData); } else if (AsciiStrnCmp (TempStr, "runtime-code", AsciiStrLen ("runtime-code")) == 0) { - DEBUG ((DEBUG_INFO, " runtime-code")); + DEBUG ((DEBUG_INFO, " runtime-code\n")); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiRuntimeServicesCode); } else if (AsciiStrnCmp (TempStr, "runtime-data", AsciiStrLen ("runtime-data")) == 0) { - DEBUG ((DEBUG_INFO, " runtime-data")); + DEBUG ((DEBUG_INFO, " runtime-data\n")); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiRuntimeServicesData); } else if (AsciiStrnCmp (TempStr, "special-purpose", AsciiStrLen ("special-purpose")) == 0) { Attribute = MEMORY_ATTRIBUTE_DEFAULT | EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE; - DEBUG ((DEBUG_INFO, " special-purpose memory")); + DEBUG ((DEBUG_INFO, " special-purpose memory\n")); BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, Attribute, StartAddress, NumberOfBytes); + } else if (AsciiStrnCmp (TempStr, "acpi-nvs", AsciiStrLen ("acpi-nvs")) == 0) { + DEBUG ((DEBUG_INFO, "\n ********* acpi-nvs ********\n")); + BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiACPIMemoryNVS); } else if (AsciiStrnCmp (TempStr, "acpi", AsciiStrLen ("acpi")) == 0) { - DEBUG ((DEBUG_INFO, " acpi, StartAddress:%x, NumberOfBytes:%x", StartAddress, NumberOfBytes)); + DEBUG ((DEBUG_INFO, " acpi, StartAddress:%x, NumberOfBytes:%x\n", StartAddress, NumberOfBytes)); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiBootServicesData); PlatformAcpiTable = BuildGuidHob (&gUniversalPayloadAcpiTableGuid, sizeof (UNIVERSAL_PAYLOAD_ACPI_TABLE)); if (PlatformAcpiTable != NULL) { - DEBUG ((DEBUG_INFO, " build gUniversalPayloadAcpiTableGuid , NumberOfBytes:%x", NumberOfBytes)); + DEBUG ((DEBUG_INFO, " build gUniversalPayloadAcpiTableGuid , NumberOfBytes:%x\n", NumberOfBytes)); PlatformAcpiTable->Rsdp = (EFI_PHYSICAL_ADDRESS)(UINTN)StartAddress; PlatformAcpiTable->Header.Revision = UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION; PlatformAcpiTable->Header.Length = sizeof (UNIVERSAL_PAYLOAD_ACPI_TABLE); } } else if (AsciiStrnCmp (TempStr, "smbios", AsciiStrLen ("smbios")) == 0) { - DEBUG ((DEBUG_INFO, " build smbios, NumberOfBytes:%x", NumberOfBytes)); + DEBUG ((DEBUG_INFO, " build smbios, NumberOfBytes:%x\n", NumberOfBytes)); BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiBootServicesData); SmbiosTable = BuildGuidHob (&gUniversalPayloadSmbios3TableGuid, sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE)); if (SmbiosTable != NULL) { @@ -299,9 +303,6 @@ ParseReservedMemory ( SmbiosTable->Header.Length = sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE); SmbiosTable->SmBiosEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)(StartAddress); } - } else if (AsciiStrnCmp (TempStr, "acpi-nvs", AsciiStrLen ("acpi-nvs")) == 0) { - DEBUG ((DEBUG_INFO, " acpi-nvs")); - BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiACPIMemoryNVS); } else { BuildMemoryAllocationHob (StartAddress, NumberOfBytes, EfiReservedMemoryType); }