From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.113]) by mx.groups.io with SMTP id smtpd.web12.5463.1622023909964489313 for ; Wed, 26 May 2021 03:11:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=qhcLi2uS; spf=pass (domain: os.amperecomputing.com, ip: 40.107.93.113, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZkuVHjSNwBrdq1N1avuDxyzP2iu1nvSubwWvnFureIGOqI5ahxwtlRD/KAJ5bFO9YsJPIk/jePQWWbtSgUKgWDo36UMGozwHr4ryCsu2fg/xB7iKsHfA0T9dhXpd+YHes+lIdP30qilgUGon74F0hhf3IvmxefkKkRkB3vgnbApB4fPjKfKPdWNv8TYTPUuXb2Q4oG5OtkvzkC09ZnwyslmGFIf+FFifx8XMR+wYllqinAiF6SvE6C9D2hnHgOMKRO3GpwTMdVUAbsfSNcbbiS+iIb3TKiwd3M5R0pzmID+/2O8KJ4E7g82qpCYbrP2CiasWh3lGYgFKSanBciCTIA== 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=Hw3tMsDRB24GlKwEpmXwlxHjBtTBIzkbgtXAKNxhCIY=; b=TsTbF3waPUfediHutMT9BQ4Ac0aI4SUScrYkbzg5jgt9lbbVj+CRIvBSIGL6n9N0FG+9hcs9ZbgE+th4arNTUbMVh0jW/ZewQ53RC/oRz7BYhrCmtMOyKlBPJ0bILh3Hs1Sc6stqDPiV+Kw8x+DqXUdLhK9qiITbUE5Yxk/rP4aWQhr5IFSY1cJE1FBd5f+FpFRENiym2QN3trY0j6LDz5CG53XNVOSHh25SMCx6h8DLQs523j35Rt7ACSszxV4M1hlzHL7psDG+3Ba58iwem4jKHZMWoX5bJ3uSKUOgOczc+WHy02PO18TtvhkxbCJII2UMIUM7R8el1QGYAiAKNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hw3tMsDRB24GlKwEpmXwlxHjBtTBIzkbgtXAKNxhCIY=; b=qhcLi2uSAZwcUcG8MfzE1vSoWXVlL+5q1mX9RzkDe2xJSr88Si4LvPqEo/Jk/HteTs8wj2NMWzxYjvTaG7oUpSqV+2n4TLtKY5jEogghpDU1UdwnR62N9hjin40Dif5bbN+6TlJOs2M2MwoW2sES5Tjf2zIpWaDsZ0Hu/WDbYvY= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR0101MB3067.prod.exchangelabs.com (2603:10b6:4:31::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 26 May 2021 10:11:47 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd%7]) with mapi id 15.20.4173.020; Wed, 26 May 2021 10:11:47 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: Nhi Pham , Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v2 12/32] AmperePlatformPkg: Add AcpiHelperLib to update ACPI DSDT table Date: Wed, 26 May 2021 17:07:04 +0700 Message-ID: <20210526100724.5359-14-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526100724.5359-1-nhi@os.amperecomputing.com> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 26 May 2021 10:11:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f3ea8a0-fdd1-4223-28dc-08d9202eabc8 X-MS-TrafficTypeDiagnostic: DM5PR0101MB3067: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VpzY8VhDzY3VmMCoaEjkAkNVzOKNYEC4q8yo8Eu384L000omye81iVTm4QFNChXwv7+UlRn/TIySUehOOwQ3po2+9G5MkuFV6IZy+AiW0ov0uuyDMlgwGgz/G72nA4pNNy6bBXX4aCNuN0Nf1/F81XCuUrNJ8rzVTCjpeVjoYu4uaav9YPkPcnUASfT70+eVRLnA5/gnLLj5JRSeS0TAucNwCs+rzUjGbZi0pQV3BZo+2iNKfjSQDdMldQ3RHWB/QpcqkOs7SvYQ0oVVs4DQIkypTPrJUvfa/9ZchHr+ECJcVJnicB17zQzLf52KWquhkMrXwx8itUxhXIX/WjsrbWrGGPjB445RKJ+GRgjjjulR4vLZMPMIl5zGGshYHCg3dC0gycNe/BNBlzHPg19z3lCKH2E0eDI4AZUK9lc/wPRb47uwuZFNyZQ9xZ9pY49FoW/yrKyTa0HYc8sv55PNiujz+XpuqzaX2embOTJCI+7Wf3QsYy8oYc2CZ99EoSSIBHzvFjZXqqULSWwFH/AbyEBBfOFoWyjZah/DCO1ztjzW7vTpcVgGNcocAFUMgwovUiZIkZ2sjxXPV2LWgzRg+nNI5o7O3DhJXKk1gv/LNwfffGNNziA6JxnSfe5awyx3ym5/hCNfFTlOPK2/GMWuEVnx5oyu0tmiCxKyBfa7sytVV5MCmcoCFY2/6FHY7ByC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39840400004)(346002)(136003)(376002)(366004)(4326008)(26005)(6666004)(1076003)(2616005)(38350700002)(15650500001)(6506007)(83380400001)(86362001)(2906002)(6486002)(8676002)(30864003)(956004)(52116002)(8936002)(186003)(54906003)(66556008)(6916009)(66476007)(6512007)(66946007)(38100700002)(5660300002)(16526019)(478600001)(316002)(69590400013);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?yC2i3tQVL96NQb5eZn1h8iQXQAN3jmsBtI+DxJe79/gnaQ1DKl9vuqApDmGN?= =?us-ascii?Q?eg9czUbLqFLA8KPIf/I+3yEqsHqIMQvzuqtu5qrsGv7cLXug5XBS8h2avJdV?= =?us-ascii?Q?HvYtAyuZucqkvuLZ/PdIdvbdQjYyTjxEPIqZy9oQ2wtj2TxEtmZfyghJjr4l?= =?us-ascii?Q?OcEfajIEc7GFbeLdF0yxtE7VKyfLJx5Oiw61gBy2DOCgHLsmlfa4j2shxyz9?= =?us-ascii?Q?8OOSwo0KFJ6P1m+9oLJUSyCkTFX4ALigC79qk77vAK0fMdJE/kxmvr2BLgUU?= =?us-ascii?Q?buqYV4LEgEqKNobE1Lp79UtQlx3rGm7p7KciZQwKwn/Gc37xqSOqaWGU0hWf?= =?us-ascii?Q?2EnjzRLrgzOrwf9Y8QPsQp7zfC9YSNiAFRLpp3tIbMyUDnZK28cU8DaCOdZ5?= =?us-ascii?Q?rJ1dyEjNnDohozCd0v4D4g+2iKBs5ZcCDWIe4sJ4NyWZPzDfk840XH1LwJXG?= =?us-ascii?Q?sialLwTCoSii/+urXLH962YINE/V1/uJFKPpUAviLKvT/UNFrTEBsi98wfOA?= =?us-ascii?Q?+x/jltTS09Kd+9IQJOebLxafnHl8wbnaMaykuPGaLfXhoHfjQAmR2TRjqJFr?= =?us-ascii?Q?StkIAEHkv9SBFoNGqF7en3L4yoy6P6Oc6wI5a7aD3nUEd60Ko/8a4bUPa+XN?= =?us-ascii?Q?0Am/4Tv1sBhNHhXdNTnBfHpX/izwqxduLpw1dVGYGw3inzeaOtbjvKarBkMM?= =?us-ascii?Q?MueO+u28xARG3Ugt4Pk6NIDEmOHUQ7wkeIvvDUZx4c9ftaXy1N96nadAdMN4?= =?us-ascii?Q?4X+zNpWGYDe0pljcSe3/mdZUDfRXrXA1bLV3NcFnBHyksiA2sswHt1AqwATC?= =?us-ascii?Q?4BCnLsh/+NJv46WUilxnO2OPe+GmH6Ok9eKvm7dAkRwGnsFd/cZzXMrBlOj6?= =?us-ascii?Q?yz4PMSXI6e6n2FapeH2KfrsVUYW0TfLZvqj51pDVnKMziOX+o18f3VqiGodn?= =?us-ascii?Q?6mQx6X0PnHZ3ai+1k2WF1IZoX7WPdW1mBUf+e0/n1hLyINTI2eb0AkeQbbjN?= =?us-ascii?Q?4Dh4U7otaWCosgC+Z4tSzRtvXMDWAdvtcG6I4Dxmz+9sTftMPhUOCPyFl2/L?= =?us-ascii?Q?Zg0daglvBjT93gxTyxS49WsI2C2jWYM6keUJ2icQCBc6CVUl0IbVYYxBgvsS?= =?us-ascii?Q?463dn37qz0P375SehwAa71GpKScHsHi/navZMt8QgrOLvcp+46EY/eYSYxwD?= =?us-ascii?Q?0+dDsb/xrDCxV6UlaU3XnCY6Mk50ySeD6UA1/N3Ga1fpbEIknW96X8BvVOjZ?= =?us-ascii?Q?AdjvAJtS9Tyzb0VJ++e6rRkDLGIK4Ipi917L/oG9eWEQfmO7JmW04tUKaF1a?= =?us-ascii?Q?35GmbrC7iqvV8goPI4n8n/1I?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f3ea8a0-fdd1-4223-28dc-08d9202eabc8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 10:11:47.5979 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EpOfDdJldHDSQRRY6q3+1Sw1TFC8BEkCwTT6hKDRjYC7wOAj5Wtuc4foTJMDvAJDCz4iVnedDr9rGZ1VhG55Pfgkx3vY39cMfPyWviPOn88= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0101MB3067 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain The AcpiHelperLib provides functions to update the ACPI DSDT table after this table is installed. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Nhi Pham --- Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec = | 3 + Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHelperLib.inf = | 33 +++ Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiHelperLib.h = | 109 +++++++++ Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHelperLib.c = | 246 ++++++++++++++++++++ 4 files changed, 391 insertions(+) diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon= /Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec index 8193ff617600..0ac075047276 100755 --- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec +++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec @@ -28,6 +28,9 @@ [LibraryClasses] ## @libraryclass Provides functions to create the ACPI PCCT Table whic= h which advertises PCC mailbox channel information. AcpiPccLib|Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h =20 + ## @libraryclass Provides helper functions to update ACPI DSDT Table. + AcpiHelperLib|Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiHelper= Lib.h + [Guids] gAmpereTokenSpaceGuid =3D { 0xdbd4436e, 0x89cb, 0x44dc, { 0xb5, 0xc0, 0x= 49, 0xc3, 0x91, 0x35, 0xbf, 0xdf } } =20 diff --git a/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHe= lperLib.inf b/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiH= elperLib.inf new file mode 100755 index 000000000000..df26a2810bd3 --- /dev/null +++ b/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHelperLib= .inf @@ -0,0 +1,33 @@ +## @file +# +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D AcpiHelperLib + FILE_GUID =3D E4F89216-E722-11E6-BF01-FE55135034F3 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D AcpiHelperLib + +[Sources] + AcpiHelperLib.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + UefiBootServicesTableLib + UefiLib + +[Protocols] + gEfiAcpiSdtProtocolGuid ## COMSUMED diff --git a/Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiHelperLib.= h b/Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiHelperLib.h new file mode 100644 index 000000000000..f98118a0f6a2 --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiHelperLib.h @@ -0,0 +1,109 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef ACPIHELPERLIB_H_ +#define ACPIHELPERLIB_H_ + +#include + +#include + +#define MAX_ACPI_NODE_PATH 256 + + +typedef struct { + EFI_ACPI_SDT_HEADER *Table; + EFI_ACPI_TABLE_VERSION TableVersion; + UINTN TableKey; +} ACPI_TABLE_DESCRIPTOR; + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + +**/ +VOID +EFIAPI +AcpiTableChecksum ( + IN UINT8 *Buffer, + IN UINTN Size + ); + +/** + This function calculates and updates the ACPI DSDT checksum. + + @param[in] AcpiTableProtocol Pointer to ACPI table protocol + +**/ +VOID +EFIAPI +AcpiDSDTUpdateChecksum ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol + ); + +/** + This function update the _STA value of a ACPI DSDT node. + + @param[in] AsciiNodePath Pointer to the path of the node. + @param[in] NodeStatus The status value needed to be updated= . + +**/ +EFI_STATUS +EFIAPI +AcpiDSDTSetNodeStatusValue ( + IN CHAR8 *AsciiNodePath, + IN CHAR8 NodeStatus + ); + +/** + This function return the handle of the ACPI DSDT table. + + @param[in] AcpiTableProtocol Pointer to ACPI table protocol. + @param[out] TableHandle Pointer to table handle. + +**/ +EFI_STATUS +EFIAPI +AcpiOpenDSDT ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol, + OUT EFI_ACPI_HANDLE *TableHandle + ); + +/** + This function return the ACPI table matching a signature. + + @param[in] TableDescriptor Pointer to ACPI table descriptor. + @param[in] TableSignature ACPI table signature. + +**/ +EFI_STATUS +EFIAPI +AcpiGetTable ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableSdtProtocol, + IN UINT32 TableSignature, + OUT ACPI_TABLE_DESCRIPTOR *TableDescriptor + ); + +/** + Check whether the ACPI table is installed or not. + + @param[in] AcpiTableSignature ACPI table signature. + + @retval TRUE Already installed. + @retval FALSE Not installed. + +**/ +BOOLEAN +EFIAPI +IsAcpiInstalled ( + IN UINT32 AcpiTableSignature + ); + +#endif /* ACPIHELPERLIB_H_ */ diff --git a/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHe= lperLib.c b/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHel= perLib.c new file mode 100644 index 000000000000..4a85dd5dc8c5 --- /dev/null +++ b/Platform/Ampere/AmperePlatformPkg/Library/AcpiHelperLib/AcpiHelperLib= .c @@ -0,0 +1,246 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DSDT_SIGNATURE 0x54445344 +#define FADT_SIGNATURE 0x50434146 + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + +**/ +VOID +EFIAPI +AcpiTableChecksum ( + IN UINT8 *Buffer, + IN UINTN Size + ) +{ + UINTN ChecksumOffset; + + ASSERT (Buffer !=3D NULL); + + ChecksumOffset =3D OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum); + + /* + * Set checksum to 0 first. + */ + Buffer[ChecksumOffset] =3D 0; + + /* + * Update checksum value. + */ + Buffer[ChecksumOffset] =3D 0 - CalculateSum8 (Buffer, Size); +} + +/** + This function calculates and updates the ACPI DSDT checksum. + + @param[in] AcpiTableProtocol Pointer to ACPI table protocol + +**/ +VOID +EFIAPI +AcpiDSDTUpdateChecksum ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + EFI_ACPI_SDT_HEADER *DsdtHdr =3D NULL; + ACPI_TABLE_DESCRIPTOR TableDescriptor; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr =3D NULL; + + ASSERT (AcpiTableProtocol !=3D NULL); + + Status =3D AcpiGetTable (AcpiTableProtocol, FADT_SIGNATURE, &TableDescri= ptor); + if (EFI_ERROR (Status) || TableDescriptor.Table =3D=3D NULL) { + return; + } + + FadtPtr =3D (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *)TableDescriptor= .Table; + + if (FadtPtr->Dsdt) { + DsdtHdr =3D (EFI_ACPI_SDT_HEADER *)(UINT64)FadtPtr->Dsdt; + } else if (FadtPtr->XDsdt) { + DsdtHdr =3D (EFI_ACPI_SDT_HEADER *)FadtPtr->XDsdt; + } + + if (DsdtHdr !=3D NULL) { + AcpiTableChecksum ((UINT8 *)DsdtHdr, DsdtHdr->Length); + } +} + +/** + This function return the handle of the ACPI DSDT table. + + @param[in] AcpiTableProtocol Pointer to ACPI table protocol. + @param[out] TableHandle Pointer to table handle. + +**/ +EFI_STATUS +EFIAPI +AcpiOpenDSDT ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol, + OUT EFI_ACPI_HANDLE *TableHandle + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + ACPI_TABLE_DESCRIPTOR TableDescriptor; + + Status =3D AcpiGetTable (AcpiTableProtocol, DSDT_SIGNATURE, &TableDescri= ptor); + if (!EFI_ERROR (Status) && (TableDescriptor.Table !=3D NULL)) { + return AcpiTableProtocol->OpenSdt (TableDescriptor.TableKey, TableHand= le); + } + + return Status; +} + +EFI_STATUS +EFIAPI +AcpiDSDTSetNodeStatusValue ( + IN CHAR8 *AsciiNodePath, + IN CHAR8 NodeStatus + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol; + EFI_ACPI_HANDLE TableHandle; + EFI_ACPI_HANDLE ChildHandle; + EFI_ACPI_DATA_TYPE DataType; + CHAR8 *Buffer; + UINTN DataSize; + + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **= )&AcpiTableProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to locate ACPI table protocol\n")); + return Status; + } + + /* Open DSDT Table */ + Status =3D AcpiOpenDSDT (AcpiTableProtocol, &TableHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D AcpiTableProtocol->FindPath (TableHandle, AsciiNodePath, &Chi= ldHandle); + if (EFI_ERROR (Status)) { + /* Close DSDT Table */ + AcpiTableProtocol->Close (TableHandle); + return EFI_SUCCESS; + } + + Status =3D AcpiTableProtocol->GetOption (ChildHandle, 2, &DataType, (VOI= D *)&Buffer, &DataSize); + if (Status =3D=3D EFI_SUCCESS && Buffer[2] =3D=3D AML_BYTE_PREFIX) { + /* + * Only patch when the initial value is byte object. + */ + Buffer[3] =3D NodeStatus; + } + + /* Close DSDT Table */ + AcpiTableProtocol->Close (TableHandle); + + /* Update DSDT Checksum */ + AcpiDSDTUpdateChecksum (AcpiTableProtocol); + + return EFI_SUCCESS; +} + +/** + This function return the ACPI table matching a signature. + + @param[in] AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param[in] TableSignature ACPI table signature. + @param[out] TableDescriptor Pointer to ACPI table descriptor. + +**/ +EFI_STATUS +EFIAPI +AcpiGetTable ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiTableSdtProtocol, + IN UINT32 TableSignature, + OUT ACPI_TABLE_DESCRIPTOR *TableDescriptor + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + UINTN TableIndex =3D 0; + + ASSERT (AcpiTableSdtProtocol !=3D NULL); + ASSERT (TableDescriptor !=3D NULL); + + /* + * Search for ACPI Table Signature + */ + while (!EFI_ERROR (Status)) { + Status =3D AcpiTableSdtProtocol->GetAcpiTable ( + TableIndex, + &(TableDescriptor->Table), + &(TableDescriptor->TableVersion), + &(TableDescriptor->TableKey) + ); + if (!EFI_ERROR (Status)) { + TableIndex++; + + if (((EFI_ACPI_SDT_HEADER *)TableDescriptor->Table)->Signature =3D= =3D TableSignature) { + return EFI_SUCCESS; + } + } + } + + /* Nothing was found. Clear the table descriptor. */ + ZeroMem (&TableDescriptor, sizeof (TableDescriptor)); + + return EFI_NOT_FOUND; +} + +/** + Check whether the ACPI table is installed or not. + + @param[in] AcpiTableSignature ACPI table signature. + + @retval TRUE Already installed. + @retval FALSE Not installed. + +**/ +BOOLEAN +EFIAPI +IsAcpiInstalled ( + IN UINT32 AcpiTableSignature + ) +{ + EFI_STATUS Status; + ACPI_TABLE_DESCRIPTOR TableDescriptor; + EFI_ACPI_SDT_PROTOCOL *AcpiTableSdtProtocol =3D NULL; + + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **= )&AcpiTableSdtProtocol); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D AcpiGetTable (AcpiTableSdtProtocol, AcpiTableSignature, &Tabl= eDescriptor); + if (!EFI_ERROR (Status) && (TableDescriptor.Table !=3D NULL)) { + return TRUE; + } + + return FALSE; +} --=20 2.17.1