From nobody Mon Feb 9 20:59:04 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+93389+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+93389+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1662549177; cv=none; d=zohomail.com; s=zohoarc; b=UpYjiiWSjuyGJdp7vj2m6KGbEuTrXqvUbQg24AAl7kzqYLpq+DVZzBHPxWZ9qZCt7s4RZALriPJR/0ku1jNddod1iyA7WxqPXqSpuft5k3xerjDCAwrA1lrLxqGy7QMDsj/OMzhQ8K2ac5uOnzE/5B9htjdE/83DpL1qlMKRTlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662549177; 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=akOysab7DLQROnHDXh2pvQCQopyd3CFzCdGLhYHVGlY=; b=oFUQ8O7t911t5pZa7ATyRiWCxRSSvf6y0HxSqu9fsXBb+ToxCUrtBcWaABZmXY+jQYB/dpgn6tuGGueDe5zHWuK3hrJ8T/WbvIgJzv+ip6ZjLFDj8qe9YRMa+glHiCQHZvrd6d2UPyELx7ANOjG2Sr5vZd6wiC/5nRnNtTdXJOo= 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+93389+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1662549177753875.5024295429408; Wed, 7 Sep 2022 04:12:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4c7nYY1788612xrQbmCD4SOo; Wed, 07 Sep 2022 04:12:56 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web11.6322.1662549175801040599 for ; Wed, 07 Sep 2022 04:12:55 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id c2so14176964plo.3 for ; Wed, 07 Sep 2022 04:12:55 -0700 (PDT) X-Gm-Message-State: zsc7zaPkUeNkijOEZ6XYmC4nx1787277AA= X-Google-Smtp-Source: AA6agR4tKHk2lYhA3bLRMwL2ZRKkVdJ3wMizh7LolmpNOEmaFG5Ela9i4bJzFcIAkh6exJxjcgs6xw== X-Received: by 2002:a17:902:ec83:b0:174:ce14:ee4 with SMTP id x3-20020a170902ec8300b00174ce140ee4mr3196342plg.17.1662549174775; Wed, 07 Sep 2022 04:12:54 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id y5-20020aa79ae5000000b0052b84ca900csm12208518pfp.62.2022.09.07.04.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:12:54 -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 16:41:19 +0530 Message-Id: <20220907111125.539698-14-sunilvl@ventanamicro.com> In-Reply-To: <20220907111125.539698-1-sunilvl@ventanamicro.com> References: <20220907111125.539698-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=1662549176; bh=4YTBcZqfJF9sRpMqvW0EfeRbqIq6uZQ2iqvNQr3OXPA=; h=Cc:Date:From:Reply-To:Subject:To; b=TlCgWE18fDMyV46tb9VlXMS+17pwG95/l/jURsedRZ4yFjTxH6g1bglWlZJp1B1R8BZ ilPDlvHJAGQ8l0w5bW5YOsxAGJyVjGQ0E2D4G0gHJRZy6AdBWPb3pWzJ9qSmSztJ5AOeU Bjw7nYp/aIN5NGdJKlNdPYte650pp8MzVTQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1662549178625100005 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 (#93389): https://edk2.groups.io/g/devel/message/93389 Mute This Topic: https://groups.io/mt/93522348/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-