From nobody Mon Feb 9 22:37:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81597+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81597+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633620780; cv=none; d=zohomail.com; s=zohoarc; b=J4tFmGlDCjKWcuXYeEqhyDsrNurMejzbqi4ymsy4a16mfLWWe0PiMqCR6AFrqhFivJ71MDH8bJ6LAE/qVvWf96dhSFlLo1tFL83eya7JyS8lSqwSwfQEMRXBsXYhmnssi5EbgmtPgLFKVuvFWDt/uVQ/DZbYwiLUZ384ZCtnBAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633620780; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=78NosZO+vMAlGB6lDAiZklzqa4U6Yw1E5M2dsQ2vvTw=; b=BX7QdUva87sPdFDicqPyPjmd7bAM9zpqQs0NKrF0kNmPNlA/K5NCEdg4ANLOFNjgqgL/2gt2UGNwzKNR1cMv1On7Vlho6zIjC9qp9F5RQrD05KhSyzaJTAvCehOnz/WN6MGFe72EXRpKjNwYYzNIFksppWzNAgAdeG7G28bF+uw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81597+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633620780769128.59474448054425; Thu, 7 Oct 2021 08:33:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TL44YY1788612xl0q0NmI8gp; Thu, 07 Oct 2021 08:33:00 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.13552.1633620779749756054 for ; Thu, 07 Oct 2021 08:32:59 -0700 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 6C509ED1; Thu, 7 Oct 2021 08:32:59 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.72.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 637EB3F66F; Thu, 7 Oct 2021 08:32:58 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei.Fedorov@arm.com Subject: [edk2-devel] [PATCH v2 16/21] DynamicTablesPkg: AML code generation to Return a NameString Date: Thu, 7 Oct 2021 16:32:05 +0100 Message-Id: <20211007153210.26608-17-Pierre.Gondois@arm.com> In-Reply-To: <20211007153210.26608-1-Pierre.Gondois@arm.com> References: <20211007153210.26608-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: h0hU37BkgoF5WocssadsK2aLx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633620780; bh=y+SexxbRlIAEc3Hp8IZkqNSxaJKhfPMB7pzZbeH+giE=; h=Date:From:Reply-To:Subject:To; b=Z9pvf4nV6oR6pZ17CEpGwIao9NRyY+ywbAH1LtCRFY9VplwQZ+SniALlK3YS3AOoXde V5kkZ62u2vrl2fhAEg3Nba4gY+NOquPimZosQZXj0aDeHUkvCfMMGn4H5M0JnVXoMNxV+ UhqCJwvFVJ+p+l+K7tcl2NqHrG4UoKkCrZA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633620782426100041 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add AmlCodeGenReturnNameString() to generate AML code for a Return object node, returning the object as a NameString. AmlCodeGenReturn ("NAM1", ParentNode, NewObjectNode) is equivalent of the following ASL code: Return(NAM1) Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../Common/AmlLib/CodeGen/AmlCodeGen.c | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/= DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index dd519bc67007..93d4ba79e937 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1154,3 +1154,184 @@ error_handler1: } return Status; } + +/** AML code generation for a Return object node. + + AmlCodeGenReturn (ReturnNode, ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return([Content of the ReturnNode]) + + The ACPI 6.3 specification, s20.2.5.3 "Type 1 Opcodes Encoding" states: + DefReturn :=3D ReturnOp ArgObject + ReturnOp :=3D 0xA4 + ArgObject :=3D TermArg =3D> DataRefObject + + Thus, the ReturnNode must be evaluated as a DataRefObject. It can + be a NameString referencing an object. As this CodeGen Api doesn't + do semantic checking, it is strongly advised to check the AML bytecode + generated by this function against an ASL compiler. + + The ReturnNode must be generated inside a Method body scope. + + @param [in] ReturnNode The object returned by the Return ASL statem= ent. + This node is deleted if an error occurs. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + Must be a MethodOp node. + @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. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenReturn ( + IN AML_NODE_HEADER * ReturnNode, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + + if ((ReturnNode =3D=3D NULL) || + ((ParentNode =3D=3D NULL) && (NewObjectNode =3D=3D NULL)) || + ((ParentNode !=3D NULL) && + !AmlNodeCompareOpCode ( + (AML_OBJECT_NODE*)ParentNode, AML_METHOD_OP, 0))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_RETURN_OP, 0), + 0, + &ObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm0, + (AML_NODE_HEADER*)ReturnNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + ReturnNode =3D NULL; + + Status =3D LinkNode ( + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + return Status; + +error_handler: + if (ReturnNode !=3D NULL) { + AmlDeleteTree (ReturnNode); + } + if (ObjectNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + return Status; +} + +/** AML code generation for a Return object node, + returning the object as an input NameString. + + AmlCodeGenReturn ("NAM1", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return(NAM1) + + The ACPI 6.3 specification, s20.2.5.3 "Type 1 Opcodes Encoding" states: + DefReturn :=3D ReturnOp ArgObject + ReturnOp :=3D 0xA4 + ArgObject :=3D TermArg =3D> DataRefObject + + Thus, the ReturnNode must be evaluated as a DataRefObject. It can + be a NameString referencing an object. As this CodeGen Api doesn't + do semantic checking, it is strongly advised to check the AML bytecode + generated by this function against an ASL compiler. + + The ReturnNode must be generated inside a Method body scope. + + @param [in] NameString The object referenced by this NameString + is returned by the Return ASL statement. + Must be a NULL-terminated ASL NameString + e.g.: "NAM1", "_SB.NAM1", etc. + The input string is copied. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + Must be a MethodOp node. + @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. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenReturnNameString ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE * DataNode; + CHAR8 * AmlNameString; + UINT32 AmlNameStringSize; + + DataNode =3D NULL; + + Status =3D ConvertAslNameToAmlName (NameString, &AmlNameString); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeNameString, + (UINT8*)AmlNameString, + AmlNameStringSize, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // AmlCodeGenReturn() deletes DataNode if error. + Status =3D AmlCodeGenReturn ( + (AML_NODE_HEADER*)DataNode, + ParentNode, + NewObjectNode + ); + ASSERT_EFI_ERROR (Status); + +exit_handler: + if (AmlNameString !=3D NULL) { + FreePool (AmlNameString); + } + return Status; +} --=20 2.17.1 -=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 (#81597): https://edk2.groups.io/g/devel/message/81597 Mute This Topic: https://groups.io/mt/86148211/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-