]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Common/AmlLib/Api/AmlApiHelper.c
DynamicTablesPkg: Apply uncrustify changes
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / AmlLib / Api / AmlApiHelper.c
CommitLineData
c85ac524
PG
1/** @file\r
2 AML Helper.\r
3\r
4 Copyright (c) 2020, Arm Limited. All rights reserved.<BR>\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
9/* Even though this file has access to the internal Node definition,\r
10 i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. Only the external node\r
11 handle types should be used, i.e. AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE,\r
12 etc.\r
13 Indeed, the functions in the "Api" folder should be implemented only\r
14 using the "safe" functions available in the "Include" folder. This\r
15 makes the functions available in the "Api" folder easy to export.\r
16*/\r
17#include <Api/AmlApiHelper.h>\r
18\r
19#include <AmlCoreInterface.h>\r
20#include <AmlInclude.h>\r
21#include <String/AmlString.h>\r
22\r
23/** Compare the NameString defined by the "Name ()" ASL function,\r
24 and stored in the NameOpNode, with the input NameString.\r
25\r
26 An ASL NameString is expected to be NULL terminated, and can be composed\r
27 of NameSegs that have less that 4 chars, like "DEV". "DEV" will be expanded\r
28 as "DEV_".\r
29\r
30 An AML NameString is not NULL terminated and is is only composed of\r
31 4 chars long NameSegs.\r
32\r
33 @param [in] NameOpNode NameOp object node defining a variable.\r
34 Must have an AML_NAME_OP/0 OpCode/SubOpCode.\r
35 NameOp object nodes are defined in ASL\r
36 using the "Name ()" function.\r
37 @param [in] AslName ASL NameString to compare the NameOp's name with.\r
38 Must be NULL terminated.\r
39\r
40 @retval TRUE If the AslName and the AmlName defined by the NameOp node\r
41 are similar.\r
42 @retval FALSE Otherwise.\r
43**/\r
44BOOLEAN\r
45EFIAPI\r
46AmlNameOpCompareName (\r
731c67e1
MK
47 IN AML_OBJECT_NODE_HANDLE NameOpNode,\r
48 IN CHAR8 *AslName\r
c85ac524
PG
49 )\r
50{\r
731c67e1
MK
51 EFI_STATUS Status;\r
52 AML_DATA_NODE_HANDLE NameDataNode;\r
c85ac524 53\r
731c67e1
MK
54 CHAR8 *AmlName;\r
55 UINT32 AmlNameSize;\r
c85ac524 56\r
731c67e1 57 BOOLEAN RetVal;\r
c85ac524
PG
58\r
59 if ((NameOpNode == NULL) ||\r
60 (AmlGetNodeType ((AML_NODE_HANDLE)NameOpNode) != EAmlNodeObject) ||\r
61 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)) ||\r
731c67e1
MK
62 (AslName == NULL))\r
63 {\r
c85ac524
PG
64 ASSERT (0);\r
65 return FALSE;\r
66 }\r
67\r
68 // Get the NameOp name, being in a data node\r
69 // which is the first fixed argument (i.e. index 0).\r
70 NameDataNode = (AML_DATA_NODE_HANDLE)AmlGetFixedArgument (\r
71 NameOpNode,\r
72 EAmlParseIndexTerm0\r
73 );\r
74 if ((NameDataNode == NULL) ||\r
75 (AmlGetNodeType ((AML_NODE_HANDLE)NameDataNode) != EAmlNodeData) ||\r
731c67e1
MK
76 (!AmlNodeHasDataType (NameDataNode, EAmlNodeDataTypeNameString)))\r
77 {\r
c85ac524
PG
78 ASSERT (0);\r
79 return FALSE;\r
80 }\r
81\r
82 // Get the size of the name.\r
83 Status = AmlGetDataNodeBuffer (NameDataNode, NULL, &AmlNameSize);\r
84 if (EFI_ERROR (Status)) {\r
85 ASSERT (0);\r
86 return FALSE;\r
87 }\r
88\r
89 // Allocate memory to fetch the name.\r
90 AmlName = AllocateZeroPool (AmlNameSize);\r
91 if (AmlName == NULL) {\r
92 ASSERT (0);\r
93 return FALSE;\r
94 }\r
95\r
96 // Fetch the name.\r
731c67e1 97 Status = AmlGetDataNodeBuffer (NameDataNode, (UINT8 *)AmlName, &AmlNameSize);\r
c85ac524
PG
98 if (EFI_ERROR (Status)) {\r
99 FreePool (AmlName);\r
100 ASSERT (0);\r
101 return FALSE;\r
102 }\r
103\r
104 // Compare the input AslName and the AmlName stored in the NameOp node.\r
105 RetVal = CompareAmlWithAslNameString (AmlName, AslName);\r
106\r
107 // Free the string buffer.\r
108 FreePool (AmlName);\r
109 return RetVal;\r
110}\r
111\r
112/** Check whether ObjectNode has the input OpCode/SubOpcode couple.\r
113\r
114 @param [in] ObjectNode Pointer to an object node.\r
115 @param [in] OpCode OpCode to check\r
116 @param [in] SubOpCode SubOpCode to check\r
117\r
118 @retval TRUE The node is an object node and\r
119 the Opcode and SubOpCode match.\r
120 @retval FALSE Otherwise.\r
121**/\r
122BOOLEAN\r
123EFIAPI\r
124AmlNodeHasOpCode (\r
731c67e1
MK
125 IN AML_OBJECT_NODE_HANDLE ObjectNode,\r
126 IN UINT8 OpCode,\r
127 IN UINT8 SubOpCode\r
c85ac524
PG
128 )\r
129{\r
731c67e1
MK
130 EFI_STATUS Status;\r
131 UINT8 NodeOpCode;\r
132 UINT8 NodeSubOpCode;\r
c85ac524
PG
133\r
134 // Get the Node information.\r
135 Status = AmlGetObjectNodeInfo (\r
136 ObjectNode,\r
137 &NodeOpCode,\r
138 &NodeSubOpCode,\r
139 NULL,\r
140 NULL\r
141 );\r
142 if (EFI_ERROR (Status)) {\r
143 ASSERT (0);\r
144 return FALSE;\r
145 }\r
146\r
147 // Check the OpCode and SubOpCode.\r
148 if ((OpCode != NodeOpCode) ||\r
731c67e1
MK
149 (SubOpCode != NodeSubOpCode))\r
150 {\r
c85ac524
PG
151 return FALSE;\r
152 }\r
153\r
154 return TRUE;\r
155}\r
156\r
157/** Check whether DataNode has the input DataType.\r
158\r
159 @param [in] DataNode Pointer to a data node.\r
160 @param [in] DataType DataType to check.\r
161\r
162 @retval TRUE The node is a data node and\r
163 the DataType match.\r
164 @retval FALSE Otherwise.\r
165**/\r
166BOOLEAN\r
167EFIAPI\r
168AmlNodeHasDataType (\r
731c67e1
MK
169 IN AML_DATA_NODE_HANDLE DataNode,\r
170 IN EAML_NODE_DATA_TYPE DataType\r
c85ac524
PG
171 )\r
172{\r
731c67e1
MK
173 EFI_STATUS Status;\r
174 EAML_NODE_DATA_TYPE NodeDataType;\r
c85ac524
PG
175\r
176 // Get the data type.\r
177 Status = AmlGetNodeDataType (DataNode, &NodeDataType);\r
178 if (EFI_ERROR (Status)) {\r
179 ASSERT (0);\r
180 return FALSE;\r
181 }\r
182\r
183 // Check the data type.\r
184 if (NodeDataType != DataType) {\r
185 return FALSE;\r
186 }\r
187\r
188 return TRUE;\r
189}\r
190\r
191/** Check whether RdNode has the input RdDataType.\r
192\r
193 @param [in] RdNode Pointer to a data node.\r
194 @param [in] RdDataType DataType to check.\r
195\r
196 @retval TRUE The node is a Resource Data node and\r
197 the RdDataType match.\r
198 @retval FALSE Otherwise.\r
199**/\r
200BOOLEAN\r
201EFIAPI\r
202AmlNodeHasRdDataType (\r
731c67e1
MK
203 IN AML_DATA_NODE_HANDLE RdNode,\r
204 IN AML_RD_HEADER RdDataType\r
c85ac524
PG
205 )\r
206{\r
731c67e1
MK
207 EFI_STATUS Status;\r
208 AML_RD_HEADER NodeRdDataType;\r
c85ac524
PG
209\r
210 // Get the resource data type.\r
211 Status = AmlGetResourceDataType (\r
212 RdNode,\r
213 &NodeRdDataType\r
214 );\r
215 if (EFI_ERROR (Status)) {\r
216 ASSERT (0);\r
217 return FALSE;\r
218 }\r
219\r
220 // Check the RdDataType.\r
221 return AmlRdCompareDescId (&NodeRdDataType, RdDataType);\r
222}\r