diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 292a1a3026..28ee87c9b1 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -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 + ); diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index c47767d0c2..3b36c55d8f 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -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; +}