TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlApiHelper.c
Go to the documentation of this file.
1
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,
12 etc.
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.
16*/
17#include <Api/AmlApiHelper.h>
18
19#include <AmlCoreInterface.h>
20#include <AmlInclude.h>
21#include <String/AmlString.h>
22
44BOOLEAN
45EFIAPI
47 IN AML_OBJECT_NODE_HANDLE NameOpNode,
48 IN CHAR8 *AslName
49 )
50{
51 EFI_STATUS Status;
52 AML_DATA_NODE_HANDLE NameDataNode;
53
54 CHAR8 *AmlName;
55 UINT32 AmlNameSize;
56
57 BOOLEAN RetVal;
58
59 if ((NameOpNode == NULL) ||
61 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)) ||
62 (AslName == NULL))
63 {
64 ASSERT (0);
65 return FALSE;
66 }
67
68 // Get the NameOp name, being in a data node
69 // which is the first fixed argument (i.e. index 0).
71 NameOpNode,
73 );
74 if ((NameDataNode == NULL) ||
75 (AmlGetNodeType ((AML_NODE_HANDLE)NameDataNode) != EAmlNodeData) ||
77 {
78 ASSERT (0);
79 return FALSE;
80 }
81
82 // Get the size of the name.
83 Status = AmlGetDataNodeBuffer (NameDataNode, NULL, &AmlNameSize);
84 if (EFI_ERROR (Status)) {
85 ASSERT (0);
86 return FALSE;
87 }
88
89 // Allocate memory to fetch the name.
90 AmlName = AllocateZeroPool (AmlNameSize);
91 if (AmlName == NULL) {
92 ASSERT (0);
93 return FALSE;
94 }
95
96 // Fetch the name.
97 Status = AmlGetDataNodeBuffer (NameDataNode, (UINT8 *)AmlName, &AmlNameSize);
98 if (EFI_ERROR (Status)) {
99 FreePool (AmlName);
100 ASSERT (0);
101 return FALSE;
102 }
103
104 // Compare the input AslName and the AmlName stored in the NameOp node.
105 RetVal = CompareAmlWithAslNameString (AmlName, AslName);
106
107 // Free the string buffer.
108 FreePool (AmlName);
109 return RetVal;
110}
111
122BOOLEAN
123EFIAPI
125 IN AML_OBJECT_NODE_HANDLE ObjectNode,
126 IN UINT8 OpCode,
127 IN UINT8 SubOpCode
128 )
129{
130 EFI_STATUS Status;
131 UINT8 NodeOpCode;
132 UINT8 NodeSubOpCode;
133
134 // Get the Node information.
135 Status = AmlGetObjectNodeInfo (
136 ObjectNode,
137 &NodeOpCode,
138 &NodeSubOpCode,
139 NULL,
140 NULL
141 );
142 if (EFI_ERROR (Status)) {
143 ASSERT (0);
144 return FALSE;
145 }
146
147 // Check the OpCode and SubOpCode.
148 if ((OpCode != NodeOpCode) ||
149 (SubOpCode != NodeSubOpCode))
150 {
151 return FALSE;
152 }
153
154 return TRUE;
155}
156
166BOOLEAN
167EFIAPI
169 IN AML_DATA_NODE_HANDLE DataNode,
170 IN EAML_NODE_DATA_TYPE DataType
171 )
172{
173 EFI_STATUS Status;
174 EAML_NODE_DATA_TYPE NodeDataType;
175
176 // Get the data type.
177 Status = AmlGetNodeDataType (DataNode, &NodeDataType);
178 if (EFI_ERROR (Status)) {
179 ASSERT (0);
180 return FALSE;
181 }
182
183 // Check the data type.
184 if (NodeDataType != DataType) {
185 return FALSE;
186 }
187
188 return TRUE;
189}
190
200BOOLEAN
201EFIAPI
204 IN AML_RD_HEADER RdDataType
205 )
206{
207 EFI_STATUS Status;
208 AML_RD_HEADER NodeRdDataType;
209
210 // Get the resource data type.
211 Status = AmlGetResourceDataType (
212 RdNode,
213 &NodeRdDataType
214 );
215 if (EFI_ERROR (Status)) {
216 ASSERT (0);
217 return FALSE;
218 }
219
220 // Check the RdDataType.
221 return AmlRdCompareDescId (&NodeRdDataType, RdDataType);
222}
BOOLEAN EFIAPI AmlNodeHasDataType(IN AML_DATA_NODE_HANDLE DataNode, IN EAML_NODE_DATA_TYPE DataType)
Definition: AmlApiHelper.c:168
BOOLEAN EFIAPI AmlNameOpCompareName(IN AML_OBJECT_NODE_HANDLE NameOpNode, IN CHAR8 *AslName)
Definition: AmlApiHelper.c:46
BOOLEAN EFIAPI AmlNodeHasOpCode(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: AmlApiHelper.c:124
BOOLEAN EFIAPI AmlNodeHasRdDataType(IN AML_DATA_NODE_HANDLE RdNode, IN AML_RD_HEADER RdDataType)
Definition: AmlApiHelper.c:202
void * AML_DATA_NODE_HANDLE
Definition: AmlLib.h:59
void * AML_OBJECT_NODE_HANDLE
Definition: AmlLib.h:55
void * AML_NODE_HANDLE
Definition: AmlLib.h:47
UINT8 AML_RD_HEADER
BOOLEAN EFIAPI CompareAmlWithAslNameString(IN CONST CHAR8 *AmlName1, IN CONST CHAR8 *AslName2)
Definition: AmlString.c:971
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
AML_NODE_HANDLE EFIAPI AmlGetFixedArgument(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN EAML_PARSE_INDEX Index)
EFI_STATUS EFIAPI AmlGetDataNodeBuffer(IN AML_DATA_NODE_HANDLE DataNode, OUT UINT8 *Buffer OPTIONAL, IN OUT UINT32 *BufferSize)
EFI_STATUS EFIAPI AmlGetObjectNodeInfo(IN AML_OBJECT_NODE_HANDLE ObjectNode, OUT UINT8 *OpCode OPTIONAL, OUT UINT8 *SubOpCode OPTIONAL, OUT UINT32 *PkgLen OPTIONAL, OUT BOOLEAN *IsNameSpaceNode OPTIONAL)
EFI_STATUS EFIAPI AmlGetResourceDataType(IN AML_DATA_NODE_HANDLE DataNode, OUT AML_RD_HEADER *ResourceDataType)
EFI_STATUS EFIAPI AmlGetNodeDataType(IN AML_DATA_NODE_HANDLE DataNode, OUT EAML_NODE_DATA_TYPE *DataType)
EAML_NODE_TYPE EFIAPI AmlGetNodeType(IN AML_NODE_HANDLE Node)
BOOLEAN EFIAPI AmlRdCompareDescId(IN CONST AML_RD_HEADER *Header, IN AML_RD_HEADER DescriptorId)
enum EAmlNodeDataType EAML_NODE_DATA_TYPE
@ EAmlParseIndexTerm0
First fixed argument index.
Definition: AmlDefines.h:65
@ EAmlNodeData
Definition: AmlDefines.h:176
@ EAmlNodeObject
Definition: AmlDefines.h:174
@ EAmlNodeDataTypeNameString
Definition: AmlDefines.h:37