From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.120]) by mx.groups.io with SMTP id smtpd.web10.14887.1631121144270191910 for ; Wed, 08 Sep 2021 10:12:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=XqD7OvD5; spf=pass (domain: os.amperecomputing.com, ip: 40.107.212.120, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhNVgyCjYWwZ2Ugz2KjIaw8eVyqAzrXBjk1+LSM6VHwQ8DUjokwr/wmcAdQRVJHxkrmWrBDAAnlrqr+1+7g7yMtyAo8qUl/SO2qK3sdnZCurHAEZ/5rcUrjKT1/mrodiRSHw8D8+91pSDOLfyNbOUQc5R9/6iJMdNzQX3v730jHf+3cOzR1fudLACphf37nhWMLd/3Q83k+NY32hvAR38E0AaHnH+ugkCVBNBbuVmjCRjVc8hNDOHr3cJ9Q7XYh2tB/UsHwZ4wdoslHnPyq4BTPT58h/GPZM7mfO3X7kePl5gpUrNCF7ZwjjLDhtvnmCMmgMfPUm0gOr3R/a9nof8g== 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; bh=VoY6roV4y/dcv6XupSxzxxI30Eeh/WtE809s7+H19QI=; b=VdJalwcq8ThZqB/bCYG2bGfkudJrWSGXZMyfg53FIKQqMoySubdxcM+woBP4zCkWLDWAc0ffzeoEjuhUDQs0wf0Xsc7BOGfwS3Aj9HilokylJayWpWpYnDtaumEwtwV8E7eor4AxQ/eRBjPKMtp/P2v2slHgHtWRS1K8SGA5vC4L1tQhVzV8qxY4rJJZ+g+WIeI77gzwD9uPkwpl5yDFz5BHc9hI3jm8w9d0ZMea1eDb3gNhVptx7lACBUiZgtCEcZc3v6pRVEMl8kSi4tYmjRh0lHMnYhsg15BtiiR3hy77J0dAhqMOlGbLgObpnMqqPZdEwIAF3y8vjyTDPTOktg== 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=VoY6roV4y/dcv6XupSxzxxI30Eeh/WtE809s7+H19QI=; b=XqD7OvD5MgCJPIVhJsLtQ+d1hmXGaZipuv8162xb+uXCQABwQztZV5L1JhH/zRs7Berxl2GQ0MN1thiRTv+tRK1TlJGcicOXfx4QgCF1eak86zLMh8jfb8gD/LN9GxqxAtKOY8LuPOm/Bs0NiRN27OM1qQVCuVqhwj7RIpQNWWg= 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 DM6PR01MB5514.prod.exchangelabs.com (2603:10b6:5:17b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.22; Wed, 8 Sep 2021 17:12:21 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3%4]) with mapi id 15.20.4500.015; Wed, 8 Sep 2021 17:12:21 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: patches@amperecomputing.com, leif@nuviainc.com, abner.chang@hpe.com, Nhi Pham , Ard Biesheuvel , Daniel Schaefer Subject: [PATCH v3 1/1] EmbeddedPkg/AcpiLib: Add more helper functions Date: Thu, 9 Sep 2021 00:10:26 +0700 Message-Id: <20210908171026.26530-1-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: HKAPR04CA0002.apcprd04.prod.outlook.com (2603:1096:203:d0::12) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from sw004.amperecomputing.com (118.69.219.201) by HKAPR04CA0002.apcprd04.prod.outlook.com (2603:1096:203:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16 via Frontend Transport; Wed, 8 Sep 2021 17:12:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fefbe039-808a-4e8f-a8d5-08d972ebd173 X-MS-TrafficTypeDiagnostic: DM6PR01MB5514: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1284; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a61YpVZWD7OkQS572mFcWOhCX6JQqNsviNi3I+u4dVv0LD2t7QFA+XAlsV9zFDb8lb1KoeeYpP97y/GOCSOXQ95yRLgVIqcKb/0xMOaonCM+xZ31dxWtLnc8a3WyHUHvo1h5ICRMbvQXeVZsoBgDU8SLHEkduTaaZLQOX0KRRHP/j+pMwhHq6dZfzhDuS8hb2kXLVhwl9zUUtMRsM6Zne2PcXiVTEtdbEs6XpbaFg8TvZRwwIrDGCmr9iBJxdNxudxwibNYtiF9r9LMXxUxc0+WFtgv72oqby2zuVh9Wpq3Zx6er35ilcrkisty3hHXBP6ypNXpXdEHKZIgXk1p5oSjih75qkl6udx2f9wD1IwnbY5w3PtJ2D0dpZZnGo18Q4VLNR1pYiT5RT8u6CDYSbipkFoFLo5QP7qPjZesjUon0OC97++XF6ViBZxEIAyVIjBcQd221cugAb7iZ8sWxyY7lNwmHFDQ7EXVu3M1s54ffPFxyczZ4nSmx5GDDqlsCnLsx3rsIUuGpHtBcki+EkL3KxQ10qvISzmZ+TluXehZv/zAoEBiG8VZ7NPQdcSNPGQTAVXpluB5NaniWWcrz1FR6QaP2rpliG5Nc/6OEJwHyTUtDaMbXNPIXalVY0UvHvc+vUVWcD0xlkIZ0zCmCW5u1d8iJnLaKcuyqBs/eSELMGptZ1E6ZJmQqLrefCJ//et5PAoHWL6ZGbh5rIijgLw== 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)(136003)(346002)(396003)(376002)(366004)(39850400004)(6486002)(6506007)(5660300002)(52116002)(8676002)(4326008)(316002)(86362001)(66556008)(26005)(66946007)(6512007)(6666004)(6916009)(66476007)(2906002)(186003)(38350700002)(2616005)(38100700002)(54906003)(8936002)(1076003)(19627235002)(83380400001)(30864003)(478600001)(956004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vcywYrNWA3CCK3NlQDj/NmgVLdn4x1NnoVU2Ojl2ftZ4YbXVQJF3A8LkXsVo?= =?us-ascii?Q?W5+MAqYchW/UJd8gOHiwos3oAOLC4zlNbSNmyRzCy3zBEepWy9U6mt8qYeqa?= =?us-ascii?Q?Sz25eh5VOGVqlu1pGtuF5Ok+BxPVjJkMMSrhULT8kD7h15Xkjl3Ar/V87ry+?= =?us-ascii?Q?XBAvNkMjGtCIXG2j3qtsGUiiNwsQ4EPZ6BPf1wsofmodX9fHo9KrxavbWOnt?= =?us-ascii?Q?FsYIs+NJ54zlGG2bIrTDqUADGIyJnkJgn8rSJs0vE6/DoORE5chbpfPgJezM?= =?us-ascii?Q?7fZPfX6jZirj+hT3qtLR9dyMGAAK8ZH58EUc2t02d7dLmQMPf56FIp9ZHFQm?= =?us-ascii?Q?h7MnYGL8mItCr7iwjj1tPUrNeQuFlda6Z9ObKnL16dzKOTkYfWIGuMVCQ0ea?= =?us-ascii?Q?krk03ydwYNaqnknNEd/1HPEfW5uuKra0C68OF9k3i8r5BFB99G9CPRGjLGKX?= =?us-ascii?Q?7wkSvVnr3V2wB64Nlf2BA8Hi7BOx7YTT0rNidBLrt2QpIqKkrcAbArrS9Ut6?= =?us-ascii?Q?G91xhFZp4x2ZwjSnTWjb8NK78mDgrHvaLyMuLpAXn/YgTXhWS0dfW9rGXrub?= =?us-ascii?Q?hFgzGWKFX0m6gmcICWbT+agwbScANETxqcCpxkm2cALI2orDRzxyQcpl+QJm?= =?us-ascii?Q?3s4APDSJnh0iSB7wDL9OkMU6M22CjM6mEhAC0BMKHNVuIE50c2CZPcjGDFQT?= =?us-ascii?Q?TJt9Cy2qSkMxrsuCofTSGmyfKPbra8kCr0o3sHmudNljJW26if/bdr3ONaX9?= =?us-ascii?Q?iWDzMrFycpB1mXLjdGA9vxGfkqvy+yaSaHVwAONyp1xfEQtOsRb1tmUSmgmX?= =?us-ascii?Q?mq4bfFufeTGN/b0F1pqwLa85/gzN12t1YxPsKqXVDxZv5kfa2zm13UA+FgzR?= =?us-ascii?Q?LcK+WjYCduqygYFn00nSGKCgkap9X4OVyrEuk22Xq18x/y6vxNng0YsmBCRO?= =?us-ascii?Q?SOp1r/c3OZnZsAAWWSBgyiOg/bAtQkhNrX46Tik+lCFTTiae7jnuvjATDpls?= =?us-ascii?Q?TFzDUb4HJwixx4LepE4a0OL7If0POol+kKL0A7GFFRIbGrjjpNbyIHcEEnGj?= =?us-ascii?Q?y1am5O8Ma4I/q3MJRU6iJAVgjZM1bYXUgZ8a/JPc5HJJuWYJ6lN2sh7fO9aR?= =?us-ascii?Q?QippxjQkdd0mmOn5eFn1jlhcDPwEN7OCRKItO5bFGC+y/NXw7yWuRRVotKVS?= =?us-ascii?Q?Bi7150aAPBV0+vGP61HF9vS3Xw9dtWZf0m696tm1NBZGNZBblxY1WAGVxKNZ?= =?us-ascii?Q?dZg/SNgUfcLvXChIyndJDZuxO9jiD2/e4rnYkBa3oBGdcmW+JSSTxUON//X4?= =?us-ascii?Q?OQXbLAdykFHGTFJr6Es04e+/?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: fefbe039-808a-4e8f-a8d5-08d972ebd173 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2021 17:12:20.9812 (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: Tubl2J4GrMPFiJpBhhMT4RTCkELw6LACleCY5SNN4UFEFHAd1HqBCpBDDwZ1LRHSqSuHTfX4SMzdnntOvJI7mnj2ySlMPp83BoSjV6RVmeQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5514 Content-Type: text/plain This adds more helper functions that assist in calculating the checksum, locating an ACPI table by signature, and updating an AML integer object. Cc: Ard Biesheuvel Cc: Daniel Schaefer Signed-off-by: Nhi Pham Acked-by: Leif Lindholm Reviewed-by: Abner Chang --- Changes since v2: + Correct the description of the AcpiLocateTableBySignature function. [Abner] Changes since v1: + Add copyright [Abner] + Improve the AcpiLocateTableBySignature function to remove the caution for the usage of SSDT table. [Abner] + AcpiAmlObjectUpdateInteger: Use the AcpiSdtProtocol->SetOption to update the value of data object. [Abner] EmbeddedPkg/Library/AcpiLib/AcpiLib.inf | 3 + EmbeddedPkg/Include/Library/AcpiLib.h | 71 +++++++ EmbeddedPkg/Library/AcpiLib/AcpiLib.c | 216 ++++++++++++++++++++ 3 files changed, 290 insertions(+) diff --git a/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf b/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf index 538fe09cca29..01b12c9423a9 100644 --- a/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf +++ b/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf @@ -1,6 +1,7 @@ #/** @file # # Copyright (c) 2014, ARM Ltd. All rights reserved. +# Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -23,6 +24,8 @@ [Packages] EmbeddedPkg/EmbeddedPkg.dec [LibraryClasses] + BaseLib + BaseMemoryLib DebugLib UefiBootServicesTableLib diff --git a/EmbeddedPkg/Include/Library/AcpiLib.h b/EmbeddedPkg/Include/Library/AcpiLib.h index c142446d9d59..8aef89416a97 100644 --- a/EmbeddedPkg/Include/Library/AcpiLib.h +++ b/EmbeddedPkg/Include/Library/AcpiLib.h @@ -2,6 +2,7 @@ Helper Library for ACPI Copyright (c) 2014-2016, ARM Ltd. All rights reserved. + Copyright (c) 2021, Ampere Computing LLC. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -13,6 +14,7 @@ #include #include +#include // // Macros for the Generic Address Space @@ -128,4 +130,73 @@ LocateAndInstallAcpiFromFv ( IN CONST EFI_GUID* AcpiFile ); +/** + This function calculates and updates a UINT8 checksum + in an ACPI description table header. + + @param Buffer Pointer to buffer to checksum + @param Size Number of bytes to checksum + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + +**/ +EFI_STATUS +EFIAPI +AcpiUpdateChecksum ( + IN OUT UINT8 *Buffer, + IN UINTN Size + ); + +/** + This function uses the ACPI SDT protocol to search an ACPI table + with a given signature. + + @param AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param TableSignature ACPI table signature. + @param Index The zero-based index of the table where to search the table. + The index will be updated to the next instance if the table + is found with the matched TableSignature. + @param Table Pointer to the table. + @param TableKey Pointer to the table key. + + @return EFI_SUCCESS The function completed successfully. + @return EFI_INVALID_PARAMETER At least one of parameters is invalid. + @retval EFI_NOT_FOUND The requested index is too large and a table was not found. + +**/ +EFI_STATUS +EFIAPI +AcpiLocateTableBySignature ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, + IN UINT32 TableSignature, + IN OUT UINTN *Index, + OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + OUT UINTN *TableKey + ); + +/** + This function updates the integer value of an AML Object. + + @param AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param TableHandle Points to the table representing the starting point + for the object path search. + @param AsciiObjectPath Pointer to the ACPI path of the object being updated. + @param Value New value to write to the object. + + @return EFI_SUCCESS The function completed successfully. + @return EFI_INVALID_PARAMETER At least one of parameters is invalid or the data type + of the ACPI object is not an integer value. + @retval EFI_NOT_FOUND The object is not found with the given path. + +**/ +EFI_STATUS +EFIAPI +AcpiAmlObjectUpdateInteger ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, + IN EFI_ACPI_HANDLE TableHandle, + IN CHAR8 *AsciiObjectPath, + IN UINTN Value + ); + #endif // __ACPI_LIB_H__ diff --git a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c b/EmbeddedPkg/Library/AcpiLib/AcpiLib.c index ff7d678433d5..ee087ec3cd5f 100644 --- a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c +++ b/EmbeddedPkg/Library/AcpiLib/AcpiLib.c @@ -1,6 +1,7 @@ /** @file * * Copyright (c) 2014-2015, ARM Limited. All rights reserved. +* Copyright (c) 2021, Ampere Computing LLC. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -9,9 +10,12 @@ #include #include +#include +#include #include #include +#include #include #include @@ -170,3 +174,215 @@ LocateAndInstallAcpiFromFv ( { return LocateAndInstallAcpiFromFvConditional (AcpiFile, NULL); } + +/** + This function calculates and updates a UINT8 checksum + in an ACPI description table header. + + @param Buffer Pointer to buffer to checksum + @param Size Number of bytes to checksum + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + +**/ +EFI_STATUS +EFIAPI +AcpiUpdateChecksum ( + IN OUT UINT8 *Buffer, + IN UINTN Size + ) +{ + UINTN ChecksumOffset; + + if (Buffer == NULL || Size == 0) { + return EFI_INVALID_PARAMETER; + } + + ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum); + + // + // Set checksum to 0 first + // + Buffer[ChecksumOffset] = 0; + + // + // Update checksum value + // + Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Size); + + return EFI_SUCCESS; +} + +/** + This function uses the ACPI SDT protocol to search an ACPI table + with a given signature. + + @param AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param TableSignature ACPI table signature. + @param Index The zero-based index of the table where to search the table. + The index will be updated to the next instance if the table + is found with the matched TableSignature. + @param Table Pointer to the table. + @param TableKey Pointer to the table key. + + @return EFI_SUCCESS The function completed successfully. + @return EFI_INVALID_PARAMETER At least one of parameters is invalid. + @retval EFI_NOT_FOUND The requested index is too large and a table was not found. + +**/ +EFI_STATUS +EFIAPI +AcpiLocateTableBySignature ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, + IN UINT32 TableSignature, + IN OUT UINTN *Index, + OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + OUT UINTN *TableKey + ) +{ + EFI_STATUS Status; + EFI_ACPI_SDT_HEADER *TempTable; + EFI_ACPI_TABLE_VERSION TableVersion; + UINTN TableIndex; + + if (AcpiSdtProtocol == NULL + || Table == NULL + || TableKey == NULL) { + return EFI_INVALID_PARAMETER; + } + + Status = EFI_SUCCESS; + + // + // Search for ACPI Table with matching signature + // + TableVersion = 0; + TableIndex = *Index; + while (!EFI_ERROR (Status)) { + Status = AcpiSdtProtocol->GetAcpiTable ( + TableIndex, + &TempTable, + &TableVersion, + TableKey + ); + if (!EFI_ERROR (Status)) { + TableIndex++; + + if (((EFI_ACPI_DESCRIPTION_HEADER *)TempTable)->Signature == TableSignature) { + *Table = (EFI_ACPI_DESCRIPTION_HEADER *)TempTable; + *Index = TableIndex; + break; + } + } + } + + return Status; +} + +/** + This function updates the integer value of an AML Object. + + @param AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param TableHandle Points to the table representing the starting point + for the object path search. + @param AsciiObjectPath Pointer to the ACPI path of the object being updated. + @param Value New value to write to the object. + + @return EFI_SUCCESS The function completed successfully. + @return EFI_INVALID_PARAMETER At least one of parameters is invalid or the data type + of the ACPI object is not an integer value. + @retval EFI_NOT_FOUND The object is not found with the given path. + +**/ +EFI_STATUS +EFIAPI +AcpiAmlObjectUpdateInteger ( + IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, + IN EFI_ACPI_HANDLE TableHandle, + IN CHAR8 *AsciiObjectPath, + IN UINTN Value + ) +{ + EFI_STATUS Status; + EFI_ACPI_HANDLE ObjectHandle; + EFI_ACPI_HANDLE DataHandle; + EFI_ACPI_DATA_TYPE DataType; + UINT8 *Buffer; + UINTN BufferSize; + UINTN DataSize; + + if (AcpiSdtProtocol == NULL || AsciiObjectPath == NULL) { + return EFI_INVALID_PARAMETER; + } + + ObjectHandle = NULL; + Status = AcpiSdtProtocol->FindPath (TableHandle, AsciiObjectPath, &ObjectHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = AcpiSdtProtocol->GetOption (ObjectHandle, 0, &DataType, (VOID *)&Buffer, &BufferSize); + if (EFI_ERROR (Status)) { + Status = EFI_NOT_FOUND; + goto Exit; + } + ASSERT (DataType == EFI_ACPI_DATA_TYPE_OPCODE); + ASSERT (Buffer != NULL); + + if (Buffer[0] != AML_NAME_OP) { + Status = EFI_NOT_FOUND; + goto Exit; + } + + // + // Get handle of data object + // + DataHandle = NULL; + Status = AcpiSdtProtocol->GetChild (ObjectHandle, &DataHandle); + ASSERT_EFI_ERROR (Status); + + Status = AcpiSdtProtocol->GetOption (DataHandle, 0, &DataType, (VOID *)&Buffer, &BufferSize); + ASSERT (DataType == EFI_ACPI_DATA_TYPE_OPCODE); + ASSERT (Buffer != NULL); + + if (Buffer[0] == AML_ZERO_OP || Buffer[0] == AML_ONE_OP) { + Status = AcpiSdtProtocol->SetOption (DataHandle, 0, (VOID *)&Value, sizeof (UINT8)); + ASSERT_EFI_ERROR (Status); + } else { + // + // Check the size of data object + // + switch (Buffer[0]) { + case AML_BYTE_PREFIX: + DataSize = sizeof (UINT8); + break; + + case AML_WORD_PREFIX: + DataSize = sizeof (UINT16); + break; + + case AML_DWORD_PREFIX: + DataSize = sizeof (UINT32); + break; + + case AML_QWORD_PREFIX: + DataSize = sizeof (UINT64); + break; + + default: + // The data type of the ACPI object is not an integer + Status = EFI_INVALID_PARAMETER; + goto Exit; + } + + Status = AcpiSdtProtocol->SetOption (DataHandle, 1, (VOID *)&Value, DataSize); + ASSERT_EFI_ERROR (Status); + } + +Exit: + AcpiSdtProtocol->Close (DataHandle); + AcpiSdtProtocol->Close (ObjectHandle); + + return Status; +} -- 2.17.1