From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.55]) by mx.groups.io with SMTP id smtpd.web11.17175.1597245814818363344 for ; Wed, 12 Aug 2020 08:23:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=0VRQ1oLK; spf=pass (domain: arm.com, ip: 40.107.8.55, 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=k/oYY8eNZsVHxDRYVgfp5/qjKLTEfvOJhuQS0SNB6VA=; b=0VRQ1oLKQKAgcw/UGCd2cb2tfhumIYqhvFPjXHcKickZxxZnsJETZYlYL3vS4CkUKYW2yXR4W5h/dhtU+CMiJ7YlMFwI2PBfOVDG9RJZ39ndyFaUp5wJToH0fZG6j8v+ix1bKYSUDkms4bAvGOYsLoybtjIi2AFsEHBIumE0ARU= Received: from AM5P194CA0023.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::33) by DBBPR08MB4425.eurprd08.prod.outlook.com (2603:10a6:10:cc::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16; Wed, 12 Aug 2020 15:23:31 +0000 Received: from VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:8f:cafe::e5) by AM5P194CA0023.outlook.office365.com (2603:10a6:203:8f::33) 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:31 +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 VE1EUR03FT044.mail.protection.outlook.com (10.152.19.106) 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:31 +0000 Received: ("Tessian outbound bac899b43a54:v64"); Wed, 12 Aug 2020 15:23:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a752c14dc4ed07a7 X-CR-MTA-TID: 64aa7808 Received: from a4fffb865fb6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 41D774C2-4A5C-45CA-892E-7409C0292015.1; Wed, 12 Aug 2020 15:23:25 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a4fffb865fb6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 12 Aug 2020 15:23:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f8bm70BUNNZ8cjHagfVs5IoN1uZEN8dRhCOs4mXhyjGSO1FcIDiLIzATh00YBEhtp8KjZ3aHiaVgT2PevNHUcGBd49YTy+03rVbD1C64D92dcEhb+GlxMzJH5Ep456uUOoQ4oesNoxKKR86x3o8FQDAXTuUI6PmqzIdeDbLbXynngysVnzw3uFSi63M74GJyHzARP5PwxynHcV85u1AdpSkHOlHb/rKhlSl1Fx+ToiIJO+rgPBdBnmLQxEMr2lrCBJAmkC7H8c1UdmtcNEJYG2K+W1ztg0Dx3UrE9Z1Uss9O/lgcwjHUeDDHDEfgqAWOi7jsKLblNawwOUFXVyhKPw== 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=k/oYY8eNZsVHxDRYVgfp5/qjKLTEfvOJhuQS0SNB6VA=; b=cyIHKsImlQPYY7yCYTFiA2ZbxDB4tvnobQM00IHQYBw/teIt23bQK8UcCS0Q5BmmXie+/8NNgzNNYbrQ/b+AxYm1AbFu7BvcvscnDmzu/ohm3h7rDonfTxHuvrU/KmVT35HGBFBfl9LPgHmKYDxqI2Gw/LF/ofDdUYTcjPMlYpL7Zi9XN3dGYCmp6REqXF7XIFCZCDzuw23m1p7sJarH76btC4dDxOn0ctJONbc4cFK/XAPEtK+8qVHq4POaxuUl8gy4TAoCgEX9+9SVAB+60bBjyU2JkR1RC8VPzBBDMd9aXQBWHLq1YBX27SOZgZUb8iPOiNYKRzjK0gjuSF+egg== 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=k/oYY8eNZsVHxDRYVgfp5/qjKLTEfvOJhuQS0SNB6VA=; b=0VRQ1oLKQKAgcw/UGCd2cb2tfhumIYqhvFPjXHcKickZxxZnsJETZYlYL3vS4CkUKYW2yXR4W5h/dhtU+CMiJ7YlMFwI2PBfOVDG9RJZ39ndyFaUp5wJToH0fZG6j8v+ix1bKYSUDkms4bAvGOYsLoybtjIi2AFsEHBIumE0ARU= Received: from AM5PR0602CA0011.eurprd06.prod.outlook.com (2603:10a6:203:a3::21) by DB8PR08MB5514.eurprd08.prod.outlook.com (2603:10a6:10:fa::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.15; Wed, 12 Aug 2020 15:23:24 +0000 Received: from AM5EUR03FT011.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::c8) by AM5PR0602CA0011.outlook.office365.com (2603:10a6:203:a3::21) 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:24 +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 AM5EUR03FT011.mail.protection.outlook.com (10.152.16.152) 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:24 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2044.4; Wed, 12 Aug 2020 15:23:24 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Wed, 12 Aug 2020 15:23:22 +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:22 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , Subject: [PATCH v1 13/30] DynamicTablesPkg: AML serialise interface Date: Wed, 12 Aug 2020 16:22:19 +0100 Message-ID: <20200812152236.31164-14-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: 2f79708c-32c3-43e0-4ee7-08d83ed3aba9 X-MS-TrafficTypeDiagnostic: DB8PR08MB5514:|DBBPR08MB4425: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:4125;OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: r8TRaMKFyV5N0+ZMWD+DblR542UZCfbcao3a2aZIErMpTXDEQceGhHaTOdW6yw6CdGsX3Gr++2YRBVnIHcpyQ4sWO4IcWnQ8s+mP62s9FvpH/PyBeszKjT6vZOXSNgXNlScbtdBwo93pQiSgBibZ6cWf6J60FgIxp3YEiN9+Iri8e3iiP3WroQ33ji3muMqESzjV2TtdU0l+QQz8SXd5iFHBF0pH6z8VyTG9IBklKbuGwSdNqNl7bUF0IEoC410wugvxxuHhSqItbW/ovMIBCMRw5GQnOUDhQT+XqzWgccx+u4GBQTJgRE39jFH5XvJokTbn//GHpAsBquBm6upyzcif5krRHY3kkTpvMhyQ9jHbPlq+AD+EQAqR21c26n8Q7lQDg/UywWw0BkQ9/UeHdA== 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;SFS:(4636009)(396003)(346002)(376002)(136003)(39860400002)(46966005)(36756003)(81166007)(44832011)(86362001)(54906003)(5660300002)(82310400002)(2906002)(426003)(6666004)(1076003)(2616005)(26005)(8936002)(8676002)(7696005)(4326008)(186003)(336012)(356005)(70206006)(316002)(83380400001)(82740400003)(478600001)(70586007)(6916009)(47076004);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5514 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 6b768dcd-8506-4335-2931-08d83ed3a7b6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ETVoDEX9gzttYSoqGuxG4a6w5q1fLoMFt9KtCrGaG+UsbGcxSgdtt0J9fo8J3StAB6+JKtbHESiQd1407222gjKca0fQoHFJ+qtN9/SFIbSzgh7AD4RKpKXYmsGf0A6EWK60WBAAD5S5iv9KdOnwa5jtwN/dVPcJ/LZFBw0TiGBjmTg1rOeNHdBHTb4O+RT+17rFy8wSgNBHi9OQUgFbep1bTC1FnSFOFu7Amr/qm1aIjoT1tjGnzSB098BJEp7Ebou8CSiFz7WQsWCiHdJgyYrblyCK6yCZ4gvhAQF849Wz3fm7xgmrdPyjrmKTpRax5ryJiSkrXcclnQXnXFv9dHQIRfEg4NUhJYfQNo2D05Jj6mq82SJtY8CzPza0vT0uRyGvDRtWIQKpmnQgb5lATA== 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)(346002)(396003)(376002)(136003)(39860400002)(46966005)(82310400002)(478600001)(6666004)(8676002)(2906002)(54906003)(44832011)(336012)(47076004)(82740400003)(81166007)(426003)(8936002)(70586007)(7696005)(2616005)(70206006)(86362001)(316002)(4326008)(186003)(83380400001)(1076003)(36906005)(36756003)(5660300002)(26005)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2020 15:23:31.0833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f79708c-32c3-43e0-4ee7-08d83ed3aba9 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: VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4425 Content-Type: text/plain From: Pierre Gondois AML Fixup and AML Codegen facilitate dynamic generation of Definition Block tables. The AML byte stream that is generated is represented in an AML tree. Once the AML table generation is completed, the AML tree needs to be serialised for installing as an ACPI table. The AML serialise interface implements the functionality to iterate the nodes in the AML tree, collating the AML bytecode, computing the checksum and writing the AML byte stream to a buffer that represents the Definition Block table. Signed-off-by: Pierre Gondois Co-authored-by: Sami Mujawar --- DynamicTablesPkg/Library/Common/AmlLib/Serialize/AmlSerialize.c | 324 ++++++++++++++++++++ 1 file changed, 324 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Serialize/AmlSerialize.c b/DynamicTablesPkg/Library/Common/AmlLib/Serialize/AmlSerialize.c new file mode 100644 index 0000000000000000000000000000000000000000..2a47c229d7480128ed0f782efa009c7a86f4a492 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/Serialize/AmlSerialize.c @@ -0,0 +1,324 @@ +/** @file + AML Serialize. + + Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include +#include +#include + +/** Callback function to copy the AML bytecodes contained in a node + to the Stream stored in the Context. + The SDT header data contained in the root node is not serialized + by this function. + + @param [in] Node Pointer to the node to copy the AML bytecodes + from. + @param [in, out] Context Contains a forward Stream to write to. + (AML_STREAM*)Context. + @param [in, out] Status At entry, contains the status returned by the + last call to this exact function during the + enumeration. + As exit, contains the returned status of the + call to this function. + Optional, can be NULL. + + @retval TRUE if the enumeration can continue or has finished without + interruption. + @retval FALSE if the enumeration needs to stopped or has stopped. +**/ +STATIC +BOOLEAN +EFIAPI +AmlSerializeNodeCallback ( + IN AML_NODE_HEADER * Node, + IN OUT VOID * Context, OPTIONAL + IN OUT EFI_STATUS * Status OPTIONAL + ) +{ + EFI_STATUS Status1; + + CONST AML_DATA_NODE * DataNode; + CONST AML_OBJECT_NODE * ObjectNode; + AML_STREAM * FStream; + + // Bytes needed to store OpCode[1] + SubOpcode[1] + MaxPkgLen[4] = 6 bytes. + UINT8 ObjectNodeInfoArray[6]; + UINT32 Index; + BOOLEAN ContinueEnum; + + CONST AML_OBJECT_NODE * ParentNode; + EAML_PARSE_INDEX IndexPtr; + + if (!IS_AML_NODE_VALID (Node) || + (Context == NULL)) { + ASSERT (0); + Status1 = EFI_INVALID_PARAMETER; + ContinueEnum = FALSE; + goto error_handler; + } + + // Ignore the second fixed argument of method invocation nodes + // as the information stored there (the argument count) is not in the + // ACPI specification. + ParentNode = (CONST AML_OBJECT_NODE*)AmlGetParent ((AML_NODE_HEADER*)Node); + if (IS_AML_OBJECT_NODE (ParentNode) && + AmlNodeCompareOpCode (ParentNode, AML_METHOD_INVOC_OP, 0) && + AmlIsNodeFixedArgument (Node, &IndexPtr)) { + if (IndexPtr == EAmlParseIndexTerm1) { + if (Status != NULL) { + *Status = EFI_SUCCESS; + } + return TRUE; + } + } + + Status1 = EFI_SUCCESS; + ContinueEnum = TRUE; + FStream = (AML_STREAM*)Context; + + if (IS_AML_DATA_NODE (Node)) { + // Copy the content of the Buffer for a DataNode. + DataNode = (AML_DATA_NODE*)Node; + Status1 = AmlStreamWrite ( + FStream, + DataNode->Buffer, + DataNode->Size + ); + if (EFI_ERROR (Status1)) { + ASSERT (0); + ContinueEnum = FALSE; + goto error_handler; + } + + } else if (IS_AML_OBJECT_NODE (Node) && + !AmlNodeHasAttribute ( + (CONST AML_OBJECT_NODE*)Node, + AML_IS_PSEUDO_OPCODE)) { + // Ignore pseudo-opcodes as they are not part of the + // ACPI specification. + + ObjectNode = (AML_OBJECT_NODE*)Node; + + Index = 0; + // Copy the opcode(s). + ObjectNodeInfoArray[Index++] = ObjectNode->AmlByteEncoding->OpCode; + if (ObjectNode->AmlByteEncoding->OpCode == AML_EXT_OP) { + ObjectNodeInfoArray[Index++] = ObjectNode->AmlByteEncoding->SubOpCode; + } + + // Copy the PkgLen. + if (AmlNodeHasAttribute (ObjectNode, AML_HAS_PKG_LENGTH)) { + Index += AmlSetPkgLength ( + ObjectNode->PkgLen, + &ObjectNodeInfoArray[Index] + ); + } + + Status1 = AmlStreamWrite ( + FStream, + ObjectNodeInfoArray, + Index + ); + if (EFI_ERROR (Status1)) { + ASSERT (0); + ContinueEnum = FALSE; + goto error_handler; + } + } // IS_AML_OBJECT_NODE (Node) + +error_handler: + if (Status != NULL) { + *Status = Status1; + } + return ContinueEnum; +} + +/** Serialize a tree to create an ACPI DSDT/SSDT table. + + If: + - the content of BufferSize is >= to the size needed to serialize the + definition block; + - Buffer is not NULL; + first serialize the ACPI DSDT/SSDT header from the root node, + then serialize the AML blob from the rest of the tree. + + The content of BufferSize is always updated to the size needed to + serialize the definition block. + + @param [in] RootNode Pointer to a root node. + @param [in] Buffer Buffer to write the DSDT/SSDT table to. + If Buffer is NULL, the size needed to + serialize the DSDT/SSDT table is returned + in BufferSize. + @param [in, out] BufferSize Pointer holding the size of the Buffer. + Its content is always updated to the size + needed to serialize the DSDT/SSDT table. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_BUFFER_TOO_SMALL No space left in the buffer. +**/ +EFI_STATUS +EFIAPI +AmlSerializeTree ( + IN AML_ROOT_NODE * RootNode, + IN UINT8 * Buffer, OPTIONAL + IN OUT UINT32 * BufferSize + ) +{ + EFI_STATUS Status; + AML_STREAM FStream; + UINT32 TableSize; + + if (!IS_AML_ROOT_NODE (RootNode) || + (BufferSize == NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Compute the total size of the AML blob. + Status = AmlComputeSize ( + (CONST AML_NODE_HEADER*)RootNode, + &TableSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the size of the ACPI header. + TableSize += (UINT32)sizeof (EFI_ACPI_DESCRIPTION_HEADER); + + // Check the size against the SDT header. + // The Length field in the SDT Header is updated if the tree has + // been modified. + if (TableSize != RootNode->SdtHeader->Length) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Buffer is not big enough, or NULL. + if ((TableSize < *BufferSize) || (Buffer == NULL)) { + *BufferSize = TableSize; + return EFI_SUCCESS; + } + + // Initialize the stream to the TableSize that is needed. + Status = AmlStreamInit ( + &FStream, + Buffer, + TableSize, + EAmlStreamDirectionForward + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Serialize the header. + Status = AmlStreamWrite ( + &FStream, + (UINT8*)RootNode->SdtHeader, + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = EFI_SUCCESS; + AmlEnumTree ( + (AML_NODE_HEADER*)RootNode, + AmlSerializeNodeCallback, + (VOID*)&FStream, + &Status + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Update the checksum. + return AcpiPlatformChecksum ((EFI_ACPI_DESCRIPTION_HEADER*)Buffer); +} + +/** Serialize an AML definition block. + + This functions allocates memory with the "AllocateZeroPool ()" + function. This memory is used to serialize the AML tree and is + returned in the Table. + + @param [in] RootNode Root node of the tree. + @param [out] Table On return, hold the serialized + definition block. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlSerializeDefinitionBlock ( + IN AML_ROOT_NODE * RootNode, + OUT EFI_ACPI_DESCRIPTION_HEADER ** Table + ) +{ + EFI_STATUS Status; + UINT8 * TableBuffer; + UINT32 TableSize; + + if (!IS_AML_ROOT_NODE (RootNode) || + (Table == NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + TableBuffer = NULL; + TableSize = 0; + + // Get the size of the SSDT table. + Status = AmlSerializeTree ( + RootNode, + TableBuffer, + &TableSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + TableBuffer = (UINT8*)AllocateZeroPool (TableSize); + if (TableBuffer == NULL) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to allocate memory for Table Buffer." + )); + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Serialize the tree to a SSDT table. + Status = AmlSerializeTree ( + RootNode, + TableBuffer, + &TableSize + ); + if (EFI_ERROR (Status)) { + FreePool (TableBuffer); + ASSERT (0); + } else { + // Save the allocated Table buffer in the table list + *Table = (EFI_ACPI_DESCRIPTION_HEADER*)TableBuffer; + } + + return Status; +} -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'