Bring in acpica 20110211, still not ok anyway
[dragonfly.git] / sys / contrib / dev / acpica-unix / debugger / dbnames.c
1 /*******************************************************************************
2  *
3  * Module Name: dbnames - Debugger commands for the acpi namespace
4  *
5  ******************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights.  You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code.  No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision.  In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change.  Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee.  Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution.  In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government.  In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acnamesp.h"
120 #include "acdebug.h"
121
122
123 #ifdef ACPI_DEBUGGER
124
125 #define _COMPONENT          ACPI_CA_DEBUGGER
126         ACPI_MODULE_NAME    ("dbnames")
127
128
129 /* Local prototypes */
130
131 static ACPI_STATUS
132 AcpiDbWalkAndMatchName (
133     ACPI_HANDLE             ObjHandle,
134     UINT32                  NestingLevel,
135     void                    *Context,
136     void                    **ReturnValue);
137
138 static ACPI_STATUS
139 AcpiDbWalkForPredefinedNames (
140     ACPI_HANDLE             ObjHandle,
141     UINT32                  NestingLevel,
142     void                    *Context,
143     void                    **ReturnValue);
144
145 static ACPI_STATUS
146 AcpiDbWalkForSpecificObjects (
147     ACPI_HANDLE             ObjHandle,
148     UINT32                  NestingLevel,
149     void                    *Context,
150     void                    **ReturnValue);
151
152 static ACPI_STATUS
153 AcpiDbIntegrityWalk (
154     ACPI_HANDLE             ObjHandle,
155     UINT32                  NestingLevel,
156     void                    *Context,
157     void                    **ReturnValue);
158
159 static ACPI_STATUS
160 AcpiDbWalkForReferences (
161     ACPI_HANDLE             ObjHandle,
162     UINT32                  NestingLevel,
163     void                    *Context,
164     void                    **ReturnValue);
165
166 static ACPI_STATUS
167 AcpiDbBusWalk (
168     ACPI_HANDLE             ObjHandle,
169     UINT32                  NestingLevel,
170     void                    *Context,
171     void                    **ReturnValue);
172
173 /*
174  * Arguments for the Objects command
175  * These object types map directly to the ACPI_TYPES
176  */
177 static ARGUMENT_INFO        AcpiDbObjectTypes [] =
178 {
179     {"ANY"},
180     {"INTEGERS"},
181     {"STRINGS"},
182     {"BUFFERS"},
183     {"PACKAGES"},
184     {"FIELDS"},
185     {"DEVICES"},
186     {"EVENTS"},
187     {"METHODS"},
188     {"MUTEXES"},
189     {"REGIONS"},
190     {"POWERRESOURCES"},
191     {"PROCESSORS"},
192     {"THERMALZONES"},
193     {"BUFFERFIELDS"},
194     {"DDBHANDLES"},
195     {"DEBUG"},
196     {"REGIONFIELDS"},
197     {"BANKFIELDS"},
198     {"INDEXFIELDS"},
199     {"REFERENCES"},
200     {"ALIAS"},
201     {NULL}           /* Must be null terminated */
202 };
203
204
205 /*******************************************************************************
206  *
207  * FUNCTION:    AcpiDbSetScope
208  *
209  * PARAMETERS:  Name                - New scope path
210  *
211  * RETURN:      Status
212  *
213  * DESCRIPTION: Set the "current scope" as maintained by this utility.
214  *              The scope is used as a prefix to ACPI paths.
215  *
216  ******************************************************************************/
217
218 void
219 AcpiDbSetScope (
220     char                    *Name)
221 {
222     ACPI_STATUS             Status;
223     ACPI_NAMESPACE_NODE     *Node;
224
225
226     if (!Name || Name[0] == 0)
227     {
228         AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
229         return;
230     }
231
232     AcpiDbPrepNamestring (Name);
233
234     if (Name[0] == '\\')
235     {
236         /* Validate new scope from the root */
237
238         Status = AcpiNsGetNode (AcpiGbl_RootNode, Name, ACPI_NS_NO_UPSEARCH,
239                     &Node);
240         if (ACPI_FAILURE (Status))
241         {
242             goto ErrorExit;
243         }
244
245         ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
246         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
247     }
248     else
249     {
250         /* Validate new scope relative to old scope */
251
252         Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name, ACPI_NS_NO_UPSEARCH,
253                     &Node);
254         if (ACPI_FAILURE (Status))
255         {
256             goto ErrorExit;
257         }
258
259         ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
260         ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
261     }
262
263     AcpiGbl_DbScopeNode = Node;
264     AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
265     return;
266
267 ErrorExit:
268
269     AcpiOsPrintf ("Could not attach scope: %s, %s\n",
270         Name, AcpiFormatException (Status));
271 }
272
273
274 /*******************************************************************************
275  *
276  * FUNCTION:    AcpiDbDumpNamespace
277  *
278  * PARAMETERS:  StartArg        - Node to begin namespace dump
279  *              DepthArg        - Maximum tree depth to be dumped
280  *
281  * RETURN:      None
282  *
283  * DESCRIPTION: Dump entire namespace or a subtree.  Each node is displayed
284  *              with type and other information.
285  *
286  ******************************************************************************/
287
288 void
289 AcpiDbDumpNamespace (
290     char                    *StartArg,
291     char                    *DepthArg)
292 {
293     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
294     UINT32                  MaxDepth = ACPI_UINT32_MAX;
295
296
297     /* No argument given, just start at the root and dump entire namespace */
298
299     if (StartArg)
300     {
301         SubtreeEntry = AcpiDbConvertToNode (StartArg);
302         if (!SubtreeEntry)
303         {
304             return;
305         }
306
307         /* Now we can check for the depth argument */
308
309         if (DepthArg)
310         {
311             MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
312         }
313     }
314
315     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
316     AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
317         ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
318
319     /* Display the subtree */
320
321     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
322     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
323         ACPI_OWNER_ID_MAX, SubtreeEntry);
324     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
325 }
326
327
328 /*******************************************************************************
329  *
330  * FUNCTION:    AcpiDbDumpNamespaceByOwner
331  *
332  * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
333  *              DepthArg        - Maximum tree depth to be dumped
334  *
335  * RETURN:      None
336  *
337  * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
338  *
339  ******************************************************************************/
340
341 void
342 AcpiDbDumpNamespaceByOwner (
343     char                    *OwnerArg,
344     char                    *DepthArg)
345 {
346     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
347     UINT32                  MaxDepth = ACPI_UINT32_MAX;
348     ACPI_OWNER_ID           OwnerId;
349
350
351     OwnerId = (ACPI_OWNER_ID) ACPI_STRTOUL (OwnerArg, NULL, 0);
352
353     /* Now we can check for the depth argument */
354
355     if (DepthArg)
356     {
357         MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
358     }
359
360     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
361     AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
362
363     /* Display the subtree */
364
365     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
366     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId,
367         SubtreeEntry);
368     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
369 }
370
371
372 /*******************************************************************************
373  *
374  * FUNCTION:    AcpiDbWalkAndMatchName
375  *
376  * PARAMETERS:  Callback from WalkNamespace
377  *
378  * RETURN:      Status
379  *
380  * DESCRIPTION: Find a particular name/names within the namespace.  Wildcards
381  *              are supported -- '?' matches any character.
382  *
383  ******************************************************************************/
384
385 static ACPI_STATUS
386 AcpiDbWalkAndMatchName (
387     ACPI_HANDLE             ObjHandle,
388     UINT32                  NestingLevel,
389     void                    *Context,
390     void                    **ReturnValue)
391 {
392     ACPI_STATUS             Status;
393     char                    *RequestedName = (char *) Context;
394     UINT32                  i;
395     ACPI_BUFFER             Buffer;
396     ACPI_WALK_INFO          Info;
397
398
399     /* Check for a name match */
400
401     for (i = 0; i < 4; i++)
402     {
403         /* Wildcard support */
404
405         if ((RequestedName[i] != '?') &&
406             (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
407         {
408             /* No match, just exit */
409
410             return (AE_OK);
411         }
412     }
413
414     /* Get the full pathname to this object */
415
416     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
417     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
418     if (ACPI_FAILURE (Status))
419     {
420         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
421     }
422     else
423     {
424         Info.OwnerId = ACPI_OWNER_ID_MAX;
425         Info.DebugLevel = ACPI_UINT32_MAX;
426         Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
427
428         AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
429         (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
430         ACPI_FREE (Buffer.Pointer);
431     }
432
433     return (AE_OK);
434 }
435
436
437 /*******************************************************************************
438  *
439  * FUNCTION:    AcpiDbFindNameInNamespace
440  *
441  * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
442  *                                wildcards are supported.
443  *
444  * RETURN:      None
445  *
446  * DESCRIPTION: Search the namespace for a given name (with wildcards)
447  *
448  ******************************************************************************/
449
450 ACPI_STATUS
451 AcpiDbFindNameInNamespace (
452     char                    *NameArg)
453 {
454     char                    AcpiName[5] = "____";
455     char                    *AcpiNamePtr = AcpiName;
456
457
458     if (ACPI_STRLEN (NameArg) > 4)
459     {
460         AcpiOsPrintf ("Name must be no longer than 4 characters\n");
461         return (AE_OK);
462     }
463
464     /* Pad out name with underscores as necessary to create a 4-char name */
465
466     AcpiUtStrupr (NameArg);
467     while (*NameArg)
468     {
469         *AcpiNamePtr = *NameArg;
470         AcpiNamePtr++;
471         NameArg++;
472     }
473
474     /* Walk the namespace from the root */
475
476     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
477                         AcpiDbWalkAndMatchName, NULL, AcpiName, NULL);
478
479     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
480     return (AE_OK);
481 }
482
483
484 /*******************************************************************************
485  *
486  * FUNCTION:    AcpiDbWalkForPredefinedNames
487  *
488  * PARAMETERS:  Callback from WalkNamespace
489  *
490  * RETURN:      Status
491  *
492  * DESCRIPTION: Detect and display predefined ACPI names (names that start with
493  *              an underscore)
494  *
495  ******************************************************************************/
496
497 static ACPI_STATUS
498 AcpiDbWalkForPredefinedNames (
499     ACPI_HANDLE             ObjHandle,
500     UINT32                  NestingLevel,
501     void                    *Context,
502     void                    **ReturnValue)
503 {
504     ACPI_NAMESPACE_NODE         *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
505     UINT32                      *Count = (UINT32 *) Context;
506     const ACPI_PREDEFINED_INFO  *Predefined;
507     const ACPI_PREDEFINED_INFO  *Package = NULL;
508     char                        *Pathname;
509
510
511     Predefined = AcpiNsCheckForPredefinedName (Node);
512     if (!Predefined)
513     {
514         return (AE_OK);
515     }
516
517     Pathname = AcpiNsGetExternalPathname (Node);
518     if (!Pathname)
519     {
520         return (AE_OK);
521     }
522
523     /* If method returns a package, the info is in the next table entry */
524
525     if (Predefined->Info.ExpectedBtypes & ACPI_BTYPE_PACKAGE)
526     {
527         Package = Predefined + 1;
528     }
529
530     AcpiOsPrintf ("%-32s arg %X ret %2.2X", Pathname,
531         Predefined->Info.ParamCount, Predefined->Info.ExpectedBtypes);
532
533     if (Package)
534     {
535         AcpiOsPrintf (" PkgType %2.2X ObjType %2.2X Count %2.2X",
536             Package->RetInfo.Type, Package->RetInfo.ObjectType1,
537             Package->RetInfo.Count1);
538     }
539
540     AcpiOsPrintf("\n");
541
542     AcpiNsCheckParameterCount (Pathname, Node, ACPI_UINT32_MAX, Predefined);
543     ACPI_FREE (Pathname);
544     (*Count)++;
545
546     return (AE_OK);
547 }
548
549
550 /*******************************************************************************
551  *
552  * FUNCTION:    AcpiDbCheckPredefinedNames
553  *
554  * PARAMETERS:  None
555  *
556  * RETURN:      None
557  *
558  * DESCRIPTION: Validate all predefined names in the namespace
559  *
560  ******************************************************************************/
561
562 void
563 AcpiDbCheckPredefinedNames (
564     void)
565 {
566     UINT32                  Count = 0;
567
568
569     /* Search all nodes in namespace */
570
571     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
572                 AcpiDbWalkForPredefinedNames, NULL, (void *) &Count, NULL);
573
574     AcpiOsPrintf ("Found %u predefined names in the namespace\n", Count);
575 }
576
577
578 /*******************************************************************************
579  *
580  * FUNCTION:    AcpiDbWalkForSpecificObjects
581  *
582  * PARAMETERS:  Callback from WalkNamespace
583  *
584  * RETURN:      Status
585  *
586  * DESCRIPTION: Display short info about objects in the namespace
587  *
588  ******************************************************************************/
589
590 static ACPI_STATUS
591 AcpiDbWalkForSpecificObjects (
592     ACPI_HANDLE             ObjHandle,
593     UINT32                  NestingLevel,
594     void                    *Context,
595     void                    **ReturnValue)
596 {
597     ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
598     ACPI_BUFFER             Buffer;
599     ACPI_STATUS             Status;
600
601
602     Info->Count++;
603
604     /* Get and display the full pathname to this object */
605
606     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
607     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
608     if (ACPI_FAILURE (Status))
609     {
610         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
611         return (AE_OK);
612     }
613
614     AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
615     ACPI_FREE (Buffer.Pointer);
616
617     /* Dump short info about the object */
618
619     (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
620     return (AE_OK);
621 }
622
623
624 /*******************************************************************************
625  *
626  * FUNCTION:    AcpiDbDisplayObjects
627  *
628  * PARAMETERS:  ObjTypeArg          - Type of object to display
629  *              DisplayCountArg     - Max depth to display
630  *
631  * RETURN:      None
632  *
633  * DESCRIPTION: Display objects in the namespace of the requested type
634  *
635  ******************************************************************************/
636
637 ACPI_STATUS
638 AcpiDbDisplayObjects (
639     char                    *ObjTypeArg,
640     char                    *DisplayCountArg)
641 {
642     ACPI_WALK_INFO          Info;
643     ACPI_OBJECT_TYPE        Type;
644
645
646     /* Get the object type */
647
648     Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
649     if (Type == ACPI_TYPE_NOT_FOUND)
650     {
651         AcpiOsPrintf ("Invalid or unsupported argument\n");
652         return (AE_OK);
653     }
654
655     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
656     AcpiOsPrintf (
657         "Objects of type [%s] defined in the current ACPI Namespace:\n",
658         AcpiUtGetTypeName (Type));
659
660     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
661
662     Info.Count = 0;
663     Info.OwnerId = ACPI_OWNER_ID_MAX;
664     Info.DebugLevel = ACPI_UINT32_MAX;
665     Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
666
667     /* Walk the namespace from the root */
668
669     (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
670                 AcpiDbWalkForSpecificObjects, NULL, (void *) &Info, NULL);
671
672     AcpiOsPrintf (
673         "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
674         Info.Count, AcpiUtGetTypeName (Type));
675
676     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
677     return (AE_OK);
678 }
679
680
681 /*******************************************************************************
682  *
683  * FUNCTION:    AcpiDbIntegrityWalk
684  *
685  * PARAMETERS:  Callback from WalkNamespace
686  *
687  * RETURN:      Status
688  *
689  * DESCRIPTION: Examine one NS node for valid values.
690  *
691  ******************************************************************************/
692
693 static ACPI_STATUS
694 AcpiDbIntegrityWalk (
695     ACPI_HANDLE             ObjHandle,
696     UINT32                  NestingLevel,
697     void                    *Context,
698     void                    **ReturnValue)
699 {
700     ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
701     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
702     ACPI_OPERAND_OBJECT     *Object;
703     BOOLEAN                 Alias = TRUE;
704
705
706     Info->Nodes++;
707
708     /* Verify the NS node, and dereference aliases */
709
710     while (Alias)
711     {
712         if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
713         {
714             AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s] - is %2.2X should be %2.2X\n",
715                 Node, AcpiUtGetDescriptorName (Node), ACPI_GET_DESCRIPTOR_TYPE (Node),
716                 ACPI_DESC_TYPE_NAMED);
717             return (AE_OK);
718         }
719
720         if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS)  ||
721             (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
722         {
723             Node = (ACPI_NAMESPACE_NODE *) Node->Object;
724         }
725         else
726         {
727             Alias = FALSE;
728         }
729     }
730
731     if (Node->Type > ACPI_TYPE_LOCAL_MAX)
732     {
733         AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
734             Node, Node->Type);
735         return (AE_OK);
736     }
737
738     if (!AcpiUtValidAcpiName (Node->Name.Integer))
739     {
740         AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
741         return (AE_OK);
742     }
743
744     Object = AcpiNsGetAttachedObject (Node);
745     if (Object)
746     {
747         Info->Objects++;
748         if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
749         {
750             AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
751                 Object, AcpiUtGetDescriptorName (Object));
752         }
753     }
754
755     return (AE_OK);
756 }
757
758
759 /*******************************************************************************
760  *
761  * FUNCTION:    AcpiDbCheckIntegrity
762  *
763  * PARAMETERS:  None
764  *
765  * RETURN:      None
766  *
767  * DESCRIPTION: Check entire namespace for data structure integrity
768  *
769  ******************************************************************************/
770
771 void
772 AcpiDbCheckIntegrity (
773     void)
774 {
775     ACPI_INTEGRITY_INFO     Info = {0,0};
776
777     /* Search all nodes in namespace */
778
779     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
780                     AcpiDbIntegrityWalk, NULL, (void *) &Info, NULL);
781
782     AcpiOsPrintf ("Verified %u namespace nodes with %u Objects\n",
783         Info.Nodes, Info.Objects);
784 }
785
786
787 /*******************************************************************************
788  *
789  * FUNCTION:    AcpiDbWalkForReferences
790  *
791  * PARAMETERS:  Callback from WalkNamespace
792  *
793  * RETURN:      Status
794  *
795  * DESCRIPTION: Check if this namespace object refers to the target object
796  *              that is passed in as the context value.
797  *
798  * Note: Currently doesn't check subobjects within the Node's object
799  *
800  ******************************************************************************/
801
802 static ACPI_STATUS
803 AcpiDbWalkForReferences (
804     ACPI_HANDLE             ObjHandle,
805     UINT32                  NestingLevel,
806     void                    *Context,
807     void                    **ReturnValue)
808 {
809     ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
810     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
811
812
813     /* Check for match against the namespace node itself */
814
815     if (Node == (void *) ObjDesc)
816     {
817         AcpiOsPrintf ("Object is a Node [%4.4s]\n",
818             AcpiUtGetNodeName (Node));
819     }
820
821     /* Check for match against the object attached to the node */
822
823     if (AcpiNsGetAttachedObject (Node) == ObjDesc)
824     {
825         AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
826             Node, AcpiUtGetNodeName (Node));
827     }
828
829     return (AE_OK);
830 }
831
832
833 /*******************************************************************************
834  *
835  * FUNCTION:    AcpiDbFindReferences
836  *
837  * PARAMETERS:  ObjectArg       - String with hex value of the object
838  *
839  * RETURN:      None
840  *
841  * DESCRIPTION: Search namespace for all references to the input object
842  *
843  ******************************************************************************/
844
845 void
846 AcpiDbFindReferences (
847     char                    *ObjectArg)
848 {
849     ACPI_OPERAND_OBJECT     *ObjDesc;
850
851
852     /* Convert string to object pointer */
853
854     ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
855
856     /* Search all nodes in namespace */
857
858     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
859                     AcpiDbWalkForReferences, NULL, (void *) ObjDesc, NULL);
860 }
861
862
863 /*******************************************************************************
864  *
865  * FUNCTION:    AcpiDbBusWalk
866  *
867  * PARAMETERS:  Callback from WalkNamespace
868  *
869  * RETURN:      Status
870  *
871  * DESCRIPTION: Display info about device objects that have a corresponding
872  *              _PRT method.
873  *
874  ******************************************************************************/
875
876 static ACPI_STATUS
877 AcpiDbBusWalk (
878     ACPI_HANDLE             ObjHandle,
879     UINT32                  NestingLevel,
880     void                    *Context,
881     void                    **ReturnValue)
882 {
883     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
884     ACPI_STATUS             Status;
885     ACPI_BUFFER             Buffer;
886     ACPI_NAMESPACE_NODE     *TempNode;
887     ACPI_DEVICE_INFO        *Info;
888     UINT32                  i;
889
890
891     if ((Node->Type != ACPI_TYPE_DEVICE) &&
892         (Node->Type != ACPI_TYPE_PROCESSOR))
893     {
894         return (AE_OK);
895     }
896
897     /* Exit if there is no _PRT under this device */
898
899     Status = AcpiGetHandle (Node, METHOD_NAME__PRT,
900                 ACPI_CAST_PTR (ACPI_HANDLE, &TempNode));
901     if (ACPI_FAILURE (Status))
902     {
903         return (AE_OK);
904     }
905
906     /* Get the full path to this device object */
907
908     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
909     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
910     if (ACPI_FAILURE (Status))
911     {
912         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
913         return (AE_OK);
914     }
915
916     Status = AcpiGetObjectInfo (ObjHandle, &Info);
917     if (ACPI_FAILURE (Status))
918     {
919         return (AE_OK);
920     }
921
922     /* Display the full path */
923
924     AcpiOsPrintf ("%-32s Type %X", (char *) Buffer.Pointer, Node->Type);
925     ACPI_FREE (Buffer.Pointer);
926
927     if (Info->Flags & ACPI_PCI_ROOT_BRIDGE)
928     {
929         AcpiOsPrintf ("  - Is PCI Root Bridge");
930     }
931     AcpiOsPrintf ("\n");
932
933     /* _PRT info */
934
935     AcpiOsPrintf ("_PRT: %p\n", TempNode);
936
937     /* Dump _ADR, _HID, _UID, _CID */
938
939     if (Info->Valid & ACPI_VALID_ADR)
940     {
941         AcpiOsPrintf ("_ADR: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Info->Address));
942     }
943     else
944     {
945         AcpiOsPrintf ("_ADR: <Not Present>\n");
946     }
947
948     if (Info->Valid & ACPI_VALID_HID)
949     {
950         AcpiOsPrintf ("_HID: %s\n", Info->HardwareId.String);
951     }
952     else
953     {
954         AcpiOsPrintf ("_HID: <Not Present>\n");
955     }
956
957     if (Info->Valid & ACPI_VALID_UID)
958     {
959         AcpiOsPrintf ("_UID: %s\n", Info->UniqueId.String);
960     }
961     else
962     {
963         AcpiOsPrintf ("_UID: <Not Present>\n");
964     }
965
966     if (Info->Valid & ACPI_VALID_CID)
967     {
968         for (i = 0; i < Info->CompatibleIdList.Count; i++)
969         {
970             AcpiOsPrintf ("_CID: %s\n",
971                 Info->CompatibleIdList.Ids[i].String);
972         }
973     }
974     else
975     {
976         AcpiOsPrintf ("_CID: <Not Present>\n");
977     }
978
979     ACPI_FREE (Info);
980     return (AE_OK);
981 }
982
983
984 /*******************************************************************************
985  *
986  * FUNCTION:    AcpiDbGetBusInfo
987  *
988  * PARAMETERS:  None
989  *
990  * RETURN:      None
991  *
992  * DESCRIPTION: Display info about system busses.
993  *
994  ******************************************************************************/
995
996 void
997 AcpiDbGetBusInfo (
998     void)
999 {
1000     /* Search all nodes in namespace */
1001
1002     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1003                     AcpiDbBusWalk, NULL, NULL, NULL);
1004 }
1005
1006 #endif /* ACPI_DEBUGGER */