1 /******************************************************************************
3 * Module Name: dtsubtable.c - handling of subtables within ACPI tables
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 #include "aslcompiler.h"
45 #include "dtcompiler.h"
47 #define _COMPONENT DT_COMPILER
48 ACPI_MODULE_NAME ("dtsubtable")
51 /******************************************************************************
53 * FUNCTION: DtCreateSubtable
55 * PARAMETERS: Buffer - Input buffer
56 * Length - Buffer length
57 * RetSubtable - Returned newly created subtable
61 * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO
62 * For example, FACS has 24 bytes reserved at the end
63 * and it's not listed at AcpiDmTableInfoFacs
65 *****************************************************************************/
71 DT_SUBTABLE **RetSubtable)
73 DT_SUBTABLE *Subtable;
77 Subtable = UtSubtableCacheCalloc ();
79 /* Create a new buffer for the subtable data */
81 String = UtStringCacheCalloc (Length);
82 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
83 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;
115 Subtable->Depth = ParentTable->Depth + 1;
117 /* Link the new entry into the child list */
119 if (!ParentTable->Child)
121 ParentTable->Child = Subtable;
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
148 * DESCRIPTION: Push a subtable onto a subtable stack
150 *****************************************************************************/
154 DT_SUBTABLE *Subtable)
157 Subtable->StackTop = Gbl_SubtableStack;
158 Gbl_SubtableStack = Subtable;
162 /******************************************************************************
164 * FUNCTION: DtPopSubtable
170 * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
172 *****************************************************************************/
178 DT_SUBTABLE *Subtable;
181 Subtable = Gbl_SubtableStack;
185 Gbl_SubtableStack = Subtable->StackTop;
190 /******************************************************************************
192 * FUNCTION: DtPeekSubtable
196 * RETURN: The subtable on top of stack
198 * DESCRIPTION: Get the subtable on top of stack
200 *****************************************************************************/
207 return (Gbl_SubtableStack);
211 /******************************************************************************
213 * FUNCTION: DtGetNextSubtable
215 * PARAMETERS: ParentTable - Parent table whose children we are
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 *****************************************************************************/
228 DT_SUBTABLE *ParentTable,
229 DT_SUBTABLE *ChildTable)
231 ACPI_FUNCTION_ENTRY ();
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 *****************************************************************************/
260 DtGetParentSubtable (
261 DT_SUBTABLE *Subtable)
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 *****************************************************************************/
287 DtGetSubtableLength (
289 ACPI_DMTABLE_INFO *Info)
291 UINT32 ByteLength = 0;
296 /* Walk entire Info table; Null name terminates */
298 for (; Info->Name; Info++)
300 if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
310 ByteLength += DtGetFieldLength (Field, Info);
312 switch (Info->Opcode)
319 case ACPI_DMT_HESTNTFY:
324 case ACPI_DMT_IORTMEM:
335 for (i = 0; i < Step; i++)
351 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
353 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
360 /******************************************************************************
362 * FUNCTION: DtSetSubtableLength
364 * PARAMETERS: Subtable - Subtable
368 * DESCRIPTION: Set length of the subtable into its length field
370 *****************************************************************************/
373 DtSetSubtableLength (
374 DT_SUBTABLE *Subtable)
377 if (!Subtable->LengthField)
382 memcpy (Subtable->LengthField, &Subtable->TotalLength,
383 Subtable->SizeOfLengthField);