From nobody Sat May 4 16:48:16 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+84586+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+84586+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042336; cv=none; d=zohomail.com; s=zohoarc; b=a+9qhXflQJ/id+t7oWuhl2PXDfnSt0CxncWujveh/rhv0Znp8bt6zQSuEKk9qWqM6ZORh0RbOcbVPDuDD55hjFInkPsjeyARvF0OXbpOyD2VGu1VC9aJXaQze2z20RLAmJ3bo8bJi4RORlZyD3UQuiaPfEVtkC8uC1vqZ8yns+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042336; 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=Z8SBKSSL+rXouvK0dYmHTt3lXpE7SckSwgwFJ3n72DQ=; b=RzIBXUKWJTHyxn/eHuz7iTGtjV+w8Mzlxm99waFxRd4xu91uBuGu3I8l14WNTOFy2jgouYENIY9Cu5V9NEGN6ZAS+smbqyZ8v0cYFFQPAMTWABvmsnJ4+KhoAmWEIfjAn4zCYdX8uOK5IQkEQyI2w18m+DOxPujXc/CDZrsvz0M= 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+84586+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 1639042336465725.4901464772928; Thu, 9 Dec 2021 01:32:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id gpx0YY1788612x2KyaM0NOIt; Thu, 09 Dec 2021 01:32:16 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9302.1639042335507913625 for ; Thu, 09 Dec 2021 01:32:15 -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 EB42211FB; Thu, 9 Dec 2021 01:32:14 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E811D3F73B; Thu, 9 Dec 2021 01:32:13 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 01/15] DynamicTablesPkg: Definition for HwInfoParser interface Date: Thu, 9 Dec 2021 10:31:54 +0100 Message-Id: <20211209093208.1249257-2-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: Ir22oRwwr6DKXGgrGZnYSkHwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042336; bh=0PD8I84ttG/S7J+QqVcv0lPe+FLaqdXXv0MP52Kc8SQ=; h=Cc:Date:From:Reply-To:Subject:To; b=ox2+RAMYLdXcFn8xrUOhPjpg4pCD64iwYRo2yTPkB/FFSt7m0unpL5BSSYN4CMaH1E9 I5CoUNA59JHiQcmw3njfS3bfmDKVZwHxz1nkimXc9ebGf6bVV+ga7YBhtssld6c1pdjd1 Lg73CU95INv+iIl1JV9ZHx9Y3IAJqSvkwnI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042336804100005 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 Reviewed-by: Joey Gouly Reviewed-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..05c21aeac00a --- /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 (#84586): https://edk2.groups.io/g/devel/message/84586 Mute This Topic: https://groups.io/mt/87608902/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 Sat May 4 16:48:16 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+84587+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+84587+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042338; cv=none; d=zohomail.com; s=zohoarc; b=RuMGNuCQO304DL3mCuvM0B5PNbgVUfyhSQT2nfnMAnK5kFuRoXJ6XzJUAtoOt3RaPlipVrdAQXfCA+0iZFeOdGMnKQizKtmhvnUqUe6TdN20HJjbX0V1/n2opnIR3p2iLUDbQuaA3ix/hhfmmL4HDk6Y5MAnFZiH7BJIfxtgk+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042338; 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=qR7XX3o7CLlrn+DYui6GyR/8iyItInkTbTf6bkx6/a0=; b=f/5Zlb9Vlob9UW/6LYvKiXE+rr6mdkeAdpp4ydiAZE/BAouSnDIHAnRQYoSNIkjJzYI88BY9d1DhzeKXhtkxewLlGB8bv95vCGPssdvyV/OLzmlIZ2fVYbwQGxsffplhXrPzNwTOPYwW+ofpFsJ0GE8yAIo6uih5uA30pxiShrM= 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+84587+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 1639042338026849.3000952208441; Thu, 9 Dec 2021 01:32:18 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id GVm2YY1788612xW81A9A9Ve1; Thu, 09 Dec 2021 01:32:17 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9303.1639042336933685021 for ; Thu, 09 Dec 2021 01:32:17 -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 946C811FB; Thu, 9 Dec 2021 01:32:16 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 574483F73B; Thu, 9 Dec 2021 01:32:15 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 02/15] DynamicTablesPkg: FdtHwInfoParser: CM Object descriptor helper Date: Thu, 9 Dec 2021 10:31:55 +0100 Message-Id: <20211209093208.1249257-3-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: mQjMikftHMOvSm0lbmP4ZHiSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042337; bh=ESlPwAbqGXUuUB+YUJCs0RWmNdhaWUiwRA5AKJzWZz8=; h=Cc:Date:From:Reply-To:Subject:To; b=wFd2qZHDIdd2GS6wAH8nfmVqgIAqovJqfvhXU2Bm8ZWZ1UQhB6ZhLJoRHRfkH3sqTSE Xc9g5/JJoloY11QCLHZMPsTpDO6meVD54ZD/wz0/mUfP6xp3alKh3PdInpw0ijlS5jMBI dy/jjeAFC1BP/D+uBbEQcGWIjNOWlEWq5S0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042339212100002 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/CmObjectDescUtility.c | 306 ++++++++++++++++++ .../FdtHwInfoParserLib/CmObjectDescUtility.h | 131 ++++++++ 2 files changed, 437 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..8be1b5b8cd88 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.c @@ -0,0 +1,306 @@ +/** @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..270e0c3528f9 --- /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 (#84587): https://edk2.groups.io/g/devel/message/84587 Mute This Topic: https://groups.io/mt/87608905/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 Sat May 4 16:48:16 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+84588+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+84588+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042339; cv=none; d=zohomail.com; s=zohoarc; b=VR6uHkTS/eO3b9Tq76nvaWieNTqPW0JndeCRO27pnYfTvRoBHOG4Lh9ytlv1qBDkXR4AmhZx3/thWbizTAH1dCViCwdei5UfvZG/b92E5CyJY3HthzfdXoKgjoTsnzrU14gz3BBIDRq3efgPHpGr1FHyb25BQeaAK138H9LfNnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042339; 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=W/O8c693G4+bD1t1AFeJ5C8FFV9fBaYT6kOde/BBwxs=; b=ap6NaH9pp+Fv67N6QF30VeSlchdzTWFYTrfmQhyhbsCZHydOzJBCRK1xREizV0ltGAE/jkRQuwF4Nib/7X7ZgrOwX31kdguA/Q4879OHohKIqIqzz5cijCZokaHb0VtFvum2BRHM4QHiGEoeCv1T8LNdcw4ZRNjNlnTjLeXyiFM= 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+84588+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 163904233952098.63428114243231; Thu, 9 Dec 2021 01:32:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id FopiYY1788612xK4bJjCFJNt; Thu, 09 Dec 2021 01:32:19 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9304.1639042338487116846 for ; Thu, 09 Dec 2021 01:32: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 18B7A1474; Thu, 9 Dec 2021 01:32:18 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F31AD3F73B; Thu, 9 Dec 2021 01:32:16 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 03/15] DynamicTablesPkg: FdtHwInfoParser: Add FDT utility functions Date: Thu, 9 Dec 2021 10:31:56 +0100 Message-Id: <20211209093208.1249257-4-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: dpSfWVPfsNlM5GIOsIkVyTwBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042339; bh=MyoGuPDk++vxO/TGsSvsGLs5NK4RpFQd0DVMmSpO7J0=; h=Cc:Date:From:Reply-To:Subject:To; b=QlVQpXf55DcEscqGi4hPqprJMSKpRc4r4vxgFkV1VflEqK+aRqnuEi369YXRq0nSoeX kSy/7gYQZYP5ujt+3GpgZnM4yEnUprohKaBcnNfOCRb1O7m6MEUgl5M0EZtveMgyiJdM5 YfhhYWDqXGLUZ1nmbmzYuFuMHsdpVOsc0rY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042341525100002 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 Reviewed-by: Sami Mujawar --- .../Library/FdtHwInfoParserLib/FdtUtility.c | 923 ++++++++++++++++++ .../Library/FdtHwInfoParserLib/FdtUtility.h | 458 +++++++++ 2 files changed, 1381 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..5314cf3808c2 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.c @@ -0,0 +1,923 @@ +/** @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..f2f425632b10 --- /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 (#84588): https://edk2.groups.io/g/devel/message/84588 Mute This Topic: https://groups.io/mt/87608906/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 Sat May 4 16:48:16 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+84589+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+84589+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042340; cv=none; d=zohomail.com; s=zohoarc; b=CyeapGIhgJ4wcGKgWqzSpMF9jA05KnN+6ZWcnLJGisietq1JbtorulTCVQnv9ggvdxgDgwCsDCbUbvBiK0ImZwzdV2I3skSmzdOeIspdcQ/S11aJGzw6w6Zdcq5XiVSdVtWYDjr+XGjKdJwAtsBM4npMmPD57EVnuV8pR4X7/CA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042340; 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=BRJ+UIxSNpSTqEt012DTEXEQpkjrnNdE4PqPT8YF9eA=; b=AU+AB3PHiejV1cpEmTAChM29Cg7X3zeZXhKDM4eOgSl6cc0ROjcfyresA77LEiRqYEGOIGKDXd/KVs7zuzf4JkISa5U8phIeNP06lyU3bxcJTti7A31xn8AEDqKzhadt6UE7ANNPU5WTtaFkgytY9MF8tUXt83r/2tBzTKWj81c= 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+84589+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 1639042340689419.89730268807466; Thu, 9 Dec 2021 01:32:20 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ah8GYY1788612xJ7a8IiAGks; Thu, 09 Dec 2021 01:32:20 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9305.1639042339678881807 for ; Thu, 09 Dec 2021 01:32:19 -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 4D6CC1476; Thu, 9 Dec 2021 01:32:19 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 68E883F73B; Thu, 9 Dec 2021 01:32:18 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 04/15] DynamicTablesPkg: FdtHwInfoParser: Add Boot Arch parser Date: Thu, 9 Dec 2021 10:31:57 +0100 Message-Id: <20211209093208.1249257-5-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: 8amecvCOiH1BhlUJAUXYMmYzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042340; bh=LtFwJAEQoX7yokO8M11tW93Xq0A1LtqufRScefwiCOA=; h=Cc:Date:From:Reply-To:Subject:To; b=c4JDVJFpDHkaCdohWxJQTtVab4fPCSU6NzQKBhDlIVek/ZwlVKzY5bM4H3PuEKZgEXM d2RfRqGW6tPGP1fMvbD7kEKS4niP2TOIuFm7tlo0Z0Do8wXKKjbC97n2CQYC6w+OBCW+J Ic5IAJ5Zezw12aGOz1w+dMbvN1XMDJnGH0s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042341787100005 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 Reviewed-by: Sami Mujawar --- .../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..b07b6b8b666a --- /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..51654f0e1ea8 --- /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 (#84589): https://edk2.groups.io/g/devel/message/84589 Mute This Topic: https://groups.io/mt/87608907/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 Sat May 4 16:48:16 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+84590+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+84590+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042342; cv=none; d=zohomail.com; s=zohoarc; b=Ou9aMl5r0qom2KMV2e30vjCEy2rwnlb5GoujugkWb3J4D0KQ6OGMtK8mlOv2+qJlfLA4j2cDLU4oF6KjiajOI6aW4VGaQj6mjyysjPR4BFHpW18LwLu1VHKr2AQRc0gejdzK0g1hxIFHSqZal/Py1Wy5EuRz1H2PFaH5ApbRNEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042342; 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=yLql5oyktCfrFlCKW02s74SudT81htrbtD0zmDFUmcc=; b=FztqCua5Ewuxoxte/6pjw7ros06q1MOOes00DlxzkJfn9a8NdukmTtoUgGVGU1VlAPas0F0YC4bX/RwRmA+DS6kEwrYMY1c7WXwVco/7/J/zal92LyJVtvBhj6nZnkmVwLive8CIAwRJ/JbpLp33I+7bd9Iz/CMl99qUhlKuz/Q= 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+84590+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 1639042342094166.03967362929745; Thu, 9 Dec 2021 01:32:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8bbmYY1788612x7NtZd0a4Jt; Thu, 09 Dec 2021 01:32:21 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9532.1639042341073511391 for ; Thu, 09 Dec 2021 01:32: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 917E811FB; Thu, 9 Dec 2021 01:32:20 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 88EAB3F73B; Thu, 9 Dec 2021 01:32:19 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 05/15] DynamicTablesPkg: FdtHwInfoParser: Generic Timer Parser Date: Thu, 9 Dec 2021 10:31:58 +0100 Message-Id: <20211209093208.1249257-6-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: sWVePtyh5wc1ySuKGxRGLj9Ex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042341; bh=M57NNfK5M5VsTIHcHaaYTtu+bXUGEE5t2NHRNGrP/IM=; h=Cc:Date:From:Reply-To:Subject:To; b=KlyEoLjZEXBVs8+OWUzBvsQwElXgvE/HABpKZQHoWRQ9+MVt2oRjKS7KenTyeJUy30W IEeGP3pXErPxpzY0We3/oCB6RXlvyXBJvTTKNx9DHpdNwJlzqPgGxCe3Dnj3Uo9Q0Z8fF 8EHwoN/fYNlV3llTJo7hWLZ1rYX8ooxoCxQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042343941100010 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 Reviewed-by: Sami Mujawar --- .../GenericTimer/ArmGenericTimerParser.c | 258 ++++++++++++++++++ .../GenericTimer/ArmGenericTimerParser.h | 66 +++++ 2 files changed, 324 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..988a81221dab --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTi= merParser.c @@ -0,0 +1,258 @@ +/** @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..d7fa278c90f9 --- /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 (#84590): https://edk2.groups.io/g/devel/message/84590 Mute This Topic: https://groups.io/mt/87608908/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 Sat May 4 16:48:16 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+84591+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+84591+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042343; cv=none; d=zohomail.com; s=zohoarc; b=XDAPkNmKiZkOwi8SlfvnUcUAXqjM+k6pGslF5gLh+bD1kmLZ+T4xNFfZtlqBtREIwUo/b+GGDcJMDvhFRE7npRl+n+Sc9XAsaJmgnfwG9Hk/sDd7290yUB0viWGzZRBwk3j7a3CbyKm63S253OURIldtevYRIbQi5x3upvs7u1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042343; 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=+h2RfZeJDj/fx05Ld7tJA1rt/Oxkptg0WW1tRIkBJLs=; b=fS+B1YO6FhB7xGJ7jwiPpI9POxIppAjuOsOWlaUYh0f2ob79ijzAijjvrnL9dqrM4DMbpnvo8pZ2ywJMYTOLMx83EGJtl4gLFCR/fqRExqrt/H8JJ2vikS56LsKlEeRcJDjXknkuOFZqlnglHJlguHsy8iXmQjAUiyuIKCs79cE= 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+84591+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 1639042343289600.3366116931066; Thu, 9 Dec 2021 01:32:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id TFgXYY1788612xxBSvw3mger; Thu, 09 Dec 2021 01:32:22 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9533.1639042342206830054 for ; Thu, 09 Dec 2021 01:32: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 D06281474; Thu, 9 Dec 2021 01:32:21 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F186C3F73B; Thu, 9 Dec 2021 01:32:20 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 06/15] DynamicTablesPkg: FdtHwInfoParser: Add Serial port parser Date: Thu, 9 Dec 2021 10:31:59 +0100 Message-Id: <20211209093208.1249257-7-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: 6mHYCLnokMzVsyXB6Q3cbJ6Lx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042342; bh=88adg6BjrEMABE401y8hwfGab2ZqaVZMOer3A2YI86w=; h=Cc:Date:From:Reply-To:Subject:To; b=tJ0+OCRUmeBRd0NwNiySDjIg1q10gjwwBau9/t5GqCJWsb39BDEFszek+Vqs8El2Eb2 ELAMuMeU0HHEX5i4FYS8KucZPsjSAFlF3Pbp5Y6vCgRaf+NmUJJNmaik0+0f9PAemeVsK gz8FgzULH/wQxLGWEQlXVWORkRuSBZV7UnY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042344183100013 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 Reviewed-by: Sami Mujawar --- .../Serial/ArmSerialPortParser.c | 633 ++++++++++++++++++ .../Serial/ArmSerialPortParser.h | 47 ++ 2 files changed, 680 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..0557e416b44c --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParse= r.c @@ -0,0 +1,633 @@ +/** @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, Size= Cells)) - 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 *)SizeVal= ue); + } else { + SerialPortInfo->BaseAddressLength =3D fdt32_to_cpu (*(UINT32 *)SizeVal= ue); + } + + // 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..de08e57e6c57 --- /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 (#84591): https://edk2.groups.io/g/devel/message/84591 Mute This Topic: https://groups.io/mt/87608909/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 Sat May 4 16:48:16 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+84592+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+84592+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042344; cv=none; d=zohomail.com; s=zohoarc; b=DtljzY7aN84Nlv2EgDsN1f214v3fujyeBH40wwlB50d56u8tnc3KhyreRYVh6sRPmxb2XBSPV2n8Dyk6csrLpKnHVvFdZe4VwaQc3xfNTEH5aSVWdqX6AoGIslRoXclIYKeoYr5Ts3ntd9XhxeGbdbGdCduWedcbbvlMNNsICMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042344; 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=xnzSuk9khIDFHGMIykLxe9NNnhkHwDt/JPsd3t8asvY=; b=fJeqCdO0q5JCeTYRDMd1iDLGnXeSkXRUMT9slfsmPmvU1vl9JrcogpaOHj7k3t++tvgW4xQwk8Anj5qnN6hOa8RL/8nx+nSfDgcx56/8oIoo1Ee5YXtdQ/wpg6VpltTZG0FZKibI6gXAhrlz7EJcenVOJm6kHjg4rSMPsV/kezE= 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+84592+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 163904234452065.98184900783929; Thu, 9 Dec 2021 01:32:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7W7DYY1788612xzjwhNccf1S; Thu, 09 Dec 2021 01:32:24 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9306.1639042343525138926 for ; Thu, 09 Dec 2021 01:32: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 29C5611FB; Thu, 9 Dec 2021 01:32:23 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1C3AA3F73B; Thu, 9 Dec 2021 01:32:21 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 07/15] DynamicTablesPkg: FdtHwInfoParser: Add GICC parser Date: Thu, 9 Dec 2021 10:32:00 +0100 Message-Id: <20211209093208.1249257-8-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: 2nX3ygYphrYYn70zUoMMmKlhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042344; bh=sfa87Fv8nzXhjCYYMgNOcH+2G+4NAcv9BMph32Dwk8w=; h=Cc:Date:From:Reply-To:Subject:To; b=uGZaB2Njnvch83yLF5/atQ5dT3G7NmY+htoJWw5rqHWMf9Mxyfo3+hL1qzZHXg+YFKB jUtyfTWSfOquYwDV+nvN+1W2ZdiA3gcEwfhzWlgkFcrSfRmosxEfZftMwEf9dnxVaFRS0 f7W/dpJtYuTOJ0bPDsYqsvy1gT0o0d8QDKQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042346306100001 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/Gic/ArmGicCParser.c | 777 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicCParser.h | 67 ++ 2 files changed, 844 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..b4e6729a4ab2 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c @@ -0,0 +1,777 @@ +/** @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 *)GicCCmObjDe= sc->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, Size= Cells)); + // 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, Size= Cells)); + // 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, Size= Cells)); + 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 *)Gic= CValue); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64 *)GicHV= alue); + GicCInfo[Index].GICV =3D (GicVValue =3D=3D NULL) ? 0 : + fdt64_to_cpu (*(UINT64 *)GicVValue); + } else { + GicCInfo[Index].PhysicalBaseAddress =3D fdt32_to_cpu (*(UINT32 *)Gic= CValue); + GicCInfo[Index].GICH =3D (GicHValue =3D=3D NULL) ? 0 : + fdt32_to_cpu (*(UINT32 *)GicHV= alue); + 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 *)GicCV= alue); + 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 *)GicCV= alue); + 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..2a0f966bf0c2 --- /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 (#84592): https://edk2.groups.io/g/devel/message/84592 Mute This Topic: https://groups.io/mt/87608910/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 Sat May 4 16:48:16 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+84593+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+84593+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042345; cv=none; d=zohomail.com; s=zohoarc; b=Fpo613dz6028n5bc/vYj2Sh9sEjG5xCvxlExcUnA1tEpfOO88IYMvaZc7qUUdHedaH4jsnItd2J2gnHuCOk4YlBv0UwqWSQ88Dwzm9bjNaGLcqDhhmbX4VgpNAZrcKHH2WLE92ZHd1WkR+49lJu4R+YAIfGK0A3qjzrCIzHQu24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042345; 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=taImTLdgpa+GlPdbHmHXjoZjblunZygfs7r2tPZf5wY=; b=m4S0nqb0AevFy+0weGc3XxIc8EIa7vWxGewvTlZ/qTDLpaqC5ToUuz87B3BcAHIwm/+QQLAZR5IEhoQdZh7pJ+fmoXjBZaU7k13ejad7uyI2Bg1tGeuRGwk2wXLUiSoEMvbFxx5Zxy7sbHfC9EjMUlT3g3ADNj0JdBt/0+SQ8Yw= 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+84593+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 1639042345914551.4344666296665; Thu, 9 Dec 2021 01:32:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EsAbYY1788612x24YIfRitz1; Thu, 09 Dec 2021 01:32:25 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9478.1639042344832197370 for ; Thu, 09 Dec 2021 01:32: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 7731D11FB; Thu, 9 Dec 2021 01:32:24 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6D04F3F73B; Thu, 9 Dec 2021 01:32:23 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 08/15] DynamicTablesPkg: FdtHwInfoParser: Add GICD parser Date: Thu, 9 Dec 2021 10:32:01 +0100 Message-Id: <20211209093208.1249257-9-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: ABNMOPiBmqO8xd3eRITHOXkHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042345; bh=Tdq/bMijL5Sw/70HBXXnDcRLoNOmOsbsDaMKwtFGBH0=; h=Cc:Date:From:Reply-To:Subject:To; b=ENfoqnn9UG1fq5LCKD9zraJuT6CTOoVpQoYRagJuD/URZdoLRgmjG5g1+eB4rcROrpa D4fjVKvd7pZPrlWvxLAZmO6wJ0EEaspuV6Euc8cTqf7NSJeeLg0dz7LP2OQzUwzRjHzu7 dHCPhCz2UubgvKue7ELsdhBYKfwn/Hc+gWE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042346649100006 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/Gic/ArmGicDParser.c | 171 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicDParser.h | 50 +++++ 2 files changed, 221 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..b7f569672980 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c @@ -0,0 +1,171 @@ +/** @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..b9581f0eb905 --- /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 (#84593): https://edk2.groups.io/g/devel/message/84593 Mute This Topic: https://groups.io/mt/87608912/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 Sat May 4 16:48:16 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+84594+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+84594+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042347; cv=none; d=zohomail.com; s=zohoarc; b=KiimpUVO7vdu8ICb6/xN1mOzYFKynUE5Tp5juXdYyV+gRgzviDUmoQhJKk63GBhT4rgyWG1/MKJwzSO13Ys4wg/BHv6h8c0/Jza5hdzjMIr9Z1mf4+Ut3cPZSkMiPh0j/FJrheHNDaZ18u68tvQiTAZnqkGIjka20nmOHoBbi5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042347; 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=vxvk8iL1r1jQSeq6hO2zXU3S489hvLVijutECdvCfyI=; b=OJ3CstaWl3fLsgrlQ/WOrI7uU6M9ing2AbiNy8DhGL/jgC75pXalHKzZ9HQno6Mx7sVtYMGWepif7kszoPe9Hj9A0rb9jErN36iWfctCgV4eFm513zizhK2PQDyXP0Pna8zGrd4wGZR6hcyO4I1t38BjIdx2r2oaOIaXdhjC3FQ= 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+84594+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 1639042347285704.4056780636882; Thu, 9 Dec 2021 01:32:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id G5AxYY1788612xto4Fe2Y3xZ; Thu, 09 Dec 2021 01:32:26 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9409.1639042346287373017 for ; Thu, 09 Dec 2021 01:32: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 E11051474; Thu, 9 Dec 2021 01:32:25 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D70C03F73B; Thu, 9 Dec 2021 01:32:24 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 09/15] DynamicTablesPkg: FdtHwInfoParser: Add MSI Frame parser Date: Thu, 9 Dec 2021 10:32:02 +0100 Message-Id: <20211209093208.1249257-10-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: ftSiILk1y00bfABNKQVsaMtPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042346; bh=8dmWcSLSubCECL15x4GVbAtvpLKR+3ORRSqh5cYDR+g=; h=Cc:Date:From:Reply-To:Subject:To; b=LZZGNWsASoLt628bYCtFgl5NSw4qb/6lIewXCyXfomF6bTu4mfTYqMbdrzdH1AuDreE hKVTBRZNZgV+M1/FjksvDPXnb4mINLfR7i8trfj2CndvYLG9Nu/iAssmNFbcDn+wyW6wC 82YmdSuXXPatW3LiF883SljBJv4yK33L2AQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042348864100002 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 Reviewed-by: Sami Mujawar --- .../Gic/ArmGicMsiFrameParser.c | 217 ++++++++++++++++++ .../Gic/ArmGicMsiFrameParser.h | 50 ++++ 2 files changed, 267 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..c474cb25fe6f --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c @@ -0,0 +1,217 @@ +/** @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..2821a784f7da --- /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 (#84594): https://edk2.groups.io/g/devel/message/84594 Mute This Topic: https://groups.io/mt/87608913/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 Sat May 4 16:48:16 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+84595+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+84595+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042348; cv=none; d=zohomail.com; s=zohoarc; b=Lg1UY49yYCWET3CtPuhwwL4dFY3qeuAmkQujH450ZL9zGMn0hlgVMu92EqXdkRXXqC/skFf7fKijXeY/SHrPdaSIy1+FmefpTJBWacv5h2tyGXTSiB5kG4+CQLqGq74pqEmfi2ySp37UmEUw1aANxsqCWMrZVlWwPpQkFUSsJlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042348; 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=AXNEPkA6mlA/BsM/PWo/nT0dsL9qNaQv7m/aMKA95AM=; b=PaMbs6R3AhIYdSIGQN+D/dyplzc2OAQ1hESC6uEackwM6xuyB1d/XPgjombObUR5g4TL00PGw8U4xfYGVHho+Cs+h8YlgK5SHPqS3yt+mqpl4G9okCxiSDeLVR4lYQU9x/piCNh2sUemDZD9/hCgnam7Z1+E4nprrwC8JnqzlIA= 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+84595+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 1639042348886148.48671687786145; Thu, 9 Dec 2021 01:32:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id JSHhYY1788612xL1AVoq2v4O; Thu, 09 Dec 2021 01:32:28 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.9270.1639042347769109733 for ; Thu, 09 Dec 2021 01:32:27 -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 5679D11FB; Thu, 9 Dec 2021 01:32:27 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4CCB23F73B; Thu, 9 Dec 2021 01:32:26 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 10/15] DynamicTablesPkg: FdtHwInfoParser: Add ITS parser Date: Thu, 9 Dec 2021 10:32:03 +0100 Message-Id: <20211209093208.1249257-11-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: MsGBkiRbRE0U6Sik9chKqaqAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042348; bh=2IxS6AqaKlubPJIYc2xzqOg/jwUOaMmE01IFWFBrkmM=; h=Cc:Date:From:Reply-To:Subject:To; b=XkbR2Qpb5ASK1ER9C/7C6pWPasVO4RY4NCy1bMHVNVw2iir0XUelnW8j9km9SmU/wTB uCuhQTakebKH2IwBaemH3tCHCwthnqLxeJt6G4qYDB5qeyg06t2HT0UDTUPwOB1vxIh+K Rr+G1+SP0KrCnGSPEhpyjZ/AvJbtTaE5tNc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042349279100006 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/Gic/ArmGicItsParser.c | 218 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicItsParser.h | 48 ++++ 2 files changed, 266 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..f23818fbd047 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c @@ -0,0 +1,218 @@ +/** @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..be944493e4d8 --- /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 (#84595): https://edk2.groups.io/g/devel/message/84595 Mute This Topic: https://groups.io/mt/87608914/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 Sat May 4 16:48:16 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+84596+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+84596+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042350; cv=none; d=zohomail.com; s=zohoarc; b=msRPXgCR2o2vBumSssGe4aVoWJjp55pXOJRSvynmNTVe1NYR4lzR0zmuLHteMEMGveIC48d3g4NnQUV2H45Ri63HEiUyltvtppZVnQx+XCJseSKYoIlUxRTte8qfYaP11VzBxp6hkFaWf0pl97f/Ce/ULxIO7ss7tmP/rE0nsos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042350; 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=j+622uoGyuYQ8t2YYE4fL5c8Gbfy3IogdlI88UxaWQ0=; b=FSEH7vL03vHJg04Cpuld3asf8mmhilbg3NKlPozvQVEj3P5hLgxUu+tIJIR/Pv57AIooZqZ3PvC6oSwU3b8z+jefXyifAZN009EDW8c/KcnUvuQyQzK6x6PKXJr640qb8f8XoJfTEFupw8Spg5e/dppiyRWXG6pgkxKx0+OHKG4= 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+84596+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 1639042350089637.4736825595838; Thu, 9 Dec 2021 01:32:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id FdiKYY1788612x2Urv3xOwp9; Thu, 09 Dec 2021 01:32:29 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9536.1639042349093777936 for ; Thu, 09 Dec 2021 01:32: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 C02D91474; Thu, 9 Dec 2021 01:32:28 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B6B453F73B; Thu, 9 Dec 2021 01:32:27 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 11/15] DynamicTablesPkg: FdtHwInfoParser: Add GICR parser Date: Thu, 9 Dec 2021 10:32:04 +0100 Message-Id: <20211209093208.1249257-12-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: q3aS25KOZVBjruh12bGreodCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042349; bh=PAvoMUra1AYrperFQ4NCHnim2/hlSMGcJqhwAdn8t9Y=; h=Cc:Date:From:Reply-To:Subject:To; b=CJz1liPjBjsMENVxpdNpoKvAaQwiuTEJjgwmf1O2GZxdOnEWZ1J/ctkKpg9ucUp55E1 tTLZvHmlZDy3EzA7/tvKyyDaXQliZPHKEnQJ403J7jCMLHSFdS9A1cIBQO8yWmj9vw5uP 4yeZJri0WpGQZvW5eBuWZP+mrlu8IxIc3EU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042351470100002 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/Gic/ArmGicRParser.c | 238 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicRParser.h | 47 ++++ 2 files changed, 285 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..0f9c7bb3fea2 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c @@ -0,0 +1,238 @@ +/** @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 *)D= ata); + } 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..c2b7eabfed1c --- /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 (#84596): https://edk2.groups.io/g/devel/message/84596 Mute This Topic: https://groups.io/mt/87608915/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 Sat May 4 16:48:16 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+84597+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+84597+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042351; cv=none; d=zohomail.com; s=zohoarc; b=KtgqoXP04qJFZLTpyD95xLZeuKh1YStpuJI+pLR+GZzyH4SZT0URjnSj52TX1QyB7lNjiKG/pGCIYj5wW1z3KSCZZTlgQO/RB7lDid05j97Rzt2uJK7FJUUzpAkC1trtCbMC7zphcIwy+aet6fwO9IcVa9Tl8d8OkbQXh6WfcrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042351; 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=LN0tofsO8Wh8HdiJdjiZBFKejGlQoTrjOJHkGbXEVRw=; b=EjrN0vTAGl47CLScb0+LEOOAiGSuREnh6QVEZwb7Dm2hYmGGfCcsiFly6bsUOjJZWu03jdt+B0PLe59vkcy9/M3Feq3qQTDTuCRuVHkUHfb5T1MIIcItUQqGmoRoXCI/9x9BSQrD9r7/eeESptpXv8K1xyvznDXVYOj528YNWQE= 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+84597+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 1639042351266780.9847628953145; Thu, 9 Dec 2021 01:32:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jL2nYY1788612xM8l8MFNaEe; Thu, 09 Dec 2021 01:32:30 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9537.1639042350272353351 for ; Thu, 09 Dec 2021 01:32: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 E72D011FB; Thu, 9 Dec 2021 01:32:29 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 19EAB3F73B; Thu, 9 Dec 2021 01:32:28 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 12/15] DynamicTablesPkg: FdtHwInfoParser: Add GIC dispatcher Date: Thu, 9 Dec 2021 10:32:05 +0100 Message-Id: <20211209093208.1249257-13-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: KXuG4B7YQXtPPaXUIFT5a51dx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042350; bh=M+7ON00iu9i+rvhd7tXacM0ysFQP41I84XIkj0185y0=; h=Cc:Date:From:Reply-To:Subject:To; b=GI0Y5l359j94Y0SFxjLXlPxsmDe9gEKAUGgdTuGhKSmpAvGBk4J14iMfUzdFfwDdjtF T977mw0YG8unxuiE5eo10/Q8Ikf0UGu+qjdVkrFUfvDgpDWu3TYhVLLGAGzCshQX+f/ui ik0xbSW+sa+HfEPIzDoyqn2wEn2Nacp9tDc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042351661100005 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 Reviewed-by: Sami Mujawar --- .../FdtHwInfoParserLib/Gic/ArmGicDispatcher.c | 218 ++++++++++++++++++ .../FdtHwInfoParserLib/Gic/ArmGicDispatcher.h | 72 ++++++ 2 files changed, 290 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..831f0d5b7365 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c @@ -0,0 +1,218 @@ +/** @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..aa942f7d1f49 --- /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 (#84597): https://edk2.groups.io/g/devel/message/84597 Mute This Topic: https://groups.io/mt/87608916/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 Sat May 4 16:48:16 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+84598+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+84598+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042352; cv=none; d=zohomail.com; s=zohoarc; b=arbOKrzBhkKUO2n7IsCEIjA5Zvg+zbGUUOnCRC506RzeMpPjkkzm462gZu/ZuSaY8zgkBt26/BkOhU163zur9Xt2KzS7Wgc9pJfOfOBYtpxKNM2fIsbephonl+7R5yN0Cje+sBGgq1CmDHddR0lsfUXq8hyERHlbseIuJHeh5Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042352; 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=7ETobtJnlq2+qq8UMzaQDe6NWPiZ0J9aa+kWHcqZ/3o=; b=g+k1cQXHeU2iSnJ9yKdk2utEigFVifgyPO/KmWd6W57XWbsOj1WwLUQJ3/JiGRc3wCD5aG0+JlSTrs1GNdRcQTQaD/io1m8jrKNxYisl4bfoBiqlxvcGBXozNsMityZQdsEvi+WDMnaIFe0KjoSNs7PDrDlYgLtlYjRmgt4NGRI= 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+84598+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 1639042352539697.8864434056323; Thu, 9 Dec 2021 01:32:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id X9EUYY1788612xZrLy64ebVu; Thu, 09 Dec 2021 01:32:32 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9479.1639042351462401010 for ; Thu, 09 Dec 2021 01:32: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 236751474; Thu, 9 Dec 2021 01:32:31 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 324D13F73B; Thu, 9 Dec 2021 01:32:30 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 13/15] DynamicTablesPkg: FdtHwInfoParser: Add PCI config parser Date: Thu, 9 Dec 2021 10:32:06 +0100 Message-Id: <20211209093208.1249257-14-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: nFqv4Kf9kMPN4wTuMp4YTFUSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042352; bh=2gd2OMpnqCzerw+KoZ4ocSM33B9wnPXGokeVbXM33fQ=; h=Cc:Date:From:Reply-To:Subject:To; b=s7UACskWpEwumy5IpjZx1O9qfSXbQBtW074yULFDQcTkAUnjJjpriP/cI0qcKnicU9c dSibqJn7VeEdgIs9gCHr1UOpZc5xr5pv7/87e+PybyTLHu3+GpV8TA5jI0ziBzebBlpG2 Y08xxJPhWtOiHiUG/4ha31qPxCYC1boQgjg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042353885100002 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 Reviewed-by: Sami Mujawar --- .../Pci/ArmPciConfigSpaceParser.c | 813 ++++++++++++++++++ .../Pci/ArmPciConfigSpaceParser.h | 143 +++ 2 files changed, 956 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..2ffff1ccd27f --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpacePars= er.c @@ -0,0 +1,813 @@ +/** @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) + PHandleOf= fset] + )) + { + 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_INF= O); + 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 (PciAddress= Attr); + PciInterruptMapInfo[Index].PciDevice =3D READ_PCI_DDDDD (PciAddressAtt= r); + Offset +=3D PCI_ADDRESS_CELLS * sizeof (U= INT32); + + // Pci irq + PciInterruptMapInfo[Index].PciInterrupt =3D fdt32_to_cpu ( + (*(UINT32 *)&Data[Offset])= & + (*(UINT32 *)&IrqMapMask[3 = * sizeof (UINT32)]) + ); + // -1 to translate from device-tree (INTA=3D1) to ACPI (INTA=3D0) irq = IDs. + PciInterruptMapInfo[Index].PciInterrupt -=3D 1; + Offset +=3D PCI_INTERRUPTS_CELLS * si= zeof (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 *)D= ata); + } else { + PciInfo->PciConfigSpaceInfo.BaseAddress =3D fdt32_to_cpu (*(UINT32 *)D= ata); + } + + // 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..6e0027abeab6 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpacePars= er.h @@ -0,0 +1,143 @@ +/** @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 (#84598): https://edk2.groups.io/g/devel/message/84598 Mute This Topic: https://groups.io/mt/87608917/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 Sat May 4 16:48:16 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+84599+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+84599+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042353; cv=none; d=zohomail.com; s=zohoarc; b=hL7+BjkEA1LVrVscmOZ+NXs0vOURgGl6DPySPRs3vxmTRMLqaZP2IUp6VJo3k296JOPkzkxZCBzHFiO1HmwsJ4dz4O/E7Lwkmxc86Fx3WhJV4bK9HkxrFYyLeqOzwyRPYoRlrtvZdy9gV3jQJixvz/PwVH3vW8T79KdtIwV4hUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042353; 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=BZzpcVPeYpWBkRnSYdujzo5V87eMReALH8FBmvumbBk=; b=FJfxQEQUqYo9nFMj5vT8TXTPP14HwIqqkjTWG1WhUjcEnRjGgemPi2xo4dERoE3e9/wc/07lIZn+Gsb/2rT7hNYoAJBRuIvol0FyiTFtRVLccrTbXK1/ISSXriAJJ3JvIZLU7Xl/m9U5yzwn/yhMdy5BGQ24Nl0hLOjJgwjh//A= 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+84599+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 1639042353873279.9386363846329; Thu, 9 Dec 2021 01:32:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AO78YY1788612xoELr6Ka7vS; Thu, 09 Dec 2021 01:32:33 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9480.1639042352883805984 for ; Thu, 09 Dec 2021 01:32: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 8D0D211FB; Thu, 9 Dec 2021 01:32:32 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8330C3F73B; Thu, 9 Dec 2021 01:32:31 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 14/15] DynamicTablesPkg: Add FdtHwInfoParser library Date: Thu, 9 Dec 2021 10:32:07 +0100 Message-Id: <20211209093208.1249257-15-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: QmfGK6ymHRjCp5nYyBeXjZ5Sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042353; bh=cXkacMS5M8ytKW7Y9fn9iyVdA7bYs5GwfXGe6IElfV0=; h=Cc:Date:From:Reply-To:Subject:To; b=g/lDctq/S6tJG3wc84yvaAkLgx/biJX+PxhuR11VkTwEw+/s09p4ReZaF2C92En68Za KAfj13mskUCTxpgdgtSQlxShpPSeuW2mlAGlIOh4fXlPzTZ31mWTaUtb6DSvSxOpuE8VN lz08jxc7jLDR8dSZJZ+6k958wt8DwltcPsQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042354219100005 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 Reviewed-by: Sami Mujawar --- DynamicTablesPkg/DynamicTablesPkg.dsc | 3 +- .../FdtHwInfoParserLib/FdtHwInfoParser.c | 192 ++++++++++++++++++ .../FdtHwInfoParserLib/FdtHwInfoParser.h | 63 ++++++ .../FdtHwInfoParserInclude.h | 17 ++ .../FdtHwInfoParserLib/FdtHwInfoParserLib.inf | 56 +++++ 5 files changed, 330 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..35e34e765f71 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c @@ -0,0 +1,192 @@ +/** @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..8a8cf38581e0 --- /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 (#84599): https://edk2.groups.io/g/devel/message/84599 Mute This Topic: https://groups.io/mt/87608918/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 Sat May 4 16:48:16 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+84600+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+84600+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1639042355; cv=none; d=zohomail.com; s=zohoarc; b=V26W0PosMxBna2/8cr5zIl8HQBzrIO3nJr16WEQTFGOMfLyViu4q5E9T3dxilCgp6dmmY4FVBpJISeHD74ohFkY7aUzsqM1utIm8KXfV/aEMwajsXvnijiBiKrrJg8bm0kHuLJvcqhefYneP/G8sZ8jZKi6Hsp43mW2nURV7p0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639042355; 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=9ILWMGCztlOuQrgqyIo1dSEZdBMsnohLDxaXS8v3k/Q=; b=QZYNDbvEjgEWcSbil3tAoDz6xrRboLZHnWriTmhljOkTIlTxBEJWyUZqz+IMI/01PbpnbZNH6lnZah71RUUt7ZMHl7Md63NYVa+jzxwP49C7FkoNakMFfL8vnNiuDNKrtkTd787YpUM9CAV77ioEDLB/n+kWhgza3vKHQO9fzM8= 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+84600+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 1639042355305160.0092594340382; Thu, 9 Dec 2021 01:32:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id by6DYY1788612x3t4shkaWcF; Thu, 09 Dec 2021 01:32:34 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9538.1639042354390925775 for ; Thu, 09 Dec 2021 01:32:34 -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 02C101474; Thu, 9 Dec 2021 01:32:34 -0800 (PST) X-Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id ED1CB3F73B; Thu, 9 Dec 2021 01:32:32 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v4 15/15] DynamicTablesPkg: Handle 16550_WITH_GAS id Date: Thu, 9 Dec 2021 10:32:08 +0100 Message-Id: <20211209093208.1249257-16-Pierre.Gondois@arm.com> In-Reply-To: <20211209093208.1249257-1-Pierre.Gondois@arm.com> References: <20211209093208.1249257-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: 2rbW4cOPOmUIahpDLMiKKpAjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639042354; bh=TEob5Ur3EGFo44EXonJ3swiEqGXDU8zNzeYDFKlpYkg=; h=Cc:Date:From:Reply-To:Subject:To; b=E1iJUWJUM6mJYy7PqbxY9j4hiU6bAMhU2/4STrRVrgXEHBKeSfVdWxpHgQwlOgvcpml Txx+a31YMtD8NTqc67mayD0aV2rGWdmXJjqFqxAkpDKHUvp28+tsaOxxTudaepThKw/tl rKK97T+rkoXNIF5kLBT0t/u9i1xlT4xrXTA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639042356357100009 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 Reviewed-by: Sami Mujawar --- .../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 0270ab89446d..389c9eb914d8 100644 --- a/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c +++ b/DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPort= FixupLib.c @@ -85,7 +85,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, @@ -147,6 +149,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 (PcdNonBsaCompliant16550Seria= lHid); --=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 (#84600): https://edk2.groups.io/g/devel/message/84600 Mute This Topic: https://groups.io/mt/87608919/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-