From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.1759.1588223653434365376 for ; Wed, 29 Apr 2020 22:14:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=FGUZAjMz; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: rangasai.v.chaganty@intel.com) IronPort-SDR: 3MqVkpmGjn3YfHFWs56fLpKMT65ycr5O1tB1P+MurpSA1+LMhQPxUugi2/0ybP7aWIY9N2I9a4 ok07fKFEbXbA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 22:14:12 -0700 IronPort-SDR: IPJ4IaaDogQ7OhE4rT87sz+UH2D1WbzMB8i8qHaWgM/52pkZeXtd43xMgayl5DAYZFpL2GTL76 Ualze3HLdvOQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="459811229" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga006.fm.intel.com with ESMTP; 29 Apr 2020 22:14:12 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 29 Apr 2020 22:14:12 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.170) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 29 Apr 2020 22:13:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h0t+MIHIJGzD8ikbsoCGoxzGohNQZ8007/IHsRy0hVtYPfr7mu2LqSgRlbxFyrOb951k6mTMkREcoIEo+jtSNyVjIhEz3Pyd6FiAWhsDe4L2YQr0c7Yd49HG/PZZ6bupzvX4Um5vdR/4lqLDFkNZZ5vvkr57XheQ8jrzqPHBSiV3kBex/Kvi7SXDWFJXCfLYleUmenHcdkOhPVbgUnKoK0LCPYwLGzYWRz/AoyGl6xOugieHCbktbALl2vAZmOTrFeJwqHVfA00DG7rlt+/32FbhC/lWAmnmUpW4hJNSeJaqlaCNTVVcw6svIOagYixOXIpZB3KFrkh4upZRYGpsWQ== 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=Skc2dmmKoqpWzf8BtV3rj9bwHUQlS4yBT1C7NGvZB5M=; b=Hsfj8f8FBYLu2zTdf9wiT9zXjWO1+8kqmJOSjRU9iKkhiN222uWM8kYSIJdnbvVmjiNAshCrw1Vox1wLoHqzr2x5cfHUM89A3aORi/t9rY9COvBfqZJFV0g5MzNPafUbwEsxWXqIUG2n8R+KCG0IFbW/wgH8kLCf3Rc/7VgnDMF8U3+zsiYGNRspR7F0WhfhSSYHK82A7RA4byDxV7ox5l1A84MajSiRtLfjpiN+3mi4AKlBWkE80mfeAxu1xnRzyXxp9kVZdw5HozimCzVu655Rrcu3IctpqRWHuCAir/kS10Of17IA+OnZA1PdaM8LnwJo//Mjd/FWTk9A4eHiNQ== 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=Skc2dmmKoqpWzf8BtV3rj9bwHUQlS4yBT1C7NGvZB5M=; b=FGUZAjMzmhzT6d0/J5kXlarNzoH6rZI9bF5lbTN5bEk9EMdiY+Z/E/XpInYsymyiLzmqnra5498Jr/Z3mkoaRpfN/AyAbHHhqiYZlcrTFxX1RdKW7uQ7fsKLo79AkSq8B0+Ul5Y9Adt6Xspwg/l0v+/xoK7sxfrtwjAA7CuCeLQ= Received: from CY4PR11MB1878.namprd11.prod.outlook.com (2603:10b6:903:11f::12) by CY4PR11MB1735.namprd11.prod.outlook.com (2603:10b6:903:127::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19; Thu, 30 Apr 2020 05:13:36 +0000 Received: from CY4PR11MB1878.namprd11.prod.outlook.com ([fe80::29da:d951:99c3:a94e]) by CY4PR11MB1878.namprd11.prod.outlook.com ([fe80::29da:d951:99c3:a94e%11]) with mapi id 15.20.2958.020; Thu, 30 Apr 2020 05:13:36 +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 v4 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Topic: [edk2-platforms:PATCH v4 7/7] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Index: AQHWHc5/pvoDylc6/E2rqhXCrEXCAaiRH8Hw Date: Thu, 30 Apr 2020 05:13:36 +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-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: [192.55.52.222] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f3429ebc-1e9c-4ed0-509b-08d7ecc53cb0 x-ms-traffictypediagnostic: CY4PR11MB1735: 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:262; x-forefront-prvs: 0389EDA07F x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vZSKzQpnxT4yhcbxnhBpsV5yIxbdQoo3xMtUQ5BuX9uxQXNt3ndxmcyiz+6WFj9zMJoKwXXa36tiAfMuqNXvDD4zQDKUDXXvbW6ovjmcsBe2l9bVWl+7tCYB1cSRTYR9skWhzMjLFPY/US1copWCNypdwTg0zPSyP/3bzI1LcxLbG1EY2XBe9FP064UYZchpOiiNsI5PEpsvvtPq4Z+O4BsOW//eeiL6GAfoCt40SoktyqiSg0E4hPOXVmpXyHxZrpdSCC3VOlr+K1d+NETmJMWmb6nndrJN/Yh79cpQBxAjMnHCjI+3f2/dNaFMjhWSqI1RCA1zCsGO/cwBZ8nOFuNG6yzwn8pQDKHMADcqM0gefmAj7SIW8OfkINkZEhQvetMH32dAUneIFpSFxFgD8PlYKNfB+sqb/4Y57I/knuTYDyj8eTp1TCiXBDNhVirMs8aRpUwfsmqpT68DABlveKzzrF0XkuwVQIqWaaWV00iyrShhVQVKK8wh4WKGdL4KKETg03c8ZmRsPsz/+eckfA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB1878.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(366004)(136003)(396003)(39860400002)(376002)(346002)(66946007)(9686003)(71200400001)(8676002)(64756008)(186003)(8936002)(66476007)(4326008)(66556008)(66446008)(30864003)(33656002)(76116006)(86362001)(6506007)(110136005)(26005)(53546011)(7696005)(316002)(54906003)(107886003)(5660300002)(966005)(2906002)(478600001)(55016002)(52536014)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: fIGUs+CRUsIV8FaMO2j/3jL0uMnE0lbv/o1ft6tmG4d+NoBTadD4PJVdCpHwOIdDJc0xjIPjdgfVTybXvfqoXxL4c+tYRQok7IBnX/UMJ375VEcxAAvpAOvcSimCj1BXkONp8KXvfZb0tmhzZVd6CQQG7CXo/8zC3F/5b7ZCGyuPp0LHrzFycn8lxXWSFx0PSe1SUgdIQOVWW3px+B1aTg5g9ChLImhFMpUX9rQX/NIYnSAoQTE13MGZVgpVRcskWkZO87c8/D7DQMCDE/zMoSPjhHu30mkiE4M3LCc26XwWF2zckBGgkTUU/9U8NhuH/A346pEONt+aLMKvEAcXRDZ+4ewHvTNyCgDdNLrXXW3b9YNn7EKJ/1jrWRZ+ATxc2ZDU4qQK+XE1apECvVCsXQmR/MKhY+F1ypG0MuPU8OKKaI6sb61YOp7LTQ6K9dLUbm+O445WLwGQ+pDwD3MX5gQsrJldHXaQG894pEQ1YJJ/kGI3HJyewMOXqJcRY471YtcibwvEe0YCoiZsMzxjgt+jwRoGB6i6HyqQDa+3G2WzwRgxXmKOoGt9xQiaWYePOlN/ExevpAbX5miDtvmwaNiU/QDippQuo0gI4h8+fvQ2q+YRS9DDpnMiKQmkeauy2Ay0zjoHGRFmqLC2hm8hEm50PxVuDWwVmLoOOj8RU8jsAGTVVmXsArkxm5rCgQzdMQHFUbUKfu9sENZOHtmMQY525jviS6rxvVfLg5tJmVahR/A97UiLm5MlnReFqbaIwgPC0LJrpd0v9OqmStTMORoU12EeIYTND+EDa0S7hSY= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: f3429ebc-1e9c-4ed0-509b-08d7ecc53cb0 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Apr 2020 05:13:36.5655 (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: HBHQzd46EQeFDgbUSZ+mPMoTxIIZWsNb8cnWZwDPM9nBA1wRUTHu/mo1MnJoM4noWiQAhlGtjrtvjvADWwjDQhNGMwNH+e1WHe5ykwZJHuI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR11MB1735 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 The following APIs have very similar descriptions UpdateNameAslCode UpdateSsdtNameAslCode UpdateMethodAslCode=09 Please help update the descriptions to better reflect the purpose of the AP= I.=20 With that: Reviewed-by: Sai Chaganty -----Original Message----- From: Shindo, Miki =20 Sent: Tuesday, April 28, 2020 7:32 PM 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: 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: 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.inf = | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 680 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..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=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 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=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=20 +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 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. + + @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..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=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 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 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 usi= ng the . + 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 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 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