Home | History | Annotate | Line # | Download | only in acpiexec
aemain.c revision 1.1.1.16
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: aemain - Main routine for the AcpiExec utility
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.13  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "aecommon.h"
     45       1.1    jruoho 
     46   1.1.1.4  christos #define _COMPONENT          ACPI_TOOLS
     47       1.1    jruoho         ACPI_MODULE_NAME    ("aemain")
     48       1.1    jruoho 
     49   1.1.1.2    jruoho 
     50   1.1.1.4  christos /*
     51   1.1.1.4  christos  * Main routine for the ACPI user-space execution utility.
     52       1.1    jruoho  *
     53   1.1.1.4  christos  * Portability note: The utility depends upon the host for command-line
     54   1.1.1.4  christos  * wildcard support - it is not implemented locally. For example:
     55       1.1    jruoho  *
     56   1.1.1.4  christos  * Linux/Unix systems: Shell expands wildcards automatically.
     57       1.1    jruoho  *
     58   1.1.1.4  christos  * Windows: The setargv.obj module must be linked in to automatically
     59   1.1.1.4  christos  * expand wildcards.
     60   1.1.1.4  christos  */
     61       1.1    jruoho 
     62   1.1.1.4  christos /* Local prototypes */
     63       1.1    jruoho 
     64   1.1.1.4  christos static int
     65   1.1.1.4  christos AeDoOptions (
     66   1.1.1.4  christos     int                     argc,
     67   1.1.1.4  christos     char                    **argv);
     68       1.1    jruoho 
     69       1.1    jruoho 
     70   1.1.1.4  christos #define AE_BUFFER_SIZE              1024
     71   1.1.1.4  christos #define ASL_MAX_FILES               256
     72       1.1    jruoho 
     73   1.1.1.4  christos /* Execution modes */
     74       1.1    jruoho 
     75   1.1.1.4  christos #define AE_MODE_COMMAND_LOOP        0   /* Normal command execution loop */
     76   1.1.1.4  christos #define AE_MODE_BATCH_MULTIPLE      1   /* -b option to execute a command line */
     77   1.1.1.4  christos #define AE_MODE_BATCH_SINGLE        2   /* -m option to execute a single control method */
     78       1.1    jruoho 
     79       1.1    jruoho 
     80   1.1.1.4  christos /* Globals */
     81       1.1    jruoho 
     82  1.1.1.14  christos BOOLEAN                     AcpiGbl_UseLocalFaultHandler = TRUE;
     83  1.1.1.15  christos BOOLEAN                     AcpiGbl_VerboseHandlers = FALSE;
     84   1.1.1.4  christos UINT8                       AcpiGbl_RegionFillValue = 0;
     85   1.1.1.4  christos BOOLEAN                     AcpiGbl_IgnoreErrors = FALSE;
     86  1.1.1.12  christos BOOLEAN                     AcpiGbl_AbortLoopOnTimeout = FALSE;
     87   1.1.1.4  christos BOOLEAN                     AcpiGbl_DbOpt_NoRegionSupport = FALSE;
     88   1.1.1.4  christos UINT8                       AcpiGbl_UseHwReducedFadt = FALSE;
     89   1.1.1.4  christos BOOLEAN                     AcpiGbl_DoInterfaceTests = FALSE;
     90   1.1.1.5  christos BOOLEAN                     AcpiGbl_LoadTestTables = FALSE;
     91   1.1.1.7  christos BOOLEAN                     AcpiGbl_AeLoadOnly = FALSE;
     92   1.1.1.4  christos static UINT8                AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP;
     93   1.1.1.4  christos static char                 BatchBuffer[AE_BUFFER_SIZE];    /* Batch command buffer */
     94  1.1.1.15  christos INIT_FILE_ENTRY             *AcpiGbl_InitEntries = NULL;
     95  1.1.1.15  christos UINT32                      AcpiGbl_InitFileLineCount = 0;
     96       1.1    jruoho 
     97   1.1.1.4  christos #define ACPIEXEC_NAME               "AML Execution/Debug Utility"
     98  1.1.1.12  christos #define AE_SUPPORTED_OPTIONS        "?b:d:e:f^ghlm^rt^v^:x:"
     99       1.1    jruoho 
    100       1.1    jruoho 
    101   1.1.1.5  christos /* Stubs for the disassembler */
    102   1.1.1.5  christos 
    103   1.1.1.5  christos void
    104   1.1.1.5  christos MpSaveGpioInfo (
    105   1.1.1.5  christos     ACPI_PARSE_OBJECT       *Op,
    106   1.1.1.5  christos     AML_RESOURCE            *Resource,
    107   1.1.1.5  christos     UINT32                  PinCount,
    108   1.1.1.5  christos     UINT16                  *PinList,
    109   1.1.1.5  christos     char                    *DeviceName)
    110   1.1.1.5  christos {
    111   1.1.1.5  christos }
    112   1.1.1.5  christos 
    113   1.1.1.5  christos void
    114   1.1.1.5  christos MpSaveSerialInfo (
    115   1.1.1.5  christos     ACPI_PARSE_OBJECT       *Op,
    116   1.1.1.5  christos     AML_RESOURCE            *Resource,
    117   1.1.1.5  christos     char                    *DeviceName)
    118   1.1.1.5  christos {
    119   1.1.1.5  christos }
    120   1.1.1.5  christos 
    121   1.1.1.5  christos 
    122       1.1    jruoho /******************************************************************************
    123       1.1    jruoho  *
    124   1.1.1.4  christos  * FUNCTION:    usage
    125       1.1    jruoho  *
    126   1.1.1.4  christos  * PARAMETERS:  None
    127       1.1    jruoho  *
    128   1.1.1.4  christos  * RETURN:      None
    129       1.1    jruoho  *
    130   1.1.1.4  christos  * DESCRIPTION: Print a usage message
    131       1.1    jruoho  *
    132   1.1.1.4  christos  *****************************************************************************/
    133       1.1    jruoho 
    134   1.1.1.4  christos static void
    135   1.1.1.4  christos usage (
    136   1.1.1.4  christos     void)
    137       1.1    jruoho {
    138       1.1    jruoho 
    139   1.1.1.4  christos     ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
    140       1.1    jruoho 
    141   1.1.1.4  christos     ACPI_OPTION ("-b \"CommandLine\"",  "Batch mode command line execution (cmd1;cmd2;...)");
    142   1.1.1.4  christos     ACPI_OPTION ("-h -?",               "Display this help message");
    143   1.1.1.4  christos     ACPI_OPTION ("-m [Method]",         "Batch mode method execution. Default=MAIN");
    144   1.1.1.4  christos     printf ("\n");
    145       1.1    jruoho 
    146   1.1.1.4  christos     ACPI_OPTION ("-da",                 "Disable method abort on error");
    147  1.1.1.14  christos     ACPI_OPTION ("-df",                 "Disable Local fault handler");
    148   1.1.1.4  christos     ACPI_OPTION ("-di",                 "Disable execution of STA/INI methods during init");
    149   1.1.1.4  christos     ACPI_OPTION ("-do",                 "Disable Operation Region address simulation");
    150  1.1.1.16  christos     ACPI_OPTION ("-dp",                 "Disable loading DSDT/SSDT as a control method\n"
    151  1.1.1.16  christos                   "                      (enable legacy grouping of module-level code)");
    152   1.1.1.4  christos     ACPI_OPTION ("-dr",                 "Disable repair of method return values");
    153   1.1.1.5  christos     ACPI_OPTION ("-ds",                 "Disable method auto-serialization");
    154   1.1.1.4  christos     ACPI_OPTION ("-dt",                 "Disable allocation tracking (performance)");
    155   1.1.1.4  christos     printf ("\n");
    156       1.1    jruoho 
    157   1.1.1.7  christos     ACPI_OPTION ("-ed",                 "Enable timer output for Debug Object");
    158   1.1.1.4  christos     ACPI_OPTION ("-ef",                 "Enable display of final memory statistics");
    159   1.1.1.4  christos     ACPI_OPTION ("-ei",                 "Enable additional tests for ACPICA interfaces");
    160   1.1.1.5  christos     ACPI_OPTION ("-el",                 "Enable loading of additional test tables");
    161  1.1.1.16  christos     ACPI_OPTION ("-eo",                 "Enable object evaluation log");
    162   1.1.1.4  christos     ACPI_OPTION ("-es",                 "Enable Interpreter Slack Mode");
    163   1.1.1.4  christos     ACPI_OPTION ("-et",                 "Enable debug semaphore timeout");
    164   1.1.1.4  christos     printf ("\n");
    165       1.1    jruoho 
    166   1.1.1.7  christos     ACPI_OPTION ("-fi <File>",          "Specify namespace initialization file");
    167   1.1.1.6  christos     ACPI_OPTION ("-fv <Value>",         "Operation Region initialization fill value");
    168   1.1.1.7  christos     printf ("\n");
    169   1.1.1.7  christos 
    170   1.1.1.7  christos     ACPI_OPTION ("-l",                  "Load tables and namespace only");
    171   1.1.1.4  christos     ACPI_OPTION ("-r",                  "Use hardware-reduced FADT V5");
    172  1.1.1.12  christos     ACPI_OPTION ("-te",                 "Exit loop on timeout instead of aborting method");
    173  1.1.1.12  christos     ACPI_OPTION ("-to <Seconds>",       "Set timeout period for AML while loops");
    174  1.1.1.12  christos     printf ("\n");
    175  1.1.1.12  christos 
    176   1.1.1.4  christos     ACPI_OPTION ("-v",                  "Display version information");
    177   1.1.1.9  christos     ACPI_OPTION ("-vd",                 "Display build date and time");
    178  1.1.1.15  christos     ACPI_OPTION ("-vh",                 "Verbose exception handler output");
    179   1.1.1.4  christos     ACPI_OPTION ("-vi",                 "Verbose initialization output");
    180   1.1.1.4  christos     ACPI_OPTION ("-vr",                 "Verbose region handler output");
    181   1.1.1.4  christos     ACPI_OPTION ("-x <DebugLevel>",     "Debug output level");
    182   1.1.1.6  christos 
    183   1.1.1.6  christos     printf ("\n  From within the interactive mode, use '?' or \"help\" to see\n"
    184   1.1.1.6  christos         "  a list of available AML Debugger commands\n");
    185       1.1    jruoho }
    186       1.1    jruoho 
    187       1.1    jruoho 
    188       1.1    jruoho /******************************************************************************
    189       1.1    jruoho  *
    190   1.1.1.4  christos  * FUNCTION:    AeDoOptions
    191       1.1    jruoho  *
    192   1.1.1.4  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    193       1.1    jruoho  *
    194       1.1    jruoho  * RETURN:      Status
    195       1.1    jruoho  *
    196   1.1.1.4  christos  * DESCRIPTION: Command line option processing
    197       1.1    jruoho  *
    198       1.1    jruoho  *****************************************************************************/
    199       1.1    jruoho 
    200   1.1.1.4  christos static int
    201   1.1.1.4  christos AeDoOptions (
    202       1.1    jruoho     int                     argc,
    203       1.1    jruoho     char                    **argv)
    204       1.1    jruoho {
    205       1.1    jruoho     int                     j;
    206   1.1.1.7  christos     UINT32                  Temp;
    207       1.1    jruoho 
    208       1.1    jruoho 
    209   1.1.1.5  christos     while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    210       1.1    jruoho     {
    211       1.1    jruoho     case 'b':
    212   1.1.1.4  christos 
    213   1.1.1.4  christos         if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
    214       1.1    jruoho         {
    215  1.1.1.16  christos             printf ("**** The length of command line (%u) exceeded maximum (%d)\n",
    216   1.1.1.4  christos                 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
    217   1.1.1.2    jruoho             return (-1);
    218       1.1    jruoho         }
    219   1.1.1.4  christos         AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
    220       1.1    jruoho         strcpy (BatchBuffer, AcpiGbl_Optarg);
    221       1.1    jruoho         break;
    222       1.1    jruoho 
    223       1.1    jruoho     case 'd':
    224   1.1.1.4  christos 
    225       1.1    jruoho         switch (AcpiGbl_Optarg[0])
    226       1.1    jruoho         {
    227       1.1    jruoho         case 'a':
    228   1.1.1.4  christos 
    229       1.1    jruoho             AcpiGbl_IgnoreErrors = TRUE;
    230       1.1    jruoho             break;
    231       1.1    jruoho 
    232  1.1.1.14  christos         case 'f':
    233  1.1.1.14  christos 
    234  1.1.1.14  christos             AcpiGbl_UseLocalFaultHandler = FALSE;
    235  1.1.1.14  christos             break;
    236  1.1.1.14  christos 
    237       1.1    jruoho         case 'i':
    238   1.1.1.4  christos 
    239   1.1.1.6  christos             AcpiGbl_DbOpt_NoIniMethods = TRUE;
    240       1.1    jruoho             break;
    241       1.1    jruoho 
    242       1.1    jruoho         case 'o':
    243   1.1.1.4  christos 
    244       1.1    jruoho             AcpiGbl_DbOpt_NoRegionSupport = TRUE;
    245       1.1    jruoho             break;
    246       1.1    jruoho 
    247  1.1.1.13  christos         case 'p':
    248  1.1.1.13  christos 
    249  1.1.1.13  christos             AcpiGbl_ExecuteTablesAsMethods = FALSE;
    250  1.1.1.13  christos             break;
    251  1.1.1.13  christos 
    252   1.1.1.3    jruoho         case 'r':
    253   1.1.1.4  christos 
    254   1.1.1.3    jruoho             AcpiGbl_DisableAutoRepair = TRUE;
    255   1.1.1.3    jruoho             break;
    256   1.1.1.3    jruoho 
    257   1.1.1.5  christos         case 's':
    258   1.1.1.5  christos 
    259   1.1.1.5  christos             AcpiGbl_AutoSerializeMethods = FALSE;
    260   1.1.1.5  christos             break;
    261   1.1.1.5  christos 
    262       1.1    jruoho         case 't':
    263   1.1.1.4  christos 
    264       1.1    jruoho             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    265       1.1    jruoho                 AcpiGbl_DisableMemTracking = TRUE;
    266       1.1    jruoho             #endif
    267       1.1    jruoho             break;
    268       1.1    jruoho 
    269       1.1    jruoho         default:
    270   1.1.1.4  christos 
    271       1.1    jruoho             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    272       1.1    jruoho             return (-1);
    273       1.1    jruoho         }
    274       1.1    jruoho         break;
    275       1.1    jruoho 
    276       1.1    jruoho     case 'e':
    277   1.1.1.4  christos 
    278       1.1    jruoho         switch (AcpiGbl_Optarg[0])
    279       1.1    jruoho         {
    280   1.1.1.7  christos         case 'd':
    281   1.1.1.7  christos 
    282   1.1.1.7  christos             AcpiGbl_DisplayDebugTimer = TRUE;
    283   1.1.1.7  christos             break;
    284   1.1.1.7  christos 
    285       1.1    jruoho         case 'f':
    286   1.1.1.4  christos 
    287       1.1    jruoho             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    288       1.1    jruoho                 AcpiGbl_DisplayFinalMemStats = TRUE;
    289       1.1    jruoho             #endif
    290       1.1    jruoho             break;
    291       1.1    jruoho 
    292   1.1.1.4  christos         case 'i':
    293   1.1.1.4  christos 
    294   1.1.1.4  christos             AcpiGbl_DoInterfaceTests = TRUE;
    295   1.1.1.4  christos             break;
    296   1.1.1.4  christos 
    297   1.1.1.5  christos         case 'l':
    298   1.1.1.4  christos 
    299   1.1.1.5  christos             AcpiGbl_LoadTestTables = TRUE;
    300       1.1    jruoho             break;
    301       1.1    jruoho 
    302  1.1.1.16  christos         case 'o':
    303   1.1.1.7  christos 
    304  1.1.1.16  christos             AcpiDbgLevel |= ACPI_LV_EVALUATION;
    305  1.1.1.16  christos             AcpiGbl_DbConsoleDebugLevel |= ACPI_LV_EVALUATION;
    306   1.1.1.7  christos             break;
    307   1.1.1.7  christos 
    308       1.1    jruoho         case 's':
    309   1.1.1.4  christos 
    310       1.1    jruoho             AcpiGbl_EnableInterpreterSlack = TRUE;
    311       1.1    jruoho             printf ("Enabling AML Interpreter slack mode\n");
    312       1.1    jruoho             break;
    313       1.1    jruoho 
    314       1.1    jruoho         case 't':
    315   1.1.1.4  christos 
    316       1.1    jruoho             AcpiGbl_DebugTimeout = TRUE;
    317       1.1    jruoho             break;
    318       1.1    jruoho 
    319       1.1    jruoho         default:
    320   1.1.1.4  christos 
    321       1.1    jruoho             printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
    322       1.1    jruoho             return (-1);
    323       1.1    jruoho         }
    324       1.1    jruoho         break;
    325       1.1    jruoho 
    326       1.1    jruoho     case 'f':
    327   1.1.1.4  christos 
    328   1.1.1.6  christos         switch (AcpiGbl_Optarg[0])
    329   1.1.1.6  christos         {
    330   1.1.1.6  christos         case 'v':   /* -fv: region fill value */
    331   1.1.1.6  christos 
    332   1.1.1.6  christos             if (AcpiGetoptArgument (argc, argv))
    333   1.1.1.6  christos             {
    334   1.1.1.6  christos                 return (-1);
    335   1.1.1.6  christos             }
    336   1.1.1.6  christos 
    337   1.1.1.6  christos             AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    338   1.1.1.6  christos             break;
    339   1.1.1.6  christos 
    340   1.1.1.6  christos         case 'i':   /* -fi: specify initialization file */
    341   1.1.1.6  christos 
    342   1.1.1.6  christos             if (AcpiGetoptArgument (argc, argv))
    343   1.1.1.6  christos             {
    344   1.1.1.6  christos                 return (-1);
    345   1.1.1.6  christos             }
    346   1.1.1.6  christos 
    347   1.1.1.6  christos             if (AeOpenInitializationFile (AcpiGbl_Optarg))
    348   1.1.1.6  christos             {
    349   1.1.1.6  christos                 return (-1);
    350   1.1.1.6  christos             }
    351   1.1.1.6  christos             break;
    352   1.1.1.6  christos 
    353   1.1.1.6  christos         default:
    354   1.1.1.6  christos 
    355   1.1.1.6  christos             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
    356   1.1.1.6  christos             return (-1);
    357   1.1.1.6  christos         }
    358       1.1    jruoho         break;
    359       1.1    jruoho 
    360       1.1    jruoho     case 'g':
    361   1.1.1.4  christos 
    362       1.1    jruoho         AcpiGbl_DbFilename = NULL;
    363       1.1    jruoho         break;
    364       1.1    jruoho 
    365   1.1.1.4  christos     case 'h':
    366   1.1.1.4  christos     case '?':
    367   1.1.1.4  christos 
    368   1.1.1.4  christos         usage();
    369   1.1.1.7  christos         return (1);
    370   1.1.1.7  christos 
    371   1.1.1.7  christos     case 'l':
    372   1.1.1.7  christos 
    373   1.1.1.7  christos         AcpiGbl_AeLoadOnly = TRUE;
    374   1.1.1.7  christos         break;
    375   1.1.1.4  christos 
    376       1.1    jruoho     case 'm':
    377   1.1.1.4  christos 
    378   1.1.1.4  christos         AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
    379       1.1    jruoho         switch (AcpiGbl_Optarg[0])
    380       1.1    jruoho         {
    381       1.1    jruoho         case '^':
    382   1.1.1.4  christos 
    383       1.1    jruoho             strcpy (BatchBuffer, "MAIN");
    384       1.1    jruoho             break;
    385       1.1    jruoho 
    386       1.1    jruoho         default:
    387   1.1.1.4  christos 
    388       1.1    jruoho             strcpy (BatchBuffer, AcpiGbl_Optarg);
    389       1.1    jruoho             break;
    390       1.1    jruoho         }
    391       1.1    jruoho         break;
    392       1.1    jruoho 
    393   1.1.1.4  christos     case 'r':
    394   1.1.1.4  christos 
    395   1.1.1.4  christos         AcpiGbl_UseHwReducedFadt = TRUE;
    396   1.1.1.4  christos         printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
    397   1.1.1.4  christos         break;
    398   1.1.1.4  christos 
    399  1.1.1.12  christos     case 't':
    400  1.1.1.12  christos 
    401  1.1.1.12  christos         switch (AcpiGbl_Optarg[0])
    402  1.1.1.12  christos         {
    403  1.1.1.12  christos         case 'o':  /* -to: Set loop timeout in seconds */
    404  1.1.1.12  christos 
    405  1.1.1.12  christos             if (AcpiGetoptArgument (argc, argv))
    406  1.1.1.12  christos             {
    407  1.1.1.12  christos                 return (-1);
    408  1.1.1.12  christos             }
    409  1.1.1.12  christos 
    410  1.1.1.12  christos             Temp = strtoul (AcpiGbl_Optarg, NULL, 0);
    411  1.1.1.12  christos             if (!Temp || (Temp > ACPI_UINT16_MAX))
    412  1.1.1.12  christos             {
    413  1.1.1.12  christos                 printf ("%s: Invalid loop timeout value\n",
    414  1.1.1.12  christos                     AcpiGbl_Optarg);
    415  1.1.1.12  christos                 return (-1);
    416  1.1.1.12  christos             }
    417  1.1.1.12  christos 
    418  1.1.1.12  christos             AcpiGbl_MaxLoopIterations = (UINT16) Temp;
    419  1.1.1.12  christos             printf ("Automatic loop timeout after %u seconds\n",
    420  1.1.1.12  christos                 AcpiGbl_MaxLoopIterations);
    421  1.1.1.12  christos             break;
    422  1.1.1.12  christos 
    423  1.1.1.12  christos         case 'e':
    424  1.1.1.12  christos 
    425  1.1.1.12  christos             AcpiGbl_AbortLoopOnTimeout = TRUE;
    426  1.1.1.12  christos             break;
    427  1.1.1.12  christos 
    428  1.1.1.12  christos         default:
    429  1.1.1.12  christos 
    430  1.1.1.12  christos             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
    431  1.1.1.12  christos             return (-1);
    432  1.1.1.12  christos         }
    433  1.1.1.12  christos         break;
    434  1.1.1.12  christos 
    435       1.1    jruoho     case 'v':
    436   1.1.1.4  christos 
    437   1.1.1.4  christos         switch (AcpiGbl_Optarg[0])
    438   1.1.1.4  christos         {
    439   1.1.1.4  christos         case '^':  /* -v: (Version): signon already emitted, just exit */
    440   1.1.1.4  christos 
    441   1.1.1.7  christos             return (1);
    442   1.1.1.4  christos 
    443   1.1.1.9  christos         case 'd':
    444   1.1.1.9  christos 
    445  1.1.1.12  christos             printf (ACPI_COMMON_BUILD_TIME);
    446   1.1.1.9  christos             return (1);
    447   1.1.1.9  christos 
    448  1.1.1.15  christos         case 'h':
    449  1.1.1.15  christos 
    450  1.1.1.15  christos             AcpiGbl_VerboseHandlers = TRUE;
    451  1.1.1.15  christos             break;
    452  1.1.1.15  christos 
    453   1.1.1.4  christos         case 'i':
    454   1.1.1.4  christos 
    455   1.1.1.4  christos             AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
    456   1.1.1.4  christos             break;
    457   1.1.1.4  christos 
    458   1.1.1.4  christos         case 'r':
    459   1.1.1.4  christos 
    460   1.1.1.4  christos             AcpiGbl_DisplayRegionAccess = TRUE;
    461   1.1.1.4  christos             break;
    462   1.1.1.4  christos 
    463   1.1.1.4  christos         default:
    464   1.1.1.4  christos 
    465   1.1.1.4  christos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    466   1.1.1.4  christos             return (-1);
    467   1.1.1.4  christos         }
    468       1.1    jruoho         break;
    469       1.1    jruoho 
    470       1.1    jruoho     case 'x':
    471   1.1.1.4  christos 
    472  1.1.1.15  christos         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
    473       1.1    jruoho         AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
    474       1.1    jruoho         printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
    475       1.1    jruoho         break;
    476       1.1    jruoho 
    477       1.1    jruoho     default:
    478   1.1.1.4  christos 
    479       1.1    jruoho         usage();
    480   1.1.1.2    jruoho         return (-1);
    481       1.1    jruoho     }
    482       1.1    jruoho 
    483   1.1.1.4  christos     return (0);
    484   1.1.1.4  christos }
    485       1.1    jruoho 
    486       1.1    jruoho 
    487   1.1.1.4  christos /******************************************************************************
    488   1.1.1.4  christos  *
    489   1.1.1.4  christos  * FUNCTION:    main
    490   1.1.1.4  christos  *
    491   1.1.1.4  christos  * PARAMETERS:  argc, argv
    492   1.1.1.4  christos  *
    493   1.1.1.4  christos  * RETURN:      Status
    494   1.1.1.4  christos  *
    495   1.1.1.4  christos  * DESCRIPTION: Main routine for AcpiExec utility
    496   1.1.1.4  christos  *
    497   1.1.1.4  christos  *****************************************************************************/
    498       1.1    jruoho 
    499   1.1.1.4  christos int ACPI_SYSTEM_XFACE
    500   1.1.1.4  christos main (
    501   1.1.1.4  christos     int                     argc,
    502   1.1.1.4  christos     char                    **argv)
    503   1.1.1.4  christos {
    504   1.1.1.7  christos     ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    505   1.1.1.4  christos     ACPI_STATUS             Status;
    506   1.1.1.4  christos     UINT32                  InitFlags;
    507   1.1.1.7  christos     int                     ExitCode = 0;
    508       1.1    jruoho 
    509       1.1    jruoho 
    510   1.1.1.4  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    511  1.1.1.11  christos 
    512  1.1.1.11  christos     signal (SIGINT, AeSignalHandler);
    513       1.1    jruoho 
    514   1.1.1.5  christos     /* Init debug globals */
    515       1.1    jruoho 
    516   1.1.1.4  christos     AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
    517   1.1.1.4  christos     AcpiDbgLayer = 0xFFFFFFFF;
    518       1.1    jruoho 
    519  1.1.1.13  christos     /* Module-level code. Use new architecture */
    520  1.1.1.13  christos 
    521  1.1.1.13  christos     AcpiGbl_ExecuteTablesAsMethods = TRUE;
    522  1.1.1.13  christos 
    523   1.1.1.9  christos     /*
    524   1.1.1.9  christos      * Initialize ACPICA and start debugger thread.
    525   1.1.1.9  christos      *
    526   1.1.1.9  christos      * NOTE: After ACPICA initialization, AcpiTerminate MUST be called
    527   1.1.1.9  christos      * before this procedure exits -- otherwise, the console may be
    528   1.1.1.9  christos      * left in an incorrect state.
    529   1.1.1.9  christos      */
    530   1.1.1.4  christos     Status = AcpiInitializeSubsystem ();
    531   1.1.1.7  christos     ACPI_CHECK_OK (AcpiInitializeSubsystem, Status);
    532   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    533   1.1.1.7  christos     {
    534   1.1.1.7  christos         goto ErrorExit;
    535   1.1.1.7  christos     }
    536   1.1.1.7  christos 
    537  1.1.1.12  christos     /* Use a shorter timeout value for acpiexec */
    538  1.1.1.12  christos 
    539  1.1.1.12  christos     AcpiGbl_MaxLoopIterations = 1;
    540  1.1.1.12  christos 
    541   1.1.1.7  christos     /* Initialize the AML debugger */
    542   1.1.1.7  christos 
    543   1.1.1.7  christos     Status = AcpiInitializeDebugger ();
    544   1.1.1.7  christos     ACPI_CHECK_OK (AcpiInitializeDebugger, Status);
    545   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    546   1.1.1.4  christos     {
    547   1.1.1.4  christos         goto ErrorExit;
    548   1.1.1.4  christos     }
    549       1.1    jruoho 
    550   1.1.1.5  christos     printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
    551   1.1.1.5  christos     if (argc < 2)
    552   1.1.1.5  christos     {
    553   1.1.1.5  christos         usage ();
    554   1.1.1.9  christos         goto NormalExit;
    555   1.1.1.5  christos     }
    556   1.1.1.5  christos 
    557   1.1.1.4  christos     /* Get the command line options */
    558       1.1    jruoho 
    559   1.1.1.7  christos     ExitCode = AeDoOptions (argc, argv);
    560   1.1.1.7  christos     if (ExitCode)
    561   1.1.1.4  christos     {
    562   1.1.1.7  christos         if (ExitCode > 0)
    563   1.1.1.7  christos         {
    564   1.1.1.7  christos             ExitCode = 0;
    565   1.1.1.7  christos         }
    566   1.1.1.7  christos 
    567   1.1.1.4  christos         goto ErrorExit;
    568   1.1.1.4  christos     }
    569       1.1    jruoho 
    570  1.1.1.15  christos     if (AcpiGbl_UseLocalFaultHandler)
    571  1.1.1.15  christos     {
    572  1.1.1.15  christos         signal (SIGSEGV, AeSignalHandler);
    573  1.1.1.15  christos     }
    574  1.1.1.15  christos 
    575  1.1.1.15  christos     AeProcessInitFile();
    576  1.1.1.15  christos 
    577   1.1.1.4  christos     /* The remaining arguments are filenames for ACPI tables */
    578       1.1    jruoho 
    579   1.1.1.4  christos     if (!argv[AcpiGbl_Optind])
    580   1.1.1.4  christos     {
    581   1.1.1.4  christos         goto EnterDebugger;
    582   1.1.1.4  christos     }
    583       1.1    jruoho 
    584   1.1.1.6  christos     AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */
    585       1.1    jruoho 
    586   1.1.1.4  christos     /* Get each of the ACPI table files on the command line */
    587       1.1    jruoho 
    588   1.1.1.4  christos     while (argv[AcpiGbl_Optind])
    589   1.1.1.4  christos     {
    590   1.1.1.7  christos         /* Get all ACPI AML tables in this file */
    591       1.1    jruoho 
    592   1.1.1.7  christos         Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind],
    593   1.1.1.9  christos             ACPI_GET_ALL_TABLES, &ListHead);
    594       1.1    jruoho         if (ACPI_FAILURE (Status))
    595       1.1    jruoho         {
    596   1.1.1.7  christos             ExitCode = -1;
    597   1.1.1.4  christos             goto ErrorExit;
    598       1.1    jruoho         }
    599       1.1    jruoho 
    600   1.1.1.4  christos         AcpiGbl_Optind++;
    601       1.1    jruoho     }
    602       1.1    jruoho 
    603   1.1.1.5  christos     printf ("\n");
    604   1.1.1.5  christos 
    605   1.1.1.4  christos     /* Build a local RSDT with all tables and let ACPICA process the RSDT */
    606       1.1    jruoho 
    607   1.1.1.7  christos     Status = AeBuildLocalTables (ListHead);
    608   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    609       1.1    jruoho     {
    610   1.1.1.4  christos         goto ErrorExit;
    611       1.1    jruoho     }
    612   1.1.1.4  christos 
    613   1.1.1.7  christos     /* Install all of the ACPI tables */
    614   1.1.1.7  christos 
    615   1.1.1.4  christos     Status = AeInstallTables ();
    616   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    617       1.1    jruoho     {
    618   1.1.1.7  christos         printf ("**** Could not install ACPI tables, %s\n",
    619   1.1.1.4  christos             AcpiFormatException (Status));
    620   1.1.1.4  christos         goto EnterDebugger;
    621   1.1.1.4  christos     }
    622   1.1.1.4  christos 
    623   1.1.1.4  christos     /*
    624   1.1.1.7  christos      * Install most of the handlers (Regions, Notify, Table, etc.)
    625   1.1.1.7  christos      * Override the default region handlers, especially SystemMemory,
    626   1.1.1.7  christos      * which is simulated in this utility.
    627   1.1.1.4  christos      */
    628   1.1.1.4  christos     Status = AeInstallEarlyHandlers ();
    629   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    630   1.1.1.4  christos     {
    631   1.1.1.4  christos         goto EnterDebugger;
    632   1.1.1.4  christos     }
    633   1.1.1.4  christos 
    634  1.1.1.13  christos     Status = AeLoadTables ();
    635  1.1.1.13  christos 
    636  1.1.1.13  christos     /*
    637  1.1.1.13  christos      * Exit namespace initialization for the "load namespace only" option.
    638  1.1.1.13  christos      * No control methods will be executed. However, still enter the
    639  1.1.1.13  christos      * the debugger.
    640  1.1.1.13  christos      */
    641  1.1.1.13  christos     if (AcpiGbl_AeLoadOnly)
    642  1.1.1.13  christos     {
    643  1.1.1.13  christos         goto EnterDebugger;
    644  1.1.1.13  christos     }
    645  1.1.1.13  christos 
    646  1.1.1.13  christos     if (ACPI_FAILURE (Status))
    647  1.1.1.13  christos     {
    648  1.1.1.13  christos         printf ("**** Could not load ACPI tables, %s\n",
    649  1.1.1.13  christos             AcpiFormatException (Status));
    650  1.1.1.13  christos         goto EnterDebugger;
    651  1.1.1.13  christos     }
    652  1.1.1.13  christos 
    653   1.1.1.4  christos     /* Setup initialization flags for ACPICA */
    654   1.1.1.4  christos 
    655   1.1.1.4  christos     InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
    656   1.1.1.6  christos     if (AcpiGbl_DbOpt_NoIniMethods)
    657   1.1.1.4  christos     {
    658   1.1.1.4  christos         InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
    659   1.1.1.4  christos     }
    660   1.1.1.4  christos 
    661   1.1.1.4  christos     /*
    662   1.1.1.4  christos      * Main initialization for ACPICA subsystem
    663   1.1.1.9  christos      * TBD: Need a way to call this after the ACPI table "LOAD" command?
    664   1.1.1.9  christos      *
    665   1.1.1.9  christos      * NOTE: This initialization does not match the _Lxx and _Exx methods
    666   1.1.1.9  christos      * to individual GPEs, as there are no real GPEs when the hardware
    667   1.1.1.9  christos      * is simulated - because there is no namespace until AeLoadTables is
    668   1.1.1.9  christos      * executed. This may have to change if AcpiExec is ever run natively
    669   1.1.1.9  christos      * on actual hardware (such as under UEFI).
    670   1.1.1.4  christos      */
    671   1.1.1.4  christos     Status = AcpiEnableSubsystem (InitFlags);
    672   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    673   1.1.1.4  christos     {
    674   1.1.1.4  christos         printf ("**** Could not EnableSubsystem, %s\n",
    675   1.1.1.4  christos             AcpiFormatException (Status));
    676   1.1.1.4  christos         goto EnterDebugger;
    677   1.1.1.4  christos     }
    678   1.1.1.4  christos 
    679   1.1.1.4  christos     /*
    680   1.1.1.4  christos      * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
    681   1.1.1.4  christos      * and fixed event handlers
    682   1.1.1.4  christos      */
    683   1.1.1.4  christos     AeInstallLateHandlers ();
    684   1.1.1.4  christos 
    685   1.1.1.4  christos     /* Finish the ACPICA initialization */
    686   1.1.1.4  christos 
    687   1.1.1.4  christos     Status = AcpiInitializeObjects (InitFlags);
    688   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    689   1.1.1.4  christos     {
    690   1.1.1.4  christos         printf ("**** Could not InitializeObjects, %s\n",
    691   1.1.1.4  christos             AcpiFormatException (Status));
    692   1.1.1.4  christos         goto EnterDebugger;
    693   1.1.1.4  christos     }
    694   1.1.1.4  christos 
    695   1.1.1.4  christos     AeMiscellaneousTests ();
    696   1.1.1.4  christos 
    697   1.1.1.4  christos 
    698   1.1.1.4  christos EnterDebugger:
    699   1.1.1.4  christos 
    700   1.1.1.4  christos     /* Exit if error above and we are in one of the batch modes */
    701   1.1.1.4  christos 
    702   1.1.1.4  christos     if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
    703   1.1.1.4  christos     {
    704   1.1.1.4  christos         goto ErrorExit;
    705       1.1    jruoho     }
    706   1.1.1.4  christos 
    707   1.1.1.4  christos     /* Run a batch command or enter the command loop */
    708   1.1.1.4  christos 
    709   1.1.1.4  christos     switch (AcpiGbl_ExecutionMode)
    710       1.1    jruoho     {
    711   1.1.1.4  christos     default:
    712   1.1.1.4  christos     case AE_MODE_COMMAND_LOOP:
    713       1.1    jruoho 
    714  1.1.1.10  christos         AcpiRunDebugger (NULL);
    715   1.1.1.4  christos         break;
    716   1.1.1.4  christos 
    717   1.1.1.4  christos     case AE_MODE_BATCH_MULTIPLE:
    718   1.1.1.4  christos 
    719  1.1.1.10  christos         AcpiRunDebugger (BatchBuffer);
    720   1.1.1.4  christos         break;
    721   1.1.1.4  christos 
    722   1.1.1.4  christos     case AE_MODE_BATCH_SINGLE:
    723   1.1.1.4  christos 
    724   1.1.1.4  christos         AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
    725   1.1.1.4  christos         break;
    726       1.1    jruoho     }
    727       1.1    jruoho 
    728   1.1.1.9  christos     /* Shut down the debugger and ACPICA */
    729   1.1.1.4  christos 
    730   1.1.1.9  christos     AcpiTerminateDebugger ();
    731   1.1.1.9  christos 
    732  1.1.1.12  christos     /* re-enable debug output for AcpiTerminate output */
    733  1.1.1.12  christos 
    734  1.1.1.12  christos     AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
    735  1.1.1.12  christos 
    736   1.1.1.9  christos NormalExit:
    737   1.1.1.9  christos     ExitCode = 0;
    738   1.1.1.4  christos 
    739   1.1.1.4  christos ErrorExit:
    740  1.1.1.12  christos     (void) AcpiTerminate ();
    741  1.1.1.11  christos     AcDeleteTableList (ListHead);
    742  1.1.1.15  christos     AcpiOsFree (AcpiGbl_InitEntries);
    743   1.1.1.7  christos     return (ExitCode);
    744       1.1    jruoho }
    745