From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id A8941D811AC for ; Fri, 8 Mar 2024 15:57:51 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Y7/ZKpDhXvDH/ldvmybRp3O4eW0QnyA6mfjE0BGQil0=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From:In-Reply-To:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Language; s=20240206; t=1709913470; v=1; b=BKYTVF5jLAYu/VUc0mreREUzbUEOBlR4TplfqUf2ZxsEgaGZ0M1NkOsOlOxHLTu7Xr8o6hro iNUq3ocDylq1FF6slU9OKdSgJogJv/9iQjp0Dv5e1U4PeCXtaVeau4PnUMqAIPp4MgVMGlOiJfh F5O+AfGetmB34IDd0sp0keyRpeNGbHzPGzX//7PT8cJXHZ6UU69UyyQpjFK7A7omVuq9ro/LRSk R3Qo5Nc2/s23dDEIED9cN54puaTgXpVYy2DYIG3peYJ+pmTYy8vqValhFXujtlx3cvhPkLQfOHN xHhiYoHuarnb1SpL93kTAbTK7oBAb/tHuYc4BcMGtxYVw== X-Received: by 127.0.0.2 with SMTP id W00hYY7687511x3kZv7hnjcS; Fri, 08 Mar 2024 07:57:50 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.54]) by mx.groups.io with SMTP id smtpd.web10.25448.1709913469495494463 for ; Fri, 08 Mar 2024 07:57:49 -0800 X-Received: from IA1PR12MB6458.namprd12.prod.outlook.com (2603:10b6:208:3aa::22) by SA1PR12MB8723.namprd12.prod.outlook.com (2603:10b6:806:385::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:57:47 +0000 X-Received: from IA1PR12MB6458.namprd12.prod.outlook.com ([fe80::b913:7732:22e1:b71e]) by IA1PR12MB6458.namprd12.prod.outlook.com ([fe80::b913:7732:22e1:b71e%7]) with mapi id 15.20.7362.029; Fri, 8 Mar 2024 15:57:47 +0000 Message-ID: Date: Fri, 08 Mar 2024 07:57:49 -0800 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [edk2-platforms PATCH v3 5/7] Silicon/Marvell: Driver to publish device tree To: devel@edk2.groups.io, ndhillon@marvell.com Cc: quic_llindhol@quicinc.com, mw@semihalf.com, sbalcerak@marvell.com References: <20240118011817.4348-1-ndhillon@marvell.com> <20240118011817.4348-6-ndhillon@marvell.com> From: "Abdul Lateef Attar via groups.io" In-Reply-To: <20240118011817.4348-6-ndhillon@marvell.com> X-ClientProxiedBy: PN2PR01CA0235.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:eb::13) To IA1PR12MB6458.namprd12.prod.outlook.com (2603:10b6:208:3aa::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA1PR12MB6458:EE_|SA1PR12MB8723:EE_ X-MS-Office365-Filtering-Correlation-Id: e599797d-6158-49b9-bbdf-08dc3f887f75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: /IssQRYjLLTksFp9/YsSbLaV4Q0QsJAStk46xfjcAcJn84TV4WQV9vU0GSlovOjvAdCryU75NRcnmzqD3l7vyQqgPGO8Qdp9HWjfw0WBg2ok3hGgyjfXEYrFUD4pP4DUXZq2OxLna952t8vWyNkdpxGH+aGUNLaS//rKfw8jVRQB0xxvLrurxwJrfliTRYEQus9j4jBswkyMto0ZIMb7Y1WO3XzAwpW3ZwiLVfSS+uxjR4sL1WnzQyff9SCoDKhHGYdnqTSjzf3HA4p7ZdECliCOGUe2CPuEid9LeseAvoOxFgCh5FURbAVcE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ENmZ1RnRjRRTlNpMERR?= =?utf-8?B?K01DZ0xBR2huYjRnVUtkSEhTMldEQk9KYzRHSHpXQkRCZ1N5Q2UyVGNLU0N2?= =?utf-8?B?TGtsTk9yYUkwSWc0SE5uaHg0c2FoM0RkUzYyeDEzVUE2WEhJaXRGbXlTVHVk?= =?utf-8?B?UmZsYzdUQ2QxUHkwLzV0cTd0MExrc3c0WERDWEdjUTFMQzFOZGdmN09NNDJR?= =?utf-8?B?ZExiQ3NWTVF2bDJoTFJCb0ZFdU5JOWVZS2ZBY2ZKM3J5cHViOTdaajgxeFk3?= =?utf-8?B?cCtlM2ppY24wNEhJaDN6endHdzVwamUzaWZLRnkyTTd1OU5LZloyZVRnRmE5?= =?utf-8?B?WFJ3NDZWL0FvWHhWdVB2M0hWeHlXb1Rnc1ZqcVRYUEU4UFZCcDR6Uy92eUhL?= =?utf-8?B?VkQ4eHhFMWxmbGFTckNxd0VHR3QrYWRFOG5jU1doY25XYXFBMk5JMytMSEhM?= =?utf-8?B?SHk3cTRUc0dHb0gxV2h2T1doZmZqR2dodDNqWC9OUlNZc0N4TFJxb0lTcXg5?= =?utf-8?B?N3JuQ3I5YnJTUmcyaWpGTzRPOStBVEh3TEFnZmphUFFtUUNCajRpN3pqTUZo?= =?utf-8?B?VEhYZkhtQmtRa01ablEvNlpUdTJtU1ljL29KWkx1aFdad1B5c2tEdVNaUUk4?= =?utf-8?Q?g5LrgBxlihLWvHShiWDese9Pg?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e599797d-6158-49b9-bbdf-08dc3f887f75 X-MS-Exchange-CrossTenant-AuthSource: IA1PR12MB6458.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:57:46.9309 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GQLDKLiMKCTDL3w3BHIs5gB9s3YbsmPGPdoXrwnaccckm/RAsiVlyv9+J8D4U6M29xWOvKwopugBslQDXiB9Lw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8723 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,AbdulLateef.Attar@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: eLRGpBwuRI0JYBgQun4ykF9Cx7686176AA= Content-Type: multipart/alternative; boundary="------------kxOaRuRScpjUzcRkT680lfqs" Content-Language: en-US X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=BKYTVF5j; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=pass (policy=none) header.from=groups.io --------------kxOaRuRScpjUzcRkT680lfqs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Narinder,     Patch looks good with minor comment inline. Thanks AbduL On 18-01-2024 06:48, Narinder Dhillon via groups.io wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > 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/FdtPlatformDxe.inf > > diff --git a/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c b/Silicon/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 = -1; > + INTN Return; > + > + if ((NodePath != NULL) && (Compatible != NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (NodePath != NULL) { > + Offset = 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 != NULL) { > + Offset = 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 >= 0) { > + Return = 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 = FALSE; > + for (Offset = fdt_next_node(FdtAddr, 0, NULL); > + Offset >= 0; > + Offset = fdt_next_node(FdtAddr, Offset, NULL)) { > + > + Name = fdt_get_name(FdtAddr, Offset, &NameLen); > + if (!Name) { > + continue; > + } > + > + if ((Name[0] == 'r') && (Name[1] == 't') && (Name[2] == 'c')) { > + Found = TRUE; > + break; > + } > + } > + > + if (Found == TRUE) { > + Return = 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 = EFI_SUCCESS; > + > + if (FeaturePcdGet(PcdFixupFdt)) { > + Status |= DeleteFdtNode (FdtAddr, (CHAR8*)PcdGetPtr (PcdFdtConfigRootNode), NULL); > + > + // Hide the RTC > + Status |= 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 = GetHobList (); > + ASSERT (HobList != 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 = GetNextGuidHob (&gFdtHobGuid, HobList); > + if (GuidHob != NULL) { > + mFdtBlobBase = (VOID *)*(UINT64 *)(GET_GUID_HOB_DATA (GuidHob)); > + FdtBlobSize = 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 = NULL; > + Status = EFI_LOAD_ERROR; > + goto Error; > + } > + } else { > + Status = EFI_NOT_FOUND; > + goto Error; > + } > + > + Status = EFI_SUCCESS; > + > + if (FeaturePcdGet(PcdPublishFdt)) { > + FdtConfigurationTableBase = AllocateRuntimeCopyPool (FdtBlobSize, mFdtBlobBase); > + > + if (FdtConfigurationTableBase == NULL) { > + goto Error; > + } > + > + Status = FdtFixup((VOID*)FdtConfigurationTableBase); > + > + if (EFI_ERROR (Status)) { > + FreePool (FdtConfigurationTableBase); > + goto Error; > + } > + > + // > + // Install the FDT into the Configuration Table > + // > + Status = 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 allocated or > + there was not enough memory in pool to install > + 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 > + // [Abdul] check the PCD for publishing the FDT instead of checking in InstallFdt() Table will be published only if the feature is enabled. if (FeaturePcdGet(PcdPublishFdt)) { InstallFdt (); } > + Status = 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 = 0x00010006 > + BASE_NAME = FdtPlatformDxe > + FILE_GUID = 6e9a4c69-57c6-4fcd-b083-4f2c3bdb6051 > + MODULE_TYPE = UEFI_DRIVER > + VERSION_STRING = 0.1 > + ENTRY_POINT = 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/Silicon/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 = { 0xb2f4c714, 0x147f, 0x4ff7, { 0x82, 0x1b, 0xce, 0x7b, 0x91, 0x7f, 0x5f, 0x2f } } > gShellFUpdateHiiGuid = { 0x9b5d2176, 0x590a, 0x49db, { 0x89, 0x5d, 0x4a, 0x70, 0xfe, 0xad, 0xbe, 0x24 } } > gShellSfHiiGuid = { 0x03a67756, 0x8cde, 0x4638, { 0x82, 0x34, 0x4a, 0x0f, 0x6d, 0x58, 0x81, 0x39 } } > + gShellDumpFdtHiiGuid = { 0x8afa7610, 0x62b1, 0x46aa, { 0xb5, 0x34, 0xc3, 0xde, 0xff, 0x39, 0x77, 0x8c } } > > [LibraryClasses] > ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h > @@ -42,6 +43,8 @@ > # that depend on the lowlevel platform initialization having been completed > gMarvellPlatformInitCompleteProtocolGuid = { 0x465b8cf7, 0x016f, 0x4ba6, { 0xbe, 0x6b, 0x28, 0x0e, 0x3a, 0x7d, 0x38, 0x6f } } > > + gMrvlFdtClientProtocolGuid = { 0xE11FACA0, 0x4710, 0x4C8E, { 0xA7, 0xA2, 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 > > +# FDT > + # FDT configuration node to be stripped before passing to OS > + gMarvellSiliconTokenSpaceGuid.PcdFdtConfigRootNode|"/marvell,ebf"|VOID*|0x50000090 > + > + gMarvellSiliconTokenSpaceGuid.PcdNodeDramBase|0x10000000000|UINT64|0x00000004 > + gMarvellSiliconTokenSpaceGuid.PcdIoBaseAddress|0x800000000000|UINT64|0x00000005 > + 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 = TRUE) > + gMarvellSiliconTokenSpaceGuid.PcdFixupFdt|TRUE|BOOLEAN|0x50000092 > + > [Protocols] > gMarvellBoardDescProtocolGuid = { 0xebed8738, 0xd4a6, 0x4001, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }} > gMarvellEepromProtocolGuid = { 0x71954bda, 0x60d3, 0x4ef8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }} > -- > 2.34.1 > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116550): https://edk2.groups.io/g/devel/message/116550 Mute This Topic: https://groups.io/mt/103800162/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- --------------kxOaRuRScpjUzcRkT680lfqs Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hi Narinder,
    Patch looks good with minor comment inline.
