From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.80]) by mx.groups.io with SMTP id smtpd.web10.4744.1637576487334504991 for ; Mon, 22 Nov 2021 02:21:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=WZdj5hN5; 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.223.80, mailfrom: abdullateef.attar@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YMACEA1xosEmA4byRGfWGoiBYMwvNyz3fsY3PLePpGkRF3KH9eN1u5ypUPF3A+4C8EGcOvOCT7Kug7J4zQ1K1uxFlEmwpyAyfCiREbTrmC0x3hftGvi2SheACjU/Mso1TNG747oIytbeZUA+CQv4ooBN06AKgySnttJSMJsaiNgxGNJFWrkR4bBMrfapZ4PHj+lqFxTek9s/e4HUQ4tb1Ccz7v6GRKXLYn0WWgcr6O2bJb1LvzDIR0ToZmsHPbC18UibDH6Zc9qTlpzHADL/OM3tccsF+GkHJATJYPB2m2cMEm5dy45g9hPPWCAwMzPeARrKq4FOfUbFupnBN7uWiw== 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=Etl55HmlEeelMFmS+PCr9EGRBw6J0sEmPmcrV6CZ9kM=; b=Aoo+4i2ZCJUjeodtw8Bm+Yk5uFalkd1gmuM8Nv7w3iF1UUAIUv6oBdzD6O/S4kJJMBBsVCIfeqJsTWb6LsReHmbcK4c4bB71x1j1Jv0AdXv9rgLkhaTKCkzAldZOGq+r1su0PwxSUleinZV7NXWnZSZwCthn2PbkZFpq3dsLHdbOIdZ5DYZ4sqvnJRtoMsSpU7Gpf04MvJkZYSNAPCHyVQK7svlyd67YEkCm9jy7609nW7wFSD+WjR74JlWUytxy4OFnw08latUHVcpIcV94xShK+H5IXp4B5E4vO897pmDEd8xu9C3Ca0gOlUVRQKkkiNrQIuKK0gwc2uiHiVJ+Aw== 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=Etl55HmlEeelMFmS+PCr9EGRBw6J0sEmPmcrV6CZ9kM=; b=WZdj5hN5OgQnl5VJaBABD+SNnM2sZS/8Qzom3yHKhxYi6WmPgeAZkgCIEC9Kdyg7iaR2eslZD2GSIHOcBX8eSTVbG7sgN8Y/o5sAHqRSSciDyZVUXGNG7BmFwz3FGTz5vBNAeqd8dGKvZ2Ktuz52b2Nfr1aeJ7ubtYHwhXWjYtg= Received: from BN9PR03CA0789.namprd03.prod.outlook.com (2603:10b6:408:13f::14) by MW3PR12MB4489.namprd12.prod.outlook.com (2603:10b6:303:5e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Mon, 22 Nov 2021 10:21:23 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13f:cafe::a8) by BN9PR03CA0789.outlook.office365.com (2603:10b6:408:13f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Mon, 22 Nov 2021 10:21:23 +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=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.20 via Frontend Transport; Mon, 22 Nov 2021 10:21:23 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 22 Nov 2021 04:21:22 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 22 Nov 2021 02:21:22 -0800 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; Mon, 22 Nov 2021 04:21:21 -0600 From: "Abdul Lateef Attar" To: CC: Ray Ni , Zhichao Gao , "Sami Mujawar" Subject: [PATCH v3 1/2] ShellPkg/AcpiView: Adds ACPI_PARSER bitfield parser Date: Mon, 22 Nov 2021 15:51:15 +0530 Message-ID: <20211122102116.22635-2-abdattar@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211122102116.22635-1-abdattar@amd.com> References: <20211122102116.22635-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: 5e9eee1f-8632-4727-c0d4-08d9ada1d564 X-MS-TrafficTypeDiagnostic: MW3PR12MB4489: 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: K14IvDE/5AhREPK73a6vui0ZBqhjv9U4kDqMJ5xkMNJbN7gBIxCfPZofjJmqLARQsuPHLTG3RSWHChHSF2D0UxfVjBR5qR2fTnvXeElXXLGmoGcx2WMa2HfFwQmHaEzd22jGNNVOTGP2luIxVwrD9gTKPZxhdltTQGJwgBECUN6Q8okse5YEwQ7NwvX86jrxB3HdcZFA/9cjM/SnZfSDdctIAD+rGrzpGZzxqBXzneyO7acpoyueixG5ye5qFv/jKk2hza24p7diguKePVi5DEse9w+PjHPPPj7wHFjw6P/PBXPBN6EANtQXv2DMuPIFQpMMHV2Z742tSAKE1J997C71Dtzpd4+iA52ZAMFhhzKfjcYyCQ2rO7i4Slep+21g//Ig1oKQeeF6xcxJ/giI6q8R3dg+DSFXt9kU5hRVFiJZKHMFRo3B3NuVJh2ZxBIFxpm6iz5BaQouchjvIWT1lypbhy9g7D/J8kDeaynD0CphqjGLA8Z6Pv7m2la2pzpEs84qjF9vHEXpT0NgYa/QP1CMbaWmmHOmE1AjPbMljUgFmp7bEn+wauDxMSGdo3Im429ePGWXf/hxSlQh7oM/W1qmViJ8xkMBDQwatQX5gHq2p48jyqrZ7IyJGJpMX/jF05wagISQWA13TpXc3nQj0HHDBs19KMkgrLjEsAps00nkUUsQPxIiEpU9leFiD9+ODw/y3ygjl0jfA3ipAmGWITRj+dYkK8DfDuIKIw+Nu38= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(316002)(8676002)(2906002)(6666004)(36756003)(426003)(82310400003)(26005)(7696005)(6916009)(70206006)(54906003)(70586007)(47076005)(508600001)(8936002)(356005)(81166007)(336012)(83380400001)(2616005)(4326008)(36860700001)(186003)(5660300002)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2021 10:21:23.0675 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e9eee1f-8632-4727-c0d4-08d9ada1d564 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4489 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 | 177 ++++++++++= ++++++++++ 2 files changed, 222 insertions(+) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 5e34a70c8bae..d64eec533fab 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 @@ -265,10 +271,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 @@ -365,6 +373,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 74056e72c359..d89c68ba3905 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 @@ -738,3 +740,178 @@ 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 lim= it.\n",=0D + Length=0D + );=0D + return 0;=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(EFI_YELLOW,=0D + ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))=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 + 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 + // 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 + Parser[Index].FieldValidator ((UINT8 *)&Data, Parser[Index].Contex= t);=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