1 /******************************************************************************
3 * Module Name: dtsubtable.c - handling of subtables within ACPI tables
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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;
79 Subtable = UtSubtableCacheCalloc ();
81 /* Create a new buffer for the subtable data */
83 String = UtStringCacheCalloc (Length);
84 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
85 ACPI_MEMCPY (Subtable->Buffer, Buffer, Length);
87 Subtable->Length = Length;
88 Subtable->TotalLength = Length;
90 *RetSubtable = Subtable;
94 /******************************************************************************
96 * FUNCTION: DtInsertSubtable
98 * PARAMETERS: ParentTable - The Parent of the new subtable
99 * Subtable - The new subtable to insert
103 * DESCRIPTION: Insert the new subtable to the parent table
105 *****************************************************************************/
109 DT_SUBTABLE *ParentTable,
110 DT_SUBTABLE *Subtable)
112 DT_SUBTABLE *ChildTable;
115 Subtable->Peer = NULL;
116 Subtable->Parent = ParentTable;
117 Subtable->Depth = ParentTable->Depth + 1;
119 /* Link the new entry into the child list */
121 if (!ParentTable->Child)
123 ParentTable->Child = Subtable;
127 /* Walk to the end of the child list */
129 ChildTable = ParentTable->Child;
130 while (ChildTable->Peer)
132 ChildTable = ChildTable->Peer;
135 /* Add new subtable at the end of the child list */
137 ChildTable->Peer = Subtable;
142 /******************************************************************************
144 * FUNCTION: DtPushSubtable
146 * PARAMETERS: Subtable - Subtable to push
150 * DESCRIPTION: Push a subtable onto a subtable stack
152 *****************************************************************************/
156 DT_SUBTABLE *Subtable)
159 Subtable->StackTop = Gbl_SubtableStack;
160 Gbl_SubtableStack = Subtable;
164 /******************************************************************************
166 * FUNCTION: DtPopSubtable
172 * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
174 *****************************************************************************/
180 DT_SUBTABLE *Subtable;
183 Subtable = Gbl_SubtableStack;
187 Gbl_SubtableStack = Subtable->StackTop;
192 /******************************************************************************
194 * FUNCTION: DtPeekSubtable
198 * RETURN: The subtable on top of stack
200 * DESCRIPTION: Get the subtable on top of stack
202 *****************************************************************************/
209 return (Gbl_SubtableStack);
213 /******************************************************************************
215 * FUNCTION: DtGetNextSubtable
217 * PARAMETERS: ParentTable - Parent table whose children we are
219 * ChildTable - Previous child that was found.
220 * The NEXT child will be returned
222 * RETURN: Pointer to the NEXT child or NULL if none is found.
224 * DESCRIPTION: Return the next peer subtable within the tree.
226 *****************************************************************************/
230 DT_SUBTABLE *ParentTable,
231 DT_SUBTABLE *ChildTable)
233 ACPI_FUNCTION_ENTRY ();
238 /* It's really the parent's _scope_ that we want */
240 return (ParentTable->Child);
243 /* Otherwise just return the next peer (NULL if at end-of-list) */
245 return (ChildTable->Peer);
249 /******************************************************************************
251 * FUNCTION: DtGetParentSubtable
253 * PARAMETERS: Subtable - Current subtable
255 * RETURN: Parent of the given subtable
257 * DESCRIPTION: Get the parent of the given subtable in the tree
259 *****************************************************************************/
262 DtGetParentSubtable (
263 DT_SUBTABLE *Subtable)
271 return (Subtable->Parent);
275 /******************************************************************************
277 * FUNCTION: DtGetSubtableLength
279 * PARAMETERS: Field - Current field list pointer
280 * Info - Data table info
282 * RETURN: Subtable length
284 * DESCRIPTION: Get length of bytes needed to compile the subtable
286 *****************************************************************************/
289 DtGetSubtableLength (
291 ACPI_DMTABLE_INFO *Info)
293 UINT32 ByteLength = 0;
298 /* Walk entire Info table; Null name terminates */
300 for (; Info->Name; Info++)
302 if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
312 ByteLength += DtGetFieldLength (Field, Info);
314 switch (Info->Opcode)
321 case ACPI_DMT_HESTNTFY:
332 for (i = 0; i < Step; i++)
348 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
350 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
357 /******************************************************************************
359 * FUNCTION: DtSetSubtableLength
361 * PARAMETERS: Subtable - Subtable
365 * DESCRIPTION: Set length of the subtable into its length field
367 *****************************************************************************/
370 DtSetSubtableLength (
371 DT_SUBTABLE *Subtable)
374 if (!Subtable->LengthField)
379 ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength,
380 Subtable->SizeOfLengthField);