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