+/** @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