Skip to content

Commit

Permalink
UefiPayloadPkg:Add SMBIOS node.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
LinusvPelt authored and mergify[bot] committed Oct 31, 2024
1 parent de19273 commit 60c6486
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
49 changes: 36 additions & 13 deletions UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <UniversalPayload/UniversalPayload.h>
#include <UniversalPayload/AcpiTable.h>
#include <UniversalPayload/SerialPortInfo.h>
#include <UniversalPayload/SmbiosTable.h>
#include <UniversalPayload/PciRootBridges.h>
#include <Guid/GraphicsInfoHob.h>
#include <Guid/UniversalPayloadSerialPortDeviceParentInfo.h>
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
gUniversalPayloadSerialPortInfoGuid
gUniversalPayloadDeviceTreeGuid
gUniversalPayloadAcpiTableGuid
gUniversalPayloadSmbios3TableGuid
gEfiHobMemoryAllocModuleGuid

[Pcd]
Expand Down
25 changes: 13 additions & 12 deletions UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -264,44 +264,45 @@ 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) {
SmbiosTable->Header.Revision = UNIVERSAL_PAYLOAD_SMBIOS_TABLE_REVISION;
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);
}
Expand Down

0 comments on commit 60c6486

Please sign in to comment.