[edk2-devel] [PATCH v1 04/13] DynamicTablesPkg: AML code generation for a Package

PierreGondois posted 13 patches 4 years, 7 months ago
There is a newer version of this series
[edk2-devel] [PATCH v1 04/13] DynamicTablesPkg: AML code generation for a Package
Posted by PierreGondois 4 years, 7 months ago
From: Pierre Gondois <Pierre.Gondois@arm.com>

Add AmlCodeGenPackage() to generate AML code for declaring
a Package() object. This function generates an empty package
node. New elements can then be added to the package's variable
argument list.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
 .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 82 ++++++++++++++++++-
 1 file changed, 81 insertions(+), 1 deletion(-)

diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
index 5d310f201319..ea9b73b464a4 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
@@ -1,7 +1,7 @@
 /** @file
   AML Code Generation.
 
-  Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
+  Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
@@ -235,6 +235,86 @@ AmlCodeGenInteger (
   return Status;
 }
 
+/** AML code generation for a Package object node.
+
+  The package generated is empty. New elements can be added via its
+  list of variable arguments.
+
+  @param [out] NewObjectNode   If success, contains the created
+                               Package object node.
+
+  @retval EFI_SUCCESS             Success.
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AmlCodeGenPackage (
+  OUT AML_OBJECT_NODE    ** NewObjectNode
+  )
+{
+  EFI_STATUS        Status;
+  AML_DATA_NODE   * DataNode;
+  UINT8             NodeCount;
+
+  if (NewObjectNode == NULL) {
+    ASSERT (0);
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DataNode = NULL;
+  NodeCount = 0;
+
+  // Create an object node.
+  // PkgLen is 2:
+  //  - one byte to store the PkgLength
+  //  - one byte for the NumElements.
+  // Cf ACPI6.3, s20.2.5 "Term Objects Encoding"
+  // DefPackage  := PackageOp PkgLength NumElements PackageElementList
+  // NumElements := ByteData
+  Status = AmlCreateObjectNode (
+             AmlGetByteEncodingByOpCode (AML_PACKAGE_OP, 0),
+             2,
+             NewObjectNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT (0);
+    return Status;
+  }
+
+  // NumElements is a ByteData.
+  Status = AmlCreateDataNode (
+             EAmlNodeDataTypeUInt,
+             &NodeCount,
+             sizeof (NodeCount),
+             &DataNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT (0);
+    goto error_handler;
+  }
+
+  Status = AmlSetFixedArgument (
+             *NewObjectNode,
+             EAmlParseIndexTerm0,
+             (AML_NODE_HEADER*)DataNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT (0);
+    goto error_handler;
+  }
+
+  return Status;
+
+error_handler:
+  AmlDeleteTree ((AML_NODE_HEADER*)*NewObjectNode);
+  if (DataNode != NULL) {
+    AmlDeleteTree ((AML_NODE_HEADER*)DataNode);
+  }
+  return Status;
+}
+
 /** AML code generation for a Name object node.
 
   @param  [in] NameString     The new variable name.
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#76945): https://edk2.groups.io/g/devel/message/76945
Mute This Topic: https://groups.io/mt/83735653/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v1 04/13] DynamicTablesPkg: AML code generation for a Package
Posted by Sami Mujawar 4 years, 4 months ago
Hi Pierre,

Thank you for this patch. 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>
>
> Add AmlCodeGenPackage() to generate AML code for declaring
> a Package() object. This function generates an empty package
> node. New elements can then be added to the package's variable
> argument list.
>
> Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
> ---
>   .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 82 ++++++++++++++++++-
>   1 file changed, 81 insertions(+), 1 deletion(-)
>
> diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> index 5d310f201319..ea9b73b464a4 100644
> --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> @@ -1,7 +1,7 @@
>   /** @file
>     AML Code Generation.
>   
> -  Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
> +  Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
>   
>     SPDX-License-Identifier: BSD-2-Clause-Patent
>   **/
> @@ -235,6 +235,86 @@ AmlCodeGenInteger (
>     return Status;
>   }
>   
> +/** AML code generation for a Package object node.
> +
> +  The package generated is empty. New elements can be added via its
> +  list of variable arguments.
> +
> +  @param [out] NewObjectNode   If success, contains the created
> +                               Package object node.
> +
> +  @retval EFI_SUCCESS             Success.
> +  @retval EFI_INVALID_PARAMETER   Invalid parameter.
> +  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
> +**/
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +AmlCodeGenPackage (
> +  OUT AML_OBJECT_NODE    ** NewObjectNode
> +  )
> +{
> +  EFI_STATUS        Status;
> +  AML_DATA_NODE   * DataNode;
> +  UINT8             NodeCount;
> +
> +  if (NewObjectNode == NULL) {
> +    ASSERT (0);
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  DataNode = NULL;
> +  NodeCount = 0;
> +
> +  // Create an object node.
> +  // PkgLen is 2:
> +  //  - one byte to store the PkgLength
> +  //  - one byte for the NumElements.
> +  // Cf ACPI6.3, s20.2.5 "Term Objects Encoding"
> +  // DefPackage  := PackageOp PkgLength NumElements PackageElementList
> +  // NumElements := ByteData
> +  Status = AmlCreateObjectNode (
> +             AmlGetByteEncodingByOpCode (AML_PACKAGE_OP, 0),
> +             2,
> +             NewObjectNode
> +             );
> +  if (EFI_ERROR (Status)) {
> +    ASSERT (0);
> +    return Status;
> +  }
> +
> +  // NumElements is a ByteData.
> +  Status = AmlCreateDataNode (
> +             EAmlNodeDataTypeUInt,
> +             &NodeCount,
> +             sizeof (NodeCount),
> +             &DataNode
> +             );
> +  if (EFI_ERROR (Status)) {
> +    ASSERT (0);
> +    goto error_handler;
> +  }
> +
> +  Status = AmlSetFixedArgument (
> +             *NewObjectNode,
> +             EAmlParseIndexTerm0,
> +             (AML_NODE_HEADER*)DataNode
> +             );
> +  if (EFI_ERROR (Status)) {
> +    ASSERT (0);
> +    goto error_handler;
> +  }
> +
> +  return Status;
> +
> +error_handler:
> +  AmlDeleteTree ((AML_NODE_HEADER*)*NewObjectNode);
> +  if (DataNode != NULL) {
> +    AmlDeleteTree ((AML_NODE_HEADER*)DataNode);
> +  }
> +  return Status;
> +}
> +
>   /** AML code generation for a Name object node.
>   
>     @param  [in] NameString     The new variable name.



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81362): https://edk2.groups.io/g/devel/message/81362
Mute This Topic: https://groups.io/mt/83735653/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-