From nobody Mon Sep 16 19:17:12 2024 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+113978+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+113978+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=marvell.com ARC-Seal: i=1; a=rsa-sha256; t=1705540733; cv=none; d=zohomail.com; s=zohoarc; b=UMrWINSbh0QUQDFe749wLhCj64q1uqJDEzIhzCpoqSKsw4NDUVzTFIuYdHkVJjjuu0IDRBVY4r7aR6SQwnk6MFm3ZKPKWXmbgMdfyWQE6c00fpz0vWGueqZf/jtXaGx8ZKCtyL2WX5Zol7yFXbEFK0hJFfJjjzmp7aOrYiEgOq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705540733; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=zHBBkcTd4F5eVz5ZYv9iQDS9tJiQQkZWrl7v/V7Rzio=; b=ExkO8O6/68VXp2lSoFO2PxosDL9B70s/fEoQKKmrHVMv1f7xfdBLugNXnS28vbP8q5V0aol2L3gN9PHMzR7BE2Ccbt9Z+GHK43SUi0WtXhnJ8S+SmUJCcsldpJ4PHUIKJtpBsiAqPtc+Pz0DJ7JTiPY32hqy/pljQbDYXvEjckQ= 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+113978+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705540733131220.18549634751548; Wed, 17 Jan 2024 17:18:53 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5ylUcbcXb1Fji5T/btcYs/AlcUCuP1RWxyb0ls1lEHs=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705540732; v=1; b=IuImDJEKdNKIBHNzj9P0BDQSJMFKcMge3oPe/ZA0Lsr7Ti91kyPl3B3LGLN8+j7Loi0f+07b Gg0hTxyemtA5zyjR8Ih72ZJynLmagrU7fkeb7xS9FX+6I80gwQ9zsXaIGCUPMAgxiuyJJw5Znig SNiWKSerJUfHHQl7VrjD6Y7w= X-Received: by 127.0.0.2 with SMTP id deoZYY1788612xBZS0LjgcOe; Wed, 17 Jan 2024 17:18:52 -0800 X-Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.148.174]) by mx.groups.io with SMTP id smtpd.web11.936.1705540731926646491 for ; Wed, 17 Jan 2024 17:18:51 -0800 X-Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40HHGq0R008637; Wed, 17 Jan 2024 17:18:51 -0800 X-Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3vpaskb4st-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 17 Jan 2024 17:18:51 -0800 (PST) X-Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 17 Jan 2024 17:18:49 -0800 X-Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 17 Jan 2024 17:18:28 -0800 X-Received: from MRVL-5Lp9he46Ey.marvell.com (unknown [10.85.176.100]) by maili.marvell.com (Postfix) with ESMTP id 377E43F7081; Wed, 17 Jan 2024 17:18:28 -0800 (PST) From: "Narinder Dhillon" To: CC: , , , Narinder Dhillon Subject: [edk2-devel] [edk2-platforms PATCH v3 5/7] Silicon/Marvell: Driver to publish device tree Date: Wed, 17 Jan 2024 17:18:15 -0800 Message-ID: <20240118011817.4348-6-ndhillon@marvell.com> In-Reply-To: <20240118011817.4348-1-ndhillon@marvell.com> References: <20240118011817.4348-1-ndhillon@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 6etvcSQPhq5U763oIdd0TDNhl3TMjX7W X-Proofpoint-GUID: 6etvcSQPhq5U763oIdd0TDNhl3TMjX7W Precedence: Bulk 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,ndhillon@marvell.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 85i8CX2EeIBTQ8r9n7wwQymLx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705540734866100002 Content-Type: text/plain; charset="utf-8" From: Narinder Dhillon This patch adds driver that can provide device tree to OS if user so wishes. PCD's are used to enable this, default is not to take this action. Signed-off-by: Narinder Dhillon --- .../Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c | 259 ++++++++++++++++++ .../Fdt/FdtPlatformDxe/FdtPlatformDxe.inf | 49 ++++ .../MarvellSiliconPkg/MarvellSiliconPkg.dec | 20 ++ 3 files changed, 328 insertions(+) create mode 100644 Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c create mode 100644 Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatformD= xe.inf diff --git a/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c b/Sil= icon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c new file mode 100644 index 0000000000..cc3b853dff --- /dev/null +++ b/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c @@ -0,0 +1,259 @@ +/** @file + + SPDX-License-Identifier: BSD-2-Clause-Patent + https://spdx.org/licenses + + Copyright (C) 2023 Marvell + + Copyright (c) 2015, ARM Ltd. All rights reserved.
+ +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +// +// Internal variables +// + +VOID *mFdtBlobBase; + +EFI_STATUS +DeleteFdtNode ( + IN VOID *FdtAddr, + CONST CHAR8 *NodePath, + CONST CHAR8 *Compatible +) +{ + INTN Offset =3D -1; + INTN Return; + + if ((NodePath !=3D NULL) && (Compatible !=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (NodePath !=3D NULL) { + Offset =3D fdt_path_offset (FdtAddr, NodePath); + + DEBUG ((DEBUG_INFO, "Offset: %d\n", Offset)); + + if (Offset < 0) { + DEBUG ((DEBUG_ERROR, "Error getting the device node %a offset: %a\n", + NodePath, fdt_strerror (Offset))); + return EFI_NOT_FOUND; + } + } + + if (Compatible !=3D NULL) { + Offset =3D fdt_node_offset_by_compatible (FdtAddr, -1, Compatible); + + DEBUG ((DEBUG_INFO, "Offset: %d\n", Offset)); + + if (Offset < 0) { + DEBUG ((DEBUG_ERROR, "Error getting the device node for %a offset: %= a\n", + Compatible, fdt_strerror (Offset))); + return EFI_NOT_FOUND; + } + } + + if (Offset >=3D 0) { + Return =3D fdt_del_node (FdtAddr, Offset); + + DEBUG ((DEBUG_INFO, "Return: %d\n", Return)); + + if (Return < 0) { + DEBUG ((DEBUG_ERROR, "Error deleting the device node %a: %a\n", + NodePath, fdt_strerror (Return))); + return EFI_NOT_FOUND; + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +DeleteRtcNode ( + IN VOID *FdtAddr + ) +{ + INT32 Offset, NameLen, Return; + BOOLEAN Found; + CONST CHAR8 *Name; + + Found =3D FALSE; + for (Offset =3D fdt_next_node(FdtAddr, 0, NULL); + Offset >=3D 0; + Offset =3D fdt_next_node(FdtAddr, Offset, NULL)) { + + Name =3D fdt_get_name(FdtAddr, Offset, &NameLen); + if (!Name) { + continue; + } + + if ((Name[0] =3D=3D 'r') && (Name[1] =3D=3D 't') && (Name[2] =3D=3D 'c= ')) { + Found =3D TRUE; + break; + } + } + + if (Found =3D=3D TRUE) { + Return =3D fdt_del_node (FdtAddr, Offset); + + if (Return < 0) { + DEBUG ((DEBUG_ERROR, "Error deleting the device node %a\n", Name)); + return EFI_NOT_FOUND; + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +FdtFixup( + IN VOID *FdtAddr + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + + if (FeaturePcdGet(PcdFixupFdt)) { + Status |=3D DeleteFdtNode (FdtAddr, (CHAR8*)PcdGetPtr (PcdFdtConfigRoo= tNode), NULL); + + // Hide the RTC + Status |=3D DeleteRtcNode (FdtAddr); + } + + if (!EFI_ERROR(Status)) { + fdt_pack(FdtAddr); + } + + return EFI_SUCCESS; +} + + +/** + Install the FDT specified by its device path in text form. + + @retval EFI_SUCCESS The FDT was installed. + @retval EFI_NOT_FOUND Failed to locate a protocol or a file. + @retval EFI_INVALID_PARAMETER Invalid device path. + @retval EFI_UNSUPPORTED Device path not supported. + @retval EFI_OUT_OF_RESOURCES An allocation failed. +**/ +STATIC +EFI_STATUS +InstallFdt ( + VOID +) +{ + EFI_STATUS Status; + UINTN FdtBlobSize; + VOID *FdtConfigurationTableBase; + VOID *HobList; + EFI_HOB_GUID_TYPE *GuidHob; + + // + // Get the HOB list. If it is not present, then ASSERT. + // + HobList =3D GetHobList (); + ASSERT (HobList !=3D NULL); + + // + // Search for FDT GUID HOB. If it is not present, then + // there's nothing we can do. It may not exist on the update path. + // + GuidHob =3D GetNextGuidHob (&gFdtHobGuid, HobList); + if (GuidHob !=3D NULL) { + mFdtBlobBase =3D (VOID *)*(UINT64 *)(GET_GUID_HOB_DATA (GuidHob)); + FdtBlobSize =3D fdt_totalsize((VOID *)mFdtBlobBase); + + // + // Ensure that the FDT header is valid and that the Size of the Device= Tree + // is smaller than the size of the read file + // + if (fdt_check_header (mFdtBlobBase)) { + DEBUG ((DEBUG_ERROR, "InstallFdt() - FDT blob seems to be corrupt\= n")); + mFdtBlobBase =3D NULL; + Status =3D EFI_LOAD_ERROR; + goto Error; + } + } else { + Status =3D EFI_NOT_FOUND; + goto Error; + } + + Status =3D EFI_SUCCESS; + + if (FeaturePcdGet(PcdPublishFdt)) { + FdtConfigurationTableBase =3D AllocateRuntimeCopyPool (FdtBlobSize, mF= dtBlobBase); + + if (FdtConfigurationTableBase =3D=3D NULL) { + goto Error; + } + + Status =3D FdtFixup((VOID*)FdtConfigurationTableBase); + + if (EFI_ERROR (Status)) { + FreePool (FdtConfigurationTableBase); + goto Error; + } + + // + // Install the FDT into the Configuration Table + // + Status =3D gBS->InstallConfigurationTable ( + &gFdtTableGuid, + FdtConfigurationTableBase + ); + + if (EFI_ERROR (Status)) { + FreePool (FdtConfigurationTableBase); + } + } + +Error: + return Status; +} + +/** + Main entry point of the FDT platform driver. + + @param[in] ImageHandle The firmware allocated handle for the present = driver + UEFI image. + @param[in] *SystemTable A pointer to the EFI System table. + + @retval EFI_SUCCESS The driver was initialized. + @retval EFI_OUT_OF_RESOURCES The "End of DXE" event could not be alloc= ated or + there was not enough memory in pool to in= stall + the Shell Dynamic Command protocol. + @retval EFI_LOAD_ERROR Unable to add the HII package. + +**/ +EFI_STATUS +FdtPlatformEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Install the Device Tree from its expected location + // + Status =3D InstallFdt (); + + ASSERT_EFI_ERROR(Status); + + return Status; +} diff --git a/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatformDxe.inf = b/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatformDxe.inf new file mode 100644 index 0000000000..4e254f17cb --- /dev/null +++ b/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatformDxe.inf @@ -0,0 +1,49 @@ +#/** @file +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# https://spdx.org/licenses +# +# Copyright (C) 2023 Marvell +# +# Copyright (c) 2015, ARM Ltd. All rights reserved.
+# +#**/ + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D FdtPlatformDxe + FILE_GUID =3D 6e9a4c69-57c6-4fcd-b083-4f2c3bdb6051 + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 0.1 + ENTRY_POINT =3D FdtPlatformEntryPoint + +[Sources.common] + FdtPlatform.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/ARM/ARM.dec + Silicon/Marvell/MarvellSiliconPkg/MarvellSiliconPkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + BaseMemoryLib + DebugLib + FdtLib + HobLib + +[Guids] + gFdtHobGuid + gFdtTableGuid + +[FeaturePcd] + gMarvellSiliconTokenSpaceGuid.PcdPublishFdt + gMarvellSiliconTokenSpaceGuid.PcdFixupFdt + +[FixedPcd] + gMarvellSiliconTokenSpaceGuid.PcdFdtConfigRootNode + +[Depex] + TRUE diff --git a/Silicon/Marvell/MarvellSiliconPkg/MarvellSiliconPkg.dec b/Sili= con/Marvell/MarvellSiliconPkg/MarvellSiliconPkg.dec index 1e17152f13..d3106f0c5d 100644 --- a/Silicon/Marvell/MarvellSiliconPkg/MarvellSiliconPkg.dec +++ b/Silicon/Marvell/MarvellSiliconPkg/MarvellSiliconPkg.dec @@ -28,6 +28,7 @@ gShellEepromHiiGuid =3D { 0xb2f4c714, 0x147f, 0x4ff7, { 0x82, 0x1b, 0xce= , 0x7b, 0x91, 0x7f, 0x5f, 0x2f } } gShellFUpdateHiiGuid =3D { 0x9b5d2176, 0x590a, 0x49db, { 0x89, 0x5d, 0x4= a, 0x70, 0xfe, 0xad, 0xbe, 0x24 } } gShellSfHiiGuid =3D { 0x03a67756, 0x8cde, 0x4638, { 0x82, 0x34, 0x4a, 0x= 0f, 0x6d, 0x58, 0x81, 0x39 } } + gShellDumpFdtHiiGuid =3D { 0x8afa7610, 0x62b1, 0x46aa, { 0xb5, 0x34, 0xc= 3, 0xde, 0xff, 0x39, 0x77, 0x8c } } =20 [LibraryClasses] ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h @@ -42,6 +43,8 @@ # that depend on the lowlevel platform initialization having been comple= ted gMarvellPlatformInitCompleteProtocolGuid =3D { 0x465b8cf7, 0x016f, 0x4ba= 6, { 0xbe, 0x6b, 0x28, 0x0e, 0x3a, 0x7d, 0x38, 0x6f } } =20 + gMrvlFdtClientProtocolGuid =3D { 0xE11FACA0, 0x4710, 0x4C8E, { 0xA7, 0xA= 2, 0x01, 0xBA, 0xA2, 0x59, 0x1B, 0x4C } } + [PcdsFixedAtBuild.common] #Board description gMarvellSiliconTokenSpaceGuid.PcdMaxCpCount|0x2|UINT8|0x30000072 @@ -198,6 +201,23 @@ gMarvellSiliconTokenSpaceGuid.PcdOpTeeRegionBase|0x0|UINT64|0x50000004 gMarvellSiliconTokenSpaceGuid.PcdOpTeeRegionSize|0x0|UINT32|0x50000005 =20 +# FDT + # FDT configuration node to be stripped before passing to OS + gMarvellSiliconTokenSpaceGuid.PcdFdtConfigRootNode|"/marvell,ebf"|VOID*|= 0x50000090 + + gMarvellSiliconTokenSpaceGuid.PcdNodeDramBase|0x10000000000|UINT64|0x000= 00004 + gMarvellSiliconTokenSpaceGuid.PcdIoBaseAddress|0x800000000000|UINT64|0x0= 0000005 + gMarvellSiliconTokenSpaceGuid.PcdNodeIoBaseAddress|0x100000000000|UINT64= |0x00000006 + gMarvellSiliconTokenSpaceGuid.PcdIoSize|0xF0000000000|UINT64|0x00000007 + + gMarvellSiliconTokenSpaceGuid.PcdGtiWatchdogBase64|0x802000000000|UINT64= |0x00000008 + +[PcdsFeatureFlag.common] + # Publish FDT to the OS as Configuration Table with gFdtTableGuid + gMarvellSiliconTokenSpaceGuid.PcdPublishFdt|FALSE|BOOLEAN|0x50000091 + # Fixup the FDT or not (taken into consideration only when PcdPublishFdt= =3D TRUE) + gMarvellSiliconTokenSpaceGuid.PcdFixupFdt|TRUE|BOOLEAN|0x50000092 + [Protocols] gMarvellBoardDescProtocolGuid =3D { 0xebed8738, 0xd4a6, 0x400= 1, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }} gMarvellEepromProtocolGuid =3D { 0x71954bda, 0x60d3, 0x4ef= 8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }} --=20 2.34.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 (#113978): https://edk2.groups.io/g/devel/message/113978 Mute This Topic: https://groups.io/mt/103800162/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-