dbexec.c revision 117521
1231990Smp/******************************************************************************* 283098Smp * 383098Smp * Module Name: dbexec - debugger control method execution 4231990Smp * $Revision: 54 $ 5231990Smp * 6231990Smp ******************************************************************************/ 7231990Smp 8231990Smp/****************************************************************************** 983098Smp * 10231990Smp * 1. Copyright Notice 1183098Smp * 1283098Smp * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 13231990Smp * All rights reserved. 1483098Smp * 15231990Smp * 2. License 16231990Smp * 17231990Smp * 2.1. This is your license from Intel Corp. under its intellectual property 18231990Smp * rights. You may have additional license terms from the party that provided 19231990Smp * you this software, covering your right to use that party's intellectual 20231990Smp * property rights. 2183098Smp * 2283098Smp * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23231990Smp * copy of the source code appearing in this file ("Covered Code") an 2483098Smp * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2583098Smp * base code distributed originally by Intel ("Original Intel Code") to copy, 26231990Smp * make derivatives, distribute, use and display any portion of the Covered 27231990Smp * Code in any form, with the right to sublicense such rights; and 28231990Smp * 2983098Smp * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30231990Smp * license (with the right to sublicense), under only those claims of Intel 31231990Smp * patents that are infringed by the Original Intel Code, to make, use, sell, 32231990Smp * offer to sell, and import the Covered Code and derivative works thereof 3383098Smp * solely to the minimum extent necessary to exercise the above copyright 3483098Smp * license, and in no event shall the patent license extend to any additions 3583098Smp * to or modifications of the Original Intel Code. No other license or right 36231990Smp * is granted directly or by implication, estoppel or otherwise; 3783098Smp * 3883098Smp * The above copyright and patent license is granted only if the following 3983098Smp * conditions are met: 4083098Smp * 4183098Smp * 3. Conditions 42231990Smp * 4383098Smp * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4483098Smp * Redistribution of source code of any substantial portion of the Covered 4583098Smp * Code or modification with rights to further distribute source must include 4683098Smp * the above Copyright Notice, the above License, this list of Conditions, 47231990Smp * and the following Disclaimer and Export Compliance provision. In addition, 48231990Smp * Licensee must cause all Covered Code to which Licensee contributes to 4983098Smp * contain a file documenting the changes Licensee made to create that Covered 5083098Smp * Code and the date of any change. Licensee must include in that file the 5183098Smp * documentation of any changes made by any predecessor Licensee. Licensee 5283098Smp * must include a prominent statement that the modification is derived, 5383098Smp * directly or indirectly, from Original Intel Code. 5483098Smp * 5583098Smp * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5683098Smp * Redistribution of source code of any substantial portion of the Covered 5783098Smp * Code or modification without rights to further distribute source must 5883098Smp * include the following Disclaimer and Export Compliance provision in the 5983098Smp * documentation and/or other materials provided with distribution. In 6083098Smp * addition, Licensee may not authorize further sublicense of source of any 6183098Smp * portion of the Covered Code, and must include terms to the effect that the 6283098Smp * license from Licensee to its licensee is limited to the intellectual 6383098Smp * property embodied in the software Licensee provides to its licensee, and 6483098Smp * not to intellectual property embodied in modifications its licensee may 6583098Smp * make. 6683098Smp * 6783098Smp * 3.3. Redistribution of Executable. Redistribution in executable form of any 6883098Smp * substantial portion of the Covered Code or modification must reproduce the 6983098Smp * above Copyright Notice, and the following Disclaimer and Export Compliance 7083098Smp * provision in the documentation and/or other materials provided with the 7183098Smp * distribution. 7283098Smp * 7383098Smp * 3.4. Intel retains all right, title, and interest in and to the Original 7483098Smp * Intel Code. 7583098Smp * 7683098Smp * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7783098Smp * Intel shall be used in advertising or otherwise to promote the sale, use or 7883098Smp * other dealings in products derived from or relating to the Covered Code 7983098Smp * without prior written authorization from Intel. 8083098Smp * 8183098Smp * 4. Disclaimer and Export Compliance 8283098Smp * 8383098Smp * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8483098Smp * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8583098Smp * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8683098Smp * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8783098Smp * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8883098Smp * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8983098Smp * PARTICULAR PURPOSE. 9083098Smp * 9183098Smp * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9283098Smp * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9383098Smp * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9483098Smp * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9583098Smp * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9683098Smp * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9783098Smp * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9883098Smp * LIMITED REMEDY. 9983098Smp * 10083098Smp * 4.3. Licensee shall not export, either directly or indirectly, any of this 10183098Smp * software or system incorporating such software without first obtaining any 10283098Smp * required license or other approval from the U. S. Department of Commerce or 10383098Smp * any other agency or department of the United States Government. In the 10483098Smp * event Licensee exports any such software from the United States or 10583098Smp * re-exports any such software from a foreign destination, Licensee shall 10683098Smp * ensure that the distribution and export/re-export of the software is in 10783098Smp * compliance with all laws, regulations, orders, or other restrictions of the 10883098Smp * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10983098Smp * any of its subsidiaries will export/re-export any technical data, process, 11083098Smp * software, or service, directly or indirectly, to any country for which the 11183098Smp * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117 118#include "acpi.h" 119#include "acdebug.h" 120#include "acnamesp.h" 121 122#ifdef ACPI_DEBUGGER 123 124#define _COMPONENT ACPI_CA_DEBUGGER 125 ACPI_MODULE_NAME ("dbexec") 126 127 128static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo; 129 130 131/******************************************************************************* 132 * 133 * FUNCTION: AcpiDbExecuteMethod 134 * 135 * PARAMETERS: Info - Valid info segment 136 * ReturnObj - Where to put return object 137 * 138 * RETURN: Status 139 * 140 * DESCRIPTION: Execute a control method. 141 * 142 ******************************************************************************/ 143 144ACPI_STATUS 145AcpiDbExecuteMethod ( 146 ACPI_DB_METHOD_INFO *Info, 147 ACPI_BUFFER *ReturnObj) 148{ 149 ACPI_STATUS Status; 150 ACPI_OBJECT_LIST ParamObjects; 151 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS]; 152 UINT32 i; 153 154 155 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel) 156 { 157 AcpiOsPrintf ("Warning: debug output is not enabled!\n"); 158 } 159 160 /* Are there arguments to the method? */ 161 162 if (Info->Args && Info->Args[0]) 163 { 164 for (i = 0; Info->Args[i] && i < ACPI_METHOD_NUM_ARGS; i++) 165 { 166 Params[i].Type = ACPI_TYPE_INTEGER; 167 Params[i].Integer.Value = ACPI_STRTOUL (Info->Args[i], NULL, 16); 168 } 169 170 ParamObjects.Pointer = Params; 171 ParamObjects.Count = i; 172 } 173 else 174 { 175 /* Setup default parameters */ 176 177 Params[0].Type = ACPI_TYPE_INTEGER; 178 Params[0].Integer.Value = 0x01020304; 179 180 Params[1].Type = ACPI_TYPE_STRING; 181 Params[1].String.Length = 12; 182 Params[1].String.Pointer = "AML Debugger"; 183 184 ParamObjects.Pointer = Params; 185 ParamObjects.Count = 2; 186 } 187 188 /* Prepare for a return object of arbitrary size */ 189 190 ReturnObj->Pointer = AcpiGbl_DbBuffer; 191 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE; 192 193 /* Do the actual method execution */ 194 195 AcpiGbl_MethodExecuting = TRUE; 196 Status = AcpiEvaluateObject (NULL, Info->Pathname, &ParamObjects, ReturnObj); 197 198 AcpiGbl_CmSingleStep = FALSE; 199 AcpiGbl_MethodExecuting = FALSE; 200 201 return (Status); 202} 203 204 205/******************************************************************************* 206 * 207 * FUNCTION: AcpiDbExecuteSetup 208 * 209 * PARAMETERS: Info - Valid method info 210 * 211 * RETURN: Status 212 * 213 * DESCRIPTION: Setup info segment prior to method execution 214 * 215 ******************************************************************************/ 216 217void 218AcpiDbExecuteSetup ( 219 ACPI_DB_METHOD_INFO *Info) 220{ 221 222 /* Catenate the current scope to the supplied name */ 223 224 Info->Pathname[0] = 0; 225 if ((Info->Name[0] != '\\') && 226 (Info->Name[0] != '/')) 227 { 228 ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf); 229 } 230 231 ACPI_STRCAT (Info->Pathname, Info->Name); 232 AcpiDbPrepNamestring (Info->Pathname); 233 234 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 235 AcpiOsPrintf ("Executing %s\n", Info->Pathname); 236 237 if (Info->Flags & EX_SINGLE_STEP) 238 { 239 AcpiGbl_CmSingleStep = TRUE; 240 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 241 } 242 243 else 244 { 245 /* No single step, allow redirection to a file */ 246 247 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 248 } 249} 250 251 252/******************************************************************************* 253 * 254 * FUNCTION: AcpiDbGetOutstandingAllocations 255 * 256 * PARAMETERS: None 257 * 258 * RETURN: Current global allocation count minus cache entries 259 * 260 * DESCRIPTION: Determine the current number of "outstanding" allocations -- 261 * those allocations that have not been freed and also are not 262 * in one of the various object caches. 263 * 264 ******************************************************************************/ 265 266UINT32 267AcpiDbGetOutstandingAllocations ( 268 void) 269{ 270 UINT32 Outstanding = 0; 271 272#ifdef ACPI_DBG_TRACK_ALLOCATIONS 273 UINT32 i; 274 275 276 for (i = ACPI_MEM_LIST_FIRST_CACHE_LIST; i < ACPI_NUM_MEM_LISTS; i++) 277 { 278 Outstanding += (AcpiGbl_MemoryLists[i].TotalAllocated - 279 AcpiGbl_MemoryLists[i].TotalFreed - 280 AcpiGbl_MemoryLists[i].CacheDepth); 281 } 282#endif 283 284 return (Outstanding); 285} 286 287 288/******************************************************************************* 289 * 290 * FUNCTION: AcpiDbExecutionWalk 291 * 292 * PARAMETERS: WALK_CALLBACK 293 * 294 * RETURN: Status 295 * 296 * DESCRIPTION: Execute a control method. Name is relative to the current 297 * scope. 298 * 299 ******************************************************************************/ 300 301ACPI_STATUS 302AcpiDbExecutionWalk ( 303 ACPI_HANDLE ObjHandle, 304 UINT32 NestingLevel, 305 void *Context, 306 void **ReturnValue) 307{ 308 ACPI_OPERAND_OBJECT *ObjDesc; 309 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 310 ACPI_BUFFER ReturnObj; 311 ACPI_STATUS Status; 312 313 314 ObjDesc = AcpiNsGetAttachedObject (Node); 315 if (ObjDesc->Method.ParamCount) 316 { 317 return (AE_OK); 318 } 319 320 ReturnObj.Pointer = NULL; 321 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 322 323 AcpiNsPrintNodePathname (Node, "Execute"); 324 325 /* Do the actual method execution */ 326 327 AcpiOsPrintf ("\n"); 328 AcpiGbl_MethodExecuting = TRUE; 329 330 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj); 331 332 AcpiOsPrintf ("[%4.4s] returned %s\n", Node->Name.Ascii, 333 AcpiFormatException (Status)); 334 AcpiGbl_MethodExecuting = FALSE; 335 336 return (AE_OK); 337} 338 339 340/******************************************************************************* 341 * 342 * FUNCTION: AcpiDbExecute 343 * 344 * PARAMETERS: Name - Name of method to execute 345 * Args - Parameters to the method 346 * Flags - single step/no single step 347 * 348 * RETURN: Status 349 * 350 * DESCRIPTION: Execute a control method. Name is relative to the current 351 * scope. 352 * 353 ******************************************************************************/ 354 355void 356AcpiDbExecute ( 357 char *Name, 358 char **Args, 359 UINT32 Flags) 360{ 361 ACPI_STATUS Status; 362 ACPI_BUFFER ReturnObj; 363 364 365#ifdef ACPI_DEBUG_OUTPUT 366 UINT32 PreviousAllocations; 367 UINT32 Allocations; 368 369 370 /* Memory allocation tracking */ 371 372 PreviousAllocations = AcpiDbGetOutstandingAllocations (); 373#endif 374 375 if (*Name == '*') 376 { 377 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, 378 AcpiDbExecutionWalk, NULL, NULL); 379 return; 380 } 381 else 382 { 383 AcpiGbl_DbMethodInfo.Name = Name; 384 AcpiGbl_DbMethodInfo.Args = Args; 385 AcpiGbl_DbMethodInfo.Flags = Flags; 386 387 ReturnObj.Pointer = NULL; 388 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 389 390 AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 391 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj); 392 } 393 394 /* 395 * Allow any handlers in separate threads to complete. 396 * (Such as Notify handlers invoked from AML executed above). 397 */ 398 AcpiOsSleep (0, 10); 399 400 401#ifdef ACPI_DEBUG_OUTPUT 402 403 /* Memory allocation tracking */ 404 405 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; 406 407 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 408 409 if (Allocations > 0) 410 { 411 AcpiOsPrintf ("Outstanding: %ld allocations after execution\n", 412 Allocations); 413 } 414#endif 415 416 if (ACPI_FAILURE (Status)) 417 { 418 AcpiOsPrintf ("Execution of %s failed with status %s\n", 419 AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status)); 420 } 421 422 else 423 { 424 /* Display a return object, if any */ 425 426 if (ReturnObj.Length) 427 { 428 AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n", 429 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, 430 (UINT32) ReturnObj.Length); 431 AcpiDbDumpObject (ReturnObj.Pointer, 1); 432 } 433 else 434 { 435 AcpiOsPrintf ("No return object from execution of %s\n", 436 AcpiGbl_DbMethodInfo.Pathname); 437 } 438 } 439 440 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 441} 442 443 444/******************************************************************************* 445 * 446 * FUNCTION: AcpiDbMethodThread 447 * 448 * PARAMETERS: Context - Execution info segment 449 * 450 * RETURN: None 451 * 452 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 453 * simply dispatches it. 454 * 455 ******************************************************************************/ 456 457void ACPI_SYSTEM_XFACE 458AcpiDbMethodThread ( 459 void *Context) 460{ 461 ACPI_STATUS Status; 462 ACPI_DB_METHOD_INFO *Info = Context; 463 UINT32 i; 464 ACPI_BUFFER ReturnObj; 465 466 467 for (i = 0; i < Info->NumLoops; i++) 468 { 469#if 0 470 if (i == 0xEFDC) 471 { 472 AcpiDbgLevel = 0x00FFFFFF; 473 } 474#endif 475 476 Status = AcpiDbExecuteMethod (Info, &ReturnObj); 477 478 if (ACPI_FAILURE (Status)) 479 { 480 AcpiOsPrintf ("%s During execution of %s at iteration %X\n", 481 AcpiFormatException (Status), Info->Pathname, i); 482 break; 483 } 484 485 if ((i % 1000) == 0) 486 { 487 AcpiOsPrintf ("%d executions\n", i); 488 } 489 490#if 0 491 if (ReturnObj.Length) 492 { 493 AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n", 494 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length); 495 AcpiDbDumpObject (ReturnObj.Pointer, 1); 496 } 497#endif 498 } 499 500 /* Signal our completion */ 501 502 Status = AcpiOsSignalSemaphore (Info->ThreadGate, 1); 503 if (ACPI_FAILURE (Status)) 504 { 505 AcpiOsPrintf ("Could not signal debugger semaphore\n"); 506 } 507} 508 509 510/******************************************************************************* 511 * 512 * FUNCTION: AcpiDbCreateExecutionThreads 513 * 514 * PARAMETERS: NumThreadsArg - Number of threads to create 515 * NumLoopsArg - Loop count for the thread(s) 516 * MethodNameArg - Control method to execute 517 * 518 * RETURN: None 519 * 520 * DESCRIPTION: Create threads to execute method(s) 521 * 522 ******************************************************************************/ 523 524void 525AcpiDbCreateExecutionThreads ( 526 char *NumThreadsArg, 527 char *NumLoopsArg, 528 char *MethodNameArg) 529{ 530 ACPI_STATUS Status; 531 UINT32 NumThreads; 532 UINT32 NumLoops; 533 UINT32 i; 534 ACPI_HANDLE ThreadGate; 535 536 537 /* Get the arguments */ 538 539 NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0); 540 NumLoops = ACPI_STRTOUL (NumLoopsArg, NULL, 0); 541 542 if (!NumThreads || !NumLoops) 543 { 544 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n", NumThreads, NumLoops); 545 return; 546 } 547 548 /* Create the synchronization semaphore */ 549 550 Status = AcpiOsCreateSemaphore (1, 0, &ThreadGate); 551 if (ACPI_FAILURE (Status)) 552 { 553 AcpiOsPrintf ("Could not create semaphore, %s\n", AcpiFormatException (Status)); 554 return; 555 } 556 557 /* Setup the context to be passed to each thread */ 558 559 AcpiGbl_DbMethodInfo.Name = MethodNameArg; 560 AcpiGbl_DbMethodInfo.Args = NULL; 561 AcpiGbl_DbMethodInfo.Flags = 0; 562 AcpiGbl_DbMethodInfo.NumLoops = NumLoops; 563 AcpiGbl_DbMethodInfo.ThreadGate = ThreadGate; 564 565 AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); 566 567 /* Create the threads */ 568 569 AcpiOsPrintf ("Creating %X threads to execute %X times each\n", NumThreads, NumLoops); 570 571 for (i = 0; i < (NumThreads); i++) 572 { 573 Status = AcpiOsQueueForExecution (OSD_PRIORITY_MED, AcpiDbMethodThread, &AcpiGbl_DbMethodInfo); 574 if (ACPI_FAILURE (Status)) 575 { 576 break; 577 } 578 } 579 580 /* Wait for all threads to complete */ 581 582 i = NumThreads; 583 while (i) /* Brain damage for OSD implementations that only support wait of 1 unit */ 584 { 585 Status = AcpiOsWaitSemaphore (ThreadGate, 1, ACPI_WAIT_FOREVER); 586 i--; 587 } 588 589 /* Cleanup and exit */ 590 591 (void) AcpiOsDeleteSemaphore (ThreadGate); 592 593 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); 594 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads); 595 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 596} 597 598 599#endif /* ACPI_DEBUGGER */ 600 601 602