From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.216.1588802096990989879 for ; Wed, 06 May 2020 14:54:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=MjJZw/nE; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: rangasai.v.chaganty@intel.com) IronPort-SDR: Iuihdi1tc9ao8u8DJ2q7tt54GL8QxJsxk92rjSCTQNnPqwzgp7aFfo1K4YVqt6QvKHBhLgVHte 9314tRhK6mTw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2020 14:54:56 -0700 IronPort-SDR: reKYP0FGw0UwvZMI9rPCRAD5ZwacD6bEs5a0qcUgK8YWit3fc6SjXK/O0a75zUddrm1YF4lGpA 4gsGmOTjnCLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,360,1583222400"; d="scan'208";a="461916055" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga006.fm.intel.com with ESMTP; 06 May 2020 14:54:56 -0700 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 6 May 2020 14:54:56 -0700 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 6 May 2020 14:54:55 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 6 May 2020 14:54:55 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 6 May 2020 14:54:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AKH55E+HOQQ5CZENugWPIA/DEAfrdjx81PIUpB+WLlAbbsCCJ2jPiMQwgmJfkHZgxBWjJvdFHcL/6rQLnbVDneYMvFlWPWSNrvUr8r35kUjTBwGkuf0Z4l1MAohyt1XIWe9fJ7f6nSJMyIKKtN9OYvl9eRCbom3nn1smYsbn5+P6SnQISQLQEe8K69TXlqWbFTTi6W+ampY9OyDF71kLSh075q7cRP9PpvhjiDa79L62Z6dOUZ4kb2MYWZbbdfeR5OdPsIVUhHRugIErsHVs+N2N++UzwVQTaZ+QVNAVvOjdiiuC33yfhaoo2UgypNp9DMzeVc/DXdT2gZqclRUeRw== 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=bauwUtADoVwUVvZl4umUji/MCFNU/cq/qb1VPUuV0b8=; b=AB6mbcxf8RRvNuVLW2aPG+6gLVE73twWJfNNAmsdHJxGvqp/5VtrdqbJ2AoGX5gNwmL34dal2dluf2P4m6N9KqaReDnjW/Y1/guDBPq3NDbzCIHdCOmSCr5p7wqs4SdO52SNAKCq6zu7v+ZdmKxPXuF9JJu0t0CCvuW+gQtQ/YRHr7aY0DCyfw+OyaIfojS5FR6PNco3sVn3XLJr/3+q5wwy+29L9wGvS7Z0Yljvp+hauanX6bplXu+kbqfN31pKAZizPT/iQd1qeOwRH+0tlJE5eA6PbAaA2BtVbqlBsdf7HkCJW+yf8Os32pHu3XtZXuI8h/Mnm/KW7jzfJdiELQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bauwUtADoVwUVvZl4umUji/MCFNU/cq/qb1VPUuV0b8=; b=MjJZw/nEuliJWtEjRe+V8fO+KpoMYJJA2mwjtgvCm9Wi/tbo5ilM8DG8toGdAveGOPcjeqVafyDz01q3bO4BU0NUSoIlDzrw5/3l/OFodxSc9gi+PVVKqkYVD/EWbnLt6ZYraXMCEPcID8+WEgCebxJMEeIo/6mcmS6F0HYrPsU= Received: from MWHPR11MB1886.namprd11.prod.outlook.com (2603:10b6:300:110::9) by MWHPR11MB1566.namprd11.prod.outlook.com (2603:10b6:301:10::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.27; Wed, 6 May 2020 21:54:47 +0000 Received: from MWHPR11MB1886.namprd11.prod.outlook.com ([fe80::64d0:a918:94e9:d710]) by MWHPR11MB1886.namprd11.prod.outlook.com ([fe80::64d0:a918:94e9:d710%9]) with mapi id 15.20.2958.030; Wed, 6 May 2020 21:54:47 +0000 From: "Chaganty, Rangasai V" To: "Shindo, Miki" , "devel@edk2.groups.io" CC: "Chiu, Chasel" , "Desimone, Nathaniel L" , "Agyeman, Prince" , "Ni, Ray" Subject: Re: [edk2-platforms:PATCH v5 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Topic: [edk2-platforms:PATCH v5 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Index: AQHWI1T70Pn07GfQuEOHjdlAqO7GyKibmzAw Date: Wed, 6 May 2020 21:54:47 +0000 Message-ID: References: <20200506031650.55020-1-miki.shindo@intel.com> <20200506031650.55020-8-miki.shindo@intel.com> In-Reply-To: <20200506031650.55020-8-miki.shindo@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [50.45.159.74] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 97d142ec-ef7d-4d4f-3d6c-08d7f2081859 x-ms-traffictypediagnostic: MWHPR11MB1566: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:323; x-forefront-prvs: 03950F25EC x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iFvOFayb8Aa2l2O2ErJoks8PjessOfOjKxJDSH9+iRUxKZfNVRdKWCusjBWRLHzYjrml+nKku6HJilzrzjyW53Rx/3/LxR6huxU/Z63jSyEOO8Fcb9oOQz/0OU+CH0esA9Bpw+P7S0kKQ6XFTrkD+oaAVAOTzpyLgX4dX2D6cTBEQmyh5Meu9EmNMWCkD6amBNnEsEp/cHmUT9VeNkOzz9SzE0YjZ89hSJM9auj/SNK5HHekM8Vfi3TKG9xKPn7o+NjOunP8hiKNNJMOofEforRj0cSKDAl4KITGm9Kf+JxPrxbIFjYXxyqhA169NhJBGvMDqTB/JuhBvNeot/uNXvoJpEJ4HeXu9r7qAik8gMrj87M6gYmCsOA86H8eghmoeJP8c4BNs7N/XwRIfMxm2NboCH/lo4oWhukKzP4ozP8UFYHfLFLna5qL6MY33cclJei/FzfrtMqktsI3w3mYTrQGWQPH9+6PEW8Ft0cH+9a0n0zmFxIbju3515ImVEC1+rHEiIigRd4bEhbIbnRu47NzbybFpac+rcHLGcPuC5OCL34RdArLC4Qnmns1GhGRvGIZ8RQdlZoG7Gkksm+xMosWSnygNpDiOWRttau0gRE= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1886.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(376002)(346002)(396003)(366004)(136003)(39860400002)(33430700001)(26005)(86362001)(2906002)(186003)(71200400001)(33656002)(8676002)(66476007)(52536014)(66946007)(54906003)(110136005)(316002)(6506007)(5660300002)(33440700001)(7696005)(53546011)(30864003)(478600001)(66556008)(64756008)(66446008)(107886003)(9686003)(76116006)(55016002)(966005)(4326008)(8936002)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: LIRBo7Znmp4QSwx55tjMV+j2+uyr+iwi32haN9fCRxR6pF6xddcPef/cPoEfd+ja/5F6ZcmcPYZIKWW5uLQH81n39zSRZ/1PQsmXVU3JL3smZJkQd+iQ71MvuKmfaNvRGfuvh8Dy5Sx8ujIcxiAJVYopQ1TCZw0p906fWvfezJFrQi5uoc8lJt2nRYjrwLd0otagdnIcetztUs/o1aNx1s0m1PR/tkMAUq4RgOZJxIic40HuNFi3GstuFIJ4g63FxQC56Dqt+fVSpViCarYB/qmlFAqTbCfsmS5OuE9I8djQqAoZzSHqMa2iW9Quf9+iFbrW5D3kuXKKlLnqz7dT8AIXMJdqCK0UkVA+z0Elw2xcGTUvIwdJvVpulwmMzuG833or4Ll8MwyDf5U1/n5tFIXxV3W9/sGBl4Bq1ahF4NZ9ynuMMVjPxbcByYYBky1KnyBi0+JO1Qr3fsBkVhtlBRjUdqt/VgEXb7uYw8C5WxiT0jUv3EfjpUrTOvbR1TNJcyItGxxsh1W9ajn7hEwqxa21tKe9rFC8AYYR53PwCFmm38TGwAhczGbRJwZJRxgX44hh9EQRI7NxfFP1fXXZOGr6zaPaObQf7JJ8IWZI7ML4gXWHj0aY5eEHRLxEFAzeyWPsQBBrLa5SHgHYMsp6cxb6sDAQ695PQ7t4V0ij520CKTKxVNzwL1JKTelZwl8OOhBSoZj+kyqcOqvtg8byaLZOLqgw0IhAfN9AwPvjNptXeuyhKAQR4uDRZhjZHDuThp5Ca++HbIplg/HpkiOOMok8lVIBVV0WoUKPXzcHGKw= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 97d142ec-ef7d-4d4f-3d6c-08d7f2081859 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 May 2020 21:54:47.7456 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8KSp2EBleAjY/6w3OnEEOLVKgoI9WOny3yfIVN4usrosObus4b94j0VRM3VLtkqK5/tqPVYeTBTdZSIdfy883os0uxTonsV4Mky0k5pnabM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1566 Return-Path: rangasai.v.chaganty@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Sai Chaganty -----Original Message----- From: Shindo, Miki =20 Sent: Tuesday, May 05, 2020 8:17 PM To: devel@edk2.groups.io Cc: Chaganty, Rangasai V ; Chiu, Chasel ; Desimone, Nathaniel L = ; Agyeman, Prince ; Ni, Ray Subject: [edk2-platforms:PATCH v5 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add= DxeAslUpdateLib support 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 Acked-by: Nate DeSimone Reviewed-by: Ray Ni Reviewed-by: Sai Chaganty Reviewed-by: Chasel Chiu --- Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c = | 520 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= + Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h = | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 4 ++++ Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf = | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 682 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..6bca596b43 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdate +++ Lib.c @@ -0,0 +1,520 @@ +/** @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=20 + called 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 at the beggining of the function calls in this libra= ry. + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ) +{ + EFI_STATUS Status; + + /// + /// Locate ACPI tables + /// + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID=20 +**) &mAcpiSdt); + ASSERT_EFI_ERROR (Status); + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID= =20 +**) &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 + + @retval 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 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 + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. +**/ +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 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. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. +**/ +EFI_STATUS +EFIAPI +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=20 + *) Table; if (CurrPtr =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + // + // EndPtr =3D beginning of table + length of table // EndPtr =3D=20 + 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] 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. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. +**/ +EFI_STATUS +EFIAPI +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=20 + *) 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. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. +**/ +EFI_STATUS +EFIAPI +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=20 + *) 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=20 +instance, + 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. + + @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 + + @retval EFI_SUCCESS - The function completed successfully. + @retval EFI_NOT_FOUND - Failed to locate AcpiTable. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. +**/ +EFI_STATUS +EFIAPI +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; +} diff --git a/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h b= /Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h new file mode 100644 index 0000000000..9b7c0552af --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h @@ -0,0 +1,116 @@ +/** @file + ASL dynamic update library definitions. + + This library provides dynamic 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=20 + dependencies, 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=20 +_ASL_UPDATE_LIB_H_ #define _ASL_UPDATE_LIB_H_ + +// +// Include files +// +#include +#include +#include +#include + + +/** + 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. + @retval EFI_NOT_FOUND Failed to locate AcpiTable. + @retval EFI_NOT_READY Not ready to locate AcpiTable. + @retval EFI_UNSUPPORTED The function is not supported in t= his library. +**/ +EFI_STATUS +EFIAPI +UpdateNameAslCode( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + 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] 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. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. + @retval EFI_UNSUPPORTED - The function is not supported in this lib= rary. +**/ +EFI_STATUS +EFIAPI +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. + @retval EFI_NOT_READY - Not ready to locate AcpiTable. + @retval EFI_UNSUPPORTED - The function is not supported in this lib= rary. +**/ +EFI_STATUS +EFIAPI +UpdateMethodAslCode ( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + This function uses the ACPI support protocol to locate an ACPI table. + It is really only useful for finding tables that only have a single=20 +instance, + 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. + + @param[in] Signature Pointer to an ASCII string contain= ing the Signature to match + @param[in, out] Table Updated with a pointer to the tabl= e + @param[in, out] Handle AcpiSupport protocol table handle = for the table found + @see AcpiSupport protocol for=20 + details + + @retval EFI_SUCCESS The function completed successfull= y. + @retval EFI_NOT_FOUND Failed to locate AcpiTable. + @retval EFI_NOT_READY Not ready to locate AcpiTable. + @retval EFI_UNSUPPORTED The function is not supported in t= his library. +**/ +EFI_STATUS +EFIAPI +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ); + +#endif diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/In= tel/IntelSiliconPkg/IntelSiliconPkg.dec index 7c43593382..e4a7fec3a3 100644 --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec @@ -38,6 +38,10 @@ # ConfigBlockLib|Include/Library/ConfigBlockLib.h =20 + ## @libraryclass Provides services to update AML in DXE # =20 + 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..cefbe30628 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdate +++ Lib.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.
# #=20 +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 DXE_DRIVER +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