1 /*******************************************************************************
2 *
3 * Module Name: dbmethod - Debug commands for control methods
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, 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.
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 "acpi.h"
46 #include "accommon.h"
47 #include "acdispat.h"
48 #include "acnamesp.h"
49 #include "acdebug.h"
50 #include "acdisasm.h"
51 #include "acparser.h"
52
53
54 #ifdef ACPI_DEBUGGER
55
56 #define _COMPONENT ACPI_CA_DEBUGGER
57 ACPI_MODULE_NAME ("dbmethod")
58
59
60 /* Local prototypes */
61
62 static ACPI_STATUS
63 AcpiDbWalkForExecute (
64 ACPI_HANDLE ObjHandle,
65 UINT32 NestingLevel,
66 void *Context,
67 void **ReturnValue);
68
69
70 /*******************************************************************************
71 *
253 if (Index > ACPI_METHOD_MAX_LOCAL)
254 {
255 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
256 goto Cleanup;
257 }
258
259 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
260 WalkState);
261 if (ACPI_FAILURE (Status))
262 {
263 goto Cleanup;
264 }
265
266 ObjDesc = WalkState->LocalVariables[Index].Object;
267
268 AcpiOsPrintf ("Local%u: ", Index);
269 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
270 break;
271
272 default:
273 break;
274 }
275
276 Cleanup:
277 AcpiUtRemoveReference (ObjDesc);
278 }
279
280
281 /*******************************************************************************
282 *
283 * FUNCTION: AcpiDbDisassembleAml
284 *
285 * PARAMETERS: Statements - Number of statements to disassemble
286 * Op - Current Op (from parse walk)
287 *
288 * RETURN: None
289 *
290 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
291 * of statements specified.
292 *
328 *
329 ******************************************************************************/
330
331 ACPI_STATUS
332 AcpiDbDisassembleMethod (
333 char *Name)
334 {
335 ACPI_STATUS Status;
336 ACPI_PARSE_OBJECT *Op;
337 ACPI_WALK_STATE *WalkState;
338 ACPI_OPERAND_OBJECT *ObjDesc;
339 ACPI_NAMESPACE_NODE *Method;
340
341
342 Method = AcpiDbConvertToNode (Name);
343 if (!Method)
344 {
345 return (AE_BAD_PARAMETER);
346 }
347
348 ObjDesc = Method->Object;
349
350 Op = AcpiPsCreateScopeOp ();
351 if (!Op)
352 {
353 return (AE_NO_MEMORY);
354 }
355
356 /* Create and initialize a new walk state */
357
358 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
359 if (!WalkState)
360 {
361 return (AE_NO_MEMORY);
362 }
363
364 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
365 ObjDesc->Method.AmlStart,
366 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
367 if (ACPI_FAILURE (Status))
368 {
369 return (Status);
370 }
371
372 /* Parse the AML */
373
374 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
375 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
376 Status = AcpiPsParseAml (WalkState);
377
378 AcpiDmDisassemble (NULL, Op, 0);
379 AcpiPsDeleteParseTree (Op);
380 return (AE_OK);
381 }
382
383
384 /*******************************************************************************
385 *
386 * FUNCTION: AcpiDbWalkForExecute
387 *
388 * PARAMETERS: Callback from WalkNamespace
389 *
390 * RETURN: Status
391 *
392 * DESCRIPTION: Batch execution module. Currently only executes predefined
393 * ACPI names.
394 *
395 ******************************************************************************/
396
397 static ACPI_STATUS
398 AcpiDbWalkForExecute (
399 ACPI_HANDLE ObjHandle,
400 UINT32 NestingLevel,
401 void *Context,
402 void **ReturnValue)
403 {
404 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
405 ACPI_EXECUTE_WALK *Info = (ACPI_EXECUTE_WALK *) Context;
406 ACPI_BUFFER ReturnObj;
407 ACPI_STATUS Status;
408 char *Pathname;
409 UINT32 i;
410 ACPI_DEVICE_INFO *ObjInfo;
411 ACPI_OBJECT_LIST ParamObjects;
412 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
413 const ACPI_PREDEFINED_INFO *Predefined;
414
415
416 Predefined = AcpiNsCheckForPredefinedName (Node);
417 if (!Predefined)
418 {
419 return (AE_OK);
420 }
421
422 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
423 {
424 return (AE_OK);
425 }
426
427 Pathname = AcpiNsGetExternalPathname (Node);
428 if (!Pathname)
429 {
430 return (AE_OK);
431 }
432
433 /* Get the object info for number of method parameters */
434
435 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
436 if (ACPI_FAILURE (Status))
437 {
438 return (Status);
439 }
440
441 ParamObjects.Pointer = NULL;
442 ParamObjects.Count = 0;
443
444 if (ObjInfo->Type == ACPI_TYPE_METHOD)
445 {
446 /* Setup default parameters */
447
448 for (i = 0; i < ObjInfo->ParamCount; i++)
449 {
450 Params[i].Type = ACPI_TYPE_INTEGER;
451 Params[i].Integer.Value = 1;
452 }
453
454 ParamObjects.Pointer = Params;
455 ParamObjects.Count = ObjInfo->ParamCount;
456 }
457
458 ACPI_FREE (ObjInfo);
459 ReturnObj.Pointer = NULL;
460 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
461
462 /* Do the actual method execution */
463
464 AcpiGbl_MethodExecuting = TRUE;
465
466 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
467
468 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
469 AcpiGbl_MethodExecuting = FALSE;
470 ACPI_FREE (Pathname);
471
472 /* Ignore status from method execution */
473
474 Status = AE_OK;
475
485 }
486
487
488 /*******************************************************************************
489 *
490 * FUNCTION: AcpiDbBatchExecute
491 *
492 * PARAMETERS: CountArg - Max number of methods to execute
493 *
494 * RETURN: None
495 *
496 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
497 * namespace, up to the max count, if specified.
498 *
499 ******************************************************************************/
500
501 void
502 AcpiDbBatchExecute (
503 char *CountArg)
504 {
505 ACPI_EXECUTE_WALK Info;
506
507
508 Info.Count = 0;
509 Info.MaxCount = ACPI_UINT32_MAX;
510
511 if (CountArg)
512 {
513 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
514 }
515
516
517 /* Search all nodes in namespace */
518
519 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
520 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
521
522 AcpiOsPrintf ("Executed %u predefined names in the namespace\n", Info.Count);
523 }
524
525 #endif /* ACPI_DEBUGGER */
|
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.
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 "acpi.h"
46 #include "accommon.h"
47 #include "acdispat.h"
48 #include "acnamesp.h"
49 #include "acdebug.h"
50 #include "acdisasm.h"
51 #include "acparser.h"
52 #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 *
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 *
330 *
331 ******************************************************************************/
332
333 ACPI_STATUS
334 AcpiDbDisassembleMethod (
335 char *Name)
336 {
337 ACPI_STATUS Status;
338 ACPI_PARSE_OBJECT *Op;
339 ACPI_WALK_STATE *WalkState;
340 ACPI_OPERAND_OBJECT *ObjDesc;
341 ACPI_NAMESPACE_NODE *Method;
342
343
344 Method = AcpiDbConvertToNode (Name);
345 if (!Method)
346 {
347 return (AE_BAD_PARAMETER);
348 }
349
350 if (Method->Type != ACPI_TYPE_METHOD)
351 {
352 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
353 Name, AcpiUtGetTypeName (Method->Type)));
354 return (AE_BAD_PARAMETER);
355 }
356
357 ObjDesc = Method->Object;
358
359 Op = AcpiPsCreateScopeOp ();
360 if (!Op)
361 {
362 return (AE_NO_MEMORY);
363 }
364
365 /* Create and initialize a new walk state */
366
367 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
368 if (!WalkState)
369 {
370 return (AE_NO_MEMORY);
371 }
372
373 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
374 ObjDesc->Method.AmlStart,
375 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
376 if (ACPI_FAILURE (Status))
377 {
378 return (Status);
379 }
380
381 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
382 WalkState->OwnerId = ObjDesc->Method.OwnerId;
383
384 /* Push start scope on scope stack and make it current */
385
386 Status = AcpiDsScopeStackPush (Method,
387 Method->Type, WalkState);
388 if (ACPI_FAILURE (Status))
389 {
390 return (Status);
391 }
392
393 /* Parse the entire method AML including deferred operators */
394
395 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
396 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
397
398 Status = AcpiPsParseAml (WalkState);
399 (void) AcpiDmParseDeferredOps (Op);
400
401 /* Now we can disassemble the method */
402
403 AcpiGbl_DbOpt_verbose = FALSE;
404 AcpiDmDisassemble (NULL, Op, 0);
405 AcpiGbl_DbOpt_verbose = TRUE;
406
407 AcpiPsDeleteParseTree (Op);
408
409 /* Method cleanup */
410
411 AcpiNsDeleteNamespaceSubtree (Method);
412 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
413 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
414 return (AE_OK);
415 }
416
417
418 /*******************************************************************************
419 *
420 * FUNCTION: AcpiDbWalkForExecute
421 *
422 * PARAMETERS: Callback from WalkNamespace
423 *
424 * RETURN: Status
425 *
426 * DESCRIPTION: Batch execution module. Currently only executes predefined
427 * ACPI names.
428 *
429 ******************************************************************************/
430
431 static ACPI_STATUS
432 AcpiDbWalkForExecute (
433 ACPI_HANDLE ObjHandle,
434 UINT32 NestingLevel,
435 void *Context,
436 void **ReturnValue)
437 {
438 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
439 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
440 char *Pathname;
441 const ACPI_PREDEFINED_INFO *Predefined;
442 ACPI_DEVICE_INFO *ObjInfo;
443 ACPI_OBJECT_LIST ParamObjects;
444 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
445 ACPI_OBJECT *ThisParam;
446 ACPI_BUFFER ReturnObj;
447 ACPI_STATUS Status;
448 UINT16 ArgTypeList;
449 UINT8 ArgCount;
450 UINT8 ArgType;
451 UINT32 i;
452
453
454 /* The name must be a predefined ACPI name */
455
456 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
457 if (!Predefined)
458 {
459 return (AE_OK);
460 }
461
462 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
463 {
464 return (AE_OK);
465 }
466
467 Pathname = AcpiNsGetExternalPathname (Node);
468 if (!Pathname)
469 {
470 return (AE_OK);
471 }
472
473 /* Get the object info for number of method parameters */
474
475 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
476 if (ACPI_FAILURE (Status))
477 {
478 return (Status);
479 }
480
481 ParamObjects.Count = 0;
482 ParamObjects.Pointer = NULL;
483
484 if (ObjInfo->Type == ACPI_TYPE_METHOD)
485 {
486 /* Setup default parameters (with proper types) */
487
488 ArgTypeList = Predefined->Info.ArgumentList;
489 ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
490
491 /*
492 * Setup the ACPI-required number of arguments, regardless of what
493 * the actual method defines. If there is a difference, then the
494 * method is wrong and a warning will be issued during execution.
495 */
496 ThisParam = Params;
497 for (i = 0; i < ArgCount; i++)
498 {
499 ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
500 ThisParam->Type = ArgType;
501
502 switch (ArgType)
503 {
504 case ACPI_TYPE_INTEGER:
505
506 ThisParam->Integer.Value = 1;
507 break;
508
509 case ACPI_TYPE_STRING:
510
511 ThisParam->String.Pointer = "This is the default argument string";
512 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer);
513 break;
514
515 case ACPI_TYPE_BUFFER:
516
517 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
518 ThisParam->Buffer.Length = 48;
519 break;
520
521 case ACPI_TYPE_PACKAGE:
522
523 ThisParam->Package.Elements = NULL;
524 ThisParam->Package.Count = 0;
525 break;
526
527 default:
528
529 AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
530 Pathname, ArgType);
531 break;
532 }
533
534 ThisParam++;
535 }
536
537 ParamObjects.Count = ArgCount;
538 ParamObjects.Pointer = Params;
539 }
540
541 ACPI_FREE (ObjInfo);
542 ReturnObj.Pointer = NULL;
543 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
544
545 /* Do the actual method execution */
546
547 AcpiGbl_MethodExecuting = TRUE;
548
549 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
550
551 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
552 AcpiGbl_MethodExecuting = FALSE;
553 ACPI_FREE (Pathname);
554
555 /* Ignore status from method execution */
556
557 Status = AE_OK;
558
568 }
569
570
571 /*******************************************************************************
572 *
573 * FUNCTION: AcpiDbBatchExecute
574 *
575 * PARAMETERS: CountArg - Max number of methods to execute
576 *
577 * RETURN: None
578 *
579 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
580 * namespace, up to the max count, if specified.
581 *
582 ******************************************************************************/
583
584 void
585 AcpiDbBatchExecute (
586 char *CountArg)
587 {
588 ACPI_DB_EXECUTE_WALK Info;
589
590
591 Info.Count = 0;
592 Info.MaxCount = ACPI_UINT32_MAX;
593
594 if (CountArg)
595 {
596 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
597 }
598
599
600 /* Search all nodes in namespace */
601
602 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
603 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
604
605 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
606 }
607
608 #endif /* ACPI_DEBUGGER */
|