public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: Pierre.Gondois@arm.com, devel@edk2.groups.io,
	Alexei Fedorov <Alexei.Fedorov@arm.com>
Cc: Akanksha Jain <akanksha.jain2@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>, nd <nd@arm.com>
Subject: Re: [PATCH v1 05/13] DynamicTablesPkg: Helper function to compute package length
Date: Fri, 1 Oct 2021 15:24:05 +0100	[thread overview]
Message-ID: <5dfb42ef-a5f3-6613-b9ba-bcfa96f8c876@arm.com> (raw)
In-Reply-To: <20210623114039.24491-6-Pierre.Gondois@arm.com>

  Hi Pierre,

This patch looks good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar


On 23/06/2021 12:40 PM, Pierre.Gondois@arm.com wrote:
> From: Pierre Gondois <Pierre.Gondois@arm.com>
>
> 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 <Pierre.Gondois@arm.com>
> ---
>   .../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/DynamicTablesPkg/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.
>   
>     Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
> -  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
> +  Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
>   
>     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 := DeviceOp PkgLength NameString TermList
> +  If:
> +   - sizeof (NameString) = 4 (the name is "DEV0" for instance);
> +   - sizeof (TermList) = (2^6-6)
> +  then the PkgLen is encoded on 1 byte. Indeed, its value is:
> +    sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) =
> +    sizeof (PkgLen) + 4 + (2^6-6)
> +  So:
> +    PkgLen = sizeof (PkgLen) + (2^6-2)
> +
> +  The input arguments Length and PkgLen represent, for the DefDevice:
> +    DefDevice := 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 == NULL) {
> +    ASSERT (0);
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  // Compute the PkgLenWidth.
> +  PkgLenWidth = AmlComputePkgLengthWidth (Length);
> +  if (PkgLenWidth == 0) {
> +    ASSERT (0);
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  // Add it to the Length.
> +  Length += 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 = AmlComputePkgLengthWidth (Length);
> +  if (ReComputedPkgLenWidth != PkgLenWidth) {
> +    if ((ReComputedPkgLenWidth != 0)   &&
> +        (ReComputedPkgLenWidth < 4)) {
> +      // No need to recompute the PkgLen since a new threshold cannot
> +      // be reached by incrementing the value by one.
> +      Length += 1;
> +    } else {
> +      ASSERT (0);
> +      return EFI_INVALID_PARAMETER;
> +    }
> +  }
> +
> +  *PkgLen = Length;
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.h b/DynamicTablesPkg/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.
>   
>     Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
> -  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
> +  Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
>   
>     SPDX-License-Identifier: BSD-2-Clause-Patent
>   **/
> @@ -326,5 +326,50 @@ AmlComputePkgLengthWidth (
>     IN  UINT32  Length
>     );
>   
> +/** 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 := DeviceOp PkgLength NameString TermList
> +  If:
> +   - sizeof (NameString) = 4 (the name is "DEV0" for instance);
> +   - sizeof (TermList) = (2^6-6)
> +  then the PkgLen is encoded on 1 byte. Indeed, its value is:
> +    sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) =
> +    sizeof (PkgLen) + 4 + (2^6-6)
> +  So:
> +    PkgLen = sizeof (PkgLen) + (2^6-2)
> +
> +  The input arguments Length and PkgLen represent, for the DefDevice:
> +    DefDevice := 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_
>   


  reply	other threads:[~2021-10-01 14:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 11:40 [PATCH v1 00/13] Create a SSDT CPU topology generator PierreGondois
2021-06-23 11:40 ` [PATCH v1 01/13] DynamicTablesPkg: Make AmlNodeGetIntegerValue public PierreGondois
2021-10-01 14:48   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 02/13] DynamicTablesPkg: AML Code generation for Register() PierreGondois
2021-10-01 12:25   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 03/13] DynamicTablesPkg: AML Code generation for Resource data EndTag PierreGondois
2021-10-01 12:48   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 04/13] DynamicTablesPkg: AML code generation for a Package PierreGondois
2021-10-01 12:55   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 05/13] DynamicTablesPkg: Helper function to compute package length PierreGondois
2021-10-01 14:24   ` Sami Mujawar [this message]
2021-06-23 11:40 ` [PATCH v1 06/13] DynamicTablesPkg: AML code generation for a ResourceTemplate PierreGondois
2021-10-01 14:34   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 07/13] DynamicTablesPkg: AML code generation for a Method PierreGondois
2021-10-01 14:52   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 08/13] DynamicTablesPkg: AML code generation to Return a NameString PierreGondois
2021-10-01 15:13   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 09/13] DynamicTablesPkg: AML code generation for a Method returning a NS PierreGondois
2021-10-01 15:23   ` Sami Mujawar
2021-10-06 13:33     ` PierreGondois
2021-06-23 11:40 ` [PATCH v1 09/13] DynamicTablesPkg: AML code generation to create " PierreGondois
2021-06-23 11:45   ` [edk2-devel] " PierreGondois
2021-06-23 11:40 ` [PATCH v1 10/13] DynamicTablesPkg: AML code generation for a _LPI object PierreGondois
2021-10-01 15:31   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 11/13] DynamicTablesPkg: AML code generation to add an _LPI state PierreGondois
2021-10-01 15:43   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 12/13] DynamicTablesPkg: Add CM_ARM_LPI_INFO object PierreGondois
2021-10-05 14:39   ` Sami Mujawar
2021-06-23 11:40 ` [PATCH v1 13/13] DynamicTablesPkg: SSDT CPU topology and LPI state generator PierreGondois
2021-10-05 14:38   ` Sami Mujawar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5dfb42ef-a5f3-6613-b9ba-bcfa96f8c876@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox