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