summaryrefslogtreecommitdiffstats
path: root/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
diff options
context:
space:
mode:
authorPierre Gondois <pierre.gondois@arm.com>2020-08-04 15:50:24 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-08-13 18:00:06 +0000
commit422e93e1de6f265ff48eaacc8cf7c44d6401062e (patch)
tree10c95bb2d416fb63964a78c9aad14d33ce87c6dd /DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
parent9f2d50f145191733e502667327c2129034a93099 (diff)
downloadedk2-422e93e1de6f265ff48eaacc8cf7c44d6401062e.tar.gz
edk2-422e93e1de6f265ff48eaacc8cf7c44d6401062e.tar.bz2
edk2-422e93e1de6f265ff48eaacc8cf7c44d6401062e.zip
DynamicTablesPkg: AML resource data helper
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>
Diffstat (limited to 'DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c')
-rw-r--r--DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
new file mode 100644
index 0000000000..8b46c7232d
--- /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);
+}