4 Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 /* Even though this file has access to the internal Node definition,
10 i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. Only the external node
11 handle types should be used, i.e. AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE,
13 Indeed, the functions in the "Api" folder should be implemented only
14 using the "safe" functions available in the "Include" folder. This
15 makes the functions available in the "Api" folder easy to export.
17 #include <Api/AmlApiHelper.h>
19 #include <AmlCoreInterface.h>
20 #include <AmlInclude.h>
21 #include <String/AmlString.h>
23 /** Compare the NameString defined by the "Name ()" ASL function,
24 and stored in the NameOpNode, with the input NameString.
26 An ASL NameString is expected to be NULL terminated, and can be composed
27 of NameSegs that have less that 4 chars, like "DEV". "DEV" will be expanded
30 An AML NameString is not NULL terminated and is is only composed of
31 4 chars long NameSegs.
33 @param [in] NameOpNode NameOp object node defining a variable.
34 Must have an AML_NAME_OP/0 OpCode/SubOpCode.
35 NameOp object nodes are defined in ASL
36 using the "Name ()" function.
37 @param [in] AslName ASL NameString to compare the NameOp's name with.
38 Must be NULL terminated.
40 @retval TRUE If the AslName and the AmlName defined by the NameOp node
42 @retval FALSE Otherwise.
46 AmlNameOpCompareName (
47 IN AML_OBJECT_NODE_HANDLE NameOpNode
,
52 AML_DATA_NODE_HANDLE NameDataNode
;
59 if ((NameOpNode
== NULL
) ||
60 (AmlGetNodeType ((AML_NODE_HANDLE
)NameOpNode
) != EAmlNodeObject
) ||
61 (!AmlNodeHasOpCode (NameOpNode
, AML_NAME_OP
, 0)) ||
68 // Get the NameOp name, being in a data node
69 // which is the first fixed argument (i.e. index 0).
70 NameDataNode
= (AML_DATA_NODE_HANDLE
)AmlGetFixedArgument (
74 if ((NameDataNode
== NULL
) ||
75 (AmlGetNodeType ((AML_NODE_HANDLE
)NameDataNode
) != EAmlNodeData
) ||
76 (!AmlNodeHasDataType (NameDataNode
, EAmlNodeDataTypeNameString
)))
82 // Get the size of the name.
83 Status
= AmlGetDataNodeBuffer (NameDataNode
, NULL
, &AmlNameSize
);
84 if (EFI_ERROR (Status
)) {
89 // Allocate memory to fetch the name.
90 AmlName
= AllocateZeroPool (AmlNameSize
);
91 if (AmlName
== NULL
) {
97 Status
= AmlGetDataNodeBuffer (NameDataNode
, (UINT8
*)AmlName
, &AmlNameSize
);
98 if (EFI_ERROR (Status
)) {
104 // Compare the input AslName and the AmlName stored in the NameOp node.
105 RetVal
= CompareAmlWithAslNameString (AmlName
, AslName
);
107 // Free the string buffer.
112 /** Check whether ObjectNode has the input OpCode/SubOpcode couple.
114 @param [in] ObjectNode Pointer to an object node.
115 @param [in] OpCode OpCode to check
116 @param [in] SubOpCode SubOpCode to check
118 @retval TRUE The node is an object node and
119 the Opcode and SubOpCode match.
120 @retval FALSE Otherwise.
125 IN AML_OBJECT_NODE_HANDLE ObjectNode
,
134 // Get the Node information.
135 Status
= AmlGetObjectNodeInfo (
142 if (EFI_ERROR (Status
)) {
147 // Check the OpCode and SubOpCode.
148 if ((OpCode
!= NodeOpCode
) ||
149 (SubOpCode
!= NodeSubOpCode
))
157 /** Check whether DataNode has the input DataType.
159 @param [in] DataNode Pointer to a data node.
160 @param [in] DataType DataType to check.
162 @retval TRUE The node is a data node and
164 @retval FALSE Otherwise.
169 IN AML_DATA_NODE_HANDLE DataNode
,
170 IN EAML_NODE_DATA_TYPE DataType
174 EAML_NODE_DATA_TYPE NodeDataType
;
176 // Get the data type.
177 Status
= AmlGetNodeDataType (DataNode
, &NodeDataType
);
178 if (EFI_ERROR (Status
)) {
183 // Check the data type.
184 if (NodeDataType
!= DataType
) {
191 /** Check whether RdNode has the input RdDataType.
193 @param [in] RdNode Pointer to a data node.
194 @param [in] RdDataType DataType to check.
196 @retval TRUE The node is a Resource Data node and
197 the RdDataType match.
198 @retval FALSE Otherwise.
202 AmlNodeHasRdDataType (
203 IN AML_DATA_NODE_HANDLE RdNode
,
204 IN AML_RD_HEADER RdDataType
208 AML_RD_HEADER NodeRdDataType
;
210 // Get the resource data type.
211 Status
= AmlGetResourceDataType (
215 if (EFI_ERROR (Status
)) {
220 // Check the RdDataType.
221 return AmlRdCompareDescId (&NodeRdDataType
, RdDataType
);