1 /****************************************************************************** 2 * 3 * Module Name: aemain - Main routine for the AcpiExec utility 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 #include "aecommon.h" 45 46 #define _COMPONENT ACPI_TOOLS 47 ACPI_MODULE_NAME ("aemain") 48 49 50 /* 51 * Main routine for the ACPI user-space execution utility. 52 * 53 * Portability note: The utility depends upon the host for command-line 54 * wildcard support - it is not implemented locally. For example: 55 * 56 * Linux/Unix systems: Shell expands wildcards automatically. 57 * 58 * Windows: The setargv.obj module must be linked in to automatically 59 * expand wildcards. 60 */ 61 extern BOOLEAN AcpiGbl_DebugTimeout; 62 63 /* Local prototypes */ 64 65 static int 66 AeDoOptions ( 67 int argc, 68 char **argv); 69 70 static ACPI_STATUS 71 AcpiDbRunBatchMode ( 72 void); 73 74 75 #define AE_BUFFER_SIZE 1024 76 #define ASL_MAX_FILES 256 77 78 /* Execution modes */ 79 80 #define AE_MODE_COMMAND_LOOP 0 /* Normal command execution loop */ 81 #define AE_MODE_BATCH_MULTIPLE 1 /* -b option to execute a command line */ 82 #define AE_MODE_BATCH_SINGLE 2 /* -m option to execute a single control method */ 83 84 85 /* Globals */ 86 87 UINT8 AcpiGbl_RegionFillValue = 0; 88 BOOLEAN AcpiGbl_IgnoreErrors = FALSE; 89 BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE; 90 UINT8 AcpiGbl_UseHwReducedFadt = FALSE; 91 BOOLEAN AcpiGbl_DoInterfaceTests = FALSE; 92 BOOLEAN AcpiGbl_LoadTestTables = 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; 96 97 #define ACPIEXEC_NAME "AML Execution/Debug Utility" 98 #define AE_SUPPORTED_OPTIONS "?b:d:e:f:ghm^orv^:x:" 99 100 101 /****************************************************************************** 102 * 103 * FUNCTION: usage 104 * 105 * PARAMETERS: None 106 * 107 * RETURN: None 108 * 109 * DESCRIPTION: Print a usage message 110 * 111 *****************************************************************************/ 112 113 static void 114 usage ( 115 void) 116 { 117 118 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ..."); 119 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"); 123 printf ("\n"); 124 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 ("-ds", "Disable method auto-serialization"); 130 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)"); 131 printf ("\n"); 132 133 ACPI_OPTION ("-ef", "Enable display of final memory statistics"); 134 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces"); 135 ACPI_OPTION ("-el", "Enable loading of additional test tables"); 136 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode"); 137 ACPI_OPTION ("-et", "Enable debug semaphore timeout"); 138 printf ("\n"); 139 140 ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value"); 141 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5"); 142 ACPI_OPTION ("-v", "Display version information"); 143 ACPI_OPTION ("-vi", "Verbose initialization output"); 144 ACPI_OPTION ("-vr", "Verbose region handler output"); 145 ACPI_OPTION ("-x <DebugLevel>", "Debug output level"); 146 } 147 148 149 /****************************************************************************** 150 * 151 * FUNCTION: AeDoOptions 152 * 153 * PARAMETERS: argc/argv - Standard argc/argv 154 * 155 * RETURN: Status 156 * 157 * DESCRIPTION: Command line option processing 158 * 159 *****************************************************************************/ 160 161 static int 162 AeDoOptions ( 163 int argc, 164 char **argv) 165 { 166 int j; 167 168 169 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) 170 { 171 case 'b': 172 173 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1)) 174 { 175 printf ("**** The length of command line (%u) exceeded maximum (%u)\n", 176 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1)); 177 return (-1); 178 } 179 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE; 180 strcpy (BatchBuffer, AcpiGbl_Optarg); 181 break; 182 183 case 'd': 184 185 switch (AcpiGbl_Optarg[0]) 186 { 187 case 'a': 188 189 AcpiGbl_IgnoreErrors = TRUE; 190 break; 191 192 case 'i': 193 194 AcpiGbl_DbOpt_ini_methods = FALSE; 195 break; 196 197 case 'o': 198 199 AcpiGbl_DbOpt_NoRegionSupport = TRUE; 200 break; 201 202 case 'r': 203 204 AcpiGbl_DisableAutoRepair = TRUE; 205 break; 206 207 case 's': 208 209 AcpiGbl_AutoSerializeMethods = FALSE; 210 break; 211 212 case 't': 213 214 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 215 AcpiGbl_DisableMemTracking = TRUE; 216 #endif 217 break; 218 219 default: 220 221 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 222 return (-1); 223 } 224 break; 225 226 case 'e': 227 228 switch (AcpiGbl_Optarg[0]) 229 { 230 case 'f': 231 232 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 233 AcpiGbl_DisplayFinalMemStats = TRUE; 234 #endif 235 break; 236 237 case 'i': 238 239 AcpiGbl_DoInterfaceTests = TRUE; 240 break; 241 242 case 'l': 243 244 AcpiGbl_LoadTestTables = TRUE; 245 break; 246 247 case 's': 248 249 AcpiGbl_EnableInterpreterSlack = TRUE; 250 printf ("Enabling AML Interpreter slack mode\n"); 251 break; 252 253 case 't': 254 255 AcpiGbl_DebugTimeout = TRUE; 256 break; 257 258 default: 259 260 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg); 261 return (-1); 262 } 263 break; 264 265 case 'f': 266 267 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 268 break; 269 270 case 'g': 271 272 AcpiGbl_DbOpt_tables = TRUE; 273 AcpiGbl_DbFilename = NULL; 274 break; 275 276 case 'h': 277 case '?': 278 279 usage(); 280 return (0); 281 282 case 'm': 283 284 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE; 285 switch (AcpiGbl_Optarg[0]) 286 { 287 case '^': 288 289 strcpy (BatchBuffer, "MAIN"); 290 break; 291 292 default: 293 294 strcpy (BatchBuffer, AcpiGbl_Optarg); 295 break; 296 } 297 break; 298 299 case 'o': 300 301 AcpiGbl_DbOpt_disasm = TRUE; 302 AcpiGbl_DbOpt_stats = TRUE; 303 break; 304 305 case 'r': 306 307 AcpiGbl_UseHwReducedFadt = TRUE; 308 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n"); 309 break; 310 311 case 'v': 312 313 switch (AcpiGbl_Optarg[0]) 314 { 315 case '^': /* -v: (Version): signon already emitted, just exit */ 316 317 exit (0); 318 319 case 'i': 320 321 AcpiDbgLevel |= ACPI_LV_INIT_NAMES; 322 break; 323 324 case 'r': 325 326 AcpiGbl_DisplayRegionAccess = TRUE; 327 break; 328 329 default: 330 331 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 332 return (-1); 333 } 334 break; 335 336 case 'x': 337 338 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0); 339 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel; 340 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel); 341 break; 342 343 default: 344 345 usage(); 346 return (-1); 347 } 348 349 return (0); 350 } 351 352 353 /****************************************************************************** 354 * 355 * FUNCTION: main 356 * 357 * PARAMETERS: argc, argv 358 * 359 * RETURN: Status 360 * 361 * DESCRIPTION: Main routine for AcpiExec utility 362 * 363 *****************************************************************************/ 364 365 int ACPI_SYSTEM_XFACE 366 main ( 367 int argc, 368 char **argv) 369 { 370 ACPI_STATUS Status; 371 UINT32 InitFlags; 372 ACPI_TABLE_HEADER *Table = NULL; 373 UINT32 TableCount; 374 AE_TABLE_DESC *TableDesc; 375 376 377 ACPI_DEBUG_INITIALIZE (); /* For debug version only */ 378 signal (SIGINT, AeCtrlCHandler); 379 380 /* Init debug globals */ 381 382 AcpiDbgLevel = ACPI_NORMAL_DEFAULT; 383 AcpiDbgLayer = 0xFFFFFFFF; 384 385 /* Init ACPICA and start debugger thread */ 386 387 Status = AcpiInitializeSubsystem (); 388 AE_CHECK_OK (AcpiInitializeSubsystem, Status); 389 if (ACPI_FAILURE (Status)) 390 { 391 goto ErrorExit; 392 } 393 394 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME)); 395 if (argc < 2) 396 { 397 usage (); 398 return (0); 399 } 400 401 /* Get the command line options */ 402 403 if (AeDoOptions (argc, argv)) 404 { 405 goto ErrorExit; 406 } 407 408 /* The remaining arguments are filenames for ACPI tables */ 409 410 if (!argv[AcpiGbl_Optind]) 411 { 412 goto EnterDebugger; 413 } 414 415 AcpiGbl_DbOpt_tables = TRUE; 416 TableCount = 0; 417 418 /* Get each of the ACPI table files on the command line */ 419 420 while (argv[AcpiGbl_Optind]) 421 { 422 /* Get one entire table */ 423 424 Status = AcpiUtReadTableFromFile (argv[AcpiGbl_Optind], &Table); 425 if (ACPI_FAILURE (Status)) 426 { 427 printf ("**** Could not get table from file %s, %s\n", 428 argv[AcpiGbl_Optind], AcpiFormatException (Status)); 429 goto ErrorExit; 430 } 431 432 /* Ignore non-AML tables, we can't use them. Except for an FADT */ 433 434 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) && 435 !AcpiUtIsAmlTable (Table)) 436 { 437 ACPI_INFO ((AE_INFO, 438 "Table [%4.4s] is not an AML table, ignoring", 439 Table->Signature)); 440 AcpiOsFree (Table); 441 } 442 else 443 { 444 /* Allocate and link a table descriptor */ 445 446 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); 447 TableDesc->Table = Table; 448 TableDesc->Next = AeTableListHead; 449 AeTableListHead = TableDesc; 450 451 TableCount++; 452 } 453 454 AcpiGbl_Optind++; 455 } 456 457 printf ("\n"); 458 459 /* Build a local RSDT with all tables and let ACPICA process the RSDT */ 460 461 Status = AeBuildLocalTables (TableCount, AeTableListHead); 462 if (ACPI_FAILURE (Status)) 463 { 464 goto ErrorExit; 465 } 466 467 Status = AeInstallTables (); 468 if (ACPI_FAILURE (Status)) 469 { 470 printf ("**** Could not load ACPI tables, %s\n", 471 AcpiFormatException (Status)); 472 goto EnterDebugger; 473 } 474 475 /* 476 * Install most of the handlers. 477 * Override some default region handlers, especially SystemMemory 478 */ 479 Status = AeInstallEarlyHandlers (); 480 if (ACPI_FAILURE (Status)) 481 { 482 goto EnterDebugger; 483 } 484 485 /* Setup initialization flags for ACPICA */ 486 487 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE); 488 if (!AcpiGbl_DbOpt_ini_methods) 489 { 490 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); 491 } 492 493 /* 494 * Main initialization for ACPICA subsystem 495 * TBD: Need a way to call this after the ACPI table "LOAD" command 496 */ 497 Status = AcpiEnableSubsystem (InitFlags); 498 if (ACPI_FAILURE (Status)) 499 { 500 printf ("**** Could not EnableSubsystem, %s\n", 501 AcpiFormatException (Status)); 502 goto EnterDebugger; 503 } 504 505 /* 506 * Install handlers for "device driver" space IDs (EC,SMBus, etc.) 507 * and fixed event handlers 508 */ 509 AeInstallLateHandlers (); 510 511 /* Finish the ACPICA initialization */ 512 513 Status = AcpiInitializeObjects (InitFlags); 514 if (ACPI_FAILURE (Status)) 515 { 516 printf ("**** Could not InitializeObjects, %s\n", 517 AcpiFormatException (Status)); 518 goto EnterDebugger; 519 } 520 521 AeMiscellaneousTests (); 522 523 524 EnterDebugger: 525 526 /* Exit if error above and we are in one of the batch modes */ 527 528 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0)) 529 { 530 goto ErrorExit; 531 } 532 533 /* Run a batch command or enter the command loop */ 534 535 switch (AcpiGbl_ExecutionMode) 536 { 537 default: 538 case AE_MODE_COMMAND_LOOP: 539 540 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL); 541 break; 542 543 case AE_MODE_BATCH_MULTIPLE: 544 545 AcpiDbRunBatchMode (); 546 break; 547 548 case AE_MODE_BATCH_SINGLE: 549 550 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); 551 Status = AcpiTerminate (); 552 break; 553 } 554 555 return (0); 556 557 558 ErrorExit: 559 560 (void) AcpiOsTerminate (); 561 return (-1); 562 } 563 564 565 /****************************************************************************** 566 * 567 * FUNCTION: AcpiDbRunBatchMode 568 * 569 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands 570 * to be executed. 571 * Use only commas to separate elements of 572 * particular command. 573 * RETURN: Status 574 * 575 * DESCRIPTION: For each command of list separated by ';' prepare the command 576 * buffer and pass it to AcpiDbCommandDispatch. 577 * 578 *****************************************************************************/ 579 580 static ACPI_STATUS 581 AcpiDbRunBatchMode ( 582 void) 583 { 584 ACPI_STATUS Status; 585 char *Ptr = BatchBuffer; 586 char *Cmd = Ptr; 587 UINT8 Run = 0; 588 589 590 AcpiGbl_MethodExecuting = FALSE; 591 AcpiGbl_StepToNextCall = FALSE; 592 593 while (*Ptr) 594 { 595 if (*Ptr == ',') 596 { 597 /* Convert commas to spaces */ 598 *Ptr = ' '; 599 } 600 else if (*Ptr == ';') 601 { 602 *Ptr = '\0'; 603 Run = 1; 604 } 605 606 Ptr++; 607 608 if (Run || (*Ptr == '\0')) 609 { 610 (void) AcpiDbCommandDispatch (Cmd, NULL, NULL); 611 Run = 0; 612 Cmd = Ptr; 613 } 614 } 615 616 Status = AcpiTerminate (); 617 return (Status); 618 } 619