public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: <devel@edk2.groups.io>
Cc: Sami Mujawar <sami.mujawar@arm.com>, <Alexei.Fedorov@arm.com>,
	<pierre.gondois@arm.com>, <ard.biesheuvel@arm.com>,
	<Matteo.Carlini@arm.com>, <Ben.Adderson@arm.com>, <nd@arm.com>
Subject: [PATCH v1 17/30] DynamicTablesPkg: AML resource data helper
Date: Wed, 12 Aug 2020 16:22:23 +0100	[thread overview]
Message-ID: <20200812152236.31164-18-sami.mujawar@arm.com> (raw)
In-Reply-To: <20200812152236.31164-1-sami.mujawar@arm.com>

From: Pierre Gondois <pierre.gondois@arm.com>

Resource data are defined in the ACPI 6.3 specification,
s6.4 "Resource Data Types for ACPI". They can be created
using the ASL ResourceTemplate () statement, cf s19.3.3
"ASL Resource Templates".

Resource data can be of the small or large type and are
defined by their encoding. The resource data is stored
in the Bytelist of a BufferOp node. To simplify
operations on resource data, the resource data parser
examines the Bytelist to detect the presence of resource
data. If the data matches the encoding of resource
data type(s), the parser fragments the resource data
buffer into resource data elements (data nodes) and
stores them in the variable arguments list of the
BufferOp node.

The resource data helper provides functions and macros
to assist operations on resource data elements.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c | 103 ++++++++++++
 DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h | 174 ++++++++++++++++++++
 2 files changed, 277 insertions(+)

diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
new file mode 100644
index 0000000000000000000000000000000000000000..8b46c7232df3bb7d49e5faa1362a485a6a413198
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
@@ -0,0 +1,103 @@
+/** @file
+  AML Resource Data.
+
+  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+  - Rd or RD   - Resource Data
+  - Rds or RDS - Resource Data Small
+  - Rdl or RDL - Resource Data Large
+**/
+
+#include <ResourceData/AmlResourceData.h>
+
+/** Check whether the resource data has the input descriptor Id.
+
+  The small/large bit is included in the descriptor Id,
+  but the size bits are not included for small resource data elements.
+
+  @param  [in]  Header        Pointer to the first byte of a resource data
+                              element.
+  @param  [in]  DescriptorId  The descriptor to check against.
+
+  @retval TRUE    The resource data has the descriptor Id.
+  @retval FALSE   Otherwise.
+**/
+BOOLEAN
+EFIAPI
+AmlRdCompareDescId (
+  IN  CONST AML_RD_HEADER   * Header,
+  IN        AML_RD_HEADER     DescriptorId
+  )
+{
+  if (Header == NULL) {
+    ASSERT (0);
+    return FALSE;
+  }
+
+  if (AML_RD_IS_LARGE (Header)) {
+    return ((*Header ^ DescriptorId) == 0);
+  } else {
+    return (((*Header & AML_RD_SMALL_ID_MASK) ^ DescriptorId) == 0);
+  }
+}
+
+/** Get the descriptor Id of the resource data.
+
+  The small/large bit is included in the descriptor Id,
+  but the size bits are not included for small resource data elements.
+
+  @param  [in]  Header  Pointer to the first byte of a resource data.
+
+  @return A descriptor Id.
+**/
+AML_RD_HEADER
+EFIAPI
+AmlRdGetDescId (
+  IN  CONST AML_RD_HEADER   * Header
+  )
+{
+  if (Header == NULL) {
+    ASSERT (0);
+    return FALSE;
+  }
+
+  if (AML_RD_IS_LARGE (Header)) {
+    return *Header;
+  }
+
+  // Header is a small resource data element.
+  return *Header & AML_RD_SMALL_ID_MASK;
+}
+
+/** Get the size of a resource data element.
+
+  If the resource data element is of the large type, the Header
+  is expected to be at least 3 bytes long.
+
+  @param  [in]  Header  Pointer to the first byte of a resource data.
+
+  @return The size of the resource data element.
+**/
+UINT32
+EFIAPI
+AmlRdGetSize (
+  IN  CONST AML_RD_HEADER   * Header
+  )
+{
+  if (Header == NULL) {
+    ASSERT (0);
+    return FALSE;
+  }
+
+  if (AML_RD_IS_LARGE (Header)) {
+    return ((ACPI_LARGE_RESOURCE_HEADER*)Header)->Length +
+             sizeof (ACPI_LARGE_RESOURCE_HEADER);
+  }
+
+  // Header is a small resource data element.
+  return ((ACPI_SMALL_RESOURCE_HEADER*)Header)->Bits.Length +
+           sizeof (ACPI_SMALL_RESOURCE_HEADER);
+}
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h
new file mode 100644
index 0000000000000000000000000000000000000000..48e4e2aaddb47e3847cb896e9bc64d4c68bda9f4
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h
@@ -0,0 +1,174 @@
+/** @file
+  AML Resource Data.
+
+  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+  - Rd or RD   - Resource Data
+  - Rds or RDS - Resource Data Small
+  - Rdl or RDL - Resource Data Large
+**/
+
+#ifndef AML_RESOURCE_DATA_H_
+#define AML_RESOURCE_DATA_H_
+
+/* This header file does not include internal Node definition,
+   i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. The node definitions
+   must be included by the caller file. The function prototypes must
+   only expose AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE, etc. node
+   definitions.
+   This allows to keep the functions defined here both internal and
+   potentially external. If necessary, any function of this file can
+   be exposed externally.
+   The Api folder is internal to the AmlLib, but should only use these
+   functions. They provide a "safe" way to interact with the AmlLib.
+*/
+
+#include <AmlInclude.h>
+#include <IndustryStandard/Acpi.h>
+
+/**
+  @defgroup ResourceDataLibrary Resource data library
+  @ingroup AMLLib
+  @{
+    Resource data are defined in the ACPI 6.3 specification,
+    s6.4 "Resource Data Types for ACPI". They can be created in ASL via the
+    ResourceTemplate () statement, cf s19.3.3 "ASL Resource Templates".
+
+    Resource data can be of the small or large type. The difference between
+    small and large resource data elements is their encoding.
+
+    Resource data are stored in the variable list of arguments of object
+    nodes.
+  @}
+*/
+
+/** Resource Descriptor header for Small/Large Resource Data Object.
+    This is the first byte of a Small/Large Resource Data element.
+
+  Can be a ACPI_SMALL_RESOURCE_HEADER or ACPI_LARGE_RESOURCE_HEADER.
+
+  @ingroup ResourceDataStructures
+*/
+typedef UINT8 AML_RD_HEADER;
+
+/** Mask for the small resource data size.
+
+  @ingroup ResourceDataStructures
+*/
+#define AML_RD_SMALL_SIZE_MASK    (0x7U)
+
+/** Mask for the small resource data ID.
+
+  @ingroup ResourceDataStructures
+*/
+#define AML_RD_SMALL_ID_MASK      (0xFU << 3)
+
+/** Mask for the large resource data ID.
+
+  @ingroup ResourceDataStructures
+*/
+#define AML_RD_LARGE_ID_MASK      (0x7FU)
+
+/**
+  @defgroup ResourceDataApis Resource data APIs
+  @ingroup ResourceDataLibrary
+  @{
+    Resource data APIs allow to manipulate/decode resource data elements.
+  @}
+*/
+
+/** Check whether a resource data is of the large type.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Header  Pointer to the first byte of a resource data.
+
+  @retval TRUE  If the resource data is of the large type.
+  @retval FALSE Otherwise.
+**/
+#define AML_RD_IS_LARGE(Header)                                               \
+          (((ACPI_SMALL_RESOURCE_HEADER*)Header)->Bits.Type ==                \
+          ACPI_LARGE_ITEM_FLAG)
+
+/** Build a small resource data descriptor Id.
+    The small/large bit is included in the descriptor Id,
+    but the size bits are not included.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Id  Descriptor Id.
+
+  @return A descriptor Id.
+**/
+#define AML_RD_BUILD_SMALL_DESC_ID(Id)  ((AML_RD_HEADER)((Id & 0xF) << 3))
+
+/** Build a large resource data descriptor Id.
+    The small/large bit is included in the descriptor Id.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Id  Id of the descriptor.
+
+  @return A descriptor Id.
+**/
+#define AML_RD_BUILD_LARGE_DESC_ID(Id)  ((AML_RD_HEADER)((BIT7) | Id))
+
+/** Check whether the resource data has the input descriptor Id.
+
+  The small/large bit is included in the descriptor Id,
+  but the size bits are not included for small resource data elements.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Header        Pointer to the first byte of a resource data
+                              element.
+  @param  [in]  DescriptorId  The descriptor to check against.
+
+  @retval TRUE    The resource data has the descriptor Id.
+  @retval FALSE   Otherwise.
+**/
+BOOLEAN
+EFIAPI
+AmlRdCompareDescId (
+  IN  CONST AML_RD_HEADER   * Header,
+  IN        AML_RD_HEADER     DescriptorId
+  );
+
+/** Get the descriptor Id of the resource data.
+
+  The small/large bit is included in the descriptor Id,
+  but the size bits are not included for small resource data elements.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Header  Pointer to the first byte of a resource data.
+
+  @return A descriptor Id.
+**/
+AML_RD_HEADER
+EFIAPI
+AmlRdGetDescId (
+  IN  CONST AML_RD_HEADER   * Header
+  );
+
+/** Get the size of a resource data element.
+
+  If the resource data element is of the large type, the Header
+  is expected to be at least 3 bytes long.
+
+  @ingroup ResourceDataApis
+
+  @param  [in]  Header  Pointer to the first byte of a resource data.
+
+  @return The size of the resource data element.
+**/
+UINT32
+EFIAPI
+AmlRdGetSize (
+  IN  CONST AML_RD_HEADER   * Header
+  );
+
+#endif // AML_RESOURCE_DATA_H_
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  parent reply	other threads:[~2020-08-12 15:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12 15:22 [PATCH v1 00/30] Add Dynamic AML generation support Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 01/30] DynamicTablesPkg: Introduction to Dynamic AML Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 02/30] DynamicTablesPkg: AmlLib definitions Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 03/30] DynamicTablesPkg: AML grammar definition Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 04/30] DynamicTablesPkg: AML node definitions Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 05/30] DynamicTablesPkg: AML tree interface Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 06/30] DynamicTablesPkg: AML tree enumerator Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 07/30] DynamicTablesPkg: AML tree traversal Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 08/30] DynamicTablesPkg: AML tree iterator Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 09/30] DynamicTablesPkg: AML tree/node cloning Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 10/30] DynamicTablesPkg: AML utility interfaces Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 11/30] DynamicTablesPkg: AML and ASL string helper Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 12/30] DynamicTablesPkg: AML stream interface Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 13/30] DynamicTablesPkg: AML serialise interface Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 14/30] DynamicTablesPkg: AML debug logging Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 15/30] DynamicTablesPkg: AML ACPI Namespace interface Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 16/30] DynamicTablesPkg: AML Parser Sami Mujawar
2020-08-12 15:22 ` Sami Mujawar [this message]
2020-08-12 15:22 ` [PATCH v1 18/30] DynamicTablesPkg: AML resource data parser Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 19/30] DynamicTablesPkg: AML Method parser Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 20/30] DynamicTablesPkg: AML Field list parser Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 21/30] DynamicTablesPkg: AML Codegen Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 22/30] DynamicTablesPkg: AML Resource Data Codegen Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 23/30] DynamicTablesPkg: AML Core interface Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 24/30] DynamicTablesPkg: AmlLib APIs Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 25/30] DynamicTablesPkg: Dynamic AML: Add AmlLib library Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 26/30] DynamicTablesPkg: Add AsciiFromHex helper function Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 27/30] DynamicTablesPkg: SSDT Serial Port Fixup library Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 28/30] DynamicTablesPkg: SSDT Serial Port generator Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 29/30] DynamicTablesPkg: Add SSDT Serial port for SPCR Sami Mujawar
2020-08-12 15:22 ` [PATCH v1 30/30] DynamicTablesPkg: Add SSDT Serial port for DBG2 Sami Mujawar
2020-08-13 15:16 ` [edk2-devel] [PATCH v1 00/30] Add Dynamic AML generation support Alexei Fedorov

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=20200812152236.31164-18-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