From nobody Mon Feb 9 02:12:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86704+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1645010039076224.34068204949654; Wed, 16 Feb 2022 03:13:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dYqsYY1788612xbltZrXf8s4; Wed, 16 Feb 2022 03:13:58 -0800 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.68]) by mx.groups.io with SMTP id smtpd.web11.10466.1645010037452567558 for ; Wed, 16 Feb 2022 03:13:57 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F+8fAID6gfinjRNWlwdX191IMi9pLRePdJzECeHvofhphNeA/1UIb0vkoIHD3SoTBc08ByinCrspI2DUI0SRIPZ3JGi++eMNj59c6uGvF3asx2trNxBonIQPcMW5sGdP1M3dEAMoVSv7t3mhKX5hdRSnR4qFAxlzcr/LqzyeRpZSYg916sKWvHRNrW+9yoZz7Q4o1Yk3VCfDEkEfp+PTI3H9YY3LdjGevwTemcCHu0jsOk2xQi3CCQRb0oQJlZBs1fILnHgbnhOUiiHTRhcfHfcuMoH2eN46ruYy5eU5M7QRDT7wz4YuRthYLE1y7U1zLh+mCNpiHEAL9Wg4W9cFZQ== 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=Fs19HKYWFA/x6lb2/WYdj2arT3M6hvbydhBgyQ2UeT8=; b=GzmcZJ2Sh+dJbjHupDux9t25A630d4QzNj+q7BUwOHZo05A1WoMTxEQOBCfZzcWez38ugEwmznuhbPIju7Dc/tvn6vWOzUubCxm8JyeBhg0uwdwTfw9wFv/HhT2dHEXnLxgQKVwNwAaRaF7HZnHUgdwxD0TUJ8eVxLx2hkKHkykVCUlU3/+Q5cqLfIV9mzegodaGAluGA1/4ULJ7dO3325qSTjbX2xPNBwfwKHKa93K1ObNLmXEYC3wnHrqHicuAj0jKKvha8JzzzsLk/iNDP0Kt7nPoG9MFXXwElAeZ4TtTH+c6tn7EZMP61+MqzLYKWieFSJy5K5V2eLF08reuzg== 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 X-Received: from MWHPR18CA0038.namprd18.prod.outlook.com (2603:10b6:320:31::24) by SN1PR12MB2479.namprd12.prod.outlook.com (2603:10b6:802:29::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.18; Wed, 16 Feb 2022 11:13:54 +0000 X-Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:320:31:cafe::a8) by MWHPR18CA0038.outlook.office365.com (2603:10b6:320:31::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17 via Frontend Transport; Wed, 16 Feb 2022 11:13:54 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+86704+1787277+3901457@groups.io; helo=mail02.groups.io; 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; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4975.11 via Frontend Transport; Wed, 16 Feb 2022 11:13:54 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) 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.18; Wed, 16 Feb 2022 05:13:53 -0600 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.18 via Frontend Transport; Wed, 16 Feb 2022 05:13:51 -0600 From: "Abdul Lateef Attar via groups.io" To: CC: Ray Ni , Zhichao Gao , Sami Mujawar Subject: [edk2-devel] [PATCH v5 1/2] ShellPkg/AcpiView: Adds ACPI_PARSER bitfield parser Date: Wed, 16 Feb 2022 16:43:54 +0530 Message-ID: <20220216111355.9801-2-abdattar@amd.com> In-Reply-To: <20220216111355.9801-1-abdattar@amd.com> References: <20220216111355.9801-1-abdattar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3fd3b7e-9773-4630-273c-08d9f13d6b5b X-MS-TrafficTypeDiagnostic: SN1PR12MB2479: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-Message-Info: 47UWb6LacwC8Du59GkEwVuhn4CAVwzQ8gyirPU/ruFIssoI/9GtQ8+Vqlpf9plQw4nagRc7uKsG3aLY49fdBgzE1g0UwVhphl36N5ucyT/GAFVPmlZ1VAqhwTI67FnZQxbuYfg6CPHfoStjGY4KwiG3A5Tl85M8JFSzfRw8K41lBZv4U/taHzAbJ0+7nf6y9dsB19P3j/GG6Gx7cbp3T0tspJbzJ7AIR4cxgLG+HSrKW4Z/AMop6yUqFbVeB/keYHdvG5qKk+QeFw34FP+kCkPh8cy/VDPFLCpJ7pXfdW/fBj+qmFkOlSg49Y8F7KhEERmzGBUw5FZAH5x3kBQJjmiJyZ8hZtG5Aph8qqyuUFSIXlrS1j5BON98zRW4FoNque+QryyOBx2WQPE6Aa++ROOTyKADmg/9u99UhMFjlIwYlotjTzDShVbybfCFao7w4yqZSZ9QhzGZPrgoorl4qad2IoioyveLKMW71KkCZW13wbOqa+XzTOQDpwZ0IGj0riLQGgdE76XNcz/YQUMYG2QsDh4kRYYzYoA8eMNfj43sL0yH6dYXMpS8H81YR98uZudeU/FFel2yCwmy8/jN9ek5PGkGjLMIF4mFCDBYpj6ejpEbvuEc9B++uvfKKSTdAPtEw5xsoLLj8qS+1/CvlQug2Qifg/fzIc1Djhil8NGEZfMrzJR/0e+blJPrSp80y63GgXVIE41UxWxIhBzLuD5ZpyjBPvmCrzP0eAy+wQ216lK63akuzBKlEX9G+LGrsSkos5pNpx07wmfxAWrb6HXQxIToOCTn3HDlwnJrIc8Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2022 11:13:54.4039 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3fd3b7e-9773-4630-273c-08d9f13d6b5b 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2479 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,abdattar@amd.com X-Gm-Message-State: mlWZmQ677KpoQ2Jw4V5nazoWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1645010038; bh=L88In1V7i6/X6DnsM38YXnUT69FvF6SZdI1j1p+h+L4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=IP3nllIe6k6yGdU39KBr9iUyWKgWuFMVQxdVsquol1CfIYAGx2WDnRlkswNHRkbp/qu Z8FKMloMk+9/gvI2G5RYMtRJ3VJU8Kkv4hBWLj0ANPUWcV/gg38b9bMi0JR/+wiZ92ezA 53ThqIHC5CxPof6MC3foqItWBW3IFUhPyug= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1645010040885100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3839 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 Reviewed-by: Sami Mujawar --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 48 +++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 188 ++++++++++= ++++++++++ 2 files changed, 236 insertions(+) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 5c916a4720b8..db8c88f6dfa4 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -2,6 +2,7 @@ Header file for ACPI parser =20 Copyright (c) 2016 - 2020, Arm Limited. All rights reserved. + Copyright (c) 2022, AMD Incorporated. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -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 processing for formatting and representation a print formatter function can be specified in 'PrintFormatter'. + + ParseAcpiBitFields() uses AcpiParser structure to parse the bit fields. + It considers Length as a number of bits that need to be parsed. + Also, the Offset field will be considered as starting offset of the bitf= ield. + The PrintFormatter function may choose to use the format string specified by 'Format' or use its own internal format string. =20 @@ -264,10 +270,12 @@ typedef struct AcpiParser { =20 /// The length of the field. /// (Byte Length column from ACPI table spec) + /// Length(in bits) of the bitfield if used with ParseAcpiBitFields(). UINT32 Length; =20 /// The offset of the field from the start of the table. /// (Byte Offset column from ACPI table spec) + /// The Bit offset of the field if used with ParseAcpiBitFields(). UINT32 Offset; =20 /// Optional Print() style format string for tracing the data. If not @@ -285,6 +293,7 @@ typedef struct AcpiParser { /// a pointer to the field data. This value is set after the FieldValida= tor /// has been called and therefore should not be used by the FieldValidat= or. /// If unused this must be set to NULL. + /// ItemPtr is not supported with ParseAcpiBitFields(). VOID **ItemPtr; =20 /// Optional pointer to a field validator function. @@ -364,6 +373,45 @@ ParseAcpi ( IN UINT32 ParserItems ); =20 +/** + This function is used to parse an ACPI table bitfield buffer. + + The ACPI table buffer is parsed using the ACPI table parser information + specified by a pointer to an array of ACPI_PARSER elements. This parser + function iterates through each item on the ACPI_PARSER array and logs th= e ACPI table bitfields. + + This function can optionally be used to parse ACPI tables and fetch spec= ific + field values. The ItemPtr member of the ACPI_PARSER structure (where use= d) + is updated by this parser function to point to the selected field data + (e.g. useful for variable length nested fields). + + ItemPtr member of ACPI_PARSER is not supported with this function. + + @param [in] Trace Trace the ACPI fields TRUE else only parse the + table. + @param [in] Indent Number of spaces to indent the output. + @param [in] AsciiName Optional pointer to an ASCII string that descri= bes + the table being parsed. + @param [in] Ptr Pointer to the start of the buffer. + @param [in] Length Length of the buffer pointed by Ptr. + @param [in] Parser Pointer to an array of ACPI_PARSER structure th= at + describes the table being parsed. + @param [in] ParserItems Number of items in the ACPI_PARSER array. + + @retval Number of bits parsed. +**/ +UINT32 +EFIAPI +ParseAcpiBitFields ( + IN BOOLEAN Trace, + IN UINT32 Indent, + IN CONST CHAR8 *AsciiName OPTIONAL, + IN UINT8 *Ptr, + IN UINT32 Length, + IN CONST ACPI_PARSER *Parser, + IN UINT32 ParserItems + ); + /** This is a helper macro to pass parameters to the Parser functions. =20 diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index cb193a5ea449..fcc56c189d65 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -2,12 +2,14 @@ ACPI parser =20 Copyright (c) 2016 - 2021, Arm Limited. All rights reserved. + Copyright (c) 2022, AMD Incorporated. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include #include #include +#include #include "AcpiParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" @@ -752,3 +754,189 @@ ParseAcpiHeader ( =20 return BytesParsed; } + +/** + This function is used to parse an ACPI table bitfield buffer. + + The ACPI table buffer is parsed using the ACPI table parser information + specified by a pointer to an array of ACPI_PARSER elements. This parser + function iterates through each item on the ACPI_PARSER array and logs th= e ACPI table bitfields. + + This function can optionally be used to parse ACPI tables and fetch spec= ific + field values. The ItemPtr member of the ACPI_PARSER structure (where use= d) + is updated by this parser function to point to the selected field data + (e.g. useful for variable length nested fields). + + ItemPtr member of ACPI_PARSER is not supported with this function. + + @param [in] Trace Trace the ACPI fields TRUE else only parse the + table. + @param [in] Indent Number of spaces to indent the output. + @param [in] AsciiName Optional pointer to an ASCII string that descri= bes + the table being parsed. + @param [in] Ptr Pointer to the start of the buffer. + @param [in] Length Length in bytes of the buffer pointed by Ptr. + @param [in] Parser Pointer to an array of ACPI_PARSER structure th= at + describes the table being parsed. + @param [in] ParserItems Number of items in the ACPI_PARSER array. + + @retval Number of bits parsed. +**/ +UINT32 +EFIAPI +ParseAcpiBitFields ( + IN BOOLEAN Trace, + IN UINT32 Indent, + IN CONST CHAR8 *AsciiName OPTIONAL, + IN UINT8 *Ptr, + IN UINT32 Length, + IN CONST ACPI_PARSER *Parser, + IN UINT32 ParserItems + ) +{ + UINT32 Index; + UINT32 Offset; + BOOLEAN HighLight; + UINTN OriginalAttribute; + + UINT64 Data; + UINT64 BitsData; + + if ((Length =3D=3D 0) || (Length > 8)) { + IncrementErrorCount (); + Print ( + L"\nERROR: Bitfield Length(%d) is zero or exceeding the 64 bit limit= .\n", + Length + ); + return 0; + } + + // + // set local variables to suppress incorrect compiler/analyzer warnings + // + OriginalAttribute =3D 0; + Offset =3D 0; + + // Increment the Indent + gIndent +=3D Indent; + + CopyMem ((VOID *)&BitsData, (VOID *)Ptr, Length); + if (Trace && (AsciiName !=3D NULL)) { + HighLight =3D GetColourHighlighting (); + + if (HighLight) { + OriginalAttribute =3D gST->ConOut->Mode->Attribute; + gST->ConOut->SetAttribute ( + gST->ConOut, + EFI_TEXT_ATTR ( + EFI_YELLOW, + ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4) + ) + ); + } + + Print ( + L"%*a%-*a :\n", + gIndent, + "", + (OUTPUT_FIELD_COLUMN_WIDTH - gIndent), + AsciiName + ); + if (HighLight) { + gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); + } + } + + for (Index =3D 0; Index < ParserItems; Index++) { + if ((Offset + Parser[Index].Length) > (Length * 8)) { + // For fields outside the buffer length provided, reset any pointers + // which were supposed to be updated by this function call + if (Parser[Index].ItemPtr !=3D NULL) { + *Parser[Index].ItemPtr =3D NULL; + } + + // We don't parse past the end of the max length specified + continue; + } + + if (Parser[Index].Length =3D=3D 0) { + IncrementErrorCount (); + // don't parse the bitfield whose length is zero + Print ( + L"\nERROR: %a: Cannot parse this field, Field Length =3D %d\n", + Parser[Index].Length + ); + continue; + } + + if (GetConsistencyChecking () && + (Offset !=3D Parser[Index].Offset)) + { + IncrementErrorCount (); + Print ( + L"\nERROR: %a: Offset Mismatch for %s\n" + L"CurrentOffset =3D %d FieldOffset =3D %d\n", + AsciiName, + Parser[Index].NameStr, + Offset, + Parser[Index].Offset + ); + } + + // extract Bitfield data for the current item + Data =3D (BitsData >> Parser[Index].Offset) & ~(~0ULL << Parser[Index]= .Length); + + if (Trace) { + // if there is a Formatter function let the function handle + // the printing else if a Format is specified in the table use + // the Format for printing + PrintFieldName (2, Parser[Index].NameStr); + if (Parser[Index].PrintFormatter !=3D NULL) { + Parser[Index].PrintFormatter (Parser[Index].Format, (UINT8 *)&Data= ); + } else if (Parser[Index].Format !=3D NULL) { + // convert bit length to byte length + switch ((Parser[Index].Length + 7) >> 3) { + // print the data depends on byte size + case 1: + DumpUint8 (Parser[Index].Format, (UINT8 *)&Data); + break; + case 2: + DumpUint16 (Parser[Index].Format, (UINT8 *)&Data); + break; + case 3: + case 4: + DumpUint32 (Parser[Index].Format, (UINT8 *)&Data); + break; + case 5: + case 6: + case 7: + case 8: + DumpUint64 (Parser[Index].Format, (UINT8 *)&Data); + break; + default: + Print ( + L"\nERROR: %a: CANNOT PARSE THIS FIELD, Field Length =3D %d\= n", + AsciiName, + Parser[Index].Length + ); + } // switch + } + + // Validating only makes sense if we are tracing + // the parsed table entries, to report by table name. + if (GetConsistencyChecking () && + (Parser[Index].FieldValidator !=3D NULL)) + { + Parser[Index].FieldValidator ((UINT8 *)&Data, Parser[Index].Contex= t); + } + + Print (L"\n"); + } // if (Trace) + + Offset +=3D Parser[Index].Length; + } // for + + // Decrement the Indent + gIndent -=3D Indent; + return Offset; +} --=20 2.25.1 -=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 (#86704): https://edk2.groups.io/g/devel/message/86704 Mute This Topic: https://groups.io/mt/89182983/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-