TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlFieldListParser.c
Go to the documentation of this file.
1
10
11#include <AmlCoreInterface.h>
14#include <Parser/AmlParser.h>
15#include <Tree/AmlNode.h>
16#include <Tree/AmlTree.h>
17
47EFIAPI
49 IN CONST AML_BYTE_ENCODING *FieldByteEncoding,
50 IN OUT AML_OBJECT_NODE *FieldNode,
51 IN OUT AML_STREAM *FStream,
52 IN OUT LIST_ENTRY *NameSpaceRefList
53 )
54{
55 EFI_STATUS Status;
56
57 UINT8 *CurrPos;
58 AML_OBJECT_NODE *NewNode;
59
60 UINT32 PkgLenOffset;
61 UINT32 PkgLenSize;
62
63 // Check whether the node is an Object Node and has a field list.
64 // The byte encoding must be a field element.
65 if ((FieldByteEncoding == NULL) ||
66 ((FieldByteEncoding->Attribute & AML_IS_FIELD_ELEMENT) == 0) ||
67 ((FieldByteEncoding->Attribute & AML_IS_PSEUDO_OPCODE) ==
70 !IS_STREAM (FStream) ||
71 IS_END_OF_STREAM (FStream) ||
72 !IS_STREAM_FORWARD (FStream) ||
73 (NameSpaceRefList == NULL))
74 {
75 ASSERT (0);
76 return EFI_INVALID_PARAMETER;
77 }
78
79 CurrPos = AmlStreamGetCurrPos (FStream);
80 if (CurrPos == NULL) {
81 ASSERT (0);
82 return EFI_INVALID_PARAMETER;
83 }
84
85 // Skip the field opcode (1 byte) as it is already in the FieldByteEncoding.
86 AMLDBG_DUMP_RAW (CurrPos, 1);
87 Status = AmlStreamProgress (FStream, 1);
88 if (EFI_ERROR (Status)) {
89 ASSERT (0);
90 return Status;
91 }
92
93 CurrPos = AmlStreamGetCurrPos (FStream);
94 if (CurrPos == NULL) {
95 ASSERT (0);
96 return EFI_INVALID_PARAMETER;
97 }
98
99 // Parse the PkgLen if available.
100 PkgLenSize = 0;
101 if ((FieldByteEncoding->Attribute & AML_HAS_PKG_LENGTH) ==
103 {
104 PkgLenOffset = AmlGetPkgLength (CurrPos, &PkgLenSize);
105 if (PkgLenOffset == 0) {
106 ASSERT (0);
107 return EFI_INVALID_PARAMETER;
108 }
109
110 // Move stream forward as the PkgLen has been read.
111 AMLDBG_DUMP_RAW (CurrPos, PkgLenOffset);
112 Status = AmlStreamProgress (FStream, PkgLenOffset);
113 if (EFI_ERROR (Status)) {
114 ASSERT (0);
115 return Status;
116 }
117
118 // Update the current position as PkgLen has been parsed.
119 CurrPos = AmlStreamGetCurrPos (FStream);
120 }
121
122 Status = AmlCreateObjectNode (
123 FieldByteEncoding,
124 PkgLenSize,
125 &NewNode
126 );
127 if (EFI_ERROR (Status)) {
128 ASSERT (0);
129 return Status;
130 }
131
132 // Add the FieldElement to the Variable Argument List.
134 (AML_NODE_HEADER *)FieldNode,
135 (AML_NODE_HEADER *)NewNode
136 );
137 if (EFI_ERROR (Status)) {
138 ASSERT (0);
139 // Delete the sub-tree if the insertion failed.
140 // Otherwise its reference will be lost.
141 AmlDeleteTree ((AML_NODE_HEADER *)NewNode);
142 return Status;
143 }
144
145 // Some field elements do not have fixed arguments.
146 if (!IS_END_OF_STREAM (FStream)) {
147 // Parse the fixed arguments of the field element.
148 Status = AmlParseFixedArguments (
149 NewNode,
150 FStream,
151 NameSpaceRefList
152 );
153 if (EFI_ERROR (Status)) {
154 ASSERT (0);
155 }
156 }
157
158 return Status;
159}
160
183STATIC
185EFIAPI
187 IN CONST AML_BYTE_ENCODING *NamedFieldByteEncoding,
188 IN OUT AML_OBJECT_NODE *FieldNode,
189 IN OUT AML_STREAM *FStream,
190 IN OUT LIST_ENTRY *NameSpaceRefList
191 )
192{
193 EFI_STATUS Status;
194 AML_OBJECT_NODE *NewNode;
195
196 // Check whether the node is an Object Node and has a field list.
197 // The byte encoding must be a char.
198 if ((NamedFieldByteEncoding == NULL) ||
199 ((NamedFieldByteEncoding->Attribute & AML_IS_NAME_CHAR) == 0) ||
201 !IS_STREAM (FStream) ||
202 IS_END_OF_STREAM (FStream) ||
203 !IS_STREAM_FORWARD (FStream) ||
204 (NameSpaceRefList == NULL))
205 {
206 ASSERT (0);
207 return EFI_INVALID_PARAMETER;
208 }
209
210 // Create a NamedField node.
211 Status = AmlCreateObjectNode (
213 0,
214 &NewNode
215 );
216 if (EFI_ERROR (Status)) {
217 ASSERT (0);
218 return Status;
219 }
220
221 // Add the NamedField node to the variable argument list.
223 (AML_NODE_HEADER *)FieldNode,
224 (AML_NODE_HEADER *)NewNode
225 );
226 if (EFI_ERROR (Status)) {
227 ASSERT (0);
228 // Delete the sub-tree if the insertion failed.
229 // Otherwise its reference will be lost.
230 AmlDeleteTree ((AML_NODE_HEADER *)NewNode);
231 return Status;
232 }
233
234 // Parse the fixed arguments: [0]NameSeg, [1]PkgLen.
235 Status = AmlParseFixedArguments (
236 NewNode,
237 FStream,
238 NameSpaceRefList
239 );
240 if (EFI_ERROR (Status)) {
241 ASSERT (0);
242 return Status;
243 }
244
245 // Add the NamedField to the namespace reference list.
246 Status = AmlAddNameSpaceReference (
247 NewNode,
248 NameSpaceRefList
249 );
250 ASSERT_EFI_ERROR (Status);
251
252 return Status;
253}
254
310EFIAPI
312 IN AML_OBJECT_NODE *FieldNode,
313 IN AML_STREAM *FStream,
314 IN LIST_ENTRY *NameSpaceRefList
315 )
316{
317 EFI_STATUS Status;
318
319 UINT8 *CurrPos;
320 CONST AML_BYTE_ENCODING *FieldByteEncoding;
321 CONST AML_BYTE_ENCODING *NamedFieldByteEncoding;
322
323 // Check whether the node is an Object Node and has a field list.
324 if (!AmlNodeHasAttribute (FieldNode, AML_HAS_FIELD_LIST) ||
325 !IS_STREAM (FStream) ||
326 IS_END_OF_STREAM (FStream) ||
327 !IS_STREAM_FORWARD (FStream) ||
328 (NameSpaceRefList == NULL))
329 {
330 ASSERT (0);
331 return EFI_INVALID_PARAMETER;
332 }
333
334 // Iterate through the field elements, creating nodes
335 // and adding them to the variable list of elements of Node.
336 while (!IS_END_OF_STREAM (FStream)) {
337 CurrPos = AmlStreamGetCurrPos (FStream);
338
339 // Check for a field opcode.
340 FieldByteEncoding = AmlGetFieldEncoding (CurrPos);
341 if (FieldByteEncoding != NULL) {
342 Status = AmlParseFieldElement (
343 FieldByteEncoding,
344 FieldNode,
345 FStream,
346 NameSpaceRefList
347 );
348 if (EFI_ERROR (Status)) {
349 ASSERT (0);
350 return Status;
351 }
352 } else {
353 // Handle the case of Pseudo OpCodes.
354 // NamedField has a Pseudo OpCode and starts with a NameChar. Therefore,
355 // call AmlGetByteEncoding() to check that the encoding is NameChar.
356 NamedFieldByteEncoding = AmlGetByteEncoding (CurrPos);
357 if ((NamedFieldByteEncoding != NULL) &&
358 (NamedFieldByteEncoding->Attribute & AML_IS_NAME_CHAR))
359 {
360 // This is a NamedField field element since it is starting with a char.
362 NamedFieldByteEncoding,
363 FieldNode,
364 FStream,
365 NameSpaceRefList
366 );
367 if (EFI_ERROR (Status)) {
368 ASSERT (0);
369 return Status;
370 }
371 } else {
372 // A field opcode or an AML byte encoding is expected.
373 ASSERT (0);
374 return EFI_INVALID_PARAMETER;
375 }
376 }
377 } // while
378
379 return EFI_SUCCESS;
380}
#define AML_IS_NAME_CHAR
Definition: Aml.h:70
#define AML_IS_FIELD_ELEMENT
Definition: Aml.h:93
#define AML_HAS_PKG_LENGTH
Definition: Aml.h:64
#define AML_HAS_FIELD_LIST
Definition: Aml.h:88
#define AML_IS_PSEUDO_OPCODE
Definition: Aml.h:103
STATIC EFI_STATUS EFIAPI AmlParseNamedFieldElement(IN CONST AML_BYTE_ENCODING *NamedFieldByteEncoding, IN OUT AML_OBJECT_NODE *FieldNode, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList)
STATIC EFI_STATUS EFIAPI AmlParseFieldElement(IN CONST AML_BYTE_ENCODING *FieldByteEncoding, IN OUT AML_OBJECT_NODE *FieldNode, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList)
EFI_STATUS EFIAPI AmlParseFieldList(IN AML_OBJECT_NODE *FieldNode, IN AML_STREAM *FStream, IN LIST_ENTRY *NameSpaceRefList)
EFI_STATUS EFIAPI AmlAddNameSpaceReference(IN CONST AML_OBJECT_NODE *Node, IN OUT LIST_ENTRY *NameSpaceRefList)
EFI_STATUS EFIAPI AmlCreateObjectNode(IN CONST AML_BYTE_ENCODING *AmlByteEncoding, IN UINT32 PkgLength, OUT AML_OBJECT_NODE **NewObjectNodePtr)
Definition: AmlNode.c:181
BOOLEAN EFIAPI AmlNodeHasAttribute(IN CONST AML_OBJECT_NODE *ObjectNode, IN AML_OP_ATTRIBUTE Attribute)
Definition: AmlNode.c:430
EFI_STATUS EFIAPI AmlParseFixedArguments(IN AML_OBJECT_NODE *ObjectNode, IN AML_STREAM *FStream, IN LIST_ENTRY *NameSpaceRefList)
Definition: AmlParser.c:893
EFI_STATUS EFIAPI AmlStreamProgress(IN AML_STREAM *Stream, IN UINT32 Offset)
Definition: AmlStream.c:324
UINT8 *EFIAPI AmlStreamGetCurrPos(IN CONST AML_STREAM *Stream)
Definition: AmlStream.c:264
#define IS_STREAM_FORWARD(Stream)
Definition: AmlStream.h:91
#define IS_STREAM(Stream)
Definition: AmlStream.h:69
#define IS_END_OF_STREAM(Stream)
Definition: AmlStream.h:80
EFI_STATUS EFIAPI AmlVarListAddTailInternal(IN AML_NODE_HEADER *ParentNode, IN AML_NODE_HEADER *NewNode)
Definition: AmlTree.c:379
UINT32 EFIAPI AmlGetPkgLength(IN CONST UINT8 *Buffer, OUT UINT32 *PkgLength)
Definition: Aml.c:621
CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncodingByOpCode(IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: Aml.c:434
CONST AML_BYTE_ENCODING *EFIAPI AmlGetByteEncoding(IN CONST UINT8 *Buffer)
Definition: Aml.c:290
CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncoding(IN CONST UINT8 *Buffer)
Definition: Aml.c:383
#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
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define AML_FIELD_NAMED_OP
Definition: AmlDefines.h:139
EFI_STATUS EFIAPI AmlDeleteTree(IN AML_NODE_HANDLE Node)