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)) ||
67 // Get the NameOp name, being in a data node
68 // which is the first fixed argument (i.e. index 0).
69 NameDataNode
= (AML_DATA_NODE_HANDLE
)AmlGetFixedArgument (
73 if ((NameDataNode
== NULL
) ||
74 (AmlGetNodeType ((AML_NODE_HANDLE
)NameDataNode
) != EAmlNodeData
) ||
75 (!AmlNodeHasDataType (NameDataNode
, EAmlNodeDataTypeNameString
))) {
80 // Get the size of the name.
81 Status
= AmlGetDataNodeBuffer (NameDataNode
, NULL
, &AmlNameSize
);
82 if (EFI_ERROR (Status
)) {
87 // Allocate memory to fetch the name.
88 AmlName
= AllocateZeroPool (AmlNameSize
);
89 if (AmlName
== NULL
) {
95 Status
= AmlGetDataNodeBuffer (NameDataNode
, (UINT8
*)AmlName
, &AmlNameSize
);
96 if (EFI_ERROR (Status
)) {
102 // Compare the input AslName and the AmlName stored in the NameOp node.
103 RetVal
= CompareAmlWithAslNameString (AmlName
, AslName
);
105 // Free the string buffer.
110 /** Check whether ObjectNode has the input OpCode/SubOpcode couple.
112 @param [in] ObjectNode Pointer to an object node.
113 @param [in] OpCode OpCode to check
114 @param [in] SubOpCode SubOpCode to check
116 @retval TRUE The node is an object node and
117 the Opcode and SubOpCode match.
118 @retval FALSE Otherwise.
123 IN AML_OBJECT_NODE_HANDLE ObjectNode
,
132 // Get the Node information.
133 Status
= AmlGetObjectNodeInfo (
140 if (EFI_ERROR (Status
)) {
145 // Check the OpCode and SubOpCode.
146 if ((OpCode
!= NodeOpCode
) ||
147 (SubOpCode
!= NodeSubOpCode
)) {
154 /** Check whether DataNode has the input DataType.
156 @param [in] DataNode Pointer to a data node.
157 @param [in] DataType DataType to check.
159 @retval TRUE The node is a data node and
161 @retval FALSE Otherwise.
166 IN AML_DATA_NODE_HANDLE DataNode
,
167 IN EAML_NODE_DATA_TYPE DataType
171 EAML_NODE_DATA_TYPE NodeDataType
;
173 // Get the data type.
174 Status
= AmlGetNodeDataType (DataNode
, &NodeDataType
);
175 if (EFI_ERROR (Status
)) {
180 // Check the data type.
181 if (NodeDataType
!= DataType
) {
188 /** Check whether RdNode has the input RdDataType.
190 @param [in] RdNode Pointer to a data node.
191 @param [in] RdDataType DataType to check.
193 @retval TRUE The node is a Resource Data node and
194 the RdDataType match.
195 @retval FALSE Otherwise.
199 AmlNodeHasRdDataType (
200 IN AML_DATA_NODE_HANDLE RdNode
,
201 IN AML_RD_HEADER RdDataType
205 AML_RD_HEADER NodeRdDataType
;
207 // Get the resource data type.
208 Status
= AmlGetResourceDataType (
212 if (EFI_ERROR (Status
)) {
217 // Check the RdDataType.
218 return AmlRdCompareDescId (&NodeRdDataType
, RdDataType
);