From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com []) by mx.groups.io with SMTP id smtpd.web11.471.1588215457962842330 for ; Wed, 29 Apr 2020 19:57:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=s6VCBOse; spf=fail (domain: intel.com, ip: , mailfrom: chasel.chiu@intel.com) IronPort-SDR: nr4vvTM1VVMfkitumAXlXfDq5wVFA11S79alZ6pFWnFZ2S/G1n2Ye7T9xgHQL9Shy7ErMPqd8D 05FtYQtbuNAw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 19:57:40 -0700 IronPort-SDR: YFn0QKdfqMuGsIYXtfCt+CjTcBkxzgP7uudfwiqwm0kFd8TiTOQ7ouQCvM2XKOcT1Y3lU7xrBh 4iXPQWzcl3Ow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,333,1583222400"; d="scan'208";a="258155515" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga003.jf.intel.com with ESMTP; 29 Apr 2020 19:57:40 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 29 Apr 2020 19:57:39 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.109) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 29 Apr 2020 19:57:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fLmDjCa6416hms3vEXf66rd2zfkwV79AHsmX4jsUmsl8x5++JVeVZ08TbvbxCOZuh7Un6ajEjpPtX5+1dPJlH3Nm2msZDpgSobbabqq3JTpWc001YmyPfSX3OPAsm0mZgpXqYRzOe3SE6vczPKWGaXeklmyY8mfVk3oYDfGOc8ATovLw8llYUfDu/AVKdZ+xTf8H6jIJydrZm3WRGWhfriphzyWHL7CaY8Ewk/iPQ5/69D7dL+p97Tx8Fl4gsojGMSzo+wlPq38xWb3vYoSQiY2zQDG64W69XtL0MnK9DvyBk+M9LO28t9T3Nd4bZHHlPNgmu4/GgBhqEmyNtH8bHQ== 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=lNlbzD20voKNBO/F84HFjZJIr88jyDh4ssosKRACxKI=; b=h4CzdafgXxPXDfDHCH3zAN17bIqTGUKZ0CNOv8La1jP1bbYg9ioNNmiB3AkGbkdm28CAh0kuikH0hD+91EHarX9DDXQFcZiJVndTuK7nmIwiAIIIdt1/1Hyb6PxCjISZ9JDdQ02MgKEkLDbMYd91QHaW6tgFdLDFJYZMHL8Frfkk2l6l39KhECadYmgwg2kZ03fboP3I/wdAQw9PhQQPQjbnBgloDYkUCk3BfuHYkVetuSTDQCAZTUdplus/7ugB/5l5YepH0mGwmf1lMl7bCK14Qc/DQ8Y2t+0sfFyx02olVKiHCNdhbIvkjT9T7+5WJXGiDfGabVe0G33YD2gYlA== 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=lNlbzD20voKNBO/F84HFjZJIr88jyDh4ssosKRACxKI=; b=s6VCBOseca5ID2dku6bHugNABD50mpPnxELIGS2pYkvBkCLL24R36RPV3ruNxM1ljwkP1KwJEVSm+atpqKPyQbXTIcOhfru06qxhuJ70K8O0wE0f0Dx7iCDfr95vSbfgI6KiNbOinHfCwAOjFWhBcUooKKKabN0G0CJd3MMwbkA= Received: from SN6PR11MB2814.namprd11.prod.outlook.com (2603:10b6:805:55::15) by SN6PR11MB3053.namprd11.prod.outlook.com (2603:10b6:805:d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 02:57:16 +0000 Received: from SN6PR11MB2814.namprd11.prod.outlook.com ([fe80::152f:df2:6370:1584]) by SN6PR11MB2814.namprd11.prod.outlook.com ([fe80::152f:df2:6370:1584%4]) with mapi id 15.20.2937.023; Thu, 30 Apr 2020 02:57:16 +0000 From: "Chiu, Chasel" To: "Shindo, Miki" , "devel@edk2.groups.io" CC: "Chaganty, Rangasai V" , "Desimone, Nathaniel L" , "Agyeman, Prince" , "Ni, Ray" Subject: Re: [edk2-platforms:PATCH v4 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Topic: [edk2-platforms:PATCH v4 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Index: AQHWHc5/pKVq3QTVRUq8SsnYHZfwQKiQ+ngg Date: Thu, 30 Apr 2020 02:57:16 +0000 Message-ID: References: <20200429023203.37544-1-miki.shindo@intel.com> <20200429023203.37544-8-miki.shindo@intel.com> In-Reply-To: <20200429023203.37544-8-miki.shindo@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 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: [192.198.147.193] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0c4a5374-cb0b-42f6-f5f8-08d7ecb23120 x-ms-traffictypediagnostic: SN6PR11MB3053: 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:130; x-forefront-prvs: 0389EDA07F x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB2814.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(39860400002)(346002)(136003)(396003)(366004)(376002)(478600001)(26005)(5660300002)(33656002)(186003)(107886003)(71200400001)(8676002)(6506007)(76116006)(966005)(2906002)(54906003)(66946007)(55016002)(53546011)(316002)(110136005)(66476007)(66556008)(8936002)(9686003)(66446008)(86362001)(64756008)(52536014)(7696005)(30864003)(4326008)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: baNYa+tr52pecAcHjEj1MLq3Bx8mOOW+lWC5/YK2R+WfJte/4KbKzKsK6Robtw54bCjEGWNW2GYQRtFqTj15+hib4HMmhCl8FHVlfRI4YHUbPpETzwUYvsrVTG0auxFiHO1Hq1mTb7yaSwTkhe4jlNULcCCc8nUTgIF0YMFKRuB3mvosY73n8m1D+ADkIVglcmur05/7oa9+Ir5IldXOoOYYwwT5lQWKziuqgia2XObsrXrDoFQTB18tlhdJ0+joPc0RwL9fDcZ5co3zmy0G9vzeVlQMAooP/6C9e3A+9pjyOJ2ZsuyVc0AHsoDJjyrtthXAZajUOcA2X8PZIxq5nKwB20sGA/xQ725mv1XppMQPnufeCM9jLEK4/FYRTVtihzoXJdCnB/zRtG41uLWeQTCDCO7W+zbQKseblHpoCdPktjbMG/3nfZmbWCiOPK2VmxMes7TjUSTvv+xOsfC0aXcFzVFzYrVQJLWTWNimGEof6vClvdC0fwy1r+zdu29/p/oSXQsYTWqgzSLUFbn4jA== x-ms-exchange-antispam-messagedata: gBUVJF8M46B//bcRQaWmKsgF1p8o24WZAacIJegGa1wvsTCrcon+4i7y6cmC16e68uUHlcKXz017BEDZv2nc1pg34J4w68dBY8H5VFTecMo44ggKnpkp11TxBQJL0RKIpQOst5Yx28XLn8zzRKW0QmV/AR4sezOtcjJMVQBeCD+PUmPaOhvSTSJO+CSVRskIkGcAqePL+48OVcwSEQI4O2iBqfuuEbYMcmGHfA2jt4/r+IQVPO2KhFhr9PjLCtXMgv5zp4Vyj+8ZBnLvy8XILbm7WzolBinggNIYVotnHLKLiNdtJP2Mbz7TbAmxDRNjY4+kGzwGpIwwK7QuVZnkui5t6gr2+aSfj6dqjFeEMktcUsPuoc9HJWGaIf1sGQaIorO3atalSduEDqufg5e75kn11zFX9CMdk5ZWlzTy73RlSxsr4ARs8UKsG1guhMAcnOBpBgj2uF4Op0Cxu5LZEDj/pBEdmogabc+B9KoYh4QW9KtpuU9LzJ57G+Mg31K8ofL4QdR2WLVSjTDftau4fn297vr1eNAlSupah8QrvIwhWKMhEuuRfXB5R3QhYHRhcni+33u+qiHistEWARDlz1qqVXXWzWYl4dNlbrkDyf/7S9Q+Mkn3pPm1gqRfe1hoJ/9PbUrL4RXpIIS2Ze9RMjvkrVgmpW3tJWIYuvcIaJ7h8OeVOt5R0sk9sE6TOvFwKW2lPqOjI/KJ1kIbSIDaCUTLwau0644A8JwL6JcIYzTv+fuxFuHjHJFMb5an48uaNuo8hkWNDUstb4tVX49c25VjzL9uoGrHSNRvujhqeGLX12x532kHJtFNxk59tvoz MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0c4a5374-cb0b-42f6-f5f8-08d7ecb23120 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Apr 2020 02:57:16.7702 (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: T3vBN5XJqmBkiC9kcTewlJd9piHyCpXapDKZcvvBd8pkebe/SzT43r1O9rL+J6+JihclHK7sS74pwd3iLxTcLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3053 Return-Path: chasel.chiu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chasel Chiu > -----Original Message----- > From: Shindo, Miki > Sent: Wednesday, April 29, 2020 10:32 AM > To: devel@edk2.groups.io > Cc: Chaganty, Rangasai V ; Chiu, Chasel > ; Desimone, Nathaniel L > ; Agyeman, Prince > ; Ni, Ray > Subject: [edk2-platforms:PATCH v4 7/7] IntelSiliconPkg/DxeAslUpdateLib: A= dd > DxeAslUpdateLib support >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2536 >=20 > This commit adds DxeAslUpdateLib library support in IntelSiliconPkg, whic= h > allows AML to be updated in DXE. >=20 > Signed-off-by: Miki Shindo > Cc: Sai Chaganty > Cc: Chasel Chiu > Cc: Nate DeSimone > Cc: Prince Agyeman > Cc: Ray Ni > Acked-by: Chasel Chiu > Acked-by: Nate DeSimone > --- > Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c > | 518 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++ > Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h > | 116 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > | 4 ++++ > Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.in= f | > 42 ++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 680 insertions(+) >=20 > diff --git > a/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c > b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c > new file mode 100644 > index 0000000000..9b3117536a > --- /dev/null > +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdate > +++ Lib.c > @@ -0,0 +1,518 @@ > +/** @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 > + 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 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, (VOI= D > +**) &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 > 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 > + > + @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 > **)&OrgTable, &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 > original 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_SIGNATURE, > + (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 || (*= (UINT8*) > 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 > +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 > + @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 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 > + *) 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_COMMON_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 || (*= (UINT8*) > 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 > original 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_SIGNATURE, > + (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_COMMON_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 > +instance, > + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. > + > + @param[in] Signature - Pointer to an ASCII string containing > the 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 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 > +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 > **)&OrgTable, &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..cfe0fc9356 > --- /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 > + 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 > +_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 > 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 library. > +**/ > +EFI_STATUS > +EFIAPI > +UpdateNameAslCode( > + IN UINT32 AslSignature, > + IN VOID *Buffer, > + IN UINTN Length > + ); > + > +/** > + This procedure will update the name of ASL Method > + > + @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 > original 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 > library. > +**/ > +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 > original 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 > library. > +**/ > +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 > using the . > + It is really only useful for finding tables that only have a single > +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 and version. > + > + @param[in] Signature Pointer to an ASCII string > containing 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 > + @see AcpiSupport protocol > for > + details > + > + @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 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/Intel/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 # > + AslUpdateLib|Include/Library/AslUpdateLib.h > + > [Guids] > ## GUID for Package token space > # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735} > diff --git > a/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.i= nf > b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.i= nf > 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.
# # > +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 > -- > 2.16.2.windows.1