public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sunil V L" <sunilvl@ventanamicro.com>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>,
	Debkumar De <debkumar.de@intel.com>,
	Catharine West <catharine.west@intel.com>,
	Daniel Schaefer <git@danielschaefer.me>,
	Abner Chang <Abner.Chang@amd.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Andrew Fish <afish@apple.com>, Ard Biesheuvel <ardb@kernel.org>,
	Heinrich Schuchardt <heinrich.schuchardt@canonical.com>,
	Anup Patel <apatel@ventanamicro.com>,
	Sunil V L <sunilvl@ventanamicro.com>
Subject: [RFC PATCH V2 13/19] MdePkg: Add PlatformPeiLib library
Date: Wed,  7 Sep 2022 17:06:20 +0530	[thread overview]
Message-ID: <20220907113626.540065-14-sunilvl@ventanamicro.com> (raw)
In-Reply-To: <20220907113626.540065-1-sunilvl@ventanamicro.com>

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@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


  parent reply	other threads:[~2022-09-07 11:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 11:36 [RFC PATCH V2 00/19] Refactor and add RISC-V support in edk2 repo Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 01/19] MdePkg/Register: Add register definition header files for RISC-V Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 02/19] MdePkg/MdePkg.dec: Add RISCV_EFI_BOOT_PROTOCOL GUID Sunil V L
2022-12-08  1:21   ` Heinrich Schuchardt
2022-09-07 11:36 ` [RFC PATCH V2 03/19] MdePkg/Protocol: Add RiscVBootProtocol.h Sunil V L
2022-12-08  1:24   ` Heinrich Schuchardt
2022-09-07 11:36 ` [RFC PATCH V2 04/19] MdeModulePkg/MdeModulePkg.dec: Add PCD variables for RISC-V Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 05/19] UefiCpuPkg.dec: Add PCD variable " Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 06/19] MdePkg/BaseLib: RISC-V: Add generic CPU related functions Sunil V L
2022-12-08  1:43   ` Heinrich Schuchardt
2022-12-08  5:04     ` Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 07/19] MdePkg: Add ArchTimerLib library Sunil V L
2022-12-08  1:59   ` Heinrich Schuchardt
2022-09-07 11:36 ` [RFC PATCH V2 08/19] MdePkg: Add RiscVSbiLib Library for RISC-V Sunil V L
2022-12-08  2:22   ` Heinrich Schuchardt
2022-09-07 11:36 ` [RFC PATCH V2 09/19] UefiCpuPkg: Update Sources in DxeCpuExceptionHandlerLib.inf Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 10/19] UefiCpuPkg: Add RISC-V support in DxeCpuExceptionHandlerLib Sunil V L
2022-12-08  0:30   ` [edk2-devel] " Ni, Ray
2022-12-08  4:58     ` Sunil V L
2022-12-08  8:32       ` Ni, Ray
2022-12-14  9:38         ` Leif Lindholm
2022-12-14 12:37           ` Ni, Ray
2022-12-16  5:22             ` Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 11/19] MdePkg/Library: Add ResetSystemLib library Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 12/19] UefiCpuPkg/SecCore: Add SEC startup code for RISC-V Sunil V L
2022-09-07 11:36 ` Sunil V L [this message]
2022-09-07 11:36 ` [RFC PATCH V2 14/19] MdeModulePkg/Universal: Add PlatformPei module " Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 15/19] UefiCpuPkg/CpuDxe: Refactor to allow other CPU architectures Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 16/19] UefiCpuPkg/CpuDxe: Add RISC-V support in CpuDxe module Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 17/19] MdeModulePkg/Universal: Add TimerDxe module Sunil V L
2022-09-07 11:36 ` [RFC PATCH V2 18/19] RISC-V: Add Qemu Virt platform support Sunil V L
2022-12-08  2:33   ` Heinrich Schuchardt
  -- strict thread matches above, loose matches on Subject: below --
2022-09-07 11:11 [RFC PATCH V2 00/19] Refactor and add RISC-V support in edk2 repo Sunil V L
2022-09-07 11:11 ` [RFC PATCH V2 13/19] MdePkg: Add PlatformPeiLib library Sunil V L

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220907113626.540065-14-sunilvl@ventanamicro.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox