TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlTreeIterator.c
Go to the documentation of this file.
1
9#include <AmlNodeDefines.h>
11
12#include <AmlCoreInterface.h>
14
23
24 // Note: The following members of this structure are opaque to the users
25 // of the Tree iterator APIs.
26
29
32
37
48EFIAPI
50 IN AML_TREE_ITERATOR *Iterator,
51 OUT AML_NODE_HEADER **OutNode
52 )
53{
54 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
55
56 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)Iterator;
57
58 // CurrentNode can be NULL, but InitialNode cannot.
59 if ((OutNode == NULL) ||
60 (InternalIterator == NULL) ||
61 (InternalIterator->Mode <= EAmlIteratorUnknown) ||
62 (InternalIterator->Mode >= EAmlIteratorModeMax) ||
63 !IS_AML_NODE_VALID (InternalIterator->InitialNode) ||
64 ((InternalIterator->CurrentNode != NULL) &&
65 !IS_AML_NODE_VALID (InternalIterator->CurrentNode)))
66 {
67 ASSERT (0);
68 return EFI_INVALID_PARAMETER;
69 }
70
71 *OutNode = (AML_NODE_HEADER *)InternalIterator->CurrentNode;
72
73 return EFI_SUCCESS;
74}
75
89EFIAPI
91 IN AML_TREE_ITERATOR *Iterator,
92 OUT AML_NODE_HEADER **NextNode
93 )
94{
95 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
96
97 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)Iterator;
98
99 // CurrentNode can be NULL, but InitialNode cannot.
100 if ((InternalIterator == NULL) ||
101 (InternalIterator->Mode != EAmlIteratorLinear) ||
102 !IS_AML_NODE_VALID (InternalIterator->InitialNode) ||
103 !IS_AML_NODE_VALID (InternalIterator->CurrentNode))
104 {
105 ASSERT (0);
106 return EFI_INVALID_PARAMETER;
107 }
108
109 // Get the next node according to the iteration mode.
110 InternalIterator->CurrentNode = AmlGetNextNode (
111 InternalIterator->CurrentNode
112 );
113
114 if (NextNode != NULL) {
115 *NextNode = (AML_NODE_HEADER *)InternalIterator->CurrentNode;
116 }
117
118 return EFI_SUCCESS;
119}
120
132STATIC
134EFIAPI
136 IN AML_TREE_ITERATOR *Iterator,
137 OUT AML_NODE_HEADER **PrevNode
138 )
139{
140 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
141
142 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)Iterator;
143
144 // CurrentNode can be NULL, but InitialNode cannot.
145 if ((InternalIterator == NULL) ||
146 (InternalIterator->Mode != EAmlIteratorLinear) ||
147 !IS_AML_NODE_VALID (InternalIterator->InitialNode) ||
148 !IS_AML_NODE_VALID (InternalIterator->CurrentNode))
149 {
150 ASSERT (0);
151 return EFI_INVALID_PARAMETER;
152 }
153
154 // Get the previous node according to the iteration mode.
155 InternalIterator->CurrentNode = AmlGetPreviousNode (
156 InternalIterator->CurrentNode
157 );
158 if (PrevNode != NULL) {
159 *PrevNode = (AML_NODE_HEADER *)InternalIterator->CurrentNode;
160 }
161
162 return EFI_SUCCESS;
163}
164
176STATIC
178EFIAPI
180 IN AML_TREE_ITERATOR *Iterator,
181 OUT AML_NODE_HEADER **NextNode
182 )
183{
184 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
185 AML_NODE_HEADER *Node;
186
187 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)Iterator;
188
189 // CurrentNode can be NULL, but InitialNode cannot.
190 if ((InternalIterator == NULL) ||
191 (InternalIterator->Mode != EAmlIteratorBranch) ||
192 !IS_AML_NODE_VALID (InternalIterator->InitialNode) ||
193 !IS_AML_NODE_VALID (InternalIterator->CurrentNode))
194 {
195 ASSERT (0);
196 return EFI_INVALID_PARAMETER;
197 }
198
199 Node = AmlGetNextNode (InternalIterator->CurrentNode);
200 // Check whether NextNode is a sibling of InitialNode.
201 if (AmlGetParent (Node) ==
202 AmlGetParent ((AML_NODE_HEADER *)InternalIterator->InitialNode))
203 {
204 Node = NULL;
205 }
206
207 InternalIterator->CurrentNode = Node;
208
209 if (NextNode != NULL) {
210 *NextNode = Node;
211 }
212
213 return EFI_SUCCESS;
214}
215
227STATIC
229EFIAPI
231 IN AML_TREE_ITERATOR *Iterator,
232 OUT AML_NODE_HEADER **PrevNode
233 )
234{
235 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
236 AML_NODE_HEADER *Node;
237
238 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)Iterator;
239
240 // CurrentNode can be NULL, but InitialNode cannot.
241 if ((InternalIterator == NULL) ||
242 (InternalIterator->Mode != EAmlIteratorBranch) ||
243 !IS_AML_NODE_VALID (InternalIterator->InitialNode) ||
244 !IS_AML_NODE_VALID (InternalIterator->CurrentNode))
245 {
246 ASSERT (0);
247 return EFI_INVALID_PARAMETER;
248 }
249
250 Node = AmlGetPreviousNode (InternalIterator->CurrentNode);
251 // Check whether PreviousNode is a sibling of InitialNode.
252 if (AmlGetParent (Node) ==
253 AmlGetParent ((AML_NODE_HEADER *)InternalIterator->InitialNode))
254 {
255 Node = NULL;
256 }
257
258 InternalIterator->CurrentNode = Node;
259
260 if (PrevNode != NULL) {
261 *PrevNode = Node;
262 }
263
264 return EFI_SUCCESS;
265}
266
281EFIAPI
283 IN AML_NODE_HEADER *Node,
284 IN EAML_ITERATOR_MODE IteratorMode,
285 OUT AML_TREE_ITERATOR **IteratorPtr
286 )
287{
288 AML_TREE_ITERATOR_INTERNAL *InternalIterator;
289
290 if (!IS_AML_NODE_VALID (Node) ||
291 (IteratorMode <= EAmlIteratorUnknown) ||
292 (IteratorMode >= EAmlIteratorModeMax) ||
293 (IteratorPtr == NULL))
294 {
295 ASSERT (0);
296 return EFI_INVALID_PARAMETER;
297 }
298
299 *IteratorPtr = NULL;
300 InternalIterator = (AML_TREE_ITERATOR_INTERNAL *)AllocateZeroPool (
301 sizeof (
303 )
304 );
305 if (InternalIterator == NULL) {
306 ASSERT (0);
307 return EFI_OUT_OF_RESOURCES;
308 }
309
310 InternalIterator->InitialNode = Node;
311 InternalIterator->CurrentNode = Node;
312 InternalIterator->Mode = IteratorMode;
313 InternalIterator->Iterator.GetNode = AmlIteratorGetNode;
314
315 switch (InternalIterator->Mode) {
317 {
318 InternalIterator->Iterator.GetNext = AmlIteratorGetNextLinear;
320 break;
321 }
323 {
324 InternalIterator->Iterator.GetNext = AmlIteratorGetNextBranch;
326 break;
327 }
328 default:
329 {
330 ASSERT (0);
331 FreePool (InternalIterator);
332 return EFI_INVALID_PARAMETER;
333 }
334 } // switch
335
336 *IteratorPtr = &InternalIterator->Iterator;
337
338 return EFI_SUCCESS;
339}
340
352EFIAPI
354 IN AML_TREE_ITERATOR *Iterator
355 )
356{
357 if (Iterator == NULL) {
358 ASSERT (0);
359 return EFI_INVALID_PARAMETER;
360 }
361
362 FreePool (Iterator);
363
364 return EFI_SUCCESS;
365}
#define IS_AML_NODE_VALID(Node)
STATIC EFI_STATUS EFIAPI AmlIteratorGetNextBranch(IN AML_TREE_ITERATOR *Iterator, OUT AML_NODE_HEADER **NextNode)
EFI_STATUS EFIAPI AmlInitializeIterator(IN AML_NODE_HEADER *Node, IN EAML_ITERATOR_MODE IteratorMode, OUT AML_TREE_ITERATOR **IteratorPtr)
STATIC EFI_STATUS EFIAPI AmlIteratorGetNextLinear(IN AML_TREE_ITERATOR *Iterator, OUT AML_NODE_HEADER **NextNode)
struct AmlTreeInternalIterator AML_TREE_ITERATOR_INTERNAL
STATIC EFI_STATUS EFIAPI AmlIteratorGetPreviousBranch(IN AML_TREE_ITERATOR *Iterator, OUT AML_NODE_HEADER **PrevNode)
STATIC EFI_STATUS EFIAPI AmlIteratorGetNode(IN AML_TREE_ITERATOR *Iterator, OUT AML_NODE_HEADER **OutNode)
STATIC EFI_STATUS EFIAPI AmlIteratorGetPreviousLinear(IN AML_TREE_ITERATOR *Iterator, OUT AML_NODE_HEADER **PrevNode)
AML_NODE_HEADER *EFIAPI AmlGetPreviousNode(IN CONST AML_NODE_HEADER *Node)
AML_NODE_HEADER *EFIAPI AmlGetNextNode(IN CONST AML_NODE_HEADER *Node)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
AML_NODE_HANDLE EFIAPI AmlGetParent(IN AML_NODE_HANDLE Node)
EFI_STATUS EFIAPI AmlDeleteIterator(IN AML_TREE_ITERATOR *Iterator)
enum EAmlIteratorMode EAML_ITERATOR_MODE
@ EAmlIteratorUnknown
Unknown/Invalid AML IteratorMode.
@ EAmlIteratorBranch
@ EAmlIteratorModeMax
Max enum.
@ EAmlIteratorLinear
AML_TREE_ITERATOR Iterator
CONST AML_NODE_HEADER * InitialNode
Pointer to the node on which the iterator has been initialized.
EAML_ITERATOR_MODE Mode
CONST AML_NODE_HEADER * CurrentNode
Pointer to the current node.
EDKII_AML_TREE_ITERATOR_GET_PREVIOUS GetPrevious
Update the current node of the iterator with the previous node.
EDKII_AML_TREE_ITERATOR_GET_NEXT GetNext
Update the current node of the iterator with the next node.
EDKII_AML_TREE_ITERATOR_GET_NODE GetNode
Get the current node of the iterator.