From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id E78F1941984 for ; Mon, 11 Dec 2023 14:27:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=syM3b7kOhRyFhe3EgJmw4xFp9vaZhntZmcZCuGAobVI=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1702304826; v=1; b=jfYIyp4LeUqyaubJG1ep7jtLOkAnIWze3gOKfLsInrGEc0oPVEPo97fkmcp0oYHX5PggWiQm 3RjEZlzgwkw64xaLgxbOE7NnXp8kyICdwtd2/nu+chXwvdJwgN5bIqCJpjatJyOFs+JRqVfb+Lx xtgk+Q3zhZBtakIqFckHTZKE= X-Received: by 127.0.0.2 with SMTP id dqq6YY7687511xJTBASBH8lJ; Mon, 11 Dec 2023 06:27:06 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9492.1702304825470231709 for ; Mon, 11 Dec 2023 06:27:05 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C936FEC; Mon, 11 Dec 2023 06:27:51 -0800 (PST) X-Received: from [10.34.100.114] (e126645.nice.arm.com [10.34.100.114]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C97333F738; Mon, 11 Dec 2023 06:27:03 -0800 (PST) Message-ID: Date: Mon, 11 Dec 2023 15:26:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Adds API to generate a method with ArgN To: Abdul Lateef Attar , devel@edk2.groups.io Cc: Abdul Lateef Attar , Sami Mujawar References: From: "PierreGondois" In-Reply-To: Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: KkZl8L5ZMxc4o140IggsKAkmx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=jfYIyp4L; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 ins= tead ? /* 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 =3D 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] =3D { { // [0] .Type =3D AmlMethodParamTypeArg, .Data =3D 2, // Length and Count are unused. }, { // [1] .Type =3D AmlMethodParamTypeInteger, .Data =3D 1000, // Length and Count are unused. }, { // [2] .Type =3D AmlMethodParamTypeString, .Data =3D "Hello", .Length =3D strlen("Hello"); // Count is unused. }, { // [3] .Type =3D AmlMethodParamTypeArg, .Data =3D 0, // Length and Count are unused. }, } AmlCodeGenMethodInvokeMethodArgn ( "MET0", "MET1", 4, TRUE, 3, MethodParamArray, 4, ParentNode, NewObjectNo= de ); 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 >=20 > 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. >=20 > e.g: > Method (MET0, 6, Serialized) > { > \_SB.MET1 (Arg0, Arg1, Arg2, Arg3, Arg4, Arg5) > } >=20 > Cc: Pierre Gondois > Cc: Sami Mujawar > Signed-off-by: Abdul Lateef Attar > --- > .../Include/Library/AmlLib/AmlLib.h | 46 ++++++ > .../Common/AmlLib/CodeGen/AmlCodeGen.c | 152 ++++++++++++++++++ > 2 files changed, 198 insertions(+) >=20 > diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTa= blesPkg/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 > ); > =20 > +/** 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 Name= String > + 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 Name= String > + e.g.: "MET1", "_SB.MET1", etc. > + The input string is copied. > + @param [in] NumArgs Number of arguments. > + Must be 0 <=3D NumArgs <=3D 6. > + @param [in] IsSerialized TRUE is equivalent to Serialized. > + FALSE is equivalent to NotSerializ= ed. > + Default is NotSerialized in ASL sp= ec. > + @param [in] SyncLevel Synchronization level for the meth= od. > + Must be 0 <=3D SyncLevel <=3D 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 n= ode. > + > + @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: > =20 > 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 Name= String > + 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 Name= String > + e.g.: "MET1", "_SB.MET1", etc. > + The input string is copied. > + @param [in] NumArgs Number of arguments. > + Must be 0 <=3D NumArgs <=3D 6. > + @param [in] IsSerialized TRUE is equivalent to Serialized. > + FALSE is equivalent to NotSerializ= ed. > + Default is NotSerialized in ASL sp= ec. > + @param [in] SyncLevel Synchronization level for the meth= od. > + Must be 0 <=3D SyncLevel <=3D 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 n= ode. > + > + @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 =3D=3D NULL) || (InvokeMethodNameString =3D=3D N= ULL)) { Is it possible to also check that ParentNode and NewObjectNode are not NULL together ? ((ParentNode =3D=3D NULL) && (NewObjectNode =3D=3D NULL)) > + return EFI_INVALID_PARAMETER; > + } > + > + // Create a Method named MethodNameString > + Status =3D AmlCodeGenMethod ( > + MethodNameString, > + NumArgs, > + IsSerialized, > + SyncLevel, > + NULL, > + &MethodNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + return Status; > + } > + > + DataNode =3D NULL; > + Status =3D ConvertAslNameToAmlName (InvokeMethodNameString, &AmlName= String); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + Status =3D AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + FreePool (AmlNameString); > + goto exit_handler; > + } > + > + Status =3D AmlCreateDataNode ( > + EAmlNodeDataTypeNameString, > + (UINT8 *)AmlNameString, > + AmlNameStringSize, > + &DataNode > + ); > + FreePool (AmlNameString); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + Status =3D AmlVarListAddTail ( > + (AML_NODE_HEADER *)MethodNode, > + (AML_NODE_HEADER *)DataNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + DataNode =3D NULL; > + > + for (ArgnCount =3D 0; ArgnCount < NumArgs; ArgnCount++) { > + Status =3D AmlCreateObjectNode ( > + AmlGetByteEncodingByOpCode (AML_ARG0 + ArgnCount, 0), > + 0, > + &ObjectNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + Status =3D 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 =3D NULL; > + } > + > + Status =3D LinkNode ( > + MethodNode, > + ParentNode, > + NewObjectNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + return Status; > + > +exit_handler: > + if (MethodNode !=3D NULL) { I don't think it's possible to have MethodNode =3D=3D NULL here. > + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); > + } > + > + return Status; > +} -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-