dtsubtable.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: dtsubtable.c - handling of subtables within ACPI tables
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer #define __DTSUBTABLE_C__
45 1.1.1.2.2.2 bouyer
46 1.1.1.2.2.2 bouyer #include "aslcompiler.h"
47 1.1.1.2.2.2 bouyer #include "dtcompiler.h"
48 1.1.1.2.2.2 bouyer
49 1.1.1.2.2.2 bouyer #define _COMPONENT DT_COMPILER
50 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("dtsubtable")
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer /******************************************************************************
54 1.1.1.2.2.2 bouyer *
55 1.1.1.2.2.2 bouyer * FUNCTION: DtCreateSubtable
56 1.1.1.2.2.2 bouyer *
57 1.1.1.2.2.2 bouyer * PARAMETERS: Buffer - Input buffer
58 1.1.1.2.2.2 bouyer * Length - Buffer length
59 1.1.1.2.2.2 bouyer * RetSubtable - Returned newly created subtable
60 1.1.1.2.2.2 bouyer *
61 1.1.1.2.2.2 bouyer * RETURN: None
62 1.1.1.2.2.2 bouyer *
63 1.1.1.2.2.2 bouyer * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO
64 1.1.1.2.2.2 bouyer * For example, FACS has 24 bytes reserved at the end
65 1.1.1.2.2.2 bouyer * and it's not listed at AcpiDmTableInfoFacs
66 1.1.1.2.2.2 bouyer *
67 1.1.1.2.2.2 bouyer *****************************************************************************/
68 1.1.1.2.2.2 bouyer
69 1.1.1.2.2.2 bouyer void
70 1.1.1.2.2.2 bouyer DtCreateSubtable (
71 1.1.1.2.2.2 bouyer UINT8 *Buffer,
72 1.1.1.2.2.2 bouyer UINT32 Length,
73 1.1.1.2.2.2 bouyer DT_SUBTABLE **RetSubtable)
74 1.1.1.2.2.2 bouyer {
75 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable;
76 1.1.1.2.2.2 bouyer
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
79 1.1.1.2.2.2 bouyer
80 1.1.1.2.2.2 bouyer /* Create a new buffer for the subtable data */
81 1.1.1.2.2.2 bouyer
82 1.1.1.2.2.2 bouyer Subtable->Buffer = UtLocalCalloc (Length);
83 1.1.1.2.2.2 bouyer ACPI_MEMCPY (Subtable->Buffer, Buffer, Length);
84 1.1.1.2.2.2 bouyer
85 1.1.1.2.2.2 bouyer Subtable->Length = Length;
86 1.1.1.2.2.2 bouyer Subtable->TotalLength = Length;
87 1.1.1.2.2.2 bouyer
88 1.1.1.2.2.2 bouyer *RetSubtable = Subtable;
89 1.1.1.2.2.2 bouyer }
90 1.1.1.2.2.2 bouyer
91 1.1.1.2.2.2 bouyer
92 1.1.1.2.2.2 bouyer /******************************************************************************
93 1.1.1.2.2.2 bouyer *
94 1.1.1.2.2.2 bouyer * FUNCTION: DtInsertSubtable
95 1.1.1.2.2.2 bouyer *
96 1.1.1.2.2.2 bouyer * PARAMETERS: ParentTable - The Parent of the new subtable
97 1.1.1.2.2.2 bouyer * Subtable - The new subtable to insert
98 1.1.1.2.2.2 bouyer *
99 1.1.1.2.2.2 bouyer * RETURN: None
100 1.1.1.2.2.2 bouyer *
101 1.1.1.2.2.2 bouyer * DESCRIPTION: Insert the new subtable to the parent table
102 1.1.1.2.2.2 bouyer *
103 1.1.1.2.2.2 bouyer *****************************************************************************/
104 1.1.1.2.2.2 bouyer
105 1.1.1.2.2.2 bouyer void
106 1.1.1.2.2.2 bouyer DtInsertSubtable (
107 1.1.1.2.2.2 bouyer DT_SUBTABLE *ParentTable,
108 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable)
109 1.1.1.2.2.2 bouyer {
110 1.1.1.2.2.2 bouyer DT_SUBTABLE *ChildTable;
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer Subtable->Peer = NULL;
114 1.1.1.2.2.2 bouyer Subtable->Parent = ParentTable;
115 1.1.1.2.2.2 bouyer
116 1.1.1.2.2.2 bouyer /* Link the new entry into the child list */
117 1.1.1.2.2.2 bouyer
118 1.1.1.2.2.2 bouyer if (!ParentTable->Child)
119 1.1.1.2.2.2 bouyer {
120 1.1.1.2.2.2 bouyer ParentTable->Child = Subtable;
121 1.1.1.2.2.2 bouyer }
122 1.1.1.2.2.2 bouyer else
123 1.1.1.2.2.2 bouyer {
124 1.1.1.2.2.2 bouyer /* Walk to the end of the child list */
125 1.1.1.2.2.2 bouyer
126 1.1.1.2.2.2 bouyer ChildTable = ParentTable->Child;
127 1.1.1.2.2.2 bouyer while (ChildTable->Peer)
128 1.1.1.2.2.2 bouyer {
129 1.1.1.2.2.2 bouyer ChildTable = ChildTable->Peer;
130 1.1.1.2.2.2 bouyer }
131 1.1.1.2.2.2 bouyer
132 1.1.1.2.2.2 bouyer /* Add new subtable at the end of the child list */
133 1.1.1.2.2.2 bouyer
134 1.1.1.2.2.2 bouyer ChildTable->Peer = Subtable;
135 1.1.1.2.2.2 bouyer }
136 1.1.1.2.2.2 bouyer }
137 1.1.1.2.2.2 bouyer
138 1.1.1.2.2.2 bouyer
139 1.1.1.2.2.2 bouyer /******************************************************************************
140 1.1.1.2.2.2 bouyer *
141 1.1.1.2.2.2 bouyer * FUNCTION: DtPushSubtable
142 1.1.1.2.2.2 bouyer *
143 1.1.1.2.2.2 bouyer * PARAMETERS: Subtable - Subtable to push
144 1.1.1.2.2.2 bouyer *
145 1.1.1.2.2.2 bouyer * RETURN: None
146 1.1.1.2.2.2 bouyer *
147 1.1.1.2.2.2 bouyer * DESCRIPTION: Push a subtable onto a subtable stack
148 1.1.1.2.2.2 bouyer *
149 1.1.1.2.2.2 bouyer *****************************************************************************/
150 1.1.1.2.2.2 bouyer
151 1.1.1.2.2.2 bouyer void
152 1.1.1.2.2.2 bouyer DtPushSubtable (
153 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable)
154 1.1.1.2.2.2 bouyer {
155 1.1.1.2.2.2 bouyer
156 1.1.1.2.2.2 bouyer Subtable->StackTop = Gbl_SubtableStack;
157 1.1.1.2.2.2 bouyer Gbl_SubtableStack = Subtable;
158 1.1.1.2.2.2 bouyer }
159 1.1.1.2.2.2 bouyer
160 1.1.1.2.2.2 bouyer
161 1.1.1.2.2.2 bouyer /******************************************************************************
162 1.1.1.2.2.2 bouyer *
163 1.1.1.2.2.2 bouyer * FUNCTION: DtPopSubtable
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer * PARAMETERS: None
166 1.1.1.2.2.2 bouyer *
167 1.1.1.2.2.2 bouyer * RETURN: None
168 1.1.1.2.2.2 bouyer *
169 1.1.1.2.2.2 bouyer * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
170 1.1.1.2.2.2 bouyer *
171 1.1.1.2.2.2 bouyer *****************************************************************************/
172 1.1.1.2.2.2 bouyer
173 1.1.1.2.2.2 bouyer void
174 1.1.1.2.2.2 bouyer DtPopSubtable (
175 1.1.1.2.2.2 bouyer void)
176 1.1.1.2.2.2 bouyer {
177 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable;
178 1.1.1.2.2.2 bouyer
179 1.1.1.2.2.2 bouyer
180 1.1.1.2.2.2 bouyer Subtable = Gbl_SubtableStack;
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer if (Subtable)
183 1.1.1.2.2.2 bouyer {
184 1.1.1.2.2.2 bouyer Gbl_SubtableStack = Subtable->StackTop;
185 1.1.1.2.2.2 bouyer }
186 1.1.1.2.2.2 bouyer }
187 1.1.1.2.2.2 bouyer
188 1.1.1.2.2.2 bouyer
189 1.1.1.2.2.2 bouyer /******************************************************************************
190 1.1.1.2.2.2 bouyer *
191 1.1.1.2.2.2 bouyer * FUNCTION: DtPeekSubtable
192 1.1.1.2.2.2 bouyer *
193 1.1.1.2.2.2 bouyer * PARAMETERS: None
194 1.1.1.2.2.2 bouyer *
195 1.1.1.2.2.2 bouyer * RETURN: The subtable on top of stack
196 1.1.1.2.2.2 bouyer *
197 1.1.1.2.2.2 bouyer * DESCRIPTION: Get the subtable on top of stack
198 1.1.1.2.2.2 bouyer *
199 1.1.1.2.2.2 bouyer *****************************************************************************/
200 1.1.1.2.2.2 bouyer
201 1.1.1.2.2.2 bouyer DT_SUBTABLE *
202 1.1.1.2.2.2 bouyer DtPeekSubtable (
203 1.1.1.2.2.2 bouyer void)
204 1.1.1.2.2.2 bouyer {
205 1.1.1.2.2.2 bouyer
206 1.1.1.2.2.2 bouyer return (Gbl_SubtableStack);
207 1.1.1.2.2.2 bouyer }
208 1.1.1.2.2.2 bouyer
209 1.1.1.2.2.2 bouyer
210 1.1.1.2.2.2 bouyer /******************************************************************************
211 1.1.1.2.2.2 bouyer *
212 1.1.1.2.2.2 bouyer * FUNCTION: DtGetNextSubtable
213 1.1.1.2.2.2 bouyer *
214 1.1.1.2.2.2 bouyer * PARAMETERS: ParentTable - Parent table whose children we are
215 1.1.1.2.2.2 bouyer * getting
216 1.1.1.2.2.2 bouyer * ChildTable - Previous child that was found.
217 1.1.1.2.2.2 bouyer * The NEXT child will be returned
218 1.1.1.2.2.2 bouyer *
219 1.1.1.2.2.2 bouyer * RETURN: Pointer to the NEXT child or NULL if none is found.
220 1.1.1.2.2.2 bouyer *
221 1.1.1.2.2.2 bouyer * DESCRIPTION: Return the next peer subtable within the tree.
222 1.1.1.2.2.2 bouyer *
223 1.1.1.2.2.2 bouyer *****************************************************************************/
224 1.1.1.2.2.2 bouyer
225 1.1.1.2.2.2 bouyer DT_SUBTABLE *
226 1.1.1.2.2.2 bouyer DtGetNextSubtable (
227 1.1.1.2.2.2 bouyer DT_SUBTABLE *ParentTable,
228 1.1.1.2.2.2 bouyer DT_SUBTABLE *ChildTable)
229 1.1.1.2.2.2 bouyer {
230 1.1.1.2.2.2 bouyer ACPI_FUNCTION_ENTRY ();
231 1.1.1.2.2.2 bouyer
232 1.1.1.2.2.2 bouyer
233 1.1.1.2.2.2 bouyer if (!ChildTable)
234 1.1.1.2.2.2 bouyer {
235 1.1.1.2.2.2 bouyer /* It's really the parent's _scope_ that we want */
236 1.1.1.2.2.2 bouyer
237 1.1.1.2.2.2 bouyer return (ParentTable->Child);
238 1.1.1.2.2.2 bouyer }
239 1.1.1.2.2.2 bouyer
240 1.1.1.2.2.2 bouyer /* Otherwise just return the next peer (NULL if at end-of-list) */
241 1.1.1.2.2.2 bouyer
242 1.1.1.2.2.2 bouyer return (ChildTable->Peer);
243 1.1.1.2.2.2 bouyer }
244 1.1.1.2.2.2 bouyer
245 1.1.1.2.2.2 bouyer
246 1.1.1.2.2.2 bouyer /******************************************************************************
247 1.1.1.2.2.2 bouyer *
248 1.1.1.2.2.2 bouyer * FUNCTION: DtGetParentSubtable
249 1.1.1.2.2.2 bouyer *
250 1.1.1.2.2.2 bouyer * PARAMETERS: Subtable - Current subtable
251 1.1.1.2.2.2 bouyer *
252 1.1.1.2.2.2 bouyer * RETURN: Parent of the given subtable
253 1.1.1.2.2.2 bouyer *
254 1.1.1.2.2.2 bouyer * DESCRIPTION: Get the parent of the given subtable in the tree
255 1.1.1.2.2.2 bouyer *
256 1.1.1.2.2.2 bouyer *****************************************************************************/
257 1.1.1.2.2.2 bouyer
258 1.1.1.2.2.2 bouyer DT_SUBTABLE *
259 1.1.1.2.2.2 bouyer DtGetParentSubtable (
260 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable)
261 1.1.1.2.2.2 bouyer {
262 1.1.1.2.2.2 bouyer
263 1.1.1.2.2.2 bouyer if (!Subtable)
264 1.1.1.2.2.2 bouyer {
265 1.1.1.2.2.2 bouyer return (NULL);
266 1.1.1.2.2.2 bouyer }
267 1.1.1.2.2.2 bouyer
268 1.1.1.2.2.2 bouyer return (Subtable->Parent);
269 1.1.1.2.2.2 bouyer }
270 1.1.1.2.2.2 bouyer
271 1.1.1.2.2.2 bouyer
272 1.1.1.2.2.2 bouyer /******************************************************************************
273 1.1.1.2.2.2 bouyer *
274 1.1.1.2.2.2 bouyer * FUNCTION: DtGetSubtableLength
275 1.1.1.2.2.2 bouyer *
276 1.1.1.2.2.2 bouyer * PARAMETERS: Field - Current field list pointer
277 1.1.1.2.2.2 bouyer * Info - Data table info
278 1.1.1.2.2.2 bouyer *
279 1.1.1.2.2.2 bouyer * RETURN: Subtable length
280 1.1.1.2.2.2 bouyer *
281 1.1.1.2.2.2 bouyer * DESCRIPTION: Get length of bytes needed to compile the subtable
282 1.1.1.2.2.2 bouyer *
283 1.1.1.2.2.2 bouyer *****************************************************************************/
284 1.1.1.2.2.2 bouyer
285 1.1.1.2.2.2 bouyer UINT32
286 1.1.1.2.2.2 bouyer DtGetSubtableLength (
287 1.1.1.2.2.2 bouyer DT_FIELD *Field,
288 1.1.1.2.2.2 bouyer ACPI_DMTABLE_INFO *Info)
289 1.1.1.2.2.2 bouyer {
290 1.1.1.2.2.2 bouyer UINT32 ByteLength = 0;
291 1.1.1.2.2.2 bouyer
292 1.1.1.2.2.2 bouyer
293 1.1.1.2.2.2 bouyer /* Walk entire Info table; Null name terminates */
294 1.1.1.2.2.2 bouyer
295 1.1.1.2.2.2 bouyer for (; Info->Name; Info++)
296 1.1.1.2.2.2 bouyer {
297 1.1.1.2.2.2 bouyer ByteLength += DtGetFieldLength (Field, Info);
298 1.1.1.2.2.2 bouyer }
299 1.1.1.2.2.2 bouyer
300 1.1.1.2.2.2 bouyer return (ByteLength);
301 1.1.1.2.2.2 bouyer }
302 1.1.1.2.2.2 bouyer
303 1.1.1.2.2.2 bouyer
304 1.1.1.2.2.2 bouyer /******************************************************************************
305 1.1.1.2.2.2 bouyer *
306 1.1.1.2.2.2 bouyer * FUNCTION: DtSetSubtableLength
307 1.1.1.2.2.2 bouyer *
308 1.1.1.2.2.2 bouyer * PARAMETERS: Subtable - Subtable
309 1.1.1.2.2.2 bouyer *
310 1.1.1.2.2.2 bouyer * RETURN: None
311 1.1.1.2.2.2 bouyer *
312 1.1.1.2.2.2 bouyer * DESCRIPTION: Set length of the subtable into its length field
313 1.1.1.2.2.2 bouyer *
314 1.1.1.2.2.2 bouyer *****************************************************************************/
315 1.1.1.2.2.2 bouyer
316 1.1.1.2.2.2 bouyer void
317 1.1.1.2.2.2 bouyer DtSetSubtableLength (
318 1.1.1.2.2.2 bouyer DT_SUBTABLE *Subtable)
319 1.1.1.2.2.2 bouyer {
320 1.1.1.2.2.2 bouyer
321 1.1.1.2.2.2 bouyer if (!Subtable->LengthField)
322 1.1.1.2.2.2 bouyer {
323 1.1.1.2.2.2 bouyer return;
324 1.1.1.2.2.2 bouyer }
325 1.1.1.2.2.2 bouyer
326 1.1.1.2.2.2 bouyer ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength,
327 1.1.1.2.2.2 bouyer Subtable->SizeOfLengthField);
328 1.1.1.2.2.2 bouyer }
329