From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.57]) by mx.groups.io with SMTP id smtpd.web12.10701.1588693592729472348 for ; Tue, 05 May 2020 08:46:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=eWpATha1; spf=pass (domain: arm.com, ip: 40.107.22.57, mailfrom: krzysztof.koch@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=Tjc1pKaba+RLXGijKGhM9TPFyWTYWjLiedSVxRly0nM=; b=eWpATha1G5JzlwQJC0G8sNrr9pZAwJBoH11xz4Qkyy+BVkZz3lQvRy8Yc6aIEIDp7IxexP+tALu5n5L3MMCnMMXbAgXouLimv0hmUWfAG5nnGCGc1tNmPhhOpGConOU8E8O8VWYkxw5ZQxzxVJsiVQTdj28jund1yx/1ABG4eSg= Received: from AM4PR0701CA0020.eurprd07.prod.outlook.com (2603:10a6:200:42::30) by AM6PR08MB5112.eurprd08.prod.outlook.com (2603:10a6:20b:ee::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 15:46:30 +0000 Received: from AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:200:42:cafe::51) by AM4PR0701CA0020.outlook.office365.com (2603:10a6:200:42::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.16 via Frontend Transport; Tue, 5 May 2020 15:46:29 +0000 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 AM5EUR03FT051.mail.protection.outlook.com (10.152.16.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 15:46:29 +0000 Received: ("Tessian outbound 567b75aed2b9:v54"); Tue, 05 May 2020 15:46:29 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6702b3f8350325be X-CR-MTA-TID: 64aa7808 Received: from 048164db55ca.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id FD8AA5A2-9B12-4C18-BFDF-4376A14002C8.1; Tue, 05 May 2020 15:46:23 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 048164db55ca.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CXXn85Oas+Z4NGOqBV/VDN83OtXiCcrKcrVKRz0allq67X2UaMzhDYidzNV0mEBlUjPGL2b79032EQ/NTXYhcQkn/UFeGdUUeCChpUeW/Ag3J1L/N20EVXpTABeupI6IcRqW1ho++bptsFYAiCi/Ev3TuRML71769sJCkjPWA8sBmbTs0qENOzsDN5s1y6pY0xY5gNJoJ6BFZJtrKDrWrEOSg7HWkuEsY5lgZNsrWNLwL9qZmsn1hbCDPYZ+nD5IkrQp5elfW/DusQiU5II7EahRXo7fW9WPqxuHdP9sqTPUAixJ62jIfIdIK5ZXI9wjTz2Fi3PgOI/gYKlF5FUQRA== 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=Tjc1pKaba+RLXGijKGhM9TPFyWTYWjLiedSVxRly0nM=; b=Tv1euLmk+YzNOd231nfpMoaeS8hsNPVKOk7u3dj14KZ06V3IMJlgprpX06FJgt3Ez+sYqw1Tgmd7+3LYV7zWBnsmNjLTzvAS7WcdHHma9RJxQ9cmVJpzEI1Hik4FuGPY7qnb0W7iR/j3dtoiwVwM+E/JH5BCWvx0RD809lzBjU9W7SZzJcEK0/gODnFmuOm3uWUrtzNSfGthVepBi/d7YL5oVR1ssbt8cLXUFs+hETkSByOgfwR7RbhqeFrL5RZ2LUf0uMjwlRwwHqCAKFoA0uzAp7eO68KU0/vqTU9WFVdVZdlfPYCxCcIYuLHe7s4GlLtnslTFj/5NEXg53K2anw== 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=Tjc1pKaba+RLXGijKGhM9TPFyWTYWjLiedSVxRly0nM=; b=eWpATha1G5JzlwQJC0G8sNrr9pZAwJBoH11xz4Qkyy+BVkZz3lQvRy8Yc6aIEIDp7IxexP+tALu5n5L3MMCnMMXbAgXouLimv0hmUWfAG5nnGCGc1tNmPhhOpGConOU8E8O8VWYkxw5ZQxzxVJsiVQTdj28jund1yx/1ABG4eSg= Received: from AM5PR04CA0032.eurprd04.prod.outlook.com (2603:10a6:206:1::45) by AM6PR08MB3717.eurprd08.prod.outlook.com (2603:10a6:20b:8e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 15:46:22 +0000 Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::82) by AM5PR04CA0032.outlook.office365.com (2603:10a6:206:1::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 15:46:22 +0000 Authentication-Results-Original: 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 AM5EUR03FT007.mail.protection.outlook.com (10.152.16.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 15:46:22 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Tue, 5 May 2020 15:46:08 +0000 Received: from E119924.Arm.com (10.57.59.39) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Tue, 5 May 2020 15:46:08 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [PATCH v1 5/6] ShellPkg: acpiview: Make IORT parsing logic data driven Date: Tue, 5 May 2020 16:46:03 +0100 Message-ID: <20200505154604.9848-6-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200505154604.9848-1-krzysztof.koch@arm.com> References: <20200505154604.9848-1-krzysztof.koch@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant 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)(346002)(136003)(39860400002)(376002)(46966005)(33430700001)(26005)(186003)(86362001)(7696005)(8676002)(8936002)(30864003)(4326008)(316002)(54906003)(478600001)(70206006)(70586007)(5660300002)(2616005)(81166007)(6916009)(336012)(44832011)(6666004)(426003)(36756003)(82740400003)(2906002)(47076004)(356005)(1076003)(82310400002)(19627235002)(33440700001);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b88126e-6e67-4550-a701-08d7f10b7a52 X-MS-TrafficTypeDiagnostic: AM6PR08MB3717:|AM6PR08MB5112: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4s6IKcwqoJPXr70XI4AA6NeszQyhjVc6r8zid8XvkrCqCMG5+dud3mA21tllH7OquWU6aNX1f2m5RuwyymFMwXcJU7ykghGm+ry3SHamGXXdbogGJ3TiMERJwURevjozEcWOSPbfiwRCz5nooP436CXvXkbgzK0MR/P+bIbQcNtD8mbueD3VJhjmvqrs/yds9o5f0XMViq+H8ez56cPMjhNW/yqOAxsGPHDGCu5PGGLUKFvKpKeWAxG4GS7O5nxGwFiNewBGHMSDrVUd7bausXkLi1kiK8FkTnxYsAak/qqrX3DJf7puUEs2wzWWsZ5ctT+LzYr8nkJ0Q6pZfTmHRMVEocOgHoAgNLXaYAzwhYTCQ2Nr54YmJWFQXU4Ohnc/LWQ8KTVllnhHF0dm74C5c6HuHfosCW7TyPsoaKlEvY5Oljnajg8DBuD/iqPJP9rlCUyAKa8RAyCHQZo0tY21ovOUSU/1r2UmN12iaiVessNHU9d+UYk66x9AMq7bx3PNeDieN6GzG0wljXxqz0HS6mryJ1WjIWqFGPF8ygfaSpHvJEW1cgx6FEBoP2T3MGEfa9e3uqq5vVSpg/rLmQekww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3717 Original-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; Return-Path: Krzysztof.Koch@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com 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)(376002)(346002)(39860400002)(46966005)(33430700001)(336012)(19627235002)(86362001)(6666004)(2616005)(44832011)(81166007)(426003)(82310400002)(316002)(54906003)(82740400003)(36906005)(47076004)(6916009)(33440700001)(478600001)(186003)(30864003)(7696005)(8936002)(8676002)(5660300002)(1076003)(36756003)(4326008)(70206006)(2906002)(70586007)(26005);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 540dcfdd-bb6e-4be0-b5e1-08d7f10b7604 X-Forefront-PRVS: 0394259C80 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vZGCEd678sWHmXvCpgYAJgKZx0kd5rblW4/JB3PT443Td2GniTzaLvE+yn9BXdQ+i7HldPp78Plk2LRFgLenb/JFtuArrpP3A4YFE3PFeIqZZoyNNgcYe0N8RFDil/a22OKtWkPv4fTRbsNIrnPuHwu+1Xnsy7xEwDYyycajv+d6RYSHOiIX7eJ5x4JbZ+f0rNGVcy7KOsNnfb0fcY8dLxR/b3AToKEC02DlP2cDtHFRyp3zO0z4bYBYcqprun/b5XHS8k2FAVV9S/p0Jdx9pvdK3enNyA3I+/ed3OWFyaL940cl5+FUxNVs4RkNWIRJ1cgOsu9JghP5DipEVItUDmq6BMCjaL1iUeSdiKYsN75XvMnEthc7UOULwD2PUBp1Dop5vlJRBVkVLKfs2QUo+2es7A8evE9HGJrwFN4dBnkFTRLpTmMWfwuR5BB9F7DvjoRhjojnRlNpz/0KdFQc7pKlWsotiKcD0miOxBKewy3D1VDvHOGas2YqokFowHzBIXWYvMfZHKNOdS8M3hlP23f4bNYB7r9BN0b7WPnrAv7/CvaKfXT4SRv/ElM7YqiHadSyB2bj6737AMh7rAXXZg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:29.4626 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b88126e-6e67-4550-a701-08d7f10b7a52 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-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5112 Content-Type: text/plain Replace the switch statement in the main parser loop with a table-driven approach. Use the ParseAcpiStruct () method to resolve how each IORT Node given should be parsed. Enumerate all structures found in the IO Remapping Table (IORT) on a per-type basis. Replace calls to AsciiSPrint () with the PrintAcpiStructName () function. Consolidate all metadata about each IORT Node. Define an array of ACPI_STRUCT_INFO structures to store the name, instance count, architecture support and handling information. Use this array to construct the ACPI_STRUCT_DATABASE for IORT. Count the number of instances of each IORT Node. Optionally report these counts after IORT table parsing is finished. Modify dedicated functions for parsing each IORT Node type such that their signatures match ACPI_STRUCT_PARSER_FUNC. This way, they can be used in the ParseAcpiStruct () call. References: - IO Remapping Table - Platform Design Document, Issue D, March 2018 Signed-off-by: Krzysztof Koch --- Notes: v1: - Make IORT parsing logic data driven [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 353 +++++++++++++------- 1 file changed, 234 insertions(+), 119 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c index 9a006a01448b897865cd7cd85651c816933acf05..0c40447b4363f10c7ea5c9eeb283cebeab24243a 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c @@ -9,10 +9,12 @@ **/ #include +#include #include #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" // Local variables STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; @@ -32,6 +34,11 @@ STATIC CONST UINT32* PmuInterruptOffset; STATIC CONST UINT32* ItsCount; +/** + Handler for each IORT Node type +**/ +STATIC ACPI_STRUCT_INFO IortStructs[]; + /** This function validates the ID Mapping array count for the ITS node. @@ -273,12 +280,7 @@ DumpIortNodeIdMappings ( while ((Index < MappingCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "ID Mapping [%d]", - Index - ); + PrintAcpiStructName ("ID Mapping", Index, sizeof (Buffer), Buffer); Offset += ParseAcpi ( TRUE, 4, @@ -296,27 +298,42 @@ DumpIortNodeIdMappings ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. - @param [in] MappingCount The ID Mapping count. - @param [in] MappingOffset The offset of the ID Mapping array + @param [in] OptArg0 The ID Mapping count. + @param [in] OptArg1 The offset of the ID Mapping array from the start of the IORT table. **/ STATIC VOID DumpIortNodeSmmuV1V2 ( - IN UINT8* Ptr, - IN UINT16 Length, - IN UINT32 MappingCount, - IN UINT32 MappingOffset + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0, + IN CONST VOID* OptArg1 ) { UINT32 Index; UINT32 Offset; - CHAR8 Buffer[50]; // Used for AsciiName param of ParseAcpi + CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + UINT32 MappingCount; + UINT32 MappingOffset; + + ASSERT (OptArg0 != NULL); + ASSERT (OptArg1 != NULL); + + MappingCount = *((UINT32*)OptArg0); + MappingOffset = *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Name, + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Count, + sizeof (Buffer), + Buffer + ); ParseAcpi ( TRUE, 2, - "SMMUv1 or SMMUv2 Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeSmmuV1V2Parser) @@ -330,7 +347,8 @@ DumpIortNodeSmmuV1V2 ( (PmuInterruptOffset == NULL)) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient SMMUv1/2 node length. Length = %d\n", + L"ERROR: Insufficient %a Node length. Length = %d\n", + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Name, Length ); return; @@ -341,11 +359,11 @@ DumpIortNodeSmmuV1V2 ( while ((Index < *InterruptContextCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "Context Interrupts Array", + Index, sizeof (Buffer), - "Context Interrupts Array [%d]", - Index + Buffer ); Offset += ParseAcpi ( TRUE, @@ -363,11 +381,11 @@ DumpIortNodeSmmuV1V2 ( while ((Index < *PmuInterruptCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "PMU Interrupts Array", + Index, sizeof (Buffer), - "PMU Interrupts Array [%d]", - Index + Buffer ); Offset += ParseAcpi ( TRUE, @@ -392,23 +410,40 @@ DumpIortNodeSmmuV1V2 ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. - @param [in] MappingCount The ID Mapping count. - @param [in] MappingOffset The offset of the ID Mapping array + @param [in] OptArg0 The ID Mapping count. + @param [in] OptArg1 The offset of the ID Mapping array from the start of the IORT table. **/ STATIC VOID DumpIortNodeSmmuV3 ( - IN UINT8* Ptr, - IN UINT16 Length, - IN UINT32 MappingCount, - IN UINT32 MappingOffset + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0, + IN CONST VOID* OptArg1 ) { + UINT32 MappingCount; + UINT32 MappingOffset; + CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + + ASSERT (OptArg0 != NULL); + ASSERT (OptArg1 != NULL); + + MappingCount = *((UINT32*)OptArg0); + MappingOffset = *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv3].Name, + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv3].Count, + sizeof (Buffer), + Buffer + ); + ParseAcpi ( TRUE, 2, - "SMMUV3 Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeSmmuV3Parser) @@ -424,24 +459,37 @@ DumpIortNodeSmmuV3 ( /** This function parses the IORT ITS node. + ITS nodes have no ID mappings. + @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. + @param [in] OptArg0 First optional argument (Not used). + @param [in] OptArg1 Second optional argument (Not used).. **/ STATIC VOID DumpIortNodeIts ( - IN UINT8* Ptr, - IN UINT16 Length + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL ) { UINT32 Offset; UINT32 Index; CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Name, + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Count, + sizeof (Buffer), + Buffer + ); + Offset = ParseAcpi ( TRUE, 2, - "ITS Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeItsParser) @@ -452,7 +500,8 @@ DumpIortNodeIts ( if (ItsCount == NULL) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient ITS group length. Length = %d.\n", + L"ERROR: Insufficient %a Node length. Length = %d.\n", + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Name, Length ); return; @@ -462,11 +511,11 @@ DumpIortNodeIts ( while ((Index < *ItsCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "GIC ITS Identifier Array", + Index, sizeof (Buffer), - "GIC ITS Identifier Array [%d]", - Index + Buffer ); Offset += ParseAcpi ( TRUE, @@ -488,25 +537,41 @@ DumpIortNodeIts ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. - @param [in] MappingCount The ID Mapping count. - @param [in] MappingOffset The offset of the ID Mapping array + @param [in] OptArg0 The ID Mapping count. + @param [in] OptArg1 The offset of the ID Mapping array from the start of the IORT table. **/ STATIC VOID DumpIortNodeNamedComponent ( - IN UINT8* Ptr, - IN UINT16 Length, - IN UINT32 MappingCount, - IN UINT32 MappingOffset + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0, + IN CONST VOID* OptArg1 ) { UINT32 Offset; + UINT32 MappingCount; + UINT32 MappingOffset; + CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + + ASSERT (OptArg0 != NULL); + ASSERT (OptArg1 != NULL); + + MappingCount = *((UINT32*)OptArg0); + MappingOffset = *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_NAMED_COMP].Name, + IortStructs[EFI_ACPI_IORT_TYPE_NAMED_COMP].Count, + sizeof (Buffer), + Buffer + ); Offset = ParseAcpi ( TRUE, 2, - "Named Component Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeNamedComponentParser) @@ -534,23 +599,40 @@ DumpIortNodeNamedComponent ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. - @param [in] MappingCount The ID Mapping count. - @param [in] MappingOffset The offset of the ID Mapping array + @param [in] OptArg0 The ID Mapping count. + @param [in] OptArg1 The offset of the ID Mapping array from the start of the IORT table. **/ STATIC VOID DumpIortNodeRootComplex ( - IN UINT8* Ptr, - IN UINT16 Length, - IN UINT32 MappingCount, - IN UINT32 MappingOffset + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0, + IN CONST VOID* OptArg1 ) { + UINT32 MappingCount; + UINT32 MappingOffset; + CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + + ASSERT (OptArg0 != NULL); + ASSERT (OptArg1 != NULL); + + MappingCount = *((UINT32*)OptArg0); + MappingOffset = *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_ROOT_COMPLEX].Name, + IortStructs[EFI_ACPI_IORT_TYPE_ROOT_COMPLEX].Count, + sizeof (Buffer), + Buffer + ); + ParseAcpi ( TRUE, 2, - "Root Complex Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeRootComplexParser) @@ -568,23 +650,40 @@ DumpIortNodeRootComplex ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Length Length of the buffer. - @param [in] MappingCount The ID Mapping count. - @param [in] MappingOffset The offset of the ID Mapping array + @param [in] OptArg0 The ID Mapping count. + @param [in] OptArg1 The offset of the ID Mapping array from the start of the IORT table. **/ STATIC VOID DumpIortNodePmcg ( - IN UINT8* Ptr, - IN UINT16 Length, - IN UINT32 MappingCount, - IN UINT32 MappingOffset -) + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0, + IN CONST VOID* OptArg1 + ) { + UINT32 MappingCount; + UINT32 MappingOffset; + CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi + + ASSERT (OptArg0 != NULL); + ASSERT (OptArg1 != NULL); + + MappingCount = *((UINT32*)OptArg0); + MappingOffset = *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_PMCG].Name, + IortStructs[EFI_ACPI_IORT_TYPE_PMCG].Count, + sizeof (Buffer), + Buffer + ); + ParseAcpi ( TRUE, 2, - "PMCG Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodePmcgParser) @@ -597,6 +696,57 @@ DumpIortNodePmcg ( ); } +/** + Information about each IORT Node type +**/ +STATIC ACPI_STRUCT_INFO IortStructs[] = { + ADD_ACPI_STRUCT_INFO_FUNC ( + "ITS Group", + EFI_ACPI_IORT_TYPE_ITS_GROUP, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodeIts + ), + ADD_ACPI_STRUCT_INFO_FUNC ( + "Named Component", + EFI_ACPI_IORT_TYPE_NAMED_COMP, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodeNamedComponent + ), + ADD_ACPI_STRUCT_INFO_FUNC ( + "Root Complex", + EFI_ACPI_IORT_TYPE_ROOT_COMPLEX, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodeRootComplex + ), + ADD_ACPI_STRUCT_INFO_FUNC ( + "SMMUv1 or SMMUv2", + EFI_ACPI_IORT_TYPE_SMMUv1v2, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodeSmmuV1V2 + ), + ADD_ACPI_STRUCT_INFO_FUNC ( + "SMMUv3", + EFI_ACPI_IORT_TYPE_SMMUv3, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodeSmmuV3 + ), + ADD_ACPI_STRUCT_INFO_FUNC ( + "PMCG", + EFI_ACPI_IORT_TYPE_PMCG, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpIortNodePmcg + ) +}; + +/** + IORT structure database +**/ +STATIC ACPI_STRUCT_DATABASE IortDatabase = { + "IORT Node", + IortStructs, + ARRAY_SIZE (IortStructs) +}; + /** This function parses the ACPI IORT table. When trace is enabled this function parses the IORT table and traces the ACPI fields. @@ -633,6 +783,8 @@ ParseAcpiIort ( return; } + ResetAcpiStructCounts (&IortDatabase); + ParseAcpi ( TRUE, 0, @@ -666,7 +818,7 @@ ParseAcpiIort ( ParseAcpi ( FALSE, 0, - "IORT Node Header", + NULL, NodePtr, AcpiTableLength - Offset, PARSER_PARAMS (IortNodeHeaderParser) @@ -681,7 +833,8 @@ ParseAcpiIort ( IncrementErrorCount (); Print ( L"ERROR: Insufficient remaining table buffer length to read the " \ - L"IORT node header. Length = %d.\n", + L"%a header. Length = %d.\n", + IortDatabase.Name, AcpiTableLength - Offset ); return; @@ -692,8 +845,9 @@ ParseAcpiIort ( ((Offset + (*IortNodeLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid IORT Node length. " \ - L"Length = %d. Offset = %d. AcpiTableLength = %d.\n", + L"ERROR: Invalid %a length. Length = %d. Offset = %d. " \ + L"AcpiTableLength = %d.\n", + IortDatabase.Name, *IortNodeLength, Offset, AcpiTableLength @@ -701,63 +855,24 @@ ParseAcpiIort ( return; } - PrintFieldName (2, L"* Node Offset *"); - Print (L"0x%x\n", Offset); - - switch (*IortNodeType) { - case EFI_ACPI_IORT_TYPE_ITS_GROUP: - DumpIortNodeIts ( - NodePtr, - *IortNodeLength - ); - break; - case EFI_ACPI_IORT_TYPE_NAMED_COMP: - DumpIortNodeNamedComponent ( - NodePtr, - *IortNodeLength, - *IortIdMappingCount, - *IortIdMappingOffset - ); - break; - case EFI_ACPI_IORT_TYPE_ROOT_COMPLEX: - DumpIortNodeRootComplex ( - NodePtr, - *IortNodeLength, - *IortIdMappingCount, - *IortIdMappingOffset - ); - break; - case EFI_ACPI_IORT_TYPE_SMMUv1v2: - DumpIortNodeSmmuV1V2 ( - NodePtr, - *IortNodeLength, - *IortIdMappingCount, - *IortIdMappingOffset - ); - break; - case EFI_ACPI_IORT_TYPE_SMMUv3: - DumpIortNodeSmmuV3 ( - NodePtr, - *IortNodeLength, - *IortIdMappingCount, - *IortIdMappingOffset - ); - break; - case EFI_ACPI_IORT_TYPE_PMCG: - DumpIortNodePmcg ( - NodePtr, - *IortNodeLength, - *IortIdMappingCount, - *IortIdMappingOffset - ); - break; - - default: - IncrementErrorCount (); - Print (L"ERROR: Unsupported IORT Node type = %d\n", *IortNodeType); - } // switch + // Parse the IORT Node + ParseAcpiStruct ( + 2, + NodePtr, + &IortDatabase, + Offset, + *IortNodeType, + *IortNodeLength, + IortIdMappingCount, + IortIdMappingOffset + ); NodePtr += (*IortNodeLength); Offset += (*IortNodeLength); } // while + + // Report and validate IORT Node counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&IortDatabase); + } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'