From nobody Mon Feb 9 23:15:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93411+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93411+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1662550661; cv=none; d=zohomail.com; s=zohoarc; b=IUDyn2uIaxNk7Lz57vHUplo5M7srhezrFqnjZRkJZAIKC7TarRy6Auy7zxk5uWuBEiqW6h2KJw3W0as/cIL0NOo1Cu4YS6vBAZMdHuPV569cXLwZQ/7fh9pZpAU62mGSqBGDJY4T44KzqNJvoZMRdRf0cNjaKzevrVL4kUDZF4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662550661; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=OkaGFJ7TrzM3AelpOD8ZgpRjSKhSpheVhmBGS5x1uFw=; b=WiNutpNwTFEUPKACM+123fdfAwB6ZQ9+AHD2C/HsRVmCqqdPz+maajqOoEPmTih6Eurbo4BkGdA+6yuqBftSyh0MLPjoTUi97xA6u/+wkUDVVaKcK7KN2NuBX1Hh/+PwWh7ifKhJ2CRWt99eAjRzZR7g7Nk4MRwG2M9mnI4eOe8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93411+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166255066165717.007943681385086; Wed, 7 Sep 2022 04:37:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yEP2YY1788612xNylOIOQbEa; Wed, 07 Sep 2022 04:37:40 -0700 X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mx.groups.io with SMTP id smtpd.web11.6495.1662550659329949039 for ; Wed, 07 Sep 2022 04:37:39 -0700 X-Received: by mail-pl1-f178.google.com with SMTP id jm11so14179037plb.13 for ; Wed, 07 Sep 2022 04:37:39 -0700 (PDT) X-Gm-Message-State: vEKksAiyKHP0YHT994VrcwMvx1787277AA= X-Google-Smtp-Source: AA6agR6WRy6f2bdps2M2u1ow2psB92nJJrQ4JtCifse2IplviXf3SE5EvvbC56ptq7LgSBC8ov4e2Q== X-Received: by 2002:a17:90a:7e87:b0:1fe:4d96:f6f6 with SMTP id j7-20020a17090a7e8700b001fe4d96f6f6mr3443934pjl.142.1662550658477; Wed, 07 Sep 2022 04:37:38 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id 8-20020a17090a000800b001fd77933fb3sm10797230pja.17.2022.09.07.04.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:37:38 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Eric Dong , Ray Ni , Rahul Kumar , Debkumar De , Catharine West , Daniel Schaefer , Abner Chang , Leif Lindholm , Andrew Fish , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel , Sunil V L Subject: [edk2-devel] [RFC PATCH V2 13/19] MdePkg: Add PlatformPeiLib library Date: Wed, 7 Sep 2022 17:06:20 +0530 Message-Id: <20220907113626.540065-14-sunilvl@ventanamicro.com> In-Reply-To: <20220907113626.540065-1-sunilvl@ventanamicro.com> References: <20220907113626.540065-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1662550660; bh=ecNihrqeL3djmTw+wKJcbf111jPVoEtiqm4XPn56nSs=; h=Cc:Date:From:Reply-To:Subject:To; b=X6aC4Rn6uttNtJUkc0maaoIH7vanj5nSoTnXB4VvAmdZBgxtpDG/q17eeznDsRresvU fAmziEIQqz9kof1FsyuZ+LERdCGCs7r60LZnB9vK38vvTwMzYjJut0A/Yrkpv3N8Ksnbm LONYqhV7mQUShdZqww8VEa6xLoMbFVSnas8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1662550663216100003 Content-Type: text/plain; charset="utf-8" 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 --- 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/Libr= ary/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 righ= ts reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D PlatformPeiLib + FILE_GUID =3D B35BD738-787B-47FB-8139-20193442CC49 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D 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/Libra= ry/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 rese= rved.
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ + 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/MdePk= g/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.
+Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include + +#include + +/** + @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 =3D NULL; + GetFirmwareContextPointer (&FirmwareContext); + + if (FirmwareContext =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree; + if (FdtPointer =3D=3D 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", __FUN= CTION__, FdtPointer)); + Base =3D FdtPointer; + ASSERT (Base !=3D NULL); + ASSERT (fdt_check_header (Base) =3D=3D 0); + + FdtSize =3D fdt_totalsize (Base); + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize); + NewBase =3D AllocatePages (FdtPages); + ASSERT (NewBase !=3D NULL); + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData); + ASSERT (FdtHobData !=3D NULL); + *FdtHobData =3D (UINTN)NewBase; + + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-