summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRebecca Cran <quic_rcran@quicinc.com>2022-01-13 09:40:52 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-02-02 18:38:55 +0000
commit33189f05278345eab608ff56e87905bdeacdbd47 (patch)
tree90533dd67798eb6be032e7c863c73a43f6b9cc3a
parent007a95055b2cad8930caf2ff7615dd0dbb189b6a (diff)
downloadedk2-33189f05278345eab608ff56e87905bdeacdbd47.tar.gz
edk2-33189f05278345eab608ff56e87905bdeacdbd47.tar.bz2
edk2-33189f05278345eab608ff56e87905bdeacdbd47.zip
DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function
Add AmlCodeGenMethodRetInteger function to generate AML code for a Method returning an Integer. Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
-rw-r--r--DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h47
-rw-r--r--DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c159
2 files changed, 206 insertions, 0 deletions
diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
index 80d05f74ee..6f214c0dfa 100644
--- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
+++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
@@ -1118,6 +1118,53 @@ AmlCodeGenMethodRetNameString (
OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
);
+/** AML code generation for a method returning an Integer.
+
+ AmlCodeGenMethodRetInteger (
+ "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode
+ );
+ is equivalent of the following ASL code:
+ Method(_CBA, 1, Serialized, 3) {
+ Return (0)
+ }
+
+ The ASL parameters "ReturnType" and "ParameterTypes" are not asked
+ in this function. They are optional parameters in ASL.
+
+ @param [in] MethodNameString The new Method's name.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "MET0", "_SB.MET0", etc.
+ The input string is copied.
+ @param [in] ReturnedInteger The value of the integer returned by the
+ method.
+ @param [in] NumArgs Number of arguments.
+ Must be 0 <= NumArgs <= 6.
+ @param [in] IsSerialized TRUE is equivalent to Serialized.
+ FALSE is equivalent to NotSerialized.
+ Default is NotSerialized in ASL spec.
+ @param [in] SyncLevel Synchronization level for the method.
+ Must be 0 <= SyncLevel <= 15.
+ Default is 0 in ASL.
+ @param [in] ParentNode If provided, set ParentNode as the parent
+ of the node created.
+ @param [out] NewObjectNode If success, contains the created node.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenMethodRetInteger (
+ IN CONST CHAR8 *MethodNameString,
+ IN UINT64 ReturnedInteger,
+ IN UINT8 NumArgs,
+ IN BOOLEAN IsSerialized,
+ IN UINT8 SyncLevel,
+ IN AML_NODE_HANDLE ParentNode OPTIONAL,
+ OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
+ );
+
/** Create a _LPI name.
AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
index 6229d10e28..e51d2dd7f0 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
@@ -1706,6 +1706,64 @@ exit_handler:
return Status;
}
+/** AML code generation for a Return object node,
+ returning an Integer.
+
+ AmlCodeGenReturn (0), ParentNode, NewObjectNode) is
+ equivalent of the following ASL code:
+ Return (0)
+
+ The ACPI 6.3 specification, 20.2.8 "Statement Opcodes Encoding" states:
+ DefReturn := ReturnOp ArgObject
+ ReturnOp := 0xA4
+ ArgObject := TermArg => DataRefObject
+
+ Thus, the ReturnNode must be evaluated as a DataRefObject.
+
+ The ReturnNode must be generated inside a Method body scope.
+
+ @param [in] Integer The integer is returned by the Return
+ ASL statement.
+ @param [in] ParentNode If provided, set ParentNode as the parent
+ of the node created.
+ Must be a MethodOp node.
+ @param [out] NewObjectNode If success, contains the created node.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AmlCodeGenReturnInteger (
+ IN UINT64 Integer,
+ IN AML_NODE_HEADER *ParentNode OPTIONAL,
+ OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ AML_OBJECT_NODE *IntNode;
+
+ IntNode = NULL;
+
+ Status = AmlCodeGenInteger (Integer, &IntNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // AmlCodeGenReturn() deletes DataNode if error.
+ Status = AmlCodeGenReturn (
+ (AML_NODE_HEADER *)IntNode,
+ ParentNode,
+ NewObjectNode
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
+
/** AML code generation for a method returning a NameString.
AmlCodeGenMethodRetNameString (
@@ -1814,6 +1872,107 @@ error_handler:
return Status;
}
+/** AML code generation for a method returning an Integer.
+
+ AmlCodeGenMethodRetInteger (
+ "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode
+ );
+ is equivalent of the following ASL code:
+ Method(_CBA, 1, Serialized, 3) {
+ Return (0)
+ }
+
+ The ASL parameters "ReturnType" and "ParameterTypes" are not asked
+ in this function. They are optional parameters in ASL.
+
+ @param [in] MethodNameString The new Method's name.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "MET0", "_SB.MET0", etc.
+ The input string is copied.
+ @param [in] ReturnedInteger The value of the integer returned by the
+ method.
+ @param [in] NumArgs Number of arguments.
+ Must be 0 <= NumArgs <= 6.
+ @param [in] IsSerialized TRUE is equivalent to Serialized.
+ FALSE is equivalent to NotSerialized.
+ Default is NotSerialized in ASL spec.
+ @param [in] SyncLevel Synchronization level for the method.
+ Must be 0 <= SyncLevel <= 15.
+ Default is 0 in ASL.
+ @param [in] ParentNode If provided, set ParentNode as the parent
+ of the node created.
+ @param [out] NewObjectNode If success, contains the created node.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenMethodRetInteger (
+ IN CONST CHAR8 *MethodNameString,
+ IN UINT64 ReturnedInteger,
+ IN UINT8 NumArgs,
+ IN BOOLEAN IsSerialized,
+ IN UINT8 SyncLevel,
+ IN AML_NODE_HANDLE ParentNode OPTIONAL,
+ OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ AML_OBJECT_NODE_HANDLE MethodNode;
+
+ if ((MethodNameString == NULL) ||
+ ((ParentNode == NULL) && (NewObjectNode == NULL)))
+ {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Create a Method named MethodNameString.
+ Status = AmlCodeGenMethod (
+ MethodNameString,
+ NumArgs,
+ IsSerialized,
+ SyncLevel,
+ NULL,
+ &MethodNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ Status = AmlCodeGenReturnInteger (
+ ReturnedInteger,
+ (AML_NODE_HANDLE)MethodNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ Status = LinkNode (
+ MethodNode,
+ ParentNode,
+ NewObjectNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ return Status;
+
+error_handler:
+ if (MethodNode != NULL) {
+ AmlDeleteTree ((AML_NODE_HANDLE)MethodNode);
+ }
+
+ return Status;
+}
+
/** Create a _LPI name.
AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is