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 E426CD802AD for ; Mon, 18 Sep 2023 15:47:25 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JoWbSJp5bvzo0yZJMsl/u3hD4VVFUyaP9mY92qMY2Mg=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1695052044; v=1; b=l00v9MPG3jQ9zumrh7Mm13LLBcmkIj6Sd+rPzYPLZre1irhq3CX1zWjY6W2tDRa+UfsaXQ38 S75dKxqBfmr3QI11Z1bcnd6AinmIEZzzqoyVIYGDz9FOGAnCZW4wJetKfqXU25pCJ25Jn48mb6S oDXkaLeAQSasRRqqL5Tnms6g= X-Received: by 127.0.0.2 with SMTP id uAckYY7687511x89vsalfQmY; Mon, 18 Sep 2023 08:47:24 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.73]) by mx.groups.io with SMTP id smtpd.web10.54928.1695052043885096481 for ; Mon, 18 Sep 2023 08:47:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yshad7l9TDxyF1Rel+ujkge/z8CMl4FzTpkJU6M88wHdFY2W5ivnP5wfcdUV/eXSQabaEocYJtBzxcGhBZctk3YJYPHnAmwVWCM0+cCo31tv7Xzrmwyvya5cruLJb9n4Q7mEJZVHR/UQ6Z0MlaRntI+nrzAkMEX15yeTxdHCcDDPKMyzji7ZmtQFNflkoYoiRBRcG5In5gssg58bHRhrUeknpjMBEA9Cb440xhCnAmnRh1rIdJ4Cdk5EllVfhmBW24smPPqlRRV4h84LO2Qg5nONgMcJXKcVY+HC7SLwj/JDt9aCeuEDPPvfncSpqv0zo7M45+ObN0/uoNLvMyqG7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k7fJv7hrQWYEXhsW3ThQhbGUtfA9ae1DPSKJgl0qdOo=; b=ncfuHq1m7lNYrQsR3DrkVurE52AWTmQn3qjfuca8dYOddxdlZiB7L/J6AVRMkrGb7xSv2BwvILvhAW6oY97ciNxIfwKc4K4fxKVmUXzKzgTcs6ZGrgwlVAN4Uhapzc/Oafg0IMmP41mQxJCvE+ulSa529saoaEWmqfetxQCiIvkGZtYI86NqkWtbOizeNus0cNCAGVB54cKbWNPMKPYtGRSj5R5W66WPKz9VnWmYHlP705UbSBk3rbp7ECDb2cqWTHO86+0b72aQ1FMU6Je5BVEu3L59DoiqVmzSLBdEIwywUUTmhtM+SgomLGIMUbn5l7aKGszbera6adjsF0MDzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from DM6PR11CA0068.namprd11.prod.outlook.com (2603:10b6:5:14c::45) by MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 18 Sep 2023 15:47:21 +0000 X-Received: from CY4PEPF0000EE38.namprd03.prod.outlook.com (2603:10b6:5:14c:cafe::6) by DM6PR11CA0068.outlook.office365.com (2603:10b6:5:14c::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 15:47:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000EE38.mail.protection.outlook.com (10.167.242.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20 via Frontend Transport; Mon, 18 Sep 2023 15:47:21 +0000 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 18 Sep 2023 08:47:04 -0700 X-Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 18 Sep 2023 08:47:04 -0700 X-Received: from 82ca859bd651.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Mon, 18 Sep 2023 08:47:04 -0700 From: "Jeff Brasen via groups.io" To: CC: , , , , , Jeff Brasen Subject: [edk2-devel] [PATCH v4 2/4] DynamicTablesPkg: Add support for simple method invocation. Date: Mon, 18 Sep 2023 15:46:58 +0000 Message-ID: <737650480edcab199927322064b2459f647f9f02.1695049337.git.jbrasen@nvidia.com> In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE38:EE_|MN2PR12MB4373:EE_ X-MS-Office365-Filtering-Correlation-Id: 8800bc04-fb30-44c1-538e-08dbb85e8ba1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: /PjfkpU6j9I8tmCFHDAJOAG7shM8n3F+WHEHuOViJEhVwHlhDIFCCiJpz5E/SUmmcDO7gNvaaXqNPyj2YzVsi9ftSqE6Y4ReNm0dqfcz12jFL0Br3XwH0ew7SQoruJ3GoMdwyztpghsQtDY7YyluSML9Wj8z/fUy80hV5zFU6xlp4KSSwR4dqyq+C+pjwY2gESLWxUqB1zit8JDxOEj4tJI9RtahrFhBTkTr3rBgItQSzjbYSTIiqX/E1hYuV8zcxgRNx30dy9vhDzG5RhnU8OSOk0ppcOYZGYOpyM0Tu7O08B7sLDAt105g3I3lCfpotlV/yzejXGK/oeJeFwsGFojQC7N6TRwLiXOqGSCya5nAOIoVv4GLhrcr0mJgQ9mCKuQJCirpwlvuFlH4FQu9iLuFp2PWloqIxjwY2kRmooQS5GlQ+so9p4NDr7oS23u8+X8MQOLHH2w809Az74A0s6opZw5Htd3fJNxHtbA40XKtHJlGa+gppSClcAhT6iHXkt0sVE3YoyAZXEIY/P/nRXSWsaPxo2ZuqNIBJlqDfGjakt1XXkGfubJUSKqcZILuFHsj9QrCw0KM4SqEt2JYsqPcdBmauLIF87bNrLEYRAAjYz+cX8JQ3/fuDT7t0HbR3ITaCPIsi0xIXhLfOfqo0z5yZHIiADaaIcl6zYm9VisKQMOSqqgLkTH1+/2UNj7U35WU1nxjHlkJdRY2GT92Eg5DDFICeJY9vnyM0XW5odqK3tgieMtwTcfTN9kb2BEV X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 15:47:21.1005 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8800bc04-fb30-44c1-538e-08dbb85e8ba1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE38.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4373 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,jbrasen@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 3TrDeSMRzQMptruae206eRjmx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=l00v9MPG; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Add support to add Return objects via AML that pass a single integer argument to the named method. Signed-off-by: Jeff Brasen --- .../Include/Library/AmlLib/AmlLib.h | 54 ++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 244 ++++++++++++++++++ 2 files changed, 298 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index d201ae9499..b82c7a3ce8 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1194,6 +1194,60 @@ AmlCodeGenMethodRetInteger ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); =20 +/** AML code generation for a method returning a NameString that takes an + integer argument. + + AmlCodeGenMethodRetNameStringIntegerArgument ( + "MET0", "MET1", 1, TRUE, 3, 5, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(MET0, 1, Serialized, 3) { + Return (MET1 (5)) + } + + 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 NameStri= ng + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedNameString The name of the object returned by the + method. Optional parameter, can be: + - NULL (ignored). + - A NULL-terminated ASL NameString. + e.g.: "MET0", "_SB.MET0", 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 NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <=3D SyncLevel <=3D 15. + Default is 0 in ASL. + @param [in] IntegerArgument Argument to pass to the NameString. + @param [in] ParentNode If provided, set ParentNode as the par= ent + 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 +AmlCodeGenMethodRetNameStringIntegerArgument ( + IN CONST CHAR8 *MethodNameString, + IN CONST CHAR8 *ReturnedNameString OPTIONAL, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN UINT64 IntegerArgument, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ); + /** Create a _LPI name. =20 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 88537b7e2d..ea519d1aa8 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1881,6 +1881,138 @@ AmlCodeGenReturnInteger ( return Status; } =20 +/** AML code generation for a Return object node, + returning the object as an input NameString with a integer argument. + + AmlCodeGenReturn ("NAM1", 6, ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return(NAM1 (6)) + + 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] Integer Argument to pass to the NameString + @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 +AmlCodeGenReturnNameStringIntegerArgument ( + IN CONST CHAR8 *NameString, + IN UINT64 Integer, + IN AML_NODE_HEADER *ParentNode OPTIONAL, + OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE *DataNode; + AML_OBJECT_NODE *IntNode; + CHAR8 *AmlNameString; + UINT32 AmlNameStringSize; + AML_OBJECT_NODE *ObjectNode; + + DataNode =3D NULL; + IntNode =3D NULL; + ObjectNode =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; + } + + Status =3D AmlCodeGenInteger (Integer, &IntNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // AmlCodeGenReturn() deletes DataNode if error. + Status =3D AmlCodeGenReturn ( + (AML_NODE_HEADER *)DataNode, + ParentNode, + &ObjectNode + ); + + // DataNode is either deleted or added to ObjectNode, set to NULL so we = don't + // delete it again + DataNode =3D NULL; + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)ObjectNode, + (AML_NODE_HANDLE)IntNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + if (NewObjectNode !=3D 0) { + *NewObjectNode =3D ObjectNode; + } + +exit_handler: + if (AmlNameString !=3D NULL) { + FreePool (AmlNameString); + } + + if (IntNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)IntNode); + } + + if (DataNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)DataNode); + } + + if (ObjectNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)ObjectNode); + } + + return Status; +} + /** AML code generation for a method returning a NameString. =20 AmlCodeGenMethodRetNameString ( @@ -1989,6 +2121,118 @@ error_handler: return Status; } =20 +/** AML code generation for a method returning a NameString that takes an + integer argument. + + AmlCodeGenMethodRetNameStringIntegerArgument ( + "MET0", "MET1", 1, TRUE, 3, 5, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(MET0, 1, Serialized, 3) { + Return (MET1 (5)) + } + + 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 NameStri= ng + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedNameString The name of the object returned by the + method. Optional parameter, can be: + - NULL (ignored). + - A NULL-terminated ASL NameString. + e.g.: "MET0", "_SB.MET0", 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 NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <=3D SyncLevel <=3D 15. + Default is 0 in ASL. + @param [in] IntegerArgument Argument to pass to the NameString. + @param [in] ParentNode If provided, set ParentNode as the par= ent + 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 +AmlCodeGenMethodRetNameStringIntegerArgument ( + IN CONST CHAR8 *MethodNameString, + IN CONST CHAR8 *ReturnedNameString OPTIONAL, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN UINT64 IntegerArgument, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE_HANDLE MethodNode; + + if ((MethodNameString =3D=3D NULL) || + ((ParentNode =3D=3D NULL) && (NewObjectNode =3D=3D NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Create a Method named MethodNameString. + Status =3D AmlCodeGenMethod ( + MethodNameString, + NumArgs, + IsSerialized, + SyncLevel, + NULL, + &MethodNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Return ReturnedNameString if provided. + if (ReturnedNameString !=3D NULL) { + Status =3D AmlCodeGenReturnNameStringIntegerArgument ( + ReturnedNameString, + IntegerArgument, + (AML_NODE_HANDLE)MethodNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + } + + Status =3D LinkNode ( + MethodNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + return Status; + +error_handler: + if (MethodNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); + } + + return Status; +} + /** AML code generation for a method returning an Integer. =20 AmlCodeGenMethodRetInteger ( --=20 2.25.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 (#108801): https://edk2.groups.io/g/devel/message/108801 Mute This Topic: https://groups.io/mt/101436335/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-