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