[edk2-devel] [RFC PATCH V2 13/19] MdePkg: Add PlatformPeiLib library
Sunil V L
sunilvl at ventanamicro.com
Wed Sep 7 11:36:20 UTC 2022
This library is required in RISC-V to build the FDT Hob. The
library can be leveraged by other architectures like ARM if
required.
Signed-off-by: Sunil V L <sunilvl at ventanamicro.com>
---
MdePkg/Library/PlatformPeiLib/PlatformPeiLib.inf | 40 ++++++++++++
MdePkg/Include/Library/PlatformPeiLib.h | 15 +++++
MdePkg/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c | 68 ++++++++++++++++++++
3 files changed, 123 insertions(+)
diff --git a/MdePkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/MdePkg/Library/PlatformPeiLib/PlatformPeiLib.inf
new file mode 100644
index 000000000000..d682b3c0f908
--- /dev/null
+++ b/MdePkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -0,0 +1,40 @@
+## @file
+# Platform Initialization Pei Library
+#
+# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001b
+ BASE_NAME = PlatformPeiLib
+ FILE_GUID = B35BD738-787B-47FB-8139-20193442CC49
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PlatformPeiLib
+
+[Sources.RISCV64]
+ RiscV64/PlatformPeiLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UefiCpuPkg/UefiCpuPkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+ FdtLib
+ PcdLib
+ PeimEntryPoint
+ BaseLib
+
+[LibraryClasses.RISCV64]
+ RiscVSbiLib
+
+[Guids]
+ gFdtHobGuid ## PRODUCES
diff --git a/MdePkg/Include/Library/PlatformPeiLib.h b/MdePkg/Include/Library/PlatformPeiLib.h
new file mode 100644
index 000000000000..1e8c5f98cfe2
--- /dev/null
+++ b/MdePkg/Include/Library/PlatformPeiLib.h
@@ -0,0 +1,15 @@
+/** @file
+ Library to initialize platform data at PEI phase
+
+ Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights reserved.<BR>
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef _PLATFORM_PEI_LIB_H_
+#define _PLATFORM_PEI_LIB_H_
+
+EFI_STATUS PlatformPeim(VOID);
+
+#endif
diff --git a/MdePkg/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c b/MdePkg/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c
new file mode 100644
index 000000000000..e62aa26df9e5
--- /dev/null
+++ b/MdePkg/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c
@@ -0,0 +1,68 @@
+/** @file
+The library call to pass the device tree to DXE via HOB.
+
+Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+Copyright (c) 2022, Ventana Micro Systems Inc. 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/RiscVSbiLib.h>
+
+#include <libfdt.h>
+
+#include <Guid/FdtHob.h>
+
+/**
+ @retval EFI_SUCCESS The address of FDT is passed in HOB.
+ EFI_UNSUPPORTED Can't locate FDT.
+**/
+EFI_STATUS
+EFIAPI
+PlatformPeim (
+ VOID
+ )
+{
+ EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext;
+ VOID *FdtPointer;
+ VOID *Base;
+ VOID *NewBase;
+ UINTN FdtSize;
+ UINTN FdtPages;
+ UINT64 *FdtHobData;
+
+ FirmwareContext = NULL;
+ GetFirmwareContextPointer (&FirmwareContext);
+
+ if (FirmwareContext == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: 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_INFO, "%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;
+}
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#93411): https://edk2.groups.io/g/devel/message/93411
Mute This Topic: https://groups.io/mt/93522720/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list