From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.106.55; helo=cam-smtp0.cambridge.arm.com; envelope-from=sami.mujawar@arm.com; receiver=edk2-devel@lists.01.org Received: from cam-smtp0.cambridge.arm.com (unknown [217.140.106.55]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3E33C21164EF2 for ; Fri, 21 Dec 2018 09:40:11 -0800 (PST) Received: from E107187.Arm.com (e107187.arm.com [10.1.195.55]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id wBLGvOUd018491; Fri, 21 Dec 2018 16:59:34 GMT From: Sami Mujawar To: edk2-devel@lists.01.org Cc: alexei.fedorov@arm.com, leif.lindholm@linaro.org, Matteo.Carlini@arm.com, Stephanie.Hughes-Fitt@arm.com, nd@arm.com Date: Fri, 21 Dec 2018 16:57:08 +0000 Message-Id: <20181221165719.49480-12-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20181221165719.49480-1-sami.mujawar@arm.com> References: <20181221165719.49480-1-sami.mujawar@arm.com> Subject: [PATCH v1 11/22] DynamicTablesPkg: Table Helper Library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 X-List-Received-Date: Fri, 21 Dec 2018 17:40:11 -0000 A helper library that implements common functionality for use by table generators. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sami Mujawar --- DynamicTablesPkg/DynamicTables.dsc.inc | 20 +++ DynamicTablesPkg/Include/Library/TableHelperLib.h | 66 ++++++++ DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c | 164 ++++++++++++++++++++ DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf | 36 +++++ 4 files changed, 286 insertions(+) diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc new file mode 100644 index 0000000000000000000000000000000000000000..1cac3e649afebb06190fb5bf6387857437706404 --- /dev/null +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -0,0 +1,20 @@ +## @file +# Dsc include file for Dynamic Tables Framework. +# +# Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + +[LibraryClasses.common] + TableHelperLib|DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf + diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h new file mode 100644 index 0000000000000000000000000000000000000000..f17a0b23ddfc0aea39b08acd2c874dbfe8a0749d --- /dev/null +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -0,0 +1,66 @@ +/** @file + + Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef TABLE_HELPER_LIB_H_ +#define TABLE_HELPER_LIB_H_ + +/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO + object from the Configuration Manager. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol + interface. + @param [out] CfgMfrInfo Pointer to the Configuration Manager Info + object structure. + + @retval EFI_SUCCESS The object is returned. + @retval EFI_INVALID_PARAMETER The Object ID is invalid. + @retval EFI_NOT_FOUND The requested Object is not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size. +**/ +EFI_STATUS +EFIAPI +GetCgfMgrInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo + ); + +/** The AddAcpiHeader function updates the ACPI header structure. It uses the + ACPI table Generator and the Configuration Manager protocol to obtain the + information required for constructing the header. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + protocol interface. + @param [in] Generator Pointer to the ACPI table Generator. + @param [in,out] AcpiHeader Pointer to the ACPI table header to be + updated. + @param [in] Length Length of the ACPI table. + + @retval EFI_SUCCESS The ACPI table is updated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object information is not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +AddAcpiHeader ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + IN CONST ACPI_TABLE_GENERATOR * CONST Generator, + IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader, + IN CONST UINT32 Length + ); + +#endif // TABLE_HELPER_LIB_H_ diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c new file mode 100644 index 0000000000000000000000000000000000000000..5a7a44f20690d93891384024b3ac197e37a470cc --- /dev/null +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -0,0 +1,164 @@ +/** @file + Table Helper + +Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. +This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include + +/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO + object from the Configuration Manager. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol + interface. + @param [out] CfgMfrInfo Pointer to the Configuration Manager Info + object structure. + + @retval EFI_SUCCESS The object is returned. + @retval EFI_INVALID_PARAMETER The Object ID is invalid. + @retval EFI_NOT_FOUND The requested Object is not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size. +**/ +EFI_STATUS +EFIAPI +GetCgfMgrInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo + ) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR CmObjectDesc; + + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CfgMfrInfo != NULL); + + *CfgMfrInfo = NULL; + Status = CfgMgrProtocol->GetObject ( + CfgMgrProtocol, + CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo), + CM_NULL_TOKEN, + &CmObjectDesc + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Get Configuration Manager Info. Status = %r\n", + Status + )); + return Status; + } + + if (CmObjectDesc.Size < sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: EStdObjCfgMgrInfo: Buffer too small, size = 0x%x\n", + CmObjectDesc.Size + )); + ASSERT ( + CmObjectDesc.Size >= sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO) + ); + return EFI_BAD_BUFFER_SIZE; + } + + *CfgMfrInfo = (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO*)CmObjectDesc.Data; + return Status; +} + +/** The AddAcpiHeader function updates the ACPI header structure pointed by + the AcpiHeader. It utilizes the ACPI table Generator and the Configuration + Manager protocol to obtain any information required for constructing the + header. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + protocol interface. + @param [in] Generator Pointer to the ACPI table Generator. + @param [in,out] AcpiHeader Pointer to the ACPI table header to be + updated. + @param [in] Length Length of the ACPI table. + + @retval EFI_SUCCESS The ACPI table is updated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object information is not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +AddAcpiHeader ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + IN CONST ACPI_TABLE_GENERATOR * CONST Generator, + IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader, + IN CONST UINT32 Length + ) +{ + EFI_STATUS Status; + CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo; + + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Generator != NULL); + ASSERT (AcpiHeader != NULL); + ASSERT (Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)); + + if ((CfgMgrProtocol == NULL) || + (Generator == NULL) || + (AcpiHeader == NULL) || + (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) + ) { + return EFI_INVALID_PARAMETER; + } + + Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to get Configuration Manager info. Status = %r\n", + Status + )); + goto error_handler; + } + + // UINT32 Signature + AcpiHeader->Signature = Generator->AcpiTableSignature; + // UINT32 Length + AcpiHeader->Length = Length; + // UINT8 Revision + AcpiHeader->Revision = Generator->AcpiTableRevision; + // UINT8 Checksum + AcpiHeader->Checksum = 0; + + // UINT8 OemId[6] + CopyMem (AcpiHeader->OemId, CfgMfrInfo->OemId, sizeof (AcpiHeader->OemId)); + + // UINT64 OemTableId + AcpiHeader->OemTableId = Generator->CreatorId; + AcpiHeader->OemTableId <<= 32; + AcpiHeader->OemTableId |= Generator->AcpiTableSignature; + + // UINT32 OemRevision + AcpiHeader->OemRevision = CfgMfrInfo->Revision; + + // UINT32 CreatorId + AcpiHeader->CreatorId = Generator->CreatorId; + // UINT32 CreatorRevision + AcpiHeader->CreatorRevision = Generator->CreatorRevision; + +error_handler: + return Status; +} diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..2568057a9e5021d9779c769e611a86da163f6d1d --- /dev/null +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf @@ -0,0 +1,36 @@ +## @file +# Table Helper +# +# Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +## + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = DynamicTableHelperLib + FILE_GUID = E315C738-3A39-4D0D-A0AF-8EDFA770AB39 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = TableHelperLib + +[Sources] + TableHelper.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + +[Protocols] + +[Guids] + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'