[edk2-devel] [PATCH v4 3/4] DynamicTablesPkg: Add support to add Strings to package

Jeff Brasen via groups.io posted 4 patches 5 months, 1 week ago
[edk2-devel] [PATCH v4 3/4] DynamicTablesPkg: Add support to add Strings to package
Posted by Jeff Brasen via groups.io 5 months, 1 week ago
Add API to add a String to a package created with NamedPackage API.



Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>

---

 .../Include/Library/AmlLib/AmlLib.h           | 17 ++++

 .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 88 +++++++++++++++++++

 2 files changed, 105 insertions(+)



diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h

index b82c7a3ce8..f4a4908753 100644

--- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h

+++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h

@@ -1472,4 +1472,21 @@ AmlCreateCpcNode (

   OUT AML_OBJECT_NODE_HANDLE  *NewCpcNode   OPTIONAL

   );

 

+/** AML code generation to add a NameString to the package in a named node.

+

+

+  @param [in]  NameString     NameString to add

+  @param [in]  NamedNode      Node to add the string to the included package.

+

+  @retval EFI_SUCCESS             Success.

+  @retval EFI_INVALID_PARAMETER   Invalid parameter.

+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.

+**/

+EFI_STATUS

+EFIAPI

+AmlAddNameStringToNamedPackage (

+  IN CHAR8                   *NameString,

+  IN AML_OBJECT_NODE_HANDLE  NamedNode

+  );

+

 #endif // AML_LIB_H_

diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c

index ea519d1aa8..2afd405750 100644

--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c

+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c

@@ -3685,3 +3685,91 @@ error_handler:

   AmlDeleteTree ((AML_NODE_HANDLE)CpcNode);

   return Status;

 }

+

+/** AML code generation to add a NameString to the package in a named node.

+

+

+  @param [in]  NameString     NameString to add

+  @param [in]  NamedNode      Node to add the string to the included package.

+

+  @retval EFI_SUCCESS             Success.

+  @retval EFI_INVALID_PARAMETER   Invalid parameter.

+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.

+**/

+EFI_STATUS

+EFIAPI

+AmlAddNameStringToNamedPackage (

+  IN CHAR8                   *NameString,

+  IN AML_OBJECT_NODE_HANDLE  NamedNode

+  )

+{

+  EFI_STATUS              Status;

+  AML_DATA_NODE           *DataNode;

+  CHAR8                   *AmlNameString;

+  UINT32                  AmlNameStringSize;

+  AML_OBJECT_NODE_HANDLE  PackageNode;

+

+  DataNode = NULL;

+

+  if ((NamedNode == NULL)                                              ||

+      (AmlGetNodeType ((AML_NODE_HANDLE)NamedNode) != EAmlNodeObject)  ||

+      (!AmlNodeHasOpCode (NamedNode, AML_NAME_OP, 0)))

+  {

+    ASSERT (0);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  PackageNode = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (

+                                          NamedNode,

+                                          EAmlParseIndexTerm1

+                                          );

+  if ((PackageNode == NULL)                                             ||

+      (AmlGetNodeType ((AML_NODE_HANDLE)PackageNode) != EAmlNodeObject) ||

+      (!AmlNodeHasOpCode (PackageNode, AML_PACKAGE_OP, 0)))

+  {

+    ASSERT (0);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = ConvertAslNameToAmlName (NameString, &AmlNameString);

+  if (EFI_ERROR (Status)) {

+    ASSERT (0);

+    return Status;

+  }

+

+  Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize);

+  if (EFI_ERROR (Status)) {

+    ASSERT (0);

+    goto exit_handler;

+  }

+

+  Status = AmlCreateDataNode (

+             EAmlNodeDataTypeNameString,

+             (UINT8 *)AmlNameString,

+             AmlNameStringSize,

+             &DataNode

+             );

+  if (EFI_ERROR (Status)) {

+    ASSERT (0);

+    goto exit_handler;

+  }

+

+  Status = AmlVarListAddTail (

+             (AML_NODE_HANDLE)PackageNode,

+             (AML_NODE_HANDLE)DataNode

+             );

+  ASSERT_EFI_ERROR (Status);

+

+exit_handler:

+  if (AmlNameString != NULL) {

+    FreePool (AmlNameString);

+  }

+

+  if (EFI_ERROR (Status)) {

+    if (DataNode != NULL) {

+      AmlDeleteTree ((AML_NODE_HANDLE)DataNode);

+    }

+  }

+

+  return Status;

+}

-- 

2.25.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108802): https://edk2.groups.io/g/devel/message/108802
Mute This Topic: https://groups.io/mt/101436338/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v4 3/4] DynamicTablesPkg: Add support to add Strings to package
Posted by Sami Mujawar 5 months ago
Hi Jeff,

