From nobody Thu Mar 28 21:22:25 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+83958+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+83958+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687359; cv=none; d=zohomail.com; s=zohoarc; b=GvWer0kYXadFjY3ioT50o+XLy8ZGsh+baWGDhEx7+fk7B/kCwr03f3DiSX+C4/L/K7kRcJBrBS6AjtpqUoQQZVih/XhDUtz5MNrSYeBCh1kbv0GvXNap4w7Dl8UEX9s14xOgDQThY664QHsOD8RxveqIIfZRXn8FJL93jgVK7aE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687359; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bamgygoMIU80LsBKpZNMwH0R20Bz1Y29UxnPoYm/d7o=; b=PeA56HrZy1w/iDpuAse/WTynb/JwsC9oJm3Gw//Xw4/6Ou5k8/WQX0EtQ/DAzlMJJitcpa7L7hZOEPmph/aCBqfZc3CVKJWjMAD57F+CpTGw2hiyvZm/0UKqmqrXulRwzVsgxq4CYBZTrdAdP6JMWCS79lrrJpyErSoiqG9sdaA= 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+83958+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 1637687359960490.758725833761; Tue, 23 Nov 2021 09:09:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 62MGYY1788612xWTmcGXq4xJ; Tue, 23 Nov 2021 09:09:17 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14273.1637687356359252930 for ; Tue, 23 Nov 2021 09:09:16 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 097D11063; Tue, 23 Nov 2021 09:09:16 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 18C7A3F5A1; Tue, 23 Nov 2021 09:09:14 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 01/15] DynamicTablesPkg: Definition for HwInfoParser interface Date: Tue, 23 Nov 2021 18:08:24 +0100 Message-Id: <20211123170838.143805-2-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: N3zClkS42ImM6rXABrJlZSlmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687357; bh=+/jDZfRWS4jtO4W5FYLndpCBNk5lw7jblriI700Ghd8=; h=Cc:Date:From:Reply-To:Subject:To; b=DaIoEL5ogdbFwJz93qzlI2ibz7E7WZRfSeaIB4icIhx1Ron3uEeMpe+KN6Y9qugbIyd gMXIh6XaF4qOUJ1+koBOnwzQfXM3CghyqD5ecdjo1VFFz78g9exPgQGfyKcAt3JPLdATg tlA70/nNL9ToYTKHOwVpq/JFcWAP6vUnnDo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687361656100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Hardware information parser is an optional module defined by the Dynamic Tables Framework. It can either parse an XML, a Device Tree or a Json file containing the platform hardware information to populate the platform information repository. The Configuration Manager can then utilise this information to generate ACPI tables for the platform. Therefore, define an interface for the HwInfoParser library class. Signed-off-by: Pierre Gondois Co-authored-by: Sami Mujawar --- DynamicTablesPkg/DynamicTablesPkg.dec | 3 + .../Include/Library/HwInfoParserLib.h | 99 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 DynamicTablesPkg/Include/Library/HwInfoParserLib.h diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/Dynam= icTablesPkg.dec index 9996bdf6f520..80a61dd2dbac 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dec +++ b/DynamicTablesPkg/DynamicTablesPkg.dec @@ -24,6 +24,9 @@ [LibraryClasses] ## @libraryclass Defines a set of APIs for Dynamic AML generation. AmlLib|Include/Library/AmlLib/AmlLib.h =20 + ## @libraryclass Defines a set of APIs to a hardware information parse= r. + HwInfoParserLib|Include/Library/HwInfoParserLib.h + ## @libraryclass Defines a set of methods for fixing up a SSDT Serial = Port. SsdtSerialPortFixupLib|Include/Library/SsdtSerialPortFixupLib.h =20 diff --git a/DynamicTablesPkg/Include/Library/HwInfoParserLib.h b/DynamicTa= blesPkg/Include/Library/HwInfoParserLib.h new file mode 100644 index 000000000000..472fbefcc6b5 --- /dev/null +++ b/DynamicTablesPkg/Include/Library/HwInfoParserLib.h @@ -0,0 +1,99 @@ +/** @file + Hardware information parser library. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef HW_INFO_PARSER_LIB_H_ +#define HW_INFO_PARSER_LIB_H_ + +#include + +/** A handle to the HwInfoParser instance. +*/ +typedef VOID * HW_INFO_PARSER_HANDLE; + +/** Function pointer called by the parser to add information. + + Callback function that the parser can use to add new + CmObj. This function must copy the CmObj data and not rely on + the parser preserving the CmObj memory. + This function is responsible of the Token allocation. + + @param [in] ParserHandle A handle to the parser instance. + @param [in] Context A pointer to the caller's context provided in + HwInfoParserInit (). + @param [in] CmObjDesc CM_OBJ_DESCRIPTOR containing the CmObj(s) to= add. + @param [out] Token If provided and success, contain the token + generated for the CmObj. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +typedef +EFI_STATUS +(EFIAPI * HW_INFO_ADD_OBJECT) ( + IN HW_INFO_PARSER_HANDLE ParserHandle, + IN VOID * Context, + IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc, + OUT CM_OBJECT_TOKEN * Token OPTIONAL + ); + +/** Initialise the HwInfoParser. + + The HwInfoParser shall use the information provided by the HwDataSource + to initialise the internal state of the parser or to index the data. This + internal state shall be linked to the ParserHandle using an implementati= on + defined mechanism. + + @param [in] HwDataSource Pointer to the blob containing the hardware + information. It can be a pointer to a Devi= ce + Tree, an XML file, etc. or any other data + structure defined by the HwInfoParser. + @param [in] Context A pointer to the caller's context. + @param [in] HwInfoAdd Function pointer called by the parser when + adding information. + @param [out] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +HwInfoParserInit ( + IN VOID * HwDataSource, + IN VOID * Context, + IN HW_INFO_ADD_OBJECT HwInfoAdd, + OUT HW_INFO_PARSER_HANDLE * ParserHandle + ); + +/** Parse the data provided by the HwDataSource. + + @param [in] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +HwInfoParse ( + IN HW_INFO_PARSER_HANDLE ParserHandle + ); + +/** Cleanup any internal state and resources that were allocated + by the the HwInfoParser. + + @param [in] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +HwInfoParserShutdown ( + IN HW_INFO_PARSER_HANDLE ParserHandle + ); + +#endif // HW_INFO_PARSER_LIB_H_ --=20 2.25.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 (#83958): https://edk2.groups.io/g/devel/message/83958 Mute This Topic: https://groups.io/mt/87263310/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- From nobody Thu Mar 28 21:22:25 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+83959+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+83959+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687362; cv=none; d=zohomail.com; s=zohoarc; b=esJmpBOB/glXNb2YegBAV3V+5H+QPEOd/PYeNh0jIx/za2nTlxwzvD++VTGIF7tV2eR3BgmxKQyvTwj+XsUHPJPIMvCEprT0q28zajmlskVCW9of+qugMbX67h7tGo+nJV/hMyXuzDk3dARkir5D7XbWv5wbBi6t6gPVmQPzJEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687362; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KvgUWO/Xi5LXAszEqDTBFyEHF1TblhM5UQPFQIgeeAo=; b=ao1tdHTXUieRcvZE/TKoY9gvVzi4rTy1ubYcER1URRRksSGRnHTLi/R6KEa5CJYt2+EmxMnvhRaIjXMTB5mWIOBpdl1IkW+kcHrfiq2BtEOG+lUsVba8UEHkSmIT1esjQkwlqr5Ad/AHfCEwpzkJzw/vFO2u0gJ0QVMAyGD6E9E= 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+83959+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 1637687362880299.36244248496564; Tue, 23 Nov 2021 09:09:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id f5WGYY1788612xVOCwLLOWYc; Tue, 23 Nov 2021 09:09:20 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.14101.1637687358044144388 for ; Tue, 23 Nov 2021 09:09:18 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A89041FB; Tue, 23 Nov 2021 09:09:17 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6AE6A3F5A1; Tue, 23 Nov 2021 09:09:16 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 02/15] DynamicTablesPkg: FdtHwInfoParser: CM Object descriptor helper Date: Tue, 23 Nov 2021 18:08:25 +0100 Message-Id: <20211123170838.143805-3-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: pUg3hMN9c5dNxq7atak7LA4zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687360; bh=ckd5VZHKCsLvnc/6ghQDKYceAwVChHvju7kNet55JVo=; h=Cc:Date:From:Reply-To:Subject:To; b=I38xlJ3eSic+JLqTKe/MvBmLigNh+oHygIoz8oVyw1VZ7gNXetcGAP/bMHwwUimNBgY riXy5HCnfRMypRHPUu9qWPfhRZDz4x7pX5nJEm6yG+MUfflAOwuS02zE/a7ZcI7YrkLrU Guv3xkx5JuxN93EgMeFuhpefE1y8kcBowfw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687364542100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois FdtHwInfoParserLib is an instance of the HwInfoParser. The FdtHwInfoParser parses a platform Device Tree and populates the Platform Information repository with Configuration Manager objects that describe the platform hardware. These Configuration Manager objects are encapsulated in Configuration Manager Object Descriptors. Therefore, add helper functions to create and free the Configuration Manager Object descriptors. Signed-off-by: Pierre Gondois --- .../FdtHwInfoParserLib/CmObjectDescUtility.c | 302 ++++++++++++++++++ .../FdtHwInfoParserLib/CmObjectDescUtility.h | 131 ++++++++ 2 files changed, 433 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDes= cUtility.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDes= cUtility.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtilit= y.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.c new file mode 100644 index 000000000000..d54256df8e83 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.c @@ -0,0 +1,302 @@ +/** @file + Configuration manager Object Descriptor Utility. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +#include "CmObjectDescUtility.h" + +/** Create a CM_OBJ_DESCRIPTOR. + + @param [in] ObjectId CM_OBJECT_ID of the node. + @param [in] Count Number of CmObj stored in the + data field. + @param [in] Data Pointer to one or more CmObj objects. + The content of this Data buffer is copied. + @param [in] Size Size of the Data buffer. + @param [out] NewCmObjDesc The created CM_OBJ_DESCRIPTOR. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +CreateCmObjDesc ( + IN CM_OBJECT_ID ObjectId, + IN UINT32 Count, + IN VOID * Data, + IN UINT32 Size, + OUT CM_OBJ_DESCRIPTOR ** NewCmObjDesc + ) +{ + CM_OBJ_DESCRIPTOR * CmObjDesc; + VOID * DataBuffer; + + if ((Count =3D=3D 0) || + (Data =3D=3D NULL) || + (Size =3D=3D 0) || + (NewCmObjDesc =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CmObjDesc =3D AllocateZeroPool (sizeof (CM_OBJ_DESCRIPTOR)); + if (CmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + DataBuffer =3D AllocateCopyPool (Size, Data); + if (DataBuffer =3D=3D NULL) { + FreePool (CmObjDesc); + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + CmObjDesc->ObjectId =3D ObjectId; + CmObjDesc->Count =3D Count; + CmObjDesc->Data =3D DataBuffer; + CmObjDesc->Size =3D Size; + + *NewCmObjDesc =3D CmObjDesc; + + return EFI_SUCCESS; +} + +/** Free resources allocated for the CM_OBJ_DESCRIPTOR. + + @param [in] CmObjDesc Pointer to the CM_OBJ_DESCRIPTOR. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FreeCmObjDesc ( + IN CM_OBJ_DESCRIPTOR * CmObjDesc + ) +{ + if (CmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (CmObjDesc->Data !=3D NULL) { + FreePool (CmObjDesc->Data); + } + + FreePool (CmObjDesc); + return EFI_SUCCESS; +} + +/** Add a single CmObj to the Configuration Manager. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] ObjectId CmObj ObjectId. + @param [in] Data CmObj Data. + @param [in] Size CmObj Size. + @param [out] Token If provided and success, + token generated for this CmObj. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AddSingleCmObj ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_OBJECT_ID ObjectId, + IN VOID *Data, + IN UINT32 Size, + OUT CM_OBJECT_TOKEN *Token OPTIONAL + ) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR CmObjDesc; + + if ((FdtParserHandle =3D=3D NULL) || + (FdtParserHandle->HwInfoAdd =3D=3D NULL) || + (Data =3D=3D NULL) || + (Size =3D=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CmObjDesc.ObjectId =3D ObjectId; + CmObjDesc.Count =3D 1; + CmObjDesc.Data =3D Data; + CmObjDesc.Size =3D Size; + + // Add the CmObj. + // Don't ask for a token. + Status =3D FdtParserHandle->HwInfoAdd ( + FdtParserHandle, + FdtParserHandle->Context, + &CmObjDesc, + Token + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Add multiple CmObj to the Configuration Manager. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] CmObjDesc CmObjDesc containing multiple CmObj + to add. + @param [in] TokenCount If provided, count of entries in the + TokenTable. + @param [out] TokenTable If provided and success, + token generated for these CmObj. + Address of an array of CM_OBJECT_TOKEN + with the same number of elements as the + CmObjDesc. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AddMultipleCmObj ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CONST CM_OBJ_DESCRIPTOR *CmObjDesc, + IN UINT32 TokenCount, OPTIONAL + OUT CM_OBJECT_TOKEN *TokenTable OPTIONAL + ) +{ + EFI_STATUS Status; + UINT32 Index; + UINT32 Count; + UINT8 * Data; + UINT32 Size; + CM_OBJ_DESCRIPTOR SingleCmObjDesc; + + if ((FdtParserHandle =3D=3D NULL) || + (FdtParserHandle->HwInfoAdd =3D=3D NULL) || + (CmObjDesc =3D=3D NULL) || + (CmObjDesc->Count =3D=3D 0) || + (CmObjDesc->Data =3D=3D NULL) || + (CmObjDesc->Size =3D=3D 0)){ + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Count =3D CmObjDesc->Count; + Data =3D CmObjDesc->Data; + Size =3D CmObjDesc->Size / Count; + + SingleCmObjDesc.ObjectId =3D CmObjDesc->ObjectId; + SingleCmObjDesc.Count =3D 1; + SingleCmObjDesc.Size =3D Size; + + for (Index =3D 0; Index < Count; Index++) { + SingleCmObjDesc.Data =3D (VOID*)&Data[Index * Size]; + // Add the CmObj. + Status =3D FdtParserHandle->HwInfoAdd ( + FdtParserHandle, + FdtParserHandle->Context, + &SingleCmObjDesc, + (TokenTable !=3D NULL) ? + &TokenTable[Index] : + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + + return Status; +} + +/** Add multiple CmObj to the Configuration Manager. + + Get one token referencing a EArmObjCmRef CmObj itself referencing + the input CmObj. In the table below, RefToken is returned. + + Token referencing an Array of tokens Array of CmObj + array of EArmObjCmRef referencing each from the input: + CmObj: CmObj from the input: + + RefToken ---> CmObjToken[0] ---> CmObj[0] + CmObjToken[1] ---> CmObj[1] + CmObjToken[2] ---> CmObj[2] + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] CmObjDesc CmObjDesc containing multiple CmObj + to add. + @param [out] Token If success, token referencing an array + of EArmObjCmRef CmObj, themselves + referencing the input CmObjs. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +AddMultipleCmObjWithCmObjRef ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_OBJ_DESCRIPTOR * CmObjDesc, + OUT CM_OBJECT_TOKEN * Token + ) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR CmObjRef; + CM_OBJECT_TOKEN *TokenTable; + INT32 TokenTableSize; + + if ((FdtParserHandle =3D=3D NULL) || + (FdtParserHandle->HwInfoAdd =3D=3D NULL) || + (CmObjDesc =3D=3D NULL) || + (CmObjDesc->Count =3D=3D 0) || + (CmObjDesc->Data =3D=3D NULL) || + (CmObjDesc->Size =3D=3D 0) || + (Token =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Allocate a buffer to store the tokens. + TokenTableSize =3D CmObjDesc->Count * sizeof (CM_OBJECT_TOKEN); + TokenTable =3D AllocateZeroPool (TokenTableSize); + if (TokenTable =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Add the input CmObjs. + Status =3D AddMultipleCmObj ( + FdtParserHandle, + CmObjDesc, + CmObjDesc->Count, + TokenTable + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + CmObjRef.ObjectId =3D CREATE_CM_ARM_OBJECT_ID (EArmObjCmRef); + CmObjRef.Data =3D TokenTable; + CmObjRef.Count =3D CmObjDesc->Count; + CmObjRef.Size =3D TokenTableSize; + + // Add the array of EArmObjCmRef CmObjs. + Status =3D FdtParserHandle->HwInfoAdd ( + FdtParserHandle, + FdtParserHandle->Context, + &CmObjRef, + Token + ); + ASSERT_EFI_ERROR (Status); + +exit_handler: + FreePool (TokenTable); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtilit= y.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.h new file mode 100644 index 000000000000..34439c716fb3 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.h @@ -0,0 +1,131 @@ +/** @file + Configuration manager Object Descriptor Utility. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef CM_OBJECT_DESC_UTILITY_H_ +#define CM_OBJECT_DESC_UTILITY_H_ + +#include + +#include "FdtHwInfoParser.h" + +/** Create a CM_OBJ_DESCRIPTOR. + + @param [in] ObjectId CM_OBJECT_ID of the node. + @param [in] Count Number of CmObj stored in the + data field. + @param [in] Data Pointer to one or more CmObj objects. + The content of this Data buffer is copied. + @param [in] Size Size of the Data buffer. + @param [out] NewCmObjDesc The created CM_OBJ_DESCRIPTOR. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +CreateCmObjDesc ( + IN CM_OBJECT_ID ObjectId, + IN UINT32 Count, + IN VOID * Data, + IN UINT32 Size, + OUT CM_OBJ_DESCRIPTOR ** NewCmObjDesc + ); + +/** Free resources allocated for the CM_OBJ_DESCRIPTOR. + + @param [in] CmObjDesc Pointer to the CM_OBJ_DESCRIPTOR. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FreeCmObjDesc ( + IN CM_OBJ_DESCRIPTOR * CmObjDesc + ); + +/** Add a single CmObj to the Configuration Manager. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] ObjectId CmObj ObjectId. + @param [in] Data CmObj Data. + @param [in] Size CmObj Size. + @param [out] Token If provided and success, + token generated for this CmObj. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AddSingleCmObj ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_OBJECT_ID ObjectId, + IN VOID *Data, + IN UINT32 Size, + OUT CM_OBJECT_TOKEN *Token OPTIONAL + ); + +/** Add multiple CmObj to the Configuration Manager. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] CmObjDesc CmObjDesc containing multiple CmObj + to add. + @param [in] TokenCount If provided, count of entries in the + TokenTable. + @param [out] TokenTable If provided and success, + token generated for these CmObj. + Address of an array of CM_OBJECT_TOKEN + with the same number of elements as the + CmObjDesc. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AddMultipleCmObj ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CONST CM_OBJ_DESCRIPTOR *CmObjDesc, + IN UINT32 TokenCount, OPTIONAL + OUT CM_OBJECT_TOKEN *TokenTable OPTIONAL + ); + +/** Add multiple CmObj to the Configuration Manager. + + Get one token referencing a EArmObjCmRef CmObj itself referencing + the input CmObj. In the table below, RefToken is returned. + + Token referencing an Array of tokens Array of CmObj + array of EArmObjCmRef referencing each from the input: + CmObj: CmObj from the input: + + RefToken ---> CmObjToken[0] ---> CmObj[0] + CmObjToken[1] ---> CmObj[1] + CmObjToken[2] ---> CmObj[2] + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] CmObjDesc CmObjDesc containing multiple CmObj + to add. + @param [out] Token If success, token referencing an array + of EArmObjCmRef CmObj, themselves + referencing the input CmObjs. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +AddMultipleCmObjWithCmObjRef ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_OBJ_DESCRIPTOR * CmObjDesc, + OUT CM_OBJECT_TOKEN * Token + ); + +#endif // CM_OBJECT_DESC_UTILITY_H_ --=20 2.25.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 (#83959): https://edk2.groups.io/g/devel/message/83959 Mute This Topic: https://groups.io/mt/87263314/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- From nobody Thu Mar 28 21:22:25 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+83960+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+83960+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687363; cv=none; d=zohomail.com; s=zohoarc; b=OhpB6QAoxwc9QeQuWIiYqCosS8t+cBTVxkG8/eCfz7JUo3St3LmnJsbnqmQv03J/hDhhQK9PH5m15bp5DqQct7zFS9hRdPedehM257OeyrsERG9qjGyCZvnn38k2imaNbHuIoPT1VRLiCAamTE7CgRlKRbP+2iTLOMQghINT0Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687363; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=kwUSNf3xMoCMoH6A64yaRBY21RDJVlP7X8l8UKsqGyY=; b=An3ihC4Woh+7A4FpAP4QBfMyooEht89Z7Ew4pJt+tAHm5HuAMiLj/lmEUBkkURleec33sn2mgCnsAqNHNzUAvOQ/ICwX+cGZaoh9igK0Tbyg0k1mg+lxOKdBGt4LmUZZrFKwsJYAzOv7iUNmQg6yjiJ16DdLp/sQj8vzjMunkxw= 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+83960+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 1637687363394701.9730247234469; Tue, 23 Nov 2021 09:09:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id fugKYY1788612xpPCZeNjO7P; Tue, 23 Nov 2021 09:09:23 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.14102.1637687359948591741 for ; Tue, 23 Nov 2021 09:09:20 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0253C1063; Tue, 23 Nov 2021 09:09:19 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 096953F5A1; Tue, 23 Nov 2021 09:09:17 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 03/15] DynamicTablesPkg: FdtHwInfoParser: Add FDT utility functions Date: Tue, 23 Nov 2021 18:08:26 +0100 Message-Id: <20211123170838.143805-4-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: aki2eB0bqH7jnAbLzCoP0IiGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687363; bh=ChpOB+OueCZGVusKK4Cgs1jyebGzicX3SBytNgo+O7I=; h=Cc:Date:From:Reply-To:Subject:To; b=amGtM2L4duBN+hcathECHunyfNmRJmHgKm8Js9ZwyL1/JRO20GaZczhlv+nSYzRv7IA kaSb8KunFThUNXUT0EC6P/IoczTWUgRacodMY/QC0Z61cGFiwr/PAhRttiyQvljkidbPF b+1nJJy/6U5XmpT4Mlxk7rHB+tDPRLGBMrY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687364562100002 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The FdtHwInfoParser parses a platform Device Tree and populates the Platform Information repository with Configuration Manager objects. Therefore, add a set of helper functions to simplify parsing of the platform Device Tree. Signed-off-by: Pierre Gondois --- .../Library/FdtHwInfoParserLib/FdtUtility.c | 907 ++++++++++++++++++ .../Library/FdtHwInfoParserLib/FdtUtility.h | 458 +++++++++ 2 files changed, 1365 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.c b/Dyn= amicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.c new file mode 100644 index 000000000000..3a88fda46127 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.c @@ -0,0 +1,907 @@ +/** @file + Flattened device tree utility. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - Device tree Specification - Release v0.3 + - linux/Documentation/devicetree/bindings/interrupt-controller/arm%2Cgic= .yaml + - linux//Documentation/devicetree/bindings/interrupt-controller/arm%2Cgi= c.yaml +**/ + +#include +#include "FdtUtility.h" + +/** Get the interrupt Id of an interrupt described in a fdt. + + Data must describe a GIC interrupt. A GIC interrupt is on at least + 3 UINT32 cells. + This function DOES NOT SUPPORT extended SPI range and extended PPI range. + + @param [in] Data Pointer to the first cell of an "interrupts" propert= y. + + @retval The interrupt id. +**/ +UINT32 +EFIAPI +FdtGetInterruptId ( + UINT32 CONST * Data + ) +{ + UINT32 IrqType; + UINT32 IrqId; + + ASSERT (Data !=3D NULL); + + IrqType =3D fdt32_to_cpu (Data[IRQ_TYPE_OFFSET]); + IrqId =3D fdt32_to_cpu (Data[IRQ_NUMBER_OFFSET]); + + switch (IrqType) { + case DT_SPI_IRQ: + IrqId +=3D SPI_OFFSET; + break; + + case DT_PPI_IRQ: + IrqId +=3D PPI_OFFSET; + break; + + default: + ASSERT (0); + IrqId =3D 0; + } + + return IrqId; +} + +/** Get the ACPI interrupt flags of an interrupt described in a fdt. + + Data must describe a GIC interrupt. A GIC interrupt is on at least + 3 UINT32 cells. + + PPI interrupt cpu mask on bits [15:8] are ignored. + + @param [in] Data Pointer to the first cell of an "interrupts" propert= y. + + @retval The interrupt flags (for ACPI). +**/ +UINT32 +EFIAPI +FdtGetInterruptFlags ( + UINT32 CONST * Data + ) +{ + UINT32 IrqFlags; + UINT32 AcpiIrqFlags; + + ASSERT (Data !=3D NULL); + + IrqFlags =3D fdt32_to_cpu (Data[IRQ_FLAGS_OFFSET]); + + AcpiIrqFlags =3D DT_IRQ_IS_EDGE_TRIGGERED (IrqFlags) ? BIT0 : 0; + AcpiIrqFlags |=3D DT_IRQ_IS_ACTIVE_LOW (IrqFlags) ? BIT1 : 0; + + return AcpiIrqFlags; +} + +/** Check whether a node has the input name. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to check the name. + @param [in] SearchName Node name to search. + This is a NULL terminated string. + + @retval True The node has the input name. + @retval FALSE Otherwise, or error. +**/ +STATIC +BOOLEAN +EFIAPI +FdtNodeHasName ( + IN CONST VOID * Fdt, + IN INT32 Node, + IN CONST VOID * SearchName + ) +{ + CONST CHAR8 * NodeName; + UINT32 Length; + + if ((Fdt =3D=3D NULL) || + (SearchName =3D=3D NULL)) { + ASSERT (0); + return FALSE; + } + + // Always compare the whole string. Don't stop at the "@" char. + Length =3D (UINT32)AsciiStrLen (SearchName); + + // Get the address of the node name. + NodeName =3D fdt_offset_ptr (Fdt, Node + FDT_TAGSIZE, Length + 1); + if (NodeName =3D=3D NULL) { + return FALSE; + } + + // SearchName must be longer than the node name. + if (Length > AsciiStrLen (NodeName)) { + return FALSE; + } + + if (AsciiStrnCmp (NodeName, SearchName, Length) !=3D 0) { + return FALSE; + } + + // The name matches perfectly, or + // the node name is XXX@addr and the XXX matches. + if ((NodeName[Length] =3D=3D '\0') || + (NodeName[Length] =3D=3D '@')) { + return TRUE; + } + + return FALSE; +} + +/** Iterate through the list of strings in the Context, + and check whether at least one string is matching the + "compatible" property of the node. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to operate the check on. + @param [in] CompatInfo COMPATIBILITY_INFO containing the list of comp= atible + strings to compare with the "compatible" prope= rty + of the node. + + @retval TRUE At least one string matched, the node is compatible. + @retval FALSE Otherwise, or error. +**/ +BOOLEAN +EFIAPI +FdtNodeIsCompatible ( + IN CONST VOID * Fdt, + IN INT32 Node, + IN CONST VOID * CompatInfo + ) +{ + UINT32 Index; + CONST COMPATIBILITY_STR * CompatibleTable; + UINT32 Count; + CONST VOID * Prop; + INT32 PropLen; + + if ((Fdt =3D=3D NULL) || + (CompatInfo =3D=3D NULL)) { + ASSERT (0); + return FALSE; + } + + Count =3D ((COMPATIBILITY_INFO*)CompatInfo)->Count; + CompatibleTable =3D ((COMPATIBILITY_INFO*)CompatInfo)->CompatTable; + + // Get the "compatible" property. + Prop =3D fdt_getprop (Fdt, Node, "compatible", &PropLen); + if ((Prop =3D=3D NULL) || (PropLen < 0)) { + return FALSE; + } + + for (Index =3D 0; Index < Count; Index++) { + if (fdt_stringlist_contains ( + Prop, + PropLen, + CompatibleTable[Index].CompatStr + )) { + return TRUE; + } + } // for + + return FALSE; +} + +/** Check whether a node has a property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to operate the check on. + @param [in] PropertyName Name of the property to search. + This is a NULL terminated string. + + @retval True The node has the property. + @retval FALSE Otherwise, or error. +**/ +BOOLEAN +EFIAPI +FdtNodeHasProperty ( + IN CONST VOID * Fdt, + IN INT32 Node, + IN CONST VOID * PropertyName + ) +{ + INT32 Size; + CONST VOID * Prop; + + if ((Fdt =3D=3D NULL) || + (PropertyName =3D=3D NULL)) { + ASSERT (0); + return FALSE; + } + + Prop =3D fdt_getprop (Fdt, Node, PropertyName, &Size); + if ((Prop =3D=3D NULL) || (Size < 0)) { + return FALSE; + } + return TRUE; +} + +/** Get the next node in the whole DT fulfilling a condition. + + The condition to fulfill is checked by the NodeChecker function. + Context is passed to NodeChecker. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node fulfilling the + condition. + @param [in, out] Depth Depth is incremented/decremented of the de= pth + difference between the input Node and the + output Node. + E.g.: If the output Node is a child node + of the input Node, contains (+1). + @param [in] NodeChecker Function called to check if the condition + is fulfilled. + @param [in] Context Context for the NodeChecker. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +STATIC +EFI_STATUS +EFIAPI +FdtGetNextCondNode ( + IN CONST VOID * Fdt, + IN OUT INT32 * Node, + IN OUT INT32 * Depth, + IN NODE_CHECKER_FUNC NodeChecker, + IN CONST VOID * Context + ) +{ + INT32 CurrNode; + + if ((Fdt =3D=3D NULL) || + (Node =3D=3D NULL) || + (Depth =3D=3D NULL) || + (NodeChecker =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CurrNode =3D *Node; + do { + CurrNode =3D fdt_next_node (Fdt, CurrNode, Depth); + if ((CurrNode =3D=3D -FDT_ERR_NOTFOUND) || + (*Depth < 0)) { + // End of the tree, no matching node found. + return EFI_NOT_FOUND; + } else if (CurrNode < 0) { + // An error occurred. + ASSERT (0); + return EFI_ABORTED; + } + } while (!NodeChecker (Fdt, CurrNode, Context)); + + // Matching node found. + *Node =3D CurrNode; + return EFI_SUCCESS; +} + +/** Get the next node in a branch fulfilling a condition. + + The condition to fulfill is checked by the NodeChecker function. + Context is passed to NodeChecker. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this + branch. + Write (-1) to search the whole tree. + @param [in] NodeChecker Function called to check if the condit= ion + is fulfilled. + @param [in] Context Context for the NodeChecker. + @param [in, out] Node At entry: Node offset to start the sea= rch. + This first node is skipped. + Write (-1) to search the whole tr= ee. + At exit: If success, contains the off= set + of the next node in the branch + fulfilling the condition. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +STATIC +EFI_STATUS +EFIAPI +FdtGetNextCondNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN NODE_CHECKER_FUNC NodeChecker, + IN CONST VOID * Context, + IN OUT INT32 * Node + ) +{ + EFI_STATUS Status; + INT32 CurrNode; + INT32 Depth; + + if ((Fdt =3D=3D NULL) || + (Node =3D=3D NULL) || + (NodeChecker =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CurrNode =3D FdtBranch; + Depth =3D 0; + + // First, check the Node is in the sub-nodes of the branch. + // This allows to find the relative depth of Node in the branch. + if (CurrNode !=3D *Node) { + for (CurrNode =3D fdt_next_node (Fdt, CurrNode, &Depth); + (CurrNode >=3D 0) && (Depth > 0); + CurrNode =3D fdt_next_node (Fdt, CurrNode, &Depth)) { + if (CurrNode =3D=3D *Node) { + // Node found. + break; + } + } // for + + if ((CurrNode < 0) || (Depth <=3D 0)) { + // Node is not a node in the branch, or an error occurred. + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } + + // Get the next node in the tree fulfilling the condition, + // in any branch. + Status =3D FdtGetNextCondNode ( + Fdt, + Node, + &Depth, + NodeChecker, + Context + ); + if (EFI_ERROR (Status)) { + ASSERT (Status =3D=3D EFI_NOT_FOUND); + return Status; + } + + if (Depth <=3D 0) { + // The node found is not in the right branch. + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** Get the next node in a branch having a matching name. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] NodeName The node name to search. + This is a NULL terminated string. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + having a matching name. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextNamedNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * NodeName, + IN OUT INT32 * Node + ) +{ + return FdtGetNextCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeHasName, + NodeName, + Node + ); +} + +/** Get the next node in a branch with at least one compatible property. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] CompatNamesInfo Table of compatible strings to compare with + the compatible property of the node. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + being compatible. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextCompatNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST COMPATIBILITY_INFO * CompatNamesInfo, + IN OUT INT32 * Node + ) +{ + return FdtGetNextCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeIsCompatible, + (CONST VOID*)CompatNamesInfo, + Node + ); +} + +/** Get the next node in a branch having the PropName property. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] PropName Name of the property to search. + This is a NULL terminated string. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + being compatible. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextPropNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * PropName, + IN OUT INT32 * Node + ) +{ + return FdtGetNextCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeHasProperty, + (CONST VOID*)PropName, + Node + ); +} + +/** Count the number of Device Tree nodes fulfilling a condition + in a Device Tree branch. + + The condition to fulfill is checked by the NodeChecker function. + Context is passed to NodeChecker. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] NodeChecker Function called to check the condition is + fulfilled. + @param [in] Context Context for the NodeChecker. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +FdtCountCondNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN NODE_CHECKER_FUNC NodeChecker, + IN CONST VOID * Context, + OUT UINT32 * NodeCount + ) +{ + EFI_STATUS Status; + INT32 CurrNode; + + if ((Fdt =3D=3D NULL) || + (NodeChecker =3D=3D NULL) || + (NodeCount =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + *NodeCount =3D 0; + CurrNode =3D FdtBranch; + while (TRUE) { + Status =3D FdtGetNextCondNodeInBranch ( + Fdt, + FdtBranch, + NodeChecker, + Context, + &CurrNode + ); + if (EFI_ERROR (Status) && + (Status !=3D EFI_NOT_FOUND)) { + ASSERT (0); + return Status; + } else if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + (*NodeCount)++; + } + return EFI_SUCCESS; +} + +/** Count the number of nodes in a branch with the input name. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] NodeName Node name to search. + This is a NULL terminated string. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountNamedNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * NodeName, + OUT UINT32 * NodeCount + ) +{ + return FdtCountCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeHasName, + NodeName, + NodeCount + ); +} + +/** Count the number of nodes in a branch with at least + one compatible property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] CompatNamesInfo Table of compatible strings to + compare with the compatible property + of the node. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountCompatNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST COMPATIBILITY_INFO * CompatNamesInfo, + OUT UINT32 * NodeCount + ) +{ + return FdtCountCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeIsCompatible, + CompatNamesInfo, + NodeCount + ); +} + +/** Count the number of nodes in a branch having the PropName property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] PropName Name of the property to search. + This is a NULL terminated string. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountPropNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * PropName, + OUT UINT32 * NodeCount + ) +{ + return FdtCountCondNodeInBranch ( + Fdt, + FdtBranch, + FdtNodeHasProperty, + PropName, + NodeCount + ); +} + +/** Get the interrupt-controller node handling the interrupts of + the input node. + + To do this, recursively search a node with either the "interrupt-control= ler" + or the "interrupt-parent" property in the parents of Node. + + Devicetree Specification, Release v0.3, + 2.4.1 "Properties for Interrupt Generating Devices": + Because the hierarchy of the nodes in the interrupt tree + might not match the devicetree, the interrupt-parent + property is available to make the definition of an + interrupt parent explicit. The value is the phandle to the + interrupt parent. If this property is missing from a + device, its interrupt parent is assumed to be its devicetree + parent. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to start the search. + @param [out] IntcNode If success, contains the offset of the + interrupt-controller node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND No interrupt-controller node found. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetIntcParentNode ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * IntcNode + ) +{ + CONST UINT32 * PHandle; + INT32 Size; + CONST VOID * Prop; + + if ((Fdt =3D=3D NULL) || + (IntcNode =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + while (TRUE) { + // Check whether the node has the "interrupt-controller" property. + Prop =3D fdt_getprop (Fdt, Node, "interrupt-controller", &Size); + if ((Prop !=3D NULL) && (Size >=3D 0)) { + // The interrupt-controller has been found. + *IntcNode =3D Node; + return EFI_SUCCESS; + } else { + // Check whether the node has the "interrupt-parent" property. + PHandle =3D fdt_getprop (Fdt, Node, "interrupt-parent", &Size); + if ((PHandle !=3D NULL) && (Size =3D=3D sizeof (UINT32))) { + // The phandle of the interrupt-controller has been found. + // Search the node having this phandle and return it. + Node =3D fdt_node_offset_by_phandle (Fdt, fdt32_to_cpu (*PHandle)); + if (Node < 0) { + ASSERT (0); + return EFI_ABORTED; + } + + *IntcNode =3D Node; + return EFI_SUCCESS; + } else if (Size !=3D -FDT_ERR_NOTFOUND) { + ASSERT (0); + return EFI_ABORTED; + } + } + + if (Node =3D=3D 0) { + // We are at the root of the tree. Not parent available. + return EFI_NOT_FOUND; + } + + // Get the parent of the node. + Node =3D fdt_parent_offset (Fdt, Node); + if (Node < 0) { + // An error occurred. + ASSERT (0); + return EFI_ABORTED; + } + } // while +} + +/** Get the "interrupt-cells" property value of the node. + + The "interrupts" property requires to know the number of cells used + to encode an interrupt. This information is stored in the + interrupt-controller of the input Node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] IntcNode Offset of an interrupt-controller node. + @param [out] IntCells If success, contains the "interrupt-cells" + property of the IntcNode. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +FdtGetInterruptCellsInfo ( + IN CONST VOID * Fdt, + IN INT32 IntcNode, + OUT INT32 * IntCells + ) +{ + CONST UINT32 * Data; + INT32 Size; + + if ((Fdt =3D=3D NULL) || + (IntCells =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Data =3D fdt_getprop (Fdt, IntcNode, "#interrupt-cells", &Size); + if ((Data =3D=3D NULL) || (Size !=3D sizeof (UINT32))) { + // If error or not on one UINT32 cell. + ASSERT (0); + return EFI_ABORTED; + } + + *IntCells =3D fdt32_to_cpu (*Data); + + return EFI_SUCCESS; +} + +/** Get the "#address-cells" and/or "#size-cells" property of the node. + + According to the Device Tree specification, s2.3.5 "#address-cells and + #size-cells": + "If missing, a client program should assume a default value of 2 for + #address-cells, and a value of 1 for #size-cells." + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node having to get the + "#address-cells" and "#size-cells" + properties from. + @param [out] AddressCells If success, number of address-cells. + If the property is not available, + default value is 2. + @param [out] SizeCells If success, number of size-cells. + If the property is not available, + default value is 1. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetAddressInfo ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * AddressCells, OPTIONAL + OUT INT32 * SizeCells OPTIONAL + ) +{ + if (Fdt =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (AddressCells !=3D NULL) { + *AddressCells =3D fdt_address_cells (Fdt, Node); + if (*AddressCells < 0) { + ASSERT (0); + return EFI_ABORTED; + } + } + + if (SizeCells !=3D NULL) { + *SizeCells =3D fdt_size_cells (Fdt, Node); + if (*SizeCells < 0) { + ASSERT (0); + return EFI_ABORTED; + } + } + + return EFI_SUCCESS; +} + +/** Get the "#address-cells" and/or "#size-cells" property of the parent n= ode. + + According to the Device Tree specification, s2.3.5 "#address-cells and + #size-cells": + "If missing, a client program should assume a default value of 2 for + #address-cells, and a value of 1 for #size-cells." + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node having to get the + "#address-cells" and "#size-cells" + properties from its parent. + @param [out] AddressCells If success, number of address-cells. + If the property is not available, + default value is 2. + @param [out] SizeCells If success, number of size-cells. + If the property is not available, + default value is 1. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetParentAddressInfo ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * AddressCells, OPTIONAL + OUT INT32 * SizeCells OPTIONAL + ) +{ + if (Fdt =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Node =3D fdt_parent_offset (Fdt, Node); + if (Node < 0) { + // End of the tree, or an error occurred. + ASSERT (0); + return EFI_ABORTED; + } + + return FdtGetAddressInfo (Fdt, Node, AddressCells, SizeCells); +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.h b/Dyn= amicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.h new file mode 100644 index 000000000000..0076c5066d4c --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.h @@ -0,0 +1,458 @@ +/** @file + Flattened device tree utility. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - Device tree Specification - Release v0.3 + - linux/Documentation/devicetree/bindings/interrupt-controller/arm%2Cgic= .yaml + - linux//Documentation/devicetree/bindings/interrupt-controller/arm%2Cgi= c.yaml +**/ + +#ifndef FDT_UTILITY_H_ +#define FDT_UTILITY_H_ + +/** Get the offset of an address in a "reg" Device Tree property. + + In a Device Tree, the "reg" property stores address/size couples. + They are stored on N 32-bits cells. + Based on the value of the #address-cells, the #size-cells and the + index in the "reg" property, compute the number of 32-bits cells + to skip. + + @param [in] Index Index in the reg property. + @param [in] AddrCells Number of cells used to store an address. + @param [in] SizeCells Number of cells used to store the size of + an address. + + @retval Number of 32-bits cells to skip to access the address. +*/ +#define GET_DT_REG_ADDRESS_OFFSET(Index, AddrCells, SizeCells) ( = \ + (Index) * ((AddrCells) + (SizeCells)) = \ + ) + +/** Get the offset of an address size in a "reg" Device Tree property. + + In a Device Tree, the "reg" property stores address/size couples. + They are stored on N 32-bits cells. + Based on the value of the #address-cells, the #size-cells and the + index in the "reg" property, compute the number of 32-bits cells + to skip. + + @param [in] Index Index in the reg property. + @param [in] AddrCells Number of cells used to store an address. + @param [in] SizeCells Number of cells used to store the size of + an address. + + @retval Number of 32-bits cells to skip to access the address size. +*/ +#define GET_DT_REG_SIZE_OFFSET(Index, AddrCells, SizeCells) ( = \ + GET_DT_REG_ADDRESS_OFFSET ((Index), (AddrCells), (SizeCells)) + = \ + (SizeCells) = \ + ) + +/// Maximum string length for compatible names. +#define COMPATIBLE_STR_LEN (32U) + +/// Interrupt macros +#define PPI_OFFSET (16U) +#define SPI_OFFSET (32U) +#define DT_PPI_IRQ (1U) +#define DT_SPI_IRQ (0U) +#define DT_IRQ_IS_EDGE_TRIGGERED(x) ((((x) & (BIT0 | BIT2)) !=3D 0)) +#define DT_IRQ_IS_ACTIVE_LOW(x) ((((x) & (BIT1 | BIT3)) !=3D 0)) +#define IRQ_TYPE_OFFSET (0U) +#define IRQ_NUMBER_OFFSET (1U) +#define IRQ_FLAGS_OFFSET (2U) + +/** Get the interrupt Id of an interrupt described in a fdt. + + Data must describe a GIC interrupt. A GIC interrupt is on at least + 3 UINT32 cells. + This function DOES NOT SUPPORT extended SPI range and extended PPI range. + + @param [in] Data Pointer to the first cell of an "interrupts" propert= y. + + @retval The interrupt id. +**/ +UINT32 +EFIAPI +FdtGetInterruptId ( + UINT32 CONST * Data + ); + +/** Get the ACPI interrupt flags of an interrupt described in a fdt. + + Data must describe a GIC interrupt. A GIC interrupt is on at least + 3 UINT32 cells. + + @param [in] Data Pointer to the first cell of an "interrupts" propert= y. + + @retval The interrupt flags (for ACPI). +**/ +UINT32 +EFIAPI +FdtGetInterruptFlags ( + UINT32 CONST * Data + ); + +/** A structure describing a compatibility string. +*/ +typedef struct CompatStr { + CONST CHAR8 CompatStr[COMPATIBLE_STR_LEN]; +} COMPATIBILITY_STR; + +/** Structure containing a list of compatible names and their count. +*/ +typedef struct CompatibilityInfo { + /// Count of entries in the NAME_TABLE. + UINT32 Count; + + /// Pointer to a table storing the names. + CONST COMPATIBILITY_STR * CompatTable; +} COMPATIBILITY_INFO; + +/** Operate a check on a Device Tree node. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] NodeOffset Offset of the node to compare input string. + @param [in] Context Context to operate the check on the node. + + @retval True The check is correct. + @retval FALSE Otherwise, or error. +**/ +typedef +BOOLEAN +(EFIAPI *NODE_CHECKER_FUNC) ( + IN CONST VOID * Fdt, + IN INT32 NodeOffset, + IN CONST VOID * Context + ); + +/** Iterate through the list of strings in the Context, + and check whether at least one string is matching the + "compatible" property of the node. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to operate the check on. + @param [in] CompatInfo COMPATIBILITY_INFO containing the list of comp= atible + strings to compare with the "compatible" prope= rty + of the node. + + @retval TRUE At least one string matched, the node is compatible. + @retval FALSE Otherwise, or error. +**/ +BOOLEAN +EFIAPI +FdtNodeIsCompatible ( + IN CONST VOID * Fdt, + IN INT32 Node, + IN CONST VOID * CompatInfo + ); + +/** Check whether a node has a property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to operate the check on. + @param [in] PropertyName Name of the property to search. + This is a NULL terminated string. + + @retval True The node has the property. + @retval FALSE Otherwise, or error. +**/ +BOOLEAN +EFIAPI +FdtNodeHasProperty ( + IN CONST VOID * Fdt, + IN INT32 Node, + IN CONST VOID * PropertyName + ); + +/** Get the next node in a branch having a matching name. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] NodeName The node name to search. + This is a NULL terminated string. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + having a matching name. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextNamedNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * NodeName, + IN OUT INT32 * Node + ); + +/** Get the next node in a branch with at least one compatible property. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] CompatNamesInfo Table of compatible strings to compare with + the compatible property of the node. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + being compatible. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextCompatNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST COMPATIBILITY_INFO * CompatNamesInfo, + IN OUT INT32 * Node + ); + +/** Get the next node in a branch having the PropName property. + + The Device tree is traversed in a depth-first search, starting from Node. + The input Node is skipped. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] PropName Name of the property to search. + This is a NULL terminated string. + @param [in, out] Node At entry: Node offset to start the search. + This first node is skipped. + Write (-1) to search the whole t= ree. + At exit: If success, contains the offset = of + the next node in the branch + being compatible. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND No matching node found. +**/ +EFI_STATUS +EFIAPI +FdtGetNextPropNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * PropName, + IN OUT INT32 * Node + ); + +/** Count the number of nodes in a branch with the input name. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] NodeName Node name to search. + This is a NULL terminated string. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountNamedNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * NodeName, + OUT UINT32 * NodeCount + ); + +/** Count the number of nodes in a branch with at least + one compatible property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] CompatibleTable Table of compatible strings to + compare with the compatible property + of the node. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountCompatNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST COMPATIBILITY_INFO * CompatNamesInfo, + OUT UINT32 * NodeCount + ); + +/** Count the number of nodes in a branch having the PropName property. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] FdtBranch Only search in the sub-nodes of this branc= h. + Write (-1) to search the whole tree. + @param [in] PropName Name of the property to search. + This is a NULL terminated string. + @param [out] NodeCount If success, contains the count of nodes + fulfilling the condition. + Can be 0. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtCountPropNodeInBranch ( + IN CONST VOID * Fdt, + IN INT32 FdtBranch, + IN CONST CHAR8 * PropName, + OUT UINT32 * NodeCount + ); + +/** Get the interrupt-controller node handling the interrupts of + the input node. + + To do this, recursively search a node with either the "interrupt-control= ler" + or the "interrupt-parent" property in the parents of Node. + + Devicetree Specification, Release v0.3, + 2.4.1 "Properties for Interrupt Generating Devices": + Because the hierarchy of the nodes in the interrupt tree + might not match the devicetree, the interrupt-parent + property is available to make the definition of an + interrupt parent explicit. The value is the phandle to the + interrupt parent. If this property is missing from a + device, its interrupt parent is assumed to be its devicetree + parent. + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node to start the search. + @param [out] IntcNode If success, contains the offset of the + interrupt-controller node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND No interrupt-controller node found. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetIntcParentNode ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * IntcNode + ); + +/** Get the "interrupt-cells" property value of the node. + + The "interrupts" property requires to know the number of cells used + to encode an interrupt. This information is stored in the + interrupt-controller of the input Node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] IntcNode Offset of an interrupt-controller node. + @param [out] IntCells If success, contains the "interrupt-cells" + property of the IntcNode. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +FdtGetInterruptCellsInfo ( + IN CONST VOID * Fdt, + IN INT32 IntcNode, + OUT INT32 * InterruptCells + ); + +/** Get the "#address-cells" and/or "#size-cells" property of the node. + + According to the Device Tree specification, s2.3.5 "#address-cells and + #size-cells": + "If missing, a client program should assume a default value of 2 for + #address-cells, and a value of 1 for #size-cells." + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node having to get the + "#address-cells" and "#size-cells" + properties from. + @param [out] AddressCells If success, number of address-cells. + If the property is not available, + default value is 2. + @param [out] SizeCells If success, number of size-cells. + If the property is not available, + default value is 1. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetAddressInfo ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * AddressCells, OPTIONAL + OUT INT32 * SizeCells OPTIONAL + ); + +/** Get the "#address-cells" and/or "#size-cells" property of the parent n= ode. + + According to the Device Tree specification, s2.3.5 "#address-cells and + #size-cells": + "If missing, a client program should assume a default value of 2 for + #address-cells, and a value of 1 for #size-cells." + + @param [in] Fdt Pointer to a Flattened Device Tree. + @param [in] Node Offset of the node having to get the + "#address-cells" and "#size-cells" + properties from its parent. + @param [out] AddressCells If success, number of address-cells. + If the property is not available, + default value is 2. + @param [out] SizeCells If success, number of size-cells. + If the property is not available, + default value is 1. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +FdtGetParentAddressInfo ( + IN CONST VOID * Fdt, + IN INT32 Node, + OUT INT32 * AddressCells, OPTIONAL + OUT INT32 * SizeCells OPTIONAL + ); + +#endif // FDT_UTILITY_H_ --=20 2.25.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 (#83960): https://edk2.groups.io/g/devel/message/83960 Mute This Topic: https://groups.io/mt/87263316/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- From nobody Thu Mar 28 21:22:26 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+83961+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+83961+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687364; cv=none; d=zohomail.com; s=zohoarc; b=eWIzL60a/MnsV4nNiq0K5j5bxzJZURNl7IZMHe7+DCwRmRDIExLY9wQOauvxDFClnxozlm61YVId4XFmTT+mb3vHc2h2u5+W75euJQ0OfHiuEweD9O9v9w6VmE8M79fZbX4iG90jyA+wjXElYGiYNGPcsKHSeX5Y8/sdT+o1YFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687364; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZoeuWd+/OnAliHGhGY+K8M15EQ2Mro/sCToET0TN3O0=; b=UVPbozPz9UzMJQyL/cDC7W11BfVrKAYnP4UySB8eUgPq7YYip5KXIjwzOqeNO+4urlxfIfbfOOsY1iwQvi2OzVxItkSysI2xC2K8k/n5djBtISVBRg54Fs8W2p4GIbIxo6iPIK/X6swB9JPVEv++ffgJgemd/w6Yvj80ktWBgE0= 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+83961+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 1637687364672478.5701260208349; Tue, 23 Nov 2021 09:09:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id sy33YY1788612xfIFKPxQvTK; Tue, 23 Nov 2021 09:09:24 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14135.1637687360807375193 for ; Tue, 23 Nov 2021 09:09:21 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C2EF1FB; Tue, 23 Nov 2021 09:09:20 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 625173F5A1; Tue, 23 Nov 2021 09:09:19 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 04/15] DynamicTablesPkg: FdtHwInfoParser: Add Boot Arch parser Date: Tue, 23 Nov 2021 18:08:27 +0100 Message-Id: <20211123170838.143805-5-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: SbLFSpJLPNO82M2xecbwSmmAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687364; bh=1BdR4jyBWEkXAl+YjYAV/SjgURiCyrFbaUB3cMVT7z8=; h=Cc:Date:From:Reply-To:Subject:To; b=RICS6ANz1fY0A/tjcCaPrKXt8S2IkRHwF+4vHgQg0TYGMGCWei6tR18EXJzjN9xAsAV tPMYr+JzJnjhdLysmk7wSUSG4fkWCL9Y3flXSppORdRGarFc4P+hDgRLlcrGaEHxTfrSZ jA44fbulWAhvNwbxsNMDyTydN0bh0C3WoNo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687366626100007 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The Fixed ACPI Description Table (FADT) is a mandatory table required for booting a standards-based operating system. The FADT table has an 'ARM Boot Architecture Flags' field that is used by an OS at boot time to determine the code path during boot. This field is used to specify if the platform complies with the PSCI specification. It is also used to describe the conduit (SMC/HVC) to be used for PSCI. The PSCI compliance information for a platform is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/arm/psci.yaml The FdtHwInfoParser implements a Boot Arch Parser that parses the platform Device Tree to create a CM_ARM_BOOT_ARCH_INFO object. The CM_ARM_BOOT_ARCH_INFO object is encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the FADT table. Signed-off-by: Pierre Gondois --- .../BootArch/ArmBootArchParser.c | 159 ++++++++++++++++++ .../BootArch/ArmBootArchParser.h | 45 +++++ 2 files changed, 204 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/Ar= mBootArchParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/Ar= mBootArchParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootAr= chParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootAr= chParser.c new file mode 100644 index 000000000000..5040e50eb16a --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParse= r.c @@ -0,0 +1,159 @@ +/** @file + Arm boot architecture parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/arm/psci.yaml +**/ + +#include "FdtHwInfoParser.h" +#include "CmObjectDescUtility.h" +#include "BootArch/ArmBootArchParser.h" + +/** List of "compatible" property values for Psci nodes. + + Other "compatible" values are not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR PsciCompatibleStr[] =3D { + {"arm,psci-0.2"}, + {"arm,psci"} +}; + +/** COMPATIBILITY_INFO structure for the PsciCompatibleInfo. +*/ +STATIC CONST COMPATIBILITY_INFO PsciCompatibleInfo =3D { + ARRAY_SIZE (PsciCompatibleStr), + PsciCompatibleStr +}; + +/** List of PSCI method strings. +*/ +STATIC CONST CHAR8 *PsciMethod[] =3D { + "smc", + "hvc" +}; + +/** Parse a Psci node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] PsciNode Offset of a Psci node. + @param [in] BootArchInfo The CM_ARM_BOOT_ARCH_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +PsciNodeParser ( + IN CONST VOID * Fdt, + IN INT32 PsciNode, + IN CM_ARM_BOOT_ARCH_INFO * BootArchInfo + ) +{ + CONST VOID * Data; + INT32 DataSize; + + if ((Fdt =3D=3D NULL) || + (BootArchInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Default to parking protocol + BootArchInfo->BootArchFlags =3D 0; + + Data =3D fdt_getprop (Fdt, PsciNode, "method", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < 0)) { + ASSERT (0); + return EFI_ABORTED; + } + + // Check PSCI conduit. + if (AsciiStrnCmp (Data, PsciMethod[0], DataSize) =3D=3D 0) { + BootArchInfo->BootArchFlags =3D EFI_ACPI_6_3_ARM_PSCI_COMPLIANT; + + } else if (AsciiStrnCmp (Data, PsciMethod[1], DataSize) =3D=3D 0) { + BootArchInfo->BootArchFlags =3D (EFI_ACPI_6_3_ARM_PSCI_COMPLIANT | + EFI_ACPI_6_3_ARM_PSCI_USE_HVC); + } + + return EFI_SUCCESS; +} + +/** CM_ARM_BOOT_ARCH_INFO parser function. + + The following structure is populated: + typedef struct CmArmBootArchInfo { + UINT16 BootArchFlags; // {Populated} + } CM_ARM_BOOT_ARCH_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmBootArchInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 PsciNode; + CM_ARM_BOOT_ARCH_INFO BootArchInfo; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ZeroMem (&BootArchInfo, sizeof (CM_ARM_BOOT_ARCH_INFO)); + + PsciNode =3D FdtBranch; + Status =3D FdtGetNextCompatNodeInBranch ( + FdtParserHandle->Fdt, + FdtBranch, + &PsciCompatibleInfo, + &PsciNode + ); + if (EFI_ERROR (Status)) { + // Error, or no node found. + ASSERT (Status =3D=3D EFI_NOT_FOUND); + return Status; + } + + // Parse the psci node. + Status =3D PsciNodeParser (FdtParserHandle->Fdt, PsciNode, &BootArchInfo= ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjBootArchInfo), + &BootArchInfo, + sizeof (CM_ARM_BOOT_ARCH_INFO), + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootAr= chParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootAr= chParser.h new file mode 100644 index 000000000000..959c65a53fb3 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParse= r.h @@ -0,0 +1,45 @@ +/** @file + Arm boot architecture parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/arm/psci.yaml +**/ + +#ifndef ARM_BOOT_ARCH_PARSER_H_ +#define ARM_BOOT_ARCH_PARSER_H_ + +/** CM_ARM_BOOT_ARCH_INFO parser function. + + The following structure is populated: + typedef struct CmArmBootArchInfo { + UINT16 BootArchFlags; // {Populated} + } CM_ARM_BOOT_ARCH_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmBootArchInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_BOOT_ARCH_PARSER_H_ --=20 2.25.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 (#83961): https://edk2.groups.io/g/devel/message/83961 Mute This Topic: https://groups.io/mt/87263317/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- From nobody Thu Mar 28 21:22:26 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+83962+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+83962+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687366; cv=none; d=zohomail.com; s=zohoarc; b=aujkybyO09+QfA0i7EsrUNzF2m47njKPDtaw/yO7VxbK5LwcRuRRBDa72Nb3Rgn7jFSHIFoSXuB0meeDjA0Mg+S/B6ZYyT7oOuC5kUs3eJwq3fVj65dWSKs2zotjx3sjUStjJJMHmyeasBmy/IBFcT6GrzpjmkZmb2YxUEJIfLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687366; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3A3r74PXxPFKdE5geU3PQPst+l61eFn9IPdve7piY70=; b=AfisfqJrcLYuPORjx7T0yguxvxu8pU9dzoE7YYrR3D59NmnM+SQbdSrhc4A1crzdKWvt1qKCigOJpo1aTyIzyX1hUrpiy7b7RPWNjuSwZ1FajHIVs0gcJDjg5tj5UHQnka8SNEpZLkoc/xoP55fi6caQcGfhMl/RsXu7ujjg5oQ= 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+83962+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 1637687366924473.81309114885516; Tue, 23 Nov 2021 09:09:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ROvlYY1788612xEoINLuP3ba; Tue, 23 Nov 2021 09:09:24 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14276.1637687361830582104 for ; Tue, 23 Nov 2021 09:09:22 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 71DA31063; Tue, 23 Nov 2021 09:09:21 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BAD8F3F5A1; Tue, 23 Nov 2021 09:09:20 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 05/15] DynamicTablesPkg: FdtHwInfoParser: Generic Timer Parser Date: Tue, 23 Nov 2021 18:08:28 +0100 Message-Id: <20211123170838.143805-6-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: e6UiPMME8148ORd4n3n76uBfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687364; bh=4K+fozP7y37nunhQ0TzW1O4StVDOqf05fD2RlfhlFoI=; h=Cc:Date:From:Reply-To:Subject:To; b=R4snBrcqJhnFtq07kzR/M4/OLrsUOtHOYNuryaNQKM5us9s3RGpBHsiqeQwi4r0hgAI ZdBq9H0f0sM1PRBqnzhfYAVZn2oVI0oGe0mIcD9H6u8qXKTGGGk1bPei3QZS3NHY773OU KXw4W7Xv86foEk2P1yACE8LtSsN9tp19Lh4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687367392100013 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The Generic Timer Description Table (GTDT) is a mandatory table required for booting a standards-based operating system. It provides an OSPM with information about a system's Generic Timer configuration. The Generic Timer (GT) is a standard timer interface implemented on ARM processor-based systems. The GTDT provides OSPM with information about a system's GT interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers. The Generic Timer information is described in the platform Device Tree. The Device Tree bindings for the Generic timers can be found at: - linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml The FdtHwInfoParser implements a Generic Timer Parser that parses the platform Device Tree to create a CM_ARM_GENERIC_TIMER_INFO object. The CM_ARM_GENERIC_TIMER_INFO object is encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the GTDT table. Note: The Generic Timer Parser currently does not support parsing of memory-mapped platform timers. Signed-off-by: Pierre Gondois --- .../GenericTimer/ArmGenericTimerParser.c | 254 ++++++++++++++++++ .../GenericTimer/ArmGenericTimerParser.h | 66 +++++ 2 files changed, 320 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTime= r/ArmGenericTimerParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTime= r/ArmGenericTimerParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGe= nericTimerParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTim= er/ArmGenericTimerParser.c new file mode 100644 index 000000000000..e7095396a5a8 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTi= merParser.c @@ -0,0 +1,254 @@ +/** @file + Arm generic timer parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml +**/ + +#include "FdtHwInfoParser.h" +#include "CmObjectDescUtility.h" +#include "GenericTimer/ArmGenericTimerParser.h" +#include "Gic/ArmGicDispatcher.h" + +/** List of "compatible" property values for timer nodes. + + Other "compatible" values are not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR TimerCompatibleStr[] =3D { + {"arm,armv7-timer"}, + {"arm,armv8-timer"} +}; + +/** Timer compatiblity information. +*/ +STATIC CONST COMPATIBILITY_INFO TimerCompatibleInfo =3D { + ARRAY_SIZE (TimerCompatibleStr), + TimerCompatibleStr +}; + +/** Parse a timer node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] TimerNode Offset of a timer node. + @param [in] GenericTimerInfo The CM_ARM_BOOT_ARCH_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +TimerNodeParser ( + IN CONST VOID * Fdt, + IN INT32 TimerNode, + IN CM_ARM_GENERIC_TIMER_INFO * GenericTimerInfo + ) +{ + EFI_STATUS Status; + CONST UINT32 * Data; + INT32 IntcNode; + UINT32 GicVersion; + INT32 DataSize; + INT32 IntCells; + BOOLEAN AlwaysOnTimer; + + if ((Fdt =3D=3D NULL) || + (GenericTimerInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Data =3D fdt_getprop (Fdt, TimerNode, "always-on", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < 0)) { + AlwaysOnTimer =3D FALSE; + } else { + AlwaysOnTimer =3D TRUE; + } + + // Get the associated interrupt-controller. + Status =3D FdtGetIntcParentNode (Fdt, TimerNode, &IntcNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Check that the interrupt-controller node is a Gic. + Status =3D GetGicVersion (Fdt, IntcNode, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Get the number of cells used to encode an interrupt. + Status =3D FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Data =3D fdt_getprop (Fdt, TimerNode, "interrupts", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize !=3D (FdtMaxTimerItem * IntCells * sizeof (UINT32)))) { + // If error or not FdtMaxTimerItem interrupts. + ASSERT (0); + return EFI_ABORTED; + } + + GenericTimerInfo->SecurePL1TimerGSIV =3D + FdtGetInterruptId (&Data[FdtSecureTimerIrq * IntCells]); + GenericTimerInfo->SecurePL1TimerFlags =3D + FdtGetInterruptFlags (&Data[FdtSecureTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL1TimerGSIV =3D + FdtGetInterruptId (&Data[FdtNonSecureTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL1TimerFlags =3D + FdtGetInterruptFlags (&Data[FdtNonSecureTimerIrq * IntCells]); + GenericTimerInfo->VirtualTimerGSIV =3D + FdtGetInterruptId (&Data[FdtVirtualTimerIrq * IntCells]); + GenericTimerInfo->VirtualTimerFlags =3D + FdtGetInterruptFlags (&Data[FdtVirtualTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL2TimerGSIV =3D + FdtGetInterruptId (&Data[FdtHypervisorTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL2TimerFlags =3D + FdtGetInterruptFlags (&Data[FdtHypervisorTimerIrq * IntCells]); + + if (AlwaysOnTimer) { + GenericTimerInfo->SecurePL1TimerFlags |=3D BIT2; + GenericTimerInfo->NonSecurePL1TimerFlags |=3D BIT2; + GenericTimerInfo->VirtualTimerFlags |=3D BIT2; + GenericTimerInfo->NonSecurePL2TimerFlags |=3D BIT2; + } + + // Setup default values + // The CntControlBase & CntReadBase Physical Address are optional if + // the system implements EL3 (Security Extensions). So, initialise + // these to their default value. + GenericTimerInfo->CounterControlBaseAddress =3D 0xFFFFFFFFFFFFFFFF; + GenericTimerInfo->CounterReadBaseAddress =3D 0xFFFFFFFFFFFFFFFF; + + // For systems not implementing ARMv8.1 VHE, this field is 0. + GenericTimerInfo->VirtualPL2TimerGSIV =3D 0; + GenericTimerInfo->VirtualPL2TimerFlags =3D 0; + + return EFI_SUCCESS; +} + +/** CM_ARM_GENERIC_TIMER_INFO parser function. + + The following structure is populated: + typedef struct CmArmGenericTimerInfo { + UINT64 CounterControlBaseAddress; // {default} + UINT64 CounterReadBaseAddress; // {default} + UINT32 SecurePL1TimerGSIV; // {Populated} + UINT32 SecurePL1TimerFlags; // {Populated} + UINT32 NonSecurePL1TimerGSIV; // {Populated} + UINT32 NonSecurePL1TimerFlags; // {Populated} + UINT32 VirtualTimerGSIV; // {Populated} + UINT32 VirtualTimerFlags; // {Populated} + UINT32 NonSecurePL2TimerGSIV; // {Populated} + UINT32 NonSecurePL2TimerFlags; // {Populated} + UINT32 VirtualPL2TimerGSIV; // {default} + UINT32 VirtualPL2TimerFlags; // {default} + } CM_ARM_GENERIC_TIMER_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGenericTimerInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 Index; + INT32 TimerNode; + UINT32 TimerNodeCount; + CM_ARM_GENERIC_TIMER_INFO GenericTimerInfo; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + Status =3D FdtCountCompatNodeInBranch ( + Fdt, + FdtBranch, + &TimerCompatibleInfo, + &TimerNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (TimerNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // Parse each timer node in the branch. + TimerNode =3D FdtBranch; + for (Index =3D 0; Index < TimerNodeCount; Index++) { + ZeroMem (&GenericTimerInfo, sizeof (CM_ARM_GENERIC_TIMER_INFO)); + + Status =3D FdtGetNextCompatNodeInBranch ( + Fdt, + FdtBranch, + &TimerCompatibleInfo, + &TimerNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Status =3D TimerNodeParser (Fdt, TimerNode, &GenericTimerInfo); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjGenericTimerInfo), + &GenericTimerInfo, + sizeof (CM_ARM_GENERIC_TIMER_INFO), + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGe= nericTimerParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTim= er/ArmGenericTimerParser.h new file mode 100644 index 000000000000..e1d294b3eea9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTi= merParser.h @@ -0,0 +1,66 @@ +/** @file + Arm generic timer parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml +**/ + +#ifndef ARM_GENERIC_TIMER_PARSER_H_ +#define ARM_GENERIC_TIMER_PARSER_H_ + +/** An enum listing the FDT interrupt items. +*/ +typedef enum FdtTimerInterruptItems { + FdtSecureTimerIrq, ///< Secure timer IRQ + FdtNonSecureTimerIrq, ///< Non-secure timer IRQ + FdtVirtualTimerIrq, ///< Virtual timer IRQ + FdtHypervisorTimerIrq, ///< Hypervisor timer IRQ + FdtMaxTimerItem ///< Max timer item +} FDT_TIMER_INTERRUPT_ITEMS; + +/** CM_ARM_BOOT_ARCH_INFO parser function. + + The following structure is populated: + typedef struct CmArmGenericTimerInfo { + UINT64 CounterControlBaseAddress; // {default} + UINT64 CounterReadBaseAddress; // {default} + UINT32 SecurePL1TimerGSIV; // {Populated} + UINT32 SecurePL1TimerFlags; // {Populated} + UINT32 NonSecurePL1TimerGSIV; // {Populated} + UINT32 NonSecurePL1TimerFlags; // {Populated} + UINT32 VirtualTimerGSIV; // {Populated} + UINT32 VirtualTimerFlags; // {Populated} + UINT32 NonSecurePL2TimerGSIV; // {Populated} + UINT32 NonSecurePL2TimerFlags; // {Populated} + UINT32 VirtualPL2TimerGSIV; // {default} + UINT32 VirtualPL2TimerFlags; // {default} + } CM_ARM_GENERIC_TIMER_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGenericTimerInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GENERIC_TIMER_PARSER_H_ --=20 2.25.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 (#83962): https://edk2.groups.io/g/devel/message/83962 Mute This Topic: https://groups.io/mt/87263319/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- From nobody Thu Mar 28 21:22:26 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+83963+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+83963+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687367; cv=none; d=zohomail.com; s=zohoarc; b=B8ljb7ErpqjRwHfZAFfYQkTbOFN9/AVEzY7Q/h6Lj8HWQ32PW4zCWKZVupBjq4EYBElUOXTX8u5IWBXsgZyenMFY/R42L1AgeG2hHoq69ipmgMcOcKwFpA2BW2rzoNW3M8VyXVYMz7dc2gNGupxZKh40A3sykHj5Kvmh5oQj+q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687367; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=s4SfTtCa76YCIF/z4vRzZ36jHjhy7NTDTqjSjKz6wm0=; b=hNyoViyUjWEWnMgWAIvfCWkl6UxxI3WATTBSrqlqkYAgLunpHpgFmMqM06WfU7C8HmI4hnzl4Fjf35rBvyKZpV/Qk0pdSG6SklKUNgDfZH5naWQQcpDs/JuJMwBun5hYCw5DbQd9PFUXaWAhyBJ9fwJIH2xQDAp3XQtQrASm8ek= 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+83963+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 1637687367441452.55667308174566; Tue, 23 Nov 2021 09:09:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id C53aYY1788612xo4eGOTD2SJ; Tue, 23 Nov 2021 09:09:27 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.14320.1637687363037740081 for ; Tue, 23 Nov 2021 09:09:23 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B72AC1FB; Tue, 23 Nov 2021 09:09:22 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D20D73F5A1; Tue, 23 Nov 2021 09:09:21 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 06/15] DynamicTablesPkg: FdtHwInfoParser: Add Serial port parser Date: Tue, 23 Nov 2021 18:08:29 +0100 Message-Id: <20211123170838.143805-7-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: BcvHgd7wBOMpZF8te76UF76px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687367; bh=DWcVVFGz+qXEQoexkmIDs/VG6yr1Ipgx4yeVjN0QA3s=; h=Cc:Date:From:Reply-To:Subject:To; b=uz6N0Cg5zyY76sEzt8/RN5zbKXOwJcugP38bQjyx5WpBtyg6fY28rKFfNy/IhbH+U5x k8eJafYmD9sfVOu2vGQapNH7rx+CVgOCm02b8fPgnS+SwbjxK9cQCDJqBrXZn4DAJdioY dhC9Y6PWrmzUvQ5O3+GgQP2EpfpiN0yMbU0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687369413100015 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The Microsoft Debug Port Table 2 (DBG2), the Serial Port Console Redirector (SPCR) table are mandatory tables required for booting a standards-based operating system. The DBG2 table is used by the OS debugger while the SPCR table is used to configure the serial terminal. Additionally, the serial ports available on a platform for generic use also need to be described in DSDT/SSDT for an OS to be able to use the serial ports. The Arm Base System Architecture 1.0 specification a lists of supported serial port hardware for Arm Platforms. This list includes the following serial port UARTs: - SBSA/Generic UART - a fully 16550 compatible UART. Along, with these the PL011 UART is the most commonly used serial port hardware on Arm platforms. The serial port hardware information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/serial/serial.yaml - linux/Documentation/devicetree/bindings/serial/8250.txt - linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt - linux/Documentation/devicetree/bindings/serial/pl011.yaml The FdtHwInfoParser implements a Serial Port Parser that parses the platform Device Tree to create CM_ARM_SERIAL_PORT_INFO objects with the following IDs: - EArmObjSerialConsolePortInfo (for use by SPCR) - EArmObjSerialDebugPortInfo (for use by DBG2) - EArmObjSerialPortInfo (for use as generic Serial Ports) The Serial Port for use by SPCR is selected by parsing the Device Tree for the '/chosen' node with the 'stdout-path' property. The next Serial Port is selected for use as the Debug Serial Port and the remaining serial ports are used as generic serial ports. The CM_ARM_SERIAL_PORT_INFO objects are encapsulated in Configuration Manager descriptor objects with the respective IDs and are added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the DBG2, SPCR and the SSDT serial port tables. Signed-off-by: Pierre Gondois --- Notes: v2: - Add pl011 compatible string in serial port parser. [Sami] - Use 16550_with_GAS ID when 16550 is detected in serial port parser. [Sami] v3: - Remove trailing whitespace. [Pierre] .../Serial/ArmSerialPortParser.c | 620 ++++++++++++++++++ .../Serial/ArmSerialPortParser.h | 47 ++ 2 files changed, 667 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmS= erialPortParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmS= erialPortParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPo= rtParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPo= rtParser.c new file mode 100644 index 000000000000..b05b04da41a6 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParse= r.c @@ -0,0 +1,620 @@ +/** @file + Arm Serial Port Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/serial/serial.yaml + - linux/Documentation/devicetree/bindings/serial/8250.txt + - linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt + - linux/Documentation/devicetree/bindings/serial/pl011.yaml +**/ + +#include + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Serial/ArmSerialPortParser.h" + +/** List of "compatible" property values for serial port nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR SerialCompatibleStr[] =3D { + {"ns16550a"}, + {"arm,sbsa-uart"}, + {"arm,pl011"} +}; + +/** COMPATIBILITY_INFO structure for the SerialCompatible. +*/ +CONST COMPATIBILITY_INFO SerialCompatibleInfo =3D { + ARRAY_SIZE (SerialCompatibleStr), + SerialCompatibleStr +}; + +/** 16550 UART compatible strings. + + Any string of this list must be part of SerialCompatible. +*/ +STATIC CONST COMPATIBILITY_STR Serial16550CompatibleStr[] =3D { + {"ns16550a"} +}; + +/** COMPATIBILITY_INFO structure for the Serial16550Compatible. +*/ +CONST COMPATIBILITY_INFO Serial16550CompatibleInfo =3D { + ARRAY_SIZE (Serial16550CompatibleStr), + Serial16550CompatibleStr +}; + +/** SBSA UART compatible strings. + + Include PL011 as SBSA uart is a subset of PL011. + + Any string of this list must be part of SerialCompatible. +*/ +STATIC CONST COMPATIBILITY_STR SerialSbsaCompatibleStr[] =3D { + {"arm,sbsa-uart"}, + {"arm,pl011"} +}; + +/** COMPATIBILITY_INFO structure for the SerialSbsaCompatible. +*/ +CONST COMPATIBILITY_INFO SerialSbsaCompatibleInfo =3D { + ARRAY_SIZE (SerialSbsaCompatibleStr), + SerialSbsaCompatibleStr +}; + +/** Parse a serial port node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] SerialPortNode Offset of a serial-port node. + @param [in] SerialPortInfo The CM_ARM_SERIAL_PORT_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +SerialPortNodeParser ( + IN CONST VOID * Fdt, + IN INT32 SerialPortNode, + IN CM_ARM_SERIAL_PORT_INFO * SerialPortInfo + ) +{ + EFI_STATUS Status; + INT32 IntcNode; + CONST UINT8 * SizeValue; + + INT32 AddressCells; + INT32 SizeCells; + INT32 IntCells; + + CONST UINT8 * Data; + INT32 DataSize; + UINT8 AccessSize; + + if ((Fdt =3D=3D NULL) || + (SerialPortInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D FdtGetParentAddressInfo ( + Fdt, + SerialPortNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, SerialPortNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < (INT32)(sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells)) - 1)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + if (AddressCells =3D=3D 2) { + SerialPortInfo->BaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + SerialPortInfo->BaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + + SizeValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_SIZE_OFFSET (0, AddressCells, SizeCells)); + if (SizeCells =3D=3D 2) { + SerialPortInfo->BaseAddressLength =3D fdt64_to_cpu (*(UINT64*)SizeValu= e); + } else { + SerialPortInfo->BaseAddressLength =3D fdt32_to_cpu (*(UINT32*)SizeValu= e); + } + + // Get the associated interrupt-controller. + Status=3D FdtGetIntcParentNode (Fdt, SerialPortNode, &IntcNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + // Get the number of cells used to encode an interrupt. + Status =3D FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Data =3D fdt_getprop (Fdt, SerialPortNode, "interrupts", &DataSize); + if ((Data =3D=3D NULL) || (DataSize !=3D (IntCells * sizeof (UINT32)))) { + // If error or not 1 interrupt. + ASSERT (0); + return EFI_ABORTED; + } + + SerialPortInfo->Interrupt =3D FdtGetInterruptId ((CONST UINT32*)Data); + + // Note: clock-frequency is optional for SBSA UART. + Data =3D fdt_getprop (Fdt, SerialPortNode, "clock-frequency", &DataSize); + if (Data !=3D NULL) { + if (DataSize < sizeof (UINT32)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } else if (fdt_node_offset_by_phandle (Fdt, fdt32_to_cpu (*Data)) >=3D= 0) { + // "clock-frequency" can be a "clocks phandle to refer to the clk us= ed". + // This is not supported. + ASSERT (0); + return EFI_UNSUPPORTED; + } + SerialPortInfo->Clock =3D fdt32_to_cpu (*(UINT32*)Data); + } + + if (FdtNodeIsCompatible (Fdt, SerialPortNode, &Serial16550CompatibleInfo= )) { + SerialPortInfo->PortSubtype =3D + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS; + + /* reg-io-width: + description: | + The size (in bytes) of the IO accesses that should be performed o= n the + device. There are some systems that require 32-bit accesses to the + UART. + */ + Data =3D fdt_getprop (Fdt, SerialPortNode, "reg-io-width", &DataSize); + if (Data !=3D NULL) { + if (DataSize < sizeof (UINT32)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + AccessSize =3D fdt32_to_cpu (*(UINT32*)Data); + if (AccessSize > EFI_ACPI_6_3_QWORD) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + SerialPortInfo->AccessSize =3D AccessSize; + } else { + // 8250/16550 defaults to byte access. + SerialPortInfo->AccessSize =3D EFI_ACPI_6_3_BYTE; + } + } else if (FdtNodeIsCompatible ( + Fdt, + SerialPortNode, + &SerialSbsaCompatibleInfo + )) { + SerialPortInfo->PortSubtype =3D + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART; + } else { + ASSERT (0); + return EFI_UNSUPPORTED; + } + + // Set Baudrate to 115200 by default + SerialPortInfo->BaudRate =3D 115200; + return EFI_SUCCESS; +} + +/** Find the console serial-port node in the DT. + + This function fetches the node referenced in the "stdout-path" + property of the "chosen" node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fd= t). + @param [out] SerialConsoleNode If success, contains the node offset + of the console serial-port node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSerialConsoleNode ( + IN CONST VOID * Fdt, + OUT INT32 * SerialConsoleNode + ) +{ + CONST CHAR8 * Prop; + INT32 PropSize; + CONST CHAR8 * Path; + INT32 PathLen; + INT32 ChosenNode; + + if ((Fdt =3D=3D NULL) || + (SerialConsoleNode =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // The "chosen" node resides at the the root of the DT. Fetch it. + ChosenNode =3D fdt_path_offset (Fdt, "/chosen"); + if (ChosenNode < 0) { + return EFI_NOT_FOUND; + } + + Prop =3D fdt_getprop (Fdt, ChosenNode, "stdout-path", &PropSize); + if ((Prop =3D=3D NULL) || (PropSize < 0)) { + return EFI_NOT_FOUND; + } + + // Determine the actual path length, as a colon terminates the path. + Path =3D ScanMem8 (Prop, ':', PropSize); + if (Path =3D=3D NULL) { + PathLen =3D (UINT32)AsciiStrLen (Prop); + } else { + PathLen =3D (INT32)(Path - Prop); + } + + // Aliases cannot start with a '/', so it must be the actual path. + if (Prop[0] =3D=3D '/') { + *SerialConsoleNode =3D fdt_path_offset_namelen (Fdt, Prop, PathLen); + return EFI_SUCCESS; + } + + // Lookup the alias, as this contains the actual path. + Path =3D fdt_get_alias_namelen (Fdt, Prop, PathLen); + if (Path =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + *SerialConsoleNode =3D fdt_path_offset (Fdt, Path); + return EFI_SUCCESS; +} + +/** CM_ARM_SERIAL_PORT_INFO dispatcher function (for a generic serial-port= ). + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] GenericSerialInfo Pointer to a serial port info list. + @param [in] NodeCount Count of serial ports to dispatch. + @param [in] SerialObjectId Serial port object ID. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmSerialPortInfoDispatch ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo, + IN INT32 NodeCount, + IN EARM_OBJECT_ID SerialObjectId +) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR * NewCmObjDesc; + + if ((GenericSerialInfo =3D=3D NULL) || (NodeCount =3D=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if ((SerialObjectId !=3D EArmObjSerialPortInfo) && + (SerialObjectId !=3D EArmObjSerialDebugPortInfo) && + (SerialObjectId !=3D EArmObjSerialConsolePortInfo)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Dispatch the Generic Serial ports + Status =3D CreateCmObjDesc ( + CREATE_CM_ARM_OBJECT_ID (SerialObjectId), + NodeCount, + GenericSerialInfo, + sizeof (CM_ARM_SERIAL_PORT_INFO) * NodeCount, + &NewCmObjDesc + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add all the CmObjs to the Configuration Manager. + Status =3D AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL); + ASSERT_EFI_ERROR (Status); + FreeCmObjDesc (NewCmObjDesc); + return Status; +} + +/** CM_ARM_SERIAL_PORT_INFO parser function (for debug/console serial-port= ). + + This parser expects FdtBranch to be the debug serial-port node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmSerialPortInfo { + UINT64 BaseAddress; // {Populated} + UINT32 Interrupt; // {Populated} + UINT64 BaudRate; // {default} + UINT32 Clock; // {Populated} + UINT16 PortSubtype; // {Populated} + UINT64 BaseAddressLength // {Populated} + } CM_ARM_SERIAL_PORT_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + @param [in] SerialObjectId ArmNamespace Object ID for the serial port. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmSerialPortInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch, + IN EARM_OBJECT_ID SerialObjectId + ) +{ + EFI_STATUS Status; + CM_ARM_SERIAL_PORT_INFO SerialInfo; + + if ((SerialObjectId !=3D EArmObjSerialDebugPortInfo) && + (SerialObjectId !=3D EArmObjSerialConsolePortInfo)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ZeroMem (&SerialInfo, sizeof (SerialInfo)); + + Status =3D SerialPortNodeParser ( + FdtParserHandle->Fdt, + FdtBranch, + &SerialInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D ArmSerialPortInfoDispatch ( + FdtParserHandle, + &SerialInfo, + 1, + SerialObjectId + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** SerialPort dispatcher. + + This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for + the following CM_OBJ_ID: + - EArmObjSerialConsolePortInfo + - EArmObjSerialDebugPortInfo + - EArmObjSerialPortInfo + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +SerialPortDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 SerialConsoleNode; + INT32 SerialDebugNode; + INT32 SerialNode; + UINT32 Index; + UINT32 SerialNodeCount; + UINT32 SerialNodesRemaining; + CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo; + UINT32 GenericSerialIndex; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + // Count the number of serial-ports. + Status =3D FdtCountCompatNodeInBranch ( + Fdt, + FdtBranch, + &SerialCompatibleInfo, + &SerialNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (SerialNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // Track remaining nodes separately as SerialNodeCount + // is used in for loop below and reducing SerialNodeCount + // would result in the Generic Serial port nodes not + // being found if the serial console port node is among + // the first few serial nodes. + SerialNodesRemaining =3D SerialNodeCount; + + // Identify the serial console port. + Status =3D GetSerialConsoleNode (Fdt, &SerialConsoleNode); + if (Status =3D=3D EFI_NOT_FOUND) { + // No serial console. + SerialConsoleNode =3D -1; + } else if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } else { + // Parse the console serial-port. + Status =3D ArmSerialPortInfoParser ( + FdtParserHandle, + SerialConsoleNode, + EArmObjSerialConsolePortInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + SerialNodesRemaining--; + } + + GenericSerialInfo =3D NULL; + if (SerialNodesRemaining > 1) { + // We have more than one serial port remaining. + // This means that the first serial port will + // be reserved as a debug port, and the remaining + // will be for general purpose use. + SerialNodesRemaining--; + GenericSerialInfo =3D AllocateZeroPool ( + SerialNodesRemaining * + sizeof (CM_ARM_SERIAL_PORT_INFO) + ); + if (GenericSerialInfo =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + } + + SerialNode =3D FdtBranch; + SerialDebugNode =3D -1; + GenericSerialIndex =3D 0; + for (Index =3D 0; Index < SerialNodeCount; Index++) { + // Search the next serial-port node in the branch. + Status =3D FdtGetNextCompatNodeInBranch ( + Fdt, + FdtBranch, + &SerialCompatibleInfo, + &SerialNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + goto exit_handler; + } + + // Ignore the serial console node. + if (SerialNode =3D=3D SerialConsoleNode) { + continue; + } else if (SerialDebugNode =3D=3D -1) { + // The first serial-port node, not being the console serial-port, + // will be the debug serial-port. + SerialDebugNode =3D SerialNode; + Status =3D ArmSerialPortInfoParser ( + FdtParserHandle, + SerialDebugNode, + EArmObjSerialDebugPortInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } else { + if (GenericSerialInfo =3D=3D NULL) { + // Should not be possible. + ASSERT (0); + Status =3D EFI_ABORTED; + goto exit_handler; + } + + Status =3D SerialPortNodeParser ( + Fdt, + SerialNode, + &GenericSerialInfo[GenericSerialIndex++] + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } + } // for + + if (GenericSerialIndex > 0) { + Status =3D ArmSerialPortInfoDispatch ( + FdtParserHandle, + GenericSerialInfo, + GenericSerialIndex, + EArmObjSerialPortInfo + ); + } + +exit_handler: + if (GenericSerialInfo !=3D NULL) { + FreePool (GenericSerialInfo); + } + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPo= rtParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPo= rtParser.h new file mode 100644 index 000000000000..5e4707849e39 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParse= r.h @@ -0,0 +1,47 @@ +/** @file + Arm Serial Port Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/serial/serial.yaml + - linux/Documentation/devicetree/bindings/serial/8250.txt +**/ + +#ifndef ARM_SERIAL_PORT_PARSER_H_ +#define ARM_SERIAL_PORT_PARSER_H_ + +/** SerialPort dispatcher. + + This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for + the following CM_OBJ_ID: + - EArmObjSerialConsolePortInfo + - EArmObjSerialDebugPortInfo + - EArmObjSerialPortInfo + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +SerialPortDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_SERIAL_PORT_PARSER_H_ --=20 2.25.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 (#83963): https://edk2.groups.io/g/devel/message/83963 Mute This Topic: https://groups.io/mt/87263320/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- From nobody Thu Mar 28 21:22:26 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+83964+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+83964+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687370; cv=none; d=zohomail.com; s=zohoarc; b=Ushtzx9ETiwdNX22Vsp91SgBpDD6sNc+2W2dvTZzd+fKcv6cfxT6GXNwnNX/ywecnvf6Ha/XFO6NqX3DlMGu3vlrWI9Yoze8Icp+t4pKJ3l8VQyOnxZbJZ7lTydM5xV3EhXt57YXI66pcxc4rt6frWZZw0RSd/rJhFrwVdjAt8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687370; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gIigmcbWRWzFYU66KqRuKLjT3kpKVxZxJqjcBNPUKwg=; b=BuM0N+xouT/rmaPLlDr5XFC2XDgru7iQirYRSzucH0KtM0cxrbKTA/HE0SagsXLeN1hIXPjDpH9fZYKq8IWmtzYQcViDUXTlfke0J1FLpKb0aWGtv5HkcxXqVz0VVe0KAOWj9e2uGHwjdgzhSZqNnmPvlV3MTeIMbgrSWRxts3Y= 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+83964+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 1637687370772752.6118593963656; Tue, 23 Nov 2021 09:09:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id C2nBYY1788612xgBnqTBEVRH; Tue, 23 Nov 2021 09:09:28 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.14320.1637687364261964236 for ; Tue, 23 Nov 2021 09:09:24 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF4091063; Tue, 23 Nov 2021 09:09:23 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 15C6B3F5A1; Tue, 23 Nov 2021 09:09:22 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 07/15] DynamicTablesPkg: FdtHwInfoParser: Add GICC parser Date: Tue, 23 Nov 2021 18:08:30 +0100 Message-Id: <20211123170838.143805-8-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: YDQyvjcUUyE6jNCxiWHpaSurx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687368; bh=ao4s6TFPOR2ob1z8O2CeYvm8bLAlRrzU+Scd60pyxrk=; h=Cc:Date:From:Reply-To:Subject:To; b=Yp4yEqRZbmr2pjw/K8qymgqgViHVGpjzb4zyL74d0fCtNTEoKpekuGPdZ8DF+F+YT1m 3qYhoBANjeAv6U3GHqesxk9BvNLTiDswt0nR341SGKMwlBxDH6Sc1uyPpRKkR+hj52CQR RSyp8AVeeMaa2lS3YeiAiTibC832PcN1LV8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687372392100023 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The GIC CPU Interface (GICC) structure is part of the Multiple APIC Description Table (MADT) that describes the interrupt model for the platform. The MADT table is a mandatory table required for booting a standards-based operating system. Arm requires the GIC interrupt model, in which the logical processors are required to have a Processor Device object in the DSDT, and must convey each processor's GIC information to the OS using the GICC structure. The CPU and GIC information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/arm/cpus.yaml - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic.yaml - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic-v3.yaml The FdtHwInfoParser implements a GIC CPU Interface Parser that parses the platform Device Tree to create CM_ARM_GICC_INFO objects which are encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MADT and the SSDT CPU information tables. Signed-off-by: Pierre Gondois --- Notes: v2: - Handle Affinity3 field in GicC parser. [Sami] v3: - Populate the 64 bits of the MPIDR field of the GicC CmObj. [Sami] .../FdtHwInfoParserLib/Gic/ArmGicCParser.c | 769 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicCParser.h | 67 ++ 2 files changed, 836 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicC= Parser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicC= Parser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.= c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c new file mode 100644 index 000000000000..7c221697975b --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c @@ -0,0 +1,769 @@ +/** @file + Arm Gic cpu parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/arm/cpus.yaml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "FdtHwInfoParser.h" +#include "CmObjectDescUtility.h" +#include "Gic/ArmGicCParser.h" +#include "Gic/ArmGicDispatcher.h" + +/** List of "compatible" property values for CPU nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR CpuCompatibleStr[] =3D { + {"arm,arm-v7"}, + {"arm,arm-v8"}, + {"arm,cortex-a15"}, + {"arm,cortex-a7"}, + {"arm,cortex-a57"} +}; + +/** COMPATIBILITY_INFO structure for CPU nodes. +*/ +STATIC CONST COMPATIBILITY_INFO CpuCompatibleInfo =3D { + ARRAY_SIZE (CpuCompatibleStr), + CpuCompatibleStr +}; + +/** Parse a "cpu" node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] CpuNode Offset of a cpu node. + @param [in] GicVersion Version of the GIC. + @param [in] AddressCells Number of address cells used for the reg + property. + @param [out] GicCInfo CM_ARM_GICC_INFO structure to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +CpuNodeParser ( + IN CONST VOID * Fdt, + IN INT32 CpuNode, + IN UINT32 GicVersion, + IN UINT32 AddressCells, + OUT CM_ARM_GICC_INFO * GicCInfo +) +{ + CONST UINT8 * Data; + INT32 DataSize; + UINT32 ProcUid; + UINT64 MpIdr; + UINT64 CheckAffMask; + + MpIdr =3D 0; + CheckAffMask =3D ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2; + + if (GicCInfo =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Data =3D fdt_getprop (Fdt, CpuNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + ((DataSize !=3D sizeof (UINT32)) && + (DataSize !=3D sizeof (UINT64)))) { + ASSERT (0); + return EFI_ABORTED; + } + + /* If cpus node's #address-cells property is set to 2 + The first reg cell bits [7:0] must be set to + bits [39:32] of MPIDR_EL1. + The second reg cell bits [23:0] must be set to + bits [23:0] of MPIDR_EL1. + */ + if (AddressCells =3D=3D 2) { + MpIdr =3D fdt64_to_cpu (*((UINT64*)Data)); + CheckAffMask |=3D ARM_CORE_AFF3; + } else { + MpIdr =3D fdt32_to_cpu (*((UINT32*)Data)); + } + + if ((MpIdr & ~CheckAffMask) !=3D 0) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // To fit the Affinity [0-3] a 32bits value, place the Aff3 on bits + // [31:24] instead of their original place ([39:32]). + ProcUid =3D MpIdr | ((MpIdr & ARM_CORE_AFF3) >> 8); + + /* ACPI 6.3, s5.2.12.14 GIC CPU Interface (GICC) Structure: + GIC 's CPU Interface Number. In GICv1/v2 implementations, + this value matches the bit index of the associated processor + in the GIC distributor's GICD_ITARGETSR register. For + GICv3/4 implementations this field must be provided by the + platform, if compatibility mode is supported. If it is not supported + by the implementation, then this field must be zero. + + Note: We do not support compatibility mode for GicV3 + */ + if (GicVersion =3D=3D 2) { + GicCInfo->CPUInterfaceNumber =3D ProcUid; + } else { + GicCInfo->CPUInterfaceNumber =3D 0; + } + + GicCInfo->AcpiProcessorUid =3D ProcUid; + GicCInfo->Flags =3D EFI_ACPI_6_3_GIC_ENABLED; + GicCInfo->MPIDR=3D MpIdr; + + return EFI_SUCCESS; +} + +/** Parse a "cpus" node and its children "cpu" nodes. + + Create as many CM_ARM_GICC_INFO structures as "cpu" nodes. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] CpusNode Offset of a cpus node. + @param [in] GicVersion Version of the GIC. + @param [out] NewGicCmObjDesc If success, CM_OBJ_DESCRIPTOR containing + all the created CM_ARM_GICC_INFO. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +CpusNodeParser ( + IN CONST VOID * Fdt, + IN INT32 CpusNode, + IN UINT32 GicVersion, + OUT CM_OBJ_DESCRIPTOR ** NewGicCmObjDesc + ) +{ + EFI_STATUS Status; + INT32 CpuNode; + UINT32 CpuNodeCount; + INT32 AddressCells; + + UINT32 Index; + CM_ARM_GICC_INFO * GicCInfoBuffer; + UINT32 GicCInfoBufferSize; + + if (NewGicCmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + AddressCells =3D fdt_address_cells (Fdt, CpusNode); + if (AddressCells < 0) { + ASSERT (0); + return EFI_ABORTED; + } + + // Count the number of "cpu" nodes under the "cpus" node. + Status =3D FdtCountNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNodeCoun= t); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (CpuNodeCount =3D=3D 0) { + ASSERT (0); + return EFI_NOT_FOUND; + } + + // Allocate memory for CpuNodeCount CM_ARM_GICC_INFO structures. + GicCInfoBufferSize =3D CpuNodeCount * sizeof (CM_ARM_GICC_INFO); + GicCInfoBuffer =3D AllocateZeroPool (GicCInfoBufferSize); + if (GicCInfoBuffer =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + CpuNode =3D CpusNode; + for (Index =3D 0; Index < CpuNodeCount; Index++) { + Status =3D FdtGetNextNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNode= ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + goto exit_handler; + } + + // Parse the "cpu" node. + if (!FdtNodeIsCompatible (Fdt, CpuNode, &CpuCompatibleInfo)) { + ASSERT (0); + Status =3D EFI_UNSUPPORTED; + goto exit_handler; + } + + Status =3D CpuNodeParser ( + Fdt, + CpuNode, + GicVersion, + AddressCells, + &GicCInfoBuffer[Index] + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } // for + + Status =3D CreateCmObjDesc ( + CREATE_CM_ARM_OBJECT_ID (EArmObjGicCInfo), + CpuNodeCount, + GicCInfoBuffer, + GicCInfoBufferSize, + NewGicCmObjDesc + ); + ASSERT_EFI_ERROR (Status); + +exit_handler: + FreePool (GicCInfoBuffer); + return Status; +} + +/** Parse a Gic compatible interrupt-controller node, + extracting GicC information generic to Gic v2 and v3. + + This function modifies a CM_OBJ_DESCRIPTOR object. + The following CM_ARM_GICC_INFO fields are patched: + - VGICMaintenanceInterrupt; + - Flags; + + @param [in] Fdt Pointer to a Flattened Device Tree (F= dt). + @param [in] GicIntcNode Offset of a Gic compatible + interrupt-controller node. + @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicCIntcNodeParser ( + IN CONST VOID * Fdt, + IN INT32 GicIntcNode, + IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc + ) +{ + EFI_STATUS Status; + INT32 IntCells; + CM_ARM_GICC_INFO * GicCInfo; + + CONST UINT8 * Data; + INT32 DataSize; + + if (GicCCmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the number of cells used to encode an interrupt. + Status =3D FdtGetInterruptCellsInfo (Fdt, GicIntcNode, &IntCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Get the GSIV maintenance interrupt. + // According to the DT bindings, this could be the: + // "Interrupt source of the parent interrupt controller on secondary GIC= s" + // but it is assumed that only one Gic is available. + Data =3D fdt_getprop (Fdt, GicIntcNode, "interrupts", &DataSize); + if ((Data !=3D NULL) && (DataSize =3D=3D (IntCells * sizeof (UINT32)))) { + GicCInfo =3D (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data; + GicCInfo->VGICMaintenanceInterrupt =3D + FdtGetInterruptId ((CONST UINT32*)Data); + GicCInfo->Flags =3D DT_IRQ_IS_EDGE_TRIGGERED ( + fdt32_to_cpu (((UINT32*)Data)[IRQ_FLAGS_OFFSET]) + ) ? + EFI_ACPI_6_3_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS= : + 0; + return Status; + } else if (DataSize < 0) { + // This property is optional and was not found. Just return. + return Status; + } + // The property exists and its size doesn't match for one interrupt. + ASSERT (0); + return EFI_ABORTED; +} + +/** Parse a Gic compatible interrupt-controller node, + extracting GicCv2 information. + + This function modifies a CM_OBJ_DESCRIPTOR object. + The following CM_ARM_GICC_INFO fields are patched: + - PhysicalAddress; + - GICH; + - GICV; + + @param [in] Fdt Pointer to a Flattened Device Tree (F= dt). + @param [in] Gicv2IntcNode Offset of a Gicv2 compatible + interrupt-controller node. + @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicCv2IntcNodeParser ( + IN CONST VOID * Fdt, + IN INT32 Gicv2IntcNode, + IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc + ) +{ + EFI_STATUS Status; + UINT32 Index; + CM_ARM_GICC_INFO * GicCInfo; + INT32 AddressCells; + INT32 SizeCells; + + CONST UINT8 * GicCValue; + CONST UINT8 * GicVValue; + CONST UINT8 * GicHValue; + + CONST UINT8 * Data; + INT32 DataSize; + UINT32 RegSize; + UINT32 RegCount; + + if (GicCCmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + GicCInfo =3D (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data; + GicVValue =3D NULL; + GicHValue =3D NULL; + + // Get the #address-cells and #size-cells property values. + Status =3D FdtGetParentAddressInfo ( + Fdt, + Gicv2IntcNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + RegSize =3D (AddressCells + SizeCells) * sizeof (UINT32); + + Data =3D fdt_getprop (Fdt, Gicv2IntcNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < 0) || + ((DataSize % RegSize) !=3D 0)) { + // If error or wrong size. + ASSERT (0); + return EFI_ABORTED; + } + + RegCount =3D DataSize/RegSize; + + switch (RegCount) { + case 4: + { + // GicV is at index 3 in the reg property. GicV is optional. + GicVValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET (3, AddressCells, SizeCells)); + // fall-through. + } + case 3: + { + // GicH is at index 2 in the reg property. GicH is optional. + GicHValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET (2, AddressCells, SizeCells)); + // fall-through. + } + case 2: + { + // GicC is at index 1 in the reg property. GicC is mandatory. + GicCValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells)); + break; + } + default: + { + // Not enough or too much information. + ASSERT (0); + return EFI_ABORTED; + } + } + + // Patch the relevant fields of the CM_ARM_GICC_INFO objects. + for (Index =3D 0; Index < GicCCmObjDesc->Count; Index++) { + if (AddressCells =3D=3D 2) { + GicCInfo[Index].PhysicalBaseAddress =3D fdt64_to_cpu (*(UINT64*)GicC= Value); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64*)GicHValue); + GicCInfo[Index].GICV =3D (GicVValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64*)GicVValue); + } else { + GicCInfo[Index].PhysicalBaseAddress =3D fdt32_to_cpu (*(UINT32*)GicC= Value); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32*)GicHValue); + GicCInfo[Index].GICV =3D (GicVValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32*)GicVValue); + } + } // for + + return EFI_SUCCESS; +} + +/** Parse a Gic compatible interrupt-controller node, + extracting GicCv3 information. + + This function modifies a CM_OBJ_DESCRIPTOR object. + The following CM_ARM_GICC_INFO fields are patched: + - PhysicalAddress; + - GICH; + - GICV; + + @param [in] Fdt Pointer to a Flattened Device Tree (F= dt). + @param [in] Gicv3IntcNode Offset of a Gicv3 compatible + interrupt-controller node. + @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicCv3IntcNodeParser ( + IN CONST VOID * Fdt, + IN INT32 Gicv3IntcNode, + IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc + ) +{ + EFI_STATUS Status; + UINT32 Index; + CM_ARM_GICC_INFO * GicCInfo; + INT32 AddressCells; + INT32 SizeCells; + UINT32 AdditionalRedistReg; + + CONST UINT8 * GicCValue; + CONST UINT8 * GicVValue; + CONST UINT8 * GicHValue; + + CONST UINT8 * Data; + INT32 DataSize; + UINT32 RegSize; + UINT32 RegCount; + + if (GicCCmObjDesc =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + GicCInfo =3D (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data; + GicCValue =3D NULL; + GicVValue =3D NULL; + GicHValue =3D NULL; + + // Get the #address-cells and #size-cells property values. + Status =3D FdtGetParentAddressInfo ( + Fdt, + Gicv3IntcNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + // The "#redistributor-regions" property is optional. + Data =3D fdt_getprop (Fdt, Gicv3IntcNode, "#redistributor-regions", &Dat= aSize); + if ((Data !=3D NULL) && (DataSize =3D=3D sizeof (UINT32))) { + ASSERT (fdt32_to_cpu (*(UINT32*)Data) > 1); + AdditionalRedistReg =3D fdt32_to_cpu (*(UINT32*)Data) - 1; + } else { + AdditionalRedistReg =3D 0; + } + + RegSize =3D (AddressCells + SizeCells) * sizeof (UINT32); + + /* + Ref: linux/blob/master/Documentation/devicetree/bindings/ + interrupt-controller/arm%2Cgic-v3.yaml + + reg: + description: | + Specifies base physical address(s) and size of the GIC + registers, in the following order: + - GIC Distributor interface (GICD) + - GIC Redistributors (GICR), one range per redistributor region + - GIC CPU interface (GICC) + - GIC Hypervisor interface (GICH) + - GIC Virtual CPU interface (GICV) + GICC, GICH and GICV are optional. + minItems: 2 + maxItems: 4096 + */ + Data =3D fdt_getprop (Fdt, Gicv3IntcNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < 0) || + ((DataSize % RegSize) !=3D 0)) { + // If error or wrong size. + ASSERT (0); + return EFI_ABORTED; + } + + RegCount =3D (DataSize / RegSize) - AdditionalRedistReg; + + // The GicD and GicR info is mandatory. + switch (RegCount) { + case 5: + { + // GicV is at index 4 in the reg property. GicV is optional. + GicVValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET ( + 4 + AdditionalRedistReg, + AddressCells, + SizeCells + )); + // fall-through. + } + case 4: + { + // GicH is at index 3 in the reg property. GicH is optional. + GicHValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET ( + 3 + AdditionalRedistReg, + AddressCells, + SizeCells + )); + // fall-through. + } + case 3: + { + // GicC is at index 2 in the reg property. GicC is optional. + // Even though GicC is optional, it is made mandatory in this parser. + GicCValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET ( + 2 + AdditionalRedistReg, + AddressCells, + SizeCells + )); + // fall-through + } + case 2: + { + // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object. + // GicD is described by the CM_ARM_GICD_INFO object. + break; + } + default: + { + // Not enough or too much information. + ASSERT (0); + return EFI_ABORTED; + } + } + + // Patch the relevant fields of the CM_ARM_GICC_INFO objects. + if (AddressCells =3D=3D 2) { + for (Index =3D 0; Index < GicCCmObjDesc->Count; Index++) { + // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object. + GicCInfo[Index].GICRBaseAddress =3D 0; + GicCInfo[Index].PhysicalBaseAddress =3D (GicCValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64*)GicCValue); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64*)GicHValue); + GicCInfo[Index].GICV =3D (GicVValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64*)GicVValue); + } + } else { + for (Index =3D 0; Index < GicCCmObjDesc->Count; Index++) { + // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object. + GicCInfo[Index].GICRBaseAddress =3D 0; + GicCInfo[Index].PhysicalBaseAddress =3D (GicCValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32*)GicCValue); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32*)GicHValue); + GicCInfo[Index].GICV =3D (GicVValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32*)GicVValue); + } + } + + return EFI_SUCCESS; +} + +/** CM_ARM_GICC_INFO parser function. + + This parser expects FdtBranch to be the "\cpus" node node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmGicCInfo { + UINT32 CPUInterfaceNumber; // {Populated} + UINT32 AcpiProcessorUid; // {Populated} + UINT32 Flags; // {Populated} + UINT32 ParkingProtocolVersion; // {default =3D 0} + UINT32 PerformanceInterruptGsiv; // {default =3D 0} + UINT64 ParkedAddress; // {default =3D 0} + UINT64 PhysicalBaseAddress; // {Populated} + UINT64 GICV; // {Populated} + UINT64 GICH; // {Populated} + UINT32 VGICMaintenanceInterrupt; // {Populated} + UINT64 GICRBaseAddress; // {default =3D 0} + UINT64 MPIDR; // {Populated} + UINT8 ProcessorPowerEfficiencyClass; // {default =3D 0} + UINT16 SpeOverflowInterrupt; // {default =3D 0} + UINT32 ProximityDomain; // {default =3D 0} + UINT32 ClockDomain; // {default =3D 0} + UINT32 AffinityFlags; // {default =3D 0} + } CM_ARM_GICC_INFO; + + The pmu information can be found in the pmu node. There is no support + for now. + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicCInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 IntcNode; + UINT32 GicVersion; + CM_OBJ_DESCRIPTOR * NewCmObjDesc; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + NewCmObjDesc =3D NULL; + + // The FdtBranch points to the Cpus Node. + // Get the interrupt-controller node associated to the "cpus" node. + Status =3D FdtGetIntcParentNode (Fdt, FdtBranch, &IntcNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Status =3D GetGicVersion (Fdt, IntcNode, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Parse the "cpus" nodes and its children "cpu" nodes, + // and create a CM_OBJ_DESCRIPTOR. + Status =3D CpusNodeParser (Fdt, FdtBranch, GicVersion, &NewCmObjDesc); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Parse the interrupt-controller node according to the Gic version. + switch (GicVersion) { + case 2: + { + Status =3D GicCv2IntcNodeParser (Fdt, IntcNode, NewCmObjDesc); + break; + } + case 3: + { + Status =3D GicCv3IntcNodeParser (Fdt, IntcNode, NewCmObjDesc); + break; + } + default: + { + // Unsupported Gic version. + ASSERT (0); + Status =3D EFI_UNSUPPORTED; + } + } + + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // Parse the Gic information common to Gic v2 and v3. + Status =3D GicCIntcNodeParser (Fdt, IntcNode, NewCmObjDesc); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // Add all the CmObjs to the Configuration Manager. + Status =3D AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + +exit_handler: + FreeCmObjDesc (NewCmObjDesc); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.= h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h new file mode 100644 index 000000000000..10e6b03c541f --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h @@ -0,0 +1,67 @@ +/** @file + Arm Gic cpu parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GICC_PARSER_H_ +#define ARM_GICC_PARSER_H_ + +/** CM_ARM_GICC_INFO parser function. + + This parser expects FdtBranch to be the "\cpus" node node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmGicCInfo { + UINT32 CPUInterfaceNumber; // {Populated} + UINT32 AcpiProcessorUid; // {Populated} + UINT32 Flags; // {Populated} + UINT32 ParkingProtocolVersion; // {default =3D 0} + UINT32 PerformanceInterruptGsiv; // {default =3D 0} + UINT64 ParkedAddress; // {default =3D 0} + UINT64 PhysicalBaseAddress; // {Populated} + UINT64 GICV; // {Populated} + UINT64 GICH; // {Populated} + UINT32 VGICMaintenanceInterrupt; // {Populated} + UINT64 GICRBaseAddress; // {default =3D 0} + UINT64 MPIDR; // {Populated} + UINT8 ProcessorPowerEfficiencyClass; // {default =3D 0} + UINT16 SpeOverflowInterrupt; // {default =3D 0} + UINT32 ProximityDomain; // {default =3D 0} + UINT32 ClockDomain; // {default =3D 0} + UINT32 AffinityFlags; // {default =3D 0} + } CM_ARM_GICC_INFO; + + The pmu information can be found in the pmu node. There is no support + for now. + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicCInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GICC_PARSER_H_ --=20 2.25.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 (#83964): https://edk2.groups.io/g/devel/message/83964 Mute This Topic: https://groups.io/mt/87263322/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- From nobody Thu Mar 28 21:22:26 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+83965+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+83965+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687371; cv=none; d=zohomail.com; s=zohoarc; b=KYEayxSrwaVHDPSB/j+MnMq18t73jkBbhhQsn/09TJH3fKO/JDNzy77ggCEFuW/FrvrtM4iXQJfmYEz0J4T298+4tFCr6AkoREQptCjVyVOetXWqvjQWCDwMKiEJfdWOcr6MMs84hM6i9dOJxwb1gkcxXWR2uBGDIhN70gVdGeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687371; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=imPqZ5v91QcrBMkOqeZ0sP1iIhGnVKdRTnZKYEnhCa4=; b=aehCVwrnK3DAgFue8j0LTgmAimHAx9CKog2CVBbsejcbUAzLkl/kDwksttRFiQ1iintXVvZwn5L1iwoPaLamaivhYT1uAFavtxfGRGRYNn/jvpAWVFfFXVzUl7DWwiBCCcHyh/88CH4e1AcrC8C5c/lLysuB4Zb76ra9YRpZ25Y= 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+83965+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 1637687371184829.1055249918021; Tue, 23 Nov 2021 09:09:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id htBnYY1788612xjMUod57NBx; Tue, 23 Nov 2021 09:09:30 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14137.1637687365568121675 for ; Tue, 23 Nov 2021 09:09:25 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31ACA1FB; Tue, 23 Nov 2021 09:09:25 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4DAA83F5A1; Tue, 23 Nov 2021 09:09:24 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 08/15] DynamicTablesPkg: FdtHwInfoParser: Add GICD parser Date: Tue, 23 Nov 2021 18:08:31 +0100 Message-Id: <20211123170838.143805-9-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: vYMpSHnWMZqWwNKUiDxYiEm5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687370; bh=sBxU8Tq2Ga9F02Xsz3L3TjSqzRfBLyHNh4C/mJ+o5u4=; h=Cc:Date:From:Reply-To:Subject:To; b=kXbAbH417+eDnNUNIZDZPG3KvaMOejBnfTDK56hwP0hq8NM6RcPUghio2BZCPbMOaBl QQ5UNbU6NJq7CyISQRPzd6IVfjFoIBWfm8KB6TbTnjJYQtbv1AB3wDVIlUzRwkFS4TyFm aptlcWF0CB6Kz4BuoYxsSmc0sPCEtvJmleg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687372531100024 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois On ARM-based systems the Generic Interrupt Controller (GIC) manages interrupts on the system. Each interrupt is identified in the GIC by an interrupt identifier (INTID). ACPI GSIVs map one to one to GIC INTIDs for peripheral interrupts, whether shared (SPI) or private (PPI). The GIC distributor provides the routing configuration for the interrupts. The GIC Distributor (GICD) structure is part of the Multiple APIC Description Table (MADT) that describes the GIC distributor to the OS. The MADT table is a mandatory table required for booting a standards-based operating system. The GIC Distributor information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic.yaml - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic-v3.yaml The FdtHwInfoParser implements a GIC Distributor Parser that parses the platform Device Tree to create CM_ARM_GICD_INFO object which is encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MADT table. Signed-off-by: Pierre Gondois --- .../FdtHwInfoParserLib/Gic/ArmGicDParser.c | 169 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicDParser.h | 50 ++++++ 2 files changed, 219 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicD= Parser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicD= Parser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.= c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c new file mode 100644 index 000000000000..b58729ac8a19 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c @@ -0,0 +1,169 @@ +/** @file + Arm Gic Distributor Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Gic/ArmGicDParser.h" + +/** Parse a Gic compatible interrupt-controller node, + extracting GicD information. + + This parser is valid for Gic v2 and v3. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] GicIntcNode Offset of a Gic compatible + interrupt-controller node. + @param [in] GicDInfo The CM_ARM_GICD_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicDIntcNodeParser ( + IN CONST VOID * Fdt, + IN INT32 GicIntcNode, + IN CM_ARM_GICD_INFO * GicDInfo + ) +{ + EFI_STATUS Status; + INT32 AddressCells; + CONST UINT8 * Data; + INT32 DataSize; + + if ((Fdt =3D=3D NULL) || + (GicDInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D FdtGetParentAddressInfo (Fdt, GicIntcNode, &AddressCells, NUL= L); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < (INT32)(AddressCells * sizeof (UIN= T32)))) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + if (AddressCells =3D=3D 2) { + GicDInfo->PhysicalBaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + GicDInfo->PhysicalBaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + + return Status; +} + +/** CM_ARM_GICD_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmGicDInfo { + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 SystemVectorBase; + UINT8 GicVersion; // {Populated} + } CM_ARM_GICD_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicDInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 GicVersion; + CM_ARM_GICD_INFO GicDInfo; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the Gic version of the interrupt-controller. + Status =3D GetGicVersion (Fdt, FdtBranch, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + ZeroMem (&GicDInfo, sizeof (GicDInfo)); + GicDInfo.GicVersion =3D GicVersion; + + // Parse the interrupt-controller depending on its Gic version. + switch (GicVersion) { + case 2: + case 3: + { + // Set the Gic version, then parse the GicD information. + Status =3D GicDIntcNodeParser (Fdt, FdtBranch, &GicDInfo); + break; + } + default: + { + // Unsupported Gic version. + ASSERT (0); + return EFI_UNSUPPORTED; + } + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjGicDInfo), + &GicDInfo, + sizeof (CM_ARM_GICD_INFO), + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.= h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h new file mode 100644 index 000000000000..a274a4b43070 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h @@ -0,0 +1,50 @@ +/** @file + Arm Gic Distributor Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GICD_PARSER_H_ +#define ARM_GICD_PARSER_H_ + +/** CM_ARM_GICD_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmGicDInfo { + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 SystemVectorBase; + UINT8 GicVersion; // {Populated} + } CM_ARM_GICD_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicDInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GICD_PARSER_H_ --=20 2.25.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 (#83965): https://edk2.groups.io/g/devel/message/83965 Mute This Topic: https://groups.io/mt/87263323/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- From nobody Thu Mar 28 21:22:26 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+83966+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+83966+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687372; cv=none; d=zohomail.com; s=zohoarc; b=UL+bminXNi2NNaLYQJyVP4IS5ozrKWRcwKi/uJQrx98ofnx/syTAga4jz6XDop9zoIRm4NX6zXXOkB4kcxmgScx/SaAgaH/74wshPGr1yuMxTGZnMbxsp0dAWkHKQcU0om8jwXV+3R4iUapYuzMSqRJKMMksyGqlVRM9BmSSR00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687372; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zOfpg7DkXjbjZsoa4R4f1Yw1x2+BHsfK07+tu1tuQig=; b=aK99C59gvgZpVv+3+YrJ8H4c+ejwh61KnisXvKeEEqmIFhu6QvbNTztVPxYfU9/uycvUUH1fRIJtCvZ8bV/Wt1sH7iJcONbGCKIypLPXLSr+nRhPhFKJsNg+JBIJ+h0DEg6WS9yOjszVb3X6KRBtph+YE/BCYCd55plF+pjK0kI= 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+83966+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 1637687372129456.01693991916113; Tue, 23 Nov 2021 09:09:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id nKwXYY1788612xEtSmXTZPeI; Tue, 23 Nov 2021 09:09:31 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.14103.1637687366519669604 for ; Tue, 23 Nov 2021 09:09:26 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 325821063; Tue, 23 Nov 2021 09:09:26 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 85A233F5A1; Tue, 23 Nov 2021 09:09:25 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 09/15] DynamicTablesPkg: FdtHwInfoParser: Add MSI Frame parser Date: Tue, 23 Nov 2021 18:08:32 +0100 Message-Id: <20211123170838.143805-10-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: ou7xl5lUlCOLUuAl6Gs2ftrFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687371; bh=205S/gHPnV0i/moFkzhoS8xISWj6rtKXwd+5vOMKhMo=; h=Cc:Date:From:Reply-To:Subject:To; b=N175gSanyBaOzvqx60M0ZJBqkKx4EiOuuxyiauyME91f1ySQnpNWbN+U7PcC5nwBdfD NsGE5t7i3CRXBr/3eXmycQjia1FRLHwvrQo+SvNm65b5DWl3nwiKrteFG9Iu+Ft5yXGK6 4hSw9YCWCuRWmdQM3t56oRpoKzoQ2101OM0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687372722100027 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Arm GIC version 2 systems that support Message Signalled Interrupts implement GICv2m MSI frame(s). Each GICv2m MSI frame consists of a 4k page which includes registers to generate message signalled interrupts to an associated GIC distributor. The frame also includes registers to discover the set of distributor lines which may be signalled by MSIs from that frame. A system may have multiple MSI frames, and separate frames may be defined for secure and non-secure access. A MSI Frame structure is part of the Multiple APIC Description Table (MADT) and must only be used to describe non-secure MSI frames. The MSI Frame information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic.yaml - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic-v3.yaml The FdtHwInfoParser implements a MSI Frame Parser that parses the platform Device Tree to create CM_ARM_GIC_MSI_FRAME_INFO objects which are encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MADT table. Signed-off-by: Pierre Gondois --- .../Gic/ArmGicMsiFrameParser.c | 214 ++++++++++++++++++ .../Gic/ArmGicMsiFrameParser.h | 50 ++++ 2 files changed, 264 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicM= siFrameParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicM= siFrameParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrame= Parser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFramePa= rser.c new file mode 100644 index 000000000000..9e6715f69ce7 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c @@ -0,0 +1,214 @@ +/** @file + Arm Gic Msi frame Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Gic/ArmGicMsiFrameParser.h" + +/** List of "compatible" property values for Msi-frame nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR MsiFrameCompatibleStr[] =3D { + {"arm,gic-v2m-frame"} +}; + +/** COMPATIBILITY_INFO structure for the MSI frame. +*/ +STATIC CONST COMPATIBILITY_INFO MsiFrameCompatibleInfo =3D { + ARRAY_SIZE (MsiFrameCompatibleStr), + MsiFrameCompatibleStr +}; + +/** Parse a Msi frame node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] MsiFrameNode Offset of a Msi frame node. + @param [in] MsiFrameId Frame ID. + @param [out] MsiFrameInfo The CM_ARM_GIC_MSI_FRAME_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +MsiFrameNodeParser ( + IN CONST VOID * Fdt, + IN INT32 MsiFrameNode, + IN UINT32 MsiFrameId, + OUT CM_ARM_GIC_MSI_FRAME_INFO * MsiFrameInfo + ) +{ + EFI_STATUS Status; + INT32 AddressCells; + CONST UINT8 * Data; + INT32 DataSize; + + if ((Fdt =3D=3D NULL) || + (MsiFrameInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D FdtGetParentAddressInfo (Fdt, MsiFrameNode, &AddressCells, NU= LL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, MsiFrameNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < (INT32)(AddressCells * sizeof (UIN= T32)))) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + if (AddressCells =3D=3D 2) { + MsiFrameInfo->PhysicalBaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + MsiFrameInfo->PhysicalBaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + + MsiFrameInfo->GicMsiFrameId =3D MsiFrameId; + + return EFI_SUCCESS; +} + +/** CM_ARM_GIC_MSI_FRAME_INFO parser function. + + The following structure is populated: + typedef struct CmArmGicMsiFrameInfo { + UINT32 GicMsiFrameId; // {Populated} + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 Flags; // {default =3D 0} + UINT16 SPICount; + UINT16 SPIBase; + } CM_ARM_GIC_MSI_FRAME_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicMsiFrameInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 MsiFrameNode; + UINT32 MsiFrameNodeCount; + + UINT32 Index; + CM_ARM_GIC_MSI_FRAME_INFO MsiFrameInfo; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + // Count the number of nodes having the "interrupt-controller" property. + Status =3D FdtCountPropNodeInBranch ( + Fdt, + FdtBranch, + "msi-controller", + &MsiFrameNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (MsiFrameNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // Parse each node having the "msi-controller" property. + MsiFrameNode =3D FdtBranch; + for (Index =3D 0; Index < MsiFrameNodeCount; Index++) { + ZeroMem (&MsiFrameInfo, sizeof (CM_ARM_GIC_MSI_FRAME_INFO)); + + Status =3D FdtGetNextPropNodeInBranch ( + Fdt, + FdtBranch, + "msi-controller", + &MsiFrameNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + if (!FdtNodeIsCompatible (Fdt, MsiFrameNode, &MsiFrameCompatibleInfo))= { + ASSERT (0); + Status =3D EFI_UNSUPPORTED; + return Status; + } + + // Parse the Msi information. + Status =3D MsiFrameNodeParser ( + Fdt, + MsiFrameNode, + Index, + &MsiFrameInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjGicMsiFrameInfo), + &MsiFrameInfo, + sizeof (CM_ARM_GIC_MSI_FRAME_INFO), + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrame= Parser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFramePa= rser.h new file mode 100644 index 000000000000..40f83010a686 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.h @@ -0,0 +1,50 @@ +/** @file + Arm Gic Msi frame Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GIC_MSI_FRAME_PARSER_H_ +#define ARM_GIC_MSI_FRAME_PARSER_H_ + +/** CM_ARM_GIC_MSI_FRAME_INFO parser function. + + The following structure is populated: + typedef struct CmArmGicMsiFrameInfo { + UINT32 GicMsiFrameId; // {Populated} + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 Flags; // {default =3D 0} + UINT16 SPICount; + UINT16 SPIBase; + } CM_ARM_GIC_MSI_FRAME_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicMsiFrameInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GIC_MSI_FRAME_PARSER_H_ --=20 2.25.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 (#83966): https://edk2.groups.io/g/devel/message/83966 Mute This Topic: https://groups.io/mt/87263325/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- From nobody Thu Mar 28 21:22:26 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+83967+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+83967+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687374; cv=none; d=zohomail.com; s=zohoarc; b=bEvma2GGxuOkC5qDbzdd+ThDWu8VgFZNDfgapD8+w4TCF9Nrq7eM9cy5yIACRhePA6ojFjb6HoFD7SdL5UPQxnOz7Vs5LmBqybO04n7tqeS+OE/Iy6251h11/EZdHw/gw03G4SFnZUfcQvR1qXxV12H+CZYYjBIzz0iRSOertxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687374; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=etyzUxpk3JrwDF8KEizcLRsjjY2R+93ZWftpFtFypb4=; b=QrXudVVRomnEXxPuYWkpxQTaBlnIJf68JynPVc0CodnOcUN5wjBytY+8ot4RtNtch7LpKxC9dHMW8QoBJS5oo98YNE/MW9wRnE65QIbYTcKVLixIccMParaHLF66t+Ev+1fRvTr/6WNQtT06RM3tJSBS+I3u28f6jZGNCvv1Aco= 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+83967+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 1637687374858686.7268289630472; Tue, 23 Nov 2021 09:09:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XLFyYY1788612xHQqVL3MhIx; Tue, 23 Nov 2021 09:09:32 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14279.1637687367824683335 for ; Tue, 23 Nov 2021 09:09:28 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7BF6B1FB; Tue, 23 Nov 2021 09:09:27 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8B61C3F5A1; Tue, 23 Nov 2021 09:09:26 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 10/15] DynamicTablesPkg: FdtHwInfoParser: Add ITS parser Date: Tue, 23 Nov 2021 18:08:33 +0100 Message-Id: <20211123170838.143805-11-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: BE9V90S3XzKK3xMpqtkUUP3Zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687372; bh=5CJq+7YNZHD5NbrRQzkZfBFO2zjro2HUKABK1of4Zbs=; h=Cc:Date:From:Reply-To:Subject:To; b=iRd1v/ZglbZ8ctxXm1PPhPLkP9pQ+dhCNcIH5zpXijgiTlm8+06YeRvCwO86ZqsN+40 DNHWWkkTSpfZXDZEjM0rMJ6tWs31x5b+xaygBsIqvGurLZzpx0hdeJyvK+5Yru0Wx1PMM ftGXg0s5OFgHQs9XTtzzW4vbJkOFMS1RDl4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687375801100037 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Arm GIC v3/v4 optionally includes support for GIC Interrupt Translation Service (ITS). The GIC ITS Structure is part of the Multiple APIC Description Table (MADT) that describes the GIC Interrupt Translation service to the OS. The GIC Interrupt Translation Service information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic-v3.yaml The FdtHwInfoParser implements a GIC ITS Parser that parses the platform Device Tree to create CM_ARM_GIC_ITS_INFO objects which are encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MADT table. Signed-off-by: Pierre Gondois --- .../FdtHwInfoParserLib/Gic/ArmGicItsParser.c | 215 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicItsParser.h | 48 ++++ 2 files changed, 263 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicI= tsParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicI= tsParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParse= r.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c new file mode 100644 index 000000000000..faaa0df1d9be --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c @@ -0,0 +1,215 @@ +/** @file + Arm Gic Interrupt Translation Service Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Gic/ArmGicItsParser.h" + +/** Parse a Gic compatible interrupt-controller node, + extracting GicIts information. + + This parser is valid for Gic v3 and higher. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] GicIntcNode Offset of a Gic compatible + interrupt-controller node. + @param [in] GicItsId Id for the Gic ITS node. + @param [in] GicItsInfo The CM_ARM_GIC_ITS_INFO to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicItsIntcNodeParser ( + IN CONST VOID * Fdt, + IN INT32 GicIntcNode, + IN UINT32 GicItsId, + IN CM_ARM_GIC_ITS_INFO * GicItsInfo + ) +{ + EFI_STATUS Status; + INT32 AddressCells; + CONST UINT8 * Data; + INT32 DataSize; + + if ((Fdt =3D=3D NULL) || + (GicItsInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D FdtGetParentAddressInfo (Fdt, GicIntcNode, &AddressCells, NUL= L); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < (INT32)(AddressCells * sizeof (UIN= T32)))) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + if (AddressCells =3D=3D 2) { + GicItsInfo->PhysicalBaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + GicItsInfo->PhysicalBaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + + // Gic Its Id + GicItsInfo->GicItsId =3D GicItsId; + + // {default =3D 0} + GicItsInfo->ProximityDomain =3D 0; + return Status; +} + +/** CM_ARM_GIC_ITS_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + Gic version must be v3 or higher. + typedef struct CmArmGicItsInfo { + UINT32 GicItsId; // {Populated} + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 ProximityDomain; // {default =3D 0} + } CM_ARM_GIC_ITS_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicItsInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 GicVersion; + CM_ARM_GIC_ITS_INFO GicItsInfo; + UINT32 Index; + INT32 GicItsNode; + UINT32 GicItsNodeCount; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the Gic version of the interrupt-controller. + Status =3D GetGicVersion (Fdt, FdtBranch, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (GicVersion < 3) { + ASSERT (0); + return EFI_UNSUPPORTED; + } + + // Count the nodes with the "msi-controller" property. + // The interrupt-controller itself can have this property, + // but the first node is skipped in the search. + Status =3D FdtCountPropNodeInBranch ( + Fdt, + FdtBranch, + "msi-controller", + &GicItsNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (GicItsNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + GicItsNode =3D FdtBranch; + for (Index =3D 0; Index < GicItsNodeCount; Index++) { + ZeroMem (&GicItsInfo, sizeof (CM_ARM_GIC_ITS_INFO)); + + Status =3D FdtGetNextPropNodeInBranch ( + Fdt, + FdtBranch, + "msi-controller", + &GicItsNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Status =3D GicItsIntcNodeParser ( + Fdt, + GicItsNode, + Index, + &GicItsInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjGicItsInfo), + &GicItsInfo, + sizeof (CM_ARM_GIC_ITS_INFO), + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParse= r.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h new file mode 100644 index 000000000000..6ea498ff71c9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h @@ -0,0 +1,48 @@ +/** @file + Arm Gic Interrupt Translation Service Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GIC_ITS_PARSER_H_ +#define ARM_GIC_ITS_PARSER_H_ + +/** CM_ARM_GIC_ITS_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + Gic version must be v3 or higher. + typedef struct CmArmGicItsInfo { + UINT32 GicItsId; // {Populated} + UINT64 PhysicalBaseAddress; // {Populated} + UINT32 ProximityDomain; // {default =3D 0} + } CM_ARM_GIC_ITS_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicItsInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GIC_ITS_PARSER_H_ --=20 2.25.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 (#83967): https://edk2.groups.io/g/devel/message/83967 Mute This Topic: https://groups.io/mt/87263326/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- From nobody Thu Mar 28 21:22:26 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+83968+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+83968+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687376; cv=none; d=zohomail.com; s=zohoarc; b=kHc6JcPpFiYLGdJSsebnAPzjjXHP53NgrmWLgaUWW0mHM02K1xVlTKREADkPF0xUrqZjXyE4i+hkS5pl57KOAbGPN2Glf1FjLQWczdprWcz5MTILYG8iHNdXk7KB0q3kwRRj9QN3Vt1hIrWs1YxMcpHHOPhX6SYE9jot6fxR5gc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687376; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=BLbPW6JiUiCffiKLAszhfxyJbJ3rZ6t9XxlsdxVlRRQ=; b=kQueNc8S1yAuiG5dOqzX9yEM50pj6JVS65oBss7AY6hi9IMB6RQPIhkNlzsOqpcsHM/qpohiRQDaS/AyIP0OaFrShK7tUGQ3EPEVrNlXV0PpQ1ILO1elo+DiYvHUsD9321f9jm0iAYrRnfMI/lWgN9jZ69GCLjMNQsoIdgEOACE= 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+83968+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 1637687376337621.9867006356316; Tue, 23 Nov 2021 09:09:36 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q6DQYY1788612xsKbBwcAjyT; Tue, 23 Nov 2021 09:09:34 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14281.1637687369024791457 for ; Tue, 23 Nov 2021 09:09:29 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3FA81063; Tue, 23 Nov 2021 09:09:28 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BA1583F5A1; Tue, 23 Nov 2021 09:09:27 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 11/15] DynamicTablesPkg: FdtHwInfoParser: Add GICR parser Date: Tue, 23 Nov 2021 18:08:34 +0100 Message-Id: <20211123170838.143805-12-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: NjeK4O5O7kh20vIkirNsNygfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687374; bh=LuBMZNQcEpfCFveqb6PtLPSX2H1kFZLY16zWqnHb1ZU=; h=Cc:Date:From:Reply-To:Subject:To; b=gwVDtw2kbXY5UOuzUo12122HBZbs/JOWJgf70gYnzRjdSiXA45/Ky7UR3Ah3KvnbCOh jnACNxSy7spXeiKDdP34nTUiN/2Mk5FQ+m+JMPM8Tut8wQmNHl4Zgkq/sYqH+RWkmHh5W Mlm7/buut1CSDPbVytaTsk6WxcOyMoPPMzE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687378100100041 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The GIC Redistributor (GICR) structure is part of the Multiple APIC Description Table (MADT) that enables the discovery of GIC Redistributor base addresses by providing the Physical Base Address of a page range containing the GIC Redistributors. More than one GICR Structure may be presented in the MADT. The GICR structures should only be used when describing GIC version 3 or higher. The GIC Redistributor information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/interrupt-controller/ arm,gic-v3.yaml The FdtHwInfoParser implements a GIC Redistributor Parser that parses the platform Device Tree to create CM_ARM_GIC_REDIST_INFO objects which are encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MADT table. Signed-off-by: Pierre Gondois --- .../FdtHwInfoParserLib/Gic/ArmGicRParser.c | 235 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicRParser.h | 47 ++++ 2 files changed, 282 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicR= Parser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicR= Parser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.= c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c new file mode 100644 index 000000000000..4d89a8c848fe --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c @@ -0,0 +1,235 @@ +/** @file + Arm Gic Redistributor Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Gic/ArmGicRParser.h" + +/** Parse a Gic compatible interrupt-controller node, + extracting GicR information. + + This parser is valid for Gic v3 and higher. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] GicIntcNode Offset of a Gic compatible + interrupt-controller node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GicRIntcNodeParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 GicIntcNode + ) +{ + EFI_STATUS Status; + UINT32 Index; + UINT32 RedistReg; + UINT32 RegSize; + INT32 AddressCells; + INT32 SizeCells; + CONST UINT8 * Data; + INT32 DataSize; + CM_ARM_GIC_REDIST_INFO GicRInfo; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + Status =3D FdtGetParentAddressInfo ( + Fdt, + GicIntcNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + // The "#redistributor-regions" property is optional. + // It indicates the number of GicR. + Data =3D fdt_getprop (Fdt, GicIntcNode, "#redistributor-regions", &DataS= ize); + if ((Data !=3D NULL) && (DataSize =3D=3D sizeof (UINT32))) { + // If available, must be on one cell. + RedistReg =3D fdt32_to_cpu (*(UINT32*)Data); + } else { + // The DT Spec says GicR is mandatory so we will + // always have one. + RedistReg =3D 1; + } + + /* + Ref: linux/blob/master/Documentation/devicetree/bindings/ + interrupt-controller/arm%2Cgic-v3.yaml + + reg: + description: | + Specifies base physical address(s) and size of the GIC + registers, in the following order: + - GIC Distributor interface (GICD) + - GIC Redistributors (GICR), one range per redistributor region + - GIC CPU interface (GICC) + - GIC Hypervisor interface (GICH) + - GIC Virtual CPU interface (GICV) + GICC, GICH and GICV are optional. + minItems: 2 + maxItems: 4096 + + Example: + interrupt-controller@2c010000 { + compatible =3D "arm,gic-v3"; + #interrupt-cells =3D <4>; + #address-cells =3D <1>; + #size-cells =3D <1>; + ranges; + interrupt-controller; + redistributor-stride =3D <0x0 0x40000>; // 256kB stride + #redistributor-regions =3D <2>; + reg =3D <0x2c010000 0x10000>, // GICD + <0x2d000000 0x800000>, // GICR 1: CPUs 0-31 + <0x2e000000 0x800000>, // GICR 2: CPUs 32-63 + <0x2c040000 0x2000>, // GICC + <0x2c060000 0x2000>, // GICH + <0x2c080000 0x2000>; // GICV + interrupts =3D <1 9 4>; + ... + } + */ + RegSize =3D (AddressCells + SizeCells) * sizeof (UINT32); + Data =3D fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < 0) || + ((DataSize % RegSize) !=3D 0)) { + // If error or wrong size. + ASSERT (0); + return EFI_ABORTED; + } + + Data +=3D GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells) + * sizeof (UINT32); + for (Index =3D 0; Index < RedistReg; Index++) { + ZeroMem (&GicRInfo, sizeof (CM_ARM_GIC_REDIST_INFO)); + + if (AddressCells =3D=3D 2) { + GicRInfo.DiscoveryRangeBaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + GicRInfo.DiscoveryRangeBaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + Data +=3D sizeof (UINT32) * AddressCells; + + if (SizeCells =3D=3D 2) { + GicRInfo.DiscoveryRangeLength =3D (UINT32)fdt64_to_cpu (*(UINT64*)Da= ta); + } else { + GicRInfo.DiscoveryRangeLength =3D fdt32_to_cpu (*(UINT32*)Data); + } + + // Add the CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjGicRedistributorInfo), + &GicRInfo, + sizeof (CM_ARM_GIC_REDIST_INFO), + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Data +=3D sizeof (UINT32) * SizeCells; + } // for + + return Status; +} + +/** CM_ARM_GIC_REDIST_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + Gic version must be v3 or higher. + typedef struct CmArmGicRedistInfo { + UINT64 DiscoveryRangeBaseAddress; // {Populated} + UINT32 DiscoveryRangeLength; // {Populated} + } CM_ARM_GIC_REDIST_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicRInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 GicVersion; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the Gic version of the interrupt-controller. + Status =3D GetGicVersion (Fdt, FdtBranch, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (GicVersion < 3) { + ASSERT (0); + return EFI_UNSUPPORTED; + } + + Status =3D GicRIntcNodeParser (FdtParserHandle, FdtBranch); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.= h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h new file mode 100644 index 000000000000..ef91c2d32cd9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h @@ -0,0 +1,47 @@ +/** @file + Arm Gic Redistributor Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GICR_PARSER_H_ +#define ARM_GICR_PARSER_H_ + +/** CM_ARM_GIC_REDIST_INFO parser function. + + This parser expects FdtBranch to be a Gic interrupt-controller node. + Gic version must be v3 or higher. + typedef struct CmArmGicRedistInfo { + UINT64 DiscoveryRangeBaseAddress; // {Populated} + UINT32 DiscoveryRangeLength; // {Populated} + } CM_ARM_GIC_REDIST_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicRInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GICR_PARSER_H_ --=20 2.25.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 (#83968): https://edk2.groups.io/g/devel/message/83968 Mute This Topic: https://groups.io/mt/87263328/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- From nobody Thu Mar 28 21:22:26 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+83969+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+83969+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687377; cv=none; d=zohomail.com; s=zohoarc; b=MzjD4xUigLie1UvksWrQo+dTq5ZWpEz4EteAaWxVEu6UqhYukKgUP9d0QmOAXe1ycsO/FTNjK62bFSVeAWRnrUWp+Muds8+2Tym5DaxPxB4WJDm0mtME0QjUngOqqgLDGdJq/hUEJT7yOR6w7U2gDlIoikjrl1mxpt2fxZsQo78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687377; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=VU2gEgspLAWYkzhLxrf8cfI+NEMG4ZDHygvv6ZisENo=; b=kaC89abwVaM5Yu1Ao+mWRI0sIr5AsU4Zb/KyA7oyfaTSgzQIzhq8FeSI1TxUwsWQ9+yPSxKPeOtgTqHGaNZ6czPEFUIBLieZsLb2Ifn29AmPx/5KBRz558Yk1eJZ0Qp23UqpeHGikeQcKsRKCTqo3Fg5XqeAIzZ1TDGnUpHia7A= 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+83969+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 1637687377797946.4264889647823; Tue, 23 Nov 2021 09:09:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id saIdYY1788612xQzXjd4KmrB; Tue, 23 Nov 2021 09:09:35 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.14104.1637687370307160682 for ; Tue, 23 Nov 2021 09:09:30 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E5B6A1FB; Tue, 23 Nov 2021 09:09:29 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F35B43F5A1; Tue, 23 Nov 2021 09:09:28 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 12/15] DynamicTablesPkg: FdtHwInfoParser: Add GIC dispatcher Date: Tue, 23 Nov 2021 18:08:35 +0100 Message-Id: <20211123170838.143805-13-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: VIz475Ksda0xOdyeXuMniIfDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687375; bh=SXArGLFUzmth8vfKfd2KRZCGsk0wQA1i+51wrzG4hTQ=; h=Cc:Date:From:Reply-To:Subject:To; b=LLE43H4ldjSoHOv+ea1LwlDoH98hfCusOzjH8+a9UBjHG3dxBTbT+C2+e9Bn0DoSmoL E+sbn5C8RkTg24oQC5cmRZs4kRRDagLHe55zJep+E0+Mdaglxds0otzki5mN7Y89Xx7Wv Ke77JKPQgXP84eDBf33bNS+y6d+CursAeJo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687379011100045 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The GIC Dispatcher is the top-level component that is responsible for invoking the respective parsers for GICC, GICD, GIC MSI Frame, GIC ITS and the GICR. Signed-off-by: Pierre Gondois --- .../FdtHwInfoParserLib/Gic/ArmGicDispatcher.c | 212 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicDispatcher.h | 72 ++++++ 2 files changed, 284 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicD= ispatcher.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicD= ispatcher.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatch= er.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c new file mode 100644 index 000000000000..3e5d7fb0cba6 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c @@ -0,0 +1,212 @@ +/** @file + Arm Gic dispatcher. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#include "FdtHwInfoParser.h" +#include "Gic/ArmGicCParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Gic/ArmGicDParser.h" +#include "Gic/ArmGicItsParser.h" +#include "Gic/ArmGicMsiFrameParser.h" +#include "Gic/ArmGicRParser.h" + +/** List of "compatible" property values for GicV2 interrupt nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR GicV2CompatibleStr[] =3D { + {"arm,cortex-a15-gic"} +}; + +/** COMPATIBILITY_INFO structure for the GICv2. +*/ +CONST COMPATIBILITY_INFO GicV2CompatibleInfo =3D { + ARRAY_SIZE (GicV2CompatibleStr), + GicV2CompatibleStr +}; + +/** List of "compatible" property values for GicV3 interrupt nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR GicV3CompatibleStr[] =3D { + {"arm,gic-v3"} +}; + +/** COMPATIBILITY_INFO structure for the GICv3. +*/ +CONST COMPATIBILITY_INFO GicV3CompatibleInfo =3D { + ARRAY_SIZE (GicV3CompatibleStr), + GicV3CompatibleStr +}; + +/** Get the Gic version of am interrupt-controller node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] IntcNode Interrupt-controller node. + @param [out] GicVersion If success, contains the Gic version of the + interrupt-controller node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +GetGicVersion ( + IN CONST VOID * Fdt, + IN INT32 IntcNode, + OUT UINT32 * GicVersion + ) +{ + if ((Fdt =3D=3D NULL) || + (GicVersion =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (FdtNodeIsCompatible (Fdt, IntcNode, &GicV2CompatibleInfo)) { + *GicVersion =3D 2; + } else if (FdtNodeIsCompatible (Fdt, IntcNode, &GicV3CompatibleInfo)) { + *GicVersion =3D 3; + } else { + // Unsupported Gic version. + ASSERT (0); + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** Gic dispatcher. + + This disptacher populates the following structures: + - CM_ARM_GICC_INFO + - CM_ARM_GICD_INFO + - CM_ARM_GIC_MSI_FRAME_INFO + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 CpusNode; + INT32 IntcNode; + UINT32 GicVersion; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + // The "cpus" node resides at the the root of the DT. Fetch it. + CpusNode =3D fdt_path_offset (Fdt, "/cpus"); + if (CpusNode < 0) { + return EFI_NOT_FOUND; + } + + // Get the interrupt-controller node associated to the "cpus" node. + Status =3D FdtGetIntcParentNode (Fdt, CpusNode, &IntcNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Status =3D GetGicVersion (Fdt, IntcNode, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Parse the GicC information. + Status =3D ArmGicCInfoParser (FdtParserHandle, CpusNode); + if (EFI_ERROR (Status)) { + // Don't try to parse GicD and GicMsiFrame information + // if no GicC information is found. Return. + ASSERT (Status =3D=3D EFI_NOT_FOUND); + return Status; + } + + // Parse the GicD information of the "cpus" interrupt-controller node. + Status =3D ArmGicDInfoParser (FdtParserHandle, IntcNode); + if (EFI_ERROR (Status)) { + // EFI_NOT_FOUND is not tolerated at this point. + ASSERT (0); + return Status; + } + + switch (GicVersion) { + case 4: + case 3: + { + // Parse the GicR information of the interrupt-controller node. + Status =3D ArmGicRInfoParser (FdtParserHandle, IntcNode); + if (EFI_ERROR (Status)) { + // EFI_NOT_FOUND is not tolerated at this point. + ASSERT (0); + return Status; + } + + // Parse the GicIts information of the interrupt-controller node. + Status =3D ArmGicItsInfoParser (FdtParserHandle, IntcNode); + if (EFI_ERROR (Status) && + (Status !=3D EFI_NOT_FOUND)) { + ASSERT (0); + return Status; + } + break; + } + case 2: + { + // Parse the GicMsiFrame information. + Status =3D ArmGicMsiFrameInfoParser (FdtParserHandle, IntcNode); + if (EFI_ERROR (Status) && + (Status !=3D EFI_NOT_FOUND)) { + ASSERT (0); + return Status; + } + break; + } + default: + { + ASSERT (0); + return EFI_UNSUPPORTED; + } + } + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatch= er.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h new file mode 100644 index 000000000000..a0671cea8a67 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h @@ -0,0 +1,72 @@ +/** @file + Arm Gic dispatcher. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.y= aml + - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v= 3.yaml +**/ + +#ifndef ARM_GIC_DISPATCHER_H_ +#define ARM_GIC_DISPATCHER_H_ + +#include +#include "FdtUtility.h" + +/** COMPATIBILITY_INFO structure for the GICv2. +*/ +extern CONST COMPATIBILITY_INFO GicV2CompatibleInfo; + +/** Get the Gic version of the interrupt-controller node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] IntcNode Interrupt-controller node. + @param [out] GicVersion If success, contains the Gic version of the + interrupt-controller node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +GetGicVersion ( + IN CONST VOID * Fdt, + IN INT32 IntcNode, + OUT UINT32 * GicVersion + ); + +/** Gic dispatcher. + + This disptacher populates the following structures: + - CM_ARM_GICC_INFO + - CM_ARM_GICD_INFO + - CM_ARM_GIC_MSI_FRAME_INFO + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmGicDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_GIC_DISPATCHER_H_ --=20 2.25.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 (#83969): https://edk2.groups.io/g/devel/message/83969 Mute This Topic: https://groups.io/mt/87263329/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- From nobody Thu Mar 28 21:22:26 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+83970+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+83970+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687379; cv=none; d=zohomail.com; s=zohoarc; b=LhUGUI/VHyFM6l0n6fRny6FYcanUULi+pI2SRGZFwlOlhXOlgVysz4gPgO2K8nQCLxtVOfVUTQQWq7dn7mrI4/pAaMkIt7GgORMgjFHu/ampxwIMJAOWYrNzuHrN0dRFZBIFADqEw8kUBBSPxDS9QzrUCyzN8fEVrLsxbLp6c/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687379; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Eujorv5BV0XlPv9ln5T29eTxHxpOkytGQE3+0wbJyxw=; b=EAg6hJZh7Z7x0SFxvvNTxLbp19Wmi7F0ux4WbXY/RJNj88TE+Cb81v1btVg74DSRbjms5bRFJ/TtOphtHIg1I35gr3zXbUoNNP0JifKp2hYCdqaa9guY6nHF555V4IGUevYcQxOMehGVydJBd5GmjfZhMcqSuz8+ZeHhxYTjx5o= 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+83970+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 1637687379406623.5809380785547; Tue, 23 Nov 2021 09:09:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DdUiYY1788612xBRd5NzveYm; Tue, 23 Nov 2021 09:09:37 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.14321.1637687371341038804 for ; Tue, 23 Nov 2021 09:09:31 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 042071063; Tue, 23 Nov 2021 09:09:31 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3EC7E3F5A1; Tue, 23 Nov 2021 09:09:30 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 13/15] DynamicTablesPkg: FdtHwInfoParser: Add PCI config parser Date: Tue, 23 Nov 2021 18:08:36 +0100 Message-Id: <20211123170838.143805-14-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: pXm10DV8LxQiN5gW8PaFi0W4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687377; bh=zBJk5RhCL11k/pXcDKGUscZvUQ1KtHd0yPfuk4/vFtc=; h=Cc:Date:From:Reply-To:Subject:To; b=Yw/YND6Aauq1hiqo6MqxfGIYXFQwLSalGl1KsdWdIF8bfGU+T1CGw+D6/TR+Eqk/ldQ E7oHVr9uB7lFytQBlBmD18ZtSkkpJH/jvS7QfPGckr9ZOfS39Gad2fMwsuaj4csypt55i EBivQ8VDhySbocMElzM5p9q33MLW1pyvZ9Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687381436100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois On platforms that implement PCIe, the PCIe configuration space information must be described to a standards-based operating system in the Memory mapped configuration space base address Description (MCFG) table. The PCIe information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/pci/ host-generic-pci.yaml The FdtHwInfoParser implements a PCI configuration space Parser that parses the platform Device Tree to create CM_ARM_PCI_CONFIG_SPACE_INFO objects which are encapsulated in a Configuration Manager descriptor object and added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the MCFG table. Signed-off-by: Pierre Gondois --- Notes: v2: - Handle absence of Pci legacy interrupts in Pci parser. [Pierre] .../Pci/ArmPciConfigSpaceParser.c | 797 ++++++++++++++++++ .../Pci/ArmPciConfigSpaceParser.h | 142 ++++ 2 files changed, 939 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciC= onfigSpaceParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciC= onfigSpaceParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSp= aceParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigS= paceParser.c new file mode 100644 index 000000000000..94b2721caaa9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpacePars= er.c @@ -0,0 +1,797 @@ +/** @file + Arm PCI Configuration Space Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/pci/host-generic-pci.yaml + - PCI Firmware Specification - Revision 3.0 + - Open Firmware Recommended Practice: Interrupt Mapping, Version 0.9 + - Devicetree Specification Release v0.3 + - linux kernel code +**/ + +#include "CmObjectDescUtility.h" +#include + +#include "FdtHwInfoParser.h" +#include "Pci/ArmPciConfigSpaceParser.h" +#include "Gic/ArmGicDispatcher.h" + +/** List of "compatible" property values for host PCIe bridges nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR PciCompatibleStr[] =3D { + {"pci-host-ecam-generic"} +}; + +/** COMPATIBILITY_INFO structure for the PCIe. +*/ +STATIC CONST COMPATIBILITY_INFO PciCompatibleInfo =3D { + ARRAY_SIZE (PciCompatibleStr), + PciCompatibleStr +}; + +/** Get the Segment group (also called: Domain Id) of a host-pci node. + + kernel/Documentation/devicetree/bindings/pci/pci.txt: + "It is required to either not set this property at all or set it for all + host bridges in the system" + + The function checks the "linux,pci-domain" property of the host-pci node. + Either all host-pci nodes must have this property, or none of them. If t= he + property is available, read it. Otherwise dynamically assign the Ids. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] HostPciNode Offset of a host-pci node. + @param [out] SegGroup Segment group assigned to the host-pci control= ler. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GetPciSegGroup ( + IN CONST VOID * Fdt, + IN INT32 HostPciNode, + OUT INT32 * SegGroup + ) +{ + CONST UINT8 * Data; + INT32 DataSize; + STATIC INT32 LocalSegGroup =3D 0; + + if ((Fdt =3D=3D NULL) || + (SegGroup =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Data =3D fdt_getprop (Fdt, HostPciNode, "linux,pci-domain", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < 0)) { + // Did not find property, assign the DomainIds ourselves. + if (LocalSegGroup < 0) { + // "linux,pci-domain" property was defined for another node. + ASSERT (0); + return EFI_ABORTED; + } + + *SegGroup =3D LocalSegGroup++; + return EFI_SUCCESS; + } + + if ((DataSize > sizeof (UINT32)) || + (LocalSegGroup > 0)) { + // Property on more than 1 cell or + // "linux,pci-domain" property was not defined for a node. + ASSERT (0); + return EFI_ABORTED; + } + + // If one node has the "linux,pci-domain" property, then all the host-pci + // nodes must have it. + LocalSegGroup =3D -1; + + *SegGroup =3D fdt32_to_cpu (*(UINT32*)Data); + return EFI_SUCCESS; +} + +/** Parse the bus-range controlled by this host-pci node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] HostPciNode Offset of a host-pci node. + @param [in, out] PciInfo PCI_PARSER_TABLE structure storing + information about the current host-pci. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +PopulateBusRange ( + IN CONST VOID * Fdt, + IN INT32 HostPciNode, + IN OUT PCI_PARSER_TABLE * PciInfo + ) +{ + CONST UINT8 * Data; + INT32 DataSize; + UINT32 StartBus; + UINT32 EndBus; + + if ((Fdt =3D=3D NULL) || + (PciInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Data =3D fdt_getprop (Fdt, HostPciNode, "bus-range", &DataSize); + if ((Data =3D=3D NULL) || (DataSize < 0)) { + // No evidence this property is mandatory. Use default values. + StartBus =3D 0; + EndBus =3D 255; + } else if (DataSize =3D=3D (2 * sizeof (UINT32))) { + // If available, the property is on two integers. + StartBus =3D fdt32_to_cpu (((UINT32*)Data)[0]); + EndBus =3D fdt32_to_cpu (((UINT32*)Data)[1]); + } else { + ASSERT (0); + return EFI_ABORTED; + } + + PciInfo->PciConfigSpaceInfo.StartBusNumber =3D StartBus; + PciInfo->PciConfigSpaceInfo.EndBusNumber =3D EndBus; + + return EFI_SUCCESS; +} + +/** Parse the PCI address map. + + The PCI address map is available in the "ranges" device-tree property. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] HostPciNode Offset of a host-pci node. + @param [in] AddressCells # of cells used to encode an address on + the parent bus. + @param [in, out] PciInfo PCI_PARSER_TABLE structure storing + information about the current host-pci. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +ParseAddressMap ( + IN CONST VOID * Fdt, + IN INT32 HostPciNode, + IN INT32 AddressCells, + IN OUT PCI_PARSER_TABLE * PciInfo + ) +{ + CONST UINT8 * Data; + INT32 DataSize; + UINT32 Index; + UINT32 Offset; + UINT32 AddressMapSize; + UINT32 Count; + UINT32 PciAddressAttr; + + CM_ARM_PCI_ADDRESS_MAP_INFO * PciAddressMapInfo; + UINT32 BufferSize; + + // The mapping is done on AddressMapSize bytes. + AddressMapSize =3D (PCI_ADDRESS_CELLS + AddressCells + PCI_SIZE_CELLS) * + sizeof (UINT32); + + Data =3D fdt_getprop (Fdt, HostPciNode, "ranges", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < 0) || + ((DataSize % AddressMapSize) !=3D 0)) { + // If error or not on AddressMapSize bytes. + ASSERT (0); + return EFI_ABORTED; + } + + Count =3D DataSize / AddressMapSize; + + // Allocate a buffer to store each address mapping. + BufferSize =3D Count * sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO); + PciAddressMapInfo =3D AllocateZeroPool (BufferSize); + if (PciAddressMapInfo =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + for (Index =3D 0; Index < Count; Index++) { + Offset =3D Index * AddressMapSize; + + // Pci address attributes + PciAddressAttr =3D fdt32_to_cpu (*(UINT32*)&Data[Offset]); + PciAddressMapInfo[Index].SpaceCode =3D READ_PCI_SS (PciAddressAttr); + Offset +=3D sizeof (UINT32); + + // Pci address + PciAddressMapInfo[Index].PciAddress =3D + fdt64_to_cpu (*(UINT64*)&Data[Offset]); + Offset +=3D (PCI_ADDRESS_CELLS - 1) * sizeof (UINT32); + + // Cpu address + if (AddressCells =3D=3D 2) { + PciAddressMapInfo[Index].CpuAddress =3D + fdt64_to_cpu (*(UINT64*)&Data[Offset]); + } else { + PciAddressMapInfo[Index].CpuAddress =3D + fdt32_to_cpu (*(UINT32*)&Data[Offset]); + } + Offset +=3D AddressCells * sizeof (UINT32); + + // Address size + PciAddressMapInfo[Index].AddressSize =3D + fdt64_to_cpu (*(UINT64*)&Data[Offset]); + Offset +=3D PCI_SIZE_CELLS * sizeof (UINT32); + } // for + + PciInfo->Mapping[PciMappingTableAddress].ObjectId =3D + CREATE_CM_ARM_OBJECT_ID (EArmObjPciAddressMapInfo); + PciInfo->Mapping[PciMappingTableAddress].Size =3D + sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO) * Count; + PciInfo->Mapping[PciMappingTableAddress].Data =3D PciAddressMapInfo; + PciInfo->Mapping[PciMappingTableAddress].Count =3D Count; + + return EFI_SUCCESS; +} + +/** Parse the PCI interrupt map. + + The PCI interrupt map is available in the "interrupt-map" + and "interrupt-map-mask" device-tree properties. + + Cf Devicetree Specification Release v0.3, + s2.4.3 Interrupt Nexus Properties + + An interrupt-map must be as: + interrupt-map =3D < [child unit address] [child interrupt specifier] + [interrupt-parent] + [parent unit address] [parent interrupt specifier] > + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] HostPciNode Offset of a host-pci node. + @param [in, out] PciInfo PCI_PARSER_TABLE structure storing + information about the current host-pci. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +ParseIrqMap ( + IN CONST VOID * Fdt, + IN INT32 HostPciNode, + IN OUT PCI_PARSER_TABLE * PciInfo + ) +{ + EFI_STATUS Status; + CONST UINT8 * Data; + INT32 DataSize; + UINT32 Index; + UINT32 Offset; + + INT32 IntcNode; + INT32 IntcAddressCells; + INT32 IntcCells; + + INT32 PciIntCells; + INT32 IntcPhandle; + + INT32 IrqMapSize; + UINT32 IrqMapCount; + CONST UINT8 * IrqMapMask; + INT32 IrqMapMaskSize; + + INT32 PHandleOffset; + UINT32 GicVersion; + + UINT32 PciAddressAttr; + + + CM_ARM_PCI_INTERRUPT_MAP_INFO * PciInterruptMapInfo; + UINT32 BufferSize; + + Data =3D fdt_getprop (Fdt, HostPciNode, "interrupt-map", &DataSize); + if ((Data =3D=3D NULL) || (DataSize <=3D 0)) { + DEBUG (( + DEBUG_WARN, + "Fdt parser: No Legacy interrupts found for PCI configuration space = at " + "address: 0x%lx, group segment: %d\n", + PciInfo->PciConfigSpaceInfo.BaseAddress, + PciInfo->PciConfigSpaceInfo.PciSegmentGroupNumber + )); + return EFI_NOT_FOUND; + } + + // PCI interrupts are expected to be on 1 cell. Check it. + Status =3D FdtGetInterruptCellsInfo (Fdt, HostPciNode, &PciIntCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + if (PciIntCells !=3D PCI_INTERRUPTS_CELLS) { + ASSERT (0); + return EFI_ABORTED; + } + + IrqMapMask =3D fdt_getprop ( + Fdt, + HostPciNode, + "interrupt-map-mask", + &IrqMapMaskSize + ); + if ((IrqMapMask =3D=3D NULL) || + (IrqMapMaskSize !=3D + (PCI_ADDRESS_CELLS + PCI_INTERRUPTS_CELLS) * sizeof (UINT32))) { + ASSERT (0); + return EFI_ABORTED; + } + + // Get the interrupt-controller of the first irq mapping. + PHandleOffset =3D (PCI_ADDRESS_CELLS + PciIntCells) * sizeof (UINT32); + if (PHandleOffset > DataSize) { + ASSERT (0); + return EFI_ABORTED; + } + IntcPhandle =3D fdt32_to_cpu (*(UINT32*)&Data[PHandleOffset]); + IntcNode =3D fdt_node_offset_by_phandle (Fdt, IntcPhandle); + if (IntcNode < 0) { + ASSERT (0); + return EFI_ABORTED; + } + + // Only support Gic(s) for now. + Status =3D GetGicVersion (Fdt, IntcNode, &GicVersion); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Get the "address-cells" property of the IntcNode. + Status =3D FdtGetAddressInfo (Fdt, IntcNode, &IntcAddressCells, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Get the "interrupt-cells" property of the IntcNode. + Status =3D FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntcCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // An irq mapping is done on IrqMapSize bytes + // (which includes 1 cell for the PHandle). + IrqMapSize =3D (PCI_ADDRESS_CELLS + PciIntCells + 1 + + IntcAddressCells + IntcCells) * sizeof (UINT32); + if ((DataSize % IrqMapSize) !=3D 0) { + // The mapping is not done on IrqMapSize bytes. + ASSERT (0); + return EFI_ABORTED; + } + IrqMapCount =3D DataSize / IrqMapSize; + + // We assume the same interrupt-controller is used for all the mappings. + // Check this is correct. + for (Index =3D 0; Index < IrqMapCount; Index++) { + if (IntcPhandle !=3D fdt32_to_cpu ( + *(UINT32*)&Data[(Index * IrqMapSize) + PHandleOffset])) { + ASSERT (0); + return EFI_ABORTED; + } + } + + // Allocate a buffer to store each interrupt mapping. + IrqMapCount =3D DataSize / IrqMapSize; + BufferSize =3D IrqMapCount * sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO); + PciInterruptMapInfo =3D AllocateZeroPool (BufferSize); + if (PciInterruptMapInfo =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + for (Index =3D 0; Index < IrqMapCount; Index++) { + Offset =3D Index * IrqMapSize; + + // Pci address attributes + PciAddressAttr =3D fdt32_to_cpu ( + (*(UINT32*)&Data[Offset]) & + (*(UINT32*)&IrqMapMask[0]) + ); + PciInterruptMapInfo[Index].PciBus =3D READ_PCI_BBBBBBBB (PciAddressAtt= r); + PciInterruptMapInfo[Index].PciDevice =3D READ_PCI_DDDDD (PciAddressAtt= r); + Offset +=3D PCI_ADDRESS_CELLS * sizeof (UINT32); + + // Pci irq + PciInterruptMapInfo[Index].PciInterrupt =3D fdt32_to_cpu ( + (*(UINT32*)&Data[Offset]) & + (*(UINT32*)&IrqMapMask[3 * sizeof (UINT= 32)]) + ); + // -1 to translate from device-tree (INTA=3D1) to ACPI (INTA=3D0) irq = IDs. + PciInterruptMapInfo[Index].PciInterrupt -=3D 1; + Offset +=3D PCI_INTERRUPTS_CELLS * sizeof (UINT32); + + // PHandle (skip it) + Offset +=3D sizeof (UINT32); + + // "Parent unit address" (skip it) + Offset +=3D IntcAddressCells * sizeof (UINT32); + + // Interrupt controller interrupt and flags + PciInterruptMapInfo[Index].IntcInterrupt.Interrupt =3D + FdtGetInterruptId ((UINT32*)&Data[Offset]); + PciInterruptMapInfo[Index].IntcInterrupt.Flags =3D + FdtGetInterruptFlags ((UINT32*)&Data[Offset]); + } // for + + PciInfo->Mapping[PciMappingTableInterrupt].ObjectId =3D + CREATE_CM_ARM_OBJECT_ID (EArmObjPciInterruptMapInfo); + PciInfo->Mapping[PciMappingTableInterrupt].Size =3D + sizeof (CM_ARM_PCI_INTERRUPT_MAP_INFO) * IrqMapCount; + PciInfo->Mapping[PciMappingTableInterrupt].Data =3D PciInterruptMapInfo; + PciInfo->Mapping[PciMappingTableInterrupt].Count =3D IrqMapCount; + + return Status; +} + +/** Parse a Host-pci node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [in] HostPciNode Offset of a host-pci node. + @param [in, out] PciInfo The CM_ARM_PCI_CONFIG_SPACE_INFO to popul= ate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +PciNodeParser ( + IN CONST VOID * Fdt, + IN INT32 HostPciNode, + IN OUT PCI_PARSER_TABLE * PciInfo + ) +{ + EFI_STATUS Status; + INT32 AddressCells; + INT32 SizeCells; + CONST UINT8 * Data; + INT32 DataSize; + INT32 SegGroup; + + if ((Fdt =3D=3D NULL) || + (PciInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Segment Group / DomainId + Status =3D GetPciSegGroup (Fdt, HostPciNode, &SegGroup); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + PciInfo->PciConfigSpaceInfo.PciSegmentGroupNumber =3D SegGroup; + + // Bus range + Status =3D PopulateBusRange (Fdt, HostPciNode, PciInfo); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D FdtGetParentAddressInfo ( + Fdt, + HostPciNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Only support 32/64 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, HostPciNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize !=3D ((AddressCells + SizeCells) * sizeof (UINT32)))) { + // If error or wrong size. + ASSERT (0); + return EFI_ABORTED; + } + + // Base address + if (AddressCells =3D=3D 2) { + PciInfo->PciConfigSpaceInfo.BaseAddress =3D fdt64_to_cpu (*(UINT64*)Da= ta); + } else { + PciInfo->PciConfigSpaceInfo.BaseAddress =3D fdt32_to_cpu (*(UINT32*)Da= ta); + } + + // Address map + Status =3D ParseAddressMap ( + Fdt, + HostPciNode, + AddressCells, + PciInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Irq map + Status =3D ParseIrqMap ( + Fdt, + HostPciNode, + PciInfo + ); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + ASSERT (0); + } + + return EFI_SUCCESS; +} + +/** Add the parsed Pci information to the Configuration Manager. + + CmObj of the following types are concerned: + - EArmObjPciConfigSpaceInfo + - EArmObjPciAddressMapInfo + - EArmObjPciInterruptMapInfo + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] PciTableInfo PCI_PARSER_TABLE structure containing the + CmObjs to add. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +PciInfoAdd ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN PCI_PARSER_TABLE *PciTableInfo + ) +{ + EFI_STATUS Status; + CM_ARM_PCI_CONFIG_SPACE_INFO *PciConfigSpaceInfo; + + if ((FdtParserHandle =3D=3D NULL) || + (PciTableInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + PciConfigSpaceInfo =3D &PciTableInfo->PciConfigSpaceInfo; + + // Add the address map space CmObj to the Configuration Manager. + Status =3D AddMultipleCmObjWithCmObjRef ( + FdtParserHandle, + &PciTableInfo->Mapping[PciMappingTableAddress], + &PciConfigSpaceInfo->AddressMapToken + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the interrupt map space CmObj to the Configuration Manager. + // Possible to have no legacy interrupts, or no device described and + // thus no interrupt-mapping. + if (PciTableInfo->Mapping[PciMappingTableInterrupt].Count !=3D 0) { + Status =3D AddMultipleCmObjWithCmObjRef ( + FdtParserHandle, + &PciTableInfo->Mapping[PciMappingTableInterrupt], + &PciConfigSpaceInfo->InterruptMapToken + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } + + // Add the configuration space CmObj to the Configuration Manager. + Status =3D AddSingleCmObj ( + FdtParserHandle, + CREATE_CM_ARM_OBJECT_ID (EArmObjPciConfigSpaceInfo), + &PciTableInfo->PciConfigSpaceInfo, + sizeof (CM_ARM_PCI_CONFIG_SPACE_INFO), + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Free the CmObjDesc of the ParserTable. + + @param [in] PciTableInfo PCI_PARSER_TABLE structure containing the + CmObjs to free. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeParserTable ( + IN PCI_PARSER_TABLE *PciTableInfo + ) +{ + UINT32 Index; + VOID *Data; + + if (PciTableInfo =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < PciMappingTableMax; Index++) { + Data =3D PciTableInfo->Mapping[Index].Data; + if (Data !=3D NULL) { + FreePool (Data); + } + } + + return EFI_SUCCESS; +} + +/** CM_ARM_PCI_CONFIG_SPACE_INFO parser function. + + The following structure is populated: + typedef struct CmArmPciConfigSpaceInfo { + UINT64 BaseAddress; // {Populated} + UINT16 PciSegmentGroupNumber; // {Populated} + UINT8 StartBusNumber; // {Populated} + UINT8 EndBusNumber; // {Populated} + } CM_ARM_PCI_CONFIG_SPACE_INFO; + + typedef struct CmArmPciAddressMapInfo { + UINT8 SpaceCode; // {Populated} + UINT64 PciAddress; // {Populated} + UINT64 CpuAddress; // {Populated} + UINT64 AddressSize; // {Populated} + } CM_ARM_PCI_ADDRESS_MAP_INFO; + + typedef struct CmArmPciInterruptMapInfo { + UINT8 PciBus; // {Populated} + UINT8 PciDevice; // {Populated} + UINT8 PciInterrupt; // {Populated} + CM_ARM_GENERIC_INTERRUPT IntcInterrupt; // {Populated} + } CM_ARM_PCI_INTERRUPT_MAP_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmPciConfigInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 Index; + INT32 PciNode; + UINT32 PciNodeCount; + PCI_PARSER_TABLE PciTableInfo; + VOID *Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + // Only search host-pci devices. + // PCI Firmware Specification Revision 3.0, s4.1.2. "MCFG Table Descript= ion": + // "This table directly refers to PCI Segment Groups defined in the syst= em + // via the _SEG object in the ACPI name space for the applicable host br= idge + // device." + Status =3D FdtCountCompatNodeInBranch ( + Fdt, + FdtBranch, + &PciCompatibleInfo, + &PciNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (PciNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // Parse each host-pci node in the branch. + PciNode =3D FdtBranch; + for (Index =3D 0; Index < PciNodeCount; Index++) { + ZeroMem (&PciTableInfo, sizeof (PCI_PARSER_TABLE)); + + Status =3D FdtGetNextCompatNodeInBranch ( + Fdt, + FdtBranch, + &PciCompatibleInfo, + &PciNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + Status =3D PciNodeParser (Fdt, PciNode, &PciTableInfo); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // Add Pci information to the Configuration Manager. + Status =3D PciInfoAdd (FdtParserHandle, &PciTableInfo); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D FreeParserTable (&PciTableInfo); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + + return Status; + +error_handler: + FreeParserTable (&PciTableInfo); + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSp= aceParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigS= paceParser.h new file mode 100644 index 000000000000..b260c53a82ab --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpacePars= er.h @@ -0,0 +1,142 @@ +/** @file + Arm PCI Configuration Space Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/pci/host-generic-pci.yaml + - PCI Firmware Specification - Revision 3.0 + - Open Firmware Recommended Practice: Interrupt Mapping, Version 0.9 + - Devicetree Specification Release v0.3 + - linux kernel code +**/ + +#ifndef ARM_PCI_CONFIG_SPACE_PARSER_H_ +#define ARM_PCI_CONFIG_SPACE_PARSER_H_ + +/** Read LEN bits at OFF offsets bits of the ADDR. + + @param [in] ADDR Address to read the bits from. + @param [in] OFF Offset of the bits to read. + @param [in] LEN Number of bits to read. + + @return The bits read. +**/ +#define READ_BITS(ADDR, OFF, LEN) (((ADDR) >> (OFF)) & ((1<<(LEN))-1)) + +/* Pci address attributes. +*/ +/// 0 if relocatable. +#define READ_PCI_N(ADDR) READ_BITS((ADDR), 31, 1) +/// 1 if prefetchable. +#define READ_PCI_P(ADDR) READ_BITS((ADDR), 30, 1) +/// 1 if aliased. +#define READ_PCI_T(ADDR) READ_BITS((ADDR), 29, 1) +/** Space code. + + 00: Configuration Space + 01: I/O Space + 10: 32-bit-address Memory Space + 11: 64-bit-address Memory Space +*/ +#define READ_PCI_SS(ADDR) READ_BITS((ADDR), 24, 2) +/// Bus number. +#define READ_PCI_BBBBBBBB(ADDR) READ_BITS((ADDR), 16, 8) +/// Device number. +#define READ_PCI_DDDDD(ADDR) READ_BITS((ADDR), 11, 5) + +/** Number of device-tree cells used for PCI nodes properties. + + Values are well defined, except the "#interrupt-cells" which + is assumed to be 1. +*/ +#define PCI_ADDRESS_CELLS 3U +#define PCI_SIZE_CELLS 2U +#define PCI_INTERRUPTS_CELLS 1U + +/** PCI interrupt flags for device-tree. + + Local Bus Specification Revision 3.0, s2.2.6., Interrupt Pins: + - 'Interrupts on PCI are optional and defined as "level sensitive," + asserted low (negative true)' +*/ +#define DT_PCI_IRQ_FLAGS(x) (((x) & 0xF) =3D=3D BIT0) + +/** Indexes in the mapping table. +*/ +typedef enum PciMappingTable { + PciMappingTableAddress, ///< 0 - Address mapping + PciMappingTableInterrupt, ///< 1 - Interrupt mapping + PciMappingTableMax, ///< 2 - Max +} PCI_MAPPING_TABLE; + +#pragma pack(1) + +/** PCI parser table + + Multiple address-map and interrupt map can correspond to + one host-pci device. This structure allows to temporarily + store the CmObjects created and generate tokens once + the whole device tree is parsed. +*/ +typedef struct PciParserTable { + /// PCI Configuration Space Info + CM_ARM_PCI_CONFIG_SPACE_INFO PciConfigSpaceInfo; + + /// Store the address mapping and interrupt mapping as CmObjDesc + /// before adding them to the Configuration Manager. + CM_OBJ_DESCRIPTOR Mapping[PciMappingTableMax]; +} PCI_PARSER_TABLE; + +#pragma pack() + +/** CM_ARM_PCI_CONFIG_SPACE_INFO parser function. + + The following structure is populated: + typedef struct CmArmPciConfigSpaceInfo { + UINT64 BaseAddress; // {Populated} + UINT16 PciSegmentGroupNumber; // {Populated} + UINT8 StartBusNumber; // {Populated} + UINT8 EndBusNumber; // {Populated} + } CM_ARM_PCI_CONFIG_SPACE_INFO; + + typedef struct CmArmPciAddressMapInfo { + UINT8 SpaceCode; // {Populated} + UINT64 PciAddress; // {Populated} + UINT64 CpuAddress; // {Populated} + UINT64 AddressSize; // {Populated} + } CM_ARM_PCI_ADDRESS_MAP_INFO; + + typedef struct CmArmPciInterruptMapInfo { + UINT8 PciBus; // {Populated} + UINT8 PciDevice; // {Populated} + UINT8 PciInterrupt; // {Populated} + CM_ARM_GENERIC_INTERRUPT IntcInterrupt; // {Populated} + } CM_ARM_PCI_INTERRUPT_MAP_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +ArmPciConfigInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_PCI_CONFIG_SPACE_PARSER_H_ --=20 2.25.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 (#83970): https://edk2.groups.io/g/devel/message/83970 Mute This Topic: https://groups.io/mt/87263332/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- From nobody Thu Mar 28 21:22:26 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+83971+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+83971+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687380; cv=none; d=zohomail.com; s=zohoarc; b=GgBYC7KvL2lf8uB2kD9aPYVNz1G9QCTLGi7s7iJJwysFnTE4ZtzPyuBRJLvyonezcleub5IWP8C8/EGzSaMJGQNY1+nJBnJDMPjINezoLK9Go0ivuLEzvkfxPRIFH7LXk25fr1eF+Qks+5Gjd7iDswY4JLl2QHLSNfGTEJOkRkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687380; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3R9ExCHiqKgb8BZN7b+lr7eFvLGLE+whkc+JhLpvZrM=; b=W1itRicR2mTA44BdH5FktCyluvCjVMhC7DdJaNHik6XcDJlmY/DgoqE3FGqO2DVZ+ODu/jRNzGwFqilNcwgwZq+Ry6iBzESmEaR1mLnvGSZ7sgjKaDM/dLOArnnYvXZUI882VHuriGxYCUNFT75Ngs+aPzPsVjdawbSdB2qjb5w= 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+83971+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 1637687380688659.015866111678; Tue, 23 Nov 2021 09:09:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9b0YYY1788612x5rXTm3BKUz; Tue, 23 Nov 2021 09:09:38 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14284.1637687372332589290 for ; Tue, 23 Nov 2021 09:09:32 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A2141FB; Tue, 23 Nov 2021 09:09:32 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 447FD3F5A1; Tue, 23 Nov 2021 09:09:31 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 14/15] DynamicTablesPkg: Add FdtHwInfoParser library Date: Tue, 23 Nov 2021 18:08:37 +0100 Message-Id: <20211123170838.143805-15-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: p64YQ6ODz1kP3MoblobasPD6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687378; bh=85hspVGRoX3clk+Sb7Q3Vh2d2JPlfCYtbKKFwysAAsc=; h=Cc:Date:From:Reply-To:Subject:To; b=iTAo7jjlr/ez362pZ71AfZloTVVvC9psPgAA233ZcNO9vAbM4fLS0tsX9ud4gQ3Ij4D AeDcT9APOAfjxuUrGwCrNSTD1cW8/E5Hz8IX/F3GrEwTXyThaeFdJ9N110xWlyoqr0F0I 1sUWIWXCzObLfKFQTpMzlOiMXGIem78exIQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687381731100005 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Hardware information parser is an optional module defined by the Dynamic Tables Framework. It can either parse an XML, a Device Tree or a Json file containing the platform hardware information to populate the platform information repository. FdtHwInfoParser library is an instance of a HwInfoParser that parses a Device Tree and populates the Configuration Manager Platform information repository. FdtHwInfoParser library is aimed at providing a solution for generating ACPI tables for Guest Partitions launched by virtual machine managers (VMMs). One such use case is Kvmtool where the Device Tree for the Guest is passed on to the firmware by Kvmtool. The Configuration Manager for Kvmtool firmware shall invoke the FdtHwInfoParser to parse the Device Tree to populate the hardware information in the Platform Info Repository. The Kvmtool Configuration Manager can the process this information to generate the required ACPI tables for the Guest VM. This approach also scales well if the number of CPUs or if the hardware configuration of the Guest partition is varied. FdtHwInfoParser thereby introduces 'Dynamic Tables for Virtual Machines'. Ref:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3741 Signed-off-by: Pierre Gondois --- DynamicTablesPkg/DynamicTablesPkg.dsc | 3 +- .../FdtHwInfoParserLib/FdtHwInfoParser.c | 190 ++++++++++++++++++ .../FdtHwInfoParserLib/FdtHwInfoParser.h | 63 ++++++ .../FdtHwInfoParserInclude.h | 17 ++ .../FdtHwInfoParserLib/FdtHwInfoParserLib.inf | 56 ++++++ 5 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPa= rser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPa= rser.h create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPa= rserInclude.h create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPa= rserLib.inf diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/Dynam= icTablesPkg.dsc index e1439a130143..a2a1b8d004d2 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dsc +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc @@ -2,7 +2,7 @@ # Dsc file for Dynamic Tables Framework. # # Copyright (c) 2019, Linaro Limited. All rights reserved.
-# Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -43,6 +43,7 @@ [Components.common] DynamicTablesPkg/Library/Common/AmlLib/AmlLib.inf DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFix= upLib.inf DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf + DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf =20 [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c = b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c new file mode 100644 index 000000000000..4c9611194421 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c @@ -0,0 +1,190 @@ +/** @file + Flattened Device Tree parser library for KvmTool. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "FdtHwInfoParser.h" +#include "BootArch/ArmBootArchParser.h" +#include "GenericTimer/ArmGenericTimerParser.h" +#include "Gic/ArmGicDispatcher.h" +#include "Pci/ArmPciConfigSpaceParser.h" +#include "Serial/ArmSerialPortParser.h" + +/** Ordered table of parsers/dispatchers. + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. +*/ +STATIC CONST FDT_HW_INFO_PARSER_FUNC HwInfoParserTable[] =3D { + ArmBootArchInfoParser, + ArmGenericTimerInfoParser, + ArmGicDispatcher, + ArmPciConfigInfoParser, + SerialPortDispatcher +}; + +/** Main dispatcher: sequentially call the parsers/dispatchers + of the HwInfoParserTable. + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +MainDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + UINT32 Index; + + if (fdt_check_header (FdtParserHandle->Fdt) < 0) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < ARRAY_SIZE (HwInfoParserTable); Index++) { + Status =3D HwInfoParserTable[Index] ( + FdtParserHandle, + FdtBranch + ); + if (EFI_ERROR (Status) && + (Status !=3D EFI_NOT_FOUND)) { + // If EFI_NOT_FOUND, the parser didn't find information in the DT. + // Don't trigger an error. + ASSERT (0); + return Status; + } + } // for + + return EFI_SUCCESS; +} + +/** Initialise the HwInfoParser. + + The HwInfoParser shall use the information provided by the HwDataSource + to initialise the internal state of the parser or to index the data. This + internal state shall be linked to the ParserHandle using an implementati= on + defined mechanism. + + @param [in] HwDataSource Pointer to the blob containing the hardware + information. It can be a pointer to a Devi= ce + Tree, an XML file, etc. or any other data + structure defined by the HwInfoParser. + @param [in] Context A pointer to the caller's context. + @param [in] HwInfoAdd Function pointer called by the parser when + adding information. + @param [out] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +HwInfoParserInit ( + IN VOID * HwDataSource, + IN VOID * Context, + IN HW_INFO_ADD_OBJECT HwInfoAdd, + OUT HW_INFO_PARSER_HANDLE * ParserHandle + ) +{ + FDT_HW_INFO_PARSER * FdtParserHandle; + + if ((ParserHandle =3D=3D NULL) || + (HwInfoAdd =3D=3D NULL) || + (HwDataSource =3D=3D NULL) || + (fdt_check_header (HwDataSource) < 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + FdtParserHandle =3D AllocateZeroPool (sizeof (FDT_HW_INFO_PARSER)); + if (FdtParserHandle =3D=3D NULL) { + *ParserHandle =3D NULL; + return EFI_OUT_OF_RESOURCES; + } + + // The HwDataSource is a pointer to the FDT data. + FdtParserHandle->Fdt =3D HwDataSource; + FdtParserHandle->Context =3D Context; + FdtParserHandle->HwInfoAdd =3D HwInfoAdd; + + *ParserHandle =3D (HW_INFO_PARSER_HANDLE)FdtParserHandle; + return EFI_SUCCESS; +} + +/** Parse the data provided by the HwDataSource. + + @param [in] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +HwInfoParse ( + IN HW_INFO_PARSER_HANDLE ParserHandle + ) +{ + EFI_STATUS Status; + + if (ParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Call all the parsers from the root node (-1). + Status =3D MainDispatcher ( + (FDT_HW_INFO_PARSER_HANDLE)ParserHandle, + -1 + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Cleanup any internal state and resources that were allocated + by the the HwInfoParser. + + @param [in] ParserHandle A handle to the parser instance. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +HwInfoParserShutdown ( + IN HW_INFO_PARSER_HANDLE ParserHandle +) +{ + if (ParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + FreePool (ParserHandle); + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h = b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h new file mode 100644 index 000000000000..1c40fc5587c9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h @@ -0,0 +1,63 @@ +/** @file + Flattened Device Tree parser definitions. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef FDT_HW_INFO_PARSER_H_ +#define FDT_HW_INFO_PARSER_H_ + +#include + +#include +#include + +#include "FdtUtility.h" + +/** A structure describing the instance of the FdtHwInfoParser. +*/ +typedef struct FdtHwInfoParser { + /// Pointer to the HwDataSource i.e. the + /// Flattened Device Tree (Fdt). + VOID * Fdt; + + /// Pointer to the caller's context. + VOID * Context; + + /// Function pointer called by the + /// parser when adding information. + HW_INFO_ADD_OBJECT HwInfoAdd; +} FDT_HW_INFO_PARSER; + +/** A pointer type for FDT_HW_INFO_PARSER. +*/ +typedef FDT_HW_INFO_PARSER* FDT_HW_INFO_PARSER_HANDLE; + +/** Function pointer to a parser function. + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] ParserHandle Handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +typedef +EFI_STATUS +(EFIAPI * FDT_HW_INFO_PARSER_FUNC) ( + IN CONST FDT_HW_INFO_PARSER_HANDLE ParserHandle, + IN INT32 FdtBranch + ); + +#endif // FDT_HW_INFO_PARSER_H_ diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInc= lude.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude= .h new file mode 100644 index 000000000000..583f290095d9 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude.h @@ -0,0 +1,17 @@ +/** @file + Include file for Fdt HwInfoParser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef FDT_HW_INFO_PARSER_INCLUDE_H_ +#define FDT_HW_INFO_PARSER_INCLUDE_H_ + +#include +#include +#include +#include +#include + +#endif // FDT_HW_INFO_PARSER_INCLUDE_H_ diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib= .inf b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf new file mode 100644 index 000000000000..d2c171accaa5 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf @@ -0,0 +1,56 @@ +## @file +# Flattened Device Tree information parser. +# +# Copyright (c) 2021, ARM Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010019 + BASE_NAME =3D FdtHwInfoParserLib + FILE_GUID =3D F174A422-BC86-41E2-9E9C-C6D6E437F4AD + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D HwInfoParserLib + +[Sources] + CmObjectDescUtility.c + CmObjectDescUtility.h + FdtHwInfoParserInclude.h + FdtHwInfoParser.c + FdtHwInfoParser.h + FdtUtility.c + FdtUtility.h + BootArch/ArmBootArchParser.c + BootArch/ArmBootArchParser.h + GenericTimer/ArmGenericTimerParser.c + GenericTimer/ArmGenericTimerParser.h + Gic/ArmGicCParser.c + Gic/ArmGicCParser.h + Gic/ArmGicDispatcher.c + Gic/ArmGicDispatcher.h + Gic/ArmGicDParser.c + Gic/ArmGicDParser.h + Gic/ArmGicItsParser.c + Gic/ArmGicItsParser.h + Gic/ArmGicMsiFrameParser.c + Gic/ArmGicMsiFrameParser.h + Gic/ArmGicRParser.c + Gic/ArmGicRParser.h + Pci/ArmPciConfigSpaceParser.c + Pci/ArmPciConfigSpaceParser.h + Serial/ArmSerialPortParser.c + Serial/ArmSerialPortParser.h + +[Packages] + ArmPkg/ArmPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + FdtLib + MemoryAllocationLib --=20 2.25.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 (#83971): https://edk2.groups.io/g/devel/message/83971 Mute This Topic: https://groups.io/mt/87263333/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- From nobody Thu Mar 28 21:22:26 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+83972+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+83972+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1637687379; cv=none; d=zohomail.com; s=zohoarc; b=jQLDvmS2CbrOHuGjLpGKW7bb5IkbOI7IIsJGGthEVjk8cy8K6Ny94XxI/+E41Pze7kxVopX4Sf99P+yCcsTmF1nlu9tgvht+ApsbOw9LNZbnTzPmbGzq8H2VRnU3dT+x6HjZjbJpo+F1Kdm8GQyuw+wwBtRjYchFbCi4ZXsIouI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687379; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=9fvgs8uHQ7LPEiFE6b8GT1kiku/N0hbjoEFTQMTODxc=; b=Pa5hgb7NH3y1/wCiBvAAlV8spCUv1FD+kFdlkMamR26W3BRGSx3VyBWVyON866gFLzuamalkt1ny1P3+CwuA8GiIJrWfq9kML1vNgBJLu/uTWLPhhLKu8qiCv5wmM7Y/282AOO3PkaI3KIR1/sNhAgAxcu4gkqINBDnIOWrnr+c= 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+83972+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 1637687379811510.84536969915996; Tue, 23 Nov 2021 09:09:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 40ZgYY1788612xufVkWIAytk; Tue, 23 Nov 2021 09:09:39 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.14322.1637687373668306288 for ; Tue, 23 Nov 2021 09:09:33 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 541131063; Tue, 23 Nov 2021 09:09:33 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4A9093F5A1; Tue, 23 Nov 2021 09:09:32 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v3 15/15] DynamicTablesPkg: Handle 16550_WITH_GAS id Date: Tue, 23 Nov 2021 18:08:38 +0100 Message-Id: <20211123170838.143805-16-Pierre.Gondois@arm.com> In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,pierre.gondois@arm.com X-Gm-Message-State: J2PMsCYYcgGX5NbPNczvvv6ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637687379; bh=MKe9X1+T23UQXD0II+B1KJWa0R2IxNb5Fx+TtWVeycw=; h=Cc:Date:From:Reply-To:Subject:To; b=EzBxTslO1W4VSwCCpdfFLg5YH1KmWiBG/MzXRjqFVlWrhE4VPawLp9nmNRi5c6sfCz6 lwMIOqWiMBYj1oMkM1Az/eVVS+QqkgCU+m6ofZZmdJM1/bpMVvfm7IvRW++SknwucrRkF RtEk4Z/nmRHal7U7EhPcFkXWTWQmw9bFzIE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637687381478100002 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Handle the EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS id when generating an AML description of a serial port. The same _HID/_CID as the EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550 are generated. Signed-off-by: Pierre Gondois --- Notes: v2: - New patch. [Pierre] .../Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSer= ialPortFixupLib.c b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/= SsdtSerialPortFixupLib.c index 79e1fabc9223..85c7293bb4a6 100644 --- a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c +++ b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c @@ -83,7 +83,9 @@ ValidateSerialPortInfo ( (SerialPortInfo->PortSubtype !=3D EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_DCC) && (SerialPortInfo->PortSubtype !=3D - EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550)) { + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550) && + (SerialPortInfo->PortSubtype !=3D + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS)) { DEBUG (( DEBUG_ERROR, "ERROR: UART port subtype is invalid." @@ -143,6 +145,7 @@ FixupIds ( // Get the _CID and _HID value to write. switch (SerialPortInfo->PortSubtype) { case EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550: + case EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS: { // If there is a non-BSA compliant HID, use that. NonBsaHid =3D (CONST CHAR8*)PcdGetPtr (PcdNonBsaCompliant16550Serial= Hid); --=20 2.25.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 (#83972): https://edk2.groups.io/g/devel/message/83972 Mute This Topic: https://groups.io/mt/87263335/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-