From: Abdul Lateef Attar <abdullateef.at...@amd.com>

Adds a wrapper API AmlCodeGenMethodInvokeMethodArgnWithInteger() to
the AmlCodeGenMethodInvokeMethodArgn().

Wrapper API provides ability to add integer arguments along
with ArgN argument.
This help to generate dynamic code to invoke another
method(might be in static ASL file) with build-in
argument parameters plus integer arguments.

e.g:
Method (MET0, 3, Serialized)
{
  \_SB.MET1 (Arg0, Arg1, Arg2, 0x10, 0x20))
}

Cc: Pierre Gondois <pierre.gond...@arm.com>
Cc: Sami Mujawar <sami.muja...@arm.com>
Signed-off-by: Abdul Lateef Attar <abdullateef.at...@amd.com>
---
 .../Include/Library/AmlLib/AmlLib.h           |  68 +++++++
 .../Common/AmlLib/CodeGen/AmlCodeGen.c        | 187 ++++++++++++++++++
 2 files changed, 255 insertions(+)

diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h 
b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
index 5ab205b5f0..132846a38a 100644
--- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
+++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
@@ -1739,4 +1739,72 @@ AmlCodeGenMethodInvokeMethodArgn (
   OUT       AML_OBJECT_NODE_HANDLE  *NewObjectNode       OPTIONAL
   );
 
+/** AML code generation for a method invoking another method
+    with ArgN arguments and optionally integer arguments.
+
+  Arg0Int = 0x10;
+  Arg1Int = 0x20;
+  AmlCodeGenMethodInvokeMethodArgnWithInteger (
+    "MET0", "MET1", 4, TRUE, 3,
+    Arg0Int, Arg1Int, NULL, NULL, NULL, NULL,
+    ParentNode, NewObjectNode
+    );
+  is equivalent of the following ASL code:
+    Method(MET0, 4, Serialized, 3) {
+      MET1 (Arg0, Arg1, Arg2, Arg3, 0x10, 0x20)
+    }
+
+  @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]  IntegerArg0          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg1          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg2          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg3          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg4          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg5          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @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
+AmlCodeGenMethodInvokeMethodArgnWithInteger (
+  IN  CONST CHAR8                   *MethodNameString,
+  IN  CONST CHAR8                   *InvokeMethodNameString,
+  IN        UINT8                   NumArgs,
+  IN        BOOLEAN                 IsSerialized,
+  IN        UINT8                   SyncLevel,
+  IN        UINT64                  *IntegerArg0        OPTIONAL,
+  IN        UINT64                  *IntegerArg1        OPTIONAL,
+  IN        UINT64                  *IntegerArg2        OPTIONAL,
+  IN        UINT64                  *IntegerArg3        OPTIONAL,
+  IN        UINT64                  *IntegerArg4        OPTIONAL,
+  IN        UINT64                  *IntegerArg5        OPTIONAL,
+  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 b05fa6d109..b3b01e7baf 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
@@ -4001,3 +4001,190 @@ exit_handler:
 
   return Status;
 }
+
+/** AML code generation for a method invoking another method
+    with ArgN arguments and optionally integer arguments.
+
+  Arg0Int = 0x10;
+  Arg1Int = 0x20;
+  AmlCodeGenMethodInvokeMethodArgnWithInteger (
+    "MET0", "MET1", 4, TRUE, 3,
+    Arg0Int, Arg1Int, NULL, NULL, NULL, NULL,
+    ParentNode, NewObjectNode
+    );
+  is equivalent of the following ASL code:
+    Method(MET0, 4, Serialized, 3) {
+      MET1 (Arg0, Arg1, Arg2, Arg3, 0x10, 0x20)
+    }
+
+  @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]  IntegerArg0          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg1          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg2          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg3          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg4          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @param [in]  IntegerArg5          If provided and meets the validation 
criteria,
+                                    then set as integer argument to invoked 
method.
+  @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
+AmlCodeGenMethodInvokeMethodArgnWithInteger (
+  IN  CONST CHAR8                   *MethodNameString,
+  IN  CONST CHAR8                   *InvokeMethodNameString,
+  IN        UINT8                   NumArgs,
+  IN        BOOLEAN                 IsSerialized,
+  IN        UINT8                   SyncLevel,
+  IN        UINT64                  *IntegerArg0        OPTIONAL,
+  IN        UINT64                  *IntegerArg1        OPTIONAL,
+  IN        UINT64                  *IntegerArg2        OPTIONAL,
+  IN        UINT64                  *IntegerArg3        OPTIONAL,
+  IN        UINT64                  *IntegerArg4        OPTIONAL,
+  IN        UINT64                  *IntegerArg5        OPTIONAL,
+  IN        AML_NODE_HANDLE         ParentNode          OPTIONAL,
+  OUT       AML_OBJECT_NODE_HANDLE  *NewObjectNode      OPTIONAL
+  )
+{
+  EFI_STATUS              Status;
+  AML_OBJECT_NODE_HANDLE  MethodObjectNode;
+  AML_OBJECT_NODE         *IntNode;
+  UINT64                  LocalIntegerArg[6];
+  UINT8                   LocalIntegerArgCount;
+  UINT8                   Index;
+
+  if ((MethodNameString == NULL) || (InvokeMethodNameString == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  /// Sanity check optional argument
+  /// AML library allows max 6 argument
+  /// Hence Integer argument count should be within the range
+  /// (NumArgs + Integer argument) should not be grater than 6
+  LocalIntegerArgCount = 0;
+  if (IntegerArg0 != NULL) {
+    if (NumArgs > 5) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg0;
+  }
+
+  if (IntegerArg1 != NULL) {
+    if (NumArgs > 4) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg1;
+  }
+
+  if (IntegerArg2 != NULL) {
+    if (NumArgs > 3) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg2;
+  }
+
+  if (IntegerArg3 != NULL) {
+    if (NumArgs > 2) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg3;
+  }
+
+  if (IntegerArg4 != NULL) {
+    if (NumArgs > 1) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg4;
+  }
+
+  if (IntegerArg5 != NULL) {
+    if (NumArgs > 0) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    LocalIntegerArg[LocalIntegerArgCount++] = *IntegerArg5;
+  }
+
+  /// Create a method invoking another method with Argn
+  Status = AmlCodeGenMethodInvokeMethodArgn (
+             MethodNameString,
+             InvokeMethodNameString,
+             NumArgs,
+             IsSerialized,
+             SyncLevel,
+             NULL,
+             &MethodObjectNode
+             );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return Status;
+  }
+
+  /// Now append the integer argument
+  for (Index = 0; Index < LocalIntegerArgCount; Index++) {
+    IntNode = NULL;
+    Status  = AmlCodeGenInteger (LocalIntegerArg[Index], &IntNode);
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      goto exit_handler;
+    }
+
+    Status = AmlVarListAddTail (
+               (AML_NODE_HANDLE)MethodObjectNode,
+               (AML_NODE_HANDLE)IntNode
+               );
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      goto exit_handler;
+    }
+  }
+
+  IntNode = NULL;
+  Status  = LinkNode (
+              MethodObjectNode,
+              ParentNode,
+              NewObjectNode
+              );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    goto exit_handler;
+  }
+
+  return Status;
+
+exit_handler:
+  if (MethodObjectNode != NULL) {
+    AmlDeleteTree ((AML_NODE_HANDLE)MethodObjectNode);
+  }
+
+  return Status;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112288): https://edk2.groups.io/g/devel/message/112288
Mute This Topic: https://groups.io/mt/103106352/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to