From nobody Sat May 18 04:13:35 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+76985+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+76985+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624455407; cv=none; d=zohomail.com; s=zohoarc; b=iUkVZfASO2mb/gJ196zo/YCgBucMfn9yVKvborYmEARMpMk85Ad09E+HNl/6aWbk32FCuHOQqx5ObfPrvvIP9L9b62TK96VRO8DM9G/fhovnR9Vnk2xbbvYQt29KqE5/KxKtPCSqpAClS/alYe1WAF+unGUE8hIXn8OiF64aLIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624455407; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZjuflpGHBo/5j36fBxzYJKzSUAkvuWFzIPEQUNSgcGw=; b=VwnpsoH2+a6kTNGXEKlqRp0whMPBeqTZavSAOi+qrNb9J2VCP46vlCRPpDyiWThxFGE4RPD8Ynx9xA0L1MSfhYa++bGuqvUZbCv9RKdRnOYlc060n5wKm/HinJQAZqA6lZ7N61+MuBvkV6dswLeSzraz1wTCJq2fnI0B8YgyXZE= 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+76985+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 162445540723979.79553141674182; Wed, 23 Jun 2021 06:36:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xtbcYY1788612xpkNfH8lntq; Wed, 23 Jun 2021 06:36:46 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.7557.1624455401313608976 for ; Wed, 23 Jun 2021 06:36:41 -0700 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 E5CA91063; Wed, 23 Jun 2021 06:36:40 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 82E753F718; Wed, 23 Jun 2021 06:36:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 1/5] DynamicTablesPkg: Definition for DynamicPlatRepoLib interface Date: Wed, 23 Jun 2021 14:36:09 +0100 Message-Id: <20210623133613.29600-2-Pierre.Gondois@arm.com> In-Reply-To: <20210623133613.29600-1-Pierre.Gondois@arm.com> References: <20210623133613.29600-1-Pierre.Gondois@arm.com> 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: gSI0lxbgikS50zCa2Itw9TE0x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624455406; bh=H1e/KSgUoXn3HTMRId0jclPabzzMsvptP8Mno2Ih+qc=; h=Cc:Date:From:Reply-To:Subject:To; b=aucprMHgIcYACzFvyIfSene1CKguYEzfX4IpBOnm/XQmfUP9LohNZwWVLQPFmMNPI9q LXPMxv48HwS6Ir6rprxtGK5HsMc3ql6Nf4USnIL+s0aMEEKp5wxpLQmhbbtwy55onPtBG 3aERZKbmxt9nSVOABAJV8aug79P/hekZyqs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DynamicPlatRepoLib library allows to handle dynamically created CmObj. The dynamic platform repository can be in the following states: 1 - Non-initialised 2 - Transient: Possibility to add CmObj to the platform, but not to query them. 3 - Finalised: Possibility to query CmObj, but not to add new. A token is allocated to each CmObj added to the dynamic platform repository (except for reference tokens CmObj). This allows to retrieve dynamic CmObjs among all CmObj (static CmObj for instance). This patch defines the library interface of the DynamicPlatRepo. Signed-off-by: Sami Mujawar Signed-off-by: Pierre Gondois --- DynamicTablesPkg/DynamicTablesPkg.dec | 3 + .../Include/Library/DynamicPlatRepoLib.h | 112 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/Dynam= icTablesPkg.dec index 80a61dd2dbac..9b74c5a67178 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 handle dynamically created C= mObj. + DynamicPlatRepoLib|Include/Library/DynamicPlatRepoLib.h + ## @libraryclass Defines a set of APIs to a hardware information parse= r. HwInfoParserLib|Include/Library/HwInfoParserLib.h =20 diff --git a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h b/Dynami= cTablesPkg/Include/Library/DynamicPlatRepoLib.h new file mode 100644 index 000000000000..8e4665bf5c59 --- /dev/null +++ b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h @@ -0,0 +1,112 @@ +/** @file + Dynamic Platform Info Repository + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#ifndef DYNAMIC_PLAT_REPO_H_ +#define DYNAMIC_PLAT_REPO_H_ + +/** A structure describing the platform configuration + manager repository information +*/ +typedef VOID* DYNAMIC_PLATFORM_REPOSITORY_INFO; + +/** Add an object to the dynamic platform repository. + + @param [in] This This dynamic platform repository. + @param [in] CmObjDesc CmObj to add. The data is copied. + @param [out] Token If not NULL, token allocated to this CmObj. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynPlatRepoAddObject ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This, + IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc, + OUT CM_OBJECT_TOKEN * Token OPTIONAL + ); + +/** Finalise the dynamic repository. + + Finalising means: + - Preventing any further objects from being added. + - Allowing to get objects from the dynamic repository + (not possible before a call to this function). + + @param [in] This This dynamic platform repository. + + @retval EFI_SUCCESS Success. + @retval EFI_ALREADY_STARTED Instance already initialised. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_BUFFER_TOO_SMALL Buffer too small. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoFinalise ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This + ); + +/** Get a CmObj from the dynamic repository. + + @param [in] This Pointer to the Dynamic Platform Repository. + @param [in] CmObjectId The Configuration Manager Object ID. + @param [in] Token An optional token identifying the object. If + unused this must be CM_NULL_TOKEN. + @param [in, out] CmObjDesc Pointer to the Configuration Manager Object + descriptor describing the requested Object. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object information is not fou= nd. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoGetObject ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This, + IN CM_OBJECT_ID CmObjectId, + IN CM_OBJECT_TOKEN Token OPTIONAL, + IN OUT CM_OBJ_DESCRIPTOR * CmObjDesc + ); + +/** Initialize the dynamic platform repository. + + @param [out] DynPlatRepo If success, contains the initialised dynamic + platform repository. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoInit ( + OUT DYNAMIC_PLATFORM_REPOSITORY_INFO ** DynPlatRepo + ); + +/** Shutdown the dynamic platform repository. + + Free all the memory allocated for the dynamic platform repository. + + @param [in] DynPlatRepo The dynamic platform repository. + + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoShutdown ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo + ); + +#endif DYNAMIC_PLAT_REPO_H_ --=20 2.17.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 (#76985): https://edk2.groups.io/g/devel/message/76985 Mute This Topic: https://groups.io/mt/83737788/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 18 04:13:35 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+76986+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+76986+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624455409; cv=none; d=zohomail.com; s=zohoarc; b=dXLJUkf1icoj2yV6GXVJw5t5aVwRD/g9UadN42YLnr2pZeo/et+WRtev1T6Rio4EE4xuaDYi5lg4/LNfidsu9/b6QvbU90Jz0euAtVUBy1iJDwVTr8ZUATGvP0QgJtgbXwMevLjlCrrtQMS+YlnN5MrxTXGvd3WnONkE9Dd33Fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624455409; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=NNlqestaTNHxjVylJScmRW1Vw7u3jcid/zcJX46yA/Y=; b=U7bsSbeGj0feA+EyD+DrNugKc23rrioAjy8JGRmXPIbasmWan9ZcRr3/GWoeEMgUy1tg9wVD+A4uBon8nRf22sZ8RidLGHlgljiawA7qBaUGcGdqJGgZZiwip00Fu2xRIl9DpWNT4IOERxny+DH+HC1yt2RPeF4f63bFWeT23vM= 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+76986+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 1624455409540766.8589746554876; Wed, 23 Jun 2021 06:36:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id helOYY1788612xj6REcuyEhX; Wed, 23 Jun 2021 06:36:48 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.7697.1624455403132278173 for ; Wed, 23 Jun 2021 06:36:43 -0700 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 A9B90ED1; Wed, 23 Jun 2021 06:36:42 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 505443F718; Wed, 23 Jun 2021 06:36:41 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 2/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenGenerator Date: Wed, 23 Jun 2021 14:36:10 +0100 Message-Id: <20210623133613.29600-3-Pierre.Gondois@arm.com> In-Reply-To: <20210623133613.29600-1-Pierre.Gondois@arm.com> References: <20210623133613.29600-1-Pierre.Gondois@arm.com> 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: xkMZubfVMefE4Upp4lx6oA6Nx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624455408; bh=87Tk5KeK5UBXZO0PyLeCYPhJO/0mUymaAgBN0ATHDfE=; h=Cc:Date:From:Reply-To:Subject:To; b=aEhrH+Fw/ukJkSP88rrH7o1Uy51bplLF8GHrY1t2PRD0rGs1IAhEeq4IhPOgKAkefmA YB5yRxYhwNyrXKGTX0yzHu8PZwnjk6NNkj0zhn9P0s7ZSsS6v3VPitulYyIzNJnjW2heZ Q495AchI8oUWpOnZEoSij5JEJHuv4NFRCD8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DynamicPlatRepo library allows to handle dynamically created CmObj. The dynamic platform repository can be in the following states: 1 - Non-initialised 2 - Transient: Possibility to add CmObj to the platform, but not to query them. 3 - Finalised: Possibility to query CmObj, but not to add new. A token is allocated to each CmObj added to the dynamic platform repository (except for reference tokens CmObj). This allows to retrieve dynamic CmObjs among all CmObj (static CmObj for instance). This patch add the TokenGenerator files. Signed-off-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../DynamicPlatRepoLib/TokenGenerator.c | 28 +++++++++++++++++++ .../DynamicPlatRepoLib/TokenGenerator.h | 26 +++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Toke= nGenerator.c create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Toke= nGenerator.h diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenera= tor.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c new file mode 100644 index 000000000000..637e784bd284 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c @@ -0,0 +1,28 @@ +/** @file + Token Generator + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#include + +/** Generate a token. + + @return A token. +**/ +CM_OBJECT_TOKEN +EFIAPI +GenerateToken ( + VOID + ) +{ + // Start Tokens at 1 to avoid collisions with CM_NULL_TOKEN. + STATIC UINTN CurrentToken =3D 1; + return (CM_OBJECT_TOKEN)(CurrentToken++); +} diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenera= tor.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h new file mode 100644 index 000000000000..44d32e5b41a1 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h @@ -0,0 +1,26 @@ +/** @file + Token Generator + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#ifndef TOKEN_GENERATOR_H_ +#define TOKEN_GENERATOR_H_ + +/** Generate a token. + + @return A token. +**/ +CM_OBJECT_TOKEN +EFIAPI +GenerateToken ( + VOID + ); + +#endif // TOKEN_GENERATOR_H_ --=20 2.17.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 (#76986): https://edk2.groups.io/g/devel/message/76986 Mute This Topic: https://groups.io/mt/83737790/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 18 04:13:35 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+76987+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+76987+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624455410; cv=none; d=zohomail.com; s=zohoarc; b=RBwTbFpFqV5bRrklvU/ZuCtdq/WEWu5OyMWp6ZdQdA5vW7RNnLNEAK5TgNtXU3FHwom9ZyVWVxSwN+LKJ5AYSUeFGFcgXlJV/wIY87g8JE/6dBGQQI+zJgJ2fbX8iCFfh2fyycIyzUofl4D4feXTYXN4CMCGASHikA9oPpDFYzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624455410; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=5Xl6y9oWXumgozU/yv/RX7XXyoDQNNroLRJroc0qaS0=; b=dedExyqFZUsSXx5/EiQ+NDALNitpZGP97cyxIlrYiniKujqBT17B4DQXOwAFVm6AQ3SgkFxeJPSHIKHwbgEliBGb/iF47uWf0GVzaGy3kyxtG5Sme0LqLCzXXPHYD1TeySPejXMfIhpbMETsJ292J5s4V5mIQlmmjsFcxvinAZ0= 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+76987+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 162445541085286.07272410082714; Wed, 23 Jun 2021 06:36:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ImQKYY1788612xB0CRozZDqr; Wed, 23 Jun 2021 06:36:50 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.7699.1624455404758681292 for ; Wed, 23 Jun 2021 06:36:44 -0700 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 67621ED1; Wed, 23 Jun 2021 06:36:44 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 119A23F718; Wed, 23 Jun 2021 06:36:42 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 3/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenFixer Date: Wed, 23 Jun 2021 14:36:11 +0100 Message-Id: <20210623133613.29600-4-Pierre.Gondois@arm.com> In-Reply-To: <20210623133613.29600-1-Pierre.Gondois@arm.com> References: <20210623133613.29600-1-Pierre.Gondois@arm.com> 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: UMboFCqy2Vwii1SIwd4r0fN6x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624455410; bh=RuxbE5vhrdBzgthoc5TJ6YjcBxeWDQz2ihCTXH7F92A=; h=Cc:Date:From:Reply-To:Subject:To; b=PD+DYTfvafthCWDlTlaQTSZ1798rgrXIrt2gYoJvF3oHz2ZI0HyH7A5qiw2kwPjWG9V 29G4zXingj3P8bZ4L30ffatKg3Ro6E9hcyWc9Bfvg8s3LOQuHutaVvdsxp8wIAKpkTiAn nK3bMTs2EloabKdVrj+JrCiSgYinaFjVnuw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DynamicPlatRepo library allows to handle dynamically created CmObj. The dynamic platform repository can be in the following states: 1 - Non-initialised 2 - Transient: Possibility to add CmObj to the platform, but not to query them. 3 - Finalised: Possibility to query CmObj, but not to add new. A token is allocated to each CmObj added to the dynamic platform repository (except for reference tokens CmObj). This allows to retrieve dynamic CmObjs among all CmObj (static CmObj for instance). This patch add the TokenFixer files, allowing to update the self-token some CmObj have. Signed-off-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../DynamicPlatRepoLib/CmObjectTokenFixer.c | 164 ++++++++++++++++++ .../DynamicPlatRepoLib/CmObjectTokenFixer.h | 52 ++++++ 2 files changed, 216 insertions(+) create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmOb= jectTokenFixer.c create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmOb= jectTokenFixer.h diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTok= enFixer.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectToke= nFixer.c new file mode 100644 index 000000000000..74eeefccf4ce --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer= .c @@ -0,0 +1,164 @@ +/** @file + Configuration Manager object token fixer + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#include +#include +#include "CmObjectTokenFixer.h" + +/** Token fixer not implemented. + + Most of the objects are not generated by this parser. Add the missing + functions when needed. + + CmObjectToken fixer function that updates the Tokens in the CmObjects. + + @param [in] CmObject Pointer to the Configuration Manager Object. + @param [in] Token Token to be updated in the CmObject. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. +**/ +STATIC +EFI_STATUS +EFIAPI +TokenFixerNotImplemented ( + IN CM_OBJ_DESCRIPTOR * CmObject, + IN CM_OBJECT_TOKEN Token + ) +{ + ASSERT (0); + return EFI_UNSUPPORTED; +} + +/** EArmObjItsGroup token fixer. + + CmObjectToken fixer function that updates the Tokens in the CmObjects. + + @param [in] CmObject Pointer to the Configuration Manager Object. + @param [in] Token Token to be updated in the CmObject. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. +**/ +STATIC +EFI_STATUS +EFIAPI +TokenFixerItsGroup ( + IN CM_OBJ_DESCRIPTOR * CmObject, + IN CM_OBJECT_TOKEN Token + ) +{ + ASSERT (CmObject !=3D NULL); + ((CM_ARM_ITS_GROUP_NODE*)CmObject)->Token =3D Token; + return EFI_SUCCESS; +} + +/** TokenFixer functions table. + + A CmObj having a CM_OBJECT_TOKEN field might need to have its + Token fixed. Each CmObj can have its Token in a specific way. +*/ +CONST +CM_OBJECT_TOKEN_FIXER TokenFixer[EArmObjMax] =3D { + NULL, ///< 0 - Reserved + NULL, ///< 1 - Boot Architecture Info + NULL, ///< 2 - CPU Info + NULL, ///< 3 - Power Management Profile Info + NULL, ///< 4 - GIC CPU Interface Info + NULL, ///< 5 - GIC Distributor Info + NULL, ///< 6 - GIC MSI Frame Info + NULL, ///< 7 - GIC Redistributor Info + NULL, ///< 8 - GIC ITS Info + NULL, ///< 9 - Serial Console Port Info + NULL, ///< 10 - Serial Debug Port Info + NULL, ///< 11 - Generic Timer Info + NULL, ///< 12 - Platform GT Block Info + NULL, ///< 13 - Generic Timer Block Frame In= fo + NULL, ///< 14 - Platform Generic Watchdog + NULL, ///< 15 - PCI Configuration Space Info + NULL, ///< 16 - Hypervisor Vendor Id + NULL, ///< 17 - Fixed feature flags for FADT + TokenFixerItsGroup, ///< 18 - ITS Group + TokenFixerNotImplemented, ///< 19 - Named Component + TokenFixerNotImplemented, ///< 20 - Root Complex + TokenFixerNotImplemented, ///< 21 - SMMUv1 or SMMUv2 + TokenFixerNotImplemented, ///< 22 - SMMUv3 + TokenFixerNotImplemented, ///< 23 - PMCG + NULL, ///< 24 - GIC ITS Identifier Array + NULL, ///< 25 - ID Mapping Array + NULL, ///< 26 - SMMU Interrupt Array + TokenFixerNotImplemented, ///< 27 - Processor Hierarchy Info + TokenFixerNotImplemented, ///< 28 - Cache Info + TokenFixerNotImplemented, ///< 29 - Processor Node ID Info + NULL, ///< 30 - CM Object Reference + NULL, ///< 31 - Memory Affinity Info + NULL, ///< 32 - Device Handle Acpi + NULL, ///< 33 - Device Handle Pci + NULL, ///< 34 - Generic Initiator Affinity + NULL, ///< 35 - Generic Serial Port Info + NULL, ///< 36 - CMN-600 Info + NULL, ///< 37 - Lpi Info + NULL, ///< 38 - Pci Address Map Info + NULL, ///< 39 - Pci Interrupt Map Info +}; + +/** CmObj token fixer. + + Some CmObj structures have a self-token, i.e. they are storing their own + token value in the CmObj. Dynamically created CmObj need to have their + self-token assigned at some point. + + @param [in] CmObjDesc Pointer to the Configuration Manager Object. + @param [in] Token Token to update the CmObjDesc with. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. +**/ +EFI_STATUS +EFIAPI +FixupCmObjectSelfToken ( + IN CM_OBJ_DESCRIPTOR * CmObjDesc, + IN CM_OBJECT_TOKEN Token + ) +{ + EFI_STATUS Status; + CM_OBJECT_TOKEN_FIXER TokenFixerFunc; + CM_OBJECT_ID ArmNamespaceObjId; + + // Only support Arm objects for now. + if ((CmObjDesc =3D=3D NULL) || + (GET_CM_NAMESPACE_ID (CmObjDesc->ObjectId) !=3D EObjNameSpaceArm)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ArmNamespaceObjId =3D GET_CM_OBJECT_ID (CmObjDesc->ObjectId); + if (ArmNamespaceObjId >=3D EArmObjMax) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Fixup self-token if necessary. + TokenFixerFunc =3D TokenFixer[ArmNamespaceObjId]; + if (TokenFixerFunc !=3D NULL) { + Status =3D TokenFixerFunc (CmObjDesc, Token); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTok= enFixer.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectToke= nFixer.h new file mode 100644 index 000000000000..d8cc7094697f --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer= .h @@ -0,0 +1,52 @@ +/** @file + Configuration Manager object token fixer + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#ifndef CM_OBJECT_TOKEN_FIXER_H_ +#define CM_OBJECT_TOKEN_FIXER_H_ + +/** CmObjectToken fixer function that updates the Tokens in the CmObjects. + + @param [in] CmObject Pointer to the Configuration Manager Object. + @param [in] Token Token to be updated in the CmObject. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. +**/ +typedef +EFI_STATUS +(EFIAPI * CM_OBJECT_TOKEN_FIXER) ( + IN CM_OBJ_DESCRIPTOR * CmObject, + IN CM_OBJECT_TOKEN Token + ); + +/** CmObj token fixer. + + Some CmObj structures have a self-token, i.e. they are storing their own + token value in the CmObj. Dynamically created CmObj need to have their + self-token assigned at some point. + + @param [in] CmObjDesc Pointer to the Configuration Manager Object. + @param [in] Token Token to update the CmObjDesc with. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. +**/ +EFI_STATUS +EFIAPI +FixupCmObjectSelfToken ( + IN CM_OBJ_DESCRIPTOR * CmObjDesc, + IN CM_OBJECT_TOKEN Token + ); + +#endif // CM_OBJECT_TOKEN_FIXER_H_ --=20 2.17.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 (#76987): https://edk2.groups.io/g/devel/message/76987 Mute This Topic: https://groups.io/mt/83737791/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 18 04:13:35 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+76988+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+76988+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624455407; cv=none; d=zohomail.com; s=zohoarc; b=L7Yu5jrVf0eD5yCckBelXoq8poWWVqnhqti1TTkKVxBETJhfYth1pQa32BQpSXOTrgfPEwyexF2TsCgUCBnhJRs5ZjjvVFUXz7VkwqZWgbHTOS61DlOMD7eMFLw2V5TK3OsiXhmvrPjdDq54wEBPN42zYhztnQqQWczTlLSdgA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624455407; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=yyMhlsoI8lVALm1/iRDDH+Bik+fh+KFZpOtdbq3DZEk=; b=FV7imu9xOJRuBS9e8Fic7YbtELeW2djlqrO4DmMQ6Q+hNS5LlmRBtgLLa5byKDhvjDLdDUJWnzmtduPumMTfkvRBrJJv13mlXt6T41Ukeq0rWocTfa7ZA5yG3doVJZJ6tcnnxMNPg1bJD6YX9eVqEXguo6E8/LhCTWr80vthrF0= 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+76988+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 1624455407813872.488689776155; Wed, 23 Jun 2021 06:36:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id reoRYY1788612xN8TPmCncWa; Wed, 23 Jun 2021 06:36:47 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7686.1624455406740266169 for ; Wed, 23 Jun 2021 06:36:46 -0700 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 4125DED1; Wed, 23 Jun 2021 06:36:46 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C5FEB3F718; Wed, 23 Jun 2021 06:36:44 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 4/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenMapper Date: Wed, 23 Jun 2021 14:36:12 +0100 Message-Id: <20210623133613.29600-5-Pierre.Gondois@arm.com> In-Reply-To: <20210623133613.29600-1-Pierre.Gondois@arm.com> References: <20210623133613.29600-1-Pierre.Gondois@arm.com> 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: RF2PjAEdZ0vqTFsEb07ed7Y6x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624455407; bh=cHnNYEkgC2CtdMrhAf8rhlInJ/GoXGUz2ONqa+epkjk=; h=Cc:Date:From:Reply-To:Subject:To; b=rBYzp9nfj4jSycbWIW9arKuIYypAgesMRCKdmgpLhAF4wOf5eEzwxxbrYl1CuKbe4QU ifmI8az49EycEgrKvXb6M7N1FpWakxxrC4Gj4seIaeqAWecoZYdb655Xj7UFBEnRlxRtT QR262UlYP4eivwEEXrT2Jf2C6Vd88TDncSw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DynamicPlatRepo library allows to handle dynamically created CmObj. The dynamic platform repository can be in the following states: 1 - Non-initialised 2 - Transient: Possibility to add CmObj to the platform, but not to query them. 3 - Finalised: Possibility to query CmObj, but not to add new. A token is allocated to each CmObj added to the dynamic platform repository (except for reference tokens CmObj). This allows to retrieve dynamic CmObjs among all CmObj (static CmObj for instance). This patch add the TokenMapper files, allowing to retrieve a CmObj from a token/CmObjId couple. Signed-off-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Common/DynamicPlatRepoLib/TokenMapper.c | 214 ++++++++++++++++++ .../Common/DynamicPlatRepoLib/TokenMapper.h | 123 ++++++++++ 2 files changed, 337 insertions(+) create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Toke= nMapper.c create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Toke= nMapper.h diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper= .c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c new file mode 100644 index 000000000000..f23bc8c1c7db --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c @@ -0,0 +1,214 @@ +/** @file + Token Mapper + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#include +#include +#include +#include + +#include "TokenMapper.h" + +/** Add a CmObjDesc to the TokenMapper. + + @param [in] TokenMapper The TokenMapper instance. + @param [in] Token CmObj token. + @param [in] ObjectId CmObj ObjectId. + @param [in] Size CmObj Size. + @param [in] Data CmObj Data. + This memory is referenced, not copied. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_BUFFER_TOO_SMALL Buffer too small. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperAddObject ( + IN TOKEN_MAPPER *TokenMapper, + IN CM_OBJECT_TOKEN Token, + IN CM_OBJECT_ID ObjectId, + IN UINT32 Size, + IN VOID *Data + ) +{ + TOKEN_MAP_DESCRIPTOR *TokenMapDesc; + CM_OBJ_DESCRIPTOR *CmObjDesc; + + if ((TokenMapper =3D=3D NULL) || + (TokenMapper->TokenDescArray =3D=3D NULL) || + (Size =3D=3D 0) || + (Data =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (TokenMapper->ItemCount >=3D TokenMapper->MaxTokenDescCount) { + ASSERT (0); + return EFI_BUFFER_TOO_SMALL; + } + + TokenMapDesc =3D &TokenMapper->TokenDescArray[TokenMapper->ItemCount++]; + TokenMapDesc->Token =3D Token; + CmObjDesc =3D &TokenMapDesc->CmObjDesc; + CmObjDesc->ObjectId =3D ObjectId; + CmObjDesc->Size =3D Size; + + // Point inside the finalized array. + CmObjDesc->Data =3D Data; + + // Only EArmObjCmRef CmObj can be added as arrays (more than 1 elements). + if ((GET_CM_NAMESPACE_ID (ObjectId) =3D=3D EObjNameSpaceArm) && + (GET_CM_OBJECT_ID (ObjectId) =3D=3D EArmObjCmRef)) { + CmObjDesc->Count =3D Size / sizeof (CM_ARM_OBJ_REF); + } else { + CmObjDesc->Count =3D 1; + } + + return EFI_SUCCESS; +} + +/** Get a CmObjDesc from a ObjectId/Token couple. + + The Token parameter is not optional. An existing token must be provided. + + @param [in] TokenMapper The TokenMapper instance. + @param [in] Token Token of the CmObj to search. + @param [in] ObjectId Object Id of the CmObj to search. + @param [out] CmObjDesc CM_OBJ_DESCRIPTOR containing the CmObj search= ed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Not found. +**/ +EFI_STATUS +EFIAPI +TokenMapperGetObject ( + IN TOKEN_MAPPER *TokenMapper, + IN CM_OBJECT_TOKEN Token, + IN CM_OBJECT_ID ObjectId, + OUT CM_OBJ_DESCRIPTOR *CmObjDesc + ) +{ + UINTN Index; + UINTN MaxCount; + TOKEN_MAP_DESCRIPTOR *TokenMapDesc; + + // Nothing to do. + if ((TokenMapper !=3D NULL) && (TokenMapper->MaxTokenDescCount =3D=3D 0)= ) { + return EFI_SUCCESS; + } + + if ((Token =3D=3D CM_NULL_TOKEN) || + (CmObjDesc =3D=3D NULL) || + (TokenMapper =3D=3D NULL) || + (TokenMapper->TokenDescArray =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + TokenMapDesc =3D TokenMapper->TokenDescArray; + MaxCount =3D TokenMapper->MaxTokenDescCount; + for (Index =3D 0; Index < MaxCount; Index++) { + if ((TokenMapDesc->CmObjDesc.ObjectId =3D=3D ObjectId) && + (TokenMapDesc->Token =3D=3D Token)) { + CopyMem ( + CmObjDesc, + &TokenMapDesc->CmObjDesc, + sizeof (CM_OBJ_DESCRIPTOR) + ); + return EFI_SUCCESS; + } + TokenMapDesc++; + } // for + + DEBUG (( + DEBUG_INFO, + "INFO: Requested CmObj of type 0x%x with token 0x%x" + " not found in the dynamic repository\n.", + ObjectId, + Token + )); + return EFI_NOT_FOUND; +} + +/** Initialise a TokenMapper. + + @param [in] TokenMapper The TokenMapper to initialise. + @param [in] DescriptorCount Number of entries to allocate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ALREADY_STARTED Instance already initialised. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperInitialise ( + IN TOKEN_MAPPER * TokenMapper, + IN UINTN DescriptorCount + ) +{ + if (TokenMapper =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Nothing to do. + if (DescriptorCount =3D=3D 0) { + return EFI_SUCCESS; + } + + if (TokenMapper->TokenDescArray !=3D NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Token mapper already initialised\n.")); + ASSERT (0); + return EFI_ALREADY_STARTED; + } + + TokenMapper->TokenDescArray =3D + AllocateZeroPool (sizeof (TOKEN_MAP_DESCRIPTOR) * DescriptorCount); + if (TokenMapper->TokenDescArray =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + TokenMapper->MaxTokenDescCount =3D DescriptorCount; + TokenMapper->ItemCount =3D 0; + + return EFI_SUCCESS; +} + +/** Shutdown a TokenMapper. + + @param [in] TokenMapper The TokenMapper to shutdown. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperShutdown ( + IN TOKEN_MAPPER * TokenMapper + ) +{ + // Nothing to do. + if ((TokenMapper !=3D NULL) && (TokenMapper->MaxTokenDescCount =3D=3D 0)= ) { + return EFI_SUCCESS; + } + + if ((TokenMapper =3D=3D NULL) || + (TokenMapper->TokenDescArray =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + FreePool (TokenMapper->TokenDescArray); + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper= .h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h new file mode 100644 index 000000000000..377fc03dcd01 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h @@ -0,0 +1,123 @@ +/** @file + Token Mapper + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#ifndef TOKEN_MAPPER_H_ +#define TOKEN_MAPPER_H_ + +#pragma pack(1) + +/** Token mapping descriptor. + + Bind a token and a CmObj together. +*/ +typedef struct TokenMapDescriptor { + /// Object Token. + CM_OBJECT_TOKEN Token; + + /// CmObjectDescriptor CM_OBJ_DESCRIPTOR.Data is a reference copy + /// and not allocated. It points to the individual objects in the + /// Dynamic Plat Repo ArmNameSpaceObjectArray. + CM_OBJ_DESCRIPTOR CmObjDesc; +} TOKEN_MAP_DESCRIPTOR; + +/** Token mapper. + + Contain all the Token/CmObj couple mapping. +**/ +typedef struct TokenMapper { + /// Maximum number of TOKEN_MAP_DESCRIPTOR entries in TokenDescArray. + UINTN MaxTokenDescCount; + + /// Next TOKEN_MAP_DESCRIPTOR entry to use in TokenDescArray. + UINTN ItemCount; + + /// Array of TOKEN_MAP_DESCRIPTOR. + TOKEN_MAP_DESCRIPTOR * TokenDescArray; +} TOKEN_MAPPER; + +#pragma pack() + +/** Add a CmObjDesc to the TokenMapper. + + @param [in] TokenMapper The TokenMapper instance. + @param [in] Token CmObj token. + @param [in] ObjectId CmObj ObjectId. + @param [in] Size CmObj Size. + @param [in] Data CmObj Data. + This memory is referenced, not copied. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_BUFFER_TOO_SMALL Buffer too small. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperAddObject ( + IN TOKEN_MAPPER *TokenMapper, + IN CM_OBJECT_TOKEN Token, + IN CM_OBJECT_ID ObjectId, + IN UINT32 Size, + IN VOID *Data + ); + +/** Get a CmObjDesc from a ObjectId/Token couple. + + The Token parameter is not optional. An existing token must be provided. + + @param [in] TokenMapper The TokenMapper instance. + @param [in] Token Token of the CmObj to search. + @param [in] ObjectId Object Id of the CmObj to search. + @param [out] CmObjDesc CM_OBJ_DESCRIPTOR containing the CmObj search= ed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Not found. +**/ +EFI_STATUS +EFIAPI +TokenMapperGetObject ( + IN TOKEN_MAPPER *TokenMapper, + IN CM_OBJECT_TOKEN Token, + IN CM_OBJECT_ID ObjectId, + OUT CM_OBJ_DESCRIPTOR *CmObjDesc + ); + +/** Initialise a TokenMapper. + + @param [in] TokenMapper The TokenMapper to initialise. + @param [in] DescriptorCount Number of entries to allocate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ALREADY_STARTED Instance already initialised. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperInitialise ( + IN TOKEN_MAPPER * TokenMapper, + IN UINTN DescriptorCount + ); + +/** Shutdown a TokenMapper. + + @param [in] TokenMapper The TokenMapper to shutdown. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +EFIAPI +TokenMapperShutdown ( + IN TOKEN_MAPPER * TokenMapper + ); + +#endif // TOKEN_MAPPER_H_ --=20 2.17.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 (#76988): https://edk2.groups.io/g/devel/message/76988 Mute This Topic: https://groups.io/mt/83737793/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 18 04:13:35 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+76989+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+76989+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624455416; cv=none; d=zohomail.com; s=zohoarc; b=CtdB0uejQCucJSUJL2vTXEa+7i8mXPW+u4UeITX1dgVXLeM/NOov5mX5p6vTENLOQ0WMqKbbim0eAkUULVGLskpabLuwjvW/Lejazt9PoQ+OWkMp7gRqjZyUXyHtfLvK+oajen6e+2lsiPe45p4UQTMXPTAKSzR10zbeJBCefl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624455416; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=/3T1JKVgq1JE0bbzuwHeKC+HiMbAFVQziAQlLUE6dts=; b=hzGIcu44RqaWaOJvBeTMzcS40vIWJ9co5W3qL7oPm7/wXkvQvp7fjLR40zwZL5sHkna0WK7qDWJPuQmAmCfb3jziM+i3uz/5GuTclLbIwoLg1uFpQ+x/0yKp9BwJunIK5SEB8A+SiDElCwyBucS26zn8ab6M71z/sEjMk16xJjw= 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+76989+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 1624455416234206.22100173570186; Wed, 23 Jun 2021 06:36:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3jAZYY1788612xXDBGHowikz; Wed, 23 Jun 2021 06:36:54 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.7795.1624455408507755551 for ; Wed, 23 Jun 2021 06:36:48 -0700 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 1CCD11063; Wed, 23 Jun 2021 06:36:48 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9FB7D3F718; Wed, 23 Jun 2021 06:36:46 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 5/5] DynamicTablesPkg: Add DynamicPlatRepo library Date: Wed, 23 Jun 2021 14:36:13 +0100 Message-Id: <20210623133613.29600-6-Pierre.Gondois@arm.com> In-Reply-To: <20210623133613.29600-1-Pierre.Gondois@arm.com> References: <20210623133613.29600-1-Pierre.Gondois@arm.com> 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: iQocCu8RAEUPzClUmg69Q6dRx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624455414; bh=dagR5p6SUhdHuilpUTTPFrBXnLkCv53xJYcoV/EyLmA=; h=Cc:Date:From:Reply-To:Subject:To; b=czJagFWYU0uJrcZAK+M/+0alGLLZm12OMbvpQFyo21Rm9eXHodKWfcIVVlcw0ISMeT6 bIKzfO7R6KiWkb0vc/MraKH36Wel/GTC1sZ8mW1USXthEnA4qeDaGjajCW/nwxazdk4VC xcPzA5OUAFC2QVhaMjYK522xziHHE7yCy0Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DynamicPlatRepo library allows to handle dynamically created CmObj. The dynamic platform repository can be in the following states: 1 - Non-initialised 2 - Transient: Possibility to add CmObj to the platform, but not to query them. 3 - Finalised: Possibility to query CmObj, but not to add new. A token is allocated to each CmObj added to the dynamic platform repository (except for reference tokens CmObj). This allows to retrieve dynamic CmObjs among all CmObj (static CmObj for instance). This patch add the inf file of the module and the main module functionnalities and update the dsc file of the package. Signed-off-by: Sami Mujawar Signed-off-by: Pierre Gondois --- DynamicTablesPkg/DynamicTablesPkg.dsc | 1 + .../Include/Library/DynamicPlatRepoLib.h | 4 +- .../DynamicPlatRepoLib/DynamicPlatRepo.c | 518 ++++++++++++++++++ .../DynamicPlatRepoInternal.h | 78 +++ .../DynamicPlatRepoLib/DynamicPlatRepoLib.inf | 33 ++ 5 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dyna= micPlatRepo.c create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dyna= micPlatRepoInternal.h create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dyna= micPlatRepoLib.inf diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/Dynam= icTablesPkg.dsc index fd7345891cf1..432c958cf8b2 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dsc +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc @@ -43,6 +43,7 @@ [Components.common] DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFix= upLib.inf DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf + DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf =20 [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h b/Dynami= cTablesPkg/Include/Library/DynamicPlatRepoLib.h index 8e4665bf5c59..4a76b30399b4 100644 --- a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h +++ b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h @@ -13,6 +13,8 @@ #ifndef DYNAMIC_PLAT_REPO_H_ #define DYNAMIC_PLAT_REPO_H_ =20 +#include + /** A structure describing the platform configuration manager repository information */ @@ -109,4 +111,4 @@ DynamicPlatRepoShutdown ( IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo ); =20 -#endif DYNAMIC_PLAT_REPO_H_ +#endif // DYNAMIC_PLAT_REPO_H_ diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlat= Repo.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo= .c new file mode 100644 index 000000000000..f26f8ad32bc8 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c @@ -0,0 +1,518 @@ +/** @file + Dynamic Platform Info Repository + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#include +#include +#include +#include +#include + +#include "CmObjectTokenFixer.h" +#include "DynamicPlatRepoInternal.h" +#include "TokenGenerator.h" + +/** Allocate a CM_OBJ_NODE. + + @param [in] CmObjDesc CmObj to wrap in a node. + All the fields of the CmObj (Data field included= ), + are copied. + @param [in] Token Token to assign to this CmObj/node. + @param [out] ObjNode Allocated ObjNode. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +AllocCmObjNode ( + IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc, + IN CM_OBJECT_TOKEN Token, + OUT CM_OBJ_NODE ** ObjNode + ) +{ + CM_OBJ_NODE *Node; + CM_OBJ_DESCRIPTOR *Desc; + + if ((CmObjDesc =3D=3D NULL) || (ObjNode =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Node =3D AllocateZeroPool (sizeof (CM_OBJ_NODE)); + if (Node =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Initialise the list head. + InitializeListHead (&Node->Link); + Node->Token =3D Token; + Desc =3D &Node->CmObjDesc; + Desc->ObjectId =3D CmObjDesc->ObjectId; + Desc->Size =3D CmObjDesc->Size; + Desc->Count =3D CmObjDesc->Count; + + // Allocate and copy the CmObject Data. + Desc->Data =3D AllocateCopyPool (CmObjDesc->Size, CmObjDesc->Data); + if (Desc->Data =3D=3D NULL) { + FreePool (Node); + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + *ObjNode =3D Node; + return EFI_SUCCESS; +} + +/** Free a CM_OBJ_NODE. + + @param [in] ObjNode ObjNode to free. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeCmObjNode ( + IN CM_OBJ_NODE * ObjNode + ) +{ + CM_OBJ_DESCRIPTOR *Desc; + + if (ObjNode =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Unlink Node + RemoveEntryList (&ObjNode->Link); + + Desc =3D &ObjNode->CmObjDesc; + if (Desc->Data !=3D NULL) { + FreePool (Desc->Data); + } + + FreePool (ObjNode); + return EFI_SUCCESS; +} + +/** Add an object to the dynamic platform repository. + + @param [in] This This dynamic platform repository. + @param [in] CmObjDesc CmObj to add. The data is copied. + @param [out] Token If not NULL, token allocated to this CmObj. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynPlatRepoAddObject ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This, + IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc, + OUT CM_OBJECT_TOKEN * Token OPTIONAL + ) +{ + EFI_STATUS Status; + CM_OBJ_NODE *ObjNode; + CM_OBJECT_ID ArmNamespaceObjId; + CM_OBJECT_TOKEN NewToken; + + // The dynamic repository must be able to receive objects. + if ((This =3D=3D NULL) || + (CmObjDesc =3D=3D NULL) || + (This->RepoState !=3D DynRepoTransient)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Check the CmObjDesc: + // - only Arm objects are supported for now. + // - only EArmObjCmRef objects can be added as arrays. + ArmNamespaceObjId =3D GET_CM_OBJECT_ID (CmObjDesc->ObjectId); + if ((CmObjDesc->Size =3D=3D 0) || + (CmObjDesc->Count =3D=3D 0) || + (ArmNamespaceObjId >=3D EArmObjMax) || + ((CmObjDesc->Count > 1) && (ArmNamespaceObjId !=3D EArmObjCmRef)) = || + (GET_CM_NAMESPACE_ID (CmObjDesc->ObjectId) !=3D EObjNameSpaceArm)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Generate a token. + NewToken =3D GenerateToken (); + + // Create an ObjNode. + Status =3D AllocCmObjNode (CmObjDesc, NewToken, &ObjNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Fixup self-token if necessary. + Status =3D FixupCmObjectSelfToken (&ObjNode->CmObjDesc, NewToken); + if (EFI_ERROR (Status)) { + FreeCmObjNode (ObjNode); + ASSERT (0); + return Status; + } + + // Add to link list. + InsertTailList (&This->ArmCmObjList[ArmNamespaceObjId], &ObjNode->Link); + This->ObjectCount +=3D 1; + + if (Token !=3D NULL) { + *Token =3D NewToken; + } + return EFI_SUCCESS; +} + +/** Group lists of CmObjNode from the ArmNameSpace to one array. + + @param [in] This This dynamic platform repository. + @param [in] ArmObjIndex Index in EARM_OBJECT_ID + (must be < EArmObjMax). + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_BUFFER_TOO_SMALL Buffer too small. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +STATIC +EFI_STATUS +EFIAPI +GroupCmObjNodes ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This, + IN UINT32 ArmObjIndex + ) +{ + EFI_STATUS Status; + UINTN Count; + UINTN Size; + UINT32 CmObjId; + UINT8 *GroupedData; + UINT8 *Data; + CM_OBJ_DESCRIPTOR *CmObjDesc; + LIST_ENTRY *ListHead; + LIST_ENTRY *Link; + + if ((This =3D=3D NULL) || + (ArmObjIndex >=3D EArmObjMax)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Count =3D 0; + Size =3D 0; + CmObjId =3D CREATE_CM_ARM_OBJECT_ID (ArmObjIndex); + ListHead =3D &This->ArmCmObjList[ArmObjIndex]; + Link =3D GetFirstNode (ListHead); + + // Compute the total count and size of the CmObj in the list. + while (Link !=3D ListHead) { + CmObjDesc =3D &((CM_OBJ_NODE*)Link)->CmObjDesc; + + if (CmObjDesc->ObjectId !=3D CmObjId) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if ((CmObjDesc->Count !=3D 1) && (ArmObjIndex !=3D EArmObjCmRef)){ + // We expect each descriptor to contain an individual object. + // EArmObjCmRef objects are counted as groups, so +1 as well. + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Count++; + Size +=3D CmObjDesc->Size; + + // Next Link + Link =3D GetNextNode (ListHead, Link); + } // while + + if (Count =3D=3D 0) { + // No objects found. + return EFI_SUCCESS; + } + + GroupedData =3D AllocateZeroPool (Size); + if (GroupedData =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Copy the Object Data and add to the TokenMapper. + Data =3D GroupedData; + Link =3D GetFirstNode (ListHead); + while (Link !=3D ListHead) { + CmObjDesc =3D &((CM_OBJ_NODE*)Link)->CmObjDesc; + CopyMem (Data, CmObjDesc->Data, CmObjDesc->Size); + + // Add the object to the Token Mapper. + // Note: The CmObject Data field of objects in the Token Mapper point + // to the memory in the GroupedData array. + Status =3D TokenMapperAddObject ( + &This->TokenMapper, + ((CM_OBJ_NODE*)Link)->Token, + CmObjDesc->ObjectId, + CmObjDesc->Size, + Data + ); + if (EFI_ERROR (Status)) { + FreePool (GroupedData); + return Status; + } + + Data +=3D CmObjDesc->Size; + Link =3D GetNextNode (ListHead, Link); + } // while + + CmObjDesc =3D &This->ArmCmObjArray[ArmObjIndex]; + CmObjDesc->ObjectId =3D CmObjId; + CmObjDesc->Size =3D Size; + CmObjDesc->Count =3D Count; + CmObjDesc->Data =3D GroupedData; + + return Status; +} + +/** Finalise the dynamic repository. + + Finalising means: + - Preventing any further objects from being added. + - Allowing to get objects from the dynamic repository + (not possible before a call to this function). + + @param [in] This This dynamic platform repository. + + @retval EFI_SUCCESS Success. + @retval EFI_ALREADY_STARTED Instance already initialised. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_BUFFER_TOO_SMALL Buffer too small. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoFinalise ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This + ) +{ + EFI_STATUS Status; + UINTN ArmObjIndex; + + if ((This =3D=3D NULL) || + (This->RepoState !=3D DynRepoTransient)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Prevent any further objects from being added. + This->RepoState =3D DynRepoFinalized; + + // Initialise the token mapper. + Status =3D TokenMapperInitialise (&This->TokenMapper, This->ObjectCount); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // For each CM_OBJECT_ID: + // - Convert the list of nodes to an array + // (the array is wrapped in a CmObjDesc). + // - Add the Token/CmObj binding to the token mapper. + for (ArmObjIndex =3D 0; ArmObjIndex < EArmObjMax; ArmObjIndex++) { + Status =3D GroupCmObjNodes (This, ArmObjIndex); + if (EFI_ERROR (Status)) { + ASSERT (0); + // Free the TokenMapper. + // Ignore the returned Status since we already failed. + TokenMapperShutdown (&This->TokenMapper); + return Status; + } + } // for + + return EFI_SUCCESS; +} + +/** Get a CmObj from the dynamic repository. + + @param [in] This Pointer to the Dynamic Platform Repository. + @param [in] CmObjectId The Configuration Manager Object ID. + @param [in] Token An optional token identifying the object. If + unused this must be CM_NULL_TOKEN. + @param [in, out] CmObjDesc Pointer to the Configuration Manager Object + descriptor describing the requested Object. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object information is not fou= nd. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoGetObject ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This, + IN CM_OBJECT_ID CmObjectId, + IN CM_OBJECT_TOKEN Token OPTIONAL, + IN OUT CM_OBJ_DESCRIPTOR * CmObjDesc + ) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR *Desc; + CM_OBJECT_ID ArmNamespaceObjId; + + if ((This =3D=3D NULL) || + (CmObjDesc =3D=3D NULL) || + (This->RepoState !=3D DynRepoFinalized)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ArmNamespaceObjId =3D GET_CM_OBJECT_ID (CmObjectId); + if (ArmNamespaceObjId >=3D EArmObjMax) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (Token !=3D CM_NULL_TOKEN) { + // Search in the Token Mapper and return the object. + Status =3D TokenMapperGetObject ( + &This->TokenMapper, + Token, + CmObjectId, + CmObjDesc + ); + ASSERT_EFI_ERROR (Status); + return Status; + } + + if (ArmNamespaceObjId =3D=3D EArmObjCmRef) { + // EArmObjCmRef object must be requested using a valid token. + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Desc =3D &This->ArmCmObjArray[ArmNamespaceObjId]; + + // Nothing here. + if (Desc->Count =3D=3D 0) { + return EFI_NOT_FOUND; + } else { + // Return the full array. + CmObjDesc->ObjectId =3D Desc->ObjectId; + CmObjDesc->Size =3D Desc->Size; + CmObjDesc->Data =3D Desc->Data; + CmObjDesc->Count =3D Desc->Count; + } + + return EFI_SUCCESS; +} + +/** Initialize the dynamic platform repository. + + @param [out] DynPlatRepo If success, contains the initialised dynamic + platform repository. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES An allocation has failed. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoInit ( + OUT DYNAMIC_PLATFORM_REPOSITORY_INFO ** DynPlatRepo + ) +{ + UINTN Index; + DYNAMIC_PLATFORM_REPOSITORY_INFO * Repo; + + if (DynPlatRepo =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Repo =3D AllocateZeroPool (sizeof (DYNAMIC_PLATFORM_REPOSITORY_INFO)); + if (Repo =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Initialise the CmObject List. + for (Index =3D 0; Index < EArmObjMax; Index++) { + InitializeListHead (&Repo->ArmCmObjList[Index]); + } + + Repo->ObjectCount =3D 0; + Repo->RepoState =3D DynRepoTransient; + + *DynPlatRepo =3D Repo; + + return EFI_SUCCESS; +} + +/** Shutdown the dynamic platform repository. + + Free all the memory allocated for the dynamic platform repository. + + @param [in] DynPlatRepo The dynamic platform repository. + + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +DynamicPlatRepoShutdown ( + IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo + ) +{ + EFI_STATUS Status; + UINT32 Index; + LIST_ENTRY * ListHead; + CM_OBJ_DESCRIPTOR * CmObjDesc; + VOID * Data; + + if (DynPlatRepo =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Free the list of objects. + for (Index =3D 0; Index < EArmObjMax; Index++) { + // Free all the nodes with this object Id. + ListHead =3D &DynPlatRepo->ArmCmObjList[Index]; + while (!IsListEmpty (ListHead)) { + FreeCmObjNode ((CM_OBJ_NODE*)GetFirstNode (ListHead)); + } // while + } // for + + // Free the arrays. + CmObjDesc =3D DynPlatRepo->ArmCmObjArray; + for (Index =3D 0; Index < EArmObjMax; Index++) { + Data =3D CmObjDesc[Index].Data; + if (Data !=3D NULL) { + FreePool (Data); + } + } // for + + // Free the TokenMapper + Status =3D TokenMapperShutdown (&DynPlatRepo->TokenMapper); + if (EFI_ERROR (Status)) { + ASSERT (0); + } + + FreePool (DynPlatRepo); + return Status; +} diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlat= RepoInternal.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dynamic= PlatRepoInternal.h new file mode 100644 index 000000000000..d03fa2b7dcec --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInt= ernal.h @@ -0,0 +1,78 @@ +/** @file + Dynamic Platform Info Repository Internal + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object +**/ + +#ifndef DYNAMIC_PLAT_REPO_INTERNAL_H_ +#define DYNAMIC_PLAT_REPO_INTERNAL_H_ + +#include "TokenMapper.h" + +#pragma pack(1) + +/** CmObj node. + + This is a node wrapper around the CM_OBJ_DESCRIPTOR structure. + It also allows to bind a token to the CM_OBJ_DESCRIPTOR. +*/ +typedef struct CmObjectNode { + /// This must be the first field in this structure. + LIST_ENTRY Link; + + /// Token associated with the CmObjDesc. + CM_OBJECT_TOKEN Token; + + /// CmObjDesc wrapped. + /// Note: the CM_OBJ_DESCRIPTOR.Data field is allocated and copied. + CM_OBJ_DESCRIPTOR CmObjDesc; +} CM_OBJ_NODE; + +/** Dynamic repository states. + + The states must progress as: + UnInitialised -> Transient -> Finalized +*/ +typedef enum DynRepoState { + DynRepoUnInitialised, ///< Un-Initialised state + DynRepoTransient, ///< Transient state - CmObjects can be added. + DynRepoFinalized, ///< Repo Locked - No further CmObjects can be add= ed. + ///< Getting objects is now possible. + DynRepoMax ///< Max value. +} EDYNAMIC_REPO_STATE; + +/** A structure describing the platform configuration + manager repository information +*/ +typedef struct DynamicPlatformRepositoryInfo { + /// Repo state machine. + EDYNAMIC_REPO_STATE RepoState; + + /// Count of all the objects added to the Dynamic Platform Repo + /// during the Transient state. + UINTN ObjectCount; + + /// Link lists of CmObj from the ArmNameSpace + /// that are added in the Transient state. + LIST_ENTRY ArmCmObjList[EArmObjMax]; + + /// Structure Members used in Finalized state. + /// An array of CmObj Descriptors from the ArmNameSpace + /// This array is populated when the Repo is finalized. + CM_OBJ_DESCRIPTOR ArmCmObjArray[EArmObjMax]; + + /// A token mapper for the objects in the ArmNamespaceObjectArray + /// The Token mapper is populated when the Repo is finalized in + /// a call to DynamicPlatRepoFinalise (). + TOKEN_MAPPER TokenMapper; +} DYNAMIC_PLATFORM_REPOSITORY_INFO; + +#pragma pack() + +#endif // DYNAMIC_PLAT_REPO_INTERNAL_H_ diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlat= RepoLib.inf b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPla= tRepoLib.inf new file mode 100644 index 000000000000..9a3cc87fd91d --- /dev/null +++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib= .inf @@ -0,0 +1,33 @@ +## @file +# Dynamic Platform Repository +# +# Copyright (c) 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D DynamicPlatRepoLib + FILE_GUID =3D 836D253D-3144-4A89-9BEE-BC55AFDC814E + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D DynamicPlatRepoLib + +[Sources] + CmObjectTokenFixer.c + CmObjectTokenFixer.h + DynamicPlatRepo.c + DynamicPlatRepoInternal.h + TokenGenerator.c + TokenGenerator.h + TokenMapper.c + TokenMapper.h + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + AcpiHelperLib + BaseLib --=20 2.17.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 (#76989): https://edk2.groups.io/g/devel/message/76989 Mute This Topic: https://groups.io/mt/83737794/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-