From nobody Tue Feb 10 02:00:55 2026 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 --- .../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-