]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/dbcmds.c
This commit was generated by cvs2svn to compensate for changes in r156952,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / dbcmds.c
1 /*******************************************************************************
2  *
3  * Module Name: dbcmds - debug commands and output routines
4  *              $Revision: 115 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, 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
117
118 #include <contrib/dev/acpica/acpi.h>
119 #include <contrib/dev/acpica/acdispat.h>
120 #include <contrib/dev/acpica/amlcode.h>
121 #include <contrib/dev/acpica/acnamesp.h>
122 #include <contrib/dev/acpica/acevents.h>
123 #include <contrib/dev/acpica/acdebug.h>
124 #include <contrib/dev/acpica/acresrc.h>
125 #include <contrib/dev/acpica/acdisasm.h>
126
127
128 #include <contrib/dev/acpica/acparser.h>
129
130 #ifdef ACPI_DEBUGGER
131
132 #define _COMPONENT          ACPI_CA_DEBUGGER
133         ACPI_MODULE_NAME    ("dbcmds")
134
135 /* Local prototypes */
136
137 static ACPI_STATUS
138 AcpiDbIntegrityWalk (
139     ACPI_HANDLE             ObjHandle,
140     UINT32                  NestingLevel,
141     void                    *Context,
142     void                    **ReturnValue);
143
144 static ACPI_STATUS
145 AcpiDbWalkAndMatchName (
146     ACPI_HANDLE             ObjHandle,
147     UINT32                  NestingLevel,
148     void                    *Context,
149     void                    **ReturnValue);
150
151 static ACPI_STATUS
152 AcpiDbWalkForReferences (
153     ACPI_HANDLE             ObjHandle,
154     UINT32                  NestingLevel,
155     void                    *Context,
156     void                    **ReturnValue);
157
158 static ACPI_STATUS
159 AcpiDbWalkForSpecificObjects (
160     ACPI_HANDLE             ObjHandle,
161     UINT32                  NestingLevel,
162     void                    *Context,
163     void                    **ReturnValue);
164
165 static ACPI_NAMESPACE_NODE *
166 AcpiDbConvertToNode (
167     char                    *InString);
168
169 static void
170 AcpiDmCompareAmlResources (
171     UINT8                   *Aml1Buffer,
172     ACPI_RSDESC_SIZE        Aml1BufferLength,
173     UINT8                   *Aml2Buffer,
174     ACPI_RSDESC_SIZE        Aml2BufferLength);
175
176 static ACPI_STATUS
177 AcpiDmTestResourceConversion (
178     ACPI_NAMESPACE_NODE     *Node,
179     char                    *Name);
180
181
182 /*
183  * Arguments for the Objects command
184  * These object types map directly to the ACPI_TYPES
185  */
186 static ARGUMENT_INFO        AcpiDbObjectTypes [] =
187 {
188     {"ANY"},
189     {"INTEGERS"},
190     {"STRINGS"},
191     {"BUFFERS"},
192     {"PACKAGES"},
193     {"FIELDS"},
194     {"DEVICES"},
195     {"EVENTS"},
196     {"METHODS"},
197     {"MUTEXES"},
198     {"REGIONS"},
199     {"POWERRESOURCES"},
200     {"PROCESSORS"},
201     {"THERMALZONES"},
202     {"BUFFERFIELDS"},
203     {"DDBHANDLES"},
204     {NULL}           /* Must be null terminated */
205 };
206
207
208 /*******************************************************************************
209  *
210  * FUNCTION:    AcpiDbConvertToNode
211  *
212  * PARAMETERS:  InString        - String to convert
213  *
214  * RETURN:      Pointer to a NS node
215  *
216  * DESCRIPTION: Convert a string to a valid NS pointer.  Handles numeric or
217  *              alpha strings.
218  *
219  ******************************************************************************/
220
221 static ACPI_NAMESPACE_NODE *
222 AcpiDbConvertToNode (
223     char                    *InString)
224 {
225     ACPI_NAMESPACE_NODE     *Node;
226
227
228     if ((*InString >= 0x30) && (*InString <= 0x39))
229     {
230         /* Numeric argument, convert */
231
232         Node = ACPI_TO_POINTER (ACPI_STRTOUL (InString, NULL, 16));
233         if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
234         {
235             AcpiOsPrintf ("Address %p is invalid in this address space\n",
236                 Node);
237             return (NULL);
238         }
239
240         /* Make sure pointer is valid NS node */
241
242         if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
243         {
244             AcpiOsPrintf ("Address %p is not a valid NS node [%s]\n",
245                     Node, AcpiUtGetDescriptorName (Node));
246             return (NULL);
247         }
248     }
249     else
250     {
251         /* Alpha argument */
252         /* The parameter is a name string that must be resolved to a
253          * Named obj
254          */
255         Node = AcpiDbLocalNsLookup (InString);
256         if (!Node)
257         {
258             Node = AcpiGbl_RootNode;
259         }
260     }
261
262     return (Node);
263 }
264
265
266 /*******************************************************************************
267  *
268  * FUNCTION:    AcpiDbSleep
269  *
270  * PARAMETERS:  ObjectArg       - Desired sleep state (0-5)
271  *
272  * RETURN:      Status
273  *
274  * DESCRIPTION: Simulate a sleep/wake sequence
275  *
276  ******************************************************************************/
277
278 ACPI_STATUS
279 AcpiDbSleep (
280     char                    *ObjectArg)
281 {
282 #if ACPI_MACHINE_WIDTH == 16
283     return (AE_OK);
284 #else
285     ACPI_STATUS             Status;
286     UINT8                   SleepState;
287
288
289     SleepState = (UINT8) ACPI_STRTOUL (ObjectArg, NULL, 0);
290
291     AcpiOsPrintf ("**** Prepare to sleep ****\n");
292     Status = AcpiEnterSleepStatePrep (SleepState);
293     if (ACPI_FAILURE (Status))
294     {
295         return (Status);
296     }
297
298     AcpiOsPrintf ("**** Going to sleep ****\n");
299     Status = AcpiEnterSleepState (SleepState);
300     if (ACPI_FAILURE (Status))
301     {
302         return (Status);
303     }
304
305     AcpiOsPrintf ("**** returning from sleep ****\n");
306     Status = AcpiLeaveSleepState (SleepState);
307
308     return (Status);
309 #endif
310 }
311
312
313 /*******************************************************************************
314  *
315  * FUNCTION:    AcpiDbWalkForReferences
316  *
317  * PARAMETERS:  Callback from WalkNamespace
318  *
319  * RETURN:      Status
320  *
321  * DESCRIPTION: Check if this namespace object refers to the target object
322  *              that is passed in as the context value.
323  *
324  * Note: Currently doesn't check subobjects within the Node's object
325  *
326  ******************************************************************************/
327
328 static ACPI_STATUS
329 AcpiDbWalkForReferences (
330     ACPI_HANDLE             ObjHandle,
331     UINT32                  NestingLevel,
332     void                    *Context,
333     void                    **ReturnValue)
334 {
335     ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
336     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
337
338
339     /* Check for match against the namespace node itself */
340
341     if (Node == (void *) ObjDesc)
342     {
343         AcpiOsPrintf ("Object is a Node [%4.4s]\n",
344             AcpiUtGetNodeName (Node));
345     }
346
347     /* Check for match against the object attached to the node */
348
349     if (AcpiNsGetAttachedObject (Node) == ObjDesc)
350     {
351         AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
352             Node, AcpiUtGetNodeName (Node));
353     }
354
355     return (AE_OK);
356 }
357
358
359 /*******************************************************************************
360  *
361  * FUNCTION:    AcpiDbFindReferences
362  *
363  * PARAMETERS:  ObjectArg       - String with hex value of the object
364  *
365  * RETURN:      None
366  *
367  * DESCRIPTION: Search namespace for all references to the input object
368  *
369  ******************************************************************************/
370
371 void
372 AcpiDbFindReferences (
373     char                    *ObjectArg)
374 {
375     ACPI_OPERAND_OBJECT     *ObjDesc;
376
377
378     /* Convert string to object pointer */
379
380     ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
381
382     /* Search all nodes in namespace */
383
384     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
385                     AcpiDbWalkForReferences, (void *) ObjDesc, NULL);
386 }
387
388
389 /*******************************************************************************
390  *
391  * FUNCTION:    AcpiDbDisplayLocks
392  *
393  * PARAMETERS:  None
394  *
395  * RETURN:      None
396  *
397  * DESCRIPTION: Display information about internal mutexes.
398  *
399  ******************************************************************************/
400
401 void
402 AcpiDbDisplayLocks (
403     void)
404 {
405     UINT32                  i;
406
407
408     for (i = 0; i < MAX_MUTEX; i++)
409     {
410         AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
411                     AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED
412                         ? "Locked" : "Unlocked");
413     }
414 }
415
416
417 /*******************************************************************************
418  *
419  * FUNCTION:    AcpiDbDisplayTableInfo
420  *
421  * PARAMETERS:  TableArg        - String with name of table to be displayed
422  *
423  * RETURN:      None
424  *
425  * DESCRIPTION: Display information about loaded tables.  Current
426  *              implementation displays all loaded tables.
427  *
428  ******************************************************************************/
429
430 void
431 AcpiDbDisplayTableInfo (
432     char                    *TableArg)
433 {
434     UINT32                  i;
435     ACPI_TABLE_DESC         *TableDesc;
436
437
438     for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++)
439     {
440         TableDesc = AcpiGbl_TableLists[i].Next;
441         while (TableDesc)
442         {
443             AcpiOsPrintf ( "%s at %p length %.5X",
444                     AcpiGbl_TableData[i].Name, TableDesc->Pointer,
445                     (UINT32) TableDesc->Length);
446
447             if (i != ACPI_TABLE_FACS)
448             {
449                 AcpiOsPrintf (" OemID=%6s TableId=%8s OemRevision=%8.8X",
450                         TableDesc->Pointer->OemId,
451                         TableDesc->Pointer->OemTableId,
452                         TableDesc->Pointer->OemRevision);
453             }
454             AcpiOsPrintf ("\n");
455
456             TableDesc = TableDesc->Next;
457         }
458     }
459 }
460
461
462 /*******************************************************************************
463  *
464  * FUNCTION:    AcpiDbUnloadAcpiTable
465  *
466  * PARAMETERS:  TableArg        - Name of the table to be unloaded
467  *              InstanceArg     - Which instance of the table to unload (if
468  *                                there are multiple tables of the same type)
469  *
470  * RETURN:      Nonde
471  *
472  * DESCRIPTION: Unload an ACPI table.
473  *              Instance is not implemented
474  *
475  ******************************************************************************/
476
477 void
478 AcpiDbUnloadAcpiTable (
479     char                    *TableArg,
480     char                    *InstanceArg)
481 {
482     UINT32                  i;
483     ACPI_STATUS             Status;
484
485
486     /* Search all tables for the target type */
487
488     for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++)
489     {
490         if (!ACPI_STRNCMP (TableArg, AcpiGbl_TableData[i].Signature,
491                 AcpiGbl_TableData[i].SigLength))
492         {
493             /* Found the table, unload it */
494
495             Status = AcpiUnloadTable (i);
496             if (ACPI_SUCCESS (Status))
497             {
498                 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
499             }
500             else
501             {
502                 AcpiOsPrintf ("%s, while unloading [%s]\n",
503                     AcpiFormatException (Status), TableArg);
504             }
505
506             return;
507         }
508     }
509
510     AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
511 }
512
513
514 /*******************************************************************************
515  *
516  * FUNCTION:    AcpiDbSetMethodBreakpoint
517  *
518  * PARAMETERS:  Location            - AML offset of breakpoint
519  *              WalkState           - Current walk info
520  *              Op                  - Current Op (from parse walk)
521  *
522  * RETURN:      None
523  *
524  * DESCRIPTION: Set a breakpoint in a control method at the specified
525  *              AML offset
526  *
527  ******************************************************************************/
528
529 void
530 AcpiDbSetMethodBreakpoint (
531     char                    *Location,
532     ACPI_WALK_STATE         *WalkState,
533     ACPI_PARSE_OBJECT       *Op)
534 {
535     UINT32                  Address;
536
537
538     if (!Op)
539     {
540         AcpiOsPrintf ("There is no method currently executing\n");
541         return;
542     }
543
544     /* Get and verify the breakpoint address */
545
546     Address = ACPI_STRTOUL (Location, NULL, 16);
547     if (Address <= Op->Common.AmlOffset)
548     {
549         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
550             Address, Op->Common.AmlOffset);
551     }
552
553     /* Save breakpoint in current walk */
554
555     WalkState->UserBreakpoint = Address;
556     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
557 }
558
559
560 /*******************************************************************************
561  *
562  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
563  *
564  * PARAMETERS:  Op                  - Current Op (from parse walk)
565  *
566  * RETURN:      None
567  *
568  * DESCRIPTION: Set a breakpoint in a control method at the specified
569  *              AML offset
570  *
571  ******************************************************************************/
572
573 void
574 AcpiDbSetMethodCallBreakpoint (
575     ACPI_PARSE_OBJECT       *Op)
576 {
577
578
579     if (!Op)
580     {
581         AcpiOsPrintf ("There is no method currently executing\n");
582         return;
583     }
584
585     AcpiGbl_StepToNextCall = TRUE;
586 }
587
588
589 /*******************************************************************************
590  *
591  * FUNCTION:    AcpiDbDisassembleAml
592  *
593  * PARAMETERS:  Statements          - Number of statements to disassemble
594  *              Op                  - Current Op (from parse walk)
595  *
596  * RETURN:      None
597  *
598  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
599  *              of statements specified.
600  *
601  ******************************************************************************/
602
603 void
604 AcpiDbDisassembleAml (
605     char                    *Statements,
606     ACPI_PARSE_OBJECT       *Op)
607 {
608     UINT32                  NumStatements = 8;
609
610
611     if (!Op)
612     {
613         AcpiOsPrintf ("There is no method currently executing\n");
614         return;
615     }
616
617     if (Statements)
618     {
619         NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
620     }
621
622 #ifdef ACPI_DISASSEMBLER
623     AcpiDmDisassemble (NULL, Op, NumStatements);
624 #endif
625 }
626
627
628 /*******************************************************************************
629  *
630  * FUNCTION:    AcpiDbDisassembleMethod
631  *
632  * PARAMETERS:  Name            - Name of control method
633  *
634  * RETURN:      None
635  *
636  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
637  *              of statements specified.
638  *
639  ******************************************************************************/
640
641 ACPI_STATUS
642 AcpiDbDisassembleMethod (
643     char                    *Name)
644 {
645     ACPI_STATUS             Status;
646     ACPI_PARSE_OBJECT       *Op;
647     ACPI_WALK_STATE         *WalkState;
648     ACPI_OPERAND_OBJECT     *ObjDesc;
649     ACPI_NAMESPACE_NODE     *Method;
650
651
652     Method = AcpiDbConvertToNode (Name);
653     if (!Method)
654     {
655         return (AE_BAD_PARAMETER);
656     }
657
658     ObjDesc = Method->Object;
659
660     Op = AcpiPsCreateScopeOp ();
661     if (!Op)
662     {
663         return (AE_NO_MEMORY);
664     }
665
666     /* Create and initialize a new walk state */
667
668     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
669     if (!WalkState)
670     {
671         return (AE_NO_MEMORY);
672     }
673
674     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
675                     ObjDesc->Method.AmlStart,
676                     ObjDesc->Method.AmlLength, NULL, 1);
677     if (ACPI_FAILURE (Status))
678     {
679         return (Status);
680     }
681
682     /* Parse the AML */
683
684     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
685     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
686     Status = AcpiPsParseAml (WalkState);
687
688 #ifdef ACPI_DISASSEMBLER
689     AcpiDmDisassemble (NULL, Op, 0);
690 #endif
691     AcpiPsDeleteParseTree (Op);
692     return (AE_OK);
693 }
694
695
696 /*******************************************************************************
697  *
698  * FUNCTION:    AcpiDbDumpNamespace
699  *
700  * PARAMETERS:  StartArg        - Node to begin namespace dump
701  *              DepthArg        - Maximum tree depth to be dumped
702  *
703  * RETURN:      None
704  *
705  * DESCRIPTION: Dump entire namespace or a subtree.  Each node is displayed
706  *              with type and other information.
707  *
708  ******************************************************************************/
709
710 void
711 AcpiDbDumpNamespace (
712     char                    *StartArg,
713     char                    *DepthArg)
714 {
715     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
716     UINT32                  MaxDepth = ACPI_UINT32_MAX;
717
718
719     /* No argument given, just start at the root and dump entire namespace */
720
721     if (StartArg)
722     {
723         SubtreeEntry = AcpiDbConvertToNode (StartArg);
724         if (!SubtreeEntry)
725         {
726             return;
727         }
728
729         /* Now we can check for the depth argument */
730
731         if (DepthArg)
732         {
733             MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
734         }
735     }
736
737     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
738     AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
739         ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
740
741     /* Display the subtree */
742
743     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
744     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
745         ACPI_OWNER_ID_MAX, SubtreeEntry);
746     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
747 }
748
749
750 /*******************************************************************************
751  *
752  * FUNCTION:    AcpiDbDumpNamespaceByOwner
753  *
754  * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
755  *              DepthArg        - Maximum tree depth to be dumped
756  *
757  * RETURN:      None
758  *
759  * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
760  *
761  ******************************************************************************/
762
763 void
764 AcpiDbDumpNamespaceByOwner (
765     char                    *OwnerArg,
766     char                    *DepthArg)
767 {
768     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
769     UINT32                  MaxDepth = ACPI_UINT32_MAX;
770     ACPI_OWNER_ID           OwnerId;
771
772
773     OwnerId = (ACPI_OWNER_ID) ACPI_STRTOUL (OwnerArg, NULL, 0);
774
775     /* Now we can check for the depth argument */
776
777     if (DepthArg)
778     {
779         MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
780     }
781
782     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
783     AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
784
785     /* Display the subtree */
786
787     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
788     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId,
789         SubtreeEntry);
790     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
791 }
792
793
794 /*******************************************************************************
795  *
796  * FUNCTION:    AcpiDbSendNotify
797  *
798  * PARAMETERS:  Name            - Name of ACPI object to send the notify to
799  *              Value           - Value of the notify to send.
800  *
801  * RETURN:      None
802  *
803  * DESCRIPTION: Send an ACPI notification.  The value specified is sent to the
804  *              named object as an ACPI notify.
805  *
806  ******************************************************************************/
807
808 void
809 AcpiDbSendNotify (
810     char                    *Name,
811     UINT32                  Value)
812 {
813     ACPI_NAMESPACE_NODE     *Node;
814     ACPI_STATUS             Status;
815
816
817     /* Translate name to an Named object */
818
819     Node = AcpiDbConvertToNode (Name);
820     if (!Node)
821     {
822         return;
823     }
824
825     /* Decode Named object type */
826
827     switch (Node->Type)
828     {
829     case ACPI_TYPE_DEVICE:
830     case ACPI_TYPE_THERMAL:
831
832          /* Send the notify */
833
834         Status = AcpiEvQueueNotifyRequest (Node, Value);
835         if (ACPI_FAILURE (Status))
836         {
837             AcpiOsPrintf ("Could not queue notify\n");
838         }
839         break;
840
841     default:
842         AcpiOsPrintf ("Named object is not a device or a thermal object\n");
843         break;
844     }
845 }
846
847
848 /*******************************************************************************
849  *
850  * FUNCTION:    AcpiDbSetMethodData
851  *
852  * PARAMETERS:  TypeArg         - L for local, A for argument
853  *              IndexArg        - which one
854  *              ValueArg        - Value to set.
855  *
856  * RETURN:      None
857  *
858  * DESCRIPTION: Set a local or argument for the running control method.
859  *              NOTE: only object supported is Number.
860  *
861  ******************************************************************************/
862
863 void
864 AcpiDbSetMethodData (
865     char                    *TypeArg,
866     char                    *IndexArg,
867     char                    *ValueArg)
868 {
869     char                    Type;
870     UINT32                  Index;
871     UINT32                  Value;
872     ACPI_WALK_STATE         *WalkState;
873     ACPI_OPERAND_OBJECT     *ObjDesc;
874     ACPI_STATUS             Status;
875     ACPI_NAMESPACE_NODE     *Node;
876
877
878     /* Validate TypeArg */
879
880     AcpiUtStrupr (TypeArg);
881     Type = TypeArg[0];
882     if ((Type != 'L') &&
883         (Type != 'A') &&
884         (Type != 'N'))
885     {
886         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
887         return;
888     }
889
890     Value = ACPI_STRTOUL (ValueArg, NULL, 16);
891
892     if (Type == 'N')
893     {
894         Node = AcpiDbConvertToNode (IndexArg);
895         if (Node->Type != ACPI_TYPE_INTEGER)
896         {
897             AcpiOsPrintf ("Can only set Integer nodes\n");
898             return;
899         }
900         ObjDesc = Node->Object;
901         ObjDesc->Integer.Value = Value;
902         return;
903     }
904
905     /* Get the index and value */
906
907     Index = ACPI_STRTOUL (IndexArg, NULL, 16);
908
909     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
910     if (!WalkState)
911     {
912         AcpiOsPrintf ("There is no method currently executing\n");
913         return;
914     }
915
916     /* Create and initialize the new object */
917
918     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
919     if (!ObjDesc)
920     {
921         AcpiOsPrintf ("Could not create an internal object\n");
922         return;
923     }
924
925     ObjDesc->Integer.Value = Value;
926
927     /* Store the new object into the target */
928
929     switch (Type)
930     {
931     case 'A':
932
933         /* Set a method argument */
934
935         if (Index > ACPI_METHOD_MAX_ARG)
936         {
937             AcpiOsPrintf ("Arg%d - Invalid argument name\n", Index);
938             return;
939         }
940
941         Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, ObjDesc,
942                     WalkState);
943         if (ACPI_FAILURE (Status))
944         {
945             return;
946         }
947
948         ObjDesc = WalkState->Arguments[Index].Object;
949
950         AcpiOsPrintf ("Arg%d: ", Index);
951         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
952         break;
953
954     case 'L':
955
956         /* Set a method local */
957
958         if (Index > ACPI_METHOD_MAX_LOCAL)
959         {
960             AcpiOsPrintf ("Local%d - Invalid local variable name\n", Index);
961             return;
962         }
963
964         Status = AcpiDsStoreObjectToLocal (AML_LOCAL_OP, Index, ObjDesc,
965                     WalkState);
966         if (ACPI_FAILURE (Status))
967         {
968             return;
969         }
970
971         ObjDesc = WalkState->LocalVariables[Index].Object;
972
973         AcpiOsPrintf ("Local%d: ", Index);
974         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
975         break;
976
977     default:
978         break;
979     }
980 }
981
982
983 /*******************************************************************************
984  *
985  * FUNCTION:    AcpiDbWalkForSpecificObjects
986  *
987  * PARAMETERS:  Callback from WalkNamespace
988  *
989  * RETURN:      Status
990  *
991  * DESCRIPTION: Display short info about objects in the namespace
992  *
993  ******************************************************************************/
994
995 static ACPI_STATUS
996 AcpiDbWalkForSpecificObjects (
997     ACPI_HANDLE             ObjHandle,
998     UINT32                  NestingLevel,
999     void                    *Context,
1000     void                    **ReturnValue)
1001 {
1002     ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
1003     ACPI_BUFFER             Buffer;
1004     ACPI_STATUS             Status;
1005
1006
1007     Info->Count++;
1008
1009     /* Get and display the full pathname to this object */
1010
1011     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1012     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
1013     if (ACPI_FAILURE (Status))
1014     {
1015         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
1016         return (AE_OK);
1017     }
1018
1019     AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
1020     ACPI_MEM_FREE (Buffer.Pointer);
1021
1022     /* Dump short info about the object */
1023
1024     (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
1025     return (AE_OK);
1026 }
1027
1028
1029 /*******************************************************************************
1030  *
1031  * FUNCTION:    AcpiDbDisplayObjects
1032  *
1033  * PARAMETERS:  ObjTypeArg          - Type of object to display
1034  *              DisplayCountArg     - Max depth to display
1035  *
1036  * RETURN:      None
1037  *
1038  * DESCRIPTION: Display objects in the namespace of the requested type
1039  *
1040  ******************************************************************************/
1041
1042 ACPI_STATUS
1043 AcpiDbDisplayObjects (
1044     char                    *ObjTypeArg,
1045     char                    *DisplayCountArg)
1046 {
1047     ACPI_WALK_INFO          Info;
1048     ACPI_OBJECT_TYPE        Type;
1049
1050
1051     /* Get the object type */
1052
1053     Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
1054     if (Type == ACPI_TYPE_NOT_FOUND)
1055     {
1056         AcpiOsPrintf ("Invalid or unsupported argument\n");
1057         return (AE_OK);
1058     }
1059
1060     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
1061     AcpiOsPrintf (
1062         "Objects of type [%s] defined in the current ACPI Namespace:\n",
1063         AcpiUtGetTypeName (Type));
1064
1065     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1066
1067     Info.Count = 0;
1068     Info.OwnerId = ACPI_OWNER_ID_MAX;
1069     Info.DebugLevel = ACPI_UINT32_MAX;
1070     Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
1071
1072     /* Walk the namespace from the root */
1073
1074     (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1075                 AcpiDbWalkForSpecificObjects, (void *) &Info, NULL);
1076
1077     AcpiOsPrintf (
1078         "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
1079         Info.Count, AcpiUtGetTypeName (Type));
1080
1081     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1082     return (AE_OK);
1083 }
1084
1085
1086 /*******************************************************************************
1087  *
1088  * FUNCTION:    AcpiDbWalkAndMatchName
1089  *
1090  * PARAMETERS:  Callback from WalkNamespace
1091  *
1092  * RETURN:      Status
1093  *
1094  * DESCRIPTION: Find a particular name/names within the namespace.  Wildcards
1095  *              are supported -- '?' matches any character.
1096  *
1097  ******************************************************************************/
1098
1099 static ACPI_STATUS
1100 AcpiDbWalkAndMatchName (
1101     ACPI_HANDLE             ObjHandle,
1102     UINT32                  NestingLevel,
1103     void                    *Context,
1104     void                    **ReturnValue)
1105 {
1106     ACPI_STATUS             Status;
1107     char                    *RequestedName = (char *) Context;
1108     UINT32                  i;
1109     ACPI_BUFFER             Buffer;
1110     ACPI_WALK_INFO          Info;
1111
1112
1113     /* Check for a name match */
1114
1115     for (i = 0; i < 4; i++)
1116     {
1117         /* Wildcard support */
1118
1119         if ((RequestedName[i] != '?') &&
1120             (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
1121         {
1122             /* No match, just exit */
1123
1124             return (AE_OK);
1125         }
1126     }
1127
1128     /* Get the full pathname to this object */
1129
1130     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1131     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
1132     if (ACPI_FAILURE (Status))
1133     {
1134         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
1135     }
1136     else
1137     {
1138         Info.OwnerId = ACPI_OWNER_ID_MAX;
1139         Info.DebugLevel = ACPI_UINT32_MAX;
1140         Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
1141
1142         AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
1143         (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
1144         ACPI_MEM_FREE (Buffer.Pointer);
1145     }
1146
1147     return (AE_OK);
1148 }
1149
1150
1151 /*******************************************************************************
1152  *
1153  * FUNCTION:    AcpiDbFindNameInNamespace
1154  *
1155  * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
1156  *                                wildcards are supported.
1157  *
1158  * RETURN:      None
1159  *
1160  * DESCRIPTION: Search the namespace for a given name (with wildcards)
1161  *
1162  ******************************************************************************/
1163
1164 ACPI_STATUS
1165 AcpiDbFindNameInNamespace (
1166     char                    *NameArg)
1167 {
1168
1169     if (ACPI_STRLEN (NameArg) > 4)
1170     {
1171         AcpiOsPrintf ("Name must be no longer than 4 characters\n");
1172         return (AE_OK);
1173     }
1174
1175     /* Walk the namespace from the root */
1176
1177     AcpiUtStrupr (NameArg);
1178     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1179                         AcpiDbWalkAndMatchName, NameArg, NULL);
1180
1181     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1182     return (AE_OK);
1183 }
1184
1185
1186 /*******************************************************************************
1187  *
1188  * FUNCTION:    AcpiDbSetScope
1189  *
1190  * PARAMETERS:  Name                - New scope path
1191  *
1192  * RETURN:      Status
1193  *
1194  * DESCRIPTION: Set the "current scope" as maintained by this utility.
1195  *              The scope is used as a prefix to ACPI paths.
1196  *
1197  ******************************************************************************/
1198
1199 void
1200 AcpiDbSetScope (
1201     char                    *Name)
1202 {
1203     ACPI_STATUS             Status;
1204     ACPI_NAMESPACE_NODE     *Node;
1205
1206
1207     if (!Name || Name[0] == 0)
1208     {
1209         AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
1210         return;
1211     }
1212
1213     AcpiDbPrepNamestring (Name);
1214
1215     if (Name[0] == '\\')
1216     {
1217         /* Validate new scope from the root */
1218
1219         Status = AcpiNsGetNodeByPath (Name, AcpiGbl_RootNode,
1220                     ACPI_NS_NO_UPSEARCH, &Node);
1221         if (ACPI_FAILURE (Status))
1222         {
1223             goto ErrorExit;
1224         }
1225
1226         ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
1227         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1228     }
1229     else
1230     {
1231         /* Validate new scope relative to old scope */
1232
1233         Status = AcpiNsGetNodeByPath (Name, AcpiGbl_DbScopeNode,
1234                     ACPI_NS_NO_UPSEARCH, &Node);
1235         if (ACPI_FAILURE (Status))
1236         {
1237             goto ErrorExit;
1238         }
1239
1240         ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
1241         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1242     }
1243
1244     AcpiGbl_DbScopeNode = Node;
1245     AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
1246     return;
1247
1248 ErrorExit:
1249
1250     AcpiOsPrintf ("Could not attach scope: %s, %s\n",
1251         Name, AcpiFormatException (Status));
1252 }
1253
1254
1255 /*******************************************************************************
1256  *
1257  * FUNCTION:    AcpiDmCompareAmlResources
1258  *
1259  * PARAMETERS:  Aml1Buffer          - Contains first resource list
1260  *              Aml1BufferLength    - Length of first resource list
1261  *              Aml2Buffer          - Contains second resource list
1262  *              Aml2BufferLength    - Length of second resource list
1263  *
1264  * RETURN:      None
1265  *
1266  * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
1267  *              order to isolate a miscompare to an individual resource)
1268  *
1269  ******************************************************************************/
1270
1271 static void
1272 AcpiDmCompareAmlResources (
1273     UINT8                   *Aml1Buffer,
1274     ACPI_RSDESC_SIZE        Aml1BufferLength,
1275     UINT8                   *Aml2Buffer,
1276     ACPI_RSDESC_SIZE        Aml2BufferLength)
1277 {
1278     UINT8                   *Aml1;
1279     UINT8                   *Aml2;
1280     ACPI_RSDESC_SIZE        Aml1Length;
1281     ACPI_RSDESC_SIZE        Aml2Length;
1282     ACPI_RSDESC_SIZE        Offset = 0;
1283     UINT8                   ResourceType;
1284     UINT32                  Count = 0;
1285
1286
1287     /* Compare overall buffer sizes (may be different due to size rounding) */
1288
1289     if (Aml1BufferLength != Aml2BufferLength)
1290     {
1291         AcpiOsPrintf (
1292             "**** Buffer length mismatch in converted AML: original %X new %X ****\n",
1293             Aml1BufferLength, Aml2BufferLength);
1294     }
1295
1296     Aml1 = Aml1Buffer;
1297     Aml2 = Aml2Buffer;
1298
1299     /* Walk the descriptor lists, comparing each descriptor */
1300
1301     while (Aml1 < (Aml1Buffer + Aml1BufferLength))
1302     {
1303         /* Get the lengths of each descriptor */
1304
1305         Aml1Length = AcpiUtGetDescriptorLength (Aml1);
1306         Aml2Length = AcpiUtGetDescriptorLength (Aml2);
1307         ResourceType = AcpiUtGetResourceType (Aml1);
1308
1309         /* Check for descriptor length match */
1310
1311         if (Aml1Length != Aml2Length)
1312         {
1313             AcpiOsPrintf (
1314                 "**** Length mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X L1 %X L2 %X ****\n",
1315                 Count, ResourceType, Offset, Aml1Length, Aml2Length);
1316             return;
1317         }
1318
1319         /* Check for descriptor byte match */
1320
1321         if (ACPI_MEMCMP (Aml1, Aml2, Aml1Length))
1322         {
1323             AcpiOsPrintf (
1324                 "**** Data mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X ****\n",
1325                 Count, ResourceType, Offset);
1326         }
1327
1328         /* Exit on EndTag descriptor */
1329
1330         if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)
1331         {
1332             return;
1333         }
1334
1335         /* Point to next descriptor in each buffer */
1336
1337         Count++;
1338         Offset += Aml1Length;
1339         Aml1 += Aml1Length;
1340         Aml2 += Aml1Length;
1341     }
1342 }
1343
1344
1345 /*******************************************************************************
1346  *
1347  * FUNCTION:    AcpiDmTestResourceConversion
1348  *
1349  * PARAMETERS:  Node            - Parent device node
1350  *              Name            - resource method name (_CRS)
1351  *
1352  * RETURN:      Status
1353  *
1354  * DESCRIPTION: Compare the original AML with a conversion of the AML to
1355  *              internal resource list, then back to AML.
1356  *
1357  ******************************************************************************/
1358
1359 static ACPI_STATUS
1360 AcpiDmTestResourceConversion (
1361     ACPI_NAMESPACE_NODE     *Node,
1362     char                    *Name)
1363 {
1364     ACPI_STATUS             Status;
1365     ACPI_BUFFER             ReturnObj;
1366     ACPI_BUFFER             ResourceObj;
1367     ACPI_BUFFER             NewAml;
1368     ACPI_OBJECT             *OriginalAml;
1369
1370
1371     AcpiOsPrintf ("Resource Conversion Comparison:\n");
1372
1373     NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1374     ReturnObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1375     ResourceObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1376
1377     /* Get the original _CRS AML resource template */
1378
1379     Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnObj);
1380     if (ACPI_FAILURE (Status))
1381     {
1382         AcpiOsPrintf ("Could not obtain %s: %s\n",
1383             Name, AcpiFormatException (Status));
1384         return (Status);
1385     }
1386
1387     /* Get the AML resource template, converted to internal resource structs */
1388
1389     Status = AcpiGetCurrentResources (Node, &ResourceObj);
1390     if (ACPI_FAILURE (Status))
1391     {
1392         AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
1393             AcpiFormatException (Status));
1394         goto Exit1;
1395     }
1396
1397     /* Convert internal resource list to external AML resource template */
1398
1399     Status = AcpiRsCreateAmlResources (ResourceObj.Pointer, &NewAml);
1400     if (ACPI_FAILURE (Status))
1401     {
1402         AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",
1403             AcpiFormatException (Status));
1404         goto Exit2;
1405     }
1406
1407     /* Compare original AML to the newly created AML resource list */
1408
1409     OriginalAml = ReturnObj.Pointer;
1410
1411     AcpiDmCompareAmlResources (
1412         OriginalAml->Buffer.Pointer, OriginalAml->Buffer.Length,
1413         NewAml.Pointer, NewAml.Length);
1414
1415     /* Cleanup and exit */
1416
1417     ACPI_MEM_FREE (NewAml.Pointer);
1418 Exit2:
1419     ACPI_MEM_FREE (ResourceObj.Pointer);
1420 Exit1:
1421     ACPI_MEM_FREE (ReturnObj.Pointer);
1422     return (Status);
1423 }
1424
1425
1426 /*******************************************************************************
1427  *
1428  * FUNCTION:    AcpiDbDisplayResources
1429  *
1430  * PARAMETERS:  ObjectArg       - String with hex value of the object
1431  *
1432  * RETURN:      None
1433  *
1434  * DESCRIPTION: Display the resource objects associated with a device.
1435  *
1436  ******************************************************************************/
1437
1438 void
1439 AcpiDbDisplayResources (
1440     char                    *ObjectArg)
1441 {
1442 #if ACPI_MACHINE_WIDTH != 16
1443
1444     ACPI_NAMESPACE_NODE     *Node;
1445     ACPI_STATUS             Status;
1446     ACPI_BUFFER             ReturnObj;
1447
1448
1449     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1450     AcpiDbgLevel |= ACPI_LV_RESOURCES;
1451
1452     /* Convert string to object pointer */
1453
1454     Node = AcpiDbConvertToNode (ObjectArg);
1455     if (!Node)
1456     {
1457         return;
1458     }
1459
1460     /* Prepare for a return object of arbitrary size */
1461
1462     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1463     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1464
1465     /* _PRT */
1466
1467     AcpiOsPrintf ("Evaluating _PRT\n");
1468
1469     /* Check if _PRT exists */
1470
1471     Status = AcpiEvaluateObject (Node, METHOD_NAME__PRT, NULL, &ReturnObj);
1472     if (ACPI_FAILURE (Status))
1473     {
1474         AcpiOsPrintf ("Could not obtain _PRT: %s\n",
1475             AcpiFormatException (Status));
1476         goto GetCrs;
1477     }
1478
1479     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1480     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1481
1482     Status = AcpiGetIrqRoutingTable (Node, &ReturnObj);
1483     if (ACPI_FAILURE (Status))
1484     {
1485         AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",
1486             AcpiFormatException (Status));
1487         goto GetCrs;
1488     }
1489
1490     AcpiRsDumpIrqList ((UINT8 *) AcpiGbl_DbBuffer);
1491
1492
1493     /* _CRS */
1494
1495 GetCrs:
1496     AcpiOsPrintf ("Evaluating _CRS\n");
1497
1498     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1499     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1500
1501     /* Check if _CRS exists */
1502
1503     Status = AcpiEvaluateObject (Node, METHOD_NAME__CRS, NULL, &ReturnObj);
1504     if (ACPI_FAILURE (Status))
1505     {
1506         AcpiOsPrintf ("Could not obtain _CRS: %s\n",
1507             AcpiFormatException (Status));
1508         goto GetPrs;
1509     }
1510
1511     /* Get the _CRS resource list */
1512
1513     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1514     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1515
1516     Status = AcpiGetCurrentResources (Node, &ReturnObj);
1517     if (ACPI_FAILURE (Status))
1518     {
1519         AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
1520             AcpiFormatException (Status));
1521         goto GetPrs;
1522     }
1523
1524     /* Dump the _CRS resource list */
1525
1526     AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
1527         ReturnObj.Pointer));
1528
1529     /*
1530      * Perform comparison of original AML to newly created AML. This tests both
1531      * the AML->Resource conversion and the Resource->Aml conversion.
1532      */
1533     Status = AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);
1534
1535     /* Execute _SRS with the resource list */
1536
1537     Status = AcpiSetCurrentResources (Node, &ReturnObj);
1538     if (ACPI_FAILURE (Status))
1539     {
1540         AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",
1541             AcpiFormatException (Status));
1542         goto GetPrs;
1543     }
1544
1545
1546     /* _PRS */
1547
1548 GetPrs:
1549     AcpiOsPrintf ("Evaluating _PRS\n");
1550
1551     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1552     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1553
1554     /* Check if _PRS exists */
1555
1556     Status = AcpiEvaluateObject (Node, METHOD_NAME__PRS, NULL, &ReturnObj);
1557     if (ACPI_FAILURE (Status))
1558     {
1559         AcpiOsPrintf ("Could not obtain _PRS: %s\n",
1560             AcpiFormatException (Status));
1561         goto Cleanup;
1562     }
1563
1564     ReturnObj.Pointer = AcpiGbl_DbBuffer;
1565     ReturnObj.Length  = ACPI_DEBUG_BUFFER_SIZE;
1566
1567     Status = AcpiGetPossibleResources (Node, &ReturnObj);
1568     if (ACPI_FAILURE (Status))
1569     {
1570         AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",
1571             AcpiFormatException (Status));
1572         goto Cleanup;
1573     }
1574
1575     AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1576
1577 Cleanup:
1578
1579     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1580     return;
1581 #endif
1582 }
1583
1584
1585 /*******************************************************************************
1586  *
1587  * FUNCTION:    AcpiDbIntegrityWalk
1588  *
1589  * PARAMETERS:  Callback from WalkNamespace
1590  *
1591  * RETURN:      Status
1592  *
1593  * DESCRIPTION: Examine one NS node for valid values.
1594  *
1595  ******************************************************************************/
1596
1597 static ACPI_STATUS
1598 AcpiDbIntegrityWalk (
1599     ACPI_HANDLE             ObjHandle,
1600     UINT32                  NestingLevel,
1601     void                    *Context,
1602     void                    **ReturnValue)
1603 {
1604     ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
1605     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1606     ACPI_OPERAND_OBJECT     *Object;
1607
1608
1609     Info->Nodes++;
1610     if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
1611     {
1612         AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s]\n",
1613             Node, AcpiUtGetDescriptorName (Node));
1614     }
1615
1616     if (Node->Type > ACPI_TYPE_LOCAL_MAX)
1617     {
1618         AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
1619             Node, Node->Type);
1620     }
1621
1622     if (!AcpiUtValidAcpiName (Node->Name.Integer))
1623     {
1624         AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
1625     }
1626
1627     Object = AcpiNsGetAttachedObject (Node);
1628     if (Object)
1629     {
1630         Info->Objects++;
1631         if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
1632         {
1633             AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
1634                 Object, AcpiUtGetDescriptorName (Object));
1635         }
1636     }
1637
1638     return (AE_OK);
1639 }
1640
1641
1642 /*******************************************************************************
1643  *
1644  * FUNCTION:    AcpiDbCheckIntegrity
1645  *
1646  * PARAMETERS:  None
1647  *
1648  * RETURN:      None
1649  *
1650  * DESCRIPTION: Check entire namespace for data structure integrity
1651  *
1652  ******************************************************************************/
1653
1654 void
1655 AcpiDbCheckIntegrity (
1656     void)
1657 {
1658     ACPI_INTEGRITY_INFO     Info = {0,0};
1659
1660     /* Search all nodes in namespace */
1661
1662     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1663                     AcpiDbIntegrityWalk, (void *) &Info, NULL);
1664
1665     AcpiOsPrintf ("Verified %d namespace nodes with %d Objects\n",
1666         Info.Nodes, Info.Objects);
1667 }
1668
1669
1670 /*******************************************************************************
1671  *
1672  * FUNCTION:    AcpiDbGenerateGpe
1673  *
1674  * PARAMETERS:  GpeArg          - Raw GPE number, ascii string
1675  *              BlockArg        - GPE block number, ascii string
1676  *                                0 or 1 for FADT GPE blocks
1677  *
1678  * RETURN:      None
1679  *
1680  * DESCRIPTION: Generate a GPE
1681  *
1682  ******************************************************************************/
1683
1684 void
1685 AcpiDbGenerateGpe (
1686     char                    *GpeArg,
1687     char                    *BlockArg)
1688 {
1689     UINT32                  BlockNumber;
1690     UINT32                  GpeNumber;
1691     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
1692
1693
1694     GpeNumber   = ACPI_STRTOUL (GpeArg, NULL, 0);
1695     BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 0);
1696
1697
1698     GpeEventInfo = AcpiEvGetGpeEventInfo (ACPI_TO_POINTER (BlockNumber),
1699         GpeNumber);
1700     if (!GpeEventInfo)
1701     {
1702         AcpiOsPrintf ("Invalid GPE\n");
1703         return;
1704     }
1705
1706     (void) AcpiEvGpeDispatch (GpeEventInfo, GpeNumber);
1707 }
1708
1709
1710 /*******************************************************************************
1711  *
1712  * FUNCTION:    AcpiDbBusWalk
1713  *
1714  * PARAMETERS:  Callback from WalkNamespace
1715  *
1716  * RETURN:      Status
1717  *
1718  * DESCRIPTION: Display info about device objects that have a corresponding
1719  *              _PRT method.
1720  *
1721  ******************************************************************************/
1722
1723 static ACPI_STATUS
1724 AcpiDbBusWalk (
1725     ACPI_HANDLE             ObjHandle,
1726     UINT32                  NestingLevel,
1727     void                    *Context,
1728     void                    **ReturnValue)
1729 {
1730     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1731     ACPI_STATUS             Status;
1732     ACPI_BUFFER             Buffer;
1733     ACPI_INTEGER            ADR;
1734     ACPI_DEVICE_ID          Id;
1735     ACPI_COMPATIBLE_ID_LIST *Cid;
1736     ACPI_NAMESPACE_NODE     *TempNode;
1737
1738
1739     /* Exit if there is no _PRT under this device */
1740
1741     Status = AcpiGetHandle (Node, METHOD_NAME__PRT, (ACPI_HANDLE *) (uintptr_t) &TempNode);
1742     if (ACPI_FAILURE (Status))
1743     {
1744         return (AE_OK);
1745     }
1746
1747     /* Get the full path to this device object */
1748
1749     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1750     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
1751     if (ACPI_FAILURE (Status))
1752     {
1753         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
1754         return (AE_OK);
1755     }
1756
1757     /* Display the full path */
1758
1759     AcpiOsPrintf ("%-32s", (char *) Buffer.Pointer);
1760     ACPI_MEM_FREE (Buffer.Pointer);
1761
1762     /* _PRT info */
1763
1764     AcpiOsPrintf ("_PRT=%p", TempNode);
1765
1766     /* Get the _ADR value */
1767
1768     Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node, &ADR);
1769     if (ACPI_FAILURE (Status))
1770     {
1771         AcpiOsPrintf (" No _ADR      ");
1772     }
1773     else
1774     {
1775         AcpiOsPrintf (" _ADR=%8.8X", (UINT32) ADR);
1776     }
1777
1778     /* Get the _HID if present */
1779
1780     Status = AcpiUtExecute_HID (Node, &Id);
1781     if (ACPI_SUCCESS (Status))
1782     {
1783         AcpiOsPrintf (" _HID=%s", Id.Value);
1784     }
1785     else
1786     {
1787         AcpiOsPrintf ("             ");
1788     }
1789
1790     /* Get the _UID if present */
1791
1792     Status = AcpiUtExecute_UID (Node, &Id);
1793     if (ACPI_SUCCESS (Status))
1794     {
1795         AcpiOsPrintf (" _UID=%s", Id.Value);
1796     }
1797
1798     /* Get the _CID if present */
1799
1800     Status = AcpiUtExecute_CID (Node, &Cid);
1801     if (ACPI_SUCCESS (Status))
1802     {
1803         AcpiOsPrintf (" _CID=%s", Cid->Id[0].Value);
1804         ACPI_MEM_FREE (Cid);
1805     }
1806
1807     AcpiOsPrintf ("\n");
1808     return (AE_OK);
1809 }
1810
1811
1812 /*******************************************************************************
1813  *
1814  * FUNCTION:    AcpiDbGetBusInfo
1815  *
1816  * PARAMETERS:  None
1817  *
1818  * RETURN:      None
1819  *
1820  * DESCRIPTION: Display info about system busses.
1821  *
1822  ******************************************************************************/
1823
1824 void
1825 AcpiDbGetBusInfo (
1826     void)
1827 {
1828     /* Search all nodes in namespace */
1829
1830     (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1831                     AcpiDbBusWalk, NULL, NULL);
1832 }
1833
1834 #endif /* ACPI_DEBUGGER */