summaryrefslogtreecommitdiff
path: root/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
diff options
context:
space:
mode:
authorPierre Gondois <Pierre.Gondois@arm.com>2021-10-08 15:46:23 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-10-08 15:39:42 +0000
commit1e33479b393902b97821ab8a0ef321045804c013 (patch)
tree9753a7e1c5e9b1211ceee3427c7111df06b0499f /DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
parent9454d1ebcbee01ccf504ea7e8bf7d7e83a8e99e2 (diff)
downloadedk2-1e33479b393902b97821ab8a0ef321045804c013.zip
edk2-1e33479b393902b97821ab8a0ef321045804c013.tar.gz
edk2-1e33479b393902b97821ab8a0ef321045804c013.tar.bz2
DynamicTablesPkg: AML code generation for a Package
Add AmlCodeGenPackage() to generate AML code for declaring a Package() object. This function generates an empty package node. New elements can then be added to the package's variable argument list. Reviewed-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Diffstat (limited to 'DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c')
-rw-r--r--DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
index cbfd9cb..a4cd250 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
@@ -1,7 +1,7 @@
/** @file
AML Code Generation.
- Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -237,6 +237,85 @@ AmlCodeGenInteger (
return Status;
}
+/** AML code generation for a Package object node.
+
+ The package generated is empty. New elements can be added via its
+ list of variable arguments.
+
+ @param [out] NewObjectNode If success, contains the created
+ Package object node.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AmlCodeGenPackage (
+ OUT AML_OBJECT_NODE ** NewObjectNode
+ )
+{
+ EFI_STATUS Status;
+ AML_DATA_NODE * DataNode;
+ UINT8 NodeCount;
+
+ if (NewObjectNode == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ NodeCount = 0;
+
+ // Create an object node.
+ // PkgLen is 2:
+ // - one byte to store the PkgLength
+ // - one byte for the NumElements.
+ // Cf ACPI6.3, s20.2.5 "Term Objects Encoding"
+ // DefPackage := PackageOp PkgLength NumElements PackageElementList
+ // NumElements := ByteData
+ Status = AmlCreateObjectNode (
+ AmlGetByteEncodingByOpCode (AML_PACKAGE_OP, 0),
+ 2,
+ NewObjectNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // NumElements is a ByteData.
+ Status = AmlCreateDataNode (
+ EAmlNodeDataTypeUInt,
+ &NodeCount,
+ sizeof (NodeCount),
+ &DataNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ Status = AmlSetFixedArgument (
+ *NewObjectNode,
+ EAmlParseIndexTerm0,
+ (AML_NODE_HEADER*)DataNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ return Status;
+
+error_handler:
+ AmlDeleteTree ((AML_NODE_HEADER*)*NewObjectNode);
+ if (DataNode != NULL) {
+ AmlDeleteTree ((AML_NODE_HEADER*)DataNode);
+ }
+ return Status;
+}
+
/** AML code generation for a Name object node.
@param [in] NameString The new variable name.