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.48]) by mx.groups.io with SMTP id smtpd.web12.16977.1597245817349588238 for ; Wed, 12 Aug 2020 08:23:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=veAM0yX7; spf=pass (domain: arm.com, ip: 40.107.8.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=DpXpBZvpFmWiljNFnAJrKkB1C8sZYIa1Cls6IKw/gqM=; b=veAM0yX7Ur1nH/P2r2HHkS4dfagjOGed3V2wEFeTaMJ4dXAJI0nKQ5gZcYfEPGsacIKY1EFtISyTdPkaxR4rYdbY4C7ZpAmscVYZQxxrDZVgCA+gsXc+MwLmutupLHphGjBgKwzZ/Lu6b9bDBCTMP7h4xpYuZZyeXw/QtuohENo= Received: from DB6PR0202CA0012.eurprd02.prod.outlook.com (2603:10a6:4:29::22) by PR3PR08MB5787.eurprd08.prod.outlook.com (2603:10a6:102:90::24) 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:34 +0000 Received: from DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:29:cafe::df) by DB6PR0202CA0012.outlook.office365.com (2603:10a6:4:29::22) 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:34 +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 DB5EUR03FT048.mail.protection.outlook.com (10.152.21.28) 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:34 +0000 Received: ("Tessian outbound a0bffebca527:v64"); Wed, 12 Aug 2020 15:23:34 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 95ec4a0c4bf8f715 X-CR-MTA-TID: 64aa7808 Received: from e406bd03f346.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id EB05D293-B403-4B74-BFBA-45EDBD767A24.1; Wed, 12 Aug 2020 15:23:28 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e406bd03f346.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 12 Aug 2020 15:23:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvf2bWyIjMuIf0ctrCFAil1w6TYUxSuc4WbOQeesu0f1U6pYEzroLWx4qYHD+Yw/1Et1xpcoMJuhbYMeFSPjnUDsmE+LMxdU2Y3xWZBRpi5vbPo9XyKUZjQwIX12Dz/Bu+FmuDbzKahqYG3cD0tDpCz0c1CRAFTabP6DpHJWP4AIze4WhLkhMou82sjnacsq8T4WBO0CVtsCCbxLxx6y1MH/TDlDbsUQNtcVG0+y8cWxMCoVE6TBReDvai5fJhHWhzFIKHXB5WgrgvymQEBT1baUBPjJqq4dU1g/svz7icLMfIqaGWmFyuHPqK+Fd2SyxPujmKSagyzWuuXsdJETEQ== 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=DpXpBZvpFmWiljNFnAJrKkB1C8sZYIa1Cls6IKw/gqM=; b=bKvnrLfP66ZkDA5nvJee1W+36pjCkG88giIklwHXyeX/YEs8RFNoBC79/fXloo7LJg9qzD7kk4ZcJFdM++gPuLlTL23Vv1cIblsi+JhkH4uOUGJnKboULOmDMQqeO47rV2VWD1pZwrwbwgQvNPFy1jcyazfffW5Xvh+6kXXW/at841aOpTiPfTriwZzKM4zk4M98BH2jDTg5+39INqghfecvHfal0rvg+OSva2+3kExvAAK9d4Of0BoPgboTVp1HnP8NaqcAxLRFJjQU0sXQ1XKOZw+NUB0MrnybSlWq+wC8hqlywgB2cEbh/e2TSmohGiJQDcr+tFX4praoJpkGsA== 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=DpXpBZvpFmWiljNFnAJrKkB1C8sZYIa1Cls6IKw/gqM=; b=veAM0yX7Ur1nH/P2r2HHkS4dfagjOGed3V2wEFeTaMJ4dXAJI0nKQ5gZcYfEPGsacIKY1EFtISyTdPkaxR4rYdbY4C7ZpAmscVYZQxxrDZVgCA+gsXc+MwLmutupLHphGjBgKwzZ/Lu6b9bDBCTMP7h4xpYuZZyeXw/QtuohENo= Received: from DB6PR0402CA0022.eurprd04.prod.outlook.com (2603:10a6:4:91::32) by AM6PR08MB3381.eurprd08.prod.outlook.com (2603:10a6:20b:43::26) 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:26 +0000 Received: from DB5EUR03FT054.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:91:cafe::87) by DB6PR0402CA0022.outlook.office365.com (2603:10a6:4:91::32) 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:26 +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 DB5EUR03FT054.mail.protection.outlook.com (10.152.20.248) 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:26 +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:24 +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:23 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , Subject: [PATCH v1 14/30] DynamicTablesPkg: AML debug logging Date: Wed, 12 Aug 2020 16:22:20 +0100 Message-ID: <20200812152236.31164-15-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: 4a4162f3-c647-4606-5960-08d83ed3ad61 X-MS-TrafficTypeDiagnostic: AM6PR08MB3381:|PR3PR08MB5787: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2958;OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: nUXpgxh0koqwWRDd9YwWrbrogln+CmwkyiLjP1GfC39/PsGCeVR5NFZO6nO3lKVnIA7IN6XQwCibSZ2iUvQaPPGOG/3lqK7K5rmqPAgyIIgYdcoDZ0o8jl+yn1oIAQ7NZLzOKwiIC0ZGwnkVePFrvVfexgjaa1NqehoxPQNT8cGfxyEyLlvKGP57JRhJLEKap7fL2CBt9jnomWVSo2StdTSJWu2UpcsCHXbZVuQczzlchBYqHItij02ld+FIAbsPfjkVjf1eg4W5gOHbxHjlLLsQMB6gM/G6mioH/V70fQ+ZBo+VwBOECkwm2Ihan9XlyFwB1CIbNZzSbiJ25v9OfoXn0jVklakY6ff0kBsbTaobt2+TxCiF+hcEW18yzTgf7tO4vQL8EgHG6/oGbdOyDQ== 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)(396003)(376002)(346002)(39860400002)(136003)(46966005)(6916009)(26005)(336012)(356005)(82310400002)(47076004)(82740400003)(81166007)(186003)(54906003)(316002)(478600001)(36756003)(83380400001)(7696005)(2616005)(8936002)(44832011)(5660300002)(1076003)(30864003)(426003)(86362001)(70206006)(2906002)(70586007)(4326008)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3381 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e8a593e3-d455-490e-ebeb-08d83ed3a8ea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xhMxJEoHme7ROSuQSIHy4i/jRFxalwNejJDZoojYJ7mL2ZLovXp8/XmrP/PDQ82AJbEsqxYVzHUMwfJnk/+6gGdoUF0GpErJCUbagy7QYqkBme/l/rOhF6WT0oj+WmzAcLbppThsgGZRgh9Tlu3/1dTs1+5+IvONXs6NfJL5DYYNTgcBNVKExrRRpH9qHs0TQyFWqbHc6grEvKY9WmZwKzaal1aGvb47Eo/fAqixO7EX3uFEi4PACeTFITY//RPmc1ezVDX0E/b8rfmcbFR6A43Urjyg4VIXXG3IMsrMyJTeP1EbVQwlnG/ds8KWw5FxGrrVOWl/V8rKVnGrV406ZZSWAiyWgaE567kK8465K2NGqzjfExhs1tS0QpglLFWJWzGotKbotNyCw+J0Lznh+A== 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)(396003)(136003)(346002)(39860400002)(376002)(46966005)(26005)(2616005)(186003)(8936002)(81166007)(4326008)(2906002)(82310400002)(47076004)(44832011)(83380400001)(6916009)(7696005)(82740400003)(336012)(426003)(478600001)(70586007)(36756003)(86362001)(1076003)(8676002)(54906003)(70206006)(316002)(30864003)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2020 15:23:34.0705 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a4162f3-c647-4606-5960-08d83ed3ad61 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: DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5787 Content-Type: text/plain From: Pierre Gondois The AML debug print functions enable logging of the operations on the AML tree and the data output. The debug logging functionality is enabled for debug builds when the DEBUG_INFO or DEBUG_VERBOSE mask is enabled in the PCD gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel Signed-off-by: Pierre Gondois Signed-off-by: Sami Mujawar --- DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.c | 546 ++++++++++++++++++++ DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.h | 154 ++++++ 2 files changed, 700 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.c b/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.c new file mode 100644 index 0000000000000000000000000000000000000000..7b11cc8e994903b3a9d2dcfd1241b8a447759717 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.c @@ -0,0 +1,546 @@ +/** @file + AML Print Function. + + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +#include +#include +#include +#include + +#if !defined (MDEPKG_NDEBUG) + +/** String table representing AML Data types as defined by EAML_NODE_DATA_TYPE. +*/ +CONST CHAR8 * NodeDataTypeStrTbl[] = { + "EAmlNodeDataTypeNone", + "EAmlNodeDataTypeReserved1", + "EAmlNodeDataTypeReserved2", + "EAmlNodeDataTypeReserved3", + "EAmlNodeDataTypeReserved4", + "EAmlNodeDataTypeReserved5", + "EAmlNodeDataTypeNameString", + "EAmlNodeDataTypeString", + "EAmlNodeDataTypeUInt", + "EAmlNodeDataTypeRaw", + "EAmlNodeDataTypeResourceData", + "EAmlNodeDataTypeFieldPkgLen", + "EAmlNodeDataTypeMax" +}; + +/** String table representing AML Node types as defined by EAML_NODE_TYPE. +*/ +CONST CHAR8 * NodeTypeStrTbl[] = { + "EAmlNodeUnknown", + "EAmlNodeRoot", + "EAmlNodeObject", + "EAmlNodeData", + "EAmlNodeMax" +}; + +/** Print Size chars at Buffer address. + + @param [in] ErrorLevel Error level for the DEBUG macro. + @param [in] Buffer Buffer containing the chars. + @param [in] Size Number of chars to print. +**/ +VOID +EFIAPI +AmlDbgPrintChars ( + IN UINT32 ErrorLevel, + IN CONST CHAR8 * Buffer, + IN UINT32 Size + ) +{ + UINT32 i; + + if (Buffer == NULL) { + ASSERT (0); + return; + } + + for (i = 0; i < Size; i++) { + DEBUG ((ErrorLevel, "%c", Buffer[i])); + } +} + +/** Print an AML NameSeg. + Don't print trailing underscores ('_'). + + @param [in] Buffer Buffer containing an AML NameSeg. +**/ +VOID +EFIAPI +AmlDbgPrintNameSeg ( + IN CONST CHAR8 * Buffer + ) +{ + if (Buffer == NULL) { + ASSERT (0); + return; + } + + DEBUG ((DEBUG_INFO, "%c", Buffer[0])); + if ((Buffer[1] == AML_NAME_CHAR__) && + (Buffer[2] == AML_NAME_CHAR__) && + (Buffer[3] == AML_NAME_CHAR__)) { + return; + } + DEBUG ((DEBUG_INFO, "%c", Buffer[1])); + if ((Buffer[2] == AML_NAME_CHAR__) && + (Buffer[3] == AML_NAME_CHAR__)) { + return; + } + DEBUG ((DEBUG_INFO, "%c", Buffer[2])); + if (Buffer[3] == AML_NAME_CHAR__) { + return; + } + DEBUG ((DEBUG_INFO, "%c", Buffer[3])); + return; +} + +/** Print an AML NameString. + + @param [in] Buffer Buffer containing an AML NameString. + @param [in] NewLine Print a newline char at the end of the NameString. +**/ +VOID +EFIAPI +AmlDbgPrintNameString ( + IN CONST CHAR8 * Buffer, + IN BOOLEAN NewLine + ) +{ + UINT8 SegCount; + UINT8 Index; + + if (Buffer == NULL) { + ASSERT (0); + return; + } + + // Handle Root and Parent(s). + if (*Buffer == AML_ROOT_CHAR) { + Buffer++; + DEBUG ((DEBUG_INFO, "\\")); + } else if (*Buffer == AML_PARENT_PREFIX_CHAR) { + do { + Buffer++; + DEBUG ((DEBUG_INFO, "^")); + } while (*Buffer == AML_PARENT_PREFIX_CHAR); + } + + // Handle SegCount(s). + if (*Buffer == AML_DUAL_NAME_PREFIX) { + Buffer++; + SegCount = 2; + } else if (*Buffer == AML_MULTI_NAME_PREFIX) { + Buffer++; + // For multi name prefix the seg count is in the second byte. + SegCount = *Buffer; + Buffer++; + } else if (AmlIsLeadNameChar (*Buffer)) { + // Only check the first char first to avoid overflow. + // Then the whole NameSeg can be checked. + if (!AmlIsNameSeg (Buffer)) { + ASSERT (0); + return; + } + SegCount = 1; + } else if (*Buffer == AML_ZERO_OP) { + SegCount = 0; + } else { + // Should not be possible. + ASSERT (0); + return; + } + + if (SegCount != 0) { + AmlDbgPrintNameSeg (Buffer); + Buffer += AML_NAME_SEG_SIZE; + for (Index = 0; Index < SegCount - 1; Index++) { + DEBUG ((DEBUG_INFO, ".")); + AmlDbgPrintNameSeg (Buffer); + Buffer += AML_NAME_SEG_SIZE; + } + } + + if (NewLine) { + DEBUG ((DEBUG_INFO, "\n")); + } + + return; +} + +/** Print the information contained in the header of the Node. + + @param [in] Node Pointer to a node. + @param [in] Level Level of the indentation. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintNodeHeader ( + IN AML_NODE_HEADER * Node, + IN UINT8 Level + ) +{ + if (!IS_AML_NODE_VALID (Node)) { + ASSERT (0); + return; + } + + DEBUG (( + DEBUG_INFO, + "%3d | %-15s | ", + Level, + NodeTypeStrTbl[Node->NodeType] + )); +} + +/** Print fields of a data node. + + @param [in] DataNode Pointer to a data node. + @param [in] Level Level of the indentation. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintDataNode ( + IN AML_DATA_NODE * DataNode, + IN UINT8 Level + ) +{ + UINT32 Idx; + + if (!IS_AML_DATA_NODE (DataNode)) { + ASSERT (0); + return; + } + + AmlDbgPrintNodeHeader ((AML_NODE_HEADER*)DataNode, Level); + + DEBUG ((DEBUG_INFO, "%-36s | ", NodeDataTypeStrTbl[DataNode->DataType])); + DEBUG ((DEBUG_INFO, "0x%04x | ", DataNode->Size)); + + if ((DataNode->DataType == EAmlNodeDataTypeNameString) || + (DataNode->DataType == EAmlNodeDataTypeString)) { + AmlDbgPrintChars ( + DEBUG_INFO, + (CONST CHAR8*)DataNode->Buffer, + DataNode->Size + ); + } else if (DataNode->DataType == EAmlNodeDataTypeUInt) { + switch (DataNode->Size) { + case 1: + { + DEBUG ((DEBUG_INFO, "0x%0x", *((UINT8*)DataNode->Buffer))); + break; + } + case 2: + { + DEBUG ((DEBUG_INFO, "0x%0x", *((UINT16*)DataNode->Buffer))); + break; + } + case 4: + { + DEBUG ((DEBUG_INFO, "0x%0lx", *((UINT32*)DataNode->Buffer))); + break; + } + case 8: + { + DEBUG ((DEBUG_INFO, "0x%0llx", *((UINT64*)DataNode->Buffer))); + break; + } + default: + { + ASSERT (0); + return; + } + } + } else { + // No specific format. + for (Idx = 0; Idx < DataNode->Size; Idx++) { + DEBUG ((DEBUG_INFO, "%02x ", DataNode->Buffer[Idx])); + } + } + + DEBUG ((DEBUG_INFO, "\n")); +} + +/** Print fields of an object node. + + @param [in] ObjectNode Pointer to an object node. + @param [in] Level Level of the indentation. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintObjectNode ( + IN AML_OBJECT_NODE * ObjectNode, + IN UINT8 Level + ) +{ + if (!IS_AML_OBJECT_NODE (ObjectNode)) { + ASSERT (0); + return; + } + + AmlDbgPrintNodeHeader ((AML_NODE_HEADER*)ObjectNode, Level); + + DEBUG ((DEBUG_INFO, "0x%02x | ", ObjectNode->AmlByteEncoding->OpCode)); + DEBUG ((DEBUG_INFO, "0x%02x | ", ObjectNode->AmlByteEncoding->SubOpCode)); + + // Print a string corresponding to the field object OpCode/SubOpCode. + if (AmlNodeHasAttribute (ObjectNode, AML_IS_FIELD_ELEMENT)) { + DEBUG ((DEBUG_INFO, "%-15s ", AmlGetFieldOpCodeStr ( + ObjectNode->AmlByteEncoding->OpCode, + 0 + ))); + } else { + // Print a string corresponding to the object OpCode/SubOpCode. + DEBUG ((DEBUG_INFO, "%-15s | ", AmlGetOpCodeStr ( + ObjectNode->AmlByteEncoding->OpCode, + ObjectNode->AmlByteEncoding->SubOpCode) + )); + } + + DEBUG ((DEBUG_INFO, "%3d | ", ObjectNode->AmlByteEncoding->MaxIndex)); + DEBUG ((DEBUG_INFO, "0x%08x | ", ObjectNode->AmlByteEncoding->Attribute)); + DEBUG ((DEBUG_INFO, "0x%04x | ", ObjectNode->PkgLen)); + if (AmlNodeHasAttribute (ObjectNode, AML_IN_NAMESPACE)) { + AmlDbgPrintNameString ( + AmlNodeGetName ((CONST AML_OBJECT_NODE*)ObjectNode), + FALSE + ); + } + + DEBUG ((DEBUG_INFO, "\n")); +} + +/** Print fields of a root node. + + @param [in] RootNode Pointer to a root node. + @param [in] Level Level of the indentation. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintRootNode ( + IN AML_ROOT_NODE * RootNode, + IN UINT8 Level + ) +{ + if (!IS_AML_ROOT_NODE (RootNode)) { + ASSERT (0); + return; + } + + AmlDbgPrintNodeHeader ((AML_NODE_HEADER*)RootNode, Level); + + DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->Signature)); + DEBUG ((DEBUG_INFO, "0x%08x | ", RootNode->SdtHeader->Length)); + DEBUG ((DEBUG_INFO, "%3d | ", RootNode->SdtHeader->Revision)); + DEBUG ((DEBUG_INFO, "0x%02x | ", RootNode->SdtHeader->Checksum)); + DEBUG (( + DEBUG_INFO, + "%c%c%c%c%c%c | ", + RootNode->SdtHeader->OemId[0], + RootNode->SdtHeader->OemId[1], + RootNode->SdtHeader->OemId[2], + RootNode->SdtHeader->OemId[3], + RootNode->SdtHeader->OemId[4], + RootNode->SdtHeader->OemId[5] + )); + DEBUG ((DEBUG_INFO, "%-16llx | ", RootNode->SdtHeader->OemTableId)); + DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->OemRevision)); + DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->CreatorId)); + DEBUG ((DEBUG_INFO, "%8x", RootNode->SdtHeader->CreatorRevision)); + DEBUG ((DEBUG_INFO, "\n")); +} + +/** Print a header to help interpreting node information. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintTableHeader ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Lvl | Node Type |\n")); + DEBUG (( + DEBUG_INFO, + " | %-15s | Signature| Length | Rev | CSum | OemId | " + "OemTableId | OemRev | CreatorId| CreatorRev\n", + NodeTypeStrTbl[EAmlNodeRoot] + )); + DEBUG (( + DEBUG_INFO, + " | %-15s | Op | SubOp| OpName | MaxI| Attribute | " + "PkgLen | NodeName (opt)\n", + NodeTypeStrTbl[EAmlNodeObject] + )); + DEBUG (( + DEBUG_INFO, + " | %-15s | Data Type | Size | " + "Buffer\n", + NodeTypeStrTbl[EAmlNodeData] + )); + DEBUG (( + DEBUG_INFO, + "---------------------------------------" + "---------------------------------------\n" + )); +} + +/** Recursively print the subtree under the Node. + This is an internal function. + + @param [in] Node Pointer to the root of the subtree to print. + Can be a root/object/data node. + @param [in] Recurse If TRUE, recurse. + @param [in] Level Level in the tree. +**/ +STATIC +VOID +EFIAPI +AmlDbgPrintTreeInternal ( + IN AML_NODE_HEADER * Node, + IN BOOLEAN Recurse, + IN UINT8 Level + ) +{ + AML_NODE_HEADER * ChildNode; + + if (!IS_AML_NODE_VALID (Node)) { + ASSERT (0); + return; + } + + if (IS_AML_DATA_NODE (Node)) { + AmlDbgPrintDataNode ((AML_DATA_NODE*)Node, Level); + return; + } else if (IS_AML_OBJECT_NODE (Node)) { + AmlDbgPrintObjectNode ((AML_OBJECT_NODE*)Node, Level); + } else if (IS_AML_ROOT_NODE (Node)) { + AmlDbgPrintRootNode ((AML_ROOT_NODE*)Node, Level); + } else { + // Should not be possible. + ASSERT (0); + return; + } + + if (!Recurse) { + return; + } + + // Get the first child node. + ChildNode = AmlGetNextSibling (Node, NULL); + while (ChildNode != NULL) { + ASSERT (Level < MAX_UINT8); + AmlDbgPrintTreeInternal (ChildNode, Recurse, (UINT8)(Level + 1)); + ChildNode = AmlGetNextSibling (Node, ChildNode); + } +} + +/** Print Node information. + + @param [in] Node Pointer to the Node to print. + Can be a root/object/data node. +**/ +VOID +EFIAPI +AmlDbgPrintNode ( + IN AML_NODE_HEADER * Node + ) +{ + AmlDbgPrintTableHeader (); + AmlDbgPrintTreeInternal (Node, FALSE, 0); +} + +/** Recursively print the subtree under the Node. + + @param [in] Node Pointer to the root of the subtree to print. + Can be a root/object/data node. +**/ +VOID +EFIAPI +AmlDbgPrintTree ( + IN AML_NODE_HEADER * Node + ) +{ + AmlDbgPrintTableHeader (); + AmlDbgPrintTreeInternal (Node, TRUE, 0); +} + +/** This function performs a raw data dump of the ACPI table. + + @param [in] Ptr Pointer to the start of the table buffer. + @param [in] Length The length of the buffer. +**/ +VOID +EFIAPI +DumpRaw ( + IN CONST UINT8 * Ptr, + IN UINT32 Length + ) +{ + UINT32 ByteCount; + UINT32 PartLineChars; + UINT32 AsciiBufferIndex; + CHAR8 AsciiBuffer[17]; + + ByteCount = 0; + AsciiBufferIndex = 0; + + DEBUG ((DEBUG_VERBOSE, "Address : 0x%p\n", Ptr)); + DEBUG ((DEBUG_VERBOSE, "Length : %lld", Length)); + + while (ByteCount < Length) { + if ((ByteCount & 0x0F) == 0) { + AsciiBuffer[AsciiBufferIndex] = '\0'; + DEBUG ((DEBUG_VERBOSE, " %a\n%08X : ", AsciiBuffer, ByteCount)); + AsciiBufferIndex = 0; + } else if ((ByteCount & 0x07) == 0) { + DEBUG ((DEBUG_VERBOSE, "- ")); + } + + if ((*Ptr >= ' ') && (*Ptr < 0x7F)) { + AsciiBuffer[AsciiBufferIndex++] = *Ptr; + } else { + AsciiBuffer[AsciiBufferIndex++] = '.'; + } + + DEBUG ((DEBUG_VERBOSE, "%02X ", *Ptr++)); + + ByteCount++; + } + + // Justify the final line using spaces before printing + // the ASCII data. + PartLineChars = (Length & 0x0F); + if (PartLineChars != 0) { + PartLineChars = 48 - (PartLineChars * 3); + if ((Length & 0x0F) <= 8) { + PartLineChars += 2; + } + while (PartLineChars > 0) { + DEBUG ((DEBUG_VERBOSE, " ")); + PartLineChars--; + } + } + + // Print ASCII data for the final line. + AsciiBuffer[AsciiBufferIndex] = '\0'; + DEBUG ((DEBUG_VERBOSE, " %a\n\n", AsciiBuffer)); +} + +#endif // MDEPKG_NDEBUG diff --git a/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.h b/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.h new file mode 100644 index 0000000000000000000000000000000000000000..68f4c7416948a20484b6d5448c231add3f1186dd --- /dev/null +++ b/DynamicTablesPkg/Library/Common/AmlLib/AmlDbgPrint/AmlDbgPrint.h @@ -0,0 +1,154 @@ +/** @file + AML Debug Print. + + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef AML_PRINT_H_ +#define AML_PRINT_H_ + +/* This header file does not include internal Node definition, + i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. The node definitions + must be included by the caller file. The function prototypes must + only expose AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE, etc. node + definitions. + This allows to keep the functions defined here both internal and + potentially external. If necessary, any function of this file can + be exposed externally. + The Api folder is internal to the AmlLib, but should only use these + functions. They provide a "safe" way to interact with the AmlLib. +*/ + +#if !defined (MDEPKG_NDEBUG) + +#include + +/** + @defgroup DbgPrintApis Print APIs for debugging. + @ingroup AMLLib + @{ + Print APIs provide a way to print: + - A buffer; + - A (root/object/data) node; + - An AML tree/branch; + - The AML NameSpace from the root node. + @} +*/ + +/** This function performs a raw data dump of the ACPI table. + + @param [in] Ptr Pointer to the start of the table buffer. + @param [in] Length The length of the buffer. +**/ +VOID +EFIAPI +DumpRaw ( + IN CONST UINT8 * Ptr, + IN UINT32 Length + ); + +/** Print Size chars at Buffer address. + + @ingroup DbgPrintApis + + @param [in] ErrorLevel Error level for the DEBUG macro. + @param [in] Buffer Buffer containing the chars. + @param [in] Size Number of chars to print. +**/ +VOID +EFIAPI +AmlDbgPrintChars ( + IN UINT32 ErrorLevel, + IN CONST CHAR8 * Buffer, + IN UINT32 Size + ); + +/** Print an AML NameSeg. + Don't print trailing underscores ('_'). + + @param [in] Buffer Buffer containing an AML NameSeg. +**/ +VOID +EFIAPI +AmlDbgPrintNameSeg ( + IN CONST CHAR8 * Buffer + ); + +/** Print an AML NameString. + + @param [in] Buffer Buffer containing an AML NameString. + @param [in] NewLine Print a newline char at the end of the NameString. +**/ +VOID +EFIAPI +AmlDbgPrintNameString ( + IN CONST CHAR8 * Buffer, + IN BOOLEAN NewLine + ); + +/** Print Node information. + + @ingroup DbgPrintApis + + @param [in] Node Pointer to the Node to print. + Can be a root/object/data node. +**/ +VOID +EFIAPI +AmlDbgPrintNode ( + IN AML_NODE_HANDLE Node + ); + +/** Recursively print the subtree under the Node. + + @ingroup DbgPrintApis + + @param [in] Node Pointer to the root of the subtree to print. + Can be a root/object/data node. +**/ +VOID +EFIAPI +AmlDbgPrintTree ( + IN AML_NODE_HANDLE Node + ); + +/** Print the absolute pathnames in the AML namespace of + all the nodes in the tree starting from the Root node. + + @ingroup DbgPrintApis + + @param [in] RootNode Pointer to a root node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_BUFFER_TOO_SMALL No space left in the buffer. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of memory. +**/ +EFI_STATUS +EFIAPI +AmlDbgPrintNameSpace ( + IN AML_ROOT_NODE_HANDLE RootNode + ); + +#else + +#define DumpRaw(Ptr, Length) + +#define AmlDbgPrintChars(ErrorLevel, Buffer, Size) + +#define AmlDbgPrintNameSeg(Buffer) + +#define AmlDbgPrintNameString(Buffer,NewLine) + +#define AmlDbgPrintNode(Node) + +#define AmlDbgPrintTree(Node) + +#define AmlDbgPrintNameSpace(RootNode) + +#endif // MDEPKG_NDEBUG + +#endif // AML_PRINT_H_ -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'