Thank you for this patch.

Please see my response inline marked [SAMI].

Regards,

Sami Mujawar

On 18/09/2023 04:46 pm, Jeff Brasen wrote:
> Add API to add a String to a package created with NamedPackage API.
>
>
>
> Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
>
> ---
>
>   .../Include/Library/AmlLib/AmlLib.h           | 17 ++++
>
>   .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 88 +++++++++++++++++++
>
>   2 files changed, 105 insertions(+)
>
>
>
> diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
>
> index b82c7a3ce8..f4a4908753 100644
>
> --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
>
> +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
>
> @@ -1472,4 +1472,21 @@ AmlCreateCpcNode (
>
>     OUT AML_OBJECT_NODE_HANDLE  *NewCpcNode   OPTIONAL
>
>     );
>
>   
>
> +/** AML code generation to add a NameString to the package in a named node.
>
> +
>
> +
>
> +  @param [in]  NameString     NameString to add
>
> +  @param [in]  NamedNode      Node to add the string to the included package.
>
> +
>
> +  @retval EFI_SUCCESS             Success.
>
> +  @retval EFI_INVALID_PARAMETER   Invalid parameter.
>
> +  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
>
> +**/
>
> +EFI_STATUS
>
> +EFIAPI
>
> +AmlAddNameStringToNamedPackage (
>
> +  IN CHAR8                   *NameString,
>
> +  IN AML_OBJECT_NODE_HANDLE  NamedNode
>
> +  );
>
> +
>
>   #endif // AML_LIB_H_
>
> diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
>
> index ea519d1aa8..2afd405750 100644
>
> --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
>
> +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
>
> @@ -3685,3 +3685,91 @@ error_handler:
>
>     AmlDeleteTree ((AML_NODE_HANDLE)CpcNode);
>
>     return Status;
>
>   }
>
> +
>
> +/** AML code generation to add a NameString to the package in a named node.
>
> +
>
> +
>
> +  @param [in]  NameString     NameString to add
>
> +  @param [in]  NamedNode      Node to add the string to the included package.
>
> +
>
> +  @retval EFI_SUCCESS             Success.
>
> +  @retval EFI_INVALID_PARAMETER   Invalid parameter.
>
> +  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
>
> +**/
>
> +EFI_STATUS
>
> +EFIAPI
>
> +AmlAddNameStringToNamedPackage (
>
> +  IN CHAR8                   *NameString,
>
> +  IN AML_OBJECT_NODE_HANDLE  NamedNode
>
> +  )
>
> +{
>
> +  EFI_STATUS              Status;
>
> +  AML_DATA_NODE           *DataNode;
>
> +  CHAR8                   *AmlNameString;
>
> +  UINT32                  AmlNameStringSize;
>
> +  AML_OBJECT_NODE_HANDLE  PackageNode;
>
> +
>
> +  DataNode = NULL;
>
> +
>
> +  if ((NamedNode == NULL)                                              ||
>
> +      (AmlGetNodeType ((AML_NODE_HANDLE)NamedNode) != EAmlNodeObject)  ||
>
> +      (!AmlNodeHasOpCode (NamedNode, AML_NAME_OP, 0)))
>
> +  {
>
> +    ASSERT (0);
>
> +    return EFI_INVALID_PARAMETER;
>
> +  }
>
> +
>
> +  PackageNode = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (
>
> +                                          NamedNode,
>
> +                                          EAmlParseIndexTerm1
>
> +                                          );
>
> +  if ((PackageNode == NULL)                                             ||
>
> +      (AmlGetNodeType ((AML_NODE_HANDLE)PackageNode) != EAmlNodeObject) ||
>
> +      (!AmlNodeHasOpCode (PackageNode, AML_PACKAGE_OP, 0)))
>
> +  {
>
> +    ASSERT (0);
>
> +    return EFI_INVALID_PARAMETER;
>
> +  }
>
> +
>
> +  Status = ConvertAslNameToAmlName (NameString, &AmlNameString);
>
> +  if (EFI_ERROR (Status)) {
>
> +    ASSERT (0);
>
> +    return Status;
>
> +  }
>
> +
>
> +  Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize);
>
> +  if (EFI_ERROR (Status)) {
>
> +    ASSERT (0);
>
> +    goto exit_handler;
>
> +  }
>
> +
>
> +  Status = AmlCreateDataNode (
>
> +             EAmlNodeDataTypeNameString,
>
> +             (UINT8 *)AmlNameString,
>
> +             AmlNameStringSize,
>
> +             &DataNode
>
> +             );
>
> +  if (EFI_ERROR (Status)) {
>
> +    ASSERT (0);
>
> +    goto exit_handler;
>
> +  }
>
> +
>
> +  Status = AmlVarListAddTail (
>
> +             (AML_NODE_HANDLE)PackageNode,
>
> +             (AML_NODE_HANDLE)DataNode
>
> +             );
>
> +  ASSERT_EFI_ERROR (Status);
>
> +
>
> +exit_handler:
>
> +  if (AmlNameString != NULL) {
>
> +    FreePool (AmlNameString);
>
> +  }
>
> +
[SAMI] I think the error handling code below can be moved after 
AmlVarListAddTail() above and ASSERT_EFI_ERROR() can me removed. If you 
agree, I will make this change before merging the series.
>
> +  if (EFI_ERROR (Status)) {
>
> +    if (DataNode != NULL) {
>
> +      AmlDeleteTree ((AML_NODE_HANDLE)DataNode);
>
> +    }
>
> +  }
>
> +
>
> +  return Status;
>
> +}
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108956): https://edk2.groups.io/g/devel/message/108956
Mute This Topic: https://groups.io/mt/101436338/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v4 3/4] DynamicTablesPkg: Add support to add Strings to package
Posted by Jeff Brasen via groups.io 5 months ago
Hi Sami,

  That sounds good.

