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.web12.8022.1587250509236370719 for ; Sat, 18 Apr 2020 15:55:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=NyVmnXcI; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: nathaniel.l.desimone@intel.com) IronPort-SDR: 2eHGIlyR7t3mKlqn65262E0eXjeNNjaCQ1I+NovpRXDeIFq7/rfHLdLO+uxpDNtW7Adu5Fl4CB jXDqNOG2czyg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 15:55:07 -0700 IronPort-SDR: Enx4FjECMmVf2YqRaCQbKALtV645eWL5/pcYe7yGKF7xuiJlSQfZSLQzTofdiKDFd9mKF+tv5U y2uHq1Wd0XXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,400,1580803200"; d="scan'208";a="283600315" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 18 Apr 2020 15:55:07 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 18 Apr 2020 15:55:07 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 18 Apr 2020 15:55:07 -0700 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (104.47.44.51) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 18 Apr 2020 15:55:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dolgo4ZEU5BpzR0E105o6ZjC7fbdVx93e2PECaZGBa3HLo5EYaGX/EuxHiLQyv72hgY+1IBbKEQfrROwzbZRWEOkafjSdhX1dckLkA1w8Q8P8IK1sfU9HrMvQwb/QPIVf7KqpRg0Zs+LhaR2cBPjZH2HbFtZ2kHH3ErX4nuhygLXZ01woCFnzw0CRQm29+4spoZtOD5eNMZpfg+0uLi1akFaf5rj45mqSgF7dKSg1OE5VqqonQX9fmmpxwJqa+LzZn4liBRqgUTnNPqG/p5qY2TkCc8Ss89NImVPGHSznjEWI2Ws+prZYuXiDIPRp6QYSrN9U34k3XyQGdyTPg2CsA== 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=eykujB0fCbpI5udcAs7vCi3dLM3zaZb2mQdMCsoDihc=; b=ea8wiUZmRcPMcbQDnc5QjZlmOb0RUCDwz1aJFTcI0zyku2VZP57MR+P5ZCdrf0guexD+TCPWEKjsWhyVMZBwPVPRcZqc2jMyGIQROlo/HDv+ny6wVmJKK6tUBgWmOgKiVZCBUGFVDznW2AvdtidYgDROMD0KxWIg4vXXpe3oy2u7W8gy+oQ8+cIOZSZi4yyCHqw1l+FFT50vZYbwgTy1C8VgDUqSgVraMYTzF0jMrrGlNsc++IWoBJHfOC4mQAEAMBTV43l/ivEG5mDQXA1XlQjBL5832RXj9gHZoDe6/VuVb9PdY5FWk+M9tdDYucVKM/G6wF5tVHmgjMq4exli4Q== 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=eykujB0fCbpI5udcAs7vCi3dLM3zaZb2mQdMCsoDihc=; b=NyVmnXcIxDXHrWYkGGXDoWQuSJIVWw1ccVH+M7Ccn9wwhgXvLYbzolf3vqfI+jhZlq2lbvVImlAfnRcbxyp4Qim3XB/h77t9+aFzdTDLKU60wBGzYdgXSDiFOIpgAGeil+mct6nATu+9EmK7HAgKvM2pCVszTrSECmfPvFUWYbg= Received: from BL0PR11MB3489.namprd11.prod.outlook.com (2603:10b6:208:75::29) by BL0PR11MB2961.namprd11.prod.outlook.com (2603:10b6:208:76::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.15; Sat, 18 Apr 2020 22:55:04 +0000 Received: from BL0PR11MB3489.namprd11.prod.outlook.com ([fe80::d0f8:bfd7:bae2:3e42]) by BL0PR11MB3489.namprd11.prod.outlook.com ([fe80::d0f8:bfd7:bae2:3e42%7]) with mapi id 15.20.2900.030; Sat, 18 Apr 2020 22:55:04 +0000 From: "Nate DeSimone" To: "Shindo, Miki" , "devel@edk2.groups.io" CC: "Chaganty, Rangasai V" , "Chiu, Chasel" , "Agyeman, Prince" , "Ni, Ray" Subject: Re: [edk2-platforms:PATCH v3] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Topic: [edk2-platforms:PATCH v3] IntelSiliconPkg/DxeAslUpdateLib: Add DxeAslUpdateLib support Thread-Index: AQHWC+UW0oSQGuDTdEOC2Ru4/4GBbKh/kJmQ Date: Sat, 18 Apr 2020 22:55:04 +0000 Message-ID: References: <20200406072910.24136-1-miki.shindo@intel.com> In-Reply-To: <20200406072910.24136-1-miki.shindo@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNmQwNWE1NWItYWQ3My00NWIwLTljYWUtYzY4YTZiYzkyMmU4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiU09OVHJJQUFrZURuTVwvckQyU0ZrNDlVbWIyVjloUmZsSUZNVDBVXC9rRFdEM0R1cUZmY0FSSURpUHNyWkh2aUJ1In0= dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows x-ctpclassification: CTP_NT authentication-results: spf=none (sender IP is ) smtp.mailfrom=nathaniel.l.desimone@intel.com; x-originating-ip: [134.134.136.198] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4e236a43-f8c1-4a24-70d3-08d7e3eb88d7 x-ms-traffictypediagnostic: BL0PR11MB2961: 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:181; x-forefront-prvs: 0377802854 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR11MB3489.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10019020)(366004)(136003)(396003)(39850400004)(346002)(376002)(33656002)(83120400001)(26005)(5660300002)(966005)(107886003)(478600001)(52536014)(4326008)(30864003)(8936002)(53546011)(2906002)(81156014)(66446008)(66946007)(76116006)(6506007)(186003)(71200400001)(8676002)(86362001)(7696005)(54906003)(110136005)(55016002)(64756008)(316002)(66556008)(66476007)(9686003)(579004);DIR:OUT;SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AwmeWF5xYgUQ4s8nRezK/tdC0P68uo9f3mfPd0loZNtkyEs3u730O3zveotP0W1cDb+AofuNavdy39peHWEUb8dHyFFGwQku0FGXWbIDIt90AJspIITCbAm/Psx1MIyZk/FXqlO+VdZur1P9KpK/fjAmcRl+Qg6nigRJ4+gsd7TLolRFWSpAX17l4dWlgbFChT77khpX42E8TR24XdShqgs3TkxGTYV51IQAJQPd9XvGgtA5WtLUww8gyevUq4n3u3q7fHnIZ1t7VMbTpz0EnQwURev0p+942jVr4bhAzkJis+KyAaVX8wFb9halvNzMNjAud2naREsFwzfjTKsDkjwdsVmwua5jMwLpaaWdgnHX5D6I1k4wcaHN/spEpReYQyozWToCx5bZl3ztYDZ/NbUKumSeR/vULjw20Zs5bT8r5uvcVjgVG7hnAseBKgpKnDNRyLgNGipw4wpy19rNVW1X8wJfE+9hofVeWefbY7Ufk6BRu/4ATi4yYQA0Bpt4fRhWllApe4vCD+N2eyJ23Q== x-ms-exchange-antispam-messagedata: EGkndSPRYQa7RHsWXViIiRAFBlWoCo8qcT95p9mcacuoqjXKdvnkAJDdaWRPXf38yZfI6212MUxNBVVXOf/jXxAKdpWifXVtXLq4Ci4dQXSgn3vNUpNY9N2TmKn+RIcdgxKwvHWv32jEA8Y1scAF9g== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 4e236a43-f8c1-4a24-70d3-08d7e3eb88d7 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2020 22:55:04.7095 (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: M9GuEzPLbsN29LkW4zMY+O92gn7w5kWeJVGZMlx5JkUyj1XoQX11XSyeBdCBcuORKd+yJGWsbxfud27D0uf5ABvaLEZkwuiDP/Sg5lbthCk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR11MB2961 Return-Path: nathaniel.l.desimone@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Miki, In AslUpdateLib.h you have cases of "EFIAPI EFI_STATUS" it should be "EFI_S= TATUS EFIAPI". Please update. Thanks, Nate=20 -----Original Message----- From: Shindo, Miki =20 Sent: Monday, April 6, 2020 12:29 AM To: devel@edk2.groups.io Cc: Chaganty, Rangasai V ; Chiu, Chasel ; Desimone, Nathaniel L = ; Agyeman, Prince ; Ni, Ray Subject: [edk2-platforms:PATCH v3] IntelSiliconPkg/DxeAslUpdateLib: Add Dxe= AslUpdateLib 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 Reviewed-by: Ray Ni --- Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.c = | 512 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h = | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 4 ++++ Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf = | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 664 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..4e031b0edd --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Library/DxeAslUpdateLib/DxeAslUpdate +++ Lib.c @@ -0,0 +1,512 @@ +/** @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 + + @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. +**/ +EFIAPI +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=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] 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. +**/ +EFIAPI +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=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. +**/ +EFIAPI +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=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 + @param[in, out] Version - The version of the table desired + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFIAPI +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; +} diff --git a/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h b= /Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h new file mode 100644 index 0000000000..c9699e59b6 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/AslUpdateLib.h @@ -0,0 +1,106 @@ +/** @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. +**/ +EFIAPI +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. +**/ +EFIAPI +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. +**/ +EFIAPI +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=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 + @param[in, out] Version On input, the version of the table= desired, + on output, the versions the table = belongs to + @see AcpiSupport protocol for=20 + details + + @retval EFI_SUCCESS The function completed successfull= y. +**/ +EFIAPI +EFI_STATUS +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 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 # =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