From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.48]) by mx.groups.io with SMTP id smtpd.web11.17186.1597245834309805901 for ; Wed, 12 Aug 2020 08:23:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=LRh6ClpR; spf=pass (domain: arm.com, ip: 40.107.20.48, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G/XvKrGpkHmmu6GGZ6lOswxLD/Sqvg27tPfHZ+Wt4vw=; b=LRh6ClpRMCU/9gosy4OAahLadoBHEfMTqRS+J5lljoIUS60PLwSHAkw7N0rrCPC8XOpmsraLivUVaN9Z3azqezrtACq79PVroTvubNKCOh/07I+NSiKBcCFm9SxsZecdXdmREWzhASriMnTKyfoboWjSTs3TD9OqxzGBxVmmhgQ= Received: from AM6P193CA0132.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::37) by AM6PR08MB4310.eurprd08.prod.outlook.com (2603:10a6:20b:b8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15; Wed, 12 Aug 2020 15:23:45 +0000 Received: from AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::a4) by AM6P193CA0132.outlook.office365.com (2603:10a6:209:85::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.15 via Frontend Transport; Wed, 12 Aug 2020 15:23:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT023.mail.protection.outlook.com (10.152.16.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16 via Frontend Transport; Wed, 12 Aug 2020 15:23:45 +0000 Received: ("Tessian outbound 195a290eb161:v64"); Wed, 12 Aug 2020 15:23:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e3ddd9ffbc240f30 X-CR-MTA-TID: 64aa7808 Received: from 8a7c49420ad1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 5C42C488-C2DE-4161-8B56-7CB28A7F6FD3.1; Wed, 12 Aug 2020 15:23:39 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8a7c49420ad1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 12 Aug 2020 15:23:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e3HGZiqyjU6sgtR0/sbxMvo3DKnrJ468sfKNIPwv5WQKsWTuMA4i01fp7aaX+ccpm3PcNy6hbNc7wyNI7RRvaFthzxdNPblA5hyQ23RdSVtWtgIMMW3agpvA0jg+LlJxqVcFs1XShjA3gso346SXBltievVNMtkMyPqd5OlsX3bZ9k8fMT7m1qIRb1bvH2uuZ+/1e9b0e7n2xAjY6YncBR2tcCPuXbOwXCxmZpno7zpOhsMNPhe6zfMj/F2/75jryXfrt22GzM1Cig/OpoX1rQKVjAg2dRv55c0PdMyCLP7Rs82GHQlUO2TCrj5xYwYp6ALYW0w6OEjXQPoa0QUQsA== 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-SenderADCheck; bh=G/XvKrGpkHmmu6GGZ6lOswxLD/Sqvg27tPfHZ+Wt4vw=; b=lI9NFVuyxTnlnL0qMJOv0046J7lJUsJDlgXpajsA1QsTIrZxr0Qmvn+sKg23dMU1L3S0+S3JckMmNrJ+s0TR4hMjdeSdm7VA85Iox4A9KofMjJjR7dT99IvjRxfa/rexBmg58633PzSXuYYgg6yhcG5foORNkypIxUZ23eDaD47lmP7YVspSaFpUq5R+2iMJtWy9ONczFiJeOGYki7+nwkjQdR/FMC+/9xJTBHYtVZxvkAJwt3ECL2H6LqrEHVyHQz+sQaEHKmfSe7Bzp6VlStEvP9Bgy0WH7v+EJBxZLCuQL47n93frqGt5s4hYo8ZQfengRdfSr0VWXTVh2G0dTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G/XvKrGpkHmmu6GGZ6lOswxLD/Sqvg27tPfHZ+Wt4vw=; b=LRh6ClpRMCU/9gosy4OAahLadoBHEfMTqRS+J5lljoIUS60PLwSHAkw7N0rrCPC8XOpmsraLivUVaN9Z3azqezrtACq79PVroTvubNKCOh/07I+NSiKBcCFm9SxsZecdXdmREWzhASriMnTKyfoboWjSTs3TD9OqxzGBxVmmhgQ= Received: from DB6PR07CA0061.eurprd07.prod.outlook.com (2603:10a6:6:2a::23) by DB8PR08MB5129.eurprd08.prod.outlook.com (2603:10a6:10:ec::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.22; Wed, 12 Aug 2020 15:23:38 +0000 Received: from DB5EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2a:cafe::2b) by DB6PR07CA0061.outlook.office365.com (2603:10a6:6:2a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.10 via Frontend Transport; Wed, 12 Aug 2020 15:23:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT059.mail.protection.outlook.com (10.152.21.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3283.16 via Frontend Transport; Wed, 12 Aug 2020 15:23:38 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Wed, 12 Aug 2020 15:23:36 +0000 Received: from E107187.Arm.com (10.57.41.222) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2044.4 via Frontend Transport; Wed, 12 Aug 2020 15:23:35 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , Subject: [PATCH v1 21/30] DynamicTablesPkg: AML Codegen Date: Wed, 12 Aug 2020 16:22:27 +0100 Message-ID: <20200812152236.31164-22-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200812152236.31164-1-sami.mujawar@arm.com> References: <20200812152236.31164-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e27f8d63-09cb-4232-6ba4-08d83ed3b429 X-MS-TrafficTypeDiagnostic: DB8PR08MB5129:|AM6PR08MB4310: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: sgWPQMPCMZsaRYuzwRxGDC/zKzl/DRNNCYDA+aO4wW/usSBj+AanYDNNGo+QmwACvqfGTY3vbKLzZeTE7DQGmYqiiSmKGmRTwcBzL/julYQmOHzPuRvRocDC5ponvfLtX++xI27hum7z8Gk/6Z50ei2CKfQi/GzpruLkAQDjJeJw80xNNBSQGUhsPi/H4+mJZgsoq6Gxfy8DNhwf425Fls+PxxJQZYTIWKkVkpWcPi9A0HJcdOr3ZN684U007Jr9c6On1mq+khWSnLmdmTMgnLP+lacrfgx7whieWLZLbPbstRZPKnTgPZZJqg6bbh+0qKCfcrwo5qgyUHaQs7FHTsFEjcXBaZxnKftcIRI0yxDLZ8TevwzMgk2i7KEr5uwJ0ZWZ6igiAdJerb7AflttPQ== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(136003)(346002)(396003)(39860400002)(376002)(46966005)(2906002)(36756003)(8936002)(82740400003)(30864003)(316002)(54906003)(4326008)(47076004)(5660300002)(6916009)(1076003)(70206006)(70586007)(81166007)(7696005)(26005)(2616005)(186003)(82310400002)(86362001)(44832011)(478600001)(83380400001)(8676002)(356005)(426003)(6666004)(336012);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5129 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: cee7da57-d20f-4c80-7fec-08d83ed3afea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GlKfnLJ7y9aE9pr+jB5YuBCbvoI6UTocPN//pn4f1ra90q0cgyC3cnHxlyePDh39cvgEppSMGwW/Z7Qh9vwW5F8wepqHd0ptoG3xsbCm6Dd3chMgGwQ4NPlmqGOKfDeSf4ke4BAdeH3HvEgmshC41hArCPCyvj81R/5JTw8KIh51Yn45FvC6ARJkEGU4LgvVU3luySYeeZ1iPJhp30z54rIAsh+YONybQqKj6s/Yr1FfE4EFE9vYc+m9x89h8x5Uj7tzlUMvp4DkmPQbmUX2/jK/alu3ypCbrKm0wal+EegHYRUWWB1OFZ5uDZhp3LHc/2wuC7RQL9DToT6+FPZwB6+G3k3cPI2YsbQZy0soZfZSg86u86XFjUMptQMLaThVBHHr2v6goIwaxex9NL3qPg== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(136003)(346002)(376002)(396003)(39860400002)(46966005)(30864003)(70206006)(5660300002)(186003)(316002)(1076003)(478600001)(8936002)(86362001)(70586007)(26005)(54906003)(36906005)(4326008)(36756003)(7696005)(2906002)(8676002)(336012)(44832011)(2616005)(426003)(6666004)(82740400003)(47076004)(81166007)(83380400001)(82310400002)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2020 15:23:45.3980 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e27f8d63-09cb-4232-6ba4-08d83ed3b429 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4310 Content-Type: text/plain From: Pierre Gondois AML Codegen is a Dynamic AML technique that facilitates generation of small segments of AML code. The AML code generated using AML Codegen is represented as nodes in the AML Tree. Some examples where AML Codegen can be used are: - AML Codegen APIs can be used to generate a simple AML tree. - An AML template can be parsed to create an AML tree. This AML Tree can be searched to locate a node that needs updating. The AML Codegen APIs can be used to attach new AML nodes. - A combination of AML Fixup and AML Codegen can be used to generate an AML tree. The AML tree can then be serialised as a Definition Block table. Following AML Codegen APIs are implemented: - AmlCodeGenDefinitionBlock() - AmlCodeGenScope() - AmlCodeGenNameString() - AmlCodeGenNameInteger() - AmlCodeGenDevice() These AML Codegen APIs in combination with AML Resource Data Codegen APIs can be used to generate a simple AML tree. Signed-off-by: Pierre Gondois Signed-off-by: Sami Mujawar --- DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 701 ++++++++++++++++++++ 1 file changed, 701 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c new file mode 100644 index 0000000000000000000000000000000000000000..d6d9f5dfe839aa8ef79153459ec9d2c2ffe72316 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -0,0 +1,701 @@ +/** @file + AML Code Generation. + + Copyright (c) 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +/** Utility function to link a node when returning from a CodeGen function. + + @param [in] Node Newly created node. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created object node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +LinkNode ( + IN AML_OBJECT_NODE * Node, + IN AML_NODE_HEADER * ParentNode, + IN AML_OBJECT_NODE ** NewObjectNode + ) +{ + EFI_STATUS Status; + + if (NewObjectNode != NULL) { + *NewObjectNode = Node; + } + + // Add RdNode as the last element. + if (ParentNode != NULL) { + Status = AmlVarListAddTail (ParentNode, (AML_NODE_HEADER*)Node); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } + + return EFI_SUCCESS; +} + +/** AML code generation for DefinitionBlock. + + Create a Root Node handle. + It is the caller's responsibility to free the allocated memory + with the AmlDeleteTree function. + + AmlCodeGenDefinitionBlock (TableSignature, OemID, TableID, OEMRevision) is + equivalent to the following ASL code: + DefinitionBlock (AMLFileName, TableSignature, ComplianceRevision, + OemID, TableID, OEMRevision) {} + with the ComplianceRevision set to 2 and the AMLFileName is ignored. + + @param[in] TableSignature 4-character ACPI signature. + Must be 'DSDT' or 'SSDT'. + @param[in] OemId 6-character string OEM identifier. + @param[in] OemTableId 8-character string OEM table identifier. + @param[in] OemRevision OEM revision number. + @param[out] DefinitionBlockTerm The ASL Term handle representing a + Definition Block. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenDefinitionBlock ( + IN CONST CHAR8 * TableSignature, + IN CONST CHAR8 * OemId, + IN CONST CHAR8 * OemTableId, + IN UINT32 OemRevision, + OUT AML_ROOT_NODE ** NewRootNode + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER AcpiHeader; + + if ((TableSignature == NULL) || + (OemId == NULL) || + (OemTableId == NULL) || + (NewRootNode == NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CopyMem (&AcpiHeader.Signature, TableSignature, 4); + AcpiHeader.Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER); + AcpiHeader.Revision = 2; + CopyMem (&AcpiHeader.OemId, OemId, 6); + CopyMem (&AcpiHeader.OemTableId, OemTableId, 8); + AcpiHeader.OemRevision = OemRevision; + AcpiHeader.CreatorId = TABLE_GENERATOR_CREATOR_ID_ARM; + AcpiHeader.CreatorRevision = CREATE_REVISION (1, 0); + + Status = AmlCreateRootNode (&AcpiHeader, NewRootNode); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** AML code generation for a String object node. + + @param [in] String Pointer to a NULL terminated string. + @param [out] NewObjectNode If success, contains the created + String object node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenString ( + IN CHAR8 * String, + OUT AML_OBJECT_NODE ** NewObjectNode + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + AML_DATA_NODE * DataNode; + + if ((String == NULL) || + (NewObjectNode == NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ObjectNode = NULL; + DataNode = NULL; + + Status = AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_STRING_PREFIX, 0), + 0, + &ObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCreateDataNode ( + EAmlNodeDataTypeString, + (UINT8*)String, + (UINT32)AsciiStrLen (String) + 1, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status = AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm0, + (AML_NODE_HEADER*)DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)DataNode); + goto error_handler; + } + + *NewObjectNode = ObjectNode; + return Status; + +error_handler: + if (ObjectNode != NULL) { + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + + return Status; +} + +/** AML code generation for an Integer object node. + + @param [in] Integer Integer of the Integer object node. + @param [out] NewObjectNode If success, contains the created + Integer object node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenInteger ( + IN UINT64 Integer, + OUT AML_OBJECT_NODE ** NewObjectNode + ) +{ + EFI_STATUS Status; + INT8 ValueWidthDiff; + + if (NewObjectNode == NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Create an object node containing Zero. + Status = AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_ZERO_OP, 0), + 0, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Update the object node with integer value. + Status = AmlNodeSetIntegerValue (*NewObjectNode, Integer, &ValueWidthDiff); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)*NewObjectNode); + } + + return Status; +} + +/** AML code generation for a Name object node. + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + This input string is copied. + @param [in] Object Object associated to the NameString. + @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. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenName ( + IN CONST CHAR8 * NameString, + IN AML_OBJECT_NODE * Object, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + AML_DATA_NODE * DataNode; + CHAR8 * AmlNameString; + UINT32 AmlNameStringSize; + + if ((NameString == NULL) || + (Object == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ObjectNode = NULL; + DataNode = NULL; + AmlNameString = NULL; + + Status = ConvertAslNameToAmlName (NameString, &AmlNameString); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_NAME_OP, 0), + 0, + &ObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateDataNode ( + EAmlNodeDataTypeNameString, + (UINT8*)AmlNameString, + AmlNameStringSize, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + Status = AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm0, + (AML_NODE_HEADER*)DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)DataNode); + goto error_handler2; + } + + Status = AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm1, + (AML_NODE_HEADER*)Object + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + Status = LinkNode ( + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + // Free AmlNameString before returning as it is copied + // in the call to AmlCreateDataNode(). + goto error_handler1; + +error_handler2: + if (ObjectNode != NULL) { + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + +error_handler1: + if (AmlNameString != NULL) { + FreePool (AmlNameString); + } + + return Status; +} + +/** AML code generation for a Name object node, containing a String. + + AmlCodeGenNameString ("_HID", "HID0000", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(_HID, "HID0000") + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] String NULL terminated String to associate to the + NameString. + @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 +AmlCodeGenNameString ( + IN CONST CHAR8 * NameString, + IN CHAR8 * String, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + + if ((NameString == NULL) || + (String == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status = AmlCodeGenString (String, &ObjectNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCodeGenName ( + NameString, + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + + return Status; +} + +/** AML code generation for a Name object node, containing an Integer. + + AmlCodeGenNameInteger ("_UID", 1, ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(_UID, One) + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] Integer Integer to associate to the NameString. + @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 +AmlCodeGenNameInteger ( + IN CONST CHAR8 * NameString, + IN UINT64 Integer, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + + if ((NameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status = AmlCodeGenInteger (Integer, &ObjectNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCodeGenName ( + NameString, + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + + return Status; +} + +/** AML code generation for a Device object node. + + AmlCodeGenDevice ("COM0", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Device(COM0) {} + + @param [in] NameString The new Device's name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @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 +AmlCodeGenDevice ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + AML_DATA_NODE * DataNode; + CHAR8 * AmlNameString; + UINT32 AmlNameStringSize; + + if ((NameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ObjectNode = NULL; + DataNode = NULL; + AmlNameString = NULL; + + Status = ConvertAslNameToAmlName (NameString, &AmlNameString); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_EXT_OP, AML_EXT_DEVICE_OP), + AmlNameStringSize + AmlComputePkgLengthWidth (AmlNameStringSize), + &ObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateDataNode ( + EAmlNodeDataTypeNameString, + (UINT8*)AmlNameString, + AmlNameStringSize, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + Status = AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm0, + (AML_NODE_HEADER*)DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)DataNode); + goto error_handler2; + } + + Status = LinkNode ( + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + // Free AmlNameString before returning as it is copied + // in the call to AmlCreateDataNode(). + goto error_handler1; + +error_handler2: + if (ObjectNode != NULL) { + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + +error_handler1: + if (AmlNameString != NULL) { + FreePool (AmlNameString); + } + + return Status; +} + +/** AML code generation for a Scope object node. + + AmlCodeGenScope ("_SB", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Scope(_SB) {} + + @param [in] NameString The new Scope's name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @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 +AmlCodeGenScope ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ObjectNode; + AML_DATA_NODE * DataNode; + CHAR8 * AmlNameString; + UINT32 AmlNameStringSize; + + if ((NameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ObjectNode = NULL; + DataNode = NULL; + AmlNameString = NULL; + + Status = ConvertAslNameToAmlName (NameString, &AmlNameString); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateObjectNode ( + AmlGetByteEncodingByOpCode (AML_SCOPE_OP, 0), + AmlNameStringSize + AmlComputePkgLengthWidth (AmlNameStringSize), + &ObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler1; + } + + Status = AmlCreateDataNode ( + EAmlNodeDataTypeNameString, + (UINT8*)AmlNameString, + AmlNameStringSize, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + Status = AmlSetFixedArgument ( + ObjectNode, + EAmlParseIndexTerm0, + (AML_NODE_HEADER*)DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)DataNode); + goto error_handler2; + } + + Status = LinkNode ( + ObjectNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler2; + } + + // Free AmlNameString before returning as it is copied + // in the call to AmlCreateDataNode(). + goto error_handler1; + +error_handler2: + if (ObjectNode != NULL) { + AmlDeleteTree ((AML_NODE_HEADER*)ObjectNode); + } + +error_handler1: + if (AmlNameString != NULL) { + FreePool (AmlNameString); + } + + return Status; +} -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'