From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mx.groups.io with SMTP id smtpd.web12.1919.1662484190796837187 for ; Tue, 06 Sep 2022 10:09:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=QJV0vKkf; spf=pass (domain: ventanamicro.com, ip: 209.85.210.178, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pf1-f178.google.com with SMTP id 145so12027504pfw.4 for ; Tue, 06 Sep 2022 10:09:50 -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=1Hd2qPr+QVbF+eT8TDZ6RItZhKEtbimLwchB3rYpk3Y=; b=QJV0vKkfKcnvhi0DtUu6rMJ9jaScBomjZWXdNJ0Qr+GVM2vaI/Muwdhm4OFObHcgk+ ZZUtlJ0p+eEWypzhD1NvyDeIwAq8ZcZZPk4e7U6wmb+qYavR2X1SUj1jmEP10JmHoLOn eFV6PBMwnNC0xcH2MXNAwimLUQf+AP+B14Q9PrMill8jeCWxtSvaWa/JjjGMyYXhckpc Q0U4Qrs3mdzw6Ufpws7Emg3dctdjlCOodF5T7lkp5pNXsjl9BtrbQVCIEOQgKApq39RC G4wuSJRh42jIvJYbRmfRBrNvzfwGwKMF2c93tXzxrg12Q45YI2IRnmf4mW5NN+i3KUeO zI0w== 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=1Hd2qPr+QVbF+eT8TDZ6RItZhKEtbimLwchB3rYpk3Y=; b=5KxU3+Q91B4jsW7jatFyVOEtt8gA7dw4cUWvnVawpNDYezoEEm+ILvguDpF8XNjHWw 5MYthc3XyTj/QxdfHo3RanQr6aHWd1RQ7/68N3o4KN4maOYDckZfgWCnmkczYURMw4Xc yUCO1Xl2g6sxQnQixJjpQ88KCjPUNO5qvgf99JGxQlBkke9YCNUBvjsfqFvBXOTQVjii SyrcchJ0SZRy+1nPkzDuZv41U1MRT6VwcriTuU0xRgHYgKeq9KQAe4cacmgoG4oJJjXn gjhTTsgfNqrBxNYnDQgmHopfi+kps3RuGbIXYUkwV1eAfo4qzIpkqv/qAjI7AcJCujcb yVOQ== X-Gm-Message-State: ACgBeo1WqDJI3N9rwp3xVNBNfVvCErmEaLQmqdMQmYzVjRUq5HTcjyBw DRC3KgUkyA8tru9Qz/g3OXhQSHveAtlTte29 X-Google-Smtp-Source: AA6agR74h5hoHNvicMvCVPdYJFePH87zef5STx6boBThom4VJdbVtaWf6dE24uQWqDFxHb94FDSi5A== X-Received: by 2002:a05:6a00:1388:b0:53e:6456:99a2 with SMTP id t8-20020a056a00138800b0053e645699a2mr12770pfg.43.1662484190045; Tue, 06 Sep 2022 10:09:50 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id b17-20020a170903229100b00176be258f41sm3806567plh.91.2022.09.06.10.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 10:09:49 -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 , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel , Sunil V L Subject: [RFC PATCH 13/17] MdePkg: Add PlatformPeiLib library Date: Tue, 6 Sep 2022 22:38:33 +0530 Message-Id: <20220906170837.491525-14-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906170837.491525-1-sunilvl@ventanamicro.com> References: <20220906170837.491525-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/Include/Library/PlatformPeiLib.h | 15 ++++ .../Library/PlatformPeiLib/PlatformPeiLib.inf | 40 +++++++++++ .../PlatformPeiLib/RiscV64/PlatformPeiLib.c | 68 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 MdePkg/Include/Library/PlatformPeiLib.h create mode 100644 MdePkg/Library/PlatformPeiLib/PlatformPeiLib.inf create mode 100644 MdePkg/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c diff --git a/MdePkg/Include/Library/PlatformPeiLib.h b/MdePkg/Include/Libra= ry/PlatformPeiLib.h new file mode 100644 index 0000000000..1e8c5f98cf --- /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/PlatformPeiLib.inf b/MdePkg/Libr= ary/PlatformPeiLib/PlatformPeiLib.inf new file mode 100644 index 0000000000..d682b3c0f9 --- /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/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c b/MdePk= g/Library/PlatformPeiLib/RiscV64/PlatformPeiLib.c new file mode 100644 index 0000000000..e62aa26df9 --- /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