public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Sami Mujawar <sami.mujawar@arm.com>
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
Subject: [PATCH v1 11/22] DynamicTablesPkg: Table Helper Library
Date: Fri, 21 Dec 2018 16:57:08 +0000	[thread overview]
Message-ID: <20181221165719.49480-12-sami.mujawar@arm.com> (raw)
In-Reply-To: <20181221165719.49480-1-sami.mujawar@arm.com>

A helper library that implements common functionality
for use by table generators.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 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.<BR>
+#
+#  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 <Protocol/AcpiTable.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <Protocol/ConfigurationManagerProtocol.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
+  )
+{
+  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)'




  parent reply	other threads:[~2018-12-21 17:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-21 16:56 [PATCH v1 00/22] DynamicTablesPkg: Introduce Dynamic Tables Framework Sami Mujawar
2018-12-21 16:56 ` [PATCH v1 01/22] DynamicTablesPkg: " Sami Mujawar
2018-12-21 16:56 ` [PATCH v1 02/22] DynamicTablesPkg: Table Generator definition Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 03/22] DynamicTablesPkg: Acpi Table Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 04/22] DynamicTablesPkg: SMBIOS " Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 05/22] DynamicTablesPkg: DT " Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 06/22] DynamicTablesPkg: Standard NameSpace Objects Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 07/22] DynamicTablesPkg: Arm " Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 08/22] DynamicTablesPkg: Configuration Manager Objects Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 09/22] DynamicTablesPkg: Configuration Manager Protocol Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 10/22] DynamicTablesPkg: Configuration Manager Helper Sami Mujawar
2018-12-21 16:57 ` Sami Mujawar [this message]
2018-12-21 16:57 ` [PATCH v1 12/22] DynamicTablesPkg: Dynamic Table Factory Protocol Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 13/22] DynamicTablesPkg: Dynamic Table Factory Dxe Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 14/22] DynamicTablesPkg: Dynamic Table Manager Dxe Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 15/22] DynamicTablesPkg: Arm Raw/DSDT/SSDT Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 16/22] DynamicTablesPkg: Arm ACPI FADT Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 17/22] DynamicTablesPkg: Arm ACPI MADT Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 18/22] DynamicTablesPkg: Arm ACPI GTDT Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 19/22] DynamicTablesPkg: Arm SPCR Table Generator Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 20/22] DynamicTablesPkg: Arm DBG2 " Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 21/22] DynamicTablesPkg: Arm PCI MCFG " Sami Mujawar
2018-12-21 16:57 ` [PATCH v1 22/22] DynamicTablesPkg: Arm IORT " Sami Mujawar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181221165719.49480-12-sami.mujawar@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox