dtcompile.c revision 208625
1208625Sjkim/******************************************************************************
2208625Sjkim *
3208625Sjkim * Module Name: dtcompile.c - Front-end for data table compiler
4208625Sjkim *
5208625Sjkim *****************************************************************************/
6208625Sjkim
7208625Sjkim/******************************************************************************
8208625Sjkim *
9208625Sjkim * 1. Copyright Notice
10208625Sjkim *
11208625Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12208625Sjkim * All rights reserved.
13208625Sjkim *
14208625Sjkim * 2. License
15208625Sjkim *
16208625Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17208625Sjkim * rights.  You may have additional license terms from the party that provided
18208625Sjkim * you this software, covering your right to use that party's intellectual
19208625Sjkim * property rights.
20208625Sjkim *
21208625Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22208625Sjkim * copy of the source code appearing in this file ("Covered Code") an
23208625Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24208625Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25208625Sjkim * make derivatives, distribute, use and display any portion of the Covered
26208625Sjkim * Code in any form, with the right to sublicense such rights; and
27208625Sjkim *
28208625Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29208625Sjkim * license (with the right to sublicense), under only those claims of Intel
30208625Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31208625Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32208625Sjkim * solely to the minimum extent necessary to exercise the above copyright
33208625Sjkim * license, and in no event shall the patent license extend to any additions
34208625Sjkim * to or modifications of the Original Intel Code.  No other license or right
35208625Sjkim * is granted directly or by implication, estoppel or otherwise;
36208625Sjkim *
37208625Sjkim * The above copyright and patent license is granted only if the following
38208625Sjkim * conditions are met:
39208625Sjkim *
40208625Sjkim * 3. Conditions
41208625Sjkim *
42208625Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43208625Sjkim * Redistribution of source code of any substantial portion of the Covered
44208625Sjkim * Code or modification with rights to further distribute source must include
45208625Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46208625Sjkim * and the following Disclaimer and Export Compliance provision.  In addition,
47208625Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48208625Sjkim * contain a file documenting the changes Licensee made to create that Covered
49208625Sjkim * Code and the date of any change.  Licensee must include in that file the
50208625Sjkim * documentation of any changes made by any predecessor Licensee.  Licensee
51208625Sjkim * must include a prominent statement that the modification is derived,
52208625Sjkim * directly or indirectly, from Original Intel Code.
53208625Sjkim *
54208625Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55208625Sjkim * Redistribution of source code of any substantial portion of the Covered
56208625Sjkim * Code or modification without rights to further distribute source must
57208625Sjkim * include the following Disclaimer and Export Compliance provision in the
58208625Sjkim * documentation and/or other materials provided with distribution.  In
59208625Sjkim * addition, Licensee may not authorize further sublicense of source of any
60208625Sjkim * portion of the Covered Code, and must include terms to the effect that the
61208625Sjkim * license from Licensee to its licensee is limited to the intellectual
62208625Sjkim * property embodied in the software Licensee provides to its licensee, and
63208625Sjkim * not to intellectual property embodied in modifications its licensee may
64208625Sjkim * make.
65208625Sjkim *
66208625Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67208625Sjkim * substantial portion of the Covered Code or modification must reproduce the
68208625Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69208625Sjkim * provision in the documentation and/or other materials provided with the
70208625Sjkim * distribution.
71208625Sjkim *
72208625Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73208625Sjkim * Intel Code.
74208625Sjkim *
75208625Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76208625Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77208625Sjkim * other dealings in products derived from or relating to the Covered Code
78208625Sjkim * without prior written authorization from Intel.
79208625Sjkim *
80208625Sjkim * 4. Disclaimer and Export Compliance
81208625Sjkim *
82208625Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83208625Sjkim * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84208625Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85208625Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86208625Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87208625Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88208625Sjkim * PARTICULAR PURPOSE.
89208625Sjkim *
90208625Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91208625Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92208625Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93208625Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94208625Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95208625Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96208625Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97208625Sjkim * LIMITED REMEDY.
98208625Sjkim *
99208625Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100208625Sjkim * software or system incorporating such software without first obtaining any
101208625Sjkim * required license or other approval from the U. S. Department of Commerce or
102208625Sjkim * any other agency or department of the United States Government.  In the
103208625Sjkim * event Licensee exports any such software from the United States or
104208625Sjkim * re-exports any such software from a foreign destination, Licensee shall
105208625Sjkim * ensure that the distribution and export/re-export of the software is in
106208625Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107208625Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108208625Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109208625Sjkim * software, or service, directly or indirectly, to any country for which the
110208625Sjkim * United States government or any agency thereof requires an export license,
111208625Sjkim * other governmental approval, or letter of assurance, without first obtaining
112208625Sjkim * such license, approval or letter.
113208625Sjkim *
114208625Sjkim *****************************************************************************/
115208625Sjkim
116208625Sjkim#define __DTCOMPILE_C__
117208625Sjkim#define _DECLARE_DT_GLOBALS
118208625Sjkim
119208625Sjkim#include "aslcompiler.h"
120208625Sjkim#include "dtcompiler.h"
121208625Sjkim
122208625Sjkim#define _COMPONENT          DT_COMPILER
123208625Sjkim        ACPI_MODULE_NAME    ("dtcompile")
124208625Sjkim
125208625Sjkimstatic char                 VersionString[9];
126208625Sjkim
127208625Sjkim
128208625Sjkim/* Local prototypes */
129208625Sjkim
130208625Sjkimstatic void
131208625SjkimDtInitialize (
132208625Sjkim    void);
133208625Sjkim
134208625Sjkimstatic ACPI_STATUS
135208625SjkimDtCompileDataTable (
136208625Sjkim    DT_FIELD                **Field);
137208625Sjkim
138208625Sjkimstatic void
139208625SjkimDtInsertCompilerIds (
140208625Sjkim    DT_FIELD                *FieldList);
141208625Sjkim
142208625Sjkim
143208625Sjkim/******************************************************************************
144208625Sjkim *
145208625Sjkim * FUNCTION:    DtDoCompile
146208625Sjkim *
147208625Sjkim * PARAMETERS:  None
148208625Sjkim *
149208625Sjkim * RETURN:      Status
150208625Sjkim *
151208625Sjkim * DESCRIPTION: Main entry point for the data table compiler.
152208625Sjkim *
153208625Sjkim * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is
154208625Sjkim *          open at seek offset zero.
155208625Sjkim *
156208625Sjkim *****************************************************************************/
157208625Sjkim
158208625SjkimACPI_STATUS
159208625SjkimDtDoCompile (
160208625Sjkim    void)
161208625Sjkim{
162208625Sjkim    ACPI_STATUS             Status;
163208625Sjkim    UINT8                   Event;
164208625Sjkim    DT_FIELD                *FieldList;
165208625Sjkim
166208625Sjkim
167208625Sjkim    /* Initialize globals */
168208625Sjkim
169208625Sjkim    DtInitialize ();
170208625Sjkim
171208625Sjkim    /*
172208625Sjkim     * Scan the input file (file is already open) and
173208625Sjkim     * build the parse tree
174208625Sjkim     */
175208625Sjkim    Event = UtBeginEvent ("Scan and parse input file");
176208625Sjkim    FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle);
177208625Sjkim    UtEndEvent (Event);
178208625Sjkim
179208625Sjkim    /* Did the parse tree get successfully constructed? */
180208625Sjkim
181208625Sjkim    if (!FieldList)
182208625Sjkim    {
183208625Sjkim        /* TBD: temporary error message. Msgs should come from function above */
184208625Sjkim
185208625Sjkim        DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
186208625Sjkim            "Could not parse input file");
187208625Sjkim        return (AE_ERROR);
188208625Sjkim    }
189208625Sjkim
190208625Sjkim    Event = UtBeginEvent ("Compile parse tree");
191208625Sjkim
192208625Sjkim    /*
193208625Sjkim     * Compile the parse tree
194208625Sjkim     */
195208625Sjkim    Status = DtCompileDataTable (&FieldList);
196208625Sjkim    UtEndEvent (Event);
197208625Sjkim
198208625Sjkim    DtFreeFieldList ();
199208625Sjkim
200208625Sjkim    if (ACPI_FAILURE (Status))
201208625Sjkim    {
202208625Sjkim        /* TBD: temporary error message. Msgs should come from function above */
203208625Sjkim
204208625Sjkim        DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
205208625Sjkim            "Could not compile input file");
206208625Sjkim        goto CleanupAndExit;
207208625Sjkim    }
208208625Sjkim
209208625Sjkim    /* Create/open the binary output file */
210208625Sjkim
211208625Sjkim    Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
212208625Sjkim    Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
213208625Sjkim    if (ACPI_FAILURE (Status))
214208625Sjkim    {
215208625Sjkim        goto CleanupAndExit;
216208625Sjkim    }
217208625Sjkim
218208625Sjkim    /* Write the binary, then the optional hex file */
219208625Sjkim
220208625Sjkim    DtOutputBinary (Gbl_RootTable);
221208625Sjkim    LsDoHexOutput ();
222208625Sjkim
223208625SjkimCleanupAndExit:
224208625Sjkim
225208625Sjkim    CmCleanupAndExit ();
226208625Sjkim    return (Status);
227208625Sjkim}
228208625Sjkim
229208625Sjkim
230208625Sjkim/******************************************************************************
231208625Sjkim *
232208625Sjkim * FUNCTION:    DtInitialize
233208625Sjkim *
234208625Sjkim * PARAMETERS:  None
235208625Sjkim *
236208625Sjkim * RETURN:      None
237208625Sjkim *
238208625Sjkim * DESCRIPTION: Initialize data table compiler globals. Enables multiple
239208625Sjkim *              compiles per invocation.
240208625Sjkim *
241208625Sjkim *****************************************************************************/
242208625Sjkim
243208625Sjkimstatic void
244208625SjkimDtInitialize (
245208625Sjkim    void)
246208625Sjkim{
247208625Sjkim
248208625Sjkim    Gbl_FieldList = NULL;
249208625Sjkim    Gbl_RootTable = NULL;
250208625Sjkim    Gbl_SubtableStack = NULL;
251208625Sjkim
252208625Sjkim    sprintf (VersionString, "%X", (UINT32) ACPI_CA_VERSION);
253208625Sjkim}
254208625Sjkim
255208625Sjkim
256208625Sjkim/******************************************************************************
257208625Sjkim *
258208625Sjkim * FUNCTION:    DtInsertCompilerIds
259208625Sjkim *
260208625Sjkim * PARAMETERS:  FieldList           - Current field list pointer
261208625Sjkim *
262208625Sjkim * RETURN:      None
263208625Sjkim *
264208625Sjkim * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
265208625Sjkim *              the original ACPI table header.
266208625Sjkim *
267208625Sjkim *****************************************************************************/
268208625Sjkim
269208625Sjkimstatic void
270208625SjkimDtInsertCompilerIds (
271208625Sjkim    DT_FIELD                *FieldList)
272208625Sjkim{
273208625Sjkim    DT_FIELD                *Next;
274208625Sjkim    UINT32                  i;
275208625Sjkim
276208625Sjkim
277208625Sjkim    /*
278208625Sjkim     * Don't insert current compiler ID if requested. Used for compiler
279208625Sjkim     * debug/validation only.
280208625Sjkim     */
281208625Sjkim    if (Gbl_UseOriginalCompilerId)
282208625Sjkim    {
283208625Sjkim        return;
284208625Sjkim    }
285208625Sjkim
286208625Sjkim    /* Walk to the Compiler fields at the end of the header */
287208625Sjkim
288208625Sjkim    Next = FieldList;
289208625Sjkim    for (i = 0; i < 7; i++)
290208625Sjkim    {
291208625Sjkim        Next = Next->Next;
292208625Sjkim    }
293208625Sjkim
294208625Sjkim    Next->Value = CompilerCreatorId;
295208625Sjkim    Next->Flags = DT_FIELD_NOT_ALLOCATED;
296208625Sjkim
297208625Sjkim    Next = Next->Next;
298208625Sjkim    Next->Value = VersionString;
299208625Sjkim    Next->Flags = DT_FIELD_NOT_ALLOCATED;
300208625Sjkim}
301208625Sjkim
302208625Sjkim
303208625Sjkim/******************************************************************************
304208625Sjkim *
305208625Sjkim * FUNCTION:    DtCompileDataTable
306208625Sjkim *
307208625Sjkim * PARAMETERS:  FieldList           - Current field list pointer
308208625Sjkim *
309208625Sjkim * RETURN:      Status
310208625Sjkim *
311208625Sjkim * DESCRIPTION: Entry point to compile one data table
312208625Sjkim *
313208625Sjkim *****************************************************************************/
314208625Sjkim
315208625Sjkimstatic ACPI_STATUS
316208625SjkimDtCompileDataTable (
317208625Sjkim    DT_FIELD                **FieldList)
318208625Sjkim{
319208625Sjkim    ACPI_DMTABLE_DATA       *TableData;
320208625Sjkim    DT_SUBTABLE             *Subtable;
321208625Sjkim    char                    *Signature;
322208625Sjkim    ACPI_TABLE_HEADER       *AcpiTableHeader;
323208625Sjkim    ACPI_STATUS             Status;
324208625Sjkim
325208625Sjkim
326208625Sjkim    /* Verify that we at least have a table signature and save it */
327208625Sjkim
328208625Sjkim    Signature = DtGetFieldValue (*FieldList, "Signature");
329208625Sjkim    if (!Signature)
330208625Sjkim    {
331208625Sjkim        DtError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, *FieldList, NULL);
332208625Sjkim        return (AE_ERROR);
333208625Sjkim    }
334208625Sjkim
335208625Sjkim    Gbl_Signature = UtLocalCalloc (ACPI_STRLEN (Signature) + 1);
336208625Sjkim    strcpy (Gbl_Signature, Signature);
337208625Sjkim
338208625Sjkim    /*
339208625Sjkim     * Handle tables that don't use the common ACPI table header structure.
340208625Sjkim     * Currently, these are the FACS and RSDP. Also check for an OEMx table,
341208625Sjkim     * these tables have user-defined contents.
342208625Sjkim     */
343208625Sjkim    if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
344208625Sjkim    {
345208625Sjkim        Status = DtCompileFacs (FieldList);
346208625Sjkim        if (ACPI_FAILURE (Status))
347208625Sjkim        {
348208625Sjkim            return (Status);
349208625Sjkim        }
350208625Sjkim
351208625Sjkim        DtSetTableLength ();
352208625Sjkim        return (Status);
353208625Sjkim    }
354208625Sjkim    else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDP))
355208625Sjkim    {
356208625Sjkim        Status = DtCompileRsdp (FieldList);
357208625Sjkim        return (Status);
358208625Sjkim    }
359208625Sjkim    else if (!ACPI_STRNCMP (Signature, "OEM", 3))
360208625Sjkim    {
361208625Sjkim        DtFatal (ASL_MSG_OEM_TABLE, *FieldList, Signature);
362208625Sjkim        return (AE_ERROR);
363208625Sjkim    }
364208625Sjkim
365208625Sjkim    /*
366208625Sjkim     * All other tables must use the common ACPI table header. Insert the
367208625Sjkim     * current iASL IDs (name, version), and compile the header now.
368208625Sjkim     */
369208625Sjkim    DtInsertCompilerIds (*FieldList);
370208625Sjkim
371208625Sjkim    Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
372208625Sjkim                &Gbl_RootTable, TRUE);
373208625Sjkim    if (ACPI_FAILURE (Status))
374208625Sjkim    {
375208625Sjkim        return (Status);
376208625Sjkim    }
377208625Sjkim
378208625Sjkim    DtPushSubtable (Gbl_RootTable);
379208625Sjkim
380208625Sjkim    /* Match signature and dispatch appropriately */
381208625Sjkim
382208625Sjkim    TableData = AcpiDmGetTableData (Signature);
383208625Sjkim    if (!TableData)
384208625Sjkim    {
385208625Sjkim        DtFatal (ASL_MSG_UNKNOWN_TABLE, *FieldList, Signature);
386208625Sjkim        return (AE_ERROR);
387208625Sjkim    }
388208625Sjkim
389208625Sjkim    if (TableData->CmTableHandler)
390208625Sjkim    {
391208625Sjkim        /* Complex table, has a handler */
392208625Sjkim
393208625Sjkim        Status = TableData->CmTableHandler ((void **) FieldList);
394208625Sjkim        if (ACPI_FAILURE (Status))
395208625Sjkim        {
396208625Sjkim            return (Status);
397208625Sjkim        }
398208625Sjkim    }
399208625Sjkim    else if (TableData->TableInfo)
400208625Sjkim    {
401208625Sjkim        /* Simple table, just walk the info table */
402208625Sjkim
403208625Sjkim        Subtable = NULL;
404208625Sjkim        Status = DtCompileTable (FieldList, TableData->TableInfo,
405208625Sjkim                    &Subtable, TRUE);
406208625Sjkim        if (ACPI_FAILURE (Status))
407208625Sjkim        {
408208625Sjkim            return (Status);
409208625Sjkim        }
410208625Sjkim
411208625Sjkim        DtInsertSubtable (Gbl_RootTable, Subtable);
412208625Sjkim        DtPopSubtable ();
413208625Sjkim    }
414208625Sjkim    else
415208625Sjkim    {
416208625Sjkim        DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
417208625Sjkim            "Missing table dispatch info");
418208625Sjkim        return (AE_ERROR);
419208625Sjkim    }
420208625Sjkim
421208625Sjkim    /* Set the final table length and then the checksum */
422208625Sjkim
423208625Sjkim    DtSetTableLength ();
424208625Sjkim    AcpiTableHeader = ACPI_CAST_PTR (
425208625Sjkim        ACPI_TABLE_HEADER, Gbl_RootTable->Buffer);
426208625Sjkim    DtSetTableChecksum (&AcpiTableHeader->Checksum);
427208625Sjkim
428208625Sjkim    return (AE_OK);
429208625Sjkim}
430208625Sjkim
431208625Sjkim
432208625Sjkim/******************************************************************************
433208625Sjkim *
434208625Sjkim * FUNCTION:    DtCompileTable
435208625Sjkim *
436208625Sjkim * PARAMETERS:  Field               - Current field list pointer
437208625Sjkim *              Info                - Info table for this ACPI table
438208625Sjkim *              RetSubtable         - Compile result of table
439208625Sjkim *              Required            - If this subtable must exist
440208625Sjkim *
441208625Sjkim * RETURN:      Status
442208625Sjkim *
443208625Sjkim * DESCRIPTION: Compile a subtable
444208625Sjkim *
445208625Sjkim *****************************************************************************/
446208625Sjkim
447208625SjkimACPI_STATUS
448208625SjkimDtCompileTable (
449208625Sjkim    DT_FIELD                **Field,
450208625Sjkim    ACPI_DMTABLE_INFO       *Info,
451208625Sjkim    DT_SUBTABLE             **RetSubtable,
452208625Sjkim    BOOLEAN                 Required)
453208625Sjkim{
454208625Sjkim    DT_FIELD                *LocalField;
455208625Sjkim    UINT32                  Length;
456208625Sjkim    DT_SUBTABLE             *Subtable;
457208625Sjkim    DT_SUBTABLE             *InlineSubtable;
458208625Sjkim    UINT32                  FieldLength = 0;
459208625Sjkim    UINT8                   FieldType;
460208625Sjkim    UINT8                   *Buffer;
461208625Sjkim    UINT8                   *FlagBuffer = NULL;
462208625Sjkim    UINT32                  FlagBitPosition = 0;
463208625Sjkim    ACPI_STATUS             Status;
464208625Sjkim
465208625Sjkim
466208625Sjkim    if (!Field || !*Field)
467208625Sjkim    {
468208625Sjkim        return (AE_BAD_PARAMETER);
469208625Sjkim    }
470208625Sjkim
471208625Sjkim    Length = DtGetSubtableLength (*Field, Info);
472208625Sjkim    Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
473208625Sjkim
474208625Sjkim    Subtable->Buffer = UtLocalCalloc (Length);
475208625Sjkim    Subtable->Length = Length;
476208625Sjkim    Subtable->TotalLength = Length;
477208625Sjkim    Buffer = Subtable->Buffer;
478208625Sjkim
479208625Sjkim    LocalField = *Field;
480208625Sjkim
481208625Sjkim    /*
482208625Sjkim     * Main loop walks the info table for this ACPI table or subtable
483208625Sjkim     */
484208625Sjkim    for (; Info->Name; Info++)
485208625Sjkim    {
486208625Sjkim        if (!LocalField)
487208625Sjkim        {
488208625Sjkim            sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
489208625Sjkim                Info->Name);
490208625Sjkim            DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
491208625Sjkim            Status = AE_BAD_DATA;
492208625Sjkim            goto Error;
493208625Sjkim        }
494208625Sjkim
495208625Sjkim        /* Does input field name match what is expected? */
496208625Sjkim
497208625Sjkim        if (ACPI_STRCMP (LocalField->Name, Info->Name))
498208625Sjkim        {
499208625Sjkim            /*
500208625Sjkim             * If Required = TRUE, the subtable must exist.
501208625Sjkim             * If Required = FALSE, the subtable is optional
502208625Sjkim             * (For example, AcpiDmTableInfoDmarScope in DMAR table is
503208625Sjkim             * optional)
504208625Sjkim             */
505208625Sjkim            if (Required)
506208625Sjkim            {
507208625Sjkim                sprintf (MsgBuffer, "Expected \"%s\"", Info->Name);
508208625Sjkim                DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
509208625Sjkim                    LocalField, MsgBuffer);
510208625Sjkim            }
511208625Sjkim            else
512208625Sjkim            {
513208625Sjkim                Status = AE_NOT_FOUND;
514208625Sjkim                goto Error;
515208625Sjkim            }
516208625Sjkim        }
517208625Sjkim
518208625Sjkim        FieldLength = DtGetFieldLength (LocalField, Info);
519208625Sjkim        FieldType = DtGetFieldType (Info);
520208625Sjkim        Gbl_InputFieldCount++;
521208625Sjkim
522208625Sjkim        switch (FieldType)
523208625Sjkim        {
524208625Sjkim        case DT_FIELD_TYPE_FLAGS_INTEGER:
525208625Sjkim            /*
526208625Sjkim             * Start of the definition of a flags field.
527208625Sjkim             * This master flags integer starts at value zero, in preparation
528208625Sjkim             * to compile and insert the flag fields from the individual bits
529208625Sjkim             */
530208625Sjkim            LocalField = LocalField->Next;
531208625Sjkim            *Field = LocalField;
532208625Sjkim
533208625Sjkim            FlagBitPosition = 0;
534208625Sjkim            FlagBuffer = Buffer;
535208625Sjkim            break;
536208625Sjkim
537208625Sjkim        case DT_FIELD_TYPE_FLAG:
538208625Sjkim
539208625Sjkim            /* Individual Flag field, can be multiple bits */
540208625Sjkim
541208625Sjkim            if (FlagBuffer)
542208625Sjkim            {
543208625Sjkim                FlagBitPosition = DtCompileFlag (FlagBuffer,
544208625Sjkim                     LocalField, Info, FlagBitPosition);
545208625Sjkim            }
546208625Sjkim            else
547208625Sjkim            {
548208625Sjkim                /* TBD - this is an internal error */
549208625Sjkim            }
550208625Sjkim
551208625Sjkim            LocalField = LocalField->Next;
552208625Sjkim            *Field = LocalField;
553208625Sjkim            break;
554208625Sjkim
555208625Sjkim        case DT_FIELD_TYPE_INLINE_SUBTABLE:
556208625Sjkim            /*
557208625Sjkim             * Recursion (one level max): compile GAS (Generic Address)
558208625Sjkim             * or Notify in-line subtable
559208625Sjkim             */
560208625Sjkim            LocalField = LocalField->Next;
561208625Sjkim            *Field = LocalField;
562208625Sjkim
563208625Sjkim            if (Info->Opcode == ACPI_DMT_GAS)
564208625Sjkim            {
565208625Sjkim                Status = DtCompileTable (Field, AcpiDmTableInfoGas,
566208625Sjkim                    &InlineSubtable, TRUE);
567208625Sjkim            }
568208625Sjkim            else
569208625Sjkim            {
570208625Sjkim                Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
571208625Sjkim                    &InlineSubtable, TRUE);
572208625Sjkim            }
573208625Sjkim
574208625Sjkim            if (ACPI_FAILURE (Status))
575208625Sjkim            {
576208625Sjkim                goto Error;
577208625Sjkim            }
578208625Sjkim
579208625Sjkim            ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength);
580208625Sjkim            ACPI_FREE (InlineSubtable->Buffer);
581208625Sjkim            ACPI_FREE (InlineSubtable);
582208625Sjkim            LocalField = *Field;
583208625Sjkim            break;
584208625Sjkim
585208625Sjkim        default:
586208625Sjkim
587208625Sjkim            /* Normal case for most field types (Integer, String, etc.) */
588208625Sjkim
589208625Sjkim            DtCompileOneField (Buffer, LocalField,
590208625Sjkim                FieldLength, FieldType, Info->Flags);
591208625Sjkim            LocalField = LocalField->Next;
592208625Sjkim
593208625Sjkim            if (Info->Flags & DT_LENGTH)
594208625Sjkim            {
595208625Sjkim                /* Field is an Integer that will contain a subtable length */
596208625Sjkim
597208625Sjkim                Subtable->LengthField = Buffer;
598208625Sjkim                Subtable->SizeOfLengthField = FieldLength;
599208625Sjkim            }
600208625Sjkim            break;
601208625Sjkim        }
602208625Sjkim
603208625Sjkim        Buffer += FieldLength;
604208625Sjkim    }
605208625Sjkim
606208625Sjkim    *Field = LocalField;
607208625Sjkim    *RetSubtable = Subtable;
608208625Sjkim    return (AE_OK);
609208625Sjkim
610208625SjkimError:
611208625Sjkim    ACPI_FREE (Subtable->Buffer);
612208625Sjkim    ACPI_FREE (Subtable);
613208625Sjkim    return (Status);
614208625Sjkim}
615