From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.109]) by mx.groups.io with SMTP id smtpd.web11.1810.1639802966596349092 for ; Fri, 17 Dec 2021 20:49:26 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=Ac3roCGa; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.109, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gzbNNrt2IvcTCOB0owwX/mZT9ISBpEntlGVTbpB1QFPRIEbRob1eFIDv7qBcBgW/SgACstZFtbu8pI11Up8CU0iinUmd0UftQtHtwNB27fVv0ZGiUAIjeYUmt6oLzUVnIp2h7XdkqKWgPdnIc4V0g7wJQHFkdNlbjjWFE1WH3M5beedcxrFefFsBBH18etvjbticfpwTMGhLLffadVnaXfj4/mcuEG3Oa9ybx5vm6rq8L68njCQ7waTjNRxmhwcMQInHSL+SSnq0kAkAWNTFhpoz2cLIMPeacKzsrCyJkslaPaU+B5X+f66QpaBZIh0r6lYpFPiAKxczmB4RGypYpg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SBYWHM2pT4ZoIw343x0/fYPXiT8fFG1oi20KTqB8yYQ=; b=NclOEON5/grO6a4s+ox3AuZbs3acysbd7JX+3aenUg1KBF5QyciWRjticYfwgmoK7Lpr+spZ3XWVh2hLuwM/JE1L6sAGYou9sq5iAu9I8rzFNKmBukOsVKjFEueVSndbZIfwYBLGJyLMhMaLkNdOWNnssN0sm91Uq2GTqEB3Lrr+ZmmFJAYlkL9THKYo5+K+lACenHre/sOWJV5bUJLg/12uNC51l54Hf0IIXEq+ooWeKqvbkrj41QUKIjU9MaIwwzy8r8Jj3RLSHJweiNMRMCU4RtJVbcnh47mk/pxZyncDGIuTvHMUa0NeOkugjNJTN5hT+KacX7ttwuJmZjnYwg== 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=SBYWHM2pT4ZoIw343x0/fYPXiT8fFG1oi20KTqB8yYQ=; b=Ac3roCGalMb6XTQGVT9pY4BTDenGcuJiIP6jWBdnWdLnHgO+GesMjZkqw0wxNO7/FNI2XWMO5i+M5hVNjlTeF3WrR+5550cqpSOpTEbj51sdBY5RLCa0aRt+bIHqIjeji3tmIty68ujHn6edkHu3/NhyQxbU0y3I8kgZRcYUIFU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by PH0PR01MB6503.prod.exchangelabs.com (2603:10b6:510:12::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.17; Sat, 18 Dec 2021 04:49:22 +0000 Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::b519:e888:c4c8:b552]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::b519:e888:c4c8:b552%8]) with mapi id 15.20.4778.017; Sat, 18 Dec 2021 04:49:22 +0000 Message-ID: <0fb8e9cd-c859-ab48-71c3-3d971afe30f9@os.amperecomputing.com> Date: Sat, 18 Dec 2021 11:49:11 +0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [edk2-devel] [PATCH v2 1/1] EmbeddedPkg/AcpiLib: Add more helper functions To: Leif Lindholm Cc: "Chang, Abner (HPS SW/FW Technologist)" , "devel@edk2.groups.io" , "patches@amperecomputing.com" , Ard Biesheuvel , "Schaefer, Daniel" References: <20210903154423.32619-1-nhi@os.amperecomputing.com> <4cc27fb8-6640-f9f8-374d-4424c789a98c@os.amperecomputing.com> From: "Nhi Pham" In-Reply-To: X-ClientProxiedBy: SI2PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:194::12) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb2f98a2-ca13-4c2e-b6b6-08d9c1e1c1f0 X-MS-TrafficTypeDiagnostic: PH0PR01MB6503:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z2UoLJXbAvRO6wQgqJXap9QOIoiF10AHdhAYBT5tI3vKYNnXz4RZ25sUtBxmvYWpHdDvrbHTkX8deRcYfIg0/uZ1KhZL27RNRbjVMwAkI1Xv9EIdaHxdeKPcnaWd+0NJJOHwflH1pyErIkEc/pE1ok+MTSb5awwN0npMk1aIqWFed1WFbC4+wUCrL0GzutP9vVj9bQ8Yp0zOi9W1xg3AFxR5inN2nR7ZQVJ3zt6/nUMjEFShqzqwAivICSD9AxduQ3zSvnnWdYObbqr6ng8P62ft2CVpSbb7daa1uszP40r4D3bdTEFrpih7uEUhrPWqVQaBSBQGFlj+L/e2/NJq4f30/uzA89vuyyLHMqFUejIESMc1FWP0xoBqJW+XUtFJ3o0Mu4faACeB1nvAJ3MOfM4PlnaCv3oBKKKsqdzeXFnwFyqDQBblLi5rOoAXJSuRoIL6rGIImgfLL2Vgo9Bwj+nEHzZio14Yt1GZ0pzle5UsXJ9JiGlpvIZ3MWqOsI+iRiU9DskX33gomtt6AAht4PMjyQokhbP1ce4/obrRSyMfx2fAZrMYJ56RDB7n53q97UrbNAkRoYjbmtiLz2FW85fEhcfxz9Ym0FC5hPfh+Ssq8py/8sWyewB101NJ/FIJPsJ5X83yUDeJW2liZ/+x5uz384rbVmKbr1t9UnczX/LhUBl9rTKiqCj7Xw7j45wBXNcxtU818sS1flBPk5qA4h7XYtoh3xBakcGmLZWxKS7hqxEqI4Yn65mD+a/sp8FrZLNWsK46/WJG6zBuk+eYJgOureZh0Aqfvk5nMSgGWiQ0KIEXffM70l5/zhUHizBN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7287.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(38100700002)(38350700002)(52116002)(31686004)(186003)(86362001)(508600001)(8936002)(8676002)(2906002)(19627235002)(6506007)(2616005)(83380400001)(53546011)(6486002)(6916009)(6666004)(66476007)(4326008)(966005)(31696002)(54906003)(66556008)(26005)(30864003)(316002)(6512007)(5660300002)(66946007)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?a2RzZEJrMVZscTdWcEZmUEMrMS9rSUkwNXAyUm1TbFdtZGxVbTcvRE9GazhJ?= =?utf-8?B?Q2VQZjdpazY5MEtuRFpodXNHOHZlMEQwYk11NmdoOVZ4OUd3SmxWZWFvaEt6?= =?utf-8?B?UnZqU3RCcHpmRFh5N3JkRHNtdFNDVWh6YkdtN3Q2MXhiUXNSL1J2Rit4TTN3?= =?utf-8?B?aUpyNDVKeFZ3ckpCUVB5TjlvTzJrUWQxb3NINVBkMDJhb0NGYmxVdTNYQ3FO?= =?utf-8?B?ZHg1dlpmYk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dUaGFkR01X?= =?utf-8?B?RWVVb1RXd1UrWXN1eXd2bEUxeHdmY05TdHF2aDVpUEQ1eUZ3MTE4QTcwRzEw?= =?utf-8?B?K1RwWkF5WmNhaEFPanFXSjNDVlprSmwxM0ZMaFRsS3lINjgvNEdYZ0MxZXVV?= =?utf-8?B?QVVxVnhYbXJjeC9nSGxRbkY3aVF0THg2QnhITFlPMEZuQ0N3SU80NjVtQ0JD?= =?utf-8?B?MWVtenF4UGhNWk5SbmRiQzFZb2lnPT0=?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb2f98a2-ca13-4c2e-b6b6-08d9c1e1c1f0 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2021 04:49:21.9434 (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: ekJ3AUvnNjBpQ19wgck5whqeZH+Gci9SKsObLc//xi/lCotys3KH19G/KenIQDdeYDENXoicUR82typ8C+frtXs6ZVGc8+a1cokvvMkbOV0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6503 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Leif, Thanks so much for merging it. Happy Holidays! Best regards, Nhi On 17/12/2021 22:56, Leif Lindholm wrote: > Hi Nhi, > > I have now pushed this patch as c63a10ecb7d6, and will get back to the > rest of the Altra port. > > / > Leif > > On Thu, Sep 09, 2021 at 00:02:36 +0700, Nhi Pham wrote: >> Thanks Abner. >> >> I will correct the description for the function AcpiLocateTableBySignature >> in the v3. >> >> Best regards, >> Nhi >> >> On 08/09/2021 11:53, Chang, Abner (HPS SW/FW Technologist) wrote: >>> After below comments are addressed, >>> >>> Reviewed-by: Abner Chang >>> >>>> -----Original Message----- >>>> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of >>>> Nhi Pham via groups.io >>>> Sent: Friday, September 3, 2021 11:44 PM >>>> To: devel@edk2.groups.io >>>> Cc: patches@amperecomputing.com; Nhi Pham >>>> ; Leif Lindholm ; Ard >>>> Biesheuvel ; Chang, Abner (HPS SW/FW >>>> Technologist) ; Schaefer, Daniel >>>> >>>> Subject: [edk2-devel] [PATCH v2 1/1] EmbeddedPkg/AcpiLib: Add more >>>> helper functions >>>> >>>> This adds more helper functions that assist in calculating the checksum, >>>> locating an ACPI table by signature, and updating an AML integer object. >>>> >>>> Cc: Leif Lindholm >>>> Cc: Ard Biesheuvel >>>> Cc: Abner Chang >>>> Cc: Daniel Schaefer >>>> Signed-off-by: Nhi Pham >>>> --- >>>> 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 | 69 +++++++ >>>> EmbeddedPkg/Library/AcpiLib/AcpiLib.c | 214 ++++++++++++++++++++ >>>> 3 files changed, 286 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..933582b7f607 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,71 @@ 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 locate an ACPI table >>>> + with a given signature that only have a single instance. >>>> + >>>> + @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. >>>> + @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..393133f54381 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,213 @@ 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 locate an ACPI table >>>> + with a given signature that only have a single instance. >>> Is the description correct? I think this function can be used to search >>> the given signature which could have multiple instances, right? >>> >>>> + >>>> + @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. >>> Could you please mention that 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 >>> Ok, that is fine to use 0 as you mentioned AML_OP_PARSE_INDEX_GET_OPCODE was defined privately. The better way >>> is to define this in EmbeddedPkg/Library/AcpiLib.h. Sorry I don't have chance to reply your last mail. >>> >>> Abner >>> >>>> *)&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 >>>> >>>> >>>> >>>> >>>>