1 /******************************************************************************
3 * Module Name: dtsubtable.c - handling of subtables within ACPI tables
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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 <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include <contrib/dev/acpica/compiler/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
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 *****************************************************************************/
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
101 * DESCRIPTION: Insert the new subtable to the parent table
103 *****************************************************************************/
107 DT_SUBTABLE *ParentTable,
108 DT_SUBTABLE *Subtable)
110 DT_SUBTABLE *ChildTable;
113 Subtable->Peer = NULL;
114 Subtable->Parent = ParentTable;
116 /* Link the new entry into the child list */
118 if (!ParentTable->Child)
120 ParentTable->Child = Subtable;
124 /* Walk to the end of the child list */
126 ChildTable = ParentTable->Child;
127 while (ChildTable->Peer)
129 ChildTable = ChildTable->Peer;
132 /* Add new subtable at the end of the child list */
134 ChildTable->Peer = Subtable;
139 /******************************************************************************
141 * FUNCTION: DtPushSubtable
143 * PARAMETERS: Subtable - Subtable to push
147 * DESCRIPTION: Push a subtable onto a subtable stack
149 *****************************************************************************/
153 DT_SUBTABLE *Subtable)
156 Subtable->StackTop = Gbl_SubtableStack;
157 Gbl_SubtableStack = Subtable;
161 /******************************************************************************
163 * FUNCTION: DtPopSubtable
169 * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
171 *****************************************************************************/
177 DT_SUBTABLE *Subtable;
180 Subtable = Gbl_SubtableStack;
184 Gbl_SubtableStack = Subtable->StackTop;
189 /******************************************************************************
191 * FUNCTION: DtPeekSubtable
195 * RETURN: The subtable on top of stack
197 * DESCRIPTION: Get the subtable on top of stack
199 *****************************************************************************/
206 return (Gbl_SubtableStack);
210 /******************************************************************************
212 * FUNCTION: DtGetNextSubtable
214 * PARAMETERS: ParentTable - Parent table whose children we are
216 * ChildTable - Previous child that was found.
217 * The NEXT child will be returned
219 * RETURN: Pointer to the NEXT child or NULL if none is found.
221 * DESCRIPTION: Return the next peer subtable within the tree.
223 *****************************************************************************/
227 DT_SUBTABLE *ParentTable,
228 DT_SUBTABLE *ChildTable)
230 ACPI_FUNCTION_ENTRY ();
235 /* It's really the parent's _scope_ that we want */
237 return (ParentTable->Child);
240 /* Otherwise just return the next peer (NULL if at end-of-list) */
242 return (ChildTable->Peer);
246 /******************************************************************************
248 * FUNCTION: DtGetParentSubtable
250 * PARAMETERS: Subtable - Current subtable
252 * RETURN: Parent of the given subtable
254 * DESCRIPTION: Get the parent of the given subtable in the tree
256 *****************************************************************************/
259 DtGetParentSubtable (
260 DT_SUBTABLE *Subtable)
268 return (Subtable->Parent);
272 /******************************************************************************
274 * FUNCTION: DtGetSubtableLength
276 * PARAMETERS: Field - Current field list pointer
277 * Info - Data table info
279 * RETURN: Subtable length
281 * DESCRIPTION: Get length of bytes needed to compile the subtable
283 *****************************************************************************/
286 DtGetSubtableLength (
288 ACPI_DMTABLE_INFO *Info)
290 UINT32 ByteLength = 0;
295 /* Walk entire Info table; Null name terminates */
297 for (; Info->Name; Info++)
304 ByteLength += DtGetFieldLength (Field, Info);
306 switch (Info->Opcode)
312 case ACPI_DMT_HESTNTFY:
321 for (i = 0; i < Step; i++)
337 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
339 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
346 /******************************************************************************
348 * FUNCTION: DtSetSubtableLength
350 * PARAMETERS: Subtable - Subtable
354 * DESCRIPTION: Set length of the subtable into its length field
356 *****************************************************************************/
359 DtSetSubtableLength (
360 DT_SUBTABLE *Subtable)
363 if (!Subtable->LengthField)
368 ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength,
369 Subtable->SizeOfLengthField);