From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.44]) by mx.groups.io with SMTP id smtpd.web12.17428.1639925083438674121 for ; Sun, 19 Dec 2021 06:44:44 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=epfcLtRI; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.92.44, mailfrom: abdullateef.attar@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I9XeU7l+hiZnrHZ8zW2F8wQxfYQOjX73PEBvT5u+RZ6M9jgfI68TfGqkF7A+BjyZ3oFEOtOHiIvChY0/ScmsS7BgxP9crzCPRv2qAjT2FS8EdLfZox98uPMyxRo52EYSP/qnVdcnJCCYyarl6QwHRo9tldzDm0wWiBZ8jomJme95tQVDGEZ16JzOoKdOQyKyLaeifqwHH6AdFyZgD4NfMF9sW5xplbQbmLXZAtyJsgyRrcewWZTHfLNnAVNO83qJkvaDofhj2cXgGzvU068V52LQBAMUUwySvg63njRb/Wm+CZp10P+CSHVvZ3MNFmpucWpziD8oqlQeNXAhLoIOsQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=44etfJNcXwejgysMNT2qaD9/ydqhK+EOiCVSvIyZ2F0=; b=Gljm8Bb2i6RQc9hDCqrDFHSMDbmtleqQrJLivii4viyms+0uddk/jOcd/VGd+r9XuqCHe6Y079Ot6h+SYeH9lWXGVP6PeA/nraHJm2iVnX7t2yuoPpW6Gre6SmYcQK5ubK11GsB9RfXfykW6MURfrxlbZgCp5diJmGtLBVPOsbB8nccMqKhMX8e1IZmMkNrNKJxpAuJIhpH8L8TqxF23o84gcPjc9lwIrR6DhmF1OByoRrrr4sksOASZN6WNArT+/5z1+GNYcVGzyDbNACShf/pPBUCxmRqxD/K7y47ymhQLHW1OaANfVX/184XuiiTVGn2bruhCE3QlODZw3afmoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=44etfJNcXwejgysMNT2qaD9/ydqhK+EOiCVSvIyZ2F0=; b=epfcLtRIm9pfBd7a5K1jbaYYihKcdA8INzqWiZS4xVjhw3kXvmOXppAmQiUTc2RkxClIF+I1FSHgrk9ufxG+B6LdnU6stiURzPXbR6uNk10jdlSJuxIIyXaGs+yaKRWsjY3xn2Jox4qicBn3UmSdqcAegRv3zyZLXlq3zw4RZeQ= Received: from DM6PR02CA0159.namprd02.prod.outlook.com (2603:10b6:5:332::26) by BY5PR12MB4228.namprd12.prod.outlook.com (2603:10b6:a03:20b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.17; Sun, 19 Dec 2021 14:44:41 +0000 Received: from DM6NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:5:332:cafe::81) by DM6PR02CA0159.outlook.office365.com (2603:10b6:5:332::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.17 via Frontend Transport; Sun, 19 Dec 2021 14:44:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT066.mail.protection.outlook.com (10.13.173.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4801.14 via Frontend Transport; Sun, 19 Dec 2021 14:44:40 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Sun, 19 Dec 2021 08:44:40 -0600 Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Sun, 19 Dec 2021 08:44:38 -0600 From: "Abdul Lateef Attar" To: CC: Ray Ni , Zhichao Gao , Sami Mujawar Subject: [PATCH v4 1/2] ShellPkg/AcpiView: Adds ACPI_PARSER bitfield parser Date: Sun, 19 Dec 2021 20:14:36 +0530 Message-ID: <20211219144437.3721-2-abdattar@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211219144437.3721-1-abdattar@amd.com> References: <20211219144437.3721-1-abdattar@amd.com> MIME-Version: 1.0 Return-Path: AbdulLateef.Attar@amd.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e43ffde5-b4da-40df-2f61-08d9c2fe16b6 X-MS-TrafficTypeDiagnostic: BY5PR12MB4228:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6pue8OIU6OQiskdptC3skvENmwzT0gQ37Oz3XCx5tMVLlhkFCgO7poZbfvyD4ifKo3FLGXN45kAkiylRbXaTwy/Z0PHpqUi5zjMfIpVwD8TEWTc6j8EgswnLK61X1vjrZEqZX2zBN3joEHhVza6ftUs/Lv+hfwWc4u1i1dKpYKSebaGFLc0B8zz2zedTbu8EVN97FgGZ+W1bmuVfbtfMMLKkjyR0QTz016PSFU1RvcMu9obUJK/pKePjpcfEmWv91n42cu1rjZyJXq7SlOUSys8Wh97oC+tj7p5GqPuA6VZr6FUbzWgAqFkHZkY0dVQJguIfEWJUP5y5b9ORHmK+qHwP0qUUlM0yjZ9XweyAL38mtU+s3DtKOAEnHkMHRQOKjxakwEewZSrq4GvgXR7HCamkRvp8ePsYHstT8MC9VjU41ak7LHZe4o5CJ1vL5UF5+T/0T6vieVrlu/Xi7VRMUClbrD1ERhYBndxwi9Py0d88fCglwmiJQKd90GW0PJjCmg0NaMKGrMt6yWYsFTyR+oYjElcZEX/9BZh8PtmME5ctR9y25UPwMW8ULuynhb2z4TSDDDGUal0QMBnF6CVnsopUVxVhrvbNBePhs6j7iDj5v6ttR4LJyKK4wp8IZTK+JjzR8glUz5TUXrOntxnSzKbBSnVSOv2O34IjHuI2mXSVRQF7PjIcNiYIK47zJHyGj4ebm+uUDqplBhzJOVUUqhn5DH4ZTUGs62CTgpBYa9tT5ByjnCjTMxiEZw4EFEZKzmKkJfEeGeVkdwARNaFV9UybqJpCSW7n7pJ7m4rKXRk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(40470700001)(5660300002)(82310400004)(6916009)(316002)(1076003)(356005)(36860700001)(81166007)(426003)(40460700001)(70206006)(7696005)(2616005)(336012)(4326008)(70586007)(26005)(2906002)(83380400001)(36756003)(8936002)(8676002)(186003)(508600001)(54906003)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2021 14:44:40.7152 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e43ffde5-b4da-40df-2f61-08d9c2fe16b6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4228 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Adds ParseAcpiBitFields() which is based on ParseAcpi() and capable of parsing the bit fields. Supports parsing of UINT8, UINT16, UINT32 and UINT64 byte data. Cc: Ray Ni Cc: Zhichao Gao Cc: Sami Mujawar Signed-off-by: Abdul Lateef Attar --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 45 +++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 185 ++++++++++= ++++++++++ 2 files changed, 230 insertions(+) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 5c916a4720b8..83266e8ec2d3 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -2,6 +2,7 @@ Header file for ACPI parser=0D =0D Copyright (c) 2016 - 2020, Arm Limited. All rights reserved.=0D + Copyright (c) 2021, AMD Incorporated. All rights reserved.=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D **/=0D =0D @@ -251,6 +252,11 @@ typedef VOID (EFIAPI *FNPTR_FIELD_VALIDATOR)(UINT8 *Pt= r, VOID *Context); the field data. If the field is more complex and requires additional=0D processing for formatting and representation a print formatter function= =0D can be specified in 'PrintFormatter'.=0D +=0D + ParseAcpiBitFields() uses AcpiParser structure to parse the bit fields.= =0D + It considers Length as a number of bits that need to be parsed.=0D + Also, the Offset field will be considered as starting offset of the bitf= ield.=0D +=0D The PrintFormatter function may choose to use the format string=0D specified by 'Format' or use its own internal format string.=0D =0D @@ -264,10 +270,12 @@ typedef struct AcpiParser { =0D /// The length of the field.=0D /// (Byte Length column from ACPI table spec)=0D + /// Length(in bits) of the bitfield if used with ParseAcpiBitFields().=0D UINT32 Length;=0D =0D /// The offset of the field from the start of the table.=0D /// (Byte Offset column from ACPI table spec)=0D + /// The Bit offset of the field if used with ParseAcpiBitFields().=0D UINT32 Offset;=0D =0D /// Optional Print() style format string for tracing the data. If not=0D @@ -364,6 +372,43 @@ ParseAcpi ( IN UINT32 ParserItems=0D );=0D =0D +/**=0D + This function is used to parse an ACPI table bitfield buffer.=0D +=0D + The ACPI table buffer is parsed using the ACPI table parser information= =0D + specified by a pointer to an array of ACPI_PARSER elements. This parser= =0D + function iterates through each item on the ACPI_PARSER array and logs th= e ACPI table bitfields.=0D +=0D + This function can optionally be used to parse ACPI tables and fetch spec= ific=0D + field values. The ItemPtr member of the ACPI_PARSER structure (where use= d)=0D + is updated by this parser function to point to the selected field data=0D + (e.g. useful for variable length nested fields).=0D +=0D + @param [in] Trace Trace the ACPI fields TRUE else only parse the= =0D + table.=0D + @param [in] Indent Number of spaces to indent the output.=0D + @param [in] AsciiName Optional pointer to an ASCII string that descri= bes=0D + the table being parsed.=0D + @param [in] Ptr Pointer to the start of the buffer.=0D + @param [in] Length Length of the buffer pointed by Ptr.=0D + @param [in] Parser Pointer to an array of ACPI_PARSER structure th= at=0D + describes the table being parsed.=0D + @param [in] ParserItems Number of items in the ACPI_PARSER array.=0D +=0D + @retval Number of bits parsed.=0D +**/=0D +UINT32=0D +EFIAPI=0D +ParseAcpiBitFields (=0D + IN BOOLEAN Trace,=0D + IN UINT32 Indent,=0D + IN CONST CHAR8 *AsciiName OPTIONAL,=0D + IN UINT8 *Ptr,=0D + IN UINT32 Length,=0D + IN CONST ACPI_PARSER *Parser,=0D + IN UINT32 ParserItems=0D + );=0D +=0D /**=0D This is a helper macro to pass parameters to the Parser functions.=0D =0D diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index cb193a5ea449..94ee26f42ab9 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -2,12 +2,14 @@ ACPI parser=0D =0D Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.=0D + Copyright (c) 2021, AMD Incorporated. All rights reserved.=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D **/=0D =0D #include =0D #include =0D #include =0D +#include =0D #include "AcpiParser.h"=0D #include "AcpiView.h"=0D #include "AcpiViewConfig.h"=0D @@ -752,3 +754,186 @@ ParseAcpiHeader ( =0D return BytesParsed;=0D }=0D +=0D +/**=0D + This function is used to parse an ACPI table bitfield buffer.=0D +=0D + The ACPI table buffer is parsed using the ACPI table parser information= =0D + specified by a pointer to an array of ACPI_PARSER elements. This parser= =0D + function iterates through each item on the ACPI_PARSER array and logs th= e ACPI table bitfields.=0D +=0D + This function can optionally be used to parse ACPI tables and fetch spec= ific=0D + field values. The ItemPtr member of the ACPI_PARSER structure (where use= d)=0D + is updated by this parser function to point to the selected field data=0D + (e.g. useful for variable length nested fields).=0D +=0D + @param [in] Trace Trace the ACPI fields TRUE else only parse the= =0D + table.=0D + @param [in] Indent Number of spaces to indent the output.=0D + @param [in] AsciiName Optional pointer to an ASCII string that descri= bes=0D + the table being parsed.=0D + @param [in] Ptr Pointer to the start of the buffer.=0D + @param [in] Length Length in bytes of the buffer pointed by Ptr.=0D + @param [in] Parser Pointer to an array of ACPI_PARSER structure th= at=0D + describes the table being parsed.=0D + @param [in] ParserItems Number of items in the ACPI_PARSER array.=0D +=0D + @retval Number of bits parsed.=0D +**/=0D +UINT32=0D +EFIAPI=0D +ParseAcpiBitFields (=0D + IN BOOLEAN Trace,=0D + IN UINT32 Indent,=0D + IN CONST CHAR8 *AsciiName OPTIONAL,=0D + IN UINT8 *Ptr,=0D + IN UINT32 Length,=0D + IN CONST ACPI_PARSER *Parser,=0D + IN UINT32 ParserItems=0D + )=0D +{=0D + UINT32 Index;=0D + UINT32 Offset;=0D + BOOLEAN HighLight;=0D + UINTN OriginalAttribute;=0D +=0D + UINT64 Data;=0D + UINT64 BitsData;=0D +=0D + if ((Length =3D=3D 0) || (Length > 8)) {=0D + IncrementErrorCount ();=0D + Print (=0D + L"\nERROR: Bitfield Length(%d) is zero or exceeding the 64 bit limit= .\n",=0D + Length=0D + );=0D + return 0;=0D + }=0D +=0D + //=0D + // set local variables to suppress incorrect compiler/analyzer warnings= =0D + //=0D + OriginalAttribute =3D 0;=0D + Offset =3D 0;=0D +=0D + // Increment the Indent=0D + gIndent +=3D Indent;=0D +=0D + CopyMem ((VOID *)&BitsData, (VOID *)Ptr, Length);=0D + if (Trace && (AsciiName !=3D NULL)) {=0D + HighLight =3D GetColourHighlighting ();=0D +=0D + if (HighLight) {=0D + OriginalAttribute =3D gST->ConOut->Mode->Attribute;=0D + gST->ConOut->SetAttribute (=0D + gST->ConOut,=0D + EFI_TEXT_ATTR (=0D + EFI_YELLOW,=0D + ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)=0D + )=0D + );=0D + }=0D +=0D + Print (=0D + L"%*a%-*a :\n",=0D + gIndent,=0D + "",=0D + (OUTPUT_FIELD_COLUMN_WIDTH - gIndent),=0D + AsciiName=0D + );=0D + if (HighLight) {=0D + gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);=0D + }=0D + }=0D +=0D + for (Index =3D 0; Index < ParserItems; Index++) {=0D + if ((Offset + Parser[Index].Length) > (Length * 8)) {=0D + // For fields outside the buffer length provided, reset any pointers= =0D + // which were supposed to be updated by this function call=0D + if (Parser[Index].ItemPtr !=3D NULL) {=0D + *Parser[Index].ItemPtr =3D NULL;=0D + }=0D +=0D + // We don't parse past the end of the max length specified=0D + continue;=0D + }=0D +=0D + if (Parser[Index].Length =3D=3D 0) {=0D + // don't parse the bitfield whose length is zero=0D + continue;=0D + }=0D +=0D + if (GetConsistencyChecking () &&=0D + (Offset !=3D Parser[Index].Offset))=0D + {=0D + IncrementErrorCount ();=0D + Print (=0D + L"\nERROR: %a: Offset Mismatch for %s\n"=0D + L"CurrentOffset =3D %d FieldOffset =3D %d\n",=0D + AsciiName,=0D + Parser[Index].NameStr,=0D + Offset,=0D + Parser[Index].Offset=0D + );=0D + }=0D +=0D + // extract Bitfield data for the current item=0D + Data =3D (BitsData >> Parser[Index].Offset) & ~(~0ULL << Parser[Index]= .Length);=0D +=0D + if (Trace) {=0D + // if there is a Formatter function let the function handle=0D + // the printing else if a Format is specified in the table use=0D + // the Format for printing=0D + PrintFieldName (2, Parser[Index].NameStr);=0D + if (Parser[Index].PrintFormatter !=3D NULL) {=0D + Parser[Index].PrintFormatter (Parser[Index].Format, (UINT8 *)&Data= );=0D + } else if (Parser[Index].Format !=3D NULL) {=0D + // convert bit length to byte length=0D + switch ((Parser[Index].Length + 7) >> 3) {=0D + // print the data depends on byte size=0D + case 1:=0D + DumpUint8 (Parser[Index].Format, (UINT8 *)&Data);=0D + break;=0D + case 2:=0D + DumpUint16 (Parser[Index].Format, (UINT8 *)&Data);=0D + break;=0D + case 3:=0D + case 4:=0D + DumpUint32 (Parser[Index].Format, (UINT8 *)&Data);=0D + break;=0D + case 5:=0D + case 6:=0D + case 7:=0D + case 8:=0D + DumpUint64 (Parser[Index].Format, (UINT8 *)&Data);=0D + break;=0D + default:=0D + Print (=0D + L"\nERROR: %a: CANNOT PARSE THIS FIELD, Field Length =3D %d\= n",=0D + AsciiName,=0D + Parser[Index].Length=0D + );=0D + } // switch=0D + }=0D +=0D + // Validating only makes sense if we are tracing=0D + // the parsed table entries, to report by table name.=0D + if (GetConsistencyChecking () &&=0D + (Parser[Index].FieldValidator !=3D NULL))=0D + {=0D + Parser[Index].FieldValidator ((UINT8 *)&Data, Parser[Index].Contex= t);=0D + }=0D +=0D + Print (L"\n");=0D + } // if (Trace)=0D +=0D + if (Parser[Index].ItemPtr !=3D NULL) {=0D + *Parser[Index].ItemPtr =3D (VOID *)(UINT8 *)&Data;=0D + }=0D +=0D + Offset +=3D Parser[Index].Length;=0D + } // for=0D +=0D + // Decrement the Indent=0D + gIndent -=3D Indent;=0D + return Offset;=0D +}=0D --=20 2.25.1