From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by mx.groups.io with SMTP id smtpd.web12.11299.1641679076470695746 for ; Sat, 08 Jan 2022 13:58:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=YVRp0uiL; spf=pass (domain: quicinc.com, ip: 199.106.114.39, mailfrom: quic_rcran@quicinc.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1641679080; x=1673215080; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0Az2HaRyVTBMBQCzLie7N588T5/FFn+j/esyeqCUDwk=; b=YVRp0uiLZ3fcMirhYEEziQDKVGID7ZVdxXmGSgigMdU/xIFdaJvI26IV kAv3GvsF4ppn2ZhsnNnDkaN8x7WyNuLAriPwOjWFna0HIlHd/WSgYbjps 2uOjRGYUXKycHSBHH7IELno5JqQqsOp0hBReDBG2X01pXhZocpRu2U9WH E=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-02.qualcomm.com with ESMTP; 08 Jan 2022 13:58:00 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2022 13:58:00 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Sat, 8 Jan 2022 13:57:59 -0800 Received: from linbox.ba.nuviainc.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Sat, 8 Jan 2022 13:57:59 -0800 From: "Rebecca Cran" To: , Sami Mujawar , "Alexei Fedorov" , Leif Lindholm CC: Rebecca Cran Subject: [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function Date: Sat, 8 Jan 2022 14:57:48 -0700 Message-ID: <20220108215748.2173-4-quic_rcran@quicinc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220108215748.2173-1-quic_rcran@quicinc.com> References: <20220108215748.2173-1-quic_rcran@quicinc.com> MIME-Version: 1.0 Return-Path: quic_rcran@quicinc.com X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) Content-Transfer-Encoding: 8bit Content-Type: text/plain Add AmlCodeGenMethodRetInteger function to generate AML code for a Method returning an Integer. Signed-off-by: Rebecca Cran --- DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 47 ++++++ DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 156 ++++++++++++++++++++ 2 files changed, 203 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 8b3e80b61466..e47cf99eaa37 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1118,6 +1118,53 @@ AmlCodeGenMethodRetNameString ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); +/** AML code generation for a method returning an Integer. + + AmlCodeGenMethodRetInteger ( + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_CBA, 1, Serialized, 3) { + Return (0) + } + + The ASL parameters "ReturnType" and "ParameterTypes" are not asked + in this function. They are optional parameters in ASL. + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedInteger The value of the integer returned by the + method. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 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 node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenMethodRetInteger ( + IN CONST CHAR8 *MethodNameString, + IN UINT64 ReturnedInteger, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ); + /** Create a _LPI name. AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 838a892c6b58..07822ead5b70 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1685,6 +1685,61 @@ exit_handler: return Status; } +/** AML code generation for a Return object node, + returning an Integer. + + AmlCodeGenReturn (0), ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return (0) + + The ACPI 6.3 specification, 20.2.8 "Statement Opcodes Encoding" states: + DefReturn := ReturnOp ArgObject + ReturnOp := 0xA4 + ArgObject := TermArg => DataRefObject + + Thus, the ReturnNode must be evaluated as a DataRefObject. + + The ReturnNode must be generated inside a Method body scope. + + @param [in] Integer The integer is returned by the Return + ASL statement. + @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 +AmlCodeGenReturnInteger ( + IN UINT64 Integer, + IN AML_NODE_HEADER *ParentNode OPTIONAL, + OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE *IntNode; + + IntNode = NULL; + + Status = AmlCodeGenInteger (Integer, &IntNode); + ASSERT_EFI_ERROR (Status); + + // AmlCodeGenReturn() deletes DataNode if error. + Status = AmlCodeGenReturn ( + (AML_NODE_HEADER *)IntNode, + ParentNode, + NewObjectNode + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + /** AML code generation for a method returning a NameString. AmlCodeGenMethodRetNameString ( @@ -1793,6 +1848,107 @@ error_handler: return Status; } +/** AML code generation for a method returning an Integer. + + AmlCodeGenMethodRetInteger ( + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_CBA, 1, Serialized, 3) { + Return (0) + } + + The ASL parameters "ReturnType" and "ParameterTypes" are not asked + in this function. They are optional parameters in ASL. + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedInteger The value of the integer returned by the + method. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 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 node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenMethodRetInteger ( + IN CONST CHAR8 *MethodNameString, + IN UINT64 ReturnedInteger, + 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; + + if ((MethodNameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Create a Method named MethodNameString. + Status = AmlCodeGenMethod ( + MethodNameString, + NumArgs, + IsSerialized, + SyncLevel, + NULL, + &MethodNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCodeGenReturnInteger ( + ReturnedInteger, + (AML_NODE_HANDLE)MethodNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status = LinkNode ( + MethodNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + return Status; + +error_handler: + if (MethodNode != NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); + } + + return Status; +} + /** Create a _LPI name. AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is -- 2.31.1