Import acpica-20050211 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / debugger / dbcmds.c
blob0055b93b184f167f40f01673ac94d239905ee7ca
1 /*******************************************************************************
3 * Module Name: dbcmds - debug commands and output routines
4 * $Revision: 116 $
6 ******************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * 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.
115 *****************************************************************************/
118 #include "acpi.h"
119 #include "acdispat.h"
120 #include "amlcode.h"
121 #include "acnamesp.h"
122 #include "acevents.h"
123 #include "acdebug.h"
124 #include "acresrc.h"
125 #include "acdisasm.h"
128 #include "acparser.h"
130 #ifdef ACPI_DEBUGGER
132 #define _COMPONENT ACPI_CA_DEBUGGER
133 ACPI_MODULE_NAME ("dbcmds")
137 * Arguments for the Objects command
138 * These object types map directly to the ACPI_TYPES
141 static ARGUMENT_INFO AcpiDbObjectTypes [] =
143 {"ANY"},
144 {"NUMBERS"},
145 {"STRINGS"},
146 {"BUFFERS"},
147 {"PACKAGES"},
148 {"FIELDS"},
149 {"DEVICES"},
150 {"EVENTS"},
151 {"METHODS"},
152 {"MUTEXES"},
153 {"REGIONS"},
154 {"POWERRESOURCES"},
155 {"PROCESSORS"},
156 {"THERMALZONES"},
157 {"BUFFERFIELDS"},
158 {"DDBHANDLES"},
159 {NULL} /* Must be null terminated */
163 /*******************************************************************************
165 * FUNCTION: AcpiDbSleep
167 * PARAMETERS: ObjectArg - Desired sleep state (0-5)
169 * RETURN: Status
171 * DESCRIPTION: Simulate a sleep/wake sequence
173 ******************************************************************************/
175 ACPI_STATUS
176 AcpiDbSleep (
177 char *ObjectArg)
179 #if ACPI_MACHINE_WIDTH == 16
180 return (AE_OK);
181 #else
182 ACPI_STATUS Status;
183 UINT8 SleepState;
186 SleepState = (UINT8) ACPI_STRTOUL (ObjectArg, NULL, 0);
188 AcpiOsPrintf ("**** Prepare to sleep ****\n");
189 Status = AcpiEnterSleepStatePrep (SleepState);
190 if (ACPI_FAILURE (Status))
192 return (Status);
195 AcpiOsPrintf ("**** Going to sleep ****\n");
196 Status = AcpiEnterSleepState (SleepState);
197 if (ACPI_FAILURE (Status))
199 return (Status);
202 AcpiOsPrintf ("**** returning from sleep ****\n");
203 Status = AcpiLeaveSleepState (SleepState);
205 return (Status);
206 #endif
210 /*******************************************************************************
212 * FUNCTION: AcpiDbWalkForReferences
214 * PARAMETERS: Callback from WalkNamespace
216 * RETURN: Status
218 * DESCRIPTION: Check if this namespace object refers to the target object
219 * that is passed in as the context value.
221 * Note: Currently doesn't check subobjects within the Node's object
223 ******************************************************************************/
225 ACPI_STATUS
226 AcpiDbWalkForReferences (
227 ACPI_HANDLE ObjHandle,
228 UINT32 NestingLevel,
229 void *Context,
230 void **ReturnValue)
232 ACPI_OPERAND_OBJECT *ObjDesc = (ACPI_OPERAND_OBJECT *) Context;
233 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
236 /* Check for match against the namespace node itself */
238 if (Node == (void *) ObjDesc)
240 AcpiOsPrintf ("Object is a Node [%4.4s]\n",
241 AcpiUtGetNodeName (Node));
244 /* Check for match against the object attached to the node */
246 if (AcpiNsGetAttachedObject (Node) == ObjDesc)
248 AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
249 Node, AcpiUtGetNodeName (Node));
252 return (AE_OK);
256 /*******************************************************************************
258 * FUNCTION: AcpiDbFindReferences
260 * PARAMETERS: ObjectArg - String with hex value of the object
262 * RETURN: None
264 * DESCRIPTION: Search namespace for all references to the input object
266 ******************************************************************************/
268 void
269 AcpiDbFindReferences (
270 char *ObjectArg)
272 ACPI_OPERAND_OBJECT *ObjDesc;
275 /* Convert string to object pointer */
277 ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
279 /* Search all nodes in namespace */
281 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
282 AcpiDbWalkForReferences, (void *) ObjDesc, NULL);
286 /*******************************************************************************
288 * FUNCTION: AcpiDbDisplayLocks
290 * PARAMETERS: None
292 * RETURN: None
294 * DESCRIPTION: Display information about internal mutexes.
296 ******************************************************************************/
298 void
299 AcpiDbDisplayLocks (void)
301 UINT32 i;
304 for (i = 0; i < MAX_MUTEX; i++)
306 AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
307 AcpiGbl_MutexInfo[i].OwnerId == ACPI_MUTEX_NOT_ACQUIRED
308 ? "Locked" : "Unlocked");
313 /*******************************************************************************
315 * FUNCTION: AcpiDbDisplayTableInfo
317 * PARAMETERS: TableArg - String with name of table to be displayed
319 * RETURN: None
321 * DESCRIPTION: Display information about loaded tables. Current
322 * implementation displays all loaded tables.
324 ******************************************************************************/
326 void
327 AcpiDbDisplayTableInfo (
328 char *TableArg)
330 UINT32 i;
331 ACPI_TABLE_DESC *TableDesc;
334 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++)
336 TableDesc = AcpiGbl_TableLists[i].Next;
337 while (TableDesc)
339 AcpiOsPrintf ( "%s at %p length %.5X",
340 AcpiGbl_TableData[i].Name, TableDesc->Pointer,
341 (UINT32) TableDesc->Length);
343 if (i != ACPI_TABLE_FACS)
345 AcpiOsPrintf (" OemID=%6s TableId=%8s OemRevision=%8.8X",
346 TableDesc->Pointer->OemId,
347 TableDesc->Pointer->OemTableId,
348 TableDesc->Pointer->OemRevision);
350 AcpiOsPrintf ("\n");
352 TableDesc = TableDesc->Next;
358 /*******************************************************************************
360 * FUNCTION: AcpiDbUnloadAcpiTable
362 * PARAMETERS: TableArg - Name of the table to be unloaded
363 * InstanceArg - Which instance of the table to unload (if
364 * there are multiple tables of the same type)
366 * RETURN: Nonde
368 * DESCRIPTION: Unload an ACPI table.
369 * Instance is not implemented
371 ******************************************************************************/
373 void
374 AcpiDbUnloadAcpiTable (
375 char *TableArg,
376 char *InstanceArg)
378 UINT32 i;
379 ACPI_STATUS Status;
382 /* Search all tables for the target type */
384 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++)
386 if (!ACPI_STRNCMP (TableArg, AcpiGbl_TableData[i].Signature,
387 AcpiGbl_TableData[i].SigLength))
389 /* Found the table, unload it */
391 Status = AcpiUnloadTable (i);
392 if (ACPI_SUCCESS (Status))
394 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
396 else
398 AcpiOsPrintf ("%s, while unloading [%s]\n",
399 AcpiFormatException (Status), TableArg);
402 return;
406 AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
410 /*******************************************************************************
412 * FUNCTION: AcpiDbSetMethodBreakpoint
414 * PARAMETERS: Location - AML offset of breakpoint
415 * WalkState - Current walk info
416 * Op - Current Op (from parse walk)
418 * RETURN: None
420 * DESCRIPTION: Set a breakpoint in a control method at the specified
421 * AML offset
423 ******************************************************************************/
425 void
426 AcpiDbSetMethodBreakpoint (
427 char *Location,
428 ACPI_WALK_STATE *WalkState,
429 ACPI_PARSE_OBJECT *Op)
431 UINT32 Address;
434 if (!Op)
436 AcpiOsPrintf ("There is no method currently executing\n");
437 return;
440 /* Get and verify the breakpoint address */
442 Address = ACPI_STRTOUL (Location, NULL, 16);
443 if (Address <= Op->Common.AmlOffset)
445 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n", Address, Op->Common.AmlOffset);
448 /* Save breakpoint in current walk */
450 WalkState->UserBreakpoint = Address;
451 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
455 /*******************************************************************************
457 * FUNCTION: AcpiDbSetMethodCallBreakpoint
459 * PARAMETERS: Op - Current Op (from parse walk)
461 * RETURN: None
463 * DESCRIPTION: Set a breakpoint in a control method at the specified
464 * AML offset
466 ******************************************************************************/
468 void
469 AcpiDbSetMethodCallBreakpoint (
470 ACPI_PARSE_OBJECT *Op)
474 if (!Op)
476 AcpiOsPrintf ("There is no method currently executing\n");
477 return;
480 AcpiGbl_StepToNextCall = TRUE;
484 /*******************************************************************************
486 * FUNCTION: AcpiDbDisassembleAml
488 * PARAMETERS: Statements - Number of statements to disassemble
489 * Op - Current Op (from parse walk)
491 * RETURN: None
493 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
494 * of statements specified.
496 ******************************************************************************/
498 void
499 AcpiDbDisassembleAml (
500 char *Statements,
501 ACPI_PARSE_OBJECT *Op)
503 UINT32 NumStatements = 8;
506 if (!Op)
508 AcpiOsPrintf ("There is no method currently executing\n");
509 return;
512 if (Statements)
514 NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
517 AcpiDmDisassemble (NULL, Op, NumStatements);
521 /*******************************************************************************
523 * FUNCTION: AcpiDbDisassembleMethod
525 * PARAMETERS: Method - Name of control method
527 * RETURN: None
529 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
530 * of statements specified.
532 ******************************************************************************/
534 ACPI_STATUS
535 AcpiDbDisassembleMethod (
536 char *Name)
538 ACPI_STATUS Status;
539 ACPI_PARSE_OBJECT *Op;
540 ACPI_WALK_STATE *WalkState;
541 ACPI_OPERAND_OBJECT *ObjDesc;
542 ACPI_NAMESPACE_NODE *Method;
545 Method = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ACPI_STRTOUL (Name, NULL, 16));
546 if (!Method)
548 return (AE_BAD_PARAMETER);
551 ObjDesc = Method->Object;
553 Op = AcpiPsCreateScopeOp ();
554 if (!Op)
556 return (AE_NO_MEMORY);
559 /* Create and initialize a new walk state */
561 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
562 if (!WalkState)
564 return (AE_NO_MEMORY);
567 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
568 ObjDesc->Method.AmlStart,
569 ObjDesc->Method.AmlLength, NULL, 1);
570 if (ACPI_FAILURE (Status))
572 return (Status);
575 /* Parse the AML */
577 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
578 Status = AcpiPsParseAml (WalkState);
580 AcpiDmDisassemble (NULL, Op, 0);
581 AcpiPsDeleteParseTree (Op);
582 return (AE_OK);
586 /*******************************************************************************
588 * FUNCTION: AcpiDbDumpNamespace
590 * PARAMETERS: StartArg - Node to begin namespace dump
591 * DepthArg - Maximum tree depth to be dumped
593 * RETURN: None
595 * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
596 * with type and other information.
598 ******************************************************************************/
600 void
601 AcpiDbDumpNamespace (
602 char *StartArg,
603 char *DepthArg)
605 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
606 UINT32 MaxDepth = ACPI_UINT32_MAX;
609 /* No argument given, just start at the root and dump entire namespace */
611 if (StartArg)
613 /* Check if numeric argument, must be a Node */
615 if ((StartArg[0] >= 0x30) && (StartArg[0] <= 0x39))
617 SubtreeEntry = ACPI_TO_POINTER (ACPI_STRTOUL (StartArg, NULL, 16));
618 if (!AcpiOsReadable (SubtreeEntry, sizeof (ACPI_NAMESPACE_NODE)))
620 AcpiOsPrintf ("Address %p is invalid in this address space\n", SubtreeEntry);
621 return;
624 if (ACPI_GET_DESCRIPTOR_TYPE (SubtreeEntry) != ACPI_DESC_TYPE_NAMED)
626 AcpiOsPrintf ("Address %p is not a valid NS node [%s]\n",
627 SubtreeEntry, AcpiUtGetDescriptorName (SubtreeEntry));
628 return;
631 else
633 /* Alpha argument */
634 /* The parameter is a name string that must be resolved to a Named obj*/
636 SubtreeEntry = AcpiDbLocalNsLookup (StartArg);
637 if (!SubtreeEntry)
639 SubtreeEntry = AcpiGbl_RootNode;
643 /* Now we can check for the depth argument */
645 if (DepthArg)
647 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
651 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
652 AcpiOsPrintf ("ACPI Namespace (from %p subtree):\n", SubtreeEntry);
654 /* Display the subtree */
656 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
657 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, ACPI_UINT32_MAX, SubtreeEntry);
658 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
662 /*******************************************************************************
664 * FUNCTION: AcpiDbDumpNamespaceByOwner
666 * PARAMETERS: OwnerArg - Owner ID whose nodes will be displayed
667 * DepthArg - Maximum tree depth to be dumped
669 * RETURN: None
671 * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
673 ******************************************************************************/
675 void
676 AcpiDbDumpNamespaceByOwner (
677 char *OwnerArg,
678 char *DepthArg)
680 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
681 UINT32 MaxDepth = ACPI_UINT32_MAX;
682 UINT16 OwnerId;
685 OwnerId = (UINT16) ACPI_STRTOUL (OwnerArg, NULL, 0);
687 /* Now we can check for the depth argument */
689 if (DepthArg)
691 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
694 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
695 AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
697 /* Display the subtree */
699 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
700 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId, SubtreeEntry);
701 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
705 /*******************************************************************************
707 * FUNCTION: AcpiDbSendNotify
709 * PARAMETERS: Name - Name of ACPI object to send the notify to
710 * Value - Value of the notify to send.
712 * RETURN: None
714 * DESCRIPTION: Send an ACPI notification. The value specified is sent to the
715 * named object as an ACPI notify.
717 ******************************************************************************/
719 void
720 AcpiDbSendNotify (
721 char *Name,
722 UINT32 Value)
724 ACPI_NAMESPACE_NODE *Node;
725 ACPI_STATUS Status;
728 /* Translate name to an Named object */
730 Node = AcpiDbLocalNsLookup (Name);
731 if (!Node)
733 return;
736 /* Decode Named object type */
738 switch (Node->Type)
740 case ACPI_TYPE_DEVICE:
741 case ACPI_TYPE_THERMAL:
743 /* Send the notify */
745 Status = AcpiEvQueueNotifyRequest (Node, Value);
746 if (ACPI_FAILURE (Status))
748 AcpiOsPrintf ("Could not queue notify\n");
750 break;
752 default:
753 AcpiOsPrintf ("Named object is not a device or a thermal object\n");
754 break;
759 /*******************************************************************************
761 * FUNCTION: AcpiDbSetMethodData
763 * PARAMETERS: TypeArg - L for local, A for argument
764 * IndexArg - which one
765 * ValueArg - Value to set.
767 * RETURN: None
769 * DESCRIPTION: Set a local or argument for the running control method.
770 * NOTE: only object supported is Number.
772 ******************************************************************************/
774 void
775 AcpiDbSetMethodData (
776 char *TypeArg,
777 char *IndexArg,
778 char *ValueArg)
780 char Type;
781 UINT32 Index;
782 UINT32 Value;
783 ACPI_WALK_STATE *WalkState;
784 ACPI_OPERAND_OBJECT *ObjDesc;
785 ACPI_STATUS Status;
788 /* Validate TypeArg */
790 ACPI_STRUPR (TypeArg);
791 Type = TypeArg[0];
792 if ((Type != 'L') &&
793 (Type != 'A'))
795 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
796 return;
799 /* Get the index and value */
801 Index = ACPI_STRTOUL (IndexArg, NULL, 16);
802 Value = ACPI_STRTOUL (ValueArg, NULL, 16);
804 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
805 if (!WalkState)
807 AcpiOsPrintf ("There is no method currently executing\n");
808 return;
811 /* Create and initialize the new object */
813 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
814 if (!ObjDesc)
816 AcpiOsPrintf ("Could not create an internal object\n");
817 return;
820 ObjDesc->Integer.Value = Value;
822 /* Store the new object into the target */
824 switch (Type)
826 case 'A':
828 /* Set a method argument */
830 if (Index > ACPI_METHOD_MAX_ARG)
832 AcpiOsPrintf ("Arg%d - Invalid argument name\n", Index);
833 return;
836 Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, ObjDesc, WalkState);
837 if (ACPI_FAILURE (Status))
839 return;
842 ObjDesc = WalkState->Arguments[Index].Object;
844 AcpiOsPrintf ("Arg%d: ", Index);
845 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
846 break;
848 case 'L':
850 /* Set a method local */
852 if (Index > ACPI_METHOD_MAX_LOCAL)
854 AcpiOsPrintf ("Local%d - Invalid local variable name\n", Index);
855 return;
858 Status = AcpiDsStoreObjectToLocal (AML_LOCAL_OP, Index, ObjDesc, WalkState);
859 if (ACPI_FAILURE (Status))
861 return;
864 ObjDesc = WalkState->LocalVariables[Index].Object;
866 AcpiOsPrintf ("Local%d: ", Index);
867 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
868 break;
870 default:
871 break;
876 /*******************************************************************************
878 * FUNCTION: AcpiDbWalkForSpecificObjects
880 * PARAMETERS: Callback from WalkNamespace
882 * RETURN: Status
884 * DESCRIPTION: Display short info about objects in the namespace
886 ******************************************************************************/
888 ACPI_STATUS
889 AcpiDbWalkForSpecificObjects (
890 ACPI_HANDLE ObjHandle,
891 UINT32 NestingLevel,
892 void *Context,
893 void **ReturnValue)
895 ACPI_OPERAND_OBJECT *ObjDesc;
896 ACPI_STATUS Status;
897 ACPI_BUFFER Buffer;
900 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjHandle);
902 /* Get and display the full pathname to this object */
904 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
905 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
906 if (ACPI_FAILURE (Status))
908 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
909 return (AE_OK);
912 AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
913 ACPI_MEM_FREE (Buffer.Pointer);
915 /* Display short information about the object */
917 if (ObjDesc)
919 AcpiOsPrintf (" %p/%p", ObjHandle, ObjDesc);
921 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
923 case ACPI_TYPE_METHOD:
924 AcpiOsPrintf (" #Args %d Concurrency %X",
925 ObjDesc->Method.ParamCount, ObjDesc->Method.Concurrency);
926 break;
928 case ACPI_TYPE_INTEGER:
929 AcpiOsPrintf (" Value %8.8X%8.8X",
930 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
931 break;
933 case ACPI_TYPE_STRING:
934 AcpiOsPrintf (" \"%s\"", ObjDesc->String.Pointer);
935 break;
937 case ACPI_TYPE_REGION:
938 AcpiOsPrintf (" SpaceId %X Length %X Address %8.8X%8.8X",
939 ObjDesc->Region.SpaceId,
940 ObjDesc->Region.Length,
941 ACPI_FORMAT_UINT64 (ObjDesc->Region.Address));
942 break;
944 case ACPI_TYPE_PACKAGE:
945 AcpiOsPrintf (" #Elements %X", ObjDesc->Package.Count);
946 break;
948 case ACPI_TYPE_BUFFER:
949 AcpiOsPrintf (" Length %X", ObjDesc->Buffer.Length);
950 break;
952 default:
953 /* Ignore other object types */
954 break;
958 AcpiOsPrintf ("\n");
959 return (AE_OK);
963 /*******************************************************************************
965 * FUNCTION: AcpiDbDisplayObjects
967 * PARAMETERS: ObjTypeArg - Type of object to display
968 * DisplayCountArg - Max depth to display
970 * RETURN: None
972 * DESCRIPTION: Display objects in the namespace of the requested type
974 ******************************************************************************/
976 ACPI_STATUS
977 AcpiDbDisplayObjects (
978 char *ObjTypeArg,
979 char *DisplayCountArg)
981 ACPI_OBJECT_TYPE Type;
984 /* Get the object type */
986 Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
987 if (Type == ACPI_TYPE_NOT_FOUND)
989 AcpiOsPrintf ("Invalid or unsupported argument\n");
990 return (AE_OK);
993 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
994 AcpiOsPrintf ("Objects of type [%s] defined in the current ACPI Namespace: \n",
995 AcpiUtGetTypeName (Type));
997 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
999 /* Walk the namespace from the root */
1001 (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1002 AcpiDbWalkForSpecificObjects, (void *) &Type, NULL);
1004 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1005 return (AE_OK);
1009 /*******************************************************************************
1011 * FUNCTION: AcpiDbWalkAndMatchName
1013 * PARAMETERS: Callback from WalkNamespace
1015 * RETURN: Status
1017 * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
1018 * are supported -- '?' matches any character.
1020 ******************************************************************************/
1022 ACPI_STATUS
1023 AcpiDbWalkAndMatchName (
1024 ACPI_HANDLE ObjHandle,
1025 UINT32 NestingLevel,
1026 void *Context,
1027 void **ReturnValue)
1029 ACPI_STATUS Status;
1030 char *RequestedName = (char *) Context;
1031 UINT32 i;
1032 ACPI_BUFFER Buffer;
1035 /* Check for a name match */
1037 for (i = 0; i < 4; i++)
1039 /* Wildcard support */
1041 if ((RequestedName[i] != '?') &&
1042 (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
1044 /* No match, just exit */
1046 return (AE_OK);
1050 /* Get the full pathname to this object */
1052 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1053 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
1054 if (ACPI_FAILURE (Status))
1056 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
1058 else
1060 AcpiOsPrintf ("%32s (%p) - %s\n", (char *) Buffer.Pointer, ObjHandle,
1061 AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) ObjHandle)->Type));
1062 ACPI_MEM_FREE (Buffer.Pointer);
1065 return (AE_OK);
1069 /*******************************************************************************
1071 * FUNCTION: AcpiDbFindNameInNamespace
1073 * PARAMETERS: NameArg - The 4-character ACPI name to find.
1074 * wildcards are supported.
1076 * RETURN: None
1078 * DESCRIPTION: Search the namespace for a given name (with wildcards)
1080 ******************************************************************************/
1082 ACPI_STATUS
1083 AcpiDbFindNameInNamespace (
1084 char *NameArg)
1087 if (ACPI_STRLEN (NameArg) > 4)
1089 AcpiOsPrintf ("Name must be no longer than 4 characters\n");
1090 return (AE_OK);
1093 /* Walk the namespace from the root */
1095 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1096 AcpiDbWalkAndMatchName, NameArg, NULL);
1098 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1099 return (AE_OK);
1103 /*******************************************************************************
1105 * FUNCTION: AcpiDbSetScope
1107 * PARAMETERS: Name - New scope path
1109 * RETURN: Status
1111 * DESCRIPTION: Set the "current scope" as maintained by this utility.
1112 * The scope is used as a prefix to ACPI paths.
1114 ******************************************************************************/
1116 void
1117 AcpiDbSetScope (
1118 char *Name)
1120 ACPI_STATUS Status;
1121 ACPI_NAMESPACE_NODE *Node;
1124 if (!Name || Name[0] == 0)
1126 AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
1127 return;
1130 AcpiDbPrepNamestring (Name);
1132 if (Name[0] == '\\')
1134 /* Validate new scope from the root */
1136 Status = AcpiNsGetNodeByPath (Name, AcpiGbl_RootNode, ACPI_NS_NO_UPSEARCH, &Node);
1137 if (ACPI_FAILURE (Status))
1139 goto ErrorExit;
1142 ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
1143 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1145 else
1147 /* Validate new scope relative to old scope */
1149 Status = AcpiNsGetNodeByPath (Name, AcpiGbl_DbScopeNode, ACPI_NS_NO_UPSEARCH, &Node);
1150 if (ACPI_FAILURE (Status))
1152 goto ErrorExit;
1155 ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
1156 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1159 AcpiGbl_DbScopeNode = Node;
1160 AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
1161 return;
1163 ErrorExit:
1165 AcpiOsPrintf ("Could not attach scope: %s, %s\n", Name, AcpiFormatException (Status));
1169 /*******************************************************************************
1171 * FUNCTION: AcpiDbDisplayResources
1173 * PARAMETERS: ObjectArg - String with hex value of the object
1175 * RETURN: None
1177 * DESCRIPTION: Display the resource objects associated with a device.
1179 ******************************************************************************/
1181 void
1182 AcpiDbDisplayResources (
1183 char *ObjectArg)
1185 #if ACPI_MACHINE_WIDTH != 16
1187 ACPI_OPERAND_OBJECT *ObjDesc;
1188 ACPI_STATUS Status;
1189 ACPI_BUFFER ReturnObj;
1192 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1193 AcpiDbgLevel |= ACPI_LV_RESOURCES;
1195 /* Convert string to object pointer */
1197 ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
1199 /* Prepare for a return object of arbitrary size */
1201 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1202 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1204 /* _PRT */
1206 AcpiOsPrintf ("Evaluating _PRT\n");
1208 Status = AcpiEvaluateObject (ObjDesc, "_PRT", NULL, &ReturnObj);
1209 if (ACPI_FAILURE (Status))
1211 AcpiOsPrintf ("Could not obtain _PRT: %s\n", AcpiFormatException (Status));
1212 goto GetCrs;
1215 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1216 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1218 Status = AcpiGetIrqRoutingTable (ObjDesc, &ReturnObj);
1219 if (ACPI_FAILURE (Status))
1221 AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n", AcpiFormatException (Status));
1223 else
1225 AcpiRsDumpIrqList ((UINT8 *) AcpiGbl_DbBuffer);
1229 /* _CRS */
1231 GetCrs:
1232 AcpiOsPrintf ("Evaluating _CRS\n");
1234 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1235 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1237 Status = AcpiEvaluateObject (ObjDesc, "_CRS", NULL, &ReturnObj);
1238 if (ACPI_FAILURE (Status))
1240 AcpiOsPrintf ("Could not obtain _CRS: %s\n", AcpiFormatException (Status));
1241 goto GetPrs;
1244 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1245 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1247 Status = AcpiGetCurrentResources (ObjDesc, &ReturnObj);
1248 if (ACPI_FAILURE (Status))
1250 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n", AcpiFormatException (Status));
1251 goto GetPrs;
1253 else
1255 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1258 Status = AcpiSetCurrentResources (ObjDesc, &ReturnObj);
1259 if (ACPI_FAILURE (Status))
1261 AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n", AcpiFormatException (Status));
1262 goto GetPrs;
1266 /* _PRS */
1268 GetPrs:
1269 AcpiOsPrintf ("Evaluating _PRS\n");
1271 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1272 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1274 Status = AcpiEvaluateObject (ObjDesc, "_PRS", NULL, &ReturnObj);
1275 if (ACPI_FAILURE (Status))
1277 AcpiOsPrintf ("Could not obtain _PRS: %s\n", AcpiFormatException (Status));
1278 goto Cleanup;
1281 ReturnObj.Pointer = AcpiGbl_DbBuffer;
1282 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
1284 Status = AcpiGetPossibleResources (ObjDesc, &ReturnObj);
1285 if (ACPI_FAILURE (Status))
1287 AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n", AcpiFormatException (Status));
1289 else
1291 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1294 Cleanup:
1296 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1297 return;
1298 #endif
1302 /*******************************************************************************
1304 * FUNCTION: AcpiDbIntegrityWalk
1306 * PARAMETERS: Callback from WalkNamespace
1308 * RETURN: Status
1310 * DESCRIPTION: Examine one NS node for valid values.
1312 ******************************************************************************/
1314 ACPI_STATUS
1315 AcpiDbIntegrityWalk (
1316 ACPI_HANDLE ObjHandle,
1317 UINT32 NestingLevel,
1318 void *Context,
1319 void **ReturnValue)
1321 ACPI_INTEGRITY_INFO *Info = (ACPI_INTEGRITY_INFO *) Context;
1322 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1323 ACPI_OPERAND_OBJECT *Object;
1326 Info->Nodes++;
1327 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
1329 AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s]\n",
1330 Node, AcpiUtGetDescriptorName (Node));
1333 if (Node->Type > ACPI_TYPE_LOCAL_MAX)
1335 AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
1336 Node, Node->Type);
1339 if (!AcpiUtValidAcpiName (Node->Name.Integer))
1341 AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
1344 Object = AcpiNsGetAttachedObject (Node);
1345 if (Object)
1347 Info->Objects++;
1348 if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
1350 AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
1351 Object, AcpiUtGetDescriptorName (Object));
1355 return (AE_OK);
1359 /*******************************************************************************
1361 * FUNCTION: AcpiDbCheckIntegrity
1363 * PARAMETERS: None
1365 * RETURN: None
1367 * DESCRIPTION: Check entire namespace for data structure integrity
1369 ******************************************************************************/
1371 void
1372 AcpiDbCheckIntegrity (void)
1374 ACPI_INTEGRITY_INFO Info = {0,0};
1376 /* Search all nodes in namespace */
1378 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1379 AcpiDbIntegrityWalk, (void *) &Info, NULL);
1381 AcpiOsPrintf ("Verified %d namespace nodes with %d Objects\n", Info.Nodes, Info.Objects);
1385 /*******************************************************************************
1387 * FUNCTION: AcpiDbGenerateGpe
1389 * PARAMETERS: None
1391 * RETURN: None
1393 * DESCRIPTION: Generate a GPE
1395 ******************************************************************************/
1397 void
1398 AcpiDbGenerateGpe (
1399 char *GpeArg,
1400 char *BlockArg)
1402 UINT32 BlockNumber;
1403 UINT32 GpeNumber;
1404 ACPI_GPE_EVENT_INFO *GpeEventInfo;
1407 GpeNumber = ACPI_STRTOUL (GpeArg, NULL, 0);
1408 BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 0);
1411 GpeEventInfo = AcpiEvGetGpeEventInfo (ACPI_TO_POINTER (BlockNumber), GpeNumber);
1412 if (!GpeEventInfo)
1414 AcpiOsPrintf ("Invalid GPE\n");
1415 return;
1418 (void) AcpiEvGpeDispatch (GpeEventInfo, GpeNumber);
1421 #endif /* ACPI_DEBUGGER */