From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.82]) by mx.groups.io with SMTP id smtpd.web11.17180.1597245821902606672 for ; Wed, 12 Aug 2020 08:23:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=wy0x0w3a; spf=pass (domain: arm.com, ip: 40.107.8.82, 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=odB2sZkl1WjsS9WuezyqAWEpxUrPMRB1OI4b3qHuvUk=; b=wy0x0w3aftVv6CFwTAAPlD9C94z9Pp8k0fwq4YxTOYSpIRZZzFunvcQsCW3bjSWPjZ9xnVOKlDZYtcyvaoFXNO/hcKHlW6Nklj+a0qDYuuQNq5X+Wy0NqXKuXNY5wgfeaOTGgmBHNYY/2O0M9axnzTJin/NNPvlh5YZWfJx5OLw= Received: from DB6P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:6:28::33) by AM5PR0801MB1841.eurprd08.prod.outlook.com (2603:10a6:203:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.15; Wed, 12 Aug 2020 15:23:39 +0000 Received: from DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:28:cafe::2c) by DB6P191CA0023.outlook.office365.com (2603:10a6:6:28::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16 via Frontend Transport; Wed, 12 Aug 2020 15:23:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass 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 DB5EUR03FT064.mail.protection.outlook.com (10.152.21.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16 via Frontend Transport; Wed, 12 Aug 2020 15:23:39 +0000 Received: ("Tessian outbound bac899b43a54:v64"); Wed, 12 Aug 2020 15:23:39 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 02d58a94a28e5e68 X-CR-MTA-TID: 64aa7808 Received: from fffea78f42a8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3EA1AB9E-3604-4CCB-A2FA-18812E5049B1.1; Wed, 12 Aug 2020 15:23:33 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fffea78f42a8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 12 Aug 2020 15:23:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oF2H1dFAq6IZuptB2pKFN841uLfUtuzzkQRDN+N8wdMI1NycgwviTXP3Z0rVWZrZ1hQCLgfVQt974uomnuUhBo1+KBvCn8yz2l2qRuOjde/89nokFZMeWO8rTzTElffz2jHRkoFfqzcmihRORZsPrNn6NO2OyV7OqaQsyJvuQ00mKuRgWNwJXKYrti+smnyugDc8mU530WrBGxP8WAgw3/fzn3ZDfaf7/fTTNuqa7TsF65WBO39ifpsOIV25YXaTJGJCbTT8X5ROA4vu59Jch/KalJriMwEebj9FGK5lp4gasyYJlBo48s+H4PdMGh9Z9tqw1oMDUSSa2sJvovTPhQ== 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-SenderADCheck; bh=odB2sZkl1WjsS9WuezyqAWEpxUrPMRB1OI4b3qHuvUk=; b=JtPmM/YVk1yzL9fNF1w4dJh1FiRSPK3wHgMq+5S9bFf8dvLoUEY53LB4Kb5cSgLtptYv4pe4SpH3ZOxJ6rSj0h7rrPc9zVl/odO9TU/t2Nfmgj7ewggjXextXYYgcMJBRiWXMWcKmM0i9fzQLVHl5a2OjtPDr6aq44QUnjgwsUjdjvMBVyDUqkdKc7/vKsr+4h/j7Hr/ycf4s+X5wxDc9ibVjZovyaShEHcxmHC4TsC98TVXXWCKc6HdymTW/h5TmMpp2eCuatGxs34fzPwaQ1N5HVZ5jWnSgfOVXxTIW3oxIzabIscHsDJtTHDkKQnUkHUfTrr2/EwKESd+nXkdew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); 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=odB2sZkl1WjsS9WuezyqAWEpxUrPMRB1OI4b3qHuvUk=; b=wy0x0w3aftVv6CFwTAAPlD9C94z9Pp8k0fwq4YxTOYSpIRZZzFunvcQsCW3bjSWPjZ9xnVOKlDZYtcyvaoFXNO/hcKHlW6Nklj+a0qDYuuQNq5X+Wy0NqXKuXNY5wgfeaOTGgmBHNYY/2O0M9axnzTJin/NNPvlh5YZWfJx5OLw= Received: from DB6PR07CA0106.eurprd07.prod.outlook.com (2603:10a6:6:2c::20) by AM6PR08MB5144.eurprd08.prod.outlook.com (2603:10a6:20b:ec::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.22; Wed, 12 Aug 2020 15:23:32 +0000 Received: from DB5EUR03FT022.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2c:cafe::78) by DB6PR07CA0106.outlook.office365.com (2603:10a6:6:2c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.10 via Frontend Transport; Wed, 12 Aug 2020 15:23:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT022.mail.protection.outlook.com (10.152.20.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3283.16 via Frontend Transport; Wed, 12 Aug 2020 15:23:31 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Wed, 12 Aug 2020 15:23:30 +0000 Received: from E107187.Arm.com (10.57.41.222) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2044.4 via Frontend Transport; Wed, 12 Aug 2020 15:23:30 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , Subject: [PATCH v1 17/30] DynamicTablesPkg: AML resource data helper Date: Wed, 12 Aug 2020 16:22:23 +0100 Message-ID: <20200812152236.31164-18-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200812152236.31164-1-sami.mujawar@arm.com> References: <20200812152236.31164-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b16986d-fb4e-4b1e-11be-08d83ed3b060 X-MS-TrafficTypeDiagnostic: AM6PR08MB5144:|AM5PR0801MB1841: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:5797;OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: olANRNyH0YHpkRtzWImg+ZbCWV5nYq04ZZtQcF3QEhvppLFFRKyF+4bdQQoeHT5s89J6SZiWM0XF5g+YuLhIbcj7u/jgOHQNQ5DoR8IcmRbEh/9DRU8NUXEUk8ROmnusFPDu5GnWtUkeesQmQZL2b9HuBkOt88yC+vAqMwdi4Qninwp48mQHgZ0QrrBi93T+E+aTPknzQ4iO3bJes4xIk2LYxZw2a1Udf5dtIvdONP49UuPueBO5Xr5ipoLpYtUbFS8wmFzDiX8ollTic8ySFPQh9M4RE5ZQHpR2Sfxemrkv/ImX8q1VgwwvRakod5Ho3QMpxUYvRY4J75Xv4iU+Fcoe40No9lRR3Qytm9sBKtq9g8VdFDRuEsNAxOlNKYuqdICMK5A8V//5QWtn/wG9kw== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(136003)(376002)(346002)(39860400002)(396003)(46966005)(6916009)(186003)(6666004)(86362001)(4326008)(1076003)(8676002)(8936002)(54906003)(336012)(7696005)(316002)(26005)(478600001)(83380400001)(44832011)(47076004)(2906002)(36756003)(82740400003)(81166007)(70586007)(70206006)(356005)(82310400002)(2616005)(5660300002)(426003);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5144 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 86b55e45-081b-4b51-36a5-08d83ed3ac1a X-Microsoft-Antispam: BCL:0; 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)(396003)(39860400002)(346002)(376002)(136003)(46966005)(8936002)(44832011)(8676002)(36756003)(2616005)(186003)(82740400003)(54906003)(47076004)(426003)(316002)(26005)(7696005)(6916009)(336012)(6666004)(4326008)(478600001)(5660300002)(70586007)(86362001)(83380400001)(1076003)(2906002)(81166007)(70206006)(82310400002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2020 15:23:39.0902 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b16986d-fb4e-4b1e-11be-08d83ed3b060 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: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1841 Content-Type: text/plain From: Pierre Gondois Resource data are defined in the ACPI 6.3 specification, s6.4 "Resource Data Types for ACPI". They can be created using the ASL ResourceTemplate () statement, cf s19.3.3 "ASL Resource Templates". Resource data can be of the small or large type and are defined by their encoding. The resource data is stored in the Bytelist of a BufferOp node. To simplify operations on resource data, the resource data parser examines the Bytelist to detect the presence of resource data. If the data matches the encoding of resource data type(s), the parser fragments the resource data buffer into resource data elements (data nodes) and stores them in the variable arguments list of the BufferOp node. The resource data helper provides functions and macros to assist operations on resource data elements. Signed-off-by: Pierre Gondois Signed-off-by: Sami Mujawar --- DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c | 103 ++++++++++++ DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h | 174 ++++++++++++++++++++ 2 files changed, 277 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c new file mode 100644 index 0000000000000000000000000000000000000000..8b46c7232df3bb7d49e5faa1362a485a6a413198 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c @@ -0,0 +1,103 @@ +/** @file + AML Resource Data. + + Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Rd or RD - Resource Data + - Rds or RDS - Resource Data Small + - Rdl or RDL - Resource Data Large +**/ + +#include + +/** Check whether the resource data has the input descriptor Id. + + The small/large bit is included in the descriptor Id, + but the size bits are not included for small resource data elements. + + @param [in] Header Pointer to the first byte of a resource data + element. + @param [in] DescriptorId The descriptor to check against. + + @retval TRUE The resource data has the descriptor Id. + @retval FALSE Otherwise. +**/ +BOOLEAN +EFIAPI +AmlRdCompareDescId ( + IN CONST AML_RD_HEADER * Header, + IN AML_RD_HEADER DescriptorId + ) +{ + if (Header == NULL) { + ASSERT (0); + return FALSE; + } + + if (AML_RD_IS_LARGE (Header)) { + return ((*Header ^ DescriptorId) == 0); + } else { + return (((*Header & AML_RD_SMALL_ID_MASK) ^ DescriptorId) == 0); + } +} + +/** Get the descriptor Id of the resource data. + + The small/large bit is included in the descriptor Id, + but the size bits are not included for small resource data elements. + + @param [in] Header Pointer to the first byte of a resource data. + + @return A descriptor Id. +**/ +AML_RD_HEADER +EFIAPI +AmlRdGetDescId ( + IN CONST AML_RD_HEADER * Header + ) +{ + if (Header == NULL) { + ASSERT (0); + return FALSE; + } + + if (AML_RD_IS_LARGE (Header)) { + return *Header; + } + + // Header is a small resource data element. + return *Header & AML_RD_SMALL_ID_MASK; +} + +/** Get the size of a resource data element. + + If the resource data element is of the large type, the Header + is expected to be at least 3 bytes long. + + @param [in] Header Pointer to the first byte of a resource data. + + @return The size of the resource data element. +**/ +UINT32 +EFIAPI +AmlRdGetSize ( + IN CONST AML_RD_HEADER * Header + ) +{ + if (Header == NULL) { + ASSERT (0); + return FALSE; + } + + if (AML_RD_IS_LARGE (Header)) { + return ((ACPI_LARGE_RESOURCE_HEADER*)Header)->Length + + sizeof (ACPI_LARGE_RESOURCE_HEADER); + } + + // Header is a small resource data element. + return ((ACPI_SMALL_RESOURCE_HEADER*)Header)->Bits.Length + + sizeof (ACPI_SMALL_RESOURCE_HEADER); +} diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h new file mode 100644 index 0000000000000000000000000000000000000000..48e4e2aaddb47e3847cb896e9bc64d4c68bda9f4 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h @@ -0,0 +1,174 @@ +/** @file + AML Resource Data. + + Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Rd or RD - Resource Data + - Rds or RDS - Resource Data Small + - Rdl or RDL - Resource Data Large +**/ + +#ifndef AML_RESOURCE_DATA_H_ +#define AML_RESOURCE_DATA_H_ + +/* This header file does not include internal Node definition, + i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. The node definitions + must be included by the caller file. The function prototypes must + only expose AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE, etc. node + definitions. + This allows to keep the functions defined here both internal and + potentially external. If necessary, any function of this file can + be exposed externally. + The Api folder is internal to the AmlLib, but should only use these + functions. They provide a "safe" way to interact with the AmlLib. +*/ + +#include +#include + +/** + @defgroup ResourceDataLibrary Resource data library + @ingroup AMLLib + @{ + Resource data are defined in the ACPI 6.3 specification, + s6.4 "Resource Data Types for ACPI". They can be created in ASL via the + ResourceTemplate () statement, cf s19.3.3 "ASL Resource Templates". + + Resource data can be of the small or large type. The difference between + small and large resource data elements is their encoding. + + Resource data are stored in the variable list of arguments of object + nodes. + @} +*/ + +/** Resource Descriptor header for Small/Large Resource Data Object. + This is the first byte of a Small/Large Resource Data element. + + Can be a ACPI_SMALL_RESOURCE_HEADER or ACPI_LARGE_RESOURCE_HEADER. + + @ingroup ResourceDataStructures +*/ +typedef UINT8 AML_RD_HEADER; + +/** Mask for the small resource data size. + + @ingroup ResourceDataStructures +*/ +#define AML_RD_SMALL_SIZE_MASK (0x7U) + +/** Mask for the small resource data ID. + + @ingroup ResourceDataStructures +*/ +#define AML_RD_SMALL_ID_MASK (0xFU << 3) + +/** Mask for the large resource data ID. + + @ingroup ResourceDataStructures +*/ +#define AML_RD_LARGE_ID_MASK (0x7FU) + +/** + @defgroup ResourceDataApis Resource data APIs + @ingroup ResourceDataLibrary + @{ + Resource data APIs allow to manipulate/decode resource data elements. + @} +*/ + +/** Check whether a resource data is of the large type. + + @ingroup ResourceDataApis + + @param [in] Header Pointer to the first byte of a resource data. + + @retval TRUE If the resource data is of the large type. + @retval FALSE Otherwise. +**/ +#define AML_RD_IS_LARGE(Header) \ + (((ACPI_SMALL_RESOURCE_HEADER*)Header)->Bits.Type == \ + ACPI_LARGE_ITEM_FLAG) + +/** Build a small resource data descriptor Id. + The small/large bit is included in the descriptor Id, + but the size bits are not included. + + @ingroup ResourceDataApis + + @param [in] Id Descriptor Id. + + @return A descriptor Id. +**/ +#define AML_RD_BUILD_SMALL_DESC_ID(Id) ((AML_RD_HEADER)((Id & 0xF) << 3)) + +/** Build a large resource data descriptor Id. + The small/large bit is included in the descriptor Id. + + @ingroup ResourceDataApis + + @param [in] Id Id of the descriptor. + + @return A descriptor Id. +**/ +#define AML_RD_BUILD_LARGE_DESC_ID(Id) ((AML_RD_HEADER)((BIT7) | Id)) + +/** Check whether the resource data has the input descriptor Id. + + The small/large bit is included in the descriptor Id, + but the size bits are not included for small resource data elements. + + @ingroup ResourceDataApis + + @param [in] Header Pointer to the first byte of a resource data + element. + @param [in] DescriptorId The descriptor to check against. + + @retval TRUE The resource data has the descriptor Id. + @retval FALSE Otherwise. +**/ +BOOLEAN +EFIAPI +AmlRdCompareDescId ( + IN CONST AML_RD_HEADER * Header, + IN AML_RD_HEADER DescriptorId + ); + +/** Get the descriptor Id of the resource data. + + The small/large bit is included in the descriptor Id, + but the size bits are not included for small resource data elements. + + @ingroup ResourceDataApis + + @param [in] Header Pointer to the first byte of a resource data. + + @return A descriptor Id. +**/ +AML_RD_HEADER +EFIAPI +AmlRdGetDescId ( + IN CONST AML_RD_HEADER * Header + ); + +/** Get the size of a resource data element. + + If the resource data element is of the large type, the Header + is expected to be at least 3 bytes long. + + @ingroup ResourceDataApis + + @param [in] Header Pointer to the first byte of a resource data. + + @return The size of the resource data element. +**/ +UINT32 +EFIAPI +AmlRdGetSize ( + IN CONST AML_RD_HEADER * Header + ); + +#endif // AML_RESOURCE_DATA_H_ -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'