Home | History | Annotate | Line # | Download | only in compiler
dtcompile.c revision 1.1.1.3.2.1
      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.1.1.2  jruoho /*
      8  1.1.1.3.2.1    yamt  * Copyright (C) 2000 - 2013, Intel Corp.
      9          1.1  jruoho  * All rights reserved.
     10          1.1  jruoho  *
     11      1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2  jruoho  * are met:
     14      1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2  jruoho  *    without modification.
     17      1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2  jruoho  *    binary redistribution.
     22      1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2  jruoho  *
     26      1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2  jruoho  * Software Foundation.
     29      1.1.1.2  jruoho  *
     30      1.1.1.2  jruoho  * NO WARRANTY
     31      1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2  jruoho  */
     43          1.1  jruoho 
     44          1.1  jruoho #define __DTCOMPILE_C__
     45          1.1  jruoho #define _DECLARE_DT_GLOBALS
     46          1.1  jruoho 
     47          1.1  jruoho #include "aslcompiler.h"
     48          1.1  jruoho #include "dtcompiler.h"
     49          1.1  jruoho 
     50          1.1  jruoho #define _COMPONENT          DT_COMPILER
     51          1.1  jruoho         ACPI_MODULE_NAME    ("dtcompile")
     52          1.1  jruoho 
     53          1.1  jruoho static char                 VersionString[9];
     54          1.1  jruoho 
     55          1.1  jruoho 
     56          1.1  jruoho /* Local prototypes */
     57          1.1  jruoho 
     58      1.1.1.2  jruoho static ACPI_STATUS
     59          1.1  jruoho DtInitialize (
     60          1.1  jruoho     void);
     61          1.1  jruoho 
     62          1.1  jruoho static ACPI_STATUS
     63          1.1  jruoho DtCompileDataTable (
     64          1.1  jruoho     DT_FIELD                **Field);
     65          1.1  jruoho 
     66          1.1  jruoho static void
     67          1.1  jruoho DtInsertCompilerIds (
     68          1.1  jruoho     DT_FIELD                *FieldList);
     69          1.1  jruoho 
     70          1.1  jruoho 
     71          1.1  jruoho /******************************************************************************
     72          1.1  jruoho  *
     73          1.1  jruoho  * FUNCTION:    DtDoCompile
     74          1.1  jruoho  *
     75          1.1  jruoho  * PARAMETERS:  None
     76          1.1  jruoho  *
     77          1.1  jruoho  * RETURN:      Status
     78          1.1  jruoho  *
     79          1.1  jruoho  * DESCRIPTION: Main entry point for the data table compiler.
     80          1.1  jruoho  *
     81          1.1  jruoho  * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is
     82          1.1  jruoho  *          open at seek offset zero.
     83          1.1  jruoho  *
     84          1.1  jruoho  *****************************************************************************/
     85          1.1  jruoho 
     86          1.1  jruoho ACPI_STATUS
     87          1.1  jruoho DtDoCompile (
     88          1.1  jruoho     void)
     89          1.1  jruoho {
     90          1.1  jruoho     ACPI_STATUS             Status;
     91          1.1  jruoho     UINT8                   Event;
     92          1.1  jruoho     DT_FIELD                *FieldList;
     93          1.1  jruoho 
     94          1.1  jruoho 
     95          1.1  jruoho     /* Initialize globals */
     96          1.1  jruoho 
     97      1.1.1.2  jruoho     Status = DtInitialize ();
     98      1.1.1.2  jruoho     if (ACPI_FAILURE (Status))
     99      1.1.1.2  jruoho     {
    100      1.1.1.2  jruoho         printf ("Error during compiler initialization, 0x%X\n", Status);
    101      1.1.1.2  jruoho         return (Status);
    102      1.1.1.2  jruoho     }
    103          1.1  jruoho 
    104  1.1.1.3.2.1    yamt     /* Preprocessor */
    105  1.1.1.3.2.1    yamt 
    106  1.1.1.3.2.1    yamt     Event = UtBeginEvent ("Preprocess input file");
    107  1.1.1.3.2.1    yamt     PrDoPreprocess ();
    108  1.1.1.3.2.1    yamt     UtEndEvent (Event);
    109  1.1.1.3.2.1    yamt 
    110  1.1.1.3.2.1    yamt     if (Gbl_PreprocessOnly)
    111  1.1.1.3.2.1    yamt     {
    112  1.1.1.3.2.1    yamt         return (AE_OK);
    113  1.1.1.3.2.1    yamt     }
    114  1.1.1.3.2.1    yamt 
    115          1.1  jruoho     /*
    116          1.1  jruoho      * Scan the input file (file is already open) and
    117          1.1  jruoho      * build the parse tree
    118          1.1  jruoho      */
    119          1.1  jruoho     Event = UtBeginEvent ("Scan and parse input file");
    120          1.1  jruoho     FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle);
    121          1.1  jruoho     UtEndEvent (Event);
    122          1.1  jruoho 
    123          1.1  jruoho     /* Did the parse tree get successfully constructed? */
    124          1.1  jruoho 
    125          1.1  jruoho     if (!FieldList)
    126          1.1  jruoho     {
    127          1.1  jruoho         /* TBD: temporary error message. Msgs should come from function above */
    128          1.1  jruoho 
    129          1.1  jruoho         DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
    130      1.1.1.2  jruoho             "Input file does not appear to be an ASL or data table source file");
    131      1.1.1.2  jruoho 
    132      1.1.1.2  jruoho         Status = AE_ERROR;
    133      1.1.1.2  jruoho         goto CleanupAndExit;
    134          1.1  jruoho     }
    135          1.1  jruoho 
    136          1.1  jruoho     Event = UtBeginEvent ("Compile parse tree");
    137          1.1  jruoho 
    138          1.1  jruoho     /*
    139          1.1  jruoho      * Compile the parse tree
    140          1.1  jruoho      */
    141          1.1  jruoho     Status = DtCompileDataTable (&FieldList);
    142          1.1  jruoho     UtEndEvent (Event);
    143          1.1  jruoho 
    144          1.1  jruoho     DtFreeFieldList ();
    145          1.1  jruoho 
    146          1.1  jruoho     if (ACPI_FAILURE (Status))
    147          1.1  jruoho     {
    148          1.1  jruoho         /* TBD: temporary error message. Msgs should come from function above */
    149          1.1  jruoho 
    150          1.1  jruoho         DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
    151          1.1  jruoho             "Could not compile input file");
    152      1.1.1.2  jruoho 
    153          1.1  jruoho         goto CleanupAndExit;
    154          1.1  jruoho     }
    155          1.1  jruoho 
    156          1.1  jruoho     /* Create/open the binary output file */
    157          1.1  jruoho 
    158          1.1  jruoho     Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
    159          1.1  jruoho     Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
    160          1.1  jruoho     if (ACPI_FAILURE (Status))
    161          1.1  jruoho     {
    162          1.1  jruoho         goto CleanupAndExit;
    163          1.1  jruoho     }
    164          1.1  jruoho 
    165          1.1  jruoho     /* Write the binary, then the optional hex file */
    166          1.1  jruoho 
    167          1.1  jruoho     DtOutputBinary (Gbl_RootTable);
    168  1.1.1.3.2.1    yamt     HxDoHexOutput ();
    169      1.1.1.2  jruoho     DtWriteTableToListing ();
    170          1.1  jruoho 
    171          1.1  jruoho CleanupAndExit:
    172          1.1  jruoho 
    173          1.1  jruoho     CmCleanupAndExit ();
    174          1.1  jruoho     return (Status);
    175          1.1  jruoho }
    176          1.1  jruoho 
    177          1.1  jruoho 
    178          1.1  jruoho /******************************************************************************
    179          1.1  jruoho  *
    180          1.1  jruoho  * FUNCTION:    DtInitialize
    181          1.1  jruoho  *
    182          1.1  jruoho  * PARAMETERS:  None
    183          1.1  jruoho  *
    184      1.1.1.2  jruoho  * RETURN:      Status
    185          1.1  jruoho  *
    186          1.1  jruoho  * DESCRIPTION: Initialize data table compiler globals. Enables multiple
    187          1.1  jruoho  *              compiles per invocation.
    188          1.1  jruoho  *
    189          1.1  jruoho  *****************************************************************************/
    190          1.1  jruoho 
    191      1.1.1.2  jruoho static ACPI_STATUS
    192          1.1  jruoho DtInitialize (
    193          1.1  jruoho     void)
    194          1.1  jruoho {
    195      1.1.1.2  jruoho     ACPI_STATUS             Status;
    196      1.1.1.2  jruoho 
    197      1.1.1.2  jruoho 
    198      1.1.1.2  jruoho     Status = AcpiOsInitialize ();
    199      1.1.1.2  jruoho     if (ACPI_FAILURE (Status))
    200      1.1.1.2  jruoho     {
    201      1.1.1.2  jruoho         return (Status);
    202      1.1.1.2  jruoho     }
    203      1.1.1.2  jruoho 
    204      1.1.1.2  jruoho     Status = AcpiUtInitGlobals ();
    205      1.1.1.2  jruoho     if (ACPI_FAILURE (Status))
    206      1.1.1.2  jruoho     {
    207      1.1.1.2  jruoho         return (Status);
    208      1.1.1.2  jruoho     }
    209          1.1  jruoho 
    210          1.1  jruoho     Gbl_FieldList = NULL;
    211          1.1  jruoho     Gbl_RootTable = NULL;
    212          1.1  jruoho     Gbl_SubtableStack = NULL;
    213          1.1  jruoho 
    214  1.1.1.3.2.1    yamt     snprintf (VersionString, sizeof(VersionString), "%X",
    215  1.1.1.3.2.1    yamt 	(UINT32) ACPI_CA_VERSION);
    216      1.1.1.2  jruoho     return (AE_OK);
    217          1.1  jruoho }
    218          1.1  jruoho 
    219          1.1  jruoho 
    220          1.1  jruoho /******************************************************************************
    221          1.1  jruoho  *
    222          1.1  jruoho  * FUNCTION:    DtInsertCompilerIds
    223          1.1  jruoho  *
    224          1.1  jruoho  * PARAMETERS:  FieldList           - Current field list pointer
    225          1.1  jruoho  *
    226          1.1  jruoho  * RETURN:      None
    227          1.1  jruoho  *
    228          1.1  jruoho  * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
    229          1.1  jruoho  *              the original ACPI table header.
    230          1.1  jruoho  *
    231          1.1  jruoho  *****************************************************************************/
    232          1.1  jruoho 
    233          1.1  jruoho static void
    234          1.1  jruoho DtInsertCompilerIds (
    235          1.1  jruoho     DT_FIELD                *FieldList)
    236          1.1  jruoho {
    237          1.1  jruoho     DT_FIELD                *Next;
    238          1.1  jruoho     UINT32                  i;
    239          1.1  jruoho 
    240          1.1  jruoho 
    241          1.1  jruoho     /*
    242          1.1  jruoho      * Don't insert current compiler ID if requested. Used for compiler
    243          1.1  jruoho      * debug/validation only.
    244          1.1  jruoho      */
    245          1.1  jruoho     if (Gbl_UseOriginalCompilerId)
    246          1.1  jruoho     {
    247          1.1  jruoho         return;
    248          1.1  jruoho     }
    249          1.1  jruoho 
    250          1.1  jruoho     /* Walk to the Compiler fields at the end of the header */
    251          1.1  jruoho 
    252          1.1  jruoho     Next = FieldList;
    253          1.1  jruoho     for (i = 0; i < 7; i++)
    254          1.1  jruoho     {
    255          1.1  jruoho         Next = Next->Next;
    256          1.1  jruoho     }
    257          1.1  jruoho 
    258      1.1.1.2  jruoho     Next->Value = ASL_CREATOR_ID;
    259          1.1  jruoho     Next->Flags = DT_FIELD_NOT_ALLOCATED;
    260          1.1  jruoho 
    261          1.1  jruoho     Next = Next->Next;
    262          1.1  jruoho     Next->Value = VersionString;
    263          1.1  jruoho     Next->Flags = DT_FIELD_NOT_ALLOCATED;
    264          1.1  jruoho }
    265          1.1  jruoho 
    266          1.1  jruoho 
    267          1.1  jruoho /******************************************************************************
    268          1.1  jruoho  *
    269          1.1  jruoho  * FUNCTION:    DtCompileDataTable
    270          1.1  jruoho  *
    271          1.1  jruoho  * PARAMETERS:  FieldList           - Current field list pointer
    272          1.1  jruoho  *
    273          1.1  jruoho  * RETURN:      Status
    274          1.1  jruoho  *
    275          1.1  jruoho  * DESCRIPTION: Entry point to compile one data table
    276          1.1  jruoho  *
    277          1.1  jruoho  *****************************************************************************/
    278          1.1  jruoho 
    279          1.1  jruoho static ACPI_STATUS
    280          1.1  jruoho DtCompileDataTable (
    281          1.1  jruoho     DT_FIELD                **FieldList)
    282          1.1  jruoho {
    283          1.1  jruoho     ACPI_DMTABLE_DATA       *TableData;
    284          1.1  jruoho     DT_SUBTABLE             *Subtable;
    285          1.1  jruoho     char                    *Signature;
    286          1.1  jruoho     ACPI_TABLE_HEADER       *AcpiTableHeader;
    287          1.1  jruoho     ACPI_STATUS             Status;
    288  1.1.1.3.2.1    yamt     DT_FIELD                *RootField = *FieldList;
    289          1.1  jruoho 
    290          1.1  jruoho 
    291          1.1  jruoho     /* Verify that we at least have a table signature and save it */
    292          1.1  jruoho 
    293      1.1.1.3  jruoho     Signature = DtGetFieldValue (*FieldList);
    294          1.1  jruoho     if (!Signature)
    295          1.1  jruoho     {
    296  1.1.1.3.2.1    yamt         snprintf (MsgBuffer, sizeof(MsgBuffer), "Expected \"%s\"", "Signature");
    297      1.1.1.2  jruoho         DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
    298      1.1.1.2  jruoho             *FieldList, MsgBuffer);
    299          1.1  jruoho         return (AE_ERROR);
    300          1.1  jruoho     }
    301          1.1  jruoho 
    302          1.1  jruoho     Gbl_Signature = UtLocalCalloc (ACPI_STRLEN (Signature) + 1);
    303          1.1  jruoho     strcpy (Gbl_Signature, Signature);
    304          1.1  jruoho 
    305          1.1  jruoho     /*
    306          1.1  jruoho      * Handle tables that don't use the common ACPI table header structure.
    307          1.1  jruoho      * Currently, these are the FACS and RSDP. Also check for an OEMx table,
    308          1.1  jruoho      * these tables have user-defined contents.
    309          1.1  jruoho      */
    310          1.1  jruoho     if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
    311          1.1  jruoho     {
    312          1.1  jruoho         Status = DtCompileFacs (FieldList);
    313          1.1  jruoho         if (ACPI_FAILURE (Status))
    314          1.1  jruoho         {
    315          1.1  jruoho             return (Status);
    316          1.1  jruoho         }
    317          1.1  jruoho 
    318          1.1  jruoho         DtSetTableLength ();
    319          1.1  jruoho         return (Status);
    320          1.1  jruoho     }
    321  1.1.1.3.2.1    yamt     else if (ACPI_VALIDATE_RSDP_SIG (Signature))
    322          1.1  jruoho     {
    323          1.1  jruoho         Status = DtCompileRsdp (FieldList);
    324          1.1  jruoho         return (Status);
    325          1.1  jruoho     }
    326  1.1.1.3.2.1    yamt     else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_S3PT))
    327  1.1.1.3.2.1    yamt     {
    328  1.1.1.3.2.1    yamt         Status = DtCompileS3pt (FieldList);
    329  1.1.1.3.2.1    yamt         if (ACPI_FAILURE (Status))
    330  1.1.1.3.2.1    yamt         {
    331  1.1.1.3.2.1    yamt             return (Status);
    332  1.1.1.3.2.1    yamt         }
    333  1.1.1.3.2.1    yamt 
    334  1.1.1.3.2.1    yamt         DtSetTableLength ();
    335  1.1.1.3.2.1    yamt         return (Status);
    336  1.1.1.3.2.1    yamt     }
    337      1.1.1.2  jruoho 
    338          1.1  jruoho     /*
    339          1.1  jruoho      * All other tables must use the common ACPI table header. Insert the
    340          1.1  jruoho      * current iASL IDs (name, version), and compile the header now.
    341          1.1  jruoho      */
    342          1.1  jruoho     DtInsertCompilerIds (*FieldList);
    343          1.1  jruoho 
    344          1.1  jruoho     Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
    345          1.1  jruoho                 &Gbl_RootTable, TRUE);
    346          1.1  jruoho     if (ACPI_FAILURE (Status))
    347          1.1  jruoho     {
    348          1.1  jruoho         return (Status);
    349          1.1  jruoho     }
    350          1.1  jruoho 
    351          1.1  jruoho     DtPushSubtable (Gbl_RootTable);
    352          1.1  jruoho 
    353      1.1.1.3  jruoho     /* Validate the signature via the ACPI table list */
    354      1.1.1.3  jruoho 
    355      1.1.1.3  jruoho     TableData = AcpiDmGetTableData (Signature);
    356  1.1.1.3.2.1    yamt     if (!TableData || Gbl_CompileGeneric)
    357      1.1.1.3  jruoho     {
    358      1.1.1.3  jruoho         DtCompileGeneric ((void **) FieldList);
    359  1.1.1.3.2.1    yamt         goto FinishHeader;
    360      1.1.1.3  jruoho     }
    361      1.1.1.3  jruoho 
    362      1.1.1.2  jruoho     /* Dispatch to per-table compile */
    363          1.1  jruoho 
    364          1.1  jruoho     if (TableData->CmTableHandler)
    365          1.1  jruoho     {
    366          1.1  jruoho         /* Complex table, has a handler */
    367          1.1  jruoho 
    368          1.1  jruoho         Status = TableData->CmTableHandler ((void **) FieldList);
    369          1.1  jruoho         if (ACPI_FAILURE (Status))
    370          1.1  jruoho         {
    371          1.1  jruoho             return (Status);
    372          1.1  jruoho         }
    373          1.1  jruoho     }
    374          1.1  jruoho     else if (TableData->TableInfo)
    375          1.1  jruoho     {
    376          1.1  jruoho         /* Simple table, just walk the info table */
    377          1.1  jruoho 
    378          1.1  jruoho         Subtable = NULL;
    379          1.1  jruoho         Status = DtCompileTable (FieldList, TableData->TableInfo,
    380          1.1  jruoho                     &Subtable, TRUE);
    381          1.1  jruoho         if (ACPI_FAILURE (Status))
    382          1.1  jruoho         {
    383          1.1  jruoho             return (Status);
    384          1.1  jruoho         }
    385          1.1  jruoho 
    386          1.1  jruoho         DtInsertSubtable (Gbl_RootTable, Subtable);
    387          1.1  jruoho         DtPopSubtable ();
    388          1.1  jruoho     }
    389          1.1  jruoho     else
    390          1.1  jruoho     {
    391          1.1  jruoho         DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
    392          1.1  jruoho             "Missing table dispatch info");
    393          1.1  jruoho         return (AE_ERROR);
    394          1.1  jruoho     }
    395          1.1  jruoho 
    396  1.1.1.3.2.1    yamt FinishHeader:
    397  1.1.1.3.2.1    yamt 
    398          1.1  jruoho     /* Set the final table length and then the checksum */
    399          1.1  jruoho 
    400          1.1  jruoho     DtSetTableLength ();
    401          1.1  jruoho     AcpiTableHeader = ACPI_CAST_PTR (
    402          1.1  jruoho         ACPI_TABLE_HEADER, Gbl_RootTable->Buffer);
    403          1.1  jruoho     DtSetTableChecksum (&AcpiTableHeader->Checksum);
    404          1.1  jruoho 
    405  1.1.1.3.2.1    yamt     DtDumpFieldList (RootField);
    406  1.1.1.3.2.1    yamt     DtDumpSubtableList ();
    407          1.1  jruoho     return (AE_OK);
    408          1.1  jruoho }
    409          1.1  jruoho 
    410          1.1  jruoho 
    411          1.1  jruoho /******************************************************************************
    412          1.1  jruoho  *
    413          1.1  jruoho  * FUNCTION:    DtCompileTable
    414          1.1  jruoho  *
    415          1.1  jruoho  * PARAMETERS:  Field               - Current field list pointer
    416          1.1  jruoho  *              Info                - Info table for this ACPI table
    417          1.1  jruoho  *              RetSubtable         - Compile result of table
    418          1.1  jruoho  *              Required            - If this subtable must exist
    419          1.1  jruoho  *
    420          1.1  jruoho  * RETURN:      Status
    421          1.1  jruoho  *
    422          1.1  jruoho  * DESCRIPTION: Compile a subtable
    423          1.1  jruoho  *
    424          1.1  jruoho  *****************************************************************************/
    425          1.1  jruoho 
    426          1.1  jruoho ACPI_STATUS
    427          1.1  jruoho DtCompileTable (
    428          1.1  jruoho     DT_FIELD                **Field,
    429          1.1  jruoho     ACPI_DMTABLE_INFO       *Info,
    430          1.1  jruoho     DT_SUBTABLE             **RetSubtable,
    431          1.1  jruoho     BOOLEAN                 Required)
    432          1.1  jruoho {
    433          1.1  jruoho     DT_FIELD                *LocalField;
    434          1.1  jruoho     UINT32                  Length;
    435          1.1  jruoho     DT_SUBTABLE             *Subtable;
    436          1.1  jruoho     DT_SUBTABLE             *InlineSubtable;
    437          1.1  jruoho     UINT32                  FieldLength = 0;
    438          1.1  jruoho     UINT8                   FieldType;
    439          1.1  jruoho     UINT8                   *Buffer;
    440          1.1  jruoho     UINT8                   *FlagBuffer = NULL;
    441  1.1.1.3.2.1    yamt     UINT32                  CurrentFlagByteOffset = 0;
    442          1.1  jruoho     ACPI_STATUS             Status;
    443          1.1  jruoho 
    444          1.1  jruoho 
    445          1.1  jruoho     if (!Field || !*Field)
    446          1.1  jruoho     {
    447          1.1  jruoho         return (AE_BAD_PARAMETER);
    448          1.1  jruoho     }
    449          1.1  jruoho 
    450  1.1.1.3.2.1    yamt     /* Ignore optional subtable if name does not match */
    451  1.1.1.3.2.1    yamt 
    452  1.1.1.3.2.1    yamt     if ((Info->Flags & DT_OPTIONAL) &&
    453  1.1.1.3.2.1    yamt         ACPI_STRCMP ((*Field)->Name, Info->Name))
    454  1.1.1.3.2.1    yamt     {
    455  1.1.1.3.2.1    yamt         *RetSubtable = NULL;
    456  1.1.1.3.2.1    yamt         return (AE_OK);
    457  1.1.1.3.2.1    yamt     }
    458  1.1.1.3.2.1    yamt 
    459          1.1  jruoho     Length = DtGetSubtableLength (*Field, Info);
    460      1.1.1.3  jruoho     if (Length == ASL_EOF)
    461      1.1.1.3  jruoho     {
    462      1.1.1.3  jruoho         return (AE_ERROR);
    463      1.1.1.3  jruoho     }
    464      1.1.1.3  jruoho 
    465          1.1  jruoho     Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
    466          1.1  jruoho 
    467      1.1.1.2  jruoho     if (Length > 0)
    468      1.1.1.2  jruoho     {
    469      1.1.1.2  jruoho         Subtable->Buffer = UtLocalCalloc (Length);
    470      1.1.1.2  jruoho     }
    471          1.1  jruoho     Subtable->Length = Length;
    472          1.1  jruoho     Subtable->TotalLength = Length;
    473          1.1  jruoho     Buffer = Subtable->Buffer;
    474          1.1  jruoho 
    475          1.1  jruoho     LocalField = *Field;
    476          1.1  jruoho 
    477          1.1  jruoho     /*
    478          1.1  jruoho      * Main loop walks the info table for this ACPI table or subtable
    479          1.1  jruoho      */
    480          1.1  jruoho     for (; Info->Name; Info++)
    481          1.1  jruoho     {
    482  1.1.1.3.2.1    yamt         if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
    483  1.1.1.3.2.1    yamt         {
    484  1.1.1.3.2.1    yamt             continue;
    485  1.1.1.3.2.1    yamt         }
    486  1.1.1.3.2.1    yamt 
    487          1.1  jruoho         if (!LocalField)
    488          1.1  jruoho         {
    489  1.1.1.3.2.1    yamt             snprintf (MsgBuffer, sizeof(MsgBuffer), "Found NULL field - Field name \"%s\" needed",
    490          1.1  jruoho                 Info->Name);
    491          1.1  jruoho             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
    492          1.1  jruoho             Status = AE_BAD_DATA;
    493          1.1  jruoho             goto Error;
    494          1.1  jruoho         }
    495          1.1  jruoho 
    496      1.1.1.2  jruoho         /* Maintain table offsets */
    497      1.1.1.2  jruoho 
    498      1.1.1.2  jruoho         LocalField->TableOffset = Gbl_CurrentTableOffset;
    499          1.1  jruoho         FieldLength = DtGetFieldLength (LocalField, Info);
    500      1.1.1.2  jruoho         Gbl_CurrentTableOffset += FieldLength;
    501      1.1.1.2  jruoho 
    502          1.1  jruoho         FieldType = DtGetFieldType (Info);
    503          1.1  jruoho         Gbl_InputFieldCount++;
    504          1.1  jruoho 
    505          1.1  jruoho         switch (FieldType)
    506          1.1  jruoho         {
    507          1.1  jruoho         case DT_FIELD_TYPE_FLAGS_INTEGER:
    508          1.1  jruoho             /*
    509          1.1  jruoho              * Start of the definition of a flags field.
    510          1.1  jruoho              * This master flags integer starts at value zero, in preparation
    511          1.1  jruoho              * to compile and insert the flag fields from the individual bits
    512          1.1  jruoho              */
    513          1.1  jruoho             LocalField = LocalField->Next;
    514          1.1  jruoho             *Field = LocalField;
    515          1.1  jruoho 
    516          1.1  jruoho             FlagBuffer = Buffer;
    517  1.1.1.3.2.1    yamt             CurrentFlagByteOffset = Info->Offset;
    518          1.1  jruoho             break;
    519          1.1  jruoho 
    520          1.1  jruoho         case DT_FIELD_TYPE_FLAG:
    521          1.1  jruoho 
    522          1.1  jruoho             /* Individual Flag field, can be multiple bits */
    523          1.1  jruoho 
    524          1.1  jruoho             if (FlagBuffer)
    525          1.1  jruoho             {
    526  1.1.1.3.2.1    yamt                 /*
    527  1.1.1.3.2.1    yamt                  * We must increment the FlagBuffer when we have crossed
    528  1.1.1.3.2.1    yamt                  * into the next flags byte within the flags field
    529  1.1.1.3.2.1    yamt                  * of type DT_FIELD_TYPE_FLAGS_INTEGER.
    530  1.1.1.3.2.1    yamt                  */
    531  1.1.1.3.2.1    yamt                 FlagBuffer += (Info->Offset - CurrentFlagByteOffset);
    532  1.1.1.3.2.1    yamt                 CurrentFlagByteOffset = Info->Offset;
    533  1.1.1.3.2.1    yamt 
    534      1.1.1.2  jruoho                 DtCompileFlag (FlagBuffer, LocalField, Info);
    535          1.1  jruoho             }
    536          1.1  jruoho             else
    537          1.1  jruoho             {
    538          1.1  jruoho                 /* TBD - this is an internal error */
    539          1.1  jruoho             }
    540          1.1  jruoho 
    541          1.1  jruoho             LocalField = LocalField->Next;
    542          1.1  jruoho             *Field = LocalField;
    543          1.1  jruoho             break;
    544          1.1  jruoho 
    545          1.1  jruoho         case DT_FIELD_TYPE_INLINE_SUBTABLE:
    546          1.1  jruoho             /*
    547          1.1  jruoho              * Recursion (one level max): compile GAS (Generic Address)
    548          1.1  jruoho              * or Notify in-line subtable
    549          1.1  jruoho              */
    550          1.1  jruoho             *Field = LocalField;
    551          1.1  jruoho 
    552          1.1  jruoho             if (Info->Opcode == ACPI_DMT_GAS)
    553          1.1  jruoho             {
    554          1.1  jruoho                 Status = DtCompileTable (Field, AcpiDmTableInfoGas,
    555          1.1  jruoho                     &InlineSubtable, TRUE);
    556          1.1  jruoho             }
    557          1.1  jruoho             else
    558          1.1  jruoho             {
    559          1.1  jruoho                 Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
    560          1.1  jruoho                     &InlineSubtable, TRUE);
    561          1.1  jruoho             }
    562          1.1  jruoho 
    563          1.1  jruoho             if (ACPI_FAILURE (Status))
    564          1.1  jruoho             {
    565          1.1  jruoho                 goto Error;
    566          1.1  jruoho             }
    567          1.1  jruoho 
    568      1.1.1.2  jruoho             DtSetSubtableLength (InlineSubtable);
    569      1.1.1.2  jruoho 
    570          1.1  jruoho             ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength);
    571          1.1  jruoho             ACPI_FREE (InlineSubtable->Buffer);
    572          1.1  jruoho             ACPI_FREE (InlineSubtable);
    573          1.1  jruoho             LocalField = *Field;
    574          1.1  jruoho             break;
    575          1.1  jruoho 
    576      1.1.1.2  jruoho         case DT_FIELD_TYPE_LABEL:
    577      1.1.1.2  jruoho 
    578      1.1.1.2  jruoho             DtWriteFieldToListing (Buffer, LocalField, 0);
    579      1.1.1.2  jruoho             LocalField = LocalField->Next;
    580      1.1.1.2  jruoho             break;
    581      1.1.1.2  jruoho 
    582          1.1  jruoho         default:
    583          1.1  jruoho 
    584          1.1  jruoho             /* Normal case for most field types (Integer, String, etc.) */
    585          1.1  jruoho 
    586          1.1  jruoho             DtCompileOneField (Buffer, LocalField,
    587          1.1  jruoho                 FieldLength, FieldType, Info->Flags);
    588      1.1.1.2  jruoho 
    589      1.1.1.2  jruoho             DtWriteFieldToListing (Buffer, LocalField, FieldLength);
    590          1.1  jruoho             LocalField = LocalField->Next;
    591          1.1  jruoho 
    592          1.1  jruoho             if (Info->Flags & DT_LENGTH)
    593          1.1  jruoho             {
    594          1.1  jruoho                 /* Field is an Integer that will contain a subtable length */
    595          1.1  jruoho 
    596          1.1  jruoho                 Subtable->LengthField = Buffer;
    597          1.1  jruoho                 Subtable->SizeOfLengthField = FieldLength;
    598          1.1  jruoho             }
    599      1.1.1.2  jruoho 
    600          1.1  jruoho             break;
    601          1.1  jruoho         }
    602          1.1  jruoho 
    603          1.1  jruoho         Buffer += FieldLength;
    604          1.1  jruoho     }
    605          1.1  jruoho 
    606          1.1  jruoho     *Field = LocalField;
    607          1.1  jruoho     *RetSubtable = Subtable;
    608          1.1  jruoho     return (AE_OK);
    609          1.1  jruoho 
    610          1.1  jruoho Error:
    611          1.1  jruoho     ACPI_FREE (Subtable->Buffer);
    612          1.1  jruoho     ACPI_FREE (Subtable);
    613          1.1  jruoho     return (Status);
    614          1.1  jruoho }
    615