]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c
DynamicTablesPkg: Arm Raw/DSDT/SSDT Generator
[mirror_edk2.git] / DynamicTablesPkg / Library / Acpi / Arm / AcpiRawLibArm / RawGenerator.c
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c
new file mode 100644 (file)
index 0000000..ae3d3ec
--- /dev/null
@@ -0,0 +1,150 @@
+/** @file\r
+  MCFG Table Generator\r
+\r
+  Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#include <Library/AcpiLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Protocol/AcpiTable.h>\r
+\r
+// Module specific include files.\r
+#include <AcpiTableGenerator.h>\r
+#include <ConfigurationManagerObject.h>\r
+#include <ConfigurationManagerHelper.h>\r
+#include <Library/TableHelperLib.h>\r
+#include <Protocol/ConfigurationManagerProtocol.h>\r
+\r
+/** Construct the ACPI table using the ACPI table data provided.\r
+\r
+  This function invokes the Configuration Manager protocol interface\r
+  to get the required hardware information for generating the ACPI\r
+  table.\r
+\r
+  If this function allocates any resources then they must be freed\r
+  in the FreeXXXXTableResources function.\r
+\r
+  @param [in]  This           Pointer to the table generator.\r
+  @param [in]  AcpiTableInfo  Pointer to the ACPI Table Info.\r
+  @param [in]  CfgMgrProtocol Pointer to the Configuration Manager\r
+                              Protocol Interface.\r
+  @param [out] Table          Pointer to the constructed ACPI Table.\r
+\r
+  @retval EFI_SUCCESS           Table generated successfully.\r
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+BuildRawTable (\r
+  IN  CONST ACPI_TABLE_GENERATOR                  * CONST This,\r
+  IN  CONST CM_STD_OBJ_ACPI_TABLE_INFO            * CONST AcpiTableInfo,\r
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  * CONST CfgMgrProtocol,\r
+  OUT       EFI_ACPI_DESCRIPTION_HEADER          ** CONST Table\r
+  )\r
+{\r
+  ASSERT (This != NULL);\r
+  ASSERT (AcpiTableInfo != NULL);\r
+  ASSERT (CfgMgrProtocol != NULL);\r
+  ASSERT (Table != NULL);\r
+  ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
+  ASSERT (AcpiTableInfo->AcpiTableData != NULL);\r
+\r
+  if (AcpiTableInfo->AcpiTableData == NULL) {\r
+    *Table = NULL;\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Table = AcpiTableInfo->AcpiTableData;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/** This macro defines the Raw Generator revision.\r
+*/\r
+#define RAW_GENERATOR_REVISION CREATE_REVISION (1, 0)\r
+\r
+/** The interface for the Raw Table Generator.\r
+*/\r
+STATIC\r
+CONST\r
+ACPI_TABLE_GENERATOR RawGenerator = {\r
+  // Generator ID\r
+  CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdRaw),\r
+  // Generator Description\r
+  L"ACPI.STD.RAW.GENERATOR",\r
+  // ACPI Table Signature - Unused\r
+  0,\r
+  // ACPI Table Revision - Unused\r
+  0,\r
+  // Minimum ACPI Table Revision - Unused\r
+  0,\r
+  // Creator ID\r
+  TABLE_GENERATOR_CREATOR_ID_ARM,\r
+  // Creator Revision\r
+  RAW_GENERATOR_REVISION,\r
+  // Build Table function\r
+  BuildRawTable,\r
+  // No additional resources are allocated by the generator.\r
+  // Hence the Free Resource function is not required.\r
+  NULL,\r
+  // Extended build function not needed\r
+  NULL,\r
+  // Extended build function not implemented by the generator.\r
+  // Hence extended free resource function is not required.\r
+  NULL\r
+};\r
+\r
+/** Register the Generator with the ACPI Table Factory.\r
+\r
+  @param [in]  ImageHandle  The handle to the image.\r
+  @param [in]  SystemTable  Pointer to the System Table.\r
+\r
+  @retval EFI_SUCCESS           The Generator is registered.\r
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
+  @retval EFI_ALREADY_STARTED   The Generator for the Table ID\r
+                                is already registered.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiRawLibConstructor (\r
+  IN CONST EFI_HANDLE                ImageHandle,\r
+  IN       EFI_SYSTEM_TABLE  * CONST SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  Status = RegisterAcpiTableGenerator (&RawGenerator);\r
+  DEBUG ((DEBUG_INFO, "RAW: Register Generator. Status = %r\n", Status));\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r
+\r
+/** Deregister the Generator from the ACPI Table Factory.\r
+\r
+  @param [in]  ImageHandle  The handle to the image.\r
+  @param [in]  SystemTable  Pointer to the System Table.\r
+\r
+  @retval EFI_SUCCESS           The Generator is deregistered.\r
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
+  @retval EFI_NOT_FOUND         The Generator is not registered.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiRawLibDestructor (\r
+  IN CONST EFI_HANDLE                ImageHandle,\r
+  IN       EFI_SYSTEM_TABLE  * CONST SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  Status = DeregisterAcpiTableGenerator (&RawGenerator);\r
+  DEBUG ((DEBUG_INFO, "RAW: Deregister Generator. Status = %r\n", Status));\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r