From nobody Sat May 4 13:43:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58642+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158869358396068.59197662958957; Tue, 5 May 2020 08:46:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HiAfYY1788612xnJE60aNfWZ; Tue, 05 May 2020 08:46:23 -0700 X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.80]) by mx.groups.io with SMTP id smtpd.web11.10670.1588693581644966031 for ; Tue, 05 May 2020 08:46:22 -0700 X-Received: from AM5PR0502CA0011.eurprd05.prod.outlook.com (2603:10a6:203:91::21) by AM6PR08MB3703.eurprd08.prod.outlook.com (2603:10a6:20b:83::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.29; Tue, 5 May 2020 15:46:18 +0000 X-Received: from VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::36) by AM5PR0502CA0011.outlook.office365.com (2603:10a6:203:91::21) 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:18 +0000 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58642+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT050.mail.protection.outlook.com (10.152.19.209) 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:17 +0000 X-Received: ("Tessian outbound fb9de21a7e90:v54"); Tue, 05 May 2020 15:46:17 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 114de6f2728fa0d4 X-CR-MTA-TID: 64aa7808 X-Received: from 09ed360f50b7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 05EC1071-0604-4F23-81E2-CA206DAFB089.1; Tue, 05 May 2020 15:46:11 +0000 X-Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 09ed360f50b7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2bbRMYdzgnpyOJcdoLpBvnr1hcsOBACJ3p/yTb9o9pxrtRRiQARvLDvNhW3yiHPChxnDxLb99v6DAciIPiWEgfDwe53OW+gOOYeihie+zikDhI1im0cr5shl8Fgu19JqCNnG77G5iU2QtGkpYdwaMweuxw6EmFeBc63nmLisozCLI2E9b947F1FYtSkFNz4HUWi4CtdwbPT1dRhR7wfaJfTRLrtUD6XjKt7h6n2bRBKXbtkNPVa5HxlxRz/Xv/yM4uG+u7MbPT+4Lm487QoDsIEACXozqfKuPlrSeLub/3dM9TzzO+tF3l7BQ4pH7ZH9FtNiUjL9TcHV2ZeaLVpfw== 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=tnTfuXJ6Oxi/2FUJsIY+z+5T5SlS4dyWmDa7z7opZkQ=; b=DHzQuWi14sZRPZulOck+m/lAxWD39G7zdvIfa2V5GprtfLtHua90m1s2/eY/UGtZKDLhAuFfR0P0CbY7Ynn53Fd34utQeCrpd4uttSu33ytl3e5Y6DRUHd2UEnEjTZO+rI4VfQXFMO4xuXxBc9lJhtu/EJf6yzoBBNn4I+nXX6tIq38YIdTGDwQGwu24zOmJE2VWny/n+E+kVcR7BnvkjIvOawHVzA48uUAK7c5ID5xws4iHUOvPaKsBMCUOx9vtsWBGEjy/aEwYGZy6y7cIoYZ6y6eE2FUfkuuM7QByCbsm1rMTAu7WiSFhyNsTG1NYOnX+X0eX8314pQEO/qLPcw== 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 X-Received: from DB6PR07CA0111.eurprd07.prod.outlook.com (2603:10a6:6:2c::25) by VI1PR0801MB1709.eurprd08.prod.outlook.com (2603:10a6:800:59::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19; Tue, 5 May 2020 15:46:09 +0000 X-Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2c:cafe::a0) by DB6PR07CA0111.outlook.office365.com (2603:10a6:6:2c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.11 via Frontend Transport; Tue, 5 May 2020 15:46:09 +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; X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) 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:09 +0000 X-Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Tue, 5 May 2020 15:46:06 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) 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; Tue, 5 May 2020 15:46:05 +0000 X-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:05 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [edk2-devel] [PATCH v1 1/6] ShellPkg: acpiview: Add interface for data-driven table parsing Date: Tue, 5 May 2020 16:45:59 +0100 Message-ID: <20200505154604.9848-2-krzysztof.koch@arm.com> 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)(136003)(346002)(396003)(376002)(39860400002)(46966005)(33430700001)(82310400002)(54906003)(478600001)(356005)(47076004)(8936002)(70586007)(426003)(6916009)(8676002)(86362001)(81166007)(70206006)(6666004)(336012)(44832011)(36756003)(26005)(186003)(82740400003)(5660300002)(316002)(7696005)(30864003)(2616005)(33440700001)(1076003)(2906002)(4326008);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74caf2a0-3637-4eae-9d31-08d7f10b7365 X-MS-TrafficTypeDiagnostic: VI1PR0801MB1709:|AM6PR08MB3703: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: +O6eeCqqMay5AS7ibBtn+JHkb5rlu6mzZuIg6lmxdM8S31JvUMclhjVBFYwPA73+3aGGC4P9eoWJVnDQ25s4PwAO4b9recZE6r3A7qPhKcRoDo/KwN3UKC6hDLtHxAACDr4kPmrzYn5IN2O6fSvQUgOjmATlIpodJ3+yZJldL7/2RGe+5qA/+GUNw3SbkU2TLfkLTtw17ifgLFlYFOcfYlG/mwrl5fEA1+gg03kPRweq57o9/vN1gezZb7Wu1XkgSGXh1R+1flfeMhyfpi078BraHkLAHFb2DIlrymFjiChBpF4FRgNbejeN4EqwK+RwWr7b95kehURwdtWaTK3laB2OHrh8KPdlzCRHyzFDKkZPJX/1mGQmwZX5FgUBbcbG4XBy8lQ/auso1aldaSVyYVod7XBcjdcpsTk23lmUkSQHtfmCit4YDtkBDPZYEFQOvsx3J/eqNhj9lo4/BJgzqInb8XHz6wk4QYRsRhW6/3h7HvDLqbbPpoKb3kZVj4WjiYmZhogyDPGUpxxt1U77FxrSf/3hiDhjuPFLPzgFNSQQVeNj1TJKP6ais+G3xkW5sM+JNfBWQuRtU3ssrFXKWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1709 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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ff872611-ac55-495f-66ec-08d7f10b6e79 X-Microsoft-Antispam-Message-Info: 7rGcOURciUnSW88AkhMpuYiwlGeMVf+ce7uD8VEVFOuapKrq9f7CE+AM7lsNhcTd7n3lelsRiVnelIUvmkJ1luUslTeBCDev9v+flxC/AkIuxO+2uzg6SD/36+/25XosiTeMR6m25GonPTFFvgBOQcxeM9iGx8e95gqDsFWGoBWlXQeWdtdtkJmSji3G/HLbT3uEtu0zd2jaOTXkVf7HVYgAFmAj7YEdUQSRhvHvce1tjMpxMAuOeHrG5rM6j6BClLsCGXvcZXNUIjE9vWdzxlYKjCEIJKTS3/ytlqXzJT3/F62SXItuqeKgc+lqoy0bcatBaK+NOKILDXcAqVKN0eFAGb2DvCVzBsXx4Qlz12wfd8r482wQwunBIkTj5k9QlBxJ4P+DWp2dfkA81VcV/1ijJuPUYgmXidNbkaI7+uU6VGGB6IV1FKAGAet4IcX29qjV7hTGQMlLG4AfxCZz7mUjEySvost9cxvK1iZZnIe/KSnjstOMYEoGa8eEZ4lXTZcC1YqUxsXQJZPnAq7VCFPG/B7BgfsLR7D1ti8AK9X+RxUZXPdlCRMvUv05nWorITus1iGTwiz/V0zPd20lhw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:17.7810 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74caf2a0-3637-4eae-9d31-08d7f10b7365 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: AM6PR08MB3703 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: WGEphnQmUhp3K3L3uLb3yZDCx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693583; bh=7Lpfbtcv+z06im9GFxECrU3tEMsLxLEKY0vOMYNV8ac=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=mbJE47vib7EtbPdU3lIbGA/Pag6PLjZZVxsEbiEPtU6s8R86jwxL/rxdC52ecCFWJ3a feNj74fZ1vW34jXjVhR974CNGRPPoOSSBQFn7MsSE4cUjSJ0iRwF0REGpSj+Wj1Ol2oZS vP0KyLhBtF9XOtckYLa7am3eMhUTrxGzx0M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define and implement an interface to streamline metadata collection and validation for structures present in each ACPI table. Most ACPI tables define substructures which constitute the table. These substructures are identified by their 'Type' field value. The range of possible 'Type' values is defined on a per-table basis. For more sophisticated ACPI table validation, additional data about each structure type needs to be maintained. This patch defines a new ACPI_STRUCT_INFO structure. It stores additional metadata about a building block of an ACPI table. ACPI_STRUCT_INFO's are organised into ACPI_STRUCT_DATABASE's. ACPI_STRUCT_DATABASE is an array of ACPI_STRUCT_INFO elements which are indexed using structure's type value. For example, in the Multiple APIC Description Table (MADT) all Interrupt Controller Structure types form a single database. In the database, the GIC CPU Interface (GICC) structure's metadata is the 11th entry (i.e. Type =3D 0xB). ACPI_STRUCT_INFO structure consists of: - ASCII name of the structure - ACPI-defined stucture Type - bitmask defining the validity of the structure for various architectures - instance counter - a handler for the structure (ACPI_STRUCT_HANDLER) The bitmask allows detection of structures in a table which are not compatible with the target platform. For example, the Multiple APIC Description Table (MADT) contains Interrupt Controller Structure definitions which apply to either the Advanced Programmable Interrupt Controller (APIC) model or the Generic Interrupt Controller (GIC) model. Presence of APIC-related structures on an Arm-based platform is a bug which is now detected and reported by acpiview. This patch adds support for compatibility checks with the Arm architecture only. However, provisions are made to allow extensions to other architectures. ACPI_STRUCT_HANDLER describes how the contents of the structure can be parsed. The possible options are: - An ACPI_PARSER array which can be passed to the ParseAcpi() function - A dedicated function for parsing the structure (ACPI_STRUCT_PARSER_FUNC) If neither of these options is provided, it is assumed that the parsing logic is not implemented. ACPI_STRUCT_PARSER_FUNC expects the the first two arguments to be the pointer to the start of the structure to parse and the length of structure's buffer. The remaining two optional arguments are context specific. This patch adds methods for: - Resetting the instance count for all structure types in a table. - Getting the combined instance count for all types in a table. - Validating the compatibility of a structure with the target arch. - Printing structure counts for the types which are compatible with the target architecture and validating that the non-compatible structures are not present in the table. - Parsing the structure according to the information provided by its handle. Finally, define a helper PrintAcpiStructName () function to streamline the printing of ACPI structure name together with the structure's current occurrence count. References: - ACPI 6.3, January 2019 Signed-off-by: Krzysztof Koch --- Notes: v1: - Add interface for data-driven table parsing [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 263 ++++++++++= ++++++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 234 ++++++++++= +++++++ 2 files changed, 497 insertions(+) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 3f12a33050a4e4ab3be2187c90ef8dcf0882283d..32566101e2de2eec3ccf44563ee= 79379404bff62 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -6,6 +6,8 @@ **/ =20 #include +#include +#include #include #include #include "AcpiParser.h" @@ -466,6 +468,267 @@ PrintFieldName ( ); } =20 +/** + Produce a Null-terminated ASCII string with the name and index of an + ACPI structure. + + The output string is in the following format: [] + + @param [in] Name Structure name. + @param [in] Index Structure index. + @param [in] BufferSize The size, in bytes, of the output buffer. + @param [out] Buffer Buffer for the output string. + + @return The number of bytes written to the buffer (not including Null-= byte) +**/ +UINTN +EFIAPI +PrintAcpiStructName ( + IN CONST CHAR8* Name, + IN UINT32 Index, + IN UINTN BufferSize, + OUT CHAR8* Buffer + ) +{ + ASSERT (Name !=3D NULL); + ASSERT (Buffer !=3D NULL); + + return AsciiSPrint (Buffer, BufferSize, "%a [%d]", Name , Index); +} + +/** + Set all ACPI structure instance counts to 0. + + @param [in,out] StructDb ACPI structure database with counts to rese= t. +**/ +VOID +EFIAPI +ResetAcpiStructCounts ( + IN OUT ACPI_STRUCT_DATABASE* StructDb + ) +{ + UINT32 Type; + + ASSERT (StructDb !=3D NULL); + ASSERT (StructDb->Entries !=3D NULL); + + for (Type =3D 0; Type < StructDb->EntryCount; Type++) { + StructDb->Entries[Type].Count =3D 0; + } +} + +/** + Sum all ACPI structure instance counts. + + @param [in] StructDb ACPI structure database with per-type counts to= sum. + + @return Total number of structure instances recorded in the database. +**/ +UINT32 +EFIAPI +SumAcpiStructCounts ( + IN CONST ACPI_STRUCT_DATABASE* StructDb + ) +{ + UINT32 Type; + UINT32 Total; + + ASSERT (StructDb !=3D NULL); + ASSERT (StructDb->Entries !=3D NULL); + + Total =3D 0; + + for (Type =3D 0; Type < StructDb->EntryCount; Type++) { + Total +=3D StructDb->Entries[Type].Count; + } + + return Total; +} + +/** + Validate that a structure with a given type value is defined for the giv= en + ACPI table and target architecture. + + The target architecture is evaluated from the firmare build parameters. + + @param [in] Type ACPI-defined structure type. + @param [in] StructDb ACPI structure database with architecture + compatibility info. + + @retval TRUE Structure is valid. + @retval FALSE Structure is not valid. +**/ +BOOLEAN +EFIAPI +IsAcpiStructTypeValid ( + IN UINT32 Type, + IN CONST ACPI_STRUCT_DATABASE* StructDb + ) +{ + UINT32 Compatible; + + ASSERT (StructDb !=3D NULL); + ASSERT (StructDb->Entries !=3D NULL); + + if (Type >=3D StructDb->EntryCount) { + return FALSE; + } + +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) + Compatible =3D StructDb->Entries[Type].CompatArch & + (ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64); +#else + Compatible =3D StructDb->Entries[Type].CompatArch; +#endif + + return (Compatible !=3D 0); +} + +/** + Print the instance count of each structure in an ACPI table that is + compatible with the target architecture. + + For structures which are not allowed for the target architecture, + validate that their instance counts are 0. + + @param [in] StructDb ACPI structure database with counts to validate. + + @retval TRUE All structures are compatible. + @retval FALSE One or more incompatible structures present. +**/ +BOOLEAN +EFIAPI +ValidateAcpiStructCounts ( + IN CONST ACPI_STRUCT_DATABASE* StructDb + ) +{ + BOOLEAN AllValid; + UINT32 Type; + + ASSERT (StructDb !=3D NULL); + ASSERT (StructDb->Entries !=3D NULL); + + AllValid =3D TRUE; + Print (L"\nTable Breakdown:\n"); + + for (Type =3D 0; Type < StructDb->EntryCount; Type++) { + ASSERT (Type =3D=3D StructDb->Entries[Type].Type); + + if (IsAcpiStructTypeValid (Type, StructDb)) { + Print ( + L"%*a%-*a : %d\n", + INSTANCE_COUNT_INDENT, + "", + OUTPUT_FIELD_COLUMN_WIDTH - INSTANCE_COUNT_INDENT, + StructDb->Entries[Type].Name, + StructDb->Entries[Type].Count + ); + } else if (StructDb->Entries[Type].Count > 0) { + AllValid =3D FALSE; + IncrementErrorCount (); + Print ( + L"ERROR: %a Structure is not valid for the target architecture " \ + L"(found %d)\n", + StructDb->Entries[Type].Name, + StructDb->Entries[Type].Count + ); + } + } + + return AllValid; +} + +/** + Parse the ACPI structure with the type value given according to instruct= ions + defined in the ACPI structure database. + + If the input structure type is defined in the database, increment struct= ure's + instance count. + + If ACPI_PARSER array is used to parse the input structure, the index of = the + structure (instance count for the type before update) gets printed along= side + the structure name. This helps debugging if there are many instances of = the + type in a table. For ACPI_STRUCT_PARSER_FUNC, the printing of the index = must + be implemented separately. + + @param [in] Indent Number of spaces to indent the output. + @param [in] Ptr Ptr to the start of the structure. + @param [in,out] StructDb ACPI structure database with instructions on h= ow + parse every structure type. + @param [in] Offset Structure offset from the start of the table. + @param [in] Type ACPI-defined structure type. + @param [in] Length Length of the structure in bytes. + @param [in] OptArg0 First optional argument to pass to parser func= tion. + @param [in] OptArg1 Second optional argument to pass to parser fun= ction. + + @retval TRUE ACPI structure parsed successfully. + @retval FALSE Undefined structure type or insufficient data to parse. +**/ +BOOLEAN +EFIAPI +ParseAcpiStruct ( + IN UINT32 Indent, + IN UINT8* Ptr, + IN OUT ACPI_STRUCT_DATABASE* StructDb, + IN UINT32 Offset, + IN UINT32 Type, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL + ) +{ + ACPI_STRUCT_PARSER_FUNC ParserFunc; + CHAR8 Buffer[80]; + + ASSERT (Ptr !=3D NULL); + ASSERT (StructDb !=3D NULL); + ASSERT (StructDb->Entries !=3D NULL); + ASSERT (StructDb->Name !=3D NULL); + + PrintFieldName (Indent, L"* Offset *"); + Print (L"0x%x\n", Offset); + + if (Type >=3D StructDb->EntryCount) { + IncrementErrorCount (); + Print (L"ERROR: Unknown %a. Type =3D %d\n", StructDb->Name, Type); + return FALSE; + } + + if (StructDb->Entries[Type].Handler.ParserFunc !=3D NULL) { + ParserFunc =3D StructDb->Entries[Type].Handler.ParserFunc; + ParserFunc (Ptr, Length, OptArg0, OptArg1); + } else if (StructDb->Entries[Type].Handler.ParserArray !=3D NULL) { + ASSERT (StructDb->Entries[Type].Handler.Elements !=3D 0); + + PrintAcpiStructName ( + StructDb->Entries[Type].Name, + StructDb->Entries[Type].Count, + sizeof (Buffer), + Buffer + ); + + ParseAcpi ( + TRUE, + Indent, + Buffer, + Ptr, + Length, + StructDb->Entries[Type].Handler.ParserArray, + StructDb->Entries[Type].Handler.Elements + ); + } else { + StructDb->Entries[Type].Count++; + Print ( + L"ERROR: Parsing of %a Structure is not implemented\n", + StructDb->Entries[Type].Name + ); + return FALSE; + } + + StructDb->Entries[Type].Count++; + return TRUE; +} + /** This function is used to parse an ACPI table buffer. =20 diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index f81ccac7e118378aa185db4b625e5bcd75f78347..70e540b3a76de0ff9ce70bcabed= 8548063bea0ff 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -300,6 +300,240 @@ typedef struct AcpiParser { VOID* Context; } ACPI_PARSER; =20 +/** + Produce a Null-terminated ASCII string with the name and index of an + ACPI structure. + + The output string is in the following format: [] + + @param [in] Name Structure name. + @param [in] Index Structure index. + @param [in] BufferSize The size, in bytes, of the output buffer. + @param [out] Buffer Buffer for the output string. + + @return The number of bytes written to the buffer (not including Null-= byte) +**/ +UINTN +EFIAPI +PrintAcpiStructName ( + IN CONST CHAR8* Name, + IN UINT32 Index, + IN UINTN BufferSize, + OUT CHAR8* Buffer + ); + +/** + Indentation for printing instance counts for structures in an ACPI table. +**/ +#define INSTANCE_COUNT_INDENT 2 + +/** + Common signature for functions which parse ACPI structures. + + @param [in] Ptr Pointer to the start of structure's buffer. + @param [in] Length Length of the buffer. + @param [in] OptArg0 First optional argument. + @param [in] OptArg1 Second optional argument. +*/ +typedef VOID (*ACPI_STRUCT_PARSER_FUNC) ( + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL + ); + +/** + Description of how an ACPI structure should be parsed. + + One of ParserFunc or ParserArray should be not NULL. Otherwise, it is + assumed that parsing of an ACPI structure is not supported. If both + ParserFunc and ParserArray are defined, ParserFunc is used. +**/ +typedef struct AcpiStructHandler { + /// Dedicated function for parsing an ACPI structure + ACPI_STRUCT_PARSER_FUNC ParserFunc; + /// Array of instructions on how each structure field should be parsed + CONST ACPI_PARSER* ParserArray; + /// Number of elements in ParserArray if ParserArray is defined + UINT32 Elements; +} ACPI_STRUCT_HANDLER; + +/** + ACPI structure compatiblity with various architectures. + + Some ACPI tables define structures which are, for example, only valid in + the X64 or Arm context. For instance, the Multiple APIC Description Table + (MADT) describes both APIC and GIC interrupt models. + + These definitions provide means to describe the belonging of a structure + in an ACPI table to a particular architecture. This way, incompatible + structures can be detected. +**/ +#define ARCH_COMPAT_IA32 BIT0 +#define ARCH_COMPAT_X64 BIT1 +#define ARCH_COMPAT_ARM BIT2 +#define ARCH_COMPAT_AARCH64 BIT3 +#define ARCH_COMPAT_RISCV64 BIT4 + +/** + Information about a structure which constitutes an ACPI table +**/ +typedef struct AcpiStructInfo { + /// ACPI-defined structure Name + CONST CHAR8* Name; + /// ACPI-defined structure Type + CONST UINT32 Type; + /// Architecture(s) for which this structure is valid + CONST UINT32 CompatArch; + /// Structure's instance count in a table + UINT32 Count; + /// Information on how to handle the structure + CONST ACPI_STRUCT_HANDLER Handler; +} ACPI_STRUCT_INFO; + +/** + Macro for defining ACPI structure info when an ACPI_PARSER array must + be used to parse the structure. +**/ +#define ADD_ACPI_STRUCT_INFO_ARRAY(Name, Type, Compat, Array) \ +{ \ + Name, Type, Compat, 0, {NULL, Array, ARRAY_SIZE (Array)} \ +} + +/** + Macro for defining ACPI structure info when an ACPI_STRUCT_PARSER_FUNC + must be used to parse the structure. +**/ +#define ADD_ACPI_STRUCT_INFO_FUNC(Name, Type, Compat, Func) \ +{ \ + Name, Type, Compat, 0, {Func, NULL, 0} \ +} + +/** + Macro for defining ACPI structure info when the structure is defined in + the ACPI spec but no parsing information is provided. +**/ +#define ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED(Name, Type, Compat) \ +{ \ + Name, Type, Compat, 0, {NULL, NULL, 0} \ +} + +/** + Database collating information about every structure type defined by + an ACPI table. +**/ +typedef struct AcpiStructDatabase { + /// ACPI-defined name for the structures being described in the database + CONST CHAR8* Name; + /// Per-structure-type information. The list must be ordered by the types + /// defined for the table. All entries must be unique and there should be + /// no gaps. + ACPI_STRUCT_INFO* Entries; + /// Total number of unique types defined for the table + CONST UINT32 EntryCount; +} ACPI_STRUCT_DATABASE; + +/** + Set all ACPI structure instance counts to 0. + + @param [in,out] StructDb ACPI structure database with counts to rese= t. +**/ +VOID +EFIAPI +ResetAcpiStructCounts ( + IN OUT ACPI_STRUCT_DATABASE* StructDb + ); + +/** + Sum all ACPI structure instance counts. + + @param [in] StructDb ACPI structure database with per-type counts to= sum. + + @return Total number of structure instances recorded in the database. +**/ +UINT32 +EFIAPI +SumAcpiStructCounts ( + IN CONST ACPI_STRUCT_DATABASE* StructDb + ); + +/** + Validate that a structure with a given type value is defined for the giv= en + ACPI table and target architecture. + + The target architecture is evaluated from the firmare build parameters. + + @param [in] Type ACPI-defined structure type. + @param [in] StructDb ACPI structure database with architecture + compatibility info. + + @retval TRUE Structure is valid. + @retval FALSE Structure is not valid. +**/ +BOOLEAN +EFIAPI +IsAcpiStructTypeValid ( + IN UINT32 Type, + IN CONST ACPI_STRUCT_DATABASE* StructDb + ); + +/** + Print the instance count of each structure in an ACPI table that is + compatible with the target architecture. + + For structures which are not allowed for the target architecture, + validate that their instance counts are 0. + + @param [in] StructDb ACPI structure database with counts to validate. + + @retval TRUE All structures are compatible. + @retval FALSE One or more incompatible structures present. +**/ +BOOLEAN +EFIAPI +ValidateAcpiStructCounts ( + IN CONST ACPI_STRUCT_DATABASE* StructDb + ); + +/** + Parse the ACPI structure with the type value given according to instruct= ions + defined in the ACPI structure database. + + If the input structure type is defined in the database, increment struct= ure's + instance count. + + If ACPI_PARSER array is used to parse the input structure, the index of = the + structure (instance count for the type before update) gets printed along= side + the structure name. This helps debugging if there are many instances of = the + type in a table. For ACPI_STRUCT_PARSER_FUNC, the printing of the index = must + be implemented separately. + + @param [in] Indent Number of spaces to indent the output. + @param [in] Ptr Ptr to the start of the structure. + @param [in,out] StructDb ACPI structure database with instructions on h= ow + parse every structure type. + @param [in] Offset Structure offset from the start of the table. + @param [in] Type ACPI-defined structure type. + @param [in] Length Length of the structure in bytes. + @param [in] OptArg0 First optional argument to pass to parser func= tion. + @param [in] OptArg1 Second optional argument to pass to parser fun= ction. + + @retval TRUE ACPI structure parsed successfully. + @retval FALSE Undefined structure type or insufficient data to parse. +**/ +BOOLEAN +EFIAPI +ParseAcpiStruct ( + IN UINT32 Indent, + IN UINT8* Ptr, + IN OUT ACPI_STRUCT_DATABASE* StructDb, + IN UINT32 Offset, + IN UINT32 Type, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL + ); + /** A structure used to store the pointers to the members of the ACPI description header structure that was parsed. -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58642): https://edk2.groups.io/g/devel/message/58642 Mute This Topic: https://groups.io/mt/74000905/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 4 13:43:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58645+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588693585817279.3511308226665; Tue, 5 May 2020 08:46:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LNi4YY1788612x4YxbrFaYA3; Tue, 05 May 2020 08:46:25 -0700 X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.75]) by mx.groups.io with SMTP id smtpd.web11.10674.1588693584438287552 for ; Tue, 05 May 2020 08:46:25 -0700 X-Received: from DB6P192CA0018.EURP192.PROD.OUTLOOK.COM (2603:10a6:4:b8::28) by AM0SPR01MB0077.eurprd08.prod.outlook.com (2603:10a6:208:170::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26; Tue, 5 May 2020 15:46:21 +0000 X-Received: from DB5EUR03FT034.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:b8:cafe::f9) by DB6P192CA0018.outlook.office365.com (2603:10a6:4:b8::28) 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:21 +0000 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58645+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT034.mail.protection.outlook.com (10.152.20.87) 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:20 +0000 X-Received: ("Tessian outbound b3a67fbfbb1f:v54"); Tue, 05 May 2020 15:46:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 38be4f80e43f7bd4 X-CR-MTA-TID: 64aa7808 X-Received: from 971ac25efc23.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DD98A327-9269-40E2-8FA1-8676775BF4F5.1; Tue, 05 May 2020 15:46:15 +0000 X-Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 971ac25efc23.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cjaRwMYJwkge4YHObF9ptiEdV5joeDdvHUG4er6ju/jZz5qGOiJ+XUW/EvlI0Eqpr+9WBb+ObjwXtxCodnTjwkwvmzfc0bfBQ1nq6X7Qizpk/iz1xfnhbFj+PA5RfOEQOwo6LdykXk5V8ZBYvzfMV2qdLvcF8cTLsTzio4oZhgwPaHd6xsAItiRdMHNkqCO8Jy4V/yGKTdc9IZwpTPC/+EB0ILzVu4cy1ozTdbAtuPHFcZ4DEH7yA+CjEjfLUosvjleSwS6161HrYidZz4sGdt4rqB+kZ0icD4yqeH4GHtPqeMqfKK/c9zgl9Yr3f29s0uQl8mUsSqIzk1Z4pGrF3w== 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=LTBM1SZ9Ohdht9ArrOgG/NcAkKf626gIZmNmOUQdLl4=; b=YtetycrQrZrCEAp2mbTybgJtILU0ijZW7tiaRFHUfhUjBZTVhl88AYNJjR2gMexCEZgC5D+9KOY3xXQ3bYinCxWq98RnjC8mhZ1s+xBoCCPaDe6KDfgagHlfgAOJPv8HMl46NLgpyLaM4hS6xaJ1QvWsobI99ep/YYpK+cBKii/UGPSiai3jqxp72YLIoNRdcCWajNpmMKcvwwRrYQiffhHX/MGVpYPXwzbC+dQ56U5CIbp2hnHOjrYl2IWyeMKcFFzq8czliey3DyeVh9tNV/YT88WTGbXgtV5jKkjzZXc4LmRRpRAM139hD9tqmmUkFr45zrE0D5WdzC7fvWoCNA== 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 X-Received: from AM6P195CA0076.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::17) by HE1PR0801MB1755.eurprd08.prod.outlook.com (2603:10a6:3:86::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.27; Tue, 5 May 2020 15:46:13 +0000 X-Received: from AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:86:cafe::aa) by AM6P195CA0076.outlook.office365.com (2603:10a6:209:86::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 15:46:13 +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; X-Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT033.mail.protection.outlook.com (10.152.16.99) 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:13 +0000 X-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:06 +0000 X-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:06 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [edk2-devel] [PATCH v1 2/6] ShellPkg: acpiview: Make MADT parsing logic data driven Date: Tue, 5 May 2020 16:46:00 +0100 Message-ID: <20200505154604.9848-3-krzysztof.koch@arm.com> 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)(39860400002)(346002)(376002)(136003)(396003)(46966005)(33430700001)(316002)(1076003)(7696005)(70206006)(426003)(81166007)(86362001)(336012)(2616005)(8676002)(26005)(54906003)(4326008)(70586007)(186003)(33440700001)(5660300002)(36756003)(47076004)(478600001)(6916009)(82740400003)(82310400002)(44832011)(8936002)(356005)(2906002)(6666004);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 872973fc-6b90-41a2-1e4e-08d7f10b752c X-MS-TrafficTypeDiagnostic: HE1PR0801MB1755:|AM0SPR01MB0077: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: akR7+6DtOShOPxwmSV0aN4gGU3+uKBoehTTY+Y1Gcegfc2R44PWRjWiUBfoKG4rXwjQUb0C62ka4hYRbfViIBGZnlwEWPhKcJpnH4MDeETqi6GOC8jj5FfFQBR+AlQI7n58bHXE1tfx/goEq7TvhQLfcOtiTSzQQawv2I6zLCQM7TpuEU5gaXRzpty7yAIQ1zKLS4JQpEUCSxHN848FdZKratJhDO4qsKfxa9hIFezSXlex8HruxFBh7OvdcsRTLK/bc3XhI4cpR1anQfp47/nJKAyv1vVnRqzPhOnWLhxG2iRSrIZp37aqtUqwH639Vi2GU7+6eh80Ip8Q9/YP1rtrbgke3lMxTlCXi6FC61fEyl0eHQ7xMQDQNs3p5QhGFxSoV5D7u2e8J0o+cDyqlwfYLaBPcP4or6PeUqOwG5biw5rC6K6+eqtgi0FeFZcNPTt2j/CF3fwfxm6JLG8XKRHggVTBnuo7gCG4l+c4MHw1VyBl0UIR/hfDM4/yVUgAS3pJ14W6aPWD431XycPMDWg1KAT9z48nAHOjTL8WRScLJtk6fhAjWmZVLqmAAUoz05tVN3o20nn8vvyCUzIWcew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1755 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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: fc852d6f-2e34-4fb5-6356-08d7f10b7080 X-Microsoft-Antispam-Message-Info: h3/65TVhhMmDHOM5CKQC8i1fkMx4Zvu9aCE/IByrBvYOCc2NBZMbLaic+hmVFzb9DnMZbyQ430z7AEGot5Papk6rNZ9rPA+yj98rl2tZkNwfn+grx/5FGmUd8ToZ9x0kO2bY3aXWi9LVqNGskyRmkg0cdvC+6P/tNCPxsFmeH0kCHsy8Dx659UVKL9P3Ym7/akq2PbjIBYmCN/KOHw3TbbdxjlsjFI0HdbMHB9CnpuT41liGQ+/SJWmC6ODcB5xmaXjauxELPuRRg3uFWSWa2L1xhqaM0PPb3VHUiB2bXBE0+chxuNQFkcq3g6kaiaj8ASw9Xv8Vtr57ZXDIQ2+Q/bEyfNkYWwMNoKHG9IMi9GmgPVzLuHwjHPni8h6LUVbSM2+ggfXlWZbqzj/SzieLv3dQqRtsgheF73KDuw0UxPa1mQs1/wzIWJAqW6VPN3K3Y3kSHVw49KVE8PTxwPb1CBee6Ft9mjEACU8yc6PlvHzAvBy0aJA94wfipIHVSeR0nVvh7cNNpCLu7s4UdZWpKk/0PeI7tuEa2W9eOxp/GQrF4F7kL9ghljgTzqBg/TbA9YfmZpLWv3EFu7O2DPSKng== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:20.8894 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 872973fc-6b90-41a2-1e4e-08d7f10b752c 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: AM0SPR01MB0077 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: EYxe3tExR7zzRQn3VTAmbUl5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693585; bh=AdCXcNCiQGYEX0cIURmhTy2Hf83SNW6XJV1nFmuUu6Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fNw51y+WbqJiHK1bIYIk8ZvGFB2MgL1GhlFL1NkFNni5oFx24gFairCi+JAPawEcnPE J3/SWSBhP9CVAQNupx/St+/ca9RcFAqtkFZ2fHTLa/WC4AwcVUSMZPyM6mKh6tJuBQV2z 6vc0K7LAGzmCVXfpmQ2Fw2VQQ+E5cPAnJhY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the switch statement in the main parser loop with a table-driven approach. Use the ParseAcpiStruct () method to resolve how each Interrupt Controller Structure given should be parsed. Enumerate all structures found in the Multiple APIC Description Table (MADT) on a per-type basis. Print the offset from the start of the table for each structure. Consolidate all metadata about each Interrupt Controller Structure. 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 MADT. Count the number of instances of each Interrupt Controller Structure type. Optionally report these counts after MADT table parsing is finished. Validate that Advanced Programmable Interrupt Controller (APIC) structures are not present on Arm-based platforms. For Arm-based platforms, make existing GIC Distributor (GICD) instance count validation code use ACPI_STRUCT_INFO. References: - ACPI 6.3 Specification - January 2019, Section 5.2.12 Signed-off-by: Krzysztof Koch --- Notes: v1: - Make MADT parsing logic data driven [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 2= 17 ++++++++++++-------- ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.h | = 3 +- 2 files changed, 134 insertions(+), 86 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/Madt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtPa= rser.c index f85d2b36532cfc5db36fe7bef9830cccc64969cc..00898a8853f45de1f813d71fe52= 920185bc92e2a 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c @@ -15,6 +15,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" #include "MadtParser.h" =20 // Local Variables @@ -200,6 +201,106 @@ STATIC CONST ACPI_PARSER MadtInterruptControllerHeade= rParser[] =3D { {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL} }; =20 +/** + Information about each Interrupt Controller Structure type. +**/ +STATIC ACPI_STRUCT_INFO MadtStructs[] =3D { + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Processor Local APIC", + EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "I/O APIC", + EFI_ACPI_6_3_IO_APIC, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Interrupt Source Override", + EFI_ACPI_6_3_INTERRUPT_SOURCE_OVERRIDE, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "NMI Source", + EFI_ACPI_6_3_NON_MASKABLE_INTERRUPT_SOURCE, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Local APIC NMI", + EFI_ACPI_6_3_LOCAL_APIC_NMI, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Local APIC Address Override", + EFI_ACPI_6_3_LOCAL_APIC_ADDRESS_OVERRIDE, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "I/O SAPIC", + EFI_ACPI_6_3_IO_SAPIC, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Local SAPIC", + EFI_ACPI_6_3_LOCAL_SAPIC, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Platform Interrupt Sources", + EFI_ACPI_6_3_PLATFORM_INTERRUPT_SOURCES, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Processor Local x2APIC", + EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ACPI_STRUCT_INFO_PARSER_NOT_IMPLEMENTED ( + "Local x2APIC NMI", + EFI_ACPI_6_3_LOCAL_X2APIC_NMI, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GICC", + EFI_ACPI_6_3_GIC, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + GicCParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GICD", + EFI_ACPI_6_3_GICD, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + GicDParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GIC MSI Frame", + EFI_ACPI_6_3_GIC_MSI_FRAME, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + GicMSIFrameParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GICR", + EFI_ACPI_6_3_GICR, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + GicRParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GIC ITS", + EFI_ACPI_6_3_GIC_ITS, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + GicITSParser + ) +}; + +/** + MADT structure database +**/ +STATIC ACPI_STRUCT_DATABASE MadtDatabase =3D { + "Interrupt Controller Structure", + MadtStructs, + ARRAY_SIZE (MadtStructs) +}; + /** This function parses the ACPI MADT table. When trace is enabled this function parses the MADT table and @@ -231,14 +332,13 @@ ParseAcpiMadt ( { UINT32 Offset; UINT8* InterruptContollerPtr; - UINT32 GICDCount; - - GICDCount =3D 0; =20 if (!Trace) { return; } =20 + ResetAcpiStructCounts (&MadtDatabase); + Offset =3D ParseAcpi ( TRUE, 0, @@ -267,7 +367,8 @@ ParseAcpiMadt ( IncrementErrorCount (); Print ( L"ERROR: Insufficient remaining table buffer length to read the " \ - L"Interrupt Controller Structure header. Length =3D %d.\n", + L"%a header. Length =3D %d.\n", + MadtDatabase.Name, AcpiTableLength - Offset ); return; @@ -278,8 +379,9 @@ ParseAcpiMadt ( ((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid Interrupt Controller Structure length. " \ - L"Length =3D %d. Offset =3D %d. AcpiTableLength =3D %d.\n", + L"ERROR: Invalid %a length. Length =3D %d. Offset =3D %d. " \ + "AcpiTableLength =3D %d.\n", + MadtDatabase.Name, *MadtInterruptControllerLength, Offset, AcpiTableLength @@ -287,87 +389,32 @@ ParseAcpiMadt ( return; } =20 - switch (*MadtInterruptControllerType) { - case EFI_ACPI_6_3_GIC: { - ParseAcpi ( - TRUE, - 2, - "GICC", - InterruptContollerPtr, - *MadtInterruptControllerLength, - PARSER_PARAMS (GicCParser) - ); - break; - } - - case EFI_ACPI_6_3_GICD: { - if (++GICDCount > 1) { - IncrementErrorCount (); - Print ( - L"ERROR: Only one GICD must be present," - L" GICDCount =3D %d\n", - GICDCount - ); - } - ParseAcpi ( - TRUE, - 2, - "GICD", - InterruptContollerPtr, - *MadtInterruptControllerLength, - PARSER_PARAMS (GicDParser) - ); - break; - } - - case EFI_ACPI_6_3_GIC_MSI_FRAME: { - ParseAcpi ( - TRUE, - 2, - "GIC MSI Frame", - InterruptContollerPtr, - *MadtInterruptControllerLength, - PARSER_PARAMS (GicMSIFrameParser) - ); - break; - } - - case EFI_ACPI_6_3_GICR: { - ParseAcpi ( - TRUE, - 2, - "GICR", - InterruptContollerPtr, - *MadtInterruptControllerLength, - PARSER_PARAMS (GicRParser) - ); - break; - } - - case EFI_ACPI_6_3_GIC_ITS: { - ParseAcpi ( - TRUE, - 2, - "GIC ITS", - InterruptContollerPtr, - *MadtInterruptControllerLength, - PARSER_PARAMS (GicITSParser) - ); - break; - } - - default: { - IncrementErrorCount (); - Print ( - L"ERROR: Unknown Interrupt Controller Structure," - L" Type =3D %d, Length =3D %d\n", - *MadtInterruptControllerType, - *MadtInterruptControllerLength - ); - } - } // switch + // Parse the Interrupt Controller Structure + ParseAcpiStruct ( + 2, + InterruptContollerPtr, + &MadtDatabase, + Offset, + *MadtInterruptControllerType, + *MadtInterruptControllerLength, + NULL, + NULL + ); =20 InterruptContollerPtr +=3D *MadtInterruptControllerLength; Offset +=3D *MadtInterruptControllerLength; } // while + + // Report and validate Interrupt Controller Structure counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&MadtDatabase); + + if (MadtStructs[EFI_ACPI_6_3_GICD].Count > 1) { + IncrementErrorCount (); + Print ( + L"ERROR: Only one %a must be present\n", + MadtStructs[EFI_ACPI_6_3_GICD].Name + ); + } + } } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/Madt= Parser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtPa= rser.h index fbbc43e09adbdf9fea302a03a61e6dc179f06a62..25128081816459106e43ef5c98a= cd23dc1f910c3 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.h @@ -1,13 +1,14 @@ /** @file Header file for MADT table parser =20 - Copyright (c) 2019, ARM Limited. All rights reserved. + Copyright (c) 2020, ARM Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent =20 @par Reference(s): - Arm Generic Interrupt Controller Architecture Specification, GIC architecture version 3 and version 4, issue E - Arm Server Base System Architecture 5.0 + - ACPI 6.3 Specification - January 2019, Section 5.2.12 **/ =20 #ifndef MADT_PARSER_H_ -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58645): https://edk2.groups.io/g/devel/message/58645 Mute This Topic: https://groups.io/mt/74000910/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 4 13:43:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58643+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588693583872333.56189515797007; Tue, 5 May 2020 08:46:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uUqyYY1788612xoCmnctPMt1; Tue, 05 May 2020 08:46:23 -0700 X-Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.44]) by mx.groups.io with SMTP id smtpd.web12.10696.1588693581894746032 for ; Tue, 05 May 2020 08:46:22 -0700 X-Received: from AM7PR04CA0006.eurprd04.prod.outlook.com (2603:10a6:20b:110::16) by HE1PR0801MB2108.eurprd08.prod.outlook.com (2603:10a6:3:51::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.21; Tue, 5 May 2020 15:46:19 +0000 X-Received: from VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:110:cafe::32) by AM7PR04CA0006.outlook.office365.com (2603:10a6:20b:110::16) 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:19 +0000 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58643+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT046.mail.protection.outlook.com (10.152.19.226) 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:18 +0000 X-Received: ("Tessian outbound b3a67fbfbb1f:v54"); Tue, 05 May 2020 15:46:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 183ecd3ec8c5d1e7 X-CR-MTA-TID: 64aa7808 X-Received: from 73efd33e49d0.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 12AFBE3E-E75A-4D37-9A93-434844198231.1; Tue, 05 May 2020 15:46:12 +0000 X-Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 73efd33e49d0.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gvIj5ceEQnjZ6Dj0/kZjeXTxMQ5gW2GrxjGmncE6nwGuiNrc7UpbPxfLSWNIXVyBuUg3hlerC6zjDg5PxvBYp3CZ+6G3EjV2gaDpX+YUqvc4c9GveYEwf8zfuB9zmgZWr3G+wxtuSHea5uLoUHvHm/ZjfC5othehyr4z0ySA7JynHoP5vwAvyVMW9RpLiAU7mtCol3tV6SjKMUD/2fxcfdqqipJ+S/D0FghSg8nbO9STH0YfWrKKs6kG1nCzW/9nLo70Qk5+ibrPhkqWWfC0/GS6fXLyDIYjsz1aLKr7Sa1M2dzdfrgYx9HGPgd2xyMtlD9a0unUURDdkZ/FOHDHrQ== 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=m+ICCV54uSnBQ7v6nyogxbyS7FGEoF+HkQWGUoprtTY=; b=IGcq2B1c8njSmY0PnlqHBQ/AB1RFyitOvaJ7Df2etplbU5ECbhHEZHPWjBq3SwJW85a6cpqcwYCogqT33ysf2ekMe+wgBbTLxACW5izmc8Vu79HLqtmLDy5u4Qzg0cu1IJRazu+7JImCQ5iur5jD1yJKiPPy5UAbq4mn04tDjloxM64t/VXlpex3qUa+TtVhhsboHA/TuLUzcaZqgJYpUPhYRA9yYOmQjbxhoHUMgXIQnasI2Em3DQGyOZYVYQQmaPA+jOVuB56pF3DV9odEbnwSammd5rnJIfeDsfRvxbVX3JS3Dm/DpPNl0rplUg5X8CV5Ld1lZfcVy399o4RHJA== 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 X-Received: from DB6PR07CA0201.eurprd07.prod.outlook.com (2603:10a6:6:42::31) by DB6PR0801MB1687.eurprd08.prod.outlook.com (2603:10a6:4:39::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.29; Tue, 5 May 2020 15:46:12 +0000 X-Received: from DB5EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:42:cafe::13) by DB6PR07CA0201.outlook.office365.com (2603:10a6:6:42::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.17 via Frontend Transport; Tue, 5 May 2020 15:46:12 +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; X-Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT058.mail.protection.outlook.com (10.152.20.255) 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:11 +0000 X-Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Tue, 5 May 2020 15:46:07 +0000 X-Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) 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; Tue, 5 May 2020 15:46:07 +0000 X-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:07 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [edk2-devel] [PATCH v1 3/6] ShellPkg: acpiview: Make SRAT parsing logic data driven Date: Tue, 5 May 2020 16:46:01 +0100 Message-ID: <20200505154604.9848-4-krzysztof.koch@arm.com> 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)(136003)(39860400002)(346002)(376002)(396003)(46966005)(33430700001)(33440700001)(478600001)(1076003)(5660300002)(6666004)(86362001)(36756003)(2906002)(26005)(82310400002)(70206006)(186003)(4326008)(70586007)(19627235002)(336012)(2616005)(426003)(44832011)(81166007)(6916009)(356005)(7696005)(316002)(8936002)(82740400003)(47076004)(54906003)(8676002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d68967b0-8243-4a2a-68b9-08d7f10b73d7 X-MS-TrafficTypeDiagnostic: DB6PR0801MB1687:|HE1PR0801MB2108: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: yC5JQTM08Mg49XTdNf+wZSzxdPBtbw3uYJ8iNA0bjksQuc/2+XfVIiJy6FtkrRluc//mmqveb91EmuI9AGOSBGc0j0C09PsFJASI0LN6dDxhQ595K+YVuGazOZCK3f4RODucq7wVXxd7UW1e1J+y73uUcYB749gd+47DCCg3tMzoHQTdcmZnMd6kjliwri43HwPX+rvir5klfHqjJZrbUDdIea/Y6+/JlMDtJVs9EfeGAo+3AzhdNF7yGPQr/QXT7moi7hsol8LFb9vtVIV9KmGbxC4rp7PVmFyEm+yq2FT1asDKEelMwE8PPf6BAndynMrkjwJooKdglJF/ecXCsYOsM6G06dz3g9sJynYNFYQBCGtHd7URNQdYU5HAUll7UNA3Nwrp6dLpceRYcG0I+bWQWjVtXnumc5/m8ssE2xE4lrU38MoK7oT9UiR5TXmwyVErrjz4dMm5dhDGkFGfSXUyQvpzuamDAldp7kaEJrPlGhR6yltHwP8mVniJVwd6MprgC29Eu6LjGkvl2pvHeLL5hfj3a+CZVdEilGPSuT7itvABNS4LGbYlSQy8HnjPWAu0V0qhJ/bqLnEPhPO+Ow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1687 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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 934dbb30-e880-4f20-6c26-08d7f10b6fcf X-Microsoft-Antispam-Message-Info: io7HOv5N3qlakkdD4wqqxuFLnNYjrzG03OFnw3E7f6uW9/E5TgdUIq5nCjmm92LQ5FaclxILYKhWfVVflPZpYteBIhQ5DQociQComt2v9EDGTjVb5cRBaubXATaXWX9PwitP2f8YnbD5RLvDJ77c3Y2/QbV3dZ3Bv6ncZNYr+3g9/InI3k9kaTCqumWWBZ92kmjQCXRORZSgQNbYGR4SNo9RWoUAto+AKxF9SwpXr7g8cjMXgXJiwt89WWmgseNmSiN+HdhkxoMzvreaZtCFTm9UdqANSiSNqwjzpUVmlGKyPMJr4GSkA0RkPZWZWOLxOSXwRiACi7ZIoleS2bjtsxOnwodaizj9kRjGMl8cZWstH7SddLGuOkE7m0gKs8YVbKcBelYRjNk0d7+AfYQ7MtpbRTPHtbfIyvkvafmnmKkzQDtG/Ed6ykdjJuloPRzVjU52bo7enbQhTz9AjxLLrrttRdXKb6JYy0eXIzLDLo/Cwh5/v8EW7N/dKI3n92anfjslIzISGEe2lcaxj2CZXP0n6BY7EFZvNqWMS3dhK2Vx5DUEza0wu9VcSTxtGaoeX/kMwW/W6DMAGx2TagSSNA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:18.5206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d68967b0-8243-4a2a-68b9-08d7f10b73d7 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: HE1PR0801MB2108 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: z4ixOwZFphHmo00m1DUK4Q0Ax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693583; bh=isNYOY/suffhNkctuLQm9SFlFPwQy8lg4Si+1LdaPoY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cysCLNaLW+rO9vPF2K1xfvEApdpb0J2ugRVfeh+VqT0wfQrJxJQAeE/dG0BmvRRxmFj 0ocSdMKKaKHYDQgFPzYEP4bfpe7XMAurEWPaTllLJn+wcp4kCeG4he+dU8xIWuxIGwXEl j08uL8/ULjm1tVFOlHVw/l4ylfSaukICLrE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the switch statement in the main parser loop with a table-driven approach. Use the ParseAcpiStruct () method to resolve how each Static Resource Allocation Structure given should be parsed. Print the offset of each Static Resource Allocation Structure from the start of the table. Consolidate all metadata about each Static Resource Allocation Structure. 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 the System Resource Affinity Table (SRAT). Count the number of instances of each Static Resource Allocation Structure type. Optionally report these counts after SRAT table parsing is finished and validate that Advanced Programmable Interrupt Controller (APIC) structures are not present on Arm-based platforms. References: - ACPI 6.3 Specification - January 2019, Section 5.2.16 Signed-off-by: Krzysztof Koch --- Notes: v1: - Make SRAT parsing logic data driven [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 2= 04 ++++++++------------ 1 file changed, 77 insertions(+), 127 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/Srat= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratPa= rser.c index 6f66be68cc0bed14811a0432c61a79fd47c54890..8ec233a52861b039979bb8291b3= c90193acd86fa 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c @@ -13,6 +13,7 @@ #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // Local Variables STATIC CONST UINT8* SratRAType; @@ -330,6 +331,57 @@ STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = =3D { {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL} }; =20 +/** + Information about each Static Resource Allocation Structure type. +**/ +STATIC ACPI_STRUCT_INFO SratStructs[] =3D { + ADD_ACPI_STRUCT_INFO_ARRAY ( + "Processor Local APIC/SAPIC Affinity", + EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64, + SratApciSapicAffinityParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "Memory Affinity", + EFI_ACPI_6_3_MEMORY_AFFINITY, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AAR= CH64, + SratMemAffinityParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "Processor Local x2APIC Affinity", + EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64, + SratX2ApciAffinityParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GICC Affinity Structure", + EFI_ACPI_6_3_GICC_AFFINITY, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + SratGicCAffinityParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "GIC ITS Affinity", + EFI_ACPI_6_3_GIC_ITS_AFFINITY, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + SratGicITSAffinityParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "Generic Initiator Affinity", + EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM |ARCH_COMPAT_AARC= H64, + SratGenericInitiatorAffinityParser + ) +}; + +/** + SRAT structure database +**/ +STATIC ACPI_STRUCT_DATABASE SratDatabase =3D { + "Static Resource Allocation Structure", + SratStructs, + ARRAY_SIZE (SratStructs) +}; + /** This function parses the ACPI SRAT table. When trace is enabled this function parses the SRAT table and @@ -357,27 +409,15 @@ ParseAcpiSrat ( IN UINT8 AcpiTableRevision ) { - UINT32 Offset; - UINT8* ResourcePtr; - UINT32 GicCAffinityIndex; - UINT32 GicITSAffinityIndex; - UINT32 GenericInitiatorAffinityIndex; - UINT32 MemoryAffinityIndex; - UINT32 ApicSapicAffinityIndex; - UINT32 X2ApicAffinityIndex; - CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi - - GicCAffinityIndex =3D 0; - GicITSAffinityIndex =3D 0; - GenericInitiatorAffinityIndex =3D 0; - MemoryAffinityIndex =3D 0; - ApicSapicAffinityIndex =3D 0; - X2ApicAffinityIndex =3D 0; + UINT32 Offset; + UINT8* ResourcePtr; =20 if (!Trace) { return; } =20 + ResetAcpiStructCounts (&SratDatabase); + Offset =3D ParseAcpi ( TRUE, 0, @@ -406,7 +446,8 @@ ParseAcpiSrat ( IncrementErrorCount (); Print ( L"ERROR: Insufficient remaining table buffer length to read the " \ - L"Static Resource Allocation structure header. Length =3D %d.\n", + L"%a header. Length =3D %d.\n", + SratDatabase.Name, AcpiTableLength - Offset ); return; @@ -417,8 +458,9 @@ ParseAcpiSrat ( ((Offset + (*SratRALength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid Static Resource Allocation Structure length. " \ - L"Length =3D %d. Offset =3D %d. AcpiTableLength =3D %d.\n", + L"ERROR: Invalid %a length. Length =3D %d. Offset =3D %d. " \ + L"AcpiTableLength =3D %d.\n", + SratDatabase.Name, *SratRALength, Offset, AcpiTableLength @@ -426,116 +468,24 @@ ParseAcpiSrat ( return; } =20 - switch (*SratRAType) { - case EFI_ACPI_6_3_GICC_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "GICC Affinity Structure [%d]", - GicCAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratGicCAffinityParser) - ); - break; - - case EFI_ACPI_6_3_GIC_ITS_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "GIC ITS Affinity Structure [%d]", - GicITSAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratGicITSAffinityParser) - ); - break; - - case EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "Generic Initiator Affinity Structure [%d]", - GenericInitiatorAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratGenericInitiatorAffinityParser) - ); - break; - - case EFI_ACPI_6_3_MEMORY_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "Memory Affinity Structure [%d]", - MemoryAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratMemAffinityParser) - ); - break; - - case EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "APIC/SAPIC Affinity Structure [%d]", - ApicSapicAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratApciSapicAffinityParser) - ); - break; - - case EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY: - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "X2APIC Affinity Structure [%d]", - X2ApicAffinityIndex++ - ); - ParseAcpi ( - TRUE, - 2, - Buffer, - ResourcePtr, - *SratRALength, - PARSER_PARAMS (SratX2ApciAffinityParser) - ); - break; - - default: - IncrementErrorCount (); - Print (L"ERROR: Unknown SRAT Affinity type =3D 0x%x\n", *SratRATyp= e); - break; - } + // Parse the Static Resource Allocation Structure + ParseAcpiStruct ( + 2, + ResourcePtr, + &SratDatabase, + Offset, + *SratRAType, + *SratRALength, + NULL, + NULL + ); =20 ResourcePtr +=3D (*SratRALength); Offset +=3D (*SratRALength); } + + // Report and validate Static Resource Allocation Structure counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&SratDatabase); + } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58643): https://edk2.groups.io/g/devel/message/58643 Mute This Topic: https://groups.io/mt/74000906/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 4 13:43:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58646+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588693589238368.78463679942365; Tue, 5 May 2020 08:46:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZJrHYY1788612xQGn7No4qMW; Tue, 05 May 2020 08:46:28 -0700 X-Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.81]) by mx.groups.io with SMTP id smtpd.web11.10677.1588693587707464757 for ; Tue, 05 May 2020 08:46:28 -0700 X-Received: from DBBPR09CA0010.eurprd09.prod.outlook.com (2603:10a6:10:c0::22) by VI1PR0802MB2558.eurprd08.prod.outlook.com (2603:10a6:800:ae::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.21; Tue, 5 May 2020 15:46:24 +0000 X-Received: from DB5EUR03FT011.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::7a) by DBBPR09CA0010.outlook.office365.com (2603:10a6:10:c0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 15:46:24 +0000 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58646+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT011.mail.protection.outlook.com (10.152.20.95) 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:24 +0000 X-Received: ("Tessian outbound fb9de21a7e90:v54"); Tue, 05 May 2020 15:46:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 44b4b4a18bbae059 X-CR-MTA-TID: 64aa7808 X-Received: from 614dce46c6eb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3499806F-738C-4AC5-8393-F25476065FDF.1; Tue, 05 May 2020 15:46:18 +0000 X-Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 614dce46c6eb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WBseuiVD/hDa3eFS3JNWVIRx4pDNvlmaz3rspxbCC7SJGsy9DBsj7UK3seg490GgwNcwXGnCl/SVU/h6Z9aTQ1pyW1kKYRrIm4tVB8XLKnygiDEscxVQWjxTPnP/FsrjzpwuGZ5KIgq/igg76SOD0esMqgf+HlH0GsCSh1KmDrULWcbqmbiiED6iCaxOSyabGQRtCOPTu0DiKGAcJRT3+DPsS4dfakxM5707/M9O7PkNHdFwbheSzhr5gdcgxhMxeCEKIilDoBjok10VOTTkCr7wS7wvv0mjhg/VOWhhkcofeVZeSBTpaeiYEBTMEtHcItoMDfYNInO9Ue5AkUhbGA== 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=3taRU50Ha63N9heycQdXv9kEDz2fGdNqqStU9vT3hZE=; b=jmV/5qypc6jzOaJHU/lCxtU4Jr5AXF0VYQviU629aWXtQ67skbkE7O6cBWdtdQlPLXWi7b1eZc5Qc+yO8rUrHUbGtfe3vooU6TT5XpXTogzgF3e/gQynDEpkSFhMc6IBcnrztNsi1u5eQ24/VWbVAg/fF04MfmOi3NPLhw69HGL90Qq4MIC75scn/qA4Fz0A5AyxINnTUpjxMDZ4cZXygVOrsEsnsffESx7kp+VBKzS0uIYsr5Qi04GE0k8DdetkOvs2REPuXUN7KCybZNzYbUtyhaWixobWgORkg/a1bNTz1dLmbHdwedN5iq/fxn12z9NpSDYe2Gla2dVJdd1scQ== 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 X-Received: from AM5PR04CA0011.eurprd04.prod.outlook.com (2603:10a6:206:1::24) by DB6PR08MB2837.eurprd08.prod.outlook.com (2603:10a6:6:19::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.27; Tue, 5 May 2020 15:46:18 +0000 X-Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::2a) by AM5PR04CA0011.outlook.office365.com (2603:10a6:206:1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 15:46:18 +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; X-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:17 +0000 X-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 X-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:07 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [edk2-devel] [PATCH v1 4/6] ShellPkg: acpiview: Make GTDT parsing logic data driven Date: Tue, 5 May 2020 16:46:02 +0100 Message-ID: <20200505154604.9848-5-krzysztof.koch@arm.com> 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)(136003)(346002)(376002)(39860400002)(396003)(46966005)(33430700001)(8676002)(26005)(70586007)(36756003)(70206006)(336012)(316002)(7696005)(426003)(186003)(1076003)(33440700001)(5660300002)(8936002)(82310400002)(478600001)(2906002)(4326008)(6916009)(6666004)(54906003)(86362001)(356005)(2616005)(47076004)(81166007)(82740400003)(44832011);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7ccda3d-a717-493f-8f29-08d7f10b7743 X-MS-TrafficTypeDiagnostic: DB6PR08MB2837:|VI1PR0802MB2558: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 0hpjZ2SvVpWBnrXsPJaMTzP8h7p/grgIUMoKYp6QWiadHmRBgpB5YNr4LFp37jQQXnDH+QTAEfWk43uMdsr99TQfqD0wbQHTGLH3+2FGwJVrR/WzWXX1Ya3EGYlrIWGxStHhdANTWr00WSCo/7pI1Paz4KLUxeVa+hsEpEmi4kEm5gnFVaEbi4o+jykkZTCbK7IflngTdcNgTgAGtPwAgkwuqlhvI3J1LJjRLIZ/veQH21oXDGZE+IHgSUtSZRPMRMzOMzsqQo13P+BOCr+HXXHPveNXR+clGaUnIFoZTFxY2OlFTHSFnera3v7TfdLaU+P/xNWUBG3caCinyKq2xBay+29m7RY+dFpdEB7i79lGH7TgpULCJKbht5gTjDc8Cn3pbQJa+oEKJLC29+Aa/u91NFY8lobrUSYZh+4Fnj+rgHWwxwGCGxHoXYZu/QoDY2fC5VdPQ8P7xNRB+RMTBo8bdexaOyUmCQxpy5iFjUstfI6gsjCvHI7xXyEoSAu6po8eYsPerlMj676vKbZNJCfjNMja4Jgj0yKXS1ktBBv9D13V3n6P0Ljfho9KY9p8KABnHjFlz/CMkktT7Vj5qA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2837 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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT011.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 5b76adea-d9d3-43dc-b3a1-08d7f10b7348 X-Microsoft-Antispam-Message-Info: VlPuU1+YUm8wEBR1Tv6kS0peO+x1JcsUWYvxqBTigKtDjQcYMcvS7swfUU9JnrCwCyk8wJ5N9C1pGb6E/GqLDWOxsSfbShwFvHtawXciAgbRWsFQd/HU6Y83G6I7D2h4iHe8+794fq+DZYE9VlHvqx6Cud573ieAXfz5B8KVT6vugAey5cRLsMu1StTEMqwEnIHcjxuzH6Ve/b3Sm3EfqyL09fp4qbeYUfncySIfj7eVzsqAk85Q8XrY9JNLVNAUWmm6pdjFJaeh3VjvjfyHMCxmWgaVVicFDbOD4HK3zX4Zc8yWeADeeXgiOfK0RapDErTgcuyHeyu03xasHOLAG85ICh5/krMhrNkYIF3cfjBIjumv6utbCZkO1DHAXBucXZ08V9eouQxkpDVc7P7J3S9e7w4uf13nhHDNBAFr9vo8Y4nQUMC20rCR1l4HPiaiDhJNKjVCmy3n7rG1IwsowZfHMY5Ka2ERilZNvz16cSJh4uf0FpT1IdjY5c6SVvFyqVe461Mpg4f9uEEwTZcD0uYKr/QM9cBcj8/DEJIjzvgX1HgNejk7x0xlBmtd/scu8nhUtEy15iM/LrxiIoYaYg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:24.3975 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7ccda3d-a717-493f-8f29-08d7f10b7743 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: VI1PR0802MB2558 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: cS26CVM5vGgG5vriUp7NLOu5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693588; bh=l3Qf3MOJpGc9qY9jCnlEmhaol6vSQ9P9zWzWyi6/mWU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=dQVbWku6w8iQvZgUdYh1LrQJms+2FAwoFSydg1H32gjozIw/92gicna7nhUcmHZytHB 8KhrIqIOTpU0fh8N6W7mcrYZAEGl/Z/InWctS+W4ks4HFoa7pbIV9uE8HLJyvZIkOdGrl GIHRyfOgLHYuQZHnuirlhwIg0woqPCa9K9Q= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the switch statement in the main parser loop with a table-driven approach. Use the ParseAcpiStruct () method to resolve how each Platform Timer Structure given should be parsed. Enumerate all structures found in the Generic Timer Description Table (GTDT) on a per-type basis. Print the offset from the start of the table for each structure. Consolidate all metadata about each Platform Timer Structure. 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 GTDT. Count the number of instances of each Platform Timer Structure type. Optionally report these counts after GTDT table parsing is finished. Modify DumpGTBlock () funtion signature so that it matches that of ACPI_STRUCT_PARSER_FUNC. This way, the function can be used in the ParseAcpiStruct () call. Remove the definition of the DumpWatchdogTimer (). Its only purpose was to call ParseAcpi () and now this process is streamlined. References: - ACPI 6.3 Specification - January 2019, Section 5.2.24 Signed-off-by: Krzysztof Koch --- Notes: v1: - Make GTDT parsing logic data driven [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c | 1= 23 ++++++++++++-------- 1 file changed, 77 insertions(+), 46 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/Gtdt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtPa= rser.c index bdd30ff45c61142c071ead63a27babab8998721b..9a9f8fda442081507768b1540f0= b9b3c6c254329 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c @@ -9,13 +9,20 @@ **/ =20 #include +#include #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // "The number of GT Block Timers must be less than or equal to 8" #define GT_BLOCK_TIMER_COUNT_MAX 8 =20 +/** + Handler for each Platform Timer Structure type +**/ +STATIC ACPI_STRUCT_INFO GtdtStructs[]; + // Local variables STATIC CONST UINT32* GtdtPlatformTimerCount; STATIC CONST UINT32* GtdtPlatformTimerOffset; @@ -167,23 +174,35 @@ STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = =3D { /** This function parses the Platform GT Block. =20 - @param [in] Ptr Pointer to the start of the GT Block data. - @param [in] Length Length of the GT Block structure. + @param [in] Ptr Pointer to the start of structure's 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 DumpGTBlock ( - IN UINT8* Ptr, - IN UINT16 Length + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL ) { UINT32 Index; UINT32 Offset; + CHAR8 Buffer[80]; + + PrintAcpiStructName ( + GtdtStructs[EFI_ACPI_6_3_GTDT_GT_BLOCK].Name, + GtdtStructs[EFI_ACPI_6_3_GTDT_GT_BLOCK].Count, + sizeof (Buffer), + Buffer + ); =20 ParseAcpi ( TRUE, 2, - "GT Block", + Buffer, Ptr, Length, PARSER_PARAMS (GtBlockParser) @@ -195,7 +214,8 @@ DumpGTBlock ( (GtBlockTimerOffset =3D=3D NULL)) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient GT Block Structure length. Length =3D %d.\n", + L"ERROR: Insufficient %a Structure length. Length =3D %d.\n", + GtdtStructs[EFI_ACPI_6_3_GTDT_GT_BLOCK].Name, Length ); return; @@ -206,41 +226,47 @@ DumpGTBlock ( =20 // Parse the specified number of GT Block Timer Structures or the GT Blo= ck // Structure buffer length. Whichever is minimum. - while ((Index++ < *GtBlockTimerCount) && + while ((Index < *GtBlockTimerCount) && (Offset < Length)) { + PrintAcpiStructName ("GT Block Timer", Index, sizeof (Buffer), Buffer); Offset +=3D ParseAcpi ( TRUE, - 2, - "GT Block Timer", + 4, + Buffer, Ptr + Offset, Length - Offset, PARSER_PARAMS (GtBlockTimerParser) ); + Index++; } } =20 /** - This function parses the Platform Watchdog timer. - - @param [in] Ptr Pointer to the start of the watchdog timer data. - @param [in] Length Length of the watchdog timer structure. + Information about each Platform Timer Structure type. **/ -STATIC -VOID -DumpWatchdogTimer ( - IN UINT8* Ptr, - IN UINT16 Length - ) -{ - ParseAcpi ( - TRUE, - 2, +STATIC ACPI_STRUCT_INFO GtdtStructs[] =3D { + ADD_ACPI_STRUCT_INFO_FUNC ( + "GT Block", + EFI_ACPI_6_3_GTDT_GT_BLOCK, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + DumpGTBlock + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( "SBSA Generic Watchdog", - Ptr, - Length, - PARSER_PARAMS (SBSAGenericWatchdogParser) - ); -} + EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG, + ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64, + SBSAGenericWatchdogParser + ) +}; + +/** + GTDT structure database +**/ +STATIC ACPI_STRUCT_DATABASE GtdtDatabase =3D { + "Platform Timer Structure", + GtdtStructs, + ARRAY_SIZE (GtdtStructs) +}; =20 /** This function parses the ACPI GTDT table. @@ -275,6 +301,8 @@ ParseAcpiGtdt ( return; } =20 + ResetAcpiStructCounts (&GtdtDatabase); + ParseAcpi ( TRUE, 0, @@ -321,7 +349,8 @@ ParseAcpiGtdt ( IncrementErrorCount (); Print ( L"ERROR: Insufficient remaining table buffer length to read the " \ - L"Platform Timer Structure header. Length =3D %d.\n", + L"%a header. Length =3D %d.\n", + GtdtDatabase.Name, AcpiTableLength - Offset ); return; @@ -332,8 +361,9 @@ ParseAcpiGtdt ( ((Offset + (*PlatformTimerLength)) > AcpiTableLength)) { IncrementErrorCount (); Print ( - L"ERROR: Invalid Platform Timer Structure length. " \ - L"Length =3D %d. Offset =3D %d. AcpiTableLength =3D %d.\n", + L"ERROR: Invalid %a length. Length =3D %d. Offset =3D %d. " \ + L"AcpiTableLength =3D %d.\n", + GtdtDatabase.Name, *PlatformTimerLength, Offset, AcpiTableLength @@ -341,23 +371,24 @@ ParseAcpiGtdt ( return; } =20 - switch (*PlatformTimerType) { - case EFI_ACPI_6_3_GTDT_GT_BLOCK: - DumpGTBlock (TimerPtr, *PlatformTimerLength); - break; - case EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG: - DumpWatchdogTimer (TimerPtr, *PlatformTimerLength); - break; - default: - IncrementErrorCount (); - Print ( - L"ERROR: Invalid Platform Timer Type =3D %d\n", - *PlatformTimerType - ); - break; - } // switch + // Parse the Platform Timer Structure + ParseAcpiStruct ( + 2, + TimerPtr, + &GtdtDatabase, + Offset, + *PlatformTimerType, + *PlatformTimerLength, + NULL, + NULL + ); =20 TimerPtr +=3D *PlatformTimerLength; Offset +=3D *PlatformTimerLength; } // while + + // Report and validate Platform Timer Type Structure counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&GtdtDatabase); + } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58646): https://edk2.groups.io/g/devel/message/58646 Mute This Topic: https://groups.io/mt/74000913/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 4 13:43:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58647+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588693594081826.4000246876959; Tue, 5 May 2020 08:46:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id azSXYY1788612x7lWvtTclCd; Tue, 05 May 2020 08:46:33 -0700 X-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 X-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 X-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 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58647+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-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 X-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 X-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 X-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 X-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 X-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; X-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 X-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 X-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: [edk2-devel] [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> 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-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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 540dcfdd-bb6e-4be0-b5e1-08d7f10b7604 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 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: yBKOps6aZLCfZtvCLWafuF3ux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693593; bh=BUIzVWs4YpcoqoVWypGNeLCFp802pLNy/1L6T3qBp4s=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=JvAStQlsFxQiQ56Ff7KUYMqG9ZcdbOCOqsEozQnd+lBC3uKq+uQvta627ffQd7D/kpG D1aXLGjVVikV958MHkCy8FXDEpuMZVfDGvokfjrk1LgpRsBxdTP/gyr4BJ57SWx6MWGA0 Y6ZQfNU9rKTQu6/56cjN5kGT/la0chrl4bc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 3= 53 +++++++++++++------- 1 file changed, 234 insertions(+), 119 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/Iort= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortPa= rser.c index 9a006a01448b897865cd7cd85651c816933acf05..0c40447b4363f10c7ea5c9eeb28= 3cebeab24243a 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c @@ -9,10 +9,12 @@ **/ =20 #include +#include #include #include #include "AcpiParser.h" #include "AcpiTableParser.h" +#include "AcpiView.h" =20 // Local variables STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; @@ -32,6 +34,11 @@ STATIC CONST UINT32* PmuInterruptOffset; =20 STATIC CONST UINT32* ItsCount; =20 +/** + Handler for each IORT Node type +**/ +STATIC ACPI_STRUCT_INFO IortStructs[]; + /** This function validates the ID Mapping array count for the ITS node. =20 @@ -273,12 +280,7 @@ DumpIortNodeIdMappings ( =20 while ((Index < MappingCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, - sizeof (Buffer), - "ID Mapping [%d]", - Index - ); + PrintAcpiStructName ("ID Mapping", Index, sizeof (Buffer), Buffer); Offset +=3D ParseAcpi ( TRUE, 4, @@ -296,27 +298,42 @@ DumpIortNodeIdMappings ( =20 @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 !=3D NULL); + ASSERT (OptArg1 !=3D NULL); + + MappingCount =3D *((UINT32*)OptArg0); + MappingOffset =3D *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Name, + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Count, + sizeof (Buffer), + Buffer + ); =20 ParseAcpi ( TRUE, 2, - "SMMUv1 or SMMUv2 Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeSmmuV1V2Parser) @@ -330,7 +347,8 @@ DumpIortNodeSmmuV1V2 ( (PmuInterruptOffset =3D=3D NULL)) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient SMMUv1/2 node length. Length =3D %d\n", + L"ERROR: Insufficient %a Node length. Length =3D %d\n", + IortStructs[EFI_ACPI_IORT_TYPE_SMMUv1v2].Name, Length ); return; @@ -341,11 +359,11 @@ DumpIortNodeSmmuV1V2 ( =20 while ((Index < *InterruptContextCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "Context Interrupts Array", + Index, sizeof (Buffer), - "Context Interrupts Array [%d]", - Index + Buffer ); Offset +=3D ParseAcpi ( TRUE, @@ -363,11 +381,11 @@ DumpIortNodeSmmuV1V2 ( =20 while ((Index < *PmuInterruptCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "PMU Interrupts Array", + Index, sizeof (Buffer), - "PMU Interrupts Array [%d]", - Index + Buffer ); Offset +=3D ParseAcpi ( TRUE, @@ -392,23 +410,40 @@ DumpIortNodeSmmuV1V2 ( =20 @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 !=3D NULL); + ASSERT (OptArg1 !=3D NULL); + + MappingCount =3D *((UINT32*)OptArg0); + MappingOffset =3D *((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. =20 + 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 =20 + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Name, + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Count, + sizeof (Buffer), + Buffer + ); + Offset =3D ParseAcpi ( TRUE, 2, - "ITS Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeItsParser) @@ -452,7 +500,8 @@ DumpIortNodeIts ( if (ItsCount =3D=3D NULL) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient ITS group length. Length =3D %d.\n", + L"ERROR: Insufficient %a Node length. Length =3D %d.\n", + IortStructs[EFI_ACPI_IORT_TYPE_ITS_GROUP].Name, Length ); return; @@ -462,11 +511,11 @@ DumpIortNodeIts ( =20 while ((Index < *ItsCount) && (Offset < Length)) { - AsciiSPrint ( - Buffer, + PrintAcpiStructName ( + "GIC ITS Identifier Array", + Index, sizeof (Buffer), - "GIC ITS Identifier Array [%d]", - Index + Buffer ); Offset +=3D ParseAcpi ( TRUE, @@ -488,25 +537,41 @@ DumpIortNodeIts ( =20 @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 !=3D NULL); + ASSERT (OptArg1 !=3D NULL); + + MappingCount =3D *((UINT32*)OptArg0); + MappingOffset =3D *((UINT32*)OptArg1); + + PrintAcpiStructName ( + IortStructs[EFI_ACPI_IORT_TYPE_NAMED_COMP].Name, + IortStructs[EFI_ACPI_IORT_TYPE_NAMED_COMP].Count, + sizeof (Buffer), + Buffer + ); =20 Offset =3D ParseAcpi ( TRUE, 2, - "Named Component Node", + Buffer, Ptr, Length, PARSER_PARAMS (IortNodeNamedComponentParser) @@ -534,23 +599,40 @@ DumpIortNodeNamedComponent ( =20 @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 !=3D NULL); + ASSERT (OptArg1 !=3D NULL); + + MappingCount =3D *((UINT32*)OptArg0); + MappingOffset =3D *((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 ( =20 @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 !=3D NULL); + ASSERT (OptArg1 !=3D NULL); + + MappingCount =3D *((UINT32*)OptArg0); + MappingOffset =3D *((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 ( ); } =20 +/** + Information about each IORT Node type +**/ +STATIC ACPI_STRUCT_INFO IortStructs[] =3D { + 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 =3D { + "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; } =20 + 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 =3D %d.\n", + L"%a header. Length =3D %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 =3D %d. Offset =3D %d. AcpiTableLength =3D %d.\n", + L"ERROR: Invalid %a length. Length =3D %d. Offset =3D %d. " \ + L"AcpiTableLength =3D %d.\n", + IortDatabase.Name, *IortNodeLength, Offset, AcpiTableLength @@ -701,63 +855,24 @@ ParseAcpiIort ( return; } =20 - 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 =3D %d\n", *IortNodeTyp= e); - } // switch + // Parse the IORT Node + ParseAcpiStruct ( + 2, + NodePtr, + &IortDatabase, + Offset, + *IortNodeType, + *IortNodeLength, + IortIdMappingCount, + IortIdMappingOffset + ); =20 NodePtr +=3D (*IortNodeLength); Offset +=3D (*IortNodeLength); } // while + + // Report and validate IORT Node counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&IortDatabase); + } } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58647): https://edk2.groups.io/g/devel/message/58647 Mute This Topic: https://groups.io/mt/74000914/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 4 13:43:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+58648+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1588693595666728.0911515796466; Tue, 5 May 2020 08:46:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id R3BLYY1788612xvV0a28mJbJ; Tue, 05 May 2020 08:46:35 -0700 X-Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.46]) by mx.groups.io with SMTP id smtpd.web12.10702.1588693594363289164 for ; Tue, 05 May 2020 08:46:34 -0700 X-Received: from DB8PR09CA0024.eurprd09.prod.outlook.com (2603:10a6:10:a0::37) by AM7PR08MB5383.eurprd08.prod.outlook.com (2603:10a6:20b:102::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26; Tue, 5 May 2020 15:46:32 +0000 X-Received: from DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:a0:cafe::e1) by DB8PR09CA0024.outlook.office365.com (2603:10a6:10:a0::37) 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:32 +0000 Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+58648+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT020.mail.protection.outlook.com (10.152.20.134) 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:32 +0000 X-Received: ("Tessian outbound b3a67fbfbb1f:v54"); Tue, 05 May 2020 15:46:31 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0f96c89f086a9475 X-CR-MTA-TID: 64aa7808 X-Received: from c2a5e0763b52.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F49A3BEC-5F37-47CC-B35B-0EC4D0C12FF7.1; Tue, 05 May 2020 15:46:26 +0000 X-Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c2a5e0763b52.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 May 2020 15:46:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J8kkml3t70JhGl4flOrb9Rht0+4u+0eZzR/svEEUrDISibPdQfZXtmRpCnf2ocK6wagXYumQThmv9KLktydZoOI3OqaCuNWePAikYoMrhxhNJBH6I8mvbAe7Xo+M5vUFG/y1/IQJwxnMRl9NQztp6HDNxnmKgA8L8qDafjwVa0NjvZS6JDmeYyW0UgsPqof93ZlX1gemcUkPx+yhM7GI5xpU8qoGVFQbXQVlahQPmFExu5UgfKtmSgHQXOyE1uoklLnzn7FAZM0f/ylps/BfsnwnSZ/1iRKnEY/ZgxXmSvtBQK0grdLL3oSlpaAkFjVRZueMScPN6yDJlMXk4ax2zA== 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=v4eQdyGhM2lANyGht6ysx90XAFg+J8ORrb1heTETNMM=; b=BTn8St1S8DRYaJakrUjs0scAsEa+4OKUmwNWTvS9Au/mNYlrKF9WMUG6ohDY46jzC947dH4pcnK//gYFwUcHIwXmEo5NowhAmSSjVmlJZ8PvzJNaF925jgB3W94dgVLpn6iqsmBXVRvhn8x8B77CQn/S0cQ3BTVdwANRj2bJwFxh2bYeeI0dhRoDxT9fQ5YMPBDncs6CshXVhVv4WsO2GFZA5HxV9e7NcT24HG7gLki0Yqjkjmb4QALhX7Sq4DamZDSX2IEaR6VLN6NgvJuUACmoC24bSejSQyP7t/1Q1RKL+NaDNPVgiNjFjcBPXfCMjttMH2Mlh0TGxqZ1P+flMg== 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 X-Received: from AM5PR04CA0027.eurprd04.prod.outlook.com (2603:10a6:206:1::40) by AM5PR0801MB1745.eurprd08.prod.outlook.com (2603:10a6:203:3a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19; Tue, 5 May 2020 15:46:24 +0000 X-Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::6b) by AM5PR04CA0027.outlook.office365.com (2603:10a6:206:1::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 15:46:24 +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; X-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:24 +0000 X-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:09 +0000 X-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:09 +0000 From: "Krzysztof Koch" To: CC: , , , , Subject: [edk2-devel] [PATCH v1 6/6] ShellPkg: acpiview: Make PPTT parsing logic data driven Date: Tue, 5 May 2020 16:46:04 +0100 Message-ID: <20200505154604.9848-7-krzysztof.koch@arm.com> 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)(346002)(136003)(396003)(376002)(39860400002)(46966005)(33430700001)(426003)(4326008)(81166007)(44832011)(8676002)(33440700001)(2906002)(1076003)(2616005)(316002)(36756003)(478600001)(6666004)(356005)(8936002)(5660300002)(186003)(26005)(86362001)(82310400002)(70586007)(6916009)(336012)(70206006)(54906003)(7696005)(47076004)(82740400003);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31e50fac-76f7-4a1b-c0ab-08d7f10b7bcf X-MS-TrafficTypeDiagnostic: AM5PR0801MB1745:|AM7PR08MB5383: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: emYoAJuZrfxdU3PAVGxaXGBtMsIEuYfbgLmjRu4l8jjhTmi/AFe1PHUuVR8r2PooCWYbl3k+zTQiCM4O3Az5548vcQYuK7tb2OaV6BeDWHKj0Ixth6VXS2SmAA1uAIhE2+/qGSmLCv6TcKWM3JcvEiEiMaVtp1+lsQ4FZ3hX8bCym7UyoKMembmHw1diUUgRcQ7cB0TGGXNBFdaE3hF+jE7BlDbzFC0L1BLexUAXw+FfoDMoiNdA18cnVgJSAQ2AwAxrSVCpgyfHxGNATN8pTaaXTld0oJKQuLUbfyOJejHnFkr7MSGYM40VcckQ5BUpgjV7W0VBwKwLb1hNHI5RB435G/ECRNaWwRhLD0K4mAqELioNRdih4t6mv0/9qz+l05wDJab52AolEoEkQmcaZCPrVGAijkb3poV6kqGTEAE74u1423xacVuR+OKZAjIjle4PNvKOLxSI7ffItELMzi9qZL0NBNhrfEKdsRzFbEuAM+EqcCrViRTpZtWCGV6d0DoJXrHUHKvZuMC+iqlqMDoD9grtsUONiQszT32+Xxs0le5IFtMvoikMj499rSLc4sY/qISIoLDtr5oJ4NziLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1745 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; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 015974d2-975a-4ea3-6061-08d7f10b773b X-Microsoft-Antispam-Message-Info: t4e0TzI8RmRshHIXLFQdWQszkSI1zJAPsMN7SwlUgyC+sJJtvjB7LYvPO0UBnXXDZFXO3o4LBOTHs8YtKBeUALEBgWihucQfWp9wvTZLfAnt1bh0phdztFlEoi4aDCEIk4P22tX5PwqP6Inu191ixrssa4O3EjeS97qS3xDme0ItSmxKZZBBgFaaBQENyQA5W+/bGD/yENUf927tJj1CRZEP+BGMcRVexXW3R9JlcUo7iM3S8mqoywuDhpKkkGyR1q8l+UriMBTpbHGcjTuUKkdFr4qlQVtGDrCk7qCZzNFnbh9/iERL3MQhE2PeERDBdvKunYwumV4ic2HhIo08ugBGrSLy8652a/BXskLzyrJenxkPddft8GwKgIcpDVG5UNHMyFkV7BP/n7G4zC778eOF8VM1mMZrqmDp1lu/nQEHUtS5s6+nCB5DKOpLbgn+N+dHXI2KVbdh5NhwEAlI3g08xNlhfB0ukbS2PckXf74MNl+lJDjmzrnbHf+mH4uOX7MpKfcRhjP9HLcIBovS68FUzpIFVZYW2r0QGBgBc4DKspxOqsf9UPms+49+ksMdFD6He6extfPWNeVOfJUIDw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 15:46:32.0271 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31e50fac-76f7-4a1b-c0ab-08d7f10b7bcf 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: AM7PR08MB5383 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,krzysztof.koch@arm.com X-Gm-Message-State: WNQArBysrVkEPgPokBoaVoclx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1588693595; bh=EWcgo1h8Ek6h7ICoBpkit2u68RFEI/lazZrfbufQSvk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wOXxraf8vHW1F0lZXIVOT53K1Ykhw1ZoM+Zv0TOREDjroxfqr2ZO/IzWoF21eAhBv6J MnhXY/And8cF/dnJHIWvLB1LTBxemn+Wc7SHmliXbmzvHZfXf0jqO04NWTts7A4hJt1Lw 2hekbE9Ok0D2vYLs/vqYxFm54gqZVbRqpow= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the switch statement in the main parser loop with a table-driven approach. Use the ParseAcpiStruct () method to resolve how each Processor Topology Structure given should be parsed. Enumerate all structures found in the Processor Properties Topology Table (PPTT) on a per-type basis. Consolidate all metadata about each Processor Topology Structure. 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 PPTT. Count the number of instances of each Processor Topology Structure type. Optionally report these counts after PPTT table parsing is finished. Remove the definition of the DumpCacheTypeStructure and DumpIDStructure functions. Their only purpose was to call ParseAcpi () and now this process is streamlined. Make DumpProcessorHierarchyNodeStructure function signature match that of ACPI_STRUCT_PARSER_FUNC. This way, the function can be called from ParseAcpiStruct (). References: - ACPI 6.3 Specification - January 2019, Section 5.2.29 Signed-off-by: Krzysztof Koch --- Notes: v1: - Make PPTT parsing logic data driven [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 1= 52 ++++++++++---------- ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h | = 2 +- 2 files changed, 74 insertions(+), 80 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/Pptt= Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttPa= rser.c index 0db272c16af0ad8824c8da4c88dd409c8550112a..b62f79b52cab989942f84b020e1= d737e8ef65439 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c @@ -21,6 +21,11 @@ STATIC CONST UINT8* ProcessorTopologyStructureLength; STATIC CONST UINT32* NumberOfPrivateResources; STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; =20 +/** + Handler for each Processor Topology Structure +**/ +STATIC ACPI_STRUCT_INFO PpttStructs[]; + /** This function validates the Cache Type Structure (Type 1) 'Number of set= s' field. @@ -243,22 +248,34 @@ STATIC CONST ACPI_PARSER IdStructureParser[] =3D { @param [in] Ptr Pointer to the start of the Processor Hierarchy Node Structure data. @param [in] Length Length of the Processor Hierarchy Node Structure. + @param [in] OptArg0 First optional argument (Not used). + @param [in] OptArg1 Second optional argument (Not used). **/ STATIC VOID DumpProcessorHierarchyNodeStructure ( - IN UINT8* Ptr, - IN UINT8 Length + IN UINT8* Ptr, + IN UINT32 Length, + IN CONST VOID* OptArg0 OPTIONAL, + IN CONST VOID* OptArg1 OPTIONAL ) { UINT32 Offset; UINT32 Index; CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH]; + CHAR8 AsciiBuffer[80]; + + PrintAcpiStructName ( + PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Name, + PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Count, + sizeof (AsciiBuffer), + AsciiBuffer + ); =20 Offset =3D ParseAcpi ( TRUE, 2, - "Processor Hierarchy Node Structure", + AsciiBuffer, Ptr, Length, PARSER_PARAMS (ProcessorHierarchyNodeStructureParser) @@ -269,7 +286,8 @@ DumpProcessorHierarchyNodeStructure ( if (NumberOfPrivateResources =3D=3D NULL) { IncrementErrorCount (); Print ( - L"ERROR: Insufficient Processor Hierarchy Node length. Length =3D %d= .\n", + L"ERROR: Insufficient %a Structure length. Length =3D %d.\n", + PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Name, Length ); return; @@ -296,7 +314,7 @@ DumpProcessorHierarchyNodeStructure ( UnicodeSPrint ( Buffer, sizeof (Buffer), - L"Private resources [%d]", + L"Private resource [%d]", Index ); =20 @@ -312,50 +330,37 @@ DumpProcessorHierarchyNodeStructure ( } =20 /** - This function parses the Cache Type Structure (Type 1). - - @param [in] Ptr Pointer to the start of the Cache Type Structure dat= a. - @param [in] Length Length of the Cache Type Structure. + Information about each Processor Topology Structure type. **/ -STATIC -VOID -DumpCacheTypeStructure ( - IN UINT8* Ptr, - IN UINT8 Length - ) -{ - ParseAcpi ( - TRUE, - 2, - "Cache Type Structure", - Ptr, - Length, - PARSER_PARAMS (CacheTypeStructureParser) - ); -} +STATIC ACPI_STRUCT_INFO PpttStructs[] =3D { + ADD_ACPI_STRUCT_INFO_FUNC ( + "Processor", + EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AAR= CH64, + DumpProcessorHierarchyNodeStructure + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "Cache", + EFI_ACPI_6_3_PPTT_TYPE_CACHE, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AAR= CH64, + CacheTypeStructureParser + ), + ADD_ACPI_STRUCT_INFO_ARRAY ( + "ID", + EFI_ACPI_6_3_PPTT_TYPE_ID, + ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AAR= CH64, + IdStructureParser + ) +}; =20 /** - This function parses the ID Structure (Type 2). - - @param [in] Ptr Pointer to the start of the ID Structure data. - @param [in] Length Length of the ID Structure. + PPTT structure database **/ -STATIC -VOID -DumpIDStructure ( - IN UINT8* Ptr, - IN UINT8 Length - ) -{ - ParseAcpi ( - TRUE, - 2, - "ID Structure", - Ptr, - Length, - PARSER_PARAMS (IdStructureParser) - ); -} +STATIC ACPI_STRUCT_DATABASE PpttDatabase =3D { + "Processor Topology Structure", + PpttStructs, + ARRAY_SIZE (PpttStructs) +}; =20 /** This function parses the ACPI PPTT table. @@ -390,6 +395,8 @@ ParseAcpiPptt ( return; } =20 + ResetAcpiStructCounts (&PpttDatabase); + Offset =3D ParseAcpi ( TRUE, 0, @@ -419,7 +426,8 @@ ParseAcpiPptt ( IncrementErrorCount (); Print ( L"ERROR: Insufficient remaining table buffer length to read the " \ - L"processor topology structure header. Length =3D %d.\n", + L"%a header. Length =3D %d.\n", + PpttDatabase.Name, AcpiTableLength - Offset ); return; @@ -430,8 +438,9 @@ ParseAcpiPptt ( ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength)= ) { IncrementErrorCount (); Print ( - L"ERROR: Invalid Processor Topology Structure length. " \ - L"Length =3D %d. Offset =3D %d. AcpiTableLength =3D %d.\n", + L"ERROR: Invalid %a length. Length =3D %d. Offset =3D %d. " \ + L"AcpiTableLength =3D %d.\n", + PpttDatabase.Name, *ProcessorTopologyStructureLength, Offset, AcpiTableLength @@ -439,39 +448,24 @@ ParseAcpiPptt ( return; } =20 - PrintFieldName (2, L"* Structure Offset *"); - Print (L"0x%x\n", Offset); - - switch (*ProcessorTopologyStructureType) { - case EFI_ACPI_6_2_PPTT_TYPE_PROCESSOR: - DumpProcessorHierarchyNodeStructure ( - ProcessorTopologyStructurePtr, - *ProcessorTopologyStructureLength - ); - break; - case EFI_ACPI_6_2_PPTT_TYPE_CACHE: - DumpCacheTypeStructure ( - ProcessorTopologyStructurePtr, - *ProcessorTopologyStructureLength - ); - break; - case EFI_ACPI_6_2_PPTT_TYPE_ID: - DumpIDStructure ( - ProcessorTopologyStructurePtr, - *ProcessorTopologyStructureLength - ); - break; - default: - IncrementErrorCount (); - Print ( - L"ERROR: Unknown processor topology structure:" - L" Type =3D %d, Length =3D %d\n", - *ProcessorTopologyStructureType, - *ProcessorTopologyStructureLength - ); - } + // Parse the Processor Topology Structure + ParseAcpiStruct ( + 2, + ProcessorTopologyStructurePtr, + &PpttDatabase, + Offset, + *ProcessorTopologyStructureType, + *ProcessorTopologyStructureLength, + NULL, + NULL + ); =20 ProcessorTopologyStructurePtr +=3D *ProcessorTopologyStructureLength; Offset +=3D *ProcessorTopologyStructureLength; } // while + + // Report and validate processor topology structure counts + if (GetConsistencyChecking ()) { + ValidateAcpiStructCounts (&PpttDatabase); + } } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/Pptt= Parser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttPa= rser.h index 2a671203fb0035bbc407ff4bb0ca9960706fa588..a0b0622ba00bda63379b6705271= 45359b738bb7d 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h @@ -1,7 +1,7 @@ /** @file Header file for PPTT parser =20 - Copyright (c) 2019, ARM Limited. All rights reserved. + Copyright (c) 2019 - 2020, ARM Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent =20 @par Reference(s): -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58648): https://edk2.groups.io/g/devel/message/58648 Mute This Topic: https://groups.io/mt/74000915/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-