From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.86]) by mx.groups.io with SMTP id smtpd.web11.230.1689027977413643256 for ; Mon, 10 Jul 2023 15:26:17 -0700 Authentication-Results: mx.groups.io; dkim=fail, err=malformed MIME header line: Subject: [PATCH v2 2/4] DynamicTablesPkg: Add support for simple method invocation.; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.93.86, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bI4zHPyChgR/yjK0M8z3CBmRwf5t/c7A+zssVLuEXKL63vRHGu9hR+r14ETZQ8/GBypURaupka0qfY2ERQU4AOxI5MZyG+vdAZ0bhcJi1oupSu2jtMFhfKHfN/6iK39M0WQ5Gq2VV95totLg7ZheljqxbIsTp1QWfO1hvaxwvB9DraOdji/SdRD0XcaehyYocOZsFbDc56ayFYetUT78rRX46jwGKMSTITTJH5FMU26HsPyngu4xOwvxOeAGrNyPFelFJyRb+1iwMScsImBqCO/+3TNX0pjf5UrBQ1yn1B03oU9xsKPxgYwcZHqURoOix1hvOD/shm0JkzjS+1mh9A== 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=VylWj+m+O4MIgCK+XVcG7NrCUXv19v8njnIdWWRZ3cA=; b=PpntcosT1jjilxwmOel2uAIu7nCrSOc13r34B05WjxXRLdmOs3kU3o8BP+J1YAB8yviICXfPZbGkZubNLFUINaKT1kikgozNpq3fMplICAtM1EJ2LXHsKWsA89/OAW23g1vzGLRhBLdA5nN6wzWznVgLr/YLEg8uf1AdgKo5QZoCioR5K1PdF3dv/wBmXayK00jPKOyB5DbyphZoXq+SgGoURiek2qgoZnpK2/WUZBkSI0OTmxJYLWo0iTl9+IUJwWQDHN0aPsX9YSd6NueaEL2HeHgQB/ztBP5/sX3Jt+u3UGQbp5oUEpyKuNjAhViI6dOuWr54Qn0zTv45DM9+dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VylWj+m+O4MIgCK+XVcG7NrCUXv19v8njnIdWWRZ3cA=; b=BckQkKN66yhhtJRWxl1qBzlBpuKuro7ZUaDiuuVZfhAR7mEjxJ2pPqpn+qMeHjqNgzQAI3xXPQdTs9YLKXQVdv0ljk8EZZie7TccHmu+wYnErCEpZDpviGs+t3Ui0ieGXo8ePqZ9wjtFNLG/unLhbMC2LpSXFWFTSGmfiIREOPIjDU20t9UcHqOk2lpHzrRwks1whkR4DqGVVFRbJbZJSL3dBVQ4mkrKtUn2dUdoOJQ8S6GLCmrmNFFH3hsmALaL7x6QlXrQ+ML+3QsnAquhkqEhlplJGWBFXjl8xdorQLEyhbZrii+O1PaW1UkKVQihzCgJ8Cc3mmzCJw4hlDL7nQ== Received: from MW4P223CA0007.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::12) by BY5PR12MB4289.namprd12.prod.outlook.com (2603:10b6:a03:204::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.31; Mon, 10 Jul 2023 22:26:14 +0000 Received: from CO1NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::2b) by MW4P223CA0007.outlook.office365.com (2603:10b6:303:80::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.31 via Frontend Transport; Mon, 10 Jul 2023 22:26:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT063.mail.protection.outlook.com (10.13.175.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.18 via Frontend Transport; Mon, 10 Jul 2023 22:26:13 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 10 Jul 2023 15:26:02 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 10 Jul 2023 15:26:02 -0700 Received: from 6cd8174ac25c.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 10 Jul 2023 15:26:01 -0700 From: "Jeff Brasen" To: CC: , , , Jeff Brasen , "Swatisri Kantamsetti" , Ashish Singhal Subject: [PATCH v2 2/4] DynamicTablesPkg: Add support for simple method invocation. Date: Mon, 10 Jul 2023 22:25:57 +0000 Message-ID: <124c8bb20d692f1b7c18758e96dbf35ed17478f6.1689027745.git.jbrasen@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT063:EE_|BY5PR12MB4289:EE_ X-MS-Office365-Filtering-Correlation-Id: 7cc620c3-e0bd-41c8-f309-08db8194abc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +nBL8FYkmLMHsc23u8BEcBkCNfTVznowV/31jPhZB2vuPXPy2ZIpgogZoYS0T2Z1BLpJzksqorLEcywQdmf2wP2b6Ailx6q2qmNTxZ08LFNBDDxUpzQB/3TzzNN5txNVfwXYPv+AFtvYKS31G1EorGc2XQCgMeS2OoSjSkZhZaIEVwaF8H+tzizBHzTukngQFKWZdl0NavJOt7R71gyEUQWQiiTjKfxgq8rE17tA2WzeC7srf98sp9gb+J/F3xHFdr7TXXjtrE8tuumbDfbNfYbo0emnuAL7azXN1bw7olmbRxkqGgEOrFJlMt4XEYw/H4JX+/C6KiZSO1FElaFTDYmDoLUGSJVR3738HabWIf4n68wK4lziT0o9D1944wlBRQNGynNhp+zBX/wvlJk/iV9YJW7y4+Nh2BoVWSOg/qXffv/0H+/T0sDUpZsEmzw3H4NN3oGILh5ni+VkSBKzuAPSVaRV1Z1gxF+zZch4Td7ZUhljuki1xZj6ZilchiHvlNo6vnsJU9l/fVdOwFvV7/JO+Nkdf1D9Qvady85aKpFR72E0SfREtP1aJpLdo2/e4svoZnFd7bfUIEwJaOUjPKpKZEA/EJNdNoS1x+Zh89+t4t60apjmiPW2gt/o4q4gkULVJlKQ76x3AOntbeHH3iIG0xm/K3wUe3BcTHVUnAKUawqc2xdtRrv6eGU7GmAcd4Y/o4IAG1y+SZnSCmuXswqyNFQkSZz89fM37+SKZ53uDJwdf02aET78mqp7kJJi X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(136003)(39860400002)(346002)(451199021)(46966006)(40470700004)(36840700001)(36860700001)(82310400005)(36756003)(86362001)(40480700001)(40460700003)(7636003)(356005)(82740400003)(478600001)(6666004)(54906003)(7696005)(8936002)(8676002)(5660300002)(2906002)(316002)(4326008)(6916009)(70206006)(70586007)(41300700001)(2616005)(426003)(336012)(26005)(107886003)(47076005)(186003)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 22:26:13.8292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7cc620c3-e0bd-41c8-f309-08db8194abc4 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4289 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Add support to add Return objects via AML that pass a single integer argument to the named method. Reviewed-by: Swatisri Kantamsetti Reviewed-by: Ashish Singhal --- .../Include/Library/AmlLib/AmlLib.h | 54 +++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 224 ++++++++++++++++++ 2 files changed, 278 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index d201ae9499fa..b82c7a3ce874 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 88537b7e2d27..d31a86e98c4c 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1881,6 +1881,118 @@ 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; + + 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 + ); + ASSERT_EFI_ERROR (Status); + + 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); + } + + return Status; +} + /** AML code generation for a method returning a NameString. =20 AmlCodeGenMethodRetNameString ( @@ -1989,6 +2101,118 @@ AmlCodeGenMethodRetNameString ( 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