Thanks,
Jeff

> -----Original Message-----
> From: Sami Mujawar <sami.mujawar@arm.com>
> Sent: Thursday, September 21, 2023 10:50 AM
> To: Jeff Brasen <jbrasen@nvidia.com>; devel@edk2.groups.io
> Cc: pierre.gondois@arm.com; Swatisri Kantamsetti <swatisrik@nvidia.com>;
> Ashish Singhal <ashishsingha@nvidia.com>; nd@arm.com
> Subject: Re: [PATCH v4 3/4] DynamicTablesPkg: Add support to add Strings to
> package
> 
> External email: Use caution opening links or attachments
> 
> 
> Hi Jeff,
> 
> Thank you for this patch.
> 
> Please see my response inline marked [SAMI].
> 
> Regards,
> 
> Sami Mujawar
> 
> On 18/09/2023 04:46 pm, Jeff Brasen wrote:
> > Add API to add a String to a package created with NamedPackage API.
> >
> >
> >
> > Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
> >
> > ---
> >
> >   .../Include/Library/AmlLib/AmlLib.h           | 17 ++++
> >
> >   .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 88
> +++++++++++++++++++
> >
> >   2 files changed, 105 insertions(+)
> >
> >
> >
> > diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
> > b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
> >
> > index b82c7a3ce8..f4a4908753 100644
> >
> > --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
> >
> > +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
> >
> > @@ -1472,4 +1472,21 @@ AmlCreateCpcNode (
> >
> >     OUT AML_OBJECT_NODE_HANDLE  *NewCpcNode   OPTIONAL
> >
> >     );
> >
> >
> >
> > +/** AML code generation to add a NameString to the package in a named
> node.
> >
> > +
> >
> > +
> >
> > +  @param [in]  NameString     NameString to add
> >
> > +  @param [in]  NamedNode      Node to add the string to the included
> package.
> >
> > +
> >
> > +  @retval EFI_SUCCESS             Success.
> >
> > +  @retval EFI_INVALID_PARAMETER   Invalid parameter.
> >
> > +  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
> >
> > +**/
> >
> > +EFI_STATUS
> >
> > +EFIAPI
> >
> > +AmlAddNameStringToNamedPackage (
> >
> > +  IN CHAR8                   *NameString,
> >
> > +  IN AML_OBJECT_NODE_HANDLE  NamedNode
> >
> > +  );
> >
> > +
> >
> >   #endif // AML_LIB_H_
> >
> > diff --git
> > a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> > b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> >
> > index ea519d1aa8..2afd405750 100644
> >
> > ---
> a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> >
> > +++
> b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
> >
> > @@ -3685,3 +3685,91 @@ error_handler:
> >
> >     AmlDeleteTree ((AML_NODE_HANDLE)CpcNode);
> >
> >     return Status;
> >
> >   }
> >
> > +
> >
> > +/** AML code generation to add a NameString to the package in a named
> node.
> >
> > +
> >
> > +
> >
> > +  @param [in]  NameString     NameString to add
> >
> > +  @param [in]  NamedNode      Node to add the string to the included
> package.
> >
> > +
> >
> > +  @retval EFI_SUCCESS             Success.
> >
> > +  @retval EFI_INVALID_PARAMETER   Invalid parameter.
> >
> > +  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.
> >
> > +**/
> >
> > +EFI_STATUS
> >
> > +EFIAPI
> >
> > +AmlAddNameStringToNamedPackage (
> >
> > +  IN CHAR8                   *NameString,
> >
> > +  IN AML_OBJECT_NODE_HANDLE  NamedNode
> >
> > +  )
> >
> > +{
> >
> > +  EFI_STATUS              Status;
> >
> > +  AML_DATA_NODE           *DataNode;
> >
> > +  CHAR8                   *AmlNameString;
> >
> > +  UINT32                  AmlNameStringSize;
> >
> > +  AML_OBJECT_NODE_HANDLE  PackageNode;
> >
> > +
> >
> > +  DataNode = NULL;
> >
> > +
> >
> > +  if ((NamedNode == NULL)                                              ||
> >
> > +      (AmlGetNodeType ((AML_NODE_HANDLE)NamedNode) !=
> EAmlNodeObject)
> > + ||
> >
> > +      (!AmlNodeHasOpCode (NamedNode, AML_NAME_OP, 0)))
> >
> > +  {
> >
> > +    ASSERT (0);
> >
> > +    return EFI_INVALID_PARAMETER;
> >
> > +  }
> >
> > +
> >
> > +  PackageNode = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (
> >
> > +                                          NamedNode,
> >
> > +                                          EAmlParseIndexTerm1
> >
> > +                                          );
> >
> > +  if ((PackageNode == NULL)                                             ||
> >
> > +      (AmlGetNodeType ((AML_NODE_HANDLE)PackageNode) !=
> > + EAmlNodeObject) ||
> >
> > +      (!AmlNodeHasOpCode (PackageNode, AML_PACKAGE_OP, 0)))
> >
> > +  {
> >
> > +    ASSERT (0);
> >
> > +    return EFI_INVALID_PARAMETER;
> >
> > +  }
> >
> > +
> >
> > +  Status = ConvertAslNameToAmlName (NameString, &AmlNameString);
> >
> > +  if (EFI_ERROR (Status)) {
> >
> > +    ASSERT (0);
> >
> > +    return Status;
> >
> > +  }
> >
> > +
> >
> > +  Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize);
> >
> > +  if (EFI_ERROR (Status)) {
> >
> > +    ASSERT (0);
> >
> > +    goto exit_handler;
> >
> > +  }
> >
> > +
> >
> > +  Status = AmlCreateDataNode (
> >
> > +             EAmlNodeDataTypeNameString,
> >
> > +             (UINT8 *)AmlNameString,
> >
> > +             AmlNameStringSize,
> >
> > +             &DataNode
> >
> > +             );
> >
> > +  if (EFI_ERROR (Status)) {
> >
> > +    ASSERT (0);
> >
> > +    goto exit_handler;
> >
> > +  }
> >
> > +
> >
> > +  Status = AmlVarListAddTail (
> >
> > +             (AML_NODE_HANDLE)PackageNode,
> >
> > +             (AML_NODE_HANDLE)DataNode
> >
> > +             );
> >
> > +  ASSERT_EFI_ERROR (Status);
> >
> > +
> >
> > +exit_handler:
> >
> > +  if (AmlNameString != NULL) {
> >
> > +    FreePool (AmlNameString);
> >
> > +  }
> >
> > +
> [SAMI] I think the error handling code below can be moved after
> AmlVarListAddTail() above and ASSERT_EFI_ERROR() can me removed. If you
> agree, I will make this change before merging the series.
> >
[Jeff] That sounds good
> > +  if (EFI_ERROR (Status)) {
> >
> > +    if (DataNode != NULL) {
> >
> > +      AmlDeleteTree ((AML_NODE_HANDLE)DataNode);
> >
> > +    }
> >
> > +  }
> >
> > +
> >
> > +  return Status;
> >
> > +}
> >


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