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 64C349414FF for ; Wed, 20 Dec 2023 10:19:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=senGlI5z7E/Ejbe8sUIFZKcBiwcBCtvgbWEcNJQeJNM=; 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=1703067577; v=1; b=r4G4W3E3l1tRmQ/2QbxSvxCe8tDtREjpqml64rUe9LIoNHgI6KvFeWfaxhp4Hf7/NdV2tsKJ m/YuKQS3iy7ZorI1zxp6YcEHNhjMhe0mAUvd6Yl2isl6X69yeOD0zlTZsykqwVMvKYZHO4GYujM irRDDj2DomSZeg8Xs7xB84CY= X-Received: by 127.0.0.2 with SMTP id 06m4YY7687511xvMFsc8U2X6; Wed, 20 Dec 2023 02:19:37 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.18843.1703067575355041255 for ; Wed, 20 Dec 2023 02:19:36 -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 1F4141FB; Wed, 20 Dec 2023 02:20:19 -0800 (PST) X-Received: from [192.168.1.25] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3D4A23F5A1; Wed, 20 Dec 2023 02:19:33 -0800 (PST) Message-ID: <8b76a1a9-1c1a-41fb-8e58-695f53f2cac7@arm.com> Date: Wed, 20 Dec 2023 11:19:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [Resend PATCH v5 4/4] DynamicTablesPkg: AML Code generation to invoke a method To: Abdul Lateef Attar , devel@edk2.groups.io Cc: Abdul Lateef Attar , Sami Mujawar References: <0304349ab5b384980681427b98dc3313faf279eb.1703064925.git.AbdulLateef.Attar@amd.com> From: "PierreGondois" In-Reply-To: <0304349ab5b384980681427b98dc3313faf279eb.1703064925.git.AbdulLateef.Attar@amd.com> 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: fkD2uZPudnNHUAIS7Nxxwi0ux7686176AA= 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=r4G4W3E3; 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 update! Reviewed-by: Pierre Gondois On 12/20/23 10:38, Abdul Lateef Attar wrote: > From: Abdul Lateef Attar >=20 > Adds API to generate AML code to invoke/call another > method. Also provides ability to pass arguments of > type integer, string, ArgObj or LocalObj. >=20 > Cc: Pierre Gondois > Cc: Sami Mujawar > Signed-off-by: Abdul Lateef Attar > --- > .../Include/Library/AmlLib/AmlLib.h | 112 +++++++++ > .../Common/AmlLib/CodeGen/AmlCodeGen.c | 235 +++++++++++++++++- > 2 files changed, 346 insertions(+), 1 deletion(-) >=20 > diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTa= blesPkg/Include/Library/AmlLib/AmlLib.h > index eb8740692f..043ec3d842 100644 > --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > @@ -101,6 +101,56 @@ typedef enum { > AmlAddressRangeMax =3D 4 > } AML_MEMORY_ATTRIBUTES_MTP; > =20 > +/** Method parameter types > + > + Possible values are: > + 0 - AmlMethodParamTypeInteger > + 1 - AmlMethodParamTypeString > + 2 - AmlMethodParamTypeArg > + 3 - AmlMethodParamTypeLocal > + > + @par Reference(s) > + - ACPI 6.5, s20.2.5 "Term Objects Encoding" > + > +**/ > +typedef enum { > + AmlMethodParamTypeInteger =3D 0, > + AmlMethodParamTypeString =3D 1, > + AmlMethodParamTypeArg =3D 2, > + AmlMethodParamTypeLocal =3D 3 > +} AML_METHOD_PARAM_TYPE; > + > +/** AML Method parameter data > + holds the AML method parameter data. > +**/ > +typedef union { > + UINT8 Arg; > + UINT8 Local; > + UINT64 Integer; > + VOID *Buffer; > +} AML_METHOD_PARAM_DATA; > + > +/** structure to hold AML method parameter types > + Type - Type of parameter > + Data - holds data of parameter > + if Type is AmlMethodParamTypeInteger > + then Data is of type Integer to hold integer value. > + if Type is AmlMethodParamTypeString > + then Data contains null terminated string. > + If Type is AmlMethodParamTypeArg > + then Data contains the Argument number, > + 0 to 6 are supported value. > + If Type is AmlMethodParamTypeLocal > + then Data contains the Local variable number, > + 0 to 7 are supported value. > + DataSize - for future use > +**/ > +typedef struct { > + AML_METHOD_PARAM_TYPE Type; > + AML_METHOD_PARAM_DATA Data; > + UINTN DataSize; > +} AML_METHOD_PARAM; > + > /** Parse the definition block. > =20 > The function parses the whole AML blob. It starts with the ACPI DSDT/= SSDT > @@ -1693,4 +1743,66 @@ AmlAddNameStringToNamedPackage ( > IN AML_OBJECT_NODE_HANDLE NamedNode > ); > =20 > +/** AML code generation to invoke/call another method. > + > + 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: > + AmlCodeGenInvokeMethod ("MET0", 0, NULL, ParentNode); > + is equivalent to the following ASL code: > + MET0 (); > + > + Example 2: > + AML_METHOD_PARAM Param[4]; > + Param[0].Data.Integer =3D 0x100; > + Param[0].Type =3D AmlMethodParamTypeInteger; > + Param[1].Data.Buffer =3D "TEST"; > + Param[1].Type =3D AmlMethodParamTypeString; > + Param[2].Data.Arg =3D 0; > + Param[2].Type =3D AmlMethodParamTypeArg; > + Param[3].Data.Local =3D 2; > + Param[3].Type =3D AmlMethodParamTypeLocal; > + AmlCodeGenInvokeMethod ("MET0", 4, Param, ParentNode); > + > + is equivalent to the following ASL code: > + MET0 (0x100, "TEST", Arg0, Local2); > + > + Example 3: > + AML_METHOD_PARAM Param[2]; > + Param[0].Data.Arg =3D 0; > + Param[0].Type =3D AmlMethodParamTypeArg; > + Param[1].Data.Integer =3D 0x100; > + Param[1].Type =3D AmlMethodParamTypeInteger; > + AmlCodeGenMethodRetNameString ("MET2", NULL, 2, TRUE, 0, ParentNode,= &MethodNode); > + AmlCodeGenInvokeMethod ("MET3", 2, Param, MethodNode); > + > + is equivalent to the following ASL code: > + Method (MET2, 2, Serialized) > + { > + MET3 (Arg0, 0x0100) > + } > + > + @param [in] MethodNameString The method name to be called or invoked. > + @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 invo= cation > + nodes are attached. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. > + **/ > +EFI_STATUS > +EFIAPI > +AmlCodeGenInvokeMethod ( > + IN CONST CHAR8 *MethodNameString, > + IN UINT8 NumArgs, > + IN AML_METHOD_PARAM *Parameters OPTIONAL, > + IN AML_NODE_HANDLE ParentNode > + ); > + > #endif // AML_LIB_H_ > diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c = b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > index a6db34fb97..ddec9b67ed 100644 > --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > @@ -2,6 +2,7 @@ > AML Code Generation. > =20 > Copyright (c) 2020 - 2022, Arm Limited. All rights reserved.
> + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. > =20 > SPDX-License-Identifier: BSD-2-Clause-Patent > **/ > @@ -921,7 +922,7 @@ AmlCodeGenNameUnicodeString ( > Status =3D AmlCreateDataNode ( > EAmlNodeDataTypeRaw, > (CONST UINT8 *)String, > - StrSize (String), > + (UINT32)StrSize (String), > &DataNode > ); > if (EFI_ERROR (Status)) { > @@ -3849,3 +3850,235 @@ exit_handler: > =20 > return Status; > } > + > +/** AML code generation to invoke/call another method. > + > + 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: > + AmlCodeGenInvokeMethod ("MET0", 0, NULL, ParentNode); > + is equivalent to the following ASL code: > + MET0 (); > + > + Example 2: > + AML_METHOD_PARAM Param[4]; > + Param[0].Data.Integer =3D 0x100; > + Param[0].Type =3D AmlMethodParamTypeInteger; > + Param[1].Data.Buffer =3D "TEST"; > + Param[1].Type =3D AmlMethodParamTypeString; > + Param[2].Data.Arg =3D 0; > + Param[2].Type =3D AmlMethodParamTypeArg; > + Param[3].Data.Local =3D 2; > + Param[3].Type =3D AmlMethodParamTypeLocal; > + AmlCodeGenInvokeMethod ("MET0", 4, Param, ParentNode); > + > + is equivalent to the following ASL code: > + MET0 (0x100, "TEST", Arg0, Local2); > + > + Example 3: > + AML_METHOD_PARAM Param[2]; > + Param[0].Data.Arg =3D 0; > + Param[0].Type =3D AmlMethodParamTypeArg; > + Param[1].Data.Integer =3D 0x100; > + Param[1].Type =3D AmlMethodParamTypeInteger; > + AmlCodeGenMethodRetNameString ("MET2", NULL, 2, TRUE, 0, ParentNode,= &MethodNode); > + AmlCodeGenInvokeMethod ("MET3", 2, Param, MethodNode); > + > + is equivalent to the following ASL code: > + Method (MET2, 2, Serialized) > + { > + MET3 (Arg0, 0x0100) > + } > + > + @param [in] MethodNameString The method name to be called or invoked. > + @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 invo= cation > + nodes are attached. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. > + **/ > +EFI_STATUS > +EFIAPI > +AmlCodeGenInvokeMethod ( > + IN CONST CHAR8 *MethodNameString, > + IN UINT8 NumArgs, > + IN AML_METHOD_PARAM *Parameters OPTIONAL, > + IN AML_NODE_HANDLE ParentNode > + ) > +{ > + EFI_STATUS Status; > + UINT8 Index; > + CHAR8 *AmlNameString; > + UINT32 AmlNameStringSize; > + AML_DATA_NODE *DataNode; > + AML_OBJECT_NODE *ObjectNode; > + AML_NODE_HANDLE *NodeStream; > + > + if ((MethodNameString =3D=3D NULL) || (ParentNode =3D=3D NULL)) { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + if ((NumArgs > 7) || > + ((Parameters =3D=3D NULL) && (NumArgs > 0))) > + { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + /// Allocate space to store methodname, object, data node pointers > + NodeStream =3D AllocateZeroPool (sizeof (AML_NODE_HANDLE) * (NumArgs += 1)); > + if (NodeStream =3D=3D NULL) { > + ASSERT (0); > + return EFI_OUT_OF_RESOURCES; > + } > + > + /// Create a called or invoked method name string. > + Status =3D ConvertAslNameToAmlName (MethodNameString, &AmlNameString); > + 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; > + } > + > + DataNode =3D NULL; > + Status =3D AmlCreateDataNode ( > + EAmlNodeDataTypeNameString, > + (UINT8 *)AmlNameString, > + AmlNameStringSize, > + &DataNode > + ); > + FreePool (AmlNameString); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + NodeStream[0] =3D (AML_NODE_HANDLE)DataNode; > + > + if (Parameters !=3D NULL) { > + /// Validate and convert the Parameters to the stream of nodes. > + for (Index =3D 0; Index < NumArgs; Index++) { > + switch (Parameters[Index].Type) { > + case AmlMethodParamTypeInteger: > + ObjectNode =3D NULL; > + Status =3D AmlCodeGenInteger (Parameters[Index].Data.Integ= er, &ObjectNode); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + NodeStream[Index+1] =3D (AML_NODE_HANDLE)ObjectNode; > + break; > + case AmlMethodParamTypeString: > + ObjectNode =3D NULL; > + if (Parameters[Index].Data.Buffer =3D=3D NULL) { > + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); > + Status =3D EFI_INVALID_PARAMETER; > + goto exit_handler; > + } > + > + Status =3D AmlCodeGenString (Parameters[Index].Data.Buffer, &O= bjectNode); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + NodeStream[Index+1] =3D (AML_NODE_HANDLE)ObjectNode; > + break; > + case AmlMethodParamTypeArg: > + ObjectNode =3D NULL; > + if (Parameters[Index].Data.Arg > (UINT8)(AML_ARG6 - AML_ARG0))= { > + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); > + Status =3D EFI_INVALID_PARAMETER; > + goto exit_handler; > + } > + > + Status =3D AmlCreateObjectNode ( > + AmlGetByteEncodingByOpCode (AML_ARG0 + Parameters[I= ndex].Data.Arg, 0), > + 0, > + &ObjectNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + NodeStream[Index+1] =3D (AML_NODE_HANDLE)ObjectNode; > + break; > + case AmlMethodParamTypeLocal: > + ObjectNode =3D NULL; > + if (Parameters[Index].Data.Local > (UINT8)(AML_LOCAL7 - AML_LO= CAL0)) { > + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); > + Status =3D EFI_INVALID_PARAMETER; > + goto exit_handler; > + } > + > + Status =3D AmlCreateObjectNode ( > + AmlGetByteEncodingByOpCode (AML_LOCAL0 + Parameters= [Index].Data.Local, 0), > + 0, > + &ObjectNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler; > + } > + > + NodeStream[Index+1] =3D (AML_NODE_HANDLE)ObjectNode; > + break; > + default: > + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); > + Status =3D EFI_INVALID_PARAMETER; > + goto exit_handler; > + break; > + } > + } > + } > + > + /// Index <=3D NumArgs, because an additional method name was added. > + for (Index =3D 0; Index <=3D NumArgs; Index++) { > + Status =3D AmlVarListAddTail ( > + (AML_NODE_HANDLE)ParentNode, > + (AML_NODE_HANDLE)NodeStream[Index] > + ); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + goto exit_handler_detach; > + } > + } > + > + FreePool (NodeStream); > + return Status; > + > +exit_handler_detach: > + /// The index contains the last successful node attached. > + for ( ; Index > 0; Index--) { > + /// Index contains the node number that is failed for AmlVarListAddT= ail(). > + /// Hence, start detaching from the last successful > + AmlDetachNode (NodeStream[Index-1]); > + } > + > +exit_handler: > + /// Index <=3D NumArgs, because an additional method name was added. > + for (Index =3D 0; Index <=3D NumArgs; Index++) { > + if (NodeStream[Index] !=3D 0) { > + AmlDeleteTree (NodeStream[Index]); > + } > + } > + > + FreePool (NodeStream); > + 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 (#112760): https://edk2.groups.io/g/devel/message/112760 Mute This Topic: https://groups.io/mt/103278521/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-