dtcompile.c revision 1.17 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dtcompile.c - Front-end for data table compiler
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.17 christos * Copyright (C) 2000 - 2021, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.17 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #define _DECLARE_DT_GLOBALS
45 1.1 jruoho
46 1.1 jruoho #include "aslcompiler.h"
47 1.1 jruoho
48 1.1 jruoho #define _COMPONENT DT_COMPILER
49 1.1 jruoho ACPI_MODULE_NAME ("dtcompile")
50 1.1 jruoho
51 1.1 jruoho static char VersionString[9];
52 1.1 jruoho
53 1.1 jruoho
54 1.1 jruoho /* Local prototypes */
55 1.1 jruoho
56 1.14 christos void
57 1.1 jruoho DtInitialize (
58 1.1 jruoho void);
59 1.1 jruoho
60 1.1 jruoho static ACPI_STATUS
61 1.1 jruoho DtCompileDataTable (
62 1.1 jruoho DT_FIELD **Field);
63 1.1 jruoho
64 1.1 jruoho static void
65 1.1 jruoho DtInsertCompilerIds (
66 1.1 jruoho DT_FIELD *FieldList);
67 1.1 jruoho
68 1.1 jruoho
69 1.1 jruoho /******************************************************************************
70 1.1 jruoho *
71 1.1 jruoho * FUNCTION: DtDoCompile
72 1.1 jruoho *
73 1.1 jruoho * PARAMETERS: None
74 1.1 jruoho *
75 1.1 jruoho * RETURN: Status
76 1.1 jruoho *
77 1.1 jruoho * DESCRIPTION: Main entry point for the data table compiler.
78 1.1 jruoho *
79 1.12 christos * Note: Assumes AslGbl_Files[ASL_FILE_INPUT] is initialized and the file is
80 1.1 jruoho * open at seek offset zero.
81 1.1 jruoho *
82 1.1 jruoho *****************************************************************************/
83 1.1 jruoho
84 1.1 jruoho ACPI_STATUS
85 1.1 jruoho DtDoCompile (
86 1.1 jruoho void)
87 1.1 jruoho {
88 1.1 jruoho ACPI_STATUS Status;
89 1.1 jruoho UINT8 Event;
90 1.1 jruoho DT_FIELD *FieldList;
91 1.14 christos ASL_GLOBAL_FILE_NODE *FileNode;
92 1.1 jruoho
93 1.1 jruoho
94 1.1 jruoho /* Initialize globals */
95 1.1 jruoho
96 1.14 christos DtInitialize ();
97 1.2 christos
98 1.2 christos /* Preprocessor */
99 1.2 christos
100 1.12 christos if (AslGbl_PreprocessFlag)
101 1.5 christos {
102 1.5 christos /* Preprocessor */
103 1.5 christos
104 1.5 christos Event = UtBeginEvent ("Preprocess input file");
105 1.5 christos PrDoPreprocess ();
106 1.5 christos UtEndEvent (Event);
107 1.2 christos
108 1.12 christos if (AslGbl_PreprocessOnly)
109 1.5 christos {
110 1.5 christos return (AE_OK);
111 1.5 christos }
112 1.2 christos }
113 1.1 jruoho
114 1.14 christos /* Compile the parse tree */
115 1.14 christos
116 1.14 christos if (AslGbl_DtLexBisonPrototype)
117 1.14 christos {
118 1.14 christos Event = UtBeginEvent ("Parse data table in prototype mode");
119 1.14 christos
120 1.14 christos DtCompilerInitLexer (AslGbl_Files[ASL_FILE_INPUT].Handle);
121 1.14 christos DtCompilerParserparse ();
122 1.14 christos FieldList = AslGbl_FieldList;
123 1.14 christos DtCompilerTerminateLexer ();
124 1.14 christos
125 1.14 christos UtEndEvent (Event);
126 1.14 christos }
127 1.14 christos else
128 1.14 christos {
129 1.14 christos /*
130 1.14 christos * Scan the input file (file is already open) and
131 1.14 christos * build the parse tree
132 1.14 christos */
133 1.14 christos Event = UtBeginEvent ("Scan and parse input file");
134 1.14 christos FieldList = DtScanFile (AslGbl_Files[ASL_FILE_INPUT].Handle);
135 1.14 christos UtEndEvent (Event);
136 1.14 christos }
137 1.1 jruoho
138 1.1 jruoho /* Did the parse tree get successfully constructed? */
139 1.1 jruoho
140 1.1 jruoho if (!FieldList)
141 1.1 jruoho {
142 1.1 jruoho /* TBD: temporary error message. Msgs should come from function above */
143 1.1 jruoho
144 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
145 1.2 christos "Input file does not appear to be an ASL or data table source file");
146 1.2 christos
147 1.13 christos return (AE_ERROR);
148 1.1 jruoho }
149 1.1 jruoho
150 1.1 jruoho Event = UtBeginEvent ("Compile parse tree");
151 1.1 jruoho
152 1.1 jruoho Status = DtCompileDataTable (&FieldList);
153 1.1 jruoho UtEndEvent (Event);
154 1.1 jruoho
155 1.14 christos FileNode = FlGetCurrentFileNode ();
156 1.15 christos
157 1.15 christos FileNode->TotalLineCount = AslGbl_CurrentLineNumber;
158 1.15 christos FileNode->OriginalInputFileSize = AslGbl_InputByteCount;
159 1.15 christos DbgPrint (ASL_PARSE_OUTPUT, "Line count: %u input file size: %u\n",
160 1.15 christos FileNode->TotalLineCount, FileNode->OriginalInputFileSize);
161 1.14 christos
162 1.1 jruoho if (ACPI_FAILURE (Status))
163 1.1 jruoho {
164 1.14 christos FileNode->ParserErrorDetected = TRUE;
165 1.14 christos
166 1.1 jruoho /* TBD: temporary error message. Msgs should come from function above */
167 1.1 jruoho
168 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
169 1.1 jruoho "Could not compile input file");
170 1.2 christos
171 1.13 christos return (Status);
172 1.1 jruoho }
173 1.1 jruoho
174 1.1 jruoho /* Create/open the binary output file */
175 1.1 jruoho
176 1.12 christos AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
177 1.12 christos Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
178 1.1 jruoho if (ACPI_FAILURE (Status))
179 1.1 jruoho {
180 1.13 christos return (Status);
181 1.1 jruoho }
182 1.1 jruoho
183 1.1 jruoho /* Write the binary, then the optional hex file */
184 1.1 jruoho
185 1.12 christos DtOutputBinary (AslGbl_RootTable);
186 1.2 christos HxDoHexOutput ();
187 1.2 christos DtWriteTableToListing ();
188 1.1 jruoho
189 1.14 christos /* Save the compile time statistics to the current file node */
190 1.14 christos
191 1.15 christos FileNode->TotalFields = AslGbl_InputFieldCount;
192 1.15 christos FileNode->OutputByteLength = AslGbl_TableLength;
193 1.14 christos
194 1.1 jruoho return (Status);
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho
198 1.1 jruoho /******************************************************************************
199 1.1 jruoho *
200 1.1 jruoho * FUNCTION: DtInitialize
201 1.1 jruoho *
202 1.1 jruoho * PARAMETERS: None
203 1.1 jruoho *
204 1.2 christos * RETURN: Status
205 1.1 jruoho *
206 1.1 jruoho * DESCRIPTION: Initialize data table compiler globals. Enables multiple
207 1.1 jruoho * compiles per invocation.
208 1.1 jruoho *
209 1.1 jruoho *****************************************************************************/
210 1.1 jruoho
211 1.14 christos void
212 1.1 jruoho DtInitialize (
213 1.1 jruoho void)
214 1.1 jruoho {
215 1.2 christos
216 1.2 christos
217 1.9 christos AcpiUtSetIntegerWidth (2); /* Set width to 64 bits */
218 1.9 christos
219 1.12 christos AslGbl_FieldList = NULL;
220 1.12 christos AslGbl_RootTable = NULL;
221 1.12 christos AslGbl_SubtableStack = NULL;
222 1.1 jruoho
223 1.3 tron snprintf (VersionString, sizeof(VersionString), "%X",
224 1.2 christos (UINT32) ACPI_CA_VERSION);
225 1.14 christos return;
226 1.1 jruoho }
227 1.1 jruoho
228 1.1 jruoho
229 1.1 jruoho /******************************************************************************
230 1.1 jruoho *
231 1.1 jruoho * FUNCTION: DtInsertCompilerIds
232 1.1 jruoho *
233 1.1 jruoho * PARAMETERS: FieldList - Current field list pointer
234 1.1 jruoho *
235 1.1 jruoho * RETURN: None
236 1.1 jruoho *
237 1.1 jruoho * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
238 1.1 jruoho * the original ACPI table header.
239 1.1 jruoho *
240 1.1 jruoho *****************************************************************************/
241 1.1 jruoho
242 1.1 jruoho static void
243 1.1 jruoho DtInsertCompilerIds (
244 1.1 jruoho DT_FIELD *FieldList)
245 1.1 jruoho {
246 1.1 jruoho DT_FIELD *Next;
247 1.1 jruoho UINT32 i;
248 1.1 jruoho
249 1.1 jruoho
250 1.1 jruoho /*
251 1.1 jruoho * Don't insert current compiler ID if requested. Used for compiler
252 1.1 jruoho * debug/validation only.
253 1.1 jruoho */
254 1.12 christos if (AslGbl_UseOriginalCompilerId)
255 1.1 jruoho {
256 1.1 jruoho return;
257 1.1 jruoho }
258 1.1 jruoho
259 1.1 jruoho /* Walk to the Compiler fields at the end of the header */
260 1.1 jruoho
261 1.1 jruoho Next = FieldList;
262 1.1 jruoho for (i = 0; i < 7; i++)
263 1.1 jruoho {
264 1.1 jruoho Next = Next->Next;
265 1.1 jruoho }
266 1.1 jruoho
267 1.2 christos Next->Value = ASL_CREATOR_ID;
268 1.1 jruoho Next->Flags = DT_FIELD_NOT_ALLOCATED;
269 1.1 jruoho
270 1.1 jruoho Next = Next->Next;
271 1.1 jruoho Next->Value = VersionString;
272 1.1 jruoho Next->Flags = DT_FIELD_NOT_ALLOCATED;
273 1.1 jruoho }
274 1.1 jruoho
275 1.1 jruoho
276 1.1 jruoho /******************************************************************************
277 1.1 jruoho *
278 1.1 jruoho * FUNCTION: DtCompileDataTable
279 1.1 jruoho *
280 1.1 jruoho * PARAMETERS: FieldList - Current field list pointer
281 1.1 jruoho *
282 1.1 jruoho * RETURN: Status
283 1.1 jruoho *
284 1.1 jruoho * DESCRIPTION: Entry point to compile one data table
285 1.1 jruoho *
286 1.1 jruoho *****************************************************************************/
287 1.1 jruoho
288 1.1 jruoho static ACPI_STATUS
289 1.1 jruoho DtCompileDataTable (
290 1.1 jruoho DT_FIELD **FieldList)
291 1.1 jruoho {
292 1.6 christos const ACPI_DMTABLE_DATA *TableData;
293 1.1 jruoho DT_SUBTABLE *Subtable;
294 1.1 jruoho char *Signature;
295 1.1 jruoho ACPI_TABLE_HEADER *AcpiTableHeader;
296 1.1 jruoho ACPI_STATUS Status;
297 1.2 christos DT_FIELD *RootField = *FieldList;
298 1.1 jruoho
299 1.1 jruoho
300 1.1 jruoho /* Verify that we at least have a table signature and save it */
301 1.1 jruoho
302 1.2 christos Signature = DtGetFieldValue (*FieldList);
303 1.1 jruoho if (!Signature)
304 1.1 jruoho {
305 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", "Signature");
306 1.2 christos DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
307 1.12 christos *FieldList, AslGbl_MsgBuffer);
308 1.1 jruoho return (AE_ERROR);
309 1.1 jruoho }
310 1.1 jruoho
311 1.12 christos AslGbl_Signature = UtLocalCacheCalloc (strlen (Signature) + 1);
312 1.12 christos strcpy (AslGbl_Signature, Signature);
313 1.1 jruoho
314 1.1 jruoho /*
315 1.1 jruoho * Handle tables that don't use the common ACPI table header structure.
316 1.1 jruoho * Currently, these are the FACS and RSDP. Also check for an OEMx table,
317 1.1 jruoho * these tables have user-defined contents.
318 1.1 jruoho */
319 1.13 christos if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS))
320 1.1 jruoho {
321 1.1 jruoho Status = DtCompileFacs (FieldList);
322 1.1 jruoho if (ACPI_FAILURE (Status))
323 1.1 jruoho {
324 1.1 jruoho return (Status);
325 1.1 jruoho }
326 1.1 jruoho
327 1.1 jruoho DtSetTableLength ();
328 1.1 jruoho return (Status);
329 1.1 jruoho }
330 1.2 christos else if (ACPI_VALIDATE_RSDP_SIG (Signature))
331 1.1 jruoho {
332 1.1 jruoho Status = DtCompileRsdp (FieldList);
333 1.1 jruoho return (Status);
334 1.1 jruoho }
335 1.13 christos else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_S3PT))
336 1.1 jruoho {
337 1.2 christos Status = DtCompileS3pt (FieldList);
338 1.2 christos if (ACPI_FAILURE (Status))
339 1.2 christos {
340 1.2 christos return (Status);
341 1.2 christos }
342 1.2 christos
343 1.2 christos DtSetTableLength ();
344 1.2 christos return (Status);
345 1.1 jruoho }
346 1.1 jruoho
347 1.1 jruoho /*
348 1.1 jruoho * All other tables must use the common ACPI table header. Insert the
349 1.1 jruoho * current iASL IDs (name, version), and compile the header now.
350 1.1 jruoho */
351 1.1 jruoho DtInsertCompilerIds (*FieldList);
352 1.1 jruoho
353 1.1 jruoho Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
354 1.12 christos &AslGbl_RootTable);
355 1.1 jruoho if (ACPI_FAILURE (Status))
356 1.1 jruoho {
357 1.1 jruoho return (Status);
358 1.1 jruoho }
359 1.1 jruoho
360 1.12 christos DtPushSubtable (AslGbl_RootTable);
361 1.1 jruoho
362 1.2 christos /* Validate the signature via the ACPI table list */
363 1.1 jruoho
364 1.1 jruoho TableData = AcpiDmGetTableData (Signature);
365 1.12 christos if (!TableData || AslGbl_CompileGeneric)
366 1.1 jruoho {
367 1.6 christos /* Unknown table signature and/or force generic compile */
368 1.6 christos
369 1.6 christos DtCompileGeneric ((void **) FieldList, NULL, NULL);
370 1.2 christos goto FinishHeader;
371 1.1 jruoho }
372 1.1 jruoho
373 1.2 christos /* Dispatch to per-table compile */
374 1.2 christos
375 1.1 jruoho if (TableData->CmTableHandler)
376 1.1 jruoho {
377 1.1 jruoho /* Complex table, has a handler */
378 1.1 jruoho
379 1.1 jruoho Status = TableData->CmTableHandler ((void **) FieldList);
380 1.1 jruoho if (ACPI_FAILURE (Status))
381 1.1 jruoho {
382 1.1 jruoho return (Status);
383 1.1 jruoho }
384 1.1 jruoho }
385 1.1 jruoho else if (TableData->TableInfo)
386 1.1 jruoho {
387 1.9 christos /* Simple table, just walk the info table, unless its empty */
388 1.1 jruoho
389 1.9 christos if (FieldList && *FieldList)
390 1.1 jruoho {
391 1.9 christos Subtable = NULL;
392 1.9 christos Status = DtCompileTable (FieldList, TableData->TableInfo,
393 1.11 christos &Subtable);
394 1.9 christos if (ACPI_FAILURE (Status))
395 1.9 christos {
396 1.9 christos return (Status);
397 1.9 christos }
398 1.9 christos
399 1.12 christos DtInsertSubtable (AslGbl_RootTable, Subtable);
400 1.9 christos DtPopSubtable ();
401 1.1 jruoho }
402 1.1 jruoho }
403 1.1 jruoho else
404 1.1 jruoho {
405 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
406 1.1 jruoho "Missing table dispatch info");
407 1.1 jruoho return (AE_ERROR);
408 1.1 jruoho }
409 1.1 jruoho
410 1.2 christos FinishHeader:
411 1.2 christos
412 1.1 jruoho /* Set the final table length and then the checksum */
413 1.1 jruoho
414 1.1 jruoho DtSetTableLength ();
415 1.1 jruoho AcpiTableHeader = ACPI_CAST_PTR (
416 1.12 christos ACPI_TABLE_HEADER, AslGbl_RootTable->Buffer);
417 1.1 jruoho DtSetTableChecksum (&AcpiTableHeader->Checksum);
418 1.1 jruoho
419 1.2 christos DtDumpFieldList (RootField);
420 1.2 christos DtDumpSubtableList ();
421 1.1 jruoho return (AE_OK);
422 1.1 jruoho }
423 1.1 jruoho
424 1.1 jruoho
425 1.1 jruoho /******************************************************************************
426 1.1 jruoho *
427 1.1 jruoho * FUNCTION: DtCompileTable
428 1.1 jruoho *
429 1.1 jruoho * PARAMETERS: Field - Current field list pointer
430 1.1 jruoho * Info - Info table for this ACPI table
431 1.1 jruoho * RetSubtable - Compile result of table
432 1.1 jruoho *
433 1.1 jruoho * RETURN: Status
434 1.1 jruoho *
435 1.1 jruoho * DESCRIPTION: Compile a subtable
436 1.1 jruoho *
437 1.1 jruoho *****************************************************************************/
438 1.1 jruoho
439 1.1 jruoho ACPI_STATUS
440 1.1 jruoho DtCompileTable (
441 1.1 jruoho DT_FIELD **Field,
442 1.1 jruoho ACPI_DMTABLE_INFO *Info,
443 1.11 christos DT_SUBTABLE **RetSubtable)
444 1.1 jruoho {
445 1.1 jruoho DT_FIELD *LocalField;
446 1.1 jruoho UINT32 Length;
447 1.1 jruoho DT_SUBTABLE *Subtable;
448 1.6 christos DT_SUBTABLE *InlineSubtable = NULL;
449 1.1 jruoho UINT32 FieldLength = 0;
450 1.1 jruoho UINT8 FieldType;
451 1.1 jruoho UINT8 *Buffer;
452 1.1 jruoho UINT8 *FlagBuffer = NULL;
453 1.4 christos char *String;
454 1.2 christos UINT32 CurrentFlagByteOffset = 0;
455 1.6 christos ACPI_STATUS Status = AE_OK;
456 1.1 jruoho
457 1.1 jruoho
458 1.15 christos if (!Field || !Info)
459 1.1 jruoho {
460 1.1 jruoho return (AE_BAD_PARAMETER);
461 1.1 jruoho }
462 1.11 christos if (!*Field)
463 1.11 christos {
464 1.11 christos /*
465 1.11 christos * The field list is empty, this means that we are out of fields to
466 1.11 christos * parse. In other words, we are at the end of the table.
467 1.11 christos */
468 1.11 christos return (AE_END_OF_TABLE);
469 1.11 christos }
470 1.1 jruoho
471 1.2 christos /* Ignore optional subtable if name does not match */
472 1.2 christos
473 1.2 christos if ((Info->Flags & DT_OPTIONAL) &&
474 1.6 christos strcmp ((*Field)->Name, Info->Name))
475 1.2 christos {
476 1.2 christos *RetSubtable = NULL;
477 1.2 christos return (AE_OK);
478 1.2 christos }
479 1.2 christos
480 1.1 jruoho Length = DtGetSubtableLength (*Field, Info);
481 1.2 christos if (Length == ASL_EOF)
482 1.2 christos {
483 1.2 christos return (AE_ERROR);
484 1.2 christos }
485 1.2 christos
486 1.4 christos Subtable = UtSubtableCacheCalloc ();
487 1.1 jruoho
488 1.2 christos if (Length > 0)
489 1.2 christos {
490 1.10 christos String = UtLocalCacheCalloc (Length);
491 1.4 christos Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
492 1.2 christos }
493 1.4 christos
494 1.1 jruoho Subtable->Length = Length;
495 1.1 jruoho Subtable->TotalLength = Length;
496 1.1 jruoho Buffer = Subtable->Buffer;
497 1.1 jruoho
498 1.1 jruoho LocalField = *Field;
499 1.6 christos Subtable->Name = LocalField->Name;
500 1.1 jruoho
501 1.1 jruoho /*
502 1.1 jruoho * Main loop walks the info table for this ACPI table or subtable
503 1.1 jruoho */
504 1.1 jruoho for (; Info->Name; Info++)
505 1.1 jruoho {
506 1.2 christos if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
507 1.2 christos {
508 1.2 christos continue;
509 1.2 christos }
510 1.2 christos
511 1.1 jruoho if (!LocalField)
512 1.1 jruoho {
513 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Found NULL field - Field name \"%s\" needed",
514 1.1 jruoho Info->Name);
515 1.12 christos DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
516 1.1 jruoho Status = AE_BAD_DATA;
517 1.1 jruoho goto Error;
518 1.1 jruoho }
519 1.1 jruoho
520 1.2 christos /* Maintain table offsets */
521 1.1 jruoho
522 1.12 christos LocalField->TableOffset = AslGbl_CurrentTableOffset;
523 1.2 christos FieldLength = DtGetFieldLength (LocalField, Info);
524 1.12 christos AslGbl_CurrentTableOffset += FieldLength;
525 1.1 jruoho
526 1.1 jruoho FieldType = DtGetFieldType (Info);
527 1.12 christos AslGbl_InputFieldCount++;
528 1.1 jruoho
529 1.15 christos if (FieldType != DT_FIELD_TYPE_INLINE_SUBTABLE &&
530 1.15 christos strcmp (Info->Name, LocalField->Name))
531 1.15 christos {
532 1.15 christos sprintf (AslGbl_MsgBuffer, "found \"%s\" expected \"%s\"",
533 1.15 christos LocalField->Name, Info->Name);
534 1.15 christos DtError (ASL_ERROR, ASL_MSG_INVALID_LABEL, LocalField, AslGbl_MsgBuffer);
535 1.15 christos }
536 1.15 christos
537 1.1 jruoho switch (FieldType)
538 1.1 jruoho {
539 1.1 jruoho case DT_FIELD_TYPE_FLAGS_INTEGER:
540 1.1 jruoho /*
541 1.1 jruoho * Start of the definition of a flags field.
542 1.1 jruoho * This master flags integer starts at value zero, in preparation
543 1.1 jruoho * to compile and insert the flag fields from the individual bits
544 1.1 jruoho */
545 1.1 jruoho LocalField = LocalField->Next;
546 1.1 jruoho *Field = LocalField;
547 1.1 jruoho
548 1.1 jruoho FlagBuffer = Buffer;
549 1.2 christos CurrentFlagByteOffset = Info->Offset;
550 1.1 jruoho break;
551 1.1 jruoho
552 1.1 jruoho case DT_FIELD_TYPE_FLAG:
553 1.1 jruoho
554 1.1 jruoho /* Individual Flag field, can be multiple bits */
555 1.1 jruoho
556 1.1 jruoho if (FlagBuffer)
557 1.1 jruoho {
558 1.2 christos /*
559 1.2 christos * We must increment the FlagBuffer when we have crossed
560 1.2 christos * into the next flags byte within the flags field
561 1.2 christos * of type DT_FIELD_TYPE_FLAGS_INTEGER.
562 1.2 christos */
563 1.2 christos FlagBuffer += (Info->Offset - CurrentFlagByteOffset);
564 1.2 christos CurrentFlagByteOffset = Info->Offset;
565 1.2 christos
566 1.2 christos DtCompileFlag (FlagBuffer, LocalField, Info);
567 1.1 jruoho }
568 1.1 jruoho else
569 1.1 jruoho {
570 1.1 jruoho /* TBD - this is an internal error */
571 1.1 jruoho }
572 1.1 jruoho
573 1.1 jruoho LocalField = LocalField->Next;
574 1.1 jruoho *Field = LocalField;
575 1.1 jruoho break;
576 1.1 jruoho
577 1.1 jruoho case DT_FIELD_TYPE_INLINE_SUBTABLE:
578 1.1 jruoho /*
579 1.1 jruoho * Recursion (one level max): compile GAS (Generic Address)
580 1.1 jruoho * or Notify in-line subtable
581 1.1 jruoho */
582 1.1 jruoho *Field = LocalField;
583 1.1 jruoho
584 1.6 christos switch (Info->Opcode)
585 1.1 jruoho {
586 1.6 christos case ACPI_DMT_GAS:
587 1.6 christos
588 1.1 jruoho Status = DtCompileTable (Field, AcpiDmTableInfoGas,
589 1.11 christos &InlineSubtable);
590 1.6 christos break;
591 1.6 christos
592 1.6 christos case ACPI_DMT_HESTNTFY:
593 1.6 christos
594 1.1 jruoho Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
595 1.11 christos &InlineSubtable);
596 1.6 christos break;
597 1.6 christos
598 1.6 christos case ACPI_DMT_IORTMEM:
599 1.6 christos
600 1.6 christos Status = DtCompileTable (Field, AcpiDmTableInfoIortAcc,
601 1.11 christos &InlineSubtable);
602 1.6 christos break;
603 1.6 christos
604 1.6 christos default:
605 1.12 christos sprintf (AslGbl_MsgBuffer, "Invalid DMT opcode: 0x%.2X",
606 1.6 christos Info->Opcode);
607 1.12 christos DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
608 1.6 christos Status = AE_BAD_DATA;
609 1.6 christos break;
610 1.1 jruoho }
611 1.1 jruoho
612 1.1 jruoho if (ACPI_FAILURE (Status))
613 1.1 jruoho {
614 1.1 jruoho goto Error;
615 1.1 jruoho }
616 1.1 jruoho
617 1.2 christos DtSetSubtableLength (InlineSubtable);
618 1.2 christos
619 1.6 christos memcpy (Buffer, InlineSubtable->Buffer, FieldLength);
620 1.1 jruoho LocalField = *Field;
621 1.1 jruoho break;
622 1.1 jruoho
623 1.2 christos case DT_FIELD_TYPE_LABEL:
624 1.2 christos
625 1.2 christos DtWriteFieldToListing (Buffer, LocalField, 0);
626 1.2 christos LocalField = LocalField->Next;
627 1.2 christos break;
628 1.2 christos
629 1.1 jruoho default:
630 1.1 jruoho
631 1.1 jruoho /* Normal case for most field types (Integer, String, etc.) */
632 1.1 jruoho
633 1.1 jruoho DtCompileOneField (Buffer, LocalField,
634 1.1 jruoho FieldLength, FieldType, Info->Flags);
635 1.2 christos
636 1.2 christos DtWriteFieldToListing (Buffer, LocalField, FieldLength);
637 1.1 jruoho LocalField = LocalField->Next;
638 1.1 jruoho
639 1.1 jruoho if (Info->Flags & DT_LENGTH)
640 1.1 jruoho {
641 1.1 jruoho /* Field is an Integer that will contain a subtable length */
642 1.1 jruoho
643 1.1 jruoho Subtable->LengthField = Buffer;
644 1.1 jruoho Subtable->SizeOfLengthField = FieldLength;
645 1.1 jruoho }
646 1.1 jruoho break;
647 1.1 jruoho }
648 1.1 jruoho
649 1.1 jruoho Buffer += FieldLength;
650 1.1 jruoho }
651 1.1 jruoho
652 1.1 jruoho *Field = LocalField;
653 1.1 jruoho *RetSubtable = Subtable;
654 1.1 jruoho return (AE_OK);
655 1.1 jruoho
656 1.1 jruoho Error:
657 1.1 jruoho ACPI_FREE (Subtable->Buffer);
658 1.1 jruoho ACPI_FREE (Subtable);
659 1.1 jruoho return (Status);
660 1.1 jruoho }
661 1.6 christos
662 1.6 christos
663 1.6 christos /******************************************************************************
664 1.6 christos *
665 1.7 christos * FUNCTION: DtCompileTwoSubtables
666 1.7 christos *
667 1.7 christos * PARAMETERS: List - Current field list pointer
668 1.7 christos * TableInfo1 - Info table 1
669 1.7 christos * TableInfo1 - Info table 2
670 1.7 christos *
671 1.7 christos * RETURN: Status
672 1.7 christos *
673 1.7 christos * DESCRIPTION: Compile tables with a header and one or more same subtables.
674 1.7 christos * Include CPEP, EINJ, ERST, MCFG, MSCT, WDAT
675 1.7 christos *
676 1.7 christos *****************************************************************************/
677 1.7 christos
678 1.7 christos ACPI_STATUS
679 1.7 christos DtCompileTwoSubtables (
680 1.7 christos void **List,
681 1.7 christos ACPI_DMTABLE_INFO *TableInfo1,
682 1.7 christos ACPI_DMTABLE_INFO *TableInfo2)
683 1.7 christos {
684 1.7 christos ACPI_STATUS Status;
685 1.7 christos DT_SUBTABLE *Subtable;
686 1.7 christos DT_SUBTABLE *ParentTable;
687 1.7 christos DT_FIELD **PFieldList = (DT_FIELD **) List;
688 1.7 christos
689 1.7 christos
690 1.11 christos Status = DtCompileTable (PFieldList, TableInfo1, &Subtable);
691 1.7 christos if (ACPI_FAILURE (Status))
692 1.7 christos {
693 1.7 christos return (Status);
694 1.7 christos }
695 1.7 christos
696 1.7 christos ParentTable = DtPeekSubtable ();
697 1.7 christos DtInsertSubtable (ParentTable, Subtable);
698 1.7 christos
699 1.7 christos while (*PFieldList)
700 1.7 christos {
701 1.11 christos Status = DtCompileTable (PFieldList, TableInfo2, &Subtable);
702 1.7 christos if (ACPI_FAILURE (Status))
703 1.7 christos {
704 1.7 christos return (Status);
705 1.7 christos }
706 1.7 christos
707 1.7 christos DtInsertSubtable (ParentTable, Subtable);
708 1.7 christos }
709 1.7 christos
710 1.7 christos return (AE_OK);
711 1.7 christos }
712 1.7 christos
713 1.7 christos
714 1.7 christos /******************************************************************************
715 1.7 christos *
716 1.6 christos * FUNCTION: DtCompilePadding
717 1.6 christos *
718 1.6 christos * PARAMETERS: Length - Padding field size
719 1.6 christos * RetSubtable - Compile result of table
720 1.6 christos *
721 1.6 christos * RETURN: Status
722 1.6 christos *
723 1.6 christos * DESCRIPTION: Compile a subtable for padding purpose
724 1.6 christos *
725 1.6 christos *****************************************************************************/
726 1.6 christos
727 1.6 christos ACPI_STATUS
728 1.6 christos DtCompilePadding (
729 1.6 christos UINT32 Length,
730 1.6 christos DT_SUBTABLE **RetSubtable)
731 1.6 christos {
732 1.6 christos DT_SUBTABLE *Subtable;
733 1.6 christos /* UINT8 *Buffer; */
734 1.6 christos char *String;
735 1.6 christos
736 1.6 christos
737 1.6 christos Subtable = UtSubtableCacheCalloc ();
738 1.6 christos
739 1.6 christos if (Length > 0)
740 1.6 christos {
741 1.10 christos String = UtLocalCacheCalloc (Length);
742 1.6 christos Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
743 1.6 christos }
744 1.6 christos
745 1.6 christos Subtable->Length = Length;
746 1.6 christos Subtable->TotalLength = Length;
747 1.6 christos /* Buffer = Subtable->Buffer; */
748 1.6 christos
749 1.6 christos *RetSubtable = Subtable;
750 1.6 christos return (AE_OK);
751 1.6 christos }
752