Hello Abdul,
Thanks for the new patches. I reviewed this one, but I think it would
be better to have one single generic function to handle the 2 cases
(and the many more that might spawn) that you have.
Would it be possible to make a function based on this kind of interface instead
?
/* Type of the function parameter. There are some missing types,
like the Local arguments, packages, etc. but this should be sufficient
for your use case.
*/
typedef enum {
AmlMethodParamTypeArg = 0,
AmlMethodParamTypeInteger,
AmlMethodParamTypeString,
} AML_METHOD_PARAM_TYPE;
/* Structure to describe each method parameter. */
struct {
AML_METHOD_TYPE Type;
union {
UINTN ArgN;
UINT64 Integer;
VOID *Data;
} Data;
UINTN Length;
/* In case packages are added one day and we need to count the elements. */
UINTN Count;
}
/* The function */
EFI_STATUS
EFIAPI
AmlCodeGenMethodInvokeMethodArgn (
IN CONST CHAR8 *MethodNameString,
IN CONST CHAR8 *InvokeMethodNameString,
IN UINT8 NumArgs,
IN BOOLEAN IsSerialized,
IN UINT8 SyncLevel,
IN AML_METHOD_PARAM_TYPE *MethodParamArray,
IN UINTN MethodParamCount,
IN AML_NODE_HANDLE ParentNode OPTIONAL,
OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
);
{
/* Based on the type of each element of MethodParamArray,
some Data node might be necessary to allocate.
*/
}
/* And to use this function: */
AML_METHOD_PARAM_TYPE MethodParamArray[4] = {
{ // [0]
.Type = AmlMethodParamTypeArg,
.Data = 2,
// Length and Count are unused.
},
{ // [1]
.Type = AmlMethodParamTypeInteger,
.Data = 1000,
// Length and Count are unused.
},
{ // [2]
.Type = AmlMethodParamTypeString,
.Data = "Hello",
.Length = strlen("Hello");
// Count is unused.
},
{ // [3]
.Type = AmlMethodParamTypeArg,
.Data = 0,
// Length and Count are unused.
},
}
AmlCodeGenMethodInvokeMethodArgn (
"MET0", "MET1", 4, TRUE, 3, MethodParamArray, 4, ParentNode, NewObjectNode
);
is equivalent of the following ASL code:
Method(MET0, 4, Serialized, 3) {
MET1 (Arg2, 1000, "Hello", Arg0)
}
Regards,
Pierre
On 12/11/23 11:37, Abdul Lateef Attar wrote:
From: Abdul Lateef Attar <abdullateef.at...@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.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 | 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.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
aswell I think. Same comment for the function declaration.
+**/
+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)) {
Is it possible to also check that ParentNode and NewObjectNode are not
NULL together ?
((ParentNode == NULL) && (NewObjectNode == 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);
I think 'ObjectNode' needs to be free here if the function fails.
+ 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) {
I don't think it's possible to have MethodNode == NULL here.
+ AmlDeleteTree ((AML_NODE_HANDLE)MethodNode);
+ }
+
+ return Status;
+}
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112299): https://edk2.groups.io/g/devel/message/112299
Mute This Topic: https://groups.io/mt/103106350/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-