From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.47]) by mx.groups.io with SMTP id smtpd.web11.5553.1636119120521332105 for ; Fri, 05 Nov 2021 06:32:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=I20mkx7M; spf=pass (domain: arm.com, ip: 40.107.2.47, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mTMKIBkp+XH+C3BI6nZLM6S2gHhADX54FUldBt5sCXA=; b=I20mkx7MOD6rswHowZf9TFfNuylGoOnvG0b4LdkusaMMIpu6Vk6mnw9+mQaB5wXCOvhytDksZTGH0cOgRzs12ddU3cdnmmLf4xjRk54u983VRN72mhn77MhB2TH1WlFe+zGV227Io2US89aWKPd1NWJXia64TnOXoX5uXb0anq8= Received: from DB8P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::40) by AS8PR08MB6533.eurprd08.prod.outlook.com (2603:10a6:20b:33e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10; Fri, 5 Nov 2021 13:31:54 +0000 Received: from DB5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:130:cafe::b2) by DB8P191CA0030.outlook.office365.com (2603:10a6:10:130::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 5 Nov 2021 13:31:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT027.mail.protection.outlook.com (10.152.20.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14 via Frontend Transport; Fri, 5 Nov 2021 13:31:54 +0000 Received: ("Tessian outbound d49ee2bec50d:v108"); Fri, 05 Nov 2021 13:31:54 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c0da351c980a355c X-CR-MTA-TID: 64aa7808 Received: from db873c1d22a1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 37AC6318-B58A-4C26-88E5-F5E9FAC2AC41.1; Fri, 05 Nov 2021 13:31:38 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id db873c1d22a1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 05 Nov 2021 13:31:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YVweHESO5+GsgEFPpAJbhZfV331pzawCMdwIiRg3q8upM7AX5XNiu5AFuV75txRdDLxr1yLP0fRj1UaVH/hoymdJ7TIllGQfi0L083rsvHkOjbxgPDC35vVU2VORyUl/Qs0/Vp9JpKMaqjw85Y4qNTMijK7uMA9t0fTKbRKCakWBDmGYXCTAY2sxq3VT6TTKApGR1DcBMzzfrAEtOgc2EYiNb+UqFeYFo2WHIErguWOzm0M5WdTn/NbmyZVsxR5KlVU/xMRJ9BHXS66KJghOQ11BNoYe/lpPRV/Pw8dkSa17YJ+KxwPw7UROPtzi8Kt3Pjh/5MZK/ymZheuoiSmrqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mTMKIBkp+XH+C3BI6nZLM6S2gHhADX54FUldBt5sCXA=; b=nIYHNFaGcTyit2BvbOb6KIiG1Smd8niEMpmVkPXPjRpnO5xT58p06V9Vk61geA1kMDWZ1yMo/DtICUi96n51mAyRJoZap9A9kZDeQyCgy3Q7MSybQXuzejBzpX4weJAe+rtBG219g3KV4gFJgzMmxiTBaM7TZTET4JJcBCELbknX3/O5VHgCru+Gg8gxbL0XZW0+Nh8Vz6LapnqNrAuH/Av101svvA15awj09U0lXnALCUbgfUmLzlC2FWGSkzjr8N8rInGXwBZmXdYBxNaMPScguT0Khg6P1zJNO2AzHU5otK/jNYMDQg5i5cDrtTo3Hdi1Aw8ImyXOu80N8IHPdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mTMKIBkp+XH+C3BI6nZLM6S2gHhADX54FUldBt5sCXA=; b=I20mkx7MOD6rswHowZf9TFfNuylGoOnvG0b4LdkusaMMIpu6Vk6mnw9+mQaB5wXCOvhytDksZTGH0cOgRzs12ddU3cdnmmLf4xjRk54u983VRN72mhn77MhB2TH1WlFe+zGV227Io2US89aWKPd1NWJXia64TnOXoX5uXb0anq8= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by AS8PR08MB6631.eurprd08.prod.outlook.com (2603:10a6:20b:339::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Fri, 5 Nov 2021 13:31:24 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65%4]) with mapi id 15.20.4669.010; Fri, 5 Nov 2021 13:31:24 +0000 Subject: Re: [PATCH v1 4/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenMapper To: Pierre.Gondois@arm.com, devel@edk2.groups.io, Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei , nd References: <20210623133613.29600-1-Pierre.Gondois@arm.com> <20210623133613.29600-5-Pierre.Gondois@arm.com> From: "Sami Mujawar" Message-ID: <37734294-6fc5-72b1-081e-ddd373719a2e@arm.com> Date: Fri, 5 Nov 2021 13:31:28 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 In-Reply-To: <20210623133613.29600-5-Pierre.Gondois@arm.com> X-ClientProxiedBy: LO2P123CA0026.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::14) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 Received: from [10.1.196.43] (217.140.106.52) by LO2P123CA0026.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 5 Nov 2021 13:31:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f6a9017-bb9d-4fe5-8aa1-08d9a060a1d2 X-MS-TrafficTypeDiagnostic: AS8PR08MB6631:|AS8PR08MB6533: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: F+DhZDCzvTsP1jFjx9yk3LVQdqLfGc2DdQC9+wI7tYOx1ODS7WNYpKsxV91ofCtUT6zj/QRXF+YW2Ta6Yum5Jze2z+qfS4otdhEfliGiVoLeCCr7Lwfejejl0r0XiUVCGciMXoJKcTV/Dn6cXFrMLNFetLbgDEU2qOqtTDmy+q9VevvaLLA5c50bsTTuAz8KayYBxsf2mh5fuqKoR///QlsaaEb7Umoeoxau4EopIwlJlz5yd3Q96xUAHB7utCqDdopgWbG6pdZvBbZpqmAQXyGcEh0toGEgdEgX+Yi8ahOeBL8CDyEbbZKINUCqyV+AkT7P5twkiMzLYQf1y87Vkqs3Whwjy2CUYnp//Qd368GMhvN+GgHXHDYKabppO0XJxBTW05xFqsD92P7Z3sVl8ar+UuCBghyctNsfCvEvcXHTFW9Bjr0GaPrjD59Rb+C4/mI+d5NQ0e2V7D/pPODbZJoO56Wjf5I5vy+ifk6a3DxRDW4CCVEBr6Pn795EG2BGnU+Y9lKu8d32Cpdhvp95a/YQtNtaubL/QW5TUhiwFPrYzgcjfRdPFsL5vLulI9Raar98FSbFivtMAfEKyxQ0Cs2tIWIUmbE6WDFdBJIP50rWNYov6Dpyr/wkGH5Ek4TMvQrAKSbHiYwjAhIM70UxLa3Q6pJ/5gR9elMJ37Wz+nWpoJH2wzS+Vf192HAyZ9dOCu5ktg6b35fVtt4ixiYZboN0x02LmjY/V5T3jJ76FRlC4WVjwvdVgrhPiRqUPvse2TR+6mIuuU+KCitwQZYbkQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6636002)(38100700002)(83380400001)(4326008)(2906002)(26005)(53546011)(5660300002)(52116002)(54906003)(956004)(508600001)(6862004)(31686004)(2616005)(66476007)(38350700002)(44832011)(316002)(186003)(30864003)(86362001)(16576012)(6486002)(8676002)(37006003)(31696002)(8936002)(66556008)(66946007)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6631 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: d773301d-0601-4045-0184-08d9a0608fc9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gB7Qr5GHPje4fGRWk8mTahIvkpB136FNBo7AMIcqoSjATl/TyjdGGeYlYfENVLYH02d9QPZ0zZAoRWRTAjwXpLqX+RnucEnihyN4Ibc4Vnx/pQT1Bizfgm7kCtB0BWaOrkcwK0g8SXBleHIhJ43Ga67ooPqz02j9PSFYQ3sIn58hExh7ZfB0hjF0FZx1Gwr+00GyGQjaaMdRxDYacX10b1ESRWDxLUkG6irUyaDVL5DRgv0lDfcHA7lterDkpq27H8LGRn6NOfqSG+AAIXRF2hoZT3CoWlCT/dMBOWKfuVwOHqOdfte45PPOhjIRx8eelfq+6IPO3Ts8WyOlfgNbi8rhszF6AibYqqed4O5MERfcyMjcPv6V2Xq1P9Bz24hWGOC435aUMZQothMK5xiVQFfoKVkwpwHcBkm8rXMlezcvUlz6BX4NdJQuikXGEpPsQbKbYfA1ZOx///+ySXpNFo0D9sZfHBCCht8xJKhIeYUw2Se4yX5B8KMOpWc/pSgo/ytEFIO5YfAhdltsghQ5VJ5gIwxth/aKnSVE6M3wWiq0aYvXhbkESVf1Bu6LdmxlC43mE/GhfhUyKiDVRLbv2fm4E01Sgoas2sLZMc4qiXyk/HvLEofGqV5lq0MvkQ1Aw2wYIkcVlmDCcpIJfdRfxtxQMotpx/X4w7VBP54UOn2PFg9ca3hw/jD2+V52SrdMJG4Gk6R7v0F3rxsnVR/k3vu+uW7vOz5N2NoFnytLqoc= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(31686004)(356005)(47076005)(316002)(508600001)(16576012)(2906002)(8676002)(82310400003)(8936002)(36756003)(31696002)(6862004)(186003)(6486002)(26005)(83380400001)(70206006)(2616005)(53546011)(70586007)(4326008)(44832011)(956004)(336012)(86362001)(5660300002)(6636002)(54906003)(36860700001)(37006003)(30864003)(81166007)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 13:31:54.1780 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f6a9017-bb9d-4fe5-8aa1-08d9a060a1d2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6533 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Hi Pierre, Please find my response inline marked [SAMI]. Regards, Sami Mujawar On 23/06/2021 02:36 PM, Pierre.Gondois@arm.com wrote: > 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/TokenMapper.c > create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.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 == NULL) || > + (TokenMapper->TokenDescArray == NULL) || > + (Size == 0) || > + (Data == NULL)) { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + if (TokenMapper->ItemCount >= TokenMapper->MaxTokenDescCount) { > + ASSERT (0); > + return EFI_BUFFER_TOO_SMALL; > + } > + > + TokenMapDesc = &TokenMapper->TokenDescArray[TokenMapper->ItemCount++]; > + TokenMapDesc->Token = Token; > + CmObjDesc = &TokenMapDesc->CmObjDesc; > + CmObjDesc->ObjectId = ObjectId; > + CmObjDesc->Size = Size; > + > + // Point inside the finalized array. > + CmObjDesc->Data = Data; > + > + // Only EArmObjCmRef CmObj can be added as arrays (more than 1 elements). > + if ((GET_CM_NAMESPACE_ID (ObjectId) == EObjNameSpaceArm) && > + (GET_CM_OBJECT_ID (ObjectId) == EArmObjCmRef)) { > + CmObjDesc->Count = Size / sizeof (CM_ARM_OBJ_REF); > + } else { > + CmObjDesc->Count = 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 searched. > + > + @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 != NULL) && (TokenMapper->MaxTokenDescCount == 0)) { > + return EFI_SUCCESS; [SAMI] I think EFI_INVALID_PARAMETER or EFI_NOT_FOUND should be returned here. Can you check, please? > + } > + > + if ((Token == CM_NULL_TOKEN) || > + (CmObjDesc == NULL) || > + (TokenMapper == NULL) || > + (TokenMapper->TokenDescArray == NULL)) { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + TokenMapDesc = TokenMapper->TokenDescArray; > + MaxCount = TokenMapper->MaxTokenDescCount; > + for (Index = 0; Index < MaxCount; Index++) { > + if ((TokenMapDesc->CmObjDesc.ObjectId == ObjectId) && > + (TokenMapDesc->Token == 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 == NULL) { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + // Nothing to do. > + if (DescriptorCount == 0) { > + return EFI_SUCCESS; > + } > + > + if (TokenMapper->TokenDescArray != NULL) { > + DEBUG ((DEBUG_ERROR, "ERROR: Token mapper already initialised\n.")); > + ASSERT (0); > + return EFI_ALREADY_STARTED; > + } > + > + TokenMapper->TokenDescArray = > + AllocateZeroPool (sizeof (TOKEN_MAP_DESCRIPTOR) * DescriptorCount); > + if (TokenMapper->TokenDescArray == NULL) { > + ASSERT (0); > + return EFI_OUT_OF_RESOURCES; > + } > + > + TokenMapper->MaxTokenDescCount = DescriptorCount; > + TokenMapper->ItemCount = 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 != NULL) && (TokenMapper->MaxTokenDescCount == 0)) { > + return EFI_SUCCESS; > + } > + > + if ((TokenMapper == NULL) || > + (TokenMapper->TokenDescArray == 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 searched. > + > + @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_