Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / dtsubtable.c
blob275d67aa2ecc47d2b2752409dafb866bc9481031
1 /******************************************************************************
3 * Module Name: dtsubtable.c - handling of subtables within ACPI tables
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __DTSUBTABLE_C__
46 #include "aslcompiler.h"
47 #include "dtcompiler.h"
49 #define _COMPONENT DT_COMPILER
50 ACPI_MODULE_NAME ("dtsubtable")
53 /******************************************************************************
55 * FUNCTION: DtCreateSubtable
57 * PARAMETERS: Buffer - Input buffer
58 * Length - Buffer length
59 * RetSubtable - Returned newly created subtable
61 * RETURN: None
63 * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO
64 * For example, FACS has 24 bytes reserved at the end
65 * and it's not listed at AcpiDmTableInfoFacs
67 *****************************************************************************/
69 void
70 DtCreateSubtable (
71 UINT8 *Buffer,
72 UINT32 Length,
73 DT_SUBTABLE **RetSubtable)
75 DT_SUBTABLE *Subtable;
78 Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
80 /* Create a new buffer for the subtable data */
82 Subtable->Buffer = UtLocalCalloc (Length);
83 ACPI_MEMCPY (Subtable->Buffer, Buffer, Length);
85 Subtable->Length = Length;
86 Subtable->TotalLength = Length;
88 *RetSubtable = Subtable;
92 /******************************************************************************
94 * FUNCTION: DtInsertSubtable
96 * PARAMETERS: ParentTable - The Parent of the new subtable
97 * Subtable - The new subtable to insert
99 * RETURN: None
101 * DESCRIPTION: Insert the new subtable to the parent table
103 *****************************************************************************/
105 void
106 DtInsertSubtable (
107 DT_SUBTABLE *ParentTable,
108 DT_SUBTABLE *Subtable)
110 DT_SUBTABLE *ChildTable;
113 Subtable->Peer = NULL;
114 Subtable->Parent = ParentTable;
115 Subtable->Depth = ParentTable->Depth + 1;
117 /* Link the new entry into the child list */
119 if (!ParentTable->Child)
121 ParentTable->Child = Subtable;
123 else
125 /* Walk to the end of the child list */
127 ChildTable = ParentTable->Child;
128 while (ChildTable->Peer)
130 ChildTable = ChildTable->Peer;
133 /* Add new subtable at the end of the child list */
135 ChildTable->Peer = Subtable;
140 /******************************************************************************
142 * FUNCTION: DtPushSubtable
144 * PARAMETERS: Subtable - Subtable to push
146 * RETURN: None
148 * DESCRIPTION: Push a subtable onto a subtable stack
150 *****************************************************************************/
152 void
153 DtPushSubtable (
154 DT_SUBTABLE *Subtable)
157 Subtable->StackTop = Gbl_SubtableStack;
158 Gbl_SubtableStack = Subtable;
162 /******************************************************************************
164 * FUNCTION: DtPopSubtable
166 * PARAMETERS: None
168 * RETURN: None
170 * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
172 *****************************************************************************/
174 void
175 DtPopSubtable (
176 void)
178 DT_SUBTABLE *Subtable;
181 Subtable = Gbl_SubtableStack;
183 if (Subtable)
185 Gbl_SubtableStack = Subtable->StackTop;
190 /******************************************************************************
192 * FUNCTION: DtPeekSubtable
194 * PARAMETERS: None
196 * RETURN: The subtable on top of stack
198 * DESCRIPTION: Get the subtable on top of stack
200 *****************************************************************************/
202 DT_SUBTABLE *
203 DtPeekSubtable (
204 void)
207 return (Gbl_SubtableStack);
211 /******************************************************************************
213 * FUNCTION: DtGetNextSubtable
215 * PARAMETERS: ParentTable - Parent table whose children we are
216 * getting
217 * ChildTable - Previous child that was found.
218 * The NEXT child will be returned
220 * RETURN: Pointer to the NEXT child or NULL if none is found.
222 * DESCRIPTION: Return the next peer subtable within the tree.
224 *****************************************************************************/
226 DT_SUBTABLE *
227 DtGetNextSubtable (
228 DT_SUBTABLE *ParentTable,
229 DT_SUBTABLE *ChildTable)
231 ACPI_FUNCTION_ENTRY ();
234 if (!ChildTable)
236 /* It's really the parent's _scope_ that we want */
238 return (ParentTable->Child);
241 /* Otherwise just return the next peer (NULL if at end-of-list) */
243 return (ChildTable->Peer);
247 /******************************************************************************
249 * FUNCTION: DtGetParentSubtable
251 * PARAMETERS: Subtable - Current subtable
253 * RETURN: Parent of the given subtable
255 * DESCRIPTION: Get the parent of the given subtable in the tree
257 *****************************************************************************/
259 DT_SUBTABLE *
260 DtGetParentSubtable (
261 DT_SUBTABLE *Subtable)
264 if (!Subtable)
266 return (NULL);
269 return (Subtable->Parent);
273 /******************************************************************************
275 * FUNCTION: DtGetSubtableLength
277 * PARAMETERS: Field - Current field list pointer
278 * Info - Data table info
280 * RETURN: Subtable length
282 * DESCRIPTION: Get length of bytes needed to compile the subtable
284 *****************************************************************************/
286 UINT32
287 DtGetSubtableLength (
288 DT_FIELD *Field,
289 ACPI_DMTABLE_INFO *Info)
291 UINT32 ByteLength = 0;
292 UINT8 Step;
293 UINT8 i;
296 /* Walk entire Info table; Null name terminates */
298 for (; Info->Name; Info++)
300 if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
302 continue;
305 if (!Field)
307 goto Error;
310 ByteLength += DtGetFieldLength (Field, Info);
312 switch (Info->Opcode)
314 case ACPI_DMT_GAS:
316 Step = 5;
317 break;
319 case ACPI_DMT_HESTNTFY:
321 Step = 9;
322 break;
324 default:
326 Step = 1;
327 break;
330 for (i = 0; i < Step; i++)
332 if (!Field)
334 goto Error;
337 Field = Field->Next;
341 return (ByteLength);
343 Error:
344 if (!Field)
346 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
347 Info->Name);
348 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
351 return (ASL_EOF);
355 /******************************************************************************
357 * FUNCTION: DtSetSubtableLength
359 * PARAMETERS: Subtable - Subtable
361 * RETURN: None
363 * DESCRIPTION: Set length of the subtable into its length field
365 *****************************************************************************/
367 void
368 DtSetSubtableLength (
369 DT_SUBTABLE *Subtable)
372 if (!Subtable->LengthField)
374 return;
377 ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength,
378 Subtable->SizeOfLengthField);