Merge from vendor branch LIBSTDC++:
[dragonfly.git] / sys / contrib / dev / acpica / dbcmds.c
1 /*******************************************************************************
2  *
3  * Module Name: dbcmds - debug commands and output routines
4  *              $Revision: 97 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
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.
21  *
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
28  *
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;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
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.
54  *
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.
66  *
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.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
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.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
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.
90  *
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.
99  *
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.
114  *
115  *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dbcmds.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $                                                                     */
117
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"
126
127 #ifdef ACPI_DEBUGGER
128
129 #define _COMPONENT          ACPI_CA_DEBUGGER
130         ACPI_MODULE_NAME    ("dbcmds")
131
132
133 /*
134  * Arguments for the Objects command
135  * These object types map directly to the ACPI_TYPES
136  */
137
138 static ARGUMENT_INFO        AcpiDbObjectTypes [] =
139 {
140     {"ANY"},
141     {"NUMBERS"},
142     {"STRINGS"},
143     {"BUFFERS"},
144     {"PACKAGES"},
145     {"FIELDS"},
146     {"DEVICES"},
147     {"EVENTS"},
148     {"METHODS"},
149     {"MUTEXES"},
150     {"REGIONS"},
151     {"POWERRESOURCES"},
152     {"PROCESSORS"},
153     {"THERMALZONES"},
154     {"BUFFERFIELDS"},
155     {"DDBHANDLES"},
156     {NULL}           /* Must be null terminated */
157 };
158
159
160 /*******************************************************************************
161  *
162  * FUNCTION:    AcpiDbWalkForReferences
163  *
164  * PARAMETERS:  Callback from WalkNamespace
165  *
166  * RETURN:      Status
167  *
168  * DESCRIPTION: Check if this namespace object refers to the target object
169  *              that is passed in as the context value.
170  *
171  * Note: Currently doesn't check subobjects within the Node's object
172  *
173  ******************************************************************************/
174
175 ACPI_STATUS
176 AcpiDbWalkForReferences (
177     ACPI_HANDLE             ObjHandle,
178     UINT32                  NestingLevel,
179     void                    *Context,
180     void                    **ReturnValue)
181 {
182     ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
183     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
184
185
186     /* Check for match against the namespace node itself */
187
188     if (Node == (void *) ObjDesc)
189     {
190         AcpiOsPrintf ("Object is a Node [%4.4s]\n", Node->Name.Ascii);
191     }
192
193     /* Check for match against the object attached to the node */
194
195     if (AcpiNsGetAttachedObject (Node) == ObjDesc)
196     {
197         AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n", Node, Node->Name.Ascii);
198     }
199
200     return (AE_OK);
201 }
202
203
204 /*******************************************************************************
205  *
206  * FUNCTION:    AcpiDbFindReferences
207  *
208  * PARAMETERS:  ObjectArg       - String with hex value of the object
209  *
210  * RETURN:      None
211  *
212  * DESCRIPTION: Search namespace for all references to the input object
213  *
214  ******************************************************************************/
215
216 void
217 AcpiDbFindReferences (
218     char                    *ObjectArg)
219 {
220     ACPI_OPERAND_OBJECT     *ObjDesc;
221
222
223     /* Convert string to object pointer */
224
225     ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
226
227     /* Search all nodes in namespace */
228
229     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
230                     AcpiDbWalkForReferences, (void *) ObjDesc, NULL);
231 }
232
233
234 /*******************************************************************************
235  *
236  * FUNCTION:    AcpiDbDisplayLocks
237  *
238  * PARAMETERS:  None
239  *
240  * RETURN:      None
241  *
242  * DESCRIPTION: Display information about internal mutexes.
243  *
244  ******************************************************************************/
245
246 void
247 AcpiDbDisplayLocks (void)
248 {
249     UINT32                  i;
250
251
252     for (i = 0; i < MAX_MTX; i++)
253     {
254         AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
255                     AcpiGbl_AcpiMutexInfo[i].OwnerId == ACPI_MUTEX_NOT_ACQUIRED
256                         ? "Locked" : "Unlocked");
257     }
258 }
259
260
261 /*******************************************************************************
262  *
263  * FUNCTION:    AcpiDbDisplayTableInfo
264  *
265  * PARAMETERS:  TableArg        - String with name of table to be displayed
266  *
267  * RETURN:      None
268  *
269  * DESCRIPTION: Display information about loaded tables.  Current
270  *              implementation displays all loaded tables.
271  *
272  ******************************************************************************/
273
274 void
275 AcpiDbDisplayTableInfo (
276     char                    *TableArg)
277 {
278     UINT32                  i;
279
280
281     for (i = 0; i < NUM_ACPI_TABLES; i++)
282     {
283         if (AcpiGbl_AcpiTables[i].Pointer)
284         {
285             AcpiOsPrintf ("%s at %p length %X\n", AcpiGbl_AcpiTableData[i].Name,
286                         AcpiGbl_AcpiTables[i].Pointer,
287                         (UINT32) AcpiGbl_AcpiTables[i].Length);
288         }
289     }
290 }
291
292
293 /*******************************************************************************
294  *
295  * FUNCTION:    AcpiDbUnloadAcpiTable
296  *
297  * PARAMETERS:  TableArg        - Name of the table to be unloaded
298  *              InstanceArg     - Which instance of the table to unload (if
299  *                                there are multiple tables of the same type)
300  *
301  * RETURN:      Nonde
302  *
303  * DESCRIPTION: Unload an ACPI table.
304  *              Instance is not implemented
305  *
306  ******************************************************************************/
307
308 void
309 AcpiDbUnloadAcpiTable (
310     char                    *TableArg,
311     char                    *InstanceArg)
312 {
313     UINT32                  i;
314     ACPI_STATUS             Status;
315
316
317     /* Search all tables for the target type */
318
319     for (i = 0; i < NUM_ACPI_TABLES; i++)
320     {
321         if (!ACPI_STRNCMP (TableArg, AcpiGbl_AcpiTableData[i].Signature,
322                 AcpiGbl_AcpiTableData[i].SigLength))
323         {
324             /* Found the table, unload it */
325
326             Status = AcpiUnloadTable (i);
327             if (ACPI_SUCCESS (Status))
328             {
329                 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
330             }
331             else
332             {
333                 AcpiOsPrintf ("%s, while unloading [%s]\n",
334                     AcpiFormatException (Status), TableArg);
335             }
336
337             return;
338         }
339     }
340
341     AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
342 }
343
344
345 /*******************************************************************************
346  *
347  * FUNCTION:    AcpiDbSetMethodBreakpoint
348  *
349  * PARAMETERS:  Location            - AML offset of breakpoint
350  *              WalkState           - Current walk info
351  *              Op                  - Current Op (from parse walk)
352  *
353  * RETURN:      None
354  *
355  * DESCRIPTION: Set a breakpoint in a control method at the specified
356  *              AML offset
357  *
358  ******************************************************************************/
359
360 void
361 AcpiDbSetMethodBreakpoint (
362     char                    *Location,
363     ACPI_WALK_STATE         *WalkState,
364     ACPI_PARSE_OBJECT       *Op)
365 {
366     UINT32                  Address;
367
368
369     if (!Op)
370     {
371         AcpiOsPrintf ("There is no method currently executing\n");
372         return;
373     }
374
375     /* Get and verify the breakpoint address */
376
377     Address = ACPI_STRTOUL (Location, NULL, 16);
378     if (Address <= Op->Common.AmlOffset)
379     {
380         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n", Address, Op->Common.AmlOffset);
381     }
382
383     /* Save breakpoint in current walk */
384
385     WalkState->UserBreakpoint = Address;
386     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
387 }
388
389
390 /*******************************************************************************
391  *
392  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
393  *
394  * PARAMETERS:  Op                  - Current Op (from parse walk)
395  *
396  * RETURN:      None
397  *
398  * DESCRIPTION: Set a breakpoint in a control method at the specified
399  *              AML offset
400  *
401  ******************************************************************************/
402
403 void
404 AcpiDbSetMethodCallBreakpoint (
405     ACPI_PARSE_OBJECT       *Op)
406 {
407
408
409     if (!Op)
410     {
411         AcpiOsPrintf ("There is no method currently executing\n");
412         return;
413     }
414
415     AcpiGbl_StepToNextCall = TRUE;
416 }
417
418
419 /*******************************************************************************
420  *
421  * FUNCTION:    AcpiDbDisassembleAml
422  *
423  * PARAMETERS:  Statements          - Number of statements to disassemble
424  *              Op                  - Current Op (from parse walk)
425  *
426  * RETURN:      None
427  *
428  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
429  *              of statements specified.
430  *
431  ******************************************************************************/
432
433 void
434 AcpiDbDisassembleAml (
435     char                    *Statements,
436     ACPI_PARSE_OBJECT       *Op)
437 {
438     UINT32                  NumStatements = 8;
439
440
441     if (!Op)
442     {
443         AcpiOsPrintf ("There is no method currently executing\n");
444         return;
445     }
446
447     if (Statements)
448     {
449         NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
450     }
451
452 #ifdef ACPI_DISASSEMBLER
453     AcpiDmDisassemble (NULL, Op, NumStatements);
454 #endif
455 }
456
457
458 /*******************************************************************************
459  *
460  * FUNCTION:    AcpiDbDumpNamespace
461  *
462  * PARAMETERS:  StartArg        - Node to begin namespace dump
463  *              DepthArg        - Maximum tree depth to be dumped
464  *
465  * RETURN:      None
466  *
467  * DESCRIPTION: Dump entire namespace or a subtree.  Each node is displayed
468  *              with type and other information.
469  *
470  ******************************************************************************/
471
472 void
473 AcpiDbDumpNamespace (
474     char                    *StartArg,
475     char                    *DepthArg)
476 {
477     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
478     UINT32                  MaxDepth = ACPI_UINT32_MAX;
479
480
481     /* No argument given, just start at the root and dump entire namespace */
482
483     if (StartArg)
484     {
485         /* Check if numeric argument, must be a Node */
486
487         if ((StartArg[0] >= 0x30) && (StartArg[0] <= 0x39))
488         {
489             SubtreeEntry = ACPI_TO_POINTER (ACPI_STRTOUL (StartArg, NULL, 16));
490             if (!AcpiOsReadable (SubtreeEntry, sizeof (ACPI_NAMESPACE_NODE)))
491             {
492                 AcpiOsPrintf ("Address %p is invalid in this address space\n", SubtreeEntry);
493                 return;
494             }
495
496             if (ACPI_GET_DESCRIPTOR_TYPE (SubtreeEntry) != ACPI_DESC_TYPE_NAMED)
497             {
498                 AcpiOsPrintf ("Address %p is not a valid Named object\n", SubtreeEntry);
499                 return;
500             }
501         }
502
503         /* Alpha argument */
504
505         else
506         {
507             /* The parameter is a name string that must be resolved to a Named obj*/
508
509             SubtreeEntry = AcpiDbLocalNsLookup (StartArg);
510             if (!SubtreeEntry)
511             {
512                 SubtreeEntry = AcpiGbl_RootNode;
513             }
514         }
515
516         /* Now we can check for the depth argument */
517
518         if (DepthArg)
519         {
520             MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
521         }
522     }
523
524     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
525     AcpiOsPrintf ("ACPI Namespace (from %p subtree):\n", SubtreeEntry);
526
527     /* Display the subtree */
528
529     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
530     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, ACPI_UINT32_MAX, SubtreeEntry);
531     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
532 }
533
534
535 /*******************************************************************************
536  *
537  * FUNCTION:    AcpiDbDumpNamespaceByOwner
538  *
539  * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
540  *              DepthArg        - Maximum tree depth to be dumped
541  *
542  * RETURN:      None
543  *
544  * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
545  *
546  ******************************************************************************/
547
548 void
549 AcpiDbDumpNamespaceByOwner (
550     char                    *OwnerArg,
551     char                    *DepthArg)
552 {
553     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
554     UINT32                  MaxDepth = ACPI_UINT32_MAX;
555     UINT16                  OwnerId;
556
557
558     OwnerId = (UINT16) ACPI_STRTOUL (OwnerArg, NULL, 0);
559
560     /* Now we can check for the depth argument */
561
562     if (DepthArg)
563     {
564         MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
565     }
566
567     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
568     AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
569
570     /* Display the subtree */
571
572     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
573     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId, SubtreeEntry);
574     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
575 }
576
577
578 /*******************************************************************************
579  *
580  * FUNCTION:    AcpiDbSendNotify
581  *
582  * PARAMETERS:  Name            - Name of ACPI object to send the notify to
583  *              Value           - Value of the notify to send.
584  *
585  * RETURN:      None
586  *
587  * DESCRIPTION: Send an ACPI notification.  The value specified is sent to the
588  *              named object as an ACPI notify.
589  *
590  ******************************************************************************/
591
592 void
593 AcpiDbSendNotify (
594     char                    *Name,
595     UINT32                  Value)
596 {
597     ACPI_NAMESPACE_NODE     *Node;
598     ACPI_STATUS             Status;
599
600
601     /* Translate name to an Named object */
602
603     Node = AcpiDbLocalNsLookup (Name);
604     if (!Node)
605     {
606         return;
607     }
608
609     /* Decode Named object type */
610
611     switch (Node->Type)
612     {
613     case ACPI_TYPE_DEVICE:
614     case ACPI_TYPE_THERMAL:
615
616          /* Send the notify */
617
618         Status = AcpiEvQueueNotifyRequest (Node, Value);
619         if (ACPI_FAILURE (Status))
620         {
621             AcpiOsPrintf ("Could not queue notify\n");
622         }
623         break;
624
625     default:
626         AcpiOsPrintf ("Named object is not a device or a thermal object\n");
627         break;
628     }
629
630 }
631
632
633 /*******************************************************************************
634  *
635  * FUNCTION:    AcpiDbSetMethodData
636  *
637  * PARAMETERS:  TypeArg         - L for local, A for argument
638  *              IndexArg        - which one
639  *              ValueArg        - Value to set.
640  *
641  * RETURN:      None
642  *
643  * DESCRIPTION: Set a local or argument for the running control method.
644  *              NOTE: only object supported is Number.
645  *
646  ******************************************************************************/
647
648 void
649 AcpiDbSetMethodData (
650     char                    *TypeArg,
651     char                    *IndexArg,
652     char                    *ValueArg)
653 {
654     char                    Type;
655     UINT32                  Index;
656     UINT32                  Value;
657     ACPI_WALK_STATE         *WalkState;
658     ACPI_OPERAND_OBJECT     *ObjDesc;
659     ACPI_STATUS             Status;
660
661
662     /* Validate TypeArg */
663
664     ACPI_STRUPR (TypeArg);
665     Type = TypeArg[0];
666     if ((Type != 'L') &&
667         (Type != 'A'))
668     {
669         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
670         return;
671     }
672
673     /* Get the index and value */
674
675     Index = ACPI_STRTOUL (IndexArg, NULL, 16);
676     Value = ACPI_STRTOUL (ValueArg, NULL, 16);
677
678     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
679     if (!WalkState)
680     {
681         AcpiOsPrintf ("There is no method currently executing\n");
682         return;
683     }
684
685
686     /* Create and initialize the new object */
687
688     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
689     if (!ObjDesc)
690     {
691         AcpiOsPrintf ("Could not create an internal object\n");
692         return;
693     }
694
695     ObjDesc->Integer.Value = Value;
696
697
698     /* Store the new object into the target */
699
700     switch (Type)
701     {
702     case 'A':
703
704         /* Set a method argument */
705
706         if (Index > ACPI_METHOD_MAX_ARG)
707         {
708             AcpiOsPrintf ("Arg%d - Invalid argument name\n", Index);
709             return;
710         }
711
712         Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, ObjDesc, WalkState);
713         if (ACPI_FAILURE (Status))
714         {
715             return;
716         }
717
718         ObjDesc = WalkState->Arguments[Index].Object;
719
720         AcpiOsPrintf ("Arg%d: ", Index);
721         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
722         break;
723
724     case 'L':
725
726         /* Set a method local */
727
728         if (Index > ACPI_METHOD_MAX_LOCAL)
729         {
730             AcpiOsPrintf ("Local%d - Invalid local variable name\n", Index);
731             return;
732         }
733
734         Status = AcpiDsStoreObjectToLocal (AML_LOCAL_OP, Index, ObjDesc, WalkState);
735         if (ACPI_FAILURE (Status))
736         {
737             return;
738         }
739
740         ObjDesc = WalkState->LocalVariables[Index].Object;
741
742         AcpiOsPrintf ("Local%d: ", Index);
743         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
744         break;
745
746     default:
747         break;
748     }
749 }
750
751
752 /*******************************************************************************
753  *
754  * FUNCTION:    AcpiDbWalkForSpecificObjects
755  *
756  * PARAMETERS:  Callback from WalkNamespace
757  *
758  * RETURN:      Status
759  *
760  * DESCRIPTION: Display short info about objects in the namespace
761  *
762  ******************************************************************************/
763
764 ACPI_STATUS
765 AcpiDbWalkForSpecificObjects (
766     ACPI_HANDLE             ObjHandle,
767     UINT32                  NestingLevel,
768     void                    *Context,
769     void                    **ReturnValue)
770 {
771     ACPI_OPERAND_OBJECT     *ObjDesc;
772     ACPI_STATUS             Status;
773     ACPI_BUFFER             Buffer;
774
775
776     ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjHandle);
777
778     /* Get and display the full pathname to this object */
779
780     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
781     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
782     if (ACPI_FAILURE (Status))
783     {
784         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
785         return (AE_OK);
786     }
787
788     AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
789     ACPI_MEM_FREE (Buffer.Pointer);
790
791
792     /* Display short information about the object */
793
794     if (ObjDesc)
795     {
796         switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
797         {
798         case ACPI_TYPE_METHOD:
799             AcpiOsPrintf ("  #Args %d  Concurrency %X",
800                     ObjDesc->Method.ParamCount, ObjDesc->Method.Concurrency);
801             break;
802
803         case ACPI_TYPE_INTEGER:
804             AcpiOsPrintf ("  Value %8.8X%8.8X",
805                     ACPI_HIDWORD (ObjDesc->Integer.Value),
806                     ACPI_LODWORD (ObjDesc->Integer.Value));
807             break;
808
809         case ACPI_TYPE_STRING:
810             AcpiOsPrintf ("  \"%s\"", ObjDesc->String.Pointer);
811             break;
812
813         case ACPI_TYPE_REGION:
814             AcpiOsPrintf ("  SpaceId %X Length %X Address %8.8X%8.8X",
815                     ObjDesc->Region.SpaceId,
816                     ObjDesc->Region.Length,
817                     ACPI_HIDWORD (ObjDesc->Region.Address),
818                     ACPI_LODWORD (ObjDesc->Region.Address));
819             break;
820
821         case ACPI_TYPE_PACKAGE:
822             AcpiOsPrintf ("  #Elements %X", ObjDesc->Package.Count);
823             break;
824
825         case ACPI_TYPE_BUFFER:
826             AcpiOsPrintf ("  Length %X", ObjDesc->Buffer.Length);
827             break;
828
829         default:
830             /* Ignore other object types */
831             break;
832         }
833     }
834
835     AcpiOsPrintf ("\n");
836     return (AE_OK);
837 }
838
839
840 /*******************************************************************************
841  *
842  * FUNCTION:    AcpiDbDisplayObjects
843  *
844  * PARAMETERS:  ObjTypeArg          - Type of object to display
845  *              DisplayCountArg     - Max depth to display
846  *
847  * RETURN:      None
848  *
849  * DESCRIPTION: Display objects in the namespace of the requested type
850  *
851  ******************************************************************************/
852
853 ACPI_STATUS
854 AcpiDbDisplayObjects (
855     char                    *ObjTypeArg,
856     char                    *DisplayCountArg)
857 {
858     ACPI_OBJECT_TYPE        Type;
859
860
861     /* Get the object type */
862
863     Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
864     if (Type == ACPI_TYPE_NOT_FOUND)
865     {
866         AcpiOsPrintf ("Invalid or unsupported argument\n");
867         return (AE_OK);
868     }
869
870     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
871     AcpiOsPrintf ("Objects of type [%s] defined in the current ACPI Namespace: \n",
872         AcpiUtGetTypeName (Type));
873
874     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
875
876     /* Walk the namespace from the root */
877
878     (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
879                         AcpiDbWalkForSpecificObjects, (void *) &Type, NULL);
880
881     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
882     return (AE_OK);
883 }
884
885
886 /*******************************************************************************
887  *
888  * FUNCTION:    AcpiDbWalkAndMatchName
889  *
890  * PARAMETERS:  Callback from WalkNamespace
891  *
892  * RETURN:      Status
893  *
894  * DESCRIPTION: Find a particular name/names within the namespace.  Wildcards
895  *              are supported -- '?' matches any character.
896  *
897  ******************************************************************************/
898
899 ACPI_STATUS
900 AcpiDbWalkAndMatchName (
901     ACPI_HANDLE             ObjHandle,
902     UINT32                  NestingLevel,
903     void                    *Context,
904     void                    **ReturnValue)
905 {
906     ACPI_STATUS             Status;
907     char                    *RequestedName = (char *) Context;
908     UINT32                  i;
909     ACPI_BUFFER             Buffer;
910
911
912     /* Check for a name match */
913
914     for (i = 0; i < 4; i++)
915     {
916         /* Wildcard support */
917
918         if ((RequestedName[i] != '?') &&
919             (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
920         {
921             /* No match, just exit */
922
923             return (AE_OK);
924         }
925     }
926
927
928     /* Get the full pathname to this object */
929
930     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
931     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
932     if (ACPI_FAILURE (Status))
933     {
934         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
935     }
936     else
937     {
938         AcpiOsPrintf ("%32s (%p) - %s\n", (char *) Buffer.Pointer, ObjHandle,
939             AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) ObjHandle)->Type));
940         ACPI_MEM_FREE (Buffer.Pointer);
941     }
942
943     return (AE_OK);
944 }
945
946
947 /*******************************************************************************
948  *
949  * FUNCTION:    AcpiDbFindNameInNamespace
950  *
951  * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
952  *                                wildcards are supported.
953  *
954  * RETURN:      None
955  *
956  * DESCRIPTION: Search the namespace for a given name (with wildcards)
957  *
958  ******************************************************************************/
959
960 ACPI_STATUS
961 AcpiDbFindNameInNamespace (
962     char                    *NameArg)
963 {
964
965     if (ACPI_STRLEN (NameArg) > 4)
966     {
967         AcpiOsPrintf ("Name must be no longer than 4 characters\n");
968         return (AE_OK);
969     }
970
971     /* Walk the namespace from the root */
972
973     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
974                         AcpiDbWalkAndMatchName, NameArg, NULL);
975
976     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
977     return (AE_OK);
978 }
979
980
981 /*******************************************************************************
982  *
983  * FUNCTION:    AcpiDbSetScope
984  *
985  * PARAMETERS:  Name                - New scope path
986  *
987  * RETURN:      Status
988  *
989  * DESCRIPTION: Set the "current scope" as maintained by this utility.
990  *              The scope is used as a prefix to ACPI paths.
991  *
992  ******************************************************************************/
993
994 void
995 AcpiDbSetScope (
996     char                    *Name)
997 {
998     ACPI_STATUS             Status;
999     ACPI_NAMESPACE_NODE     *Node;
1000
1001
1002     if (!Name || Name[0] == 0)
1003     {
1004         AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
1005         return;
1006     }
1007
1008     AcpiDbPrepNamestring (Name);
1009
1010
1011     if (Name[0] == '\\')
1012     {
1013         /* Validate new scope from the root */
1014
1015         Status = AcpiNsGetNodeByPath (Name, AcpiGbl_RootNode, ACPI_NS_NO_UPSEARCH, &Node);
1016         if (ACPI_FAILURE (Status))
1017         {
1018             goto ErrorExit;
1019         }
1020
1021         ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
1022         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1023     }
1024     else
1025     {
1026         /* Validate new scope relative to old scope */
1027
1028         Status = AcpiNsGetNodeByPath (Name, AcpiGbl_DbScopeNode, ACPI_NS_NO_UPSEARCH, &Node);
1029         if (ACPI_FAILURE (Status))
1030         {
1031             goto ErrorExit;
1032         }
1033
1034         ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
1035         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1036     }
1037
1038     AcpiGbl_DbScopeNode = Node;
1039     AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
1040     return;
1041
1042
1043 ErrorExit:
1044
1045     AcpiOsPrintf ("Could not attach scope: %s, %s\n", Name, AcpiFormatException (Status));
1046 }
1047
1048
1049 /*******************************************************************************
1050  *
1051  * FUNCTION:    AcpiDbDisplayResources
1052  *
1053  * PARAMETERS:  ObjectArg       - String with hex value of the object
1054  *
1055  * RETURN:      None
1056  *
1057  * DESCRIPTION: Display the resource objects associated with a device.
1058  *
1059  ******************************************************************************/
1060
1061 void
1062 AcpiDbDisplayResources (
1063     char                    *ObjectArg)
1064 {
1065 #if ACPI_MACHINE_WIDTH != 16
1066
1067     ACPI_OPERAND_OBJECT     *ObjDesc;
1068     ACPI_STATUS             Status;
1069     ACPI_BUFFER             ReturnObj;
1070
1071
1072     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1073     AcpiDbgLevel |= ACPI_LV_RESOURCES;
1074
1075     /* Convert string to object pointer */
1076
1077     ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
1078
1079     /* Prepare for a return object of arbitrary size */
1080
1081     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1082     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1083
1084     /* _PRT */
1085
1086     AcpiOsPrintf ("Evaluating _PRT\n");
1087
1088     Status = AcpiEvaluateObject (ObjDesc, "_PRT", NULL, &ReturnObj);
1089     if (ACPI_FAILURE (Status))
1090     {
1091         AcpiOsPrintf ("Could not obtain _PRT: %s\n", AcpiFormatException (Status));
1092         goto GetCrs;
1093     }
1094
1095     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1096     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1097
1098     Status = AcpiGetIrqRoutingTable (ObjDesc, &ReturnObj);
1099     if (ACPI_FAILURE (Status))
1100     {
1101         AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n", AcpiFormatException (Status));
1102     }
1103
1104     else
1105     {
1106         AcpiRsDumpIrqList ((UINT8 *) AcpiGbl_DbBuffer);
1107     }
1108
1109
1110     /* _CRS */
1111
1112 GetCrs:
1113     AcpiOsPrintf ("Evaluating _CRS\n");
1114
1115     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1116     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1117
1118     Status = AcpiEvaluateObject (ObjDesc, "_CRS", NULL, &ReturnObj);
1119     if (ACPI_FAILURE (Status))
1120     {
1121         AcpiOsPrintf ("Could not obtain _CRS: %s\n", AcpiFormatException (Status));
1122         goto GetPrs;
1123     }
1124
1125     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1126     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1127
1128     Status = AcpiGetCurrentResources (ObjDesc, &ReturnObj);
1129     if (ACPI_FAILURE (Status))
1130     {
1131         AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n", AcpiFormatException (Status));
1132         goto GetPrs;
1133     }
1134
1135     else
1136     {
1137         AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1138     }
1139
1140     Status = AcpiSetCurrentResources (ObjDesc, &ReturnObj);
1141     if (ACPI_FAILURE (Status))
1142     {
1143         AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n", AcpiFormatException (Status));
1144         goto GetPrs;
1145     }
1146
1147
1148     /* _PRS */
1149
1150 GetPrs:
1151     AcpiOsPrintf ("Evaluating _PRS\n");
1152
1153     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1154     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1155
1156     Status = AcpiEvaluateObject (ObjDesc, "_PRS", NULL, &ReturnObj);
1157     if (ACPI_FAILURE (Status))
1158     {
1159         AcpiOsPrintf ("Could not obtain _PRS: %s\n", AcpiFormatException (Status));
1160         goto Cleanup;
1161     }
1162
1163     ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1164     ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1165
1166     Status = AcpiGetPossibleResources (ObjDesc, &ReturnObj);
1167     if (ACPI_FAILURE (Status))
1168     {
1169         AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n", AcpiFormatException (Status));
1170     }
1171
1172     else
1173     {
1174         AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1175     }
1176
1177
1178 Cleanup:
1179
1180     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1181     return;
1182 #endif
1183
1184 }
1185
1186
1187 /*******************************************************************************
1188  *
1189  * FUNCTION:    AcpiDbIntegrityWalk
1190  *
1191  * PARAMETERS:  Callback from WalkNamespace
1192  *
1193  * RETURN:      Status
1194  *
1195  * DESCRIPTION: Examine one NS node for valid values.
1196  *
1197  ******************************************************************************/
1198
1199 ACPI_STATUS
1200 AcpiDbIntegrityWalk (
1201     ACPI_HANDLE             ObjHandle,
1202     UINT32                  NestingLevel,
1203     void                    *Context,
1204     void                    **ReturnValue)
1205 {
1206     ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
1207     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1208     ACPI_OPERAND_OBJECT     *Object;
1209
1210
1211     Info->Nodes++;
1212     if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
1213     {
1214         AcpiOsPrintf ("Invalid Descriptor Type for Node %p, Type = %X\n",
1215             Node, ACPI_GET_DESCRIPTOR_TYPE (Node));
1216     }
1217
1218     if (Node->Type > ACPI_TYPE_LOCAL_MAX)
1219     {
1220         AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
1221             Node, Node->Type);
1222     }
1223
1224     if (!AcpiUtValidAcpiName (Node->Name.Integer))
1225     {
1226         AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
1227     }
1228
1229     Object = AcpiNsGetAttachedObject (Node);
1230     if (Object)
1231     {
1232         Info->Objects++;
1233         if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
1234         {
1235             AcpiOsPrintf ("Invalid Descriptor Type for Object %p, Type = %X\n",
1236                 Object, ACPI_GET_DESCRIPTOR_TYPE (Object));
1237         }
1238     }
1239
1240
1241     return (AE_OK);
1242 }
1243
1244
1245 /*******************************************************************************
1246  *
1247  * FUNCTION:    AcpiDbCheckIntegrity
1248  *
1249  * PARAMETERS:  None
1250  *
1251  * RETURN:      None
1252  *
1253  * DESCRIPTION: Check entire namespace for data structure integrity
1254  *
1255  ******************************************************************************/
1256
1257 void
1258 AcpiDbCheckIntegrity (void)
1259 {
1260     ACPI_INTEGRITY_INFO     Info = {0,0};
1261
1262     /* Search all nodes in namespace */
1263
1264     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1265                     AcpiDbIntegrityWalk, (void *) &Info, NULL);
1266
1267     AcpiOsPrintf ("Verified %d namespace nodes with %d Objects\n", Info.Nodes, Info.Objects);
1268
1269 }
1270
1271
1272 /*******************************************************************************
1273  *
1274  * FUNCTION:    AcpiDbGenerateGpe
1275  *
1276  * PARAMETERS:  None
1277  *
1278  * RETURN:      None
1279  *
1280  * DESCRIPTION: Generate a GPE
1281  *
1282  ******************************************************************************/
1283
1284 void
1285 AcpiDbGenerateGpe (
1286     char                    *GpeArg,
1287     char                    *BlockArg)
1288 {
1289     UINT32                  BlockNumber;
1290     UINT32                  GpeNumber;
1291     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
1292
1293
1294     GpeNumber   = ACPI_STRTOUL (GpeArg, NULL, 10);
1295     BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 10);
1296
1297
1298     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeNumber);
1299     if (!GpeEventInfo)
1300     {
1301         AcpiOsPrintf ("Invalid GPE\n");
1302         return;
1303     }
1304
1305     AcpiEvGpeDispatch (GpeEventInfo);
1306
1307 }
1308
1309 #endif /* ACPI_DEBUGGER */