From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.113]) by mx.groups.io with SMTP id smtpd.web11.4123.1607505862036673049 for ; Wed, 09 Dec 2020 01:24:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=CDK+BYx3; spf=pass (domain: os.amperecomputing.com, ip: 40.107.220.113, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l0b39j1SIPULHPB6ZcH1xE6GjMGNEBeTEjVsySovZ3loh6u7VH8zIqXDVXBIvLkLX8OrlghIXiuAEBoRUynKiDEHjaUtxG4GTQ28aAZphPppEQ36qiKPSOnd30kAIqLW1T7pMKU4DN7suOCgbpeldGK6mv6uOfNF2ItrLVGdOXBUCpWaJ7pQsy2TV8RMtqz1W3/seJry6dTU7OaocL2xJeCR/WHiPU4BgQBXbGdj439tbGDeAT/Pfkv3BfFRtgE8YqnTfFpgC/O8bHPn/9qfM6z/YoLbxND4EfIjma3zUp/fX4VlGILdPdzhrIbQRSm3Ks4p9NtZsMKCzvREc6jXgQ== 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=a1khfVk8YCAUD7VgpRy7wUzN1714F8tl9A+ndx+y0yA=; b=VwpSw1rKrsP83Jtn3DndZYdQ4v7nP7aALFiPHxSJWJqOpEAhMxm9rKG4ingSj5rXYu9tsOG9l5SDsB6zif36BOp+uNxoxYa4Ys5DqNt5jjgbV7X1fWNKfaheWYOleQyD2DrhMHmHARHSDLkUzP5tmLsI8vhDOzyNBqucQwXON0A37MuEthV+0m8chpXS8nupr/zEaMHQZP3CKtSruSdzINqMtgyjeRsQBWD1iaK9TIYrNgKxTBJKiiSa68yYIo4CS7LRD28TmM1vhbHcatebNcgyiF7TTn83jxFXJ9YjXwjKclAPpsYM62jw6niGAWS0jdesL3YB99i6AkBAkOoWwA== 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=a1khfVk8YCAUD7VgpRy7wUzN1714F8tl9A+ndx+y0yA=; b=CDK+BYx3FFRDJgfLZBulnpLZK2fIQwK7dJHKap6Si3gvvTLcsEFVgMtYa3FexXYDhfe06QXWlRIKZosKhdzKCr6q4w7myQST9rpp3kzNwuZpwyJJ4OMTvDF06K+8Wibj0+lL546yWmW5R88kt74Bt5gEToLgNiQaFu9Up3ZzVws= 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 DM6PR01MB5609.prod.exchangelabs.com (2603:10b6:5:157::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Wed, 9 Dec 2020 09:24:21 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3632.023; Wed, 9 Dec 2020 09:24:21 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham Subject: [edk2-platforms][PATCH 07/34] Platform/Ampere: Add AcpiHelperLib to update ACPI DSDT table Date: Wed, 9 Dec 2020 16:25:04 +0700 Message-Id: <20201209092531.30867-8-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201209092531.30867-1-nhi@os.amperecomputing.com> References: <20201209092531.30867-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::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 sw004.amperecomputing.com (118.69.219.201) by HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Wed, 9 Dec 2020 09:24:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d744cf3a-67e5-4a3c-7a68-08d89c2435e7 X-MS-TrafficTypeDiagnostic: DM6PR01MB5609: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3vO+TFEAnZoj0dKzZDsYDawXI/1caPaPs+KIag+7ElX00TBIakoR3+/CiHcB9REMJI5KKPGuP1uQZwn6E1iQcG4PPl19ivFplETXZqmzhlagUN9r9ZYlKMJcMAFvh3tq68KZ2AlpXsB679gAJQFYI5ht9OG01LrbF8GY/j73k6wSXa0cHE+mE1DdbJnE20tZi2QQ5P2zqn8kwOlQYYm+jxaz+D8WAjgOpuE4kZkt3EnSXB1frnvPmORCL0EPIx0F2c7P6bK8kb1+Ip38383slxp6radARiI66KTcjD0lql5MOQyd5j6tT/PsT2aJAttHITc7pk3t84kEUEh/+9F0rM5Mh3gb+mZt55Lt/t4JR7zPK5gJ6MpY1AbtF3bCdiHh 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)(376002)(136003)(346002)(366004)(5660300002)(956004)(508600001)(52116002)(30864003)(66946007)(6916009)(2616005)(1076003)(86362001)(6512007)(66476007)(26005)(8936002)(16526019)(107886003)(6666004)(186003)(6486002)(8676002)(6506007)(83380400001)(2906002)(15650500001)(34490700003)(66556008)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?s3txLjPS/YkjATctU/o5crBKZM+7+pJdmTlwNNbRrgpd1ODsSxg1s2aA9NU0?= =?us-ascii?Q?ucVHe3sfpgM2CT84LzHiskd0A+xVNFF1IuxuzmDYmjTGrknwzvEeOb805GSH?= =?us-ascii?Q?eSYxuSa80wUPtcBjRthfzzWTgw1RjGzLyYv/MwQgaP3KzwkJ7AM/wymC/Rnv?= =?us-ascii?Q?Wxb0lkqLG4bzrF66x0PSa2jNVvlPCi1VEByW3LQM743Up40NpCFEXgt4kqOo?= =?us-ascii?Q?XSLWQy/O1OQIPr5eNxLDzSASP/F1gY6LQXbRpuW9NeDzR5qlwnM7Ay1HJvrF?= =?us-ascii?Q?08qtgo2ue4xUaKTIN4dg+lpyjk1mX2+NPbuuFs79P5G5PuM0cBbe5BcC/CMr?= =?us-ascii?Q?kMKwH7owdI+pXtGKH6LSGdUWJRHjSe09+GiI/IXbyT95BAB2SQuF9+MJIADP?= =?us-ascii?Q?WR4zh1WxS8a6rTAEN2hpG1UWT4hr4T2neCgTN7eT9/veHyEu4HwmxGED399g?= =?us-ascii?Q?uZ7ze7xR6+S/tHXl+tx+d4piSYcQAC3HG5pCQ440Xb4KixhK7ql4e0qfn2gd?= =?us-ascii?Q?KAzIfXurSb8WjakS16HLfFqIlfT+vtdEggSv94GHjRgBzxEASVURxsLu1VaN?= =?us-ascii?Q?YjjivjeOSQQQibfz/nIwlesxRIgdabaCd+SvHwwoORn1lmOPu2K6WGhY5U48?= =?us-ascii?Q?bVlt8BtvY/x+udEsQr3KH4OupCyuJ/SClnP/dLp0Dfw2djuNn9/Mm2S2n32M?= =?us-ascii?Q?I6bRd6XWWnvBkjE0BtBlWDSCsiIF8zAP+AiscYo1c8YhxY48SnotnWPKUXPO?= =?us-ascii?Q?8fbIuBY4EsO3LZ5qQ139FNaJs/UQQ0WOGBTwALvuxq6RTU75f87mY1DhCrtO?= =?us-ascii?Q?cwTs7I3xQQ4WirpXq/QkSAbGV+W/KWVJ/J9Q35gCbkNaPAyz69ZuXj9JuSiB?= =?us-ascii?Q?BMYBHyBKZbFD808m36dP/KsSB3Bym6kVrIRxPaP5zRqVB7ofRylF50RAsk18?= =?us-ascii?Q?FWEw7+/wQcuLhPrWu2OPqNveQ9iH6FPgPqIOqjugZ0DTuv3xOk3QeQ4ooOHe?= =?us-ascii?Q?9RnI?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2020 09:24:20.8904 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: d744cf3a-67e5-4a3c-7a68-08d89c2435e7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: e6RyM3PYlj8/LLF9C+aF5uB1cmwi8mI0XCAUwxrQgcZc5ArTJOgFuFz8EBZOZi+OCRC1ylev1TEe0m6RE7uKUHIrhSyzn8NKsLRCMqLjXDM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5609 Content-Type: text/plain The AcpiHelperLib provides functions to update the ACPI DSDT table after the table is installed. Signed-off-by: Nhi Pham --- Silicon/Ampere/AmperePkg.dec | 2 + Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.inf | 33 +++ Silicon/Ampere/Include/Library/AcpiHelperLib.h | 109 +++++++++ Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.c | 247 ++++++++++++++++++++ 4 files changed, 391 insertions(+) diff --git a/Silicon/Ampere/AmperePkg.dec b/Silicon/Ampere/AmperePkg.dec index fa5b7074f749..3d6ddfb39b97 100755 --- a/Silicon/Ampere/AmperePkg.dec +++ b/Silicon/Ampere/AmperePkg.dec @@ -28,6 +28,8 @@ [LibraryClasses] ## @libraryclass Provides functions to create the ACPI PCCT Table which which advertises PCC mailbox channel information. AcpiPccLib|Silicon/Ampere/Include/Library/AcpiPccLib.h + ## @libraryclass Provides helper functions to update ACPI DSDT Table. + AcpiHelperLib|Silicon/Ampere/Include/Library/AcpiHelperLib.h [Guids] gAmpereTokenSpaceGuid = { 0xdbd4436e, 0x89cb, 0x44dc, { 0xb5, 0xc0, 0x49, 0xc3, 0x91, 0x35, 0xbf, 0xdf } } diff --git a/Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.inf b/Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.inf new file mode 100755 index 000000000000..acf14623d87c --- /dev/null +++ b/Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.inf @@ -0,0 +1,33 @@ +## @file +# +# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = AcpiHelperLib + FILE_GUID = E4F89216-E722-11E6-BF01-FE55135034F3 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = AcpiHelperLib + +[Sources] + AcpiHelperLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Silicon/Ampere/AmperePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + UefiBootServicesTableLib + UefiLib + DebugLib + +[Protocols] + gEfiAcpiSdtProtocolGuid ## COMSUMED diff --git a/Silicon/Ampere/Include/Library/AcpiHelperLib.h b/Silicon/Ampere/Include/Library/AcpiHelperLib.h new file mode 100644 index 000000000000..9ab13c4b0714 --- /dev/null +++ b/Silicon/Ampere/Include/Library/AcpiHelperLib.h @@ -0,0 +1,109 @@ +/** @file + + Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _ACPIHELPERLIB_H_ +#define _ACPIHELPERLIB_H_ + +#include +#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/Library/AcpiHelperLib/AcpiHelperLib.c b/Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.c new file mode 100755 index 000000000000..9baf44272a30 --- /dev/null +++ b/Platform/Ampere/Library/AcpiHelperLib/AcpiHelperLib.c @@ -0,0 +1,247 @@ +/** @file + + Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#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 != NULL); + + ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum); + + /* + * Set checksum to 0 first. + */ + Buffer[ChecksumOffset] = 0; + + /* + * Update checksum value. + */ + Buffer[ChecksumOffset] = 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 = EFI_SUCCESS; + EFI_ACPI_SDT_HEADER *DsdtHdr = NULL; + ACPI_TABLE_DESCRIPTOR TableDescriptor; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr = NULL; + + ASSERT (AcpiTableProtocol != NULL); + + Status = AcpiGetTable (AcpiTableProtocol, FADT_SIGNATURE, &TableDescriptor); + if (EFI_ERROR (Status) || TableDescriptor.Table == NULL) { + return; + } + + FadtPtr = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) TableDescriptor.Table; + + if (FadtPtr->Dsdt) { + DsdtHdr = (EFI_ACPI_SDT_HEADER *)(UINT64) FadtPtr->Dsdt; + } else if (FadtPtr->XDsdt) { + DsdtHdr = (EFI_ACPI_SDT_HEADER *) FadtPtr->XDsdt; + } + + if (DsdtHdr != 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 = EFI_SUCCESS; + ACPI_TABLE_DESCRIPTOR TableDescriptor; + + Status = AcpiGetTable (AcpiTableProtocol, DSDT_SIGNATURE, &TableDescriptor); + if (!EFI_ERROR (Status) && (TableDescriptor.Table != NULL)) { + return AcpiTableProtocol->OpenSdt (TableDescriptor.TableKey, TableHandle); + } + + return Status; +} + +EFI_STATUS +EFIAPI +AcpiDSDTSetNodeStatusValue ( + IN CHAR8 *AsciiNodePath, + IN CHAR8 NodeStatus + ) +{ + EFI_STATUS Status = 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 = 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 = AcpiOpenDSDT (AcpiTableProtocol, &TableHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = AcpiTableProtocol->FindPath (TableHandle, AsciiNodePath, &ChildHandle); + if (EFI_ERROR (Status)) { + /* Close DSDT Table */ + AcpiTableProtocol->Close (TableHandle); + return EFI_SUCCESS; + } + + Status = AcpiTableProtocol->GetOption (ChildHandle, 2, &DataType, (VOID *) &Buffer, &DataSize); + if (Status == EFI_SUCCESS && Buffer[2] == AML_BYTE_PREFIX) { + /* + * Only patch when the initial value is byte object. + */ + Buffer[3] = 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 = EFI_SUCCESS; + UINTN TableIndex = 0; + + ASSERT (AcpiTableSdtProtocol != NULL); + ASSERT (TableDescriptor != NULL); + + /* + * Search for ACPI Table Signature + */ + while (!EFI_ERROR (Status)) { + Status = AcpiTableSdtProtocol->GetAcpiTable ( + TableIndex, + &(TableDescriptor->Table), + &(TableDescriptor->TableVersion), + &(TableDescriptor->TableKey) + ); + if (!EFI_ERROR (Status)) { + TableIndex++; + + if (((EFI_ACPI_SDT_HEADER *)TableDescriptor->Table)->Signature == 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 = NULL; + + Status = gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableSdtProtocol); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = AcpiGetTable (AcpiTableSdtProtocol, AcpiTableSignature, &TableDescriptor); + if (!EFI_ERROR (Status) && (TableDescriptor.Table != NULL)) { + return TRUE; + } + + return FALSE; +} -- 2.17.1