Skip to content

Commit

Permalink
UPSTREAM: UefiPayloadPkg: Add fdt hob
Browse files Browse the repository at this point in the history
We need to parse RAS and other related data from fdt.
  • Loading branch information
dhaval-rivos committed Nov 19, 2024
1 parent 7c48d03 commit 8dcaa94
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
EmbeddedPkg/EmbeddedPkg.dec

[LibraryClasses]
BaseMemoryLib
Expand All @@ -42,6 +43,7 @@
gUniversalPayloadAcpiTableGuid
gUniversalPayloadSmbios3TableGuid
gEfiHobMemoryAllocModuleGuid
gFdtHobGuid

[Pcd]
gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable
101 changes: 101 additions & 0 deletions UefiPayloadPkg/Library/CustomFdtNodeParserLib/RiscVFdtNodeParserLib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** @file
* Parser functionality specific to Risc-V
Copyright (c) 2024, Rivos Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <PiPei.h>
#include <Pi/PiHob.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/PrintLib.h>
#include <Library/FdtLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>
#include "../UefiPayloadEntry/UefiPayloadEntry.h"

/**
Build RV CPU HOB using infomation from FDT.
@param FdtBase
**/
STATIC VOID
EFIAPI
BuildRVCpuHob (
IN VOID *FdtBase
)
{
INT32 Node;
INT32 Property;
CONST FDT_PROPERTY *PropertyPtr;
INT32 TempLen;
UINT32 *Data32;
INT32 Len;
EFI_HOB_RISCV_CPU *Hob;

Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "cpus", (INT32)AsciiStrLen ("cpus"));
ASSERT (Node > 0);
if (FdtGetProperty (FdtBase, Node, "boot-hart", &Len) != 0) {
Property = FdtFirstPropertyOffset (FdtBase, Node);
PropertyPtr = FdtGetPropertyByOffset (FdtBase, Property, &TempLen);
Data32 = (UINT32 *)(PropertyPtr->Data);

Hob = CreateHob (EFI_HOB_TYPE_RISCV_CPU, sizeof (EFI_HOB_RISCV_CPU));
ASSERT (Hob != NULL);
Hob->CpuId = (UINT8)Fdt32ToCpu (*Data32);

//
// Zero the reserved space to match HOB spec
//
ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
}
}

/**
Build FDT HOB using infomation from FDT.
@param FdtBase
**/
STATIC VOID
EFIAPI
BuildFdtHob (
IN VOID *FdtBase
)
{
VOID *NewBase;
UINTN FdtSize;
UINTN FdtPages;
UINT64 *FdtHobData;

ASSERT (FdtCheckHeader (FdtBase) == 0);
FdtSize = FdtTotalSize (FdtBase);
FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
NewBase = AllocatePages (FdtPages);
ASSERT (NewBase != NULL);
FdtOpenInto (FdtBase, NewBase, EFI_PAGES_TO_SIZE (FdtPages));

FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
ASSERT (FdtHobData != NULL);
*FdtHobData = (UINTN)NewBase;
}

/**
It will Parse FDT -custom node based on information from bootloaders.
@param[in] FdtBase The starting memory address of FdtBase
@param[in] HobList The starting memory address of New Hob list.
**/
UINTN
EFIAPI
CustomFdtNodeParser (
IN VOID *FdtBase,
IN VOID *HobList
)
{
BuildRVCpuHob (FdtBase);
BuildFdtHob (FdtBase);
return EFI_SUCCESS;
}

0 comments on commit 8dcaa94

Please sign in to comment.