public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abdul Lateef Attar via groups.io" <AbdulLateef.Attar=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>,
	Pierre Gondois <pierre.gondois@arm.com>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Adds API to generate a method with ArgN
Date: Mon, 11 Dec 2023 16:07:32 +0530	[thread overview]
Message-ID: <c4bfb4817bf8c5f1e5f6406c2ede9de6612b3a86.1702290369.git.AbdulLateef.Attar@amd.com> (raw)
In-Reply-To: <cover.1702290369.git.AbdulLateef.Attar@amd.com>

From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>

Adds an API to generate a method which invokes another
method with arguments.
This help to generate dynamic code to invoke another
method(might be in static ASL file) with build-in
argument parameters.

e.g:
Method (MET0, 6, Serialized)
{
  \_SB.MET1 (Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)
}

Cc: Pierre Gondois <pierre.gondois@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
 .../Include/Library/AmlLib/AmlLib.h           |  46 ++++++
 .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 152 ++++++++++++++++++
 2 files changed, 198 insertions(+)

diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
index eb8740692f..5ab205b5f0 100644
--- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
+++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
@@ -1693,4 +1693,50 @@ AmlAddNameStringToNamedPackage (
   IN AML_OBJECT_NODE_HANDLE  NamedNode
   );
 
+/** AML code generation for a method invoking another method
+    with ArgN arguments.
+
+  AmlCodeGenMethodInvokeMethodArgn (
+    "MET0", "MET1", 4, TRUE, 3, ParentNode, NewObjectNode
+    );
+  is equivalent of the following ASL code:
+    Method(MET0, 4, Serialized, 3) {
+      MET1 (Arg0, Arg1, Arg2, Arg3)
+    }
+
+  @param [in]  MethodNameString       The new Method's name.
+                                      Must be a NULL-terminated ASL NameString
+                                      e.g.: "MET0", "_SB.MET0", etc.
+                                      The input string is copied.
+  @param [in]  InvokeMethodNameString The called/invoked method's name.
+                                      Must be a NULL-terminated ASL NameString
+                                      e.g.: "MET1", "_SB.MET1", etc.
+                                      The input string is copied.
+  @param [in]  NumArgs                Number of arguments.
+                                      Must be 0 <= NumArgs <= 6.
+  @param [in]  IsSerialized           TRUE is equivalent to Serialized.
+                                      FALSE is equivalent to NotSerialized.
+                                      Default is NotSerialized in ASL spec.
+  @param [in]  SyncLevel              Synchronization level for the method.
+                                      Must be 0 <= SyncLevel <= 15.
+                                      Default is 0 in ASL.
+  @param [in]  ParentNode             If provided, set ParentNode as the parent
+                                      of the node created.
+  @param [out] NewObjectNode          If success, contains the created node.
+
+  @retval EFI_SUCCESS             Success.
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenMethodInvokeMethodArgn (
+  IN  CONST CHAR8                   *MethodNameString,
+  IN  CONST CHAR8                   *InvokeMethodNameString,
+  IN        UINT8                   NumArgs,
+  IN        BOOLEAN                 IsSerialized,
+  IN        UINT8                   SyncLevel,
+  IN        AML_NODE_HANDLE         ParentNode           OPTIONAL,
+  OUT       AML_OBJECT_NODE_HANDLE  *NewObjectNode       OPTIONAL
+  );
+
 #endif // AML_LIB_H_
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
index a6db34fb97..b05fa6d109 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
@@ -3849,3 +3849,155 @@ exit_handler:
 
   return Status;
 }
+
+/** AML code generation for a method invoking another method
+    with ArgN arguments.
+
+  AmlCodeGenMethodInvokeMethodArgn (
+    "MET0", "MET1", 4, TRUE, 3, ParentNode, NewObjectNode
+    );
+  is equivalent of the following ASL code:
+    Method(MET0, 4, Serialized, 3) {
+      MET1 (Arg0, Arg1, Arg2, Arg3)
+    }
+
+  @param [in]  MethodNameString       The new Method's name.
+                                      Must be a NULL-terminated ASL NameString
+                                      e.g.: "MET0", "_SB.MET0", etc.
+                                      The input string is copied.
+  @param [in]  InvokeMethodNameString The called/invoked method's name.
+                                      Must be a NULL-terminated ASL NameString
+                                      e.g.: "MET1", "_SB.MET1", etc.
+                                      The input string is copied.
+  @param [in]  NumArgs                Number of arguments.
+                                      Must be 0 <= NumArgs <= 6.
+  @param [in]  IsSerialized           TRUE is equivalent to Serialized.
+                                      FALSE is equivalent to NotSerialized.
+                                      Default is NotSerialized in ASL spec.
+  @param [in]  SyncLevel              Synchronization level for the method.
+                                      Must be 0 <= SyncLevel <= 15.
+                                      Default is 0 in ASL.
+  @param [in]  ParentNode             If provided, set ParentNode as the parent
+                                      of the node created.
+  @param [out] NewObjectNode          If success, contains the created node.
+
+  @retval EFI_SUCCESS             Success.
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenMethodInvokeMethodArgn (
+  IN  CONST CHAR8                   *MethodNameString,
+  IN  CONST CHAR8                   *InvokeMethodNameString,
+  IN        UINT8                   NumArgs,
+  IN        BOOLEAN                 IsSerialized,
+  IN        UINT8                   SyncLevel,
+  IN        AML_NODE_HANDLE         ParentNode           OPTIONAL,
+  OUT       AML_OBJECT_NODE_HANDLE  *NewObjectNode        OPTIONAL
+  )
+{
+  EFI_STATUS              Status;
+  AML_OBJECT_NODE_HANDLE  MethodNode;
+  AML_DATA_NODE           *DataNode;
+  AML_OBJECT_NODE         *ObjectNode;
+  CHAR8                   *AmlNameString;
+  UINT32                  AmlNameStringSize;
+  UINT8                   ArgnCount;
+
+  if ((MethodNameString == NULL) || (InvokeMethodNameString == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  // Create a Method named MethodNameString
+  Status = AmlCodeGenMethod (
+             MethodNameString,
+             NumArgs,
+             IsSerialized,
+             SyncLevel,
+             NULL,
+             &MethodNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return Status;
+  }
+
+  DataNode = NULL;
+  Status   = ConvertAslNameToAmlName (InvokeMethodNameString, &AmlNameString);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    goto exit_handler;
+  }
+
+  Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    FreePool (AmlNameString);
+    goto exit_handler;
+  }
+
+  Status = AmlCreateDataNode (
+             EAmlNodeDataTypeNameString,
+             (UINT8 *)AmlNameString,
+             AmlNameStringSize,
+             &DataNode
+             );
+  FreePool (AmlNameString);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    goto exit_handler;
+  }
+
+  Status = AmlVarListAddTail (
+             (AML_NODE_HEADER *)MethodNode,
+             (AML_NODE_HEADER *)DataNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    goto exit_handler;
+  }
+
+  DataNode = NULL;
+
+  for (ArgnCount = 0; ArgnCount < NumArgs; ArgnCount++) {
+    Status = AmlCreateObjectNode (
+               AmlGetByteEncodingByOpCode (AML_ARG0 + ArgnCount, 0),
+               0,
+               &ObjectNode
+               );
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      goto exit_handler;
+    }
+
+    Status = AmlVarListAddTail (
+               (AML_NODE_HEADER *)MethodNode,
+               (AML_NODE_HEADER *)ObjectNode
+               );
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      goto exit_handler;
+    }
+
+    ObjectNode = NULL;
+  }
+
+  Status = LinkNode (
+             MethodNode,
+             ParentNode,
+             NewObjectNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    goto exit_handler;
+  }
+
+  return Status;
+
+exit_handler:
+  if (MethodNode != NULL) {
+    AmlDeleteTree ((AML_NODE_HANDLE)MethodNode);
+  }
+
+  return Status;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112286): https://edk2.groups.io/g/devel/message/112286
Mute This Topic: https://groups.io/mt/103106350/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-12-11 10:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 10:37 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Updated word I/O Abdul Lateef Attar via groups.io
2023-12-11 10:37 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: AML Code generation for word I/O ranges Abdul Lateef Attar via groups.io
2023-12-11 10:37 ` [edk2-devel] [PATCH v3 2/5] DynamicTablesPkg: Corrects AmlCodeGenRdWordBusNumber parameters Abdul Lateef Attar via groups.io
2023-12-11 10:37 ` [edk2-devel] [PATCH v3 3/5] DynamicTablesPkg: Corrects function pointer typedef of AML_PARSE_FUNCTION Abdul Lateef Attar via groups.io
2023-12-11 10:37 ` Abdul Lateef Attar via groups.io [this message]
2023-12-11 14:26   ` [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Adds API to generate a method with ArgN PierreGondois
2023-12-14  4:13     ` Abdul Lateef Attar via groups.io
2023-12-11 10:37 ` [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Adds wrapper API AmlCodeGenMethodInvokeMethodArgn Abdul Lateef Attar via groups.io

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=c4bfb4817bf8c5f1e5f6406c2ede9de6612b3a86.1702290369.git.AbdulLateef.Attar@amd.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