1 /******************************************************************************* 2 * 3 * Module Name: dbexec - debugger control method execution 4 * 5 ******************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include "acpi.h" 153 #include "accommon.h" 154 #include "acdebug.h" 155 #include "acnamesp.h" 156 157 #ifdef ACPI_DEBUGGER 158 159 #define _COMPONENT ACPI_CA_DEBUGGER 160 ACPI_MODULE_NAME ("dbexec") 161 162 163 static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo; 164 165 /* Local prototypes */ 166 167 static ACPI_STATUS 168 AcpiDbExecuteMethod ( 169 ACPI_DB_METHOD_INFO *Info, 170 ACPI_BUFFER *ReturnObj); 171 172 static ACPI_STATUS 173 AcpiDbExecuteSetup ( 174 ACPI_DB_METHOD_INFO *Info); 175 176 static UINT32 177 AcpiDbGetOutstandingAllocations ( 178 void); 179 180 static void ACPI_SYSTEM_XFACE 181 AcpiDbMethodThread ( 182 void *Context); 183 184 static ACPI_STATUS 185 AcpiDbExecutionWalk ( 186 ACPI_HANDLE ObjHandle, 187 UINT32 NestingLevel, 188 void *Context, 189 void **ReturnValue); 190 191 192 /******************************************************************************* 193 * 194 * FUNCTION: AcpiDbDeleteObjects 195 * 196 * PARAMETERS: Count - Count of objects in the list 197 * Objects - Array of ACPI_OBJECTs to be deleted 198 * 199 * RETURN: None 200 * 201 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested 202 * packages via recursion. 203 * 204 ******************************************************************************/ 205 206 void 207 AcpiDbDeleteObjects ( 208 UINT32 Count, 209 ACPI_OBJECT *Objects) 210 { 211 UINT32 i; 212 213 214 for (i = 0; i < Count; i++) 215 { 216 switch (Objects[i].Type) 217 { 218 case ACPI_TYPE_BUFFER: 219 220 ACPI_FREE (Objects[i].Buffer.Pointer); 221 break; 222 223 case ACPI_TYPE_PACKAGE: 224 225 /* Recursive call to delete package elements */ 226 227 AcpiDbDeleteObjects (Objects[i].Package.Count, 228 Objects[i].Package.Elements); 229 230 /* Free the elements array */ 231 232 ACPI_FREE (Objects[i].Package.Elements); 233 break; 234 235 default: 236 237 break; 238 } 239 } 240 } 241 242 243 /******************************************************************************* 244 * 245 * FUNCTION: AcpiDbExecuteMethod 246 * 247 * PARAMETERS: Info - Valid info segment 248 * ReturnObj - Where to put return object 249 * 250 * RETURN: Status 251 * 252 * DESCRIPTION: Execute a control method. 253 * 254 ******************************************************************************/ 255 256 static ACPI_STATUS 257 AcpiDbExecuteMethod ( 258 ACPI_DB_METHOD_INFO *Info, 259 ACPI_BUFFER *ReturnObj) 260 { 261 ACPI_STATUS Status; 262 ACPI_OBJECT_LIST ParamObjects; 263 ACPI_OBJECT Params[ACPI_DEBUGGER_MAX_ARGS + 1]; 264 UINT32 i; 265 266 267 ACPI_FUNCTION_TRACE (DbExecuteMethod); 268 269 270 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel) 271 { 272 AcpiOsPrintf ("Warning: debug output is not enabled!\n"); 273 } 274 275 ParamObjects.Count = 0; 276 ParamObjects.Pointer = NULL; 277 278 /* Pass through any command-line arguments */ 279 280 if (Info->Args && Info->Args[0]) 281 { 282 /* Get arguments passed on the command line */ 283 284 for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++) 285 { 286 /* Convert input string (token) to an actual ACPI_OBJECT */ 287 288 Status = AcpiDbConvertToObject (Info->Types[i], 289 Info->Args[i], &Params[i]); 290 if (ACPI_FAILURE (Status)) 291 { 292 ACPI_EXCEPTION ((AE_INFO, Status, 293 "While parsing method arguments")); 294 goto Cleanup; 295 } 296 } 297 298 ParamObjects.Count = i; 299 ParamObjects.Pointer = Params; 300 } 301 302 /* Prepare for a return object of arbitrary size */ 303 304 ReturnObj->Pointer = AcpiGbl_DbBuffer; 305 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE; 306 307 /* Do the actual method execution */ 308 309 AcpiGbl_MethodExecuting = TRUE; 310 Status = AcpiEvaluateObject (NULL, Info->Pathname, 311 &ParamObjects, ReturnObj); 312 313 AcpiGbl_CmSingleStep = FALSE; 314 AcpiGbl_MethodExecuting = FALSE; 315 316 if (ACPI_FAILURE (Status)) 317 { 318 if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod) 319 { 320 /* Clear the abort and fall back to the debugger prompt */ 321 322 ACPI_EXCEPTION ((AE_INFO, Status, 323 "Aborting top-level method")); 324 325 AcpiGbl_AbortMethod = FALSE; 326 Status = AE_OK; 327 goto Cleanup; 328 } 329 330 ACPI_EXCEPTION ((AE_INFO, Status, 331 "while executing %s from debugger", Info->Pathname)); 332 333 if (Status == AE_BUFFER_OVERFLOW) 334 { 335 ACPI_ERROR ((AE_INFO, 336 "Possible overflow of internal debugger " 337 "buffer (size 0x%X needed 0x%X)", 338 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length)); 339 } 340 } 341 342 Cleanup: 343 AcpiDbDeleteObjects (ParamObjects.Count, Params); 344 return_ACPI_STATUS (Status); 345 } 346 347 348 /******************************************************************************* 349 * 350 * FUNCTION: AcpiDbExecuteSetup 351 * 352 * PARAMETERS: Info - Valid method info 353 * 354 * RETURN: None 355 * 356 * DESCRIPTION: Setup info segment prior to method execution 357 * 358 ******************************************************************************/ 359 360 static ACPI_STATUS 361 AcpiDbExecuteSetup ( 362 ACPI_DB_METHOD_INFO *Info) 363 { 364 ACPI_STATUS Status; 365 366 367 ACPI_FUNCTION_NAME (DbExecuteSetup); 368 369 370 /* Catenate the current scope to the supplied name */ 371 372 Info->Pathname[0] = 0; 373 if ((Info->Name[0] != '\\') && 374 (Info->Name[0] != '/')) 375 { 376 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname), 377 AcpiGbl_DbScopeBuf)) 378 { 379 Status = AE_BUFFER_OVERFLOW; 380 goto ErrorExit; 381 } 382 } 383 384 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname), 385 Info->Name)) 386 { 387 Status = AE_BUFFER_OVERFLOW; 388 goto ErrorExit; 389 } 390 391 AcpiDbPrepNamestring (Info->Pathname); 392 393 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 394 AcpiOsPrintf ("Evaluating %s\n", Info->Pathname); 395 396 if (Info->Flags & EX_SINGLE_STEP) 397 { 398 AcpiGbl_CmSingleStep = TRUE; 399 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 400 } 401 402 else 403 { 404 /* No single step, allow redirection to a file */ 405 406 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 407 } 408 409 return (AE_OK); 410 411 ErrorExit: 412 413 ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution")); 414 return (Status); 415 } 416 417 418 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 419 UINT32 420 AcpiDbGetCacheInfo ( 421 ACPI_MEMORY_LIST *Cache) 422 { 423 424 return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth); 425 } 426 #endif 427 428 /******************************************************************************* 429 * 430 * FUNCTION: AcpiDbGetOutstandingAllocations 431 * 432 * PARAMETERS: None 433 * 434 * RETURN: Current global allocation count minus cache entries 435 * 436 * DESCRIPTION: Determine the current number of "outstanding" allocations -- 437 * those allocations that have not been freed and also are not 438 * in one of the various object caches. 439 * 440 ******************************************************************************/ 441 442 static UINT32 443 AcpiDbGetOutstandingAllocations ( 444 void) 445 { 446 UINT32 Outstanding = 0; 447 448 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 449 450 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache); 451 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache); 452 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache); 453 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache); 454 #endif 455 456 return (Outstanding); 457 } 458 459 460 /******************************************************************************* 461 * 462 * FUNCTION: AcpiDbExecutionWalk 463 * 464 * PARAMETERS: WALK_CALLBACK 465 * 466 * RETURN: Status 467 * 468 * DESCRIPTION: Execute a control method. Name is relative to the current 469 * scope. 470 * 471 ******************************************************************************/ 472 473 static ACPI_STATUS 474 AcpiDbExecutionWalk ( 475 ACPI_HANDLE ObjHandle, 476 UINT32 NestingLevel, 477 void *Context, 478 void **ReturnValue) 479 { 480 ACPI_OPERAND_OBJECT *ObjDesc; 481 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 482 ACPI_BUFFER ReturnObj; 483 ACPI_STATUS Status; 484 485 486 ObjDesc = AcpiNsGetAttachedObject (Node); 487 if (ObjDesc->Method.ParamCount) 488 { 489 return (AE_OK); 490 } 491 492 ReturnObj.Pointer = NULL; 493 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 494 495 AcpiNsPrintNodePathname (Node, "Evaluating"); 496 497 /* Do the actual method execution */ 498 499 AcpiOsPrintf ("\n"); 500 AcpiGbl_MethodExecuting = TRUE; 501 502 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj); 503 504 AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n", 505 AcpiUtGetNodeName (Node), 506 AcpiFormatException (Status)); 507 508 AcpiGbl_MethodExecuting = FALSE; 509 return (AE_OK); 510 } 511 512 513 /******************************************************************************* 514 * 515 * FUNCTION: AcpiDbExecute 516 * 517 * PARAMETERS: Name - Name of method to execute 518 * Args - Parameters to the method 519 * Types - 520 * Flags - single step/no single step 521 * 522 * RETURN: None 523 * 524 * DESCRIPTION: Execute a control method. Name is relative to the current 525 * scope. 526 * 527 ******************************************************************************/ 528 529 void 530 AcpiDbExecute ( 531 char *Name, 532 char **Args, 533 ACPI_OBJECT_TYPE *Types, 534 UINT32 Flags) 535 { 536 ACPI_STATUS Status; 537 ACPI_BUFFER ReturnObj; 538 char *NameString; 539 540 #ifdef ACPI_DEBUG_OUTPUT 541 UINT32 PreviousAllocations; 542 UINT32 Allocations; 543 #endif 544 545 546 /* 547 * Allow one execution to be performed by debugger or single step 548 * execution will be dead locked by the interpreter mutexes. 549 */ 550 if (AcpiGbl_MethodExecuting) 551 { 552 AcpiOsPrintf ("Only one debugger execution is allowed.\n"); 553 return; 554 } 555 556 #ifdef ACPI_DEBUG_OUTPUT 557 /* Memory allocation tracking */ 558 559 PreviousAllocations = AcpiDbGetOutstandingAllocations (); 560 #endif 561 562 if (*Name == '*') 563 { 564 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, 565 ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL); 566 return; 567 } 568 569 NameString = ACPI_ALLOCATE (strlen (Name) + 1); 570 if (!NameString) 571 { 572 return; 573 } 574 575 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO)); 576 strcpy (NameString, Name); 577 AcpiUtStrupr (NameString); 578 579 /* Subcommand to Execute all predefined names in the namespace */ 580 581 if (!strncmp (NameString, "PREDEF", 6)) 582 { 583 AcpiDbEvaluatePredefinedNames (); 584 ACPI_FREE (NameString); 585 return; 586 } 587 588 AcpiGbl_DbMethodInfo.Name = NameString; 589 AcpiGbl_DbMethodInfo.Args = Args; 590 AcpiGbl_DbMethodInfo.Types = Types; 591 AcpiGbl_DbMethodInfo.Flags = Flags; 592 593 ReturnObj.Pointer = NULL; 594 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 595 596 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 597 if (ACPI_FAILURE (Status)) 598 { 599 ACPI_FREE (NameString); 600 return; 601 } 602 603 /* Get the NS node, determines existence also */ 604 605 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname, 606 &AcpiGbl_DbMethodInfo.Method); 607 if (ACPI_SUCCESS (Status)) 608 { 609 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, 610 &ReturnObj); 611 } 612 ACPI_FREE (NameString); 613 614 /* 615 * Allow any handlers in separate threads to complete. 616 * (Such as Notify handlers invoked from AML executed above). 617 */ 618 AcpiOsSleep ((UINT64) 10); 619 620 #ifdef ACPI_DEBUG_OUTPUT 621 622 /* Memory allocation tracking */ 623 624 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; 625 626 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 627 628 if (Allocations > 0) 629 { 630 AcpiOsPrintf ( 631 "0x%X Outstanding allocations after evaluation of %s\n", 632 Allocations, AcpiGbl_DbMethodInfo.Pathname); 633 } 634 #endif 635 636 if (ACPI_FAILURE (Status)) 637 { 638 AcpiOsPrintf ("Evaluation of %s failed with status %s\n", 639 AcpiGbl_DbMethodInfo.Pathname, 640 AcpiFormatException (Status)); 641 } 642 else 643 { 644 /* Display a return object, if any */ 645 646 if (ReturnObj.Length) 647 { 648 AcpiOsPrintf ( 649 "Evaluation of %s returned object %p, " 650 "external buffer length %X\n", 651 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, 652 (UINT32) ReturnObj.Length); 653 654 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); 655 656 /* Dump a _PLD buffer if present */ 657 658 if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 659 AcpiGbl_DbMethodInfo.Method)->Name.Ascii), 660 METHOD_NAME__PLD)) 661 { 662 AcpiDbDumpPldBuffer (ReturnObj.Pointer); 663 } 664 } 665 else 666 { 667 AcpiOsPrintf ("No object was returned from evaluation of %s\n", 668 AcpiGbl_DbMethodInfo.Pathname); 669 } 670 } 671 672 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 673 } 674 675 676 /******************************************************************************* 677 * 678 * FUNCTION: AcpiDbMethodThread 679 * 680 * PARAMETERS: Context - Execution info segment 681 * 682 * RETURN: None 683 * 684 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 685 * simply dispatches it. 686 * 687 ******************************************************************************/ 688 689 static void ACPI_SYSTEM_XFACE 690 AcpiDbMethodThread ( 691 void *Context) 692 { 693 ACPI_STATUS Status; 694 ACPI_DB_METHOD_INFO *Info = Context; 695 ACPI_DB_METHOD_INFO LocalInfo; 696 UINT32 i; 697 UINT8 Allow; 698 ACPI_BUFFER ReturnObj; 699 700 701 /* 702 * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments. 703 * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads 704 * concurrently. 705 * 706 * Note: The arguments we are passing are used by the ASL test suite 707 * (aslts). Do not change them without updating the tests. 708 */ 709 (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER); 710 711 if (Info->InitArgs) 712 { 713 AcpiDbUint32ToHexString (Info->NumCreated, 714 Info->IndexOfThreadStr); 715 AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (), 716 Info->IdOfThreadStr); 717 } 718 719 if (Info->Threads && (Info->NumCreated < Info->NumThreads)) 720 { 721 Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId(); 722 } 723 724 LocalInfo = *Info; 725 LocalInfo.Args = LocalInfo.Arguments; 726 LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr; 727 LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr; 728 LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr; 729 LocalInfo.Arguments[3] = NULL; 730 731 LocalInfo.Types = LocalInfo.ArgTypes; 732 733 (void) AcpiOsSignalSemaphore (Info->InfoGate, 1); 734 735 for (i = 0; i < Info->NumLoops; i++) 736 { 737 Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj); 738 if (ACPI_FAILURE (Status)) 739 { 740 AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n", 741 AcpiFormatException (Status), Info->Pathname, i); 742 if (Status == AE_ABORT_METHOD) 743 { 744 break; 745 } 746 } 747 748 #if 0 749 if ((i % 100) == 0) 750 { 751 AcpiOsPrintf ("%u loops, Thread 0x%x\n", 752 i, AcpiOsGetThreadId ()); 753 } 754 755 if (ReturnObj.Length) 756 { 757 AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n", 758 Info->Pathname, ReturnObj.Pointer, 759 (UINT32) ReturnObj.Length); 760 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); 761 } 762 #endif 763 } 764 765 /* Signal our completion */ 766 767 Allow = 0; 768 (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 769 1, ACPI_WAIT_FOREVER); 770 Info->NumCompleted++; 771 772 if (Info->NumCompleted == Info->NumThreads) 773 { 774 /* Do signal for main thread once only */ 775 Allow = 1; 776 } 777 778 (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1); 779 780 if (Allow) 781 { 782 Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1); 783 if (ACPI_FAILURE (Status)) 784 { 785 AcpiOsPrintf ( 786 "Could not signal debugger thread sync semaphore, %s\n", 787 AcpiFormatException (Status)); 788 } 789 } 790 } 791 792 793 /******************************************************************************* 794 * 795 * FUNCTION: AcpiDbCreateExecutionThreads 796 * 797 * PARAMETERS: NumThreadsArg - Number of threads to create 798 * NumLoopsArg - Loop count for the thread(s) 799 * MethodNameArg - Control method to execute 800 * 801 * RETURN: None 802 * 803 * DESCRIPTION: Create threads to execute method(s) 804 * 805 ******************************************************************************/ 806 807 void 808 AcpiDbCreateExecutionThreads ( 809 char *NumThreadsArg, 810 char *NumLoopsArg, 811 char *MethodNameArg) 812 { 813 ACPI_STATUS Status; 814 UINT32 NumThreads; 815 UINT32 NumLoops; 816 UINT32 i; 817 UINT32 Size; 818 ACPI_MUTEX MainThreadGate; 819 ACPI_MUTEX ThreadCompleteGate; 820 ACPI_MUTEX InfoGate; 821 822 823 /* Get the arguments */ 824 825 NumThreads = strtoul (NumThreadsArg, NULL, 0); 826 NumLoops = strtoul (NumLoopsArg, NULL, 0); 827 828 if (!NumThreads || !NumLoops) 829 { 830 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n", 831 NumThreads, NumLoops); 832 return; 833 } 834 835 /* 836 * Create the semaphore for synchronization of 837 * the created threads with the main thread. 838 */ 839 Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate); 840 if (ACPI_FAILURE (Status)) 841 { 842 AcpiOsPrintf ("Could not create semaphore for " 843 "synchronization with the main thread, %s\n", 844 AcpiFormatException (Status)); 845 return; 846 } 847 848 /* 849 * Create the semaphore for synchronization 850 * between the created threads. 851 */ 852 Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate); 853 if (ACPI_FAILURE (Status)) 854 { 855 AcpiOsPrintf ("Could not create semaphore for " 856 "synchronization between the created threads, %s\n", 857 AcpiFormatException (Status)); 858 859 (void) AcpiOsDeleteSemaphore (MainThreadGate); 860 return; 861 } 862 863 Status = AcpiOsCreateSemaphore (1, 1, &InfoGate); 864 if (ACPI_FAILURE (Status)) 865 { 866 AcpiOsPrintf ("Could not create semaphore for " 867 "synchronization of AcpiGbl_DbMethodInfo, %s\n", 868 AcpiFormatException (Status)); 869 870 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 871 (void) AcpiOsDeleteSemaphore (MainThreadGate); 872 return; 873 } 874 875 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO)); 876 877 /* Array to store IDs of threads */ 878 879 AcpiGbl_DbMethodInfo.NumThreads = NumThreads; 880 Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads; 881 882 AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size); 883 if (AcpiGbl_DbMethodInfo.Threads == NULL) 884 { 885 AcpiOsPrintf ("No memory for thread IDs array\n"); 886 (void) AcpiOsDeleteSemaphore (MainThreadGate); 887 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 888 (void) AcpiOsDeleteSemaphore (InfoGate); 889 return; 890 } 891 memset (AcpiGbl_DbMethodInfo.Threads, 0, Size); 892 893 /* Setup the context to be passed to each thread */ 894 895 AcpiGbl_DbMethodInfo.Name = MethodNameArg; 896 AcpiGbl_DbMethodInfo.Flags = 0; 897 AcpiGbl_DbMethodInfo.NumLoops = NumLoops; 898 AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate; 899 AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate; 900 AcpiGbl_DbMethodInfo.InfoGate = InfoGate; 901 902 /* Init arguments to be passed to method */ 903 904 AcpiGbl_DbMethodInfo.InitArgs = 1; 905 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments; 906 AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr; 907 AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr; 908 AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr; 909 AcpiGbl_DbMethodInfo.Arguments[3] = NULL; 910 911 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes; 912 AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER; 913 AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER; 914 AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER; 915 916 AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr); 917 918 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 919 if (ACPI_FAILURE (Status)) 920 { 921 goto CleanupAndExit; 922 } 923 924 /* Get the NS node, determines existence also */ 925 926 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname, 927 &AcpiGbl_DbMethodInfo.Method); 928 if (ACPI_FAILURE (Status)) 929 { 930 AcpiOsPrintf ("%s Could not get handle for %s\n", 931 AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname); 932 goto CleanupAndExit; 933 } 934 935 /* Create the threads */ 936 937 AcpiOsPrintf ("Creating %X threads to execute %X times each\n", 938 NumThreads, NumLoops); 939 940 for (i = 0; i < (NumThreads); i++) 941 { 942 Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread, 943 &AcpiGbl_DbMethodInfo); 944 if (ACPI_FAILURE (Status)) 945 { 946 break; 947 } 948 } 949 950 /* Wait for all threads to complete */ 951 952 (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER); 953 954 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 955 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads); 956 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 957 958 CleanupAndExit: 959 960 /* Cleanup and exit */ 961 962 (void) AcpiOsDeleteSemaphore (MainThreadGate); 963 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 964 (void) AcpiOsDeleteSemaphore (InfoGate); 965 966 AcpiOsFree (AcpiGbl_DbMethodInfo.Threads); 967 AcpiGbl_DbMethodInfo.Threads = NULL; 968 } 969 970 #endif /* ACPI_DEBUGGER */ 971