]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: AML resource data helper
authorPierre Gondois <pierre.gondois@arm.com>
Tue, 4 Aug 2020 14:50:24 +0000 (15:50 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 13 Aug 2020 18:00:06 +0000 (18:00 +0000)
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>
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c [new file with mode: 0644]
DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h [new file with mode: 0644]

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