TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlSerialize.c
Go to the documentation of this file.
1
9#include <AmlNodeDefines.h>
10
11#include <AmlCoreInterface.h>
12#include <Stream/AmlStream.h>
13#include <Tree/AmlNode.h>
14#include <Tree/AmlTree.h>
15#include <Utils/AmlUtility.h>
16
38BOOLEAN
39EFIAPI
41 IN AML_NODE_HEADER *Node,
42 IN OUT VOID *Context OPTIONAL,
43 IN OUT EFI_STATUS *Status OPTIONAL
44 )
45{
46 EFI_STATUS Status1;
47
48 CONST AML_DATA_NODE *DataNode;
49 CONST AML_OBJECT_NODE *ObjectNode;
50 AML_STREAM *FStream;
51
52 // Bytes needed to store OpCode[1] + SubOpcode[1] + MaxPkgLen[4] = 6 bytes.
53 UINT8 ObjectNodeInfoArray[6];
54 UINT32 Index;
55 BOOLEAN ContinueEnum;
56
57 CONST AML_OBJECT_NODE *ParentNode;
58 EAML_PARSE_INDEX IndexPtr;
59
60 if (!IS_AML_NODE_VALID (Node) ||
61 (Context == NULL))
62 {
63 ASSERT (0);
64 Status1 = EFI_INVALID_PARAMETER;
65 ContinueEnum = FALSE;
66 goto error_handler;
67 }
68
69 // Ignore the second fixed argument of method invocation nodes
70 // as the information stored there (the argument count) is not in the
71 // ACPI specification.
72 ParentNode = (CONST AML_OBJECT_NODE *)AmlGetParent ((AML_NODE_HEADER *)Node);
73 if (IS_AML_OBJECT_NODE (ParentNode) &&
75 AmlIsNodeFixedArgument (Node, &IndexPtr))
76 {
77 if (IndexPtr == EAmlParseIndexTerm1) {
78 if (Status != NULL) {
79 *Status = EFI_SUCCESS;
80 }
81
82 return TRUE;
83 }
84 }
85
86 Status1 = EFI_SUCCESS;
87 ContinueEnum = TRUE;
88 FStream = (AML_STREAM *)Context;
89
90 if (IS_AML_DATA_NODE (Node)) {
91 // Copy the content of the Buffer for a DataNode.
92 DataNode = (AML_DATA_NODE *)Node;
93 Status1 = AmlStreamWrite (
94 FStream,
95 DataNode->Buffer,
96 DataNode->Size
97 );
98 if (EFI_ERROR (Status1)) {
99 ASSERT (0);
100 ContinueEnum = FALSE;
101 goto error_handler;
102 }
103 } else if (IS_AML_OBJECT_NODE (Node) &&
105 (CONST AML_OBJECT_NODE *)Node,
107 ))
108 {
109 // Ignore pseudo-opcodes as they are not part of the
110 // ACPI specification.
111
112 ObjectNode = (AML_OBJECT_NODE *)Node;
113
114 Index = 0;
115 // Copy the opcode(s).
116 ObjectNodeInfoArray[Index++] = ObjectNode->AmlByteEncoding->OpCode;
117 if (ObjectNode->AmlByteEncoding->OpCode == AML_EXT_OP) {
118 ObjectNodeInfoArray[Index++] = ObjectNode->AmlByteEncoding->SubOpCode;
119 }
120
121 // Copy the PkgLen.
122 if (AmlNodeHasAttribute (ObjectNode, AML_HAS_PKG_LENGTH)) {
123 Index += AmlSetPkgLength (
124 ObjectNode->PkgLen,
125 &ObjectNodeInfoArray[Index]
126 );
127 }
128
129 Status1 = AmlStreamWrite (
130 FStream,
131 ObjectNodeInfoArray,
132 Index
133 );
134 if (EFI_ERROR (Status1)) {
135 ASSERT (0);
136 ContinueEnum = FALSE;
137 goto error_handler;
138 }
139 } // IS_AML_OBJECT_NODE (Node)
140
141error_handler:
142 if (Status != NULL) {
143 *Status = Status1;
144 }
145
146 return ContinueEnum;
147}
148
175EFIAPI
177 IN AML_ROOT_NODE *RootNode,
178 IN UINT8 *Buffer OPTIONAL,
179 IN OUT UINT32 *BufferSize
180 )
181{
182 EFI_STATUS Status;
183 AML_STREAM FStream;
184 UINT32 TableSize;
185
186 if (!IS_AML_ROOT_NODE (RootNode) ||
187 (BufferSize == NULL))
188 {
189 ASSERT (0);
190 return EFI_INVALID_PARAMETER;
191 }
192
193 // Compute the total size of the AML blob.
194 Status = AmlComputeSize (
195 (CONST AML_NODE_HEADER *)RootNode,
196 &TableSize
197 );
198 if (EFI_ERROR (Status)) {
199 ASSERT (0);
200 return Status;
201 }
202
203 // Add the size of the ACPI header.
204 TableSize += (UINT32)sizeof (EFI_ACPI_DESCRIPTION_HEADER);
205
206 // Check the size against the SDT header.
207 // The Length field in the SDT Header is updated if the tree has
208 // been modified.
209 if (TableSize != RootNode->SdtHeader->Length) {
210 ASSERT (0);
211 return EFI_INVALID_PARAMETER;
212 }
213
214 // Buffer is not big enough, or NULL.
215 if ((TableSize < *BufferSize) || (Buffer == NULL)) {
216 *BufferSize = TableSize;
217 return EFI_SUCCESS;
218 }
219
220 // Initialize the stream to the TableSize that is needed.
221 Status = AmlStreamInit (
222 &FStream,
223 Buffer,
224 TableSize,
226 );
227 if (EFI_ERROR (Status)) {
228 ASSERT (0);
229 return Status;
230 }
231
232 // Serialize the header.
233 Status = AmlStreamWrite (
234 &FStream,
235 (UINT8 *)RootNode->SdtHeader,
237 );
238 if (EFI_ERROR (Status)) {
239 ASSERT (0);
240 return Status;
241 }
242
243 Status = EFI_SUCCESS;
245 (AML_NODE_HEADER *)RootNode,
247 (VOID *)&FStream,
248 &Status
249 );
250 if (EFI_ERROR (Status)) {
251 ASSERT (0);
252 return Status;
253 }
254
255 // Update the checksum.
257}
258
274EFIAPI
276 IN AML_ROOT_NODE *RootNode,
278 )
279{
280 EFI_STATUS Status;
281 UINT8 *TableBuffer;
282 UINT32 TableSize;
283
284 if (!IS_AML_ROOT_NODE (RootNode) ||
285 (Table == NULL))
286 {
287 ASSERT (0);
288 return EFI_INVALID_PARAMETER;
289 }
290
291 *Table = NULL;
292 TableBuffer = NULL;
293 TableSize = 0;
294
295 // Get the size of the SSDT table.
296 Status = AmlSerializeTree (
297 RootNode,
298 TableBuffer,
299 &TableSize
300 );
301 if (EFI_ERROR (Status)) {
302 ASSERT (0);
303 return Status;
304 }
305
306 TableBuffer = (UINT8 *)AllocateZeroPool (TableSize);
307 if (TableBuffer == NULL) {
308 DEBUG ((
309 DEBUG_ERROR,
310 "ERROR: Failed to allocate memory for Table Buffer."
311 ));
312 ASSERT (0);
313 return EFI_OUT_OF_RESOURCES;
314 }
315
316 // Serialize the tree to a SSDT table.
317 Status = AmlSerializeTree (
318 RootNode,
319 TableBuffer,
320 &TableSize
321 );
322 if (EFI_ERROR (Status)) {
323 FreePool (TableBuffer);
324 ASSERT (0);
325 } else {
326 // Save the allocated Table buffer in the table list
327 *Table = (EFI_ACPI_DESCRIPTION_HEADER *)TableBuffer;
328 }
329
330 return Status;
331}
#define AML_HAS_PKG_LENGTH
Definition: Aml.h:64
#define AML_IS_PSEUDO_OPCODE
Definition: Aml.h:103
BOOLEAN EFIAPI AmlNodeCompareOpCode(IN CONST AML_OBJECT_NODE *ObjectNode, IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: AmlNode.c:457
BOOLEAN EFIAPI AmlNodeHasAttribute(IN CONST AML_OBJECT_NODE *ObjectNode, IN AML_OP_ATTRIBUTE Attribute)
Definition: AmlNode.c:430
#define IS_AML_ROOT_NODE(Node)
#define IS_AML_OBJECT_NODE(Node)
#define IS_AML_DATA_NODE(Node)
#define IS_AML_NODE_VALID(Node)
EFI_STATUS EFIAPI AmlSerializeDefinitionBlock(IN AML_ROOT_NODE *RootNode, OUT EFI_ACPI_DESCRIPTION_HEADER **Table)
Definition: AmlSerialize.c:275
EFI_STATUS EFIAPI AmlSerializeTree(IN AML_ROOT_NODE *RootNode, IN UINT8 *Buffer OPTIONAL, IN OUT UINT32 *BufferSize)
Definition: AmlSerialize.c:176
STATIC BOOLEAN EFIAPI AmlSerializeNodeCallback(IN AML_NODE_HEADER *Node, IN OUT VOID *Context OPTIONAL, IN OUT EFI_STATUS *Status OPTIONAL)
Definition: AmlSerialize.c:40
EFI_STATUS EFIAPI AmlStreamWrite(IN AML_STREAM *Stream, IN CONST UINT8 *Buffer, IN UINT32 Size)
Definition: AmlStream.c:512
EFI_STATUS EFIAPI AmlStreamInit(IN OUT AML_STREAM *Stream, IN UINT8 *Buffer, IN UINT32 MaxBufferSize, IN EAML_STREAM_DIRECTION Direction)
Definition: AmlStream.c:25
@ EAmlStreamDirectionForward
Definition: AmlStream.h:20
BOOLEAN EFIAPI AmlIsNodeFixedArgument(IN CONST AML_NODE_HEADER *Node, OUT EAML_PARSE_INDEX *IndexPtr)
Definition: AmlTree.c:110
EFI_STATUS EFIAPI AcpiPlatformChecksum(IN EFI_ACPI_DESCRIPTION_HEADER *AcpiTable)
Definition: AmlUtility.c:24
EFI_STATUS EFIAPI AmlComputeSize(IN CONST AML_NODE_HEADER *Node, IN OUT UINT32 *Size)
Definition: AmlUtility.c:169
UINT8 EFIAPI AmlSetPkgLength(IN UINT32 Length, OUT UINT8 *Buffer)
Definition: Aml.c:724
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 TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
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)
BOOLEAN EFIAPI AmlEnumTree(IN AML_NODE_HANDLE Node, IN EDKII_AML_TREE_ENUM_CALLBACK CallBack, IN OUT VOID *Context OPTIONAL, OUT EFI_STATUS *Status OPTIONAL)
#define AML_METHOD_INVOC_OP
Definition: AmlDefines.h:120
enum EAmlParseIndex EAML_PARSE_INDEX
@ EAmlParseIndexTerm1
Second fixed argument index.
Definition: AmlDefines.h:66
UINT8 * Buffer
Pointer to a buffer.
Definition: AmlStream.h:34