1 /******************************************************************************
3 * Module Name: aemain - Main routine for the AcpiExec utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("aemain")
51 * Main routine for the ACPI user-space execution utility.
53 * Portability note: The utility depends upon the host for command-line
54 * wildcard support - it is not implemented locally. For example:
56 * Linux/Unix systems: Shell expands wildcards automatically.
58 * Windows: The setargv.obj module must be linked in to automatically
62 extern BOOLEAN AcpiGbl_DebugTimeout
;
64 /* Local prototypes */
76 #define AE_BUFFER_SIZE 1024
77 #define ASL_MAX_FILES 256
81 #define AE_MODE_COMMAND_LOOP 0 /* Normal command execution loop */
82 #define AE_MODE_BATCH_MULTIPLE 1 /* -b option to execute a command line */
83 #define AE_MODE_BATCH_SINGLE 2 /* -m option to execute a single control method */
88 UINT8 AcpiGbl_RegionFillValue
= 0;
89 BOOLEAN AcpiGbl_IgnoreErrors
= FALSE
;
90 BOOLEAN AcpiGbl_DbOpt_NoRegionSupport
= FALSE
;
91 UINT8 AcpiGbl_UseHwReducedFadt
= FALSE
;
92 BOOLEAN AcpiGbl_DoInterfaceTests
= FALSE
;
93 static UINT8 AcpiGbl_ExecutionMode
= AE_MODE_COMMAND_LOOP
;
94 static char BatchBuffer
[AE_BUFFER_SIZE
]; /* Batch command buffer */
95 static AE_TABLE_DESC
*AeTableListHead
= NULL
;
97 #define ACPIEXEC_NAME "AML Execution/Debug Utility"
98 #define AE_SUPPORTED_OPTIONS "?b:d:e:f:ghm^orv^:x:"
101 /******************************************************************************
109 * DESCRIPTION: Print a usage message
111 *****************************************************************************/
118 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
120 ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)");
121 ACPI_OPTION ("-h -?", "Display this help message");
122 ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN");
125 ACPI_OPTION ("-da", "Disable method abort on error");
126 ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init");
127 ACPI_OPTION ("-do", "Disable Operation Region address simulation");
128 ACPI_OPTION ("-dr", "Disable repair of method return values");
129 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)");
132 ACPI_OPTION ("-ef", "Enable display of final memory statistics");
133 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces");
134 ACPI_OPTION ("-em", "Enable Interpreter Serialized Mode");
135 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode");
136 ACPI_OPTION ("-et", "Enable debug semaphore timeout");
139 ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value");
140 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5");
141 ACPI_OPTION ("-v", "Display version information");
142 ACPI_OPTION ("-vi", "Verbose initialization output");
143 ACPI_OPTION ("-vr", "Verbose region handler output");
144 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
148 /******************************************************************************
150 * FUNCTION: AeDoOptions
152 * PARAMETERS: argc/argv - Standard argc/argv
156 * DESCRIPTION: Command line option processing
158 *****************************************************************************/
168 while ((j
= AcpiGetopt (argc
, argv
, AE_SUPPORTED_OPTIONS
)) != EOF
) switch (j
)
172 if (strlen (AcpiGbl_Optarg
) > (AE_BUFFER_SIZE
-1))
174 printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
175 (UINT32
) strlen (AcpiGbl_Optarg
), (AE_BUFFER_SIZE
-1));
178 AcpiGbl_ExecutionMode
= AE_MODE_BATCH_MULTIPLE
;
179 strcpy (BatchBuffer
, AcpiGbl_Optarg
);
184 switch (AcpiGbl_Optarg
[0])
188 AcpiGbl_IgnoreErrors
= TRUE
;
193 AcpiGbl_DbOpt_ini_methods
= FALSE
;
198 AcpiGbl_DbOpt_NoRegionSupport
= TRUE
;
203 AcpiGbl_DisableAutoRepair
= TRUE
;
208 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
209 AcpiGbl_DisableMemTracking
= TRUE
;
215 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg
);
222 switch (AcpiGbl_Optarg
[0])
226 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
227 AcpiGbl_DisplayFinalMemStats
= TRUE
;
233 AcpiGbl_DoInterfaceTests
= TRUE
;
238 AcpiGbl_AllMethodsSerialized
= TRUE
;
239 printf ("Enabling AML Interpreter serialized mode\n");
244 AcpiGbl_EnableInterpreterSlack
= TRUE
;
245 printf ("Enabling AML Interpreter slack mode\n");
250 AcpiGbl_DebugTimeout
= TRUE
;
255 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg
);
262 AcpiGbl_RegionFillValue
= (UINT8
) strtoul (AcpiGbl_Optarg
, NULL
, 0);
267 AcpiGbl_DbOpt_tables
= TRUE
;
268 AcpiGbl_DbFilename
= NULL
;
279 AcpiGbl_ExecutionMode
= AE_MODE_BATCH_SINGLE
;
280 switch (AcpiGbl_Optarg
[0])
284 strcpy (BatchBuffer
, "MAIN");
289 strcpy (BatchBuffer
, AcpiGbl_Optarg
);
296 AcpiGbl_DbOpt_disasm
= TRUE
;
297 AcpiGbl_DbOpt_stats
= TRUE
;
302 AcpiGbl_UseHwReducedFadt
= TRUE
;
303 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
308 switch (AcpiGbl_Optarg
[0])
310 case '^': /* -v: (Version): signon already emitted, just exit */
316 AcpiDbgLevel
|= ACPI_LV_INIT_NAMES
;
321 AcpiGbl_DisplayRegionAccess
= TRUE
;
326 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg
);
333 AcpiDbgLevel
= strtoul (AcpiGbl_Optarg
, NULL
, 0);
334 AcpiGbl_DbConsoleDebugLevel
= AcpiDbgLevel
;
335 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel
);
348 /******************************************************************************
352 * PARAMETERS: argc, argv
356 * DESCRIPTION: Main routine for AcpiExec utility
358 *****************************************************************************/
360 int ACPI_SYSTEM_XFACE
367 ACPI_TABLE_HEADER
*Table
= NULL
;
369 AE_TABLE_DESC
*TableDesc
;
372 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
374 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME
));
381 signal (SIGINT
, AeCtrlCHandler
);
385 AcpiDbgLevel
= ACPI_NORMAL_DEFAULT
;
386 AcpiDbgLayer
= 0xFFFFFFFF;
388 /* Init ACPI and start debugger thread */
390 Status
= AcpiInitializeSubsystem ();
391 AE_CHECK_OK (AcpiInitializeSubsystem
, Status
);
392 if (ACPI_FAILURE (Status
))
397 /* Get the command line options */
399 if (AeDoOptions (argc
, argv
))
404 /* The remaining arguments are filenames for ACPI tables */
406 if (!argv
[AcpiGbl_Optind
])
411 AcpiGbl_DbOpt_tables
= TRUE
;
414 /* Get each of the ACPI table files on the command line */
416 while (argv
[AcpiGbl_Optind
])
418 /* Get one entire table */
420 Status
= AcpiDbReadTableFromFile (argv
[AcpiGbl_Optind
], &Table
);
421 if (ACPI_FAILURE (Status
))
423 printf ("**** Could not get table from file %s, %s\n",
424 argv
[AcpiGbl_Optind
], AcpiFormatException (Status
));
428 /* Ignore non-AML tables, we can't use them. Except for an FADT */
430 if (!ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_FADT
) &&
431 !AcpiUtIsAmlTable (Table
))
434 "Table [%4.4s] is not an AML table, ignoring",
440 /* Allocate and link a table descriptor */
442 TableDesc
= AcpiOsAllocate (sizeof (AE_TABLE_DESC
));
443 TableDesc
->Table
= Table
;
444 TableDesc
->Next
= AeTableListHead
;
445 AeTableListHead
= TableDesc
;
453 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
455 Status
= AeBuildLocalTables (TableCount
, AeTableListHead
);
456 if (ACPI_FAILURE (Status
))
461 Status
= AeInstallTables ();
462 if (ACPI_FAILURE (Status
))
464 printf ("**** Could not load ACPI tables, %s\n",
465 AcpiFormatException (Status
));
470 * Install most of the handlers.
471 * Override some default region handlers, especially SystemMemory
473 Status
= AeInstallEarlyHandlers ();
474 if (ACPI_FAILURE (Status
))
479 /* Setup initialization flags for ACPICA */
481 InitFlags
= (ACPI_NO_HANDLER_INIT
| ACPI_NO_ACPI_ENABLE
);
482 if (!AcpiGbl_DbOpt_ini_methods
)
484 InitFlags
|= (ACPI_NO_DEVICE_INIT
| ACPI_NO_OBJECT_INIT
);
488 * Main initialization for ACPICA subsystem
489 * TBD: Need a way to call this after the ACPI table "LOAD" command
491 Status
= AcpiEnableSubsystem (InitFlags
);
492 if (ACPI_FAILURE (Status
))
494 printf ("**** Could not EnableSubsystem, %s\n",
495 AcpiFormatException (Status
));
500 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
501 * and fixed event handlers
503 AeInstallLateHandlers ();
505 /* Finish the ACPICA initialization */
507 Status
= AcpiInitializeObjects (InitFlags
);
508 if (ACPI_FAILURE (Status
))
510 printf ("**** Could not InitializeObjects, %s\n",
511 AcpiFormatException (Status
));
515 AeMiscellaneousTests ();
520 /* Exit if error above and we are in one of the batch modes */
522 if (ACPI_FAILURE (Status
) && (AcpiGbl_ExecutionMode
> 0))
527 /* Run a batch command or enter the command loop */
529 switch (AcpiGbl_ExecutionMode
)
532 case AE_MODE_COMMAND_LOOP
:
534 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT
, NULL
);
537 case AE_MODE_BATCH_MULTIPLE
:
539 AcpiDbRunBatchMode ();
542 case AE_MODE_BATCH_SINGLE
:
544 AcpiDbExecute (BatchBuffer
, NULL
, NULL
, EX_NO_SINGLE_STEP
);
545 Status
= AcpiTerminate ();
554 (void) AcpiOsTerminate ();
559 /******************************************************************************
561 * FUNCTION: AcpiDbRunBatchMode
563 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
565 * Use only commas to separate elements of
566 * particular command.
569 * DESCRIPTION: For each command of list separated by ';' prepare the command
570 * buffer and pass it to AcpiDbCommandDispatch.
572 *****************************************************************************/
579 char *Ptr
= BatchBuffer
;
584 AcpiGbl_MethodExecuting
= FALSE
;
585 AcpiGbl_StepToNextCall
= FALSE
;
591 /* Convert commas to spaces */
594 else if (*Ptr
== ';')
602 if (Run
|| (*Ptr
== '\0'))
604 (void) AcpiDbCommandDispatch (Cmd
, NULL
, NULL
);
610 Status
= AcpiTerminate ();