From nobody Wed May 1 12:59:46 2024 Delivered-To: importer@patchew.org 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+55556+1787277+3901457@groups.io; helo=web01.groups.io; 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+55556+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1583446474; cv=none; d=zohomail.com; s=zohoarc; b=LxU9XZHr4iDUv5D9T9xCBH6IbWkOdiD2okKjNm+8/VOQuIycdC8JQOkHPlK18KSNAFQXAiJop7+d2rLkD7F5T4R7hCFR0gqFXxyvPeA3QeeGmxAMkxI9mnnFHV4JN7yKL4RiPdRNWvKKjrAk8oHId8RLzppXWcH0MUR1CP/o3Rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583446474; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=1jXbVh3sL03qkQ6N47IvqjEg4Dmcp7qKkE5n0PVKBUQ=; b=N8o33fO2yFPuWlt2w0PZLyq2XUZza3XhnXN9YjU07pCtVoQZyZ2Qf06VyZYDHaCirSkyUttZ2DrQDVnTMyO7RsppEVb6uRkJN5Fc5iaFAePbVMD2+sdw0Tq5YoRIzlrTJ6j+UtSOwcRYux82VkvlW9MJyKKHYKzIVCmQYk+rX5M= ARC-Authentication-Results: i=1; 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+55556+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583446474191854.8331616954249; Thu, 5 Mar 2020 14:14:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id xEafYY1788612x3VMnsMk15w; Thu, 05 Mar 2020 14:14:33 -0800 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.2968.1583446472779577845 for ; Thu, 05 Mar 2020 14:14:32 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 14:14:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,519,1574150400"; d="scan'208";a="287797207" X-Received: from mshindo-desk2.amr.corp.intel.com ([10.9.69.166]) by FMSMGA003.fm.intel.com with ESMTP; 05 Mar 2020 14:14:32 -0800 From: "Miki Shindo" To: devel@edk2.groups.io Cc: Sai Chaganty , Chasel Chiu , Nate DeSimone , Prince Agyeman , Ray Ni Subject: [edk2-devel] [edk2-platform:PATCH v2] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Date: Thu, 5 Mar 2020 14:14:23 -0800 Message-Id: <20200305221423.24224-1-miki.shindo@intel.com> 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,miki.shindo@intel.com X-Gm-Message-State: nymYwo9tOADAsEJ7Dsprdx3xx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583446473; bh=OnwlUEeOLm51gtJL1gDdrgoNfZw+AlJvx5pKc3e7e6M=; h=Cc:Date:From:Reply-To:Subject:To; b=YWEsM2VThWzD6Z0USafUA0kRJp6uD4YAa6nsujWVrgnV85dd1FTArHmFHl2orFR1s7/ xGgTzzHYZvx7oUXJUz5ZNotYsdNNtZY7BRWUAdrzoqutkRH7t7ha0v1x3UAYL34TuVBNp q28wB359XD8X8gJ/bH6D5r8vXAhP9QzN4wc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2536 This commit adds DxeAslUpdateLib library support in IntelSiliconPkg, which allows AML to be updated in DXE. Signed-off-by: Miki Shindo Cc: Sai Chaganty Cc: Chasel Chiu Cc: Nate DeSimone Cc: Prince Agyeman Cc: Ray Ni Reviewed-by: Chasel Chiu Acked-by: Chasel Chiu --- Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c = | 553 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++ Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h = | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 4 ++++ Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf = | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 777 insertions(+) diff --git a/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUp= dateLib.c b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpd= ateLib.c new file mode 100644 index 0000000000..1eae8bca62 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib= .c @@ -0,0 +1,553 @@ +/** @file + Boot service DXE ASL update library implementation. + Note that the current version of the library updates AML. + + These functions in this file can be called during DXE and cannot be call= ed during runtime + or in SMM which should use a RT or SMM library. + + This library uses the ACPI Support protocol. + + Copyright (c) 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// +// Function implemenations +// +static EFI_ACPI_SDT_PROTOCOL *mAcpiSdt =3D NULL; +static EFI_ACPI_TABLE_PROTOCOL *mAcpiTable =3D NULL; + +/** + Initialize the ASL update library state. + This must be called prior to invoking other library functions. + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ) +{ + EFI_STATUS Status; + + /// + /// Locate ACPI tables + /// + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **= ) &mAcpiSdt); + ASSERT_EFI_ERROR (Status); + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID = **) &mAcpiTable); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** + This function calculates and updates an UINT8 checksum. + + @param Buffer Pointer to buffer to checksum + @param Size Number of bytes to checksum + @param ChecksumOffset Offset to place the checksum result in + + @return EFI_SUCCESS The function completed successfully. + +**/ +EFI_STATUS +AcpiPlatformChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ) +{ + UINT8 Sum; + UINT8 *Ptr; + + Sum =3D 0; + // + // Initialize pointer + // + Ptr =3D Buffer; + + // + // set checksum to 0 first + // + Ptr[ChecksumOffset] =3D 0; + + // + // add all content of buffer + // + while ((Size--) !=3D 0) { + Sum =3D (UINT8) (Sum + (*Ptr++)); + } + // + // set checksum + // + Ptr =3D Buffer; + Ptr[ChecksumOffset] =3D (UINT8) (0xff - Sum + 1); + + return EFI_SUCCESS; +} + +/** + This procedure will update immediate value assigned to a Name + + @param[in] AslSignature - The signature of Operation Region that we= want to update. + @param[in] Buffer - source of data to be written over origina= l aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. +**/ +EFI_STATUS +UpdateNameAslCode ( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINT8 *CurrPtr; + UINT8 *EndPtr; + UINT32 *Signature; + UINT8 *DsdtPointer; + UINTN Handle; + UINT8 DataSize; + + if (mAcpiTable =3D=3D NULL) { + InitializeAslUpdateLib (); + if (mAcpiTable =3D=3D NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Handle =3D 0; + Status =3D LocateAcpiTableBySignature ( + EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATUR= E, + (EFI_ACPI_DESCRIPTION_HEADER **) &Table, + &Handle + ); + if (EFI_ERROR (Status)) { + return Status; + } + + /// + /// Point to the beginning of the DSDT table + /// + CurrPtr =3D (UINT8 *) Table; + if (CurrPtr =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + // + // EndPtr =3D beginning of table + length of table + // + EndPtr =3D CurrPtr + ((EFI_ACPI_COMMON_HEADER *) CurrPtr)->Length; + + /// + /// Loop through the ASL looking for values that we must fix up. + /// + for (DsdtPointer =3D CurrPtr; DsdtPointer < EndPtr; DsdtPointer++) { + /// + /// Get a pointer to compare for signature + /// + Signature =3D (UINT32 *) DsdtPointer; + /// + /// Check if this is the Device Object signature we are looking for + /// + if ((*Signature) =3D=3D AslSignature) { + /// + /// Look for Name Encoding + /// + if (*(DsdtPointer-1) =3D=3D AML_NAME_OP) { + /// + /// Check if size of new and old data is the same + /// + DataSize =3D *(DsdtPointer+4); + if ((Length =3D=3D 1 && DataSize =3D=3D 0xA) || + (Length =3D=3D 2 && DataSize =3D=3D 0xB) || + (Length =3D=3D 4 && DataSize =3D=3D 0xC)) { + CopyMem (DsdtPointer+5, Buffer, Length); + } else if (Length =3D=3D 1 && ((*(UINT8*) Buffer) =3D=3D 0 || (*(U= INT8*) Buffer) =3D=3D 1) && (DataSize =3D=3D 0 || DataSize =3D=3D 1)) { + CopyMem (DsdtPointer+4, Buffer, Length); + } else { + FreePool (Table); + return EFI_BAD_BUFFER_SIZE; + } + Status =3D mAcpiTable->UninstallAcpiTable ( + mAcpiTable, + Handle + ); + Handle =3D 0; + Status =3D mAcpiTable->InstallAcpiTable ( + mAcpiTable, + Table, + Table->Length, + &Handle + ); + FreePool (Table); + return Status; + } + } + } + return EFI_NOT_FOUND; +} + +/** + This procedure will update immediate value assigned to a Name in SSDT ta= ble + + @param[in] TableId - Pointer to an ASCII string containing the= OEM Table ID from the ACPI table header + @param[in] TableIdSize - Length of the TableId to match. Table ID= are 8 bytes long, this function + @param[in] Buffer - source of data to be written over origina= l aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. +**/ +EFI_STATUS +UpdateSsdtNameAslCode ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINT8 *CurrPtr; + UINT32 *Signature; + UINT8 *SsdtPointer; + UINTN Handle; + UINT8 DataSize; + + if (mAcpiTable =3D=3D NULL) { + InitializeAslUpdateLib (); + if (mAcpiTable =3D=3D NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Handle =3D 0; + Status =3D LocateAcpiTableByOemTableId ( + TableId, + TableIdSize, + (EFI_ACPI_DESCRIPTION_HEADER **) &Table, + &Handle + ); + if (EFI_ERROR (Status)) { + return Status; + } + + /// + /// Point to the beginning of the DSDT table + /// + CurrPtr =3D (UINT8 *) Table; + if (CurrPtr =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + /// + /// Loop through the ASL looking for values that we must fix up. + /// + for (SsdtPointer =3D CurrPtr; SsdtPointer <=3D (CurrPtr + ((EFI_ACPI_COM= MON_HEADER *) CurrPtr)->Length); SsdtPointer++) { + /// + /// Get a pointer to compare for signature + /// + Signature =3D (UINT32 *) SsdtPointer; + /// + /// Check if this is the Device Object signature we are looking for + /// + if ((*Signature) =3D=3D AslSignature) { + /// + /// Look for Name Encoding + /// + if (*(SsdtPointer-1) =3D=3D AML_NAME_OP) { + /// + /// Check if size of new and old data is the same + /// + DataSize =3D *(SsdtPointer+4); + if ((Length =3D=3D 1 && DataSize =3D=3D 0xA) || + (Length =3D=3D 2 && DataSize =3D=3D 0xB) || + (Length =3D=3D 4 && DataSize =3D=3D 0xC)) { + CopyMem (SsdtPointer+5, Buffer, Length); + } else if (Length =3D=3D 1 && ((*(UINT8*) Buffer) =3D=3D 0 || (*(U= INT8*) Buffer) =3D=3D 1) && (DataSize =3D=3D 0 || DataSize =3D=3D 1)) { + CopyMem (SsdtPointer+4, Buffer, Length); + } else { + return EFI_BAD_BUFFER_SIZE; + } + AcpiPlatformChecksum ( + Table, + Table->Length, + OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, + Checksum) + ); + return Status; + } + } + } + return EFI_NOT_FOUND; +} + +/** + This procedure will update the name of ASL Method + + @param[in] AslSignature - The signature of Operation Region that we= want to update. + @param[in] Buffer - source of data to be written over origina= l aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. +**/ +EFI_STATUS +UpdateMethodAslCode ( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINT8 *CurrPtr; + UINT32 *Signature; + UINT8 *DsdtPointer; + UINTN Handle; + + if (mAcpiTable =3D=3D NULL) { + InitializeAslUpdateLib (); + if (mAcpiTable =3D=3D NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Handle =3D 0; + Status =3D LocateAcpiTableBySignature ( + EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATUR= E, + (EFI_ACPI_DESCRIPTION_HEADER **) &Table, + &Handle + ); + if (EFI_ERROR (Status)) { + return Status; + } + + /// + /// Point to the beginning of the DSDT table + /// + CurrPtr =3D (UINT8 *) Table; + if (CurrPtr =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + /// + /// Loop through the ASL looking for values that we must fix up. + /// + for (DsdtPointer =3D CurrPtr; DsdtPointer <=3D (CurrPtr + ((EFI_ACPI_COM= MON_HEADER *) CurrPtr)->Length); DsdtPointer++) { + /// + /// Get a pointer to compare for signature + /// + Signature =3D (UINT32 *) DsdtPointer; + /// + /// Check if this is the Device Object signature we are looking for + /// + if ((*Signature) =3D=3D AslSignature) { + /// + /// Look for Name Encoding + /// + if ((*(DsdtPointer-3) =3D=3D AML_METHOD_OP) + || (*(DsdtPointer-2) =3D=3D AML_METHOD_OP) + ) + { + CopyMem (DsdtPointer, Buffer, Length); + Status =3D mAcpiTable->UninstallAcpiTable ( + mAcpiTable, + Handle + ); + Handle =3D 0; + Status =3D mAcpiTable->InstallAcpiTable ( + mAcpiTable, + Table, + Table->Length, + &Handle + ); + FreePool (Table); + return Status; + } + } + } + return EFI_NOT_FOUND; +} + +/** + This function uses the ACPI SDT protocol to locate an ACPI table. + It is really only useful for finding tables that only have a single inst= ance, + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. + + @param[in] Signature - Pointer to an ASCII string containing t= he OEM Table ID from the ACPI table header + @param[in, out] Table - Updated with a pointer to the table + @param[in, out] Handle - AcpiSupport protocol table handle for t= he table found + @param[in, out] Version - The version of the table desired + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ) +{ + EFI_STATUS Status; + INTN Index; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_DESCRIPTION_HEADER *OrgTable; + + if (mAcpiSdt =3D=3D NULL) { + InitializeAslUpdateLib (); + if (mAcpiSdt =3D=3D NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Version =3D 0; + Index =3D 0; + do { + Status =3D mAcpiSdt->GetAcpiTable (Index, (EFI_ACPI_SDT_HEADER **)&Org= Table, &Version, Handle); + if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + ASSERT_EFI_ERROR (Status); + Index++; + } while (OrgTable->Signature !=3D Signature); + + if (Status !=3D EFI_NOT_FOUND) { + *Table =3D AllocateCopyPool (OrgTable->Length, OrgTable); + ASSERT (*Table); + } + + /// + /// If we found the table, there will be no error. + /// + return Status; +} + +/** + This function uses the ACPI SDT protocol to locate an ACPI SSDT table. + + @param[in] TableId - Pointer to an ASCII string containing the= OEM Table ID from the ACPI table header + @param[in] TableIdSize - Length of the TableId to match. Table ID= are 8 bytes long, this function + will consider it a match if the first Tab= leIdSize bytes match + @param[in, out] Table - Updated with a pointer to the table + @param[in, out] Handle - AcpiSupport protocol table handle for the= table found + @param[in, out] Version - See AcpiSupport protocol, GetAcpiTable fu= nction for use + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableByOemTableId ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ) +{ + EFI_STATUS Status; + INTN Index; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_DESCRIPTION_HEADER *OrgTable; + + if (mAcpiSdt =3D=3D NULL) { + InitializeAslUpdateLib (); + if (mAcpiSdt =3D=3D NULL) { + return EFI_NOT_READY; + } + } + /// + /// Locate table with matching ID + /// + Version =3D 0; + Index =3D 0; + do { + Status =3D mAcpiSdt->GetAcpiTable (Index, (EFI_ACPI_SDT_HEADER **)&Org= Table, &Version, Handle); + if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + ASSERT_EFI_ERROR (Status); + Index++; + } while (CompareMem (&(OrgTable->OemTableId), TableId, TableIdSize)); + + if (Status !=3D EFI_NOT_FOUND) { + *Table =3D OrgTable; + ASSERT (*Table); + } + + /// + /// If we found the table, there will be no error. + /// + return Status; +} + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + @param[in] ChecksumOffset Offset to place the checksum result in + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +AcpiChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ) +{ + UINT8 Sum; + UINT8 *Ptr; + + Sum =3D 0; + /// + /// Initialize pointer + /// + Ptr =3D Buffer; + + /// + /// set checksum to 0 first + /// + Ptr[ChecksumOffset] =3D 0; + + /// + /// add all content of buffer + /// + while (Size--) { + Sum =3D (UINT8) (Sum + (*Ptr++)); + } + /// + /// set checksum + /// + Ptr =3D Buffer; + Ptr[ChecksumOffset] =3D (UINT8) (0xff - Sum + 1); + + return EFI_SUCCESS; +} diff --git a/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h b= /Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h new file mode 100644 index 0000000000..108bb52413 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h @@ -0,0 +1,178 @@ +/** @file + ASL dynamic update library definitions. + + This library provides dymanic update to various ASL structures. + There may be different libraries for different environments (PEI, BS, RT= , SMM). + Make sure you meet the requirements for the library (protocol dependenci= es, use + restrictions, etc). + + Note that the current version of the library updates AML. + + Copyright (c) 2020 Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#ifndef _ASL_UPDATE_LIB_H_ +#define _ASL_UPDATE_LIB_H_ + +// +// Include files +// +#include +#include +#include + +// +// AML parsing definitions +// +#define AML_RESRC_TEMP_END_TAG 0x0079 + +// +// ASL PSS package structure layout +// +#pragma pack (1) +typedef struct { + UINT8 NameOp; // 12h ;First opcode is a NameOp. + UINT8 PackageLead; // 20h ;First opcode is a NameOp. + UINT8 NumEntries; // 06h ;First opcode is a NameOp. + UINT8 DwordPrefix1; // 0Ch + UINT32 CoreFrequency; // 00h + UINT8 DwordPrefix2; // 0Ch + UINT32 Power; // 00h + UINT8 DwordPrefix3; // 0Ch + UINT32 TransLatency; // 00h + UINT8 DwordPrefix4; // 0Ch + UINT32 BmLatency; // 00h + UINT8 DwordPrefix5; // 0Ch + UINT32 Control; // 00h + UINT8 DwordPrefix6; // 0Ch + UINT32 Status; // 00h +} PSS_PACKAGE_LAYOUT; +#pragma pack() + +/** + Initialize the ASL update library state. + This must be called prior to invoking other library functions. + + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ); + +/** + This procedure will update immediate value assigned to a Name + + @param[in] AslSignature The signature of Operation Region = that we want to update. + @param[in] Buffer source of data to be written over = original aml + @param[in] Length length of data to be overwritten + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFI_STATUS +UpdateNameAslCode( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + This procedure will update the name of ASL Method + + @param[in] AslSignature - The signature of Operation Region that we= want to update. + @param[in] Buffer - source of data to be written over origina= l aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. +**/ +EFI_STATUS +UpdateSsdtNameAslCode ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + This procedure will update the name of ASL Method + + @param[in] AslSignature - The signature of Operation Region that we= want to update. + @param[in] Buffer - source of data to be written over origina= l aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. +**/ +EFI_STATUS +UpdateMethodAslCode ( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + This function uses the ACPI support protocol to locate an ACPI table usi= ng the . + It is really only useful for finding tables that only have a single inst= ance, + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. + Matches are determined by finding the table with ACPI table that has + a matching signature and version. + + @param[in] Signature Pointer to an ASCII string contain= ing the Signature to match + @param[in, out] Table Updated with a pointer to the table + @param[in, out] Handle AcpiSupport protocol table handle = for the table found + @param[in, out] Version On input, the version of the table= desired, + on output, the versions the table = belongs to + @see AcpiSupport protocol for deta= ils + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFI_STATUS +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ); + +/** + This function uses the ACPI support protocol to locate an ACPI SSDT tabl= e. + The table is located by searching for a matching OEM Table ID field. + Partial match searches are supported via the TableIdSize parameter. + + @param[in] TableId Pointer to an ASCII string contain= ing the OEM Table ID from the ACPI table header + @param[in] TableIdSize Length of the TableId to match. T= able ID are 8 bytes long, this function + will consider it a match if the fi= rst TableIdSize bytes match + @param[in, out] Table Updated with a pointer to the table + @param[in, out] Handle AcpiSupport protocol table handle = for the table found + @param[in, out] Version See AcpiSupport protocol, GetAcpiT= able function for use + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFI_STATUS +LocateAcpiTableByOemTableId ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ); + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + @param[in] ChecksumOffset Offset to place the checksum resul= t in + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFI_STATUS +AcpiChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ); + +#endif diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/In= tel/IntelSiliconPkg/IntelSiliconPkg.dec index 3c49fb289c..d5debbf0da 100644 --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec @@ -30,6 +30,10 @@ # PeiGetVtdPmrAlignmentLib|Include/Library/PeiGetVtdPmrAlignmentLib.h =20 + ## @libraryclass Provides services to update AML in DXE + # + AslUpdateLib|Include/Library/AslUpdateLib.h + [Guids] ## GUID for Package token space # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735} diff --git a/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUp= dateLib.inf b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslU= pdateLib.inf new file mode 100644 index 0000000000..1183b320d5 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib= .inf @@ -0,0 +1,42 @@ +## @file +# Provides services to update ASL tables. +# Note that the current version of the library updates AML. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + + +[Defines] +INF_VERSION =3D 0x00010017 +BASE_NAME =3D DxeAslUpdateLib +FILE_GUID =3D 8621697D-4E3A-4bf2-ADB0-3E2FF06559CA +VERSION_STRING =3D 1.0 +MODULE_TYPE =3D BASE +LIBRARY_CLASS =3D AslUpdateLib + + +[LibraryClasses] +BaseLib +IoLib +DebugLib +PcdLib +BaseMemoryLib +UefiLib +MemoryAllocationLib + + +[Packages] +MdePkg/MdePkg.dec +IntelSiliconPkg/IntelSiliconPkg.dec + +[Sources] +DxeAslUpdateLib.c + + +[Protocols] +gEfiAcpiTableProtocolGuid ## CONSUMES +gEfiAcpiSdtProtocolGuid ## CONSUMES --=20 2.16.2.windows.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 (#55556): https://edk2.groups.io/g/devel/message/55556 Mute This Topic: https://groups.io/mt/71760104/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-