Home | History | Annotate | Line # | Download | only in acpiexec
aemain.c revision 1.1.1.5.2.5
      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.5.2.5     skrll  * Copyright (C) 2000 - 2017, 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.4  christos UINT8                       AcpiGbl_RegionFillValue = 0;
     83      1.1.1.4  christos BOOLEAN                     AcpiGbl_IgnoreErrors = FALSE;
     84      1.1.1.4  christos BOOLEAN                     AcpiGbl_DbOpt_NoRegionSupport = FALSE;
     85      1.1.1.4  christos UINT8                       AcpiGbl_UseHwReducedFadt = FALSE;
     86      1.1.1.4  christos BOOLEAN                     AcpiGbl_DoInterfaceTests = FALSE;
     87      1.1.1.5  christos BOOLEAN                     AcpiGbl_LoadTestTables = FALSE;
     88  1.1.1.5.2.2     skrll BOOLEAN                     AcpiGbl_AeLoadOnly = FALSE;
     89      1.1.1.4  christos static UINT8                AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP;
     90      1.1.1.4  christos static char                 BatchBuffer[AE_BUFFER_SIZE];    /* Batch command buffer */
     91  1.1.1.5.2.4     skrll static char                 AeBuildDate[] = __DATE__;
     92  1.1.1.5.2.4     skrll static char                 AeBuildTime[] = __TIME__;
     93          1.1    jruoho 
     94      1.1.1.4  christos #define ACPIEXEC_NAME               "AML Execution/Debug Utility"
     95  1.1.1.5.2.2     skrll #define AE_SUPPORTED_OPTIONS        "?b:d:e:f^ghi:lm^rv^:x:"
     96          1.1    jruoho 
     97          1.1    jruoho 
     98      1.1.1.5  christos /* Stubs for the disassembler */
     99      1.1.1.5  christos 
    100      1.1.1.5  christos void
    101      1.1.1.5  christos MpSaveGpioInfo (
    102      1.1.1.5  christos     ACPI_PARSE_OBJECT       *Op,
    103      1.1.1.5  christos     AML_RESOURCE            *Resource,
    104      1.1.1.5  christos     UINT32                  PinCount,
    105      1.1.1.5  christos     UINT16                  *PinList,
    106      1.1.1.5  christos     char                    *DeviceName)
    107      1.1.1.5  christos {
    108      1.1.1.5  christos }
    109      1.1.1.5  christos 
    110      1.1.1.5  christos void
    111      1.1.1.5  christos MpSaveSerialInfo (
    112      1.1.1.5  christos     ACPI_PARSE_OBJECT       *Op,
    113      1.1.1.5  christos     AML_RESOURCE            *Resource,
    114      1.1.1.5  christos     char                    *DeviceName)
    115      1.1.1.5  christos {
    116      1.1.1.5  christos }
    117      1.1.1.5  christos 
    118      1.1.1.5  christos 
    119          1.1    jruoho /******************************************************************************
    120          1.1    jruoho  *
    121      1.1.1.4  christos  * FUNCTION:    usage
    122          1.1    jruoho  *
    123      1.1.1.4  christos  * PARAMETERS:  None
    124          1.1    jruoho  *
    125      1.1.1.4  christos  * RETURN:      None
    126          1.1    jruoho  *
    127      1.1.1.4  christos  * DESCRIPTION: Print a usage message
    128          1.1    jruoho  *
    129      1.1.1.4  christos  *****************************************************************************/
    130          1.1    jruoho 
    131      1.1.1.4  christos static void
    132      1.1.1.4  christos usage (
    133      1.1.1.4  christos     void)
    134          1.1    jruoho {
    135          1.1    jruoho 
    136      1.1.1.4  christos     ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
    137          1.1    jruoho 
    138      1.1.1.4  christos     ACPI_OPTION ("-b \"CommandLine\"",  "Batch mode command line execution (cmd1;cmd2;...)");
    139      1.1.1.4  christos     ACPI_OPTION ("-h -?",               "Display this help message");
    140      1.1.1.4  christos     ACPI_OPTION ("-m [Method]",         "Batch mode method execution. Default=MAIN");
    141      1.1.1.4  christos     printf ("\n");
    142          1.1    jruoho 
    143      1.1.1.4  christos     ACPI_OPTION ("-da",                 "Disable method abort on error");
    144      1.1.1.4  christos     ACPI_OPTION ("-di",                 "Disable execution of STA/INI methods during init");
    145      1.1.1.4  christos     ACPI_OPTION ("-do",                 "Disable Operation Region address simulation");
    146      1.1.1.4  christos     ACPI_OPTION ("-dr",                 "Disable repair of method return values");
    147      1.1.1.5  christos     ACPI_OPTION ("-ds",                 "Disable method auto-serialization");
    148      1.1.1.4  christos     ACPI_OPTION ("-dt",                 "Disable allocation tracking (performance)");
    149      1.1.1.4  christos     printf ("\n");
    150          1.1    jruoho 
    151  1.1.1.5.2.2     skrll     ACPI_OPTION ("-ed",                 "Enable timer output for Debug Object");
    152      1.1.1.4  christos     ACPI_OPTION ("-ef",                 "Enable display of final memory statistics");
    153      1.1.1.4  christos     ACPI_OPTION ("-ei",                 "Enable additional tests for ACPICA interfaces");
    154      1.1.1.5  christos     ACPI_OPTION ("-el",                 "Enable loading of additional test tables");
    155  1.1.1.5.2.2     skrll     ACPI_OPTION ("-em",                 "Enable grouping of module-level code");
    156  1.1.1.5.2.4     skrll     ACPI_OPTION ("-ep",                 "Enable TermList parsing for scope objects");
    157      1.1.1.4  christos     ACPI_OPTION ("-es",                 "Enable Interpreter Slack Mode");
    158      1.1.1.4  christos     ACPI_OPTION ("-et",                 "Enable debug semaphore timeout");
    159      1.1.1.4  christos     printf ("\n");
    160          1.1    jruoho 
    161  1.1.1.5.2.2     skrll     ACPI_OPTION ("-fi <File>",          "Specify namespace initialization file");
    162  1.1.1.5.2.1     skrll     ACPI_OPTION ("-fv <Value>",         "Operation Region initialization fill value");
    163  1.1.1.5.2.2     skrll     printf ("\n");
    164  1.1.1.5.2.2     skrll 
    165  1.1.1.5.2.2     skrll     ACPI_OPTION ("-i <Count>",          "Maximum iterations for AML while loops");
    166  1.1.1.5.2.2     skrll     ACPI_OPTION ("-l",                  "Load tables and namespace only");
    167      1.1.1.4  christos     ACPI_OPTION ("-r",                  "Use hardware-reduced FADT V5");
    168      1.1.1.4  christos     ACPI_OPTION ("-v",                  "Display version information");
    169  1.1.1.5.2.4     skrll     ACPI_OPTION ("-vd",                 "Display build date and time");
    170      1.1.1.4  christos     ACPI_OPTION ("-vi",                 "Verbose initialization output");
    171      1.1.1.4  christos     ACPI_OPTION ("-vr",                 "Verbose region handler output");
    172      1.1.1.4  christos     ACPI_OPTION ("-x <DebugLevel>",     "Debug output level");
    173  1.1.1.5.2.1     skrll 
    174  1.1.1.5.2.1     skrll     printf ("\n  From within the interactive mode, use '?' or \"help\" to see\n"
    175  1.1.1.5.2.1     skrll         "  a list of available AML Debugger commands\n");
    176          1.1    jruoho }
    177          1.1    jruoho 
    178          1.1    jruoho 
    179          1.1    jruoho /******************************************************************************
    180          1.1    jruoho  *
    181      1.1.1.4  christos  * FUNCTION:    AeDoOptions
    182          1.1    jruoho  *
    183      1.1.1.4  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    184          1.1    jruoho  *
    185          1.1    jruoho  * RETURN:      Status
    186          1.1    jruoho  *
    187      1.1.1.4  christos  * DESCRIPTION: Command line option processing
    188          1.1    jruoho  *
    189          1.1    jruoho  *****************************************************************************/
    190          1.1    jruoho 
    191      1.1.1.4  christos static int
    192      1.1.1.4  christos AeDoOptions (
    193          1.1    jruoho     int                     argc,
    194          1.1    jruoho     char                    **argv)
    195          1.1    jruoho {
    196          1.1    jruoho     int                     j;
    197  1.1.1.5.2.2     skrll     UINT32                  Temp;
    198          1.1    jruoho 
    199          1.1    jruoho 
    200      1.1.1.5  christos     while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    201          1.1    jruoho     {
    202          1.1    jruoho     case 'b':
    203      1.1.1.4  christos 
    204      1.1.1.4  christos         if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
    205          1.1    jruoho         {
    206      1.1.1.4  christos             printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
    207      1.1.1.4  christos                 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
    208      1.1.1.2    jruoho             return (-1);
    209          1.1    jruoho         }
    210      1.1.1.4  christos         AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
    211          1.1    jruoho         strcpy (BatchBuffer, AcpiGbl_Optarg);
    212          1.1    jruoho         break;
    213          1.1    jruoho 
    214          1.1    jruoho     case 'd':
    215      1.1.1.4  christos 
    216          1.1    jruoho         switch (AcpiGbl_Optarg[0])
    217          1.1    jruoho         {
    218          1.1    jruoho         case 'a':
    219      1.1.1.4  christos 
    220          1.1    jruoho             AcpiGbl_IgnoreErrors = TRUE;
    221          1.1    jruoho             break;
    222          1.1    jruoho 
    223          1.1    jruoho         case 'i':
    224      1.1.1.4  christos 
    225  1.1.1.5.2.1     skrll             AcpiGbl_DbOpt_NoIniMethods = TRUE;
    226          1.1    jruoho             break;
    227          1.1    jruoho 
    228          1.1    jruoho         case 'o':
    229      1.1.1.4  christos 
    230          1.1    jruoho             AcpiGbl_DbOpt_NoRegionSupport = TRUE;
    231          1.1    jruoho             break;
    232          1.1    jruoho 
    233      1.1.1.3    jruoho         case 'r':
    234      1.1.1.4  christos 
    235      1.1.1.3    jruoho             AcpiGbl_DisableAutoRepair = TRUE;
    236      1.1.1.3    jruoho             break;
    237      1.1.1.3    jruoho 
    238      1.1.1.5  christos         case 's':
    239      1.1.1.5  christos 
    240      1.1.1.5  christos             AcpiGbl_AutoSerializeMethods = FALSE;
    241      1.1.1.5  christos             break;
    242      1.1.1.5  christos 
    243          1.1    jruoho         case 't':
    244      1.1.1.4  christos 
    245          1.1    jruoho             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    246          1.1    jruoho                 AcpiGbl_DisableMemTracking = TRUE;
    247          1.1    jruoho             #endif
    248          1.1    jruoho             break;
    249          1.1    jruoho 
    250          1.1    jruoho         default:
    251      1.1.1.4  christos 
    252          1.1    jruoho             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    253          1.1    jruoho             return (-1);
    254          1.1    jruoho         }
    255          1.1    jruoho         break;
    256          1.1    jruoho 
    257          1.1    jruoho     case 'e':
    258      1.1.1.4  christos 
    259          1.1    jruoho         switch (AcpiGbl_Optarg[0])
    260          1.1    jruoho         {
    261  1.1.1.5.2.2     skrll         case 'd':
    262  1.1.1.5.2.2     skrll 
    263  1.1.1.5.2.2     skrll             AcpiGbl_DisplayDebugTimer = TRUE;
    264  1.1.1.5.2.2     skrll             break;
    265  1.1.1.5.2.2     skrll 
    266          1.1    jruoho         case 'f':
    267      1.1.1.4  christos 
    268          1.1    jruoho             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    269          1.1    jruoho                 AcpiGbl_DisplayFinalMemStats = TRUE;
    270          1.1    jruoho             #endif
    271          1.1    jruoho             break;
    272          1.1    jruoho 
    273      1.1.1.4  christos         case 'i':
    274      1.1.1.4  christos 
    275      1.1.1.4  christos             AcpiGbl_DoInterfaceTests = TRUE;
    276      1.1.1.4  christos             break;
    277      1.1.1.4  christos 
    278      1.1.1.5  christos         case 'l':
    279      1.1.1.4  christos 
    280      1.1.1.5  christos             AcpiGbl_LoadTestTables = TRUE;
    281          1.1    jruoho             break;
    282          1.1    jruoho 
    283  1.1.1.5.2.2     skrll         case 'm':
    284  1.1.1.5.2.2     skrll 
    285  1.1.1.5.2.2     skrll             AcpiGbl_GroupModuleLevelCode = TRUE;
    286  1.1.1.5.2.2     skrll             break;
    287  1.1.1.5.2.2     skrll 
    288  1.1.1.5.2.4     skrll         case 'p':
    289  1.1.1.5.2.4     skrll 
    290  1.1.1.5.2.4     skrll             AcpiGbl_ParseTableAsTermList = TRUE;
    291  1.1.1.5.2.4     skrll             break;
    292  1.1.1.5.2.4     skrll 
    293          1.1    jruoho         case 's':
    294      1.1.1.4  christos 
    295          1.1    jruoho             AcpiGbl_EnableInterpreterSlack = TRUE;
    296          1.1    jruoho             printf ("Enabling AML Interpreter slack mode\n");
    297          1.1    jruoho             break;
    298          1.1    jruoho 
    299          1.1    jruoho         case 't':
    300      1.1.1.4  christos 
    301          1.1    jruoho             AcpiGbl_DebugTimeout = TRUE;
    302          1.1    jruoho             break;
    303          1.1    jruoho 
    304          1.1    jruoho         default:
    305      1.1.1.4  christos 
    306          1.1    jruoho             printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
    307          1.1    jruoho             return (-1);
    308          1.1    jruoho         }
    309          1.1    jruoho         break;
    310          1.1    jruoho 
    311          1.1    jruoho     case 'f':
    312      1.1.1.4  christos 
    313  1.1.1.5.2.1     skrll         switch (AcpiGbl_Optarg[0])
    314  1.1.1.5.2.1     skrll         {
    315  1.1.1.5.2.1     skrll         case 'v':   /* -fv: region fill value */
    316  1.1.1.5.2.1     skrll 
    317  1.1.1.5.2.1     skrll             if (AcpiGetoptArgument (argc, argv))
    318  1.1.1.5.2.1     skrll             {
    319  1.1.1.5.2.1     skrll                 return (-1);
    320  1.1.1.5.2.1     skrll             }
    321  1.1.1.5.2.1     skrll 
    322  1.1.1.5.2.1     skrll             AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    323  1.1.1.5.2.1     skrll             break;
    324  1.1.1.5.2.1     skrll 
    325  1.1.1.5.2.1     skrll         case 'i':   /* -fi: specify initialization file */
    326  1.1.1.5.2.1     skrll 
    327  1.1.1.5.2.1     skrll             if (AcpiGetoptArgument (argc, argv))
    328  1.1.1.5.2.1     skrll             {
    329  1.1.1.5.2.1     skrll                 return (-1);
    330  1.1.1.5.2.1     skrll             }
    331  1.1.1.5.2.1     skrll 
    332  1.1.1.5.2.1     skrll             if (AeOpenInitializationFile (AcpiGbl_Optarg))
    333  1.1.1.5.2.1     skrll             {
    334  1.1.1.5.2.1     skrll                 return (-1);
    335  1.1.1.5.2.1     skrll             }
    336  1.1.1.5.2.1     skrll             break;
    337  1.1.1.5.2.1     skrll 
    338  1.1.1.5.2.1     skrll         default:
    339  1.1.1.5.2.1     skrll 
    340  1.1.1.5.2.1     skrll             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
    341  1.1.1.5.2.1     skrll             return (-1);
    342  1.1.1.5.2.1     skrll         }
    343          1.1    jruoho         break;
    344          1.1    jruoho 
    345          1.1    jruoho     case 'g':
    346      1.1.1.4  christos 
    347          1.1    jruoho         AcpiGbl_DbFilename = NULL;
    348          1.1    jruoho         break;
    349          1.1    jruoho 
    350      1.1.1.4  christos     case 'h':
    351      1.1.1.4  christos     case '?':
    352      1.1.1.4  christos 
    353      1.1.1.4  christos         usage();
    354  1.1.1.5.2.2     skrll         return (1);
    355  1.1.1.5.2.2     skrll 
    356  1.1.1.5.2.2     skrll     case 'i':
    357  1.1.1.5.2.2     skrll 
    358  1.1.1.5.2.2     skrll         Temp = strtoul (AcpiGbl_Optarg, NULL, 0);
    359  1.1.1.5.2.2     skrll         if (!Temp || (Temp > ACPI_UINT16_MAX))
    360  1.1.1.5.2.2     skrll         {
    361  1.1.1.5.2.2     skrll             printf ("%s: Invalid max loops value\n", AcpiGbl_Optarg);
    362  1.1.1.5.2.2     skrll             return (-1);
    363  1.1.1.5.2.2     skrll         }
    364  1.1.1.5.2.2     skrll 
    365  1.1.1.5.2.2     skrll         AcpiGbl_MaxLoopIterations = (UINT16) Temp;
    366  1.1.1.5.2.2     skrll         printf ("Max Loop Iterations is %u (0x%X)\n",
    367  1.1.1.5.2.2     skrll             AcpiGbl_MaxLoopIterations, AcpiGbl_MaxLoopIterations);
    368  1.1.1.5.2.2     skrll         break;
    369  1.1.1.5.2.2     skrll 
    370  1.1.1.5.2.2     skrll     case 'l':
    371  1.1.1.5.2.2     skrll 
    372  1.1.1.5.2.2     skrll         AcpiGbl_AeLoadOnly = TRUE;
    373  1.1.1.5.2.2     skrll         break;
    374      1.1.1.4  christos 
    375          1.1    jruoho     case 'm':
    376      1.1.1.4  christos 
    377      1.1.1.4  christos         AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
    378          1.1    jruoho         switch (AcpiGbl_Optarg[0])
    379          1.1    jruoho         {
    380          1.1    jruoho         case '^':
    381      1.1.1.4  christos 
    382          1.1    jruoho             strcpy (BatchBuffer, "MAIN");
    383          1.1    jruoho             break;
    384          1.1    jruoho 
    385          1.1    jruoho         default:
    386      1.1.1.4  christos 
    387          1.1    jruoho             strcpy (BatchBuffer, AcpiGbl_Optarg);
    388          1.1    jruoho             break;
    389          1.1    jruoho         }
    390          1.1    jruoho         break;
    391          1.1    jruoho 
    392      1.1.1.4  christos     case 'r':
    393      1.1.1.4  christos 
    394      1.1.1.4  christos         AcpiGbl_UseHwReducedFadt = TRUE;
    395      1.1.1.4  christos         printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
    396      1.1.1.4  christos         break;
    397      1.1.1.4  christos 
    398          1.1    jruoho     case 'v':
    399      1.1.1.4  christos 
    400      1.1.1.4  christos         switch (AcpiGbl_Optarg[0])
    401      1.1.1.4  christos         {
    402      1.1.1.4  christos         case '^':  /* -v: (Version): signon already emitted, just exit */
    403      1.1.1.4  christos 
    404      1.1.1.5  christos             (void) AcpiOsTerminate ();
    405  1.1.1.5.2.2     skrll             return (1);
    406      1.1.1.4  christos 
    407  1.1.1.5.2.4     skrll         case 'd':
    408  1.1.1.5.2.4     skrll 
    409  1.1.1.5.2.4     skrll             printf ("Build date/time: %s %s\n", AeBuildDate, AeBuildTime);
    410  1.1.1.5.2.4     skrll             return (1);
    411  1.1.1.5.2.4     skrll 
    412      1.1.1.4  christos         case 'i':
    413      1.1.1.4  christos 
    414      1.1.1.4  christos             AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
    415      1.1.1.4  christos             break;
    416      1.1.1.4  christos 
    417      1.1.1.4  christos         case 'r':
    418      1.1.1.4  christos 
    419      1.1.1.4  christos             AcpiGbl_DisplayRegionAccess = TRUE;
    420      1.1.1.4  christos             break;
    421      1.1.1.4  christos 
    422      1.1.1.4  christos         default:
    423      1.1.1.4  christos 
    424      1.1.1.4  christos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    425      1.1.1.4  christos             return (-1);
    426      1.1.1.4  christos         }
    427          1.1    jruoho         break;
    428          1.1    jruoho 
    429          1.1    jruoho     case 'x':
    430      1.1.1.4  christos 
    431          1.1    jruoho         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
    432          1.1    jruoho         AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
    433          1.1    jruoho         printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
    434          1.1    jruoho         break;
    435          1.1    jruoho 
    436          1.1    jruoho     default:
    437      1.1.1.4  christos 
    438          1.1    jruoho         usage();
    439      1.1.1.2    jruoho         return (-1);
    440          1.1    jruoho     }
    441          1.1    jruoho 
    442      1.1.1.4  christos     return (0);
    443      1.1.1.4  christos }
    444          1.1    jruoho 
    445          1.1    jruoho 
    446      1.1.1.4  christos /******************************************************************************
    447      1.1.1.4  christos  *
    448      1.1.1.4  christos  * FUNCTION:    main
    449      1.1.1.4  christos  *
    450      1.1.1.4  christos  * PARAMETERS:  argc, argv
    451      1.1.1.4  christos  *
    452      1.1.1.4  christos  * RETURN:      Status
    453      1.1.1.4  christos  *
    454      1.1.1.4  christos  * DESCRIPTION: Main routine for AcpiExec utility
    455      1.1.1.4  christos  *
    456      1.1.1.4  christos  *****************************************************************************/
    457          1.1    jruoho 
    458      1.1.1.4  christos int ACPI_SYSTEM_XFACE
    459      1.1.1.4  christos main (
    460      1.1.1.4  christos     int                     argc,
    461      1.1.1.4  christos     char                    **argv)
    462      1.1.1.4  christos {
    463  1.1.1.5.2.2     skrll     ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    464      1.1.1.4  christos     ACPI_STATUS             Status;
    465      1.1.1.4  christos     UINT32                  InitFlags;
    466  1.1.1.5.2.2     skrll     int                     ExitCode = 0;
    467          1.1    jruoho 
    468          1.1    jruoho 
    469      1.1.1.4  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    470      1.1.1.4  christos     signal (SIGINT, AeCtrlCHandler);
    471          1.1    jruoho 
    472      1.1.1.5  christos     /* Init debug globals */
    473          1.1    jruoho 
    474      1.1.1.4  christos     AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
    475      1.1.1.4  christos     AcpiDbgLayer = 0xFFFFFFFF;
    476          1.1    jruoho 
    477  1.1.1.5.2.4     skrll     /*
    478  1.1.1.5.2.4     skrll      * Initialize ACPICA and start debugger thread.
    479  1.1.1.5.2.4     skrll      *
    480  1.1.1.5.2.4     skrll      * NOTE: After ACPICA initialization, AcpiTerminate MUST be called
    481  1.1.1.5.2.4     skrll      * before this procedure exits -- otherwise, the console may be
    482  1.1.1.5.2.4     skrll      * left in an incorrect state.
    483  1.1.1.5.2.4     skrll      */
    484      1.1.1.4  christos     Status = AcpiInitializeSubsystem ();
    485  1.1.1.5.2.2     skrll     ACPI_CHECK_OK (AcpiInitializeSubsystem, Status);
    486  1.1.1.5.2.2     skrll     if (ACPI_FAILURE (Status))
    487  1.1.1.5.2.2     skrll     {
    488  1.1.1.5.2.2     skrll         goto ErrorExit;
    489  1.1.1.5.2.2     skrll     }
    490  1.1.1.5.2.2     skrll 
    491  1.1.1.5.2.2     skrll     /* ACPICA runtime configuration */
    492  1.1.1.5.2.2     skrll 
    493  1.1.1.5.2.2     skrll     AcpiGbl_MaxLoopIterations = 400;
    494  1.1.1.5.2.2     skrll 
    495  1.1.1.5.2.2     skrll 
    496  1.1.1.5.2.2     skrll     /* Initialize the AML debugger */
    497  1.1.1.5.2.2     skrll 
    498  1.1.1.5.2.2     skrll     Status = AcpiInitializeDebugger ();
    499  1.1.1.5.2.2     skrll     ACPI_CHECK_OK (AcpiInitializeDebugger, Status);
    500      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    501      1.1.1.4  christos     {
    502      1.1.1.4  christos         goto ErrorExit;
    503      1.1.1.4  christos     }
    504          1.1    jruoho 
    505      1.1.1.5  christos     printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
    506      1.1.1.5  christos     if (argc < 2)
    507      1.1.1.5  christos     {
    508      1.1.1.5  christos         usage ();
    509  1.1.1.5.2.4     skrll         goto NormalExit;
    510      1.1.1.5  christos     }
    511      1.1.1.5  christos 
    512      1.1.1.4  christos     /* Get the command line options */
    513          1.1    jruoho 
    514  1.1.1.5.2.2     skrll     ExitCode = AeDoOptions (argc, argv);
    515  1.1.1.5.2.2     skrll     if (ExitCode)
    516      1.1.1.4  christos     {
    517  1.1.1.5.2.2     skrll         if (ExitCode > 0)
    518  1.1.1.5.2.2     skrll         {
    519  1.1.1.5.2.2     skrll             ExitCode = 0;
    520  1.1.1.5.2.2     skrll         }
    521  1.1.1.5.2.2     skrll 
    522      1.1.1.4  christos         goto ErrorExit;
    523      1.1.1.4  christos     }
    524          1.1    jruoho 
    525      1.1.1.4  christos     /* The remaining arguments are filenames for ACPI tables */
    526          1.1    jruoho 
    527      1.1.1.4  christos     if (!argv[AcpiGbl_Optind])
    528      1.1.1.4  christos     {
    529      1.1.1.4  christos         goto EnterDebugger;
    530      1.1.1.4  christos     }
    531          1.1    jruoho 
    532  1.1.1.5.2.1     skrll     AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */
    533          1.1    jruoho 
    534      1.1.1.4  christos     /* Get each of the ACPI table files on the command line */
    535          1.1    jruoho 
    536      1.1.1.4  christos     while (argv[AcpiGbl_Optind])
    537      1.1.1.4  christos     {
    538  1.1.1.5.2.2     skrll         /* Get all ACPI AML tables in this file */
    539          1.1    jruoho 
    540  1.1.1.5.2.2     skrll         Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind],
    541  1.1.1.5.2.4     skrll             ACPI_GET_ALL_TABLES, &ListHead);
    542          1.1    jruoho         if (ACPI_FAILURE (Status))
    543          1.1    jruoho         {
    544  1.1.1.5.2.2     skrll             ExitCode = -1;
    545      1.1.1.4  christos             goto ErrorExit;
    546          1.1    jruoho         }
    547          1.1    jruoho 
    548      1.1.1.4  christos         AcpiGbl_Optind++;
    549          1.1    jruoho     }
    550          1.1    jruoho 
    551      1.1.1.5  christos     printf ("\n");
    552      1.1.1.5  christos 
    553      1.1.1.4  christos     /* Build a local RSDT with all tables and let ACPICA process the RSDT */
    554          1.1    jruoho 
    555  1.1.1.5.2.2     skrll     Status = AeBuildLocalTables (ListHead);
    556      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    557          1.1    jruoho     {
    558      1.1.1.4  christos         goto ErrorExit;
    559          1.1    jruoho     }
    560      1.1.1.4  christos 
    561  1.1.1.5.2.2     skrll     /* Install all of the ACPI tables */
    562  1.1.1.5.2.2     skrll 
    563      1.1.1.4  christos     Status = AeInstallTables ();
    564      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    565          1.1    jruoho     {
    566  1.1.1.5.2.2     skrll         printf ("**** Could not install ACPI tables, %s\n",
    567      1.1.1.4  christos             AcpiFormatException (Status));
    568      1.1.1.4  christos         goto EnterDebugger;
    569      1.1.1.4  christos     }
    570      1.1.1.4  christos 
    571      1.1.1.4  christos     /*
    572  1.1.1.5.2.2     skrll      * Install most of the handlers (Regions, Notify, Table, etc.)
    573  1.1.1.5.2.2     skrll      * Override the default region handlers, especially SystemMemory,
    574  1.1.1.5.2.2     skrll      * which is simulated in this utility.
    575      1.1.1.4  christos      */
    576      1.1.1.4  christos     Status = AeInstallEarlyHandlers ();
    577      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    578      1.1.1.4  christos     {
    579      1.1.1.4  christos         goto EnterDebugger;
    580      1.1.1.4  christos     }
    581      1.1.1.4  christos 
    582      1.1.1.4  christos     /* Setup initialization flags for ACPICA */
    583      1.1.1.4  christos 
    584      1.1.1.4  christos     InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
    585  1.1.1.5.2.1     skrll     if (AcpiGbl_DbOpt_NoIniMethods)
    586      1.1.1.4  christos     {
    587      1.1.1.4  christos         InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
    588      1.1.1.4  christos     }
    589      1.1.1.4  christos 
    590      1.1.1.4  christos     /*
    591      1.1.1.4  christos      * Main initialization for ACPICA subsystem
    592  1.1.1.5.2.4     skrll      * TBD: Need a way to call this after the ACPI table "LOAD" command?
    593  1.1.1.5.2.4     skrll      *
    594  1.1.1.5.2.4     skrll      * NOTE: This initialization does not match the _Lxx and _Exx methods
    595  1.1.1.5.2.4     skrll      * to individual GPEs, as there are no real GPEs when the hardware
    596  1.1.1.5.2.4     skrll      * is simulated - because there is no namespace until AeLoadTables is
    597  1.1.1.5.2.4     skrll      * executed. This may have to change if AcpiExec is ever run natively
    598  1.1.1.5.2.4     skrll      * on actual hardware (such as under UEFI).
    599      1.1.1.4  christos      */
    600      1.1.1.4  christos     Status = AcpiEnableSubsystem (InitFlags);
    601      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    602      1.1.1.4  christos     {
    603      1.1.1.4  christos         printf ("**** Could not EnableSubsystem, %s\n",
    604      1.1.1.4  christos             AcpiFormatException (Status));
    605      1.1.1.4  christos         goto EnterDebugger;
    606      1.1.1.4  christos     }
    607      1.1.1.4  christos 
    608  1.1.1.5.2.2     skrll     Status = AeLoadTables ();
    609  1.1.1.5.2.2     skrll 
    610  1.1.1.5.2.2     skrll     /*
    611  1.1.1.5.2.2     skrll      * Exit namespace initialization for the "load namespace only" option.
    612  1.1.1.5.2.2     skrll      * No control methods will be executed. However, still enter the
    613  1.1.1.5.2.2     skrll      * the debugger.
    614  1.1.1.5.2.2     skrll      */
    615  1.1.1.5.2.2     skrll     if (AcpiGbl_AeLoadOnly)
    616  1.1.1.5.2.2     skrll     {
    617  1.1.1.5.2.2     skrll         goto EnterDebugger;
    618  1.1.1.5.2.2     skrll     }
    619  1.1.1.5.2.2     skrll 
    620  1.1.1.5.2.2     skrll     if (ACPI_FAILURE (Status))
    621  1.1.1.5.2.2     skrll     {
    622  1.1.1.5.2.2     skrll         printf ("**** Could not load ACPI tables, %s\n",
    623  1.1.1.5.2.2     skrll             AcpiFormatException (Status));
    624  1.1.1.5.2.2     skrll         goto EnterDebugger;
    625  1.1.1.5.2.2     skrll     }
    626  1.1.1.5.2.2     skrll 
    627      1.1.1.4  christos     /*
    628      1.1.1.4  christos      * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
    629      1.1.1.4  christos      * and fixed event handlers
    630      1.1.1.4  christos      */
    631      1.1.1.4  christos     AeInstallLateHandlers ();
    632      1.1.1.4  christos 
    633      1.1.1.4  christos     /* Finish the ACPICA initialization */
    634      1.1.1.4  christos 
    635      1.1.1.4  christos     Status = AcpiInitializeObjects (InitFlags);
    636      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    637      1.1.1.4  christos     {
    638      1.1.1.4  christos         printf ("**** Could not InitializeObjects, %s\n",
    639      1.1.1.4  christos             AcpiFormatException (Status));
    640      1.1.1.4  christos         goto EnterDebugger;
    641      1.1.1.4  christos     }
    642      1.1.1.4  christos 
    643      1.1.1.4  christos     AeMiscellaneousTests ();
    644      1.1.1.4  christos 
    645      1.1.1.4  christos 
    646      1.1.1.4  christos EnterDebugger:
    647      1.1.1.4  christos 
    648      1.1.1.4  christos     /* Exit if error above and we are in one of the batch modes */
    649      1.1.1.4  christos 
    650      1.1.1.4  christos     if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
    651      1.1.1.4  christos     {
    652      1.1.1.4  christos         goto ErrorExit;
    653          1.1    jruoho     }
    654      1.1.1.4  christos 
    655      1.1.1.4  christos     /* Run a batch command or enter the command loop */
    656      1.1.1.4  christos 
    657      1.1.1.4  christos     switch (AcpiGbl_ExecutionMode)
    658          1.1    jruoho     {
    659      1.1.1.4  christos     default:
    660      1.1.1.4  christos     case AE_MODE_COMMAND_LOOP:
    661          1.1    jruoho 
    662  1.1.1.5.2.5     skrll         AcpiRunDebugger (NULL);
    663      1.1.1.4  christos         break;
    664      1.1.1.4  christos 
    665      1.1.1.4  christos     case AE_MODE_BATCH_MULTIPLE:
    666      1.1.1.4  christos 
    667  1.1.1.5.2.5     skrll         AcpiRunDebugger (BatchBuffer);
    668      1.1.1.4  christos         break;
    669      1.1.1.4  christos 
    670      1.1.1.4  christos     case AE_MODE_BATCH_SINGLE:
    671      1.1.1.4  christos 
    672      1.1.1.4  christos         AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
    673      1.1.1.4  christos         break;
    674          1.1    jruoho     }
    675          1.1    jruoho 
    676  1.1.1.5.2.4     skrll     /* Shut down the debugger and ACPICA */
    677      1.1.1.4  christos 
    678  1.1.1.5.2.4     skrll     AcpiTerminateDebugger ();
    679  1.1.1.5.2.4     skrll 
    680  1.1.1.5.2.4     skrll NormalExit:
    681  1.1.1.5.2.4     skrll     ExitCode = 0;
    682      1.1.1.4  christos 
    683      1.1.1.4  christos ErrorExit:
    684      1.1.1.4  christos     (void) AcpiOsTerminate ();
    685  1.1.1.5.2.2     skrll     return (ExitCode);
    686          1.1    jruoho }
    687