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