DynamicTablesPkg/AmlLib: Adds API method returning method invocations

Introduce AmlCodeGenReturnInvokeMethod(), a new AML code generation API
that creates AML code for methods whose body returns the result of a
method invocation, i.e. Return(MethodName(args...)).

Supported parameter types for method arguments include:
  - AmlMethodParamTypeInteger: Integer constants.
  - AmlMethodParamTypeString:  String literals.
  - AmlMethodParamTypeArg:     ArgObj references (Arg0-Arg6).
  - AmlMethodParamTypeLocal:   LocalObj references (Local0-Local7).

The resulting MethodInvocation node is wrapped in a Return statement
via AmlCodeGenReturn() and linked to the specified parent node.

Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
This commit is contained in:
Abdul Lateef Attar 2026-02-06 13:39:42 +00:00 committed by mergify[bot]
parent 1774a34cc5
commit cb4cbc5216
2 changed files with 171 additions and 0 deletions

View file

@ -2304,3 +2304,68 @@ AmlCodeGenMethodNotifyList (
IN AML_NODE_HANDLE ParentNode OPTIONAL,
OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
);
/** AML code generation to Return Method invocation.
This method is a subset implementation of MethodInvocation
defined in the ACPI specification 6.5,
section 20.2.5 "Term Objects Encoding".
Added integer, string, ArgObj and LocalObj support.
Example 1:
AmlCodeGenReturnInvokeMethod ("MET0", 0, NULL, ParentNode, &NewObjectNode);
is equivalent to the following ASL code:
Return (MET0 () )
Example 2:
AML_METHOD_PARAM Param[4];
Param[0].Data.Integer = 0x100;
Param[0].Type = AmlMethodParamTypeInteger;
Param[1].Data.Buffer = "TEST";
Param[1].Type = AmlMethodParamTypeString;
Param[2].Data.Arg = 0;
Param[2].Type = AmlMethodParamTypeArg;
Param[3].Data.Local = 2;
Param[3].Type = AmlMethodParamTypeLocal;
AmlCodeGenReturnInvokeMethod ("MET0", 4, Param, ParentNode, &NewObjectNode);
is equivalent to the following ASL code:
Return (MET0 (0x100, "TEST", Arg0, Local2) )
Example 3:
AML_METHOD_PARAM Param[2];
Param[0].Data.Arg = 0;
Param[0].Type = AmlMethodParamTypeArg;
Param[1].Data.Integer = 0x100;
Param[1].Type = AmlMethodParamTypeInteger;
AmlCodeGenMethodRetNameString ("MET2", NULL, 2, TRUE, 0,
ParentNode, &MethodNode);
AmlCodeGenReturnInvokeMethod ("MET3", 2, Param, MethodNode, &NewObjectNode);
is equivalent to the following ASL code:
Method (MET2, 2, Serialized)
{
Return (MET3 (Arg0, 0x0100) )
}
@param [in] MethodNameString The method name to be returned.
@param [in] NumArgs Number of arguments to be passed,
0 to 7 are permissible values.
@param [in] Parameters Contains the parameter data.
@param [in] ParentNode The parent node to which the method return
nodes are attached.
@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.
**/
EFI_STATUS
EFIAPI
AmlCodeGenReturnInvokeMethod (
IN CONST CHAR8 *MethodNameString,
IN UINT8 NumArgs,
IN AML_METHOD_PARAM *Parameters OPTIONAL,
IN AML_NODE_HANDLE ParentNode OPTIONAL,
OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
);

View file

@ -5569,3 +5569,109 @@ error_handler:
return Status;
}
/** AML code generation to Return Method invocation.
This method is a subset implementation of MethodInvocation
defined in the ACPI specification 6.5,
section 20.2.5 "Term Objects Encoding".
Added integer, string, ArgObj and LocalObj support.
Example 1:
AmlCodeGenReturnInvokeMethod ("MET0", 0, NULL, ParentNode, &NewObjectNode);
is equivalent to the following ASL code:
Return (MET0 () )
Example 2:
AML_METHOD_PARAM Param[4];
Param[0].Data.Integer = 0x100;
Param[0].Type = AmlMethodParamTypeInteger;
Param[1].Data.Buffer = "TEST";
Param[1].Type = AmlMethodParamTypeString;
Param[2].Data.Arg = 0;
Param[2].Type = AmlMethodParamTypeArg;
Param[3].Data.Local = 2;
Param[3].Type = AmlMethodParamTypeLocal;
AmlCodeGenReturnInvokeMethod ("MET0", 4, Param, ParentNode, &NewObjectNode);
is equivalent to the following ASL code:
Return (MET0 (0x100, "TEST", Arg0, Local2) )
Example 3:
AML_METHOD_PARAM Param[2];
Param[0].Data.Arg = 0;
Param[0].Type = AmlMethodParamTypeArg;
Param[1].Data.Integer = 0x100;
Param[1].Type = AmlMethodParamTypeInteger;
AmlCodeGenMethodRetNameString ("MET2", NULL, 2, TRUE, 0,
ParentNode, &MethodNode);
AmlCodeGenReturnInvokeMethod ("MET3", 2, Param, MethodNode, &NewObjectNode);
is equivalent to the following ASL code:
Method (MET2, 2, Serialized)
{
Return (MET3 (Arg0, 0x0100) )
}
@param [in] MethodNameString The method name to be returned.
@param [in] NumArgs Number of arguments to be passed,
0 to 7 are permissible values.
@param [in] Parameters Contains the parameter data.
@param [in] ParentNode The parent node to which the method return
nodes are attached.
@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.
**/
EFI_STATUS
EFIAPI
AmlCodeGenReturnInvokeMethod (
IN CONST CHAR8 *MethodNameString,
IN UINT8 NumArgs,
IN AML_METHOD_PARAM *Parameters OPTIONAL,
IN AML_NODE_HANDLE ParentNode OPTIONAL,
OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
)
{
EFI_STATUS Status;
AML_OBJECT_NODE_HANDLE MethodInvocationNode;
if ((MethodNameString == NULL) ||
((ParentNode == NULL) && (NewObjectNode == NULL)))
{
ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
return EFI_INVALID_PARAMETER;
}
if ((NumArgs > AML_METHOD_MAX_NUM_ARGS) ||
((Parameters == NULL) && (NumArgs > 0)))
{
ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
return EFI_INVALID_PARAMETER;
}
Status = AmlCodeGenInvokeMethod (
MethodNameString,
NumArgs,
Parameters,
NULL,
&MethodInvocationNode
);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
return Status;
}
Status = AmlCodeGenReturn (
(AML_NODE_HEADER *)MethodInvocationNode,
ParentNode,
NewObjectNode
);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
}
return Status;
}