1 /******************************************************************************* 2 * 3 * Module Name: dbmethod - Debug commands for control methods 4 * 5 ******************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2013, 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 45 #include <contrib/dev/acpica/include/acpi.h> 46 #include <contrib/dev/acpica/include/accommon.h> 47 #include <contrib/dev/acpica/include/acdispat.h> 48 #include <contrib/dev/acpica/include/acnamesp.h> 49 #include <contrib/dev/acpica/include/acdebug.h> 50 #include <contrib/dev/acpica/include/acdisasm.h> 51 #include <contrib/dev/acpica/include/acparser.h> 52 #include <contrib/dev/acpica/include/acpredef.h> 53 54 55 #ifdef ACPI_DEBUGGER 56 57 #define _COMPONENT ACPI_CA_DEBUGGER 58 ACPI_MODULE_NAME ("dbmethod") 59 60 61 /* Local prototypes */ 62 63 static ACPI_STATUS 64 AcpiDbWalkForExecute ( 65 ACPI_HANDLE ObjHandle, 66 UINT32 NestingLevel, 67 void *Context, 68 void **ReturnValue); 69 70 71 /******************************************************************************* 72 * 73 * FUNCTION: AcpiDbSetMethodBreakpoint 74 * 75 * PARAMETERS: Location - AML offset of breakpoint 76 * WalkState - Current walk info 77 * Op - Current Op (from parse walk) 78 * 79 * RETURN: None 80 * 81 * DESCRIPTION: Set a breakpoint in a control method at the specified 82 * AML offset 83 * 84 ******************************************************************************/ 85 86 void 87 AcpiDbSetMethodBreakpoint ( 88 char *Location, 89 ACPI_WALK_STATE *WalkState, 90 ACPI_PARSE_OBJECT *Op) 91 { 92 UINT32 Address; 93 94 95 if (!Op) 96 { 97 AcpiOsPrintf ("There is no method currently executing\n"); 98 return; 99 } 100 101 /* Get and verify the breakpoint address */ 102 103 Address = ACPI_STRTOUL (Location, NULL, 16); 104 if (Address <= Op->Common.AmlOffset) 105 { 106 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n", 107 Address, Op->Common.AmlOffset); 108 } 109 110 /* Save breakpoint in current walk */ 111 112 WalkState->UserBreakpoint = Address; 113 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address); 114 } 115 116 117 /******************************************************************************* 118 * 119 * FUNCTION: AcpiDbSetMethodCallBreakpoint 120 * 121 * PARAMETERS: Op - Current Op (from parse walk) 122 * 123 * RETURN: None 124 * 125 * DESCRIPTION: Set a breakpoint in a control method at the specified 126 * AML offset 127 * 128 ******************************************************************************/ 129 130 void 131 AcpiDbSetMethodCallBreakpoint ( 132 ACPI_PARSE_OBJECT *Op) 133 { 134 135 136 if (!Op) 137 { 138 AcpiOsPrintf ("There is no method currently executing\n"); 139 return; 140 } 141 142 AcpiGbl_StepToNextCall = TRUE; 143 } 144 145 146 /******************************************************************************* 147 * 148 * FUNCTION: AcpiDbSetMethodData 149 * 150 * PARAMETERS: TypeArg - L for local, A for argument 151 * IndexArg - which one 152 * ValueArg - Value to set. 153 * 154 * RETURN: None 155 * 156 * DESCRIPTION: Set a local or argument for the running control method. 157 * NOTE: only object supported is Number. 158 * 159 ******************************************************************************/ 160 161 void 162 AcpiDbSetMethodData ( 163 char *TypeArg, 164 char *IndexArg, 165 char *ValueArg) 166 { 167 char Type; 168 UINT32 Index; 169 UINT32 Value; 170 ACPI_WALK_STATE *WalkState; 171 ACPI_OPERAND_OBJECT *ObjDesc; 172 ACPI_STATUS Status; 173 ACPI_NAMESPACE_NODE *Node; 174 175 176 /* Validate TypeArg */ 177 178 AcpiUtStrupr (TypeArg); 179 Type = TypeArg[0]; 180 if ((Type != 'L') && 181 (Type != 'A') && 182 (Type != 'N')) 183 { 184 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg); 185 return; 186 } 187 188 Value = ACPI_STRTOUL (ValueArg, NULL, 16); 189 190 if (Type == 'N') 191 { 192 Node = AcpiDbConvertToNode (IndexArg); 193 if (Node->Type != ACPI_TYPE_INTEGER) 194 { 195 AcpiOsPrintf ("Can only set Integer nodes\n"); 196 return; 197 } 198 ObjDesc = Node->Object; 199 ObjDesc->Integer.Value = Value; 200 return; 201 } 202 203 /* Get the index and value */ 204 205 Index = ACPI_STRTOUL (IndexArg, NULL, 16); 206 207 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList); 208 if (!WalkState) 209 { 210 AcpiOsPrintf ("There is no method currently executing\n"); 211 return; 212 } 213 214 /* Create and initialize the new object */ 215 216 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value); 217 if (!ObjDesc) 218 { 219 AcpiOsPrintf ("Could not create an internal object\n"); 220 return; 221 } 222 223 /* Store the new object into the target */ 224 225 switch (Type) 226 { 227 case 'A': 228 229 /* Set a method argument */ 230 231 if (Index > ACPI_METHOD_MAX_ARG) 232 { 233 AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index); 234 goto Cleanup; 235 } 236 237 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc, 238 WalkState); 239 if (ACPI_FAILURE (Status)) 240 { 241 goto Cleanup; 242 } 243 244 ObjDesc = WalkState->Arguments[Index].Object; 245 246 AcpiOsPrintf ("Arg%u: ", Index); 247 AcpiDmDisplayInternalObject (ObjDesc, WalkState); 248 break; 249 250 case 'L': 251 252 /* Set a method local */ 253 254 if (Index > ACPI_METHOD_MAX_LOCAL) 255 { 256 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index); 257 goto Cleanup; 258 } 259 260 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc, 261 WalkState); 262 if (ACPI_FAILURE (Status)) 263 { 264 goto Cleanup; 265 } 266 267 ObjDesc = WalkState->LocalVariables[Index].Object; 268 269 AcpiOsPrintf ("Local%u: ", Index); 270 AcpiDmDisplayInternalObject (ObjDesc, WalkState); 271 break; 272 273 default: 274 275 break; 276 } 277 278 Cleanup: 279 AcpiUtRemoveReference (ObjDesc); 280 } 281 282 283 /******************************************************************************* 284 * 285 * FUNCTION: AcpiDbDisassembleAml 286 * 287 * PARAMETERS: Statements - Number of statements to disassemble 288 * Op - Current Op (from parse walk) 289 * 290 * RETURN: None 291 * 292 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number 293 * of statements specified. 294 * 295 ******************************************************************************/ 296 297 void 298 AcpiDbDisassembleAml ( 299 char *Statements, 300 ACPI_PARSE_OBJECT *Op) 301 { 302 UINT32 NumStatements = 8; 303 304 305 if (!Op) 306 { 307 AcpiOsPrintf ("There is no method currently executing\n"); 308 return; 309 } 310 311 if (Statements) 312 { 313 NumStatements = ACPI_STRTOUL (Statements, NULL, 0); 314 } 315 316 #ifdef ACPI_DISASSEMBLER 317 AcpiDmDisassemble (NULL, Op, NumStatements); 318 #endif 319 } 320 321 322 /******************************************************************************* 323 * 324 * FUNCTION: AcpiDbDisassembleMethod 325 * 326 * PARAMETERS: Name - Name of control method 327 * 328 * RETURN: None 329 * 330 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number 331 * of statements specified. 332 * 333 ******************************************************************************/ 334 335 ACPI_STATUS 336 AcpiDbDisassembleMethod ( 337 char *Name) 338 { 339 ACPI_STATUS Status; 340 ACPI_PARSE_OBJECT *Op; 341 ACPI_WALK_STATE *WalkState; 342 ACPI_OPERAND_OBJECT *ObjDesc; 343 ACPI_NAMESPACE_NODE *Method; 344 345 346 Method = AcpiDbConvertToNode (Name); 347 if (!Method) 348 { 349 return (AE_BAD_PARAMETER); 350 } 351 352 if (Method->Type != ACPI_TYPE_METHOD) 353 { 354 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method", 355 Name, AcpiUtGetTypeName (Method->Type))); 356 return (AE_BAD_PARAMETER); 357 } 358 359 ObjDesc = Method->Object; 360 361 Op = AcpiPsCreateScopeOp (); 362 if (!Op) 363 { 364 return (AE_NO_MEMORY); 365 } 366 367 /* Create and initialize a new walk state */ 368 369 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL); 370 if (!WalkState) 371 { 372 return (AE_NO_MEMORY); 373 } 374 375 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, 376 ObjDesc->Method.AmlStart, 377 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1); 378 if (ACPI_FAILURE (Status)) 379 { 380 return (Status); 381 } 382 383 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId); 384 WalkState->OwnerId = ObjDesc->Method.OwnerId; 385 386 /* Push start scope on scope stack and make it current */ 387 388 Status = AcpiDsScopeStackPush (Method, 389 Method->Type, WalkState); 390 if (ACPI_FAILURE (Status)) 391 { 392 return (Status); 393 } 394 395 /* Parse the entire method AML including deferred operators */ 396 397 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE; 398 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE; 399 400 Status = AcpiPsParseAml (WalkState); 401 (void) AcpiDmParseDeferredOps (Op); 402 403 /* Now we can disassemble the method */ 404 405 AcpiGbl_DbOpt_verbose = FALSE; 406 #ifdef ACPI_DISASSEMBLER 407 AcpiDmDisassemble (NULL, Op, 0); 408 #endif 409 AcpiGbl_DbOpt_verbose = TRUE; 410 411 AcpiPsDeleteParseTree (Op); 412 413 /* Method cleanup */ 414 415 AcpiNsDeleteNamespaceSubtree (Method); 416 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId); 417 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId); 418 return (AE_OK); 419 } 420 421 422 /******************************************************************************* 423 * 424 * FUNCTION: AcpiDbWalkForExecute 425 * 426 * PARAMETERS: Callback from WalkNamespace 427 * 428 * RETURN: Status 429 * 430 * DESCRIPTION: Batch execution module. Currently only executes predefined 431 * ACPI names. 432 * 433 ******************************************************************************/ 434 435 static ACPI_STATUS 436 AcpiDbWalkForExecute ( 437 ACPI_HANDLE ObjHandle, 438 UINT32 NestingLevel, 439 void *Context, 440 void **ReturnValue) 441 { 442 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 443 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context; 444 char *Pathname; 445 const ACPI_PREDEFINED_INFO *Predefined; 446 ACPI_DEVICE_INFO *ObjInfo; 447 ACPI_OBJECT_LIST ParamObjects; 448 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS]; 449 ACPI_OBJECT *ThisParam; 450 ACPI_BUFFER ReturnObj; 451 ACPI_STATUS Status; 452 UINT16 ArgTypeList; 453 UINT8 ArgCount; 454 UINT8 ArgType; 455 UINT32 i; 456 457 458 /* The name must be a predefined ACPI name */ 459 460 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii); 461 if (!Predefined) 462 { 463 return (AE_OK); 464 } 465 466 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE) 467 { 468 return (AE_OK); 469 } 470 471 Pathname = AcpiNsGetExternalPathname (Node); 472 if (!Pathname) 473 { 474 return (AE_OK); 475 } 476 477 /* Get the object info for number of method parameters */ 478 479 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo); 480 if (ACPI_FAILURE (Status)) 481 { 482 return (Status); 483 } 484 485 ParamObjects.Count = 0; 486 ParamObjects.Pointer = NULL; 487 488 if (ObjInfo->Type == ACPI_TYPE_METHOD) 489 { 490 /* Setup default parameters (with proper types) */ 491 492 ArgTypeList = Predefined->Info.ArgumentList; 493 ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList); 494 495 /* 496 * Setup the ACPI-required number of arguments, regardless of what 497 * the actual method defines. If there is a difference, then the 498 * method is wrong and a warning will be issued during execution. 499 */ 500 ThisParam = Params; 501 for (i = 0; i < ArgCount; i++) 502 { 503 ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList); 504 ThisParam->Type = ArgType; 505 506 switch (ArgType) 507 { 508 case ACPI_TYPE_INTEGER: 509 510 ThisParam->Integer.Value = 1; 511 break; 512 513 case ACPI_TYPE_STRING: 514 515 ThisParam->String.Pointer = "This is the default argument string"; 516 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer); 517 break; 518 519 case ACPI_TYPE_BUFFER: 520 521 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */ 522 ThisParam->Buffer.Length = 48; 523 break; 524 525 case ACPI_TYPE_PACKAGE: 526 527 ThisParam->Package.Elements = NULL; 528 ThisParam->Package.Count = 0; 529 break; 530 531 default: 532 533 AcpiOsPrintf ("%s: Unsupported argument type: %u\n", 534 Pathname, ArgType); 535 break; 536 } 537 538 ThisParam++; 539 } 540 541 ParamObjects.Count = ArgCount; 542 ParamObjects.Pointer = Params; 543 } 544 545 ACPI_FREE (ObjInfo); 546 ReturnObj.Pointer = NULL; 547 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 548 549 /* Do the actual method execution */ 550 551 AcpiGbl_MethodExecuting = TRUE; 552 553 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj); 554 555 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status)); 556 AcpiGbl_MethodExecuting = FALSE; 557 ACPI_FREE (Pathname); 558 559 /* Ignore status from method execution */ 560 561 Status = AE_OK; 562 563 /* Update count, check if we have executed enough methods */ 564 565 Info->Count++; 566 if (Info->Count >= Info->MaxCount) 567 { 568 Status = AE_CTRL_TERMINATE; 569 } 570 571 return (Status); 572 } 573 574 575 /******************************************************************************* 576 * 577 * FUNCTION: AcpiDbBatchExecute 578 * 579 * PARAMETERS: CountArg - Max number of methods to execute 580 * 581 * RETURN: None 582 * 583 * DESCRIPTION: Namespace batch execution. Execute predefined names in the 584 * namespace, up to the max count, if specified. 585 * 586 ******************************************************************************/ 587 588 void 589 AcpiDbBatchExecute ( 590 char *CountArg) 591 { 592 ACPI_DB_EXECUTE_WALK Info; 593 594 595 Info.Count = 0; 596 Info.MaxCount = ACPI_UINT32_MAX; 597 598 if (CountArg) 599 { 600 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0); 601 } 602 603 604 /* Search all nodes in namespace */ 605 606 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, 607 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL); 608 609 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count); 610 } 611 612 #endif /* ACPI_DEBUGGER */ 613