Home | History | Annotate | Line # | Download | only in compiler
dttemplate.c revision 1.1.1.7
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: dttemplate - ACPI table template generation
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7      1.1    jruoho /*
      8  1.1.1.7  christos  * Copyright (C) 2000 - 2016, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11      1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1    jruoho  * modification, are permitted provided that the following conditions
     13      1.1    jruoho  * are met:
     14      1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1    jruoho  *    without modification.
     17      1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1    jruoho  *    binary redistribution.
     22      1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1    jruoho  *    from this software without specific prior written permission.
     25      1.1    jruoho  *
     26      1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1    jruoho  * Software Foundation.
     29      1.1    jruoho  *
     30      1.1    jruoho  * NO WARRANTY
     31      1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "aslcompiler.h"
     45      1.1    jruoho #include "acapps.h"
     46      1.1    jruoho #include "dtcompiler.h"
     47      1.1    jruoho #include "dttemplate.h" /* Contains the hex ACPI table templates */
     48      1.1    jruoho 
     49      1.1    jruoho #define _COMPONENT          DT_COMPILER
     50      1.1    jruoho         ACPI_MODULE_NAME    ("dttemplate")
     51      1.1    jruoho 
     52      1.1    jruoho 
     53      1.1    jruoho /* Local prototypes */
     54      1.1    jruoho 
     55      1.1    jruoho static BOOLEAN
     56      1.1    jruoho AcpiUtIsSpecialTable (
     57      1.1    jruoho     char                    *Signature);
     58      1.1    jruoho 
     59      1.1    jruoho static ACPI_STATUS
     60  1.1.1.7  christos DtCreateOneTemplateFile (
     61  1.1.1.7  christos     char                    *Signature,
     62  1.1.1.7  christos     UINT32                  TableCount);
     63  1.1.1.7  christos 
     64  1.1.1.7  christos static ACPI_STATUS
     65      1.1    jruoho DtCreateOneTemplate (
     66      1.1    jruoho     char                    *Signature,
     67  1.1.1.7  christos     UINT32                  TableCount,
     68  1.1.1.6  christos     const ACPI_DMTABLE_DATA *TableData);
     69      1.1    jruoho 
     70      1.1    jruoho static ACPI_STATUS
     71      1.1    jruoho DtCreateAllTemplates (
     72      1.1    jruoho     void);
     73      1.1    jruoho 
     74  1.1.1.7  christos static int
     75  1.1.1.7  christos DtEmitDefinitionBlock (
     76  1.1.1.7  christos     FILE                    *File,
     77  1.1.1.7  christos     char                    *Filename,
     78  1.1.1.7  christos     char                    *Signature,
     79  1.1.1.7  christos     UINT32                  Instance);
     80  1.1.1.7  christos 
     81      1.1    jruoho 
     82      1.1    jruoho /*******************************************************************************
     83      1.1    jruoho  *
     84      1.1    jruoho  * FUNCTION:    AcpiUtIsSpecialTable
     85      1.1    jruoho  *
     86      1.1    jruoho  * PARAMETERS:  Signature           - ACPI table signature
     87      1.1    jruoho  *
     88      1.1    jruoho  * RETURN:      TRUE if signature is a special ACPI table
     89      1.1    jruoho  *
     90      1.1    jruoho  * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI
     91      1.1    jruoho  *              table data structure (AcpiDmTableData).
     92      1.1    jruoho  *
     93      1.1    jruoho  ******************************************************************************/
     94      1.1    jruoho 
     95      1.1    jruoho static BOOLEAN
     96      1.1    jruoho AcpiUtIsSpecialTable (
     97      1.1    jruoho     char                    *Signature)
     98      1.1    jruoho {
     99      1.1    jruoho 
    100      1.1    jruoho     if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) ||
    101  1.1.1.6  christos         ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT) ||
    102      1.1    jruoho         ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT) ||
    103      1.1    jruoho         ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS) ||
    104      1.1    jruoho         ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
    105      1.1    jruoho     {
    106      1.1    jruoho         return (TRUE);
    107      1.1    jruoho     }
    108      1.1    jruoho 
    109      1.1    jruoho     return (FALSE);
    110      1.1    jruoho }
    111      1.1    jruoho 
    112      1.1    jruoho 
    113      1.1    jruoho /*******************************************************************************
    114      1.1    jruoho  *
    115      1.1    jruoho  * FUNCTION:    DtCreateTemplates
    116      1.1    jruoho  *
    117  1.1.1.7  christos  * PARAMETERS:  argv                - Standard command line arguments
    118      1.1    jruoho  *
    119      1.1    jruoho  * RETURN:      Status
    120      1.1    jruoho  *
    121      1.1    jruoho  * DESCRIPTION: Create one or more template files.
    122      1.1    jruoho  *
    123      1.1    jruoho  ******************************************************************************/
    124      1.1    jruoho 
    125      1.1    jruoho ACPI_STATUS
    126      1.1    jruoho DtCreateTemplates (
    127  1.1.1.7  christos     char                    **argv)
    128      1.1    jruoho {
    129  1.1.1.7  christos     char                    *Signature;
    130  1.1.1.7  christos     char                    *End;
    131  1.1.1.7  christos     unsigned long           TableCount;
    132  1.1.1.7  christos     ACPI_STATUS             Status = AE_OK;
    133      1.1    jruoho 
    134      1.1    jruoho 
    135      1.1    jruoho     AslInitializeGlobals ();
    136      1.1    jruoho 
    137  1.1.1.7  christos     Status = AdInitialize ();
    138  1.1.1.7  christos     if (ACPI_FAILURE (Status))
    139  1.1.1.7  christos     {
    140  1.1.1.7  christos         return (Status);
    141  1.1.1.7  christos     }
    142  1.1.1.7  christos 
    143  1.1.1.7  christos     /*
    144  1.1.1.7  christos      * Special cases for DSDT, ALL, and '*'
    145  1.1.1.7  christos      */
    146  1.1.1.3  christos 
    147  1.1.1.7  christos     /* Default (no signature option) is DSDT */
    148  1.1.1.7  christos 
    149  1.1.1.7  christos     if (AcpiGbl_Optind < 3)
    150  1.1.1.3  christos     {
    151  1.1.1.7  christos         Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, 0);
    152  1.1.1.7  christos         goto Exit;
    153  1.1.1.3  christos     }
    154      1.1    jruoho 
    155  1.1.1.7  christos     AcpiGbl_Optind--;
    156  1.1.1.7  christos     Signature = argv[AcpiGbl_Optind];
    157  1.1.1.3  christos     AcpiUtStrupr (Signature);
    158  1.1.1.7  christos 
    159  1.1.1.7  christos     /*
    160  1.1.1.7  christos      * Multiple SSDT support (-T <ssdt count>)
    161  1.1.1.7  christos      */
    162  1.1.1.7  christos     TableCount = strtoul (Signature, &End, 0);
    163  1.1.1.7  christos     if (Signature != End)
    164  1.1.1.7  christos     {
    165  1.1.1.7  christos         /* The count is used for table ID and method name - max is 254(+1) */
    166  1.1.1.7  christos 
    167  1.1.1.7  christos         if (TableCount > 254)
    168  1.1.1.7  christos         {
    169  1.1.1.7  christos             fprintf (stderr, "%u SSDTs requested, maximum is 254\n",
    170  1.1.1.7  christos                 (unsigned int) TableCount);
    171  1.1.1.7  christos 
    172  1.1.1.7  christos             Status = AE_LIMIT;
    173  1.1.1.7  christos             goto Exit;
    174  1.1.1.7  christos         }
    175  1.1.1.7  christos 
    176  1.1.1.7  christos         Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, TableCount);
    177  1.1.1.7  christos         goto Exit;
    178  1.1.1.7  christos     }
    179  1.1.1.7  christos 
    180  1.1.1.7  christos     if (!strcmp (Signature, "ALL"))
    181      1.1    jruoho     {
    182  1.1.1.3  christos         /* Create all available/known templates */
    183  1.1.1.3  christos 
    184      1.1    jruoho         Status = DtCreateAllTemplates ();
    185  1.1.1.7  christos         goto Exit;
    186      1.1    jruoho     }
    187      1.1    jruoho 
    188      1.1    jruoho     /*
    189  1.1.1.7  christos      * Normal case: Create template for each signature
    190  1.1.1.7  christos      */
    191  1.1.1.7  christos     while (argv[AcpiGbl_Optind])
    192  1.1.1.7  christos     {
    193  1.1.1.7  christos         Signature = argv[AcpiGbl_Optind];
    194  1.1.1.7  christos         AcpiUtStrupr (Signature);
    195  1.1.1.7  christos 
    196  1.1.1.7  christos         Status = DtCreateOneTemplateFile (Signature, 0);
    197  1.1.1.7  christos         if (ACPI_FAILURE (Status))
    198  1.1.1.7  christos         {
    199  1.1.1.7  christos             goto Exit;
    200  1.1.1.7  christos         }
    201  1.1.1.7  christos 
    202  1.1.1.7  christos         AcpiGbl_Optind++;
    203  1.1.1.7  christos     }
    204  1.1.1.7  christos 
    205  1.1.1.7  christos 
    206  1.1.1.7  christos Exit:
    207  1.1.1.7  christos     /* Shutdown ACPICA subsystem */
    208  1.1.1.7  christos 
    209  1.1.1.7  christos     (void) AcpiTerminate ();
    210  1.1.1.7  christos     CmDeleteCaches ();
    211  1.1.1.7  christos     return (Status);
    212  1.1.1.7  christos }
    213  1.1.1.7  christos 
    214  1.1.1.7  christos 
    215  1.1.1.7  christos /*******************************************************************************
    216  1.1.1.7  christos  *
    217  1.1.1.7  christos  * FUNCTION:    DtCreateOneTemplateFile
    218  1.1.1.7  christos  *
    219  1.1.1.7  christos  * PARAMETERS:  Signature           - ACPI table signature
    220  1.1.1.7  christos  *
    221  1.1.1.7  christos  * RETURN:      Status
    222  1.1.1.7  christos  *
    223  1.1.1.7  christos  * DESCRIPTION: Create one template file of the requested signature.
    224  1.1.1.7  christos  *
    225  1.1.1.7  christos  ******************************************************************************/
    226  1.1.1.7  christos 
    227  1.1.1.7  christos static ACPI_STATUS
    228  1.1.1.7  christos DtCreateOneTemplateFile (
    229  1.1.1.7  christos     char                    *Signature,
    230  1.1.1.7  christos     UINT32                  TableCount)
    231  1.1.1.7  christos {
    232  1.1.1.7  christos     const ACPI_DMTABLE_DATA *TableData;
    233  1.1.1.7  christos     ACPI_STATUS             Status;
    234  1.1.1.7  christos 
    235  1.1.1.7  christos 
    236  1.1.1.7  christos     /*
    237      1.1    jruoho      * Validate signature and get the template data:
    238      1.1    jruoho      *  1) Signature must be 4 characters
    239      1.1    jruoho      *  2) Signature must be a recognized ACPI table
    240      1.1    jruoho      *  3) There must be a template associated with the signature
    241      1.1    jruoho      */
    242      1.1    jruoho     if (strlen (Signature) != ACPI_NAME_SIZE)
    243      1.1    jruoho     {
    244  1.1.1.3  christos         fprintf (stderr,
    245  1.1.1.7  christos             "%s: Invalid ACPI table signature "
    246  1.1.1.7  christos             "(length must be 4 characters)\n", Signature);
    247      1.1    jruoho         return (AE_ERROR);
    248      1.1    jruoho     }
    249      1.1    jruoho 
    250      1.1    jruoho     /*
    251      1.1    jruoho      * Some slack for the two strange tables whose name is different than
    252      1.1    jruoho      * their signatures: MADT->APIC and FADT->FACP.
    253      1.1    jruoho      */
    254      1.1    jruoho     if (!strcmp (Signature, "MADT"))
    255      1.1    jruoho     {
    256      1.1    jruoho         Signature = "APIC";
    257      1.1    jruoho     }
    258      1.1    jruoho     else if (!strcmp (Signature, "FADT"))
    259      1.1    jruoho     {
    260      1.1    jruoho         Signature = "FACP";
    261      1.1    jruoho     }
    262      1.1    jruoho 
    263  1.1.1.7  christos     /* TableData will point to the template */
    264  1.1.1.7  christos 
    265      1.1    jruoho     TableData = AcpiDmGetTableData (Signature);
    266      1.1    jruoho     if (TableData)
    267      1.1    jruoho     {
    268      1.1    jruoho         if (!TableData->Template)
    269      1.1    jruoho         {
    270  1.1.1.3  christos             fprintf (stderr, "%4.4s: No template available\n", Signature);
    271      1.1    jruoho             return (AE_ERROR);
    272      1.1    jruoho         }
    273      1.1    jruoho     }
    274      1.1    jruoho     else if (!AcpiUtIsSpecialTable (Signature))
    275      1.1    jruoho     {
    276      1.1    jruoho         fprintf (stderr,
    277  1.1.1.3  christos             "%4.4s: Unrecognized ACPI table signature\n", Signature);
    278      1.1    jruoho         return (AE_ERROR);
    279      1.1    jruoho     }
    280      1.1    jruoho 
    281  1.1.1.7  christos     Status = DtCreateOneTemplate (Signature, TableCount, TableData);
    282      1.1    jruoho     return (Status);
    283      1.1    jruoho }
    284      1.1    jruoho 
    285      1.1    jruoho 
    286      1.1    jruoho /*******************************************************************************
    287      1.1    jruoho  *
    288      1.1    jruoho  * FUNCTION:    DtCreateAllTemplates
    289      1.1    jruoho  *
    290      1.1    jruoho  * PARAMETERS:  None
    291      1.1    jruoho  *
    292      1.1    jruoho  * RETURN:      Status
    293      1.1    jruoho  *
    294      1.1    jruoho  * DESCRIPTION: Create all currently defined template files
    295      1.1    jruoho  *
    296      1.1    jruoho  ******************************************************************************/
    297      1.1    jruoho 
    298      1.1    jruoho static ACPI_STATUS
    299      1.1    jruoho DtCreateAllTemplates (
    300      1.1    jruoho     void)
    301      1.1    jruoho {
    302  1.1.1.6  christos     const ACPI_DMTABLE_DATA *TableData;
    303      1.1    jruoho     ACPI_STATUS             Status;
    304      1.1    jruoho 
    305      1.1    jruoho 
    306      1.1    jruoho     fprintf (stderr, "Creating all supported Template files\n");
    307      1.1    jruoho 
    308      1.1    jruoho     /* Walk entire ACPI table data structure */
    309      1.1    jruoho 
    310      1.1    jruoho     for (TableData = AcpiDmTableData; TableData->Signature; TableData++)
    311      1.1    jruoho     {
    312      1.1    jruoho         /* If table has a template, create the template file */
    313      1.1    jruoho 
    314      1.1    jruoho         if (TableData->Template)
    315      1.1    jruoho         {
    316      1.1    jruoho             Status = DtCreateOneTemplate (TableData->Signature,
    317  1.1.1.7  christos                 0, TableData);
    318      1.1    jruoho             if (ACPI_FAILURE (Status))
    319      1.1    jruoho             {
    320      1.1    jruoho                 return (Status);
    321      1.1    jruoho             }
    322      1.1    jruoho         }
    323      1.1    jruoho     }
    324      1.1    jruoho 
    325      1.1    jruoho     /*
    326  1.1.1.3  christos      * Create the special ACPI tables:
    327      1.1    jruoho      * 1) DSDT/SSDT are AML tables, not data tables
    328      1.1    jruoho      * 2) FACS and RSDP have non-standard headers
    329      1.1    jruoho      */
    330  1.1.1.7  christos     Status = DtCreateOneTemplate (ACPI_SIG_DSDT, 0, NULL);
    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.1.7  christos     Status = DtCreateOneTemplate (ACPI_SIG_SSDT, 0, NULL);
    337      1.1    jruoho     if (ACPI_FAILURE (Status))
    338      1.1    jruoho     {
    339      1.1    jruoho         return (Status);
    340      1.1    jruoho     }
    341      1.1    jruoho 
    342  1.1.1.7  christos     Status = DtCreateOneTemplate (ACPI_SIG_OSDT, 0, NULL);
    343      1.1    jruoho     if (ACPI_FAILURE (Status))
    344      1.1    jruoho     {
    345      1.1    jruoho         return (Status);
    346      1.1    jruoho     }
    347      1.1    jruoho 
    348  1.1.1.7  christos     Status = DtCreateOneTemplate (ACPI_SIG_FACS, 0, NULL);
    349  1.1.1.7  christos     if (ACPI_FAILURE (Status))
    350  1.1.1.7  christos     {
    351  1.1.1.7  christos         return (Status);
    352  1.1.1.7  christos     }
    353  1.1.1.7  christos 
    354  1.1.1.7  christos     Status = DtCreateOneTemplate (ACPI_RSDP_NAME, 0, NULL);
    355      1.1    jruoho     if (ACPI_FAILURE (Status))
    356      1.1    jruoho     {
    357      1.1    jruoho         return (Status);
    358      1.1    jruoho     }
    359      1.1    jruoho 
    360      1.1    jruoho     return (AE_OK);
    361      1.1    jruoho }
    362      1.1    jruoho 
    363      1.1    jruoho 
    364      1.1    jruoho /*******************************************************************************
    365      1.1    jruoho  *
    366      1.1    jruoho  * FUNCTION:    DtCreateOneTemplate
    367      1.1    jruoho  *
    368      1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature, NULL terminated.
    369  1.1.1.7  christos  *              TableCount          - Used for SSDTs in same file as DSDT
    370      1.1    jruoho  *              TableData           - Entry in ACPI table data structure.
    371      1.1    jruoho  *                                    NULL if a special ACPI table.
    372      1.1    jruoho  *
    373      1.1    jruoho  * RETURN:      Status
    374      1.1    jruoho  *
    375      1.1    jruoho  * DESCRIPTION: Create one template source file for the requested ACPI table.
    376      1.1    jruoho  *
    377      1.1    jruoho  ******************************************************************************/
    378      1.1    jruoho 
    379      1.1    jruoho static ACPI_STATUS
    380      1.1    jruoho DtCreateOneTemplate (
    381      1.1    jruoho     char                    *Signature,
    382  1.1.1.7  christos     UINT32                  TableCount,
    383  1.1.1.6  christos     const ACPI_DMTABLE_DATA  *TableData)
    384      1.1    jruoho {
    385      1.1    jruoho     char                    *DisasmFilename;
    386      1.1    jruoho     FILE                    *File;
    387      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    388  1.1.1.7  christos     int                     Actual;
    389  1.1.1.7  christos     UINT32                  i;
    390      1.1    jruoho 
    391      1.1    jruoho 
    392      1.1    jruoho     /* New file will have a .asl suffix */
    393      1.1    jruoho 
    394      1.1    jruoho     DisasmFilename = FlGenerateFilename (
    395      1.1    jruoho         Signature, FILE_SUFFIX_ASL_CODE);
    396      1.1    jruoho     if (!DisasmFilename)
    397      1.1    jruoho     {
    398      1.1    jruoho         fprintf (stderr, "Could not generate output filename\n");
    399      1.1    jruoho         return (AE_ERROR);
    400      1.1    jruoho     }
    401      1.1    jruoho 
    402      1.1    jruoho     AcpiUtStrlwr (DisasmFilename);
    403  1.1.1.7  christos     if (!UtQueryForOverwrite (DisasmFilename))
    404  1.1.1.7  christos     {
    405  1.1.1.7  christos         return (AE_ERROR);
    406  1.1.1.7  christos     }
    407  1.1.1.7  christos 
    408      1.1    jruoho     File = fopen (DisasmFilename, "w+");
    409      1.1    jruoho     if (!File)
    410      1.1    jruoho     {
    411  1.1.1.7  christos         fprintf (stderr, "Could not open output file %s\n",
    412  1.1.1.7  christos             DisasmFilename);
    413      1.1    jruoho         return (AE_ERROR);
    414      1.1    jruoho     }
    415      1.1    jruoho 
    416      1.1    jruoho     /* Emit the common file header */
    417      1.1    jruoho 
    418      1.1    jruoho     AcpiOsRedirectOutput (File);
    419      1.1    jruoho 
    420      1.1    jruoho     AcpiOsPrintf ("/*\n");
    421      1.1    jruoho     AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * "));
    422      1.1    jruoho 
    423  1.1.1.7  christos     if (TableCount == 0)
    424  1.1.1.7  christos     {
    425  1.1.1.7  christos         AcpiOsPrintf (" * Template for [%4.4s] ACPI Table",
    426  1.1.1.7  christos             Signature);
    427  1.1.1.7  christos     }
    428  1.1.1.7  christos     else
    429  1.1.1.7  christos     {
    430  1.1.1.7  christos         AcpiOsPrintf (" * Template for [%4.4s] and %u [SSDT] ACPI Tables",
    431  1.1.1.7  christos             Signature, TableCount);
    432  1.1.1.7  christos     }
    433      1.1    jruoho 
    434      1.1    jruoho     /* Dump the actual ACPI table */
    435      1.1    jruoho 
    436      1.1    jruoho     if (TableData)
    437      1.1    jruoho     {
    438      1.1    jruoho         /* Normal case, tables that appear in AcpiDmTableData */
    439      1.1    jruoho 
    440  1.1.1.6  christos         AcpiOsPrintf (" (static data table)\n");
    441  1.1.1.6  christos 
    442      1.1    jruoho         if (Gbl_VerboseTemplates)
    443      1.1    jruoho         {
    444      1.1    jruoho             AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]"
    445      1.1    jruoho                 "  FieldName : HexFieldValue\n */\n\n");
    446      1.1    jruoho         }
    447      1.1    jruoho         else
    448      1.1    jruoho         {
    449      1.1    jruoho             AcpiOsPrintf (" * Format: [ByteLength]"
    450  1.1.1.6  christos                 "  FieldName : HexFieldValue\n */\n");
    451      1.1    jruoho         }
    452      1.1    jruoho 
    453      1.1    jruoho         AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    454      1.1    jruoho             TableData->Template));
    455      1.1    jruoho     }
    456      1.1    jruoho     else
    457      1.1    jruoho     {
    458  1.1.1.7  christos         /* Special ACPI tables - DSDT, SSDT, OSDT, FACS, RSDP */
    459  1.1.1.6  christos 
    460  1.1.1.6  christos         AcpiOsPrintf (" (AML byte code table)\n");
    461  1.1.1.6  christos         AcpiOsPrintf (" */\n");
    462  1.1.1.7  christos 
    463      1.1    jruoho         if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
    464      1.1    jruoho         {
    465  1.1.1.7  christos             Actual = DtEmitDefinitionBlock (
    466  1.1.1.7  christos                 File, DisasmFilename, ACPI_SIG_DSDT, 1);
    467  1.1.1.7  christos             if (Actual < 0)
    468  1.1.1.3  christos             {
    469  1.1.1.3  christos                 Status = AE_ERROR;
    470  1.1.1.3  christos                 goto Cleanup;
    471  1.1.1.3  christos             }
    472  1.1.1.7  christos 
    473  1.1.1.7  christos             /* Emit any requested SSDTs into the same file */
    474  1.1.1.7  christos 
    475  1.1.1.7  christos             for (i = 1; i <= TableCount; i++)
    476  1.1.1.7  christos             {
    477  1.1.1.7  christos                 Actual = DtEmitDefinitionBlock (
    478  1.1.1.7  christos                     File, DisasmFilename, ACPI_SIG_SSDT, i + 1);
    479  1.1.1.7  christos                 if (Actual < 0)
    480  1.1.1.7  christos                 {
    481  1.1.1.7  christos                     Status = AE_ERROR;
    482  1.1.1.7  christos                     goto Cleanup;
    483  1.1.1.7  christos                 }
    484  1.1.1.7  christos             }
    485      1.1    jruoho         }
    486      1.1    jruoho         else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT))
    487      1.1    jruoho         {
    488  1.1.1.7  christos             Actual = DtEmitDefinitionBlock (
    489  1.1.1.7  christos                 File, DisasmFilename, ACPI_SIG_SSDT, 1);
    490  1.1.1.7  christos             if (Actual < 0)
    491  1.1.1.3  christos             {
    492  1.1.1.3  christos                 Status = AE_ERROR;
    493  1.1.1.3  christos                 goto Cleanup;
    494  1.1.1.3  christos             }
    495      1.1    jruoho         }
    496  1.1.1.6  christos         else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT))
    497  1.1.1.6  christos         {
    498  1.1.1.7  christos             Actual = DtEmitDefinitionBlock (
    499  1.1.1.7  christos                 File, DisasmFilename, ACPI_SIG_OSDT, 1);
    500  1.1.1.7  christos             if (Actual < 0)
    501  1.1.1.6  christos             {
    502  1.1.1.6  christos                 Status = AE_ERROR;
    503  1.1.1.6  christos                 goto Cleanup;
    504  1.1.1.6  christos             }
    505  1.1.1.6  christos         }
    506  1.1.1.7  christos         else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
    507      1.1    jruoho         {
    508      1.1    jruoho             AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    509      1.1    jruoho                 TemplateFacs));
    510      1.1    jruoho         }
    511      1.1    jruoho         else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
    512      1.1    jruoho         {
    513      1.1    jruoho             AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    514      1.1    jruoho                 TemplateRsdp));
    515      1.1    jruoho         }
    516      1.1    jruoho         else
    517      1.1    jruoho         {
    518      1.1    jruoho             fprintf (stderr,
    519      1.1    jruoho                 "%4.4s, Unrecognized ACPI table signature\n", Signature);
    520  1.1.1.3  christos             Status = AE_ERROR;
    521  1.1.1.3  christos             goto Cleanup;
    522      1.1    jruoho         }
    523      1.1    jruoho     }
    524      1.1    jruoho 
    525  1.1.1.7  christos     if (TableCount == 0)
    526  1.1.1.7  christos     {
    527  1.1.1.7  christos         fprintf (stderr,
    528  1.1.1.7  christos             "Created ACPI table template for [%4.4s], "
    529  1.1.1.7  christos             "written to \"%s\"\n",
    530  1.1.1.7  christos             Signature, DisasmFilename);
    531  1.1.1.7  christos     }
    532  1.1.1.7  christos     else
    533  1.1.1.7  christos     {
    534  1.1.1.7  christos         fprintf (stderr,
    535  1.1.1.7  christos             "Created ACPI table templates for [%4.4s] "
    536  1.1.1.7  christos             "and %u [SSDT], written to \"%s\"\n",
    537  1.1.1.7  christos             Signature, TableCount, DisasmFilename);
    538  1.1.1.7  christos     }
    539      1.1    jruoho 
    540  1.1.1.3  christos Cleanup:
    541      1.1    jruoho     fclose (File);
    542      1.1    jruoho     AcpiOsRedirectOutput (stdout);
    543      1.1    jruoho     return (Status);
    544      1.1    jruoho }
    545  1.1.1.7  christos 
    546  1.1.1.7  christos 
    547  1.1.1.7  christos /*******************************************************************************
    548  1.1.1.7  christos  *
    549  1.1.1.7  christos  * FUNCTION:    DtEmitDefinitionBlock
    550  1.1.1.7  christos  *
    551  1.1.1.7  christos  * PARAMETERS:  File                - An open file for the block
    552  1.1.1.7  christos  *              Filename            - Filename for same, for error msg(s)
    553  1.1.1.7  christos  *              Signature           - ACPI signature for the block
    554  1.1.1.7  christos  *              Instance            - Used for multiple SSDTs in the same file
    555  1.1.1.7  christos  *
    556  1.1.1.7  christos  * RETURN:      Status from fprintf
    557  1.1.1.7  christos  *
    558  1.1.1.7  christos  * DESCRIPTION: Emit the raw ASL for a complete Definition Block (DSDT or SSDT)
    559  1.1.1.7  christos  *
    560  1.1.1.7  christos  * Note: The AMLFileName parameter for DefinitionBlock is left as a NULL
    561  1.1.1.7  christos  * string. This allows the compiler to create the output AML filename from
    562  1.1.1.7  christos  * the input filename.
    563  1.1.1.7  christos  *
    564  1.1.1.7  christos  ******************************************************************************/
    565  1.1.1.7  christos 
    566  1.1.1.7  christos static int
    567  1.1.1.7  christos DtEmitDefinitionBlock (
    568  1.1.1.7  christos     FILE                    *File,
    569  1.1.1.7  christos     char                    *Filename,
    570  1.1.1.7  christos     char                    *Signature,
    571  1.1.1.7  christos     UINT32                  Instance)
    572  1.1.1.7  christos {
    573  1.1.1.7  christos     int                     Status;
    574  1.1.1.7  christos 
    575  1.1.1.7  christos 
    576  1.1.1.7  christos     Status = fprintf (File,
    577  1.1.1.7  christos         "DefinitionBlock (\"\", \"%4.4s\", 2, \"Intel\", \"_%4.4s_%.2X\", 0x00000001)\n"
    578  1.1.1.7  christos         "{\n"
    579  1.1.1.7  christos         "    Method (%2.2s%.2X)\n"
    580  1.1.1.7  christos         "    {\n"
    581  1.1.1.7  christos         "    }\n"
    582  1.1.1.7  christos         "}\n\n",
    583  1.1.1.7  christos         Signature, Signature, Instance, Signature, Instance);
    584  1.1.1.7  christos 
    585  1.1.1.7  christos     if (Status < 0)
    586  1.1.1.7  christos     {
    587  1.1.1.7  christos         fprintf (stderr,
    588  1.1.1.7  christos             "Could not write %4.4s to output file %s\n",
    589  1.1.1.7  christos             Signature, Filename);
    590  1.1.1.7  christos     }
    591  1.1.1.7  christos 
    592  1.1.1.7  christos     return (Status);
    593  1.1.1.7  christos }
    594