1 /******************************************************************************* 2 * 3 * Module Name: dbexec - debugger control method execution 4 * 5 ******************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2016, 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 <contrib/dev/acpica/include/acpi.h> 45 #include <contrib/dev/acpica/include/accommon.h> 46 #include <contrib/dev/acpica/include/acdebug.h> 47 #include <contrib/dev/acpica/include/acnamesp.h> 48 49 50 #define _COMPONENT ACPI_CA_DEBUGGER 51 ACPI_MODULE_NAME ("dbexec") 52 53 54 static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo; 55 56 /* Local prototypes */ 57 58 static ACPI_STATUS 59 AcpiDbExecuteMethod ( 60 ACPI_DB_METHOD_INFO *Info, 61 ACPI_BUFFER *ReturnObj); 62 63 static ACPI_STATUS 64 AcpiDbExecuteSetup ( 65 ACPI_DB_METHOD_INFO *Info); 66 67 static UINT32 68 AcpiDbGetOutstandingAllocations ( 69 void); 70 71 static void ACPI_SYSTEM_XFACE 72 AcpiDbMethodThread ( 73 void *Context); 74 75 static ACPI_STATUS 76 AcpiDbExecutionWalk ( 77 ACPI_HANDLE ObjHandle, 78 UINT32 NestingLevel, 79 void *Context, 80 void **ReturnValue); 81 82 83 /******************************************************************************* 84 * 85 * FUNCTION: AcpiDbDeleteObjects 86 * 87 * PARAMETERS: Count - Count of objects in the list 88 * Objects - Array of ACPI_OBJECTs to be deleted 89 * 90 * RETURN: None 91 * 92 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested 93 * packages via recursion. 94 * 95 ******************************************************************************/ 96 97 void 98 AcpiDbDeleteObjects ( 99 UINT32 Count, 100 ACPI_OBJECT *Objects) 101 { 102 UINT32 i; 103 104 105 for (i = 0; i < Count; i++) 106 { 107 switch (Objects[i].Type) 108 { 109 case ACPI_TYPE_BUFFER: 110 111 ACPI_FREE (Objects[i].Buffer.Pointer); 112 break; 113 114 case ACPI_TYPE_PACKAGE: 115 116 /* Recursive call to delete package elements */ 117 118 AcpiDbDeleteObjects (Objects[i].Package.Count, 119 Objects[i].Package.Elements); 120 121 /* Free the elements array */ 122 123 ACPI_FREE (Objects[i].Package.Elements); 124 break; 125 126 default: 127 128 break; 129 } 130 } 131 } 132 133 134 /******************************************************************************* 135 * 136 * FUNCTION: AcpiDbExecuteMethod 137 * 138 * PARAMETERS: Info - Valid info segment 139 * ReturnObj - Where to put return object 140 * 141 * RETURN: Status 142 * 143 * DESCRIPTION: Execute a control method. 144 * 145 ******************************************************************************/ 146 147 static ACPI_STATUS 148 AcpiDbExecuteMethod ( 149 ACPI_DB_METHOD_INFO *Info, 150 ACPI_BUFFER *ReturnObj) 151 { 152 ACPI_STATUS Status; 153 ACPI_OBJECT_LIST ParamObjects; 154 ACPI_OBJECT Params[ACPI_DEBUGGER_MAX_ARGS + 1]; 155 UINT32 i; 156 157 158 ACPI_FUNCTION_TRACE (DbExecuteMethod); 159 160 161 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel) 162 { 163 AcpiOsPrintf ("Warning: debug output is not enabled!\n"); 164 } 165 166 ParamObjects.Count = 0; 167 ParamObjects.Pointer = NULL; 168 169 /* Pass through any command-line arguments */ 170 171 if (Info->Args && Info->Args[0]) 172 { 173 /* Get arguments passed on the command line */ 174 175 for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++) 176 { 177 /* Convert input string (token) to an actual ACPI_OBJECT */ 178 179 Status = AcpiDbConvertToObject (Info->Types[i], 180 Info->Args[i], &Params[i]); 181 if (ACPI_FAILURE (Status)) 182 { 183 ACPI_EXCEPTION ((AE_INFO, Status, 184 "While parsing method arguments")); 185 goto Cleanup; 186 } 187 } 188 189 ParamObjects.Count = i; 190 ParamObjects.Pointer = Params; 191 } 192 193 /* Prepare for a return object of arbitrary size */ 194 195 ReturnObj->Pointer = AcpiGbl_DbBuffer; 196 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE; 197 198 /* Do the actual method execution */ 199 200 AcpiGbl_MethodExecuting = TRUE; 201 Status = AcpiEvaluateObject (NULL, Info->Pathname, 202 &ParamObjects, ReturnObj); 203 204 AcpiGbl_CmSingleStep = FALSE; 205 AcpiGbl_MethodExecuting = FALSE; 206 207 if (ACPI_FAILURE (Status)) 208 { 209 ACPI_EXCEPTION ((AE_INFO, Status, 210 "while executing %s from debugger", Info->Pathname)); 211 212 if (Status == AE_BUFFER_OVERFLOW) 213 { 214 ACPI_ERROR ((AE_INFO, 215 "Possible overflow of internal debugger " 216 "buffer (size 0x%X needed 0x%X)", 217 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length)); 218 } 219 } 220 221 Cleanup: 222 AcpiDbDeleteObjects (ParamObjects.Count, Params); 223 return_ACPI_STATUS (Status); 224 } 225 226 227 /******************************************************************************* 228 * 229 * FUNCTION: AcpiDbExecuteSetup 230 * 231 * PARAMETERS: Info - Valid method info 232 * 233 * RETURN: None 234 * 235 * DESCRIPTION: Setup info segment prior to method execution 236 * 237 ******************************************************************************/ 238 239 static ACPI_STATUS 240 AcpiDbExecuteSetup ( 241 ACPI_DB_METHOD_INFO *Info) 242 { 243 ACPI_STATUS Status; 244 245 246 ACPI_FUNCTION_NAME (DbExecuteSetup); 247 248 249 /* Catenate the current scope to the supplied name */ 250 251 Info->Pathname[0] = 0; 252 if ((Info->Name[0] != '\\') && 253 (Info->Name[0] != '/')) 254 { 255 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname), 256 AcpiGbl_DbScopeBuf)) 257 { 258 Status = AE_BUFFER_OVERFLOW; 259 goto ErrorExit; 260 } 261 } 262 263 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname), 264 Info->Name)) 265 { 266 Status = AE_BUFFER_OVERFLOW; 267 goto ErrorExit; 268 } 269 270 AcpiDbPrepNamestring (Info->Pathname); 271 272 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 273 AcpiOsPrintf ("Evaluating %s\n", Info->Pathname); 274 275 if (Info->Flags & EX_SINGLE_STEP) 276 { 277 AcpiGbl_CmSingleStep = TRUE; 278 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 279 } 280 281 else 282 { 283 /* No single step, allow redirection to a file */ 284 285 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 286 } 287 288 return (AE_OK); 289 290 ErrorExit: 291 292 ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution")); 293 return (Status); 294 } 295 296 297 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 298 UINT32 299 AcpiDbGetCacheInfo ( 300 ACPI_MEMORY_LIST *Cache) 301 { 302 303 return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth); 304 } 305 #endif 306 307 /******************************************************************************* 308 * 309 * FUNCTION: AcpiDbGetOutstandingAllocations 310 * 311 * PARAMETERS: None 312 * 313 * RETURN: Current global allocation count minus cache entries 314 * 315 * DESCRIPTION: Determine the current number of "outstanding" allocations -- 316 * those allocations that have not been freed and also are not 317 * in one of the various object caches. 318 * 319 ******************************************************************************/ 320 321 static UINT32 322 AcpiDbGetOutstandingAllocations ( 323 void) 324 { 325 UINT32 Outstanding = 0; 326 327 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 328 329 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache); 330 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache); 331 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache); 332 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache); 333 #endif 334 335 return (Outstanding); 336 } 337 338 339 /******************************************************************************* 340 * 341 * FUNCTION: AcpiDbExecutionWalk 342 * 343 * PARAMETERS: WALK_CALLBACK 344 * 345 * RETURN: Status 346 * 347 * DESCRIPTION: Execute a control method. Name is relative to the current 348 * scope. 349 * 350 ******************************************************************************/ 351 352 static ACPI_STATUS 353 AcpiDbExecutionWalk ( 354 ACPI_HANDLE ObjHandle, 355 UINT32 NestingLevel, 356 void *Context, 357 void **ReturnValue) 358 { 359 ACPI_OPERAND_OBJECT *ObjDesc; 360 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 361 ACPI_BUFFER ReturnObj; 362 ACPI_STATUS Status; 363 364 365 ObjDesc = AcpiNsGetAttachedObject (Node); 366 if (ObjDesc->Method.ParamCount) 367 { 368 return (AE_OK); 369 } 370 371 ReturnObj.Pointer = NULL; 372 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 373 374 AcpiNsPrintNodePathname (Node, "Evaluating"); 375 376 /* Do the actual method execution */ 377 378 AcpiOsPrintf ("\n"); 379 AcpiGbl_MethodExecuting = TRUE; 380 381 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj); 382 383 AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n", 384 AcpiUtGetNodeName (Node), 385 AcpiFormatException (Status)); 386 387 AcpiGbl_MethodExecuting = FALSE; 388 return (AE_OK); 389 } 390 391 392 /******************************************************************************* 393 * 394 * FUNCTION: AcpiDbExecute 395 * 396 * PARAMETERS: Name - Name of method to execute 397 * Args - Parameters to the method 398 * Types - 399 * Flags - single step/no single step 400 * 401 * RETURN: None 402 * 403 * DESCRIPTION: Execute a control method. Name is relative to the current 404 * scope. 405 * 406 ******************************************************************************/ 407 408 void 409 AcpiDbExecute ( 410 char *Name, 411 char **Args, 412 ACPI_OBJECT_TYPE *Types, 413 UINT32 Flags) 414 { 415 ACPI_STATUS Status; 416 ACPI_BUFFER ReturnObj; 417 char *NameString; 418 419 #ifdef ACPI_DEBUG_OUTPUT 420 UINT32 PreviousAllocations; 421 UINT32 Allocations; 422 #endif 423 424 425 /* 426 * Allow one execution to be performed by debugger or single step 427 * execution will be dead locked by the interpreter mutexes. 428 */ 429 if (AcpiGbl_MethodExecuting) 430 { 431 AcpiOsPrintf ("Only one debugger execution is allowed.\n"); 432 return; 433 } 434 435 #ifdef ACPI_DEBUG_OUTPUT 436 /* Memory allocation tracking */ 437 438 PreviousAllocations = AcpiDbGetOutstandingAllocations (); 439 #endif 440 441 if (*Name == '*') 442 { 443 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, 444 ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL); 445 return; 446 } 447 448 NameString = ACPI_ALLOCATE (strlen (Name) + 1); 449 if (!NameString) 450 { 451 return; 452 } 453 454 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO)); 455 strcpy (NameString, Name); 456 AcpiUtStrupr (NameString); 457 458 /* Subcommand to Execute all predefined names in the namespace */ 459 460 if (!strncmp (NameString, "PREDEF", 6)) 461 { 462 AcpiDbEvaluatePredefinedNames (); 463 ACPI_FREE (NameString); 464 return; 465 } 466 467 AcpiGbl_DbMethodInfo.Name = NameString; 468 AcpiGbl_DbMethodInfo.Args = Args; 469 AcpiGbl_DbMethodInfo.Types = Types; 470 AcpiGbl_DbMethodInfo.Flags = Flags; 471 472 ReturnObj.Pointer = NULL; 473 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 474 475 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 476 if (ACPI_FAILURE (Status)) 477 { 478 ACPI_FREE (NameString); 479 return; 480 } 481 482 /* Get the NS node, determines existence also */ 483 484 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname, 485 &AcpiGbl_DbMethodInfo.Method); 486 if (ACPI_SUCCESS (Status)) 487 { 488 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, 489 &ReturnObj); 490 } 491 ACPI_FREE (NameString); 492 493 /* 494 * Allow any handlers in separate threads to complete. 495 * (Such as Notify handlers invoked from AML executed above). 496 */ 497 AcpiOsSleep ((UINT64) 10); 498 499 #ifdef ACPI_DEBUG_OUTPUT 500 501 /* Memory allocation tracking */ 502 503 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; 504 505 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 506 507 if (Allocations > 0) 508 { 509 AcpiOsPrintf ( 510 "0x%X Outstanding allocations after evaluation of %s\n", 511 Allocations, AcpiGbl_DbMethodInfo.Pathname); 512 } 513 #endif 514 515 if (ACPI_FAILURE (Status)) 516 { 517 AcpiOsPrintf ("Evaluation of %s failed with status %s\n", 518 AcpiGbl_DbMethodInfo.Pathname, 519 AcpiFormatException (Status)); 520 } 521 else 522 { 523 /* Display a return object, if any */ 524 525 if (ReturnObj.Length) 526 { 527 AcpiOsPrintf ( 528 "Evaluation of %s returned object %p, " 529 "external buffer length %X\n", 530 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, 531 (UINT32) ReturnObj.Length); 532 533 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); 534 535 /* Dump a _PLD buffer if present */ 536 537 if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 538 AcpiGbl_DbMethodInfo.Method)->Name.Ascii), 539 METHOD_NAME__PLD)) 540 { 541 AcpiDbDumpPldBuffer (ReturnObj.Pointer); 542 } 543 } 544 else 545 { 546 AcpiOsPrintf ("No object was returned from evaluation of %s\n", 547 AcpiGbl_DbMethodInfo.Pathname); 548 } 549 } 550 551 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 552 } 553 554 555 /******************************************************************************* 556 * 557 * FUNCTION: AcpiDbMethodThread 558 * 559 * PARAMETERS: Context - Execution info segment 560 * 561 * RETURN: None 562 * 563 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 564 * simply dispatches it. 565 * 566 ******************************************************************************/ 567 568 static void ACPI_SYSTEM_XFACE 569 AcpiDbMethodThread ( 570 void *Context) 571 { 572 ACPI_STATUS Status; 573 ACPI_DB_METHOD_INFO *Info = Context; 574 ACPI_DB_METHOD_INFO LocalInfo; 575 UINT32 i; 576 UINT8 Allow; 577 ACPI_BUFFER ReturnObj; 578 579 580 /* 581 * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments. 582 * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads 583 * concurrently. 584 * 585 * Note: The arguments we are passing are used by the ASL test suite 586 * (aslts). Do not change them without updating the tests. 587 */ 588 (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER); 589 590 if (Info->InitArgs) 591 { 592 AcpiDbUint32ToHexString (Info->NumCreated, 593 Info->IndexOfThreadStr); 594 AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (), 595 Info->IdOfThreadStr); 596 } 597 598 if (Info->Threads && (Info->NumCreated < Info->NumThreads)) 599 { 600 Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId(); 601 } 602 603 LocalInfo = *Info; 604 LocalInfo.Args = LocalInfo.Arguments; 605 LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr; 606 LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr; 607 LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr; 608 LocalInfo.Arguments[3] = NULL; 609 610 LocalInfo.Types = LocalInfo.ArgTypes; 611 612 (void) AcpiOsSignalSemaphore (Info->InfoGate, 1); 613 614 for (i = 0; i < Info->NumLoops; i++) 615 { 616 Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj); 617 if (ACPI_FAILURE (Status)) 618 { 619 AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n", 620 AcpiFormatException (Status), Info->Pathname, i); 621 if (Status == AE_ABORT_METHOD) 622 { 623 break; 624 } 625 } 626 627 #if 0 628 if ((i % 100) == 0) 629 { 630 AcpiOsPrintf ("%u loops, Thread 0x%x\n", 631 i, AcpiOsGetThreadId ()); 632 } 633 634 if (ReturnObj.Length) 635 { 636 AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n", 637 Info->Pathname, ReturnObj.Pointer, 638 (UINT32) ReturnObj.Length); 639 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); 640 } 641 #endif 642 } 643 644 /* Signal our completion */ 645 646 Allow = 0; 647 (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 648 1, ACPI_WAIT_FOREVER); 649 Info->NumCompleted++; 650 651 if (Info->NumCompleted == Info->NumThreads) 652 { 653 /* Do signal for main thread once only */ 654 Allow = 1; 655 } 656 657 (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1); 658 659 if (Allow) 660 { 661 Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1); 662 if (ACPI_FAILURE (Status)) 663 { 664 AcpiOsPrintf ( 665 "Could not signal debugger thread sync semaphore, %s\n", 666 AcpiFormatException (Status)); 667 } 668 } 669 } 670 671 672 /******************************************************************************* 673 * 674 * FUNCTION: AcpiDbCreateExecutionThreads 675 * 676 * PARAMETERS: NumThreadsArg - Number of threads to create 677 * NumLoopsArg - Loop count for the thread(s) 678 * MethodNameArg - Control method to execute 679 * 680 * RETURN: None 681 * 682 * DESCRIPTION: Create threads to execute method(s) 683 * 684 ******************************************************************************/ 685 686 void 687 AcpiDbCreateExecutionThreads ( 688 char *NumThreadsArg, 689 char *NumLoopsArg, 690 char *MethodNameArg) 691 { 692 ACPI_STATUS Status; 693 UINT32 NumThreads; 694 UINT32 NumLoops; 695 UINT32 i; 696 UINT32 Size; 697 ACPI_MUTEX MainThreadGate; 698 ACPI_MUTEX ThreadCompleteGate; 699 ACPI_MUTEX InfoGate; 700 701 702 /* Get the arguments */ 703 704 NumThreads = strtoul (NumThreadsArg, NULL, 0); 705 NumLoops = strtoul (NumLoopsArg, NULL, 0); 706 707 if (!NumThreads || !NumLoops) 708 { 709 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n", 710 NumThreads, NumLoops); 711 return; 712 } 713 714 /* 715 * Create the semaphore for synchronization of 716 * the created threads with the main thread. 717 */ 718 Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate); 719 if (ACPI_FAILURE (Status)) 720 { 721 AcpiOsPrintf ("Could not create semaphore for " 722 "synchronization with the main thread, %s\n", 723 AcpiFormatException (Status)); 724 return; 725 } 726 727 /* 728 * Create the semaphore for synchronization 729 * between the created threads. 730 */ 731 Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate); 732 if (ACPI_FAILURE (Status)) 733 { 734 AcpiOsPrintf ("Could not create semaphore for " 735 "synchronization between the created threads, %s\n", 736 AcpiFormatException (Status)); 737 738 (void) AcpiOsDeleteSemaphore (MainThreadGate); 739 return; 740 } 741 742 Status = AcpiOsCreateSemaphore (1, 1, &InfoGate); 743 if (ACPI_FAILURE (Status)) 744 { 745 AcpiOsPrintf ("Could not create semaphore for " 746 "synchronization of AcpiGbl_DbMethodInfo, %s\n", 747 AcpiFormatException (Status)); 748 749 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 750 (void) AcpiOsDeleteSemaphore (MainThreadGate); 751 return; 752 } 753 754 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO)); 755 756 /* Array to store IDs of threads */ 757 758 AcpiGbl_DbMethodInfo.NumThreads = NumThreads; 759 Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads; 760 761 AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size); 762 if (AcpiGbl_DbMethodInfo.Threads == NULL) 763 { 764 AcpiOsPrintf ("No memory for thread IDs array\n"); 765 (void) AcpiOsDeleteSemaphore (MainThreadGate); 766 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 767 (void) AcpiOsDeleteSemaphore (InfoGate); 768 return; 769 } 770 memset (AcpiGbl_DbMethodInfo.Threads, 0, Size); 771 772 /* Setup the context to be passed to each thread */ 773 774 AcpiGbl_DbMethodInfo.Name = MethodNameArg; 775 AcpiGbl_DbMethodInfo.Flags = 0; 776 AcpiGbl_DbMethodInfo.NumLoops = NumLoops; 777 AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate; 778 AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate; 779 AcpiGbl_DbMethodInfo.InfoGate = InfoGate; 780 781 /* Init arguments to be passed to method */ 782 783 AcpiGbl_DbMethodInfo.InitArgs = 1; 784 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments; 785 AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr; 786 AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr; 787 AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr; 788 AcpiGbl_DbMethodInfo.Arguments[3] = NULL; 789 790 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes; 791 AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER; 792 AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER; 793 AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER; 794 795 AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr); 796 797 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 798 if (ACPI_FAILURE (Status)) 799 { 800 goto CleanupAndExit; 801 } 802 803 /* Get the NS node, determines existence also */ 804 805 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname, 806 &AcpiGbl_DbMethodInfo.Method); 807 if (ACPI_FAILURE (Status)) 808 { 809 AcpiOsPrintf ("%s Could not get handle for %s\n", 810 AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname); 811 goto CleanupAndExit; 812 } 813 814 /* Create the threads */ 815 816 AcpiOsPrintf ("Creating %X threads to execute %X times each\n", 817 NumThreads, NumLoops); 818 819 for (i = 0; i < (NumThreads); i++) 820 { 821 Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread, 822 &AcpiGbl_DbMethodInfo); 823 if (ACPI_FAILURE (Status)) 824 { 825 break; 826 } 827 } 828 829 /* Wait for all threads to complete */ 830 831 (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER); 832 833 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 834 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads); 835 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 836 837 CleanupAndExit: 838 839 /* Cleanup and exit */ 840 841 (void) AcpiOsDeleteSemaphore (MainThreadGate); 842 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate); 843 (void) AcpiOsDeleteSemaphore (InfoGate); 844 845 AcpiOsFree (AcpiGbl_DbMethodInfo.Threads); 846 AcpiGbl_DbMethodInfo.Threads = NULL; 847 } 848