From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=nNHtMOKU; spf=pass (domain: ventanamicro.com, ip: 209.85.214.178, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pl1-f178.google.com with SMTP id jm11so14179037plb.13 for ; Wed, 07 Sep 2022 04:37:39 -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=KP7E32ed9ZMeqUG5F5SvhqByC448YgXo4JAVfNaPnRk=; b=nNHtMOKU0K4i3agdUle5qsmn8g0TuhRqxQw7B06bAO/kjPUnvkMG6itkR8htgRZczR jL+I42B3LJ4SYXJIHhmGJtBuHz0y8nSDQnaP5dJkHz6zBwc2iTqauZ53BXFq0AgV+AKO FoPFKowpzGXuxAiQQXR4UEHjgTbPJAke4pSstxcKmcFCDwGsld6NOJywFReQE9ZjXvX8 YZ/5gzAd0mVLH0GdSCK064O3pkU+pAeCYsQkDg/Y5XuYuoCbuxL1CNEDJQuly52oxP0N OvzIdMPZxNqYQvomKRAifR5gmq/lwoVGtsfwQUjAFrrOC41ea7rQz4REoaNIUFQTlpWR V6EA== 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=KP7E32ed9ZMeqUG5F5SvhqByC448YgXo4JAVfNaPnRk=; b=XanYK9xGaNCX28R2z9ABNdUQBeefRPLoHo3Tu8oBV8INw8gDJBwSvxaxKC5ED61QHJ ZmmoUFcRwx1s3763kX3aII4fBh4yZ2vUfemGUSAJ/5zLYN3cUPzll/Rwx8ROgvsyjG0U qjymRzLhIfqkHEAcszjg964CSKiICZpuFfBaMw8BhWTqD9T0tp/zUoXPp1ca2kLZGOTu L5X2lhKA63ZsJkQQL36r6eDYMHrin6e6BFQMuEhrk2bN0BMnqfOVeCVfGcmXOAjqXDDK q0yXFTwWtClDP9fdC7zwd/tdFu0gGxWRpwZT98ewz+l9bSnRzyVrWQa2hIxNLyvYZgOr b6vg== X-Gm-Message-State: ACgBeo1LFeacrnz9OP7nYkGYJMydUFzYuLbcZSGDeDi6lgYGwNDwhbVh LschODHIxRAMZWPtETncNeD04bd2N9ifodxn 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907113626.540065-1-sunilvl@ventanamicro.com> References: <20220907113626.540065-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/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.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# 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.
+ 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/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.
+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 = 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