Thanks
AbduL
   
On 18-01-2024 06:48, Narinder Dhillon via groups.io wrote:
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


From: Narinder Dhillon <ndhillon@marvell.com>

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 <ndhillon@marvell.com>
---
 .../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/FdtPlatformDxe.inf

diff --git a/Silicon/Marvell/Drivers/Fdt/FdtPlatformDxe/FdtPlatform.c b/Silicon/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.<BR>
+
+**/
+
+#include <Uefi.h>
+#include <Library/PcdLib.h>
+#include <Library/BdsLib.h>
+#include <Pi/PiBootMode.h>
+#include <Pi/PiHob.h>
+#include <Library/HobLib.h>
+#include <Library/HiiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Guid/FdtHob.h>
+#include <libfdt.h>
+
+//
+// Internal variables
+//
+
+VOID       *mFdtBlobBase;
+
+EFI_STATUS
+DeleteFdtNode (
+  IN  VOID    *FdtAddr,
+  CONST CHAR8 *NodePath,
+  CONST CHAR8 *Compatible
+)
+{
+  INTN        Offset = -1;
+  INTN        Return;
+
+  if ((NodePath != NULL) && (Compatible != NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (NodePath != NULL) {
+    Offset = 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 != NULL) {
+    Offset = 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 >= 0) {
+    Return = 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 = FALSE;
+  for (Offset = fdt_next_node(FdtAddr, 0, NULL);
+    Offset >= 0;
+    Offset = fdt_next_node(FdtAddr, Offset, NULL)) {
+
+    Name = fdt_get_name(FdtAddr, Offset, &NameLen);
+    if (!Name) {
+      continue;
+    }
+
+    if ((Name[0] == 'r') && (Name[1] == 't') && (Name[2] == 'c')) {
+      Found = TRUE;
+      break;
+    }
+  }
+
+  if (Found == TRUE) {
+    Return = 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 = EFI_SUCCESS;
+
+  if (FeaturePcdGet(PcdFixupFdt)) {
+    Status |= DeleteFdtNode (FdtAddr, (CHAR8*)PcdGetPtr (PcdFdtConfigRootNode), NULL);
+
+    // Hide the RTC
+    Status |= 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 = GetHobList ();
+  ASSERT (HobList != 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 = GetNextGuidHob (&gFdtHobGuid, HobList);
+  if (GuidHob != NULL) {
+    mFdtBlobBase = (VOID *)*(UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
+    FdtBlobSize = 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 = NULL;
+        Status = EFI_LOAD_ERROR;
+        goto Error;
+    }
+  } else {
+    Status = EFI_NOT_FOUND;
+    goto Error;
+  }
+
+  Status = EFI_SUCCESS;
+
+  if (FeaturePcdGet(PcdPublishFdt)) {
+    FdtConfigurationTableBase = AllocateRuntimeCopyPool (FdtBlobSize, mFdtBlobBase);
+
+    if (FdtConfigurationTableBase == NULL) {
+        goto Error;
+    }
+
+    Status = FdtFixup((VOID*)FdtConfigurationTableBase);
+
+    if (EFI_ERROR (Status)) {
+      FreePool (FdtConfigurationTableBase);
+      goto Error;
+    }
+
+    //
+    // Install the FDT into the Configuration Table
+    //
+    Status = 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 allocated or
+                                 there was not enough memory in pool to install
+                                 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
+  //

[Abdul] check the PCD for publishing the FDT instead of checking in InstallFdt()

Table will be published only if the feature is enabled.

if (FeaturePcdGet(PcdPublishFdt)) {
	
 InstallFdt ();
}

+  Status = 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.<BR>
+#
+#**/
+
+[Defines]
+  INF_VERSION     = 0x00010006
+  BASE_NAME       = FdtPlatformDxe
+  FILE_GUID       = 6e9a4c69-57c6-4fcd-b083-4f2c3bdb6051
+  MODULE_TYPE     = UEFI_DRIVER
+  VERSION_STRING  = 0.1
+  ENTRY_POINT     = 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/Silicon/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 = { 0xb2f4c714, 0x147f, 0x4ff7, { 0x82, 0x1b, 0xce, 0x7b, 0x91, 0x7f, 0x5f, 0x2f } }
   gShellFUpdateHiiGuid = { 0x9b5d2176, 0x590a, 0x49db, { 0x89, 0x5d, 0x4a, 0x70, 0xfe, 0xad, 0xbe, 0x24 } }
   gShellSfHiiGuid = { 0x03a67756, 0x8cde, 0x4638, { 0x82, 0x34, 0x4a, 0x0f, 0x6d, 0x58, 0x81, 0x39 } }
+  gShellDumpFdtHiiGuid = { 0x8afa7610, 0x62b1, 0x46aa, { 0xb5, 0x34, 0xc3, 0xde, 0xff, 0x39, 0x77, 0x8c } }

 [LibraryClasses]
   ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h
@@ -42,6 +43,8 @@
   # that depend on the lowlevel platform initialization having been completed
   gMarvellPlatformInitCompleteProtocolGuid = { 0x465b8cf7, 0x016f, 0x4ba6, { 0xbe, 0x6b, 0x28, 0x0e, 0x3a, 0x7d, 0x38, 0x6f } }

+  gMrvlFdtClientProtocolGuid = { 0xE11FACA0, 0x4710, 0x4C8E, { 0xA7, 0xA2, 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

+# FDT
+  # FDT configuration node to be stripped before passing to OS
+  gMarvellSiliconTokenSpaceGuid.PcdFdtConfigRootNode|"/marvell,ebf"|VOID*|0x50000090
+
+  gMarvellSiliconTokenSpaceGuid.PcdNodeDramBase|0x10000000000|UINT64|0x00000004
+  gMarvellSiliconTokenSpaceGuid.PcdIoBaseAddress|0x800000000000|UINT64|0x00000005
+  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 = TRUE)
+  gMarvellSiliconTokenSpaceGuid.PcdFixupFdt|TRUE|BOOLEAN|0x50000092
+
 [Protocols]
   gMarvellBoardDescProtocolGuid            = { 0xebed8738, 0xd4a6, 0x4001, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }}
   gMarvellEepromProtocolGuid               = { 0x71954bda, 0x60d3, 0x4ef8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }}
--
2.34.1






_._,_._,_

Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#116550) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--------------kxOaRuRScpjUzcRkT680lfqs--