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 break; 275 } 276 277 Cleanup: 278 AcpiUtRemoveReference (ObjDesc); 279 } 280 281 282 /******************************************************************************* 283 * 284 * FUNCTION: AcpiDbDisassembleAml 285 * 286 * PARAMETERS: Statements - Number of statements to disassemble 287 * Op - Current Op (from parse walk) 288 * 289 * RETURN: None 290 * 291 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number 292 * of statements specified. 293 * 294 ******************************************************************************/ 295 296 void 297 AcpiDbDisassembleAml ( 298 char *Statements, 299 ACPI_PARSE_OBJECT *Op) 300 { 301 UINT32 NumStatements = 8; 302 303 304 if (!Op) 305 { 306 AcpiOsPrintf ("There is no method currently executing\n"); 307 return; 308 } 309 310 if (Statements) 311 { 312 NumStatements = ACPI_STRTOUL (Statements, NULL, 0); 313 } 314 315 #ifdef ACPI_DISASSEMBLER 316 AcpiDmDisassemble (NULL, Op, NumStatements); 317 #endif 318 } 319 320 321 /******************************************************************************* 322 * 323 * FUNCTION: AcpiDbDisassembleMethod 324 * 325 * PARAMETERS: Name - Name of control method 326 * 327 * RETURN: None 328 * 329 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number 330 * of statements specified. 331 * 332 ******************************************************************************/ 333 334 ACPI_STATUS 335 AcpiDbDisassembleMethod ( 336 char *Name) 337 { 338 ACPI_STATUS Status; 339 ACPI_PARSE_OBJECT *Op; 340 ACPI_WALK_STATE *WalkState; 341 ACPI_OPERAND_OBJECT *ObjDesc; 342 ACPI_NAMESPACE_NODE *Method; 343 344 345 Method = AcpiDbConvertToNode (Name); 346 if (!Method) 347 { 348 return (AE_BAD_PARAMETER); 349 } 350 351 if (Method->Type != ACPI_TYPE_METHOD) 352 { 353 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method", 354 Name, AcpiUtGetTypeName (Method->Type))); 355 return (AE_BAD_PARAMETER); 356 } 357 358 ObjDesc = Method->Object; 359 360 Op = AcpiPsCreateScopeOp (); 361 if (!Op) 362 { 363 return (AE_NO_MEMORY); 364 } 365 366 /* Create and initialize a new walk state */ 367 368 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL); 369 if (!WalkState) 370 { 371 return (AE_NO_MEMORY); 372 } 373 374 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, 375 ObjDesc->Method.AmlStart, 376 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1); 377 if (ACPI_FAILURE (Status)) 378 { 379 return (Status); 380 } 381 382 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId); 383 WalkState->OwnerId = ObjDesc->Method.OwnerId; 384 385 /* Push start scope on scope stack and make it current */ 386 387 Status = AcpiDsScopeStackPush (Method, 388 Method->Type, WalkState); 389 if (ACPI_FAILURE (Status)) 390 { 391 return (Status); 392 } 393 394 /* Parse the entire method AML including deferred operators */ 395 396 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE; 397 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE; 398 399 Status = AcpiPsParseAml (WalkState); 400 (void) AcpiDmParseDeferredOps (Op); 401 402 /* Now we can disassemble the method */ 403 404 AcpiGbl_DbOpt_verbose = FALSE; 405 #ifdef ACPI_DISASSEMBLER 406 AcpiDmDisassemble (NULL, Op, 0); 407 #endif 408 AcpiGbl_DbOpt_verbose = TRUE; 409 410 AcpiPsDeleteParseTree (Op); 411 412 /* Method cleanup */ 413 414 AcpiNsDeleteNamespaceSubtree (Method); 415 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId); 416 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId); 417 return (AE_OK); 418 } 419 420 421 /******************************************************************************* 422 * 423 * FUNCTION: AcpiDbWalkForExecute 424 * 425 * PARAMETERS: Callback from WalkNamespace 426 * 427 * RETURN: Status 428 * 429 * DESCRIPTION: Batch execution module. Currently only executes predefined 430 * ACPI names. 431 * 432 ******************************************************************************/ 433 434 static ACPI_STATUS 435 AcpiDbWalkForExecute ( 436 ACPI_HANDLE ObjHandle, 437 UINT32 NestingLevel, 438 void *Context, 439 void **ReturnValue) 440 { 441 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 442 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context; 443 char *Pathname; 444 const ACPI_PREDEFINED_INFO *Predefined; 445 ACPI_DEVICE_INFO *ObjInfo; 446 ACPI_OBJECT_LIST ParamObjects; 447 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS]; 448 ACPI_OBJECT *ThisParam; 449 ACPI_BUFFER ReturnObj; 450 ACPI_STATUS Status; 451 UINT16 ArgTypeList; 452 UINT8 ArgCount; 453 UINT8 ArgType; 454 UINT32 i; 455 456 457 /* The name must be a predefined ACPI name */ 458 459 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii); 460 if (!Predefined) 461 { 462 return (AE_OK); 463 } 464 465 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE) 466 { 467 return (AE_OK); 468 } 469 470 Pathname = AcpiNsGetExternalPathname (Node); 471 if (!Pathname) 472 { 473 return (AE_OK); 474 } 475 476 /* Get the object info for number of method parameters */ 477 478 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo); 479 if (ACPI_FAILURE (Status)) 480 { 481 return (Status); 482 } 483 484 ParamObjects.Count = 0; 485 ParamObjects.Pointer = NULL; 486 487 if (ObjInfo->Type == ACPI_TYPE_METHOD) 488 { 489 /* Setup default parameters (with proper types) */ 490 491 ArgTypeList = Predefined->Info.ArgumentList; 492 ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList); 493 494 /* 495 * Setup the ACPI-required number of arguments, regardless of what 496 * the actual method defines. If there is a difference, then the 497 * method is wrong and a warning will be issued during execution. 498 */ 499 ThisParam = Params; 500 for (i = 0; i < ArgCount; i++) 501 { 502 ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList); 503 ThisParam->Type = ArgType; 504 505 switch (ArgType) 506 { 507 case ACPI_TYPE_INTEGER: 508 ThisParam->Integer.Value = 1; 509 break; 510 511 case ACPI_TYPE_STRING: 512 ThisParam->String.Pointer = "This is the default argument string"; 513 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer); 514 break; 515 516 case ACPI_TYPE_BUFFER: 517 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */ 518 ThisParam->Buffer.Length = 48; 519 break; 520 521 case ACPI_TYPE_PACKAGE: 522 ThisParam->Package.Elements = NULL; 523 ThisParam->Package.Count = 0; 524 break; 525 526 default: 527 AcpiOsPrintf ("%s: Unsupported argument type: %u\n", 528 Pathname, ArgType); 529 break; 530 } 531 532 ThisParam++; 533 } 534 535 ParamObjects.Count = ArgCount; 536 ParamObjects.Pointer = Params; 537 } 538 539 ACPI_FREE (ObjInfo); 540 ReturnObj.Pointer = NULL; 541 ReturnObj.Length = ACPI_ALLOCATE_BUFFER; 542 543 /* Do the actual method execution */ 544 545 AcpiGbl_MethodExecuting = TRUE; 546 547 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj); 548 549 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status)); 550 AcpiGbl_MethodExecuting = FALSE; 551 ACPI_FREE (Pathname); 552 553 /* Ignore status from method execution */ 554 555 Status = AE_OK; 556 557 /* Update count, check if we have executed enough methods */ 558 559 Info->Count++; 560 if (Info->Count >= Info->MaxCount) 561 { 562 Status = AE_CTRL_TERMINATE; 563 } 564 565 return (Status); 566 } 567 568 569 /******************************************************************************* 570 * 571 * FUNCTION: AcpiDbBatchExecute 572 * 573 * PARAMETERS: CountArg - Max number of methods to execute 574 * 575 * RETURN: None 576 * 577 * DESCRIPTION: Namespace batch execution. Execute predefined names in the 578 * namespace, up to the max count, if specified. 579 * 580 ******************************************************************************/ 581 582 void 583 AcpiDbBatchExecute ( 584 char *CountArg) 585 { 586 ACPI_DB_EXECUTE_WALK Info; 587 588 589 Info.Count = 0; 590 Info.MaxCount = ACPI_UINT32_MAX; 591 592 if (CountArg) 593 { 594 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0); 595 } 596 597 598 /* Search all nodes in namespace */ 599 600 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, 601 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL); 602 603 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count); 604 } 605 606 #endif /* ACPI_DEBUGGER */ 607