From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=PvSLBpEX; spf=pass (domain: ventanamicro.com, ip: 209.85.214.174, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pl1-f174.google.com with SMTP id c2so14176964plo.3 for ; Wed, 07 Sep 2022 04:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=R9vM+eoPYS0VwnBsNtaXSPs3zBGzrGuDIrXV8xY9LDM=; b=PvSLBpEXhXVDoraNkPEd3DzUoOyD1Wu8GByEfjAbEU9JJQrAvRj3UUCi2ywlZnjQ35 bs/Zl9sJQfyraLICZHaTNfE5C/lUutgJ47PbCQNvqCi3SxwppdEyONZkvUHYZWDVTm0a 5x3SWryh4DEchnuBALDRYVVGER4ou9nMp2VglxbgpSgfVFsUjingVCvPtxikbXZQ2Ou1 Sv8+LamZD3yMAwO37RAieL00RpdBntQQ69DmbMyIeRDjt/wy5CKo+yBq47upKK2v8Deq TNWYreEEQygYXvCM2SgUpkRw03xPbkqL32rNXvOlTbW3vVtcJJ6fc425T1bLRRW2M0JQ LZEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=R9vM+eoPYS0VwnBsNtaXSPs3zBGzrGuDIrXV8xY9LDM=; b=AuUQDHQ1biFNxEZKAS/j42yZePOgPIKYpRZf7QxNqK/2PKUcXOFS4/yXvbTwexsKb5 h52DzABh9XyWx7KUbP+ZrT58PfQhlFBHhWqQc+PveCxQIYhVHpT0TaKSs/VlC0clJyKQ 3/INdeVQZfRdWPXK6BmdFxDhVPVuNlDWv7Lgb7nsiOMyJUoKxdebe4fAoTbmaEnThaOO X0RH9/sDUGol23f6ZaUgexQyu2V1NlQAlszZ9gxfj9U0eHeNLBABM72oAZuwIOMHL8Y0 bN+aGrNir1dp1ifMOFJ+WGziPuGw3MhpX0YCA9qio/swtDBIJrD4T/am760h25U2ulAs WM9Q== X-Gm-Message-State: ACgBeo2o50rBNYPekE7LQYsa9nVkzAEndhGTbj/CfWBSTlAg1FpOEF5Y C313dlZxjdfjlOWQ/VXn8A8oh84irOWVeX8Z 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907111125.539698-1-sunilvl@ventanamicro.com> References: <20220907111125.539698-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=0D +# Platform Initialization Pei Library=0D +#=0D +# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D PlatformPeiLib=0D + FILE_GUID =3D B35BD738-787B-47FB-8139-20193442CC49=0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D PlatformPeiLib=0D +=0D +[Sources.RISCV64]=0D + RiscV64/PlatformPeiLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + HobLib=0D + FdtLib=0D + PcdLib=0D + PeimEntryPoint=0D + BaseLib=0D +=0D +[LibraryClasses.RISCV64]=0D + RiscVSbiLib=0D +=0D +[Guids]=0D + gFdtHobGuid ## PRODUCES=0D 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=0D + Library to initialize platform data at PEI phase=0D +=0D + Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights rese= rved.
=0D + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef _PLATFORM_PEI_LIB_H_=0D +#define _PLATFORM_PEI_LIB_H_=0D +=0D +EFI_STATUS PlatformPeim(VOID);=0D +=0D +#endif=0D 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=0D +The library call to pass the device tree to DXE via HOB.=0D +=0D +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights = reserved.
=0D +Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include =0D +=0D +#include =0D +=0D +/**=0D + @retval EFI_SUCCESS The address of FDT is passed in HOB.=0D + EFI_UNSUPPORTED Can't locate FDT.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PlatformPeim (=0D + VOID=0D + )=0D +{=0D + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext;=0D + VOID *FdtPointer;=0D + VOID *Base;=0D + VOID *NewBase;=0D + UINTN FdtSize;=0D + UINTN FdtPages;=0D + UINT64 *FdtHobData;=0D +=0D + FirmwareContext =3D NULL;=0D + GetFirmwareContextPointer (&FirmwareContext);=0D +=0D + if (FirmwareContext =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __FUNCTION__));= =0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree;=0D + if (FdtPointer =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__));=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: Build FDT HOB - FDT at address: 0x%x \n", __FUN= CTION__, FdtPointer));=0D + Base =3D FdtPointer;=0D + ASSERT (Base !=3D NULL);=0D + ASSERT (fdt_check_header (Base) =3D=3D 0);=0D +=0D + FdtSize =3D fdt_totalsize (Base);=0D + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize);=0D + NewBase =3D AllocatePages (FdtPages);=0D + ASSERT (NewBase !=3D NULL);=0D + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));=0D +=0D + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);=0D + ASSERT (FdtHobData !=3D NULL);=0D + *FdtHobData =3D (UINTN)NewBase;=0D +=0D + return EFI_SUCCESS;=0D +}=0D --=20 2.25.1