From nobody Tue Feb 10 08:31:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+76946+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+76946+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624448506; cv=none; d=zohomail.com; s=zohoarc; b=TanrggstJrkdISCQ70+ghP//H4/9dmxHxZTtiA4c2KV9ROS6cUrb7vKu4AdZSIz/TZJN9ZRAlg1KtzL6h1xETagwBShSRtyDef/HJPGNXtFnO9+VQvkKytj+c+LrAOBgMASdMowJNpkaJfESwDB5wnlmnmNijYjRHZ68zyf0Nhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624448506; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=HwhQt+GPKOmXFWxU6hIV3EqpaXwZxK8c2ouSutRucUs=; b=Q2ULWR4pnoq1kJEQjbADvMApBTMPBZnELXM4JeZqX7gF3uzupsAXX50l580XFkzvByVZEsSsSh/nvLFobTjrTpreCouTTybRW3slf24ALry6mxEXVnsr4DEsY3M2haOm3YMxIjfu/SvcJ502/iEXITuNnF2ZmZ65MIXRW4ooJB0= 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+76946+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 1624448506454480.09083920908006; Wed, 23 Jun 2021 04:41:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YtnGYY1788612xIbVWadbHWP; Wed, 23 Jun 2021 04:41:46 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6278.1624448500427470836 for ; Wed, 23 Jun 2021 04:41:40 -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 1F89A31B; Wed, 23 Jun 2021 04:41: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 BD8113F719; Wed, 23 Jun 2021 04:41:38 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 05/13] DynamicTablesPkg: Helper function to compute package length Date: Wed, 23 Jun 2021 12:40:30 +0100 Message-Id: <20210623114039.24491-6-Pierre.Gondois@arm.com> In-Reply-To: <20210623114039.24491-1-Pierre.Gondois@arm.com> References: <20210623114039.24491-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: h4J2m7IgpeKqeAEW825TttAhx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624448506; bh=1OnuqhiMtDXJn7Wwmi03R5xxEERycyUL8zpbZTjjncY=; h=Cc:Date:From:Reply-To:Subject:To; b=M4mtOxjxTmHbRPRoz6FybvbWiQGaA13PT1QHUuahEKrox6KexM0OHJBk+3EVC9dHjZa 0DqIQzaOdqCN+JCcpcEJZvGY326wpZJui3Jl8cT6xrrXz2Xqu1xRMAdPM1EwO2wyYwy/r P6ErUhVrQrE+oanHoGBeAt7pRu4VZfxigqY= 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 Some AML object have a PkgLen which indicates the size of the AML object. The package length can be encoded in 1 to 4 bytes. The bytes used to encode the PkgLen is itself counted in the PkgLen value. So, if an AML object's size increments/decrements, the number of bytes used to encode the PkgLen value can itself increment/decrement. Therefore, a helper function AmlComputePkgLength() is introduced to simply computation of the PkgLen. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../Library/Common/AmlLib/AmlEncoding/Aml.c | 87 ++++++++++++++++++- .../Library/Common/AmlLib/AmlEncoding/Aml.h | 47 +++++++++- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.c b/Dyn= amicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.c index eadafca97ea5..d829b1869846 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.c @@ -2,7 +2,7 @@ AML grammar definitions. =20 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
- Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -803,3 +803,88 @@ AmlComputePkgLengthWidth ( // Length < 2^6 return 1; } + +/** Given a length, compute the value of a PkgLen. + + In AML, some object have a PkgLen, telling the size of the AML object. + It can be encoded in 1 to 4 bytes. The bytes used to encode the PkgLen is + itself counted in the PkgLen value. + This means that if an AML object sees its size increment/decrement, + the number of bytes used to encode the PkgLen value can itself + increment/decrement. + + For instance, the AML encoding of a DeviceOp is: + DefDevice :=3D DeviceOp PkgLength NameString TermList + If: + - sizeof (NameString) =3D 4 (the name is "DEV0" for instance); + - sizeof (TermList) =3D (2^6-6) + then the PkgLen is encoded on 1 byte. Indeed, its value is: + sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) =3D + sizeof (PkgLen) + 4 + (2^6-6) + So: + PkgLen =3D sizeof (PkgLen) + (2^6-2) + + The input arguments Length and PkgLen represent, for the DefDevice: + DefDevice :=3D DeviceOp PkgLength NameString TermList + |------Length-----| + |--------*PgkLength---------| + + @param [in] Length The length to encode as a PkgLen. + Length cannot exceed 2^28 - 4 (4 bytes for the + PkgLen encoding). + The size of the PkgLen encoding bytes should not be + counted in this length value. + @param [out] PkgLen If success, contains the value of the PkgLen, + ready to encode in the PkgLen format. + This value takes into account the size of PkgLen + encoding. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlComputePkgLength ( + IN UINT32 Length, + OUT UINT32 * PkgLen + ) +{ + UINT32 PkgLenWidth; + UINT32 ReComputedPkgLenWidth; + + if (PkgLen =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Compute the PkgLenWidth. + PkgLenWidth =3D AmlComputePkgLengthWidth (Length); + if (PkgLenWidth =3D=3D 0) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Add it to the Length. + Length +=3D PkgLenWidth; + + // Check that adding the PkgLenWidth didn't trigger a domino effect, + // increasing the encoding width of the PkgLen again. + // The PkgLen is encoded in at most 4 bytes. It is possible to increase + // the PkgLen width if its encoding is less than 3 bytes. + ReComputedPkgLenWidth =3D AmlComputePkgLengthWidth (Length); + if (ReComputedPkgLenWidth !=3D PkgLenWidth) { + if ((ReComputedPkgLenWidth !=3D 0) && + (ReComputedPkgLenWidth < 4)) { + // No need to recompute the PkgLen since a new threshold cannot + // be reached by incrementing the value by one. + Length +=3D 1; + } else { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } + + *PkgLen =3D Length; + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.h b/Dyn= amicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.h index 35c0680b6159..0641500fcd5f 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.h +++ b/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.h @@ -2,7 +2,7 @@ AML grammar definitions. =20 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
- Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -326,5 +326,50 @@ AmlComputePkgLengthWidth ( IN UINT32 Length ); =20 +/** Given a length, compute the value of a PkgLen. + + In AML, some object have a PkgLen, telling the size of the AML object. + It can be encoded in 1 to 4 bytes. The bytes used to encode the PkgLen is + itself counted in the PkgLen value. + This means that if an AML object sees its size increment/decrement, + the number of bytes used to encode the PkgLen value can itself + increment/decrement. + + For instance, the AML encoding of a DeviceOp is: + DefDevice :=3D DeviceOp PkgLength NameString TermList + If: + - sizeof (NameString) =3D 4 (the name is "DEV0" for instance); + - sizeof (TermList) =3D (2^6-6) + then the PkgLen is encoded on 1 byte. Indeed, its value is: + sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) =3D + sizeof (PkgLen) + 4 + (2^6-6) + So: + PkgLen =3D sizeof (PkgLen) + (2^6-2) + + The input arguments Length and PkgLen represent, for the DefDevice: + DefDevice :=3D DeviceOp PkgLength NameString TermList + |------Length-----| + |--------*PgkLength---------| + + @param [in] Length The length to encode as a PkgLen. + Length cannot exceed 2^28 - 4 (4 bytes for the + PkgLen encoding). + The size of the PkgLen encoding bytes should not be + counted in this length value. + @param [out] PkgLen If success, contains the value of the PkgLen, + ready to encode in the PkgLen format. + This value takes into account the size of PkgLen + encoding. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlComputePkgLength ( + IN UINT32 Length, + OUT UINT32 * PkgLen + ); + #endif // AML_H_ =20 --=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 (#76946): https://edk2.groups.io/g/devel/message/76946 Mute This Topic: https://groups.io/mt/83735655/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-