From: Abner Chang <abner.ch...@hpe.com>

Cc: Daniel Schaefer <daniel.schaefer>
Cc: Abner Chang <abner.ch...@hpe.com>
Cc: Sunil V L <suni...@ventanamicro.com>
Reviewed-by: Abner Chang <abner.ch...@hpe.com>

Signed-off-by: Daniel Schaefer <daniel.schae...@hpe.com>
---
 Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc |  5 ++
 Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf |  1 +
 Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf            | 49 
++++++++++++++
 Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c              | 70 
++++++++++++++++++++
 Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi          |  2 +-
 5 files changed, 126 insertions(+), 1 deletion(-)

diff --git 
a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc 
b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
index e971993b7b00..4fab3c4bdcbb 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
@@ -150,6 +150,10 @@
   
RiscVPlatformTimerLib|Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf

   
CpuExceptionHandlerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVExceptionLib/CpuExceptionHandlerDxeLib.inf

 

+

+  # Flattened Device Tree (FDT) access library

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

 [LibraryClasses.common.SEC]

 !ifdef $(DEBUG_ON_SERIAL_PORT)

   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

@@ -400,6 +404,7 @@
     <LibraryClasses>

       PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf

   }

+  Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf

 

   #

   # DXE Phase modules

diff --git 
a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf 
b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
index 820e19d11334..f0bd65fad648 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
@@ -101,6 +101,7 @@ INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 

 # RISC-V Platform PEI Driver

 INF  Platform/RISC-V/PlatformPkg/Universal/Pei/PlatformPei/PlatformPei.inf

+INF  Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf

 

 
################################################################################

 

diff --git a/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf 
b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf
new file mode 100644
index 000000000000..8dc58f0a8bf4
--- /dev/null
+++ b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf
@@ -0,0 +1,49 @@
+## @file

+# The FDT Peim driver is used to pass the device tree to DXE phase.

+#

+# Copyright (c) 2021, Hewlett Packard Enterprise Developmente LP. All rights 
reserved.<BR>

+#

+# SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = FdtPei

+  MODULE_UNI_FILE                = FdtPei.uni

+  FILE_GUID                      = 724FD5E9-F35E-4386-B1E1-2ADA6103C4F9

+  MODULE_TYPE                    = PEIM

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = PeimPassFdt

+

+#

+# The following information is for reference only and not required by the 
build tools.

+#

+#  VALID_ARCHITECTURES           = RISCV64

+#

+

+[Sources]

+  FdtPeim.c

+

+[Packages]

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  DebugLib

+  HobLib

+  FdtLib

+  PcdLib

+  PeiServicesLib

+  PeimEntryPoint

+  RiscVFirmwareContextLib

+

+[Guids]

+  gFdtHobGuid   ## PRODUCES

+

+[Depex]

+  TRUE

diff --git a/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c 
b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c
new file mode 100644
index 000000000000..2cd94f291c7d
--- /dev/null
+++ b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c
@@ -0,0 +1,70 @@
+/** @file

+The module to pass the device tree to DXE via HOB.

+

+Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights 
reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/RiscVFirmwareContextLib.h>

+

+#include <libfdt.h>

+

+#include <Guid/FdtHob.h>

+

+/**

+  The entrypoint of the module, it will pass the FDT via a HOB.

+

+  @param  FileHandle             Handle of the file being invoked.

+  @param  PeiServices            Describes the list of possible PEI Services.

+

+  @retval TODO

+**/

+EFI_STATUS

+EFIAPI

+PeimPassFdt (

+  IN EFI_PEI_FILE_HANDLE        FileHandle,

+  IN CONST EFI_PEI_SERVICES     **PeiServices

+  )

+{

+  VOID   *FdtPointer;

+  VOID   *Base;

+  VOID   *NewBase;

+  UINTN  FdtSize;

+  UINTN  FdtPages;

+  UINT64 *FdtHobData;

+  EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext;

+

+  FirmwareContext = NULL;

+  GetFirmwareContextPointer (&FirmwareContext);

+

+  if (FirmwareContext == NULL) {

+    DEBUG((DEBUG_ERROR, "%a: OpenSBI Firmware Context is NULL\n", 
__FUNCTION__));

+    return EFI_UNSUPPORTED;

+  }

+  FdtPointer = (VOID *)FirmwareContext->FlattenedDeviceTree;

+  if (FdtPointer == NULL) {

+    DEBUG((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__));

+    return EFI_UNSUPPORTED;

+  }

+  DEBUG((DEBUG_ERROR, "%a: Build FDT HOB - FDT at address: 0x%x \n", 
__FUNCTION__, FdtPointer));

+  Base = FdtPointer;

+  ASSERT (Base != NULL);

+  ASSERT (fdt_check_header (Base) == 0);

+

+  FdtSize = fdt_totalsize (Base);

+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);

+  NewBase = AllocatePages (FdtPages);

+  ASSERT (NewBase != NULL);

+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));

+

+  FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);

+  ASSERT (FdtHobData != NULL);

+  *FdtHobData = (UINTN)NewBase;

+

+  return EFI_SUCCESS;

+}

diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi 
b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
index 937caee08331..a731c7e36988 160000
--- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
+++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
@@ -1 +1 @@
-Subproject commit 937caee0833115f69d697ca190001ba0aa5c7368
+Subproject commit a731c7e36988c3308e1978ecde491f2f6182d490
-- 
2.31.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82283): https://edk2.groups.io/g/devel/message/82283
Mute This Topic: https://groups.io/mt/86432346/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to