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.52; 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.52]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 10ECD2194D3B3 for ; Thu, 24 Jan 2019 07:44:47 -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 x0OFifCc013695; Thu, 24 Jan 2019 15:44:45 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: Thu, 24 Jan 2019 15:44:27 +0000 Message-Id: <20190124154436.21996-14-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20190124154436.21996-1-sami.mujawar@arm.com> References: <20190124154436.21996-1-sami.mujawar@arm.com> Subject: [PATCH v2 13/22] DynamicTablesPkg: Dynamic Table Factory Dxe 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: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 X-List-Received-Date: Thu, 24 Jan 2019 15:44:49 -0000 The dynamic table factory dxe implements the dynamic table factory protocol. It also implements the ACPI, SMBIOS and DT table factories. The table generators register themselves with the respective table factories and the factories are responsible for instantiating instances of the generators to build the firmware tables. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sami Mujawar --- DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/AcpiTableFactory/AcpiTableFactory.c | 226 ++++++++++++++++++++ DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c | 225 +++++++++++++++++++ DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h | 125 +++++++++++ DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c | 90 ++++++++ DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf | 60 ++++++ DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c | 226 ++++++++++++++++++++ DynamicTablesPkg/DynamicTables.dsc.inc | 6 + DynamicTablesPkg/{DynamicTables.dsc.inc => DynamicTables.fdf.inc} | 10 +- DynamicTablesPkg/DynamicTablesPkg.dec | 11 + 9 files changed, 974 insertions(+), 5 deletions(-) diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/AcpiTableFactory/AcpiTableFactory.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/AcpiTableFactory/AcpiTableFactory.c new file mode 100644 index 0000000000000000000000000000000000000000..3ebbcda6d360ba7d1d49992e966fbf72bafb4976 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/AcpiTableFactory/AcpiTableFactory.c @@ -0,0 +1,226 @@ +/** @file + ACPI Table Factory + + Copyright (c) 2017 - 2019, 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. + + @par Glossary: + - Std - Standard +**/ + +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include + +#include "DynamicTableFactory.h" + +extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; + +/** Return a pointer to the ACPI table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The ACPI table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested ACPI table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetAcpiTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST ACPI_TABLE_GENERATOR_ID GeneratorId, + OUT CONST ACPI_TABLE_GENERATOR ** CONST Generator + ) +{ + UINT16 TableId; + EDKII_DYNAMIC_TABLE_FACTORY_INFO * FactoryInfo; + + ASSERT (This != NULL); + + FactoryInfo = This->TableFactoryInfo; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Invalid Generator pointer\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_ACPI (GeneratorId)) { + DEBUG ((DEBUG_ERROR, "ERROR: Generator Type is not ACPI\n")); + return EFI_INVALID_PARAMETER; + } + + *Generator = NULL; + TableId = GET_TABLE_ID (GeneratorId); + if (IS_GENERATOR_NAMESPACE_STD (GeneratorId)) { + if (TableId >= EStdAcpiTableIdMax) { + ASSERT (TableId < EStdAcpiTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->StdAcpiTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->StdAcpiTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomACPIGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomACPIGenerators)); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->CustomAcpiTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->CustomAcpiTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } + return EFI_SUCCESS; +} + +/** Register ACPI table factory generator. + + The ACPI table factory maintains a list of the Standard and OEM ACPI + table generators. + + @param [in] Generator Pointer to the ACPI table generator. + + @retval EFI_SUCCESS The Generator was registered + successfully. + @retval EFI_INVALID_PARAMETER The Generator ID is invalid or + the Generator pointer is NULL. + @retval EFI_ALREADY_STARTED The Generator for the Table ID is + already registered. +**/ +EFI_STATUS +EFIAPI +RegisterAcpiTableGenerator ( + IN CONST ACPI_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: ACPI register - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_ACPI (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: ACPI register - Generator" \ + " Type is not ACPI\n" + )); + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description)); + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdAcpiTableIdMax) { + ASSERT (TableId < EStdAcpiTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdAcpiTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.StdAcpiTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomACPIGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomACPIGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomAcpiTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.CustomAcpiTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } + return EFI_SUCCESS; +} + +/** Deregister ACPI generator. + + This function is called by the ACPI table generator to deregister itself + from the ACPI table factory. + + @param [in] Generator Pointer to the ACPI table generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER The generator is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +DeregisterAcpiTableGenerator ( + IN CONST ACPI_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: ACPI deregister - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_ACPI (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: ACPI deregister - Generator" \ + " Type is not ACPI\n" + )); + return EFI_INVALID_PARAMETER; + } + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdAcpiTableIdMax) { + ASSERT (TableId < EStdAcpiTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdAcpiTableGeneratorList[TableId] != NULL) { + if (Generator != TableFactoryInfo.StdAcpiTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.StdAcpiTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomACPIGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomACPIGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomAcpiTableGeneratorList[TableId] != NULL) { + if (Generator != + TableFactoryInfo.CustomAcpiTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.CustomAcpiTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } + + DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description)); + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c new file mode 100644 index 0000000000000000000000000000000000000000..98b7e70fc1557b7c8f7159bfc50c4b971f51f89a --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c @@ -0,0 +1,225 @@ +/** @file + Device Tree Table Factory + + Copyright (c) 2017 - 2019, 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. + + @par Glossary: + - Std - Standard +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include + +#include "DynamicTableFactory.h" + +extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; + +/** Return a pointer to the DT table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The DT table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested DT table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetDtTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST DT_TABLE_GENERATOR_ID GeneratorId, + OUT CONST DT_TABLE_GENERATOR ** CONST Generator + ) +{ + UINT16 TableId; + EDKII_DYNAMIC_TABLE_FACTORY_INFO * FactoryInfo; + + ASSERT (This != NULL); + + FactoryInfo = This->TableFactoryInfo; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Invalid Generator pointer\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_DT (GeneratorId)) { + DEBUG ((DEBUG_ERROR, "ERROR: Generator Type is not DT\n")); + return EFI_INVALID_PARAMETER; + } + + *Generator = NULL; + TableId = GET_TABLE_ID (GeneratorId); + if (IS_GENERATOR_NAMESPACE_STD (GeneratorId)) { + if (TableId >= EStdDtTableIdMax) { + ASSERT (TableId < EStdDtTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->StdDtTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->StdDtTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators)); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->CustomDtTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->CustomDtTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } + return EFI_SUCCESS; +} + +/** Register DT table factory generator. + + The DT table factory maintains a list of the Standard and OEM DT + table generators. + + @param [in] Generator Pointer to the DT table generator. + + @retval EFI_SUCCESS The Generator was registered + successfully. + @retval EFI_INVALID_PARAMETER The Generator ID is invalid or + the Generator pointer is NULL. + @retval EFI_ALREADY_STARTED The Generator for the Table ID is + already registered. +**/ +EFI_STATUS +EFIAPI +RegisterDtTableGenerator ( + IN CONST DT_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: DT register - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_DT (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: DT register - Generator" \ + " Type is not DT\n" + )); + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description)); + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdDtTableIdMax) { + ASSERT (TableId < EStdDtTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdDtTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.StdDtTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.CustomDtTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } + return EFI_SUCCESS; +} + +/** Deregister DT generator. + + This function is called by the DT table generator to deregister itself + from the DT table factory. + + @param [in] Generator Pointer to the DT table generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER The generator is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +DeregisterDtTableGenerator ( + IN CONST DT_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: DT deregister - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_DT (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: DT deregister - Generator" \ + " Type is not DT\n" + )); + return EFI_INVALID_PARAMETER; + } + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdDtTableIdMax) { + ASSERT (TableId < EStdDtTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdDtTableGeneratorList[TableId] != NULL) { + if (Generator != TableFactoryInfo.StdDtTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.StdDtTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] != NULL) { + if (Generator != + TableFactoryInfo.CustomDtTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.CustomDtTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } + + DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description)); + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..100a87c31294749363d930cc722813a450039165 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h @@ -0,0 +1,125 @@ +/** @file + + Copyright (c) 2017 - 2019, 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. + + @par Glossary: + - Std - Standard + - ACPI - Advanced Configuration and Power Interface + - SMBIOS - System Management BIOS + - DT - Device Tree +**/ + +#ifndef DYNAMIC_TABLE_FACTORY_H_ +#define DYNAMIC_TABLE_FACTORY_H_ + +#pragma pack(1) + +/** A structure that holds the list of registered ACPI and + SMBIOS table generators. +*/ +typedef struct DynamicTableFactoryInfo { + /// An array for holding the list of Standard ACPI Table Generators. + CONST ACPI_TABLE_GENERATOR * + StdAcpiTableGeneratorList[EStdAcpiTableIdMax]; + + /// An array for holding the list of Custom ACPI Table Generators. + CONST ACPI_TABLE_GENERATOR * + CustomAcpiTableGeneratorList[FixedPcdGet16 ( + PcdMaxCustomACPIGenerators + )]; + + /// An array for holding the list of Standard SMBIOS Table Generators. + CONST SMBIOS_TABLE_GENERATOR * + StdSmbiosTableGeneratorList[EStdSmbiosTableIdMax]; + + /// An array for holding the list of Custom SMBIOS Table Generators. + CONST SMBIOS_TABLE_GENERATOR * + CustomSmbiosTableGeneratorList[FixedPcdGet16 ( + PcdMaxCustomSMBIOSGenerators + )]; + + /// An array for holding the list of Standard DT Table Generators. + CONST DT_TABLE_GENERATOR * + StdDtTableGeneratorList[EStdDtTableIdMax]; + + /// An array for holding the list of Custom DT Table Generators. + CONST DT_TABLE_GENERATOR * + CustomDtTableGeneratorList[FixedPcdGet16 ( + PcdMaxCustomDTGenerators + )]; +} EDKII_DYNAMIC_TABLE_FACTORY_INFO; + +/** Return a pointer to the ACPI table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The ACPI table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested ACPI table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetAcpiTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST ACPI_TABLE_GENERATOR_ID GeneratorId, + OUT CONST ACPI_TABLE_GENERATOR ** CONST Generator + ); + +/** Return a pointer to the SMBIOS table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The SMBIOS table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested SMBIOS table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetSmbiosTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST SMBIOS_TABLE_GENERATOR_ID GeneratorId, + OUT CONST SMBIOS_TABLE_GENERATOR ** CONST Generator + ); + +/** Return a pointer to the DT table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The DT table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested DT table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetDtTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST DT_TABLE_GENERATOR_ID GeneratorId, + OUT CONST DT_TABLE_GENERATOR ** CONST Generator + ); + +#pragma pack() + +#endif // DYNAMIC_TABLE_FACTORY_H_ diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c new file mode 100644 index 0000000000000000000000000000000000000000..4915d379e88bdb9e0fb023d7ad8fb8dd73870f04 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c @@ -0,0 +1,90 @@ +/** @file + Dynamic Table Factory Dxe + + 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 +#include +#include +#include +#include +#include + +#include "DynamicTableFactory.h" + +/** The Dynamic Table Factory protocol structure that holds the + list of registered ACPI and SMBIOS table generators. +*/ +EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; + +/** A structure describing the Dynamic Table Factory protocol. +*/ +STATIC +CONST +EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL DynamicTableFactoryProtocol = { + CREATE_REVISION (1, 0), + GetAcpiTableGenerator, + RegisterAcpiTableGenerator, + DeregisterAcpiTableGenerator, + GetSmbiosTableGenerator, + RegisterSmbiosTableGenerator, + DeregisterSmbiosTableGenerator, + GetDtTableGenerator, + RegisterDtTableGenerator, + DeregisterDtTableGenerator, + &TableFactoryInfo +}; + +/** Entrypoint for Dynamic Table Factory Dxe. + + @param ImageHandle + @param SystemTable + + @retval EFI_SUCCESS Success. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_NOT_FOUND Required interface/object was not found. + @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid. +**/ +EFI_STATUS +EFIAPI +DynamicTableFactoryDxeInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE * CONST SystemTable + ) +{ + EFI_STATUS Status; + + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkiiDynamicTableFactoryProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID*)&DynamicTableFactoryProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to install the Dynamic Table Factory Protocol." \ + " Status = %r\n", + Status + )); + } + return Status; +} diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf new file mode 100644 index 0000000000000000000000000000000000000000..740811d0fc0590543a62360e6753eb04fb675d70 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf @@ -0,0 +1,60 @@ +## @file +# Module to manage the list of available table factories. +# +# 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 = DynamicTableFactoryDxe + FILE_GUID = FE846898-7403-4932-B8AD-A0491F0C2CBA + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = DynamicTableFactoryDxeInitialize + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + AcpiTableFactory/AcpiTableFactory.c + DeviceTreeTableFactory/DeviceTreeTableFactory.c + DynamicTableFactoryDxe.c + SmbiosTableFactory/SmbiosTableFactory.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + MemoryAllocationLib + PrintLib + TableHelperLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[FixedPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomACPIGenerators + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomSMBIOSGenerators + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomDTGenerators + +[Protocols] + gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEdkiiConfigurationManagerProtocolGuid + gEdkiiDynamicTableFactoryProtocolGuid + +[Depex] + TRUE diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c new file mode 100644 index 0000000000000000000000000000000000000000..798cde4860308d237cda3cdc388438dd8bfe0486 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c @@ -0,0 +1,226 @@ +/** @file + SMBIOS Table Factory + + Copyright (c) 2017 - 2019, 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. + + @par Glossary: + - Std - Standard +**/ + +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include + +#include "DynamicTableFactory.h" + +extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; + +/** Return a pointer to the SMBIOS table generator. + + @param [in] This Pointer to the Dynamic Table Factory Protocol. + @param [in] GeneratorId The SMBIOS table generator ID for the + requested generator. + @param [out] Generator Pointer to the requested SMBIOS table + generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +GetSmbiosTableGenerator ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This, + IN CONST SMBIOS_TABLE_GENERATOR_ID GeneratorId, + OUT CONST SMBIOS_TABLE_GENERATOR ** CONST Generator + ) +{ + UINT16 TableId; + EDKII_DYNAMIC_TABLE_FACTORY_INFO * FactoryInfo; + + ASSERT (This != NULL); + + FactoryInfo = This->TableFactoryInfo; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Invalid Generator pointer\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_SMBIOS (GeneratorId)) { + DEBUG ((DEBUG_ERROR, "ERROR: Generator Type is not SMBIOS\n")); + return EFI_INVALID_PARAMETER; + } + + *Generator = NULL; + TableId = GET_TABLE_ID (GeneratorId); + if (IS_GENERATOR_NAMESPACE_STD (GeneratorId)) { + if (TableId >= EStdSmbiosTableIdMax) { + ASSERT (TableId < EStdSmbiosTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->StdSmbiosTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->StdSmbiosTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)); + return EFI_INVALID_PARAMETER; + } + if (FactoryInfo->CustomSmbiosTableGeneratorList[TableId] != NULL) { + *Generator = FactoryInfo->CustomSmbiosTableGeneratorList[TableId]; + } else { + return EFI_NOT_FOUND; + } + } + return EFI_SUCCESS; +} + +/** Register SMBIOS table factory generator. + + The SMBIOS table factory maintains a list of the Standard and OEM SMBIOS + table generators. + + @param [in] Generator Pointer to the SMBIOS table generator. + + @retval EFI_SUCCESS The Generator was registered + successfully. + @retval EFI_INVALID_PARAMETER The Generator ID is invalid or + the Generator pointer is NULL. + @retval EFI_ALREADY_STARTED The Generator for the Table ID is + already registered. +**/ +EFI_STATUS +EFIAPI +RegisterSmbiosTableGenerator ( + IN CONST SMBIOS_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: SMBIOS register - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_SMBIOS (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SMBIOS register - Generator" \ + " Type is not SMBIOS\n" + )); + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description)); + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdSmbiosTableIdMax) { + ASSERT (TableId < EStdSmbiosTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] == NULL) { + TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] = Generator; + } else { + return EFI_ALREADY_STARTED; + } + } + return EFI_SUCCESS; +} + +/** Deregister SMBIOS generator. + + This function is called by the SMBIOS table generator to deregister itself + from the SMBIOS table factory. + + @param [in] Generator Pointer to the SMBIOS table generator. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER The generator is invalid. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +DeregisterSmbiosTableGenerator ( + IN CONST SMBIOS_TABLE_GENERATOR * CONST Generator + ) +{ + UINT16 TableId; + + if (Generator == NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: SMBIOS deregister - Invalid Generator\n")); + return EFI_INVALID_PARAMETER; + } + + if (!IS_GENERATOR_TYPE_SMBIOS (Generator->GeneratorID)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SMBIOS deregister - Generator" \ + " Type is not SMBIOS\n" + )); + return EFI_INVALID_PARAMETER; + } + + TableId = GET_TABLE_ID (Generator->GeneratorID); + if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) { + if (TableId >= EStdSmbiosTableIdMax) { + ASSERT (TableId < EStdSmbiosTableIdMax); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] != NULL) { + if (Generator != TableFactoryInfo.StdSmbiosTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } else { + if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) { + ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)); + return EFI_INVALID_PARAMETER; + } + if (TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] != NULL) { + if (Generator != + TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId]) { + return EFI_INVALID_PARAMETER; + } + TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] = NULL; + } else { + return EFI_NOT_FOUND; + } + } + + DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description)); + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 1cac3e649afebb06190fb5bf6387857437706404..9803b345c6660ad9d5c6b2e0617e856c10069a32 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -18,3 +18,9 @@ [Defines] [LibraryClasses.common] TableHelperLib|DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf +[Components.common] + # + # Dynamic Table Factory Dxe + # + DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf + diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.fdf.inc similarity index 73% copy from DynamicTablesPkg/DynamicTables.dsc.inc copy to DynamicTablesPkg/DynamicTables.fdf.inc index 1cac3e649afebb06190fb5bf6387857437706404..4123c6a8b751b2454c8890a75e925a7c9af97afc 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.fdf.inc @@ -1,5 +1,5 @@ ## @file -# Dsc include file for Dynamic Tables Framework. +# fdf include file for Dynamic Tables Framework. # # Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
# @@ -13,8 +13,8 @@ # ## -[Defines] - -[LibraryClasses.common] - TableHelperLib|DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf + # + # Dynamic Table Factory Dxe + # + INF DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec index 3137c14247920974082bd74173cab4e7ac02b3f7..21e904ce1e250477be899b506bce72d12087ed74 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dec +++ b/DynamicTablesPkg/DynamicTablesPkg.dec @@ -30,3 +30,14 @@ [Protocols] # Dynamic Table Factory Protocol GUID gEdkiiDynamicTableFactoryProtocolGuid = { 0x91d1e327, 0xfe5a, 0x49b8, { 0xab, 0x65, 0xe, 0xce, 0x2d, 0xdb, 0x45, 0xec } } +[PcdsFixedAtBuild] + + # Maximum number of Custom ACPI Generators + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomACPIGenerators|1|UINT16|0xC0000001 + + # Maximum number of Custom SMBIOS Generators + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomSMBIOSGenerators|1|UINT16|0xC0000002 + + # Maximum number of Custom DT Generators + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxCustomDTGenerators|1|UINT16|0xC0000003 + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'