Home | History | Annotate | Line # | Download | only in compiler
dtcompile.c revision 1.11.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.2  christos /*
      8  1.11.2.1  christos  * Copyright (C) 2000 - 2019, 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.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.2  christos static ACPI_STATUS
     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.11.2.1  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.1    jruoho 
     92       1.1    jruoho 
     93       1.1    jruoho     /* Initialize globals */
     94       1.1    jruoho 
     95       1.2  christos     Status = DtInitialize ();
     96       1.2  christos     if (ACPI_FAILURE (Status))
     97       1.2  christos     {
     98       1.2  christos         printf ("Error during compiler initialization, 0x%X\n", Status);
     99       1.2  christos         return (Status);
    100       1.2  christos     }
    101       1.2  christos 
    102       1.2  christos     /* Preprocessor */
    103       1.2  christos 
    104  1.11.2.1  christos     if (AslGbl_PreprocessFlag)
    105       1.5  christos     {
    106       1.5  christos         /* Preprocessor */
    107       1.5  christos 
    108       1.5  christos         Event = UtBeginEvent ("Preprocess input file");
    109       1.5  christos         PrDoPreprocess ();
    110       1.5  christos         UtEndEvent (Event);
    111       1.2  christos 
    112  1.11.2.1  christos         if (AslGbl_PreprocessOnly)
    113       1.5  christos         {
    114       1.5  christos             return (AE_OK);
    115       1.5  christos         }
    116       1.2  christos     }
    117       1.1    jruoho 
    118       1.1    jruoho     /*
    119       1.1    jruoho      * Scan the input file (file is already open) and
    120       1.1    jruoho      * build the parse tree
    121       1.1    jruoho      */
    122       1.1    jruoho     Event = UtBeginEvent ("Scan and parse input file");
    123  1.11.2.1  christos     FieldList = DtScanFile (AslGbl_Files[ASL_FILE_INPUT].Handle);
    124       1.1    jruoho     UtEndEvent (Event);
    125       1.1    jruoho 
    126       1.1    jruoho     /* Did the parse tree get successfully constructed? */
    127       1.1    jruoho 
    128       1.1    jruoho     if (!FieldList)
    129       1.1    jruoho     {
    130       1.1    jruoho         /* TBD: temporary error message. Msgs should come from function above */
    131       1.1    jruoho 
    132       1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
    133       1.2  christos             "Input file does not appear to be an ASL or data table source file");
    134       1.2  christos 
    135  1.11.2.1  christos         return (AE_ERROR);
    136       1.1    jruoho     }
    137       1.1    jruoho 
    138       1.1    jruoho     Event = UtBeginEvent ("Compile parse tree");
    139       1.1    jruoho 
    140       1.1    jruoho     /*
    141       1.1    jruoho      * Compile the parse tree
    142       1.1    jruoho      */
    143       1.1    jruoho     Status = DtCompileDataTable (&FieldList);
    144       1.1    jruoho     UtEndEvent (Event);
    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.2  christos 
    153  1.11.2.1  christos         return (Status);
    154       1.1    jruoho     }
    155       1.1    jruoho 
    156       1.1    jruoho     /* Create/open the binary output file */
    157       1.1    jruoho 
    158  1.11.2.1  christos     AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
    159  1.11.2.1  christos     Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
    160       1.1    jruoho     if (ACPI_FAILURE (Status))
    161       1.1    jruoho     {
    162  1.11.2.1  christos         return (Status);
    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.11.2.1  christos     DtOutputBinary (AslGbl_RootTable);
    168       1.2  christos     HxDoHexOutput ();
    169       1.2  christos     DtWriteTableToListing ();
    170       1.1    jruoho 
    171       1.1    jruoho     return (Status);
    172       1.1    jruoho }
    173       1.1    jruoho 
    174       1.1    jruoho 
    175       1.1    jruoho /******************************************************************************
    176       1.1    jruoho  *
    177       1.1    jruoho  * FUNCTION:    DtInitialize
    178       1.1    jruoho  *
    179       1.1    jruoho  * PARAMETERS:  None
    180       1.1    jruoho  *
    181       1.2  christos  * RETURN:      Status
    182       1.1    jruoho  *
    183       1.1    jruoho  * DESCRIPTION: Initialize data table compiler globals. Enables multiple
    184       1.1    jruoho  *              compiles per invocation.
    185       1.1    jruoho  *
    186       1.1    jruoho  *****************************************************************************/
    187       1.1    jruoho 
    188       1.2  christos static ACPI_STATUS
    189       1.1    jruoho DtInitialize (
    190       1.1    jruoho     void)
    191       1.1    jruoho {
    192       1.2  christos     ACPI_STATUS             Status;
    193       1.2  christos 
    194       1.2  christos 
    195       1.2  christos     Status = AcpiOsInitialize ();
    196       1.2  christos     if (ACPI_FAILURE (Status))
    197       1.2  christos     {
    198       1.2  christos         return (Status);
    199       1.2  christos     }
    200       1.2  christos 
    201       1.2  christos     Status = AcpiUtInitGlobals ();
    202       1.2  christos     if (ACPI_FAILURE (Status))
    203       1.2  christos     {
    204       1.2  christos         return (Status);
    205       1.2  christos     }
    206       1.1    jruoho 
    207       1.9  christos     AcpiUtSetIntegerWidth (2); /* Set width to 64 bits */
    208       1.9  christos 
    209  1.11.2.1  christos     AslGbl_FieldList = NULL;
    210  1.11.2.1  christos     AslGbl_RootTable = NULL;
    211  1.11.2.1  christos     AslGbl_SubtableStack = NULL;
    212       1.1    jruoho 
    213       1.3      tron     snprintf (VersionString, sizeof(VersionString), "%X",
    214       1.2  christos 	(UINT32) ACPI_CA_VERSION);
    215       1.2  christos     return (AE_OK);
    216       1.1    jruoho }
    217       1.1    jruoho 
    218       1.1    jruoho 
    219       1.1    jruoho /******************************************************************************
    220       1.1    jruoho  *
    221       1.1    jruoho  * FUNCTION:    DtInsertCompilerIds
    222       1.1    jruoho  *
    223       1.1    jruoho  * PARAMETERS:  FieldList           - Current field list pointer
    224       1.1    jruoho  *
    225       1.1    jruoho  * RETURN:      None
    226       1.1    jruoho  *
    227       1.1    jruoho  * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
    228       1.1    jruoho  *              the original ACPI table header.
    229       1.1    jruoho  *
    230       1.1    jruoho  *****************************************************************************/
    231       1.1    jruoho 
    232       1.1    jruoho static void
    233       1.1    jruoho DtInsertCompilerIds (
    234       1.1    jruoho     DT_FIELD                *FieldList)
    235       1.1    jruoho {
    236       1.1    jruoho     DT_FIELD                *Next;
    237       1.1    jruoho     UINT32                  i;
    238       1.1    jruoho 
    239       1.1    jruoho 
    240       1.1    jruoho     /*
    241       1.1    jruoho      * Don't insert current compiler ID if requested. Used for compiler
    242       1.1    jruoho      * debug/validation only.
    243       1.1    jruoho      */
    244  1.11.2.1  christos     if (AslGbl_UseOriginalCompilerId)
    245       1.1    jruoho     {
    246       1.1    jruoho         return;
    247       1.1    jruoho     }
    248       1.1    jruoho 
    249       1.1    jruoho     /* Walk to the Compiler fields at the end of the header */
    250       1.1    jruoho 
    251       1.1    jruoho     Next = FieldList;
    252       1.1    jruoho     for (i = 0; i < 7; i++)
    253       1.1    jruoho     {
    254       1.1    jruoho         Next = Next->Next;
    255       1.1    jruoho     }
    256       1.1    jruoho 
    257       1.2  christos     Next->Value = ASL_CREATOR_ID;
    258       1.1    jruoho     Next->Flags = DT_FIELD_NOT_ALLOCATED;
    259       1.1    jruoho 
    260       1.1    jruoho     Next = Next->Next;
    261       1.1    jruoho     Next->Value = VersionString;
    262       1.1    jruoho     Next->Flags = DT_FIELD_NOT_ALLOCATED;
    263       1.1    jruoho }
    264       1.1    jruoho 
    265       1.1    jruoho 
    266       1.1    jruoho /******************************************************************************
    267       1.1    jruoho  *
    268       1.1    jruoho  * FUNCTION:    DtCompileDataTable
    269       1.1    jruoho  *
    270       1.1    jruoho  * PARAMETERS:  FieldList           - Current field list pointer
    271       1.1    jruoho  *
    272       1.1    jruoho  * RETURN:      Status
    273       1.1    jruoho  *
    274       1.1    jruoho  * DESCRIPTION: Entry point to compile one data table
    275       1.1    jruoho  *
    276       1.1    jruoho  *****************************************************************************/
    277       1.1    jruoho 
    278       1.1    jruoho static ACPI_STATUS
    279       1.1    jruoho DtCompileDataTable (
    280       1.1    jruoho     DT_FIELD                **FieldList)
    281       1.1    jruoho {
    282       1.6  christos     const ACPI_DMTABLE_DATA *TableData;
    283       1.1    jruoho     DT_SUBTABLE             *Subtable;
    284       1.1    jruoho     char                    *Signature;
    285       1.1    jruoho     ACPI_TABLE_HEADER       *AcpiTableHeader;
    286       1.1    jruoho     ACPI_STATUS             Status;
    287       1.2  christos     DT_FIELD                *RootField = *FieldList;
    288       1.1    jruoho 
    289       1.1    jruoho 
    290       1.1    jruoho     /* Verify that we at least have a table signature and save it */
    291       1.1    jruoho 
    292       1.2  christos     Signature = DtGetFieldValue (*FieldList);
    293       1.1    jruoho     if (!Signature)
    294       1.1    jruoho     {
    295  1.11.2.1  christos         snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", "Signature");
    296       1.2  christos         DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
    297  1.11.2.1  christos             *FieldList, AslGbl_MsgBuffer);
    298       1.1    jruoho         return (AE_ERROR);
    299       1.1    jruoho     }
    300       1.1    jruoho 
    301  1.11.2.1  christos     AslGbl_Signature = UtLocalCacheCalloc (strlen (Signature) + 1);
    302  1.11.2.1  christos     strcpy (AslGbl_Signature, Signature);
    303       1.1    jruoho 
    304       1.1    jruoho     /*
    305       1.1    jruoho      * Handle tables that don't use the common ACPI table header structure.
    306       1.1    jruoho      * Currently, these are the FACS and RSDP. Also check for an OEMx table,
    307       1.1    jruoho      * these tables have user-defined contents.
    308       1.1    jruoho      */
    309  1.11.2.1  christos     if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS))
    310       1.1    jruoho     {
    311       1.1    jruoho         Status = DtCompileFacs (FieldList);
    312       1.1    jruoho         if (ACPI_FAILURE (Status))
    313       1.1    jruoho         {
    314       1.1    jruoho             return (Status);
    315       1.1    jruoho         }
    316       1.1    jruoho 
    317       1.1    jruoho         DtSetTableLength ();
    318       1.1    jruoho         return (Status);
    319       1.1    jruoho     }
    320       1.2  christos     else if (ACPI_VALIDATE_RSDP_SIG (Signature))
    321       1.1    jruoho     {
    322       1.1    jruoho         Status = DtCompileRsdp (FieldList);
    323       1.1    jruoho         return (Status);
    324       1.1    jruoho     }
    325  1.11.2.1  christos     else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_S3PT))
    326       1.1    jruoho     {
    327       1.2  christos         Status = DtCompileS3pt (FieldList);
    328       1.2  christos         if (ACPI_FAILURE (Status))
    329       1.2  christos         {
    330       1.2  christos             return (Status);
    331       1.2  christos         }
    332       1.2  christos 
    333       1.2  christos         DtSetTableLength ();
    334       1.2  christos         return (Status);
    335       1.1    jruoho     }
    336       1.1    jruoho 
    337       1.1    jruoho     /*
    338       1.1    jruoho      * All other tables must use the common ACPI table header. Insert the
    339       1.1    jruoho      * current iASL IDs (name, version), and compile the header now.
    340       1.1    jruoho      */
    341       1.1    jruoho     DtInsertCompilerIds (*FieldList);
    342       1.1    jruoho 
    343       1.1    jruoho     Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
    344  1.11.2.1  christos         &AslGbl_RootTable);
    345       1.1    jruoho     if (ACPI_FAILURE (Status))
    346       1.1    jruoho     {
    347       1.1    jruoho         return (Status);
    348       1.1    jruoho     }
    349       1.1    jruoho 
    350  1.11.2.1  christos     DtPushSubtable (AslGbl_RootTable);
    351       1.1    jruoho 
    352       1.2  christos     /* Validate the signature via the ACPI table list */
    353       1.1    jruoho 
    354       1.1    jruoho     TableData = AcpiDmGetTableData (Signature);
    355  1.11.2.1  christos     if (!TableData || AslGbl_CompileGeneric)
    356       1.1    jruoho     {
    357       1.6  christos         /* Unknown table signature and/or force generic compile */
    358       1.6  christos 
    359       1.6  christos         DtCompileGeneric ((void **) FieldList, NULL, NULL);
    360       1.2  christos         goto FinishHeader;
    361       1.1    jruoho     }
    362       1.1    jruoho 
    363       1.2  christos     /* Dispatch to per-table compile */
    364       1.2  christos 
    365       1.1    jruoho     if (TableData->CmTableHandler)
    366       1.1    jruoho     {
    367       1.1    jruoho         /* Complex table, has a handler */
    368       1.1    jruoho 
    369       1.1    jruoho         Status = TableData->CmTableHandler ((void **) FieldList);
    370       1.1    jruoho         if (ACPI_FAILURE (Status))
    371       1.1    jruoho         {
    372       1.1    jruoho             return (Status);
    373       1.1    jruoho         }
    374       1.1    jruoho     }
    375       1.1    jruoho     else if (TableData->TableInfo)
    376       1.1    jruoho     {
    377       1.9  christos         /* Simple table, just walk the info table, unless its empty */
    378       1.1    jruoho 
    379       1.9  christos         if (FieldList && *FieldList)
    380       1.1    jruoho         {
    381       1.9  christos             Subtable = NULL;
    382       1.9  christos             Status = DtCompileTable (FieldList, TableData->TableInfo,
    383      1.11  christos                 &Subtable);
    384       1.9  christos             if (ACPI_FAILURE (Status))
    385       1.9  christos             {
    386       1.9  christos                 return (Status);
    387       1.9  christos             }
    388       1.9  christos 
    389  1.11.2.1  christos             DtInsertSubtable (AslGbl_RootTable, Subtable);
    390       1.9  christos             DtPopSubtable ();
    391       1.1    jruoho         }
    392       1.1    jruoho     }
    393       1.1    jruoho     else
    394       1.1    jruoho     {
    395       1.1    jruoho         DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
    396       1.1    jruoho             "Missing table dispatch info");
    397       1.1    jruoho         return (AE_ERROR);
    398       1.1    jruoho     }
    399       1.1    jruoho 
    400       1.2  christos FinishHeader:
    401       1.2  christos 
    402       1.1    jruoho     /* Set the final table length and then the checksum */
    403       1.1    jruoho 
    404       1.1    jruoho     DtSetTableLength ();
    405       1.1    jruoho     AcpiTableHeader = ACPI_CAST_PTR (
    406  1.11.2.1  christos         ACPI_TABLE_HEADER, AslGbl_RootTable->Buffer);
    407       1.1    jruoho     DtSetTableChecksum (&AcpiTableHeader->Checksum);
    408       1.1    jruoho 
    409       1.2  christos     DtDumpFieldList (RootField);
    410       1.2  christos     DtDumpSubtableList ();
    411       1.1    jruoho     return (AE_OK);
    412       1.1    jruoho }
    413       1.1    jruoho 
    414       1.1    jruoho 
    415       1.1    jruoho /******************************************************************************
    416       1.1    jruoho  *
    417       1.1    jruoho  * FUNCTION:    DtCompileTable
    418       1.1    jruoho  *
    419       1.1    jruoho  * PARAMETERS:  Field               - Current field list pointer
    420       1.1    jruoho  *              Info                - Info table for this ACPI table
    421       1.1    jruoho  *              RetSubtable         - Compile result of table
    422       1.1    jruoho  *
    423       1.1    jruoho  * RETURN:      Status
    424       1.1    jruoho  *
    425       1.1    jruoho  * DESCRIPTION: Compile a subtable
    426       1.1    jruoho  *
    427       1.1    jruoho  *****************************************************************************/
    428       1.1    jruoho 
    429       1.1    jruoho ACPI_STATUS
    430       1.1    jruoho DtCompileTable (
    431       1.1    jruoho     DT_FIELD                **Field,
    432       1.1    jruoho     ACPI_DMTABLE_INFO       *Info,
    433      1.11  christos     DT_SUBTABLE             **RetSubtable)
    434       1.1    jruoho {
    435       1.1    jruoho     DT_FIELD                *LocalField;
    436       1.1    jruoho     UINT32                  Length;
    437       1.1    jruoho     DT_SUBTABLE             *Subtable;
    438       1.6  christos     DT_SUBTABLE             *InlineSubtable = NULL;
    439       1.1    jruoho     UINT32                  FieldLength = 0;
    440       1.1    jruoho     UINT8                   FieldType;
    441       1.1    jruoho     UINT8                   *Buffer;
    442       1.1    jruoho     UINT8                   *FlagBuffer = NULL;
    443       1.4  christos     char                    *String;
    444       1.2  christos     UINT32                  CurrentFlagByteOffset = 0;
    445       1.6  christos     ACPI_STATUS             Status = AE_OK;
    446       1.1    jruoho 
    447       1.1    jruoho 
    448      1.11  christos     if (!Field)
    449       1.1    jruoho     {
    450       1.1    jruoho         return (AE_BAD_PARAMETER);
    451       1.1    jruoho     }
    452      1.11  christos     if (!*Field)
    453      1.11  christos     {
    454      1.11  christos         /*
    455      1.11  christos          * The field list is empty, this means that we are out of fields to
    456      1.11  christos          * parse. In other words, we are at the end of the table.
    457      1.11  christos          */
    458      1.11  christos         return (AE_END_OF_TABLE);
    459      1.11  christos     }
    460       1.1    jruoho 
    461       1.2  christos     /* Ignore optional subtable if name does not match */
    462       1.2  christos 
    463       1.2  christos     if ((Info->Flags & DT_OPTIONAL) &&
    464       1.6  christos         strcmp ((*Field)->Name, Info->Name))
    465       1.2  christos     {
    466       1.2  christos         *RetSubtable = NULL;
    467       1.2  christos         return (AE_OK);
    468       1.2  christos     }
    469       1.2  christos 
    470       1.1    jruoho     Length = DtGetSubtableLength (*Field, Info);
    471       1.2  christos     if (Length == ASL_EOF)
    472       1.2  christos     {
    473       1.2  christos         return (AE_ERROR);
    474       1.2  christos     }
    475       1.2  christos 
    476       1.4  christos     Subtable = UtSubtableCacheCalloc ();
    477       1.1    jruoho 
    478       1.2  christos     if (Length > 0)
    479       1.2  christos     {
    480      1.10  christos         String = UtLocalCacheCalloc (Length);
    481       1.4  christos         Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
    482       1.2  christos     }
    483       1.4  christos 
    484       1.1    jruoho     Subtable->Length = Length;
    485       1.1    jruoho     Subtable->TotalLength = Length;
    486       1.1    jruoho     Buffer = Subtable->Buffer;
    487       1.1    jruoho 
    488       1.1    jruoho     LocalField = *Field;
    489       1.6  christos     Subtable->Name = LocalField->Name;
    490       1.1    jruoho 
    491       1.1    jruoho     /*
    492       1.1    jruoho      * Main loop walks the info table for this ACPI table or subtable
    493       1.1    jruoho      */
    494       1.1    jruoho     for (; Info->Name; Info++)
    495       1.1    jruoho     {
    496       1.2  christos         if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
    497       1.2  christos         {
    498       1.2  christos             continue;
    499       1.2  christos         }
    500       1.2  christos 
    501       1.1    jruoho         if (!LocalField)
    502       1.1    jruoho         {
    503  1.11.2.1  christos             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Found NULL field - Field name \"%s\" needed",
    504       1.1    jruoho                 Info->Name);
    505  1.11.2.1  christos             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    506       1.1    jruoho             Status = AE_BAD_DATA;
    507       1.1    jruoho             goto Error;
    508       1.1    jruoho         }
    509       1.1    jruoho 
    510       1.2  christos         /* Maintain table offsets */
    511       1.1    jruoho 
    512  1.11.2.1  christos         LocalField->TableOffset = AslGbl_CurrentTableOffset;
    513       1.2  christos         FieldLength = DtGetFieldLength (LocalField, Info);
    514  1.11.2.1  christos         AslGbl_CurrentTableOffset += FieldLength;
    515       1.1    jruoho 
    516       1.1    jruoho         FieldType = DtGetFieldType (Info);
    517  1.11.2.1  christos         AslGbl_InputFieldCount++;
    518       1.1    jruoho 
    519       1.1    jruoho         switch (FieldType)
    520       1.1    jruoho         {
    521       1.1    jruoho         case DT_FIELD_TYPE_FLAGS_INTEGER:
    522       1.1    jruoho             /*
    523       1.1    jruoho              * Start of the definition of a flags field.
    524       1.1    jruoho              * This master flags integer starts at value zero, in preparation
    525       1.1    jruoho              * to compile and insert the flag fields from the individual bits
    526       1.1    jruoho              */
    527       1.1    jruoho             LocalField = LocalField->Next;
    528       1.1    jruoho             *Field = LocalField;
    529       1.1    jruoho 
    530       1.1    jruoho             FlagBuffer = Buffer;
    531       1.2  christos             CurrentFlagByteOffset = Info->Offset;
    532       1.1    jruoho             break;
    533       1.1    jruoho 
    534       1.1    jruoho         case DT_FIELD_TYPE_FLAG:
    535       1.1    jruoho 
    536       1.1    jruoho             /* Individual Flag field, can be multiple bits */
    537       1.1    jruoho 
    538       1.1    jruoho             if (FlagBuffer)
    539       1.1    jruoho             {
    540       1.2  christos                 /*
    541       1.2  christos                  * We must increment the FlagBuffer when we have crossed
    542       1.2  christos                  * into the next flags byte within the flags field
    543       1.2  christos                  * of type DT_FIELD_TYPE_FLAGS_INTEGER.
    544       1.2  christos                  */
    545       1.2  christos                 FlagBuffer += (Info->Offset - CurrentFlagByteOffset);
    546       1.2  christos                 CurrentFlagByteOffset = Info->Offset;
    547       1.2  christos 
    548       1.2  christos                 DtCompileFlag (FlagBuffer, LocalField, Info);
    549       1.1    jruoho             }
    550       1.1    jruoho             else
    551       1.1    jruoho             {
    552       1.1    jruoho                 /* TBD - this is an internal error */
    553       1.1    jruoho             }
    554       1.1    jruoho 
    555       1.1    jruoho             LocalField = LocalField->Next;
    556       1.1    jruoho             *Field = LocalField;
    557       1.1    jruoho             break;
    558       1.1    jruoho 
    559       1.1    jruoho         case DT_FIELD_TYPE_INLINE_SUBTABLE:
    560       1.1    jruoho             /*
    561       1.1    jruoho              * Recursion (one level max): compile GAS (Generic Address)
    562       1.1    jruoho              * or Notify in-line subtable
    563       1.1    jruoho              */
    564       1.1    jruoho             *Field = LocalField;
    565       1.1    jruoho 
    566       1.6  christos             switch (Info->Opcode)
    567       1.1    jruoho             {
    568       1.6  christos             case ACPI_DMT_GAS:
    569       1.6  christos 
    570       1.1    jruoho                 Status = DtCompileTable (Field, AcpiDmTableInfoGas,
    571      1.11  christos                     &InlineSubtable);
    572       1.6  christos                 break;
    573       1.6  christos 
    574       1.6  christos             case ACPI_DMT_HESTNTFY:
    575       1.6  christos 
    576       1.1    jruoho                 Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
    577      1.11  christos                     &InlineSubtable);
    578       1.6  christos                 break;
    579       1.6  christos 
    580       1.6  christos             case ACPI_DMT_IORTMEM:
    581       1.6  christos 
    582       1.6  christos                 Status = DtCompileTable (Field, AcpiDmTableInfoIortAcc,
    583      1.11  christos                     &InlineSubtable);
    584       1.6  christos                 break;
    585       1.6  christos 
    586       1.6  christos             default:
    587  1.11.2.1  christos                 sprintf (AslGbl_MsgBuffer, "Invalid DMT opcode: 0x%.2X",
    588       1.6  christos                     Info->Opcode);
    589  1.11.2.1  christos                 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    590       1.6  christos                 Status = AE_BAD_DATA;
    591       1.6  christos                 break;
    592       1.1    jruoho             }
    593       1.1    jruoho 
    594       1.1    jruoho             if (ACPI_FAILURE (Status))
    595       1.1    jruoho             {
    596       1.1    jruoho                 goto Error;
    597       1.1    jruoho             }
    598       1.1    jruoho 
    599       1.2  christos             DtSetSubtableLength (InlineSubtable);
    600       1.2  christos 
    601       1.6  christos             memcpy (Buffer, InlineSubtable->Buffer, FieldLength);
    602       1.1    jruoho             LocalField = *Field;
    603       1.1    jruoho             break;
    604       1.1    jruoho 
    605       1.2  christos         case DT_FIELD_TYPE_LABEL:
    606       1.2  christos 
    607       1.2  christos             DtWriteFieldToListing (Buffer, LocalField, 0);
    608       1.2  christos             LocalField = LocalField->Next;
    609       1.2  christos             break;
    610       1.2  christos 
    611       1.1    jruoho         default:
    612       1.1    jruoho 
    613       1.1    jruoho             /* Normal case for most field types (Integer, String, etc.) */
    614       1.1    jruoho 
    615       1.1    jruoho             DtCompileOneField (Buffer, LocalField,
    616       1.1    jruoho                 FieldLength, FieldType, Info->Flags);
    617       1.2  christos 
    618       1.2  christos             DtWriteFieldToListing (Buffer, LocalField, FieldLength);
    619       1.1    jruoho             LocalField = LocalField->Next;
    620       1.1    jruoho 
    621       1.1    jruoho             if (Info->Flags & DT_LENGTH)
    622       1.1    jruoho             {
    623       1.1    jruoho                 /* Field is an Integer that will contain a subtable length */
    624       1.1    jruoho 
    625       1.1    jruoho                 Subtable->LengthField = Buffer;
    626       1.1    jruoho                 Subtable->SizeOfLengthField = FieldLength;
    627       1.1    jruoho             }
    628       1.1    jruoho             break;
    629       1.1    jruoho         }
    630       1.1    jruoho 
    631       1.1    jruoho         Buffer += FieldLength;
    632       1.1    jruoho     }
    633       1.1    jruoho 
    634       1.1    jruoho     *Field = LocalField;
    635       1.1    jruoho     *RetSubtable = Subtable;
    636       1.1    jruoho     return (AE_OK);
    637       1.1    jruoho 
    638       1.1    jruoho Error:
    639       1.1    jruoho     ACPI_FREE (Subtable->Buffer);
    640       1.1    jruoho     ACPI_FREE (Subtable);
    641       1.1    jruoho     return (Status);
    642       1.1    jruoho }
    643       1.6  christos 
    644       1.6  christos 
    645       1.6  christos /******************************************************************************
    646       1.6  christos  *
    647       1.7  christos  * FUNCTION:    DtCompileTwoSubtables
    648       1.7  christos  *
    649       1.7  christos  * PARAMETERS:  List                - Current field list pointer
    650       1.7  christos  *              TableInfo1          - Info table 1
    651       1.7  christos  *              TableInfo1          - Info table 2
    652       1.7  christos  *
    653       1.7  christos  * RETURN:      Status
    654       1.7  christos  *
    655       1.7  christos  * DESCRIPTION: Compile tables with a header and one or more same subtables.
    656       1.7  christos  *              Include CPEP, EINJ, ERST, MCFG, MSCT, WDAT
    657       1.7  christos  *
    658       1.7  christos  *****************************************************************************/
    659       1.7  christos 
    660       1.7  christos ACPI_STATUS
    661       1.7  christos DtCompileTwoSubtables (
    662       1.7  christos     void                    **List,
    663       1.7  christos     ACPI_DMTABLE_INFO       *TableInfo1,
    664       1.7  christos     ACPI_DMTABLE_INFO       *TableInfo2)
    665       1.7  christos {
    666       1.7  christos     ACPI_STATUS             Status;
    667       1.7  christos     DT_SUBTABLE             *Subtable;
    668       1.7  christos     DT_SUBTABLE             *ParentTable;
    669       1.7  christos     DT_FIELD                **PFieldList = (DT_FIELD **) List;
    670       1.7  christos 
    671       1.7  christos 
    672      1.11  christos     Status = DtCompileTable (PFieldList, TableInfo1, &Subtable);
    673       1.7  christos     if (ACPI_FAILURE (Status))
    674       1.7  christos     {
    675       1.7  christos         return (Status);
    676       1.7  christos     }
    677       1.7  christos 
    678       1.7  christos     ParentTable = DtPeekSubtable ();
    679       1.7  christos     DtInsertSubtable (ParentTable, Subtable);
    680       1.7  christos 
    681       1.7  christos     while (*PFieldList)
    682       1.7  christos     {
    683      1.11  christos         Status = DtCompileTable (PFieldList, TableInfo2, &Subtable);
    684       1.7  christos         if (ACPI_FAILURE (Status))
    685       1.7  christos         {
    686       1.7  christos             return (Status);
    687       1.7  christos         }
    688       1.7  christos 
    689       1.7  christos         DtInsertSubtable (ParentTable, Subtable);
    690       1.7  christos     }
    691       1.7  christos 
    692       1.7  christos     return (AE_OK);
    693       1.7  christos }
    694       1.7  christos 
    695       1.7  christos 
    696       1.7  christos /******************************************************************************
    697       1.7  christos  *
    698       1.6  christos  * FUNCTION:    DtCompilePadding
    699       1.6  christos  *
    700       1.6  christos  * PARAMETERS:  Length              - Padding field size
    701       1.6  christos  *              RetSubtable         - Compile result of table
    702       1.6  christos  *
    703       1.6  christos  * RETURN:      Status
    704       1.6  christos  *
    705       1.6  christos  * DESCRIPTION: Compile a subtable for padding purpose
    706       1.6  christos  *
    707       1.6  christos  *****************************************************************************/
    708       1.6  christos 
    709       1.6  christos ACPI_STATUS
    710       1.6  christos DtCompilePadding (
    711       1.6  christos     UINT32                  Length,
    712       1.6  christos     DT_SUBTABLE             **RetSubtable)
    713       1.6  christos {
    714       1.6  christos     DT_SUBTABLE             *Subtable;
    715       1.6  christos     /* UINT8                   *Buffer; */
    716       1.6  christos     char                    *String;
    717       1.6  christos 
    718       1.6  christos 
    719       1.6  christos     Subtable = UtSubtableCacheCalloc ();
    720       1.6  christos 
    721       1.6  christos     if (Length > 0)
    722       1.6  christos     {
    723      1.10  christos         String = UtLocalCacheCalloc (Length);
    724       1.6  christos         Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
    725       1.6  christos     }
    726       1.6  christos 
    727       1.6  christos     Subtable->Length = Length;
    728       1.6  christos     Subtable->TotalLength = Length;
    729       1.6  christos     /* Buffer = Subtable->Buffer; */
    730       1.6  christos 
    731       1.6  christos     *RetSubtable = Subtable;
    732       1.6  christos     return (AE_OK);
    733       1.6  christos }
    734